]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: Add back static routes after DHCPv4 lease expires.
authorSusant Sahani <ssahani@redhat.com>
Mon, 29 Apr 2019 05:02:34 +0000 (10:32 +0530)
committerLennart Poettering <lennart@poettering.net>
Mon, 29 Apr 2019 16:13:31 +0000 (18:13 +0200)
1. When the DHCPv4 lease expires kernel removes the route. So add it back
when we gain lease again.

Closes https://github.com/systemd/systemd/issues/12426

2. When UseRoutes=false do not remove router

src/network/networkd-dhcp4.c
src/network/networkd-link.c
src/network/networkd-link.h

index 9ea49b09de5d578cac8f58cf129084b15aef825f..301d9c67b934338b3ae2128decd271c10ebb5e18 100644 (file)
@@ -214,10 +214,7 @@ static int dhcp_lease_lost(Link *link) {
                                 }
                         }
                 }
-        }
 
-        r = address_new(&address);
-        if (r >= 0) {
                 r = sd_dhcp_lease_get_router(link->dhcp_lease, &router);
                 if (r > 0 && !in4_addr_is_null(&router[0])) {
                         _cleanup_(route_freep) Route *route_gw = NULL;
@@ -241,7 +238,10 @@ static int dhcp_lease_lost(Link *link) {
                                 route_remove(route, link, NULL);
                         }
                 }
+        }
 
+        r = address_new(&address);
+        if (r >= 0) {
                 r = sd_dhcp_lease_get_address(link->dhcp_lease, &addr);
                 if (r >= 0) {
                         r = sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask);
@@ -308,6 +308,9 @@ static int dhcp4_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *
 
         link_set_dhcp_routes(link);
 
+        /* Add back static routes since kernel removes while DHCPv4 address is removed from when lease expires */
+        link_request_set_routes(link);
+
         if (link->dhcp4_messages == 0) {
                 link->dhcp4_configured = true;
                 link_check_ready(link);
index 567df736141529a8b93c97640fef3c7b718c0c67..3e22efb92a6b48df0a4e79bc4ae7c80c26f58902 100644 (file)
@@ -913,7 +913,7 @@ static int route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
         return 1;
 }
 
-static int link_request_set_routes(Link *link) {
+int link_request_set_routes(Link *link) {
         enum {
                 PHASE_NON_GATEWAY, /* First phase: Routes without a gateway */
                 PHASE_GATEWAY,     /* Second phase: Routes with a gateway */
index e5497379d75b7d19114f8e5d2f9a004b382db1eb..7d8808e400fecb7aed36bc0d3e4ca7fb64aa9c6f 100644 (file)
@@ -180,6 +180,7 @@ int link_send_changed(Link *link, const char *property, ...) _sentinel_;
 uint32_t link_get_vrf_table(Link *link);
 uint32_t link_get_dhcp_route_table(Link *link);
 uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
+int link_request_set_routes(Link *link);
 
 #define ADDRESS_FMT_VAL(address)                   \
         be32toh((address).s_addr) >> 24,           \