]> git.puffer.fish Git - matthieu/frr.git/commitdiff
staticd: Allow daemon to have backup static routes
authorDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 22 Jun 2018 01:55:38 +0000 (21:55 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Sun, 29 Jul 2018 16:43:23 +0000 (12:43 -0400)
Modify staticd to allow it to have backup static routes
with higher admin distance.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
staticd/static_nht.c
staticd/static_routes.c
staticd/static_zebra.c
staticd/static_zebra.h

index aea175b19b221e1c6134de30998797a01f945ba6..f9f937f905687ce79c65ad249f3ce60896fbe8d8 100644 (file)
@@ -70,8 +70,12 @@ void static_nht_update(struct prefix *p, uint32_t nh_num,
 
                        if (orig != si->nh_valid)
                                reinstall = true;
+
+                       if (reinstall) {
+                               static_zebra_route_add(rn, si, vrf_id,
+                                                      SAFI_UNICAST, true);
+                               reinstall = false;
+                       }
                }
-               if (reinstall)
-                       static_zebra_route_add(rn, vrf_id, SAFI_UNICAST, true);
        }
 }
index b7699ae3f33aa782dfe6dae834135be8374b5b6a..9f4338f946a9c948a10694e1cba5e93586ffb12d 100644 (file)
@@ -33,7 +33,8 @@
 #include "static_zebra.h"
 
 /* Install static route into rib. */
-static void static_install_route(struct route_node *rn, safi_t safi)
+static void static_install_route(struct route_node *rn,
+                                struct static_route *si_changed, safi_t safi)
 {
        struct static_route *si;
 
@@ -42,19 +43,20 @@ static void static_install_route(struct route_node *rn, safi_t safi)
 
        si = rn->info;
        if (si)
-               static_zebra_route_add(rn, si->vrf_id, safi, true);
+               static_zebra_route_add(rn, si_changed, si->vrf_id, safi, true);
 
 }
 
 /* Uninstall static route from RIB. */
 static void static_uninstall_route(vrf_id_t vrf_id, safi_t safi,
-                                  struct route_node *rn)
+                                  struct route_node *rn,
+                                  struct static_route *si_changed)
 {
 
        if (rn->info)
-               static_zebra_route_add(rn, vrf_id, safi, true);
+               static_zebra_route_add(rn, si_changed, vrf_id, safi, true);
        else
-               static_zebra_route_add(rn, vrf_id, safi, false);
+               static_zebra_route_add(rn, si_changed, vrf_id, safi, false);
 }
 
 int static_add_route(afi_t afi, safi_t safi, uint8_t type, struct prefix *p,
@@ -180,14 +182,14 @@ int static_add_route(afi_t afi, safi_t safi, uint8_t type, struct prefix *p,
 
        /* check whether interface exists in system & install if it does */
        if (!ifname)
-               static_install_route(rn, safi);
+               static_install_route(rn, si, safi);
        else {
                struct interface *ifp;
 
                ifp = if_lookup_by_name(ifname, nh_svrf->vrf->vrf_id);
                if (ifp && ifp->ifindex != IFINDEX_INTERNAL) {
                        si->ifindex = ifp->ifindex;
-                       static_install_route(rn, safi);
+                       static_install_route(rn, si, safi);
                } else
                        zlog_warn("Static Route using %s interface not installed because the interface does not exist in specified vrf",
                                  ifname);
@@ -253,7 +255,7 @@ int static_delete_route(afi_t afi, safi_t safi, uint8_t type, struct prefix *p,
         * If we have other si nodes then route replace
         * else delete the route
         */
-       static_uninstall_route(si->vrf_id, safi, rn);
+       static_uninstall_route(si->vrf_id, safi, rn, si);
        route_unlock_node(rn);
 
        /* Free static route configuration. */
@@ -296,7 +298,7 @@ static void static_ifindex_update_af(struct interface *ifp, bool up, afi_t afi,
                                }
                        }
 
-                       static_install_route(rn, safi);
+                       static_install_route(rn, si, safi);
                }
        }
 }
@@ -340,7 +342,7 @@ static void static_fixup_vrf(struct static_vrf *svrf,
                }
 
                if (install)
-                       static_install_route(rn, safi);
+                       static_install_route(rn, si, safi);
        }
 }
 
@@ -379,7 +381,7 @@ static void static_enable_vrf(struct static_vrf *svrf,
                }
 
                if (install)
-                       static_install_route(rn, safi);
+                       static_install_route(rn, si, safi);
        }
 }
 
@@ -441,7 +443,7 @@ static void static_cleanup_vrf(struct static_vrf *svrf,
                        if (strcmp(svrf->vrf->name, si->nh_vrfname) != 0)
                                continue;
 
-                       static_uninstall_route(si->vrf_id, safi, rn);
+                       static_uninstall_route(si->vrf_id, safi, rn, si);
                }
        }
 }
@@ -462,7 +464,7 @@ static void static_disable_vrf(struct route_table *stable,
 
        for (rn = route_top(stable); rn; rn = route_next(rn))
                for (si = rn->info; si; si = si->next)
-                       static_uninstall_route(si->vrf_id, safi, rn);
+                       static_uninstall_route(si->vrf_id, safi, rn, si);
 }
 
 /*
index 9802aa548af93046469f42d17d29793cf02229a6..27e126e2a6419ef5f1ba800b48bf3592e7e84f58 100644 (file)
@@ -240,8 +240,9 @@ void static_zebra_nht_register(struct static_route *si, bool reg)
        si->nh_registered = reg;
 }
 
-extern void static_zebra_route_add(struct route_node *rn, vrf_id_t vrf_id,
-                                  safi_t safi, bool install)
+extern void static_zebra_route_add(struct route_node *rn,
+                                  struct static_route *si_changed,
+                                  vrf_id_t vrf_id, safi_t safi, bool install)
 {
        struct static_route *si = rn->info;
        const struct prefix *p, *src_pp;
@@ -262,29 +263,26 @@ extern void static_zebra_route_add(struct route_node *rn, vrf_id_t vrf_id,
                SET_FLAG(api.message, ZAPI_MESSAGE_SRCPFX);
                memcpy(&api.src_prefix, src_pp, sizeof(api.src_prefix));
        }
-
+       SET_FLAG(api.flags, ZEBRA_FLAG_RR_USE_DISTANCE);
        SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
+       if (si_changed->distance) {
+               SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE);
+               api.distance = si_changed->distance;
+       }
+       if (si_changed->tag) {
+               SET_FLAG(api.message, ZAPI_MESSAGE_TAG);
+               api.tag = si_changed->tag;
+       }
+       api.tableid = si_changed->table_id;
 
+       zlog_debug("Distance sent down: %d %d", si_changed->distance, install);
        for (/*loaded above*/; si; si = si->next) {
                api_nh = &api.nexthops[nh_num];
                if (si->nh_vrf_id == VRF_UNKNOWN)
                        continue;
 
-               /*
-                * If we create a ecmp static route the
-                * last distance and tag entered wins.  Why because
-                * this cli choosen sucks
-                */
-               if (si->distance) {
-                       SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE);
-                       api.distance = si->distance;
-               }
-               if (si->tag) {
-                       SET_FLAG(api.message, ZAPI_MESSAGE_TAG);
-                       api.tag = si->tag;
-               }
-
-               api.tableid = si->table_id;
+               if (si->distance != si_changed->distance)
+                       continue;
 
                api_nh->vrf_id = si->nh_vrf_id;
                switch (si->type) {
index 6b73b0dd3d0c6daf4410ad36169b79c4c72d328b..a82eb162e10b3db124bdca7454a321d74d42e197 100644 (file)
@@ -23,7 +23,8 @@ extern struct thread_master *master;
 
 extern void static_zebra_nht_register(struct static_route *si, bool reg);
 
-extern void static_zebra_route_add(struct route_node *rn, vrf_id_t vrf_id,
-                                  safi_t safi, bool install);
+extern void static_zebra_route_add(struct route_node *rn,
+                                  struct static_route *si_changed,
+                                  vrf_id_t vrf_id, safi_t safi, bool install);
 extern void static_zebra_init(void);
 #endif