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 struct attr_extra *extra = bgp_attr_extra_get(attr);
414 extra->encap_tunneltype = BGP_ENCAP_TYPE_MPLS;
418 bgp_encap_type_mpls_in_gre_to_tlv(
419 struct bgp_encap_type_mpls_in_gre *bet, /* input structure */
422 struct attr_extra *extra = bgp_attr_extra_get(attr);
424 extra->encap_tunneltype = BGP_ENCAP_TYPE_MPLS_IN_GRE;
428 bgp_encap_type_vxlan_gpe_to_tlv(
429 struct bgp_encap_type_vxlan_gpe *bet, /* input structure */
432 struct attr_extra *extra = bgp_attr_extra_get(attr);
434 extra->encap_tunneltype = BGP_ENCAP_TYPE_VXLAN_GPE;
438 bgp_encap_type_mpls_in_udp_to_tlv(
439 struct bgp_encap_type_mpls_in_udp *bet, /* input structure */
442 struct attr_extra *extra = bgp_attr_extra_get(attr);
444 extra->encap_tunneltype = BGP_ENCAP_TYPE_MPLS_IN_UDP;
448 /***********************************************************************
450 ***********************************************************************/
453 subtlv_decode_encap_l2tpv3_over_ip(
454 struct bgp_attr_encap_subtlv *subtlv,
455 struct bgp_tea_subtlv_encap_l2tpv3_over_ip *st)
457 if (subtlv->length < 4) {
458 zlog_debug("%s, subtlv length %d is less than 4",
459 __func__, subtlv->length);
463 st->sessionid = (subtlv->value[0] << 24) |
464 (subtlv->value[1] << 16) |
465 (subtlv->value[2] << 8) |
467 st->cookie_length = subtlv->length - 4;
468 if (st->cookie_length > sizeof(st->cookie)) {
469 zlog_debug("%s, subtlv length %d is greater than %d",
470 __func__, st->cookie_length, (int)sizeof(st->cookie));
473 memcpy(st->cookie, subtlv->value + 4, st->cookie_length);
479 subtlv_decode_encap_gre(
480 struct bgp_attr_encap_subtlv *subtlv,
481 struct bgp_tea_subtlv_encap_gre_key *st)
483 if (subtlv->length != 4) {
484 zlog_debug("%s, subtlv length %d does not equal 4",
485 __func__, subtlv->length);
488 st->gre_key = (subtlv->value[0] << 24) |
489 (subtlv->value[1] << 16) |
490 (subtlv->value[2] << 8) |
496 subtlv_decode_encap_pbb(
497 struct bgp_attr_encap_subtlv *subtlv,
498 struct bgp_tea_subtlv_encap_pbb *st)
500 if (subtlv->length != 1 + 3 + 6 + 2) {
501 zlog_debug("%s, subtlv length %d does not equal %d",
502 __func__, subtlv->length, 1 + 3 + 6 + 2);
505 if (subtlv->value[0] & 0x80) {
507 st->isid = (subtlv->value[1] << 16) |
508 (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);
521 subtlv_decode_proto_type(
522 struct bgp_attr_encap_subtlv *subtlv,
523 struct bgp_tea_subtlv_proto_type *st)
525 if (subtlv->length != 2) {
526 zlog_debug("%s, subtlv length %d does not equal 2",
527 __func__, subtlv->length);
530 st->proto = (subtlv->value[0] << 8) | subtlv->value[1];
537 struct bgp_attr_encap_subtlv *subtlv,
538 struct bgp_tea_subtlv_color *st)
540 if (subtlv->length != 8) {
541 zlog_debug("%s, subtlv length %d does not equal 8",
542 __func__, subtlv->length);
545 if ((subtlv->value[0] != 0x03) ||
546 (subtlv->value[1] != 0x0b) ||
547 (subtlv->value[2] != 0) ||
548 (subtlv->value[3] != 0)) {
549 zlog_debug("%s, subtlv value 1st 4 bytes are not 0x030b0000", __func__);
552 st->color = (subtlv->value[4] << 24) |
553 (subtlv->value[5] << 16) |
554 (subtlv->value[6] << 8) |
561 subtlv_decode_ipsec_ta(
562 struct bgp_attr_encap_subtlv *subtlv,
563 struct bgp_tea_subtlv_ipsec_ta *st)
565 st->authenticator_length = subtlv->length - 2;
566 if (st->authenticator_length > sizeof(st->value)) {
567 zlog_debug("%s, authenticator length %d exceeds storage maximum %d",
568 __func__, st->authenticator_length, (int)sizeof(st->value));
571 st->authenticator_type = (subtlv->value[0] << 8) | subtlv->value[1];
572 memcpy(st->value, subtlv->value + 2, st->authenticator_length);
576 /* draft-rosen-idr-tunnel-encaps 2.1 */
578 subtlv_decode_remote_endpoint(
579 struct bgp_attr_encap_subtlv *subtlv,
580 struct bgp_tea_subtlv_remote_endpoint *st)
583 if (subtlv->length != 8 && subtlv->length != 20 ) {
584 zlog_debug("%s, subtlv length %d does not equal 8 or 20",
585 __func__, subtlv->length);
588 if (subtlv->length == 8) {
589 st->family = AF_INET;
590 st->ip_address.v4.s_addr = ((subtlv->value[0] << 24) |
591 (subtlv->value[1] << 16) |
592 (subtlv->value[2] << 8) |
595 st->family = AF_INET6;
596 memcpy (&(st->ip_address.v6.s6_addr), subtlv->value, 16);
598 i = subtlv->length - 4;
599 st->as4 = ((subtlv->value[i] << 24) |
600 (subtlv->value[i+1] << 16) |
601 (subtlv->value[i+2] << 8) |
606 /***********************************************************************
607 * TUNNEL TYPE-SPECIFIC TLV DECODE
608 ***********************************************************************/
611 tlv_to_bgp_encap_type_l2tpv3overip(
612 struct bgp_attr_encap_subtlv *stlv, /* subtlv chain */
613 struct bgp_encap_type_l2tpv3_over_ip *bet) /* caller-allocated */
615 struct bgp_attr_encap_subtlv *st;
618 for (st = stlv; st; st = st->next) {
620 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION:
621 rc |= subtlv_decode_encap_l2tpv3_over_ip(st, &bet->st_encap);
622 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_ENCAP);
625 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE:
626 rc |= subtlv_decode_proto_type(st, &bet->st_proto);
627 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_PROTO_TYPE);
630 case BGP_ENCAP_SUBTLV_TYPE_COLOR:
631 rc |= subtlv_decode_color(st, &bet->st_color);
632 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_COLOR);
635 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
636 rc |= subtlv_decode_remote_endpoint(st, &bet->st_endpoint);
637 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
641 zlog_debug("%s: unexpected subtlv type %d", __func__, st->type);
650 tlv_to_bgp_encap_type_gre(
651 struct bgp_attr_encap_subtlv *stlv, /* subtlv chain */
652 struct bgp_encap_type_gre *bet) /* caller-allocated */
654 struct bgp_attr_encap_subtlv *st;
657 for (st = stlv; st; st = st->next) {
659 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION:
660 rc |= subtlv_decode_encap_gre(st, &bet->st_encap);
661 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_ENCAP);
664 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE:
665 rc |= subtlv_decode_proto_type(st, &bet->st_proto);
666 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_PROTO_TYPE);
669 case BGP_ENCAP_SUBTLV_TYPE_COLOR:
670 rc |= subtlv_decode_color(st, &bet->st_color);
671 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_COLOR);
674 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
675 rc |= subtlv_decode_remote_endpoint(st, &bet->st_endpoint);
676 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
680 zlog_debug("%s: unexpected subtlv type %d", __func__, st->type);
689 tlv_to_bgp_encap_type_ip_in_ip(
690 struct bgp_attr_encap_subtlv *stlv, /* subtlv chain */
691 struct bgp_encap_type_ip_in_ip *bet) /* caller-allocated */
693 struct bgp_attr_encap_subtlv *st;
696 for (st = stlv; st; st = st->next) {
698 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE:
699 rc |= subtlv_decode_proto_type(st, &bet->st_proto);
700 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_PROTO_TYPE);
703 case BGP_ENCAP_SUBTLV_TYPE_COLOR:
704 rc |= subtlv_decode_color(st, &bet->st_color);
705 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_COLOR);
708 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
709 rc |= subtlv_decode_remote_endpoint(st, &bet->st_endpoint);
710 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
714 zlog_debug("%s: unexpected subtlv type %d", __func__, st->type);
723 tlv_to_bgp_encap_type_transmit_tunnel_endpoint(
724 struct bgp_attr_encap_subtlv *stlv,
725 struct bgp_encap_type_transmit_tunnel_endpoint *bet)
727 struct bgp_attr_encap_subtlv *st;
730 for (st = stlv; st; st = st->next) {
733 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
734 rc |= subtlv_decode_remote_endpoint(st, &bet->st_endpoint);
735 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
739 zlog_debug("%s: unexpected subtlv type %d", __func__, st->type);
748 tlv_to_bgp_encap_type_ipsec_in_tunnel_mode(
749 struct bgp_attr_encap_subtlv *stlv, /* subtlv chain */
750 struct bgp_encap_type_ipsec_in_tunnel_mode *bet) /* caller-allocated */
752 struct bgp_attr_encap_subtlv *st;
755 for (st = stlv; st; st = st->next) {
757 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA:
758 rc |= subtlv_decode_ipsec_ta(st, &bet->st_ipsec_ta);
759 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_IPSEC_TA);
762 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
763 rc |= subtlv_decode_remote_endpoint(st, &bet->st_endpoint);
764 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
768 zlog_debug("%s: unexpected subtlv type %d", __func__, st->type);
777 tlv_to_bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode(
778 struct bgp_attr_encap_subtlv *stlv,
779 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode *bet)
781 struct bgp_attr_encap_subtlv *st;
784 for (st = stlv; st; st = st->next) {
786 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA:
787 rc |= subtlv_decode_ipsec_ta(st, &bet->st_ipsec_ta);
788 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_IPSEC_TA);
791 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
792 rc |= subtlv_decode_remote_endpoint(st, &bet->st_endpoint);
793 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
797 zlog_debug("%s: unexpected subtlv type %d", __func__, st->type);
806 tlv_to_bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode(
807 struct bgp_attr_encap_subtlv *stlv,
808 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode *bet)
810 struct bgp_attr_encap_subtlv *st;
813 for (st = stlv; st; st = st->next) {
815 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA:
816 rc |= subtlv_decode_ipsec_ta(st, &bet->st_ipsec_ta);
817 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_IPSEC_TA);
820 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
821 rc |= subtlv_decode_remote_endpoint(st, &bet->st_endpoint);
822 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
826 zlog_debug("%s: unexpected subtlv type %d", __func__, st->type);
835 tlv_to_bgp_encap_type_vxlan(
836 struct bgp_attr_encap_subtlv *stlv,
837 struct bgp_encap_type_vxlan *bet)
839 struct bgp_attr_encap_subtlv *st;
842 for (st = stlv; st; st = st->next) {
845 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
846 rc |= subtlv_decode_remote_endpoint(st, &bet->st_endpoint);
847 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
851 zlog_debug("%s: unexpected subtlv type %d", __func__, st->type);
860 tlv_to_bgp_encap_type_nvgre(
861 struct bgp_attr_encap_subtlv *stlv,
862 struct bgp_encap_type_nvgre *bet)
864 struct bgp_attr_encap_subtlv *st;
867 for (st = stlv; st; st = st->next) {
870 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
871 rc |= subtlv_decode_remote_endpoint(st, &bet->st_endpoint);
872 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
876 zlog_debug("%s: unexpected subtlv type %d", __func__, st->type);
885 tlv_to_bgp_encap_type_mpls(
886 struct bgp_attr_encap_subtlv *stlv,
887 struct bgp_encap_type_mpls *bet)
889 struct bgp_attr_encap_subtlv *st;
892 for (st = stlv; st; st = st->next) {
895 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
896 rc |= subtlv_decode_remote_endpoint(st, &bet->st_endpoint);
897 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
901 zlog_debug("%s: unexpected subtlv type %d", __func__, st->type);
910 tlv_to_bgp_encap_type_mpls_in_gre(
911 struct bgp_attr_encap_subtlv *stlv,
912 struct bgp_encap_type_mpls_in_gre *bet)
914 struct bgp_attr_encap_subtlv *st;
917 for (st = stlv; st; st = st->next) {
920 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
921 rc |= subtlv_decode_remote_endpoint(st, &bet->st_endpoint);
922 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
926 zlog_debug("%s: unexpected subtlv type %d", __func__, st->type);
935 tlv_to_bgp_encap_type_vxlan_gpe(
936 struct bgp_attr_encap_subtlv *stlv,
937 struct bgp_encap_type_vxlan_gpe *bet)
939 struct bgp_attr_encap_subtlv *st;
942 for (st = stlv; st; st = st->next) {
945 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
946 rc |= subtlv_decode_remote_endpoint(st, &bet->st_endpoint);
947 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
951 zlog_debug("%s: unexpected subtlv type %d", __func__, st->type);
960 tlv_to_bgp_encap_type_mpls_in_udp(
961 struct bgp_attr_encap_subtlv *stlv,
962 struct bgp_encap_type_mpls_in_udp *bet)
964 struct bgp_attr_encap_subtlv *st;
967 for (st = stlv; st; st = st->next) {
970 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
971 rc |= subtlv_decode_remote_endpoint(st, &bet->st_endpoint);
972 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
976 zlog_debug("%s: unexpected subtlv type %d", __func__, st->type);
985 tlv_to_bgp_encap_type_pbb(
986 struct bgp_attr_encap_subtlv *stlv, /* subtlv chain */
987 struct bgp_encap_type_pbb *bet) /* caller-allocated */
989 struct bgp_attr_encap_subtlv *st;
992 for (st = stlv; st; st = st->next) {
994 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION:
995 rc |= subtlv_decode_encap_pbb(st, &bet->st_encap);
996 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_ENCAP);
999 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
1000 rc |= subtlv_decode_remote_endpoint(st, &bet->st_endpoint);
1001 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
1005 zlog_debug("%s: unexpected subtlv type %d", __func__, st->type);