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;
}
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;
}
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;
}
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;
}
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);
}
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);
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);
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);
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);
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);
}
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);
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);
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);
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);
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");
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,
"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);
"", " 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)
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;
}
- }
- if (created) {
- if (DFLT_OSPF_LOG_ADJACENCY_CHANGES)
- SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
+ *vrf_name = argv[idx_vrf + 1]->arg;
+ if (*vrf_name && strmatch(*vrf_name, VRF_DEFAULT_NAME))
+ *vrf_name = NULL;
}
- return ospf;
+ return CMD_SUCCESS;
}
static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty,
"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;
}
"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;
}
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)
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)
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)
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();
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)
{
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,
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)
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)
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,
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(
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);
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));
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
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);
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);
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);
*/
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;
}
/* 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;
}
struct ospf_if_params *params;
const char *auth_str;
int write = 0;
- struct ospf *ospf = vrf->info;
FOR_ALL_INTERFACES (vrf, ifp) {
/* 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");