]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospfd: don't initialize ospf every time "router ospf" is used
authorIgor Ryzhov <iryzhov@nfware.com>
Tue, 13 Oct 2020 22:46:27 +0000 (01:46 +0300)
committerIgor Ryzhov <iryzhov@nfware.com>
Wed, 28 Oct 2020 18:35:49 +0000 (21:35 +0300)
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>
ospfd/ospf_vty.c
ospfd/ospfd.c
ospfd/ospfd.h

index da6ba89deff6ecaffb65dbde478e4d7bf7f2876d..53e8260621b8c039edeb55a5323eafb57506c398 100644 (file)
@@ -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;
index 60eb4d0e24c7f756235027c9eb9bb95663dade95..e25e22ec6e49b2e034dd3508cc5cc85c3954787f 100644 (file)
@@ -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
  */
index e5e07875e87ba3647e00975a520aca9e9de51398..dba7ee8c337223bbfce0d4faa9f60cd37b5ca12a 100644 (file)
@@ -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);