ospfd: don't rely on instance existence in vty

Store instance index at startup and use it when processing vty commands.
The instance itself may be created and deleted by the user in runtime
using `[no] router ospf X` command.

Fixes #7908

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
This commit is contained in:
Igor Ryzhov 2021-01-28 02:41:07 +03:00
parent 0ff7911386
commit 409f98ab44
5 changed files with 155 additions and 186 deletions

View File

@ -616,7 +616,7 @@ DEFUN (debug_ospf_packet,
if (inst) // user passed instance ID
{
if (!ospf_lookup_instance(strtoul(argv[2]->arg, NULL, 10)))
if (inst != ospf_instance)
return CMD_NOT_MY_INSTANCE;
}
@ -692,7 +692,7 @@ DEFUN (no_debug_ospf_packet,
if (inst) // user passed instance ID
{
if (!ospf_lookup_instance(strtoul(argv[3]->arg, NULL, 10)))
if (inst != ospf_instance)
return CMD_NOT_MY_INSTANCE;
}
@ -763,7 +763,7 @@ DEFUN (debug_ospf_ism,
if (inst) // user passed instance ID
{
if (!ospf_lookup_instance(strtoul(argv[2]->arg, NULL, 10)))
if (inst != ospf_instance)
return CMD_NOT_MY_INSTANCE;
}
@ -814,7 +814,7 @@ DEFUN (no_debug_ospf_ism,
if (inst) // user passed instance ID
{
if (!ospf_lookup_instance(strtoul(argv[3]->arg, NULL, 10)))
if (inst != ospf_instance)
return CMD_NOT_MY_INSTANCE;
}
@ -909,8 +909,8 @@ DEFUN (debug_ospf_instance_nsm,
unsigned short instance = 0;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
if (!ospf_lookup_instance(instance))
return CMD_SUCCESS;
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
return debug_ospf_nsm_common(vty, 4, argc, argv);
}
@ -981,7 +981,7 @@ DEFUN (no_debug_ospf_instance_nsm,
unsigned short instance = 0;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
if (!ospf_lookup_instance(instance))
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
return no_debug_ospf_nsm_common(vty, 5, argc, argv);
@ -1062,7 +1062,7 @@ DEFUN (debug_ospf_instance_lsa,
unsigned short instance = 0;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
if (!ospf_lookup_instance(instance))
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
return debug_ospf_lsa_common(vty, 4, argc, argv);
@ -1145,7 +1145,7 @@ DEFUN (no_debug_ospf_instance_lsa,
unsigned short instance = 0;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
if (!ospf_lookup_instance(instance))
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
return no_debug_ospf_lsa_common(vty, 5, argc, argv);
@ -1207,7 +1207,7 @@ DEFUN (debug_ospf_instance_zebra,
unsigned short instance = 0;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
if (!ospf_lookup_instance(instance))
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
return debug_ospf_zebra_common(vty, 4, argc, argv);
@ -1271,8 +1271,8 @@ DEFUN (no_debug_ospf_instance_zebra,
unsigned short instance = 0;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
if (!ospf_lookup_instance(instance))
return CMD_SUCCESS;
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
return no_debug_ospf_zebra_common(vty, 5, argc, argv);
}
@ -1317,8 +1317,8 @@ DEFUN (debug_ospf_instance_event,
unsigned short instance = 0;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
if (!ospf_lookup_instance(instance))
return CMD_SUCCESS;
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (vty->node == CONFIG_NODE)
CONF_DEBUG_ON(event, EVENT);
@ -1339,8 +1339,8 @@ DEFUN (no_debug_ospf_instance_event,
unsigned short instance = 0;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
if (!ospf_lookup_instance(instance))
return CMD_SUCCESS;
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (vty->node == CONFIG_NODE)
CONF_DEBUG_OFF(event, EVENT);
@ -1387,8 +1387,8 @@ DEFUN (debug_ospf_instance_nssa,
unsigned short instance = 0;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
if (!ospf_lookup_instance(instance))
return CMD_SUCCESS;
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (vty->node == CONFIG_NODE)
CONF_DEBUG_ON(nssa, NSSA);
@ -1409,8 +1409,8 @@ DEFUN (no_debug_ospf_instance_nssa,
unsigned short instance = 0;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
if (!ospf_lookup_instance(instance))
return CMD_SUCCESS;
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (vty->node == CONFIG_NODE)
CONF_DEBUG_OFF(nssa, NSSA);
@ -1625,12 +1625,12 @@ DEFUN (no_debug_ospf,
return CMD_SUCCESS;
}
static int show_debugging_ospf_common(struct vty *vty, struct ospf *ospf)
static int show_debugging_ospf_common(struct vty *vty)
{
int i;
if (ospf->instance)
vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
if (ospf_instance)
vty_out(vty, "\nOSPF Instance: %d\n\n", ospf_instance);
vty_out(vty, "OSPF debugging status:\n");
@ -1742,13 +1742,7 @@ DEFUN_NOSH (show_debugging_ospf,
DEBUG_STR
OSPF_STR)
{
struct ospf *ospf = NULL;
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL)
return CMD_SUCCESS;
return show_debugging_ospf_common(vty, ospf);
return show_debugging_ospf_common(vty);
}
DEFUN_NOSH (show_debugging_ospf_instance,
@ -1760,14 +1754,13 @@ DEFUN_NOSH (show_debugging_ospf_instance,
"Instance ID\n")
{
int idx_number = 3;
struct ospf *ospf;
unsigned short instance = 0;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
if ((ospf = ospf_lookup_instance(instance)) == NULL)
return CMD_SUCCESS;
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
return show_debugging_ospf_common(vty, ospf);
return show_debugging_ospf_common(vty);
}
static int config_write_debug(struct vty *vty);
@ -1790,16 +1783,11 @@ static int config_write_debug(struct vty *vty)
"", " send", " recv", "",
" detail", " send detail", " recv detail", " detail"};
struct ospf *ospf;
char str[16];
memset(str, 0, 16);
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL)
return CMD_SUCCESS;
if (ospf->instance)
snprintf(str, sizeof(str), " %u", ospf->instance);
if (ospf_instance)
snprintf(str, sizeof(str), " %u", ospf_instance);
/* debug ospf ism (status|events|timers). */
if (IS_CONF_DEBUG_OSPF(ism, ISM) == OSPF_DEBUG_ISM)

View File

@ -146,9 +146,6 @@ FRR_DAEMON_INFO(ospfd, OSPF, .vty_port = OSPF_VTY_PORT,
/* OSPFd main routine. */
int main(int argc, char **argv)
{
unsigned short instance = 0;
bool created = false;
#ifdef SUPPORT_OSPF_API
/* OSPF apiserver is disabled by default. */
ospf_apiserver_enable = 0;
@ -169,8 +166,8 @@ int main(int argc, char **argv)
switch (opt) {
case 'n':
ospfd_di.instance = instance = atoi(optarg);
if (instance < 1)
ospfd_di.instance = ospf_instance = atoi(optarg);
if (ospf_instance < 1)
exit(0);
break;
case 0:
@ -208,7 +205,7 @@ int main(int argc, char **argv)
/* OSPFd inits. */
ospf_if_init();
ospf_zebra_init(master, instance);
ospf_zebra_init(master, ospf_instance);
/* OSPF vty inits. */
ospf_vty_init();
@ -227,17 +224,6 @@ int main(int argc, char **argv)
/* OSPF errors init */
ospf_error_init();
/*
* Need to initialize the default ospf structure, so the interface mode
* commands can be duly processed if they are received before 'router
* ospf', when ospfd is restarted
*/
if (instance && !ospf_get_instance(instance, &created)) {
flog_err(EC_OSPF_INIT_FAIL, "OSPF instance init failed: %s",
strerror(errno));
exit(1);
}
frr_config_fork();
frr_run(master);

View File

@ -140,44 +140,37 @@ int ospf_oi_count(struct interface *ifp)
all_vrf = strmatch(vrf_name, "all"); \
}
static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty,
struct cmd_token *argv[],
const int argc, uint32_t enable,
unsigned short *instance)
static int ospf_router_cmd_parse(struct vty *vty, struct cmd_token *argv[],
const int argc, unsigned short *instance,
const char **vrf_name)
{
struct ospf *ospf = NULL;
int idx_vrf = 0, idx_inst = 0;
const char *vrf_name = NULL;
bool created = false;
*instance = 0;
if (argv_find(argv, argc, "(1-65535)", &idx_inst))
if (argv_find(argv, argc, "(1-65535)", &idx_inst)) {
if (ospf_instance == 0) {
vty_out(vty,
"%% OSPF is not running in instance mode\n");
return CMD_WARNING_CONFIG_FAILED;
}
*instance = strtoul(argv[idx_inst]->arg, NULL, 10);
}
*vrf_name = NULL;
if (argv_find(argv, argc, "vrf", &idx_vrf)) {
vrf_name = argv[idx_vrf + 1]->arg;
if (vrf_name == NULL || strmatch(vrf_name, VRF_DEFAULT_NAME))
vrf_name = NULL;
if (enable) {
/* Allocate VRF aware instance */
ospf = ospf_get(*instance, vrf_name, &created);
} else {
ospf = ospf_lookup_by_inst_name(*instance, vrf_name);
}
} else {
if (enable) {
ospf = ospf_get(*instance, NULL, &created);
} else {
ospf = ospf_lookup_instance(*instance);
if (ospf_instance != 0) {
vty_out(vty,
"%% VRF is not supported in instance mode\n");
return CMD_WARNING_CONFIG_FAILED;
}
*vrf_name = argv[idx_vrf + 1]->arg;
if (*vrf_name && strmatch(*vrf_name, VRF_DEFAULT_NAME))
*vrf_name = NULL;
}
if (created) {
if (DFLT_OSPF_LOG_ADJACENCY_CHANGES)
SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
}
return ospf;
return CMD_SUCCESS;
}
static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty,
@ -213,28 +206,35 @@ DEFUN_NOSH (router_ospf,
"Instance ID\n"
VRF_CMD_HELP_STR)
{
struct ospf *ospf = NULL;
int ret = CMD_SUCCESS;
unsigned short instance = 0;
unsigned short instance;
const char *vrf_name;
bool created = false;
struct ospf *ospf;
int ret;
ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 1, &instance);
if (!ospf)
return CMD_WARNING_CONFIG_FAILED;
ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name);
if (ret != CMD_SUCCESS)
return ret;
/* The following logic to set the vty qobj index is in place to be able
to ignore the commands which dont belong to this instance. */
if (ospf->instance != instance) {
if (instance != ospf_instance) {
VTY_PUSH_CONTEXT_NULL(OSPF_NODE);
ret = CMD_NOT_MY_INSTANCE;
} else {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
instance, ospf->name ? ospf->name : "NIL",
ospf->vrf_id, ospf->oi_running);
VTY_PUSH_CONTEXT(OSPF_NODE, ospf);
return CMD_NOT_MY_INSTANCE;
}
ospf = ospf_get(instance, vrf_name, &created);
if (created)
if (DFLT_OSPF_LOG_ADJACENCY_CHANGES)
SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
ospf->instance, ospf->name ? ospf->name : "NIL",
ospf->vrf_id, ospf->oi_running);
VTY_PUSH_CONTEXT(OSPF_NODE, ospf);
return ret;
}
@ -247,19 +247,25 @@ DEFUN (no_router_ospf,
"Instance ID\n"
VRF_CMD_HELP_STR)
{
unsigned short instance;
const char *vrf_name;
struct ospf *ospf;
unsigned short instance = 0;
int ret;
ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 0, &instance);
if (ospf == NULL) {
if (instance)
return CMD_NOT_MY_INSTANCE;
else
return CMD_WARNING;
}
ospf_finish(ospf);
ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name);
if (ret != CMD_SUCCESS)
return ret;
return CMD_SUCCESS;
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
ospf = ospf_lookup(instance, vrf_name);
if (ospf)
ospf_finish(ospf);
else
ret = CMD_WARNING_CONFIG_FAILED;
return ret;
}
@ -3381,11 +3387,11 @@ DEFUN (show_ip_ospf_instance,
json_object *json = NULL;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (!ospf->oi_running)
ospf = ospf_lookup_instance(instance);
if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;
if (uj)
@ -4131,11 +4137,11 @@ DEFUN (show_ip_ospf_instance_interface,
json_object *json = NULL;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (!ospf->oi_running)
ospf = ospf_lookup_instance(instance);
if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;
if (uj)
@ -4526,11 +4532,11 @@ DEFUN (show_ip_ospf_instance_neighbor,
int ret = CMD_SUCCESS;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (!ospf->oi_running)
ospf = ospf_lookup_instance(instance);
if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;
if (uj)
@ -4741,11 +4747,11 @@ DEFUN (show_ip_ospf_instance_neighbor_all,
int ret = CMD_SUCCESS;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (!ospf->oi_running)
ospf = ospf_lookup_instance(instance);
if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;
if (uj)
json = json_object_new_object();
@ -4881,11 +4887,11 @@ DEFUN (show_ip_ospf_instance_neighbor_int,
show_ip_ospf_neighbour_header(vty);
instance = strtoul(argv[idx_number]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (!ospf->oi_running)
ospf = ospf_lookup_instance(instance);
if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;
if (!uj)
@ -5359,11 +5365,11 @@ DEFPY (show_ip_ospf_instance_neighbor_id,
{
struct ospf *ospf;
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (!ospf->oi_running)
ospf = ospf_lookup_instance(instance);
if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;
return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json,
@ -5532,11 +5538,11 @@ DEFUN (show_ip_ospf_instance_neighbor_detail,
int ret = CMD_SUCCESS;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (!ospf->oi_running)
ospf = ospf_lookup_instance(instance);
if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;
if (uj)
@ -5727,11 +5733,11 @@ DEFUN (show_ip_ospf_instance_neighbor_detail_all,
int ret = CMD_SUCCESS;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (!ospf->oi_running)
ospf = ospf_lookup_instance(instance);
if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;
if (uj)
@ -5859,11 +5865,11 @@ DEFUN (show_ip_ospf_instance_neighbor_int_detail,
bool uj = use_json(argc, argv);
instance = strtoul(argv[idx_number]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (!ospf->oi_running)
ospf = ospf_lookup_instance(instance);
if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;
return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname,
@ -7136,10 +7142,11 @@ DEFUN (show_ip_ospf_instance_database,
if (argv_find(argv, argc, "(1-65535)", &idx)) {
instance = strtoul(argv[idx]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (!ospf->oi_running)
ospf = ospf_lookup_instance(instance);
if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;
return (show_ip_ospf_database_common(
@ -7212,15 +7219,12 @@ DEFUN (show_ip_ospf_instance_database_max,
json = json_object_new_object();
instance = strtoul(argv[idx_number]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (!ospf->oi_running) {
vty_out(vty, "%% OSPF instance not found\n");
ospf = ospf_lookup_instance(instance);
if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;
}
show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0, json, uj);
@ -7355,13 +7359,12 @@ DEFUN (show_ip_ospf_instance_database_type_adv_router,
if (argv_find(argv, argc, "(1-65535)", &idx)) {
instance = strtoul(argv[idx]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (!ospf->oi_running) {
vty_out(vty, "%% OSPF instance not found\n");
ospf = ospf_lookup_instance(instance);
if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;
}
return (show_ip_ospf_database_type_adv_router_common(
vty, ospf, idx ? 1 : 0, argc, argv, use_vrf, json, uj));
@ -8819,7 +8822,7 @@ DEFUN (ip_ospf_area,
else
ospf = ospf_lookup_instance(instance);
if (instance && ospf == NULL) {
if (instance && instance != ospf_instance) {
/*
* At this point we know we have received
* an instance and there is no ospf instance
@ -8944,7 +8947,7 @@ DEFUN (no_ip_ospf_area,
else
ospf = ospf_lookup_instance(instance);
if (instance && ospf == NULL)
if (instance && instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
argv_find(argv, argc, "area", &idx);
@ -10918,11 +10921,11 @@ DEFUN (show_ip_ospf_instance_border_routers,
unsigned short instance = 0;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (!ospf->oi_running)
ospf = ospf_lookup_instance(instance);
if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;
return show_ip_ospf_border_routers_common(vty, ospf, 0);
@ -11086,11 +11089,11 @@ DEFUN (show_ip_ospf_instance_route,
unsigned short instance = 0;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
if (!ospf->oi_running)
ospf = ospf_lookup_instance(instance);
if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;
return show_ip_ospf_route_common(vty, ospf, NULL, 0);
@ -11189,8 +11192,7 @@ DEFPY (clear_ip_ospf_neighbor,
*/
if (instance != 0) {
/* This means clear only the particular ospf process */
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
}
@ -11220,8 +11222,7 @@ DEFPY (clear_ip_ospf_process,
/* Check if instance is not passed as an argument */
if (instance != 0) {
/* This means clear only the particular ospf process */
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
}
@ -11545,7 +11546,6 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
struct ospf_if_params *params;
const char *auth_str;
int write = 0;
struct ospf *ospf = vrf->info;
FOR_ALL_INTERFACES (vrf, ifp) {
@ -11698,9 +11698,9 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
/* Area print. */
if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
if (ospf && ospf->instance)
if (ospf_instance)
vty_out(vty, " ip ospf %d",
ospf->instance);
ospf_instance);
else
vty_out(vty, " ip ospf");

View File

@ -70,6 +70,8 @@ static struct ospf_master ospf_master;
/* OSPF process wide configuration pointer to export. */
struct ospf_master *om;
unsigned short ospf_instance;
extern struct zclient *zclient;
@ -511,36 +513,28 @@ static void ospf_init(struct ospf *ospf)
ospf_router_id_update(ospf);
}
struct ospf *ospf_get(unsigned short instance, const char *name, bool *created)
struct ospf *ospf_lookup(unsigned short instance, const char *name)
{
struct ospf *ospf;
/* vrf name provided call inst and name based api
* in case of no name pass default ospf instance */
if (name)
if (ospf_instance) {
ospf = ospf_lookup_instance(instance);
} else {
ospf = ospf_lookup_by_inst_name(instance, name);
else
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
*created = (ospf == NULL);
if (ospf == NULL) {
ospf = ospf_new(instance, name);
ospf_add(ospf);
ospf_init(ospf);
}
return ospf;
}
struct ospf *ospf_get_instance(unsigned short instance, bool *created)
struct ospf *ospf_get(unsigned short instance, const char *name, bool *created)
{
struct ospf *ospf;
ospf = ospf_lookup_instance(instance);
ospf = ospf_lookup(instance, name);
*created = (ospf == NULL);
if (ospf == NULL) {
ospf = ospf_new(instance, NULL /* VRF_DEFAULT*/);
ospf = ospf_new(instance, name);
ospf_add(ospf);
ospf_init(ospf);

View File

@ -633,6 +633,7 @@ struct ospf_nbr_nbma {
/* Extern variables. */
extern struct ospf_master *om;
extern unsigned short ospf_instance;
extern const int ospf_redistributed_proto_max;
extern struct zclient *zclient;
extern struct thread_master *master;
@ -642,10 +643,10 @@ extern struct zebra_privs_t ospfd_privs;
/* Prototypes. */
extern const char *ospf_redist_string(unsigned int route_type);
extern struct ospf *ospf_lookup_instance(unsigned short);
extern struct ospf *ospf_lookup(unsigned short instance, const char *name);
extern struct ospf *ospf_get(unsigned short instance, const char *name,
bool *created);
extern struct ospf *ospf_new_alloc(unsigned short instance, const char *name);
extern struct ospf *ospf_get_instance(unsigned short, bool *created);
extern struct ospf *ospf_lookup_by_inst_name(unsigned short instance,
const char *name);
extern struct ospf *ospf_lookup_by_vrf_id(vrf_id_t vrf_id);