1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2015, LabN Consulting, L.L.C.
17 #include "bgp_encap_types.h"
18 #include "bgp_encap_tlv.h"
20 /***********************************************************************
22 ***********************************************************************/
25 static struct bgp_attr_encap_subtlv
*subtlv_encode_encap_l2tpv3_over_ip(
26 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
28 struct bgp_attr_encap_subtlv
*new;
30 int total
= 4 + st
->cookie_length
;
33 assert(st
->cookie_length
<= sizeof(st
->cookie
));
34 assert(total
<= 0xff);
36 new = XCALLOC(MTYPE_ENCAP_TLV
,
37 sizeof(struct bgp_attr_encap_subtlv
) + total
);
39 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
43 *p
++ = (st
->sessionid
& 0xff000000) >> 24;
44 *p
++ = (st
->sessionid
& 0xff0000) >> 16;
45 *p
++ = (st
->sessionid
& 0xff00) >> 8;
46 *p
++ = (st
->sessionid
& 0xff);
47 memcpy(p
, st
->cookie
, st
->cookie_length
);
52 static struct bgp_attr_encap_subtlv
*
53 subtlv_encode_encap_gre(struct bgp_tea_subtlv_encap_gre_key
*st
)
55 struct bgp_attr_encap_subtlv
*new;
59 assert(total
<= 0xff);
61 new = XCALLOC(MTYPE_ENCAP_TLV
,
62 sizeof(struct bgp_attr_encap_subtlv
) + total
);
64 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
68 *p
++ = (st
->gre_key
& 0xff000000) >> 24;
69 *p
++ = (st
->gre_key
& 0xff0000) >> 16;
70 *p
++ = (st
->gre_key
& 0xff00) >> 8;
71 *p
++ = (st
->gre_key
& 0xff);
75 static struct bgp_attr_encap_subtlv
*
76 subtlv_encode_encap_pbb(struct bgp_tea_subtlv_encap_pbb
*st
)
78 struct bgp_attr_encap_subtlv
*new;
80 int total
= 1 + 3 + 6 + 2; /* flags + isid + madaddr + vid */
82 assert(total
<= 0xff);
84 new = XCALLOC(MTYPE_ENCAP_TLV
,
85 sizeof(struct bgp_attr_encap_subtlv
) + total
);
87 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
91 *p
++ = (st
->flag_isid
? 0x80 : 0) | (st
->flag_vid
? 0x40 : 0) | 0;
93 *p
= (st
->isid
& 0xff0000) >> 16;
94 *(p
+ 1) = (st
->isid
& 0xff00) >> 8;
95 *(p
+ 2) = (st
->isid
& 0xff);
98 memcpy(p
, st
->macaddr
, 6);
101 *p
++ = (st
->vid
& 0xf00) >> 8;
102 *p
++ = st
->vid
& 0xff;
108 static struct bgp_attr_encap_subtlv
*
109 subtlv_encode_proto_type(struct bgp_tea_subtlv_proto_type
*st
)
111 struct bgp_attr_encap_subtlv
*new;
115 assert(total
<= 0xff);
117 new = XCALLOC(MTYPE_ENCAP_TLV
,
118 sizeof(struct bgp_attr_encap_subtlv
) + total
);
120 new->type
= BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
;
124 *p
++ = (st
->proto
& 0xff00) >> 8;
125 *p
++ = (st
->proto
& 0xff);
130 static struct bgp_attr_encap_subtlv
*
131 subtlv_encode_color(struct bgp_tea_subtlv_color
*st
)
133 struct bgp_attr_encap_subtlv
*new;
137 assert(total
<= 0xff);
139 new = XCALLOC(MTYPE_ENCAP_TLV
,
140 sizeof(struct bgp_attr_encap_subtlv
) + total
);
142 new->type
= BGP_ENCAP_SUBTLV_TYPE_COLOR
;
146 *p
++ = 0x03; /* transitive*/
148 *p
++ = 0; /* reserved */
149 *p
++ = 0; /* reserved */
151 *p
++ = (st
->color
& 0xff000000) >> 24;
152 *p
++ = (st
->color
& 0xff0000) >> 16;
153 *p
++ = (st
->color
& 0xff00) >> 8;
154 *p
++ = (st
->color
& 0xff);
160 static struct bgp_attr_encap_subtlv
*
161 subtlv_encode_ipsec_ta(struct bgp_tea_subtlv_ipsec_ta
*st
)
163 struct bgp_attr_encap_subtlv
*new;
165 int total
= 2 + st
->authenticator_length
;
168 assert(st
->authenticator_length
<= sizeof(st
->value
));
169 assert(total
<= 0xff);
171 new = XCALLOC(MTYPE_ENCAP_TLV
,
172 sizeof(struct bgp_attr_encap_subtlv
) + total
);
174 new->type
= BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
;
178 *p
++ = (st
->authenticator_type
& 0xff00) >> 8;
179 *p
++ = st
->authenticator_type
& 0xff;
180 memcpy(p
, st
->value
, st
->authenticator_length
);
184 /* draft-rosen-idr-tunnel-encaps 2.1 */
185 static struct bgp_attr_encap_subtlv
*
186 subtlv_encode_remote_endpoint(struct bgp_tea_subtlv_remote_endpoint
*st
)
188 struct bgp_attr_encap_subtlv
*new;
191 int total
= (st
->family
== AF_INET
? 8 : 20);
193 assert(total
<= 0xff);
195 new = XCALLOC(MTYPE_ENCAP_TLV
,
196 sizeof(struct bgp_attr_encap_subtlv
) + total
);
198 new->type
= BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
;
201 if (st
->family
== AF_INET
) {
202 memcpy(p
, &(st
->ip_address
.v4
.s_addr
), IPV4_MAX_BYTELEN
);
203 p
+= IPV4_MAX_BYTELEN
;
205 assert(st
->family
== AF_INET6
);
206 memcpy(p
, &(st
->ip_address
.v6
.s6_addr
), IPV6_MAX_BYTELEN
);
207 p
+= IPV6_MAX_BYTELEN
;
209 memcpy(p
, &(st
->as4
), 4);
213 /***********************************************************************
214 * TUNNEL TYPE-SPECIFIC TLV ENCODE
215 ***********************************************************************/
218 * requires "extra" and "last" to be defined in caller
220 #define ENC_SUBTLV(flag, function, field) \
222 struct bgp_attr_encap_subtlv *new; \
223 if (CHECK_FLAG(bet->valid_subtlvs, (flag))) { \
224 new = function(&bet->field); \
228 attr->encap_subtlvs = new; \
234 void bgp_encap_type_l2tpv3overip_to_tlv(
235 struct bgp_encap_type_l2tpv3_over_ip
*bet
, /* input structure */
238 struct bgp_attr_encap_subtlv
*last
;
240 /* advance to last subtlv */
241 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
244 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_L2TPV3_OVER_IP
;
246 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
248 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_l2tpv3_over_ip
,
250 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
,
252 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
253 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
,
254 subtlv_encode_remote_endpoint
, st_endpoint
);
257 void bgp_encap_type_gre_to_tlv(
258 struct bgp_encap_type_gre
*bet
, /* input structure */
261 struct bgp_attr_encap_subtlv
*last
;
263 /* advance to last subtlv */
264 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
267 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_GRE
;
269 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_gre
, st_encap
);
270 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
,
272 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
273 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
,
274 subtlv_encode_remote_endpoint
, st_endpoint
);
277 void bgp_encap_type_ip_in_ip_to_tlv(
278 struct bgp_encap_type_ip_in_ip
*bet
, /* input structure */
281 struct bgp_attr_encap_subtlv
*last
;
283 /* advance to last subtlv */
284 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
287 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_IP_IN_IP
;
289 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
,
291 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
292 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
,
293 subtlv_encode_remote_endpoint
, st_endpoint
);
296 void bgp_encap_type_transmit_tunnel_endpoint(
297 struct bgp_encap_type_transmit_tunnel_endpoint
298 *bet
, /* input structure */
301 struct bgp_attr_encap_subtlv
*last
;
303 /* advance to last subtlv */
304 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
307 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT
;
309 /* no subtlvs for this type */
312 void bgp_encap_type_ipsec_in_tunnel_mode_to_tlv(
313 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
, /* input structure */
316 struct bgp_attr_encap_subtlv
*last
;
318 /* advance to last subtlv */
319 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
322 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE
;
324 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
,
328 void bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
329 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
330 *bet
, /* input structure */
333 struct bgp_attr_encap_subtlv
*last
;
335 /* advance to last subtlv */
336 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
339 attr
->encap_tunneltype
=
340 BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
342 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
,
346 void bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
347 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
348 *bet
, /* input structure */
351 struct bgp_attr_encap_subtlv
*last
;
353 /* advance to last subtlv */
354 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
357 attr
->encap_tunneltype
=
358 BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
360 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
,
364 void bgp_encap_type_pbb_to_tlv(
365 struct bgp_encap_type_pbb
*bet
, /* input structure */
368 struct bgp_attr_encap_subtlv
*last
;
370 /* advance to last subtlv */
371 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
374 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_PBB
;
376 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
377 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_pbb
, st_encap
);
380 void bgp_encap_type_vxlan_to_tlv(
381 struct bgp_encap_type_vxlan
*bet
, /* input structure */
384 struct bgp_attr_encap_subtlv
*tlv
;
387 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN
;
389 if (bet
== NULL
|| !bet
->vnid
)
391 XFREE(MTYPE_ENCAP_TLV
, attr
->encap_subtlvs
);
392 tlv
= XCALLOC(MTYPE_ENCAP_TLV
,
393 sizeof(struct bgp_attr_encap_subtlv
) + 12);
394 tlv
->type
= 1; /* encapsulation type */
397 vnid
= htonl(bet
->vnid
| VXLAN_ENCAP_MASK_VNID_VALID
);
398 memcpy(&tlv
->value
, &vnid
, 4);
400 if (bet
->mac_address
) {
401 char *ptr
= (char *)&tlv
->value
+ 4;
402 memcpy(ptr
, bet
->mac_address
, 6);
404 attr
->encap_subtlvs
= tlv
;
408 void bgp_encap_type_nvgre_to_tlv(
409 struct bgp_encap_type_nvgre
*bet
, /* input structure */
412 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_NVGRE
;
415 void bgp_encap_type_mpls_to_tlv(
416 struct bgp_encap_type_mpls
*bet
, /* input structure */
419 return; /* no encap attribute for MPLS */
422 void bgp_encap_type_mpls_in_gre_to_tlv(
423 struct bgp_encap_type_mpls_in_gre
*bet
, /* input structure */
426 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_GRE
;
429 void bgp_encap_type_vxlan_gpe_to_tlv(
430 struct bgp_encap_type_vxlan_gpe
*bet
, /* input structure */
434 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN_GPE
;
437 void bgp_encap_type_mpls_in_udp_to_tlv(
438 struct bgp_encap_type_mpls_in_udp
*bet
, /* input structure */
442 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_UDP
;
446 /***********************************************************************
448 ***********************************************************************/
450 static int subtlv_decode_encap_l2tpv3_over_ip(
451 struct bgp_attr_encap_subtlv
*subtlv
,
452 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
454 if (subtlv
->length
< 4) {
455 zlog_debug("%s, subtlv length %d is less than 4", __func__
,
460 ptr_get_be32(subtlv
->value
, &st
->sessionid
);
461 st
->cookie_length
= subtlv
->length
- 4;
462 if (st
->cookie_length
> sizeof(st
->cookie
)) {
463 zlog_debug("%s, subtlv length %d is greater than %d", __func__
,
464 st
->cookie_length
, (int)sizeof(st
->cookie
));
467 memcpy(st
->cookie
, subtlv
->value
+ 4, st
->cookie_length
);
472 static int subtlv_decode_encap_gre(struct bgp_attr_encap_subtlv
*subtlv
,
473 struct bgp_tea_subtlv_encap_gre_key
*st
)
475 if (subtlv
->length
!= 4) {
476 zlog_debug("%s, subtlv length %d does not equal 4", __func__
,
480 ptr_get_be32(subtlv
->value
, &st
->gre_key
);
484 static int subtlv_decode_encap_pbb(struct bgp_attr_encap_subtlv
*subtlv
,
485 struct bgp_tea_subtlv_encap_pbb
*st
)
487 if (subtlv
->length
!= 1 + 3 + 6 + 2) {
488 zlog_debug("%s, subtlv length %d does not equal %d", __func__
,
489 subtlv
->length
, 1 + 3 + 6 + 2);
492 if (subtlv
->value
[0] & 0x80) {
494 st
->isid
= (subtlv
->value
[1] << 16) | (subtlv
->value
[2] << 8)
497 if (subtlv
->value
[0] & 0x40) {
499 st
->vid
= ((subtlv
->value
[10] & 0x0f) << 8) | subtlv
->value
[11];
501 memcpy(st
->macaddr
, subtlv
->value
+ 4, 6);
506 static int subtlv_decode_proto_type(struct bgp_attr_encap_subtlv
*subtlv
,
507 struct bgp_tea_subtlv_proto_type
*st
)
509 if (subtlv
->length
!= 2) {
510 zlog_debug("%s, subtlv length %d does not equal 2", __func__
,
514 st
->proto
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
519 static int subtlv_decode_color(struct bgp_attr_encap_subtlv
*subtlv
,
520 struct bgp_tea_subtlv_color
*st
)
522 if (subtlv
->length
!= 8) {
523 zlog_debug("%s, subtlv length %d does not equal 8", __func__
,
527 if ((subtlv
->value
[0] != 0x03) || (subtlv
->value
[1] != 0x0b)
528 || (subtlv
->value
[2] != 0) || (subtlv
->value
[3] != 0)) {
529 zlog_debug("%s, subtlv value 1st 4 bytes are not 0x030b0000",
533 ptr_get_be32(subtlv
->value
+ 4, &st
->color
);
538 static int subtlv_decode_ipsec_ta(struct bgp_attr_encap_subtlv
*subtlv
,
539 struct bgp_tea_subtlv_ipsec_ta
*st
)
541 st
->authenticator_length
= subtlv
->length
- 2;
542 if (st
->authenticator_length
> sizeof(st
->value
)) {
544 "%s, authenticator length %d exceeds storage maximum %d",
545 __func__
, st
->authenticator_length
,
546 (int)sizeof(st
->value
));
549 st
->authenticator_type
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
550 memcpy(st
->value
, subtlv
->value
+ 2, st
->authenticator_length
);
554 /* draft-rosen-idr-tunnel-encaps 2.1 */
556 subtlv_decode_remote_endpoint(struct bgp_attr_encap_subtlv
*subtlv
,
557 struct bgp_tea_subtlv_remote_endpoint
*st
)
560 if (subtlv
->length
!= 8 && subtlv
->length
!= 20) {
561 zlog_debug("%s, subtlv length %d does not equal 8 or 20",
562 __func__
, subtlv
->length
);
565 if (subtlv
->length
== 8) {
566 st
->family
= AF_INET
;
567 memcpy(&st
->ip_address
.v4
.s_addr
, subtlv
->value
,
570 st
->family
= AF_INET6
;
571 memcpy(&(st
->ip_address
.v6
.s6_addr
), subtlv
->value
,
574 i
= subtlv
->length
- 4;
575 ptr_get_be32(subtlv
->value
+ i
, &st
->as4
);
579 /***********************************************************************
580 * TUNNEL TYPE-SPECIFIC TLV DECODE
581 ***********************************************************************/
583 int tlv_to_bgp_encap_type_l2tpv3overip(
584 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
585 struct bgp_encap_type_l2tpv3_over_ip
*bet
) /* caller-allocated */
587 struct bgp_attr_encap_subtlv
*st
;
590 for (st
= stlv
; st
; st
= st
->next
) {
592 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
593 rc
|= subtlv_decode_encap_l2tpv3_over_ip(
595 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
598 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
599 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
600 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
603 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
604 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
605 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
608 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
609 rc
|= subtlv_decode_remote_endpoint(st
,
611 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
615 zlog_debug("%s: unexpected subtlv type %d", __func__
,
624 int tlv_to_bgp_encap_type_gre(
625 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
626 struct bgp_encap_type_gre
*bet
) /* caller-allocated */
628 struct bgp_attr_encap_subtlv
*st
;
631 for (st
= stlv
; st
; st
= st
->next
) {
633 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
634 rc
|= subtlv_decode_encap_gre(st
, &bet
->st_encap
);
635 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
638 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
639 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
640 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
643 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
644 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
645 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
648 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
649 rc
|= subtlv_decode_remote_endpoint(st
,
651 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
655 zlog_debug("%s: unexpected subtlv type %d", __func__
,
664 int tlv_to_bgp_encap_type_ip_in_ip(
665 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
666 struct bgp_encap_type_ip_in_ip
*bet
) /* caller-allocated */
668 struct bgp_attr_encap_subtlv
*st
;
671 for (st
= stlv
; st
; st
= st
->next
) {
673 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
674 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
675 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
678 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
679 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
680 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
683 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
684 rc
|= subtlv_decode_remote_endpoint(st
,
686 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
690 zlog_debug("%s: unexpected subtlv type %d", __func__
,
699 int tlv_to_bgp_encap_type_transmit_tunnel_endpoint(
700 struct bgp_attr_encap_subtlv
*stlv
,
701 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
)
703 struct bgp_attr_encap_subtlv
*st
;
706 for (st
= stlv
; st
; st
= st
->next
) {
709 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
710 rc
|= subtlv_decode_remote_endpoint(st
,
712 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
716 zlog_debug("%s: unexpected subtlv type %d", __func__
,
725 int tlv_to_bgp_encap_type_ipsec_in_tunnel_mode(
726 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
727 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
) /* caller-allocated */
729 struct bgp_attr_encap_subtlv
*st
;
732 for (st
= stlv
; st
; st
= st
->next
) {
734 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
735 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
736 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
739 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
740 rc
|= subtlv_decode_remote_endpoint(st
,
742 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
746 zlog_debug("%s: unexpected subtlv type %d", __func__
,
755 int tlv_to_bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode(
756 struct bgp_attr_encap_subtlv
*stlv
,
757 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
759 struct bgp_attr_encap_subtlv
*st
;
762 for (st
= stlv
; st
; st
= st
->next
) {
764 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
765 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
766 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
769 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
770 rc
|= subtlv_decode_remote_endpoint(st
,
772 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
776 zlog_debug("%s: unexpected subtlv type %d", __func__
,
785 int tlv_to_bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode(
786 struct bgp_attr_encap_subtlv
*stlv
,
787 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
789 struct bgp_attr_encap_subtlv
*st
;
792 for (st
= stlv
; st
; st
= st
->next
) {
794 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
795 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
796 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
799 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
800 rc
|= subtlv_decode_remote_endpoint(st
,
802 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
806 zlog_debug("%s: unexpected subtlv type %d", __func__
,
815 int tlv_to_bgp_encap_type_vxlan(struct bgp_attr_encap_subtlv
*stlv
,
816 struct bgp_encap_type_vxlan
*bet
)
818 struct bgp_attr_encap_subtlv
*st
;
821 for (st
= stlv
; st
; st
= st
->next
) {
824 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
825 rc
|= subtlv_decode_remote_endpoint(st
,
827 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
831 zlog_debug("%s: unexpected subtlv type %d", __func__
,
840 int tlv_to_bgp_encap_type_nvgre(struct bgp_attr_encap_subtlv
*stlv
,
841 struct bgp_encap_type_nvgre
*bet
)
843 struct bgp_attr_encap_subtlv
*st
;
846 for (st
= stlv
; st
; st
= st
->next
) {
849 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
850 rc
|= subtlv_decode_remote_endpoint(st
,
852 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
856 zlog_debug("%s: unexpected subtlv type %d", __func__
,
865 int tlv_to_bgp_encap_type_mpls(struct bgp_attr_encap_subtlv
*stlv
,
866 struct bgp_encap_type_mpls
*bet
)
868 struct bgp_attr_encap_subtlv
*st
;
871 for (st
= stlv
; st
; st
= st
->next
) {
874 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
875 rc
|= subtlv_decode_remote_endpoint(st
,
877 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
881 zlog_debug("%s: unexpected subtlv type %d", __func__
,
890 int tlv_to_bgp_encap_type_mpls_in_gre(struct bgp_attr_encap_subtlv
*stlv
,
891 struct bgp_encap_type_mpls_in_gre
*bet
)
893 struct bgp_attr_encap_subtlv
*st
;
896 for (st
= stlv
; st
; st
= st
->next
) {
899 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
900 rc
|= subtlv_decode_remote_endpoint(st
,
902 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
906 zlog_debug("%s: unexpected subtlv type %d", __func__
,
915 int tlv_to_bgp_encap_type_vxlan_gpe(struct bgp_attr_encap_subtlv
*stlv
,
916 struct bgp_encap_type_vxlan_gpe
*bet
)
918 struct bgp_attr_encap_subtlv
*st
;
921 for (st
= stlv
; st
; st
= st
->next
) {
924 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
925 rc
|= subtlv_decode_remote_endpoint(st
,
927 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
931 zlog_debug("%s: unexpected subtlv type %d", __func__
,
940 int tlv_to_bgp_encap_type_mpls_in_udp(struct bgp_attr_encap_subtlv
*stlv
,
941 struct bgp_encap_type_mpls_in_udp
*bet
)
943 struct bgp_attr_encap_subtlv
*st
;
946 for (st
= stlv
; st
; st
= st
->next
) {
949 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
950 rc
|= subtlv_decode_remote_endpoint(st
,
952 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
956 zlog_debug("%s: unexpected subtlv type %d", __func__
,
965 int tlv_to_bgp_encap_type_pbb(
966 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
967 struct bgp_encap_type_pbb
*bet
) /* caller-allocated */
969 struct bgp_attr_encap_subtlv
*st
;
972 for (st
= stlv
; st
; st
= st
->next
) {
974 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
975 rc
|= subtlv_decode_encap_pbb(st
, &bet
->st_encap
);
976 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
979 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
980 rc
|= subtlv_decode_remote_endpoint(st
,
982 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
986 zlog_debug("%s: unexpected subtlv type %d", __func__
,