From 798c3572a010467156107005bc992ce4f9d81f8a Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 27 Apr 2017 11:00:25 -0400 Subject: [PATCH 1/8] bgpd: Modify 'show ... bgp ... summary' to only display pertinent info Modify the 'show ... bgp ... summary' command when you are looking at a afi( with no safi specified ) to only display output for those safi's that have been configured. Signed-off-by: Donald Sharp --- bgpd/bgp_vty.c | 57 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index e94de682d5..bb99982528 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -6692,6 +6692,27 @@ bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi, return CMD_SUCCESS; } +/* + * Return if we have a peer configured to use this afi/safi + */ +static int +bgp_show_summary_afi_safi_peer_exists (struct bgp *bgp, int afi, int safi) +{ + struct listnode *node; + struct peer *peer; + + for (ALL_LIST_ELEMENTS_RO (bgp->peer, node, peer)) + { + if (!CHECK_FLAG (peer->flags, PEER_FLAG_CONFIG_NODE)) + continue; + + if (peer->afc[afi][safi]) + return 1; + } + + return 0; +} + static void bgp_show_summary_afi_safi (struct vty *vty, struct bgp *bgp, int afi, int safi, u_char use_json, json_object *json) @@ -6700,6 +6721,7 @@ bgp_show_summary_afi_safi (struct vty *vty, struct bgp *bgp, int afi, int safi, int afi_wildcard = (afi == AFI_MAX); int safi_wildcard = (safi == SAFI_MAX); int is_wildcard = (afi_wildcard || safi_wildcard); + if (use_json && is_wildcard) vty_out (vty, "{%s", VTY_NEWLINE); if (afi_wildcard) @@ -6710,26 +6732,33 @@ bgp_show_summary_afi_safi (struct vty *vty, struct bgp *bgp, int afi, int safi, safi = 1; /* SAFI_UNICAST */ while (safi < SAFI_MAX) { - if (is_wildcard) + if (bgp_show_summary_afi_safi_peer_exists (bgp, afi, safi)) { - if (use_json) + if (is_wildcard) { - json = json_object_new_object(); + /* + * So limit output to those afi/safi pairs that + * actualy have something interesting in them + */ + if (use_json) + { + json = json_object_new_object(); - if (! is_first) - vty_out (vty, ",%s", VTY_NEWLINE); + if (! is_first) + vty_out (vty, ",%s", VTY_NEWLINE); + else + is_first = 0; + + vty_out(vty, "\"%s\":", afi_safi_json(afi, safi)); + } else - is_first = 0; - - vty_out(vty, "\"%s\":", afi_safi_json(afi, safi)); - } - else - { - vty_out (vty, "%s%s Summary:%s", - VTY_NEWLINE, afi_safi_print(afi, safi), VTY_NEWLINE); + { + vty_out (vty, "%s%s Summary:%s", + VTY_NEWLINE, afi_safi_print(afi, safi), VTY_NEWLINE); + } } + bgp_show_summary (vty, bgp, afi, safi, use_json, json); } - bgp_show_summary (vty, bgp, afi, safi, use_json, json); safi++; if (safi == SAFI_RESERVED_4 || safi == SAFI_RESERVED_5) /* handle special cases to match zebra.h */ From b9f77ec810963d3d45df000e4f6631c14e21ef5d Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 27 Apr 2017 11:03:25 -0400 Subject: [PATCH 2/8] bgpd: Make json output to be camelCase Signed-off-by: Donald Sharp --- bgpd/bgp_vty.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index bb99982528..5c04340aa2 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -6918,27 +6918,33 @@ afi_safi_print (afi_t afi, safi_t safi) return "Unknown"; } +/* + * Please note that we have intentionally camelCased + * the return strings here. So if you want + * to use this function, please ensure you + * are doing this within json output + */ const char * afi_safi_json (afi_t afi, safi_t safi) { if (afi == AFI_IP && safi == SAFI_UNICAST) - return "IPv4Unicast"; + return "ipv4Unicast"; else if (afi == AFI_IP && safi == SAFI_MULTICAST) - return "IPv4Multicast"; + return "ipv4Multicast"; else if (afi == AFI_IP && safi == SAFI_MPLS_VPN) - return "IPv4VPN"; + return "ipv4Vpn"; else if (afi == AFI_IP && safi == SAFI_ENCAP) - return "IPv4Encap"; + return "ipv4Encap"; else if (afi == AFI_IP6 && safi == SAFI_UNICAST) - return "IPv6Unicast"; + return "ipv6Unicast"; else if (afi == AFI_IP6 && safi == SAFI_MULTICAST) - return "IPv6Multicast"; + return "ipv6Multicast"; else if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN) - return "IPv6VPN"; + return "ipv6Vpn"; else if (afi == AFI_IP6 && safi == SAFI_ENCAP) - return "IPv6Encap"; + return "ipv6Encap"; else if (afi == AFI_L2VPN && safi == SAFI_EVPN) - return "L2VPN EVPN"; + return "l2VpnEvpn"; else return "Unknown"; } From 46854ac0aefb0f31fe268d706285263872cf3afe Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 27 Apr 2017 13:13:30 -0400 Subject: [PATCH 3/8] bgpd: Fix 'show .. bgp ... neighbors ' command The 'show ip bgp neighbors swp31s0' command was not working properly. This fixes that issue. This command still has issues that need to be investigated but for the moment this gets the command working in the form that is needed. More rework can come. Signed-off-by: Donald Sharp --- bgpd/bgp_vty.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 5c04340aa2..cc58fe64fc 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -8825,9 +8825,11 @@ DEFUN (show_ip_bgp_neighbors, int idx = 0; - if (argv_find (argv, argc, "WORD", &idx)) - vrf = argv[idx]->arg; + if (argv_find (argv, argc, "view", &idx) || + argv_find (argv, argc, "vrf", &idx)) + vrf = argv[idx+1]->arg; + idx++; if (argv_find (argv, argc, "A.B.C.D", &idx) || argv_find (argv, argc, "X:X::X:X", &idx) || argv_find (argv, argc, "WORD", &idx)) From fcc65b0ff436bf9e10eaaa6c75b60d3288f6850e Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 27 Apr 2017 16:08:36 -0400 Subject: [PATCH 4/8] bgpd: Allow old vpnv4 commands to compile Signed-off-by: Donald Sharp --- bgpd/bgp_mplsvpn.c | 19 ------------------- configure.ac | 4 ++-- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index d29fb26030..88cde15e83 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -773,25 +773,6 @@ bgp_show_mpls_vpn (struct vty *vty, afi_t afi, struct prefix_rd *prd, return CMD_SUCCESS; } -#ifdef KEEP_OLD_VPN_COMMANDS -DEFUN (show_ip_bgp_vpn_all, - show_ip_bgp_vpn_all_cmd, - "show [ip] bgp ", - SHOW_STR - IP_STR - BGP_STR - BGP_VPNVX_HELP_STR) -{ - afi_t afi; - int idx = 0; - - if (argv_find_and_parse_vpnvx (argv, argc, &idx, &afi)) - return bgp_show_mpls_vpn (vty, afi, NULL, bgp_show_type_normal, NULL, 0, 0); - - return CMD_SUCCESS; -} -#endif - DEFUN (show_bgp_ip_vpn_all_rd, show_bgp_ip_vpn_all_rd_cmd, "show bgp "BGP_AFI_CMD_STR" vpn all [rd ASN:nn_or_IP-address:nn] [json]", diff --git a/configure.ac b/configure.ac index 6661f45d7c..96052c6f66 100755 --- a/configure.ac +++ b/configure.ac @@ -294,7 +294,7 @@ AC_ARG_ENABLE(rr-semantics, AC_ARG_ENABLE([protobuf], AS_HELP_STRING([--enable-protobuf], [Enable experimental protobuf support])) AC_ARG_ENABLE([oldvpn_commands], - AS_HELP_STRING([--enable-old-vpn-commands], [Keep old vpn commands])) + AS_HELP_STRING([--enable-oldvpn-commands], [Keep old vpn commands])) AC_CHECK_HEADERS(json-c/json.h) AC_CHECK_LIB(json-c, json_object_get, LIBS="$LIBS -ljson-c") @@ -406,7 +406,7 @@ fi # # Logic for old vpn commans support. # -if test "$enable_old_vpn_commands" = "yes"; then +if test "$enable_oldvpn_commands" = "yes"; then AC_DEFINE(KEEP_OLD_VPN_COMMANDS,, [Define for compiling with old vpn commands]) fi From 7c680483e5df494afdeaa25374d96935bc388faf Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 27 Apr 2017 20:19:36 -0400 Subject: [PATCH 5/8] vtysh: Add back in some missing ospf6 commands Signed-off-by: Donald Sharp --- vtysh/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/vtysh/Makefile.am b/vtysh/Makefile.am index 544b467e32..9b81f99607 100644 --- a/vtysh/Makefile.am +++ b/vtysh/Makefile.am @@ -76,6 +76,7 @@ endif if OSPF6D vtysh_scan += $(top_srcdir)/ospf6d/ospf6_abr.c +vtysh_scan += $(top_srcdir)/ospf6d/ospf6_asbr.c vtysh_scan += $(top_srcdir)/ospf6d/ospf6_area.c vtysh_scan += $(top_srcdir)/ospf6d/ospf6_bfd.c vtysh_scan += $(top_srcdir)/ospf6d/ospf6_flood.c From 373886aba91b963111b13bf01521a7680c5ffee9 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 27 Apr 2017 21:51:26 -0400 Subject: [PATCH 6/8] ospf6d: Fix some issues with 'show ipv6 ospf6 data..' 1) linkstate-id was made optional in one case 2) The ipv4 address was being looked at in the wrong spot Signed-off-by: Donald Sharp --- ospf6d/ospf6d.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ospf6d/ospf6d.c b/ospf6d/ospf6d.c index 036cc6d4c8..b067a66e27 100644 --- a/ospf6d/ospf6d.c +++ b/ospf6d/ospf6d.c @@ -296,7 +296,7 @@ DEFUN (show_ipv6_ospf6_database_id, "Dump LSAs\n" "Display LSA's internal information\n") { - int idx_ipv4 = 4; + int idx_ipv4 = 5; int idx_level = 6; int level; struct listnode *i, *j; @@ -388,7 +388,7 @@ DEFUN (show_ipv6_ospf6_database_router, DEFUN (show_ipv6_ospf6_database_type_id, show_ipv6_ospf6_database_type_id_cmd, - "show ipv6 ospf6 database [linkstate-id] A.B.C.D []", + "show ipv6 ospf6 database linkstate-id A.B.C.D []", SHOW_STR IPV6_STR OSPF6_STR From 30a24af0925868211df83ff2c4a06acd874cdf5c Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 27 Apr 2017 22:04:56 -0400 Subject: [PATCH 7/8] ospf6d: Fix parse_type_spec The function parse_type_spec was always looking in argv[0] of for figuring out the type of the command. Since the type location could change, use the passed in idx_lsa. Signed-off-by: Donald Sharp --- ospf6d/ospf6d.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ospf6d/ospf6d.c b/ospf6d/ospf6d.c index b067a66e27..aa219c7807 100644 --- a/ospf6d/ospf6d.c +++ b/ospf6d/ospf6d.c @@ -147,19 +147,19 @@ parse_type_spec (int idx_lsa, int argc, struct cmd_token **argv) if (argc > idx_lsa) { - if (strmatch (argv[0]->text, "router")) + if (strmatch (argv[idx_lsa]->text, "router")) type = htons (OSPF6_LSTYPE_ROUTER); - else if (strmatch (argv[0]->text, "network")) + else if (strmatch (argv[idx_lsa]->text, "network")) type = htons (OSPF6_LSTYPE_NETWORK); - else if (strmatch (argv[0]->text, "as-external")) + else if (strmatch (argv[idx_lsa]->text, "as-external")) type = htons (OSPF6_LSTYPE_AS_EXTERNAL); - else if (strmatch (argv[0]->text, "intra-prefix")) + else if (strmatch (argv[idx_lsa]->text, "intra-prefix")) type = htons (OSPF6_LSTYPE_INTRA_PREFIX); - else if (strmatch (argv[0]->text, "inter-router")) + else if (strmatch (argv[idx_lsa]->text, "inter-router")) type = htons (OSPF6_LSTYPE_INTER_ROUTER); - else if (strmatch (argv[0]->text, "inter-prefix")) + else if (strmatch (argv[idx_lsa]->text, "inter-prefix")) type = htons (OSPF6_LSTYPE_INTER_PREFIX); - else if (strmatch (argv[0]->text, "link")) + else if (strmatch (argv[idx_lsa]->text, "link")) type = htons (OSPF6_LSTYPE_LINK); } From 87e34b58899bea95296d0e2d107cde4b3f4a1972 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 28 Apr 2017 13:50:09 -0400 Subject: [PATCH 8/8] bgpd: Fix some crashes due to NULL pointer If you specified A.B.C.D, the code would still try to read A.B.C.D/M and not find it and pass in a NULL pointer which crashed the code. Signed-off-by: Donald Sharp --- bgpd/bgp_route.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 32cf0bcb89..d3a6e7e906 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -9297,8 +9297,17 @@ DEFUN (show_ip_bgp_vpn_all_route_prefix, vty_out (vty, "Can't find default instance%s", VTY_NEWLINE); return CMD_WARNING; } - network = argv_find (argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; - network = argv_find (argv, argc, "A.B.C.D/M", &idx) ? argv[idx]->arg : NULL; + + if (argv_find (argv, argc, "A.B.C.D", &idx)) + network = argv[idx]->arg; + else if (argv_find (argv, argc, "A.B.C.D/M", &idx)) + network = argv[idx]->arg; + else + { + vty_out (vty, "Unable to figure out Network%s", VTY_NEWLINE); + return CMD_WARNING; + } + return bgp_show_route (vty, bgp, network, AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); } #endif /* KEEP_OLD_VPN_COMMANDS */ @@ -9318,8 +9327,16 @@ DEFUN (show_ip_bgp_l2vpn_evpn_all_route_prefix, { int idx = 0; char *network = NULL; - network = argv_find (argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; - network = argv_find (argv, argc, "A.B.C.D/M", &idx) ? argv[idx]->arg : NULL; + + if (argv_find (argv, argc, "A.B.C.D", &idx)) + network = argv[idx]->arg; + else if (argv_find (argv, argc, "A.B.C.D/M", &idx)) + network = argv[idx]->arg; + else + { + vty_out (vty, "Unable to figure out Network%s", VTY_NEWLINE); + return CMD_WARNING; + } return bgp_show_route (vty, NULL, network, AFI_L2VPN, SAFI_EVPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv)); }