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 str2tag (const char *str
, u_char
*tag
)
395 l
= strtoul (str
, &endptr
, 10);
397 if (*endptr
!= '\0' || errno
|| l
> UINT32_MAX
)
402 tag
[0] = (u_char
)(t
>> 12);
403 tag
[1] = (u_char
)(t
>> 4);
404 tag
[2] = (u_char
)(t
<< 4);
410 prefix_rd2str (struct prefix_rd
*prd
, char *buf
, size_t size
)
417 if (size
< RD_ADDRSTRLEN
)
422 type
= decode_rd_type (pnt
);
424 if (type
== RD_TYPE_AS
)
426 decode_rd_as (pnt
+ 2, &rd_as
);
427 snprintf (buf
, size
, "%u:%d", rd_as
.as
, rd_as
.val
);
430 else if (type
== RD_TYPE_AS4
)
432 decode_rd_as4 (pnt
+ 2, &rd_as
);
433 snprintf (buf
, size
, "%u:%d", rd_as
.as
, rd_as
.val
);
436 else if (type
== RD_TYPE_IP
)
438 decode_rd_ip (pnt
+ 2, &rd_ip
);
439 snprintf (buf
, size
, "%s:%d", inet_ntoa (rd_ip
.ip
), rd_ip
.val
);
443 else if (type
== RD_TYPE_VNC_ETH
)
445 snprintf(buf
, size
, "LHI:%d, %02x:%02x:%02x:%02x:%02x:%02x",
447 *(pnt
+2), /* MAC[0] */
460 /* For testing purpose, static route of MPLS-VPN. */
461 DEFUN (vpnv4_network
,
463 "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
464 "Specify a network to announce via BGP\n"
466 "Specify Route Distinguisher\n"
467 "VPN Route Distinguisher\n"
471 int idx_ipv4_prefixlen
= 1;
472 int idx_ext_community
= 3;
474 return bgp_static_set_safi (SAFI_MPLS_VPN
, vty
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_ext_community
]->arg
,
475 argv
[idx_word
]->arg
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
478 DEFUN (vpnv4_network_route_map
,
479 vpnv4_network_route_map_cmd
,
480 "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD route-map WORD",
481 "Specify a network to announce via BGP\n"
483 "Specify Route Distinguisher\n"
484 "VPN Route Distinguisher\n"
490 int idx_ipv4_prefixlen
= 1;
491 int idx_ext_community
= 3;
494 return bgp_static_set_safi (SAFI_MPLS_VPN
, vty
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_ext_community
]->arg
, argv
[idx_word
]->arg
,
495 argv
[idx_word_2
]->arg
, 0, NULL
, NULL
, NULL
, NULL
);
498 /* For testing purpose, static route of MPLS-VPN. */
499 DEFUN (no_vpnv4_network
,
500 no_vpnv4_network_cmd
,
501 "no network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
503 "Specify a network to announce via BGP\n"
505 "Specify Route Distinguisher\n"
506 "VPN Route Distinguisher\n"
510 int idx_ipv4_prefixlen
= 2;
511 int idx_ext_community
= 4;
513 return bgp_static_unset_safi (SAFI_MPLS_VPN
, vty
, argv
[idx_ipv4_prefixlen
]->arg
,
514 argv
[idx_ext_community
]->arg
, argv
[idx_word
]->arg
,
515 0, NULL
, NULL
, NULL
);
518 DEFUN (vpnv6_network
,
520 "network X:X::X:X/M rd ASN:nn_or_IP-address:nn tag WORD [route-map WORD]",
521 "Specify a network to announce via BGP\n"
522 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
523 "Specify Route Distinguisher\n"
524 "VPN Route Distinguisher\n"
530 int idx_ipv6_prefix
= 1;
531 int idx_ext_community
= 3;
535 return bgp_static_set_safi (SAFI_MPLS_VPN
, vty
, argv
[idx_ipv6_prefix
]->arg
, argv
[idx_ext_community
]->arg
, argv
[idx_word
]->arg
, argv
[idx_word_2
]->arg
, 0, NULL
, NULL
, NULL
, NULL
);
537 return bgp_static_set_safi (SAFI_MPLS_VPN
, vty
, argv
[idx_ipv6_prefix
]->arg
, argv
[idx_ext_community
]->arg
, argv
[idx_word
]->arg
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
540 /* For testing purpose, static route of MPLS-VPN. */
541 DEFUN (no_vpnv6_network
,
542 no_vpnv6_network_cmd
,
543 "no network X:X::X:X/M rd ASN:nn_or_IP-address:nn tag WORD",
545 "Specify a network to announce via BGP\n"
546 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
547 "Specify Route Distinguisher\n"
548 "VPN Route Distinguisher\n"
552 int idx_ipv6_prefix
= 2;
553 int idx_ext_community
= 4;
555 return bgp_static_unset_safi (SAFI_MPLS_VPN
, vty
, argv
[idx_ipv6_prefix
]->arg
, argv
[idx_ext_community
]->arg
, argv
[idx_word
]->arg
, 0, NULL
, NULL
, NULL
);
559 bgp_show_mpls_vpn (struct vty
*vty
, afi_t afi
, struct prefix_rd
*prd
,
560 enum bgp_show_type type
, void *output_arg
, int tags
, u_char use_json
)
563 struct bgp_table
*table
;
569 char v4_header
[] = " Network Next Hop Metric LocPrf Weight Path%s";
570 char v4_header_tag
[] = " Network Next Hop In tag/Out tag%s";
571 unsigned long output_count
= 0;
572 unsigned long total_count
= 0;
573 json_object
*json
= NULL
;
574 json_object
*json_mroute
= NULL
;
575 json_object
*json_nroute
= NULL
;
576 json_object
*json_array
= NULL
;
577 json_object
*json_scode
= NULL
;
578 json_object
*json_ocode
= NULL
;
580 bgp
= bgp_get_default ();
584 vty_out (vty
, "No BGP process is configured%s", VTY_NEWLINE
);
590 json_scode
= json_object_new_object();
591 json_ocode
= json_object_new_object();
592 json
= json_object_new_object();
593 json_mroute
= json_object_new_object();
594 json_nroute
= json_object_new_object();
596 json_object_string_add(json_scode
, "suppressed", "s");
597 json_object_string_add(json_scode
, "damped", "d");
598 json_object_string_add(json_scode
, "history", "h");
599 json_object_string_add(json_scode
, "valid", "*");
600 json_object_string_add(json_scode
, "best", ">");
601 json_object_string_add(json_scode
, "internal", "i");
603 json_object_string_add(json_ocode
, "igp", "i");
604 json_object_string_add(json_ocode
, "egp", "e");
605 json_object_string_add(json_ocode
, "incomplete", "?");
608 if ((afi
!= AFI_IP
) && (afi
!= AFI_IP6
))
610 vty_out (vty
, "Afi %d not supported%s", afi
, VTY_NEWLINE
);
614 for (rn
= bgp_table_top (bgp
->rib
[afi
][SAFI_MPLS_VPN
]); rn
; rn
= bgp_route_next (rn
))
616 if (prd
&& memcmp (rn
->p
.u
.val
, prd
->val
, 8) != 0)
619 if ((table
= rn
->info
) != NULL
)
623 for (rm
= bgp_table_top (table
); rm
; rm
= bgp_route_next (rm
))
627 json_array
= json_object_new_array();
631 for (ri
= rm
->info
; ri
; ri
= ri
->next
)
633 if (type
== bgp_show_type_neighbor
)
635 union sockunion
*su
= output_arg
;
637 if (ri
->peer
->su_remote
== NULL
|| ! sockunion_same(ri
->peer
->su_remote
, su
))
646 json_object_int_add(json
, "bgpTableVersion", 0);
647 json_object_string_add(json
, "bgpLocalRouterId", inet_ntoa (bgp
->router_id
));
648 json_object_object_add(json
, "bgpStatusCodes", json_scode
);
649 json_object_object_add(json
, "bgpOriginCodes", json_ocode
);
655 vty_out (vty
, v4_header_tag
, VTY_NEWLINE
);
658 vty_out (vty
, "BGP table version is 0, local router ID is %s%s",
659 inet_ntoa (bgp
->router_id
), VTY_NEWLINE
);
660 vty_out (vty
, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
662 vty_out (vty
, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
663 VTY_NEWLINE
, VTY_NEWLINE
);
664 vty_out (vty
, v4_header
, VTY_NEWLINE
);
674 struct rd_ip rd_ip
= {0};
676 struct rd_vnc_eth rd_vnc_eth
= {0};
682 /* Decode RD type. */
683 type
= decode_rd_type (pnt
);
684 /* Decode RD value. */
685 if (type
== RD_TYPE_AS
)
686 decode_rd_as (pnt
+ 2, &rd_as
);
687 else if (type
== RD_TYPE_AS4
)
688 decode_rd_as4 (pnt
+ 2, &rd_as
);
689 else if (type
== RD_TYPE_IP
)
690 decode_rd_ip (pnt
+ 2, &rd_ip
);
692 else if (type
== RD_TYPE_VNC_ETH
)
693 decode_rd_vnc_eth (pnt
, &rd_vnc_eth
);
699 if (type
== RD_TYPE_AS
|| type
== RD_TYPE_AS4
)
700 sprintf (buffer
, "%u:%d", rd_as
.as
, rd_as
.val
);
701 else if (type
== RD_TYPE_IP
)
702 sprintf (buffer
, "%s:%d", inet_ntoa (rd_ip
.ip
), rd_ip
.val
);
703 json_object_string_add(json_nroute
, "routeDistinguisher", buffer
);
707 vty_out (vty
, "Route Distinguisher: ");
709 if (type
== RD_TYPE_AS
|| type
== RD_TYPE_AS4
)
710 vty_out (vty
, "%u:%d", rd_as
.as
, rd_as
.val
);
711 else if (type
== RD_TYPE_IP
)
712 vty_out (vty
, "%s:%d", inet_ntoa (rd_ip
.ip
), rd_ip
.val
);
714 else if (type
== RD_TYPE_VNC_ETH
)
715 vty_out (vty
, "%u:%02x:%02x:%02x:%02x:%02x:%02x",
716 rd_vnc_eth
.local_nve_id
,
717 rd_vnc_eth
.macaddr
.octet
[0],
718 rd_vnc_eth
.macaddr
.octet
[1],
719 rd_vnc_eth
.macaddr
.octet
[2],
720 rd_vnc_eth
.macaddr
.octet
[3],
721 rd_vnc_eth
.macaddr
.octet
[4],
722 rd_vnc_eth
.macaddr
.octet
[5]);
724 vty_out (vty
, "%s", VTY_NEWLINE
);
729 route_vty_out_tag (vty
, &rm
->p
, ri
, 0, SAFI_MPLS_VPN
, json_array
);
731 route_vty_out (vty
, &rm
->p
, ri
, 0, SAFI_MPLS_VPN
, json_array
);
741 sprintf(buf_a
, "%s/%d", inet_ntop (p
->family
, &p
->u
.prefix
, buf_b
, BUFSIZ
), p
->prefixlen
);
742 json_object_object_add(json_mroute
, buf_a
, json_array
);
752 sprintf(buf_a
, "%s/%d", inet_ntop (p
->family
, &p
->u
.prefix
, buf_b
, BUFSIZ
), p
->prefixlen
);
753 json_object_object_add(json_nroute
, buf_a
, json_mroute
);
760 json_object_object_add(json
, "routes", json_nroute
);
761 vty_out (vty
, "%s%s", json_object_to_json_string_ext(json
, JSON_C_TO_STRING_PRETTY
), VTY_NEWLINE
);
762 json_object_free(json
);
766 if (output_count
== 0)
767 vty_out (vty
, "No prefixes displayed, %ld exist%s", total_count
, VTY_NEWLINE
);
769 vty_out (vty
, "%sDisplayed %ld routes and %ld total paths%s",
770 VTY_NEWLINE
, output_count
, total_count
, VTY_NEWLINE
);
776 DEFUN (show_bgp_ip_vpn_all_rd
,
777 show_bgp_ip_vpn_all_rd_cmd
,
778 "show bgp "BGP_AFI_CMD_STR
" vpn all [rd ASN:nn_or_IP-address:nn] [json]",
783 "Display VPN NLRI specific information\n"
784 "Display information for a route distinguisher\n"
785 "VPN Route Distinguisher\n"
790 struct prefix_rd prd
;
794 if (argv_find_and_parse_afi (argv
, argc
, &idx
, &afi
))
796 if (argc
>= 7 && argv
[idx_rd
]->arg
)
798 ret
= str2prefix_rd (argv
[idx_rd
]->arg
, &prd
);
801 vty_out (vty
, "%% Malformed Route Distinguisher%s", VTY_NEWLINE
);
804 return bgp_show_mpls_vpn (vty
, afi
, &prd
, bgp_show_type_normal
, NULL
, 0, use_json (argc
, argv
));
808 return bgp_show_mpls_vpn (vty
, afi
, NULL
, bgp_show_type_normal
, NULL
, 0, use_json (argc
, argv
));
814 DEFUN (show_ip_bgp_vpn_rd
,
815 show_ip_bgp_vpn_rd_cmd
,
816 "show [ip] bgp "BGP_AFI_CMD_STR
" vpn rd ASN:nn_or_IP-address:nn",
821 "Address Family modifier\n"
822 "Display information for a route distinguisher\n"
823 "VPN Route Distinguisher\n")
825 int idx_ext_community
= argc
-1;
827 struct prefix_rd prd
;
831 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
833 ret
= str2prefix_rd (argv
[idx_ext_community
]->arg
, &prd
);
836 vty_out (vty
, "%% Malformed Route Distinguisher%s", VTY_NEWLINE
);
839 return bgp_show_mpls_vpn (vty
, afi
, &prd
, bgp_show_type_normal
, NULL
, 0, 0);
844 #ifdef KEEP_OLD_VPN_COMMANDS
845 DEFUN (show_ip_bgp_vpn_all
,
846 show_ip_bgp_vpn_all_cmd
,
847 "show [ip] bgp <vpnv4|vpnv6>",
856 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
857 return bgp_show_mpls_vpn (vty
, afi
, NULL
, bgp_show_type_normal
, NULL
, 0, 0);
861 DEFUN (show_ip_bgp_vpn_all_tags
,
862 show_ip_bgp_vpn_all_tags_cmd
,
863 "show [ip] bgp <vpnv4|vpnv6> all tags",
868 "Display information about all VPNv4/VPNV6 NLRIs\n"
869 "Display BGP tags for prefixes\n")
874 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
875 return bgp_show_mpls_vpn (vty
, afi
, NULL
, bgp_show_type_normal
, NULL
, 1, 0);
879 DEFUN (show_ip_bgp_vpn_rd_tags
,
880 show_ip_bgp_vpn_rd_tags_cmd
,
881 "show [ip] bgp <vpnv4|vpnv6> rd ASN:nn_or_IP-address:nn tags",
886 "Display information for a route distinguisher\n"
887 "VPN Route Distinguisher\n"
888 "Display BGP tags for prefixes\n")
890 int idx_ext_community
= 5;
892 struct prefix_rd prd
;
896 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
898 ret
= str2prefix_rd (argv
[idx_ext_community
]->arg
, &prd
);
901 vty_out (vty
, "%% Malformed Route Distinguisher%s", VTY_NEWLINE
);
904 return bgp_show_mpls_vpn (vty
, afi
, &prd
, bgp_show_type_normal
, NULL
, 1, 0);
909 DEFUN (show_ip_bgp_vpn_all_neighbor_routes
,
910 show_ip_bgp_vpn_all_neighbor_routes_cmd
,
911 "show [ip] bgp <vpnv4|vpnv6> all neighbors A.B.C.D routes [json]",
916 "Display information about all VPNv4/VPNv6 NLRIs\n"
917 "Detailed information on TCP and BGP neighbor connections\n"
918 "Neighbor to display information about\n"
919 "Display routes learned from neighbor\n"
926 u_char uj
= use_json(argc
, argv
);
930 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
932 ret
= str2sockunion (argv
[idx_ipv4
]->arg
, &su
);
937 json_object
*json_no
= NULL
;
938 json_no
= json_object_new_object();
939 json_object_string_add(json_no
, "warning", "Malformed address");
940 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
941 json_object_free(json_no
);
944 vty_out (vty
, "Malformed address: %s%s", argv
[idx_ipv4
]->arg
, VTY_NEWLINE
);
948 peer
= peer_lookup (NULL
, &su
);
949 if (! peer
|| ! peer
->afc
[afi
][SAFI_MPLS_VPN
])
953 json_object
*json_no
= NULL
;
954 json_no
= json_object_new_object();
955 json_object_string_add(json_no
, "warning", "No such neighbor or address family");
956 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
957 json_object_free(json_no
);
960 vty_out (vty
, "%% No such neighbor or address family%s", VTY_NEWLINE
);
964 return bgp_show_mpls_vpn (vty
, afi
, NULL
, bgp_show_type_neighbor
, &su
, 0, uj
);
969 DEFUN (show_ip_bgp_vpn_rd_neighbor_routes
,
970 show_ip_bgp_vpn_rd_neighbor_routes_cmd
,
971 "show [ip] bgp <vpnv4|vpnv6> rd ASN:nn_or_IP-address:nn neighbors A.B.C.D routes [json]",
976 "Display information for a route distinguisher\n"
977 "VPN Route Distinguisher\n"
978 "Detailed information on TCP and BGP neighbor connections\n"
979 "Neighbor to display information about\n"
980 "Display routes learned from neighbor\n"
983 int idx_ext_community
= 5;
988 struct prefix_rd prd
;
989 u_char uj
= use_json(argc
, argv
);
993 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
995 ret
= str2prefix_rd (argv
[idx_ext_community
]->arg
, &prd
);
1000 json_object
*json_no
= NULL
;
1001 json_no
= json_object_new_object();
1002 json_object_string_add(json_no
, "warning", "Malformed Route Distinguisher");
1003 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
1004 json_object_free(json_no
);
1007 vty_out (vty
, "%% Malformed Route Distinguisher%s", VTY_NEWLINE
);
1011 ret
= str2sockunion (argv
[idx_ipv4
]->arg
, &su
);
1016 json_object
*json_no
= NULL
;
1017 json_no
= json_object_new_object();
1018 json_object_string_add(json_no
, "warning", "Malformed address");
1019 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
1020 json_object_free(json_no
);
1023 vty_out (vty
, "Malformed address: %s%s", argv
[idx_ext_community
]->arg
, VTY_NEWLINE
);
1027 peer
= peer_lookup (NULL
, &su
);
1028 if (! peer
|| ! peer
->afc
[afi
][SAFI_MPLS_VPN
])
1032 json_object
*json_no
= NULL
;
1033 json_no
= json_object_new_object();
1034 json_object_string_add(json_no
, "warning", "No such neighbor or address family");
1035 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
1036 json_object_free(json_no
);
1039 vty_out (vty
, "%% No such neighbor or address family%s", VTY_NEWLINE
);
1043 return bgp_show_mpls_vpn (vty
, afi
, &prd
, bgp_show_type_neighbor
, &su
, 0, uj
);
1048 DEFUN (show_ip_bgp_vpn_all_neighbor_advertised_routes
,
1049 show_ip_bgp_vpn_all_neighbor_advertised_routes_cmd
,
1050 "show [ip] bgp <vpnv4|vpnv6> all neighbors A.B.C.D advertised-routes [json]",
1055 "Display information about all VPNv4/VPNv6 NLRIs\n"
1056 "Detailed information on TCP and BGP neighbor connections\n"
1057 "Neighbor to display information about\n"
1058 "Display the routes advertised to a BGP neighbor\n"
1065 u_char uj
= use_json(argc
, argv
);
1069 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
1071 ret
= str2sockunion (argv
[idx_ipv4
]->arg
, &su
);
1076 json_object
*json_no
= NULL
;
1077 json_no
= json_object_new_object();
1078 json_object_string_add(json_no
, "warning", "Malformed address");
1079 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
1080 json_object_free(json_no
);
1083 vty_out (vty
, "Malformed address: %s%s", argv
[idx_ipv4
]->arg
, VTY_NEWLINE
);
1086 peer
= peer_lookup (NULL
, &su
);
1087 if (! peer
|| ! peer
->afc
[afi
][SAFI_MPLS_VPN
])
1091 json_object
*json_no
= NULL
;
1092 json_no
= json_object_new_object();
1093 json_object_string_add(json_no
, "warning", "No such neighbor or address family");
1094 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
1095 json_object_free(json_no
);
1098 vty_out (vty
, "%% No such neighbor or address family%s", VTY_NEWLINE
);
1101 return show_adj_route_vpn (vty
, peer
, NULL
, AFI_IP
, SAFI_MPLS_VPN
, uj
);
1106 DEFUN (show_ip_bgp_vpn_rd_neighbor_advertised_routes
,
1107 show_ip_bgp_vpn_rd_neighbor_advertised_routes_cmd
,
1108 "show [ip] bgp <vpnv4|vpnv6> rd ASN:nn_or_IP-address:nn neighbors A.B.C.D advertised-routes [json]",
1113 "Display information for a route distinguisher\n"
1114 "VPN Route Distinguisher\n"
1115 "Detailed information on TCP and BGP neighbor connections\n"
1116 "Neighbor to display information about\n"
1117 "Display the routes advertised to a BGP neighbor\n"
1120 int idx_ext_community
= 5;
1124 struct prefix_rd prd
;
1126 u_char uj
= use_json(argc
, argv
);
1130 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
1132 ret
= str2sockunion (argv
[idx_ipv4
]->arg
, &su
);
1137 json_object
*json_no
= NULL
;
1138 json_no
= json_object_new_object();
1139 json_object_string_add(json_no
, "warning", "Malformed address");
1140 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
1141 json_object_free(json_no
);
1144 vty_out (vty
, "Malformed address: %s%s", argv
[idx_ext_community
]->arg
, VTY_NEWLINE
);
1147 peer
= peer_lookup (NULL
, &su
);
1148 if (! peer
|| ! peer
->afc
[afi
][SAFI_MPLS_VPN
])
1152 json_object
*json_no
= NULL
;
1153 json_no
= json_object_new_object();
1154 json_object_string_add(json_no
, "warning", "No such neighbor or address family");
1155 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
1156 json_object_free(json_no
);
1159 vty_out (vty
, "%% No such neighbor or address family%s", VTY_NEWLINE
);
1163 ret
= str2prefix_rd (argv
[idx_ext_community
]->arg
, &prd
);
1168 json_object
*json_no
= NULL
;
1169 json_no
= json_object_new_object();
1170 json_object_string_add(json_no
, "warning", "Malformed Route Distinguisher");
1171 vty_out (vty
, "%s%s", json_object_to_json_string(json_no
), VTY_NEWLINE
);
1172 json_object_free(json_no
);
1175 vty_out (vty
, "%% Malformed Route Distinguisher%s", VTY_NEWLINE
);
1179 return show_adj_route_vpn (vty
, peer
, &prd
, AFI_IP
, SAFI_MPLS_VPN
, uj
);
1183 #endif /* KEEP_OLD_VPN_COMMANDS */
1186 bgp_mplsvpn_init (void)
1188 install_element (BGP_VPNV4_NODE
, &vpnv4_network_cmd
);
1189 install_element (BGP_VPNV4_NODE
, &vpnv4_network_route_map_cmd
);
1190 install_element (BGP_VPNV4_NODE
, &no_vpnv4_network_cmd
);
1192 install_element (BGP_VPNV6_NODE
, &vpnv6_network_cmd
);
1193 install_element (BGP_VPNV6_NODE
, &no_vpnv6_network_cmd
);
1195 install_element (VIEW_NODE
, &show_bgp_ip_vpn_all_rd_cmd
);
1196 install_element (VIEW_NODE
, &show_ip_bgp_vpn_rd_cmd
);
1197 #ifdef KEEP_OLD_VPN_COMMANDS
1198 install_element (VIEW_NODE
, &show_ip_bgp_vpn_all_cmd
);
1199 install_element (VIEW_NODE
, &show_ip_bgp_vpn_rd_cmd
);
1200 install_element (VIEW_NODE
, &show_ip_bgp_vpn_all_tags_cmd
);
1201 install_element (VIEW_NODE
, &show_ip_bgp_vpn_rd_tags_cmd
);
1202 install_element (VIEW_NODE
, &show_ip_bgp_vpn_all_neighbor_routes_cmd
);
1203 install_element (VIEW_NODE
, &show_ip_bgp_vpn_rd_neighbor_routes_cmd
);
1204 install_element (VIEW_NODE
, &show_ip_bgp_vpn_all_neighbor_advertised_routes_cmd
);
1205 install_element (VIEW_NODE
, &show_ip_bgp_vpn_rd_neighbor_advertised_routes_cmd
);
1206 #endif /* KEEP_OLD_VPN_COMMANDS */