]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_encap_tlv.c
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / bgpd / bgp_encap_tlv.c
1 /*
2 * Copyright 2015, LabN Consulting, L.L.C.
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include <zebra.h>
20
21 #include "command.h"
22 #include "memory.h"
23 #include "prefix.h"
24 #include "filter.h"
25 #include "stream.h"
26
27 #include "bgpd.h"
28 #include "bgp_attr.h"
29
30 #include "bgp_encap_types.h"
31 #include "bgp_encap_tlv.h"
32
33 /***********************************************************************
34 * SUBTLV ENCODE
35 ***********************************************************************/
36
37 /* rfc5512 4.1 */
38 static struct bgp_attr_encap_subtlv *subtlv_encode_encap_l2tpv3_over_ip(
39 struct bgp_tea_subtlv_encap_l2tpv3_over_ip *st)
40 {
41 struct bgp_attr_encap_subtlv *new;
42 uint8_t *p;
43 int total = 4 + st->cookie_length;
44
45 /* sanity check */
46 assert(st->cookie_length <= sizeof(st->cookie));
47 assert(total <= 0xff);
48
49 new = XCALLOC(MTYPE_ENCAP_TLV,
50 sizeof(struct bgp_attr_encap_subtlv) + total);
51 assert(new);
52 new->type = BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION;
53 new->length = total;
54 p = new->value;
55
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);
61 return new;
62 }
63
64 /* rfc5512 4.1 */
65 static struct bgp_attr_encap_subtlv *
66 subtlv_encode_encap_gre(struct bgp_tea_subtlv_encap_gre_key *st)
67 {
68 struct bgp_attr_encap_subtlv *new;
69 uint8_t *p;
70 int total = 4;
71
72 assert(total <= 0xff);
73
74 new = XCALLOC(MTYPE_ENCAP_TLV,
75 sizeof(struct bgp_attr_encap_subtlv) + total);
76 assert(new);
77 new->type = BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION;
78 new->length = total;
79 p = new->value;
80
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);
85 return new;
86 }
87
88 static struct bgp_attr_encap_subtlv *
89 subtlv_encode_encap_pbb(struct bgp_tea_subtlv_encap_pbb *st)
90 {
91 struct bgp_attr_encap_subtlv *new;
92 uint8_t *p;
93 int total = 1 + 3 + 6 + 2; /* flags + isid + madaddr + vid */
94
95 assert(total <= 0xff);
96
97 new = XCALLOC(MTYPE_ENCAP_TLV,
98 sizeof(struct bgp_attr_encap_subtlv) + total);
99 assert(new);
100 new->type = BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION;
101 new->length = total;
102 p = new->value;
103
104 *p++ = (st->flag_isid ? 0x80 : 0) | (st->flag_vid ? 0x40 : 0) | 0;
105 if (st->flag_isid) {
106 *p = (st->isid & 0xff0000) >> 16;
107 *(p + 1) = (st->isid & 0xff00) >> 8;
108 *(p + 2) = (st->isid & 0xff);
109 }
110 p += 3;
111 memcpy(p, st->macaddr, 6);
112 p += 6;
113 if (st->flag_vid) {
114 *p++ = (st->vid & 0xf00) >> 8;
115 *p++ = st->vid & 0xff;
116 }
117 return new;
118 }
119
120 /* rfc5512 4.2 */
121 static struct bgp_attr_encap_subtlv *
122 subtlv_encode_proto_type(struct bgp_tea_subtlv_proto_type *st)
123 {
124 struct bgp_attr_encap_subtlv *new;
125 uint8_t *p;
126 int total = 2;
127
128 assert(total <= 0xff);
129
130 new = XCALLOC(MTYPE_ENCAP_TLV,
131 sizeof(struct bgp_attr_encap_subtlv) + total);
132 assert(new);
133 new->type = BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE;
134 new->length = total;
135 p = new->value;
136
137 *p++ = (st->proto & 0xff00) >> 8;
138 *p++ = (st->proto & 0xff);
139 return new;
140 }
141
142 /* rfc5512 4.3 */
143 static struct bgp_attr_encap_subtlv *
144 subtlv_encode_color(struct bgp_tea_subtlv_color *st)
145 {
146 struct bgp_attr_encap_subtlv *new;
147 uint8_t *p;
148 int total = 8;
149
150 assert(total <= 0xff);
151
152 new = XCALLOC(MTYPE_ENCAP_TLV,
153 sizeof(struct bgp_attr_encap_subtlv) + total);
154 assert(new);
155 new->type = BGP_ENCAP_SUBTLV_TYPE_COLOR;
156 new->length = total;
157 p = new->value;
158
159 *p++ = 0x03; /* transitive*/
160 *p++ = 0x0b;
161 *p++ = 0; /* reserved */
162 *p++ = 0; /* reserved */
163
164 *p++ = (st->color & 0xff000000) >> 24;
165 *p++ = (st->color & 0xff0000) >> 16;
166 *p++ = (st->color & 0xff00) >> 8;
167 *p++ = (st->color & 0xff);
168
169 return new;
170 }
171
172 /* rfc 5566 4. */
173 static struct bgp_attr_encap_subtlv *
174 subtlv_encode_ipsec_ta(struct bgp_tea_subtlv_ipsec_ta *st)
175 {
176 struct bgp_attr_encap_subtlv *new;
177 uint8_t *p;
178 int total = 2 + st->authenticator_length;
179
180 /* sanity check */
181 assert(st->authenticator_length <= sizeof(st->value));
182 assert(total <= 0xff);
183
184 new = XCALLOC(MTYPE_ENCAP_TLV,
185 sizeof(struct bgp_attr_encap_subtlv) + total);
186 assert(new);
187 new->type = BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA;
188 new->length = total;
189 p = new->value;
190
191 *p++ = (st->authenticator_type & 0xff00) >> 8;
192 *p++ = st->authenticator_type & 0xff;
193 memcpy(p, st->value, st->authenticator_length);
194 return new;
195 }
196
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)
200 {
201 struct bgp_attr_encap_subtlv *new;
202 uint8_t *p;
203
204 int total = (st->family == AF_INET ? 8 : 20);
205
206 assert(total <= 0xff);
207
208 new = XCALLOC(MTYPE_ENCAP_TLV,
209 sizeof(struct bgp_attr_encap_subtlv) + total);
210 assert(new);
211 new->type = BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT;
212 new->length = total;
213 p = new->value;
214 if (st->family == AF_INET) {
215 memcpy(p, &(st->ip_address.v4.s_addr), IPV4_MAX_BYTELEN);
216 p += IPV4_MAX_BYTELEN;
217 } else {
218 assert(st->family == AF_INET6);
219 memcpy(p, &(st->ip_address.v6.s6_addr), IPV6_MAX_BYTELEN);
220 p += IPV6_MAX_BYTELEN;
221 }
222 memcpy(p, &(st->as4), 4);
223 return new;
224 }
225
226 /***********************************************************************
227 * TUNNEL TYPE-SPECIFIC TLV ENCODE
228 ***********************************************************************/
229
230 /*
231 * requires "extra" and "last" to be defined in caller
232 */
233 #define ENC_SUBTLV(flag, function, field) \
234 do { \
235 struct bgp_attr_encap_subtlv *new; \
236 if (CHECK_FLAG(bet->valid_subtlvs, (flag))) { \
237 new = function(&bet->field); \
238 if (last) { \
239 last->next = new; \
240 } else { \
241 attr->encap_subtlvs = new; \
242 } \
243 last = new; \
244 } \
245 } while (0)
246
247 void bgp_encap_type_l2tpv3overip_to_tlv(
248 struct bgp_encap_type_l2tpv3_over_ip *bet, /* input structure */
249 struct attr *attr)
250 {
251 struct bgp_attr_encap_subtlv *last;
252
253 /* advance to last subtlv */
254 for (last = attr->encap_subtlvs; last && last->next; last = last->next)
255 ;
256
257 attr->encap_tunneltype = BGP_ENCAP_TYPE_L2TPV3_OVER_IP;
258
259 assert(CHECK_FLAG(bet->valid_subtlvs, BGP_TEA_SUBTLV_ENCAP));
260
261 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP, subtlv_encode_encap_l2tpv3_over_ip,
262 st_encap);
263 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE, subtlv_encode_proto_type,
264 st_proto);
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);
268 }
269
270 void bgp_encap_type_gre_to_tlv(
271 struct bgp_encap_type_gre *bet, /* input structure */
272 struct attr *attr)
273 {
274 struct bgp_attr_encap_subtlv *last;
275
276 /* advance to last subtlv */
277 for (last = attr->encap_subtlvs; last && last->next; last = last->next)
278 ;
279
280 attr->encap_tunneltype = BGP_ENCAP_TYPE_GRE;
281
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,
284 st_proto);
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);
288 }
289
290 void bgp_encap_type_ip_in_ip_to_tlv(
291 struct bgp_encap_type_ip_in_ip *bet, /* input structure */
292 struct attr *attr)
293 {
294 struct bgp_attr_encap_subtlv *last;
295
296 /* advance to last subtlv */
297 for (last = attr->encap_subtlvs; last && last->next; last = last->next)
298 ;
299
300 attr->encap_tunneltype = BGP_ENCAP_TYPE_IP_IN_IP;
301
302 ENC_SUBTLV(BGP_TEA_SUBTLV_PROTO_TYPE, subtlv_encode_proto_type,
303 st_proto);
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);
307 }
308
309 void bgp_encap_type_transmit_tunnel_endpoint(
310 struct bgp_encap_type_transmit_tunnel_endpoint
311 *bet, /* input structure */
312 struct attr *attr)
313 {
314 struct bgp_attr_encap_subtlv *last;
315
316 /* advance to last subtlv */
317 for (last = attr->encap_subtlvs; last && last->next; last = last->next)
318 ;
319
320 attr->encap_tunneltype = BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT;
321
322 /* no subtlvs for this type */
323 }
324
325 void bgp_encap_type_ipsec_in_tunnel_mode_to_tlv(
326 struct bgp_encap_type_ipsec_in_tunnel_mode *bet, /* input structure */
327 struct attr *attr)
328 {
329 struct bgp_attr_encap_subtlv *last;
330
331 /* advance to last subtlv */
332 for (last = attr->encap_subtlvs; last && last->next; last = last->next)
333 ;
334
335 attr->encap_tunneltype = BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE;
336
337 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA, subtlv_encode_ipsec_ta,
338 st_ipsec_ta);
339 }
340
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 */
344 struct attr *attr)
345 {
346 struct bgp_attr_encap_subtlv *last;
347
348 /* advance to last subtlv */
349 for (last = attr->encap_subtlvs; last && last->next; last = last->next)
350 ;
351
352 attr->encap_tunneltype =
353 BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE;
354
355 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA, subtlv_encode_ipsec_ta,
356 st_ipsec_ta);
357 }
358
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 */
362 struct attr *attr)
363 {
364 struct bgp_attr_encap_subtlv *last;
365
366 /* advance to last subtlv */
367 for (last = attr->encap_subtlvs; last && last->next; last = last->next)
368 ;
369
370 attr->encap_tunneltype =
371 BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE;
372
373 ENC_SUBTLV(BGP_TEA_SUBTLV_IPSEC_TA, subtlv_encode_ipsec_ta,
374 st_ipsec_ta);
375 }
376
377 void bgp_encap_type_pbb_to_tlv(
378 struct bgp_encap_type_pbb *bet, /* input structure */
379 struct attr *attr)
380 {
381 struct bgp_attr_encap_subtlv *last;
382
383 /* advance to last subtlv */
384 for (last = attr->encap_subtlvs; last && last->next; last = last->next)
385 ;
386
387 attr->encap_tunneltype = BGP_ENCAP_TYPE_PBB;
388
389 assert(CHECK_FLAG(bet->valid_subtlvs, BGP_TEA_SUBTLV_ENCAP));
390 ENC_SUBTLV(BGP_TEA_SUBTLV_ENCAP, subtlv_encode_encap_pbb, st_encap);
391 }
392
393 void bgp_encap_type_vxlan_to_tlv(
394 struct bgp_encap_type_vxlan *bet, /* input structure */
395 struct attr *attr)
396 {
397 struct bgp_attr_encap_subtlv *tlv;
398 uint32_t vnid;
399
400 attr->encap_tunneltype = BGP_ENCAP_TYPE_VXLAN;
401
402 if (bet == NULL || !bet->vnid)
403 return;
404 XFREE(MTYPE_ENCAP_TLV, attr->encap_subtlvs);
405 tlv = XCALLOC(MTYPE_ENCAP_TLV,
406 sizeof(struct bgp_attr_encap_subtlv) + 12);
407 tlv->type = 1; /* encapsulation type */
408 tlv->length = 12;
409 if (bet->vnid) {
410 vnid = htonl(bet->vnid | VXLAN_ENCAP_MASK_VNID_VALID);
411 memcpy(&tlv->value, &vnid, 4);
412 }
413 if (bet->mac_address) {
414 char *ptr = (char *)&tlv->value + 4;
415 memcpy(ptr, bet->mac_address, 6);
416 }
417 attr->encap_subtlvs = tlv;
418 return;
419 }
420
421 void bgp_encap_type_nvgre_to_tlv(
422 struct bgp_encap_type_nvgre *bet, /* input structure */
423 struct attr *attr)
424 {
425 attr->encap_tunneltype = BGP_ENCAP_TYPE_NVGRE;
426 }
427
428 void bgp_encap_type_mpls_to_tlv(
429 struct bgp_encap_type_mpls *bet, /* input structure */
430 struct attr *attr)
431 {
432 return; /* no encap attribute for MPLS */
433 }
434
435 void bgp_encap_type_mpls_in_gre_to_tlv(
436 struct bgp_encap_type_mpls_in_gre *bet, /* input structure */
437 struct attr *attr)
438 {
439 attr->encap_tunneltype = BGP_ENCAP_TYPE_MPLS_IN_GRE;
440 }
441
442 void bgp_encap_type_vxlan_gpe_to_tlv(
443 struct bgp_encap_type_vxlan_gpe *bet, /* input structure */
444 struct attr *attr)
445 {
446
447 attr->encap_tunneltype = BGP_ENCAP_TYPE_VXLAN_GPE;
448 }
449
450 void bgp_encap_type_mpls_in_udp_to_tlv(
451 struct bgp_encap_type_mpls_in_udp *bet, /* input structure */
452 struct attr *attr)
453 {
454
455 attr->encap_tunneltype = BGP_ENCAP_TYPE_MPLS_IN_UDP;
456 }
457
458
459 /***********************************************************************
460 * SUBTLV DECODE
461 ***********************************************************************/
462 /* rfc5512 4.1 */
463 static int subtlv_decode_encap_l2tpv3_over_ip(
464 struct bgp_attr_encap_subtlv *subtlv,
465 struct bgp_tea_subtlv_encap_l2tpv3_over_ip *st)
466 {
467 if (subtlv->length < 4) {
468 zlog_debug("%s, subtlv length %d is less than 4", __func__,
469 subtlv->length);
470 return -1;
471 }
472
473 ptr_get_be32(subtlv->value, &st->sessionid);
474 st->cookie_length = subtlv->length - 4;
475 if (st->cookie_length > sizeof(st->cookie)) {
476 zlog_debug("%s, subtlv length %d is greater than %d", __func__,
477 st->cookie_length, (int)sizeof(st->cookie));
478 return -1;
479 }
480 memcpy(st->cookie, subtlv->value + 4, st->cookie_length);
481 return 0;
482 }
483
484 /* rfc5512 4.1 */
485 static int subtlv_decode_encap_gre(struct bgp_attr_encap_subtlv *subtlv,
486 struct bgp_tea_subtlv_encap_gre_key *st)
487 {
488 if (subtlv->length != 4) {
489 zlog_debug("%s, subtlv length %d does not equal 4", __func__,
490 subtlv->length);
491 return -1;
492 }
493 ptr_get_be32(subtlv->value, &st->gre_key);
494 return 0;
495 }
496
497 static int subtlv_decode_encap_pbb(struct bgp_attr_encap_subtlv *subtlv,
498 struct bgp_tea_subtlv_encap_pbb *st)
499 {
500 if (subtlv->length != 1 + 3 + 6 + 2) {
501 zlog_debug("%s, subtlv length %d does not equal %d", __func__,
502 subtlv->length, 1 + 3 + 6 + 2);
503 return -1;
504 }
505 if (subtlv->value[0] & 0x80) {
506 st->flag_isid = 1;
507 st->isid = (subtlv->value[1] << 16) | (subtlv->value[2] << 8)
508 | subtlv->value[3];
509 }
510 if (subtlv->value[0] & 0x40) {
511 st->flag_vid = 1;
512 st->vid = ((subtlv->value[10] & 0x0f) << 8) | subtlv->value[11];
513 }
514 memcpy(st->macaddr, subtlv->value + 4, 6);
515 return 0;
516 }
517
518 /* rfc5512 4.2 */
519 static int subtlv_decode_proto_type(struct bgp_attr_encap_subtlv *subtlv,
520 struct bgp_tea_subtlv_proto_type *st)
521 {
522 if (subtlv->length != 2) {
523 zlog_debug("%s, subtlv length %d does not equal 2", __func__,
524 subtlv->length);
525 return -1;
526 }
527 st->proto = (subtlv->value[0] << 8) | subtlv->value[1];
528 return 0;
529 }
530
531 /* rfc5512 4.3 */
532 static int subtlv_decode_color(struct bgp_attr_encap_subtlv *subtlv,
533 struct bgp_tea_subtlv_color *st)
534 {
535 if (subtlv->length != 8) {
536 zlog_debug("%s, subtlv length %d does not equal 8", __func__,
537 subtlv->length);
538 return -1;
539 }
540 if ((subtlv->value[0] != 0x03) || (subtlv->value[1] != 0x0b)
541 || (subtlv->value[2] != 0) || (subtlv->value[3] != 0)) {
542 zlog_debug("%s, subtlv value 1st 4 bytes are not 0x030b0000",
543 __func__);
544 return -1;
545 }
546 ptr_get_be32(subtlv->value + 4, &st->color);
547 return 0;
548 }
549
550 /* rfc 5566 4. */
551 static int subtlv_decode_ipsec_ta(struct bgp_attr_encap_subtlv *subtlv,
552 struct bgp_tea_subtlv_ipsec_ta *st)
553 {
554 st->authenticator_length = subtlv->length - 2;
555 if (st->authenticator_length > sizeof(st->value)) {
556 zlog_debug(
557 "%s, authenticator length %d exceeds storage maximum %d",
558 __func__, st->authenticator_length,
559 (int)sizeof(st->value));
560 return -1;
561 }
562 st->authenticator_type = (subtlv->value[0] << 8) | subtlv->value[1];
563 memcpy(st->value, subtlv->value + 2, st->authenticator_length);
564 return 0;
565 }
566
567 /* draft-rosen-idr-tunnel-encaps 2.1 */
568 static int
569 subtlv_decode_remote_endpoint(struct bgp_attr_encap_subtlv *subtlv,
570 struct bgp_tea_subtlv_remote_endpoint *st)
571 {
572 int i;
573 if (subtlv->length != 8 && subtlv->length != 20) {
574 zlog_debug("%s, subtlv length %d does not equal 8 or 20",
575 __func__, subtlv->length);
576 return -1;
577 }
578 if (subtlv->length == 8) {
579 st->family = AF_INET;
580 memcpy(&st->ip_address.v4.s_addr, subtlv->value,
581 IPV4_MAX_BYTELEN);
582 } else {
583 st->family = AF_INET6;
584 memcpy(&(st->ip_address.v6.s6_addr), subtlv->value,
585 IPV6_MAX_BYTELEN);
586 }
587 i = subtlv->length - 4;
588 ptr_get_be32(subtlv->value + i, &st->as4);
589 return 0;
590 }
591
592 /***********************************************************************
593 * TUNNEL TYPE-SPECIFIC TLV DECODE
594 ***********************************************************************/
595
596 int tlv_to_bgp_encap_type_l2tpv3overip(
597 struct bgp_attr_encap_subtlv *stlv, /* subtlv chain */
598 struct bgp_encap_type_l2tpv3_over_ip *bet) /* caller-allocated */
599 {
600 struct bgp_attr_encap_subtlv *st;
601 int rc = 0;
602
603 for (st = stlv; st; st = st->next) {
604 switch (st->type) {
605 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION:
606 rc |= subtlv_decode_encap_l2tpv3_over_ip(
607 st, &bet->st_encap);
608 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_ENCAP);
609 break;
610
611 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE:
612 rc |= subtlv_decode_proto_type(st, &bet->st_proto);
613 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_PROTO_TYPE);
614 break;
615
616 case BGP_ENCAP_SUBTLV_TYPE_COLOR:
617 rc |= subtlv_decode_color(st, &bet->st_color);
618 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_COLOR);
619 break;
620
621 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
622 rc |= subtlv_decode_remote_endpoint(st,
623 &bet->st_endpoint);
624 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
625 break;
626
627 default:
628 zlog_debug("%s: unexpected subtlv type %d", __func__,
629 st->type);
630 rc |= -1;
631 break;
632 }
633 }
634 return rc;
635 }
636
637 int tlv_to_bgp_encap_type_gre(
638 struct bgp_attr_encap_subtlv *stlv, /* subtlv chain */
639 struct bgp_encap_type_gre *bet) /* caller-allocated */
640 {
641 struct bgp_attr_encap_subtlv *st;
642 int rc = 0;
643
644 for (st = stlv; st; st = st->next) {
645 switch (st->type) {
646 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION:
647 rc |= subtlv_decode_encap_gre(st, &bet->st_encap);
648 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_ENCAP);
649 break;
650
651 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE:
652 rc |= subtlv_decode_proto_type(st, &bet->st_proto);
653 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_PROTO_TYPE);
654 break;
655
656 case BGP_ENCAP_SUBTLV_TYPE_COLOR:
657 rc |= subtlv_decode_color(st, &bet->st_color);
658 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_COLOR);
659 break;
660
661 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
662 rc |= subtlv_decode_remote_endpoint(st,
663 &bet->st_endpoint);
664 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
665 break;
666
667 default:
668 zlog_debug("%s: unexpected subtlv type %d", __func__,
669 st->type);
670 rc |= -1;
671 break;
672 }
673 }
674 return rc;
675 }
676
677 int tlv_to_bgp_encap_type_ip_in_ip(
678 struct bgp_attr_encap_subtlv *stlv, /* subtlv chain */
679 struct bgp_encap_type_ip_in_ip *bet) /* caller-allocated */
680 {
681 struct bgp_attr_encap_subtlv *st;
682 int rc = 0;
683
684 for (st = stlv; st; st = st->next) {
685 switch (st->type) {
686 case BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE:
687 rc |= subtlv_decode_proto_type(st, &bet->st_proto);
688 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_PROTO_TYPE);
689 break;
690
691 case BGP_ENCAP_SUBTLV_TYPE_COLOR:
692 rc |= subtlv_decode_color(st, &bet->st_color);
693 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_COLOR);
694 break;
695
696 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
697 rc |= subtlv_decode_remote_endpoint(st,
698 &bet->st_endpoint);
699 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
700 break;
701
702 default:
703 zlog_debug("%s: unexpected subtlv type %d", __func__,
704 st->type);
705 rc |= -1;
706 break;
707 }
708 }
709 return rc;
710 }
711
712 int tlv_to_bgp_encap_type_transmit_tunnel_endpoint(
713 struct bgp_attr_encap_subtlv *stlv,
714 struct bgp_encap_type_transmit_tunnel_endpoint *bet)
715 {
716 struct bgp_attr_encap_subtlv *st;
717 int rc = 0;
718
719 for (st = stlv; st; st = st->next) {
720 switch (st->type) {
721
722 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
723 rc |= subtlv_decode_remote_endpoint(st,
724 &bet->st_endpoint);
725 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
726 break;
727
728 default:
729 zlog_debug("%s: unexpected subtlv type %d", __func__,
730 st->type);
731 rc |= -1;
732 break;
733 }
734 }
735 return rc;
736 }
737
738 int tlv_to_bgp_encap_type_ipsec_in_tunnel_mode(
739 struct bgp_attr_encap_subtlv *stlv, /* subtlv chain */
740 struct bgp_encap_type_ipsec_in_tunnel_mode *bet) /* caller-allocated */
741 {
742 struct bgp_attr_encap_subtlv *st;
743 int rc = 0;
744
745 for (st = stlv; st; st = st->next) {
746 switch (st->type) {
747 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA:
748 rc |= subtlv_decode_ipsec_ta(st, &bet->st_ipsec_ta);
749 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_IPSEC_TA);
750 break;
751
752 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
753 rc |= subtlv_decode_remote_endpoint(st,
754 &bet->st_endpoint);
755 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
756 break;
757
758 default:
759 zlog_debug("%s: unexpected subtlv type %d", __func__,
760 st->type);
761 rc |= -1;
762 break;
763 }
764 }
765 return rc;
766 }
767
768 int tlv_to_bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode(
769 struct bgp_attr_encap_subtlv *stlv,
770 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode *bet)
771 {
772 struct bgp_attr_encap_subtlv *st;
773 int rc = 0;
774
775 for (st = stlv; st; st = st->next) {
776 switch (st->type) {
777 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA:
778 rc |= subtlv_decode_ipsec_ta(st, &bet->st_ipsec_ta);
779 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_IPSEC_TA);
780 break;
781
782 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
783 rc |= subtlv_decode_remote_endpoint(st,
784 &bet->st_endpoint);
785 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
786 break;
787
788 default:
789 zlog_debug("%s: unexpected subtlv type %d", __func__,
790 st->type);
791 rc |= -1;
792 break;
793 }
794 }
795 return rc;
796 }
797
798 int tlv_to_bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode(
799 struct bgp_attr_encap_subtlv *stlv,
800 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode *bet)
801 {
802 struct bgp_attr_encap_subtlv *st;
803 int rc = 0;
804
805 for (st = stlv; st; st = st->next) {
806 switch (st->type) {
807 case BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA:
808 rc |= subtlv_decode_ipsec_ta(st, &bet->st_ipsec_ta);
809 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_IPSEC_TA);
810 break;
811
812 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
813 rc |= subtlv_decode_remote_endpoint(st,
814 &bet->st_endpoint);
815 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
816 break;
817
818 default:
819 zlog_debug("%s: unexpected subtlv type %d", __func__,
820 st->type);
821 rc |= -1;
822 break;
823 }
824 }
825 return rc;
826 }
827
828 int tlv_to_bgp_encap_type_vxlan(struct bgp_attr_encap_subtlv *stlv,
829 struct bgp_encap_type_vxlan *bet)
830 {
831 struct bgp_attr_encap_subtlv *st;
832 int rc = 0;
833
834 for (st = stlv; st; st = st->next) {
835 switch (st->type) {
836
837 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
838 rc |= subtlv_decode_remote_endpoint(st,
839 &bet->st_endpoint);
840 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
841 break;
842
843 default:
844 zlog_debug("%s: unexpected subtlv type %d", __func__,
845 st->type);
846 rc |= -1;
847 break;
848 }
849 }
850 return rc;
851 }
852
853 int tlv_to_bgp_encap_type_nvgre(struct bgp_attr_encap_subtlv *stlv,
854 struct bgp_encap_type_nvgre *bet)
855 {
856 struct bgp_attr_encap_subtlv *st;
857 int rc = 0;
858
859 for (st = stlv; st; st = st->next) {
860 switch (st->type) {
861
862 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
863 rc |= subtlv_decode_remote_endpoint(st,
864 &bet->st_endpoint);
865 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
866 break;
867
868 default:
869 zlog_debug("%s: unexpected subtlv type %d", __func__,
870 st->type);
871 rc |= -1;
872 break;
873 }
874 }
875 return rc;
876 }
877
878 int tlv_to_bgp_encap_type_mpls(struct bgp_attr_encap_subtlv *stlv,
879 struct bgp_encap_type_mpls *bet)
880 {
881 struct bgp_attr_encap_subtlv *st;
882 int rc = 0;
883
884 for (st = stlv; st; st = st->next) {
885 switch (st->type) {
886
887 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
888 rc |= subtlv_decode_remote_endpoint(st,
889 &bet->st_endpoint);
890 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
891 break;
892
893 default:
894 zlog_debug("%s: unexpected subtlv type %d", __func__,
895 st->type);
896 rc |= -1;
897 break;
898 }
899 }
900 return rc;
901 }
902
903 int tlv_to_bgp_encap_type_mpls_in_gre(struct bgp_attr_encap_subtlv *stlv,
904 struct bgp_encap_type_mpls_in_gre *bet)
905 {
906 struct bgp_attr_encap_subtlv *st;
907 int rc = 0;
908
909 for (st = stlv; st; st = st->next) {
910 switch (st->type) {
911
912 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
913 rc |= subtlv_decode_remote_endpoint(st,
914 &bet->st_endpoint);
915 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
916 break;
917
918 default:
919 zlog_debug("%s: unexpected subtlv type %d", __func__,
920 st->type);
921 rc |= -1;
922 break;
923 }
924 }
925 return rc;
926 }
927
928 int tlv_to_bgp_encap_type_vxlan_gpe(struct bgp_attr_encap_subtlv *stlv,
929 struct bgp_encap_type_vxlan_gpe *bet)
930 {
931 struct bgp_attr_encap_subtlv *st;
932 int rc = 0;
933
934 for (st = stlv; st; st = st->next) {
935 switch (st->type) {
936
937 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
938 rc |= subtlv_decode_remote_endpoint(st,
939 &bet->st_endpoint);
940 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
941 break;
942
943 default:
944 zlog_debug("%s: unexpected subtlv type %d", __func__,
945 st->type);
946 rc |= -1;
947 break;
948 }
949 }
950 return rc;
951 }
952
953 int tlv_to_bgp_encap_type_mpls_in_udp(struct bgp_attr_encap_subtlv *stlv,
954 struct bgp_encap_type_mpls_in_udp *bet)
955 {
956 struct bgp_attr_encap_subtlv *st;
957 int rc = 0;
958
959 for (st = stlv; st; st = st->next) {
960 switch (st->type) {
961
962 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
963 rc |= subtlv_decode_remote_endpoint(st,
964 &bet->st_endpoint);
965 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
966 break;
967
968 default:
969 zlog_debug("%s: unexpected subtlv type %d", __func__,
970 st->type);
971 rc |= -1;
972 break;
973 }
974 }
975 return rc;
976 }
977
978 int tlv_to_bgp_encap_type_pbb(
979 struct bgp_attr_encap_subtlv *stlv, /* subtlv chain */
980 struct bgp_encap_type_pbb *bet) /* caller-allocated */
981 {
982 struct bgp_attr_encap_subtlv *st;
983 int rc = 0;
984
985 for (st = stlv; st; st = st->next) {
986 switch (st->type) {
987 case BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION:
988 rc |= subtlv_decode_encap_pbb(st, &bet->st_encap);
989 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_ENCAP);
990 break;
991
992 case BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT:
993 rc |= subtlv_decode_remote_endpoint(st,
994 &bet->st_endpoint);
995 SET_SUBTLV_FLAG(bet, BGP_TEA_SUBTLV_REMOTE_ENDPOINT);
996 break;
997
998 default:
999 zlog_debug("%s: unexpected subtlv type %d", __func__,
1000 st->type);
1001 rc |= -1;
1002 break;
1003 }
1004 }
1005 return rc;
1006 }