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
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
32 #include "bgpd/bgpd.h"
33 #include "bgpd/bgp_table.h"
34 #include "bgpd/bgp_route.h"
35 #include "bgpd/bgp_attr.h"
36 #include "bgpd/bgp_mplsvpn.h"
37 #include "bgpd/bgp_packet.h"
38 #include "bgpd/bgp_vty.h"
39 #include "bgpd/bgp_vpn.h"
42 #include "bgpd/rfapi/rfapi_backend.h"
46 argv_find_and_parse_vpnvx(struct cmd_token
**argv
, int argc
, int *index
, afi_t
*afi
)
49 if (argv_find (argv
, argc
, "vpnv4", index
))
55 else if (argv_find (argv
, argc
, "vpnv6", index
))
65 decode_rd_type (u_char
*pnt
)
69 v
= ((u_int16_t
) *pnt
++ << 8);
72 * VNC L2 stores LHI in lower byte, so omit it
74 if (v
!= RD_TYPE_VNC_ETH
)
75 v
|= (u_int16_t
) *pnt
;
76 #else /* duplicate code for clarity */
77 v
|= (u_int16_t
) *pnt
;
84 encode_rd_type (u_int16_t v
, u_char
*pnt
)
86 *((u_int16_t
*)pnt
) = htons(v
);
90 decode_label (u_char
*pnt
)
94 l
= ((u_int32_t
) *pnt
++ << 12);
95 l
|= (u_int32_t
) *pnt
++ << 4;
96 l
|= (u_int32_t
) ((*pnt
& 0xf0) >> 4);
101 encode_label(u_int32_t label
,
106 *pnt
++ = (label
>>12) & 0xff;
107 *pnt
++ = (label
>>4) & 0xff;
108 *pnt
++ = ((label
<<4)+1) & 0xff; /* S=1 */
111 /* type == RD_TYPE_AS */
113 decode_rd_as (u_char
*pnt
, struct rd_as
*rd_as
)
115 rd_as
->as
= (u_int16_t
) *pnt
++ << 8;
116 rd_as
->as
|= (u_int16_t
) *pnt
++;
118 rd_as
->val
= ((u_int32_t
) *pnt
++ << 24);
119 rd_as
->val
|= ((u_int32_t
) *pnt
++ << 16);
120 rd_as
->val
|= ((u_int32_t
) *pnt
++ << 8);
121 rd_as
->val
|= (u_int32_t
) *pnt
;
124 /* type == RD_TYPE_AS4 */
126 decode_rd_as4 (u_char
*pnt
, struct rd_as
*rd_as
)
128 rd_as
->as
= (u_int32_t
) *pnt
++ << 24;
129 rd_as
->as
|= (u_int32_t
) *pnt
++ << 16;
130 rd_as
->as
|= (u_int32_t
) *pnt
++ << 8;
131 rd_as
->as
|= (u_int32_t
) *pnt
++;
133 rd_as
->val
= ((u_int16_t
) *pnt
++ << 8);
134 rd_as
->val
|= (u_int16_t
) *pnt
;
137 /* type == RD_TYPE_IP */
139 decode_rd_ip (u_char
*pnt
, struct rd_ip
*rd_ip
)
141 memcpy (&rd_ip
->ip
, pnt
, 4);
144 rd_ip
->val
= ((u_int16_t
) *pnt
++ << 8);
145 rd_ip
->val
|= (u_int16_t
) *pnt
;
149 /* type == RD_TYPE_VNC_ETH */
151 decode_rd_vnc_eth (u_char
*pnt
, struct rd_vnc_eth
*rd_vnc_eth
)
153 rd_vnc_eth
->type
= RD_TYPE_VNC_ETH
;
154 rd_vnc_eth
->local_nve_id
= pnt
[1];
155 memcpy (rd_vnc_eth
->macaddr
.octet
, pnt
+ 2, ETHER_ADDR_LEN
);
160 bgp_nlri_parse_vpn (struct peer
*peer
, struct attr
*attr
,
161 struct bgp_nlri
*packet
)
171 struct prefix_rd prd
;
176 u_int32_t addpath_id
;
178 /* Check peer status. */
179 if (peer
->status
!= Established
)
183 prd
.family
= AF_UNSPEC
;
187 lim
= pnt
+ packet
->length
;
192 addpath_encoded
= (CHECK_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ADDPATH_AF_RX_ADV
) &&
193 CHECK_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ADDPATH_AF_TX_RCV
));
195 #define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
196 for (; pnt
< lim
; pnt
+= psize
)
198 /* Clear prefix structure. */
199 memset (&p
, 0, sizeof (struct prefix
));
204 /* When packet overflow occurs return immediately. */
205 if (pnt
+ BGP_ADDPATH_ID_LEN
> lim
)
208 addpath_id
= ntohl(*((uint32_t*) pnt
));
209 pnt
+= BGP_ADDPATH_ID_LEN
;
212 /* Fetch prefix length. */
214 p
.family
= afi2family (packet
->afi
);
215 psize
= PSIZE (prefixlen
);
217 if (prefixlen
< VPN_PREFIXLEN_MIN_BYTES
*8)
219 zlog_err ("%s [Error] Update packet error / VPN (prefix length %d less than VPN min length)",
220 peer
->host
, prefixlen
);
224 /* sanity check against packet data */
225 if ((pnt
+ psize
) > lim
)
227 zlog_err ("%s [Error] Update packet error / VPN (prefix length %d exceeds packet size %u)",
229 prefixlen
, (uint
)(lim
-pnt
));
233 /* sanity check against storage for the IP address portion */
234 if ((psize
- VPN_PREFIXLEN_MIN_BYTES
) > (ssize_t
) sizeof(p
.u
))
236 zlog_err ("%s [Error] Update packet error / VPN (psize %d exceeds storage size %zu)",
238 prefixlen
- VPN_PREFIXLEN_MIN_BYTES
*8, sizeof(p
.u
));
242 /* Sanity check against max bitlen of the address family */
243 if ((psize
- VPN_PREFIXLEN_MIN_BYTES
) > prefix_blen (&p
))
245 zlog_err ("%s [Error] Update packet error / VPN (psize %d exceeds family (%u) max byte len %u)",
247 prefixlen
- VPN_PREFIXLEN_MIN_BYTES
*8,
248 p
.family
, prefix_blen (&p
));
252 /* Copyr label to prefix. */
255 /* Copy routing distinguisher to rd. */
256 memcpy (&prd
.val
, pnt
+ 3, 8);
258 /* Decode RD type. */
259 type
= decode_rd_type (pnt
+ 3);
264 decode_rd_as (pnt
+ 5, &rd_as
);
268 decode_rd_as4 (pnt
+ 5, &rd_as
);
272 decode_rd_ip (pnt
+ 5, &rd_ip
);
276 case RD_TYPE_VNC_ETH
:
281 zlog_err ("Unknown RD type %d", type
);
282 break; /* just report */
285 p
.prefixlen
= prefixlen
- VPN_PREFIXLEN_MIN_BYTES
*8;/* exclude label & RD */
286 memcpy (&p
.u
.prefix
, pnt
+ VPN_PREFIXLEN_MIN_BYTES
,
287 psize
- VPN_PREFIXLEN_MIN_BYTES
);
291 bgp_update (peer
, &p
, addpath_id
, attr
, packet
->afi
, SAFI_MPLS_VPN
,
292 ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
, tagpnt
, 0, NULL
);
296 bgp_withdraw (peer
, &p
, addpath_id
, attr
, packet
->afi
, SAFI_MPLS_VPN
,
297 ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
, tagpnt
, NULL
);
300 /* Packet length consistency check. */
303 zlog_err ("%s [Error] Update packet error / VPN (%zu data remaining after parsing)",
304 peer
->host
, lim
- pnt
);
309 #undef VPN_PREFIXLEN_MIN_BYTES
313 str2prefix_rd (const char *str
, struct prefix_rd
*prd
)
315 int ret
; /* ret of called functions */
316 int lret
; /* local ret, of this func */
319 struct stream
*s
= NULL
;
325 prd
->family
= AF_UNSPEC
;
329 p
= strchr (str
, ':');
333 if (! all_digit (p
+ 1))
336 half
= XMALLOC (MTYPE_TMP
, (p
- str
) + 1);
337 memcpy (half
, str
, (p
- str
));
338 half
[p
- str
] = '\0';
340 p2
= strchr (str
, '.');
344 unsigned long as_val
;
346 if (! all_digit (half
))
352 stream_putw (s
, RD_TYPE_AS4
);
353 stream_putl (s
, as_val
);
354 stream_putw (s
, atol (p
+ 1));
358 stream_putw (s
, RD_TYPE_AS
);
359 stream_putw (s
, as_val
);
360 stream_putl (s
, atol (p
+ 1));
365 ret
= inet_aton (half
, &addr
);
369 stream_putw (s
, RD_TYPE_IP
);
370 stream_put_in_addr (s
, &addr
);
371 stream_putw (s
, atol (p
+ 1));
373 memcpy (prd
->val
, s
->data
, 8);
380 XFREE(MTYPE_TMP
, half
);
385 prefix_rd2str (struct prefix_rd
*prd
, char *buf
, size_t size
)
392 if (size
< RD_ADDRSTRLEN
)
397 type
= decode_rd_type (pnt
);
399 if (type
== RD_TYPE_AS
)
401 decode_rd_as (pnt
+ 2, &rd_as
);
402 snprintf (buf
, size
, "%u:%d", rd_as
.as
, rd_as
.val
);
405 else if (type
== RD_TYPE_AS4
)
407 decode_rd_as4 (pnt
+ 2, &rd_as
);
408 snprintf (buf
, size
, "%u:%d", rd_as
.as
, rd_as
.val
);
411 else if (type
== RD_TYPE_IP
)
413 decode_rd_ip (pnt
+ 2, &rd_ip
);
414 snprintf (buf
, size
, "%s:%d", inet_ntoa (rd_ip
.ip
), rd_ip
.val
);
418 else if (type
== RD_TYPE_VNC_ETH
)
420 snprintf(buf
, size
, "LHI:%d, %02x:%02x:%02x:%02x:%02x:%02x",
422 *(pnt
+2), /* MAC[0] */
435 /* For testing purpose, static route of MPLS-VPN. */
436 DEFUN (vpnv4_network
,
438 "network A.B.C.D/M rd ASN:nn_or_IP-address:nn <tag|label> (0-1048575)",
439 "Specify a network to announce via BGP\n"
441 "Specify Route Distinguisher\n"
442 "VPN Route Distinguisher\n"
443 "VPN NLRI label (tag)\n"
444 "VPN NLRI label (tag)\n"
447 int idx_ipv4_prefixlen
= 1;
448 int idx_ext_community
= 3;
450 return bgp_static_set_safi (AFI_IP
, SAFI_MPLS_VPN
, vty
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_ext_community
]->arg
,
451 argv
[idx_label
]->arg
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
454 DEFUN (vpnv4_network_route_map
,
455 vpnv4_network_route_map_cmd
,
456 "network A.B.C.D/M rd ASN:nn_or_IP-address:nn <tag|label> (0-1048575) route-map WORD",
457 "Specify a network to announce via BGP\n"
459 "Specify Route Distinguisher\n"
460 "VPN Route Distinguisher\n"
461 "VPN NLRI label (tag)\n"
462 "VPN NLRI label (tag)\n"
467 int idx_ipv4_prefixlen
= 1;
468 int idx_ext_community
= 3;
471 return bgp_static_set_safi (AFI_IP
, SAFI_MPLS_VPN
, vty
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_ext_community
]->arg
, argv
[idx_label
]->arg
,
472 argv
[idx_word_2
]->arg
, 0, NULL
, NULL
, NULL
, NULL
);
475 /* For testing purpose, static route of MPLS-VPN. */
476 DEFUN (no_vpnv4_network
,
477 no_vpnv4_network_cmd
,
478 "no network A.B.C.D/M rd ASN:nn_or_IP-address:nn <tag|label> (0-1048575)",
480 "Specify a network to announce via BGP\n"
482 "Specify Route Distinguisher\n"
483 "VPN Route Distinguisher\n"
484 "VPN NLRI label (tag)\n"
485 "VPN NLRI label (tag)\n"
488 int idx_ipv4_prefixlen
= 2;
489 int idx_ext_community
= 4;
491 return bgp_static_unset_safi (AFI_IP
, SAFI_MPLS_VPN
, vty
, argv
[idx_ipv4_prefixlen
]->arg
,
492 argv
[idx_ext_community
]->arg
, argv
[idx_label
]->arg
,
493 0, NULL
, NULL
, NULL
);
496 DEFUN (vpnv6_network
,
498 "network X:X::X:X/M rd ASN:nn_or_IP-address:nn <tag|label> (0-1048575) [route-map WORD]",
499 "Specify a network to announce via BGP\n"
500 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
501 "Specify Route Distinguisher\n"
502 "VPN Route Distinguisher\n"
503 "VPN NLRI label (tag)\n"
504 "VPN NLRI label (tag)\n"
509 int idx_ipv6_prefix
= 1;
510 int idx_ext_community
= 3;
514 return bgp_static_set_safi (AFI_IP6
, SAFI_MPLS_VPN
, vty
, argv
[idx_ipv6_prefix
]->arg
, argv
[idx_ext_community
]->arg
, argv
[idx_label
]->arg
, argv
[idx_word_2
]->arg
, 0, NULL
, NULL
, NULL
, NULL
);
516 return bgp_static_set_safi (AFI_IP6
, SAFI_MPLS_VPN
, vty
, argv
[idx_ipv6_prefix
]->arg
, argv
[idx_ext_community
]->arg
, argv
[idx_label
]->arg
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
519 /* For testing purpose, static route of MPLS-VPN. */
520 DEFUN (no_vpnv6_network
,
521 no_vpnv6_network_cmd
,
522 "no network X:X::X:X/M rd ASN:nn_or_IP-address:nn <tag|label> (0-1048575)",
524 "Specify a network to announce via BGP\n"
525 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
526 "Specify Route Distinguisher\n"
527 "VPN Route Distinguisher\n"
528 "VPN NLRI label (tag)\n"
529 "VPN NLRI label (tag)\n"
532 int idx_ipv6_prefix
= 2;
533 int idx_ext_community
= 4;
535 return bgp_static_unset_safi (AFI_IP6
, SAFI_MPLS_VPN
, vty
, argv
[idx_ipv6_prefix
]->arg
, argv
[idx_ext_community
]->arg
, argv
[idx_label
]->arg
, 0, NULL
, NULL
, NULL
);
539 bgp_show_mpls_vpn (struct vty
*vty
, afi_t afi
, struct prefix_rd
*prd
,
540 enum bgp_show_type type
, void *output_arg
, int tags
, u_char use_json
)
543 struct bgp_table
*table
;
549 char v4_header
[] = " Network Next Hop Metric LocPrf Weight Path%s";
550 char v4_header_tag
[] = " Network Next Hop In tag/Out tag%s";
551 unsigned long output_count
= 0;
552 unsigned long total_count
= 0;
553 json_object
*json
= NULL
;
554 json_object
*json_mroute
= NULL
;
555 json_object
*json_nroute
= NULL
;
556 json_object
*json_array
= NULL
;
557 json_object
*json_scode
= NULL
;
558 json_object
*json_ocode
= NULL
;
560 bgp
= bgp_get_default ();
564 vty_out (vty
, "No BGP process is configured%s", VTY_NEWLINE
);
570 json_scode
= json_object_new_object();
571 json_ocode
= json_object_new_object();
572 json
= json_object_new_object();
573 json_mroute
= json_object_new_object();
574 json_nroute
= json_object_new_object();
576 json_object_string_add(json_scode
, "suppressed", "s");
577 json_object_string_add(json_scode
, "damped", "d");
578 json_object_string_add(json_scode
, "history", "h");
579 json_object_string_add(json_scode
, "valid", "*");
580 json_object_string_add(json_scode
, "best", ">");
581 json_object_string_add(json_scode
, "internal", "i");
583 json_object_string_add(json_ocode
, "igp", "i");
584 json_object_string_add(json_ocode
, "egp", "e");
585 json_object_string_add(json_ocode
, "incomplete", "?");
588 if ((afi
!= AFI_IP
) && (afi
!= AFI_IP6
))
590 vty_out (vty
, "Afi %d not supported%s", afi
, VTY_NEWLINE
);
594 for (rn
= bgp_table_top (bgp
->rib
[afi
][SAFI_MPLS_VPN
]); rn
; rn
= bgp_route_next (rn
))
596 if (prd
&& memcmp (rn
->p
.u
.val
, prd
->val
, 8) != 0)
599 if ((table
= rn
->info
) != NULL
)
603 for (rm
= bgp_table_top (table
); rm
; rm
= bgp_route_next (rm
))
607 json_array
= json_object_new_array();
611 for (ri
= rm
->info
; ri
; ri
= ri
->next
)
613 if (type
== bgp_show_type_neighbor
)
615 union sockunion
*su
= output_arg
;
617 if (ri
->peer
->su_remote
== NULL
|| ! sockunion_same(ri
->peer
->su_remote
, su
))
626 json_object_int_add(json
, "bgpTableVersion", 0);
627 json_object_string_add(json
, "bgpLocalRouterId", inet_ntoa (bgp
->router_id
));
628 json_object_object_add(json
, "bgpStatusCodes", json_scode
);
629 json_object_object_add(json
, "bgpOriginCodes", json_ocode
);
635 vty_out (vty
, v4_header_tag
, VTY_NEWLINE
);
638 vty_out (vty
, "BGP table version is 0, local router ID is %s%s",
639 inet_ntoa (bgp
->router_id
), VTY_NEWLINE
);
640 vty_out (vty
, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
642 vty_out (vty
, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
643 VTY_NEWLINE
, VTY_NEWLINE
);
644 vty_out (vty
, v4_header
, VTY_NEWLINE
);
654 struct rd_ip rd_ip
= {0};
656 struct rd_vnc_eth rd_vnc_eth
= {0};
662 /* Decode RD type. */
663 type
= decode_rd_type (pnt
);
664 /* Decode RD value. */
665 if (type
== RD_TYPE_AS
)
666 decode_rd_as (pnt
+ 2, &rd_as
);
667 else if (type
== RD_TYPE_AS4
)
668 decode_rd_as4 (pnt
+ 2, &rd_as
);
669 else if (type
== RD_TYPE_IP
)
670 decode_rd_ip (pnt
+ 2, &rd_ip
);
672 else if (type
== RD_TYPE_VNC_ETH
)
673 decode_rd_vnc_eth (pnt
, &rd_vnc_eth
);
679 if (type
== RD_TYPE_AS
|| type
== RD_TYPE_AS4
)
680 sprintf (buffer
, "%u:%d", rd_as
.as
, rd_as
.val
);
681 else if (type
== RD_TYPE_IP
)
682 sprintf (buffer
, "%s:%d", inet_ntoa (rd_ip
.ip
), rd_ip
.val
);
683 json_object_string_add(json_nroute
, "routeDistinguisher", buffer
);
687 vty_out (vty
, "Route Distinguisher: ");
689 if (type
== RD_TYPE_AS
|| type
== RD_TYPE_AS4
)
690 vty_out (vty
, "%u:%d", rd_as
.as
, rd_as
.val
);
691 else if (type
== RD_TYPE_IP
)
692 vty_out (vty
, "%s:%d", inet_ntoa (rd_ip
.ip
), rd_ip
.val
);
694 else if (type
== RD_TYPE_VNC_ETH
)
695 vty_out (vty
, "%u:%02x:%02x:%02x:%02x:%02x:%02x",
696 rd_vnc_eth
.local_nve_id
,
697 rd_vnc_eth
.macaddr
.octet
[0],
698 rd_vnc_eth
.macaddr
.octet
[1],
699 rd_vnc_eth
.macaddr
.octet
[2],
700 rd_vnc_eth
.macaddr
.octet
[3],
701 rd_vnc_eth
.macaddr
.octet
[4],
702 rd_vnc_eth
.macaddr
.octet
[5]);
704 vty_out (vty
, "%s", VTY_NEWLINE
);
709 route_vty_out_tag (vty
, &rm
->p
, ri
, 0, SAFI_MPLS_VPN
, json_array
);
711 route_vty_out (vty
, &rm
->p
, ri
, 0, SAFI_MPLS_VPN
, json_array
);
721 sprintf(buf_a
, "%s/%d", inet_ntop (p
->family
, &p
->u
.prefix
, buf_b
, BUFSIZ
), p
->prefixlen
);
722 json_object_object_add(json_mroute
, buf_a
, json_array
);
732 sprintf(buf_a
, "%s/%d", inet_ntop (p
->family
, &p
->u
.prefix
, buf_b
, BUFSIZ
), p
->prefixlen
);
733 json_object_object_add(json_nroute
, buf_a
, json_mroute
);
740 json_object_object_add(json
, "routes", json_nroute
);
741 vty_out (vty
, "%s%s", json_object_to_json_string_ext(json
, JSON_C_TO_STRING_PRETTY
), VTY_NEWLINE
);
742 json_object_free(json
);
746 if (output_count
== 0)
747 vty_out (vty
, "No prefixes displayed, %ld exist%s", total_count
, VTY_NEWLINE
);
749 vty_out (vty
, "%sDisplayed %ld routes and %ld total paths%s",
750 VTY_NEWLINE
, output_count
, total_count
, VTY_NEWLINE
);
756 DEFUN (show_bgp_ip_vpn_all_rd
,
757 show_bgp_ip_vpn_all_rd_cmd
,
758 "show bgp "BGP_AFI_CMD_STR
" vpn all [rd ASN:nn_or_IP-address:nn] [json]",
763 "Display VPN NLRI specific information\n"
764 "Display information for a route distinguisher\n"
765 "VPN Route Distinguisher\n"
770 struct prefix_rd prd
;
774 if (argv_find_and_parse_afi (argv
, argc
, &idx
, &afi
))
776 if (argc
>= 7 && argv
[idx_rd
]->arg
)
778 ret
= str2prefix_rd (argv
[idx_rd
]->arg
, &prd
);
781 vty_out (vty
, "%% Malformed Route Distinguisher%s", VTY_NEWLINE
);
784 return bgp_show_mpls_vpn (vty
, afi
, &prd
, bgp_show_type_normal
, NULL
, 0, use_json (argc
, argv
));
788 return bgp_show_mpls_vpn (vty
, afi
, NULL
, bgp_show_type_normal
, NULL
, 0, use_json (argc
, argv
));
794 DEFUN (show_ip_bgp_vpn_rd
,
795 show_ip_bgp_vpn_rd_cmd
,
796 "show [ip] bgp "BGP_AFI_CMD_STR
" vpn rd ASN:nn_or_IP-address:nn",
801 "Address Family modifier\n"
802 "Display information for a route distinguisher\n"
803 "VPN Route Distinguisher\n")
805 int idx_ext_community
= argc
-1;
807 struct prefix_rd prd
;
811 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
813 ret
= str2prefix_rd (argv
[idx_ext_community
]->arg
, &prd
);
816 vty_out (vty
, "%% Malformed Route Distinguisher%s", VTY_NEWLINE
);
819 return bgp_show_mpls_vpn (vty
, afi
, &prd
, bgp_show_type_normal
, NULL
, 0, 0);
824 #ifdef KEEP_OLD_VPN_COMMANDS
825 DEFUN (show_ip_bgp_vpn_all
,
826 show_ip_bgp_vpn_all_cmd
,
827 "show [ip] bgp <vpnv4|vpnv6>",
836 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
837 return bgp_show_mpls_vpn (vty
, afi
, NULL
, bgp_show_type_normal
, NULL
, 0, 0);
841 DEFUN (show_ip_bgp_vpn_all_tags
,
842 show_ip_bgp_vpn_all_tags_cmd
,
843 "show [ip] bgp <vpnv4|vpnv6> all tags",
848 "Display information about all VPNv4/VPNV6 NLRIs\n"
849 "Display BGP tags for prefixes\n")
854 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
855 return bgp_show_mpls_vpn (vty
, afi
, NULL
, bgp_show_type_normal
, NULL
, 1, 0);
859 DEFUN (show_ip_bgp_vpn_rd_tags
,
860 show_ip_bgp_vpn_rd_tags_cmd
,
861 "show [ip] bgp <vpnv4|vpnv6> rd ASN:nn_or_IP-address:nn tags",
866 "Display information for a route distinguisher\n"
867 "VPN Route Distinguisher\n"
868 "Display BGP tags for prefixes\n")
870 int idx_ext_community
= 5;
872 struct prefix_rd prd
;
876 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
878 ret
= str2prefix_rd (argv
[idx_ext_community
]->arg
, &prd
);
881 vty_out (vty
, "%% Malformed Route Distinguisher%s", VTY_NEWLINE
);
884 return bgp_show_mpls_vpn (vty
, afi
, &prd
, bgp_show_type_normal
, NULL
, 1, 0);
889 DEFUN (show_ip_bgp_vpn_all_neighbor_routes
,
890 show_ip_bgp_vpn_all_neighbor_routes_cmd
,
891 "show [ip] bgp <vpnv4|vpnv6> all neighbors A.B.C.D routes [json]",
896 "Display information about all VPNv4/VPNv6 NLRIs\n"
897 "Detailed information on TCP and BGP neighbor connections\n"
898 "Neighbor to display information about\n"
899 "Display routes learned from neighbor\n"
906 u_char uj
= use_json(argc
, argv
);
910 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
912 ret
= str2sockunion (argv
[idx_ipv4
]->arg
, &su
);
917 json_object
*json_no
= NULL
;
918 json_no
= json_object_new_object();
919 json_object_string_add(json_no
, "warning", "Malformed address");
920 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
921 json_object_free(json_no
);
924 vty_out (vty
, "Malformed address: %s%s", argv
[idx_ipv4
]->arg
, VTY_NEWLINE
);
928 peer
= peer_lookup (NULL
, &su
);
929 if (! peer
|| ! peer
->afc
[afi
][SAFI_MPLS_VPN
])
933 json_object
*json_no
= NULL
;
934 json_no
= json_object_new_object();
935 json_object_string_add(json_no
, "warning", "No such neighbor or address family");
936 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
937 json_object_free(json_no
);
940 vty_out (vty
, "%% No such neighbor or address family%s", VTY_NEWLINE
);
944 return bgp_show_mpls_vpn (vty
, afi
, NULL
, bgp_show_type_neighbor
, &su
, 0, uj
);
949 DEFUN (show_ip_bgp_vpn_rd_neighbor_routes
,
950 show_ip_bgp_vpn_rd_neighbor_routes_cmd
,
951 "show [ip] bgp <vpnv4|vpnv6> rd ASN:nn_or_IP-address:nn neighbors A.B.C.D routes [json]",
956 "Display information for a route distinguisher\n"
957 "VPN Route Distinguisher\n"
958 "Detailed information on TCP and BGP neighbor connections\n"
959 "Neighbor to display information about\n"
960 "Display routes learned from neighbor\n"
963 int idx_ext_community
= 5;
968 struct prefix_rd prd
;
969 u_char uj
= use_json(argc
, argv
);
973 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
975 ret
= str2prefix_rd (argv
[idx_ext_community
]->arg
, &prd
);
980 json_object
*json_no
= NULL
;
981 json_no
= json_object_new_object();
982 json_object_string_add(json_no
, "warning", "Malformed Route Distinguisher");
983 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
984 json_object_free(json_no
);
987 vty_out (vty
, "%% Malformed Route Distinguisher%s", VTY_NEWLINE
);
991 ret
= str2sockunion (argv
[idx_ipv4
]->arg
, &su
);
996 json_object
*json_no
= NULL
;
997 json_no
= json_object_new_object();
998 json_object_string_add(json_no
, "warning", "Malformed address");
999 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
1000 json_object_free(json_no
);
1003 vty_out (vty
, "Malformed address: %s%s", argv
[idx_ext_community
]->arg
, VTY_NEWLINE
);
1007 peer
= peer_lookup (NULL
, &su
);
1008 if (! peer
|| ! peer
->afc
[afi
][SAFI_MPLS_VPN
])
1012 json_object
*json_no
= NULL
;
1013 json_no
= json_object_new_object();
1014 json_object_string_add(json_no
, "warning", "No such neighbor or address family");
1015 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
1016 json_object_free(json_no
);
1019 vty_out (vty
, "%% No such neighbor or address family%s", VTY_NEWLINE
);
1023 return bgp_show_mpls_vpn (vty
, afi
, &prd
, bgp_show_type_neighbor
, &su
, 0, uj
);
1028 DEFUN (show_ip_bgp_vpn_all_neighbor_advertised_routes
,
1029 show_ip_bgp_vpn_all_neighbor_advertised_routes_cmd
,
1030 "show [ip] bgp <vpnv4|vpnv6> all neighbors A.B.C.D advertised-routes [json]",
1035 "Display information about all VPNv4/VPNv6 NLRIs\n"
1036 "Detailed information on TCP and BGP neighbor connections\n"
1037 "Neighbor to display information about\n"
1038 "Display the routes advertised to a BGP neighbor\n"
1045 u_char uj
= use_json(argc
, argv
);
1049 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
1051 ret
= str2sockunion (argv
[idx_ipv4
]->arg
, &su
);
1056 json_object
*json_no
= NULL
;
1057 json_no
= json_object_new_object();
1058 json_object_string_add(json_no
, "warning", "Malformed address");
1059 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
1060 json_object_free(json_no
);
1063 vty_out (vty
, "Malformed address: %s%s", argv
[idx_ipv4
]->arg
, VTY_NEWLINE
);
1066 peer
= peer_lookup (NULL
, &su
);
1067 if (! peer
|| ! peer
->afc
[afi
][SAFI_MPLS_VPN
])
1071 json_object
*json_no
= NULL
;
1072 json_no
= json_object_new_object();
1073 json_object_string_add(json_no
, "warning", "No such neighbor or address family");
1074 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
1075 json_object_free(json_no
);
1078 vty_out (vty
, "%% No such neighbor or address family%s", VTY_NEWLINE
);
1081 return show_adj_route_vpn (vty
, peer
, NULL
, AFI_IP
, SAFI_MPLS_VPN
, uj
);
1086 DEFUN (show_ip_bgp_vpn_rd_neighbor_advertised_routes
,
1087 show_ip_bgp_vpn_rd_neighbor_advertised_routes_cmd
,
1088 "show [ip] bgp <vpnv4|vpnv6> rd ASN:nn_or_IP-address:nn neighbors A.B.C.D advertised-routes [json]",
1093 "Display information for a route distinguisher\n"
1094 "VPN Route Distinguisher\n"
1095 "Detailed information on TCP and BGP neighbor connections\n"
1096 "Neighbor to display information about\n"
1097 "Display the routes advertised to a BGP neighbor\n"
1100 int idx_ext_community
= 5;
1104 struct prefix_rd prd
;
1106 u_char uj
= use_json(argc
, argv
);
1110 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
1112 ret
= str2sockunion (argv
[idx_ipv4
]->arg
, &su
);
1117 json_object
*json_no
= NULL
;
1118 json_no
= json_object_new_object();
1119 json_object_string_add(json_no
, "warning", "Malformed address");
1120 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
1121 json_object_free(json_no
);
1124 vty_out (vty
, "Malformed address: %s%s", argv
[idx_ext_community
]->arg
, VTY_NEWLINE
);
1127 peer
= peer_lookup (NULL
, &su
);
1128 if (! peer
|| ! peer
->afc
[afi
][SAFI_MPLS_VPN
])
1132 json_object
*json_no
= NULL
;
1133 json_no
= json_object_new_object();
1134 json_object_string_add(json_no
, "warning", "No such neighbor or address family");
1135 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
1136 json_object_free(json_no
);
1139 vty_out (vty
, "%% No such neighbor or address family%s", VTY_NEWLINE
);
1143 ret
= str2prefix_rd (argv
[idx_ext_community
]->arg
, &prd
);
1148 json_object
*json_no
= NULL
;
1149 json_no
= json_object_new_object();
1150 json_object_string_add(json_no
, "warning", "Malformed Route Distinguisher");
1151 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
1152 json_object_free(json_no
);
1155 vty_out (vty
, "%% Malformed Route Distinguisher%s", VTY_NEWLINE
);
1159 return show_adj_route_vpn (vty
, peer
, &prd
, AFI_IP
, SAFI_MPLS_VPN
, uj
);
1163 #endif /* KEEP_OLD_VPN_COMMANDS */
1166 bgp_mplsvpn_init (void)
1168 install_element (BGP_VPNV4_NODE
, &vpnv4_network_cmd
);
1169 install_element (BGP_VPNV4_NODE
, &vpnv4_network_route_map_cmd
);
1170 install_element (BGP_VPNV4_NODE
, &no_vpnv4_network_cmd
);
1172 install_element (BGP_VPNV6_NODE
, &vpnv6_network_cmd
);
1173 install_element (BGP_VPNV6_NODE
, &no_vpnv6_network_cmd
);
1175 install_element (VIEW_NODE
, &show_bgp_ip_vpn_all_rd_cmd
);
1176 install_element (VIEW_NODE
, &show_ip_bgp_vpn_rd_cmd
);
1177 #ifdef KEEP_OLD_VPN_COMMANDS
1178 install_element (VIEW_NODE
, &show_ip_bgp_vpn_all_cmd
);
1179 install_element (VIEW_NODE
, &show_ip_bgp_vpn_all_tags_cmd
);
1180 install_element (VIEW_NODE
, &show_ip_bgp_vpn_rd_tags_cmd
);
1181 install_element (VIEW_NODE
, &show_ip_bgp_vpn_all_neighbor_routes_cmd
);
1182 install_element (VIEW_NODE
, &show_ip_bgp_vpn_rd_neighbor_routes_cmd
);
1183 install_element (VIEW_NODE
, &show_ip_bgp_vpn_all_neighbor_advertised_routes_cmd
);
1184 install_element (VIEW_NODE
, &show_ip_bgp_vpn_rd_neighbor_advertised_routes_cmd
);
1185 #endif /* KEEP_OLD_VPN_COMMANDS */