Skip to content

Commit

Permalink
ospfd: don't initialize ospf every time "router ospf" is used
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
idryzhov committed Oct 13, 2020
1 parent cbf1568 commit 0549eed
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 65 deletions.
37 changes: 0 additions & 37 deletions ospfd/ospf_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,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)
Expand All @@ -227,46 +224,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;
Expand Down
51 changes: 25 additions & 26 deletions ospfd/ospfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -399,6 +401,29 @@ struct ospf *ospf_get(unsigned short instance, const char *name, bool *created)
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;
Expand Down Expand Up @@ -1128,32 +1153,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
*/
Expand Down
2 changes: 0 additions & 2 deletions ospfd/ospfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,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);

Expand Down

0 comments on commit 0549eed

Please sign in to comment.