mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-05 06:34:44 +00:00
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>
This commit is contained in:
parent
ac425bfc2b
commit
ae872c2f88
120
bgpd/bgp_rpki.c
120
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)
|
||||
{
|
||||
if (!is_synchronized()) {
|
||||
vty_out(vty, "No connection to RPKI cache server.\n");
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
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 = get_connected_group();
|
||||
struct rtr_mgr_group *group;
|
||||
|
||||
if (uj)
|
||||
json = json_object_new_object();
|
||||
|
||||
if (!is_synchronized()) {
|
||||
if (!json)
|
||||
vty_out(vty, "No connection to RPKI cache server.\n");
|
||||
else
|
||||
vty_json(vty, json);
|
||||
|
||||
if (!group) {
|
||||
vty_out(vty, "Cannot find a connected group.\n");
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
vty_out(vty, "Connected to group %d\n", group->preference);
|
||||
|
||||
group = get_connected_group();
|
||||
if (!group) {
|
||||
if (!json)
|
||||
vty_out(vty, "Cannot find a connected group.\n");
|
||||
else
|
||||
vty_json(vty, json);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,7 @@ Displaying RPKI
|
||||
received from the cache servers and stored in the router. Based on this data,
|
||||
the router validates BGP Updates.
|
||||
|
||||
.. clicmd:: show rpki cache-connection
|
||||
.. clicmd:: show rpki cache-connection [json]
|
||||
|
||||
Display all configured cache servers, whether active or not.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user