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
30 #include "bgp_encap_types.h"
31 #include "bgp_encap_tlv.h"
33 /***********************************************************************
35 ***********************************************************************/
38 static struct bgp_attr_encap_subtlv
*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
,
50 sizeof(struct bgp_attr_encap_subtlv
) + 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(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
,
75 sizeof(struct bgp_attr_encap_subtlv
) + 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(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
,
98 sizeof(struct bgp_attr_encap_subtlv
) + total
);
100 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
104 *p
++ = (st
->flag_isid
? 0x80 : 0) | (st
->flag_vid
? 0x40 : 0) | 0;
106 *p
= (st
->isid
& 0xff0000) >> 16;
107 *(p
+ 1) = (st
->isid
& 0xff00) >> 8;
108 *(p
+ 2) = (st
->isid
& 0xff);
111 memcpy(p
, st
->macaddr
, 6);
114 *p
++ = (st
->vid
& 0xf00) >> 8;
115 *p
++ = st
->vid
& 0xff;
121 static struct bgp_attr_encap_subtlv
*
122 subtlv_encode_proto_type(struct bgp_tea_subtlv_proto_type
*st
)
124 struct bgp_attr_encap_subtlv
*new;
128 assert(total
<= 0xff);
130 new = XCALLOC(MTYPE_ENCAP_TLV
,
131 sizeof(struct bgp_attr_encap_subtlv
) + total
);
133 new->type
= BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
;
137 *p
++ = (st
->proto
& 0xff00) >> 8;
138 *p
++ = (st
->proto
& 0xff);
143 static struct bgp_attr_encap_subtlv
*
144 subtlv_encode_color(struct bgp_tea_subtlv_color
*st
)
146 struct bgp_attr_encap_subtlv
*new;
150 assert(total
<= 0xff);
152 new = XCALLOC(MTYPE_ENCAP_TLV
,
153 sizeof(struct bgp_attr_encap_subtlv
) + total
);
155 new->type
= BGP_ENCAP_SUBTLV_TYPE_COLOR
;
159 *p
++ = 0x03; /* transitive*/
161 *p
++ = 0; /* reserved */
162 *p
++ = 0; /* reserved */
164 *p
++ = (st
->color
& 0xff000000) >> 24;
165 *p
++ = (st
->color
& 0xff0000) >> 16;
166 *p
++ = (st
->color
& 0xff00) >> 8;
167 *p
++ = (st
->color
& 0xff);
173 static struct bgp_attr_encap_subtlv
*
174 subtlv_encode_ipsec_ta(struct bgp_tea_subtlv_ipsec_ta
*st
)
176 struct bgp_attr_encap_subtlv
*new;
178 int total
= 2 + st
->authenticator_length
;
181 assert(st
->authenticator_length
<= sizeof(st
->value
));
182 assert(total
<= 0xff);
184 new = XCALLOC(MTYPE_ENCAP_TLV
,
185 sizeof(struct bgp_attr_encap_subtlv
) + total
);
187 new->type
= BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
;
191 *p
++ = (st
->authenticator_type
& 0xff00) >> 8;
192 *p
++ = st
->authenticator_type
& 0xff;
193 memcpy(p
, st
->value
, st
->authenticator_length
);
197 /* draft-rosen-idr-tunnel-encaps 2.1 */
198 static struct bgp_attr_encap_subtlv
*
199 subtlv_encode_remote_endpoint(struct bgp_tea_subtlv_remote_endpoint
*st
)
201 struct bgp_attr_encap_subtlv
*new;
204 int total
= (st
->family
== AF_INET
? 8 : 20);
206 assert(total
<= 0xff);
208 new = XCALLOC(MTYPE_ENCAP_TLV
,
209 sizeof(struct bgp_attr_encap_subtlv
) + total
);
211 new->type
= BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
;
214 if (st
->family
== AF_INET
) {
215 memcpy(p
, &(st
->ip_address
.v4
.s_addr
), IPV4_MAX_BYTELEN
);
216 p
+= IPV4_MAX_BYTELEN
;
218 assert(st
->family
== AF_INET6
);
219 memcpy(p
, &(st
->ip_address
.v6
.s6_addr
), IPV6_MAX_BYTELEN
);
220 p
+= IPV6_MAX_BYTELEN
;
222 memcpy(p
, &(st
->as4
), 4);
226 /***********************************************************************
227 * TUNNEL TYPE-SPECIFIC TLV ENCODE
228 ***********************************************************************/
231 * requires "extra" and "last" to be defined in caller
233 #define ENC_SUBTLV(flag, function, field) \
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; \
247 void bgp_encap_type_l2tpv3overip_to_tlv(
248 struct bgp_encap_type_l2tpv3_over_ip
*bet
, /* input structure */
251 struct bgp_attr_encap_subtlv
*last
;
253 /* advance to last subtlv */
254 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
,
263 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
,
265 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
266 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
,
267 subtlv_encode_remote_endpoint
, st_endpoint
);
270 void bgp_encap_type_gre_to_tlv(
271 struct bgp_encap_type_gre
*bet
, /* input structure */
274 struct bgp_attr_encap_subtlv
*last
;
276 /* advance to last subtlv */
277 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
280 attr
->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
,
285 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
286 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
,
287 subtlv_encode_remote_endpoint
, st_endpoint
);
290 void bgp_encap_type_ip_in_ip_to_tlv(
291 struct bgp_encap_type_ip_in_ip
*bet
, /* input structure */
294 struct bgp_attr_encap_subtlv
*last
;
296 /* advance to last subtlv */
297 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
300 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_IP_IN_IP
;
302 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
,
304 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
305 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
,
306 subtlv_encode_remote_endpoint
, st_endpoint
);
309 void bgp_encap_type_transmit_tunnel_endpoint(
310 struct bgp_encap_type_transmit_tunnel_endpoint
311 *bet
, /* input structure */
314 struct bgp_attr_encap_subtlv
*last
;
316 /* advance to last subtlv */
317 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
320 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT
;
322 /* no subtlvs for this type */
325 void bgp_encap_type_ipsec_in_tunnel_mode_to_tlv(
326 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
, /* input structure */
329 struct bgp_attr_encap_subtlv
*last
;
331 /* advance to last subtlv */
332 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
335 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE
;
337 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
,
341 void bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
342 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
343 *bet
, /* input structure */
346 struct bgp_attr_encap_subtlv
*last
;
348 /* advance to last subtlv */
349 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
352 attr
->encap_tunneltype
=
353 BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
355 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
,
359 void bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
360 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
361 *bet
, /* input structure */
364 struct bgp_attr_encap_subtlv
*last
;
366 /* advance to last subtlv */
367 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
370 attr
->encap_tunneltype
=
371 BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
373 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
,
377 void bgp_encap_type_pbb_to_tlv(
378 struct bgp_encap_type_pbb
*bet
, /* input structure */
381 struct bgp_attr_encap_subtlv
*last
;
383 /* advance to last subtlv */
384 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
387 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_PBB
;
389 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
390 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_pbb
, st_encap
);
393 void bgp_encap_type_vxlan_to_tlv(
394 struct bgp_encap_type_vxlan
*bet
, /* input structure */
397 struct bgp_attr_encap_subtlv
*tlv
;
400 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN
;
402 if (bet
== NULL
|| !bet
->vnid
)
404 XFREE(MTYPE_ENCAP_TLV
, attr
->encap_subtlvs
);
405 tlv
= XCALLOC(MTYPE_ENCAP_TLV
,
406 sizeof(struct bgp_attr_encap_subtlv
) + 12);
407 tlv
->type
= 1; /* encapsulation type */
410 vnid
= htonl(bet
->vnid
| VXLAN_ENCAP_MASK_VNID_VALID
);
411 memcpy(&tlv
->value
, &vnid
, 4);
413 if (bet
->mac_address
) {
414 char *ptr
= (char *)&tlv
->value
+ 4;
415 memcpy(ptr
, bet
->mac_address
, 6);
417 attr
->encap_subtlvs
= tlv
;
421 void bgp_encap_type_nvgre_to_tlv(
422 struct bgp_encap_type_nvgre
*bet
, /* input structure */
425 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_NVGRE
;
428 void bgp_encap_type_mpls_to_tlv(
429 struct bgp_encap_type_mpls
*bet
, /* input structure */
432 return; /* no encap attribute for MPLS */
435 void bgp_encap_type_mpls_in_gre_to_tlv(
436 struct bgp_encap_type_mpls_in_gre
*bet
, /* input structure */
439 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_GRE
;
442 void bgp_encap_type_vxlan_gpe_to_tlv(
443 struct bgp_encap_type_vxlan_gpe
*bet
, /* input structure */
447 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN_GPE
;
450 void bgp_encap_type_mpls_in_udp_to_tlv(
451 struct bgp_encap_type_mpls_in_udp
*bet
, /* input structure */
455 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_UDP
;
459 /***********************************************************************
461 ***********************************************************************/
463 static int subtlv_decode_encap_l2tpv3_over_ip(
464 struct bgp_attr_encap_subtlv
*subtlv
,
465 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
467 if (subtlv
->length
< 4) {
468 zlog_debug("%s, subtlv length %d is less than 4", __func__
,
473 ptr_get_be32(subtlv
->value
, &st
->sessionid
);
474 st
->cookie_length
= subtlv
->length
- 4;
475 if (st
->cookie_length
> sizeof(st
->cookie
)) {
476 zlog_debug("%s, subtlv length %d is greater than %d", __func__
,
477 st
->cookie_length
, (int)sizeof(st
->cookie
));
480 memcpy(st
->cookie
, subtlv
->value
+ 4, st
->cookie_length
);
485 static int subtlv_decode_encap_gre(struct bgp_attr_encap_subtlv
*subtlv
,
486 struct bgp_tea_subtlv_encap_gre_key
*st
)
488 if (subtlv
->length
!= 4) {
489 zlog_debug("%s, subtlv length %d does not equal 4", __func__
,
493 ptr_get_be32(subtlv
->value
, &st
->gre_key
);
497 static int subtlv_decode_encap_pbb(struct bgp_attr_encap_subtlv
*subtlv
,
498 struct bgp_tea_subtlv_encap_pbb
*st
)
500 if (subtlv
->length
!= 1 + 3 + 6 + 2) {
501 zlog_debug("%s, subtlv length %d does not equal %d", __func__
,
502 subtlv
->length
, 1 + 3 + 6 + 2);
505 if (subtlv
->value
[0] & 0x80) {
507 st
->isid
= (subtlv
->value
[1] << 16) | (subtlv
->value
[2] << 8)
510 if (subtlv
->value
[0] & 0x40) {
512 st
->vid
= ((subtlv
->value
[10] & 0x0f) << 8) | subtlv
->value
[11];
514 memcpy(st
->macaddr
, subtlv
->value
+ 4, 6);
519 static int subtlv_decode_proto_type(struct bgp_attr_encap_subtlv
*subtlv
,
520 struct bgp_tea_subtlv_proto_type
*st
)
522 if (subtlv
->length
!= 2) {
523 zlog_debug("%s, subtlv length %d does not equal 2", __func__
,
527 st
->proto
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
532 static int subtlv_decode_color(struct bgp_attr_encap_subtlv
*subtlv
,
533 struct bgp_tea_subtlv_color
*st
)
535 if (subtlv
->length
!= 8) {
536 zlog_debug("%s, subtlv length %d does not equal 8", __func__
,
540 if ((subtlv
->value
[0] != 0x03) || (subtlv
->value
[1] != 0x0b)
541 || (subtlv
->value
[2] != 0) || (subtlv
->value
[3] != 0)) {
542 zlog_debug("%s, subtlv value 1st 4 bytes are not 0x030b0000",
546 ptr_get_be32(subtlv
->value
+ 4, &st
->color
);
551 static int subtlv_decode_ipsec_ta(struct bgp_attr_encap_subtlv
*subtlv
,
552 struct bgp_tea_subtlv_ipsec_ta
*st
)
554 st
->authenticator_length
= subtlv
->length
- 2;
555 if (st
->authenticator_length
> sizeof(st
->value
)) {
557 "%s, authenticator length %d exceeds storage maximum %d",
558 __func__
, st
->authenticator_length
,
559 (int)sizeof(st
->value
));
562 st
->authenticator_type
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
563 memcpy(st
->value
, subtlv
->value
+ 2, st
->authenticator_length
);
567 /* draft-rosen-idr-tunnel-encaps 2.1 */
569 subtlv_decode_remote_endpoint(struct bgp_attr_encap_subtlv
*subtlv
,
570 struct bgp_tea_subtlv_remote_endpoint
*st
)
573 if (subtlv
->length
!= 8 && subtlv
->length
!= 20) {
574 zlog_debug("%s, subtlv length %d does not equal 8 or 20",
575 __func__
, subtlv
->length
);
578 if (subtlv
->length
== 8) {
579 st
->family
= AF_INET
;
580 memcpy(&st
->ip_address
.v4
.s_addr
, subtlv
->value
,
583 st
->family
= AF_INET6
;
584 memcpy(&(st
->ip_address
.v6
.s6_addr
), subtlv
->value
,
587 i
= subtlv
->length
- 4;
588 ptr_get_be32(subtlv
->value
+ i
, &st
->as4
);
592 /***********************************************************************
593 * TUNNEL TYPE-SPECIFIC TLV DECODE
594 ***********************************************************************/
596 int tlv_to_bgp_encap_type_l2tpv3overip(
597 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
598 struct bgp_encap_type_l2tpv3_over_ip
*bet
) /* caller-allocated */
600 struct bgp_attr_encap_subtlv
*st
;
603 for (st
= stlv
; st
; st
= st
->next
) {
605 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
606 rc
|= subtlv_decode_encap_l2tpv3_over_ip(
608 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
611 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
612 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
613 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
616 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
617 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
618 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
621 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
622 rc
|= subtlv_decode_remote_endpoint(st
,
624 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
628 zlog_debug("%s: unexpected subtlv type %d", __func__
,
637 int tlv_to_bgp_encap_type_gre(
638 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
639 struct bgp_encap_type_gre
*bet
) /* caller-allocated */
641 struct bgp_attr_encap_subtlv
*st
;
644 for (st
= stlv
; st
; st
= st
->next
) {
646 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
647 rc
|= subtlv_decode_encap_gre(st
, &bet
->st_encap
);
648 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
651 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
652 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
653 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
656 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
657 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
658 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
661 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
662 rc
|= subtlv_decode_remote_endpoint(st
,
664 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
668 zlog_debug("%s: unexpected subtlv type %d", __func__
,
677 int tlv_to_bgp_encap_type_ip_in_ip(
678 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
679 struct bgp_encap_type_ip_in_ip
*bet
) /* caller-allocated */
681 struct bgp_attr_encap_subtlv
*st
;
684 for (st
= stlv
; st
; st
= st
->next
) {
686 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
687 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
688 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
691 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
692 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
693 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
696 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
697 rc
|= subtlv_decode_remote_endpoint(st
,
699 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
703 zlog_debug("%s: unexpected subtlv type %d", __func__
,
712 int tlv_to_bgp_encap_type_transmit_tunnel_endpoint(
713 struct bgp_attr_encap_subtlv
*stlv
,
714 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
)
716 struct bgp_attr_encap_subtlv
*st
;
719 for (st
= stlv
; st
; st
= st
->next
) {
722 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
723 rc
|= subtlv_decode_remote_endpoint(st
,
725 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
729 zlog_debug("%s: unexpected subtlv type %d", __func__
,
738 int tlv_to_bgp_encap_type_ipsec_in_tunnel_mode(
739 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
740 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
) /* caller-allocated */
742 struct bgp_attr_encap_subtlv
*st
;
745 for (st
= stlv
; st
; st
= st
->next
) {
747 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
748 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
749 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
752 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
753 rc
|= subtlv_decode_remote_endpoint(st
,
755 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
759 zlog_debug("%s: unexpected subtlv type %d", __func__
,
768 int tlv_to_bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode(
769 struct bgp_attr_encap_subtlv
*stlv
,
770 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
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
,
785 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
789 zlog_debug("%s: unexpected subtlv type %d", __func__
,
798 int tlv_to_bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode(
799 struct bgp_attr_encap_subtlv
*stlv
,
800 struct bgp_encap_type_mpls_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
,
815 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
819 zlog_debug("%s: unexpected subtlv type %d", __func__
,
828 int tlv_to_bgp_encap_type_vxlan(struct bgp_attr_encap_subtlv
*stlv
,
829 struct bgp_encap_type_vxlan
*bet
)
831 struct bgp_attr_encap_subtlv
*st
;
834 for (st
= stlv
; st
; st
= st
->next
) {
837 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
838 rc
|= subtlv_decode_remote_endpoint(st
,
840 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
844 zlog_debug("%s: unexpected subtlv type %d", __func__
,
853 int tlv_to_bgp_encap_type_nvgre(struct bgp_attr_encap_subtlv
*stlv
,
854 struct bgp_encap_type_nvgre
*bet
)
856 struct bgp_attr_encap_subtlv
*st
;
859 for (st
= stlv
; st
; st
= st
->next
) {
862 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
863 rc
|= subtlv_decode_remote_endpoint(st
,
865 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
869 zlog_debug("%s: unexpected subtlv type %d", __func__
,
878 int tlv_to_bgp_encap_type_mpls(struct bgp_attr_encap_subtlv
*stlv
,
879 struct bgp_encap_type_mpls
*bet
)
881 struct bgp_attr_encap_subtlv
*st
;
884 for (st
= stlv
; st
; st
= st
->next
) {
887 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
888 rc
|= subtlv_decode_remote_endpoint(st
,
890 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
894 zlog_debug("%s: unexpected subtlv type %d", __func__
,
903 int tlv_to_bgp_encap_type_mpls_in_gre(struct bgp_attr_encap_subtlv
*stlv
,
904 struct bgp_encap_type_mpls_in_gre
*bet
)
906 struct bgp_attr_encap_subtlv
*st
;
909 for (st
= stlv
; st
; st
= st
->next
) {
912 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
913 rc
|= subtlv_decode_remote_endpoint(st
,
915 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
919 zlog_debug("%s: unexpected subtlv type %d", __func__
,
928 int tlv_to_bgp_encap_type_vxlan_gpe(struct bgp_attr_encap_subtlv
*stlv
,
929 struct bgp_encap_type_vxlan_gpe
*bet
)
931 struct bgp_attr_encap_subtlv
*st
;
934 for (st
= stlv
; st
; st
= st
->next
) {
937 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
938 rc
|= subtlv_decode_remote_endpoint(st
,
940 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
944 zlog_debug("%s: unexpected subtlv type %d", __func__
,
953 int tlv_to_bgp_encap_type_mpls_in_udp(struct bgp_attr_encap_subtlv
*stlv
,
954 struct bgp_encap_type_mpls_in_udp
*bet
)
956 struct bgp_attr_encap_subtlv
*st
;
959 for (st
= stlv
; st
; st
= st
->next
) {
962 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
963 rc
|= subtlv_decode_remote_endpoint(st
,
965 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
969 zlog_debug("%s: unexpected subtlv type %d", __func__
,
978 int tlv_to_bgp_encap_type_pbb(
979 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
980 struct bgp_encap_type_pbb
*bet
) /* caller-allocated */
982 struct bgp_attr_encap_subtlv
*st
;
985 for (st
= stlv
; st
; st
= st
->next
) {
987 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
988 rc
|= subtlv_decode_encap_pbb(st
, &bet
->st_encap
);
989 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
992 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
993 rc
|= subtlv_decode_remote_endpoint(st
,
995 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
999 zlog_debug("%s: unexpected subtlv type %d", __func__
,