Skip to content

Commit 5cd2981

Browse files
authored
Merge pull request #14891 from FRRouting/mergify/bp/stable/9.1/pr-14856
lib: fix show route map JSON display (backport #14856)
2 parents e3e69cf + b3abdd8 commit 5cd2981

File tree

3 files changed

+70
-16
lines changed

3 files changed

+70
-16
lines changed

doc/user/zebra.rst

-2
Original file line numberDiff line numberDiff line change
@@ -1434,8 +1434,6 @@ zebra Terminal Mode Commands
14341434

14351435
.. clicmd:: show ip prefix-list [NAME]
14361436

1437-
.. clicmd:: show route-map [NAME]
1438-
14391437
.. clicmd:: show ip protocol
14401438

14411439
.. clicmd:: show ip forward

lib/routemap.c

+11-14
Original file line numberDiff line numberDiff line change
@@ -1070,20 +1070,17 @@ static int vty_show_route_map(struct vty *vty, const char *name, bool use_json)
10701070
{
10711071
struct route_map *map;
10721072
json_object *json = NULL;
1073-
json_object *json_proto = NULL;
10741073

1075-
if (use_json) {
1074+
if (use_json)
10761075
json = json_object_new_object();
1077-
json_proto = json_object_new_object();
1078-
json_object_object_add(json, frr_protonameinst, json_proto);
1079-
} else
1076+
else
10801077
vty_out(vty, "%s:\n", frr_protonameinst);
10811078

10821079
if (name) {
10831080
map = route_map_lookup_by_name(name);
10841081

10851082
if (map) {
1086-
vty_show_route_map_entry(vty, map, json_proto);
1083+
vty_show_route_map_entry(vty, map, json);
10871084
} else if (!use_json) {
10881085
vty_out(vty, "%s: 'route-map %s' not found\n",
10891086
frr_protonameinst, name);
@@ -1099,7 +1096,7 @@ static int vty_show_route_map(struct vty *vty, const char *name, bool use_json)
10991096
list_sort(maplist, sort_route_map);
11001097

11011098
for (ALL_LIST_ELEMENTS_RO(maplist, ln, map))
1102-
vty_show_route_map_entry(vty, map, json_proto);
1099+
vty_show_route_map_entry(vty, map, json);
11031100

11041101
list_delete(&maplist);
11051102
}
@@ -3145,13 +3142,13 @@ DEFPY (rmap_clear_counters,
31453142

31463143
}
31473144

3148-
DEFUN (rmap_show_name,
3149-
rmap_show_name_cmd,
3150-
"show route-map [WORD] [json]",
3151-
SHOW_STR
3152-
"route-map information\n"
3153-
"route-map name\n"
3154-
JSON_STR)
3145+
DEFUN_NOSH (rmap_show_name,
3146+
rmap_show_name_cmd,
3147+
"show route-map [WORD] [json]",
3148+
SHOW_STR
3149+
"route-map information\n"
3150+
"route-map name\n"
3151+
JSON_STR)
31553152
{
31563153
bool uj = use_json(argc, argv);
31573154
int idx = 0;

vtysh/vtysh.c

+59
Original file line numberDiff line numberDiff line change
@@ -3396,6 +3396,63 @@ DEFUN (vtysh_show_running_config,
33963396
return vtysh_write_terminal(self, vty, argc, argv);
33973397
}
33983398

3399+
static void show_route_map_send(const char *route_map, bool json)
3400+
{
3401+
unsigned int i;
3402+
bool first = true;
3403+
char command_line[128];
3404+
3405+
snprintf(command_line, sizeof(command_line), "show route-map ");
3406+
if (route_map)
3407+
strlcat(command_line, route_map, sizeof(command_line));
3408+
if (json)
3409+
strlcat(command_line, " json", sizeof(command_line));
3410+
3411+
if (json)
3412+
vty_out(vty, "{");
3413+
3414+
for (i = 0; i < array_size(vtysh_client); i++) {
3415+
const struct vtysh_client *client = &vtysh_client[i];
3416+
bool is_connected = true;
3417+
3418+
if (!CHECK_FLAG(client->flag, VTYSH_RMAP))
3419+
continue;
3420+
3421+
for (; client; client = client->next)
3422+
if (client->fd < 0)
3423+
is_connected = false;
3424+
3425+
if (!is_connected)
3426+
continue;
3427+
3428+
if (json && !first)
3429+
vty_out(vty, ",");
3430+
else
3431+
first = false;
3432+
3433+
if (json)
3434+
vty_out(vty, "\"%s\":", vtysh_client[i].name);
3435+
3436+
vtysh_client_execute_name(vtysh_client[i].name, command_line);
3437+
}
3438+
3439+
if (json)
3440+
vty_out(vty, "}\n");
3441+
}
3442+
3443+
DEFPY (show_route_map,
3444+
show_route_map_cmd,
3445+
"show route-map [WORD]$route_map [json]$json",
3446+
SHOW_STR
3447+
"route-map information\n"
3448+
"route-map name\n"
3449+
JSON_STR)
3450+
{
3451+
show_route_map_send(route_map, !!json);
3452+
3453+
return CMD_SUCCESS;
3454+
}
3455+
33993456
DEFUN (vtysh_integrated_config,
34003457
vtysh_integrated_config_cmd,
34013458
"service integrated-vtysh-config",
@@ -5047,6 +5104,8 @@ void vtysh_init_vty(void)
50475104
install_element(ENABLE_NODE, &vtysh_copy_running_config_cmd);
50485105
install_element(ENABLE_NODE, &vtysh_copy_to_running_cmd);
50495106

5107+
install_element(ENABLE_NODE, &show_route_map_cmd);
5108+
50505109
/* "write terminal" command. */
50515110
install_element(ENABLE_NODE, &vtysh_write_terminal_cmd);
50525111

0 commit comments

Comments
 (0)