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
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.
30 #include "bgp_encap_types.h"
31 #include "bgp_encap_tlv.h"
33 /***********************************************************************
35 ***********************************************************************/
38 static struct bgp_attr_encap_subtlv
*
39 subtlv_encode_encap_l2tpv3_over_ip(
40 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
42 struct bgp_attr_encap_subtlv
*new;
44 int total
= 4 + st
->cookie_length
;
47 assert(st
->cookie_length
<= sizeof(st
->cookie
));
48 assert(total
<= 0xff);
50 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
52 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
56 *p
++ = (st
->sessionid
& 0xff000000) >> 24;
57 *p
++ = (st
->sessionid
& 0xff0000) >> 16;
58 *p
++ = (st
->sessionid
& 0xff00) >> 8;
59 *p
++ = (st
->sessionid
& 0xff);
60 memcpy(p
, st
->cookie
, st
->cookie_length
);
65 static struct bgp_attr_encap_subtlv
*
66 subtlv_encode_encap_gre(
67 struct bgp_tea_subtlv_encap_gre_key
*st
)
69 struct bgp_attr_encap_subtlv
*new;
73 assert(total
<= 0xff);
75 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
77 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
81 *p
++ = (st
->gre_key
& 0xff000000) >> 24;
82 *p
++ = (st
->gre_key
& 0xff0000) >> 16;
83 *p
++ = (st
->gre_key
& 0xff00) >> 8;
84 *p
++ = (st
->gre_key
& 0xff);
88 static struct bgp_attr_encap_subtlv
*
89 subtlv_encode_encap_pbb(
90 struct bgp_tea_subtlv_encap_pbb
*st
)
92 struct bgp_attr_encap_subtlv
*new;
94 int total
= 1 + 3 + 6 + 2; /* flags + isid + madaddr + vid */
96 assert(total
<= 0xff);
98 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
100 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
104 *p
++ = (st
->flag_isid
? 0x80: 0) |
105 (st
->flag_vid
? 0x40: 0) |
108 *p
= (st
->isid
& 0xff0000) >> 16;
109 *(p
+1) = (st
->isid
& 0xff00) >> 8;
110 *(p
+2) = (st
->isid
& 0xff);
113 memcpy(p
, st
->macaddr
, 6);
116 *p
++ = (st
->vid
& 0xf00) >> 8;
117 *p
++ = st
->vid
& 0xff;
123 static struct bgp_attr_encap_subtlv
*
124 subtlv_encode_proto_type(
125 struct bgp_tea_subtlv_proto_type
*st
)
127 struct bgp_attr_encap_subtlv
*new;
131 assert(total
<= 0xff);
133 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
135 new->type
= BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
;
139 *p
++ = (st
->proto
& 0xff00) >> 8;
140 *p
++ = (st
->proto
& 0xff);
145 static struct bgp_attr_encap_subtlv
*
147 struct bgp_tea_subtlv_color
*st
)
149 struct bgp_attr_encap_subtlv
*new;
153 assert(total
<= 0xff);
155 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
157 new->type
= BGP_ENCAP_SUBTLV_TYPE_COLOR
;
161 *p
++ = 0x03; /* transitive*/
163 *p
++ = 0; /* reserved */
164 *p
++ = 0; /* reserved */
166 *p
++ = (st
->color
& 0xff000000) >> 24;
167 *p
++ = (st
->color
& 0xff0000) >> 16;
168 *p
++ = (st
->color
& 0xff00) >> 8;
169 *p
++ = (st
->color
& 0xff);
175 static struct bgp_attr_encap_subtlv
*
176 subtlv_encode_ipsec_ta(
177 struct bgp_tea_subtlv_ipsec_ta
*st
)
179 struct bgp_attr_encap_subtlv
*new;
181 int total
= 2 + st
->authenticator_length
;
184 assert(st
->authenticator_length
<= sizeof(st
->value
));
185 assert(total
<= 0xff);
187 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
189 new->type
= BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
;
193 *p
++ = (st
->authenticator_type
& 0xff00) >> 8;
194 *p
++ = st
->authenticator_type
& 0xff;
195 memcpy(p
, st
->value
, st
->authenticator_length
);
199 /* draft-rosen-idr-tunnel-encaps 2.1 */
200 static struct bgp_attr_encap_subtlv
*
201 subtlv_encode_remote_endpoint(
202 struct bgp_tea_subtlv_remote_endpoint
*st
)
204 struct bgp_attr_encap_subtlv
*new;
207 int total
= (st
->family
==AF_INET
?8:20);
209 assert(total
<= 0xff);
211 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
213 new->type
= BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
;
216 if (st
->family
== AF_INET
) {
217 memcpy (p
, &(st
->ip_address
.v4
.s_addr
), 4);
220 assert (st
->family
== AF_INET6
);
221 memcpy (p
, &(st
->ip_address
.v6
.s6_addr
), 16);
224 memcpy (p
, &(st
->as4
), 4);
228 /***********************************************************************
229 * TUNNEL TYPE-SPECIFIC TLV ENCODE
230 ***********************************************************************/
233 * requires "extra" and "last" to be defined in caller
235 #define ENC_SUBTLV(flag, function, field) do {\
236 struct bgp_attr_encap_subtlv *new;\
237 if (CHECK_FLAG(bet->valid_subtlvs, (flag))) {\
238 new = function(&bet->field);\
242 extra->encap_subtlvs = new;\
249 bgp_encap_type_l2tpv3overip_to_tlv(
250 struct bgp_encap_type_l2tpv3_over_ip
*bet
, /* input structure */
253 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
254 struct bgp_attr_encap_subtlv
*last
;
256 /* advance to last subtlv */
257 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
259 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_L2TPV3_OVER_IP
;
261 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
263 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_l2tpv3_over_ip
, st_encap
);
264 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
265 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
266 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
270 bgp_encap_type_gre_to_tlv(
271 struct bgp_encap_type_gre
*bet
, /* input structure */
274 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
275 struct bgp_attr_encap_subtlv
*last
;
277 /* advance to last subtlv */
278 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
280 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_GRE
;
282 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_gre
, st_encap
);
283 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
284 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
285 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
289 bgp_encap_type_ip_in_ip_to_tlv(
290 struct bgp_encap_type_ip_in_ip
*bet
, /* input structure */
293 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
294 struct bgp_attr_encap_subtlv
*last
;
296 /* advance to last subtlv */
297 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
299 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IP_IN_IP
;
301 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
302 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
303 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
307 bgp_encap_type_transmit_tunnel_endpoint(
308 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
, /* input structure */
311 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
312 struct bgp_attr_encap_subtlv
*last
;
314 /* advance to last subtlv */
315 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
317 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT
;
319 /* no subtlvs for this type */
323 bgp_encap_type_ipsec_in_tunnel_mode_to_tlv(
324 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
, /* input structure */
327 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
328 struct bgp_attr_encap_subtlv
*last
;
330 /* advance to last subtlv */
331 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
333 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE
;
335 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
339 bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
340 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
, /* input structure */
343 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
344 struct bgp_attr_encap_subtlv
*last
;
346 /* advance to last subtlv */
347 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
349 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
351 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
355 bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
356 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
*bet
, /* input structure */
359 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
360 struct bgp_attr_encap_subtlv
*last
;
362 /* advance to last subtlv */
363 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
365 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
367 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
371 bgp_encap_type_pbb_to_tlv(
372 struct bgp_encap_type_pbb
*bet
, /* input structure */
375 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
376 struct bgp_attr_encap_subtlv
*last
;
378 /* advance to last subtlv */
379 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
381 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_PBB
;
383 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
384 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_pbb
, st_encap
);
388 bgp_encap_type_vxlan_to_tlv(
389 struct bgp_encap_type_vxlan
*bet
, /* input structure */
392 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
393 struct bgp_attr_encap_subtlv
*tlv
;
396 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN
;
398 if(bet
== NULL
||!bet
->vnid
)
400 if(extra
->encap_subtlvs
)
401 XFREE(MTYPE_ENCAP_TLV
, extra
->encap_subtlvs
);
402 tlv
= XCALLOC (MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
)-1+12);
403 tlv
->type
= 1; /* encapsulation type */
407 vnid
= htonl(bet
->vnid
| VXLAN_ENCAP_MASK_VNID_VALID
);
408 memcpy(&tlv
->value
, &vnid
, 4);
412 char *ptr
= (char *)&tlv
->value
+ 4;
413 memcpy( ptr
, bet
->mac_address
, 6);
415 extra
->encap_subtlvs
= tlv
;
420 bgp_encap_type_nvgre_to_tlv(
421 struct bgp_encap_type_nvgre
*bet
, /* input structure */
424 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
426 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_NVGRE
;
430 bgp_encap_type_mpls_to_tlv(
431 struct bgp_encap_type_mpls
*bet
, /* input structure */
434 return; /* no encap attribute for MPLS */
438 bgp_encap_type_mpls_in_gre_to_tlv(
439 struct bgp_encap_type_mpls_in_gre
*bet
, /* input structure */
442 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
444 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_GRE
;
448 bgp_encap_type_vxlan_gpe_to_tlv(
449 struct bgp_encap_type_vxlan_gpe
*bet
, /* input structure */
452 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
454 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN_GPE
;
458 bgp_encap_type_mpls_in_udp_to_tlv(
459 struct bgp_encap_type_mpls_in_udp
*bet
, /* input structure */
462 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
464 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_UDP
;
468 /***********************************************************************
470 ***********************************************************************/
473 subtlv_decode_encap_l2tpv3_over_ip(
474 struct bgp_attr_encap_subtlv
*subtlv
,
475 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
477 if (subtlv
->length
< 4) {
478 zlog_debug("%s, subtlv length %d is less than 4",
479 __func__
, subtlv
->length
);
483 st
->sessionid
= (subtlv
->value
[0] << 24) |
484 (subtlv
->value
[1] << 16) |
485 (subtlv
->value
[2] << 8) |
487 st
->cookie_length
= subtlv
->length
- 4;
488 if (st
->cookie_length
> sizeof(st
->cookie
)) {
489 zlog_debug("%s, subtlv length %d is greater than %d",
490 __func__
, st
->cookie_length
, (int)sizeof(st
->cookie
));
493 memcpy(st
->cookie
, subtlv
->value
+ 4, st
->cookie_length
);
499 subtlv_decode_encap_gre(
500 struct bgp_attr_encap_subtlv
*subtlv
,
501 struct bgp_tea_subtlv_encap_gre_key
*st
)
503 if (subtlv
->length
!= 4) {
504 zlog_debug("%s, subtlv length %d does not equal 4",
505 __func__
, subtlv
->length
);
508 st
->gre_key
= (subtlv
->value
[0] << 24) |
509 (subtlv
->value
[1] << 16) |
510 (subtlv
->value
[2] << 8) |
516 subtlv_decode_encap_pbb(
517 struct bgp_attr_encap_subtlv
*subtlv
,
518 struct bgp_tea_subtlv_encap_pbb
*st
)
520 if (subtlv
->length
!= 1 + 3 + 6 + 2) {
521 zlog_debug("%s, subtlv length %d does not equal %d",
522 __func__
, subtlv
->length
, 1 + 3 + 6 + 2);
525 if (subtlv
->value
[0] & 0x80) {
527 st
->isid
= (subtlv
->value
[1] << 16) |
528 (subtlv
->value
[2] << 8) |
531 if (subtlv
->value
[0] & 0x40) {
533 st
->vid
= ((subtlv
->value
[10] & 0x0f) << 8) | subtlv
->value
[11];
535 memcpy(st
->macaddr
, subtlv
->value
+ 4, 6);
541 subtlv_decode_proto_type(
542 struct bgp_attr_encap_subtlv
*subtlv
,
543 struct bgp_tea_subtlv_proto_type
*st
)
545 if (subtlv
->length
!= 2) {
546 zlog_debug("%s, subtlv length %d does not equal 2",
547 __func__
, subtlv
->length
);
550 st
->proto
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
557 struct bgp_attr_encap_subtlv
*subtlv
,
558 struct bgp_tea_subtlv_color
*st
)
560 if (subtlv
->length
!= 8) {
561 zlog_debug("%s, subtlv length %d does not equal 8",
562 __func__
, subtlv
->length
);
565 if ((subtlv
->value
[0] != 0x03) ||
566 (subtlv
->value
[1] != 0x0b) ||
567 (subtlv
->value
[2] != 0) ||
568 (subtlv
->value
[3] != 0)) {
569 zlog_debug("%s, subtlv value 1st 4 bytes are not 0x030b0000", __func__
);
572 st
->color
= (subtlv
->value
[4] << 24) |
573 (subtlv
->value
[5] << 16) |
574 (subtlv
->value
[6] << 8) |
581 subtlv_decode_ipsec_ta(
582 struct bgp_attr_encap_subtlv
*subtlv
,
583 struct bgp_tea_subtlv_ipsec_ta
*st
)
585 st
->authenticator_length
= subtlv
->length
- 2;
586 if (st
->authenticator_length
> sizeof(st
->value
)) {
587 zlog_debug("%s, authenticator length %d exceeds storage maximum %d",
588 __func__
, st
->authenticator_length
, (int)sizeof(st
->value
));
591 st
->authenticator_type
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
592 memcpy(st
->value
, subtlv
->value
+ 2, st
->authenticator_length
);
596 /* draft-rosen-idr-tunnel-encaps 2.1 */
598 subtlv_decode_remote_endpoint(
599 struct bgp_attr_encap_subtlv
*subtlv
,
600 struct bgp_tea_subtlv_remote_endpoint
*st
)
603 if (subtlv
->length
!= 8 && subtlv
->length
!= 20 ) {
604 zlog_debug("%s, subtlv length %d does not equal 8 or 20",
605 __func__
, subtlv
->length
);
608 if (subtlv
->length
== 8) {
609 st
->family
= AF_INET
;
610 st
->ip_address
.v4
.s_addr
= ((subtlv
->value
[0] << 24) |
611 (subtlv
->value
[1] << 16) |
612 (subtlv
->value
[2] << 8) |
615 st
->family
= AF_INET6
;
616 memcpy (&(st
->ip_address
.v6
.s6_addr
), subtlv
->value
, 16);
618 i
= subtlv
->length
- 4;
619 st
->as4
= ((subtlv
->value
[i
] << 24) |
620 (subtlv
->value
[i
+1] << 16) |
621 (subtlv
->value
[i
+2] << 8) |
626 /***********************************************************************
627 * TUNNEL TYPE-SPECIFIC TLV DECODE
628 ***********************************************************************/
631 tlv_to_bgp_encap_type_l2tpv3overip(
632 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
633 struct bgp_encap_type_l2tpv3_over_ip
*bet
) /* caller-allocated */
635 struct bgp_attr_encap_subtlv
*st
;
638 for (st
= stlv
; st
; st
= st
->next
) {
640 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
641 rc
|= subtlv_decode_encap_l2tpv3_over_ip(st
, &bet
->st_encap
);
642 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
645 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
646 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
647 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
650 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
651 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
652 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
655 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
656 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
657 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
661 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
670 tlv_to_bgp_encap_type_gre(
671 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
672 struct bgp_encap_type_gre
*bet
) /* caller-allocated */
674 struct bgp_attr_encap_subtlv
*st
;
677 for (st
= stlv
; st
; st
= st
->next
) {
679 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
680 rc
|= subtlv_decode_encap_gre(st
, &bet
->st_encap
);
681 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
684 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
685 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
686 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
689 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
690 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
691 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
694 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
695 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
696 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
700 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
709 tlv_to_bgp_encap_type_ip_in_ip(
710 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
711 struct bgp_encap_type_ip_in_ip
*bet
) /* caller-allocated */
713 struct bgp_attr_encap_subtlv
*st
;
716 for (st
= stlv
; st
; st
= st
->next
) {
718 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
719 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
720 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
723 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
724 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
725 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
728 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
729 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
730 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
734 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
743 tlv_to_bgp_encap_type_transmit_tunnel_endpoint(
744 struct bgp_attr_encap_subtlv
*stlv
,
745 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
)
747 struct bgp_attr_encap_subtlv
*st
;
750 for (st
= stlv
; st
; st
= st
->next
) {
753 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
754 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
755 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
759 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
768 tlv_to_bgp_encap_type_ipsec_in_tunnel_mode(
769 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
770 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
) /* caller-allocated */
772 struct bgp_attr_encap_subtlv
*st
;
775 for (st
= stlv
; st
; st
= st
->next
) {
777 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
778 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
779 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
782 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
783 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
784 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
788 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
797 tlv_to_bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode(
798 struct bgp_attr_encap_subtlv
*stlv
,
799 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
801 struct bgp_attr_encap_subtlv
*st
;
804 for (st
= stlv
; st
; st
= st
->next
) {
806 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
807 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
808 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
811 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
812 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
813 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
817 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
826 tlv_to_bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode(
827 struct bgp_attr_encap_subtlv
*stlv
,
828 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
830 struct bgp_attr_encap_subtlv
*st
;
833 for (st
= stlv
; st
; st
= st
->next
) {
835 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
836 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
837 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
840 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
841 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
842 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
846 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
855 tlv_to_bgp_encap_type_vxlan(
856 struct bgp_attr_encap_subtlv
*stlv
,
857 struct bgp_encap_type_vxlan
*bet
)
859 struct bgp_attr_encap_subtlv
*st
;
862 for (st
= stlv
; st
; st
= st
->next
) {
865 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
866 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
867 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
871 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
880 tlv_to_bgp_encap_type_nvgre(
881 struct bgp_attr_encap_subtlv
*stlv
,
882 struct bgp_encap_type_nvgre
*bet
)
884 struct bgp_attr_encap_subtlv
*st
;
887 for (st
= stlv
; st
; st
= st
->next
) {
890 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
891 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
892 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
896 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
905 tlv_to_bgp_encap_type_mpls(
906 struct bgp_attr_encap_subtlv
*stlv
,
907 struct bgp_encap_type_mpls
*bet
)
909 struct bgp_attr_encap_subtlv
*st
;
912 for (st
= stlv
; st
; st
= st
->next
) {
915 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
916 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
917 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
921 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
930 tlv_to_bgp_encap_type_mpls_in_gre(
931 struct bgp_attr_encap_subtlv
*stlv
,
932 struct bgp_encap_type_mpls_in_gre
*bet
)
934 struct bgp_attr_encap_subtlv
*st
;
937 for (st
= stlv
; st
; st
= st
->next
) {
940 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
941 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
942 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
946 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
955 tlv_to_bgp_encap_type_vxlan_gpe(
956 struct bgp_attr_encap_subtlv
*stlv
,
957 struct bgp_encap_type_vxlan_gpe
*bet
)
959 struct bgp_attr_encap_subtlv
*st
;
962 for (st
= stlv
; st
; st
= st
->next
) {
965 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
966 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
967 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
971 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
980 tlv_to_bgp_encap_type_mpls_in_udp(
981 struct bgp_attr_encap_subtlv
*stlv
,
982 struct bgp_encap_type_mpls_in_udp
*bet
)
984 struct bgp_attr_encap_subtlv
*st
;
987 for (st
= stlv
; st
; st
= st
->next
) {
990 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
991 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
992 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
996 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
1005 tlv_to_bgp_encap_type_pbb(
1006 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
1007 struct bgp_encap_type_pbb
*bet
) /* caller-allocated */
1009 struct bgp_attr_encap_subtlv
*st
;
1012 for (st
= stlv
; st
; st
= st
->next
) {
1014 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
1015 rc
|= subtlv_decode_encap_pbb(st
, &bet
->st_encap
);
1016 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
1019 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
1020 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
1021 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
1025 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);