summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ospfd/ospf_interface.c40
-rw-r--r--ospfd/ospf_vty.c77
-rw-r--r--ospfd/ospfd.c76
-rw-r--r--ospfd/ospfd.h2
4 files changed, 99 insertions, 96 deletions
diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c
index 6e34740166..e461345fe5 100644
--- a/ospfd/ospf_interface.c
+++ b/ospfd/ospf_interface.c
@@ -535,6 +535,7 @@ static struct ospf_if_params *ospf_new_if_params(void)
UNSET_IF_PARAM(oip, auth_simple);
UNSET_IF_PARAM(oip, auth_crypt);
UNSET_IF_PARAM(oip, auth_type);
+ UNSET_IF_PARAM(oip, if_area);
oip->auth_crypt = list_new();
@@ -579,8 +580,8 @@ void ospf_free_if_params(struct interface *ifp, struct in_addr addr)
&& !OSPF_IF_PARAM_CONFIGURED(oip, type)
&& !OSPF_IF_PARAM_CONFIGURED(oip, auth_simple)
&& !OSPF_IF_PARAM_CONFIGURED(oip, auth_type)
- && listcount(oip->auth_crypt) == 0
- && ntohl(oip->network_lsa_seqnum) != OSPF_INITIAL_SEQUENCE_NUMBER) {
+ && !OSPF_IF_PARAM_CONFIGURED(oip, if_area)
+ && listcount(oip->auth_crypt) == 0) {
ospf_del_if_params(oip);
rn->info = NULL;
route_unlock_node(rn);
@@ -1276,6 +1277,9 @@ void ospf_if_interface(struct interface *ifp)
static int ospf_ifp_create(struct interface *ifp)
{
struct ospf *ospf = NULL;
+ struct ospf_if_params *params;
+ struct route_node *rn;
+ uint32_t count = 0;
if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
zlog_debug(
@@ -1297,6 +1301,19 @@ static int ospf_ifp_create(struct interface *ifp)
if (!ospf)
return 0;
+ params = IF_DEF_PARAMS(ifp);
+ if (OSPF_IF_PARAM_CONFIGURED(params, if_area))
+ count++;
+
+ for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn))
+ if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area))
+ count++;
+
+ if (count > 0) {
+ ospf->if_ospf_cli_count += count;
+ ospf_interface_area_set(ospf, ifp);
+ }
+
ospf_if_recalculate_output_cost(ifp);
ospf_if_update(ospf, ifp);
@@ -1362,7 +1379,10 @@ static int ospf_ifp_down(struct interface *ifp)
static int ospf_ifp_destroy(struct interface *ifp)
{
+ struct ospf *ospf;
+ struct ospf_if_params *params;
struct route_node *rn;
+ uint32_t count = 0;
if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
zlog_debug(
@@ -1373,6 +1393,22 @@ static int ospf_ifp_destroy(struct interface *ifp)
hook_call(ospf_if_delete, ifp);
+ ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ if (ospf) {
+ params = IF_DEF_PARAMS(ifp);
+ if (OSPF_IF_PARAM_CONFIGURED(params, if_area))
+ count++;
+
+ for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn))
+ if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area))
+ count++;
+
+ if (count > 0) {
+ ospf->if_ospf_cli_count -= count;
+ ospf_interface_area_unset(ospf, ifp);
+ }
+ }
+
for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
if (rn->info)
ospf_if_free((struct ospf_interface *)rn->info);
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index 1060f20bdf..7e41880bca 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -214,9 +214,6 @@ DEFUN_NOSH (router_ospf,
struct ospf *ospf = NULL;
int ret = CMD_SUCCESS;
unsigned short instance = 0;
- struct vrf *vrf = NULL;
- struct route_node *rn;
- struct interface *ifp;
ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 1, &instance);
if (!ospf)
@@ -228,46 +225,12 @@ DEFUN_NOSH (router_ospf,
VTY_PUSH_CONTEXT_NULL(OSPF_NODE);
ret = CMD_NOT_MY_INSTANCE;
} else {
- if (ospf->vrf_id != VRF_UNKNOWN)
- ospf->oi_running = 1;
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);
-
- /* Activate 'ip ospf area x' configured interfaces for given
- * vrf. Activate area on vrf x aware interfaces.
- * vrf_enable callback calls router_id_update which
- * internally will call ospf_if_update to trigger
- * network_run_state
- */
- vrf = vrf_lookup_by_id(ospf->vrf_id);
-
- FOR_ALL_INTERFACES (vrf, ifp) {
- struct ospf_if_params *params;
-
- params = IF_DEF_PARAMS(ifp);
- if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
- for (rn = route_top(ospf->networks); rn;
- rn = route_next(rn)) {
- if (rn->info != NULL) {
- vty_out(vty,
- "Interface %s has area config but please remove all network commands first.\n",
- ifp->name);
- return ret;
- }
- }
- if (!ospf_interface_area_is_already_set(ospf,
- ifp)) {
- ospf_interface_area_set(ospf, ifp);
- ospf->if_ospf_cli_count++;
- }
- }
- }
-
- ospf_router_id_update(ospf);
}
return ret;
@@ -8151,6 +8114,7 @@ DEFUN (ip_ospf_area,
struct ospf *ospf = NULL;
unsigned short instance = 0;
char *areaid;
+ uint32_t count = 0;
if (argv_find(argv, argc, "(1-65535)", &idx))
instance = strtol(argv[idx]->arg, NULL, 10);
@@ -8175,15 +8139,28 @@ DEFUN (ip_ospf_area,
* allow the other instance(process) handle
* the configuration command.
*/
+ count = 0;
+
params = IF_DEF_PARAMS(ifp);
if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
UNSET_IF_PARAM(params, if_area);
- ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ count++;
+ }
+
+ for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn))
+ if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
+ UNSET_IF_PARAM(params, if_area);
+ count++;
+ }
+
+ if (count > 0) {
+ ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
if (ospf) {
ospf_interface_area_unset(ospf, ifp);
- ospf->if_ospf_cli_count--;
+ ospf->if_ospf_cli_count -= count;
}
}
+
return CMD_NOT_MY_INSTANCE;
}
@@ -8197,6 +8174,16 @@ DEFUN (ip_ospf_area,
return CMD_WARNING_CONFIG_FAILED;
}
+ if (ospf) {
+ for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) {
+ if (rn->info != NULL) {
+ vty_out(vty,
+ "Please remove all network commands first.\n");
+ return CMD_WARNING_CONFIG_FAILED;
+ }
+ }
+ }
+
params = IF_DEF_PARAMS(ifp);
if (OSPF_IF_PARAM_CONFIGURED(params, if_area)
&& !IPV4_ADDR_SAME(&params->if_area, &area_id)) {
@@ -8216,22 +8203,12 @@ DEFUN (ip_ospf_area,
params = ospf_get_if_params((ifp), (addr));
if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
vty_out(vty,
- "Must remove previous area/address config before changing ospf area");
+ "Must remove previous area/address config before changing ospf area\n");
return CMD_WARNING_CONFIG_FAILED;
}
ospf_if_update_params((ifp), (addr));
}
- if (ospf) {
- for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) {
- if (rn->info != NULL) {
- vty_out(vty,
- "Please remove all network commands first.\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
- }
- }
-
/* enable ospf on this interface with area_id */
if (params) {
SET_IF_PARAM(params, if_area);
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index 3718f82c05..c16798e2fc 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -385,6 +385,8 @@ struct ospf *ospf_lookup_by_inst_name(unsigned short instance, const char *name)
struct ospf *ospf_get(unsigned short instance, const char *name, bool *created)
{
struct ospf *ospf;
+ struct vrf *vrf;
+ struct interface *ifp;
/* vrf name provided call inst and name based api
* in case of no name pass default ospf instance */
@@ -398,10 +400,39 @@ struct ospf *ospf_get(unsigned short instance, const char *name, bool *created)
ospf = ospf_new(instance, name);
ospf_add(ospf);
- if (ospf->router_id_static.s_addr == INADDR_ANY)
- ospf_router_id_update(ospf);
-
ospf_opaque_type11_lsa_init(ospf);
+
+ if (ospf->vrf_id != VRF_UNKNOWN)
+ ospf->oi_running = 1;
+
+ /* Activate 'ip ospf area x' configured interfaces for given
+ * vrf. Activate area on vrf x aware interfaces.
+ * vrf_enable callback calls router_id_update which
+ * internally will call ospf_if_update to trigger
+ * network_run_state
+ */
+ vrf = vrf_lookup_by_id(ospf->vrf_id);
+
+ FOR_ALL_INTERFACES (vrf, ifp) {
+ struct ospf_if_params *params;
+ struct route_node *rn;
+ uint32_t count = 0;
+
+ params = IF_DEF_PARAMS(ifp);
+ if (OSPF_IF_PARAM_CONFIGURED(params, if_area))
+ count++;
+
+ for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn))
+ if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area))
+ count++;
+
+ if (count > 0) {
+ ospf_interface_area_set(ospf, ifp);
+ ospf->if_ospf_cli_count += count;
+ }
+ }
+
+ ospf_router_id_update(ospf);
}
return ospf;
@@ -417,9 +448,6 @@ struct ospf *ospf_get_instance(unsigned short instance, bool *created)
ospf = ospf_new(instance, NULL /* VRF_DEFAULT*/);
ospf_add(ospf);
- if (ospf->router_id_static.s_addr == INADDR_ANY)
- ospf_router_id_update(ospf);
-
ospf_opaque_type11_lsa_init(ospf);
}
@@ -585,7 +613,6 @@ static void ospf_finish_final(struct ospf *ospf)
struct route_node *rn;
struct ospf_nbr_nbma *nbr_nbma;
struct ospf_lsa *lsa;
- struct interface *ifp;
struct ospf_interface *oi;
struct ospf_area *area;
struct ospf_vl_data *vl_data;
@@ -628,15 +655,6 @@ static void ospf_finish_final(struct ospf *ospf)
if (ospf->vrf_id == VRF_DEFAULT)
ospf_ldp_sync_gbl_exit(ospf, true);
- /* Remove any ospf interface config params */
- FOR_ALL_INTERFACES (vrf, ifp) {
- struct ospf_if_params *params;
-
- params = IF_DEF_PARAMS(ifp);
- if (OSPF_IF_PARAM_CONFIGURED(params, if_area))
- UNSET_IF_PARAM(params, if_area);
- }
-
/* Reset interface. */
for (ALL_LIST_ELEMENTS(ospf->oiflist, node, nnode, oi))
ospf_if_free(oi);
@@ -1144,32 +1162,6 @@ void ospf_interface_area_unset(struct ospf *ospf, struct interface *ifp)
update_redistributed(ospf, 0); /* interfaces possibly removed */
}
-bool ospf_interface_area_is_already_set(struct ospf *ospf,
- struct interface *ifp)
-{
- struct route_node *rn_oi;
-
- if (!ospf)
- return false; /* Ospf not ready yet */
-
- /* Find interfaces that may need to be removed. */
- for (rn_oi = route_top(IF_OIFS(ifp)); rn_oi;
- rn_oi = route_next(rn_oi)) {
- struct ospf_interface *oi = rn_oi->info;
-
- if (oi == NULL)
- continue;
-
- if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
- continue;
- /* at least one route covered by interface
- * that implies already done
- */
- return true;
- }
- return false;
-}
-
/* Check whether interface matches given network
* returns: 1, true. 0, false
*/
diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h
index 5535cb40ab..5be897400b 100644
--- a/ospfd/ospfd.h
+++ b/ospfd/ospfd.h
@@ -608,8 +608,6 @@ extern void ospf_area_del_if(struct ospf_area *, struct ospf_interface *);
extern void ospf_interface_area_set(struct ospf *, struct interface *);
extern void ospf_interface_area_unset(struct ospf *, struct interface *);
-extern bool ospf_interface_area_is_already_set(struct ospf *ospf,
- struct interface *ifp);
extern void ospf_route_map_init(void);