]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: add IPv4LL route right after .network file is parsed
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 5 Mar 2019 01:51:57 +0000 (10:51 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 13 Mar 2019 02:59:18 +0000 (11:59 +0900)
Previously, the route is added when the .network config is assigned
to a Link. So, if multiple links match the .network file, the route
entry becomes duplicated in the corresponding Network object.

src/network/networkd-network.c
src/network/networkd-route.c
src/network/networkd-route.h

index 341b6335d6c098a5875f05b71db5405396ca2b40..81d6d35c7c917c9597f4a22dcf3ccc2398e4d4cd 100644 (file)
@@ -423,6 +423,10 @@ int network_load_one(Manager *manager, const char *filename) {
 
         network_apply_anonymize_if_set(network);
 
+        r = network_add_ipv4ll_route(network);
+        if (r < 0)
+                log_warning_errno(r, "%s: Failed to add IPv4LL route, ignoring: %m", network->filename);
+
         LIST_PREPEND(networks, manager->networks, network);
         network->manager = manager;
 
@@ -637,33 +641,11 @@ int network_get(Manager *manager, sd_device *device,
 }
 
 int network_apply(Network *network, Link *link) {
-        int r;
-
         assert(network);
         assert(link);
 
         link->network = network;
 
-        if (network->ipv4ll_route) {
-                Route *route;
-
-                r = route_new_static(network, NULL, 0, &route);
-                if (r < 0)
-                        return r;
-
-                r = inet_pton(AF_INET, "169.254.0.0", &route->dst.in);
-                if (r == 0)
-                        return -EINVAL;
-                if (r < 0)
-                        return -errno;
-
-                route->family = AF_INET;
-                route->dst_prefixlen = 16;
-                route->scope = RT_SCOPE_LINK;
-                route->priority = IPV4LL_ROUTE_METRIC;
-                route->protocol = RTPROT_STATIC;
-        }
-
         if (network->n_dns > 0 ||
             !strv_isempty(network->ntp) ||
             !ordered_set_isempty(network->search_domains) ||
index 207469878055785b539a32a3fab41d23f6c86eef..2e3ea1279948acb3c68dcc9ca404f8c1355f8213 100644 (file)
@@ -677,6 +677,34 @@ int route_configure(
         return 0;
 }
 
+int network_add_ipv4ll_route(Network *network) {
+        _cleanup_(route_freep) Route *n = NULL;
+        int r;
+
+        assert(network);
+
+        if (!network->ipv4ll_route)
+                return 0;
+
+        /* IPv4LLRoute= is in [Network] section. */
+        r = route_new_static(network, NULL, 0, &n);
+        if (r < 0)
+                return r;
+
+        r = in_addr_from_string(AF_INET, "169.254.0.0", &n->dst);
+        if (r < 0)
+                return r;
+
+        n->family = AF_INET;
+        n->dst_prefixlen = 16;
+        n->scope = RT_SCOPE_LINK;
+        n->priority = IPV4LL_ROUTE_METRIC;
+        n->protocol = RTPROT_STATIC;
+
+        TAKE_PTR(n);
+        return 0;
+}
+
 int config_parse_gateway(
                 const char *unit,
                 const char *filename,
index 7a9fc161bbcee728a2cc855ae4378763cf085c9e..9c6c4b8b0d58029565c537edd5fd2337210cad22 100644 (file)
@@ -59,6 +59,8 @@ int route_expire_handler(sd_event_source *s, uint64_t usec, void *userdata);
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(Route*, route_free);
 
+int network_add_ipv4ll_route(Network *network);
+
 CONFIG_PARSER_PROTOTYPE(config_parse_gateway);
 CONFIG_PARSER_PROTOTYPE(config_parse_preferred_src);
 CONFIG_PARSER_PROTOTYPE(config_parse_destination);