]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Add JSON support for `show rpki cache-server`
authorDonatas Abraitis <donatas@opensourcerouting.org>
Tue, 24 May 2022 12:43:47 +0000 (15:43 +0300)
committerDonatas Abraitis <donatas@opensourcerouting.org>
Tue, 24 May 2022 16:31:11 +0000 (19:31 +0300)
```
spine1-debian-11# sh rpki cache-server json
{
  "servers":[
    {
      "mode":"tcp",
      "host":"192.168.10.17",
      "port":"8283"
    },
    {
      "mode":"tcp",
      "host":"192.168.10.17",
      "port":"8282"
    }
  ]
}
spine1-debian-11# sh rpki cache-server
host: 192.168.10.17 port: 8283
host: 192.168.10.17 port: 8282
spine1-debian-11#
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
bgpd/bgp_rpki.c
doc/user/rpki.rst

index e20ea15e037556b493b8f1ce69ec584cf684c43f..1acb36127f4793608f3311e1769b824a3d92c961 100644 (file)
@@ -1278,37 +1278,89 @@ DEFPY (show_rpki_prefix,
        return CMD_SUCCESS;
 }
 
-DEFUN (show_rpki_cache_server,
+DEFPY (show_rpki_cache_server,
        show_rpki_cache_server_cmd,
-       "show rpki cache-server",
+       "show rpki cache-server [json$uj]",
        SHOW_STR
        RPKI_OUTPUT_STRING
-       "SHOW configured cache server\n")
+       "Show configured cache server\n"
+       JSON_STR)
 {
+       struct json_object *json = NULL;
+       struct json_object *json_server = NULL;
+       struct json_object *json_servers = NULL;
        struct listnode *cache_node;
        struct cache *cache;
 
+       if (uj) {
+               json = json_object_new_object();
+               json_servers = json_object_new_array();
+               json_object_object_add(json, "servers", json_servers);
+       }
+
        for (ALL_LIST_ELEMENTS_RO(cache_list, cache_node, cache)) {
                if (cache->type == TCP) {
-                       vty_out(vty, "host: %s port: %s\n",
-                               cache->tr_config.tcp_config->host,
-                               cache->tr_config.tcp_config->port);
+                       if (!json) {
+                               vty_out(vty, "host: %s port: %s\n",
+                                       cache->tr_config.tcp_config->host,
+                                       cache->tr_config.tcp_config->port);
+                       } else {
+                               json_server = json_object_new_object();
+                               json_object_string_add(json_server, "mode",
+                                                      "tcp");
+                               json_object_string_add(
+                                       json_server, "host",
+                                       cache->tr_config.tcp_config->host);
+                               json_object_string_add(
+                                       json_server, "port",
+                                       cache->tr_config.tcp_config->port);
+                               json_object_array_add(json_servers,
+                                                     json_server);
+                       }
 
 #if defined(FOUND_SSH)
                } else if (cache->type == SSH) {
-                       vty_out(vty,
-                               "host: %s port: %d username: %s server_hostkey_path: %s client_privkey_path: %s\n",
-                               cache->tr_config.ssh_config->host,
-                               cache->tr_config.ssh_config->port,
-                               cache->tr_config.ssh_config->username,
-                               cache->tr_config.ssh_config
-                                       ->server_hostkey_path,
-                               cache->tr_config.ssh_config
-                                       ->client_privkey_path);
+                       if (!json) {
+                               vty_out(vty,
+                                       "host: %s port: %d username: %s server_hostkey_path: %s client_privkey_path: %s\n",
+                                       cache->tr_config.ssh_config->host,
+                                       cache->tr_config.ssh_config->port,
+                                       cache->tr_config.ssh_config->username,
+                                       cache->tr_config.ssh_config
+                                               ->server_hostkey_path,
+                                       cache->tr_config.ssh_config
+                                               ->client_privkey_path);
+                       } else {
+                               json_server = json_object_new_object();
+                               json_object_string_add(json_server, "mode",
+                                                      "ssh");
+                               json_object_string_add(
+                                       json_server, "host",
+                                       cache->tr_config.ssh_config->host);
+                               json_object_int_add(
+                                       json_server, "port",
+                                       cache->tr_config.ssh_config->port);
+                               json_object_string_add(
+                                       json_server, "username",
+                                       cache->tr_config.ssh_config->username);
+                               json_object_string_add(
+                                       json_server, "serverHostkeyPath",
+                                       cache->tr_config.ssh_config
+                                               ->server_hostkey_path);
+                               json_object_string_add(
+                                       json_server, "clientPrivkeyPath",
+                                       cache->tr_config.ssh_config
+                                               ->client_privkey_path);
+                               json_object_array_add(json_servers,
+                                                     json_server);
+                       }
 #endif
                }
        }
 
+       if (json)
+               vty_json(vty, json);
+
        return CMD_SUCCESS;
 }
 
index f03d8233f78ac6e384b205656e8ca9ca0f4ac684..ece788d9e3c42a7c0d96b4c6c00a7fb2321cecb7 100644 (file)
@@ -216,10 +216,14 @@ 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 [json]
+.. clicmd:: show rpki cache-server [json]
 
    Display all configured cache servers, whether active or not.
 
+.. clicmd:: show rpki cache-connection [json]
+
+   Display all cache connections, and show which is connected or not.
+
 .. clicmd:: show bgp [afi] [safi] <A.B.C.D|A.B.C.D/M|X:X::X:X|X:X::X:X/M> rpki <valid|invalid|notfound>
 
    Display for the specified prefix or address the bgp paths that match the given rpki state.