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>
This commit is contained in:
Philippe Guibert 2019-09-19 16:37:14 +02:00 committed by Louis Scalbert
parent 1420189c11
commit a42d490ac2
3 changed files with 71 additions and 13 deletions

View File

@ -51,6 +51,9 @@
#include "bgpd/bgp_routemap_nb.h" #include "bgpd/bgp_routemap_nb.h"
#include "bgpd/bgp_community_alias.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 #ifdef ENABLE_BGP_VNC
#include "bgpd/rfapi/rfapi_backend.h" #include "bgpd/rfapi/rfapi_backend.h"
#endif #endif
@ -344,9 +347,29 @@ static int bgp_vrf_disable(struct vrf *vrf)
return 0; 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) static void bgp_vrf_init(void)
{ {
vrf_init(bgp_vrf_new, bgp_vrf_enable, bgp_vrf_disable, bgp_vrf_delete); 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) static void bgp_vrf_terminate(void)

View File

@ -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_RTRLIB, "BGP RPKI RTRLib");
DEFINE_MTYPE_STATIC(BGPD, BGP_RPKI_REVALIDATE, "BGP RPKI Revalidation"); DEFINE_MTYPE_STATIC(BGPD, BGP_RPKI_REVALIDATE, "BGP RPKI Revalidation");
#define STR_SEPARATOR 10
#define POLLING_PERIOD_DEFAULT 3600 #define POLLING_PERIOD_DEFAULT 3600
#define EXPIRE_INTERVAL_DEFAULT 7200 #define EXPIRE_INTERVAL_DEFAULT 7200
#define RETRY_INTERVAL_DEFAULT 600 #define RETRY_INTERVAL_DEFAULT 600
@ -109,6 +111,8 @@ struct rpki_vrf {
static struct rpki_vrf *find_rpki_vrf(const char *vrfname); 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_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 bgp_rpki_write_debug(struct vty *vty, bool running);
static int start(struct rpki_vrf *rpki_vrf); static int start(struct rpki_vrf *rpki_vrf);
static void stop(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(frr_early_fini, bgp_rpki_fini);
hook_register(bgp_hook_config_write_debug, &bgp_rpki_write_debug); 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_vrf_update, &bgp_rpki_vrf_update);
hook_register(bgp_hook_config_write_vrf, &bgp_rpki_hook_write_vrf);
return 0; return 0;
} }
@ -1449,14 +1454,34 @@ static int bgp_rpki_write_debug(struct vty *vty, bool running)
return 0; 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 listnode *cache_node;
struct cache *cache; 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;
/* assume default vrf */ if (!vrf) {
rpki_vrf = find_rpki_vrf(NULL); 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;
if (!rpki_vrf) if (!rpki_vrf)
return ERROR; return ERROR;
@ -1467,17 +1492,18 @@ static int config_write(struct vty *vty)
/* do not display the default config values */ /* do not display the default config values */
return 0; return 0;
vty_out(vty, "!\n"); if (vrf_id == VRF_DEFAULT)
vty_out(vty, "rpki\n"); vty_out(vty, "%s!\n", sep);
vty_out(vty, "%srpki\n", sep);
if (rpki_vrf->polling_period != POLLING_PERIOD_DEFAULT) 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); rpki_vrf->polling_period);
if (rpki_vrf->retry_interval != RETRY_INTERVAL_DEFAULT) 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); rpki_vrf->retry_interval);
if (rpki_vrf->expire_interval != EXPIRE_INTERVAL_DEFAULT) 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); rpki_vrf->expire_interval);
for (ALL_LIST_ELEMENTS_RO(rpki_vrf->cache_list, cache_node, cache)) { for (ALL_LIST_ELEMENTS_RO(rpki_vrf->cache_list, cache_node, cache)) {
@ -1488,8 +1514,8 @@ static int config_write(struct vty *vty)
#endif #endif
case TCP: case TCP:
tcp_config = cache->tr_config.tcp_config; tcp_config = cache->tr_config.tcp_config;
vty_out(vty, " rpki cache %s %s ", tcp_config->host, vty_out(vty, "%s rpki cache %s %s ", sep,
tcp_config->port); tcp_config->host, tcp_config->port);
if (tcp_config->bindaddr) if (tcp_config->bindaddr)
vty_out(vty, "source %s ", vty_out(vty, "source %s ",
tcp_config->bindaddr); tcp_config->bindaddr);
@ -1497,7 +1523,7 @@ static int config_write(struct vty *vty)
#if defined(FOUND_SSH) #if defined(FOUND_SSH)
case SSH: case SSH:
ssh_config = cache->tr_config.ssh_config; 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->host, ssh_config->port,
ssh_config->username, ssh_config->username,
ssh_config->client_privkey_path, 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, "preference %hhu\n", cache->preference);
} }
vty_out(vty, "exit\n");
vty_out(vty, "%sexit\n%s", sep, vrf_id == VRF_DEFAULT ? "!\n" : "");
return 1; 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) static struct rpki_vrf *get_rpki_vrf(const char *vrfname)
{ {
struct rpki_vrf *rpki_vrf = NULL; struct rpki_vrf *rpki_vrf = NULL;

View File

@ -34,6 +34,9 @@
#include "lib/bfd.h" #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_MAX_HOSTNAME 64 /* Linux max, is larger than most other sys */
#define BGP_PEER_MAX_HASH_SIZE 16384 #define BGP_PEER_MAX_HASH_SIZE 16384