Move ospf initialization to the actual place where it is created.
We don't need to do that every time "router ospf" is entered.
Also remove a couple of useless checks that can never be true.
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
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)
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;
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 */
ospf_add(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;
+
+ params = IF_DEF_PARAMS(ifp);
+ if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
+ ospf_interface_area_set(ospf, ifp);
+ ospf->if_ospf_cli_count++;
+ }
+ }
+
+ ospf_router_id_update(ospf);
}
return ospf;
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
*/
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);