diff options
author | Donatas Abraitis <donatas@opensourcerouting.org> | 2022-05-23 18:40:45 +0200 |
---|---|---|
committer | Donatas Abraitis <donatas@opensourcerouting.org> | 2022-05-23 23:06:07 +0200 |
commit | ae872c2f88a0fae01760d9125f710604cb653609 (patch) | |
tree | b34cae67b194fd88f6f02caac5025589d5483a21 /bgpd | |
parent | Merge pull request #11150 from opensourcerouting/fix/use_librtr_higher_0.8.0 (diff) | |
download | frr-ae872c2f88a0fae01760d9125f710604cb653609.tar.xz frr-ae872c2f88a0fae01760d9125f710604cb653609.zip |
bgpd: Add JSON output for `show rpki cache-connection`
```
spine1-debian-11# sh rpki cache-connection
Connected to group 1
rpki tcp cache 192.168.10.17 8283 pref 1 (connected)
rpki tcp cache 192.168.10.17 8282 pref 2
spine1-debian-11# sh rpki cache-connection json
{
"connectedGroup":1,
"connections":[
{
"mode":"tcp",
"host":"192.168.10.17",
"port":"8283",
"preference":1,
"state":"connected"
},
{
"mode":"tcp",
"host":"192.168.10.17",
"port":"8282",
"preference":2,
"state":"disconnected"
}
]
}
```
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
Diffstat (limited to 'bgpd')
-rw-r--r-- | bgpd/bgp_rpki.c | 114 |
1 files changed, 92 insertions, 22 deletions
diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c index 97e94a97c..b6f59d671 100644 --- a/bgpd/bgp_rpki.c +++ b/bgpd/bgp_rpki.c @@ -1312,28 +1312,51 @@ DEFUN (show_rpki_cache_server, return CMD_SUCCESS; } -DEFUN (show_rpki_cache_connection, +DEFPY (show_rpki_cache_connection, show_rpki_cache_connection_cmd, - "show rpki cache-connection", + "show rpki cache-connection [json$uj]", SHOW_STR RPKI_OUTPUT_STRING - "Show to which RPKI Cache Servers we have a connection\n") + "Show to which RPKI Cache Servers we have a connection\n" + JSON_STR) { + struct json_object *json = NULL; + struct json_object *json_conn = NULL; + struct json_object *json_conns = NULL; + struct listnode *cache_node; + struct cache *cache; + struct rtr_mgr_group *group; + + if (uj) + json = json_object_new_object(); + if (!is_synchronized()) { - vty_out(vty, "No connection to RPKI cache server.\n"); + if (!json) + vty_out(vty, "No connection to RPKI cache server.\n"); + else + vty_json(vty, json); return CMD_SUCCESS; } - struct listnode *cache_node; - struct cache *cache; - struct rtr_mgr_group *group = get_connected_group(); - + group = get_connected_group(); if (!group) { - vty_out(vty, "Cannot find a connected group.\n"); + if (!json) + vty_out(vty, "Cannot find a connected group.\n"); + else + vty_json(vty, json); + return CMD_SUCCESS; } - vty_out(vty, "Connected to group %d\n", group->preference); + + if (!json) { + vty_out(vty, "Connected to group %d\n", group->preference); + } else { + json_conns = json_object_new_array(); + json_object_int_add(json, "connectedGroup", group->preference); + json_object_object_add(json, "connections", json_conns); + } + for (ALL_LIST_ELEMENTS_RO(cache_list, cache_node, cache)) { struct tr_tcp_config *tcp_config; #if defined(FOUND_SSH) @@ -1342,22 +1365,66 @@ DEFUN (show_rpki_cache_connection, switch (cache->type) { case TCP: tcp_config = cache->tr_config.tcp_config; - vty_out(vty, "rpki tcp cache %s %s pref %hhu%s\n", - tcp_config->host, tcp_config->port, - cache->preference, - cache->rtr_socket->state == RTR_ESTABLISHED - ? " (connected)" - : ""); + + if (!json) { + vty_out(vty, + "rpki tcp cache %s %s pref %hhu%s\n", + tcp_config->host, tcp_config->port, + cache->preference, + cache->rtr_socket->state == + RTR_ESTABLISHED + ? " (connected)" + : ""); + } else { + json_conn = json_object_new_object(); + json_object_string_add(json_conn, "mode", + "tcp"); + json_object_string_add(json_conn, "host", + tcp_config->host); + json_object_string_add(json_conn, "port", + tcp_config->port); + json_object_int_add(json_conn, "preference", + cache->preference); + json_object_string_add( + json_conn, "state", + cache->rtr_socket->state == + RTR_ESTABLISHED + ? "connected" + : "disconnected"); + json_object_array_add(json_conns, json_conn); + } break; #if defined(FOUND_SSH) case SSH: ssh_config = cache->tr_config.ssh_config; - vty_out(vty, "rpki ssh cache %s %u pref %hhu%s\n", - ssh_config->host, ssh_config->port, - cache->preference, - cache->rtr_socket->state == RTR_ESTABLISHED - ? " (connected)" - : ""); + + if (!json) { + vty_out(vty, + "rpki ssh cache %s %u pref %hhu%s\n", + ssh_config->host, ssh_config->port, + cache->preference, + cache->rtr_socket->state == + RTR_ESTABLISHED + ? " (connected)" + : ""); + } else { + json_conn = json_object_new_object(); + json_object_string_add(json_conn, "mode", + "ssh"); + json_object_string_add(json_conn, "host", + ssh_config->host); + json_object_string_add(json_conn, "port", + ssh_config->port); + json_object_int_add(json_conn, "preference", + cache->preference); + json_object_string_add( + json_conn, "state", + cache->rtr_socket->state == + RTR_ESTABLISHED + ? "connected" + : "disconnected"); + json_object_array_add(json_conns, json_conn); + } break; #endif default: @@ -1365,6 +1432,9 @@ DEFUN (show_rpki_cache_connection, } } + if (json) + vty_json(vty, json); + return CMD_SUCCESS; } |