]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_encap.c
convert <1-255> to (1-255), ()s to <>s, etc
[mirror_frr.git] / bgpd / bgp_encap.c
CommitLineData
587ff0fd
LB
1
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, 0, attr, afi, SAFI_ENCAP,
232 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, NULL, 0);
233 } else {
234 bgp_withdraw (peer, &p, 0, 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, 0, NULL);
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, NULL);
486 else
487 route_vty_out (vty, &rm->p, ri, 0, SAFI_ENCAP, NULL);
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}
514#ifdef HAVE_IPV6
515DEFUN (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}
525#endif
526
527DEFUN (show_bgp_ipv4_encap_rd,
528 show_bgp_ipv4_encap_rd_cmd,
529 "show bgp ipv4 encap rd ASN:nn_or_IP-address:nn",
530 SHOW_STR
531 BGP_STR
532 "Address Family\n"
533 "Display ENCAP NLRI specific information\n"
534 "Display information for a route distinguisher\n"
535 "ENCAP Route Distinguisher\n")
536{
537 int ret;
538 struct prefix_rd prd;
539
540 ret = str2prefix_rd (argv[0], &prd);
541 if (! ret)
542 {
543 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
544 return CMD_WARNING;
545 }
546 return bgp_show_encap (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 0);
547}
548#ifdef HAVE_IPV6
549DEFUN (show_bgp_ipv6_encap_rd,
550 show_bgp_ipv6_encap_rd_cmd,
551 "show bgp ipv6 encap rd ASN:nn_or_IP-address:nn",
552 SHOW_STR
553 BGP_STR
554 "Address Family\n"
555 "Display ENCAP NLRI specific information\n"
556 "Display information for a route distinguisher\n"
557 "ENCAP Route Distinguisher\n"
558 "Display BGP tags for prefixes\n")
559{
560 int ret;
561 struct prefix_rd prd;
562
563 ret = str2prefix_rd (argv[0], &prd);
564 if (! ret)
565 {
566 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
567 return CMD_WARNING;
568 }
569 return bgp_show_encap (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 0);
570}
571#endif
572
573DEFUN (show_bgp_ipv4_encap_tags,
574 show_bgp_ipv4_encap_tags_cmd,
575 "show bgp ipv4 encap tags",
576 SHOW_STR
577 BGP_STR
578 "Address Family\n"
579 "Display ENCAP NLRI specific information\n"
580 "Display BGP tags for prefixes\n")
581{
582 return bgp_show_encap (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 1);
583}
584#ifdef HAVE_IPV6
585DEFUN (show_bgp_ipv6_encap_tags,
586 show_bgp_ipv6_encap_tags_cmd,
587 "show bgp ipv6 encap tags",
588 SHOW_STR
589 BGP_STR
590 "Address Family\n"
591 "Display ENCAP NLRI specific information\n"
592 "Display BGP tags for prefixes\n")
593{
594 return bgp_show_encap (vty, AFI_IP6, NULL, bgp_show_type_normal, NULL, 1);
595}
596#endif
597
598DEFUN (show_bgp_ipv4_encap_rd_tags,
599 show_bgp_ipv4_encap_rd_tags_cmd,
600 "show bgp ipv4 encap rd ASN:nn_or_IP-address:nn tags",
601 SHOW_STR
602 BGP_STR
603 "Address Family\n"
604 "Display ENCAP NLRI specific information\n"
605 "Display information for a route distinguisher\n"
606 "ENCAP Route Distinguisher\n"
607 "Display BGP tags for prefixes\n")
608{
609 int ret;
610 struct prefix_rd prd;
611
612 ret = str2prefix_rd (argv[0], &prd);
613 if (! ret)
614 {
615 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
616 return CMD_WARNING;
617 }
618 return bgp_show_encap (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 1);
619}
620#ifdef HAVE_IPV6
621DEFUN (show_bgp_ipv6_encap_rd_tags,
622 show_bgp_ipv6_encap_rd_tags_cmd,
623 "show bgp ipv6 encap rd ASN:nn_or_IP-address:nn tags",
624 SHOW_STR
625 BGP_STR
626 "Address Family\n"
627 "Display ENCAP NLRI specific information\n"
628 "Display information for a route distinguisher\n"
629 "ENCAP Route Distinguisher\n"
630 "Display BGP tags for prefixes\n")
631{
632 int ret;
633 struct prefix_rd prd;
634
635 ret = str2prefix_rd (argv[0], &prd);
636 if (! ret)
637 {
638 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
639 return CMD_WARNING;
640 }
641 return bgp_show_encap (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 1);
642}
643#endif
644
645DEFUN (show_bgp_ipv4_encap_neighbor_routes,
646 show_bgp_ipv4_encap_neighbor_routes_cmd,
647 "show bgp ipv4 encap neighbors A.B.C.D routes",
648 SHOW_STR
649 BGP_STR
650 "Address Family\n"
651 "Display ENCAP NLRI specific information\n"
652 "Detailed information on TCP and BGP neighbor connections\n"
653 "Neighbor to display information about\n"
654 "Display routes learned from neighbor\n")
655{
656 union sockunion *su;
657 struct peer *peer;
658
659 su = sockunion_str2su (argv[0]);
660 if (su == NULL)
661 {
662 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
663 return CMD_WARNING;
664 }
665
666 peer = peer_lookup (NULL, su);
667 if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP])
668 {
669 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
670 return CMD_WARNING;
671 }
672
673 return bgp_show_encap (vty, AFI_IP, NULL, bgp_show_type_neighbor, su, 0);
674}
675#ifdef HAVE_IPV6
676DEFUN (show_bgp_ipv6_encap_neighbor_routes,
677 show_bgp_ipv6_encap_neighbor_routes_cmd,
678 "show bgp ipv6 encap neighbors A.B.C.D routes",
679 SHOW_STR
680 BGP_STR
681 "Address Family\n"
682 "Display ENCAP NLRI specific information\n"
683 "Detailed information on TCP and BGP neighbor connections\n"
684 "Neighbor to display information about\n"
685 "Display routes learned from neighbor\n")
686{
687 union sockunion *su;
688 struct peer *peer;
689
690 su = sockunion_str2su (argv[0]);
691 if (su == NULL)
692 {
693 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
694 return CMD_WARNING;
695 }
696
697 peer = peer_lookup (NULL, su);
698 if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP])
699 {
700 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
701 return CMD_WARNING;
702 }
703
704 return bgp_show_encap (vty, AFI_IP6, NULL, bgp_show_type_neighbor, su, 0);
705}
706#endif
707
708DEFUN (show_bgp_ipv4_encap_rd_neighbor_routes,
709 show_bgp_ipv4_encap_rd_neighbor_routes_cmd,
6147e2c6 710 "show bgp ipv4 encap rd ASN:nn_or_IP-address:nn neighbors <A.B.C.D|X:X::X:X> routes",
587ff0fd
LB
711 SHOW_STR
712 BGP_STR
713 "Address Family\n"
714 "Display ENCAP NLRI specific information\n"
715 "Display information for a route distinguisher\n"
716 "ENCAP Route Distinguisher\n"
717 "Detailed information on TCP and BGP neighbor connections\n"
718 "Neighbor to display information about\n"
719 "Neighbor to display information about\n"
720 "Display routes learned from neighbor\n")
721{
722 int ret;
723 union sockunion *su;
724 struct peer *peer;
725 struct prefix_rd prd;
726
727 ret = str2prefix_rd (argv[0], &prd);
728 if (! ret)
729 {
730 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
731 return CMD_WARNING;
732 }
733
734 su = sockunion_str2su (argv[1]);
735 if (su == NULL)
736 {
737 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
738 return CMD_WARNING;
739 }
740
741 peer = peer_lookup (NULL, su);
742 if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP])
743 {
744 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
745 return CMD_WARNING;
746 }
747
748 return bgp_show_encap (vty, AFI_IP, &prd, bgp_show_type_neighbor, su, 0);
749}
750#ifdef HAVE_IPV6
751DEFUN (show_bgp_ipv6_encap_rd_neighbor_routes,
752 show_bgp_ipv6_encap_rd_neighbor_routes_cmd,
6147e2c6 753 "show bgp ipv6 encap rd ASN:nn_or_IP-address:nn neighbors <A.B.C.D|X:X::X:X> routes",
587ff0fd
LB
754 SHOW_STR
755 BGP_STR
756 "Address Family\n"
757 "Display ENCAP NLRI specific information\n"
758 "Display information for a route distinguisher\n"
759 "ENCAP Route Distinguisher\n"
760 "Detailed information on TCP and BGP neighbor connections\n"
761 "Neighbor to display information about\n"
762 "Neighbor to display information about\n"
763 "Display routes learned from neighbor\n")
764{
765 int ret;
766 union sockunion *su;
767 struct peer *peer;
768 struct prefix_rd prd;
769
770 ret = str2prefix_rd (argv[0], &prd);
771 if (! ret)
772 {
773 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
774 return CMD_WARNING;
775 }
776
777 su = sockunion_str2su (argv[1]);
778 if (su == NULL)
779 {
780 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
781 return CMD_WARNING;
782 }
783
784 peer = peer_lookup (NULL, su);
785 if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP])
786 {
787 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
788 return CMD_WARNING;
789 }
790
791 return bgp_show_encap (vty, AFI_IP6, &prd, bgp_show_type_neighbor, su, 0);
792}
793#endif
794
795DEFUN (show_bgp_ipv4_encap_neighbor_advertised_routes,
796 show_bgp_ipv4_encap_neighbor_advertised_routes_cmd,
797 "show bgp ipv4 encap neighbors A.B.C.D advertised-routes",
798 SHOW_STR
799 BGP_STR
800 "Address Family\n"
801 "Display ENCAP NLRI specific information\n"
802 "Detailed information on TCP and BGP neighbor connections\n"
803 "Neighbor to display information about\n"
804 "Display the routes advertised to a BGP neighbor\n")
805{
806 int ret;
807 struct peer *peer;
808 union sockunion su;
809
810 ret = str2sockunion (argv[0], &su);
811 if (ret < 0)
812 {
813 vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
814 return CMD_WARNING;
815 }
816 peer = peer_lookup (NULL, &su);
817 if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP])
818 {
819 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
820 return CMD_WARNING;
821 }
822
823 return show_adj_route_encap (vty, peer, NULL);
824}
825#ifdef HAVE_IPV6
826DEFUN (show_bgp_ipv6_encap_neighbor_advertised_routes,
827 show_bgp_ipv6_encap_neighbor_advertised_routes_cmd,
828 "show bgp ipv6 encap neighbors A.B.C.D advertised-routes",
829 SHOW_STR
830 BGP_STR
831 "Address Family\n"
832 "Display ENCAP NLRI specific information\n"
833 "Detailed information on TCP and BGP neighbor connections\n"
834 "Neighbor to display information about\n"
835 "Display the routes advertised to a BGP neighbor\n")
836{
837 int ret;
838 struct peer *peer;
839 union sockunion su;
840
841 ret = str2sockunion (argv[0], &su);
842 if (ret < 0)
843 {
844 vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
845 return CMD_WARNING;
846 }
847 peer = peer_lookup (NULL, &su);
848 if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP])
849 {
850 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
851 return CMD_WARNING;
852 }
853
854 return show_adj_route_encap (vty, peer, NULL);
855}
856#endif
857
858DEFUN (show_bgp_ipv4_encap_rd_neighbor_advertised_routes,
859 show_bgp_ipv4_encap_rd_neighbor_advertised_routes_cmd,
6147e2c6 860 "show bgp ipv4 encap rd ASN:nn_or_IP-address:nn neighbors <A.B.C.D|X:X::X:X> advertised-routes",
587ff0fd
LB
861 SHOW_STR
862 BGP_STR
863 "Address Family\n"
864 "Display ENCAP NLRI specific information\n"
865 "Display information for a route distinguisher\n"
866 "ENCAP Route Distinguisher\n"
867 "Detailed information on TCP and BGP neighbor connections\n"
868 "Neighbor to display information about\n"
869 "Neighbor to display information about\n"
870 "Display the routes advertised to a BGP neighbor\n")
871{
872 int ret;
873 struct peer *peer;
874 struct prefix_rd prd;
875 union sockunion su;
876
877 ret = str2sockunion (argv[1], &su);
878 if (ret < 0)
879 {
880 vty_out (vty, "%% Malformed address: %s%s", argv[1], VTY_NEWLINE);
881 return CMD_WARNING;
882 }
883 peer = peer_lookup (NULL, &su);
884 if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP])
885 {
886 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
887 return CMD_WARNING;
888 }
889
890 ret = str2prefix_rd (argv[0], &prd);
891 if (! ret)
892 {
893 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
894 return CMD_WARNING;
895 }
896
897 return show_adj_route_encap (vty, peer, &prd);
898}
899#ifdef HAVE_IPV6
900DEFUN (show_bgp_ipv6_encap_rd_neighbor_advertised_routes,
901 show_bgp_ipv6_encap_rd_neighbor_advertised_routes_cmd,
6147e2c6 902 "show bgp ipv6 encap rd ASN:nn_or_IP-address:nn neighbors <A.B.C.D|X:X::X:X> advertised-routes",
587ff0fd
LB
903 SHOW_STR
904 BGP_STR
905 "Address Family\n"
906 "Display ENCAP NLRI specific information\n"
907 "Display information for a route distinguisher\n"
908 "ENCAP Route Distinguisher\n"
909 "Detailed information on TCP and BGP neighbor connections\n"
910 "Neighbor to display information about\n"
911 "Neighbor to display information about\n"
912 "Display the routes advertised to a BGP neighbor\n")
913{
914 int ret;
915 struct peer *peer;
916 struct prefix_rd prd;
917 union sockunion su;
918
919 ret = str2sockunion (argv[1], &su);
920 if (ret < 0)
921 {
922 vty_out (vty, "%% Malformed address: %s%s", argv[1], VTY_NEWLINE);
923 return CMD_WARNING;
924 }
925 peer = peer_lookup (NULL, &su);
926 if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP])
927 {
928 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
929 return CMD_WARNING;
930 }
931
932 ret = str2prefix_rd (argv[0], &prd);
933 if (! ret)
934 {
935 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
936 return CMD_WARNING;
937 }
938
939 return show_adj_route_encap (vty, peer, &prd);
940}
941#endif
942
943void
944bgp_encap_init (void)
945{
8b1fb8be
LB
946 install_element (BGP_ENCAP_NODE, &encap_network_cmd);
947 install_element (BGP_ENCAP_NODE, &no_encap_network_cmd);
587ff0fd
LB
948
949 install_element (VIEW_NODE, &show_bgp_ipv4_encap_cmd);
950 install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_cmd);
951 install_element (VIEW_NODE, &show_bgp_ipv4_encap_tags_cmd);
952 install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_tags_cmd);
953 install_element (VIEW_NODE, &show_bgp_ipv4_encap_neighbor_routes_cmd);
954 install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_neighbor_routes_cmd);
955 install_element (VIEW_NODE, &show_bgp_ipv4_encap_neighbor_advertised_routes_cmd);
956 install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_neighbor_advertised_routes_cmd);
957
958#ifdef HAVE_IPV6
959 install_element (VIEW_NODE, &show_bgp_ipv6_encap_cmd);
960 install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_cmd);
961 install_element (VIEW_NODE, &show_bgp_ipv6_encap_tags_cmd);
962 install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_tags_cmd);
963 install_element (VIEW_NODE, &show_bgp_ipv6_encap_neighbor_routes_cmd);
964 install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_neighbor_routes_cmd);
965 install_element (VIEW_NODE, &show_bgp_ipv6_encap_neighbor_advertised_routes_cmd);
966 install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_neighbor_advertised_routes_cmd);
967#endif
968
969
970 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_cmd);
971 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_rd_cmd);
972 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_tags_cmd);
973 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_rd_tags_cmd);
974 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_neighbor_routes_cmd);
975 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_rd_neighbor_routes_cmd);
976 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_neighbor_advertised_routes_cmd);
977 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_rd_neighbor_advertised_routes_cmd);
978
979#ifdef HAVE_IPV6
980 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_cmd);
981 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_rd_cmd);
982 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_tags_cmd);
983 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_rd_tags_cmd);
984 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_neighbor_routes_cmd);
985 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_rd_neighbor_routes_cmd);
986 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_neighbor_advertised_routes_cmd);
987 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_rd_neighbor_advertised_routes_cmd);
988#endif
989
990
991}