From b4898a387bc919e80de1a98aba2215a46c7cc070 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 27 Jan 2017 09:07:44 -0500 Subject: [PATCH] bgp: Add Asserts and remove dead code Add asserts to how I expect bgp_vty_find_and_parse_afi_safi to be used. Signed-off-by: Donald Sharp --- bgpd/bgp_route.c | 43 ++++++++++++++++--------------------------- bgpd/bgp_vty.c | 4 ++++ 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 0225a0bbef..ca96bae020 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -8065,18 +8065,12 @@ DEFUN (show_ip_bgp, int uj = use_json (argc, argv); if (uj) argc--; - if (vrf != VRF_ALL) + bgp = bgp_lookup_by_vrf_id (vrf); + if (bgp == NULL) { - vty_out(vty, "VRF-id: %d", vrf); - bgp = bgp_lookup_by_vrf_id (vrf); - if (bgp == NULL) - { - vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE); - return CMD_WARNING; - } + vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE); + return CMD_WARNING; } - else - bgp = NULL; if (argv_find(argv, argc, "cidr-only", &idx)) return bgp_show (vty, bgp, afi, safi, bgp_show_type_cidr_only, NULL, uj); @@ -9332,26 +9326,21 @@ DEFUN (show_ip_bgp_instance_neighbor_advertised_route, int uj = use_json (argc, argv); if (uj) argc--; - if (vrf != VRF_ALL) + bgp = bgp_lookup_by_vrf_id (vrf); + if (bgp == NULL) { - bgp = bgp_lookup_by_vrf_id (vrf); - if (bgp == NULL) - { - if (uj) - { - json_object *json_no = NULL; - json_no = json_object_new_object(); - json_object_string_add(json_no, "warning", "Can't find BGP view"); - vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); - json_object_free(json_no); + if (uj) + { + json_object *json_no = NULL; + json_no = json_object_new_object(); + json_object_string_add(json_no, "warning", "Can't find BGP view"); + vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE); + json_object_free(json_no); } - else - vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE); - return CMD_WARNING; - } + else + vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE); + return CMD_WARNING; } - else - bgp = NULL; /* neighbors */ argv_find (argv, argc, "neighbors", &idx); diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 7462f29e31..52ba24d36b 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -237,6 +237,10 @@ bgp_vty_find_and_parse_afi_safi_vrf (struct vty *vty, struct cmd_token **argv, i { char *vrf_name = NULL; + assert (afi); + assert (safi); + assert (*vrf == VRF_UNKNOWN); + if (argv_find (argv, argc, "ip", idx)) *afi = AFI_IP; -- 2.39.5