Tomato 1.28
[tomato.git] / release / src / router / zebra / bgpd / bgp_mplsvpn.c
blobf444cdf084ea5f2d980623d1657cac793b459574
1 /* MPLS-VPN
2 * Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
22 #include <zebra.h>
24 #include "command.h"
25 #include "prefix.h"
26 #include "table.h"
27 #include "log.h"
28 #include "memory.h"
29 #include "stream.h"
31 #include "bgpd/bgpd.h"
32 #include "bgpd/bgp_route.h"
33 #include "bgpd/bgp_attr.h"
34 #include "bgpd/bgp_mplsvpn.h"
36 int peer_activate (struct vty *, char *, int, int);
37 int peer_deactivate (struct vty *, char *, int, int);
38 int route_vty_out (struct vty *, struct prefix *, struct bgp_info *, int, safi_t);
39 int route_vty_out_tag (struct vty *, struct prefix *, struct bgp_info *, int, safi_t);
40 void route_vty_out_tmp (struct vty *, struct prefix *, struct attr *, safi_t);
42 u_int16_t
43 decode_rd_type (u_char *pnt)
45 u_int16_t v;
47 v = ((u_int16_t) *pnt++ << 8);
48 v |= (u_int16_t) *pnt;
49 return v;
52 u_int32_t
53 decode_label (u_char *pnt)
55 u_int32_t l;
57 l = ((u_int32_t) *pnt++ << 12);
58 l |= (u_int32_t) *pnt++ << 4;
59 l |= (u_int32_t) ((*pnt & 0xf0) >> 4);
60 return l;
63 void
64 decode_rd_as (u_char *pnt, struct rd_as *rd_as)
66 rd_as->as = (u_int16_t) *pnt++ << 8;
67 rd_as->as |= (u_int16_t) *pnt++;
69 rd_as->val = ((u_int32_t) *pnt++ << 24);
70 rd_as->val |= ((u_int32_t) *pnt++ << 16);
71 rd_as->val |= ((u_int32_t) *pnt++ << 8);
72 rd_as->val |= (u_int32_t) *pnt;
75 void
76 decode_rd_ip (u_char *pnt, struct rd_ip *rd_ip)
78 memcpy (&rd_ip->ip, pnt, 4);
79 pnt += 4;
81 rd_ip->val = ((u_int16_t) *pnt++ << 8);
82 rd_ip->val |= (u_int16_t) *pnt;
85 int bgp_update (struct peer *, struct prefix *, struct attr *,
86 afi_t, safi_t, int, int, struct prefix_rd *, u_char *);
88 int bgp_withdraw (struct peer *, struct prefix *, struct attr *,
89 int, int, int, int, struct prefix_rd *, u_char *);
90 int
91 nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
92 struct bgp_nlri *packet)
94 u_char *pnt;
95 u_char *lim;
96 struct prefix p;
97 int psize;
98 int prefixlen;
99 u_int32_t label;
100 u_int16_t type;
101 struct rd_as rd_as;
102 struct rd_ip rd_ip;
103 struct prefix_rd prd;
104 u_char *tagpnt;
106 /* Check peer status. */
107 if (peer->status != Established)
108 return 0;
110 /* Make prefix_rd */
111 prd.family = AF_UNSPEC;
112 prd.prefixlen = 64;
114 pnt = packet->nlri;
115 lim = pnt + packet->length;
117 for (; pnt < lim; pnt += psize)
119 /* Clear prefix structure. */
120 memset (&p, 0, sizeof (struct prefix));
122 /* Fetch prefix length. */
123 prefixlen = *pnt++;
124 p.family = AF_INET;
125 psize = PSIZE (prefixlen);
127 if (prefixlen < 88)
129 zlog_err ("prefix length is less than 88: %d", prefixlen);
130 return -1;
133 label = decode_label (pnt);
135 /* Copyr label to prefix. */
136 tagpnt = pnt;;
138 /* Copy routing distinguisher to rd. */
139 memcpy (&prd.val, pnt + 3, 8);
141 /* Decode RD type. */
142 type = decode_rd_type (pnt + 3);
144 /* Decode RD value. */
145 if (type == RD_TYPE_AS)
146 decode_rd_as (pnt + 5, &rd_as);
147 else if (type == RD_TYPE_IP)
148 decode_rd_ip (pnt + 5, &rd_ip);
149 else
151 zlog_err ("Invalid RD type %d", type);
152 return -1;
155 p.prefixlen = prefixlen - 88;
156 memcpy (&p.u.prefix, pnt + 11, psize - 11);
157 #if 0
158 if (type == RD_TYPE_AS)
159 zlog_info ("prefix %ld:%ld:%ld:%s/%d", label, rd_as.as, rd_as.val,
160 inet_ntoa (p.u.prefix4), p.prefixlen);
161 else if (type == RD_TYPE_IP)
162 zlog_info ("prefix %ld:%s:%ld:%s/%d", label, inet_ntoa (rd_ip.ip),
163 rd_ip.val, inet_ntoa (p.u.prefix4), p.prefixlen);
164 #endif /* 0 */
166 if (pnt + psize > lim)
167 return -1;
169 if (attr)
170 bgp_update (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
171 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
172 else
173 bgp_withdraw (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
174 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
177 /* Packet length consistency check. */
178 if (pnt != lim)
179 return -1;
181 return 0;
184 DEFUN (address_family_vpnv4,
185 address_family_vpnv4_cmd,
186 "address-family vpnv4",
187 "Enter Address Family command mode\n"
188 "Address family\n")
190 vty->node = BGP_VPNV4_NODE;
191 return CMD_SUCCESS;
194 ALIAS (address_family_vpnv4,
195 address_family_vpnv4_unicast_cmd,
196 "address-family vpnv4 unicast",
197 "Enter Address Family command mode\n"
198 "Address family\n"
199 "Address Family Modifier\n")
201 DEFUN (vpnv4_activate,
202 vpnv4_activate_cmd,
203 "neighbor A.B.C.D activate",
204 NEIGHBOR_STR
205 "Neighbor address\n"
206 "Enable the Address Family for this Neighbor\n")
208 return peer_activate (vty, argv[0], AFI_IP, SAFI_MPLS_VPN);
211 DEFUN (no_vpnv4_activate,
212 no_vpnv4_activate_cmd,
213 "no neighbor A.B.C.D activate",
214 NO_STR
215 NEIGHBOR_STR
216 "Neighbor address\n"
217 "Enable the Address Family for this Neighbor\n")
219 return peer_deactivate (vty, argv[0], AFI_IP, SAFI_MPLS_VPN);
222 extern struct peer *peer_self;
225 str2prefix_rd (u_char *str, struct prefix_rd *prd)
227 int ret;
228 u_char *p;
229 u_char *p2;
230 struct stream *s;
231 u_char *half;
232 struct in_addr addr;
234 s = stream_new (8);
236 prd->family = AF_UNSPEC;
237 prd->prefixlen = 64;
239 p = strchr (str, ':');
240 if (! p)
241 return 0;
243 if (! all_digit (p + 1))
244 return 0;
246 half = XMALLOC (MTYPE_TMP, (p - str) + 1);
247 memcpy (half, str, (p - str));
248 half[p - str] = '\0';
250 p2 = strchr (str, '.');
252 if (! p2)
254 if (! all_digit (half))
256 XFREE (MTYPE_TMP, half);
257 return 0;
259 stream_putw (s, RD_TYPE_AS);
260 stream_putw (s, atoi (half));
261 stream_putl (s, atol (p + 1));
263 else
265 ret = inet_aton (half, &addr);
266 if (! ret)
268 XFREE (MTYPE_TMP, half);
269 return 0;
271 stream_putw (s, RD_TYPE_IP);
272 stream_put_in_addr (s, &addr);
273 stream_putw (s, atol (p + 1));
275 memcpy (prd->val, s->data, 8);
277 return 1;
281 str2tag (u_char *str, u_char *tag)
283 u_int32_t l;
285 l = atol (str);
287 tag[0] = (u_char)(l >> 12);
288 tag[1] = (u_char)(l >> 4);
289 tag[2] = (u_char)(l << 4);
291 return 1;
294 char *
295 prefix_rd2str (struct prefix_rd *prd, char *buf, size_t size)
297 u_char *pnt;
298 u_int16_t type;
299 struct rd_as rd_as;
300 struct rd_ip rd_ip;
302 if (size < RD_ADDRSTRLEN)
303 return NULL;
305 pnt = prd->val;
307 type = decode_rd_type (pnt);
309 if (type == RD_TYPE_AS)
311 decode_rd_as (pnt + 2, &rd_as);
312 snprintf (buf, size, "%d:%d", rd_as.as, rd_as.val);
313 return buf;
315 else if (type == RD_TYPE_IP)
317 decode_rd_ip (pnt + 2, &rd_ip);
318 snprintf (buf, size, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
319 return buf;
322 return NULL;
325 /* For testing purpose, static route of MPLS-VPN. */
326 DEFUN (vpnv4_network,
327 vpnv4_network_cmd,
328 "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
329 "Specify a network to announce via BGP\n"
330 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
331 "Specify Route Distinguisher\n"
332 "VPN Route Distinguisher\n"
333 "BGP tag\n"
334 "tag value\n")
336 return bgp_static_set_vpnv4 (vty, argv[0], argv[1], argv[2]);
339 /* For testing purpose, static route of MPLS-VPN. */
340 DEFUN (no_vpnv4_network,
341 no_vpnv4_network_cmd,
342 "no network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
343 NO_STR
344 "Specify a network to announce via BGP\n"
345 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
346 "Specify Route Distinguisher\n"
347 "VPN Route Distinguisher\n"
348 "BGP tag\n"
349 "tag value\n")
351 return bgp_static_unset_vpnv4 (vty, argv[0], argv[1], argv[2]);
355 show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd)
357 struct bgp *bgp;
358 struct route_table *table;
359 struct route_node *rn;
360 struct route_node *rm;
361 struct attr *attr;
362 int rd_header;
363 int header = 1;
364 char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
366 bgp = bgp_get_default ();
367 if (bgp == NULL)
369 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
370 return CMD_WARNING;
373 for (rn = route_top (peer->adj_out[AFI_IP][SAFI_MPLS_VPN]); rn; rn = route_next (rn))
375 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
376 continue;
378 if ((table = rn->info) != NULL)
380 rd_header = 1;
382 for (rm = route_top (table); rm; rm = route_next (rm))
383 if ((attr = rm->info) != NULL)
385 if (header)
387 vty_out (vty, "BGP table version is 0, local router ID is %s%s",
388 inet_ntoa (bgp->id), VTY_NEWLINE);
389 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
390 VTY_NEWLINE);
391 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
392 VTY_NEWLINE, VTY_NEWLINE);
393 vty_out (vty, v4_header, VTY_NEWLINE);
394 header = 0;
397 if (rd_header)
399 u_int16_t type;
400 struct rd_as rd_as;
401 struct rd_ip rd_ip;
402 u_char *pnt;
404 pnt = rn->p.u.val;
406 /* Decode RD type. */
407 type = decode_rd_type (pnt);
408 /* Decode RD value. */
409 if (type == RD_TYPE_AS)
410 decode_rd_as (pnt + 2, &rd_as);
411 else if (type == RD_TYPE_IP)
412 decode_rd_ip (pnt + 2, &rd_ip);
414 vty_out (vty, "Route Distinguisher: ");
416 if (type == RD_TYPE_AS)
417 vty_out (vty, "%d:%d", rd_as.as, rd_as.val);
418 else if (type == RD_TYPE_IP)
419 vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
421 vty_out (vty, "%s", VTY_NEWLINE);
422 rd_header = 0;
424 route_vty_out_tmp (vty, &rm->p, attr, SAFI_MPLS_VPN);
428 return CMD_SUCCESS;
431 enum bgp_show_type
433 bgp_show_type_normal,
434 bgp_show_type_regexp,
435 bgp_show_type_prefix_list,
436 bgp_show_type_filter_list,
437 bgp_show_type_neighbor,
438 bgp_show_type_cidr_only,
439 bgp_show_type_prefix_longer,
440 bgp_show_type_community_all,
441 bgp_show_type_community,
442 bgp_show_type_community_exact,
443 bgp_show_type_community_list,
444 bgp_show_type_community_list_exact
448 bgp_show_mpls_vpn (struct vty *vty, struct prefix_rd *prd, enum bgp_show_type type,
449 void *output_arg, int tags)
451 struct bgp *bgp;
452 struct route_table *table;
453 struct route_node *rn;
454 struct route_node *rm;
455 struct bgp_info *ri;
456 int rd_header;
457 int header = 1;
458 char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
459 char v4_header_tag[] = " Network Next Hop In tag/Out tag%s";
461 bgp = bgp_get_default ();
462 if (bgp == NULL)
464 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
465 return CMD_WARNING;
468 for (rn = route_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = route_next (rn))
470 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
471 continue;
473 if ((table = rn->info) != NULL)
475 rd_header = 1;
477 for (rm = route_top (table); rm; rm = route_next (rm))
478 for (ri = rm->info; ri; ri = ri->next)
480 if (type == bgp_show_type_neighbor)
482 union sockunion *su = output_arg;
484 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
485 continue;
487 if (header)
489 if (tags)
490 vty_out (vty, v4_header_tag, VTY_NEWLINE);
491 else
493 vty_out (vty, "BGP table version is 0, local router ID is %s%s",
494 inet_ntoa (bgp->id), VTY_NEWLINE);
495 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
496 VTY_NEWLINE);
497 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
498 VTY_NEWLINE, VTY_NEWLINE);
499 vty_out (vty, v4_header, VTY_NEWLINE);
501 header = 0;
504 if (rd_header)
506 u_int16_t type;
507 struct rd_as rd_as;
508 struct rd_ip rd_ip;
509 u_char *pnt;
511 pnt = rn->p.u.val;
513 /* Decode RD type. */
514 type = decode_rd_type (pnt);
515 /* Decode RD value. */
516 if (type == RD_TYPE_AS)
517 decode_rd_as (pnt + 2, &rd_as);
518 else if (type == RD_TYPE_IP)
519 decode_rd_ip (pnt + 2, &rd_ip);
521 vty_out (vty, "Route Distinguisher: ");
523 if (type == RD_TYPE_AS)
524 vty_out (vty, "%d:%d", rd_as.as, rd_as.val);
525 else if (type == RD_TYPE_IP)
526 vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
528 vty_out (vty, "%s", VTY_NEWLINE);
529 rd_header = 0;
531 if (tags)
532 route_vty_out_tag (vty, &rm->p, ri, 0, SAFI_MPLS_VPN);
533 else
534 route_vty_out (vty, &rm->p, ri, 0, SAFI_MPLS_VPN);
538 return CMD_SUCCESS;
542 bgp_show_mpls_vpn_route (struct vty *vty, char *ip_str, struct prefix_rd *prd,
543 int prefix_check)
545 int ret;
546 struct bgp *bgp;
547 struct route_table *table;
548 struct route_node *rn;
549 struct route_node *rm;
550 struct bgp_info *ri;
551 int rd_header;
552 struct prefix match;
553 int display = 0;
554 char buf[INET6_ADDRSTRLEN];
556 /* Check IP address argument. */
557 ret = str2prefix (ip_str, &match);
558 if (! ret)
560 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
561 return CMD_WARNING;
564 match.family = AF_INET;
565 /* match.prefixlen = IPV4_MAX_BITLEN; */
567 bgp = bgp_get_default ();
568 if (bgp == NULL)
570 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
571 return CMD_WARNING;
574 for (rn = route_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn;
575 rn = route_next (rn))
577 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
578 continue;
580 if ((table = rn->info) != NULL)
582 rd_header = 1;
584 if ((rm = route_node_match (table, &match)) != NULL)
586 if (prefix_check && rm->p.prefixlen != match.prefixlen)
587 continue;
589 for (ri = rm->info; ri; ri = ri->next)
591 if (rd_header)
593 u_int16_t type;
594 struct rd_as rd_as;
595 struct rd_ip rd_ip;
596 u_char *pnt;
598 pnt = rn->p.u.val;
600 /* Decode RD type. */
601 type = decode_rd_type (pnt);
602 /* Decode RD value. */
603 if (type == RD_TYPE_AS)
604 decode_rd_as (pnt + 2, &rd_as);
605 else if (type == RD_TYPE_IP)
606 decode_rd_ip (pnt + 2, &rd_ip);
608 vty_out (vty, "BGP routing table entry for ");
610 if (type == RD_TYPE_AS)
611 vty_out (vty, "%d:%d", rd_as.as, rd_as.val);
612 else if (type == RD_TYPE_IP)
613 vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
615 vty_out (vty, ":%s/%d", inet_ntop (rm->p.family, &rm->p.u.prefix, buf, INET6_ADDRSTRLEN),
616 rm->p.prefixlen);
618 vty_out (vty, "%s", VTY_NEWLINE);
619 rd_header = 0;
621 display++;
622 route_vty_out_detail (vty, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
627 if (! display)
629 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
630 return CMD_WARNING;
633 return CMD_SUCCESS;
636 DEFUN (show_ip_bgp_vpnv4_all,
637 show_ip_bgp_vpnv4_all_cmd,
638 "show ip bgp vpnv4 all",
639 SHOW_STR
640 IP_STR
641 BGP_STR
642 "Display VPNv4 NLRI specific information\n"
643 "Display information about all VPNv4 NLRIs\n")
645 return bgp_show_mpls_vpn (vty, NULL, bgp_show_type_normal, NULL, 0);
648 DEFUN (show_ip_bgp_vpnv4_rd,
649 show_ip_bgp_vpnv4_rd_cmd,
650 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn",
651 SHOW_STR
652 IP_STR
653 BGP_STR
654 "Display VPNv4 NLRI specific information\n"
655 "Display information for a route distinguisher\n"
656 "VPN Route Distinguisher\n")
658 int ret;
659 struct prefix_rd prd;
661 ret = str2prefix_rd (argv[0], &prd);
662 if (! ret)
664 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
665 return CMD_WARNING;
667 return bgp_show_mpls_vpn (vty, &prd, bgp_show_type_normal, NULL, 0);
670 DEFUN (show_ip_bgp_vpnv4_all_tags,
671 show_ip_bgp_vpnv4_all_tags_cmd,
672 "show ip bgp vpnv4 all tags",
673 SHOW_STR
674 IP_STR
675 BGP_STR
676 "Display VPNv4 NLRI specific information\n"
677 "Display information about all VPNv4 NLRIs\n"
678 "Display BGP tags for prefixes\n")
680 return bgp_show_mpls_vpn (vty, NULL, bgp_show_type_normal, NULL, 1);
683 DEFUN (show_ip_bgp_vpnv4_rd_tags,
684 show_ip_bgp_vpnv4_rd_tags_cmd,
685 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn tags",
686 SHOW_STR
687 IP_STR
688 BGP_STR
689 "Display VPNv4 NLRI specific information\n"
690 "Display information for a route distinguisher\n"
691 "VPN Route Distinguisher\n"
692 "Display BGP tags for prefixes\n")
694 int ret;
695 struct prefix_rd prd;
697 ret = str2prefix_rd (argv[0], &prd);
698 if (! ret)
700 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
701 return CMD_WARNING;
703 return bgp_show_mpls_vpn (vty, &prd, bgp_show_type_normal, NULL, 1);
706 DEFUN (show_ip_bgp_vpnv4_all_route,
707 show_ip_bgp_vpnv4_all_route_cmd,
708 "show ip bgp vpnv4 all A.B.C.D",
709 SHOW_STR
710 IP_STR
711 BGP_STR
712 "Display VPNv4 NLRI specific information\n"
713 "Display information about all VPNv4 NLRIs\n"
714 "Network in the BGP routing table to display\n")
716 return bgp_show_mpls_vpn_route (vty, argv[0], NULL, 0);
719 DEFUN (show_ip_bgp_vpnv4_all_prefix,
720 show_ip_bgp_vpnv4_all_prefix_cmd,
721 "show ip bgp vpnv4 all A.B.C.D/M",
722 SHOW_STR
723 IP_STR
724 BGP_STR
725 "Display VPNv4 NLRI specific information\n"
726 "Display information about all VPNv4 NLRIs\n"
727 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
729 return bgp_show_mpls_vpn_route (vty, argv[0], NULL, 1);
732 DEFUN (show_ip_bgp_vpnv4_rd_route,
733 show_ip_bgp_vpnv4_rd_route_cmd,
734 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
735 SHOW_STR
736 IP_STR
737 BGP_STR
738 "Display VPNv4 NLRI specific information\n"
739 "Display information for a route distinguisher\n"
740 "VPN Route Distinguisher\n"
741 "Network in the BGP routing table to display\n")
743 int ret;
744 struct prefix_rd prd;
746 ret = str2prefix_rd (argv[0], &prd);
747 if (! ret)
749 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
750 return CMD_WARNING;
752 return bgp_show_mpls_vpn_route (vty, argv[1], &prd, 0);
755 DEFUN (show_ip_bgp_vpnv4_rd_prefix,
756 show_ip_bgp_vpnv4_rd_prefix_cmd,
757 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
758 SHOW_STR
759 IP_STR
760 BGP_STR
761 "Display VPNv4 NLRI specific information\n"
762 "Display information for a route distinguisher\n"
763 "VPN Route Distinguisher\n"
764 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
766 int ret;
767 struct prefix_rd prd;
769 ret = str2prefix_rd (argv[0], &prd);
770 if (! ret)
772 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
773 return CMD_WARNING;
775 return bgp_show_mpls_vpn_route (vty, argv[1], &prd, 1);
778 DEFUN (show_ip_bgp_vpnv4_all_neighbor_routes,
779 show_ip_bgp_vpnv4_all_neighbor_routes_cmd,
780 "show ip bgp vpnv4 all neighbors A.B.C.D routes",
781 SHOW_STR
782 IP_STR
783 BGP_STR
784 "Display VPNv4 NLRI specific information\n"
785 "Display information about all VPNv4 NLRIs\n"
786 "Detailed information on TCP and BGP neighbor connections\n"
787 "Neighbor to display information about\n"
788 "Display routes learned from neighbor\n")
790 union sockunion *su;
791 struct peer *peer;
793 su = sockunion_str2su (argv[0]);
794 if (su == NULL)
796 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
797 return CMD_WARNING;
800 peer = peer_lookup_by_su (su);
801 if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
803 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
804 return CMD_WARNING;
807 return bgp_show_mpls_vpn (vty, NULL, bgp_show_type_neighbor, su, 0);
810 DEFUN (show_ip_bgp_vpnv4_rd_neighbor_routes,
811 show_ip_bgp_vpnv4_rd_neighbor_routes_cmd,
812 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D routes",
813 SHOW_STR
814 IP_STR
815 BGP_STR
816 "Display VPNv4 NLRI specific information\n"
817 "Display information for a route distinguisher\n"
818 "VPN Route Distinguisher\n"
819 "Detailed information on TCP and BGP neighbor connections\n"
820 "Neighbor to display information about\n"
821 "Display routes learned from neighbor\n")
823 int ret;
824 union sockunion *su;
825 struct peer *peer;
826 struct prefix_rd prd;
828 ret = str2prefix_rd (argv[0], &prd);
829 if (! ret)
831 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
832 return CMD_WARNING;
835 su = sockunion_str2su (argv[1]);
836 if (su == NULL)
838 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
839 return CMD_WARNING;
842 peer = peer_lookup_by_su (su);
843 if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
845 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
846 return CMD_WARNING;
849 return bgp_show_mpls_vpn (vty, &prd, bgp_show_type_neighbor, su, 0);
852 DEFUN (show_ip_bgp_vpnv4_all_neighbor_advertised_routes,
853 show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd,
854 "show ip bgp vpnv4 all neighbors A.B.C.D advertised-routes",
855 SHOW_STR
856 IP_STR
857 BGP_STR
858 "Display VPNv4 NLRI specific information\n"
859 "Display information about all VPNv4 NLRIs\n"
860 "Detailed information on TCP and BGP neighbor connections\n"
861 "Neighbor to display information about\n"
862 "Display the routes advertised to a BGP neighbor\n")
864 int ret;
865 struct peer *peer;
866 union sockunion su;
868 ret = str2sockunion (argv[0], &su);
869 if (ret < 0)
871 vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
872 return CMD_WARNING;
874 peer = peer_lookup_by_su (&su);
875 if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
877 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
878 return CMD_WARNING;
881 return show_adj_route_vpn (vty, peer, NULL);
884 DEFUN (show_ip_bgp_vpnv4_rd_neighbor_advertised_routes,
885 show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd,
886 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D advertised-routes",
887 SHOW_STR
888 IP_STR
889 BGP_STR
890 "Display VPNv4 NLRI specific information\n"
891 "Display information for a route distinguisher\n"
892 "VPN Route Distinguisher\n"
893 "Detailed information on TCP and BGP neighbor connections\n"
894 "Neighbor to display information about\n"
895 "Display the routes advertised to a BGP neighbor\n")
897 int ret;
898 struct peer *peer;
899 struct prefix_rd prd;
900 union sockunion su;
902 ret = str2sockunion (argv[1], &su);
903 if (ret < 0)
905 vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
906 return CMD_WARNING;
908 peer = peer_lookup_by_su (&su);
909 if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
911 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
912 return CMD_WARNING;
915 ret = str2prefix_rd (argv[0], &prd);
916 if (! ret)
918 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
919 return CMD_WARNING;
922 return show_adj_route_vpn (vty, peer, &prd);
925 /* BGP_VPNV4_NODE. */
926 struct cmd_node bgp_vpnv4_node =
928 BGP_VPNV4_NODE,
929 "%s(config-router-af)# ",
933 void
934 bgp_mplsvpn_init ()
936 install_node (&bgp_vpnv4_node, NULL);
937 install_default (BGP_VPNV4_NODE);
939 install_element (BGP_NODE, &address_family_vpnv4_cmd);
940 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
941 install_element (BGP_VPNV4_NODE, &vpnv4_activate_cmd);
942 install_element (BGP_VPNV4_NODE, &no_vpnv4_activate_cmd);
943 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
945 install_element (BGP_VPNV4_NODE, &vpnv4_network_cmd);
946 install_element (BGP_VPNV4_NODE, &no_vpnv4_network_cmd);
948 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_cmd);
949 install_element (BGP_VPNV4_NODE, &neighbor_maximum_prefix_warning_cmd);
950 install_element (BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_cmd);
951 install_element (BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_val_cmd);
952 install_element (BGP_VPNV4_NODE, &no_neighbor_maximum_prefix_val2_cmd);
954 install_element (BGP_VPNV4_NODE, &neighbor_nexthop_self_cmd);
955 install_element (BGP_VPNV4_NODE, &no_neighbor_nexthop_self_cmd);
957 install_element (BGP_VPNV4_NODE, &neighbor_send_community_cmd);
958 install_element (BGP_VPNV4_NODE, &neighbor_send_community_type_cmd);
959 install_element (BGP_VPNV4_NODE, &no_neighbor_send_community_cmd);
960 install_element (BGP_VPNV4_NODE, &no_neighbor_send_community_type_cmd);
962 install_element (BGP_VPNV4_NODE, &neighbor_route_reflector_client_cmd);
963 install_element (BGP_VPNV4_NODE, &no_neighbor_route_reflector_client_cmd);
965 install_element (BGP_VPNV4_NODE, &neighbor_route_server_client_cmd);
966 install_element (BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd);
968 install_element (BGP_VPNV4_NODE, &neighbor_distribute_list_cmd);
969 install_element (BGP_VPNV4_NODE, &no_neighbor_distribute_list_cmd);
970 install_element (BGP_VPNV4_NODE, &neighbor_prefix_list_cmd);
971 install_element (BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd);
972 install_element (BGP_VPNV4_NODE, &neighbor_filter_list_cmd);
973 install_element (BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd);
974 install_element (BGP_VPNV4_NODE, &neighbor_route_map_cmd);
975 install_element (BGP_VPNV4_NODE, &no_neighbor_route_map_cmd);
977 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_cmd);
978 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_cmd);
979 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
980 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
981 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
982 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
983 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_tags_cmd);
984 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_tags_cmd);
985 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbor_routes_cmd);
986 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbor_routes_cmd);
987 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd);
988 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd);
990 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_cmd);
991 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_cmd);
992 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
993 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
994 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
995 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
996 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_tags_cmd);
997 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_tags_cmd);
998 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_neighbor_routes_cmd);
999 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_neighbor_routes_cmd);
1000 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd);
1001 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd);