summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilippe Guibert <philippe.guibert@6wind.com>2019-09-19 16:37:14 +0200
committerLouis Scalbert <louis.scalbert@6wind.com>2024-01-18 13:23:36 +0100
commita42d490ac2eac007a5730b19118f34f18a68e439 (patch)
treef350122ab0cfc99e86ebe54e332ea6e3e7ad6ba5
parent1420189c11e52f8ff306de5d3d0e6a81293e54a9 (diff)
bgpd: show per vrf rpki configuration in show run
Show per VRF RPKI configuration in "show run". Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com> Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
-rw-r--r--bgpd/bgp_main.c23
-rw-r--r--bgpd/bgp_rpki.c58
-rw-r--r--bgpd/bgpd.h3
3 files changed, 71 insertions, 13 deletions
diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c
index 739fab7ddd..1666d654c5 100644
--- a/bgpd/bgp_main.c
+++ b/bgpd/bgp_main.c
@@ -51,6 +51,9 @@
#include "bgpd/bgp_routemap_nb.h"
#include "bgpd/bgp_community_alias.h"
+DEFINE_HOOK(bgp_hook_config_write_vrf, (struct vty *vty, struct vrf *vrf),
+ (vty, vrf));
+
#ifdef ENABLE_BGP_VNC
#include "bgpd/rfapi/rfapi_backend.h"
#endif
@@ -344,9 +347,29 @@ static int bgp_vrf_disable(struct vrf *vrf)
return 0;
}
+static int bgp_vrf_config_write(struct vty *vty)
+{
+ struct vrf *vrf;
+
+ RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
+ if (vrf->vrf_id == VRF_DEFAULT) {
+ vty_out(vty, "!\n");
+ continue;
+ }
+ vty_out(vty, "vrf %s\n", vrf->name);
+
+ hook_call(bgp_hook_config_write_vrf, vty, vrf);
+
+ vty_out(vty, "exit-vrf\n!\n");
+ }
+
+ return 0;
+}
+
static void bgp_vrf_init(void)
{
vrf_init(bgp_vrf_new, bgp_vrf_enable, bgp_vrf_disable, bgp_vrf_delete);
+ vrf_cmd_init(bgp_vrf_config_write);
}
static void bgp_vrf_terminate(void)
diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c
index f2778b0d94..9a056678ae 100644
--- a/bgpd/bgp_rpki.c
+++ b/bgpd/bgp_rpki.c
@@ -50,6 +50,8 @@ DEFINE_MTYPE_STATIC(BGPD, BGP_RPKI_CACHE_GROUP, "BGP RPKI Cache server group");
DEFINE_MTYPE_STATIC(BGPD, BGP_RPKI_RTRLIB, "BGP RPKI RTRLib");
DEFINE_MTYPE_STATIC(BGPD, BGP_RPKI_REVALIDATE, "BGP RPKI Revalidation");
+#define STR_SEPARATOR 10
+
#define POLLING_PERIOD_DEFAULT 3600
#define EXPIRE_INTERVAL_DEFAULT 7200
#define RETRY_INTERVAL_DEFAULT 600
@@ -109,6 +111,8 @@ struct rpki_vrf {
static struct rpki_vrf *find_rpki_vrf(const char *vrfname);
static int bgp_rpki_vrf_update(struct vrf *vrf, bool enabled);
+static int bgp_rpki_write_vrf(struct vty *vty, struct vrf *vrf);
+static int bgp_rpki_hook_write_vrf(struct vty *vty, struct vrf *vrf);
static int bgp_rpki_write_debug(struct vty *vty, bool running);
static int start(struct rpki_vrf *rpki_vrf);
static void stop(struct rpki_vrf *rpki_vrf);
@@ -852,6 +856,7 @@ static int bgp_rpki_module_init(void)
hook_register(frr_early_fini, bgp_rpki_fini);
hook_register(bgp_hook_config_write_debug, &bgp_rpki_write_debug);
hook_register(bgp_hook_vrf_update, &bgp_rpki_vrf_update);
+ hook_register(bgp_hook_config_write_vrf, &bgp_rpki_hook_write_vrf);
return 0;
}
@@ -1449,14 +1454,34 @@ static int bgp_rpki_write_debug(struct vty *vty, bool running)
return 0;
}
-static int config_write(struct vty *vty)
+static int bgp_rpki_hook_write_vrf(struct vty *vty, struct vrf *vrf)
+{
+ int ret;
+
+ ret = bgp_rpki_write_vrf(vty, vrf);
+ if (ret == ERROR)
+ return 0;
+ return ret;
+}
+
+static int bgp_rpki_write_vrf(struct vty *vty, struct vrf *vrf)
{
struct listnode *cache_node;
struct cache *cache;
- struct rpki_vrf *rpki_vrf;
+ struct rpki_vrf *rpki_vrf = NULL;
+ char sep[STR_SEPARATOR];
+ vrf_id_t vrf_id = VRF_DEFAULT;
+
+ if (!vrf) {
+ rpki_vrf = find_rpki_vrf(NULL);
+ snprintf(sep, sizeof(sep), "%s", "");
+ } else if (vrf->vrf_id != VRF_DEFAULT) {
+ rpki_vrf = find_rpki_vrf(vrf->name);
+ snprintf(sep, sizeof(sep), "%s", " ");
+ vrf_id = vrf->vrf_id;
+ } else
+ return ERROR;
- /* assume default vrf */
- rpki_vrf = find_rpki_vrf(NULL);
if (!rpki_vrf)
return ERROR;
@@ -1467,17 +1492,18 @@ static int config_write(struct vty *vty)
/* do not display the default config values */
return 0;
- vty_out(vty, "!\n");
- vty_out(vty, "rpki\n");
+ if (vrf_id == VRF_DEFAULT)
+ vty_out(vty, "%s!\n", sep);
+ vty_out(vty, "%srpki\n", sep);
if (rpki_vrf->polling_period != POLLING_PERIOD_DEFAULT)
- vty_out(vty, " rpki polling_period %d\n",
+ vty_out(vty, "%s rpki polling_period %d\n", sep,
rpki_vrf->polling_period);
if (rpki_vrf->retry_interval != RETRY_INTERVAL_DEFAULT)
- vty_out(vty, " rpki retry_interval %d\n",
+ vty_out(vty, "%s rpki retry_interval %d\n", sep,
rpki_vrf->retry_interval);
if (rpki_vrf->expire_interval != EXPIRE_INTERVAL_DEFAULT)
- vty_out(vty, " rpki expire_interval %d\n",
+ vty_out(vty, "%s rpki expire_interval %d\n", sep,
rpki_vrf->expire_interval);
for (ALL_LIST_ELEMENTS_RO(rpki_vrf->cache_list, cache_node, cache)) {
@@ -1488,8 +1514,8 @@ static int config_write(struct vty *vty)
#endif
case TCP:
tcp_config = cache->tr_config.tcp_config;
- vty_out(vty, " rpki cache %s %s ", tcp_config->host,
- tcp_config->port);
+ vty_out(vty, "%s rpki cache %s %s ", sep,
+ tcp_config->host, tcp_config->port);
if (tcp_config->bindaddr)
vty_out(vty, "source %s ",
tcp_config->bindaddr);
@@ -1497,7 +1523,7 @@ static int config_write(struct vty *vty)
#if defined(FOUND_SSH)
case SSH:
ssh_config = cache->tr_config.ssh_config;
- vty_out(vty, " rpki cache %s %u %s %s %s ",
+ vty_out(vty, "%s rpki cache %s %u %s %s %s ", sep,
ssh_config->host, ssh_config->port,
ssh_config->username,
ssh_config->client_privkey_path,
@@ -1515,11 +1541,17 @@ static int config_write(struct vty *vty)
vty_out(vty, "preference %hhu\n", cache->preference);
}
- vty_out(vty, "exit\n");
+
+ vty_out(vty, "%sexit\n%s", sep, vrf_id == VRF_DEFAULT ? "!\n" : "");
return 1;
}
+static int config_write(struct vty *vty)
+{
+ return bgp_rpki_write_vrf(vty, NULL);
+}
+
static struct rpki_vrf *get_rpki_vrf(const char *vrfname)
{
struct rpki_vrf *rpki_vrf = NULL;
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 73a909f98f..1cc82748b6 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -34,6 +34,9 @@
#include "lib/bfd.h"
+DECLARE_HOOK(bgp_hook_config_write_vrf, (struct vty *vty, struct vrf *vrf),
+ (vty, vrf));
+
#define BGP_MAX_HOSTNAME 64 /* Linux max, is larger than most other sys */
#define BGP_PEER_MAX_HASH_SIZE 16384