2 * Copyright 2015, LabN Consulting, L.L.C.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #include "bgp_encap_types.h"
31 #include "bgp_encap_tlv.h"
33 /***********************************************************************
35 ***********************************************************************/
38 static struct bgp_attr_encap_subtlv
*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
) - 1 + total
);
52 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
56 *p
++ = (st
->sessionid
& 0xff000000) >> 24;
57 *p
++ = (st
->sessionid
& 0xff0000) >> 16;
58 *p
++ = (st
->sessionid
& 0xff00) >> 8;
59 *p
++ = (st
->sessionid
& 0xff);
60 memcpy(p
, st
->cookie
, st
->cookie_length
);
65 static struct bgp_attr_encap_subtlv
*
66 subtlv_encode_encap_gre(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
) - 1 + total
);
77 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
81 *p
++ = (st
->gre_key
& 0xff000000) >> 24;
82 *p
++ = (st
->gre_key
& 0xff0000) >> 16;
83 *p
++ = (st
->gre_key
& 0xff00) >> 8;
84 *p
++ = (st
->gre_key
& 0xff);
88 static struct bgp_attr_encap_subtlv
*
89 subtlv_encode_encap_pbb(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
) - 1 + 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
) - 1 + 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
) - 1 + 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
) - 1 + 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
) - 1 + 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
), 4);
218 assert(st
->family
== AF_INET6
);
219 memcpy(p
, &(st
->ip_address
.v6
.s6_addr
), 16);
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 extra->encap_subtlvs = new; \
247 void bgp_encap_type_l2tpv3overip_to_tlv(
248 struct bgp_encap_type_l2tpv3_over_ip
*bet
, /* input structure */
251 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
252 struct bgp_attr_encap_subtlv
*last
;
254 /* advance to last subtlv */
255 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
,
264 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
,
266 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
267 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
,
268 subtlv_encode_remote_endpoint
, st_endpoint
);
271 void 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
)
282 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_GRE
;
284 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_gre
, st_encap
);
285 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
,
287 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
288 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
,
289 subtlv_encode_remote_endpoint
, st_endpoint
);
292 void bgp_encap_type_ip_in_ip_to_tlv(
293 struct bgp_encap_type_ip_in_ip
*bet
, /* input structure */
296 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
297 struct bgp_attr_encap_subtlv
*last
;
299 /* advance to last subtlv */
300 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
303 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IP_IN_IP
;
305 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
,
307 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
308 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
,
309 subtlv_encode_remote_endpoint
, st_endpoint
);
312 void bgp_encap_type_transmit_tunnel_endpoint(
313 struct bgp_encap_type_transmit_tunnel_endpoint
314 *bet
, /* input structure */
317 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
318 struct bgp_attr_encap_subtlv
*last
;
320 /* advance to last subtlv */
321 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
324 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT
;
326 /* no subtlvs for this type */
329 void bgp_encap_type_ipsec_in_tunnel_mode_to_tlv(
330 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
, /* input structure */
333 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
334 struct bgp_attr_encap_subtlv
*last
;
336 /* advance to last subtlv */
337 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
340 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE
;
342 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
,
346 void bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
347 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
348 *bet
, /* input structure */
351 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
352 struct bgp_attr_encap_subtlv
*last
;
354 /* advance to last subtlv */
355 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
358 extra
->encap_tunneltype
=
359 BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
361 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
,
365 void bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
366 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
367 *bet
, /* input structure */
370 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
371 struct bgp_attr_encap_subtlv
*last
;
373 /* advance to last subtlv */
374 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
377 extra
->encap_tunneltype
=
378 BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
380 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
,
384 void bgp_encap_type_pbb_to_tlv(
385 struct bgp_encap_type_pbb
*bet
, /* input structure */
388 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
389 struct bgp_attr_encap_subtlv
*last
;
391 /* advance to last subtlv */
392 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
)
395 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_PBB
;
397 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
398 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_pbb
, st_encap
);
401 void bgp_encap_type_vxlan_to_tlv(
402 struct bgp_encap_type_vxlan
*bet
, /* input structure */
405 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
406 struct bgp_attr_encap_subtlv
*tlv
;
409 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN
;
411 if (bet
== NULL
|| !bet
->vnid
)
413 if (extra
->encap_subtlvs
)
414 XFREE(MTYPE_ENCAP_TLV
, extra
->encap_subtlvs
);
415 tlv
= XCALLOC(MTYPE_ENCAP_TLV
,
416 sizeof(struct bgp_attr_encap_subtlv
) - 1 + 12);
417 tlv
->type
= 1; /* encapsulation type */
420 vnid
= htonl(bet
->vnid
| VXLAN_ENCAP_MASK_VNID_VALID
);
421 memcpy(&tlv
->value
, &vnid
, 4);
423 if (bet
->mac_address
) {
424 char *ptr
= (char *)&tlv
->value
+ 4;
425 memcpy(ptr
, bet
->mac_address
, 6);
427 extra
->encap_subtlvs
= tlv
;
431 void bgp_encap_type_nvgre_to_tlv(
432 struct bgp_encap_type_nvgre
*bet
, /* input structure */
435 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
437 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_NVGRE
;
440 void bgp_encap_type_mpls_to_tlv(
441 struct bgp_encap_type_mpls
*bet
, /* input structure */
444 return; /* no encap attribute for MPLS */
447 void bgp_encap_type_mpls_in_gre_to_tlv(
448 struct bgp_encap_type_mpls_in_gre
*bet
, /* input structure */
451 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
453 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_GRE
;
456 void bgp_encap_type_vxlan_gpe_to_tlv(
457 struct bgp_encap_type_vxlan_gpe
*bet
, /* input structure */
460 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
462 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN_GPE
;
465 void bgp_encap_type_mpls_in_udp_to_tlv(
466 struct bgp_encap_type_mpls_in_udp
*bet
, /* input structure */
469 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
471 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_UDP
;
475 /***********************************************************************
477 ***********************************************************************/
479 static int subtlv_decode_encap_l2tpv3_over_ip(
480 struct bgp_attr_encap_subtlv
*subtlv
,
481 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
483 if (subtlv
->length
< 4) {
484 zlog_debug("%s, subtlv length %d is less than 4", __func__
,
489 st
->sessionid
= (subtlv
->value
[0] << 24) | (subtlv
->value
[1] << 16)
490 | (subtlv
->value
[2] << 8) | subtlv
->value
[3];
491 st
->cookie_length
= subtlv
->length
- 4;
492 if (st
->cookie_length
> sizeof(st
->cookie
)) {
493 zlog_debug("%s, subtlv length %d is greater than %d", __func__
,
494 st
->cookie_length
, (int)sizeof(st
->cookie
));
497 memcpy(st
->cookie
, subtlv
->value
+ 4, st
->cookie_length
);
502 static int subtlv_decode_encap_gre(struct bgp_attr_encap_subtlv
*subtlv
,
503 struct bgp_tea_subtlv_encap_gre_key
*st
)
505 if (subtlv
->length
!= 4) {
506 zlog_debug("%s, subtlv length %d does not equal 4", __func__
,
510 st
->gre_key
= (subtlv
->value
[0] << 24) | (subtlv
->value
[1] << 16)
511 | (subtlv
->value
[2] << 8) | subtlv
->value
[3];
515 static int subtlv_decode_encap_pbb(struct bgp_attr_encap_subtlv
*subtlv
,
516 struct bgp_tea_subtlv_encap_pbb
*st
)
518 if (subtlv
->length
!= 1 + 3 + 6 + 2) {
519 zlog_debug("%s, subtlv length %d does not equal %d", __func__
,
520 subtlv
->length
, 1 + 3 + 6 + 2);
523 if (subtlv
->value
[0] & 0x80) {
525 st
->isid
= (subtlv
->value
[1] << 16) | (subtlv
->value
[2] << 8)
528 if (subtlv
->value
[0] & 0x40) {
530 st
->vid
= ((subtlv
->value
[10] & 0x0f) << 8) | subtlv
->value
[11];
532 memcpy(st
->macaddr
, subtlv
->value
+ 4, 6);
537 static int subtlv_decode_proto_type(struct bgp_attr_encap_subtlv
*subtlv
,
538 struct bgp_tea_subtlv_proto_type
*st
)
540 if (subtlv
->length
!= 2) {
541 zlog_debug("%s, subtlv length %d does not equal 2", __func__
,
545 st
->proto
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
550 static int subtlv_decode_color(struct bgp_attr_encap_subtlv
*subtlv
,
551 struct bgp_tea_subtlv_color
*st
)
553 if (subtlv
->length
!= 8) {
554 zlog_debug("%s, subtlv length %d does not equal 8", __func__
,
558 if ((subtlv
->value
[0] != 0x03) || (subtlv
->value
[1] != 0x0b)
559 || (subtlv
->value
[2] != 0) || (subtlv
->value
[3] != 0)) {
560 zlog_debug("%s, subtlv value 1st 4 bytes are not 0x030b0000",
564 st
->color
= (subtlv
->value
[4] << 24) | (subtlv
->value
[5] << 16)
565 | (subtlv
->value
[6] << 8) | subtlv
->value
[7];
570 static int subtlv_decode_ipsec_ta(struct bgp_attr_encap_subtlv
*subtlv
,
571 struct bgp_tea_subtlv_ipsec_ta
*st
)
573 st
->authenticator_length
= subtlv
->length
- 2;
574 if (st
->authenticator_length
> sizeof(st
->value
)) {
576 "%s, authenticator length %d exceeds storage maximum %d",
577 __func__
, st
->authenticator_length
,
578 (int)sizeof(st
->value
));
581 st
->authenticator_type
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
582 memcpy(st
->value
, subtlv
->value
+ 2, st
->authenticator_length
);
586 /* draft-rosen-idr-tunnel-encaps 2.1 */
588 subtlv_decode_remote_endpoint(struct bgp_attr_encap_subtlv
*subtlv
,
589 struct bgp_tea_subtlv_remote_endpoint
*st
)
592 if (subtlv
->length
!= 8 && subtlv
->length
!= 20) {
593 zlog_debug("%s, subtlv length %d does not equal 8 or 20",
594 __func__
, subtlv
->length
);
597 if (subtlv
->length
== 8) {
598 st
->family
= AF_INET
;
599 st
->ip_address
.v4
.s_addr
=
600 ((subtlv
->value
[0] << 24) | (subtlv
->value
[1] << 16)
601 | (subtlv
->value
[2] << 8) | subtlv
->value
[3]);
603 st
->family
= AF_INET6
;
604 memcpy(&(st
->ip_address
.v6
.s6_addr
), subtlv
->value
, 16);
606 i
= subtlv
->length
- 4;
607 st
->as4
= ((subtlv
->value
[i
] << 24) | (subtlv
->value
[i
+ 1] << 16)
608 | (subtlv
->value
[i
+ 2] << 8) | subtlv
->value
[i
+ 3]);
612 /***********************************************************************
613 * TUNNEL TYPE-SPECIFIC TLV DECODE
614 ***********************************************************************/
616 int tlv_to_bgp_encap_type_l2tpv3overip(
617 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
618 struct bgp_encap_type_l2tpv3_over_ip
*bet
) /* caller-allocated */
620 struct bgp_attr_encap_subtlv
*st
;
623 for (st
= stlv
; st
; st
= st
->next
) {
625 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
626 rc
|= subtlv_decode_encap_l2tpv3_over_ip(
628 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
631 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
632 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
633 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
636 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
637 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
638 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
641 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
642 rc
|= subtlv_decode_remote_endpoint(st
,
644 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
648 zlog_debug("%s: unexpected subtlv type %d", __func__
,
657 int tlv_to_bgp_encap_type_gre(
658 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
659 struct bgp_encap_type_gre
*bet
) /* caller-allocated */
661 struct bgp_attr_encap_subtlv
*st
;
664 for (st
= stlv
; st
; st
= st
->next
) {
666 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
667 rc
|= subtlv_decode_encap_gre(st
, &bet
->st_encap
);
668 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
671 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
672 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
673 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
676 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
677 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
678 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
681 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
682 rc
|= subtlv_decode_remote_endpoint(st
,
684 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
688 zlog_debug("%s: unexpected subtlv type %d", __func__
,
697 int tlv_to_bgp_encap_type_ip_in_ip(
698 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
699 struct bgp_encap_type_ip_in_ip
*bet
) /* caller-allocated */
701 struct bgp_attr_encap_subtlv
*st
;
704 for (st
= stlv
; st
; st
= st
->next
) {
706 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
707 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
708 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
711 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
712 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
713 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
716 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
717 rc
|= subtlv_decode_remote_endpoint(st
,
719 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
723 zlog_debug("%s: unexpected subtlv type %d", __func__
,
732 int tlv_to_bgp_encap_type_transmit_tunnel_endpoint(
733 struct bgp_attr_encap_subtlv
*stlv
,
734 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
)
736 struct bgp_attr_encap_subtlv
*st
;
739 for (st
= stlv
; st
; st
= st
->next
) {
742 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
743 rc
|= subtlv_decode_remote_endpoint(st
,
745 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
749 zlog_debug("%s: unexpected subtlv type %d", __func__
,
758 int tlv_to_bgp_encap_type_ipsec_in_tunnel_mode(
759 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
760 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
) /* caller-allocated */
762 struct bgp_attr_encap_subtlv
*st
;
765 for (st
= stlv
; st
; st
= st
->next
) {
767 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
768 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
769 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
772 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
773 rc
|= subtlv_decode_remote_endpoint(st
,
775 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
779 zlog_debug("%s: unexpected subtlv type %d", __func__
,
788 int tlv_to_bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode(
789 struct bgp_attr_encap_subtlv
*stlv
,
790 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
792 struct bgp_attr_encap_subtlv
*st
;
795 for (st
= stlv
; st
; st
= st
->next
) {
797 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
798 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
799 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
802 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
803 rc
|= subtlv_decode_remote_endpoint(st
,
805 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
809 zlog_debug("%s: unexpected subtlv type %d", __func__
,
818 int tlv_to_bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode(
819 struct bgp_attr_encap_subtlv
*stlv
,
820 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
822 struct bgp_attr_encap_subtlv
*st
;
825 for (st
= stlv
; st
; st
= st
->next
) {
827 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
828 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
829 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
832 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
833 rc
|= subtlv_decode_remote_endpoint(st
,
835 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
839 zlog_debug("%s: unexpected subtlv type %d", __func__
,
848 int tlv_to_bgp_encap_type_vxlan(struct bgp_attr_encap_subtlv
*stlv
,
849 struct bgp_encap_type_vxlan
*bet
)
851 struct bgp_attr_encap_subtlv
*st
;
854 for (st
= stlv
; st
; st
= st
->next
) {
857 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
858 rc
|= subtlv_decode_remote_endpoint(st
,
860 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
864 zlog_debug("%s: unexpected subtlv type %d", __func__
,
873 int tlv_to_bgp_encap_type_nvgre(struct bgp_attr_encap_subtlv
*stlv
,
874 struct bgp_encap_type_nvgre
*bet
)
876 struct bgp_attr_encap_subtlv
*st
;
879 for (st
= stlv
; st
; st
= st
->next
) {
882 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
883 rc
|= subtlv_decode_remote_endpoint(st
,
885 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
889 zlog_debug("%s: unexpected subtlv type %d", __func__
,
898 int tlv_to_bgp_encap_type_mpls(struct bgp_attr_encap_subtlv
*stlv
,
899 struct bgp_encap_type_mpls
*bet
)
901 struct bgp_attr_encap_subtlv
*st
;
904 for (st
= stlv
; st
; st
= st
->next
) {
907 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
908 rc
|= subtlv_decode_remote_endpoint(st
,
910 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
914 zlog_debug("%s: unexpected subtlv type %d", __func__
,
923 int tlv_to_bgp_encap_type_mpls_in_gre(struct bgp_attr_encap_subtlv
*stlv
,
924 struct bgp_encap_type_mpls_in_gre
*bet
)
926 struct bgp_attr_encap_subtlv
*st
;
929 for (st
= stlv
; st
; st
= st
->next
) {
932 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
933 rc
|= subtlv_decode_remote_endpoint(st
,
935 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
939 zlog_debug("%s: unexpected subtlv type %d", __func__
,
948 int tlv_to_bgp_encap_type_vxlan_gpe(struct bgp_attr_encap_subtlv
*stlv
,
949 struct bgp_encap_type_vxlan_gpe
*bet
)
951 struct bgp_attr_encap_subtlv
*st
;
954 for (st
= stlv
; st
; st
= st
->next
) {
957 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
958 rc
|= subtlv_decode_remote_endpoint(st
,
960 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
964 zlog_debug("%s: unexpected subtlv type %d", __func__
,
973 int tlv_to_bgp_encap_type_mpls_in_udp(struct bgp_attr_encap_subtlv
*stlv
,
974 struct bgp_encap_type_mpls_in_udp
*bet
)
976 struct bgp_attr_encap_subtlv
*st
;
979 for (st
= stlv
; st
; st
= st
->next
) {
982 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
983 rc
|= subtlv_decode_remote_endpoint(st
,
985 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
989 zlog_debug("%s: unexpected subtlv type %d", __func__
,
998 int tlv_to_bgp_encap_type_pbb(
999 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
1000 struct bgp_encap_type_pbb
*bet
) /* caller-allocated */
1002 struct bgp_attr_encap_subtlv
*st
;
1005 for (st
= stlv
; st
; st
= st
->next
) {
1007 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
1008 rc
|= subtlv_decode_encap_pbb(st
, &bet
->st_encap
);
1009 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
1012 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
1013 rc
|= subtlv_decode_remote_endpoint(st
,
1015 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
1019 zlog_debug("%s: unexpected subtlv type %d", __func__
,