blob: 900bc4875a2276d4ca98bdcd3008c2ad6f5d742d [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* MPLS-VPN
2 Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "command.h"
24#include "prefix.h"
25#include "log.h"
26#include "memory.h"
27#include "stream.h"
Donald Sharp04907292016-01-07 10:03:01 -050028#include "filter.h"
paul718e3742002-12-13 20:15:29 +000029
30#include "bgpd/bgpd.h"
31#include "bgpd/bgp_table.h"
32#include "bgpd/bgp_route.h"
33#include "bgpd/bgp_attr.h"
34#include "bgpd/bgp_mplsvpn.h"
Paul Jakma18ab08b2016-01-27 16:37:33 +000035#include "bgpd/bgp_packet.h"
paul718e3742002-12-13 20:15:29 +000036
paul94f2b392005-06-28 12:44:16 +000037static u_int16_t
paul718e3742002-12-13 20:15:29 +000038decode_rd_type (u_char *pnt)
39{
40 u_int16_t v;
41
42 v = ((u_int16_t) *pnt++ << 8);
43 v |= (u_int16_t) *pnt;
44 return v;
45}
46
47u_int32_t
48decode_label (u_char *pnt)
49{
50 u_int32_t l;
51
52 l = ((u_int32_t) *pnt++ << 12);
53 l |= (u_int32_t) *pnt++ << 4;
54 l |= (u_int32_t) ((*pnt & 0xf0) >> 4);
55 return l;
56}
57
Lou Bergera03bd162016-01-12 13:41:54 -050058/* type == RD_TYPE_AS */
paul94f2b392005-06-28 12:44:16 +000059static void
paul718e3742002-12-13 20:15:29 +000060decode_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
Lou Bergera03bd162016-01-12 13:41:54 -050071/* type == RD_TYPE_AS4 */
72static void
73decode_rd_as4 (u_char *pnt, struct rd_as *rd_as)
74{
75 rd_as->as = (u_int32_t) *pnt++ << 24;
76 rd_as->as |= (u_int32_t) *pnt++ << 16;
77 rd_as->as |= (u_int32_t) *pnt++ << 8;
78 rd_as->as |= (u_int32_t) *pnt++;
79
80 rd_as->val = ((u_int16_t) *pnt++ << 8);
81 rd_as->val |= (u_int16_t) *pnt;
82}
83
84/* type == RD_TYPE_IP */
paul94f2b392005-06-28 12:44:16 +000085static void
paul718e3742002-12-13 20:15:29 +000086decode_rd_ip (u_char *pnt, struct rd_ip *rd_ip)
87{
88 memcpy (&rd_ip->ip, pnt, 4);
89 pnt += 4;
90
91 rd_ip->val = ((u_int16_t) *pnt++ << 8);
92 rd_ip->val |= (u_int16_t) *pnt;
93}
94
Paul Jakma18ab08b2016-01-27 16:37:33 +000095static int
96bgp_nlri_parse_vpn_body (struct peer *peer, struct attr *attr,
97 struct bgp_nlri *packet, bool update)
paul718e3742002-12-13 20:15:29 +000098{
99 u_char *pnt;
100 u_char *lim;
101 struct prefix p;
Lou Berger9da04bc2016-01-12 13:41:55 -0500102 int psize = 0;
paul718e3742002-12-13 20:15:29 +0000103 int prefixlen;
paul718e3742002-12-13 20:15:29 +0000104 u_int16_t type;
105 struct rd_as rd_as;
106 struct rd_ip rd_ip;
107 struct prefix_rd prd;
108 u_char *tagpnt;
109
110 /* Check peer status. */
111 if (peer->status != Established)
112 return 0;
113
114 /* Make prefix_rd */
115 prd.family = AF_UNSPEC;
116 prd.prefixlen = 64;
117
118 pnt = packet->nlri;
119 lim = pnt + packet->length;
120
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000121#define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
paul718e3742002-12-13 20:15:29 +0000122 for (; pnt < lim; pnt += psize)
123 {
124 /* Clear prefix structure. */
125 memset (&p, 0, sizeof (struct prefix));
126
127 /* Fetch prefix length. */
128 prefixlen = *pnt++;
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000129 p.family = afi2family (packet->afi);
paul718e3742002-12-13 20:15:29 +0000130 psize = PSIZE (prefixlen);
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000131
132 /* sanity check against packet data */
Paul Jakma18ab08b2016-01-27 16:37:33 +0000133 if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8)
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000134 {
Paul Jakma18ab08b2016-01-27 16:37:33 +0000135 plog_err (peer->log,
136 "%s [Error] Update packet error / VPNv4"
137 " (prefix length %d less than VPNv4 min length)",
138 peer->host, prefixlen);
139 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
140 BGP_NOTIFY_UPDATE_OPT_ATTR_ERR);
141 return -1;
142 }
143 if ((pnt + psize) > lim)
144 {
145 plog_err (peer->log,
146 "%s [Error] Update packet error / VPNv4"
147 " (psize %u exceeds packet size (%u)",
148 peer->host,
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000149 prefixlen, (uint)(lim-pnt));
Paul Jakma18ab08b2016-01-27 16:37:33 +0000150 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
151 BGP_NOTIFY_UPDATE_OPT_ATTR_ERR);
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000152 return -1;
153 }
154
155 /* sanity check against storage for the IP address portion */
156 if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u))
157 {
Paul Jakma18ab08b2016-01-27 16:37:33 +0000158 plog_err (peer->log,
159 "%s [Error] Update packet error / VPNv4"
160 " (psize %u exceeds storage size (%zu)",
161 peer->host,
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000162 prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u));
Paul Jakma18ab08b2016-01-27 16:37:33 +0000163 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
164 BGP_NOTIFY_UPDATE_OPT_ATTR_ERR);
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000165 return -1;
166 }
167
168 /* Sanity check against max bitlen of the address family */
169 if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p))
170 {
Paul Jakma18ab08b2016-01-27 16:37:33 +0000171 plog_err (peer->log,
172 "%s [Error] Update packet error / VPNv4"
173 " (psize %u exceeds family (%u) max byte len %u)",
174 peer->host,
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000175 prefixlen - VPN_PREFIXLEN_MIN_BYTES*8,
176 p.family, prefix_blen (&p));
Paul Jakma18ab08b2016-01-27 16:37:33 +0000177 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
178 BGP_NOTIFY_UPDATE_OPT_ATTR_ERR);
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000179 return -1;
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000180 }
181
paul718e3742002-12-13 20:15:29 +0000182 /* Copyr label to prefix. */
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000183 tagpnt = pnt;
paul718e3742002-12-13 20:15:29 +0000184
185 /* Copy routing distinguisher to rd. */
186 memcpy (&prd.val, pnt + 3, 8);
187
188 /* Decode RD type. */
189 type = decode_rd_type (pnt + 3);
190
Lou Bergera03bd162016-01-12 13:41:54 -0500191 switch (type)
192 {
193 case RD_TYPE_AS:
194 decode_rd_as (pnt + 5, &rd_as);
195 break;
196
197 case RD_TYPE_AS4:
198 decode_rd_as4 (pnt + 5, &rd_as);
199 break;
200
201 case RD_TYPE_IP:
202 decode_rd_ip (pnt + 5, &rd_ip);
203 break;
204
Lou Berger050defe2016-01-12 13:41:59 -0500205 default:
206 zlog_err ("Unknown RD type %d", type);
207 break; /* just report */
208 }
paul718e3742002-12-13 20:15:29 +0000209
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000210 p.prefixlen = prefixlen - VPN_PREFIXLEN_MIN_BYTES*8;
211 memcpy (&p.u.prefix, pnt + VPN_PREFIXLEN_MIN_BYTES,
212 psize - VPN_PREFIXLEN_MIN_BYTES);
paul718e3742002-12-13 20:15:29 +0000213
Paul Jakma18ab08b2016-01-27 16:37:33 +0000214 if (update)
215 {
216 if (attr)
217 bgp_update (peer, &p, attr, packet->afi, SAFI_MPLS_VPN,
218 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0);
219 else
220 bgp_withdraw (peer, &p, attr, packet->afi, SAFI_MPLS_VPN,
221 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
222 }
paul718e3742002-12-13 20:15:29 +0000223 }
paul718e3742002-12-13 20:15:29 +0000224 /* Packet length consistency check. */
225 if (pnt != lim)
Paul Jakma18ab08b2016-01-27 16:37:33 +0000226 {
227 plog_err (peer->log,
228 "%s [Error] Update packet error / VPNv4"
229 " (%zu data remaining after parsing)",
230 peer->host, lim - pnt);
231 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
232 BGP_NOTIFY_UPDATE_OPT_ATTR_ERR);
233 return -1;
234 }
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000235
paul718e3742002-12-13 20:15:29 +0000236 return 0;
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000237#undef VPN_PREFIXLEN_MIN_BYTES
paul718e3742002-12-13 20:15:29 +0000238}
239
240int
Paul Jakma18ab08b2016-01-27 16:37:33 +0000241bgp_nlri_sanity_check_vpn (struct peer *peer, struct bgp_nlri *nlri)
242{
243 return bgp_nlri_parse_vpn_body (peer, NULL, nlri, false);
244}
245
246int
247bgp_nlri_parse_vpn (struct peer *peer, struct attr *attr,
248 struct bgp_nlri *packet)
249{
250 return bgp_nlri_parse_vpn_body (peer, attr, packet, true);
251}
252
253int
paulfd79ac92004-10-13 05:06:08 +0000254str2prefix_rd (const char *str, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +0000255{
Lou Berger056f3762013-04-10 12:30:04 -0700256 int ret; /* ret of called functions */
257 int lret; /* local ret, of this func */
paul5228ad22004-06-04 17:58:18 +0000258 char *p;
259 char *p2;
Lou Berger056f3762013-04-10 12:30:04 -0700260 struct stream *s = NULL;
261 char *half = NULL;
paul718e3742002-12-13 20:15:29 +0000262 struct in_addr addr;
263
264 s = stream_new (8);
265
266 prd->family = AF_UNSPEC;
267 prd->prefixlen = 64;
268
Lou Berger056f3762013-04-10 12:30:04 -0700269 lret = 0;
paul718e3742002-12-13 20:15:29 +0000270 p = strchr (str, ':');
271 if (! p)
Lou Berger056f3762013-04-10 12:30:04 -0700272 goto out;
paul718e3742002-12-13 20:15:29 +0000273
274 if (! all_digit (p + 1))
Lou Berger056f3762013-04-10 12:30:04 -0700275 goto out;
paul718e3742002-12-13 20:15:29 +0000276
277 half = XMALLOC (MTYPE_TMP, (p - str) + 1);
278 memcpy (half, str, (p - str));
279 half[p - str] = '\0';
280
281 p2 = strchr (str, '.');
282
283 if (! p2)
284 {
285 if (! all_digit (half))
Lou Berger056f3762013-04-10 12:30:04 -0700286 goto out;
287
paul718e3742002-12-13 20:15:29 +0000288 stream_putw (s, RD_TYPE_AS);
289 stream_putw (s, atoi (half));
290 stream_putl (s, atol (p + 1));
291 }
292 else
293 {
294 ret = inet_aton (half, &addr);
295 if (! ret)
Lou Berger056f3762013-04-10 12:30:04 -0700296 goto out;
297
paul718e3742002-12-13 20:15:29 +0000298 stream_putw (s, RD_TYPE_IP);
299 stream_put_in_addr (s, &addr);
300 stream_putw (s, atol (p + 1));
301 }
302 memcpy (prd->val, s->data, 8);
Lou Berger056f3762013-04-10 12:30:04 -0700303 lret = 1;
paul718e3742002-12-13 20:15:29 +0000304
Lou Berger056f3762013-04-10 12:30:04 -0700305out:
306 if (s)
307 stream_free (s);
308 if (half)
309 XFREE(MTYPE_TMP, half);
310 return lret;
paul718e3742002-12-13 20:15:29 +0000311}
312
313int
paulfd79ac92004-10-13 05:06:08 +0000314str2tag (const char *str, u_char *tag)
paul718e3742002-12-13 20:15:29 +0000315{
paulfd79ac92004-10-13 05:06:08 +0000316 unsigned long l;
317 char *endptr;
318 u_int32_t t;
paul718e3742002-12-13 20:15:29 +0000319
Ulrich Weber664711c2011-12-21 02:24:11 +0400320 if (*str == '-')
321 return 0;
paulfd79ac92004-10-13 05:06:08 +0000322
Ulrich Weber664711c2011-12-21 02:24:11 +0400323 errno = 0;
324 l = strtoul (str, &endptr, 10);
325
326 if (*endptr != '\0' || errno || l > UINT32_MAX)
paulfd79ac92004-10-13 05:06:08 +0000327 return 0;
paul718e3742002-12-13 20:15:29 +0000328
paulfd79ac92004-10-13 05:06:08 +0000329 t = (u_int32_t) l;
330
331 tag[0] = (u_char)(t >> 12);
332 tag[1] = (u_char)(t >> 4);
333 tag[2] = (u_char)(t << 4);
paul718e3742002-12-13 20:15:29 +0000334
335 return 1;
336}
337
338char *
339prefix_rd2str (struct prefix_rd *prd, char *buf, size_t size)
340{
341 u_char *pnt;
342 u_int16_t type;
343 struct rd_as rd_as;
344 struct rd_ip rd_ip;
345
346 if (size < RD_ADDRSTRLEN)
347 return NULL;
348
349 pnt = prd->val;
350
351 type = decode_rd_type (pnt);
352
353 if (type == RD_TYPE_AS)
354 {
355 decode_rd_as (pnt + 2, &rd_as);
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400356 snprintf (buf, size, "%u:%d", rd_as.as, rd_as.val);
paul718e3742002-12-13 20:15:29 +0000357 return buf;
358 }
Lou Bergera03bd162016-01-12 13:41:54 -0500359 else if (type == RD_TYPE_AS4)
360 {
361 decode_rd_as4 (pnt + 2, &rd_as);
362 snprintf (buf, size, "%u:%d", rd_as.as, rd_as.val);
363 return buf;
364 }
paul718e3742002-12-13 20:15:29 +0000365 else if (type == RD_TYPE_IP)
366 {
367 decode_rd_ip (pnt + 2, &rd_ip);
368 snprintf (buf, size, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
369 return buf;
370 }
paul718e3742002-12-13 20:15:29 +0000371 return NULL;
372}
373
374/* For testing purpose, static route of MPLS-VPN. */
375DEFUN (vpnv4_network,
376 vpnv4_network_cmd,
377 "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
378 "Specify a network to announce via BGP\n"
379 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
380 "Specify Route Distinguisher\n"
381 "VPN Route Distinguisher\n"
382 "BGP tag\n"
383 "tag value\n")
384{
Lou Bergera76d9ca2016-01-12 13:41:53 -0500385 return bgp_static_set_safi (SAFI_MPLS_VPN, vty, argv[0], argv[1], argv[2], NULL);
386}
387
388DEFUN (vpnv4_network_route_map,
389 vpnv4_network_route_map_cmd,
390 "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD route-map WORD",
391 "Specify a network to announce via BGP\n"
392 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
393 "Specify Route Distinguisher\n"
394 "VPN Route Distinguisher\n"
395 "BGP tag\n"
396 "tag value\n"
397 "route map\n"
398 "route map name\n")
399{
400 return bgp_static_set_safi (SAFI_MPLS_VPN, vty, argv[0], argv[1], argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +0000401}
402
403/* For testing purpose, static route of MPLS-VPN. */
404DEFUN (no_vpnv4_network,
405 no_vpnv4_network_cmd,
406 "no network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
407 NO_STR
408 "Specify a network to announce via BGP\n"
409 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
410 "Specify Route Distinguisher\n"
411 "VPN Route Distinguisher\n"
412 "BGP tag\n"
413 "tag value\n")
414{
Lou Bergera76d9ca2016-01-12 13:41:53 -0500415 return bgp_static_unset_safi (SAFI_MPLS_VPN, vty, argv[0], argv[1], argv[2]);
paul718e3742002-12-13 20:15:29 +0000416}
417
paul94f2b392005-06-28 12:44:16 +0000418static int
paul718e3742002-12-13 20:15:29 +0000419show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd)
420{
421 struct bgp *bgp;
422 struct bgp_table *table;
423 struct bgp_node *rn;
424 struct bgp_node *rm;
425 struct attr *attr;
426 int rd_header;
427 int header = 1;
428 char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
429
430 bgp = bgp_get_default ();
431 if (bgp == NULL)
432 {
433 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
434 return CMD_WARNING;
435 }
436
437 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn;
438 rn = bgp_route_next (rn))
439 {
440 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
441 continue;
442
443 if ((table = rn->info) != NULL)
444 {
445 rd_header = 1;
446
447 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
448 if ((attr = rm->info) != NULL)
449 {
450 if (header)
451 {
452 vty_out (vty, "BGP table version is 0, local router ID is %s%s",
453 inet_ntoa (bgp->router_id), VTY_NEWLINE);
454 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
455 VTY_NEWLINE);
456 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
457 VTY_NEWLINE, VTY_NEWLINE);
458 vty_out (vty, v4_header, VTY_NEWLINE);
459 header = 0;
460 }
461
462 if (rd_header)
463 {
464 u_int16_t type;
465 struct rd_as rd_as;
466 struct rd_ip rd_ip;
467 u_char *pnt;
468
469 pnt = rn->p.u.val;
470
471 /* Decode RD type. */
472 type = decode_rd_type (pnt);
473 /* Decode RD value. */
474 if (type == RD_TYPE_AS)
475 decode_rd_as (pnt + 2, &rd_as);
Lou Bergera03bd162016-01-12 13:41:54 -0500476 else if (type == RD_TYPE_AS4)
477 decode_rd_as4 (pnt + 2, &rd_as);
paul718e3742002-12-13 20:15:29 +0000478 else if (type == RD_TYPE_IP)
479 decode_rd_ip (pnt + 2, &rd_ip);
480
481 vty_out (vty, "Route Distinguisher: ");
482
483 if (type == RD_TYPE_AS)
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400484 vty_out (vty, "%u:%d", rd_as.as, rd_as.val);
Lou Bergera03bd162016-01-12 13:41:54 -0500485 else if (type == RD_TYPE_AS4)
486 vty_out (vty, "%u:%d", rd_as.as, rd_as.val);
paul718e3742002-12-13 20:15:29 +0000487 else if (type == RD_TYPE_IP)
488 vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
489
490 vty_out (vty, "%s", VTY_NEWLINE);
491 rd_header = 0;
492 }
493 route_vty_out_tmp (vty, &rm->p, attr, SAFI_MPLS_VPN);
494 }
495 }
496 }
497 return CMD_SUCCESS;
498}
499
500enum bgp_show_type
501{
502 bgp_show_type_normal,
503 bgp_show_type_regexp,
504 bgp_show_type_prefix_list,
505 bgp_show_type_filter_list,
506 bgp_show_type_neighbor,
507 bgp_show_type_cidr_only,
508 bgp_show_type_prefix_longer,
509 bgp_show_type_community_all,
510 bgp_show_type_community,
511 bgp_show_type_community_exact,
512 bgp_show_type_community_list,
513 bgp_show_type_community_list_exact
514};
515
paul94f2b392005-06-28 12:44:16 +0000516static int
Lou Berger35c36862016-01-12 13:42:06 -0500517bgp_show_mpls_vpn(
518 struct vty *vty,
519 afi_t afi,
520 struct prefix_rd *prd,
521 enum bgp_show_type type,
522 void *output_arg,
523 int tags)
paul718e3742002-12-13 20:15:29 +0000524{
525 struct bgp *bgp;
526 struct bgp_table *table;
527 struct bgp_node *rn;
528 struct bgp_node *rm;
529 struct bgp_info *ri;
530 int rd_header;
531 int header = 1;
532 char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
533 char v4_header_tag[] = " Network Next Hop In tag/Out tag%s";
534
Lou Bergerbf1ae6c2016-01-12 13:42:08 -0500535 unsigned long output_count = 0;
536 unsigned long total_count = 0;
537
paul718e3742002-12-13 20:15:29 +0000538 bgp = bgp_get_default ();
539 if (bgp == NULL)
540 {
541 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
542 return CMD_WARNING;
543 }
544
Lou Berger9da04bc2016-01-12 13:41:55 -0500545 if ((afi != AFI_IP) && (afi != AFI_IP6))
546 {
547 vty_out (vty, "Afi %d not supported%s", afi, VTY_NEWLINE);
548 return CMD_WARNING;
549 }
550
551 for (rn = bgp_table_top (bgp->rib[afi][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +0000552 {
553 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
554 continue;
555
556 if ((table = rn->info) != NULL)
557 {
558 rd_header = 1;
559
560 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
561 for (ri = rm->info; ri; ri = ri->next)
562 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -0500563 total_count++;
paul718e3742002-12-13 20:15:29 +0000564 if (type == bgp_show_type_neighbor)
565 {
566 union sockunion *su = output_arg;
567
568 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
569 continue;
570 }
571 if (header)
572 {
573 if (tags)
574 vty_out (vty, v4_header_tag, VTY_NEWLINE);
575 else
576 {
577 vty_out (vty, "BGP table version is 0, local router ID is %s%s",
578 inet_ntoa (bgp->router_id), VTY_NEWLINE);
579 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
580 VTY_NEWLINE);
581 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
582 VTY_NEWLINE, VTY_NEWLINE);
583 vty_out (vty, v4_header, VTY_NEWLINE);
584 }
585 header = 0;
586 }
587
588 if (rd_header)
589 {
590 u_int16_t type;
591 struct rd_as rd_as;
592 struct rd_ip rd_ip;
593 u_char *pnt;
594
595 pnt = rn->p.u.val;
596
597 /* Decode RD type. */
598 type = decode_rd_type (pnt);
599 /* Decode RD value. */
600 if (type == RD_TYPE_AS)
601 decode_rd_as (pnt + 2, &rd_as);
Lou Bergera03bd162016-01-12 13:41:54 -0500602 else if (type == RD_TYPE_AS4)
603 decode_rd_as4 (pnt + 2, &rd_as);
paul718e3742002-12-13 20:15:29 +0000604 else if (type == RD_TYPE_IP)
605 decode_rd_ip (pnt + 2, &rd_ip);
606
607 vty_out (vty, "Route Distinguisher: ");
608
609 if (type == RD_TYPE_AS)
Lou Bergera03bd162016-01-12 13:41:54 -0500610 vty_out (vty, "as2 %u:%d", rd_as.as, rd_as.val);
611 else if (type == RD_TYPE_AS4)
612 vty_out (vty, "as4 %u:%d", rd_as.as, rd_as.val);
paul718e3742002-12-13 20:15:29 +0000613 else if (type == RD_TYPE_IP)
Lou Bergera03bd162016-01-12 13:41:54 -0500614 vty_out (vty, "ip %s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
paul718e3742002-12-13 20:15:29 +0000615
616 vty_out (vty, "%s", VTY_NEWLINE);
617 rd_header = 0;
618 }
619 if (tags)
620 route_vty_out_tag (vty, &rm->p, ri, 0, SAFI_MPLS_VPN);
621 else
622 route_vty_out (vty, &rm->p, ri, 0, SAFI_MPLS_VPN);
Lou Bergerbf1ae6c2016-01-12 13:42:08 -0500623 output_count++;
paul718e3742002-12-13 20:15:29 +0000624 }
625 }
626 }
Lou Bergerbf1ae6c2016-01-12 13:42:08 -0500627
628 if (output_count == 0)
629 {
630 vty_out (vty, "No prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
631 }
632 else
633 vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
634 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
635
paul718e3742002-12-13 20:15:29 +0000636 return CMD_SUCCESS;
637}
638
Lou Berger35c36862016-01-12 13:42:06 -0500639DEFUN (show_bgp_ipv4_vpn,
640 show_bgp_ipv4_vpn_cmd,
641 "show bgp ipv4 vpn",
paul718e3742002-12-13 20:15:29 +0000642 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000643 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -0500644 "Address Family\n"
645 "Display VPN NLRI specific information\n")
paul718e3742002-12-13 20:15:29 +0000646{
Lou Berger35c36862016-01-12 13:42:06 -0500647 return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 0);
paul718e3742002-12-13 20:15:29 +0000648}
649
Lou Berger35c36862016-01-12 13:42:06 -0500650DEFUN (show_bgp_ipv6_vpn,
651 show_bgp_ipv6_vpn_cmd,
652 "show bgp ipv6 vpn",
paul718e3742002-12-13 20:15:29 +0000653 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000654 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -0500655 "Address Family\n"
656 "Display VPN NLRI specific information\n")
657{
658 return bgp_show_mpls_vpn (vty, AFI_IP6, NULL, bgp_show_type_normal, NULL, 0);
659}
Lou Berger35c36862016-01-12 13:42:06 -0500660
661DEFUN (show_bgp_ipv4_vpn_rd,
662 show_bgp_ipv4_vpn_rd_cmd,
663 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn",
664 SHOW_STR
665 BGP_STR
666 "Address Family\n"
667 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +0000668 "Display information for a route distinguisher\n"
669 "VPN Route Distinguisher\n")
670{
671 int ret;
672 struct prefix_rd prd;
673
674 ret = str2prefix_rd (argv[0], &prd);
675 if (! ret)
676 {
677 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
678 return CMD_WARNING;
679 }
Lou Berger35c36862016-01-12 13:42:06 -0500680 return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 0);
paul718e3742002-12-13 20:15:29 +0000681}
682
Lou Berger35c36862016-01-12 13:42:06 -0500683DEFUN (show_bgp_ipv6_vpn_rd,
684 show_bgp_ipv6_vpn_rd_cmd,
685 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn",
paul718e3742002-12-13 20:15:29 +0000686 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000687 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -0500688 "Address Family\n"
689 "Display VPN NLRI specific information\n"
690 "Display information for a route distinguisher\n"
691 "VPN Route Distinguisher\n")
692{
693 int ret;
694 struct prefix_rd prd;
695
696 ret = str2prefix_rd (argv[0], &prd);
697 if (! ret)
698 {
699 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
700 return CMD_WARNING;
701 }
702 return bgp_show_mpls_vpn (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 0);
703}
704
705
706DEFUN (show_bgp_ipv4_vpn_tags,
707 show_bgp_ipv4_vpn_tags_cmd,
708 "show bgp ipv4 vpn tags",
709 SHOW_STR
710 BGP_STR
711 "Address Family\n"
712 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +0000713 "Display BGP tags for prefixes\n")
714{
Lou Berger35c36862016-01-12 13:42:06 -0500715 return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 1);
716}
717DEFUN (show_bgp_ipv6_vpn_tags,
718 show_bgp_ipv6_vpn_tags_cmd,
719 "show bgp ipv6 vpn tags",
720 SHOW_STR
721 BGP_STR
722 "Address Family\n"
723 "Display VPN NLRI specific information\n"
724 "Display BGP tags for prefixes\n")
725{
726 return bgp_show_mpls_vpn (vty, AFI_IP6, NULL, bgp_show_type_normal, NULL, 1);
paul718e3742002-12-13 20:15:29 +0000727}
728
Lou Berger35c36862016-01-12 13:42:06 -0500729DEFUN (show_bgp_ipv4_vpn_rd_tags,
730 show_bgp_ipv4_vpn_rd_tags_cmd,
731 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn tags",
paul718e3742002-12-13 20:15:29 +0000732 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000733 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -0500734 "Address Family\n"
735 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +0000736 "Display information for a route distinguisher\n"
737 "VPN Route Distinguisher\n"
738 "Display BGP tags for prefixes\n")
739{
740 int ret;
741 struct prefix_rd prd;
742
743 ret = str2prefix_rd (argv[0], &prd);
744 if (! ret)
745 {
746 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
747 return CMD_WARNING;
748 }
Lou Berger35c36862016-01-12 13:42:06 -0500749 return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 1);
750}
751DEFUN (show_bgp_ipv6_vpn_rd_tags,
752 show_bgp_ipv6_vpn_rd_tags_cmd,
753 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn tags",
754 SHOW_STR
755 BGP_STR
756 "Address Family\n"
757 "Display VPN NLRI specific information\n"
758 "Display information for a route distinguisher\n"
759 "VPN Route Distinguisher\n"
760 "Display BGP tags for prefixes\n")
761{
762 int ret;
763 struct prefix_rd prd;
764
765 ret = str2prefix_rd (argv[0], &prd);
766 if (! ret)
767 {
768 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
769 return CMD_WARNING;
770 }
771 return bgp_show_mpls_vpn (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 1);
paul718e3742002-12-13 20:15:29 +0000772}
773
Lou Berger35c36862016-01-12 13:42:06 -0500774DEFUN (show_bgp_ipv4_vpn_neighbor_routes,
775 show_bgp_ipv4_vpn_neighbor_routes_cmd,
776 "show bgp ipv4 vpn neighbors (A.B.C.D|X:X::X:X) routes",
paul718e3742002-12-13 20:15:29 +0000777 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000778 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -0500779 "Address Family\n"
780 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +0000781 "Detailed information on TCP and BGP neighbor connections\n"
782 "Neighbor to display information about\n"
Lou Berger35c36862016-01-12 13:42:06 -0500783 "Neighbor to display information about\n"
paul718e3742002-12-13 20:15:29 +0000784 "Display routes learned from neighbor\n")
785{
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200786 union sockunion su;
paul718e3742002-12-13 20:15:29 +0000787 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200788 int ret;
789
790 ret = str2sockunion (argv[0], &su);
791 if (ret < 0)
paul718e3742002-12-13 20:15:29 +0000792 {
793 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200794 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +0000795 }
796
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200797 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +0000798 if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
799 {
800 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
801 return CMD_WARNING;
802 }
803
Lou Berger35c36862016-01-12 13:42:06 -0500804 return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_neighbor, &su, 0);
paul718e3742002-12-13 20:15:29 +0000805}
806
Lou Berger35c36862016-01-12 13:42:06 -0500807DEFUN (show_bgp_ipv6_vpn_neighbor_routes,
808 show_bgp_ipv6_vpn_neighbor_routes_cmd,
809 "show bgp ipv6 vpn neighbors (A.B.C.D|X:X::X:X) routes",
paul718e3742002-12-13 20:15:29 +0000810 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000811 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -0500812 "Address Family\n"
813 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +0000814 "Detailed information on TCP and BGP neighbor connections\n"
815 "Neighbor to display information about\n"
Lou Berger35c36862016-01-12 13:42:06 -0500816 "Neighbor to display information about\n"
paul718e3742002-12-13 20:15:29 +0000817 "Display routes learned from neighbor\n")
818{
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200819 union sockunion su;
paul718e3742002-12-13 20:15:29 +0000820 struct peer *peer;
paul718e3742002-12-13 20:15:29 +0000821
Lou Berger35c36862016-01-12 13:42:06 -0500822 int ret;
paul718e3742002-12-13 20:15:29 +0000823
Lou Berger35c36862016-01-12 13:42:06 -0500824 ret = str2sockunion (argv[0], &su);
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200825 if (ret < 0)
paul718e3742002-12-13 20:15:29 +0000826 {
827 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200828 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +0000829 }
830
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200831 peer = peer_lookup (NULL, &su);
Lou Berger35c36862016-01-12 13:42:06 -0500832 if (! peer || ! peer->afc[AFI_IP6][SAFI_MPLS_VPN])
paul718e3742002-12-13 20:15:29 +0000833 {
834 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
835 return CMD_WARNING;
836 }
837
Lou Berger35c36862016-01-12 13:42:06 -0500838 return bgp_show_mpls_vpn (vty, AFI_IP6, NULL, bgp_show_type_neighbor, &su, 0);
paul718e3742002-12-13 20:15:29 +0000839}
840
Lou Berger35c36862016-01-12 13:42:06 -0500841DEFUN (show_bgp_ipv4_vpn_neighbor_advertised_routes,
842 show_bgp_ipv4_vpn_neighbor_advertised_routes_cmd,
843 "show bgp ipv4 vpn neighbors (A.B.C.D|X:X::X:X) advertised-routes",
paul718e3742002-12-13 20:15:29 +0000844 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000845 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -0500846 "Address Family\n"
847 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +0000848 "Detailed information on TCP and BGP neighbor connections\n"
849 "Neighbor to display information about\n"
850 "Display the routes advertised to a BGP neighbor\n")
851{
852 int ret;
853 struct peer *peer;
854 union sockunion su;
855
856 ret = str2sockunion (argv[0], &su);
857 if (ret < 0)
858 {
859 vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
860 return CMD_WARNING;
861 }
862 peer = peer_lookup (NULL, &su);
863 if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
864 {
865 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
866 return CMD_WARNING;
867 }
868
869 return show_adj_route_vpn (vty, peer, NULL);
870}
Lou Berger35c36862016-01-12 13:42:06 -0500871DEFUN (show_bgp_ipv6_vpn_neighbor_advertised_routes,
872 show_bgp_ipv6_vpn_neighbor_advertised_routes_cmd,
873 "show bgp ipv6 vpn neighbors (A.B.C.D|X:X::X:X) advertised-routes",
874 SHOW_STR
875 BGP_STR
876 "Address Family\n"
877 "Display VPN NLRI specific information\n"
878 "Detailed information on TCP and BGP neighbor connections\n"
879 "Neighbor to display information about\n"
880 "Display the routes advertised to a BGP neighbor\n")
881{
882 int ret;
883 struct peer *peer;
884 union sockunion su;
885
886 ret = str2sockunion (argv[0], &su);
887 if (ret < 0)
888 {
889 vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
890 return CMD_WARNING;
891 }
892 peer = peer_lookup (NULL, &su);
893 if (! peer || ! peer->afc[AFI_IP6][SAFI_MPLS_VPN])
894 {
895 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
896 return CMD_WARNING;
897 }
898
899 return show_adj_route_vpn (vty, peer, NULL);
900}
paul718e3742002-12-13 20:15:29 +0000901
902DEFUN (show_ip_bgp_vpnv4_rd_neighbor_advertised_routes,
Lou Berger35c36862016-01-12 13:42:06 -0500903 show_bgp_ipv4_vpn_rd_neighbor_advertised_routes_cmd,
904 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) advertised-routes",
paul718e3742002-12-13 20:15:29 +0000905 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000906 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -0500907 "Address Family\n"
908 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +0000909 "Display information for a route distinguisher\n"
910 "VPN Route Distinguisher\n"
911 "Detailed information on TCP and BGP neighbor connections\n"
912 "Neighbor to display information about\n"
Lou Berger35c36862016-01-12 13:42:06 -0500913 "Neighbor to display information about\n"
paul718e3742002-12-13 20:15:29 +0000914 "Display the routes advertised to a BGP neighbor\n")
915{
916 int ret;
917 struct peer *peer;
918 struct prefix_rd prd;
919 union sockunion su;
paul718e3742002-12-13 20:15:29 +0000920 ret = str2sockunion (argv[1], &su);
921 if (ret < 0)
922 {
Lou Berger35c36862016-01-12 13:42:06 -0500923 vty_out (vty, "%% Malformed address: %s%s", argv[1], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000924 return CMD_WARNING;
925 }
926 peer = peer_lookup (NULL, &su);
927 if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
928 {
929 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
930 return CMD_WARNING;
931 }
932
933 ret = str2prefix_rd (argv[0], &prd);
934 if (! ret)
935 {
936 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
937 return CMD_WARNING;
938 }
939
940 return show_adj_route_vpn (vty, peer, &prd);
941}
Lou Berger35c36862016-01-12 13:42:06 -0500942DEFUN (show_ip_bgp_vpnv6_rd_neighbor_advertised_routes,
943 show_bgp_ipv6_vpn_rd_neighbor_advertised_routes_cmd,
944 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) advertised-routes",
945 SHOW_STR
946 BGP_STR
947 "Address Family\n"
948 "Display VPN NLRI specific information\n"
949 "Display information for a route distinguisher\n"
950 "VPN Route Distinguisher\n"
951 "Detailed information on TCP and BGP neighbor connections\n"
952 "Neighbor to display information about\n"
953 "Neighbor to display information about\n"
954 "Display the routes advertised to a BGP neighbor\n")
955{
956 int ret;
957 struct peer *peer;
958 struct prefix_rd prd;
959 union sockunion su;
960 ret = str2sockunion (argv[1], &su);
961 if (ret < 0)
962 {
963 vty_out (vty, "%% Malformed address: %s%s", argv[1], VTY_NEWLINE);
964 return CMD_WARNING;
965 }
966 peer = peer_lookup (NULL, &su);
967 if (! peer || ! peer->afc[AFI_IP6][SAFI_MPLS_VPN])
968 {
969 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
970 return CMD_WARNING;
971 }
972
973 ret = str2prefix_rd (argv[0], &prd);
974 if (! ret)
975 {
976 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
977 return CMD_WARNING;
978 }
979
980 return show_adj_route_vpn (vty, peer, &prd);
981}
982
983DEFUN (show_bgp_ipv4_vpn_rd_neighbor_routes,
984 show_bgp_ipv4_vpn_rd_neighbor_routes_cmd,
985 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) routes",
986 SHOW_STR
987 BGP_STR
988 "Address Family\n"
989 "Address Family modifier\n"
990 "Display information for a route distinguisher\n"
991 "VPN Route Distinguisher\n"
992 "Detailed information on TCP and BGP neighbor connections\n"
993 "Neighbor to display information about\n"
994 "Display routes learned from neighbor\n")
995{
996 int ret;
997 union sockunion *su;
998 struct peer *peer;
999 struct prefix_rd prd;
1000
1001 ret = str2prefix_rd (argv[0], &prd);
1002 if (! ret)
1003 {
1004 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
1005 return CMD_WARNING;
1006 }
1007
1008 su = sockunion_str2su (argv[1]);
1009 if (su == NULL)
1010 {
1011 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
1012 return CMD_WARNING;
1013 }
1014
1015 peer = peer_lookup (NULL, su);
1016 if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
1017 {
1018 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
1019 return CMD_WARNING;
1020 }
1021
1022 return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_neighbor, su, 0);
1023}
1024DEFUN (show_bgp_ipv6_vpn_rd_neighbor_routes,
1025 show_bgp_ipv6_vpn_rd_neighbor_routes_cmd,
1026 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) routes",
1027 SHOW_STR
1028 BGP_STR
1029 "Address Family\n"
1030 "Address Family modifier\n"
1031 "Display information for a route distinguisher\n"
1032 "VPN Route Distinguisher\n"
1033 "Detailed information on TCP and BGP neighbor connections\n"
1034 "Neighbor to display information about\n"
1035 "Display routes learned from neighbor\n")
1036{
1037 int ret;
1038 union sockunion *su;
1039 struct peer *peer;
1040 struct prefix_rd prd;
1041
1042 ret = str2prefix_rd (argv[0], &prd);
1043 if (! ret)
1044 {
1045 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
1046 return CMD_WARNING;
1047 }
1048
1049 su = sockunion_str2su (argv[1]);
1050 if (su == NULL)
1051 {
1052 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
1053 return CMD_WARNING;
1054 }
1055
1056 peer = peer_lookup (NULL, su);
1057 if (! peer || ! peer->afc[AFI_IP6][SAFI_MPLS_VPN])
1058 {
1059 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
1060 return CMD_WARNING;
1061 }
1062
1063 return bgp_show_mpls_vpn (vty, AFI_IP6, &prd, bgp_show_type_neighbor, su, 0);
1064}
paul718e3742002-12-13 20:15:29 +00001065
1066void
paul94f2b392005-06-28 12:44:16 +00001067bgp_mplsvpn_init (void)
paul718e3742002-12-13 20:15:29 +00001068{
1069 install_element (BGP_VPNV4_NODE, &vpnv4_network_cmd);
Lou Bergera76d9ca2016-01-12 13:41:53 -05001070 install_element (BGP_VPNV4_NODE, &vpnv4_network_route_map_cmd);
paul718e3742002-12-13 20:15:29 +00001071 install_element (BGP_VPNV4_NODE, &no_vpnv4_network_cmd);
1072
Lou Berger35c36862016-01-12 13:42:06 -05001073 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_cmd);
1074 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_cmd);
1075 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_tags_cmd);
1076 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_tags_cmd);
1077 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_neighbor_routes_cmd);
1078 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_neighbor_advertised_routes_cmd);
1079 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_neighbor_advertised_routes_cmd);
1080 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +00001081
Lou Berger35c36862016-01-12 13:42:06 -05001082 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_cmd);
1083 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_cmd);
1084 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_tags_cmd);
1085 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_tags_cmd);
1086 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_neighbor_routes_cmd);
1087 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_neighbor_advertised_routes_cmd);
1088 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_neighbor_advertised_routes_cmd);
1089 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +00001090
Lou Berger35c36862016-01-12 13:42:06 -05001091 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_cmd);
1092 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_cmd);
1093 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_tags_cmd);
1094 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_tags_cmd);
1095 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_neighbor_routes_cmd);
1096 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_neighbor_advertised_routes_cmd);
1097 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_neighbor_advertised_routes_cmd);
1098 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_neighbor_routes_cmd);
1099
Lou Berger35c36862016-01-12 13:42:06 -05001100 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_cmd);
1101 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_cmd);
1102 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_tags_cmd);
1103 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_tags_cmd);
1104 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_neighbor_routes_cmd);
1105 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_neighbor_advertised_routes_cmd);
1106 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_neighbor_advertised_routes_cmd);
1107 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +00001108}