2 * Copyright 2015, LabN Consulting, L.L.C.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include "bgp_encap_types.h"
32 #include "bgp_encap_tlv.h"
34 /***********************************************************************
36 ***********************************************************************/
39 static struct bgp_attr_encap_subtlv
*
40 subtlv_encode_encap_l2tpv3_over_ip(
41 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
43 struct bgp_attr_encap_subtlv
*new;
45 int total
= 4 + st
->cookie_length
;
48 assert(st
->cookie_length
<= sizeof(st
->cookie
));
49 assert(total
<= 0xff);
51 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
53 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
57 *p
++ = (st
->sessionid
& 0xff000000) >> 24;
58 *p
++ = (st
->sessionid
& 0xff0000) >> 16;
59 *p
++ = (st
->sessionid
& 0xff00) >> 8;
60 *p
++ = (st
->sessionid
& 0xff);
61 memcpy(p
, st
->cookie
, st
->cookie_length
);
66 static struct bgp_attr_encap_subtlv
*
67 subtlv_encode_encap_gre(
68 struct bgp_tea_subtlv_encap_gre_key
*st
)
70 struct bgp_attr_encap_subtlv
*new;
74 assert(total
<= 0xff);
76 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
78 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
82 *p
++ = (st
->gre_key
& 0xff000000) >> 24;
83 *p
++ = (st
->gre_key
& 0xff0000) >> 16;
84 *p
++ = (st
->gre_key
& 0xff00) >> 8;
85 *p
++ = (st
->gre_key
& 0xff);
89 static struct bgp_attr_encap_subtlv
*
90 subtlv_encode_encap_pbb(
91 struct bgp_tea_subtlv_encap_pbb
*st
)
93 struct bgp_attr_encap_subtlv
*new;
95 int total
= 1 + 3 + 6 + 2; /* flags + isid + madaddr + vid */
97 assert(total
<= 0xff);
99 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
101 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
105 *p
++ = (st
->flag_isid
? 0x80: 0) |
106 (st
->flag_vid
? 0x40: 0) |
109 *p
= (st
->isid
& 0xff0000) >> 16;
110 *(p
+1) = (st
->isid
& 0xff00) >> 8;
111 *(p
+2) = (st
->isid
& 0xff);
114 memcpy(p
, st
->macaddr
, 6);
117 *p
++ = (st
->vid
& 0xf00) >> 8;
118 *p
++ = st
->vid
& 0xff;
124 static struct bgp_attr_encap_subtlv
*
125 subtlv_encode_proto_type(
126 struct bgp_tea_subtlv_proto_type
*st
)
128 struct bgp_attr_encap_subtlv
*new;
132 assert(total
<= 0xff);
134 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
136 new->type
= BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
;
140 *p
++ = (st
->proto
& 0xff00) >> 8;
141 *p
++ = (st
->proto
& 0xff);
146 static struct bgp_attr_encap_subtlv
*
148 struct bgp_tea_subtlv_color
*st
)
150 struct bgp_attr_encap_subtlv
*new;
154 assert(total
<= 0xff);
156 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
158 new->type
= BGP_ENCAP_SUBTLV_TYPE_COLOR
;
162 *p
++ = 0x03; /* transitive*/
164 *p
++ = 0; /* reserved */
165 *p
++ = 0; /* reserved */
167 *p
++ = (st
->color
& 0xff000000) >> 24;
168 *p
++ = (st
->color
& 0xff0000) >> 16;
169 *p
++ = (st
->color
& 0xff00) >> 8;
170 *p
++ = (st
->color
& 0xff);
176 static struct bgp_attr_encap_subtlv
*
177 subtlv_encode_ipsec_ta(
178 struct bgp_tea_subtlv_ipsec_ta
*st
)
180 struct bgp_attr_encap_subtlv
*new;
182 int total
= 2 + st
->authenticator_length
;
185 assert(st
->authenticator_length
<= sizeof(st
->value
));
186 assert(total
<= 0xff);
188 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
190 new->type
= BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
;
194 *p
++ = (st
->authenticator_type
& 0xff00) >> 8;
195 *p
++ = st
->authenticator_type
& 0xff;
196 memcpy(p
, st
->value
, st
->authenticator_length
);
200 /* draft-rosen-idr-tunnel-encaps 2.1 */
201 static struct bgp_attr_encap_subtlv
*
202 subtlv_encode_remote_endpoint(
203 struct bgp_tea_subtlv_remote_endpoint
*st
)
205 struct bgp_attr_encap_subtlv
*new;
208 int total
= (st
->family
==AF_INET
?8:20);
210 assert(total
<= 0xff);
212 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
214 new->type
= BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
;
217 if (st
->family
== AF_INET
) {
218 memcpy (p
, &(st
->ip_address
.v4
.s_addr
), 4);
221 assert (st
->family
== AF_INET6
);
222 memcpy (p
, &(st
->ip_address
.v6
.s6_addr
), 16);
225 memcpy (p
, &(st
->as4
), 4);
229 /***********************************************************************
230 * TUNNEL TYPE-SPECIFIC TLV ENCODE
231 ***********************************************************************/
234 * requires "extra" and "last" to be defined in caller
236 #define ENC_SUBTLV(flag, function, field) do {\
237 struct bgp_attr_encap_subtlv *new;\
238 if (CHECK_FLAG(bet->valid_subtlvs, (flag))) {\
239 new = function(&bet->field);\
243 extra->encap_subtlvs = new;\
250 bgp_encap_type_l2tpv3overip_to_tlv(
251 struct bgp_encap_type_l2tpv3_over_ip
*bet
, /* input structure */
254 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
255 struct bgp_attr_encap_subtlv
*last
;
257 /* advance to last subtlv */
258 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
260 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_L2TPV3_OVER_IP
;
262 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
264 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_l2tpv3_over_ip
, st_encap
);
265 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
266 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
267 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
271 bgp_encap_type_gre_to_tlv(
272 struct bgp_encap_type_gre
*bet
, /* input structure */
275 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
276 struct bgp_attr_encap_subtlv
*last
;
278 /* advance to last subtlv */
279 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
281 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_GRE
;
283 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_gre
, st_encap
);
284 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
285 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
286 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
290 bgp_encap_type_ip_in_ip_to_tlv(
291 struct bgp_encap_type_ip_in_ip
*bet
, /* input structure */
294 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
295 struct bgp_attr_encap_subtlv
*last
;
297 /* advance to last subtlv */
298 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
300 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IP_IN_IP
;
302 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
303 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
304 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
308 bgp_encap_type_transmit_tunnel_endpoint(
309 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
, /* input structure */
312 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
313 struct bgp_attr_encap_subtlv
*last
;
315 /* advance to last subtlv */
316 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
318 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT
;
320 /* no subtlvs for this type */
324 bgp_encap_type_ipsec_in_tunnel_mode_to_tlv(
325 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
, /* input structure */
328 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
329 struct bgp_attr_encap_subtlv
*last
;
331 /* advance to last subtlv */
332 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
334 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE
;
336 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
340 bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
341 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
, /* input structure */
344 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
345 struct bgp_attr_encap_subtlv
*last
;
347 /* advance to last subtlv */
348 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
350 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
352 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
356 bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
357 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
*bet
, /* input structure */
360 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
361 struct bgp_attr_encap_subtlv
*last
;
363 /* advance to last subtlv */
364 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
366 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
368 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
372 bgp_encap_type_pbb_to_tlv(
373 struct bgp_encap_type_pbb
*bet
, /* input structure */
376 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
377 struct bgp_attr_encap_subtlv
*last
;
379 /* advance to last subtlv */
380 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
382 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_PBB
;
384 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
385 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_pbb
, st_encap
);
389 bgp_encap_type_vxlan_to_tlv(
390 struct bgp_encap_type_vxlan
*bet
, /* input structure */
393 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
395 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN
;
399 bgp_encap_type_nvgre_to_tlv(
400 struct bgp_encap_type_nvgre
*bet
, /* input structure */
403 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
405 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_NVGRE
;
409 bgp_encap_type_mpls_to_tlv(
410 struct bgp_encap_type_mpls
*bet
, /* input structure */
413 return; /* no encap attribute for MPLS */
417 bgp_encap_type_mpls_in_gre_to_tlv(
418 struct bgp_encap_type_mpls_in_gre
*bet
, /* input structure */
421 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
423 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_GRE
;
427 bgp_encap_type_vxlan_gpe_to_tlv(
428 struct bgp_encap_type_vxlan_gpe
*bet
, /* input structure */
431 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
433 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN_GPE
;
437 bgp_encap_type_mpls_in_udp_to_tlv(
438 struct bgp_encap_type_mpls_in_udp
*bet
, /* input structure */
441 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
443 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_UDP
;
447 /***********************************************************************
449 ***********************************************************************/
452 subtlv_decode_encap_l2tpv3_over_ip(
453 struct bgp_attr_encap_subtlv
*subtlv
,
454 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
456 if (subtlv
->length
< 4) {
457 zlog_debug("%s, subtlv length %d is less than 4",
458 __func__
, subtlv
->length
);
462 st
->sessionid
= (subtlv
->value
[0] << 24) |
463 (subtlv
->value
[1] << 16) |
464 (subtlv
->value
[2] << 8) |
466 st
->cookie_length
= subtlv
->length
- 4;
467 if (st
->cookie_length
> sizeof(st
->cookie
)) {
468 zlog_debug("%s, subtlv length %d is greater than %d",
469 __func__
, st
->cookie_length
, (int)sizeof(st
->cookie
));
472 memcpy(st
->cookie
, subtlv
->value
+ 4, st
->cookie_length
);
478 subtlv_decode_encap_gre(
479 struct bgp_attr_encap_subtlv
*subtlv
,
480 struct bgp_tea_subtlv_encap_gre_key
*st
)
482 if (subtlv
->length
!= 4) {
483 zlog_debug("%s, subtlv length %d does not equal 4",
484 __func__
, subtlv
->length
);
487 st
->gre_key
= (subtlv
->value
[0] << 24) |
488 (subtlv
->value
[1] << 16) |
489 (subtlv
->value
[2] << 8) |
495 subtlv_decode_encap_pbb(
496 struct bgp_attr_encap_subtlv
*subtlv
,
497 struct bgp_tea_subtlv_encap_pbb
*st
)
499 if (subtlv
->length
!= 1 + 3 + 6 + 2) {
500 zlog_debug("%s, subtlv length %d does not equal %d",
501 __func__
, subtlv
->length
, 1 + 3 + 6 + 2);
504 if (subtlv
->value
[0] & 0x80) {
506 st
->isid
= (subtlv
->value
[1] << 16) |
507 (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);
520 subtlv_decode_proto_type(
521 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",
526 __func__
, subtlv
->length
);
529 st
->proto
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
536 struct bgp_attr_encap_subtlv
*subtlv
,
537 struct bgp_tea_subtlv_color
*st
)
539 if (subtlv
->length
!= 8) {
540 zlog_debug("%s, subtlv length %d does not equal 8",
541 __func__
, subtlv
->length
);
544 if ((subtlv
->value
[0] != 0x03) ||
545 (subtlv
->value
[1] != 0x0b) ||
546 (subtlv
->value
[2] != 0) ||
547 (subtlv
->value
[3] != 0)) {
548 zlog_debug("%s, subtlv value 1st 4 bytes are not 0x030b0000", __func__
);
551 st
->color
= (subtlv
->value
[4] << 24) |
552 (subtlv
->value
[5] << 16) |
553 (subtlv
->value
[6] << 8) |
560 subtlv_decode_ipsec_ta(
561 struct bgp_attr_encap_subtlv
*subtlv
,
562 struct bgp_tea_subtlv_ipsec_ta
*st
)
564 st
->authenticator_length
= subtlv
->length
- 2;
565 if (st
->authenticator_length
> sizeof(st
->value
)) {
566 zlog_debug("%s, authenticator length %d exceeds storage maximum %d",
567 __func__
, st
->authenticator_length
, (int)sizeof(st
->value
));
570 st
->authenticator_type
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
571 memcpy(st
->value
, subtlv
->value
+ 2, st
->authenticator_length
);
575 /* draft-rosen-idr-tunnel-encaps 2.1 */
577 subtlv_decode_remote_endpoint(
578 struct bgp_attr_encap_subtlv
*subtlv
,
579 struct bgp_tea_subtlv_remote_endpoint
*st
)
582 if (subtlv
->length
!= 8 && subtlv
->length
!= 20 ) {
583 zlog_debug("%s, subtlv length %d does not equal 8 or 20",
584 __func__
, subtlv
->length
);
587 if (subtlv
->length
== 8) {
588 st
->family
= AF_INET
;
589 st
->ip_address
.v4
.s_addr
= ((subtlv
->value
[0] << 24) |
590 (subtlv
->value
[1] << 16) |
591 (subtlv
->value
[2] << 8) |
594 st
->family
= AF_INET6
;
595 memcpy (&(st
->ip_address
.v6
.s6_addr
), subtlv
->value
, 16);
597 i
= subtlv
->length
- 4;
598 st
->as4
= ((subtlv
->value
[i
] << 24) |
599 (subtlv
->value
[i
+1] << 16) |
600 (subtlv
->value
[i
+2] << 8) |
605 /***********************************************************************
606 * TUNNEL TYPE-SPECIFIC TLV DECODE
607 ***********************************************************************/
610 tlv_to_bgp_encap_type_l2tpv3overip(
611 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
612 struct bgp_encap_type_l2tpv3_over_ip
*bet
) /* caller-allocated */
614 struct bgp_attr_encap_subtlv
*st
;
617 for (st
= stlv
; st
; st
= st
->next
) {
619 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
620 rc
|= subtlv_decode_encap_l2tpv3_over_ip(st
, &bet
->st_encap
);
621 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
624 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
625 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
626 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
629 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
630 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
631 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
634 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
635 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
636 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
640 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
649 tlv_to_bgp_encap_type_gre(
650 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
651 struct bgp_encap_type_gre
*bet
) /* caller-allocated */
653 struct bgp_attr_encap_subtlv
*st
;
656 for (st
= stlv
; st
; st
= st
->next
) {
658 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
659 rc
|= subtlv_decode_encap_gre(st
, &bet
->st_encap
);
660 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
663 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
664 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
665 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
668 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
669 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
670 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
673 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
674 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
675 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
679 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
688 tlv_to_bgp_encap_type_ip_in_ip(
689 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
690 struct bgp_encap_type_ip_in_ip
*bet
) /* caller-allocated */
692 struct bgp_attr_encap_subtlv
*st
;
695 for (st
= stlv
; st
; st
= st
->next
) {
697 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
698 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
699 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
702 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
703 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
704 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
707 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
708 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
709 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
713 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
722 tlv_to_bgp_encap_type_transmit_tunnel_endpoint(
723 struct bgp_attr_encap_subtlv
*stlv
,
724 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
)
726 struct bgp_attr_encap_subtlv
*st
;
729 for (st
= stlv
; st
; st
= st
->next
) {
732 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
733 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
734 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
738 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
747 tlv_to_bgp_encap_type_ipsec_in_tunnel_mode(
748 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
749 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
) /* caller-allocated */
751 struct bgp_attr_encap_subtlv
*st
;
754 for (st
= stlv
; st
; st
= st
->next
) {
756 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
757 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
758 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
761 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
762 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
763 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
767 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
776 tlv_to_bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode(
777 struct bgp_attr_encap_subtlv
*stlv
,
778 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
780 struct bgp_attr_encap_subtlv
*st
;
783 for (st
= stlv
; st
; st
= st
->next
) {
785 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
786 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
787 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
790 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
791 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
792 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
796 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
805 tlv_to_bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode(
806 struct bgp_attr_encap_subtlv
*stlv
,
807 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
809 struct bgp_attr_encap_subtlv
*st
;
812 for (st
= stlv
; st
; st
= st
->next
) {
814 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
815 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
816 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
819 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
820 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
821 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
825 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
834 tlv_to_bgp_encap_type_vxlan(
835 struct bgp_attr_encap_subtlv
*stlv
,
836 struct bgp_encap_type_vxlan
*bet
)
838 struct bgp_attr_encap_subtlv
*st
;
841 for (st
= stlv
; st
; st
= st
->next
) {
844 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
845 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
846 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
850 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
859 tlv_to_bgp_encap_type_nvgre(
860 struct bgp_attr_encap_subtlv
*stlv
,
861 struct bgp_encap_type_nvgre
*bet
)
863 struct bgp_attr_encap_subtlv
*st
;
866 for (st
= stlv
; st
; st
= st
->next
) {
869 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
870 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
871 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
875 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
884 tlv_to_bgp_encap_type_mpls(
885 struct bgp_attr_encap_subtlv
*stlv
,
886 struct bgp_encap_type_mpls
*bet
)
888 struct bgp_attr_encap_subtlv
*st
;
891 for (st
= stlv
; st
; st
= st
->next
) {
894 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
895 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
896 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
900 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
909 tlv_to_bgp_encap_type_mpls_in_gre(
910 struct bgp_attr_encap_subtlv
*stlv
,
911 struct bgp_encap_type_mpls_in_gre
*bet
)
913 struct bgp_attr_encap_subtlv
*st
;
916 for (st
= stlv
; st
; st
= st
->next
) {
919 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
920 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
921 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
925 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
934 tlv_to_bgp_encap_type_vxlan_gpe(
935 struct bgp_attr_encap_subtlv
*stlv
,
936 struct bgp_encap_type_vxlan_gpe
*bet
)
938 struct bgp_attr_encap_subtlv
*st
;
941 for (st
= stlv
; st
; st
= st
->next
) {
944 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
945 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
946 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
950 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
959 tlv_to_bgp_encap_type_mpls_in_udp(
960 struct bgp_attr_encap_subtlv
*stlv
,
961 struct bgp_encap_type_mpls_in_udp
*bet
)
963 struct bgp_attr_encap_subtlv
*st
;
966 for (st
= stlv
; st
; st
= st
->next
) {
969 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
970 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
971 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
975 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
984 tlv_to_bgp_encap_type_pbb(
985 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
986 struct bgp_encap_type_pbb
*bet
) /* caller-allocated */
988 struct bgp_attr_encap_subtlv
*st
;
991 for (st
= stlv
; st
; st
= st
->next
) {
993 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
994 rc
|= subtlv_decode_encap_pbb(st
, &bet
->st_encap
);
995 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
998 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
999 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
1000 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
1004 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);