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 extra->encap_subtlvs = new;\
248 bgp_encap_type_l2tpv3overip_to_tlv(
249 struct bgp_encap_type_l2tpv3_over_ip
*bet
, /* input structure */
252 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
253 struct bgp_attr_encap_subtlv
*last
;
255 /* advance to last subtlv */
256 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
258 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_L2TPV3_OVER_IP
;
260 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
262 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_l2tpv3_over_ip
, st_encap
);
263 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
264 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
265 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
269 bgp_encap_type_gre_to_tlv(
270 struct bgp_encap_type_gre
*bet
, /* input structure */
273 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
274 struct bgp_attr_encap_subtlv
*last
;
276 /* advance to last subtlv */
277 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
279 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_GRE
;
281 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_gre
, st_encap
);
282 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
283 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
284 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
288 bgp_encap_type_ip_in_ip_to_tlv(
289 struct bgp_encap_type_ip_in_ip
*bet
, /* input structure */
292 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
293 struct bgp_attr_encap_subtlv
*last
;
295 /* advance to last subtlv */
296 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
298 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IP_IN_IP
;
300 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
301 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
302 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
306 bgp_encap_type_transmit_tunnel_endpoint(
307 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
, /* input structure */
310 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
311 struct bgp_attr_encap_subtlv
*last
;
313 /* advance to last subtlv */
314 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
316 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT
;
318 /* no subtlvs for this type */
322 bgp_encap_type_ipsec_in_tunnel_mode_to_tlv(
323 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
, /* input structure */
326 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
327 struct bgp_attr_encap_subtlv
*last
;
329 /* advance to last subtlv */
330 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
332 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE
;
334 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
338 bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
339 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
, /* input structure */
342 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
343 struct bgp_attr_encap_subtlv
*last
;
345 /* advance to last subtlv */
346 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
348 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
350 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
354 bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
355 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
*bet
, /* input structure */
358 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
359 struct bgp_attr_encap_subtlv
*last
;
361 /* advance to last subtlv */
362 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
364 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
366 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
370 bgp_encap_type_pbb_to_tlv(
371 struct bgp_encap_type_pbb
*bet
, /* input structure */
374 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
375 struct bgp_attr_encap_subtlv
*last
;
377 /* advance to last subtlv */
378 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
380 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_PBB
;
382 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
383 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_pbb
, st_encap
);
387 bgp_encap_type_vxlan_to_tlv(
388 struct bgp_encap_type_vxlan
*bet
, /* input structure */
391 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
392 struct bgp_attr_encap_subtlv
*tlv
;
395 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN
;
397 if(bet
== NULL
||!bet
->vnid
)
399 if(extra
->encap_subtlvs
)
400 XFREE(MTYPE_ENCAP_TLV
, extra
->encap_subtlvs
);
401 tlv
= XCALLOC (MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
)-1+12);
402 tlv
->type
= 1; /* encapsulation type */
406 vnid
= htonl(bet
->vnid
| VXLAN_ENCAP_MASK_VNID_VALID
);
407 memcpy(&tlv
->value
, &vnid
, 4);
411 char *ptr
= (char *)&tlv
->value
+ 4;
412 memcpy( ptr
, bet
->mac_address
, 6);
414 extra
->encap_subtlvs
= tlv
;
419 bgp_encap_type_nvgre_to_tlv(
420 struct bgp_encap_type_nvgre
*bet
, /* input structure */
423 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
425 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_NVGRE
;
429 bgp_encap_type_mpls_to_tlv(
430 struct bgp_encap_type_mpls
*bet
, /* input structure */
433 return; /* no encap attribute for MPLS */
437 bgp_encap_type_mpls_in_gre_to_tlv(
438 struct bgp_encap_type_mpls_in_gre
*bet
, /* input structure */
441 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
443 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_GRE
;
447 bgp_encap_type_vxlan_gpe_to_tlv(
448 struct bgp_encap_type_vxlan_gpe
*bet
, /* input structure */
451 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
453 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN_GPE
;
457 bgp_encap_type_mpls_in_udp_to_tlv(
458 struct bgp_encap_type_mpls_in_udp
*bet
, /* input structure */
461 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
463 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_UDP
;
467 /***********************************************************************
469 ***********************************************************************/
472 subtlv_decode_encap_l2tpv3_over_ip(
473 struct bgp_attr_encap_subtlv
*subtlv
,
474 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
476 if (subtlv
->length
< 4) {
477 zlog_debug("%s, subtlv length %d is less than 4",
478 __func__
, subtlv
->length
);
482 st
->sessionid
= (subtlv
->value
[0] << 24) |
483 (subtlv
->value
[1] << 16) |
484 (subtlv
->value
[2] << 8) |
486 st
->cookie_length
= subtlv
->length
- 4;
487 if (st
->cookie_length
> sizeof(st
->cookie
)) {
488 zlog_debug("%s, subtlv length %d is greater than %d",
489 __func__
, st
->cookie_length
, (int)sizeof(st
->cookie
));
492 memcpy(st
->cookie
, subtlv
->value
+ 4, st
->cookie_length
);
498 subtlv_decode_encap_gre(
499 struct bgp_attr_encap_subtlv
*subtlv
,
500 struct bgp_tea_subtlv_encap_gre_key
*st
)
502 if (subtlv
->length
!= 4) {
503 zlog_debug("%s, subtlv length %d does not equal 4",
504 __func__
, subtlv
->length
);
507 st
->gre_key
= (subtlv
->value
[0] << 24) |
508 (subtlv
->value
[1] << 16) |
509 (subtlv
->value
[2] << 8) |
515 subtlv_decode_encap_pbb(
516 struct bgp_attr_encap_subtlv
*subtlv
,
517 struct bgp_tea_subtlv_encap_pbb
*st
)
519 if (subtlv
->length
!= 1 + 3 + 6 + 2) {
520 zlog_debug("%s, subtlv length %d does not equal %d",
521 __func__
, subtlv
->length
, 1 + 3 + 6 + 2);
524 if (subtlv
->value
[0] & 0x80) {
526 st
->isid
= (subtlv
->value
[1] << 16) |
527 (subtlv
->value
[2] << 8) |
530 if (subtlv
->value
[0] & 0x40) {
532 st
->vid
= ((subtlv
->value
[10] & 0x0f) << 8) | subtlv
->value
[11];
534 memcpy(st
->macaddr
, subtlv
->value
+ 4, 6);
540 subtlv_decode_proto_type(
541 struct bgp_attr_encap_subtlv
*subtlv
,
542 struct bgp_tea_subtlv_proto_type
*st
)
544 if (subtlv
->length
!= 2) {
545 zlog_debug("%s, subtlv length %d does not equal 2",
546 __func__
, subtlv
->length
);
549 st
->proto
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
556 struct bgp_attr_encap_subtlv
*subtlv
,
557 struct bgp_tea_subtlv_color
*st
)
559 if (subtlv
->length
!= 8) {
560 zlog_debug("%s, subtlv length %d does not equal 8",
561 __func__
, subtlv
->length
);
564 if ((subtlv
->value
[0] != 0x03) ||
565 (subtlv
->value
[1] != 0x0b) ||
566 (subtlv
->value
[2] != 0) ||
567 (subtlv
->value
[3] != 0)) {
568 zlog_debug("%s, subtlv value 1st 4 bytes are not 0x030b0000", __func__
);
571 st
->color
= (subtlv
->value
[4] << 24) |
572 (subtlv
->value
[5] << 16) |
573 (subtlv
->value
[6] << 8) |
580 subtlv_decode_ipsec_ta(
581 struct bgp_attr_encap_subtlv
*subtlv
,
582 struct bgp_tea_subtlv_ipsec_ta
*st
)
584 st
->authenticator_length
= subtlv
->length
- 2;
585 if (st
->authenticator_length
> sizeof(st
->value
)) {
586 zlog_debug("%s, authenticator length %d exceeds storage maximum %d",
587 __func__
, st
->authenticator_length
, (int)sizeof(st
->value
));
590 st
->authenticator_type
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
591 memcpy(st
->value
, subtlv
->value
+ 2, st
->authenticator_length
);
595 /* draft-rosen-idr-tunnel-encaps 2.1 */
597 subtlv_decode_remote_endpoint(
598 struct bgp_attr_encap_subtlv
*subtlv
,
599 struct bgp_tea_subtlv_remote_endpoint
*st
)
602 if (subtlv
->length
!= 8 && subtlv
->length
!= 20 ) {
603 zlog_debug("%s, subtlv length %d does not equal 8 or 20",
604 __func__
, subtlv
->length
);
607 if (subtlv
->length
== 8) {
608 st
->family
= AF_INET
;
609 st
->ip_address
.v4
.s_addr
= ((subtlv
->value
[0] << 24) |
610 (subtlv
->value
[1] << 16) |
611 (subtlv
->value
[2] << 8) |
614 st
->family
= AF_INET6
;
615 memcpy (&(st
->ip_address
.v6
.s6_addr
), subtlv
->value
, 16);
617 i
= subtlv
->length
- 4;
618 st
->as4
= ((subtlv
->value
[i
] << 24) |
619 (subtlv
->value
[i
+1] << 16) |
620 (subtlv
->value
[i
+2] << 8) |
625 /***********************************************************************
626 * TUNNEL TYPE-SPECIFIC TLV DECODE
627 ***********************************************************************/
630 tlv_to_bgp_encap_type_l2tpv3overip(
631 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
632 struct bgp_encap_type_l2tpv3_over_ip
*bet
) /* caller-allocated */
634 struct bgp_attr_encap_subtlv
*st
;
637 for (st
= stlv
; st
; st
= st
->next
) {
639 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
640 rc
|= subtlv_decode_encap_l2tpv3_over_ip(st
, &bet
->st_encap
);
641 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
644 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
645 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
646 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
649 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
650 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
651 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
654 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
655 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
656 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
660 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
669 tlv_to_bgp_encap_type_gre(
670 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
671 struct bgp_encap_type_gre
*bet
) /* caller-allocated */
673 struct bgp_attr_encap_subtlv
*st
;
676 for (st
= stlv
; st
; st
= st
->next
) {
678 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
679 rc
|= subtlv_decode_encap_gre(st
, &bet
->st_encap
);
680 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
683 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
684 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
685 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
688 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
689 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
690 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
693 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
694 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
695 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
699 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
708 tlv_to_bgp_encap_type_ip_in_ip(
709 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
710 struct bgp_encap_type_ip_in_ip
*bet
) /* caller-allocated */
712 struct bgp_attr_encap_subtlv
*st
;
715 for (st
= stlv
; st
; st
= st
->next
) {
717 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
718 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
719 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
722 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
723 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
724 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
727 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
728 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
729 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
733 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
742 tlv_to_bgp_encap_type_transmit_tunnel_endpoint(
743 struct bgp_attr_encap_subtlv
*stlv
,
744 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
)
746 struct bgp_attr_encap_subtlv
*st
;
749 for (st
= stlv
; st
; st
= st
->next
) {
752 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
753 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
754 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
758 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
767 tlv_to_bgp_encap_type_ipsec_in_tunnel_mode(
768 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
769 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
) /* caller-allocated */
771 struct bgp_attr_encap_subtlv
*st
;
774 for (st
= stlv
; st
; st
= st
->next
) {
776 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
777 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
778 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
781 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
782 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
783 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
787 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
796 tlv_to_bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode(
797 struct bgp_attr_encap_subtlv
*stlv
,
798 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
800 struct bgp_attr_encap_subtlv
*st
;
803 for (st
= stlv
; st
; st
= st
->next
) {
805 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
806 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
807 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
810 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
811 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
812 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
816 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
825 tlv_to_bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode(
826 struct bgp_attr_encap_subtlv
*stlv
,
827 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
829 struct bgp_attr_encap_subtlv
*st
;
832 for (st
= stlv
; st
; st
= st
->next
) {
834 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
835 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
836 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
839 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
840 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
841 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
845 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
854 tlv_to_bgp_encap_type_vxlan(
855 struct bgp_attr_encap_subtlv
*stlv
,
856 struct bgp_encap_type_vxlan
*bet
)
858 struct bgp_attr_encap_subtlv
*st
;
861 for (st
= stlv
; st
; st
= st
->next
) {
864 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
865 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
866 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
870 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
879 tlv_to_bgp_encap_type_nvgre(
880 struct bgp_attr_encap_subtlv
*stlv
,
881 struct bgp_encap_type_nvgre
*bet
)
883 struct bgp_attr_encap_subtlv
*st
;
886 for (st
= stlv
; st
; st
= st
->next
) {
889 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
890 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
891 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
895 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
904 tlv_to_bgp_encap_type_mpls(
905 struct bgp_attr_encap_subtlv
*stlv
,
906 struct bgp_encap_type_mpls
*bet
)
908 struct bgp_attr_encap_subtlv
*st
;
911 for (st
= stlv
; st
; st
= st
->next
) {
914 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
915 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
916 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
920 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
929 tlv_to_bgp_encap_type_mpls_in_gre(
930 struct bgp_attr_encap_subtlv
*stlv
,
931 struct bgp_encap_type_mpls_in_gre
*bet
)
933 struct bgp_attr_encap_subtlv
*st
;
936 for (st
= stlv
; st
; st
= st
->next
) {
939 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
940 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
941 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
945 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
954 tlv_to_bgp_encap_type_vxlan_gpe(
955 struct bgp_attr_encap_subtlv
*stlv
,
956 struct bgp_encap_type_vxlan_gpe
*bet
)
958 struct bgp_attr_encap_subtlv
*st
;
961 for (st
= stlv
; st
; st
= st
->next
) {
964 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
965 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
966 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
970 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
979 tlv_to_bgp_encap_type_mpls_in_udp(
980 struct bgp_attr_encap_subtlv
*stlv
,
981 struct bgp_encap_type_mpls_in_udp
*bet
)
983 struct bgp_attr_encap_subtlv
*st
;
986 for (st
= stlv
; st
; st
= st
->next
) {
989 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
990 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
991 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
995 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
1004 tlv_to_bgp_encap_type_pbb(
1005 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
1006 struct bgp_encap_type_pbb
*bet
) /* caller-allocated */
1008 struct bgp_attr_encap_subtlv
*st
;
1011 for (st
= stlv
; st
; st
= st
->next
) {
1013 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
1014 rc
|= subtlv_decode_encap_pbb(st
, &bet
->st_encap
);
1015 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
1018 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
1019 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
1020 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
1024 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);