]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/network/networkd-nexthop.c
tree-wide: make sure net/if.h is included before any linux/ header
[thirdparty/systemd.git] / src / network / networkd-nexthop.c
index cf62e0e82dc666450a42faf5bf2d87ec4c1bc980..1b44ef320c9dfaff2d08a0df3d51b67bcce37091 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright © 2019 VMware, Inc.
  */
 
+/* Make sure the net/if.h header is included before any linux/ one */
 #include <net/if.h>
 #include <linux/nexthop.h>
 
@@ -12,6 +13,7 @@
 #include "networkd-network.h"
 #include "networkd-nexthop.h"
 #include "networkd-queue.h"
+#include "networkd-route.h"
 #include "networkd-route-util.h"
 #include "parse-util.h"
 #include "set.h"
@@ -97,6 +99,7 @@ static NextHop* nexthop_free(NextHop *nexthop) {
         config_section_free(nexthop->section);
         hashmap_free_free(nexthop->group);
         set_free(nexthop->nexthops);
+        set_free(nexthop->routes);
 
         return mfree(nexthop);
 }
@@ -488,7 +491,7 @@ static int nexthop_remove_dependents(NextHop *nexthop, Manager *manager) {
         assert(nexthop);
         assert(manager);
 
-        /* If a nexthop is removed, the kernel silently removes nexthops that depend on the
+        /* If a nexthop is removed, the kernel silently removes nexthops and routes that depend on the
          * removed nexthop. Let's remove them for safety (though, they are already removed in the kernel,
          * hence that should fail), and forget them. */
 
@@ -502,6 +505,10 @@ static int nexthop_remove_dependents(NextHop *nexthop, Manager *manager) {
                 RET_GATHER(r, nexthop_remove(nh, manager));
         }
 
+        Route *route;
+        SET_FOREACH(route, nexthop->routes)
+                RET_GATHER(r, route_remove(route, manager));
+
         return r;
 }
 
@@ -546,6 +553,9 @@ int nexthop_remove(NextHop *nexthop, Manager *manager) {
         assert(nexthop->id > 0);
         assert(manager);
 
+        /* If the nexthop is remembered, then use the remembered object. */
+        (void) nexthop_get_by_id(manager, PTR_TO_UINT32(nexthop->id), &nexthop);
+
         /* link may be NULL. */
         (void) link_get_by_index(manager, nexthop->ifindex, &link);
 
@@ -860,7 +870,7 @@ static void link_mark_nexthops(Link *link, bool foreign) {
                         continue;
 
                 /* When 'foreign' is true, mark only foreign nexthops, and vice versa. */
-                if (foreign != (nexthop->source == NETWORK_CONFIG_SOURCE_FOREIGN))
+                if (nexthop->source != (foreign ? NETWORK_CONFIG_SOURCE_FOREIGN : NETWORK_CONFIG_SOURCE_STATIC))
                         continue;
 
                 /* Ignore nexthops not assigned yet or already removed. */