Skip to content

Commit 9d4286e

Browse files
committed
bgpd: ability to remove rpki contexts from vty
rpki context can be removed by doing 'no rpki' command from configure node. this work allows to allocate the associated rpki_vrf context when entering in rpki node, instead of at the initialisation step. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
1 parent 28eb941 commit 9d4286e

1 file changed

Lines changed: 60 additions & 24 deletions

File tree

bgpd/bgp_rpki.c

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -572,33 +572,53 @@ static void rpki_init_sync_socket(struct rpki_vrf *rpki_vrf)
572572

573573
}
574574

575-
static int bgp_rpki_init(struct thread_master *master)
575+
static struct rpki_vrf *bgp_rpki_allocate(const char *vrfname)
576576
{
577-
struct rpki_vrf *def_rpki_vrf;
577+
struct rpki_vrf *rpki_vrf;
578+
579+
rpki_vrf = XCALLOC(MTYPE_BGP_RPKI_CACHE,
580+
sizeof(struct rpki_vrf));
578581

582+
rpki_vrf->rtr_is_running = 0;
583+
rpki_vrf->rtr_is_stopping = 0;
584+
rpki_vrf->cache_list = list_new();
585+
rpki_vrf->cache_list->del = (void (*)(void *)) & free_cache;
586+
rpki_vrf->polling_period = POLLING_PERIOD_DEFAULT;
587+
rpki_vrf->expire_interval = EXPIRE_INTERVAL_DEFAULT;
588+
rpki_vrf->retry_interval = RETRY_INTERVAL_DEFAULT;
589+
590+
if (vrfname && !strmatch(vrfname, VRF_DEFAULT_NAME))
591+
rpki_vrf->vrfname = XSTRDUP(MTYPE_BGP_RPKI_CACHE,
592+
vrfname);
593+
QOBJ_REG(rpki_vrf, rpki_vrf);
594+
listnode_add(rpki_vrf_list, rpki_vrf);
595+
return rpki_vrf;
596+
}
597+
598+
static int bgp_rpki_init(struct thread_master *master)
599+
{
579600
rpki_debug_conf = 0;
580601
rpki_debug_term = 0;
581602

582603
rpki_vrf_list = list_new();
583-
/* initialise default vrf cache list */
584-
def_rpki_vrf = XCALLOC(MTYPE_BGP_RPKI_CACHE,
585-
sizeof(struct rpki_vrf));
586-
listnode_add(rpki_vrf_list, def_rpki_vrf);
604+
install_cli_commands();
587605

588-
def_rpki_vrf->rtr_is_running = 0;
589-
def_rpki_vrf->rtr_is_stopping = 0;
590-
def_rpki_vrf->cache_list = list_new();
591-
def_rpki_vrf->cache_list->del = (void (*)(void *)) & free_cache;
592-
def_rpki_vrf->polling_period = POLLING_PERIOD_DEFAULT;
593-
def_rpki_vrf->expire_interval = EXPIRE_INTERVAL_DEFAULT;
594-
def_rpki_vrf->retry_interval = RETRY_INTERVAL_DEFAULT;
606+
return 0;
607+
}
595608

596-
QOBJ_REG(def_rpki_vrf, rpki_vrf);
609+
static void bgp_rpki_finish(struct rpki_vrf *rpki_vrf)
610+
{
611+
stop(rpki_vrf);
612+
list_delete(&rpki_vrf->cache_list);
597613

598-
install_cli_commands();
614+
close(rpki_vrf->rpki_sync_socket_rtr);
615+
close(rpki_vrf->rpki_sync_socket_bgpd);
599616

600-
rpki_init_sync_socket(def_rpki_vrf);
601-
return 0;
617+
listnode_delete(rpki_vrf_list, rpki_vrf);
618+
QOBJ_UNREG(rpki_vrf);
619+
if (rpki_vrf->vrfname)
620+
XFREE(MTYPE_BGP_RPKI_CACHE, rpki_vrf->vrfname);
621+
XFREE(MTYPE_BGP_RPKI_CACHE, rpki_vrf);
602622
}
603623

604624
static int bgp_rpki_fini(void)
@@ -609,12 +629,7 @@ static int bgp_rpki_fini(void)
609629
rpki_vrf = find_rpki_vrf(NULL);
610630
if (!rpki_vrf)
611631
return 0;
612-
613-
stop(rpki_vrf);
614-
list_delete(&rpki_vrf->cache_list);
615-
616-
close(rpki_vrf->rpki_sync_socket_rtr);
617-
close(rpki_vrf->rpki_sync_socket_bgpd);
632+
bgp_rpki_finish(rpki_vrf);
618633

619634
return 0;
620635
}
@@ -1068,8 +1083,28 @@ DEFUN_NOSH (rpki,
10681083
vty->node = RPKI_NODE;
10691084
/* assume default vrf */
10701085
rpki_vrf = find_rpki_vrf(NULL);
1086+
if (!rpki_vrf) {
1087+
rpki_vrf = bgp_rpki_allocate(NULL);
1088+
1089+
rpki_init_sync_socket(rpki_vrf);
1090+
}
1091+
VTY_PUSH_CONTEXT(RPKI_NODE, rpki_vrf);
1092+
return CMD_SUCCESS;
1093+
}
1094+
1095+
DEFUN_NOSH (no_rpki,
1096+
no_rpki_cmd,
1097+
"no rpki",
1098+
NO_STR
1099+
"Enable rpki and enter rpki configuration mode\n")
1100+
{
1101+
struct rpki_vrf *rpki_vrf;
1102+
1103+
/* assume default vrf */
1104+
rpki_vrf = find_rpki_vrf(NULL);
1105+
10711106
if (rpki_vrf)
1072-
VTY_PUSH_CONTEXT(RPKI_NODE, rpki_vrf);
1107+
bgp_rpki_finish(rpki_vrf);
10731108
return CMD_SUCCESS;
10741109
}
10751110

@@ -1770,6 +1805,7 @@ static void install_cli_commands(void)
17701805
install_default(RPKI_NODE);
17711806
overwrite_exit_commands();
17721807
install_element(CONFIG_NODE, &rpki_cmd);
1808+
install_element(CONFIG_NODE, &no_rpki_cmd);
17731809

17741810
install_element(ENABLE_NODE, &bgp_rpki_start_cmd);
17751811
install_element(ENABLE_NODE, &bgp_rpki_stop_cmd);

0 commit comments

Comments
 (0)