]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: AFI option to query nexthops based on AFI 12573/head
authorPooja Jagadeesh Doijode <pdoijode@nvidia.com>
Thu, 5 Jan 2023 02:53:12 +0000 (18:53 -0800)
committerPooja Jagadeesh Doijode <pdoijode@nvidia.com>
Thu, 5 Jan 2023 02:53:12 +0000 (18:53 -0800)
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>
bgpd/bgp_nexthop.c
bgpd/subdir.am
doc/user/bgp.rst

index 36c5699b0424adf5d8837c3e85379f9f9587f00f..23a5aa219056e17e0534f38329292ed4ce4ba82d 100644 (file)
@@ -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;
 
@@ -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;
        }
 
@@ -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();
@@ -1199,9 +1199,11 @@ 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
@@ -1209,43 +1211,35 @@ DEFUN (show_ip_bgp_nexthop,
        "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
@@ -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;
 }
 
index 88f53da35efe3b0fa888ce91ce3b462fdb266a3a..c1f5a61438ac2a5b38655982eb853cdfee6ec443 100644 (file)
@@ -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 = \
index a1e6f35e342b1494a485633e94f5f54dce22e067..cd5672511f5177fd58edbb82f1dacd883e3cf1c7 100644 (file)
@@ -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]