From 4e5df67e9d3400bc0aa498d72eea7a10bd6d3cbb Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Wed, 14 Oct 2020 01:46:27 +0300 Subject: [PATCH] ospfd: don't initialize ospf every time "router ospf" is used 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 --- ospfd/ospf_vty.c | 37 ----------------------------------- ospfd/ospfd.c | 51 ++++++++++++++++++++++++------------------------ ospfd/ospfd.h | 2 -- 3 files changed, 25 insertions(+), 65 deletions(-) diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index da6ba89def..53e8260621 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -212,9 +212,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) @@ -226,46 +223,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; diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 60eb4d0e24..e25e22ec6e 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -380,6 +380,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 */ @@ -394,6 +396,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; @@ -1113,32 +1138,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 e5e07875e8..dba7ee8c33 100644 --- a/ospfd/ospfd.h +++ b/ospfd/ospfd.h @@ -576,8 +576,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); -- 2.39.5