chiark / gitweb /
networkd: always prefer dhcp routes over ipv4ll routes
[elogind.git] / src / network / networkd-link.c
index 961c1ab8ad13f3a1845f78b5ae3b7c80a4ceeddc..3e35090d37453ea257681858e23c6c887a8edfa9 100644 (file)
@@ -427,7 +427,7 @@ static int link_set_dhcp_routes(Link *link) {
                 route->in_addr.in = static_routes[i].gw_addr;
                 route->dst_addr.in = static_routes[i].dst_addr;
                 route->dst_prefixlen = static_routes[i].dst_prefixlen;
-                route->metrics = DHCP_STATIC_ROUTE_METRIC;
+                route->metrics = DHCP_ROUTE_METRIC;
 
                 r = route_configure(route, link, &route_handler);
                 if (r < 0) {
@@ -491,7 +491,7 @@ static int link_enter_set_routes(Link *link) {
 
                         route->family = AF_INET;
                         route->scope = RT_SCOPE_LINK;
-                        route->metrics = 99;
+                        route->metrics = IPV4LL_ROUTE_METRIC;
 
                         r = route_configure(route, link, &route_handler);
                         if (r < 0) {
@@ -539,7 +539,7 @@ static int link_enter_set_routes(Link *link) {
                         route_gw->dst_addr.in = gateway;
                         route_gw->dst_prefixlen = 32;
                         route_gw->scope = RT_SCOPE_LINK;
-                        route_gw->metrics = DHCP_STATIC_ROUTE_METRIC;
+                        route_gw->metrics = DHCP_ROUTE_METRIC;
 
                         r = route_configure(route_gw, link, &route_handler);
                         if (r < 0) {
@@ -552,7 +552,7 @@ static int link_enter_set_routes(Link *link) {
 
                         route->family = AF_INET;
                         route->in_addr.in = gateway;
-                        route->metrics = DHCP_STATIC_ROUTE_METRIC;
+                        route->metrics = DHCP_ROUTE_METRIC;
 
                         r = route_configure(route, link, &route_handler);
                         if (r < 0) {
@@ -599,10 +599,35 @@ static int route_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata)
         return 0;
 }
 
+static int link_get_address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
+        _cleanup_link_unref_ Link *link = userdata;
+        int r;
+
+        assert(rtnl);
+        assert(m);
+        assert(link);
+        assert(link->manager);
+
+        for (; m; m = sd_rtnl_message_next(m)) {
+                r = sd_rtnl_message_get_errno(m);
+                if (r < 0) {
+                        log_debug_link(link, "getting address failed: %s", strerror(-r));
+                        continue;
+                }
+
+                r = link_rtnl_process_address(rtnl, m, link->manager);
+                if (r < 0)
+                        log_warning_link(link, "could not process address: %s", strerror(-r));
+        }
+
+        return 1;
+}
+
 static int address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
         _cleanup_link_unref_ Link *link = userdata;
         int r;
 
+        assert(rtnl);
         assert(m);
         assert(link);
         assert(link->ifname);
@@ -623,6 +648,11 @@ static int address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
                                 link->ifname, strerror(-r),
                                 "ERRNO=%d", -r,
                                 NULL);
+        if (r >= 0) {
+                /* calling handler directly so take a ref */
+                link_ref(link);
+                link_get_address_handler(rtnl, m, link);
+        }
 
         if (link->addr_messages == 0) {
                 log_debug_link(link, "addresses set");
@@ -2233,30 +2263,6 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *use
         return 1;
 }
 
-static int link_get_address_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
-        _cleanup_link_unref_ Link *link = userdata;
-        int r;
-
-        assert(rtnl);
-        assert(m);
-        assert(link);
-        assert(link->manager);
-
-        for (; m; m = sd_rtnl_message_next(m)) {
-                r = sd_rtnl_message_get_errno(m);
-                if (r < 0) {
-                        log_debug_link(link, "getting address failed: %s", strerror(-r));
-                        continue;
-                }
-
-                r = link_rtnl_process_address(rtnl, m, link->manager);
-                if (r < 0)
-                        log_warning_link(link, "could not process address: %s", strerror(-r));
-        }
-
-        return 1;
-}
-
 int link_add(Manager *m, sd_rtnl_message *message, Link **ret) {
         Link *link;
         _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;