/src/frr/bgpd/rfapi/rfapi_encap_tlv.c
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-2.0-or-later |
2 | | /* |
3 | | * Copyright 2015-2016, LabN Consulting, L.L.C. |
4 | | */ |
5 | | |
6 | | #include "lib/zebra.h" |
7 | | |
8 | | #include "lib/memory.h" |
9 | | #include "lib/prefix.h" |
10 | | #include "lib/table.h" |
11 | | #include "lib/vty.h" |
12 | | |
13 | | #include "bgpd/bgpd.h" |
14 | | #include "bgpd/bgp_attr.h" |
15 | | |
16 | | #include "bgpd/bgp_encap_types.h" |
17 | | #include "bgpd/bgp_encap_tlv.h" |
18 | | |
19 | | #include "bgpd/rfapi/rfapi.h" |
20 | | #include "bgpd/rfapi/rfapi_encap_tlv.h" |
21 | | #include "bgpd/rfapi/rfapi_private.h" |
22 | | #include "bgpd/rfapi/rfapi_monitor.h" |
23 | | #include "bgpd/rfapi/rfapi_vty.h" |
24 | | #include "bgpd/rfapi/bgp_rfapi_cfg.h" |
25 | | #include "bgpd/rfapi/vnc_debug.h" |
26 | | |
27 | | static void rfapi_add_endpoint_address_to_subtlv( |
28 | | struct bgp *bgp, struct rfapi_ip_addr *ea, |
29 | | struct bgp_tea_subtlv_remote_endpoint *subtlv) |
30 | 0 | { |
31 | 0 | subtlv->family = ea->addr_family; |
32 | 0 | if (subtlv->family == AF_INET) |
33 | 0 | subtlv->ip_address.v4 = ea->addr.v4; |
34 | 0 | else |
35 | 0 | subtlv->ip_address.v6 = ea->addr.v6; |
36 | 0 | subtlv->as4 = htonl(bgp->as); |
37 | 0 | } |
38 | | |
39 | | bgp_encap_types |
40 | | rfapi_tunneltype_option_to_tlv(struct bgp *bgp, struct rfapi_ip_addr *ea, |
41 | | struct rfapi_tunneltype_option *tto, |
42 | | struct attr *attr, int always_add) |
43 | 0 | { |
44 | |
|
45 | 0 | #define _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS(ttype) \ |
46 | 0 | if ((always_add \ |
47 | 0 | || (bgp->rfapi_cfg \ |
48 | 0 | && !CHECK_FLAG(bgp->rfapi_cfg->flags, \ |
49 | 0 | BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP))) \ |
50 | 0 | && ea \ |
51 | 0 | && !CHECK_SUBTLV_FLAG(&tto->bgpinfo.ttype, \ |
52 | 0 | BGP_TEA_SUBTLV_REMOTE_ENDPOINT)) { \ |
53 | 0 | rfapi_add_endpoint_address_to_subtlv( \ |
54 | 0 | bgp, ea, &tto->bgpinfo.ttype.st_endpoint); \ |
55 | 0 | SET_SUBTLV_FLAG(&tto->bgpinfo.ttype, \ |
56 | 0 | BGP_TEA_SUBTLV_REMOTE_ENDPOINT); \ |
57 | 0 | } |
58 | |
|
59 | 0 | struct rfapi_tunneltype_option dto; |
60 | 0 | if (tto == NULL) { /* create default type */ |
61 | 0 | tto = &dto; |
62 | 0 | memset(tto, 0, sizeof(dto)); |
63 | 0 | tto->type = RFAPI_BGP_ENCAP_TYPE_DEFAULT; |
64 | 0 | } |
65 | 0 | switch (tto->type) { |
66 | 0 | case BGP_ENCAP_TYPE_L2TPV3_OVER_IP: |
67 | 0 | _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS(l2tpv3_ip); |
68 | 0 | bgp_encap_type_l2tpv3overip_to_tlv(&tto->bgpinfo.l2tpv3_ip, |
69 | 0 | attr); |
70 | 0 | break; |
71 | | |
72 | 0 | case BGP_ENCAP_TYPE_GRE: |
73 | 0 | _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS(gre); |
74 | 0 | bgp_encap_type_gre_to_tlv(&tto->bgpinfo.gre, attr); |
75 | 0 | break; |
76 | | |
77 | 0 | case BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT: |
78 | 0 | _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS(transmit_tunnel_endpoint); |
79 | 0 | bgp_encap_type_transmit_tunnel_endpoint( |
80 | 0 | &tto->bgpinfo.transmit_tunnel_endpoint, attr); |
81 | 0 | break; |
82 | | |
83 | 0 | case BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE: |
84 | 0 | _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS(ipsec_tunnel); |
85 | 0 | bgp_encap_type_ipsec_in_tunnel_mode_to_tlv( |
86 | 0 | &tto->bgpinfo.ipsec_tunnel, attr); |
87 | 0 | break; |
88 | | |
89 | 0 | case BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE: |
90 | 0 | _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS(ip_ipsec); |
91 | 0 | bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode_to_tlv( |
92 | 0 | &tto->bgpinfo.ip_ipsec, attr); |
93 | 0 | break; |
94 | | |
95 | 0 | case BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE: |
96 | 0 | _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS(mpls_ipsec); |
97 | 0 | bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode_to_tlv( |
98 | 0 | &tto->bgpinfo.mpls_ipsec, attr); |
99 | 0 | break; |
100 | | |
101 | 0 | case BGP_ENCAP_TYPE_IP_IN_IP: |
102 | 0 | _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS(ip_ip); |
103 | 0 | bgp_encap_type_ip_in_ip_to_tlv(&tto->bgpinfo.ip_ip, attr); |
104 | 0 | break; |
105 | | |
106 | 0 | case BGP_ENCAP_TYPE_VXLAN: |
107 | 0 | _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS(vxlan); |
108 | 0 | bgp_encap_type_vxlan_to_tlv(&tto->bgpinfo.vxlan, attr); |
109 | 0 | break; |
110 | | |
111 | 0 | case BGP_ENCAP_TYPE_NVGRE: |
112 | 0 | _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS(nvgre); |
113 | 0 | bgp_encap_type_nvgre_to_tlv(&tto->bgpinfo.nvgre, attr); |
114 | 0 | break; |
115 | | |
116 | 0 | case BGP_ENCAP_TYPE_MPLS: |
117 | | /* nothing to do for MPLS */ |
118 | 0 | break; |
119 | | |
120 | 0 | case BGP_ENCAP_TYPE_MPLS_IN_GRE: |
121 | 0 | _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS(mpls_gre); |
122 | 0 | bgp_encap_type_mpls_in_gre_to_tlv(&tto->bgpinfo.mpls_gre, attr); |
123 | 0 | break; |
124 | | |
125 | 0 | case BGP_ENCAP_TYPE_VXLAN_GPE: |
126 | 0 | _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS(vxlan_gpe); |
127 | 0 | bgp_encap_type_vxlan_gpe_to_tlv(&tto->bgpinfo.vxlan_gpe, attr); |
128 | 0 | break; |
129 | | |
130 | 0 | case BGP_ENCAP_TYPE_MPLS_IN_UDP: |
131 | 0 | _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS(mpls_udp); |
132 | 0 | bgp_encap_type_mpls_in_udp_to_tlv(&tto->bgpinfo.mpls_udp, attr); |
133 | 0 | break; |
134 | | |
135 | 0 | case BGP_ENCAP_TYPE_PBB: |
136 | 0 | _RTTO_MAYBE_ADD_ENDPOINT_ADDRESS(pbb); |
137 | 0 | bgp_encap_type_pbb_to_tlv(&tto->bgpinfo.pbb, attr); |
138 | 0 | break; |
139 | | |
140 | 0 | case BGP_ENCAP_TYPE_RESERVED: |
141 | 0 | assert(!"Cannot process BGP_ENCAP_TYPE_RESERVED"); |
142 | 0 | } |
143 | 0 | return tto->type; |
144 | 0 | } |
145 | | |
146 | | struct rfapi_un_option *rfapi_encap_tlv_to_un_option(struct attr *attr) |
147 | 0 | { |
148 | 0 | struct rfapi_un_option *uo = NULL; |
149 | 0 | struct rfapi_tunneltype_option *tto; |
150 | 0 | int rc; |
151 | 0 | struct bgp_attr_encap_subtlv *stlv; |
152 | | |
153 | | /* no tunnel encap attr stored */ |
154 | 0 | if (!attr->encap_tunneltype) |
155 | 0 | return NULL; |
156 | | |
157 | 0 | stlv = attr->encap_subtlvs; |
158 | |
|
159 | 0 | uo = XCALLOC(MTYPE_RFAPI_UN_OPTION, sizeof(struct rfapi_un_option)); |
160 | 0 | uo->type = RFAPI_UN_OPTION_TYPE_TUNNELTYPE; |
161 | 0 | uo->v.tunnel.type = attr->encap_tunneltype; |
162 | 0 | tto = &uo->v.tunnel; |
163 | |
|
164 | 0 | switch (attr->encap_tunneltype) { |
165 | 0 | case BGP_ENCAP_TYPE_L2TPV3_OVER_IP: |
166 | 0 | rc = tlv_to_bgp_encap_type_l2tpv3overip( |
167 | 0 | stlv, &tto->bgpinfo.l2tpv3_ip); |
168 | 0 | break; |
169 | | |
170 | 0 | case BGP_ENCAP_TYPE_GRE: |
171 | 0 | rc = tlv_to_bgp_encap_type_gre(stlv, &tto->bgpinfo.gre); |
172 | 0 | break; |
173 | | |
174 | 0 | case BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT: |
175 | 0 | rc = tlv_to_bgp_encap_type_transmit_tunnel_endpoint( |
176 | 0 | stlv, &tto->bgpinfo.transmit_tunnel_endpoint); |
177 | 0 | break; |
178 | | |
179 | 0 | case BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE: |
180 | 0 | rc = tlv_to_bgp_encap_type_ipsec_in_tunnel_mode( |
181 | 0 | stlv, &tto->bgpinfo.ipsec_tunnel); |
182 | 0 | break; |
183 | | |
184 | 0 | case BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE: |
185 | 0 | rc = tlv_to_bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode( |
186 | 0 | stlv, &tto->bgpinfo.ip_ipsec); |
187 | 0 | break; |
188 | | |
189 | 0 | case BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE: |
190 | 0 | rc = tlv_to_bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode( |
191 | 0 | stlv, &tto->bgpinfo.mpls_ipsec); |
192 | 0 | break; |
193 | | |
194 | 0 | case BGP_ENCAP_TYPE_IP_IN_IP: |
195 | 0 | rc = tlv_to_bgp_encap_type_ip_in_ip(stlv, &tto->bgpinfo.ip_ip); |
196 | 0 | break; |
197 | | |
198 | 0 | case BGP_ENCAP_TYPE_VXLAN: |
199 | 0 | rc = tlv_to_bgp_encap_type_vxlan(stlv, &tto->bgpinfo.vxlan); |
200 | 0 | break; |
201 | | |
202 | 0 | case BGP_ENCAP_TYPE_NVGRE: |
203 | 0 | rc = tlv_to_bgp_encap_type_nvgre(stlv, &tto->bgpinfo.nvgre); |
204 | 0 | break; |
205 | | |
206 | 0 | case BGP_ENCAP_TYPE_MPLS: |
207 | 0 | rc = tlv_to_bgp_encap_type_mpls(stlv, &tto->bgpinfo.mpls); |
208 | 0 | break; |
209 | | |
210 | 0 | case BGP_ENCAP_TYPE_MPLS_IN_GRE: |
211 | 0 | rc = tlv_to_bgp_encap_type_mpls_in_gre(stlv, |
212 | 0 | &tto->bgpinfo.mpls_gre); |
213 | 0 | break; |
214 | | |
215 | 0 | case BGP_ENCAP_TYPE_VXLAN_GPE: |
216 | 0 | rc = tlv_to_bgp_encap_type_vxlan_gpe(stlv, |
217 | 0 | &tto->bgpinfo.vxlan_gpe); |
218 | 0 | break; |
219 | | |
220 | 0 | case BGP_ENCAP_TYPE_MPLS_IN_UDP: |
221 | 0 | rc = tlv_to_bgp_encap_type_mpls_in_udp(stlv, |
222 | 0 | &tto->bgpinfo.mpls_udp); |
223 | 0 | break; |
224 | | |
225 | 0 | case BGP_ENCAP_TYPE_PBB: |
226 | 0 | rc = tlv_to_bgp_encap_type_pbb(stlv, &tto->bgpinfo.pbb); |
227 | 0 | break; |
228 | | |
229 | 0 | default: |
230 | 0 | vnc_zlog_debug_verbose("%s: unknown tunnel type %d", __func__, |
231 | 0 | attr->encap_tunneltype); |
232 | 0 | rc = -1; |
233 | 0 | break; |
234 | 0 | } |
235 | 0 | if (rc) { |
236 | 0 | XFREE(MTYPE_RFAPI_UN_OPTION, uo); |
237 | 0 | } |
238 | 0 | return uo; |
239 | 0 | } |
240 | | |
241 | | /*********************************************************************** |
242 | | * SUBTLV PRINT |
243 | | ***********************************************************************/ |
244 | | |
245 | | static void subtlv_print_encap_l2tpv3_over_ip( |
246 | | void *stream, int column_offset, |
247 | | struct bgp_tea_subtlv_encap_l2tpv3_over_ip *st) |
248 | 0 | { |
249 | 0 | int (*fp)(void *, const char *, ...); |
250 | 0 | struct vty *vty; |
251 | 0 | void *out; |
252 | 0 | const char *vty_newline; |
253 | |
|
254 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
255 | 0 | return; |
256 | 0 | if (!st) |
257 | 0 | return; |
258 | | |
259 | 0 | fp(out, "%*s%s%s", column_offset, "", "SubTLV: Encap(L2TPv3 over IP)", |
260 | 0 | vty_newline); |
261 | 0 | fp(out, "%*s SessionID: %d%s", column_offset, "", st->sessionid, |
262 | 0 | vty_newline); |
263 | 0 | fp(out, "%*s Cookie: (length %d)%s", column_offset, "", |
264 | 0 | st->cookie_length, vty_newline); |
265 | 0 | } |
266 | | |
267 | | static void subtlv_print_encap_gre(void *stream, int column_offset, |
268 | | struct bgp_tea_subtlv_encap_gre_key *st) |
269 | 0 | { |
270 | 0 | int (*fp)(void *, const char *, ...); |
271 | 0 | struct vty *vty; |
272 | 0 | void *out; |
273 | 0 | const char *vty_newline; |
274 | |
|
275 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
276 | 0 | return; |
277 | 0 | if (!st) |
278 | 0 | return; |
279 | | |
280 | 0 | fp(out, "%*s%s%s", column_offset, "", "SubTLV: Encap(GRE)", |
281 | 0 | vty_newline); |
282 | 0 | fp(out, "%*s GRE key: %d (0x%x)%s", column_offset, "", st->gre_key, |
283 | 0 | st->gre_key, vty_newline); |
284 | 0 | } |
285 | | |
286 | | static void subtlv_print_encap_pbb(void *stream, int column_offset, |
287 | | struct bgp_tea_subtlv_encap_pbb *st) |
288 | 0 | { |
289 | 0 | int (*fp)(void *, const char *, ...); |
290 | 0 | struct vty *vty; |
291 | 0 | void *out; |
292 | 0 | const char *vty_newline; |
293 | |
|
294 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
295 | 0 | return; |
296 | 0 | if (!st) |
297 | 0 | return; |
298 | | |
299 | 0 | fp(out, "%*s%s%s", column_offset, "", "SubTLV: Encap(PBB)", |
300 | 0 | vty_newline); |
301 | 0 | if (st->flag_isid) { |
302 | 0 | fp(out, "%*s ISID: %d (0x%x)%s", column_offset, "", st->isid, |
303 | 0 | st->isid, vty_newline); |
304 | 0 | } |
305 | 0 | if (st->flag_vid) { |
306 | 0 | fp(out, "%*s VID: %d (0x%x)%s", column_offset, "", st->vid, |
307 | 0 | st->vid, vty_newline); |
308 | 0 | } |
309 | 0 | fp(out, "%*s MACADDR %02x:%02x:%02x:%02x:%02x:%02x%s", column_offset, |
310 | 0 | "", st->macaddr[0], st->macaddr[1], st->macaddr[2], st->macaddr[3], |
311 | 0 | st->macaddr[4], st->macaddr[5], vty_newline); |
312 | 0 | } |
313 | | |
314 | | static void subtlv_print_proto_type(void *stream, int column_offset, |
315 | | struct bgp_tea_subtlv_proto_type *st) |
316 | 0 | { |
317 | 0 | int (*fp)(void *, const char *, ...); |
318 | 0 | struct vty *vty; |
319 | 0 | void *out; |
320 | 0 | const char *vty_newline; |
321 | |
|
322 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
323 | 0 | return; |
324 | 0 | if (!st) |
325 | 0 | return; |
326 | | |
327 | 0 | fp(out, "%*s%s%s", column_offset, "", "SubTLV: Encap(Proto Type)", |
328 | 0 | vty_newline); |
329 | 0 | fp(out, "%*s Proto %d (0x%x)%s", column_offset, "", st->proto, |
330 | 0 | st->proto, vty_newline); |
331 | 0 | } |
332 | | |
333 | | static void subtlv_print_color(void *stream, int column_offset, |
334 | | struct bgp_tea_subtlv_color *st) |
335 | 0 | { |
336 | 0 | int (*fp)(void *, const char *, ...); |
337 | 0 | struct vty *vty; |
338 | 0 | void *out; |
339 | 0 | const char *vty_newline; |
340 | |
|
341 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
342 | 0 | return; |
343 | 0 | if (!st) |
344 | 0 | return; |
345 | | |
346 | 0 | fp(out, "%*s%s%s", column_offset, "", "SubTLV: Color", vty_newline); |
347 | 0 | fp(out, "%*s Color: %d (0x%x)", column_offset, "", st->color, |
348 | 0 | st->color, vty_newline); |
349 | 0 | } |
350 | | |
351 | | static void subtlv_print_ipsec_ta(void *stream, int column_offset, |
352 | | struct bgp_tea_subtlv_ipsec_ta *st) |
353 | 0 | { |
354 | 0 | int (*fp)(void *, const char *, ...); |
355 | 0 | struct vty *vty; |
356 | 0 | void *out; |
357 | 0 | const char *vty_newline; |
358 | |
|
359 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
360 | 0 | return; |
361 | 0 | if (!st) |
362 | 0 | return; |
363 | | |
364 | 0 | fp(out, "%*s%s%s", column_offset, "", "SubTLV: IPSEC TA", vty_newline); |
365 | 0 | fp(out, "%*s Authenticator Type: %d (0x%x)", column_offset, "", |
366 | 0 | st->authenticator_type, st->authenticator_type, vty_newline); |
367 | 0 | fp(out, "%*s Authenticator: (length %d)", column_offset, "", |
368 | 0 | st->authenticator_length, vty_newline); |
369 | 0 | } |
370 | | |
371 | | /*********************************************************************** |
372 | | * TLV PRINT |
373 | | ***********************************************************************/ |
374 | | |
375 | | static void |
376 | | print_encap_type_l2tpv3overip(void *stream, int column_offset, |
377 | | struct bgp_encap_type_l2tpv3_over_ip *bet) |
378 | 0 | { |
379 | 0 | const char *type = "L2TPv3 over IP"; |
380 | 0 | int (*fp)(void *, const char *, ...); |
381 | 0 | struct vty *vty; |
382 | 0 | void *out; |
383 | 0 | const char *vty_newline; |
384 | |
|
385 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
386 | 0 | return; |
387 | 0 | if (!bet) |
388 | 0 | return; |
389 | | |
390 | 0 | fp(out, "%*sTEA type %s%s", column_offset, "", type, vty_newline); |
391 | |
|
392 | 0 | subtlv_print_encap_l2tpv3_over_ip(stream, column_offset + 2, |
393 | 0 | &bet->st_encap); |
394 | 0 | subtlv_print_proto_type(stream, column_offset + 2, &bet->st_proto); |
395 | 0 | subtlv_print_color(stream, column_offset + 2, &bet->st_color); |
396 | 0 | } |
397 | | |
398 | | static void print_encap_type_gre(void *stream, int column_offset, |
399 | | struct bgp_encap_type_gre *bet) |
400 | 0 | { |
401 | 0 | const char *type = "GRE"; |
402 | 0 | int (*fp)(void *, const char *, ...); |
403 | 0 | struct vty *vty; |
404 | 0 | void *out; |
405 | 0 | const char *vty_newline; |
406 | |
|
407 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
408 | 0 | return; |
409 | 0 | if (!bet) |
410 | 0 | return; |
411 | | |
412 | 0 | fp(out, "%*sTEA type %s%s", column_offset, "", type, vty_newline); |
413 | |
|
414 | 0 | subtlv_print_encap_gre(stream, column_offset + 2, &bet->st_encap); |
415 | 0 | subtlv_print_proto_type(stream, column_offset + 2, &bet->st_proto); |
416 | 0 | subtlv_print_color(stream, column_offset + 2, &bet->st_color); |
417 | 0 | } |
418 | | |
419 | | static void print_encap_type_ip_in_ip(void *stream, int column_offset, |
420 | | struct bgp_encap_type_ip_in_ip *bet) |
421 | 0 | { |
422 | 0 | const char *type = "IP in IP"; |
423 | 0 | int (*fp)(void *, const char *, ...); |
424 | 0 | struct vty *vty; |
425 | 0 | void *out; |
426 | 0 | const char *vty_newline; |
427 | |
|
428 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
429 | 0 | return; |
430 | 0 | if (!bet) |
431 | 0 | return; |
432 | | |
433 | 0 | fp(out, "%*sTEA type %s%s", column_offset, "", type, vty_newline); |
434 | |
|
435 | 0 | subtlv_print_proto_type(stream, column_offset + 2, &bet->st_proto); |
436 | 0 | subtlv_print_color(stream, column_offset + 2, &bet->st_color); |
437 | 0 | } |
438 | | |
439 | | static void print_encap_type_transmit_tunnel_endpoint( |
440 | | void *stream, int column_offset, |
441 | | struct bgp_encap_type_transmit_tunnel_endpoint *bet) |
442 | 0 | { |
443 | 0 | const char *type = "Transmit Tunnel Endpoint"; |
444 | 0 | int (*fp)(void *, const char *, ...); |
445 | 0 | struct vty *vty; |
446 | 0 | void *out; |
447 | 0 | const char *vty_newline; |
448 | |
|
449 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
450 | 0 | return; |
451 | 0 | if (!bet) |
452 | 0 | return; |
453 | | |
454 | 0 | fp(out, "%*sTEA type %s%s", column_offset, "", type, vty_newline); |
455 | | |
456 | | /* no subtlvs for this type */ |
457 | 0 | } |
458 | | |
459 | | static void print_encap_type_ipsec_in_tunnel_mode( |
460 | | void *stream, int column_offset, |
461 | | struct bgp_encap_type_ipsec_in_tunnel_mode *bet) |
462 | 0 | { |
463 | 0 | const char *type = "IPSEC in Tunnel mode"; |
464 | 0 | int (*fp)(void *, const char *, ...); |
465 | 0 | struct vty *vty; |
466 | 0 | void *out; |
467 | 0 | const char *vty_newline; |
468 | |
|
469 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
470 | 0 | return; |
471 | 0 | if (!bet) |
472 | 0 | return; |
473 | | |
474 | 0 | fp(out, "%*sTEA type %s%s", column_offset, "", type, vty_newline); |
475 | 0 | subtlv_print_ipsec_ta(stream, column_offset + 2, &bet->st_ipsec_ta); |
476 | 0 | } |
477 | | |
478 | | static void print_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode( |
479 | | void *stream, int column_offset, |
480 | | struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode *bet) |
481 | 0 | { |
482 | 0 | const char *type = "IP in IP Tunnel with IPSEC transport mode"; |
483 | 0 | int (*fp)(void *, const char *, ...); |
484 | 0 | struct vty *vty; |
485 | 0 | void *out; |
486 | 0 | const char *vty_newline; |
487 | |
|
488 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
489 | 0 | return; |
490 | 0 | if (!bet) |
491 | 0 | return; |
492 | | |
493 | 0 | fp(out, "%*sTEA type %s%s", column_offset, "", type, vty_newline); |
494 | |
|
495 | 0 | subtlv_print_ipsec_ta(stream, column_offset + 2, &bet->st_ipsec_ta); |
496 | 0 | } |
497 | | |
498 | | static void print_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode( |
499 | | void *stream, int column_offset, |
500 | | struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode *bet) |
501 | 0 | { |
502 | 0 | const char *type = "MPLS in IP Tunnel with IPSEC transport mode"; |
503 | 0 | int (*fp)(void *, const char *, ...); |
504 | 0 | struct vty *vty; |
505 | 0 | void *out; |
506 | 0 | const char *vty_newline; |
507 | |
|
508 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
509 | 0 | return; |
510 | 0 | if (!bet) |
511 | 0 | return; |
512 | | |
513 | 0 | fp(out, "%*sTEA type %s%s", column_offset, "", type, vty_newline); |
514 | |
|
515 | 0 | subtlv_print_ipsec_ta(stream, column_offset + 2, &bet->st_ipsec_ta); |
516 | 0 | } |
517 | | |
518 | | |
519 | | static void print_encap_type_pbb(void *stream, int column_offset, |
520 | | struct bgp_encap_type_pbb *bet) |
521 | 0 | { |
522 | 0 | const char *type = "PBB"; |
523 | 0 | int (*fp)(void *, const char *, ...); |
524 | 0 | struct vty *vty; |
525 | 0 | void *out; |
526 | 0 | const char *vty_newline; |
527 | |
|
528 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
529 | 0 | return; |
530 | 0 | if (!bet) |
531 | 0 | return; |
532 | | |
533 | 0 | fp(out, "%*sTEA type %s%s", column_offset, "", type, vty_newline); |
534 | |
|
535 | 0 | subtlv_print_encap_pbb(stream, column_offset + 2, &bet->st_encap); |
536 | 0 | } |
537 | | |
538 | | |
539 | | static void print_encap_type_vxlan(void *stream, int column_offset, |
540 | | struct bgp_encap_type_vxlan *bet) |
541 | 0 | { |
542 | 0 | const char *type = "VXLAN"; |
543 | 0 | int (*fp)(void *, const char *, ...); |
544 | 0 | struct vty *vty; |
545 | 0 | void *out; |
546 | 0 | const char *vty_newline; |
547 | |
|
548 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
549 | 0 | return; |
550 | 0 | if (!bet) |
551 | 0 | return; |
552 | | |
553 | 0 | fp(out, "%*sTEA type %s%s", column_offset, "", type, vty_newline); |
554 | | |
555 | | /* no subtlvs for this type */ |
556 | 0 | } |
557 | | |
558 | | |
559 | | static void print_encap_type_nvgre(void *stream, int column_offset, |
560 | | struct bgp_encap_type_nvgre *bet) |
561 | 0 | { |
562 | 0 | const char *type = "NVGRE"; |
563 | 0 | int (*fp)(void *, const char *, ...); |
564 | 0 | struct vty *vty; |
565 | 0 | void *out; |
566 | 0 | const char *vty_newline; |
567 | |
|
568 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
569 | 0 | return; |
570 | 0 | if (!bet) |
571 | 0 | return; |
572 | | |
573 | 0 | fp(out, "%*sTEA type %s%s", column_offset, "", type, vty_newline); |
574 | | |
575 | | /* no subtlvs for this type */ |
576 | 0 | } |
577 | | |
578 | | static void print_encap_type_mpls(void *stream, int column_offset, |
579 | | struct bgp_encap_type_mpls *bet) |
580 | 0 | { |
581 | 0 | const char *type = "MPLS"; |
582 | 0 | int (*fp)(void *, const char *, ...); |
583 | 0 | struct vty *vty; |
584 | 0 | void *out; |
585 | 0 | const char *vty_newline; |
586 | |
|
587 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
588 | 0 | return; |
589 | 0 | if (!bet) |
590 | 0 | return; |
591 | | |
592 | 0 | fp(out, "%*sTEA type %s%s", column_offset, "", type, vty_newline); |
593 | | |
594 | | /* no subtlvs for this type */ |
595 | 0 | } |
596 | | |
597 | | static void print_encap_type_mpls_in_gre(void *stream, int column_offset, |
598 | | struct bgp_encap_type_mpls_in_gre *bet) |
599 | 0 | { |
600 | 0 | const char *type = "MPLS in GRE"; |
601 | 0 | int (*fp)(void *, const char *, ...); |
602 | 0 | struct vty *vty; |
603 | 0 | void *out; |
604 | 0 | const char *vty_newline; |
605 | |
|
606 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
607 | 0 | return; |
608 | 0 | if (!bet) |
609 | 0 | return; |
610 | | |
611 | 0 | fp(out, "%*sTEA type %s%s", column_offset, "", type, vty_newline); |
612 | | |
613 | | /* no subtlvs for this type */ |
614 | 0 | } |
615 | | |
616 | | static void print_encap_type_vxlan_gpe(void *stream, int column_offset, |
617 | | struct bgp_encap_type_vxlan_gpe *bet) |
618 | 0 | { |
619 | 0 | const char *type = "VXLAN GPE"; |
620 | 0 | int (*fp)(void *, const char *, ...); |
621 | 0 | struct vty *vty; |
622 | 0 | void *out; |
623 | 0 | const char *vty_newline; |
624 | |
|
625 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
626 | 0 | return; |
627 | 0 | if (!bet) |
628 | 0 | return; |
629 | | |
630 | 0 | fp(out, "%*sTEA type %s%s", column_offset, "", type, vty_newline); |
631 | | |
632 | | /* no subtlvs for this type */ |
633 | 0 | } |
634 | | |
635 | | static void print_encap_type_mpls_in_udp(void *stream, int column_offset, |
636 | | struct bgp_encap_type_mpls_in_udp *bet) |
637 | 0 | { |
638 | 0 | const char *type = "MPLS in UDP"; |
639 | 0 | int (*fp)(void *, const char *, ...); |
640 | 0 | struct vty *vty; |
641 | 0 | void *out; |
642 | 0 | const char *vty_newline; |
643 | |
|
644 | 0 | if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) |
645 | 0 | return; |
646 | 0 | if (!bet) |
647 | 0 | return; |
648 | | |
649 | 0 | fp(out, "%*sTEA type %s%s", column_offset, "", type, vty_newline); |
650 | | |
651 | | /* no subtlvs for this type */ |
652 | 0 | } |
653 | | |
654 | | void rfapi_print_tunneltype_option(void *stream, int column_offset, |
655 | | struct rfapi_tunneltype_option *tto) |
656 | 0 | { |
657 | 0 | switch (tto->type) { |
658 | 0 | case BGP_ENCAP_TYPE_L2TPV3_OVER_IP: |
659 | 0 | print_encap_type_l2tpv3overip(stream, column_offset, |
660 | 0 | &tto->bgpinfo.l2tpv3_ip); |
661 | 0 | break; |
662 | | |
663 | 0 | case BGP_ENCAP_TYPE_GRE: |
664 | 0 | print_encap_type_gre(stream, column_offset, &tto->bgpinfo.gre); |
665 | 0 | break; |
666 | | |
667 | 0 | case BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT: |
668 | 0 | print_encap_type_transmit_tunnel_endpoint( |
669 | 0 | stream, column_offset, |
670 | 0 | &tto->bgpinfo.transmit_tunnel_endpoint); |
671 | 0 | break; |
672 | | |
673 | 0 | case BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE: |
674 | 0 | print_encap_type_ipsec_in_tunnel_mode( |
675 | 0 | stream, column_offset, &tto->bgpinfo.ipsec_tunnel); |
676 | 0 | break; |
677 | | |
678 | 0 | case BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE: |
679 | 0 | print_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode( |
680 | 0 | stream, column_offset, &tto->bgpinfo.ip_ipsec); |
681 | 0 | break; |
682 | | |
683 | 0 | case BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE: |
684 | 0 | print_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode( |
685 | 0 | stream, column_offset, &tto->bgpinfo.mpls_ipsec); |
686 | 0 | break; |
687 | | |
688 | 0 | case BGP_ENCAP_TYPE_IP_IN_IP: |
689 | 0 | print_encap_type_ip_in_ip(stream, column_offset, |
690 | 0 | &tto->bgpinfo.ip_ip); |
691 | 0 | break; |
692 | | |
693 | 0 | case BGP_ENCAP_TYPE_VXLAN: |
694 | 0 | print_encap_type_vxlan(stream, column_offset, |
695 | 0 | &tto->bgpinfo.vxlan); |
696 | 0 | break; |
697 | | |
698 | 0 | case BGP_ENCAP_TYPE_NVGRE: |
699 | 0 | print_encap_type_nvgre(stream, column_offset, |
700 | 0 | &tto->bgpinfo.nvgre); |
701 | 0 | break; |
702 | | |
703 | 0 | case BGP_ENCAP_TYPE_MPLS: |
704 | 0 | print_encap_type_mpls(stream, column_offset, |
705 | 0 | &tto->bgpinfo.mpls); |
706 | 0 | break; |
707 | | |
708 | 0 | case BGP_ENCAP_TYPE_MPLS_IN_GRE: |
709 | 0 | print_encap_type_mpls_in_gre(stream, column_offset, |
710 | 0 | &tto->bgpinfo.mpls_gre); |
711 | 0 | break; |
712 | | |
713 | 0 | case BGP_ENCAP_TYPE_VXLAN_GPE: |
714 | 0 | print_encap_type_vxlan_gpe(stream, column_offset, |
715 | 0 | &tto->bgpinfo.vxlan_gpe); |
716 | 0 | break; |
717 | | |
718 | 0 | case BGP_ENCAP_TYPE_MPLS_IN_UDP: |
719 | 0 | print_encap_type_mpls_in_udp(stream, column_offset, |
720 | 0 | &tto->bgpinfo.mpls_udp); |
721 | 0 | break; |
722 | | |
723 | 0 | case BGP_ENCAP_TYPE_PBB: |
724 | 0 | print_encap_type_pbb(stream, column_offset, &tto->bgpinfo.pbb); |
725 | 0 | break; |
726 | | |
727 | 0 | case BGP_ENCAP_TYPE_RESERVED: |
728 | | assert(!"Cannot process BGP_ENCAP_TYPE_RESERVED"); |
729 | 0 | } |
730 | 0 | } |