]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/network/networkd-link.c
network: dhcp: create explicit host route to gateway
[thirdparty/systemd.git] / src / network / networkd-link.c
index a7ba46692ca369a4baa27b0b031fdf86a68247dc..14cc8715ce844224ae2cd30b3c865504e5a4bdcf 100644 (file)
@@ -228,6 +228,7 @@ static int link_enter_set_routes(Link *link) {
 
         if (link->dhcp_lease) {
                 _cleanup_route_free_ Route *route = NULL;
+                _cleanup_route_free_ Route *route_gw = NULL;
                 struct in_addr gateway;
 
                 r = sd_dhcp_lease_get_router(link->dhcp_lease, &gateway);
@@ -244,6 +245,30 @@ static int link_enter_set_routes(Link *link) {
                         return r;
                 }
 
+                r = route_new_dynamic(&route_gw);
+                if (r < 0) {
+                        log_error_link(link, "Could not allocate route: %s",
+                                       strerror(-r));
+                        return r;
+                }
+
+                /* The dhcp netmask may mask out the gateway. Add an explicit
+                 * route for the gw host so that we can route no matter the
+                 * netmask or existing kernel route tables. */
+                route_gw->family = AF_INET;
+                route_gw->dst_addr.in = gateway;
+                route_gw->dst_prefixlen = 32;
+                route_gw->scope = RT_SCOPE_LINK;
+
+                r = route_configure(route_gw, link, &route_handler);
+                if (r < 0) {
+                        log_warning_link(link,
+                                         "could not set host route: %s", strerror(-r));
+                        return r;
+                }
+
+                link->route_messages ++;
+
                 route->family = AF_INET;
                 route->in_addr.in = gateway;