]> git.proxmox.com Git - mirror_frr.git/commitdiff
staticd: fix nexthop creation and installation
authorIgor Ryzhov <iryzhov@nfware.com>
Wed, 17 Feb 2021 11:19:40 +0000 (14:19 +0300)
committerIgor Ryzhov <iryzhov@nfware.com>
Wed, 17 Feb 2021 11:19:40 +0000 (14:19 +0300)
Currently, staticd creates a VRF for the nexthop it is trying to install.
Later, when this nexthop is deleted, the VRF stays in the system and can
not be deleted by the user because "no vrf" command doesn't work for this
VRF because it was not created through northbound code.

There is no need to create the VRF. Just set nh_vrf_id to VRF_UNKNOWN
when the VRF doesn't exist.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
staticd/static_nb_config.c
staticd/static_routes.c
staticd/static_vrf.c
staticd/static_vrf.h

index cbcfea77cc676d920f56d8ffd5e1cee0caa499e7..3f1d0aa4963401c69cd51f4b510b6e63d1e89d2a 100644 (file)
@@ -148,18 +148,6 @@ static bool static_nexthop_create(struct nb_cb_create_args *args,
                                                      "./gateway"));
                nh = static_add_nexthop(rn, pn, info->safi, info->svrf, nh_type,
                                        &ipaddr, ifname, nh_vrf, 0);
-               if (!nh) {
-                       char buf[SRCDEST2STR_BUFFER];
-
-                       flog_warn(
-                               EC_LIB_NB_CB_CONFIG_APPLY,
-                               "%s : nh [%d:%s:%s:%s] nexthop creation failed",
-                               srcdest_rnode2str(rn, buf, sizeof(buf)),
-                               nh_type, ifname,
-                               yang_dnode_get_string(args->dnode, "./gateway"),
-                               nh_vrf);
-                       return NB_ERR;
-               }
                nb_running_set_entry(args->dnode, nh);
                break;
        }
index 69d424ef57a4c380172fb8b47710a814a491c3ef..3a6afabb3412e5478cd5eae0fd58a0f20a82d7db 100644 (file)
@@ -220,10 +220,7 @@ static_add_nexthop(struct route_node *rn, struct static_path *pn, safi_t safi,
 
        route_lock_node(rn);
 
-       nh_svrf = static_vty_get_unknown_vrf(nh_vrf);
-
-       if (!nh_svrf)
-               return NULL;
+       nh_svrf = static_vrf_lookup_by_name(nh_vrf);
 
        /* Make new static route structure. */
        nh = XCALLOC(MTYPE_STATIC_NEXTHOP, sizeof(struct static_nexthop));
@@ -231,8 +228,8 @@ static_add_nexthop(struct route_node *rn, struct static_path *pn, safi_t safi,
        nh->type = type;
        nh->color = color;
 
-       nh->nh_vrf_id = nh_svrf->vrf->vrf_id;
-       strlcpy(nh->nh_vrfname, nh_svrf->vrf->name, sizeof(nh->nh_vrfname));
+       nh->nh_vrf_id = nh_svrf ? nh_svrf->vrf->vrf_id : VRF_UNKNOWN;
+       strlcpy(nh->nh_vrfname, nh_vrf, sizeof(nh->nh_vrfname));
 
        if (ifname)
                strlcpy(nh->ifname, ifname, sizeof(nh->ifname));
@@ -267,7 +264,7 @@ static_add_nexthop(struct route_node *rn, struct static_path *pn, safi_t safi,
        }
        static_nexthop_list_add_after(&(pn->nexthop_list), cp, nh);
 
-       if (nh_svrf->vrf->vrf_id == VRF_UNKNOWN) {
+       if (nh->nh_vrf_id == VRF_UNKNOWN) {
                zlog_warn(
                        "Static Route to %pFX not installed currently because dependent config not fully available",
                        &rn->p);
@@ -281,7 +278,7 @@ static_add_nexthop(struct route_node *rn, struct static_path *pn, safi_t safi,
                break;
        case STATIC_IPV4_GATEWAY_IFNAME:
        case STATIC_IPV6_GATEWAY_IFNAME:
-               ifp = if_lookup_by_name(ifname, nh_svrf->vrf->vrf_id);
+               ifp = if_lookup_by_name(ifname, nh->nh_vrf_id);
                if (ifp && ifp->ifindex != IFINDEX_INTERNAL)
                        nh->ifindex = ifp->ifindex;
                else
@@ -294,7 +291,7 @@ static_add_nexthop(struct route_node *rn, struct static_path *pn, safi_t safi,
                nh->bh_type = STATIC_BLACKHOLE_NULL;
                break;
        case STATIC_IFNAME:
-               ifp = if_lookup_by_name(ifname, nh_svrf->vrf->vrf_id);
+               ifp = if_lookup_by_name(ifname, nh->nh_vrf_id);
                if (ifp && ifp->ifindex != IFINDEX_INTERNAL) {
                        nh->ifindex = ifp->ifindex;
                } else
@@ -312,28 +309,15 @@ void static_install_nexthop(struct route_node *rn, struct static_path *pn,
                            struct static_vrf *svrf, const char *ifname,
                            static_types type, const char *nh_vrf)
 {
-       struct static_vrf *nh_svrf;
        struct interface *ifp;
 
-       nh_svrf = static_vty_get_unknown_vrf(nh_vrf);
-
-       if (!nh_svrf) {
-               char nexthop_str[NEXTHOP_STR];
-
-               static_get_nh_str(nh, nexthop_str, sizeof(nexthop_str));
-               DEBUGD(&static_dbg_route,
-                      "Static Route %pFX not installed for %s vrf %s not ready",
-                      &rn->p, nexthop_str, nh_vrf);
-               return;
-       }
-
-       if (nh_svrf->vrf->vrf_id == VRF_UNKNOWN) {
+       if (nh->nh_vrf_id == VRF_UNKNOWN) {
                char nexthop_str[NEXTHOP_STR];
 
                static_get_nh_str(nh, nexthop_str, sizeof(nexthop_str));
                DEBUGD(&static_dbg_route,
                       "Static Route %pFX not installed for %s vrf %s is unknown",
-                      &rn->p, nexthop_str, nh_vrf);
+                      &rn->p, nexthop_str, nh->nh_vrfname);
                return;
        }
 
@@ -353,7 +337,7 @@ void static_install_nexthop(struct route_node *rn, struct static_path *pn,
                static_install_path(rn, pn, safi, svrf);
                break;
        case STATIC_IFNAME:
-               ifp = if_lookup_by_name(ifname, nh_svrf->vrf->vrf_id);
+               ifp = if_lookup_by_name(ifname, nh->nh_vrf_id);
                if (ifp && ifp->ifindex != IFINDEX_INTERNAL)
                        static_install_path(rn, pn, safi, svrf);
 
@@ -365,13 +349,9 @@ int static_delete_nexthop(struct route_node *rn, struct static_path *pn,
                          safi_t safi, struct static_vrf *svrf,
                          struct static_nexthop *nh)
 {
-       struct static_vrf *nh_svrf;
-
-       nh_svrf = static_vrf_lookup_by_name(nh->nh_vrfname);
-
        static_nexthop_list_del(&(pn->nexthop_list), nh);
 
-       if (nh_svrf->vrf->vrf_id == VRF_UNKNOWN)
+       if (nh->nh_vrf_id == VRF_UNKNOWN)
                goto EXIT;
 
        static_zebra_nht_register(rn, nh, false);
index 83894e92672f5a7ae1dc6a6c9b0f1a0c5e8e1c96..2133093bb302b3fa3f980085f35f96e312c9c9a4 100644 (file)
@@ -261,25 +261,3 @@ void static_vrf_terminate(void)
 {
        vrf_terminate();
 }
-
-struct static_vrf *static_vty_get_unknown_vrf(const char *vrf_name)
-{
-       struct static_vrf *svrf;
-       struct vrf *vrf;
-
-       svrf = static_vrf_lookup_by_name(vrf_name);
-
-       if (svrf)
-               return svrf;
-
-       vrf = vrf_get(VRF_UNKNOWN, vrf_name);
-       if (!vrf)
-               return NULL;
-       svrf = vrf->info;
-       if (!svrf)
-               return NULL;
-       /* Mark as having FRR configuration */
-       vrf_set_user_cfged(vrf);
-
-       return svrf;
-}
index 12ad1b255af0a40dd610bc4d57a599218ef90744..81296f286463351e7ce6ca65239532d6f310a709 100644 (file)
@@ -45,5 +45,4 @@ struct route_table *static_vrf_static_table(afi_t afi, safi_t safi,
                                            struct static_vrf *svrf);
 extern void static_vrf_terminate(void);
 
-struct static_vrf *static_vty_get_unknown_vrf(const char *vrf_name);
 #endif