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