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.
31 #include "bgp_encap_types.h"
32 #include "bgp_encap_tlv.h"
34 /***********************************************************************
36 ***********************************************************************/
39 static struct bgp_attr_encap_subtlv
*
40 subtlv_encode_encap_l2tpv3_over_ip(
41 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
43 struct bgp_attr_encap_subtlv
*new;
45 int total
= 4 + st
->cookie_length
;
48 assert(st
->cookie_length
<= sizeof(st
->cookie
));
49 assert(total
<= 0xff);
51 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
53 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
57 *p
++ = (st
->sessionid
& 0xff000000) >> 24;
58 *p
++ = (st
->sessionid
& 0xff0000) >> 16;
59 *p
++ = (st
->sessionid
& 0xff00) >> 8;
60 *p
++ = (st
->sessionid
& 0xff);
61 memcpy(p
, st
->cookie
, st
->cookie_length
);
66 static struct bgp_attr_encap_subtlv
*
67 subtlv_encode_encap_gre(
68 struct bgp_tea_subtlv_encap_gre_key
*st
)
70 struct bgp_attr_encap_subtlv
*new;
74 assert(total
<= 0xff);
76 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
78 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
82 *p
++ = (st
->gre_key
& 0xff000000) >> 24;
83 *p
++ = (st
->gre_key
& 0xff0000) >> 16;
84 *p
++ = (st
->gre_key
& 0xff00) >> 8;
85 *p
++ = (st
->gre_key
& 0xff);
89 static struct bgp_attr_encap_subtlv
*
90 subtlv_encode_encap_pbb(
91 struct bgp_tea_subtlv_encap_pbb
*st
)
93 struct bgp_attr_encap_subtlv
*new;
95 int total
= 1 + 3 + 6 + 2; /* flags + isid + madaddr + vid */
97 assert(total
<= 0xff);
99 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
101 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
105 *p
++ = (st
->flag_isid
? 0x80: 0) |
106 (st
->flag_vid
? 0x40: 0) |
109 *p
= (st
->isid
& 0xff0000) >> 16;
110 *(p
+1) = (st
->isid
& 0xff00) >> 8;
111 *(p
+2) = (st
->isid
& 0xff);
114 memcpy(p
, st
->macaddr
, 6);
117 *p
++ = (st
->vid
& 0xf00) >> 8;
118 *p
++ = st
->vid
& 0xff;
124 static struct bgp_attr_encap_subtlv
*
125 subtlv_encode_proto_type(
126 struct bgp_tea_subtlv_proto_type
*st
)
128 struct bgp_attr_encap_subtlv
*new;
132 assert(total
<= 0xff);
134 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
136 new->type
= BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
;
140 *p
++ = (st
->proto
& 0xff00) >> 8;
141 *p
++ = (st
->proto
& 0xff);
146 static struct bgp_attr_encap_subtlv
*
148 struct bgp_tea_subtlv_color
*st
)
150 struct bgp_attr_encap_subtlv
*new;
154 assert(total
<= 0xff);
156 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
158 new->type
= BGP_ENCAP_SUBTLV_TYPE_COLOR
;
162 *p
++ = 0x03; /* transitive*/
164 *p
++ = 0; /* reserved */
165 *p
++ = 0; /* reserved */
167 *p
++ = (st
->color
& 0xff000000) >> 24;
168 *p
++ = (st
->color
& 0xff0000) >> 16;
169 *p
++ = (st
->color
& 0xff00) >> 8;
170 *p
++ = (st
->color
& 0xff);
176 static struct bgp_attr_encap_subtlv
*
177 subtlv_encode_ipsec_ta(
178 struct bgp_tea_subtlv_ipsec_ta
*st
)
180 struct bgp_attr_encap_subtlv
*new;
182 int total
= 2 + st
->authenticator_length
;
185 assert(st
->authenticator_length
<= sizeof(st
->value
));
186 assert(total
<= 0xff);
188 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
190 new->type
= BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
;
194 *p
++ = (st
->authenticator_type
& 0xff00) >> 8;
195 *p
++ = st
->authenticator_type
& 0xff;
196 memcpy(p
, st
->value
, st
->authenticator_length
);
200 /* draft-rosen-idr-tunnel-encaps 2.1 */
201 static struct bgp_attr_encap_subtlv
*
202 subtlv_encode_remote_endpoint(
203 struct bgp_tea_subtlv_remote_endpoint
*st
)
205 struct bgp_attr_encap_subtlv
*new;
208 int total
= (st
->family
==AF_INET
?8:20);
210 assert(total
<= 0xff);
212 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
214 new->type
= BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
;
217 if (st
->family
== AF_INET
) {
218 memcpy (p
, &(st
->ip_address
.v4
.s_addr
), 4);
221 assert (st
->family
== AF_INET6
);
222 memcpy (p
, &(st
->ip_address
.v6
.s6_addr
), 16);
225 memcpy (p
, &(st
->as4
), 4);
229 /***********************************************************************
230 * TUNNEL TYPE-SPECIFIC TLV ENCODE
231 ***********************************************************************/
234 * requires "extra" and "last" to be defined in caller
236 #define ENC_SUBTLV(flag, function, field) do {\
237 struct bgp_attr_encap_subtlv *new;\
238 if (CHECK_FLAG(bet->valid_subtlvs, (flag))) {\
239 new = function(&bet->field);\
243 extra->encap_subtlvs = new;\
250 bgp_encap_type_l2tpv3overip_to_tlv(
251 struct bgp_encap_type_l2tpv3_over_ip
*bet
, /* input structure */
254 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
255 struct bgp_attr_encap_subtlv
*last
;
257 /* advance to last subtlv */
258 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
260 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_L2TPV3_OVER_IP
;
262 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
264 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_l2tpv3_over_ip
, st_encap
);
265 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
266 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
267 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
271 bgp_encap_type_gre_to_tlv(
272 struct bgp_encap_type_gre
*bet
, /* input structure */
275 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
276 struct bgp_attr_encap_subtlv
*last
;
278 /* advance to last subtlv */
279 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
281 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_GRE
;
283 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_gre
, st_encap
);
284 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
285 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
286 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
290 bgp_encap_type_ip_in_ip_to_tlv(
291 struct bgp_encap_type_ip_in_ip
*bet
, /* input structure */
294 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
295 struct bgp_attr_encap_subtlv
*last
;
297 /* advance to last subtlv */
298 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
300 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IP_IN_IP
;
302 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
303 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
304 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
308 bgp_encap_type_transmit_tunnel_endpoint(
309 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
, /* input structure */
312 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
313 struct bgp_attr_encap_subtlv
*last
;
315 /* advance to last subtlv */
316 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
318 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT
;
320 /* no subtlvs for this type */
324 bgp_encap_type_ipsec_in_tunnel_mode_to_tlv(
325 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
, /* input structure */
328 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
329 struct bgp_attr_encap_subtlv
*last
;
331 /* advance to last subtlv */
332 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
334 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE
;
336 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
340 bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
341 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
, /* input structure */
344 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
345 struct bgp_attr_encap_subtlv
*last
;
347 /* advance to last subtlv */
348 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
350 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
352 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
356 bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
357 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
*bet
, /* input structure */
360 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
361 struct bgp_attr_encap_subtlv
*last
;
363 /* advance to last subtlv */
364 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
366 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
368 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
372 bgp_encap_type_pbb_to_tlv(
373 struct bgp_encap_type_pbb
*bet
, /* input structure */
376 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
377 struct bgp_attr_encap_subtlv
*last
;
379 /* advance to last subtlv */
380 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
382 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_PBB
;
384 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
385 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_pbb
, st_encap
);
389 bgp_encap_type_vxlan_to_tlv(
390 struct bgp_encap_type_vxlan
*bet
, /* input structure */
393 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
394 struct bgp_attr_encap_subtlv
*tlv
;
397 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN
;
399 if(bet
== NULL
||!bet
->vnid
)
401 if(extra
->encap_subtlvs
)
402 XFREE(MTYPE_ENCAP_TLV
, extra
->encap_subtlvs
);
403 tlv
= XCALLOC (MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
)-1+12);
404 tlv
->type
= 1; /* encapsulation type */
408 vnid
= htonl(bet
->vnid
| VXLAN_ENCAP_MASK_VNID_VALID
);
409 memcpy(&tlv
->value
, &vnid
, 4);
413 char *ptr
= (char *)&tlv
->value
+ 4;
414 memcpy( ptr
, bet
->mac_address
, 6);
416 extra
->encap_subtlvs
= tlv
;
421 bgp_encap_type_nvgre_to_tlv(
422 struct bgp_encap_type_nvgre
*bet
, /* input structure */
425 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
427 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_NVGRE
;
431 bgp_encap_type_mpls_to_tlv(
432 struct bgp_encap_type_mpls
*bet
, /* input structure */
435 return; /* no encap attribute for MPLS */
439 bgp_encap_type_mpls_in_gre_to_tlv(
440 struct bgp_encap_type_mpls_in_gre
*bet
, /* input structure */
443 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
445 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_GRE
;
449 bgp_encap_type_vxlan_gpe_to_tlv(
450 struct bgp_encap_type_vxlan_gpe
*bet
, /* input structure */
453 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
455 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN_GPE
;
459 bgp_encap_type_mpls_in_udp_to_tlv(
460 struct bgp_encap_type_mpls_in_udp
*bet
, /* input structure */
463 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
465 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_UDP
;
469 /***********************************************************************
471 ***********************************************************************/
474 subtlv_decode_encap_l2tpv3_over_ip(
475 struct bgp_attr_encap_subtlv
*subtlv
,
476 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
478 if (subtlv
->length
< 4) {
479 zlog_debug("%s, subtlv length %d is less than 4",
480 __func__
, subtlv
->length
);
484 st
->sessionid
= (subtlv
->value
[0] << 24) |
485 (subtlv
->value
[1] << 16) |
486 (subtlv
->value
[2] << 8) |
488 st
->cookie_length
= subtlv
->length
- 4;
489 if (st
->cookie_length
> sizeof(st
->cookie
)) {
490 zlog_debug("%s, subtlv length %d is greater than %d",
491 __func__
, st
->cookie_length
, (int)sizeof(st
->cookie
));
494 memcpy(st
->cookie
, subtlv
->value
+ 4, st
->cookie_length
);
500 subtlv_decode_encap_gre(
501 struct bgp_attr_encap_subtlv
*subtlv
,
502 struct bgp_tea_subtlv_encap_gre_key
*st
)
504 if (subtlv
->length
!= 4) {
505 zlog_debug("%s, subtlv length %d does not equal 4",
506 __func__
, subtlv
->length
);
509 st
->gre_key
= (subtlv
->value
[0] << 24) |
510 (subtlv
->value
[1] << 16) |
511 (subtlv
->value
[2] << 8) |
517 subtlv_decode_encap_pbb(
518 struct bgp_attr_encap_subtlv
*subtlv
,
519 struct bgp_tea_subtlv_encap_pbb
*st
)
521 if (subtlv
->length
!= 1 + 3 + 6 + 2) {
522 zlog_debug("%s, subtlv length %d does not equal %d",
523 __func__
, subtlv
->length
, 1 + 3 + 6 + 2);
526 if (subtlv
->value
[0] & 0x80) {
528 st
->isid
= (subtlv
->value
[1] << 16) |
529 (subtlv
->value
[2] << 8) |
532 if (subtlv
->value
[0] & 0x40) {
534 st
->vid
= ((subtlv
->value
[10] & 0x0f) << 8) | subtlv
->value
[11];
536 memcpy(st
->macaddr
, subtlv
->value
+ 4, 6);
542 subtlv_decode_proto_type(
543 struct bgp_attr_encap_subtlv
*subtlv
,
544 struct bgp_tea_subtlv_proto_type
*st
)
546 if (subtlv
->length
!= 2) {
547 zlog_debug("%s, subtlv length %d does not equal 2",
548 __func__
, subtlv
->length
);
551 st
->proto
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
558 struct bgp_attr_encap_subtlv
*subtlv
,
559 struct bgp_tea_subtlv_color
*st
)
561 if (subtlv
->length
!= 8) {
562 zlog_debug("%s, subtlv length %d does not equal 8",
563 __func__
, subtlv
->length
);
566 if ((subtlv
->value
[0] != 0x03) ||
567 (subtlv
->value
[1] != 0x0b) ||
568 (subtlv
->value
[2] != 0) ||
569 (subtlv
->value
[3] != 0)) {
570 zlog_debug("%s, subtlv value 1st 4 bytes are not 0x030b0000", __func__
);
573 st
->color
= (subtlv
->value
[4] << 24) |
574 (subtlv
->value
[5] << 16) |
575 (subtlv
->value
[6] << 8) |
582 subtlv_decode_ipsec_ta(
583 struct bgp_attr_encap_subtlv
*subtlv
,
584 struct bgp_tea_subtlv_ipsec_ta
*st
)
586 st
->authenticator_length
= subtlv
->length
- 2;
587 if (st
->authenticator_length
> sizeof(st
->value
)) {
588 zlog_debug("%s, authenticator length %d exceeds storage maximum %d",
589 __func__
, st
->authenticator_length
, (int)sizeof(st
->value
));
592 st
->authenticator_type
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
593 memcpy(st
->value
, subtlv
->value
+ 2, st
->authenticator_length
);
597 /* draft-rosen-idr-tunnel-encaps 2.1 */
599 subtlv_decode_remote_endpoint(
600 struct bgp_attr_encap_subtlv
*subtlv
,
601 struct bgp_tea_subtlv_remote_endpoint
*st
)
604 if (subtlv
->length
!= 8 && subtlv
->length
!= 20 ) {
605 zlog_debug("%s, subtlv length %d does not equal 8 or 20",
606 __func__
, subtlv
->length
);
609 if (subtlv
->length
== 8) {
610 st
->family
= AF_INET
;
611 st
->ip_address
.v4
.s_addr
= ((subtlv
->value
[0] << 24) |
612 (subtlv
->value
[1] << 16) |
613 (subtlv
->value
[2] << 8) |
616 st
->family
= AF_INET6
;
617 memcpy (&(st
->ip_address
.v6
.s6_addr
), subtlv
->value
, 16);
619 i
= subtlv
->length
- 4;
620 st
->as4
= ((subtlv
->value
[i
] << 24) |
621 (subtlv
->value
[i
+1] << 16) |
622 (subtlv
->value
[i
+2] << 8) |
627 /***********************************************************************
628 * TUNNEL TYPE-SPECIFIC TLV DECODE
629 ***********************************************************************/
632 tlv_to_bgp_encap_type_l2tpv3overip(
633 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
634 struct bgp_encap_type_l2tpv3_over_ip
*bet
) /* caller-allocated */
636 struct bgp_attr_encap_subtlv
*st
;
639 for (st
= stlv
; st
; st
= st
->next
) {
641 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
642 rc
|= subtlv_decode_encap_l2tpv3_over_ip(st
, &bet
->st_encap
);
643 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
646 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
647 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
648 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
651 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
652 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
653 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
656 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
657 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
658 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
662 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
671 tlv_to_bgp_encap_type_gre(
672 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
673 struct bgp_encap_type_gre
*bet
) /* caller-allocated */
675 struct bgp_attr_encap_subtlv
*st
;
678 for (st
= stlv
; st
; st
= st
->next
) {
680 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
681 rc
|= subtlv_decode_encap_gre(st
, &bet
->st_encap
);
682 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
685 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
686 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
687 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
690 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
691 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
692 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
695 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
696 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
697 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
701 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
710 tlv_to_bgp_encap_type_ip_in_ip(
711 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
712 struct bgp_encap_type_ip_in_ip
*bet
) /* caller-allocated */
714 struct bgp_attr_encap_subtlv
*st
;
717 for (st
= stlv
; st
; st
= st
->next
) {
719 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
720 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
721 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
724 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
725 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
726 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
729 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
730 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
731 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
735 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
744 tlv_to_bgp_encap_type_transmit_tunnel_endpoint(
745 struct bgp_attr_encap_subtlv
*stlv
,
746 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
)
748 struct bgp_attr_encap_subtlv
*st
;
751 for (st
= stlv
; st
; st
= st
->next
) {
754 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
755 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
756 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
760 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
769 tlv_to_bgp_encap_type_ipsec_in_tunnel_mode(
770 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
771 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
) /* caller-allocated */
773 struct bgp_attr_encap_subtlv
*st
;
776 for (st
= stlv
; st
; st
= st
->next
) {
778 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
779 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
780 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
783 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
784 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
785 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
789 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
798 tlv_to_bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode(
799 struct bgp_attr_encap_subtlv
*stlv
,
800 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
802 struct bgp_attr_encap_subtlv
*st
;
805 for (st
= stlv
; st
; st
= st
->next
) {
807 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
808 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
809 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
812 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
813 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
814 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
818 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
827 tlv_to_bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode(
828 struct bgp_attr_encap_subtlv
*stlv
,
829 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
831 struct bgp_attr_encap_subtlv
*st
;
834 for (st
= stlv
; st
; st
= st
->next
) {
836 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
837 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
838 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
841 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
842 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
843 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
847 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
856 tlv_to_bgp_encap_type_vxlan(
857 struct bgp_attr_encap_subtlv
*stlv
,
858 struct bgp_encap_type_vxlan
*bet
)
860 struct bgp_attr_encap_subtlv
*st
;
863 for (st
= stlv
; st
; st
= st
->next
) {
866 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
867 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
868 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
872 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
881 tlv_to_bgp_encap_type_nvgre(
882 struct bgp_attr_encap_subtlv
*stlv
,
883 struct bgp_encap_type_nvgre
*bet
)
885 struct bgp_attr_encap_subtlv
*st
;
888 for (st
= stlv
; st
; st
= st
->next
) {
891 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
892 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
893 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
897 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
906 tlv_to_bgp_encap_type_mpls(
907 struct bgp_attr_encap_subtlv
*stlv
,
908 struct bgp_encap_type_mpls
*bet
)
910 struct bgp_attr_encap_subtlv
*st
;
913 for (st
= stlv
; st
; st
= st
->next
) {
916 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
917 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
918 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
922 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
931 tlv_to_bgp_encap_type_mpls_in_gre(
932 struct bgp_attr_encap_subtlv
*stlv
,
933 struct bgp_encap_type_mpls_in_gre
*bet
)
935 struct bgp_attr_encap_subtlv
*st
;
938 for (st
= stlv
; st
; st
= st
->next
) {
941 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
942 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
943 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
947 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
956 tlv_to_bgp_encap_type_vxlan_gpe(
957 struct bgp_attr_encap_subtlv
*stlv
,
958 struct bgp_encap_type_vxlan_gpe
*bet
)
960 struct bgp_attr_encap_subtlv
*st
;
963 for (st
= stlv
; st
; st
= st
->next
) {
966 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
967 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
968 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
972 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
981 tlv_to_bgp_encap_type_mpls_in_udp(
982 struct bgp_attr_encap_subtlv
*stlv
,
983 struct bgp_encap_type_mpls_in_udp
*bet
)
985 struct bgp_attr_encap_subtlv
*st
;
988 for (st
= stlv
; st
; st
= st
->next
) {
991 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
992 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
993 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
997 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
1006 tlv_to_bgp_encap_type_pbb(
1007 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
1008 struct bgp_encap_type_pbb
*bet
) /* caller-allocated */
1010 struct bgp_attr_encap_subtlv
*st
;
1013 for (st
= stlv
; st
; st
= st
->next
) {
1015 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
1016 rc
|= subtlv_decode_encap_pbb(st
, &bet
->st_encap
);
1017 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
1020 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
1021 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
1022 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
1026 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);