]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: add "json" option to "show bgp as-path-access-list"
authorRenato Westphal <renato@opensourcerouting.org>
Mon, 2 Aug 2021 18:38:26 +0000 (15:38 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Mon, 2 Aug 2021 18:53:02 +0000 (15:53 -0300)
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
bgpd/bgp_filter.c
doc/user/bgp.rst

index 8d6691945fe24d38f590ec89e9841f4a67194830..641cc7605fd17eb9524f217e249266b48cee3f00 100644 (file)
@@ -612,78 +612,118 @@ DEFUN (no_as_path_all,
        return CMD_SUCCESS;
 }
 
-static void as_list_show(struct vty *vty, struct as_list *aslist)
+static void as_list_show(struct vty *vty, struct as_list *aslist,
+                        json_object *json)
 {
        struct as_filter *asfilter;
+       json_object *json_aslist = NULL;
 
-       vty_out(vty, "AS path access list %s\n", aslist->name);
+       if (json) {
+               json_aslist = json_object_new_array();
+               json_object_object_add(json, aslist->name, json_aslist);
+       } else
+               vty_out(vty, "AS path access list %s\n", aslist->name);
 
        for (asfilter = aslist->head; asfilter; asfilter = asfilter->next) {
-               vty_out(vty, "    %s %s\n", filter_type_str(asfilter->type),
-                       asfilter->reg_str);
+               if (json) {
+                       json_object *json_asfilter = json_object_new_object();
+
+                       json_object_int_add(json_asfilter, "sequenceNumber",
+                                           asfilter->seq);
+                       json_object_string_add(json_asfilter, "type",
+                                              filter_type_str(asfilter->type));
+                       json_object_string_add(json_asfilter, "regExp",
+                                              asfilter->reg_str);
+
+                       json_object_array_add(json_aslist, json_asfilter);
+               } else
+                       vty_out(vty, "    %s %s\n",
+                               filter_type_str(asfilter->type),
+                               asfilter->reg_str);
        }
 }
 
-static void as_list_show_all(struct vty *vty)
+static void as_list_show_all(struct vty *vty, json_object *json)
 {
        struct as_list *aslist;
-       struct as_filter *asfilter;
-
-       for (aslist = as_list_master.str.head; aslist; aslist = aslist->next) {
-               vty_out(vty, "AS path access list %s\n", aslist->name);
 
-               for (asfilter = aslist->head; asfilter;
-                    asfilter = asfilter->next) {
-                       vty_out(vty, "    %s %s\n",
-                               filter_type_str(asfilter->type),
-                               asfilter->reg_str);
-               }
-       }
+       for (aslist = as_list_master.str.head; aslist; aslist = aslist->next)
+               as_list_show(vty, aslist, json);
 }
 
 DEFUN (show_as_path_access_list,
        show_bgp_as_path_access_list_cmd,
-       "show bgp as-path-access-list WORD",
+       "show bgp as-path-access-list WORD [json]",
        SHOW_STR
        BGP_STR
        "List AS path access lists\n"
-       "AS path access list name\n")
+       "AS path access list name\n"
+       JSON_STR)
 {
        int idx_word = 3;
        struct as_list *aslist;
+       bool uj = use_json(argc, argv);
+       json_object *json = NULL;
+
+       if (uj)
+               json = json_object_new_object();
 
        aslist = as_list_lookup(argv[idx_word]->arg);
        if (aslist)
-               as_list_show(vty, aslist);
+               as_list_show(vty, aslist, json);
+
+       if (uj) {
+               vty_out(vty, "%s\n",
+                       json_object_to_json_string_ext(
+                               json, JSON_C_TO_STRING_PRETTY));
+               json_object_free(json);
+       }
 
        return CMD_SUCCESS;
 }
 
 ALIAS (show_as_path_access_list,
        show_ip_as_path_access_list_cmd,
-       "show ip as-path-access-list WORD",
+       "show ip as-path-access-list WORD [json]",
        SHOW_STR
        IP_STR
        "List AS path access lists\n"
-       "AS path access list name\n")
+       "AS path access list name\n"
+       JSON_STR)
 
 DEFUN (show_as_path_access_list_all,
        show_bgp_as_path_access_list_all_cmd,
-       "show bgp as-path-access-list",
+       "show bgp as-path-access-list [json]",
        SHOW_STR
        BGP_STR
-       "List AS path access lists\n")
+       "List AS path access lists\n"
+       JSON_STR)
 {
-       as_list_show_all(vty);
+       bool uj = use_json(argc, argv);
+       json_object *json = NULL;
+
+       if (uj)
+               json = json_object_new_object();
+
+       as_list_show_all(vty, json);
+
+       if (uj) {
+               vty_out(vty, "%s\n",
+                       json_object_to_json_string_ext(
+                               json, JSON_C_TO_STRING_PRETTY));
+               json_object_free(json);
+       }
+
        return CMD_SUCCESS;
 }
 
 ALIAS (show_as_path_access_list_all,
        show_ip_as_path_access_list_all_cmd,
-       "show ip as-path-access-list",
+       "show ip as-path-access-list [json]",
        SHOW_STR
        IP_STR
-       "List AS path access lists\n")
+       "List AS path access lists\n"
+       JSON_STR)
 
 static int config_write_as_list(struct vty *vty)
 {
index 32a51fdb704e7a4f2defcccb139a7cab8713a3ea..ef72c5030a1ceb6158206f0f8bd214e9b5eee331 100644 (file)
@@ -1896,7 +1896,17 @@ AS path access list is user defined AS path.
 
    This command defines a new AS path access list.
 
+.. clicmd:: show bgp as-path-access-list [json]
 
+   Display all BGP AS Path access lists.
+
+   If the ``json`` option is specified, output is displayed in JSON format.
+
+.. clicmd:: show bgp as-path-access-list WORD [json]
+
+   Display the specified BGP AS Path access list.
+
+   If the ``json`` option is specified, output is displayed in JSON format.
 
 .. _bgp-bogon-filter-example: