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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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_label.h"
37 #include "bgpd/bgp_mplsvpn.h"
38 #include "bgpd/bgp_packet.h"
39 #include "bgpd/bgp_vty.h"
40 #include "bgpd/bgp_vpn.h"
43 #include "bgpd/rfapi/rfapi_backend.h"
47 argv_find_and_parse_vpnvx(struct cmd_token
**argv
, int argc
, int *index
, afi_t
*afi
)
50 if (argv_find (argv
, argc
, "vpnv4", index
))
56 else if (argv_find (argv
, argc
, "vpnv6", index
))
66 decode_rd_type (u_char
*pnt
)
70 v
= ((u_int16_t
) *pnt
++ << 8);
73 * VNC L2 stores LHI in lower byte, so omit it
75 if (v
!= RD_TYPE_VNC_ETH
)
76 v
|= (u_int16_t
) *pnt
;
77 #else /* duplicate code for clarity */
78 v
|= (u_int16_t
) *pnt
;
85 encode_rd_type (u_int16_t v
, u_char
*pnt
)
87 *((u_int16_t
*)pnt
) = htons(v
);
91 decode_label (mpls_label_t
*label_pnt
)
94 u_char
*pnt
= (u_char
*) label_pnt
;
96 l
= ((u_int32_t
) *pnt
++ << 12);
97 l
|= (u_int32_t
) *pnt
++ << 4;
98 l
|= (u_int32_t
) ((*pnt
& 0xf0) >> 4);
103 encode_label(mpls_label_t label
,
104 mpls_label_t
*label_pnt
)
106 u_char
*pnt
= (u_char
*) label_pnt
;
109 *pnt
++ = (label
>>12) & 0xff;
110 *pnt
++ = (label
>>4) & 0xff;
111 *pnt
++ = ((label
<<4)+1) & 0xff; /* S=1 */
114 /* type == RD_TYPE_AS */
116 decode_rd_as (u_char
*pnt
, struct rd_as
*rd_as
)
118 rd_as
->as
= (u_int16_t
) *pnt
++ << 8;
119 rd_as
->as
|= (u_int16_t
) *pnt
++;
121 rd_as
->val
= ((u_int32_t
) *pnt
++ << 24);
122 rd_as
->val
|= ((u_int32_t
) *pnt
++ << 16);
123 rd_as
->val
|= ((u_int32_t
) *pnt
++ << 8);
124 rd_as
->val
|= (u_int32_t
) *pnt
;
127 /* type == RD_TYPE_AS4 */
129 decode_rd_as4 (u_char
*pnt
, struct rd_as
*rd_as
)
131 rd_as
->as
= (u_int32_t
) *pnt
++ << 24;
132 rd_as
->as
|= (u_int32_t
) *pnt
++ << 16;
133 rd_as
->as
|= (u_int32_t
) *pnt
++ << 8;
134 rd_as
->as
|= (u_int32_t
) *pnt
++;
136 rd_as
->val
= ((u_int16_t
) *pnt
++ << 8);
137 rd_as
->val
|= (u_int16_t
) *pnt
;
140 /* type == RD_TYPE_IP */
142 decode_rd_ip (u_char
*pnt
, struct rd_ip
*rd_ip
)
144 memcpy (&rd_ip
->ip
, pnt
, 4);
147 rd_ip
->val
= ((u_int16_t
) *pnt
++ << 8);
148 rd_ip
->val
|= (u_int16_t
) *pnt
;
152 /* type == RD_TYPE_VNC_ETH */
154 decode_rd_vnc_eth (u_char
*pnt
, struct rd_vnc_eth
*rd_vnc_eth
)
156 rd_vnc_eth
->type
= RD_TYPE_VNC_ETH
;
157 rd_vnc_eth
->local_nve_id
= pnt
[1];
158 memcpy (rd_vnc_eth
->macaddr
.octet
, pnt
+ 2, ETHER_ADDR_LEN
);
163 bgp_nlri_parse_vpn (struct peer
*peer
, struct attr
*attr
,
164 struct bgp_nlri
*packet
)
174 struct prefix_rd prd
;
179 u_int32_t addpath_id
;
181 /* Check peer status. */
182 if (peer
->status
!= Established
)
186 prd
.family
= AF_UNSPEC
;
190 lim
= pnt
+ packet
->length
;
195 addpath_encoded
= (CHECK_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ADDPATH_AF_RX_ADV
) &&
196 CHECK_FLAG (peer
->af_cap
[afi
][safi
], PEER_CAP_ADDPATH_AF_TX_RCV
));
198 #define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
199 for (; pnt
< lim
; pnt
+= psize
)
201 /* Clear prefix structure. */
202 memset (&p
, 0, sizeof (struct prefix
));
207 /* When packet overflow occurs return immediately. */
208 if (pnt
+ BGP_ADDPATH_ID_LEN
> lim
)
211 addpath_id
= ntohl(*((uint32_t*) pnt
));
212 pnt
+= BGP_ADDPATH_ID_LEN
;
215 /* Fetch prefix length. */
217 p
.family
= afi2family (packet
->afi
);
218 psize
= PSIZE (prefixlen
);
220 if (prefixlen
< VPN_PREFIXLEN_MIN_BYTES
*8)
222 zlog_err ("%s [Error] Update packet error / VPN (prefix length %d less than VPN min length)",
223 peer
->host
, prefixlen
);
227 /* sanity check against packet data */
228 if ((pnt
+ psize
) > lim
)
230 zlog_err ("%s [Error] Update packet error / VPN (prefix length %d exceeds packet size %u)",
232 prefixlen
, (uint
)(lim
-pnt
));
236 /* sanity check against storage for the IP address portion */
237 if ((psize
- VPN_PREFIXLEN_MIN_BYTES
) > (ssize_t
) sizeof(p
.u
))
239 zlog_err ("%s [Error] Update packet error / VPN (psize %d exceeds storage size %zu)",
241 prefixlen
- VPN_PREFIXLEN_MIN_BYTES
*8, sizeof(p
.u
));
245 /* Sanity check against max bitlen of the address family */
246 if ((psize
- VPN_PREFIXLEN_MIN_BYTES
) > prefix_blen (&p
))
248 zlog_err ("%s [Error] Update packet error / VPN (psize %d exceeds family (%u) max byte len %u)",
250 prefixlen
- VPN_PREFIXLEN_MIN_BYTES
*8,
251 p
.family
, prefix_blen (&p
));
255 /* Copy label to prefix. */
256 memcpy(&label
, pnt
, BGP_LABEL_BYTES
);
257 bgp_set_valid_label(&label
);
259 /* Copy routing distinguisher to rd. */
260 memcpy (&prd
.val
, pnt
+ BGP_LABEL_BYTES
, 8);
262 /* Decode RD type. */
263 type
= decode_rd_type (pnt
+ BGP_LABEL_BYTES
);
268 decode_rd_as (pnt
+ 5, &rd_as
);
272 decode_rd_as4 (pnt
+ 5, &rd_as
);
276 decode_rd_ip (pnt
+ 5, &rd_ip
);
280 case RD_TYPE_VNC_ETH
:
285 zlog_err ("Unknown RD type %d", type
);
286 break; /* just report */
289 p
.prefixlen
= prefixlen
- VPN_PREFIXLEN_MIN_BYTES
*8;/* exclude label & RD */
290 memcpy (&p
.u
.prefix
, pnt
+ VPN_PREFIXLEN_MIN_BYTES
,
291 psize
- VPN_PREFIXLEN_MIN_BYTES
);
295 bgp_update (peer
, &p
, addpath_id
, attr
, packet
->afi
, SAFI_MPLS_VPN
,
296 ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
, &label
, 0, NULL
);
300 bgp_withdraw (peer
, &p
, addpath_id
, attr
, packet
->afi
, SAFI_MPLS_VPN
,
301 ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
, &label
, NULL
);
304 /* Packet length consistency check. */
307 zlog_err ("%s [Error] Update packet error / VPN (%zu data remaining after parsing)",
308 peer
->host
, lim
- pnt
);
313 #undef VPN_PREFIXLEN_MIN_BYTES
317 str2prefix_rd (const char *str
, struct prefix_rd
*prd
)
319 int ret
; /* ret of called functions */
320 int lret
; /* local ret, of this func */
323 struct stream
*s
= NULL
;
329 prd
->family
= AF_UNSPEC
;
333 p
= strchr (str
, ':');
337 if (! all_digit (p
+ 1))
340 half
= XMALLOC (MTYPE_TMP
, (p
- str
) + 1);
341 memcpy (half
, str
, (p
- str
));
342 half
[p
- str
] = '\0';
344 p2
= strchr (str
, '.');
348 unsigned long as_val
;
350 if (! all_digit (half
))
356 stream_putw (s
, RD_TYPE_AS4
);
357 stream_putl (s
, as_val
);
358 stream_putw (s
, atol (p
+ 1));
362 stream_putw (s
, RD_TYPE_AS
);
363 stream_putw (s
, as_val
);
364 stream_putl (s
, atol (p
+ 1));
369 ret
= inet_aton (half
, &addr
);
373 stream_putw (s
, RD_TYPE_IP
);
374 stream_put_in_addr (s
, &addr
);
375 stream_putw (s
, atol (p
+ 1));
377 memcpy (prd
->val
, s
->data
, 8);
384 XFREE(MTYPE_TMP
, half
);
389 prefix_rd2str (struct prefix_rd
*prd
, char *buf
, size_t size
)
396 if (size
< RD_ADDRSTRLEN
)
401 type
= decode_rd_type (pnt
);
403 if (type
== RD_TYPE_AS
)
405 decode_rd_as (pnt
+ 2, &rd_as
);
406 snprintf (buf
, size
, "%u:%d", rd_as
.as
, rd_as
.val
);
409 else if (type
== RD_TYPE_AS4
)
411 decode_rd_as4 (pnt
+ 2, &rd_as
);
412 snprintf (buf
, size
, "%u:%d", rd_as
.as
, rd_as
.val
);
415 else if (type
== RD_TYPE_IP
)
417 decode_rd_ip (pnt
+ 2, &rd_ip
);
418 snprintf (buf
, size
, "%s:%d", inet_ntoa (rd_ip
.ip
), rd_ip
.val
);
422 else if (type
== RD_TYPE_VNC_ETH
)
424 snprintf(buf
, size
, "LHI:%d, %02x:%02x:%02x:%02x:%02x:%02x",
426 *(pnt
+2), /* MAC[0] */
439 /* For testing purpose, static route of MPLS-VPN. */
440 DEFUN (vpnv4_network
,
442 "network A.B.C.D/M rd ASN:nn_or_IP-address:nn <tag|label> (0-1048575)",
443 "Specify a network to announce via BGP\n"
445 "Specify Route Distinguisher\n"
446 "VPN Route Distinguisher\n"
447 "VPN NLRI label (tag)\n"
448 "VPN NLRI label (tag)\n"
451 int idx_ipv4_prefixlen
= 1;
452 int idx_ext_community
= 3;
454 return bgp_static_set_safi (AFI_IP
, SAFI_MPLS_VPN
, vty
, argv
[idx_ipv4_prefixlen
]->arg
, argv
[idx_ext_community
]->arg
,
455 argv
[idx_label
]->arg
, NULL
, 0, NULL
, NULL
, NULL
, NULL
);
458 DEFUN (vpnv4_network_route_map
,
459 vpnv4_network_route_map_cmd
,
460 "network A.B.C.D/M rd ASN:nn_or_IP-address:nn <tag|label> (0-1048575) route-map WORD",
461 "Specify a network to announce via BGP\n"
463 "Specify Route Distinguisher\n"
464 "VPN Route Distinguisher\n"
465 "VPN NLRI label (tag)\n"
466 "VPN NLRI label (tag)\n"
471 int idx_ipv4_prefixlen
= 1;
472 int idx_ext_community
= 3;
475 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
,
476 argv
[idx_word_2
]->arg
, 0, NULL
, NULL
, NULL
, NULL
);
479 /* For testing purpose, static route of MPLS-VPN. */
480 DEFUN (no_vpnv4_network
,
481 no_vpnv4_network_cmd
,
482 "no network A.B.C.D/M rd ASN:nn_or_IP-address:nn <tag|label> (0-1048575)",
484 "Specify a network to announce via BGP\n"
486 "Specify Route Distinguisher\n"
487 "VPN Route Distinguisher\n"
488 "VPN NLRI label (tag)\n"
489 "VPN NLRI label (tag)\n"
492 int idx_ipv4_prefixlen
= 2;
493 int idx_ext_community
= 4;
495 return bgp_static_unset_safi (AFI_IP
, SAFI_MPLS_VPN
, vty
, argv
[idx_ipv4_prefixlen
]->arg
,
496 argv
[idx_ext_community
]->arg
, argv
[idx_label
]->arg
,
497 0, NULL
, NULL
, NULL
);
500 DEFUN (vpnv6_network
,
502 "network X:X::X:X/M rd ASN:nn_or_IP-address:nn <tag|label> (0-1048575) [route-map WORD]",
503 "Specify a network to announce via BGP\n"
504 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
505 "Specify Route Distinguisher\n"
506 "VPN Route Distinguisher\n"
507 "VPN NLRI label (tag)\n"
508 "VPN NLRI label (tag)\n"
513 int idx_ipv6_prefix
= 1;
514 int idx_ext_community
= 3;
518 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
);
520 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
);
523 /* For testing purpose, static route of MPLS-VPN. */
524 DEFUN (no_vpnv6_network
,
525 no_vpnv6_network_cmd
,
526 "no network X:X::X:X/M rd ASN:nn_or_IP-address:nn <tag|label> (0-1048575)",
528 "Specify a network to announce via BGP\n"
529 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
530 "Specify Route Distinguisher\n"
531 "VPN Route Distinguisher\n"
532 "VPN NLRI label (tag)\n"
533 "VPN NLRI label (tag)\n"
536 int idx_ipv6_prefix
= 2;
537 int idx_ext_community
= 4;
539 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
);
543 bgp_show_mpls_vpn (struct vty
*vty
, afi_t afi
, struct prefix_rd
*prd
,
544 enum bgp_show_type type
, void *output_arg
, int tags
, u_char use_json
)
547 struct bgp_table
*table
;
553 unsigned long output_count
= 0;
554 unsigned long total_count
= 0;
555 json_object
*json
= NULL
;
556 json_object
*json_mroute
= NULL
;
557 json_object
*json_nroute
= NULL
;
558 json_object
*json_array
= NULL
;
559 json_object
*json_scode
= NULL
;
560 json_object
*json_ocode
= NULL
;
562 bgp
= bgp_get_default ();
566 vty_outln (vty
, "No BGP process is configured");
572 json_scode
= json_object_new_object();
573 json_ocode
= json_object_new_object();
574 json
= json_object_new_object();
575 json_mroute
= json_object_new_object();
576 json_nroute
= json_object_new_object();
578 json_object_string_add(json_scode
, "suppressed", "s");
579 json_object_string_add(json_scode
, "damped", "d");
580 json_object_string_add(json_scode
, "history", "h");
581 json_object_string_add(json_scode
, "valid", "*");
582 json_object_string_add(json_scode
, "best", ">");
583 json_object_string_add(json_scode
, "internal", "i");
585 json_object_string_add(json_ocode
, "igp", "i");
586 json_object_string_add(json_ocode
, "egp", "e");
587 json_object_string_add(json_ocode
, "incomplete", "?");
590 if ((afi
!= AFI_IP
) && (afi
!= AFI_IP6
))
592 vty_outln (vty
, "Afi %d not supported", afi
);
596 for (rn
= bgp_table_top (bgp
->rib
[afi
][SAFI_MPLS_VPN
]); rn
; rn
= bgp_route_next (rn
))
598 if (prd
&& memcmp (rn
->p
.u
.val
, prd
->val
, 8) != 0)
601 if ((table
= rn
->info
) != NULL
)
605 for (rm
= bgp_table_top (table
); rm
; rm
= bgp_route_next (rm
))
609 json_array
= json_object_new_array();
613 for (ri
= rm
->info
; ri
; ri
= ri
->next
)
615 if (type
== bgp_show_type_neighbor
)
617 union sockunion
*su
= output_arg
;
619 if (ri
->peer
->su_remote
== NULL
|| ! sockunion_same(ri
->peer
->su_remote
, su
))
628 json_object_int_add(json
, "bgpTableVersion", 0);
629 json_object_string_add(json
, "bgpLocalRouterId", inet_ntoa (bgp
->router_id
));
630 json_object_object_add(json
, "bgpStatusCodes", json_scode
);
631 json_object_object_add(json
, "bgpOriginCodes", json_ocode
);
637 vty_outln (vty
, V4_HEADER_TAG
);
640 vty_outln (vty
, "BGP table version is 0, local router ID is %s",
641 inet_ntoa(bgp
->router_id
));
643 "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal");
644 vty_outln (vty
, "Origin codes: i - IGP, e - EGP, ? - incomplete%s",
646 vty_outln (vty
, V4_HEADER
);
656 struct rd_ip rd_ip
= {0};
658 struct rd_vnc_eth rd_vnc_eth
= {0};
664 /* Decode RD type. */
665 type
= decode_rd_type (pnt
);
666 /* Decode RD value. */
667 if (type
== RD_TYPE_AS
)
668 decode_rd_as (pnt
+ 2, &rd_as
);
669 else if (type
== RD_TYPE_AS4
)
670 decode_rd_as4 (pnt
+ 2, &rd_as
);
671 else if (type
== RD_TYPE_IP
)
672 decode_rd_ip (pnt
+ 2, &rd_ip
);
674 else if (type
== RD_TYPE_VNC_ETH
)
675 decode_rd_vnc_eth (pnt
, &rd_vnc_eth
);
681 if (type
== RD_TYPE_AS
|| type
== RD_TYPE_AS4
)
682 sprintf (buffer
, "%u:%d", rd_as
.as
, rd_as
.val
);
683 else if (type
== RD_TYPE_IP
)
684 sprintf (buffer
, "%s:%d", inet_ntoa (rd_ip
.ip
), rd_ip
.val
);
685 json_object_string_add(json_nroute
, "routeDistinguisher", buffer
);
689 vty_out (vty
, "Route Distinguisher: ");
691 if (type
== RD_TYPE_AS
|| type
== RD_TYPE_AS4
)
692 vty_out (vty
, "%u:%d", rd_as
.as
, rd_as
.val
);
693 else if (type
== RD_TYPE_IP
)
694 vty_out (vty
, "%s:%d", inet_ntoa (rd_ip
.ip
), rd_ip
.val
);
696 else if (type
== RD_TYPE_VNC_ETH
)
697 vty_out (vty
, "%u:%02x:%02x:%02x:%02x:%02x:%02x",
698 rd_vnc_eth
.local_nve_id
,
699 rd_vnc_eth
.macaddr
.octet
[0],
700 rd_vnc_eth
.macaddr
.octet
[1],
701 rd_vnc_eth
.macaddr
.octet
[2],
702 rd_vnc_eth
.macaddr
.octet
[3],
703 rd_vnc_eth
.macaddr
.octet
[4],
704 rd_vnc_eth
.macaddr
.octet
[5]);
706 vty_out (vty
, VTYNL
);
711 route_vty_out_tag (vty
, &rm
->p
, ri
, 0, SAFI_MPLS_VPN
, json_array
);
713 route_vty_out (vty
, &rm
->p
, ri
, 0, SAFI_MPLS_VPN
, json_array
);
723 sprintf(buf_a
, "%s/%d", inet_ntop (p
->family
, &p
->u
.prefix
, buf_b
, BUFSIZ
), p
->prefixlen
);
724 json_object_object_add(json_mroute
, buf_a
, json_array
);
734 sprintf(buf_a
, "%s/%d", inet_ntop (p
->family
, &p
->u
.prefix
, buf_b
, BUFSIZ
), p
->prefixlen
);
735 json_object_object_add(json_nroute
, buf_a
, json_mroute
);
742 json_object_object_add(json
, "routes", json_nroute
);
743 vty_outln (vty
, "%s",
744 json_object_to_json_string_ext(json
, JSON_C_TO_STRING_PRETTY
));
745 json_object_free(json
);
749 if (output_count
== 0)
750 vty_outln (vty
, "No prefixes displayed, %ld exist", total_count
);
752 vty_outln (vty
, "%sDisplayed %ld routes and %ld total paths",
753 VTYNL
, output_count
, total_count
);
759 DEFUN (show_bgp_ip_vpn_all_rd
,
760 show_bgp_ip_vpn_all_rd_cmd
,
761 "show bgp "BGP_AFI_CMD_STR
" vpn all [rd ASN:nn_or_IP-address:nn] [json]",
766 "Display VPN NLRI specific information\n"
767 "Display information for a route distinguisher\n"
768 "VPN Route Distinguisher\n"
773 struct prefix_rd prd
;
777 if (argv_find_and_parse_afi (argv
, argc
, &idx
, &afi
))
779 if (argc
>= 7 && argv
[idx_rd
]->arg
)
781 ret
= str2prefix_rd (argv
[idx_rd
]->arg
, &prd
);
784 vty_outln (vty
, "%% Malformed Route Distinguisher");
787 return bgp_show_mpls_vpn (vty
, afi
, &prd
, bgp_show_type_normal
, NULL
, 0, use_json (argc
, argv
));
791 return bgp_show_mpls_vpn (vty
, afi
, NULL
, bgp_show_type_normal
, NULL
, 0, use_json (argc
, argv
));
797 DEFUN (show_ip_bgp_vpn_rd
,
798 show_ip_bgp_vpn_rd_cmd
,
799 "show [ip] bgp "BGP_AFI_CMD_STR
" vpn rd ASN:nn_or_IP-address:nn",
804 "Address Family modifier\n"
805 "Display information for a route distinguisher\n"
806 "VPN Route Distinguisher\n")
808 int idx_ext_community
= argc
-1;
810 struct prefix_rd prd
;
814 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
816 ret
= str2prefix_rd (argv
[idx_ext_community
]->arg
, &prd
);
819 vty_outln (vty
, "%% Malformed Route Distinguisher");
822 return bgp_show_mpls_vpn (vty
, afi
, &prd
, bgp_show_type_normal
, NULL
, 0, 0);
827 #ifdef KEEP_OLD_VPN_COMMANDS
828 DEFUN (show_ip_bgp_vpn_all
,
829 show_ip_bgp_vpn_all_cmd
,
830 "show [ip] bgp <vpnv4|vpnv6>",
839 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
840 return bgp_show_mpls_vpn (vty
, afi
, NULL
, bgp_show_type_normal
, NULL
, 0, 0);
844 DEFUN (show_ip_bgp_vpn_all_tags
,
845 show_ip_bgp_vpn_all_tags_cmd
,
846 "show [ip] bgp <vpnv4|vpnv6> all tags",
851 "Display information about all VPNv4/VPNV6 NLRIs\n"
852 "Display BGP tags for prefixes\n")
857 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
858 return bgp_show_mpls_vpn (vty
, afi
, NULL
, bgp_show_type_normal
, NULL
, 1, 0);
862 DEFUN (show_ip_bgp_vpn_rd_tags
,
863 show_ip_bgp_vpn_rd_tags_cmd
,
864 "show [ip] bgp <vpnv4|vpnv6> rd ASN:nn_or_IP-address:nn tags",
869 "Display information for a route distinguisher\n"
870 "VPN Route Distinguisher\n"
871 "Display BGP tags for prefixes\n")
873 int idx_ext_community
= 5;
875 struct prefix_rd prd
;
879 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
881 ret
= str2prefix_rd (argv
[idx_ext_community
]->arg
, &prd
);
884 vty_outln (vty
, "%% Malformed Route Distinguisher");
887 return bgp_show_mpls_vpn (vty
, afi
, &prd
, bgp_show_type_normal
, NULL
, 1, 0);
892 DEFUN (show_ip_bgp_vpn_all_neighbor_routes
,
893 show_ip_bgp_vpn_all_neighbor_routes_cmd
,
894 "show [ip] bgp <vpnv4|vpnv6> all neighbors A.B.C.D routes [json]",
899 "Display information about all VPNv4/VPNv6 NLRIs\n"
900 "Detailed information on TCP and BGP neighbor connections\n"
901 "Neighbor to display information about\n"
902 "Display routes learned from neighbor\n"
909 u_char uj
= use_json(argc
, argv
);
913 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
915 ret
= str2sockunion (argv
[idx_ipv4
]->arg
, &su
);
920 json_object
*json_no
= NULL
;
921 json_no
= json_object_new_object();
922 json_object_string_add(json_no
, "warning", "Malformed address");
923 vty_outln (vty
, "%s", json_object_to_json_string(json_no
));
924 json_object_free(json_no
);
927 vty_outln (vty
, "Malformed address: %s", argv
[idx_ipv4
]->arg
);
931 peer
= peer_lookup (NULL
, &su
);
932 if (! peer
|| ! peer
->afc
[afi
][SAFI_MPLS_VPN
])
936 json_object
*json_no
= NULL
;
937 json_no
= json_object_new_object();
938 json_object_string_add(json_no
, "warning", "No such neighbor or address family");
939 vty_outln (vty
, "%s", json_object_to_json_string(json_no
));
940 json_object_free(json_no
);
943 vty_outln (vty
, "%% No such neighbor or address family");
947 return bgp_show_mpls_vpn (vty
, afi
, NULL
, bgp_show_type_neighbor
, &su
, 0, uj
);
952 DEFUN (show_ip_bgp_vpn_rd_neighbor_routes
,
953 show_ip_bgp_vpn_rd_neighbor_routes_cmd
,
954 "show [ip] bgp <vpnv4|vpnv6> rd ASN:nn_or_IP-address:nn neighbors A.B.C.D routes [json]",
959 "Display information for a route distinguisher\n"
960 "VPN Route Distinguisher\n"
961 "Detailed information on TCP and BGP neighbor connections\n"
962 "Neighbor to display information about\n"
963 "Display routes learned from neighbor\n"
966 int idx_ext_community
= 5;
971 struct prefix_rd prd
;
972 u_char uj
= use_json(argc
, argv
);
976 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
978 ret
= str2prefix_rd (argv
[idx_ext_community
]->arg
, &prd
);
983 json_object
*json_no
= NULL
;
984 json_no
= json_object_new_object();
985 json_object_string_add(json_no
, "warning", "Malformed Route Distinguisher");
986 vty_outln (vty
, "%s", json_object_to_json_string(json_no
));
987 json_object_free(json_no
);
990 vty_outln (vty
, "%% Malformed Route Distinguisher");
994 ret
= str2sockunion (argv
[idx_ipv4
]->arg
, &su
);
999 json_object
*json_no
= NULL
;
1000 json_no
= json_object_new_object();
1001 json_object_string_add(json_no
, "warning", "Malformed address");
1002 vty_outln (vty
, "%s", json_object_to_json_string(json_no
));
1003 json_object_free(json_no
);
1006 vty_outln (vty
, "Malformed address: %s",
1007 argv
[idx_ext_community
]->arg
);
1011 peer
= peer_lookup (NULL
, &su
);
1012 if (! peer
|| ! peer
->afc
[afi
][SAFI_MPLS_VPN
])
1016 json_object
*json_no
= NULL
;
1017 json_no
= json_object_new_object();
1018 json_object_string_add(json_no
, "warning", "No such neighbor or address family");
1019 vty_outln (vty
, "%s", json_object_to_json_string(json_no
));
1020 json_object_free(json_no
);
1023 vty_outln (vty
, "%% No such neighbor or address family");
1027 return bgp_show_mpls_vpn (vty
, afi
, &prd
, bgp_show_type_neighbor
, &su
, 0, uj
);
1032 DEFUN (show_ip_bgp_vpn_all_neighbor_advertised_routes
,
1033 show_ip_bgp_vpn_all_neighbor_advertised_routes_cmd
,
1034 "show [ip] bgp <vpnv4|vpnv6> all neighbors A.B.C.D advertised-routes [json]",
1039 "Display information about all VPNv4/VPNv6 NLRIs\n"
1040 "Detailed information on TCP and BGP neighbor connections\n"
1041 "Neighbor to display information about\n"
1042 "Display the routes advertised to a BGP neighbor\n"
1049 u_char uj
= use_json(argc
, argv
);
1053 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
1055 ret
= str2sockunion (argv
[idx_ipv4
]->arg
, &su
);
1060 json_object
*json_no
= NULL
;
1061 json_no
= json_object_new_object();
1062 json_object_string_add(json_no
, "warning", "Malformed address");
1063 vty_outln (vty
, "%s", json_object_to_json_string(json_no
));
1064 json_object_free(json_no
);
1067 vty_outln (vty
, "Malformed address: %s", argv
[idx_ipv4
]->arg
);
1070 peer
= peer_lookup (NULL
, &su
);
1071 if (! peer
|| ! peer
->afc
[afi
][SAFI_MPLS_VPN
])
1075 json_object
*json_no
= NULL
;
1076 json_no
= json_object_new_object();
1077 json_object_string_add(json_no
, "warning", "No such neighbor or address family");
1078 vty_outln (vty
, "%s", json_object_to_json_string(json_no
));
1079 json_object_free(json_no
);
1082 vty_outln (vty
, "%% No such neighbor or address family");
1085 return show_adj_route_vpn (vty
, peer
, NULL
, AFI_IP
, SAFI_MPLS_VPN
, uj
);
1090 DEFUN (show_ip_bgp_vpn_rd_neighbor_advertised_routes
,
1091 show_ip_bgp_vpn_rd_neighbor_advertised_routes_cmd
,
1092 "show [ip] bgp <vpnv4|vpnv6> rd ASN:nn_or_IP-address:nn neighbors A.B.C.D advertised-routes [json]",
1097 "Display information for a route distinguisher\n"
1098 "VPN Route Distinguisher\n"
1099 "Detailed information on TCP and BGP neighbor connections\n"
1100 "Neighbor to display information about\n"
1101 "Display the routes advertised to a BGP neighbor\n"
1104 int idx_ext_community
= 5;
1108 struct prefix_rd prd
;
1110 u_char uj
= use_json(argc
, argv
);
1114 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
1116 ret
= str2sockunion (argv
[idx_ipv4
]->arg
, &su
);
1121 json_object
*json_no
= NULL
;
1122 json_no
= json_object_new_object();
1123 json_object_string_add(json_no
, "warning", "Malformed address");
1124 vty_outln (vty
, "%s", json_object_to_json_string(json_no
));
1125 json_object_free(json_no
);
1128 vty_outln (vty
, "Malformed address: %s",
1129 argv
[idx_ext_community
]->arg
);
1132 peer
= peer_lookup (NULL
, &su
);
1133 if (! peer
|| ! peer
->afc
[afi
][SAFI_MPLS_VPN
])
1137 json_object
*json_no
= NULL
;
1138 json_no
= json_object_new_object();
1139 json_object_string_add(json_no
, "warning", "No such neighbor or address family");
1140 vty_outln (vty
, "%s", json_object_to_json_string(json_no
));
1141 json_object_free(json_no
);
1144 vty_outln (vty
, "%% No such neighbor or address family");
1148 ret
= str2prefix_rd (argv
[idx_ext_community
]->arg
, &prd
);
1153 json_object
*json_no
= NULL
;
1154 json_no
= json_object_new_object();
1155 json_object_string_add(json_no
, "warning", "Malformed Route Distinguisher");
1156 vty_outln (vty
, "%s", json_object_to_json_string(json_no
));
1157 json_object_free(json_no
);
1160 vty_outln (vty
, "%% Malformed Route Distinguisher");
1164 return show_adj_route_vpn (vty
, peer
, &prd
, AFI_IP
, SAFI_MPLS_VPN
, uj
);
1168 #endif /* KEEP_OLD_VPN_COMMANDS */
1171 bgp_mplsvpn_init (void)
1173 install_element (BGP_VPNV4_NODE
, &vpnv4_network_cmd
);
1174 install_element (BGP_VPNV4_NODE
, &vpnv4_network_route_map_cmd
);
1175 install_element (BGP_VPNV4_NODE
, &no_vpnv4_network_cmd
);
1177 install_element (BGP_VPNV6_NODE
, &vpnv6_network_cmd
);
1178 install_element (BGP_VPNV6_NODE
, &no_vpnv6_network_cmd
);
1180 install_element (VIEW_NODE
, &show_bgp_ip_vpn_all_rd_cmd
);
1181 install_element (VIEW_NODE
, &show_ip_bgp_vpn_rd_cmd
);
1182 #ifdef KEEP_OLD_VPN_COMMANDS
1183 install_element (VIEW_NODE
, &show_ip_bgp_vpn_all_cmd
);
1184 install_element (VIEW_NODE
, &show_ip_bgp_vpn_all_tags_cmd
);
1185 install_element (VIEW_NODE
, &show_ip_bgp_vpn_rd_tags_cmd
);
1186 install_element (VIEW_NODE
, &show_ip_bgp_vpn_all_neighbor_routes_cmd
);
1187 install_element (VIEW_NODE
, &show_ip_bgp_vpn_rd_neighbor_routes_cmd
);
1188 install_element (VIEW_NODE
, &show_ip_bgp_vpn_all_neighbor_advertised_routes_cmd
);
1189 install_element (VIEW_NODE
, &show_ip_bgp_vpn_rd_neighbor_advertised_routes_cmd
);
1190 #endif /* KEEP_OLD_VPN_COMMANDS */