Skip to content

Commit

Permalink
bgpd: AFI option to query nexthops based on AFI
Browse files Browse the repository at this point in the history
Added ipv4 and ipv6 option to existing "show bgp nexthop"
command to be able to query nexthops that belong to a
particular address-family.

Also fixed the warnings of MR 12171

Signed-off-by: Pooja Jagadeesh Doijode <pdoijode@nvidia.com>
  • Loading branch information
Pdoijode committed Jan 5, 2023
1 parent 8da79d0 commit 071ec80
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 46 deletions.
75 changes: 29 additions & 46 deletions bgpd/bgp_nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ bool bgp_subgrp_multiaccess_check_v4(struct in_addr nexthop,
static void bgp_show_bgp_path_info_flags(uint32_t flags, json_object *json)
{
json_object *json_flags = NULL;

if (!json)
return;

Expand Down Expand Up @@ -1104,7 +1105,6 @@ static void bgp_show_nexthops(struct vty *vty, struct bgp *bgp,
json_object_object_add(
json, (afi == AFI_IP) ? "ipv4" : "ipv6",
json_afi);

return;
}

Expand All @@ -1126,7 +1126,7 @@ static int show_ip_bgp_nexthop_table(struct vty *vty, const char *name,
{
struct bgp *bgp;

if (name && strcmp(name, VRF_DEFAULT_NAME) != 0)
if (name && !strmatch(name, VRF_DEFAULT_NAME))
bgp = bgp_lookup_by_name(name);
else
bgp = bgp_get_default();
Expand Down Expand Up @@ -1199,53 +1199,47 @@ static void bgp_show_all_instances_nexthops_vty(struct vty *vty,
}
}

DEFUN (show_ip_bgp_nexthop,
#include "bgpd/bgp_nexthop_clippy.c"

DEFPY (show_ip_bgp_nexthop,
show_ip_bgp_nexthop_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] nexthop [<A.B.C.D|X:X::X:X>] [detail] [json]",
"show [ip] bgp [<view|vrf> VIEWVRFNAME$vrf] nexthop [<A.B.C.D|X:X::X:X>$nhop] [<ipv4$afi [A.B.C.D$nhop]|ipv6$afi [X:X::X:X$nhop]>] [detail$detail] [json$uj]",
SHOW_STR
IP_STR
BGP_STR
BGP_INSTANCE_HELP_STR
"BGP nexthop table\n"
"IPv4 nexthop address\n"
"IPv6 nexthop address\n"
"BGP nexthop IPv4 table\n"
"IPv4 nexthop address\n"
"BGP nexthop IPv6 table\n"
"IPv6 nexthop address\n"
"Show detailed information\n"
JSON_STR)
{
int rc = 0;
int idx = 0;
int nh_idx = 0;
char *vrf = NULL;
char *nhop_ip = NULL;
json_object *json = NULL;
bool uj = use_json(argc, argv);
bool detail = false;
afi_t afiz = AFI_UNSPEC;

if (uj)
json = json_object_new_object();

if (argv_find(argv, argc, "view", &idx)
|| argv_find(argv, argc, "vrf", &idx))
vrf = argv[++idx]->arg;

if (argv_find(argv, argc, "A.B.C.D", &nh_idx)
|| argv_find(argv, argc, "X:X::X:X", &nh_idx))
nhop_ip = argv[nh_idx]->arg;
if (afi)
afiz = bgp_vty_afi_from_str(afi);

if (argv_find(argv, argc, "detail", &idx))
detail = true;

rc = show_ip_bgp_nexthop_table(vty, vrf, nhop_ip, false, json,
AFI_UNSPEC, detail);
rc = show_ip_bgp_nexthop_table(vty, vrf, nhop_str, false, json, afiz,
detail);

if (uj)
vty_json(vty, json);

return rc;
}

DEFUN (show_ip_bgp_import_check,
DEFPY (show_ip_bgp_import_check,
show_ip_bgp_import_check_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] import-check-table [detail] [json]",
"show [ip] bgp [<view|vrf> VIEWVRFNAME$vrf] import-check-table [detail$detail] [json$uj]",
SHOW_STR
IP_STR
BGP_STR
Expand All @@ -1255,58 +1249,47 @@ DEFUN (show_ip_bgp_import_check,
JSON_STR)
{
int rc = 0;
int idx = 0;
char *vrf = NULL;
json_object *json = NULL;
bool uj = use_json(argc, argv);
bool detail = false;

if (uj)
json = json_object_new_object();

if (argv_find(argv, argc, "view", &idx)
|| argv_find(argv, argc, "vrf", &idx))
vrf = argv[++idx]->arg;

if (argv_find(argv, argc, "detail", &idx))
detail = true;

rc = show_ip_bgp_nexthop_table(vty, vrf, NULL, true, json, AFI_UNSPEC,
detail);

if (uj)
vty_json(vty, json);

return rc;
}

DEFUN (show_ip_bgp_instance_all_nexthop,
DEFPY (show_ip_bgp_instance_all_nexthop,
show_ip_bgp_instance_all_nexthop_cmd,
"show [ip] bgp <view|vrf> all nexthop [json]",
"show [ip] bgp <view|vrf> all nexthop [<ipv4|ipv6>$afi] [detail$detail] [json$uj]",
SHOW_STR
IP_STR
BGP_STR
BGP_INSTANCE_ALL_HELP_STR
"BGP nexthop table\n"
"BGP IPv4 nexthop table\n"
"BGP IPv6 nexthop table\n"
"Show detailed information\n"
JSON_STR)
{
json_object *json = NULL;
bool uj = use_json(argc, argv);
int idx = 0;
afi_t afi = AFI_UNSPEC;
bool detail = false;
afi_t afiz = AFI_UNSPEC;

if (uj)
json = json_object_new_object();

argv_find_and_parse_afi(argv, argc, &idx, &afi);

if (argv_find(argv, argc, "detail", &idx))
detail = true;
if (afi)
afiz = bgp_vty_afi_from_str(afi);

bgp_show_all_instances_nexthops_vty(vty, json, afi, detail);
bgp_show_all_instances_nexthops_vty(vty, json, afiz, detail);

if (uj)
vty_json(vty, json);

return CMD_SUCCESS;
}

Expand Down
1 change: 1 addition & 0 deletions bgpd/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ clippy_scan += \
bgpd/bgp_routemap.c \
bgpd/bgp_rpki.c \
bgpd/bgp_vty.c \
bgpd/bgp_nexthop.c \
# end

nodist_bgpd_bgpd_SOURCES = \
Expand Down
3 changes: 3 additions & 0 deletions doc/user/bgp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4483,6 +4483,9 @@ Displaying Update Group Information

Displaying Nexthop Information
--------------------
.. clicmd:: show [ip] bgp [<view|vrf> VIEWVRFNAME] nexthop ipv4 [A.B.C.D] [detail] [json]

.. clicmd:: show [ip] bgp [<view|vrf> VIEWVRFNAME] nexthop ipv6 [X:X::X:X] [detail] [json]

.. clicmd:: show [ip] bgp [<view|vrf> VIEWVRFNAME] nexthop [<A.B.C.D|X:X::X:X>] [detail] [json]

Expand Down

0 comments on commit 071ec80

Please sign in to comment.