blob: 83bb6ca9d9019d1e4815e42f7e2e9600b6a169a3 [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"
Paul Jakma518a4b72016-02-04 13:27:04 +000033#include "bgpd/bgp_packet.h"
paul718e3742002-12-13 20:15:29 +000034#include "bgpd/bgp_attr.h"
35#include "bgpd/bgp_mplsvpn.h"
Paul Jakma18ab08b2016-01-27 16:37:33 +000036#include "bgpd/bgp_packet.h"
paul718e3742002-12-13 20:15:29 +000037
paul94f2b392005-06-28 12:44:16 +000038static u_int16_t
paul718e3742002-12-13 20:15:29 +000039decode_rd_type (u_char *pnt)
40{
41 u_int16_t v;
42
43 v = ((u_int16_t) *pnt++ << 8);
44 v |= (u_int16_t) *pnt;
45 return v;
46}
47
48u_int32_t
49decode_label (u_char *pnt)
50{
51 u_int32_t l;
52
53 l = ((u_int32_t) *pnt++ << 12);
54 l |= (u_int32_t) *pnt++ << 4;
55 l |= (u_int32_t) ((*pnt & 0xf0) >> 4);
56 return l;
57}
58
Lou Bergera03bd162016-01-12 13:41:54 -050059/* type == RD_TYPE_AS */
paul94f2b392005-06-28 12:44:16 +000060static void
paul718e3742002-12-13 20:15:29 +000061decode_rd_as (u_char *pnt, struct rd_as *rd_as)
62{
63 rd_as->as = (u_int16_t) *pnt++ << 8;
64 rd_as->as |= (u_int16_t) *pnt++;
65
66 rd_as->val = ((u_int32_t) *pnt++ << 24);
67 rd_as->val |= ((u_int32_t) *pnt++ << 16);
68 rd_as->val |= ((u_int32_t) *pnt++ << 8);
69 rd_as->val |= (u_int32_t) *pnt;
70}
71
Lou Bergera03bd162016-01-12 13:41:54 -050072/* type == RD_TYPE_AS4 */
73static void
74decode_rd_as4 (u_char *pnt, struct rd_as *rd_as)
75{
76 rd_as->as = (u_int32_t) *pnt++ << 24;
77 rd_as->as |= (u_int32_t) *pnt++ << 16;
78 rd_as->as |= (u_int32_t) *pnt++ << 8;
79 rd_as->as |= (u_int32_t) *pnt++;
80
81 rd_as->val = ((u_int16_t) *pnt++ << 8);
82 rd_as->val |= (u_int16_t) *pnt;
83}
84
85/* type == RD_TYPE_IP */
paul94f2b392005-06-28 12:44:16 +000086static void
paul718e3742002-12-13 20:15:29 +000087decode_rd_ip (u_char *pnt, struct rd_ip *rd_ip)
88{
89 memcpy (&rd_ip->ip, pnt, 4);
90 pnt += 4;
91
92 rd_ip->val = ((u_int16_t) *pnt++ << 8);
93 rd_ip->val |= (u_int16_t) *pnt;
94}
95
Paul Jakma18ab08b2016-01-27 16:37:33 +000096static int
97bgp_nlri_parse_vpn_body (struct peer *peer, struct attr *attr,
98 struct bgp_nlri *packet, bool update)
paul718e3742002-12-13 20:15:29 +000099{
100 u_char *pnt;
101 u_char *lim;
102 struct prefix p;
Lou Berger9da04bc2016-01-12 13:41:55 -0500103 int psize = 0;
paul718e3742002-12-13 20:15:29 +0000104 int prefixlen;
paul718e3742002-12-13 20:15:29 +0000105 u_int16_t type;
106 struct rd_as rd_as;
107 struct rd_ip rd_ip;
108 struct prefix_rd prd;
109 u_char *tagpnt;
110
111 /* Check peer status. */
112 if (peer->status != Established)
113 return 0;
114
115 /* Make prefix_rd */
116 prd.family = AF_UNSPEC;
117 prd.prefixlen = 64;
118
119 pnt = packet->nlri;
120 lim = pnt + packet->length;
121
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000122#define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
paul718e3742002-12-13 20:15:29 +0000123 for (; pnt < lim; pnt += psize)
124 {
125 /* Clear prefix structure. */
126 memset (&p, 0, sizeof (struct prefix));
127
128 /* Fetch prefix length. */
129 prefixlen = *pnt++;
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000130 p.family = afi2family (packet->afi);
paul718e3742002-12-13 20:15:29 +0000131 psize = PSIZE (prefixlen);
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000132
133 /* sanity check against packet data */
Paul Jakma18ab08b2016-01-27 16:37:33 +0000134 if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8)
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000135 {
Paul Jakma18ab08b2016-01-27 16:37:33 +0000136 plog_err (peer->log,
137 "%s [Error] Update packet error / VPNv4"
138 " (prefix length %d less than VPNv4 min length)",
139 peer->host, prefixlen);
140 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
141 BGP_NOTIFY_UPDATE_OPT_ATTR_ERR);
142 return -1;
143 }
144 if ((pnt + psize) > lim)
145 {
146 plog_err (peer->log,
147 "%s [Error] Update packet error / VPNv4"
148 " (psize %u exceeds packet size (%u)",
149 peer->host,
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000150 prefixlen, (uint)(lim-pnt));
Paul Jakma18ab08b2016-01-27 16:37:33 +0000151 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
152 BGP_NOTIFY_UPDATE_OPT_ATTR_ERR);
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000153 return -1;
154 }
155
156 /* sanity check against storage for the IP address portion */
157 if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u))
158 {
Paul Jakma18ab08b2016-01-27 16:37:33 +0000159 plog_err (peer->log,
160 "%s [Error] Update packet error / VPNv4"
161 " (psize %u exceeds storage size (%zu)",
162 peer->host,
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000163 prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u));
Paul Jakma18ab08b2016-01-27 16:37:33 +0000164 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
165 BGP_NOTIFY_UPDATE_OPT_ATTR_ERR);
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000166 return -1;
167 }
168
169 /* Sanity check against max bitlen of the address family */
170 if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p))
171 {
Paul Jakma18ab08b2016-01-27 16:37:33 +0000172 plog_err (peer->log,
173 "%s [Error] Update packet error / VPNv4"
174 " (psize %u exceeds family (%u) max byte len %u)",
175 peer->host,
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000176 prefixlen - VPN_PREFIXLEN_MIN_BYTES*8,
177 p.family, prefix_blen (&p));
Paul Jakma18ab08b2016-01-27 16:37:33 +0000178 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
179 BGP_NOTIFY_UPDATE_OPT_ATTR_ERR);
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000180 return -1;
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000181 }
182
paul718e3742002-12-13 20:15:29 +0000183 /* Copyr label to prefix. */
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000184 tagpnt = pnt;
paul718e3742002-12-13 20:15:29 +0000185
186 /* Copy routing distinguisher to rd. */
187 memcpy (&prd.val, pnt + 3, 8);
188
189 /* Decode RD type. */
190 type = decode_rd_type (pnt + 3);
191
Lou Bergera03bd162016-01-12 13:41:54 -0500192 switch (type)
193 {
194 case RD_TYPE_AS:
195 decode_rd_as (pnt + 5, &rd_as);
196 break;
197
198 case RD_TYPE_AS4:
199 decode_rd_as4 (pnt + 5, &rd_as);
200 break;
201
202 case RD_TYPE_IP:
203 decode_rd_ip (pnt + 5, &rd_ip);
204 break;
205
Lou Berger050defe2016-01-12 13:41:59 -0500206 default:
207 zlog_err ("Unknown RD type %d", type);
208 break; /* just report */
209 }
paul718e3742002-12-13 20:15:29 +0000210
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000211 p.prefixlen = prefixlen - VPN_PREFIXLEN_MIN_BYTES*8;
212 memcpy (&p.u.prefix, pnt + VPN_PREFIXLEN_MIN_BYTES,
213 psize - VPN_PREFIXLEN_MIN_BYTES);
paul718e3742002-12-13 20:15:29 +0000214
Paul Jakma18ab08b2016-01-27 16:37:33 +0000215 if (update)
216 {
217 if (attr)
218 bgp_update (peer, &p, attr, packet->afi, SAFI_MPLS_VPN,
219 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0);
220 else
221 bgp_withdraw (peer, &p, attr, packet->afi, SAFI_MPLS_VPN,
222 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
223 }
paul718e3742002-12-13 20:15:29 +0000224 }
paul718e3742002-12-13 20:15:29 +0000225 /* Packet length consistency check. */
226 if (pnt != lim)
Paul Jakma18ab08b2016-01-27 16:37:33 +0000227 {
228 plog_err (peer->log,
229 "%s [Error] Update packet error / VPNv4"
230 " (%zu data remaining after parsing)",
231 peer->host, lim - pnt);
232 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
233 BGP_NOTIFY_UPDATE_OPT_ATTR_ERR);
234 return -1;
235 }
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000236
paul718e3742002-12-13 20:15:29 +0000237 return 0;
Donald Sharpa3bc7e92016-01-27 16:54:45 +0000238#undef VPN_PREFIXLEN_MIN_BYTES
paul718e3742002-12-13 20:15:29 +0000239}
240
241int
Paul Jakma18ab08b2016-01-27 16:37:33 +0000242bgp_nlri_sanity_check_vpn (struct peer *peer, struct bgp_nlri *nlri)
243{
244 return bgp_nlri_parse_vpn_body (peer, NULL, nlri, false);
245}
246
247int
248bgp_nlri_parse_vpn (struct peer *peer, struct attr *attr,
249 struct bgp_nlri *packet)
250{
251 return bgp_nlri_parse_vpn_body (peer, attr, packet, true);
252}
253
254int
paulfd79ac92004-10-13 05:06:08 +0000255str2prefix_rd (const char *str, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +0000256{
Lou Berger056f3762013-04-10 12:30:04 -0700257 int ret; /* ret of called functions */
258 int lret; /* local ret, of this func */
paul5228ad22004-06-04 17:58:18 +0000259 char *p;
260 char *p2;
Lou Berger056f3762013-04-10 12:30:04 -0700261 struct stream *s = NULL;
262 char *half = NULL;
paul718e3742002-12-13 20:15:29 +0000263 struct in_addr addr;
264
265 s = stream_new (8);
266
267 prd->family = AF_UNSPEC;
268 prd->prefixlen = 64;
269
Lou Berger056f3762013-04-10 12:30:04 -0700270 lret = 0;
paul718e3742002-12-13 20:15:29 +0000271 p = strchr (str, ':');
272 if (! p)
Lou Berger056f3762013-04-10 12:30:04 -0700273 goto out;
paul718e3742002-12-13 20:15:29 +0000274
275 if (! all_digit (p + 1))
Lou Berger056f3762013-04-10 12:30:04 -0700276 goto out;
paul718e3742002-12-13 20:15:29 +0000277
278 half = XMALLOC (MTYPE_TMP, (p - str) + 1);
279 memcpy (half, str, (p - str));
280 half[p - str] = '\0';
281
282 p2 = strchr (str, '.');
283
284 if (! p2)
285 {
286 if (! all_digit (half))
Lou Berger056f3762013-04-10 12:30:04 -0700287 goto out;
288
paul718e3742002-12-13 20:15:29 +0000289 stream_putw (s, RD_TYPE_AS);
290 stream_putw (s, atoi (half));
291 stream_putl (s, atol (p + 1));
292 }
293 else
294 {
295 ret = inet_aton (half, &addr);
296 if (! ret)
Lou Berger056f3762013-04-10 12:30:04 -0700297 goto out;
298
paul718e3742002-12-13 20:15:29 +0000299 stream_putw (s, RD_TYPE_IP);
300 stream_put_in_addr (s, &addr);
301 stream_putw (s, atol (p + 1));
302 }
303 memcpy (prd->val, s->data, 8);
Lou Berger056f3762013-04-10 12:30:04 -0700304 lret = 1;
paul718e3742002-12-13 20:15:29 +0000305
Lou Berger056f3762013-04-10 12:30:04 -0700306out:
307 if (s)
308 stream_free (s);
309 if (half)
310 XFREE(MTYPE_TMP, half);
311 return lret;
paul718e3742002-12-13 20:15:29 +0000312}
313
314int
paulfd79ac92004-10-13 05:06:08 +0000315str2tag (const char *str, u_char *tag)
paul718e3742002-12-13 20:15:29 +0000316{
paulfd79ac92004-10-13 05:06:08 +0000317 unsigned long l;
318 char *endptr;
319 u_int32_t t;
paul718e3742002-12-13 20:15:29 +0000320
Ulrich Weber664711c2011-12-21 02:24:11 +0400321 if (*str == '-')
322 return 0;
paulfd79ac92004-10-13 05:06:08 +0000323
Ulrich Weber664711c2011-12-21 02:24:11 +0400324 errno = 0;
325 l = strtoul (str, &endptr, 10);
326
327 if (*endptr != '\0' || errno || l > UINT32_MAX)
paulfd79ac92004-10-13 05:06:08 +0000328 return 0;
paul718e3742002-12-13 20:15:29 +0000329
paulfd79ac92004-10-13 05:06:08 +0000330 t = (u_int32_t) l;
331
332 tag[0] = (u_char)(t >> 12);
333 tag[1] = (u_char)(t >> 4);
334 tag[2] = (u_char)(t << 4);
paul718e3742002-12-13 20:15:29 +0000335
336 return 1;
337}
338
339char *
340prefix_rd2str (struct prefix_rd *prd, char *buf, size_t size)
341{
342 u_char *pnt;
343 u_int16_t type;
344 struct rd_as rd_as;
345 struct rd_ip rd_ip;
346
347 if (size < RD_ADDRSTRLEN)
348 return NULL;
349
350 pnt = prd->val;
351
352 type = decode_rd_type (pnt);
353
354 if (type == RD_TYPE_AS)
355 {
356 decode_rd_as (pnt + 2, &rd_as);
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400357 snprintf (buf, size, "%u:%d", rd_as.as, rd_as.val);
paul718e3742002-12-13 20:15:29 +0000358 return buf;
359 }
Lou Bergera03bd162016-01-12 13:41:54 -0500360 else if (type == RD_TYPE_AS4)
361 {
362 decode_rd_as4 (pnt + 2, &rd_as);
363 snprintf (buf, size, "%u:%d", rd_as.as, rd_as.val);
364 return buf;
365 }
paul718e3742002-12-13 20:15:29 +0000366 else if (type == RD_TYPE_IP)
367 {
368 decode_rd_ip (pnt + 2, &rd_ip);
369 snprintf (buf, size, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
370 return buf;
371 }
paul718e3742002-12-13 20:15:29 +0000372 return NULL;
373}
374
375/* For testing purpose, static route of MPLS-VPN. */
376DEFUN (vpnv4_network,
377 vpnv4_network_cmd,
378 "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
379 "Specify a network to announce via BGP\n"
380 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
381 "Specify Route Distinguisher\n"
382 "VPN Route Distinguisher\n"
383 "BGP tag\n"
384 "tag value\n")
385{
Lou Bergera76d9ca2016-01-12 13:41:53 -0500386 return bgp_static_set_safi (SAFI_MPLS_VPN, vty, argv[0], argv[1], argv[2], NULL);
387}
388
389DEFUN (vpnv4_network_route_map,
390 vpnv4_network_route_map_cmd,
391 "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD route-map WORD",
392 "Specify a network to announce via BGP\n"
393 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
394 "Specify Route Distinguisher\n"
395 "VPN Route Distinguisher\n"
396 "BGP tag\n"
397 "tag value\n"
398 "route map\n"
399 "route map name\n")
400{
401 return bgp_static_set_safi (SAFI_MPLS_VPN, vty, argv[0], argv[1], argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +0000402}
403
404/* For testing purpose, static route of MPLS-VPN. */
405DEFUN (no_vpnv4_network,
406 no_vpnv4_network_cmd,
407 "no network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
408 NO_STR
409 "Specify a network to announce via BGP\n"
410 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
411 "Specify Route Distinguisher\n"
412 "VPN Route Distinguisher\n"
413 "BGP tag\n"
414 "tag value\n")
415{
Lou Bergera76d9ca2016-01-12 13:41:53 -0500416 return bgp_static_unset_safi (SAFI_MPLS_VPN, vty, argv[0], argv[1], argv[2]);
paul718e3742002-12-13 20:15:29 +0000417}
418
paul94f2b392005-06-28 12:44:16 +0000419static int
paul718e3742002-12-13 20:15:29 +0000420show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd)
421{
422 struct bgp *bgp;
423 struct bgp_table *table;
424 struct bgp_node *rn;
425 struct bgp_node *rm;
426 struct attr *attr;
427 int rd_header;
428 int header = 1;
429 char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
430
431 bgp = bgp_get_default ();
432 if (bgp == NULL)
433 {
434 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
435 return CMD_WARNING;
436 }
437
438 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn;
439 rn = bgp_route_next (rn))
440 {
441 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
442 continue;
443
444 if ((table = rn->info) != NULL)
445 {
446 rd_header = 1;
447
448 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
449 if ((attr = rm->info) != NULL)
450 {
451 if (header)
452 {
453 vty_out (vty, "BGP table version is 0, local router ID is %s%s",
454 inet_ntoa (bgp->router_id), VTY_NEWLINE);
455 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
456 VTY_NEWLINE);
457 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
458 VTY_NEWLINE, VTY_NEWLINE);
459 vty_out (vty, v4_header, VTY_NEWLINE);
460 header = 0;
461 }
462
463 if (rd_header)
464 {
465 u_int16_t type;
466 struct rd_as rd_as;
467 struct rd_ip rd_ip;
468 u_char *pnt;
469
470 pnt = rn->p.u.val;
471
472 /* Decode RD type. */
473 type = decode_rd_type (pnt);
474 /* Decode RD value. */
475 if (type == RD_TYPE_AS)
476 decode_rd_as (pnt + 2, &rd_as);
Lou Bergera03bd162016-01-12 13:41:54 -0500477 else if (type == RD_TYPE_AS4)
478 decode_rd_as4 (pnt + 2, &rd_as);
paul718e3742002-12-13 20:15:29 +0000479 else if (type == RD_TYPE_IP)
480 decode_rd_ip (pnt + 2, &rd_ip);
481
482 vty_out (vty, "Route Distinguisher: ");
483
484 if (type == RD_TYPE_AS)
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400485 vty_out (vty, "%u:%d", rd_as.as, rd_as.val);
Lou Bergera03bd162016-01-12 13:41:54 -0500486 else if (type == RD_TYPE_AS4)
487 vty_out (vty, "%u:%d", rd_as.as, rd_as.val);
paul718e3742002-12-13 20:15:29 +0000488 else if (type == RD_TYPE_IP)
489 vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
490
491 vty_out (vty, "%s", VTY_NEWLINE);
492 rd_header = 0;
493 }
494 route_vty_out_tmp (vty, &rm->p, attr, SAFI_MPLS_VPN);
495 }
496 }
497 }
498 return CMD_SUCCESS;
499}
500
501enum bgp_show_type
502{
503 bgp_show_type_normal,
504 bgp_show_type_regexp,
505 bgp_show_type_prefix_list,
506 bgp_show_type_filter_list,
507 bgp_show_type_neighbor,
508 bgp_show_type_cidr_only,
509 bgp_show_type_prefix_longer,
510 bgp_show_type_community_all,
511 bgp_show_type_community,
512 bgp_show_type_community_exact,
513 bgp_show_type_community_list,
514 bgp_show_type_community_list_exact
515};
516
paul94f2b392005-06-28 12:44:16 +0000517static int
Lou Berger35c36862016-01-12 13:42:06 -0500518bgp_show_mpls_vpn(
519 struct vty *vty,
520 afi_t afi,
521 struct prefix_rd *prd,
522 enum bgp_show_type type,
523 void *output_arg,
524 int tags)
paul718e3742002-12-13 20:15:29 +0000525{
526 struct bgp *bgp;
527 struct bgp_table *table;
528 struct bgp_node *rn;
529 struct bgp_node *rm;
530 struct bgp_info *ri;
531 int rd_header;
532 int header = 1;
533 char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
534 char v4_header_tag[] = " Network Next Hop In tag/Out tag%s";
535
Lou Bergerbf1ae6c2016-01-12 13:42:08 -0500536 unsigned long output_count = 0;
537 unsigned long total_count = 0;
538
paul718e3742002-12-13 20:15:29 +0000539 bgp = bgp_get_default ();
540 if (bgp == NULL)
541 {
542 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
543 return CMD_WARNING;
544 }
545
Lou Berger9da04bc2016-01-12 13:41:55 -0500546 if ((afi != AFI_IP) && (afi != AFI_IP6))
547 {
548 vty_out (vty, "Afi %d not supported%s", afi, VTY_NEWLINE);
549 return CMD_WARNING;
550 }
551
552 for (rn = bgp_table_top (bgp->rib[afi][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +0000553 {
554 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
555 continue;
556
557 if ((table = rn->info) != NULL)
558 {
559 rd_header = 1;
560
561 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
562 for (ri = rm->info; ri; ri = ri->next)
563 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -0500564 total_count++;
paul718e3742002-12-13 20:15:29 +0000565 if (type == bgp_show_type_neighbor)
566 {
567 union sockunion *su = output_arg;
568
569 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
570 continue;
571 }
572 if (header)
573 {
574 if (tags)
575 vty_out (vty, v4_header_tag, VTY_NEWLINE);
576 else
577 {
578 vty_out (vty, "BGP table version is 0, local router ID is %s%s",
579 inet_ntoa (bgp->router_id), VTY_NEWLINE);
580 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
581 VTY_NEWLINE);
582 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
583 VTY_NEWLINE, VTY_NEWLINE);
584 vty_out (vty, v4_header, VTY_NEWLINE);
585 }
586 header = 0;
587 }
588
589 if (rd_header)
590 {
591 u_int16_t type;
592 struct rd_as rd_as;
593 struct rd_ip rd_ip;
594 u_char *pnt;
595
596 pnt = rn->p.u.val;
597
598 /* Decode RD type. */
599 type = decode_rd_type (pnt);
600 /* Decode RD value. */
601 if (type == RD_TYPE_AS)
602 decode_rd_as (pnt + 2, &rd_as);
Lou Bergera03bd162016-01-12 13:41:54 -0500603 else if (type == RD_TYPE_AS4)
604 decode_rd_as4 (pnt + 2, &rd_as);
paul718e3742002-12-13 20:15:29 +0000605 else if (type == RD_TYPE_IP)
606 decode_rd_ip (pnt + 2, &rd_ip);
607
608 vty_out (vty, "Route Distinguisher: ");
609
610 if (type == RD_TYPE_AS)
Lou Bergera03bd162016-01-12 13:41:54 -0500611 vty_out (vty, "as2 %u:%d", rd_as.as, rd_as.val);
612 else if (type == RD_TYPE_AS4)
613 vty_out (vty, "as4 %u:%d", rd_as.as, rd_as.val);
paul718e3742002-12-13 20:15:29 +0000614 else if (type == RD_TYPE_IP)
Lou Bergera03bd162016-01-12 13:41:54 -0500615 vty_out (vty, "ip %s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
paul718e3742002-12-13 20:15:29 +0000616
617 vty_out (vty, "%s", VTY_NEWLINE);
618 rd_header = 0;
619 }
620 if (tags)
621 route_vty_out_tag (vty, &rm->p, ri, 0, SAFI_MPLS_VPN);
622 else
623 route_vty_out (vty, &rm->p, ri, 0, SAFI_MPLS_VPN);
Lou Bergerbf1ae6c2016-01-12 13:42:08 -0500624 output_count++;
paul718e3742002-12-13 20:15:29 +0000625 }
626 }
627 }
Lou Bergerbf1ae6c2016-01-12 13:42:08 -0500628
629 if (output_count == 0)
630 {
631 vty_out (vty, "No prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
632 }
633 else
634 vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
635 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
636
paul718e3742002-12-13 20:15:29 +0000637 return CMD_SUCCESS;
638}
639
Lou Berger35c36862016-01-12 13:42:06 -0500640DEFUN (show_bgp_ipv4_vpn,
641 show_bgp_ipv4_vpn_cmd,
642 "show bgp ipv4 vpn",
paul718e3742002-12-13 20:15:29 +0000643 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000644 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -0500645 "Address Family\n"
646 "Display VPN NLRI specific information\n")
paul718e3742002-12-13 20:15:29 +0000647{
Lou Berger35c36862016-01-12 13:42:06 -0500648 return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 0);
paul718e3742002-12-13 20:15:29 +0000649}
650
Lou Berger35c36862016-01-12 13:42:06 -0500651DEFUN (show_bgp_ipv6_vpn,
652 show_bgp_ipv6_vpn_cmd,
653 "show bgp ipv6 vpn",
paul718e3742002-12-13 20:15:29 +0000654 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000655 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -0500656 "Address Family\n"
657 "Display VPN NLRI specific information\n")
658{
659 return bgp_show_mpls_vpn (vty, AFI_IP6, NULL, bgp_show_type_normal, NULL, 0);
660}
Lou Berger35c36862016-01-12 13:42:06 -0500661
662DEFUN (show_bgp_ipv4_vpn_rd,
663 show_bgp_ipv4_vpn_rd_cmd,
664 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn",
665 SHOW_STR
666 BGP_STR
667 "Address Family\n"
668 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +0000669 "Display information for a route distinguisher\n"
670 "VPN Route Distinguisher\n")
671{
672 int ret;
673 struct prefix_rd prd;
674
675 ret = str2prefix_rd (argv[0], &prd);
676 if (! ret)
677 {
678 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
679 return CMD_WARNING;
680 }
Lou Berger35c36862016-01-12 13:42:06 -0500681 return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 0);
paul718e3742002-12-13 20:15:29 +0000682}
683
Lou Berger35c36862016-01-12 13:42:06 -0500684DEFUN (show_bgp_ipv6_vpn_rd,
685 show_bgp_ipv6_vpn_rd_cmd,
686 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn",
paul718e3742002-12-13 20:15:29 +0000687 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000688 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -0500689 "Address Family\n"
690 "Display VPN NLRI specific information\n"
691 "Display information for a route distinguisher\n"
692 "VPN Route Distinguisher\n")
693{
694 int ret;
695 struct prefix_rd prd;
696
697 ret = str2prefix_rd (argv[0], &prd);
698 if (! ret)
699 {
700 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
701 return CMD_WARNING;
702 }
703 return bgp_show_mpls_vpn (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 0);
704}
705
706
707DEFUN (show_bgp_ipv4_vpn_tags,
708 show_bgp_ipv4_vpn_tags_cmd,
709 "show bgp ipv4 vpn tags",
710 SHOW_STR
711 BGP_STR
712 "Address Family\n"
713 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +0000714 "Display BGP tags for prefixes\n")
715{
Lou Berger35c36862016-01-12 13:42:06 -0500716 return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 1);
717}
718DEFUN (show_bgp_ipv6_vpn_tags,
719 show_bgp_ipv6_vpn_tags_cmd,
720 "show bgp ipv6 vpn tags",
721 SHOW_STR
722 BGP_STR
723 "Address Family\n"
724 "Display VPN NLRI specific information\n"
725 "Display BGP tags for prefixes\n")
726{
727 return bgp_show_mpls_vpn (vty, AFI_IP6, NULL, bgp_show_type_normal, NULL, 1);
paul718e3742002-12-13 20:15:29 +0000728}
729
Lou Berger35c36862016-01-12 13:42:06 -0500730DEFUN (show_bgp_ipv4_vpn_rd_tags,
731 show_bgp_ipv4_vpn_rd_tags_cmd,
732 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn tags",
paul718e3742002-12-13 20:15:29 +0000733 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000734 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -0500735 "Address Family\n"
736 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +0000737 "Display information for a route distinguisher\n"
738 "VPN Route Distinguisher\n"
739 "Display BGP tags for prefixes\n")
740{
741 int ret;
742 struct prefix_rd prd;
743
744 ret = str2prefix_rd (argv[0], &prd);
745 if (! ret)
746 {
747 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
748 return CMD_WARNING;
749 }
Lou Berger35c36862016-01-12 13:42:06 -0500750 return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 1);
751}
752DEFUN (show_bgp_ipv6_vpn_rd_tags,
753 show_bgp_ipv6_vpn_rd_tags_cmd,
754 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn tags",
755 SHOW_STR
756 BGP_STR
757 "Address Family\n"
758 "Display VPN NLRI specific information\n"
759 "Display information for a route distinguisher\n"
760 "VPN Route Distinguisher\n"
761 "Display BGP tags for prefixes\n")
762{
763 int ret;
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 return bgp_show_mpls_vpn (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 1);
paul718e3742002-12-13 20:15:29 +0000773}
774
Lou Berger35c36862016-01-12 13:42:06 -0500775DEFUN (show_bgp_ipv4_vpn_neighbor_routes,
776 show_bgp_ipv4_vpn_neighbor_routes_cmd,
777 "show bgp ipv4 vpn neighbors (A.B.C.D|X:X::X:X) routes",
paul718e3742002-12-13 20:15:29 +0000778 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000779 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -0500780 "Address Family\n"
781 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +0000782 "Detailed information on TCP and BGP neighbor connections\n"
783 "Neighbor to display information about\n"
Lou Berger35c36862016-01-12 13:42:06 -0500784 "Neighbor to display information about\n"
paul718e3742002-12-13 20:15:29 +0000785 "Display routes learned from neighbor\n")
786{
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200787 union sockunion su;
paul718e3742002-12-13 20:15:29 +0000788 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200789 int ret;
790
791 ret = str2sockunion (argv[0], &su);
792 if (ret < 0)
paul718e3742002-12-13 20:15:29 +0000793 {
794 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200795 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +0000796 }
797
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200798 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +0000799 if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
800 {
801 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
802 return CMD_WARNING;
803 }
804
Lou Berger35c36862016-01-12 13:42:06 -0500805 return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_neighbor, &su, 0);
paul718e3742002-12-13 20:15:29 +0000806}
807
Lou Berger35c36862016-01-12 13:42:06 -0500808DEFUN (show_bgp_ipv6_vpn_neighbor_routes,
809 show_bgp_ipv6_vpn_neighbor_routes_cmd,
810 "show bgp ipv6 vpn neighbors (A.B.C.D|X:X::X:X) routes",
paul718e3742002-12-13 20:15:29 +0000811 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000812 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -0500813 "Address Family\n"
814 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +0000815 "Detailed information on TCP and BGP neighbor connections\n"
816 "Neighbor to display information about\n"
Lou Berger35c36862016-01-12 13:42:06 -0500817 "Neighbor to display information about\n"
paul718e3742002-12-13 20:15:29 +0000818 "Display routes learned from neighbor\n")
819{
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200820 union sockunion su;
paul718e3742002-12-13 20:15:29 +0000821 struct peer *peer;
paul718e3742002-12-13 20:15:29 +0000822
Lou Berger35c36862016-01-12 13:42:06 -0500823 int ret;
paul718e3742002-12-13 20:15:29 +0000824
Lou Berger35c36862016-01-12 13:42:06 -0500825 ret = str2sockunion (argv[0], &su);
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200826 if (ret < 0)
paul718e3742002-12-13 20:15:29 +0000827 {
828 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200829 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +0000830 }
831
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200832 peer = peer_lookup (NULL, &su);
Lou Berger35c36862016-01-12 13:42:06 -0500833 if (! peer || ! peer->afc[AFI_IP6][SAFI_MPLS_VPN])
paul718e3742002-12-13 20:15:29 +0000834 {
835 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
836 return CMD_WARNING;
837 }
838
Lou Berger35c36862016-01-12 13:42:06 -0500839 return bgp_show_mpls_vpn (vty, AFI_IP6, NULL, bgp_show_type_neighbor, &su, 0);
paul718e3742002-12-13 20:15:29 +0000840}
841
Lou Berger35c36862016-01-12 13:42:06 -0500842DEFUN (show_bgp_ipv4_vpn_neighbor_advertised_routes,
843 show_bgp_ipv4_vpn_neighbor_advertised_routes_cmd,
844 "show bgp ipv4 vpn neighbors (A.B.C.D|X:X::X:X) advertised-routes",
paul718e3742002-12-13 20:15:29 +0000845 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000846 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -0500847 "Address Family\n"
848 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +0000849 "Detailed information on TCP and BGP neighbor connections\n"
850 "Neighbor to display information about\n"
851 "Display the routes advertised to a BGP neighbor\n")
852{
853 int ret;
854 struct peer *peer;
855 union sockunion su;
856
857 ret = str2sockunion (argv[0], &su);
858 if (ret < 0)
859 {
860 vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
861 return CMD_WARNING;
862 }
863 peer = peer_lookup (NULL, &su);
864 if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
865 {
866 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
867 return CMD_WARNING;
868 }
869
870 return show_adj_route_vpn (vty, peer, NULL);
871}
Lou Berger35c36862016-01-12 13:42:06 -0500872DEFUN (show_bgp_ipv6_vpn_neighbor_advertised_routes,
873 show_bgp_ipv6_vpn_neighbor_advertised_routes_cmd,
874 "show bgp ipv6 vpn neighbors (A.B.C.D|X:X::X:X) advertised-routes",
875 SHOW_STR
876 BGP_STR
877 "Address Family\n"
878 "Display VPN NLRI specific information\n"
879 "Detailed information on TCP and BGP neighbor connections\n"
880 "Neighbor to display information about\n"
881 "Display the routes advertised to a BGP neighbor\n")
882{
883 int ret;
884 struct peer *peer;
885 union sockunion su;
886
887 ret = str2sockunion (argv[0], &su);
888 if (ret < 0)
889 {
890 vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
891 return CMD_WARNING;
892 }
893 peer = peer_lookup (NULL, &su);
894 if (! peer || ! peer->afc[AFI_IP6][SAFI_MPLS_VPN])
895 {
896 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
897 return CMD_WARNING;
898 }
899
900 return show_adj_route_vpn (vty, peer, NULL);
901}
paul718e3742002-12-13 20:15:29 +0000902
903DEFUN (show_ip_bgp_vpnv4_rd_neighbor_advertised_routes,
Lou Berger35c36862016-01-12 13:42:06 -0500904 show_bgp_ipv4_vpn_rd_neighbor_advertised_routes_cmd,
905 "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 +0000906 SHOW_STR
paul718e3742002-12-13 20:15:29 +0000907 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -0500908 "Address Family\n"
909 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +0000910 "Display information for a route distinguisher\n"
911 "VPN Route Distinguisher\n"
912 "Detailed information on TCP and BGP neighbor connections\n"
913 "Neighbor to display information about\n"
Lou Berger35c36862016-01-12 13:42:06 -0500914 "Neighbor to display information about\n"
paul718e3742002-12-13 20:15:29 +0000915 "Display the routes advertised to a BGP neighbor\n")
916{
917 int ret;
918 struct peer *peer;
919 struct prefix_rd prd;
920 union sockunion su;
paul718e3742002-12-13 20:15:29 +0000921 ret = str2sockunion (argv[1], &su);
922 if (ret < 0)
923 {
Lou Berger35c36862016-01-12 13:42:06 -0500924 vty_out (vty, "%% Malformed address: %s%s", argv[1], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000925 return CMD_WARNING;
926 }
927 peer = peer_lookup (NULL, &su);
928 if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
929 {
930 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
931 return CMD_WARNING;
932 }
933
934 ret = str2prefix_rd (argv[0], &prd);
935 if (! ret)
936 {
937 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
938 return CMD_WARNING;
939 }
940
941 return show_adj_route_vpn (vty, peer, &prd);
942}
Lou Berger35c36862016-01-12 13:42:06 -0500943DEFUN (show_ip_bgp_vpnv6_rd_neighbor_advertised_routes,
944 show_bgp_ipv6_vpn_rd_neighbor_advertised_routes_cmd,
945 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) advertised-routes",
946 SHOW_STR
947 BGP_STR
948 "Address Family\n"
949 "Display VPN NLRI specific information\n"
950 "Display information for a route distinguisher\n"
951 "VPN Route Distinguisher\n"
952 "Detailed information on TCP and BGP neighbor connections\n"
953 "Neighbor to display information about\n"
954 "Neighbor to display information about\n"
955 "Display the routes advertised to a BGP neighbor\n")
956{
957 int ret;
958 struct peer *peer;
959 struct prefix_rd prd;
960 union sockunion su;
961 ret = str2sockunion (argv[1], &su);
962 if (ret < 0)
963 {
964 vty_out (vty, "%% Malformed address: %s%s", argv[1], VTY_NEWLINE);
965 return CMD_WARNING;
966 }
967 peer = peer_lookup (NULL, &su);
968 if (! peer || ! peer->afc[AFI_IP6][SAFI_MPLS_VPN])
969 {
970 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
971 return CMD_WARNING;
972 }
973
974 ret = str2prefix_rd (argv[0], &prd);
975 if (! ret)
976 {
977 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
978 return CMD_WARNING;
979 }
980
981 return show_adj_route_vpn (vty, peer, &prd);
982}
983
984DEFUN (show_bgp_ipv4_vpn_rd_neighbor_routes,
985 show_bgp_ipv4_vpn_rd_neighbor_routes_cmd,
986 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) routes",
987 SHOW_STR
988 BGP_STR
989 "Address Family\n"
990 "Address Family modifier\n"
991 "Display information for a route distinguisher\n"
992 "VPN Route Distinguisher\n"
993 "Detailed information on TCP and BGP neighbor connections\n"
994 "Neighbor to display information about\n"
995 "Display routes learned from neighbor\n")
996{
997 int ret;
998 union sockunion *su;
999 struct peer *peer;
1000 struct prefix_rd prd;
1001
1002 ret = str2prefix_rd (argv[0], &prd);
1003 if (! ret)
1004 {
1005 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
1006 return CMD_WARNING;
1007 }
1008
1009 su = sockunion_str2su (argv[1]);
1010 if (su == NULL)
1011 {
1012 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
1013 return CMD_WARNING;
1014 }
1015
1016 peer = peer_lookup (NULL, su);
1017 if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
1018 {
1019 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
1020 return CMD_WARNING;
1021 }
1022
1023 return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_neighbor, su, 0);
1024}
1025DEFUN (show_bgp_ipv6_vpn_rd_neighbor_routes,
1026 show_bgp_ipv6_vpn_rd_neighbor_routes_cmd,
1027 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) routes",
1028 SHOW_STR
1029 BGP_STR
1030 "Address Family\n"
1031 "Address Family modifier\n"
1032 "Display information for a route distinguisher\n"
1033 "VPN Route Distinguisher\n"
1034 "Detailed information on TCP and BGP neighbor connections\n"
1035 "Neighbor to display information about\n"
1036 "Display routes learned from neighbor\n")
1037{
1038 int ret;
1039 union sockunion *su;
1040 struct peer *peer;
1041 struct prefix_rd prd;
1042
1043 ret = str2prefix_rd (argv[0], &prd);
1044 if (! ret)
1045 {
1046 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
1047 return CMD_WARNING;
1048 }
1049
1050 su = sockunion_str2su (argv[1]);
1051 if (su == NULL)
1052 {
1053 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
1054 return CMD_WARNING;
1055 }
1056
1057 peer = peer_lookup (NULL, su);
1058 if (! peer || ! peer->afc[AFI_IP6][SAFI_MPLS_VPN])
1059 {
1060 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
1061 return CMD_WARNING;
1062 }
1063
1064 return bgp_show_mpls_vpn (vty, AFI_IP6, &prd, bgp_show_type_neighbor, su, 0);
1065}
paul718e3742002-12-13 20:15:29 +00001066
1067void
paul94f2b392005-06-28 12:44:16 +00001068bgp_mplsvpn_init (void)
paul718e3742002-12-13 20:15:29 +00001069{
1070 install_element (BGP_VPNV4_NODE, &vpnv4_network_cmd);
Lou Bergera76d9ca2016-01-12 13:41:53 -05001071 install_element (BGP_VPNV4_NODE, &vpnv4_network_route_map_cmd);
paul718e3742002-12-13 20:15:29 +00001072 install_element (BGP_VPNV4_NODE, &no_vpnv4_network_cmd);
1073
Lou Berger35c36862016-01-12 13:42:06 -05001074 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_cmd);
1075 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_cmd);
1076 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_tags_cmd);
1077 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_tags_cmd);
1078 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_neighbor_routes_cmd);
1079 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_neighbor_advertised_routes_cmd);
1080 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_neighbor_advertised_routes_cmd);
1081 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +00001082
Lou Berger35c36862016-01-12 13:42:06 -05001083 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_cmd);
1084 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_cmd);
1085 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_tags_cmd);
1086 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_tags_cmd);
1087 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_neighbor_routes_cmd);
1088 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_neighbor_advertised_routes_cmd);
1089 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_neighbor_advertised_routes_cmd);
1090 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +00001091
Lou Berger35c36862016-01-12 13:42:06 -05001092 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_cmd);
1093 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_cmd);
1094 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_tags_cmd);
1095 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_tags_cmd);
1096 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_neighbor_routes_cmd);
1097 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_neighbor_advertised_routes_cmd);
1098 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_neighbor_advertised_routes_cmd);
1099 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_neighbor_routes_cmd);
1100
Lou Berger35c36862016-01-12 13:42:06 -05001101 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_cmd);
1102 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_cmd);
1103 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_tags_cmd);
1104 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_tags_cmd);
1105 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_neighbor_routes_cmd);
1106 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_neighbor_advertised_routes_cmd);
1107 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_neighbor_advertised_routes_cmd);
1108 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +00001109}