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