blob: d0beb1ba65748be5e9994ea9c43e0a27680e7127 [file] [log] [blame]
Lou Berger298cc2f2016-01-12 13:42:02 -05001
2/*
3 * This file created by LabN Consulting, L.L.C.
4 *
5 *
6 * This file is based on bgp_mplsvpn.c which is Copyright (C) 2000
7 * Kunihiro Ishiguro <kunihiro@zebra.org>
8 *
9 */
10
11/*
12
13This file is part of GNU Zebra.
14
15GNU Zebra is free software; you can redistribute it and/or modify it
16under the terms of the GNU General Public License as published by the
17Free Software Foundation; either version 2, or (at your option) any
18later version.
19
20GNU Zebra is distributed in the hope that it will be useful, but
21WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with GNU Zebra; see the file COPYING. If not, write to the Free
27Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
2802111-1307, USA. */
29
30#include <zebra.h>
31
32#include "command.h"
33#include "prefix.h"
34#include "log.h"
35#include "memory.h"
36#include "stream.h"
37#include "filter.h"
38
39#include "bgpd/bgpd.h"
40#include "bgpd/bgp_table.h"
41#include "bgpd/bgp_route.h"
42#include "bgpd/bgp_attr.h"
43#include "bgpd/bgp_ecommunity.h"
44#include "bgpd/bgp_mplsvpn.h"
45#include "bgpd/bgp_vty.h"
46#include "bgpd/bgp_encap.h"
47
48static u_int16_t
49decode_rd_type (u_char *pnt)
50{
51 u_int16_t v;
52
53 v = ((u_int16_t) *pnt++ << 8);
54 v |= (u_int16_t) *pnt;
55 return v;
56}
57
58
59static void
60decode_rd_as (u_char *pnt, struct rd_as *rd_as)
61{
62 rd_as->as = (u_int16_t) *pnt++ << 8;
63 rd_as->as |= (u_int16_t) *pnt++;
64
65 rd_as->val = ((u_int32_t) *pnt++) << 24;
66 rd_as->val |= ((u_int32_t) *pnt++) << 16;
67 rd_as->val |= ((u_int32_t) *pnt++) << 8;
68 rd_as->val |= (u_int32_t) *pnt;
69}
70
71static void
72decode_rd_as4 (u_char *pnt, struct rd_as *rd_as)
73{
74 rd_as->as = (u_int32_t) *pnt++ << 24;
75 rd_as->as |= (u_int32_t) *pnt++ << 16;
76 rd_as->as |= (u_int32_t) *pnt++ << 8;
77 rd_as->as |= (u_int32_t) *pnt++;
78
79 rd_as->val = ((u_int32_t) *pnt++ << 8);
80 rd_as->val |= (u_int32_t) *pnt;
81}
82
83static void
84decode_rd_ip (u_char *pnt, struct rd_ip *rd_ip)
85{
86 memcpy (&rd_ip->ip, pnt, 4);
87 pnt += 4;
88
89 rd_ip->val = ((u_int16_t) *pnt++ << 8);
90 rd_ip->val |= (u_int16_t) *pnt;
91}
92
93static void
94ecom2prd(struct ecommunity *ecom, struct prefix_rd *prd)
95{
96 int i;
97
98 memset(prd, 0, sizeof(struct prefix_rd));
99 prd->family = AF_UNSPEC;
100 prd->prefixlen = 64;
101
102 if (!ecom)
103 return;
104
105 for (i = 0; i < (ecom->size * ECOMMUNITY_SIZE); i += ECOMMUNITY_SIZE) {
106
107 uint8_t *ep;
108
109 ep = ecom->val + i;
110
111 switch (ep[0]) {
112 default:
113 continue;
114
115 case 0x80:
116 case 0x81:
117 case 0x82:
118 if (ep[1] == 0x0) {
119 prd->val[1] = ep[0] & 0x03;
120 memcpy(prd->val + 2, ep + 2, 6);
121 return;
122 }
123 }
124 }
125}
126
127int
128bgp_nlri_parse_encap(
129 afi_t afi,
130 struct peer *peer,
131 struct attr *attr, /* Need even for withdraw */
132 struct bgp_nlri *packet,
133 int withdraw) /* 0=update, !0 = withdraw */
134{
135 u_char *pnt;
136 u_char *lim;
137 struct prefix p;
138 int psize = 0;
139 int prefixlen;
140 struct rd_as rd_as;
141 struct rd_ip rd_ip;
142 struct prefix_rd prd;
143 struct ecommunity *pEcom = NULL;
144 u_int16_t rdtype = 0xffff;
145 char buf[BUFSIZ];
146
147 /* Check peer status. */
148 if (peer->status != Established)
149 return 0;
150
151 /* Make prefix_rd */
152 if (attr && attr->extra && attr->extra->ecommunity)
153 pEcom = attr->extra->ecommunity;
154
155 ecom2prd(pEcom, &prd);
156 memset(&rd_as, 0, sizeof(rd_as));
157 memset(&rd_ip, 0, sizeof(rd_ip));
158
159 if (pEcom) {
160
161 rdtype = (prd.val[0] << 8) | prd.val[1];
162
163 /* Decode RD value. */
164 if (rdtype == RD_TYPE_AS)
165 decode_rd_as (prd.val + 2, &rd_as);
166 else if (rdtype == RD_TYPE_IP)
167 decode_rd_ip (prd.val + 2, &rd_ip);
168 else if (rdtype == RD_TYPE_AS4)
169 decode_rd_as4 (prd.val + 2, &rd_as);
170 else
171 {
172 zlog_err ("Invalid RD type %d", rdtype);
173 }
174
175 }
176
177 /*
178 * NB: this code was based on the MPLS VPN code, which supported RDs.
179 * For the moment we are retaining the underlying RIB structure that
180 * keeps a per-RD radix tree, but since the RDs are not carried over
181 * the wire, we set the RD internally to 0.
182 */
183 prd.family = AF_UNSPEC;
184 prd.prefixlen = 64;
185 memset(prd.val, 0, sizeof(prd.val));
186
187 pnt = packet->nlri;
188 lim = pnt + packet->length;
189
190 for (; pnt < lim; pnt += psize)
191 {
192 /* Clear prefix structure. */
193 memset (&p, 0, sizeof (struct prefix));
194
195 /* Fetch prefix length. */
196 prefixlen = *pnt++;
197 p.family = afi2family(afi);
198 if (p.family == 0) {
199 /* bad afi, shouldn't happen */
200 zlog_warn("%s: bad afi %d, dropping incoming route", __func__, afi);
201 continue;
202 }
203 psize = PSIZE (prefixlen);
204
205 p.prefixlen = prefixlen;
206 memcpy (&p.u.prefix, pnt, psize);
207
208 if (pnt + psize > lim)
209 return -1;
210
211
212 if (rdtype == RD_TYPE_AS)
213 zlog_info ("rd-as %u:%u prefix %s/%d", rd_as.as, rd_as.val,
214 inet_ntop (p.family, &p.u.prefix, buf, BUFSIZ),
215 p.prefixlen);
216 else if (rdtype == RD_TYPE_IP)
217 zlog_info ("rd-ip %s:%u prefix %s/%d", inet_ntoa (rd_ip.ip),
218 rd_ip.val,
219 inet_ntop (p.family, &p.u.prefix, buf, BUFSIZ),
220 p.prefixlen);
221 else if (rdtype == RD_TYPE_AS4)
222 zlog_info ("rd-as4 %u:%u prefix %s/%d", rd_as.as, rd_as.val,
223 inet_ntop (p.family, &p.u.prefix, buf, BUFSIZ),
224 p.prefixlen);
225 else
226 zlog_info ("rd unknown, default to 0:0 prefix %s/%d",
227 inet_ntop (p.family, &p.u.prefix, buf, BUFSIZ),
228 p.prefixlen);
229
230 if (!withdraw) {
231 bgp_update (peer, &p, attr, afi, SAFI_ENCAP,
232 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, NULL, 0);
233 } else {
234 bgp_withdraw (peer, &p, attr, afi, SAFI_ENCAP,
235 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, NULL);
236 }
237 }
238
239 /* Packet length consistency check. */
240 if (pnt != lim)
241 return -1;
242
243 return 0;
244}
245
246
247/* TBD: these routes should probably all be host routes */
248
249/* For testing purpose, static route of ENCAP. */
250DEFUN (encap_network,
251 encap_network_cmd,
252 "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
253 "Specify a network to announce via BGP\n"
254 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
255 "Specify Route Distinguisher\n"
256 "ENCAP Route Distinguisher\n"
257 "BGP tag\n"
258 "tag value\n")
259{
260 return bgp_static_set_safi (SAFI_ENCAP, vty, argv[0], argv[1], argv[2], NULL);
261}
262
263/* For testing purpose, static route of ENCAP. */
264DEFUN (no_encap_network,
265 no_encap_network_cmd,
266 "no network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
267 NO_STR
268 "Specify a network to announce via BGP\n"
269 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
270 "Specify Route Distinguisher\n"
271 "ENCAP Route Distinguisher\n"
272 "BGP tag\n"
273 "tag value\n")
274{
275 return bgp_static_unset_safi (SAFI_ENCAP, vty, argv[0], argv[1], argv[2]);
276}
277
278static int
279show_adj_route_encap (struct vty *vty, struct peer *peer, struct prefix_rd *prd)
280{
281 struct bgp *bgp;
282 struct bgp_table *table;
283 struct bgp_node *rn;
284 struct bgp_node *rm;
285 struct attr *attr;
286 int rd_header;
287 int header = 1;
288 char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
289
290 bgp = bgp_get_default ();
291 if (bgp == NULL)
292 {
293 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
294 return CMD_WARNING;
295 }
296
297 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_ENCAP]); rn;
298 rn = bgp_route_next (rn))
299 {
300 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
301 continue;
302
303 if ((table = rn->info) != NULL)
304 {
305 rd_header = 1;
306
307 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
308 if ((attr = rm->info) != NULL)
309 {
310 if (header)
311 {
312 vty_out (vty, "BGP table version is 0, local router ID is %s%s",
313 inet_ntoa (bgp->router_id), VTY_NEWLINE);
314 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
315 VTY_NEWLINE);
316 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
317 VTY_NEWLINE, VTY_NEWLINE);
318 vty_out (vty, v4_header, VTY_NEWLINE);
319 header = 0;
320 }
321
322 if (rd_header)
323 {
324 u_int16_t type;
325 struct rd_as rd_as;
326 struct rd_ip rd_ip;
327 u_char *pnt;
328
329 pnt = rn->p.u.val;
330
331 vty_out (vty, "Route Distinguisher: ");
332
333 /* Decode RD type. */
334 type = decode_rd_type (pnt);
335
336 switch (type) {
337
338 case RD_TYPE_AS:
339 decode_rd_as (pnt + 2, &rd_as);
340 vty_out (vty, "%u:%d", rd_as.as, rd_as.val);
341 break;
342
343 case RD_TYPE_IP:
344 decode_rd_ip (pnt + 2, &rd_ip);
345 vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
346 break;
347
348 default:
349 vty_out (vty, "unknown RD type");
350 }
351
352
353 vty_out (vty, "%s", VTY_NEWLINE);
354 rd_header = 0;
355 }
356 route_vty_out_tmp (vty, &rm->p, attr, SAFI_ENCAP);
357 }
358 }
359 }
360 return CMD_SUCCESS;
361}
362
363enum bgp_show_type
364{
365 bgp_show_type_normal,
366 bgp_show_type_regexp,
367 bgp_show_type_prefix_list,
368 bgp_show_type_filter_list,
369 bgp_show_type_neighbor,
370 bgp_show_type_cidr_only,
371 bgp_show_type_prefix_longer,
372 bgp_show_type_community_all,
373 bgp_show_type_community,
374 bgp_show_type_community_exact,
375 bgp_show_type_community_list,
376 bgp_show_type_community_list_exact
377};
378
379static int
380bgp_show_encap (
381 struct vty *vty,
382 afi_t afi,
383 struct prefix_rd *prd,
384 enum bgp_show_type type,
385 void *output_arg,
386 int tags)
387{
388 struct bgp *bgp;
389 struct bgp_table *table;
390 struct bgp_node *rn;
391 struct bgp_node *rm;
392 struct bgp_info *ri;
393 int rd_header;
394 int header = 1;
395 char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
396 char v4_header_tag[] = " Network Next Hop In tag/Out tag%s";
397
398 unsigned long output_count = 0;
399 unsigned long total_count = 0;
400
401 bgp = bgp_get_default ();
402 if (bgp == NULL)
403 {
404 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
405 return CMD_WARNING;
406 }
407
408 if ((afi != AFI_IP) && (afi != AFI_IP6)) {
409 vty_out (vty, "Afi %d not supported%s", afi, VTY_NEWLINE);
410 return CMD_WARNING;
411 }
412
413 for (rn = bgp_table_top (bgp->rib[afi][SAFI_ENCAP]); rn; rn = bgp_route_next (rn))
414 {
415 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
416 continue;
417
418 if ((table = rn->info) != NULL)
419 {
420 rd_header = 1;
421
422 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
423 for (ri = rm->info; ri; ri = ri->next)
424 {
425 total_count++;
426 if (type == bgp_show_type_neighbor)
427 {
428 union sockunion *su = output_arg;
429
430 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
431 continue;
432 }
433 if (header)
434 {
435 if (tags)
436 vty_out (vty, v4_header_tag, VTY_NEWLINE);
437 else
438 {
439 vty_out (vty, "BGP table version is 0, local router ID is %s%s",
440 inet_ntoa (bgp->router_id), VTY_NEWLINE);
441 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
442 VTY_NEWLINE);
443 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
444 VTY_NEWLINE, VTY_NEWLINE);
445 vty_out (vty, v4_header, VTY_NEWLINE);
446 }
447 header = 0;
448 }
449
450 if (rd_header)
451 {
452 u_int16_t type;
453 struct rd_as rd_as;
454 struct rd_ip rd_ip;
455 u_char *pnt;
456
457 pnt = rn->p.u.val;
458
459 /* Decode RD type. */
460 type = decode_rd_type (pnt);
461
462 vty_out (vty, "Route Distinguisher: ");
463
464 switch (type) {
465
466 case RD_TYPE_AS:
467 decode_rd_as (pnt + 2, &rd_as);
468 vty_out (vty, "%u:%d", rd_as.as, rd_as.val);
469 break;
470
471 case RD_TYPE_IP:
472 decode_rd_ip (pnt + 2, &rd_ip);
473 vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
474 break;
475
476 default:
477 vty_out (vty, "Unknown RD type");
478 break;
479 }
480
481 vty_out (vty, "%s", VTY_NEWLINE);
482 rd_header = 0;
483 }
484 if (tags)
485 route_vty_out_tag (vty, &rm->p, ri, 0, SAFI_ENCAP);
486 else
487 route_vty_out (vty, &rm->p, ri, 0, SAFI_ENCAP);
488 output_count++;
489 }
490 }
491 }
492
493 if (output_count == 0)
494 {
495 vty_out (vty, "No prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
496 }
497 else
498 vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
499 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
500
501 return CMD_SUCCESS;
502}
503
504DEFUN (show_bgp_ipv4_encap,
505 show_bgp_ipv4_encap_cmd,
506 "show bgp ipv4 encap",
507 SHOW_STR
508 BGP_STR
509 "Address Family\n"
510 "Display ENCAP NLRI specific information\n")
511{
512 return bgp_show_encap (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 0);
513}
Lou Berger205e6742016-01-12 13:42:11 -0500514
Lou Berger298cc2f2016-01-12 13:42:02 -0500515DEFUN (show_bgp_ipv6_encap,
516 show_bgp_ipv6_encap_cmd,
517 "show bgp ipv6 encap",
518 SHOW_STR
519 BGP_STR
520 "Address Family\n"
521 "Display ENCAP NLRI specific information\n")
522{
523 return bgp_show_encap (vty, AFI_IP6, NULL, bgp_show_type_normal, NULL, 0);
524}
Lou Berger298cc2f2016-01-12 13:42:02 -0500525
526DEFUN (show_bgp_ipv4_encap_rd,
527 show_bgp_ipv4_encap_rd_cmd,
528 "show bgp ipv4 encap rd ASN:nn_or_IP-address:nn",
529 SHOW_STR
530 BGP_STR
531 "Address Family\n"
532 "Display ENCAP NLRI specific information\n"
533 "Display information for a route distinguisher\n"
534 "ENCAP Route Distinguisher\n")
535{
536 int ret;
537 struct prefix_rd prd;
538
539 ret = str2prefix_rd (argv[0], &prd);
540 if (! ret)
541 {
542 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
543 return CMD_WARNING;
544 }
545 return bgp_show_encap (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 0);
546}
Lou Berger205e6742016-01-12 13:42:11 -0500547
Lou Berger298cc2f2016-01-12 13:42:02 -0500548DEFUN (show_bgp_ipv6_encap_rd,
549 show_bgp_ipv6_encap_rd_cmd,
550 "show bgp ipv6 encap rd ASN:nn_or_IP-address:nn",
551 SHOW_STR
552 BGP_STR
553 "Address Family\n"
554 "Display ENCAP NLRI specific information\n"
555 "Display information for a route distinguisher\n"
556 "ENCAP Route Distinguisher\n"
557 "Display BGP tags for prefixes\n")
558{
559 int ret;
560 struct prefix_rd prd;
561
562 ret = str2prefix_rd (argv[0], &prd);
563 if (! ret)
564 {
565 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
566 return CMD_WARNING;
567 }
568 return bgp_show_encap (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 0);
569}
Lou Berger298cc2f2016-01-12 13:42:02 -0500570
571DEFUN (show_bgp_ipv4_encap_tags,
572 show_bgp_ipv4_encap_tags_cmd,
573 "show bgp ipv4 encap tags",
574 SHOW_STR
575 BGP_STR
576 "Address Family\n"
577 "Display ENCAP NLRI specific information\n"
578 "Display BGP tags for prefixes\n")
579{
580 return bgp_show_encap (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 1);
581}
Lou Berger205e6742016-01-12 13:42:11 -0500582
Lou Berger298cc2f2016-01-12 13:42:02 -0500583DEFUN (show_bgp_ipv6_encap_tags,
584 show_bgp_ipv6_encap_tags_cmd,
585 "show bgp ipv6 encap tags",
586 SHOW_STR
587 BGP_STR
588 "Address Family\n"
589 "Display ENCAP NLRI specific information\n"
590 "Display BGP tags for prefixes\n")
591{
592 return bgp_show_encap (vty, AFI_IP6, NULL, bgp_show_type_normal, NULL, 1);
593}
Lou Berger205e6742016-01-12 13:42:11 -0500594
Lou Berger298cc2f2016-01-12 13:42:02 -0500595
596DEFUN (show_bgp_ipv4_encap_rd_tags,
597 show_bgp_ipv4_encap_rd_tags_cmd,
598 "show bgp ipv4 encap rd ASN:nn_or_IP-address:nn tags",
599 SHOW_STR
600 BGP_STR
601 "Address Family\n"
602 "Display ENCAP NLRI specific information\n"
603 "Display information for a route distinguisher\n"
604 "ENCAP Route Distinguisher\n"
605 "Display BGP tags for prefixes\n")
606{
607 int ret;
608 struct prefix_rd prd;
609
610 ret = str2prefix_rd (argv[0], &prd);
611 if (! ret)
612 {
613 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
614 return CMD_WARNING;
615 }
616 return bgp_show_encap (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 1);
617}
Lou Berger205e6742016-01-12 13:42:11 -0500618
Lou Berger298cc2f2016-01-12 13:42:02 -0500619DEFUN (show_bgp_ipv6_encap_rd_tags,
620 show_bgp_ipv6_encap_rd_tags_cmd,
621 "show bgp ipv6 encap rd ASN:nn_or_IP-address:nn tags",
622 SHOW_STR
623 BGP_STR
624 "Address Family\n"
625 "Display ENCAP NLRI specific information\n"
626 "Display information for a route distinguisher\n"
627 "ENCAP Route Distinguisher\n"
628 "Display BGP tags for prefixes\n")
629{
630 int ret;
631 struct prefix_rd prd;
632
633 ret = str2prefix_rd (argv[0], &prd);
634 if (! ret)
635 {
636 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
637 return CMD_WARNING;
638 }
639 return bgp_show_encap (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 1);
640}
Lou Berger298cc2f2016-01-12 13:42:02 -0500641
642DEFUN (show_bgp_ipv4_encap_neighbor_routes,
643 show_bgp_ipv4_encap_neighbor_routes_cmd,
644 "show bgp ipv4 encap neighbors A.B.C.D routes",
645 SHOW_STR
646 BGP_STR
647 "Address Family\n"
648 "Display ENCAP NLRI specific information\n"
649 "Detailed information on TCP and BGP neighbor connections\n"
650 "Neighbor to display information about\n"
651 "Display routes learned from neighbor\n")
652{
653 union sockunion *su;
654 struct peer *peer;
655
656 su = sockunion_str2su (argv[0]);
657 if (su == NULL)
658 {
659 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
660 return CMD_WARNING;
661 }
662
663 peer = peer_lookup (NULL, su);
664 if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP])
665 {
666 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
667 return CMD_WARNING;
668 }
669
670 return bgp_show_encap (vty, AFI_IP, NULL, bgp_show_type_neighbor, su, 0);
671}
Lou Berger205e6742016-01-12 13:42:11 -0500672
Lou Berger298cc2f2016-01-12 13:42:02 -0500673DEFUN (show_bgp_ipv6_encap_neighbor_routes,
674 show_bgp_ipv6_encap_neighbor_routes_cmd,
675 "show bgp ipv6 encap neighbors A.B.C.D routes",
676 SHOW_STR
677 BGP_STR
678 "Address Family\n"
679 "Display ENCAP NLRI specific information\n"
680 "Detailed information on TCP and BGP neighbor connections\n"
681 "Neighbor to display information about\n"
682 "Display routes learned from neighbor\n")
683{
684 union sockunion *su;
685 struct peer *peer;
686
687 su = sockunion_str2su (argv[0]);
688 if (su == NULL)
689 {
690 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
691 return CMD_WARNING;
692 }
693
694 peer = peer_lookup (NULL, su);
695 if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP])
696 {
697 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
698 return CMD_WARNING;
699 }
700
701 return bgp_show_encap (vty, AFI_IP6, NULL, bgp_show_type_neighbor, su, 0);
702}
Lou Berger298cc2f2016-01-12 13:42:02 -0500703
704DEFUN (show_bgp_ipv4_encap_rd_neighbor_routes,
705 show_bgp_ipv4_encap_rd_neighbor_routes_cmd,
706 "show bgp ipv4 encap rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) routes",
707 SHOW_STR
708 BGP_STR
709 "Address Family\n"
710 "Display ENCAP NLRI specific information\n"
711 "Display information for a route distinguisher\n"
712 "ENCAP Route Distinguisher\n"
713 "Detailed information on TCP and BGP neighbor connections\n"
714 "Neighbor to display information about\n"
715 "Neighbor to display information about\n"
716 "Display routes learned from neighbor\n")
717{
718 int ret;
719 union sockunion *su;
720 struct peer *peer;
721 struct prefix_rd prd;
722
723 ret = str2prefix_rd (argv[0], &prd);
724 if (! ret)
725 {
726 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
727 return CMD_WARNING;
728 }
729
730 su = sockunion_str2su (argv[1]);
731 if (su == NULL)
732 {
733 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
734 return CMD_WARNING;
735 }
736
737 peer = peer_lookup (NULL, su);
738 if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP])
739 {
740 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
741 return CMD_WARNING;
742 }
743
744 return bgp_show_encap (vty, AFI_IP, &prd, bgp_show_type_neighbor, su, 0);
745}
Lou Berger205e6742016-01-12 13:42:11 -0500746
Lou Berger298cc2f2016-01-12 13:42:02 -0500747DEFUN (show_bgp_ipv6_encap_rd_neighbor_routes,
748 show_bgp_ipv6_encap_rd_neighbor_routes_cmd,
749 "show bgp ipv6 encap rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) routes",
750 SHOW_STR
751 BGP_STR
752 "Address Family\n"
753 "Display ENCAP NLRI specific information\n"
754 "Display information for a route distinguisher\n"
755 "ENCAP Route Distinguisher\n"
756 "Detailed information on TCP and BGP neighbor connections\n"
757 "Neighbor to display information about\n"
758 "Neighbor to display information about\n"
759 "Display routes learned from neighbor\n")
760{
761 int ret;
762 union sockunion *su;
763 struct peer *peer;
764 struct prefix_rd prd;
765
766 ret = str2prefix_rd (argv[0], &prd);
767 if (! ret)
768 {
769 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
770 return CMD_WARNING;
771 }
772
773 su = sockunion_str2su (argv[1]);
774 if (su == NULL)
775 {
776 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
777 return CMD_WARNING;
778 }
779
780 peer = peer_lookup (NULL, su);
781 if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP])
782 {
783 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
784 return CMD_WARNING;
785 }
786
787 return bgp_show_encap (vty, AFI_IP6, &prd, bgp_show_type_neighbor, su, 0);
788}
Lou Berger298cc2f2016-01-12 13:42:02 -0500789
790DEFUN (show_bgp_ipv4_encap_neighbor_advertised_routes,
791 show_bgp_ipv4_encap_neighbor_advertised_routes_cmd,
792 "show bgp ipv4 encap neighbors A.B.C.D advertised-routes",
793 SHOW_STR
794 BGP_STR
795 "Address Family\n"
796 "Display ENCAP NLRI specific information\n"
797 "Detailed information on TCP and BGP neighbor connections\n"
798 "Neighbor to display information about\n"
799 "Display the routes advertised to a BGP neighbor\n")
800{
801 int ret;
802 struct peer *peer;
803 union sockunion su;
804
805 ret = str2sockunion (argv[0], &su);
806 if (ret < 0)
807 {
808 vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
809 return CMD_WARNING;
810 }
811 peer = peer_lookup (NULL, &su);
812 if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP])
813 {
814 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
815 return CMD_WARNING;
816 }
817
818 return show_adj_route_encap (vty, peer, NULL);
819}
Lou Berger205e6742016-01-12 13:42:11 -0500820
Lou Berger298cc2f2016-01-12 13:42:02 -0500821DEFUN (show_bgp_ipv6_encap_neighbor_advertised_routes,
822 show_bgp_ipv6_encap_neighbor_advertised_routes_cmd,
823 "show bgp ipv6 encap neighbors A.B.C.D advertised-routes",
824 SHOW_STR
825 BGP_STR
826 "Address Family\n"
827 "Display ENCAP NLRI specific information\n"
828 "Detailed information on TCP and BGP neighbor connections\n"
829 "Neighbor to display information about\n"
830 "Display the routes advertised to a BGP neighbor\n")
831{
832 int ret;
833 struct peer *peer;
834 union sockunion su;
835
836 ret = str2sockunion (argv[0], &su);
837 if (ret < 0)
838 {
839 vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
840 return CMD_WARNING;
841 }
842 peer = peer_lookup (NULL, &su);
843 if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP])
844 {
845 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
846 return CMD_WARNING;
847 }
848
849 return show_adj_route_encap (vty, peer, NULL);
850}
Lou Berger298cc2f2016-01-12 13:42:02 -0500851
852DEFUN (show_bgp_ipv4_encap_rd_neighbor_advertised_routes,
853 show_bgp_ipv4_encap_rd_neighbor_advertised_routes_cmd,
854 "show bgp ipv4 encap rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) advertised-routes",
855 SHOW_STR
856 BGP_STR
857 "Address Family\n"
858 "Display ENCAP NLRI specific information\n"
859 "Display information for a route distinguisher\n"
860 "ENCAP Route Distinguisher\n"
861 "Detailed information on TCP and BGP neighbor connections\n"
862 "Neighbor to display information about\n"
863 "Neighbor to display information about\n"
864 "Display the routes advertised to a BGP neighbor\n")
865{
866 int ret;
867 struct peer *peer;
868 struct prefix_rd prd;
869 union sockunion su;
870
871 ret = str2sockunion (argv[1], &su);
872 if (ret < 0)
873 {
874 vty_out (vty, "%% Malformed address: %s%s", argv[1], VTY_NEWLINE);
875 return CMD_WARNING;
876 }
877 peer = peer_lookup (NULL, &su);
878 if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP])
879 {
880 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
881 return CMD_WARNING;
882 }
883
884 ret = str2prefix_rd (argv[0], &prd);
885 if (! ret)
886 {
887 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
888 return CMD_WARNING;
889 }
890
891 return show_adj_route_encap (vty, peer, &prd);
892}
Lou Berger205e6742016-01-12 13:42:11 -0500893
Lou Berger298cc2f2016-01-12 13:42:02 -0500894DEFUN (show_bgp_ipv6_encap_rd_neighbor_advertised_routes,
895 show_bgp_ipv6_encap_rd_neighbor_advertised_routes_cmd,
896 "show bgp ipv6 encap rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) advertised-routes",
897 SHOW_STR
898 BGP_STR
899 "Address Family\n"
900 "Display ENCAP NLRI specific information\n"
901 "Display information for a route distinguisher\n"
902 "ENCAP Route Distinguisher\n"
903 "Detailed information on TCP and BGP neighbor connections\n"
904 "Neighbor to display information about\n"
905 "Neighbor to display information about\n"
906 "Display the routes advertised to a BGP neighbor\n")
907{
908 int ret;
909 struct peer *peer;
910 struct prefix_rd prd;
911 union sockunion su;
912
913 ret = str2sockunion (argv[1], &su);
914 if (ret < 0)
915 {
916 vty_out (vty, "%% Malformed address: %s%s", argv[1], VTY_NEWLINE);
917 return CMD_WARNING;
918 }
919 peer = peer_lookup (NULL, &su);
920 if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP])
921 {
922 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
923 return CMD_WARNING;
924 }
925
926 ret = str2prefix_rd (argv[0], &prd);
927 if (! ret)
928 {
929 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
930 return CMD_WARNING;
931 }
932
933 return show_adj_route_encap (vty, peer, &prd);
934}
Lou Berger298cc2f2016-01-12 13:42:02 -0500935
936void
937bgp_encap_init (void)
938{
Lou Bergera3fda882016-01-12 13:42:04 -0500939 install_element (BGP_ENCAP_NODE, &encap_network_cmd);
940 install_element (BGP_ENCAP_NODE, &no_encap_network_cmd);
Lou Berger298cc2f2016-01-12 13:42:02 -0500941
942 install_element (VIEW_NODE, &show_bgp_ipv4_encap_cmd);
943 install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_cmd);
944 install_element (VIEW_NODE, &show_bgp_ipv4_encap_tags_cmd);
945 install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_tags_cmd);
946 install_element (VIEW_NODE, &show_bgp_ipv4_encap_neighbor_routes_cmd);
947 install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_neighbor_routes_cmd);
948 install_element (VIEW_NODE, &show_bgp_ipv4_encap_neighbor_advertised_routes_cmd);
949 install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_neighbor_advertised_routes_cmd);
950
Lou Berger298cc2f2016-01-12 13:42:02 -0500951 install_element (VIEW_NODE, &show_bgp_ipv6_encap_cmd);
952 install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_cmd);
953 install_element (VIEW_NODE, &show_bgp_ipv6_encap_tags_cmd);
954 install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_tags_cmd);
955 install_element (VIEW_NODE, &show_bgp_ipv6_encap_neighbor_routes_cmd);
956 install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_neighbor_routes_cmd);
957 install_element (VIEW_NODE, &show_bgp_ipv6_encap_neighbor_advertised_routes_cmd);
958 install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_neighbor_advertised_routes_cmd);
Lou Berger298cc2f2016-01-12 13:42:02 -0500959
960 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_cmd);
961 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_rd_cmd);
962 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_tags_cmd);
963 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_rd_tags_cmd);
964 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_neighbor_routes_cmd);
965 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_rd_neighbor_routes_cmd);
966 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_neighbor_advertised_routes_cmd);
967 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_rd_neighbor_advertised_routes_cmd);
968
Lou Berger298cc2f2016-01-12 13:42:02 -0500969 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_cmd);
970 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_rd_cmd);
971 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_tags_cmd);
972 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_rd_tags_cmd);
973 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_neighbor_routes_cmd);
974 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_rd_neighbor_routes_cmd);
975 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_neighbor_advertised_routes_cmd);
976 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_rd_neighbor_advertised_routes_cmd);
Lou Berger298cc2f2016-01-12 13:42:02 -0500977
978}