diff options
Diffstat (limited to 'bgpd/bgp_vty.c')
| -rw-r--r-- | bgpd/bgp_vty.c | 219 |
1 files changed, 150 insertions, 69 deletions
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 1460a26215..3669ea7736 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -301,7 +301,7 @@ int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index, int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty, struct cmd_token **argv, int argc, int *idx, afi_t *afi, safi_t *safi, - struct bgp **bgp) + struct bgp **bgp, bool use_json) { char *vrf_name = NULL; @@ -312,18 +312,24 @@ int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty, if (argv_find(argv, argc, "ip", idx)) *afi = AFI_IP; - if (argv_find(argv, argc, "view", idx) - || argv_find(argv, argc, "vrf", idx)) { + if (argv_find(argv, argc, "view", idx)) vrf_name = argv[*idx + 1]->arg; - + else if (argv_find(argv, argc, "vrf", idx)) { + vrf_name = argv[*idx + 1]->arg; + if (strmatch(vrf_name, VRF_DEFAULT_NAME)) + vrf_name = NULL; + } + if (vrf_name) { if (strmatch(vrf_name, "all")) *bgp = NULL; else { *bgp = bgp_lookup_by_name(vrf_name); if (!*bgp) { - vty_out(vty, - "View/Vrf specified is unknown: %s\n", - vrf_name); + if (use_json) + vty_out(vty, "{}\n"); + else + vty_out(vty, "View/Vrf %s is unknown\n", + vrf_name); *idx = 0; return 0; } @@ -331,7 +337,11 @@ int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty, } else { *bgp = bgp_get_default(); if (!*bgp) { - vty_out(vty, "Unable to find default BGP instance\n"); + if (use_json) + vty_out(vty, "{}\n"); + else + vty_out(vty, + "Default BGP instance not found\n"); *idx = 0; return 0; } @@ -910,9 +920,12 @@ DEFUN_NOSH (router_bgp, if (argc > 3) { name = argv[idx_vrf]->arg; - if (!strcmp(argv[idx_view_vrf]->text, "vrf")) - inst_type = BGP_INSTANCE_TYPE_VRF; - else if (!strcmp(argv[idx_view_vrf]->text, "view")) + if (!strcmp(argv[idx_view_vrf]->text, "vrf")) { + if (strmatch(name, VRF_DEFAULT_NAME)) + name = NULL; + else + inst_type = BGP_INSTANCE_TYPE_VRF; + } else if (!strcmp(argv[idx_view_vrf]->text, "view")) inst_type = BGP_INSTANCE_TYPE_VIEW; } @@ -7144,13 +7157,17 @@ DEFUN (clear_ip_bgp_all, if (argv_find(argv, argc, "ip", &idx)) afi = AFI_IP; - /* [<view|vrf> VIEWVRFNAME] */ - if (argv_find(argv, argc, "view", &idx) - || argv_find(argv, argc, "vrf", &idx)) { + /* [<vrf> VIEWVRFNAME] */ + if (argv_find(argv, argc, "vrf", &idx)) { + vrf = argv[idx + 1]->arg; + idx += 2; + if (vrf && strmatch(vrf, VRF_DEFAULT_NAME)) + vrf = NULL; + } else if (argv_find(argv, argc, "view", &idx)) { + /* [<view> VIEWVRFNAME] */ vrf = argv[idx + 1]->arg; idx += 2; } - /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */ if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) argv_find_and_parse_safi(argv, argc, &idx, &safi); @@ -7215,8 +7232,16 @@ DEFUN (clear_ip_bgp_prefix, int idx = 0; /* [<view|vrf> VIEWVRFNAME] */ - if (argv_find(argv, argc, "VIEWVRFNAME", &idx)) - vrf = argv[idx]->arg; + if (argv_find(argv, argc, "vrf", &idx)) { + vrf = argv[idx + 1]->arg; + idx += 2; + if (vrf && strmatch(vrf, VRF_DEFAULT_NAME)) + vrf = NULL; + } else if (argv_find(argv, argc, "view", &idx)) { + /* [<view> VIEWVRFNAME] */ + vrf = argv[idx + 1]->arg; + idx += 2; + } prefix = argv[argc - 1]->arg; @@ -7258,16 +7283,23 @@ DEFUN (clear_bgp_instance_ipv6_safi_prefix, "Clear bestpath and re-advertise\n" "IPv6 prefix\n") { - int idx_word = 3; int idx_safi = 0; + int idx_vrfview = 0; int idx_ipv6_prefix = 0; safi_t safi = SAFI_UNICAST; char *prefix = argv_find(argv, argc, "X:X::X:X/M", &idx_ipv6_prefix) ? argv[idx_ipv6_prefix]->arg : NULL; - /* [<view|vrf> VIEWVRFNAME] */ - char *vrfview = argv_find(argv, argc, "VIEWVRFNAME", &idx_word) ? - argv[idx_word]->arg : NULL; + char *vrfview = NULL; + /* [<view|vrf> VIEWVRFNAME] */ + if (argv_find(argv, argc, "vrf", &idx_vrfview)) { + vrfview = argv[idx_vrfview + 1]->arg; + if (vrfview && strmatch(vrfview, VRF_DEFAULT_NAME)) + vrfview = NULL; + } else if (argv_find(argv, argc, "view", &idx_vrfview)) { + /* [<view> VIEWVRFNAME] */ + vrfview = argv[idx_vrfview + 1]->arg; + } argv_find_and_parse_safi(argv, argc, &idx_safi, &safi); return bgp_clear_prefix( @@ -7317,7 +7349,7 @@ DEFUN (show_bgp_vrfs, struct list *inst = bm->bgp; struct listnode *node; struct bgp *bgp; - uint8_t uj = use_json(argc, argv); + bool uj = use_json(argc, argv); json_object *json = NULL; json_object *json_vrfs = NULL; int count = 0; @@ -7458,10 +7490,18 @@ DEFUN(show_bgp_martian_nexthop_db, show_bgp_martian_nexthop_db_cmd, { struct bgp *bgp = NULL; int idx = 0; - - if (argv_find(argv, argc, "view", &idx) - || argv_find(argv, argc, "vrf", &idx)) - bgp = bgp_lookup_by_name(argv[idx + 1]->arg); + char *name = NULL; + + /* [<vrf> VIEWVRFNAME] */ + if (argv_find(argv, argc, "vrf", &idx)) { + name = argv[idx + 1]->arg; + if (name && strmatch(name, VRF_DEFAULT_NAME)) + name = NULL; + } else if (argv_find(argv, argc, "view", &idx)) + /* [<view> VIEWVRFNAME] */ + name = argv[idx + 1]->arg; + if (name) + bgp = bgp_lookup_by_name(name); else bgp = bgp_get_default(); @@ -7638,7 +7678,7 @@ static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json) /* Show BGP peer's summary information. */ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, - uint8_t use_json, json_object *json) + bool use_json, json_object *json) { struct peer *peer; struct listnode *node, *nnode; @@ -8055,14 +8095,14 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, } static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi, - int safi, uint8_t use_json, + int safi, bool use_json, json_object *json) { int is_first = 1; int afi_wildcard = (afi == AFI_MAX); int safi_wildcard = (safi == SAFI_MAX); int is_wildcard = (afi_wildcard || safi_wildcard); - bool json_output = false; + bool nbr_output = false; if (use_json && is_wildcard) vty_out(vty, "{\n"); @@ -8073,7 +8113,7 @@ static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi, safi = 1; /* SAFI_UNICAST */ while (safi < SAFI_MAX) { if (bgp_afi_safi_peer_exists(bgp, afi, safi)) { - json_output = true; + nbr_output = true; if (is_wildcard) { /* * So limit output to those afi/safi @@ -8112,22 +8152,28 @@ static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi, if (use_json && is_wildcard) vty_out(vty, "}\n"); - else if (use_json && !json_output) - vty_out(vty, "{}\n"); + else if (!nbr_output) { + if (use_json) + vty_out(vty, "{}\n"); + else + vty_out(vty, "%% No BGP neighbors found\n"); + } } static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi, - safi_t safi, uint8_t use_json) + safi_t safi, bool use_json) { struct listnode *node, *nnode; struct bgp *bgp; json_object *json = NULL; int is_first = 1; + bool nbr_output = false; if (use_json) vty_out(vty, "{\n"); for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) { + nbr_output = true; if (use_json) { json = json_object_new_object(); @@ -8151,10 +8197,12 @@ static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi, if (use_json) vty_out(vty, "}\n"); + else if (!nbr_output) + vty_out(vty, "%% BGP instance not found\n"); } int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi, - safi_t safi, uint8_t use_json) + safi_t safi, bool use_json) { struct bgp *bgp; @@ -8171,7 +8219,7 @@ int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi, vty_out(vty, "{}\n"); else vty_out(vty, - "%% No such BGP instance exist\n"); + "%% BGP instance not found\n"); return CMD_WARNING; } @@ -8185,6 +8233,13 @@ int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi, if (bgp) bgp_show_summary_afi_safi(vty, bgp, afi, safi, use_json, NULL); + else { + if (use_json) + vty_out(vty, "{}\n"); + else + vty_out(vty, "%% BGP instance not found\n"); + return CMD_WARNING; + } return CMD_SUCCESS; } @@ -8211,16 +8266,20 @@ DEFUN (show_ip_bgp_summary, /* show [ip] bgp */ if (argv_find(argv, argc, "ip", &idx)) afi = AFI_IP; - /* [<view|vrf> VIEWVRFNAME] */ - if (argv_find(argv, argc, "view", &idx) - || argv_find(argv, argc, "vrf", &idx)) - vrf = argv[++idx]->arg; + /* [<vrf> VIEWVRFNAME] */ + if (argv_find(argv, argc, "vrf", &idx)) { + vrf = argv[idx + 1]->arg; + if (vrf && strmatch(vrf, VRF_DEFAULT_NAME)) + vrf = NULL; + } else if (argv_find(argv, argc, "view", &idx)) + /* [<view> VIEWVRFNAME] */ + vrf = argv[idx + 1]->arg; /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */ if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) { argv_find_and_parse_safi(argv, argc, &idx, &safi); } - int uj = use_json(argc, argv); + bool uj = use_json(argc, argv); return bgp_show_summary_vty(vty, vrf, afi, safi, uj); } @@ -8302,7 +8361,7 @@ static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p, afi_t afi, safi_t safi, uint16_t adv_smcap, uint16_t adv_rmcap, uint16_t rcv_smcap, uint16_t rcv_rmcap, - uint8_t use_json, json_object *json_pref) + bool use_json, json_object *json_pref) { /* Send-Mode */ if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap) @@ -8362,7 +8421,7 @@ static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p, } static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi, - safi_t safi, uint8_t use_json, + safi_t safi, bool use_json, json_object *json_neigh) { struct bgp_filter *filter; @@ -8937,7 +8996,7 @@ static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi, } } -static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json, +static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, json_object *json) { struct bgp *bgp; @@ -10684,12 +10743,13 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json, static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp, enum show_type type, union sockunion *su, - const char *conf_if, uint8_t use_json, + const char *conf_if, bool use_json, json_object *json) { struct listnode *node, *nnode; struct peer *peer; int find = 0; + bool nbr_output = false; for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE)) @@ -10698,6 +10758,7 @@ static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp, switch (type) { case show_all: bgp_show_peer(vty, peer, use_json, json); + nbr_output = true; break; case show_peer: if (conf_if) { @@ -10727,6 +10788,9 @@ static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp, vty_out(vty, "%% No such neighbor in this view/vrf\n"); } + if (type != show_peer && !nbr_output && !use_json) + vty_out(vty, "%% No BGP neighbors found\n"); + if (use_json) { vty_out(vty, "%s\n", json_object_to_json_string_ext( json, JSON_C_TO_STRING_PRETTY)); @@ -10741,18 +10805,20 @@ static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp, static void bgp_show_all_instances_neighbors_vty(struct vty *vty, enum show_type type, const char *ip_str, - uint8_t use_json) + bool use_json) { struct listnode *node, *nnode; struct bgp *bgp; union sockunion su; json_object *json = NULL; int ret, is_first = 1; + bool nbr_output = false; if (use_json) vty_out(vty, "{\n"); for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) { + nbr_output = true; if (use_json) { if (!(json = json_object_new_object())) { flog_err( @@ -10805,11 +10871,13 @@ static void bgp_show_all_instances_neighbors_vty(struct vty *vty, if (use_json) vty_out(vty, "}\n"); + else if (!nbr_output) + vty_out(vty, "%% BGP instance not found\n"); } static int bgp_show_neighbor_vty(struct vty *vty, const char *name, enum show_type type, const char *ip_str, - uint8_t use_json) + bool use_json) { int ret; struct bgp *bgp; @@ -10826,8 +10894,6 @@ static int bgp_show_neighbor_vty(struct vty *vty, const char *name, if (!bgp) { if (use_json) { json = json_object_new_object(); - json_object_boolean_true_add( - json, "bgpNoSuchInstance"); vty_out(vty, "%s\n", json_object_to_json_string_ext( json, @@ -10835,7 +10901,7 @@ static int bgp_show_neighbor_vty(struct vty *vty, const char *name, json_object_free(json); } else vty_out(vty, - "%% No such BGP instance exist\n"); + "%% BGP instance not found\n"); return CMD_WARNING; } @@ -10859,6 +10925,11 @@ static int bgp_show_neighbor_vty(struct vty *vty, const char *name, json); } json_object_free(json); + } else { + if (use_json) + vty_out(vty, "{}\n"); + else + vty_out(vty, "%% BGP instance not found\n"); } return CMD_SUCCESS; @@ -10884,12 +10955,17 @@ DEFUN (show_ip_bgp_neighbors, char *sh_arg = NULL; enum show_type sh_type; - uint8_t uj = use_json(argc, argv); + bool uj = use_json(argc, argv); int idx = 0; - if (argv_find(argv, argc, "view", &idx) - || argv_find(argv, argc, "vrf", &idx)) + /* [<vrf> VIEWVRFNAME] */ + if (argv_find(argv, argc, "vrf", &idx)) { + vrf = argv[idx + 1]->arg; + if (vrf && strmatch(vrf, VRF_DEFAULT_NAME)) + vrf = NULL; + } else if (argv_find(argv, argc, "view", &idx)) + /* [<view> VIEWVRFNAME] */ vrf = argv[idx + 1]->arg; idx++; @@ -10994,8 +11070,8 @@ DEFUN (show_ip_bgp_attr_info, return CMD_SUCCESS; } -static int bgp_show_route_leak_vty(struct vty *vty, const char *name, - afi_t afi, safi_t safi, uint8_t use_json) +static int bgp_show_route_leak_vty(struct vty *vty, const char *name, afi_t afi, + safi_t safi, bool use_json) { struct bgp *bgp; struct listnode *node; @@ -11011,16 +11087,9 @@ static int bgp_show_route_leak_vty(struct vty *vty, const char *name, json = json_object_new_object(); - /* Provide context for the block */ - json_object_string_add(json, "vrf", name ? name : "default"); - json_object_string_add(json, "afiSafi", - afi_safi_print(afi, safi)); - bgp = name ? bgp_lookup_by_name(name) : bgp_get_default(); if (!bgp) { - json_object_boolean_true_add(json, - "bgpNoSuchInstance"); vty_out(vty, "%s\n", json_object_to_json_string_ext( json, @@ -11030,6 +11099,11 @@ static int bgp_show_route_leak_vty(struct vty *vty, const char *name, return CMD_WARNING; } + /* Provide context for the block */ + json_object_string_add(json, "vrf", name ? name : "default"); + json_object_string_add(json, "afiSafi", + afi_safi_print(afi, safi)); + if (!CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_VRF_TO_VRF_IMPORT)) { json_object_string_add(json, "importFromVrfs", "none"); @@ -11168,7 +11242,7 @@ DEFUN (show_ip_bgp_route_leak, afi_t afi = AFI_MAX; safi_t safi = SAFI_MAX; - uint8_t uj = use_json(argc, argv); + bool uj = use_json(argc, argv); int idx = 0; /* show [ip] bgp */ @@ -11183,8 +11257,11 @@ DEFUN (show_ip_bgp_route_leak, return CMD_WARNING; } - if (argv_find(argv, argc, "vrf", &idx)) - vrf = argv[++idx]->arg; + if (argv_find(argv, argc, "vrf", &idx)) { + vrf = argv[idx + 1]->arg; + if (vrf && strmatch(vrf, VRF_DEFAULT_NAME)) + vrf = NULL; + } /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */ if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) { argv_find_and_parse_safi(argv, argc, &idx, &safi); @@ -11257,10 +11334,14 @@ DEFUN (show_ip_bgp_updgrps, /* show [ip] bgp */ if (argv_find(argv, argc, "ip", &idx)) afi = AFI_IP; - /* [<view|vrf> VIEWVRFNAME] */ - if (argv_find(argv, argc, "view", &idx) - || argv_find(argv, argc, "vrf", &idx)) - vrf = argv[++idx]->arg; + /* [<vrf> VIEWVRFNAME] */ + if (argv_find(argv, argc, "vrf", &idx)) { + vrf = argv[idx + 1]->arg; + if (vrf && strmatch(vrf, VRF_DEFAULT_NAME)) + vrf = NULL; + } else if (argv_find(argv, argc, "view", &idx)) + /* [<view> VIEWVRFNAME] */ + vrf = argv[idx + 1]->arg; /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */ if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) { argv_find_and_parse_safi(argv, argc, &idx, &safi); @@ -11486,7 +11567,7 @@ static int bgp_show_peer_group_vty(struct vty *vty, const char *name, bgp = name ? bgp_lookup_by_name(name) : bgp_get_default(); if (!bgp) { - vty_out(vty, "%% No such BGP instance exists\n"); + vty_out(vty, "%% BGP instance not found\n"); return CMD_WARNING; } |
