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