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
*
39 subtlv_encode_encap_l2tpv3_over_ip(
40 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
42 struct bgp_attr_encap_subtlv
*new;
44 int total
= 4 + st
->cookie_length
;
47 assert(st
->cookie_length
<= sizeof(st
->cookie
));
48 assert(total
<= 0xff);
50 new = XCALLOC(MTYPE_ENCAP_TLV
, 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(
67 struct bgp_tea_subtlv_encap_gre_key
*st
)
69 struct bgp_attr_encap_subtlv
*new;
73 assert(total
<= 0xff);
75 new = XCALLOC(MTYPE_ENCAP_TLV
, 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(
90 struct bgp_tea_subtlv_encap_pbb
*st
)
92 struct bgp_attr_encap_subtlv
*new;
94 int total
= 1 + 3 + 6 + 2; /* flags + isid + madaddr + vid */
96 assert(total
<= 0xff);
98 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
100 new->type
= BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
;
104 *p
++ = (st
->flag_isid
? 0x80: 0) |
105 (st
->flag_vid
? 0x40: 0) |
108 *p
= (st
->isid
& 0xff0000) >> 16;
109 *(p
+1) = (st
->isid
& 0xff00) >> 8;
110 *(p
+2) = (st
->isid
& 0xff);
113 memcpy(p
, st
->macaddr
, 6);
116 *p
++ = (st
->vid
& 0xf00) >> 8;
117 *p
++ = st
->vid
& 0xff;
123 static struct bgp_attr_encap_subtlv
*
124 subtlv_encode_proto_type(
125 struct bgp_tea_subtlv_proto_type
*st
)
127 struct bgp_attr_encap_subtlv
*new;
131 assert(total
<= 0xff);
133 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
135 new->type
= BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
;
139 *p
++ = (st
->proto
& 0xff00) >> 8;
140 *p
++ = (st
->proto
& 0xff);
145 static struct bgp_attr_encap_subtlv
*
147 struct bgp_tea_subtlv_color
*st
)
149 struct bgp_attr_encap_subtlv
*new;
153 assert(total
<= 0xff);
155 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
157 new->type
= BGP_ENCAP_SUBTLV_TYPE_COLOR
;
161 *p
++ = 0x03; /* transitive*/
163 *p
++ = 0; /* reserved */
164 *p
++ = 0; /* reserved */
166 *p
++ = (st
->color
& 0xff000000) >> 24;
167 *p
++ = (st
->color
& 0xff0000) >> 16;
168 *p
++ = (st
->color
& 0xff00) >> 8;
169 *p
++ = (st
->color
& 0xff);
175 static struct bgp_attr_encap_subtlv
*
176 subtlv_encode_ipsec_ta(
177 struct bgp_tea_subtlv_ipsec_ta
*st
)
179 struct bgp_attr_encap_subtlv
*new;
181 int total
= 2 + st
->authenticator_length
;
184 assert(st
->authenticator_length
<= sizeof(st
->value
));
185 assert(total
<= 0xff);
187 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
189 new->type
= BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
;
193 *p
++ = (st
->authenticator_type
& 0xff00) >> 8;
194 *p
++ = st
->authenticator_type
& 0xff;
195 memcpy(p
, st
->value
, st
->authenticator_length
);
199 /* draft-rosen-idr-tunnel-encaps 2.1 */
200 static struct bgp_attr_encap_subtlv
*
201 subtlv_encode_remote_endpoint(
202 struct bgp_tea_subtlv_remote_endpoint
*st
)
204 struct bgp_attr_encap_subtlv
*new;
207 int total
= (st
->family
==AF_INET
?8:20);
209 assert(total
<= 0xff);
211 new = XCALLOC(MTYPE_ENCAP_TLV
, sizeof(struct bgp_attr_encap_subtlv
) - 1 + total
);
213 new->type
= BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
;
216 if (st
->family
== AF_INET
) {
217 memcpy (p
, &(st
->ip_address
.v4
.s_addr
), 4);
220 assert (st
->family
== AF_INET6
);
221 memcpy (p
, &(st
->ip_address
.v6
.s6_addr
), 16);
224 memcpy (p
, &(st
->as4
), 4);
228 /***********************************************************************
229 * TUNNEL TYPE-SPECIFIC TLV ENCODE
230 ***********************************************************************/
233 * requires "extra" and "last" to be defined in caller
235 #define ENC_SUBTLV(flag, function, field) do {\
236 struct bgp_attr_encap_subtlv *new;\
237 if (CHECK_FLAG(bet->valid_subtlvs, (flag))) {\
238 new = function(&bet->field);\
242 extra->encap_subtlvs = new;\
249 bgp_encap_type_l2tpv3overip_to_tlv(
250 struct bgp_encap_type_l2tpv3_over_ip
*bet
, /* input structure */
253 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
254 struct bgp_attr_encap_subtlv
*last
;
256 /* advance to last subtlv */
257 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
259 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_L2TPV3_OVER_IP
;
261 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
263 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_l2tpv3_over_ip
, st_encap
);
264 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
265 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
266 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
270 bgp_encap_type_gre_to_tlv(
271 struct bgp_encap_type_gre
*bet
, /* input structure */
274 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
275 struct bgp_attr_encap_subtlv
*last
;
277 /* advance to last subtlv */
278 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
280 extra
->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
, st_proto
);
284 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
285 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
289 bgp_encap_type_ip_in_ip_to_tlv(
290 struct bgp_encap_type_ip_in_ip
*bet
, /* input structure */
293 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
294 struct bgp_attr_encap_subtlv
*last
;
296 /* advance to last subtlv */
297 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
299 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IP_IN_IP
;
301 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE
, subtlv_encode_proto_type
, st_proto
);
302 ENC_SUBTLV(BGP_TEA_SUBTLV_COLOR
, subtlv_encode_color
, st_color
);
303 ENC_SUBTLV(BGP_TEA_SUBTLV_REMOTE_ENDPOINT
, subtlv_encode_remote_endpoint
, st_endpoint
);
307 bgp_encap_type_transmit_tunnel_endpoint(
308 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
, /* input structure */
311 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
312 struct bgp_attr_encap_subtlv
*last
;
314 /* advance to last subtlv */
315 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
317 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT
;
319 /* no subtlvs for this type */
323 bgp_encap_type_ipsec_in_tunnel_mode_to_tlv(
324 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
, /* input structure */
327 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
328 struct bgp_attr_encap_subtlv
*last
;
330 /* advance to last subtlv */
331 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
333 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE
;
335 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
339 bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
340 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
, /* input structure */
343 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
344 struct bgp_attr_encap_subtlv
*last
;
346 /* advance to last subtlv */
347 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
349 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
351 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
355 bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode_to_tlv(
356 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
*bet
, /* input structure */
359 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
360 struct bgp_attr_encap_subtlv
*last
;
362 /* advance to last subtlv */
363 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
365 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE
;
367 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA
, subtlv_encode_ipsec_ta
, st_ipsec_ta
);
371 bgp_encap_type_pbb_to_tlv(
372 struct bgp_encap_type_pbb
*bet
, /* input structure */
375 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
376 struct bgp_attr_encap_subtlv
*last
;
378 /* advance to last subtlv */
379 for (last
= extra
->encap_subtlvs
; last
&& last
->next
; last
= last
->next
);
381 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_PBB
;
383 assert(CHECK_FLAG(bet
->valid_subtlvs
, BGP_TEA_SUBTLV_ENCAP
));
384 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP
, subtlv_encode_encap_pbb
, st_encap
);
388 bgp_encap_type_vxlan_to_tlv(
389 struct bgp_encap_type_vxlan
*bet
, /* input structure */
392 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
394 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN
;
398 bgp_encap_type_nvgre_to_tlv(
399 struct bgp_encap_type_nvgre
*bet
, /* input structure */
402 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
404 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_NVGRE
;
408 bgp_encap_type_mpls_to_tlv(
409 struct bgp_encap_type_mpls
*bet
, /* input structure */
412 return; /* no encap attribute for MPLS */
416 bgp_encap_type_mpls_in_gre_to_tlv(
417 struct bgp_encap_type_mpls_in_gre
*bet
, /* input structure */
420 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
422 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_GRE
;
426 bgp_encap_type_vxlan_gpe_to_tlv(
427 struct bgp_encap_type_vxlan_gpe
*bet
, /* input structure */
430 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
432 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_VXLAN_GPE
;
436 bgp_encap_type_mpls_in_udp_to_tlv(
437 struct bgp_encap_type_mpls_in_udp
*bet
, /* input structure */
440 struct attr_extra
*extra
= bgp_attr_extra_get(attr
);
442 extra
->encap_tunneltype
= BGP_ENCAP_TYPE_MPLS_IN_UDP
;
446 /***********************************************************************
448 ***********************************************************************/
451 subtlv_decode_encap_l2tpv3_over_ip(
452 struct bgp_attr_encap_subtlv
*subtlv
,
453 struct bgp_tea_subtlv_encap_l2tpv3_over_ip
*st
)
455 if (subtlv
->length
< 4) {
456 zlog_debug("%s, subtlv length %d is less than 4",
457 __func__
, subtlv
->length
);
461 st
->sessionid
= (subtlv
->value
[0] << 24) |
462 (subtlv
->value
[1] << 16) |
463 (subtlv
->value
[2] << 8) |
465 st
->cookie_length
= subtlv
->length
- 4;
466 if (st
->cookie_length
> sizeof(st
->cookie
)) {
467 zlog_debug("%s, subtlv length %d is greater than %d",
468 __func__
, st
->cookie_length
, (int)sizeof(st
->cookie
));
471 memcpy(st
->cookie
, subtlv
->value
+ 4, st
->cookie_length
);
477 subtlv_decode_encap_gre(
478 struct bgp_attr_encap_subtlv
*subtlv
,
479 struct bgp_tea_subtlv_encap_gre_key
*st
)
481 if (subtlv
->length
!= 4) {
482 zlog_debug("%s, subtlv length %d does not equal 4",
483 __func__
, subtlv
->length
);
486 st
->gre_key
= (subtlv
->value
[0] << 24) |
487 (subtlv
->value
[1] << 16) |
488 (subtlv
->value
[2] << 8) |
494 subtlv_decode_encap_pbb(
495 struct bgp_attr_encap_subtlv
*subtlv
,
496 struct bgp_tea_subtlv_encap_pbb
*st
)
498 if (subtlv
->length
!= 1 + 3 + 6 + 2) {
499 zlog_debug("%s, subtlv length %d does not equal %d",
500 __func__
, subtlv
->length
, 1 + 3 + 6 + 2);
503 if (subtlv
->value
[0] & 0x80) {
505 st
->isid
= (subtlv
->value
[1] << 16) |
506 (subtlv
->value
[2] << 8) |
509 if (subtlv
->value
[0] & 0x40) {
511 st
->vid
= ((subtlv
->value
[10] & 0x0f) << 8) | subtlv
->value
[11];
513 memcpy(st
->macaddr
, subtlv
->value
+ 4, 6);
519 subtlv_decode_proto_type(
520 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",
525 __func__
, subtlv
->length
);
528 st
->proto
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
535 struct bgp_attr_encap_subtlv
*subtlv
,
536 struct bgp_tea_subtlv_color
*st
)
538 if (subtlv
->length
!= 8) {
539 zlog_debug("%s, subtlv length %d does not equal 8",
540 __func__
, subtlv
->length
);
543 if ((subtlv
->value
[0] != 0x03) ||
544 (subtlv
->value
[1] != 0x0b) ||
545 (subtlv
->value
[2] != 0) ||
546 (subtlv
->value
[3] != 0)) {
547 zlog_debug("%s, subtlv value 1st 4 bytes are not 0x030b0000", __func__
);
550 st
->color
= (subtlv
->value
[4] << 24) |
551 (subtlv
->value
[5] << 16) |
552 (subtlv
->value
[6] << 8) |
559 subtlv_decode_ipsec_ta(
560 struct bgp_attr_encap_subtlv
*subtlv
,
561 struct bgp_tea_subtlv_ipsec_ta
*st
)
563 st
->authenticator_length
= subtlv
->length
- 2;
564 if (st
->authenticator_length
> sizeof(st
->value
)) {
565 zlog_debug("%s, authenticator length %d exceeds storage maximum %d",
566 __func__
, st
->authenticator_length
, (int)sizeof(st
->value
));
569 st
->authenticator_type
= (subtlv
->value
[0] << 8) | subtlv
->value
[1];
570 memcpy(st
->value
, subtlv
->value
+ 2, st
->authenticator_length
);
574 /* draft-rosen-idr-tunnel-encaps 2.1 */
576 subtlv_decode_remote_endpoint(
577 struct bgp_attr_encap_subtlv
*subtlv
,
578 struct bgp_tea_subtlv_remote_endpoint
*st
)
581 if (subtlv
->length
!= 8 && subtlv
->length
!= 20 ) {
582 zlog_debug("%s, subtlv length %d does not equal 8 or 20",
583 __func__
, subtlv
->length
);
586 if (subtlv
->length
== 8) {
587 st
->family
= AF_INET
;
588 st
->ip_address
.v4
.s_addr
= ((subtlv
->value
[0] << 24) |
589 (subtlv
->value
[1] << 16) |
590 (subtlv
->value
[2] << 8) |
593 st
->family
= AF_INET6
;
594 memcpy (&(st
->ip_address
.v6
.s6_addr
), subtlv
->value
, 16);
596 i
= subtlv
->length
- 4;
597 st
->as4
= ((subtlv
->value
[i
] << 24) |
598 (subtlv
->value
[i
+1] << 16) |
599 (subtlv
->value
[i
+2] << 8) |
604 /***********************************************************************
605 * TUNNEL TYPE-SPECIFIC TLV DECODE
606 ***********************************************************************/
609 tlv_to_bgp_encap_type_l2tpv3overip(
610 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
611 struct bgp_encap_type_l2tpv3_over_ip
*bet
) /* caller-allocated */
613 struct bgp_attr_encap_subtlv
*st
;
616 for (st
= stlv
; st
; st
= st
->next
) {
618 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
619 rc
|= subtlv_decode_encap_l2tpv3_over_ip(st
, &bet
->st_encap
);
620 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
623 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
624 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
625 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
628 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
629 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
630 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
633 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
634 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
635 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
639 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
648 tlv_to_bgp_encap_type_gre(
649 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
650 struct bgp_encap_type_gre
*bet
) /* caller-allocated */
652 struct bgp_attr_encap_subtlv
*st
;
655 for (st
= stlv
; st
; st
= st
->next
) {
657 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
658 rc
|= subtlv_decode_encap_gre(st
, &bet
->st_encap
);
659 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
662 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
663 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
664 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
667 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
668 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
669 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
672 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
673 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
674 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
678 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
687 tlv_to_bgp_encap_type_ip_in_ip(
688 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
689 struct bgp_encap_type_ip_in_ip
*bet
) /* caller-allocated */
691 struct bgp_attr_encap_subtlv
*st
;
694 for (st
= stlv
; st
; st
= st
->next
) {
696 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE
:
697 rc
|= subtlv_decode_proto_type(st
, &bet
->st_proto
);
698 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_PROTO_TYPE
);
701 case BGP_ENCAP_SUBTLV_TYPE_COLOR
:
702 rc
|= subtlv_decode_color(st
, &bet
->st_color
);
703 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_COLOR
);
706 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
707 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
708 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
712 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
721 tlv_to_bgp_encap_type_transmit_tunnel_endpoint(
722 struct bgp_attr_encap_subtlv
*stlv
,
723 struct bgp_encap_type_transmit_tunnel_endpoint
*bet
)
725 struct bgp_attr_encap_subtlv
*st
;
728 for (st
= stlv
; st
; st
= st
->next
) {
731 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
732 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
733 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
737 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
746 tlv_to_bgp_encap_type_ipsec_in_tunnel_mode(
747 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
748 struct bgp_encap_type_ipsec_in_tunnel_mode
*bet
) /* caller-allocated */
750 struct bgp_attr_encap_subtlv
*st
;
753 for (st
= stlv
; st
; st
= st
->next
) {
755 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
756 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
757 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
760 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
761 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
762 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
766 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
775 tlv_to_bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode(
776 struct bgp_attr_encap_subtlv
*stlv
,
777 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
779 struct bgp_attr_encap_subtlv
*st
;
782 for (st
= stlv
; st
; st
= st
->next
) {
784 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
785 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
786 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
789 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
790 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
791 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
795 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
804 tlv_to_bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode(
805 struct bgp_attr_encap_subtlv
*stlv
,
806 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
*bet
)
808 struct bgp_attr_encap_subtlv
*st
;
811 for (st
= stlv
; st
; st
= st
->next
) {
813 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA
:
814 rc
|= subtlv_decode_ipsec_ta(st
, &bet
->st_ipsec_ta
);
815 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_IPSEC_TA
);
818 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
819 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
820 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
824 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
833 tlv_to_bgp_encap_type_vxlan(
834 struct bgp_attr_encap_subtlv
*stlv
,
835 struct bgp_encap_type_vxlan
*bet
)
837 struct bgp_attr_encap_subtlv
*st
;
840 for (st
= stlv
; st
; st
= st
->next
) {
843 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
844 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
845 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
849 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
858 tlv_to_bgp_encap_type_nvgre(
859 struct bgp_attr_encap_subtlv
*stlv
,
860 struct bgp_encap_type_nvgre
*bet
)
862 struct bgp_attr_encap_subtlv
*st
;
865 for (st
= stlv
; st
; st
= st
->next
) {
868 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
869 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
870 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
874 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
883 tlv_to_bgp_encap_type_mpls(
884 struct bgp_attr_encap_subtlv
*stlv
,
885 struct bgp_encap_type_mpls
*bet
)
887 struct bgp_attr_encap_subtlv
*st
;
890 for (st
= stlv
; st
; st
= st
->next
) {
893 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
894 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
895 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
899 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
908 tlv_to_bgp_encap_type_mpls_in_gre(
909 struct bgp_attr_encap_subtlv
*stlv
,
910 struct bgp_encap_type_mpls_in_gre
*bet
)
912 struct bgp_attr_encap_subtlv
*st
;
915 for (st
= stlv
; st
; st
= st
->next
) {
918 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
919 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
920 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
924 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
933 tlv_to_bgp_encap_type_vxlan_gpe(
934 struct bgp_attr_encap_subtlv
*stlv
,
935 struct bgp_encap_type_vxlan_gpe
*bet
)
937 struct bgp_attr_encap_subtlv
*st
;
940 for (st
= stlv
; st
; st
= st
->next
) {
943 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
944 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
945 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
949 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
958 tlv_to_bgp_encap_type_mpls_in_udp(
959 struct bgp_attr_encap_subtlv
*stlv
,
960 struct bgp_encap_type_mpls_in_udp
*bet
)
962 struct bgp_attr_encap_subtlv
*st
;
965 for (st
= stlv
; st
; st
= st
->next
) {
968 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
969 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
970 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
974 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);
983 tlv_to_bgp_encap_type_pbb(
984 struct bgp_attr_encap_subtlv
*stlv
, /* subtlv chain */
985 struct bgp_encap_type_pbb
*bet
) /* caller-allocated */
987 struct bgp_attr_encap_subtlv
*st
;
990 for (st
= stlv
; st
; st
= st
->next
) {
992 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION
:
993 rc
|= subtlv_decode_encap_pbb(st
, &bet
->st_encap
);
994 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_ENCAP
);
997 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT
:
998 rc
|= subtlv_decode_remote_endpoint(st
, &bet
->st_endpoint
);
999 SET_SUBTLV_FLAG(bet
, BGP_TEA_SUBTLV_REMOTE_ENDPOINT
);
1003 zlog_debug("%s: unexpected subtlv type %d", __func__
, st
->type
);