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
*subtlv_encode_encap_l2tpv3_over_ip(
38 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
40 struct bgp_attr_encap_subtlv
*new;
42 int total
= 4 + st
->cookie_length
;
45 assert(st
->cookie_length
<= sizeof(st
->cookie
));
46 assert(total
<= 0xff);
48 new = XCALLOC(MTYPE_ENCAP_TLV
,
49 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(struct bgp_tea_subtlv_encap_gre_key
*st
)
67 struct bgp_attr_encap_subtlv
*new;
71 assert(total
<= 0xff);
73 new = XCALLOC(MTYPE_ENCAP_TLV
,
74 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(struct bgp_tea_subtlv_encap_pbb
*st
)
90 struct bgp_attr_encap_subtlv
*new;
92 int total
= 1 + 3 + 6 + 2; /* flags + isid + madaddr + vid */
94 assert(total
<= 0xff);
96 new = XCALLOC(MTYPE_ENCAP_TLV
,
97 sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
99 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
103 *p
++ = (st
->flag_isid
? 0x80 : 0) | (st
->flag_vid
? 0x40 : 0) | 0;
105 *p
= (st
->isid
& 0xff0000) >> 16;
106 *(p
+ 1) = (st
->isid
& 0xff00) >> 8;
107 *(p
+ 2) = (st
->isid
& 0xff);
110 memcpy(p
, st
->macaddr
, 6);
113 *p
++ = (st
->vid
& 0xf00) >> 8;
114 *p
++ = st
->vid
& 0xff;
120 static struct bgp_attr_encap_subtlv
*
121 subtlv_encode_proto_type(struct bgp_tea_subtlv_proto_type
*st
)
123 struct bgp_attr_encap_subtlv
*new;
127 assert(total
<= 0xff);
129 new = XCALLOC(MTYPE_ENCAP_TLV
,
130 sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
132 new->type
= BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
;
136 *p
++ = (st
->proto
& 0xff00) >> 8;
137 *p
++ = (st
->proto
& 0xff);
142 static struct bgp_attr_encap_subtlv
*
143 subtlv_encode_color(struct bgp_tea_subtlv_color
*st
)
145 struct bgp_attr_encap_subtlv
*new;
149 assert(total
<= 0xff);
151 new = XCALLOC(MTYPE_ENCAP_TLV
,
152 sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
154 new->type
= BGP_ENCAP_SUBTLV_TYPE_COLOR
;
158 *p
++ = 0x03; /* transitive*/
160 *p
++ = 0; /* reserved */
161 *p
++ = 0; /* reserved */
163 *p
++ = (st
->color
& 0xff000000) >> 24;
164 *p
++ = (st
->color
& 0xff0000) >> 16;
165 *p
++ = (st
->color
& 0xff00) >> 8;
166 *p
++ = (st
->color
& 0xff);
172 static struct bgp_attr_encap_subtlv
*
173 subtlv_encode_ipsec_ta(struct bgp_tea_subtlv_ipsec_ta
*st
)
175 struct bgp_attr_encap_subtlv
*new;
177 int total
= 2 + st
->authenticator_length
;
180 assert(st
->authenticator_length
<= sizeof(st
->value
));
181 assert(total
<= 0xff);
183 new = XCALLOC(MTYPE_ENCAP_TLV
,
184 sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
186 new->type
= BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
;
190 *p
++ = (st
->authenticator_type
& 0xff00) >> 8;
191 *p
++ = st
->authenticator_type
& 0xff;
192 memcpy(p
, st
->value
, st
->authenticator_length
);
196 /* draft-rosen-idr-tunnel-encaps 2.1 */
197 static struct bgp_attr_encap_subtlv
*
198 subtlv_encode_remote_endpoint(struct bgp_tea_subtlv_remote_endpoint
*st
)
200 struct bgp_attr_encap_subtlv
*new;
203 int total
= (st
->family
== AF_INET
? 8 : 20);
205 assert(total
<= 0xff);
207 new = XCALLOC(MTYPE_ENCAP_TLV
,
208 sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
210 new->type
= BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
;
213 if (st
->family
== AF_INET
) {
214 memcpy(p
, &(st
->ip_address
.v4
.s_addr
), 4);
217 assert(st
->family
== AF_INET6
);
218 memcpy(p
, &(st
->ip_address
.v6
.s6_addr
), 16);
221 memcpy(p
, &(st
->as4
), 4);
225 /***********************************************************************
226 * TUNNEL TYPE-SPECIFIC TLV ENCODE
227 ***********************************************************************/
230 * requires "extra" and "last" to be defined in caller
232 #define ENC_SUBTLV(flag, function, field) \
234 struct bgp_attr_encap_subtlv *new; \
235 if (CHECK_FLAG(bet->valid_subtlvs, (flag))) { \
236 new = function(&bet->field); \
240 attr->encap_subtlvs = new; \
246 void bgp_encap_type_l2tpv3overip_to_tlv(
247 struct bgp_encap_type_l2tpv3_over_ip
*bet
, /* input structure */
250 struct bgp_attr_encap_subtlv
*last
;
252 /* advance to last subtlv */
253 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
256 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_L2TPV3_OVER_IP
;
258 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
260 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_l2tpv3_over_ip
,
262 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
,
264 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
265 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
,
266 subtlv_encode_remote_endpoint
, st_endpoint
);
269 void bgp_encap_type_gre_to_tlv(
270 struct bgp_encap_type_gre
*bet
, /* input structure */
273 struct bgp_attr_encap_subtlv
*last
;
275 /* advance to last subtlv */
276 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
279 attr
->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
,
284 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
285 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
,
286 subtlv_encode_remote_endpoint
, st_endpoint
);
289 void bgp_encap_type_ip_in_ip_to_tlv(
290 struct bgp_encap_type_ip_in_ip
*bet
, /* input structure */
293 struct bgp_attr_encap_subtlv
*last
;
295 /* advance to last subtlv */
296 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
299 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_IP_IN_IP
;
301 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
,
303 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
304 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
,
305 subtlv_encode_remote_endpoint
, st_endpoint
);
308 void bgp_encap_type_transmit_tunnel_endpoint(
309 struct bgp_encap_type_transmit_tunnel_endpoint
310 *bet
, /* input structure */
313 struct bgp_attr_encap_subtlv
*last
;
315 /* advance to last subtlv */
316 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
319 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT
;
321 /* no subtlvs for this type */
324 void bgp_encap_type_ipsec_in_tunnel_mode_to_tlv(
325 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
, /* input structure */
328 struct bgp_attr_encap_subtlv
*last
;
330 /* advance to last subtlv */
331 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
334 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE
;
336 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
,
340 void 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
342 *bet
, /* input structure */
345 struct bgp_attr_encap_subtlv
*last
;
347 /* advance to last subtlv */
348 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
351 attr
->encap_tunneltype
=
352 BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
354 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
,
358 void bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
359 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
360 *bet
, /* input structure */
363 struct bgp_attr_encap_subtlv
*last
;
365 /* advance to last subtlv */
366 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
369 attr
->encap_tunneltype
=
370 BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
372 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
,
376 void bgp_encap_type_pbb_to_tlv(
377 struct bgp_encap_type_pbb
*bet
, /* input structure */
380 struct bgp_attr_encap_subtlv
*last
;
382 /* advance to last subtlv */
383 for (last
= attr
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
386 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_PBB
;
388 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
389 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_pbb
, st_encap
);
392 void bgp_encap_type_vxlan_to_tlv(
393 struct bgp_encap_type_vxlan
*bet
, /* input structure */
396 struct bgp_attr_encap_subtlv
*tlv
;
399 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN
;
401 if (bet
== NULL
|| !bet
->vnid
)
403 if (attr
->encap_subtlvs
)
404 XFREE(MTYPE_ENCAP_TLV
, attr
->encap_subtlvs
);
405 tlv
= XCALLOC(MTYPE_ENCAP_TLV
,
406 sizeof(struct bgp_attr_encap_subtlv
) - 1 + 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 st
->sessionid
= (subtlv
->value
[0] << 24) | (subtlv
->value
[1] << 16)
474 | (subtlv
->value
[2] << 8) | subtlv
->value
[3];
475 st
->cookie_length
= subtlv
->length
- 4;
476 if (st
->cookie_length
> sizeof(st
->cookie
)) {
477 zlog_debug("%s, subtlv length %d is greater than %d", __func__
,
478 st
->cookie_length
, (int)sizeof(st
->cookie
));
481 memcpy(st
->cookie
, subtlv
->value
+ 4, st
->cookie_length
);
486 static int subtlv_decode_encap_gre(struct bgp_attr_encap_subtlv
*subtlv
,
487 struct bgp_tea_subtlv_encap_gre_key
*st
)
489 if (subtlv
->length
!= 4) {
490 zlog_debug("%s, subtlv length %d does not equal 4", __func__
,
494 st
->gre_key
= (subtlv
->value
[0] << 24) | (subtlv
->value
[1] << 16)
495 | (subtlv
->value
[2] << 8) | subtlv
->value
[3];
499 static int subtlv_decode_encap_pbb(struct bgp_attr_encap_subtlv
*subtlv
,
500 struct bgp_tea_subtlv_encap_pbb
*st
)
502 if (subtlv
->length
!= 1 + 3 + 6 + 2) {
503 zlog_debug("%s, subtlv length %d does not equal %d", __func__
,
504 subtlv
->length
, 1 + 3 + 6 + 2);
507 if (subtlv
->value
[0] & 0x80) {
509 st
->isid
= (subtlv
->value
[1] << 16) | (subtlv
->value
[2] << 8)
512 if (subtlv
->value
[0] & 0x40) {
514 st
->vid
= ((subtlv
->value
[10] & 0x0f) << 8) | subtlv
->value
[11];
516 memcpy(st
->macaddr
, subtlv
->value
+ 4, 6);
521 static int subtlv_decode_proto_type(struct bgp_attr_encap_subtlv
*subtlv
,
522 struct bgp_tea_subtlv_proto_type
*st
)
524 if (subtlv
->length
!= 2) {
525 zlog_debug("%s, subtlv length %d does not equal 2", __func__
,
529 st
->proto
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
534 static int subtlv_decode_color(struct bgp_attr_encap_subtlv
*subtlv
,
535 struct bgp_tea_subtlv_color
*st
)
537 if (subtlv
->length
!= 8) {
538 zlog_debug("%s, subtlv length %d does not equal 8", __func__
,
542 if ((subtlv
->value
[0] != 0x03) || (subtlv
->value
[1] != 0x0b)
543 || (subtlv
->value
[2] != 0) || (subtlv
->value
[3] != 0)) {
544 zlog_debug("%s, subtlv value 1st 4 bytes are not 0x030b0000",
548 st
->color
= (subtlv
->value
[4] << 24) | (subtlv
->value
[5] << 16)
549 | (subtlv
->value
[6] << 8) | subtlv
->value
[7];
554 static int subtlv_decode_ipsec_ta(struct bgp_attr_encap_subtlv
*subtlv
,
555 struct bgp_tea_subtlv_ipsec_ta
*st
)
557 st
->authenticator_length
= subtlv
->length
- 2;
558 if (st
->authenticator_length
> sizeof(st
->value
)) {
560 "%s, authenticator length %d exceeds storage maximum %d",
561 __func__
, st
->authenticator_length
,
562 (int)sizeof(st
->value
));
565 st
->authenticator_type
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
566 memcpy(st
->value
, subtlv
->value
+ 2, st
->authenticator_length
);
570 /* draft-rosen-idr-tunnel-encaps 2.1 */
572 subtlv_decode_remote_endpoint(struct bgp_attr_encap_subtlv
*subtlv
,
573 struct bgp_tea_subtlv_remote_endpoint
*st
)
576 if (subtlv
->length
!= 8 && subtlv
->length
!= 20) {
577 zlog_debug("%s, subtlv length %d does not equal 8 or 20",
578 __func__
, subtlv
->length
);
581 if (subtlv
->length
== 8) {
582 st
->family
= AF_INET
;
583 st
->ip_address
.v4
.s_addr
=
584 ((subtlv
->value
[0] << 24) | (subtlv
->value
[1] << 16)
585 | (subtlv
->value
[2] << 8) | subtlv
->value
[3]);
587 st
->family
= AF_INET6
;
588 memcpy(&(st
->ip_address
.v6
.s6_addr
), subtlv
->value
, 16);
590 i
= subtlv
->length
- 4;
591 st
->as4
= ((subtlv
->value
[i
] << 24) | (subtlv
->value
[i
+ 1] << 16)
592 | (subtlv
->value
[i
+ 2] << 8) | subtlv
->value
[i
+ 3]);
596 /***********************************************************************
597 * TUNNEL TYPE-SPECIFIC TLV DECODE
598 ***********************************************************************/
600 int tlv_to_bgp_encap_type_l2tpv3overip(
601 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
602 struct bgp_encap_type_l2tpv3_over_ip
*bet
) /* caller-allocated */
604 struct bgp_attr_encap_subtlv
*st
;
607 for (st
= stlv
; st
; st
= st
->next
) {
609 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
610 rc
|= subtlv_decode_encap_l2tpv3_over_ip(
612 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
615 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
616 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
617 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
620 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
621 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
622 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
625 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
626 rc
|= subtlv_decode_remote_endpoint(st
,
628 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
632 zlog_debug("%s: unexpected subtlv type %d", __func__
,
641 int tlv_to_bgp_encap_type_gre(
642 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
643 struct bgp_encap_type_gre
*bet
) /* caller-allocated */
645 struct bgp_attr_encap_subtlv
*st
;
648 for (st
= stlv
; st
; st
= st
->next
) {
650 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
651 rc
|= subtlv_decode_encap_gre(st
, &bet
->st_encap
);
652 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
655 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
656 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
657 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
660 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
661 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
662 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
665 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
666 rc
|= subtlv_decode_remote_endpoint(st
,
668 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
672 zlog_debug("%s: unexpected subtlv type %d", __func__
,
681 int tlv_to_bgp_encap_type_ip_in_ip(
682 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
683 struct bgp_encap_type_ip_in_ip
*bet
) /* caller-allocated */
685 struct bgp_attr_encap_subtlv
*st
;
688 for (st
= stlv
; st
; st
= st
->next
) {
690 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
691 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
692 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
695 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
696 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
697 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
700 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
701 rc
|= subtlv_decode_remote_endpoint(st
,
703 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
707 zlog_debug("%s: unexpected subtlv type %d", __func__
,
716 int tlv_to_bgp_encap_type_transmit_tunnel_endpoint(
717 struct bgp_attr_encap_subtlv
*stlv
,
718 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
)
720 struct bgp_attr_encap_subtlv
*st
;
723 for (st
= stlv
; st
; st
= st
->next
) {
726 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
727 rc
|= subtlv_decode_remote_endpoint(st
,
729 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
733 zlog_debug("%s: unexpected subtlv type %d", __func__
,
742 int tlv_to_bgp_encap_type_ipsec_in_tunnel_mode(
743 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
744 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
) /* caller-allocated */
746 struct bgp_attr_encap_subtlv
*st
;
749 for (st
= stlv
; st
; st
= st
->next
) {
751 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
752 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
753 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
756 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
757 rc
|= subtlv_decode_remote_endpoint(st
,
759 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
763 zlog_debug("%s: unexpected subtlv type %d", __func__
,
772 int tlv_to_bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode(
773 struct bgp_attr_encap_subtlv
*stlv
,
774 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
776 struct bgp_attr_encap_subtlv
*st
;
779 for (st
= stlv
; st
; st
= st
->next
) {
781 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
782 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
783 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
786 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
787 rc
|= subtlv_decode_remote_endpoint(st
,
789 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
793 zlog_debug("%s: unexpected subtlv type %d", __func__
,
802 int tlv_to_bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode(
803 struct bgp_attr_encap_subtlv
*stlv
,
804 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
806 struct bgp_attr_encap_subtlv
*st
;
809 for (st
= stlv
; st
; st
= st
->next
) {
811 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
812 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
813 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
816 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
817 rc
|= subtlv_decode_remote_endpoint(st
,
819 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
823 zlog_debug("%s: unexpected subtlv type %d", __func__
,
832 int tlv_to_bgp_encap_type_vxlan(struct bgp_attr_encap_subtlv
*stlv
,
833 struct bgp_encap_type_vxlan
*bet
)
835 struct bgp_attr_encap_subtlv
*st
;
838 for (st
= stlv
; st
; st
= st
->next
) {
841 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
842 rc
|= subtlv_decode_remote_endpoint(st
,
844 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
848 zlog_debug("%s: unexpected subtlv type %d", __func__
,
857 int tlv_to_bgp_encap_type_nvgre(struct bgp_attr_encap_subtlv
*stlv
,
858 struct bgp_encap_type_nvgre
*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
,
869 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
873 zlog_debug("%s: unexpected subtlv type %d", __func__
,
882 int tlv_to_bgp_encap_type_mpls(struct bgp_attr_encap_subtlv
*stlv
,
883 struct bgp_encap_type_mpls
*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
,
894 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
898 zlog_debug("%s: unexpected subtlv type %d", __func__
,
907 int tlv_to_bgp_encap_type_mpls_in_gre(struct bgp_attr_encap_subtlv
*stlv
,
908 struct bgp_encap_type_mpls_in_gre
*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
,
919 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
923 zlog_debug("%s: unexpected subtlv type %d", __func__
,
932 int tlv_to_bgp_encap_type_vxlan_gpe(struct bgp_attr_encap_subtlv
*stlv
,
933 struct bgp_encap_type_vxlan_gpe
*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
,
944 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
948 zlog_debug("%s: unexpected subtlv type %d", __func__
,
957 int tlv_to_bgp_encap_type_mpls_in_udp(struct bgp_attr_encap_subtlv
*stlv
,
958 struct bgp_encap_type_mpls_in_udp
*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
,
969 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
973 zlog_debug("%s: unexpected subtlv type %d", __func__
,
982 int tlv_to_bgp_encap_type_pbb(
983 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
984 struct bgp_encap_type_pbb
*bet
) /* caller-allocated */
986 struct bgp_attr_encap_subtlv
*st
;
989 for (st
= stlv
; st
; st
= st
->next
) {
991 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
992 rc
|= subtlv_decode_encap_pbb(st
, &bet
->st_encap
);
993 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
996 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
997 rc
|= subtlv_decode_remote_endpoint(st
,
999 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
1003 zlog_debug("%s: unexpected subtlv type %d", __func__
,