2 * Copyright 2015, LabN Consulting, L.L.C.
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.
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.
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
29 #include "bgp_encap_types.h"
30 #include "bgp_encap_tlv.h"
32 /***********************************************************************
34 ***********************************************************************/
37 static struct bgp_attr_encap_subtlv
*
38 subtlv_encode_encap_l2tpv3_over_ip(
39 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
41 struct bgp_attr_encap_subtlv
*new;
43 int total
= 4 + st
->cookie_length
;
46 assert(st
->cookie_length
<= sizeof(st
->cookie
));
47 assert(total
<= 0xff);
49 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
51 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
55 *p
++ = (st
->sessionid
& 0xff000000) >> 24;
56 *p
++ = (st
->sessionid
& 0xff0000) >> 16;
57 *p
++ = (st
->sessionid
& 0xff00) >> 8;
58 *p
++ = (st
->sessionid
& 0xff);
59 memcpy(p
, st
->cookie
, st
->cookie_length
);
64 static struct bgp_attr_encap_subtlv
*
65 subtlv_encode_encap_gre(
66 struct bgp_tea_subtlv_encap_gre_key
*st
)
68 struct bgp_attr_encap_subtlv
*new;
72 assert(total
<= 0xff);
74 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
76 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
80 *p
++ = (st
->gre_key
& 0xff000000) >> 24;
81 *p
++ = (st
->gre_key
& 0xff0000) >> 16;
82 *p
++ = (st
->gre_key
& 0xff00) >> 8;
83 *p
++ = (st
->gre_key
& 0xff);
87 static struct bgp_attr_encap_subtlv
*
88 subtlv_encode_encap_pbb(
89 struct bgp_tea_subtlv_encap_pbb
*st
)
91 struct bgp_attr_encap_subtlv
*new;
93 int total
= 1 + 3 + 6 + 2; /* flags + isid + madaddr + vid */
95 assert(total
<= 0xff);
97 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
99 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
103 *p
++ = (st
->flag_isid
? 0x80: 0) |
104 (st
->flag_vid
? 0x40: 0) |
107 *p
= (st
->isid
& 0xff0000) >> 16;
108 *(p
+1) = (st
->isid
& 0xff00) >> 8;
109 *(p
+2) = (st
->isid
& 0xff);
112 memcpy(p
, st
->macaddr
, 6);
115 *p
++ = (st
->vid
& 0xf00) >> 8;
116 *p
++ = st
->vid
& 0xff;
122 static struct bgp_attr_encap_subtlv
*
123 subtlv_encode_proto_type(
124 struct bgp_tea_subtlv_proto_type
*st
)
126 struct bgp_attr_encap_subtlv
*new;
130 assert(total
<= 0xff);
132 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
134 new->type
= BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
;
138 *p
++ = (st
->proto
& 0xff00) >> 8;
139 *p
++ = (st
->proto
& 0xff);
144 static struct bgp_attr_encap_subtlv
*
146 struct bgp_tea_subtlv_color
*st
)
148 struct bgp_attr_encap_subtlv
*new;
152 assert(total
<= 0xff);
154 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
156 new->type
= BGP_ENCAP_SUBTLV_TYPE_COLOR
;
160 *p
++ = 0x03; /* transitive*/
162 *p
++ = 0; /* reserved */
163 *p
++ = 0; /* reserved */
165 *p
++ = (st
->color
& 0xff000000) >> 24;
166 *p
++ = (st
->color
& 0xff0000) >> 16;
167 *p
++ = (st
->color
& 0xff00) >> 8;
168 *p
++ = (st
->color
& 0xff);
174 static struct bgp_attr_encap_subtlv
*
175 subtlv_encode_ipsec_ta(
176 struct bgp_tea_subtlv_ipsec_ta
*st
)
178 struct bgp_attr_encap_subtlv
*new;
180 int total
= 2 + st
->authenticator_length
;
183 assert(st
->authenticator_length
<= sizeof(st
->value
));
184 assert(total
<= 0xff);
186 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
188 new->type
= BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
;
192 *p
++ = (st
->authenticator_type
& 0xff00) >> 8;
193 *p
++ = st
->authenticator_type
& 0xff;
194 memcpy(p
, st
->value
, st
->authenticator_length
);
198 /* draft-rosen-idr-tunnel-encaps 2.1 */
199 static struct bgp_attr_encap_subtlv
*
200 subtlv_encode_remote_endpoint(
201 struct bgp_tea_subtlv_remote_endpoint
*st
)
203 struct bgp_attr_encap_subtlv
*new;
206 int total
= (st
->family
==AF_INET
?8:20);
208 assert(total
<= 0xff);
210 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
212 new->type
= BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
;
215 if (st
->family
== AF_INET
) {
216 memcpy (p
, &(st
->ip_address
.v4
.s_addr
), 4);
219 assert (st
->family
== AF_INET6
);
220 memcpy (p
, &(st
->ip_address
.v6
.s6_addr
), 16);
223 memcpy (p
, &(st
->as4
), 4);
227 /***********************************************************************
228 * TUNNEL TYPE-SPECIFIC TLV ENCODE
229 ***********************************************************************/
232 * requires "extra" and "last" to be defined in caller
234 #define ENC_SUBTLV(flag, function, field) do {\
235 struct bgp_attr_encap_subtlv *new;\
236 if (CHECK_FLAG(bet->valid_subtlvs, (flag))) {\
237 new = function(&bet->field);\
241 attr->encap_subtlvs = new;\
248 bgp_encap_type_l2tpv3overip_to_tlv(
249 struct bgp_encap_type_l2tpv3_over_ip
*bet
, /* input structure */
252 struct bgp_attr_encap_subtlv
*last
;
254 /* advance to last subtlv */
255 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
257 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_L2TPV3_OVER_IP
;
259 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
261 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_l2tpv3_over_ip
, st_encap
);
262 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
263 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
264 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
268 bgp_encap_type_gre_to_tlv(
269 struct bgp_encap_type_gre
*bet
, /* input structure */
272 struct bgp_attr_encap_subtlv
*last
;
274 /* advance to last subtlv */
275 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
277 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_GRE
;
279 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_gre
, st_encap
);
280 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
281 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
282 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
286 bgp_encap_type_ip_in_ip_to_tlv(
287 struct bgp_encap_type_ip_in_ip
*bet
, /* input structure */
290 struct bgp_attr_encap_subtlv
*last
;
292 /* advance to last subtlv */
293 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
295 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_IP_IN_IP
;
297 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
298 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
299 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
303 bgp_encap_type_transmit_tunnel_endpoint(
304 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
, /* input structure */
307 struct bgp_attr_encap_subtlv
*last
;
309 /* advance to last subtlv */
310 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
312 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT
;
314 /* no subtlvs for this type */
318 bgp_encap_type_ipsec_in_tunnel_mode_to_tlv(
319 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
, /* input structure */
322 struct bgp_attr_encap_subtlv
*last
;
324 /* advance to last subtlv */
325 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
327 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE
;
329 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
333 bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
334 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
, /* input structure */
337 struct bgp_attr_encap_subtlv
*last
;
339 /* advance to last subtlv */
340 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
342 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
344 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
348 bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
349 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
*bet
, /* input structure */
352 struct bgp_attr_encap_subtlv
*last
;
354 /* advance to last subtlv */
355 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
357 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
359 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
363 bgp_encap_type_pbb_to_tlv(
364 struct bgp_encap_type_pbb
*bet
, /* input structure */
367 struct bgp_attr_encap_subtlv
*last
;
369 /* advance to last subtlv */
370 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
372 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_PBB
;
374 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
375 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_pbb
, st_encap
);
379 bgp_encap_type_vxlan_to_tlv(
380 struct bgp_encap_type_vxlan
*bet
, /* input structure */
383 struct bgp_attr_encap_subtlv
*tlv
;
386 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN
;
388 if(bet
== NULL
||!bet
->vnid
)
390 if(attr
->encap_subtlvs
)
391 XFREE(MTYPE_ENCAP_TLV
, attr
->encap_subtlvs
);
392 tlv
= XCALLOC (MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
)-1+12);
393 tlv
->type
= 1; /* encapsulation type */
397 vnid
= htonl(bet
->vnid
| VXLAN_ENCAP_MASK_VNID_VALID
);
398 memcpy(&tlv
->value
, &vnid
, 4);
402 char *ptr
= (char *)&tlv
->value
+ 4;
403 memcpy( ptr
, bet
->mac_address
, 6);
405 attr
->encap_subtlvs
= tlv
;
410 bgp_encap_type_nvgre_to_tlv(
411 struct bgp_encap_type_nvgre
*bet
, /* input structure */
414 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_NVGRE
;
418 bgp_encap_type_mpls_to_tlv(
419 struct bgp_encap_type_mpls
*bet
, /* input structure */
422 return; /* no encap attribute for MPLS */
426 bgp_encap_type_mpls_in_gre_to_tlv(
427 struct bgp_encap_type_mpls_in_gre
*bet
, /* input structure */
430 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_GRE
;
434 bgp_encap_type_vxlan_gpe_to_tlv(
435 struct bgp_encap_type_vxlan_gpe
*bet
, /* input structure */
439 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN_GPE
;
443 bgp_encap_type_mpls_in_udp_to_tlv(
444 struct bgp_encap_type_mpls_in_udp
*bet
, /* input structure */
448 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_UDP
;
452 /***********************************************************************
454 ***********************************************************************/
457 subtlv_decode_encap_l2tpv3_over_ip(
458 struct bgp_attr_encap_subtlv
*subtlv
,
459 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
461 if (subtlv
->length
< 4) {
462 zlog_debug("%s, subtlv length %d is less than 4",
463 __func__
, subtlv
->length
);
467 st
->sessionid
= (subtlv
->value
[0] << 24) |
468 (subtlv
->value
[1] << 16) |
469 (subtlv
->value
[2] << 8) |
471 st
->cookie_length
= subtlv
->length
- 4;
472 if (st
->cookie_length
> sizeof(st
->cookie
)) {
473 zlog_debug("%s, subtlv length %d is greater than %d",
474 __func__
, st
->cookie_length
, (int)sizeof(st
->cookie
));
477 memcpy(st
->cookie
, subtlv
->value
+ 4, st
->cookie_length
);
483 subtlv_decode_encap_gre(
484 struct bgp_attr_encap_subtlv
*subtlv
,
485 struct bgp_tea_subtlv_encap_gre_key
*st
)
487 if (subtlv
->length
!= 4) {
488 zlog_debug("%s, subtlv length %d does not equal 4",
489 __func__
, subtlv
->length
);
492 st
->gre_key
= (subtlv
->value
[0] << 24) |
493 (subtlv
->value
[1] << 16) |
494 (subtlv
->value
[2] << 8) |
500 subtlv_decode_encap_pbb(
501 struct bgp_attr_encap_subtlv
*subtlv
,
502 struct bgp_tea_subtlv_encap_pbb
*st
)
504 if (subtlv
->length
!= 1 + 3 + 6 + 2) {
505 zlog_debug("%s, subtlv length %d does not equal %d",
506 __func__
, subtlv
->length
, 1 + 3 + 6 + 2);
509 if (subtlv
->value
[0] & 0x80) {
511 st
->isid
= (subtlv
->value
[1] << 16) |
512 (subtlv
->value
[2] << 8) |
515 if (subtlv
->value
[0] & 0x40) {
517 st
->vid
= ((subtlv
->value
[10] & 0x0f) << 8) | subtlv
->value
[11];
519 memcpy(st
->macaddr
, subtlv
->value
+ 4, 6);
525 subtlv_decode_proto_type(
526 struct bgp_attr_encap_subtlv
*subtlv
,
527 struct bgp_tea_subtlv_proto_type
*st
)
529 if (subtlv
->length
!= 2) {
530 zlog_debug("%s, subtlv length %d does not equal 2",
531 __func__
, subtlv
->length
);
534 st
->proto
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
541 struct bgp_attr_encap_subtlv
*subtlv
,
542 struct bgp_tea_subtlv_color
*st
)
544 if (subtlv
->length
!= 8) {
545 zlog_debug("%s, subtlv length %d does not equal 8",
546 __func__
, subtlv
->length
);
549 if ((subtlv
->value
[0] != 0x03) ||
550 (subtlv
->value
[1] != 0x0b) ||
551 (subtlv
->value
[2] != 0) ||
552 (subtlv
->value
[3] != 0)) {
553 zlog_debug("%s, subtlv value 1st 4 bytes are not 0x030b0000", __func__
);
556 st
->color
= (subtlv
->value
[4] << 24) |
557 (subtlv
->value
[5] << 16) |
558 (subtlv
->value
[6] << 8) |
565 subtlv_decode_ipsec_ta(
566 struct bgp_attr_encap_subtlv
*subtlv
,
567 struct bgp_tea_subtlv_ipsec_ta
*st
)
569 st
->authenticator_length
= subtlv
->length
- 2;
570 if (st
->authenticator_length
> sizeof(st
->value
)) {
571 zlog_debug("%s, authenticator length %d exceeds storage maximum %d",
572 __func__
, st
->authenticator_length
, (int)sizeof(st
->value
));
575 st
->authenticator_type
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
576 memcpy(st
->value
, subtlv
->value
+ 2, st
->authenticator_length
);
580 /* draft-rosen-idr-tunnel-encaps 2.1 */
582 subtlv_decode_remote_endpoint(
583 struct bgp_attr_encap_subtlv
*subtlv
,
584 struct bgp_tea_subtlv_remote_endpoint
*st
)
587 if (subtlv
->length
!= 8 && subtlv
->length
!= 20 ) {
588 zlog_debug("%s, subtlv length %d does not equal 8 or 20",
589 __func__
, subtlv
->length
);
592 if (subtlv
->length
== 8) {
593 st
->family
= AF_INET
;
594 st
->ip_address
.v4
.s_addr
= ((subtlv
->value
[0] << 24) |
595 (subtlv
->value
[1] << 16) |
596 (subtlv
->value
[2] << 8) |
599 st
->family
= AF_INET6
;
600 memcpy (&(st
->ip_address
.v6
.s6_addr
), subtlv
->value
, 16);
602 i
= subtlv
->length
- 4;
603 st
->as4
= ((subtlv
->value
[i
] << 24) |
604 (subtlv
->value
[i
+1] << 16) |
605 (subtlv
->value
[i
+2] << 8) |
610 /***********************************************************************
611 * TUNNEL TYPE-SPECIFIC TLV DECODE
612 ***********************************************************************/
615 tlv_to_bgp_encap_type_l2tpv3overip(
616 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
617 struct bgp_encap_type_l2tpv3_over_ip
*bet
) /* caller-allocated */
619 struct bgp_attr_encap_subtlv
*st
;
622 for (st
= stlv
; st
; st
= st
->next
) {
624 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
625 rc
|= subtlv_decode_encap_l2tpv3_over_ip(st
, &bet
->st_encap
);
626 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
629 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
630 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
631 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
634 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
635 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
636 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
639 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
640 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
641 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
645 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
654 tlv_to_bgp_encap_type_gre(
655 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
656 struct bgp_encap_type_gre
*bet
) /* caller-allocated */
658 struct bgp_attr_encap_subtlv
*st
;
661 for (st
= stlv
; st
; st
= st
->next
) {
663 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
664 rc
|= subtlv_decode_encap_gre(st
, &bet
->st_encap
);
665 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
668 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
669 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
670 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
673 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
674 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
675 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
678 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
679 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
680 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
684 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
693 tlv_to_bgp_encap_type_ip_in_ip(
694 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
695 struct bgp_encap_type_ip_in_ip
*bet
) /* caller-allocated */
697 struct bgp_attr_encap_subtlv
*st
;
700 for (st
= stlv
; st
; st
= st
->next
) {
702 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
703 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
704 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
707 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
708 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
709 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
712 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
713 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
714 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
718 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
727 tlv_to_bgp_encap_type_transmit_tunnel_endpoint(
728 struct bgp_attr_encap_subtlv
*stlv
,
729 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
)
731 struct bgp_attr_encap_subtlv
*st
;
734 for (st
= stlv
; st
; st
= st
->next
) {
737 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
738 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
739 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
743 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
752 tlv_to_bgp_encap_type_ipsec_in_tunnel_mode(
753 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
754 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
) /* caller-allocated */
756 struct bgp_attr_encap_subtlv
*st
;
759 for (st
= stlv
; st
; st
= st
->next
) {
761 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
762 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
763 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
766 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
767 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
768 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
772 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
781 tlv_to_bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode(
782 struct bgp_attr_encap_subtlv
*stlv
,
783 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
785 struct bgp_attr_encap_subtlv
*st
;
788 for (st
= stlv
; st
; st
= st
->next
) {
790 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
791 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
792 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
795 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
796 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
797 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
801 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
810 tlv_to_bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode(
811 struct bgp_attr_encap_subtlv
*stlv
,
812 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
814 struct bgp_attr_encap_subtlv
*st
;
817 for (st
= stlv
; st
; st
= st
->next
) {
819 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
820 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
821 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
824 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
825 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
826 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
830 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
839 tlv_to_bgp_encap_type_vxlan(
840 struct bgp_attr_encap_subtlv
*stlv
,
841 struct bgp_encap_type_vxlan
*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
, &bet
->st_endpoint
);
851 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
855 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
864 tlv_to_bgp_encap_type_nvgre(
865 struct bgp_attr_encap_subtlv
*stlv
,
866 struct bgp_encap_type_nvgre
*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
, &bet
->st_endpoint
);
876 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
880 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
889 tlv_to_bgp_encap_type_mpls(
890 struct bgp_attr_encap_subtlv
*stlv
,
891 struct bgp_encap_type_mpls
*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
, &bet
->st_endpoint
);
901 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
905 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
914 tlv_to_bgp_encap_type_mpls_in_gre(
915 struct bgp_attr_encap_subtlv
*stlv
,
916 struct bgp_encap_type_mpls_in_gre
*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
, &bet
->st_endpoint
);
926 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
930 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
939 tlv_to_bgp_encap_type_vxlan_gpe(
940 struct bgp_attr_encap_subtlv
*stlv
,
941 struct bgp_encap_type_vxlan_gpe
*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
, &bet
->st_endpoint
);
951 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
955 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
964 tlv_to_bgp_encap_type_mpls_in_udp(
965 struct bgp_attr_encap_subtlv
*stlv
,
966 struct bgp_encap_type_mpls_in_udp
*bet
)
968 struct bgp_attr_encap_subtlv
*st
;
971 for (st
= stlv
; st
; st
= st
->next
) {
974 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
975 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
976 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
980 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
989 tlv_to_bgp_encap_type_pbb(
990 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
991 struct bgp_encap_type_pbb
*bet
) /* caller-allocated */
993 struct bgp_attr_encap_subtlv
*st
;
996 for (st
= stlv
; st
; st
= st
->next
) {
998 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
999 rc
|= subtlv_decode_encap_pbb(st
, &bet
->st_encap
);
1000 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
1003 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
1004 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
1005 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
1009 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);