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
), 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 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 if (attr
->encap_subtlvs
)
405 XFREE(MTYPE_ENCAP_TLV
, attr
->encap_subtlvs
);
406 tlv
= XCALLOC(MTYPE_ENCAP_TLV
,
407 sizeof(struct bgp_attr_encap_subtlv
) + 12);
408 tlv
->type
= 1; /* encapsulation type */
411 vnid
= htonl(bet
->vnid
| VXLAN_ENCAP_MASK_VNID_VALID
);
412 memcpy(&tlv
->value
, &vnid
, 4);
414 if (bet
->mac_address
) {
415 char *ptr
= (char *)&tlv
->value
+ 4;
416 memcpy(ptr
, bet
->mac_address
, 6);
418 attr
->encap_subtlvs
= tlv
;
422 void bgp_encap_type_nvgre_to_tlv(
423 struct bgp_encap_type_nvgre
*bet
, /* input structure */
426 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_NVGRE
;
429 void bgp_encap_type_mpls_to_tlv(
430 struct bgp_encap_type_mpls
*bet
, /* input structure */
433 return; /* no encap attribute for MPLS */
436 void bgp_encap_type_mpls_in_gre_to_tlv(
437 struct bgp_encap_type_mpls_in_gre
*bet
, /* input structure */
440 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_GRE
;
443 void bgp_encap_type_vxlan_gpe_to_tlv(
444 struct bgp_encap_type_vxlan_gpe
*bet
, /* input structure */
448 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN_GPE
;
451 void bgp_encap_type_mpls_in_udp_to_tlv(
452 struct bgp_encap_type_mpls_in_udp
*bet
, /* input structure */
456 attr
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_UDP
;
460 /***********************************************************************
462 ***********************************************************************/
464 static int subtlv_decode_encap_l2tpv3_over_ip(
465 struct bgp_attr_encap_subtlv
*subtlv
,
466 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
468 if (subtlv
->length
< 4) {
469 zlog_debug("%s, subtlv length %d is less than 4", __func__
,
474 ptr_get_be32(subtlv
->value
, &st
->sessionid
);
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 ptr_get_be32(subtlv
->value
, &st
->gre_key
);
498 static int subtlv_decode_encap_pbb(struct bgp_attr_encap_subtlv
*subtlv
,
499 struct bgp_tea_subtlv_encap_pbb
*st
)
501 if (subtlv
->length
!= 1 + 3 + 6 + 2) {
502 zlog_debug("%s, subtlv length %d does not equal %d", __func__
,
503 subtlv
->length
, 1 + 3 + 6 + 2);
506 if (subtlv
->value
[0] & 0x80) {
508 st
->isid
= (subtlv
->value
[1] << 16) | (subtlv
->value
[2] << 8)
511 if (subtlv
->value
[0] & 0x40) {
513 st
->vid
= ((subtlv
->value
[10] & 0x0f) << 8) | subtlv
->value
[11];
515 memcpy(st
->macaddr
, subtlv
->value
+ 4, 6);
520 static int subtlv_decode_proto_type(struct bgp_attr_encap_subtlv
*subtlv
,
521 struct bgp_tea_subtlv_proto_type
*st
)
523 if (subtlv
->length
!= 2) {
524 zlog_debug("%s, subtlv length %d does not equal 2", __func__
,
528 st
->proto
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
533 static int subtlv_decode_color(struct bgp_attr_encap_subtlv
*subtlv
,
534 struct bgp_tea_subtlv_color
*st
)
536 if (subtlv
->length
!= 8) {
537 zlog_debug("%s, subtlv length %d does not equal 8", __func__
,
541 if ((subtlv
->value
[0] != 0x03) || (subtlv
->value
[1] != 0x0b)
542 || (subtlv
->value
[2] != 0) || (subtlv
->value
[3] != 0)) {
543 zlog_debug("%s, subtlv value 1st 4 bytes are not 0x030b0000",
547 ptr_get_be32(subtlv
->value
+ 4, &st
->color
);
552 static int subtlv_decode_ipsec_ta(struct bgp_attr_encap_subtlv
*subtlv
,
553 struct bgp_tea_subtlv_ipsec_ta
*st
)
555 st
->authenticator_length
= subtlv
->length
- 2;
556 if (st
->authenticator_length
> sizeof(st
->value
)) {
558 "%s, authenticator length %d exceeds storage maximum %d",
559 __func__
, st
->authenticator_length
,
560 (int)sizeof(st
->value
));
563 st
->authenticator_type
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
564 memcpy(st
->value
, subtlv
->value
+ 2, st
->authenticator_length
);
568 /* draft-rosen-idr-tunnel-encaps 2.1 */
570 subtlv_decode_remote_endpoint(struct bgp_attr_encap_subtlv
*subtlv
,
571 struct bgp_tea_subtlv_remote_endpoint
*st
)
574 if (subtlv
->length
!= 8 && subtlv
->length
!= 20) {
575 zlog_debug("%s, subtlv length %d does not equal 8 or 20",
576 __func__
, subtlv
->length
);
579 if (subtlv
->length
== 8) {
580 st
->family
= AF_INET
;
581 memcpy(&st
->ip_address
.v4
.s_addr
, subtlv
->value
, 4);
583 st
->family
= AF_INET6
;
584 memcpy(&(st
->ip_address
.v6
.s6_addr
), subtlv
->value
, 16);
586 i
= subtlv
->length
- 4;
587 ptr_get_be32(subtlv
->value
+ i
, &st
->as4
);
591 /***********************************************************************
592 * TUNNEL TYPE-SPECIFIC TLV DECODE
593 ***********************************************************************/
595 int tlv_to_bgp_encap_type_l2tpv3overip(
596 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
597 struct bgp_encap_type_l2tpv3_over_ip
*bet
) /* caller-allocated */
599 struct bgp_attr_encap_subtlv
*st
;
602 for (st
= stlv
; st
; st
= st
->next
) {
604 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
605 rc
|= subtlv_decode_encap_l2tpv3_over_ip(
607 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
610 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
611 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
612 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
615 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
616 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
617 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
620 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
621 rc
|= subtlv_decode_remote_endpoint(st
,
623 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
627 zlog_debug("%s: unexpected subtlv type %d", __func__
,
636 int tlv_to_bgp_encap_type_gre(
637 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
638 struct bgp_encap_type_gre
*bet
) /* caller-allocated */
640 struct bgp_attr_encap_subtlv
*st
;
643 for (st
= stlv
; st
; st
= st
->next
) {
645 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
646 rc
|= subtlv_decode_encap_gre(st
, &bet
->st_encap
);
647 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
650 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
651 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
652 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
655 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
656 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
657 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
660 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
661 rc
|= subtlv_decode_remote_endpoint(st
,
663 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
667 zlog_debug("%s: unexpected subtlv type %d", __func__
,
676 int tlv_to_bgp_encap_type_ip_in_ip(
677 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
678 struct bgp_encap_type_ip_in_ip
*bet
) /* caller-allocated */
680 struct bgp_attr_encap_subtlv
*st
;
683 for (st
= stlv
; st
; st
= st
->next
) {
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
,
698 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
702 zlog_debug("%s: unexpected subtlv type %d", __func__
,
711 int tlv_to_bgp_encap_type_transmit_tunnel_endpoint(
712 struct bgp_attr_encap_subtlv
*stlv
,
713 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
)
715 struct bgp_attr_encap_subtlv
*st
;
718 for (st
= stlv
; st
; st
= st
->next
) {
721 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
722 rc
|= subtlv_decode_remote_endpoint(st
,
724 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
728 zlog_debug("%s: unexpected subtlv type %d", __func__
,
737 int tlv_to_bgp_encap_type_ipsec_in_tunnel_mode(
738 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
739 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
) /* caller-allocated */
741 struct bgp_attr_encap_subtlv
*st
;
744 for (st
= stlv
; st
; st
= st
->next
) {
746 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
747 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
748 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
751 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
752 rc
|= subtlv_decode_remote_endpoint(st
,
754 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
758 zlog_debug("%s: unexpected subtlv type %d", __func__
,
767 int tlv_to_bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode(
768 struct bgp_attr_encap_subtlv
*stlv
,
769 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
771 struct bgp_attr_encap_subtlv
*st
;
774 for (st
= stlv
; st
; st
= st
->next
) {
776 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
777 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
778 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
781 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
782 rc
|= subtlv_decode_remote_endpoint(st
,
784 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
788 zlog_debug("%s: unexpected subtlv type %d", __func__
,
797 int tlv_to_bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode(
798 struct bgp_attr_encap_subtlv
*stlv
,
799 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
801 struct bgp_attr_encap_subtlv
*st
;
804 for (st
= stlv
; st
; st
= st
->next
) {
806 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
807 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
808 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
811 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
812 rc
|= subtlv_decode_remote_endpoint(st
,
814 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
818 zlog_debug("%s: unexpected subtlv type %d", __func__
,
827 int tlv_to_bgp_encap_type_vxlan(struct bgp_attr_encap_subtlv
*stlv
,
828 struct bgp_encap_type_vxlan
*bet
)
830 struct bgp_attr_encap_subtlv
*st
;
833 for (st
= stlv
; st
; st
= st
->next
) {
836 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
837 rc
|= subtlv_decode_remote_endpoint(st
,
839 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
843 zlog_debug("%s: unexpected subtlv type %d", __func__
,
852 int tlv_to_bgp_encap_type_nvgre(struct bgp_attr_encap_subtlv
*stlv
,
853 struct bgp_encap_type_nvgre
*bet
)
855 struct bgp_attr_encap_subtlv
*st
;
858 for (st
= stlv
; st
; st
= st
->next
) {
861 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
862 rc
|= subtlv_decode_remote_endpoint(st
,
864 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
868 zlog_debug("%s: unexpected subtlv type %d", __func__
,
877 int tlv_to_bgp_encap_type_mpls(struct bgp_attr_encap_subtlv
*stlv
,
878 struct bgp_encap_type_mpls
*bet
)
880 struct bgp_attr_encap_subtlv
*st
;
883 for (st
= stlv
; st
; st
= st
->next
) {
886 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
887 rc
|= subtlv_decode_remote_endpoint(st
,
889 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
893 zlog_debug("%s: unexpected subtlv type %d", __func__
,
902 int tlv_to_bgp_encap_type_mpls_in_gre(struct bgp_attr_encap_subtlv
*stlv
,
903 struct bgp_encap_type_mpls_in_gre
*bet
)
905 struct bgp_attr_encap_subtlv
*st
;
908 for (st
= stlv
; st
; st
= st
->next
) {
911 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
912 rc
|= subtlv_decode_remote_endpoint(st
,
914 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
918 zlog_debug("%s: unexpected subtlv type %d", __func__
,
927 int tlv_to_bgp_encap_type_vxlan_gpe(struct bgp_attr_encap_subtlv
*stlv
,
928 struct bgp_encap_type_vxlan_gpe
*bet
)
930 struct bgp_attr_encap_subtlv
*st
;
933 for (st
= stlv
; st
; st
= st
->next
) {
936 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
937 rc
|= subtlv_decode_remote_endpoint(st
,
939 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
943 zlog_debug("%s: unexpected subtlv type %d", __func__
,
952 int tlv_to_bgp_encap_type_mpls_in_udp(struct bgp_attr_encap_subtlv
*stlv
,
953 struct bgp_encap_type_mpls_in_udp
*bet
)
955 struct bgp_attr_encap_subtlv
*st
;
958 for (st
= stlv
; st
; st
= st
->next
) {
961 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
962 rc
|= subtlv_decode_remote_endpoint(st
,
964 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
968 zlog_debug("%s: unexpected subtlv type %d", __func__
,
977 int tlv_to_bgp_encap_type_pbb(
978 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
979 struct bgp_encap_type_pbb
*bet
) /* caller-allocated */
981 struct bgp_attr_encap_subtlv
*st
;
984 for (st
= stlv
; st
; st
= st
->next
) {
986 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
987 rc
|= subtlv_decode_encap_pbb(st
, &bet
->st_encap
);
988 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
991 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
992 rc
|= subtlv_decode_remote_endpoint(st
,
994 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
998 zlog_debug("%s: unexpected subtlv type %d", __func__
,