]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: ignore Static Routes option when Classless Static Routes is given (#7807)
authorSusant Sahani <145210+ssahani@users.noreply.github.com>
Fri, 19 Jan 2018 23:42:45 +0000 (05:12 +0530)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 19 Jan 2018 23:42:45 +0000 (08:42 +0900)
When the DHCP server returns both a Classless Static Routes
option and a Static Routes option, the DHCP client MUST ignore the
Static Routes option.

Closes #7792

src/libsystemd-network/dhcp-lease-internal.h
src/libsystemd-network/sd-dhcp-lease.c
src/network/networkd-dhcp4.c

index ac5cc47efdc715ff335a0a0d790b6c4469406ef6..65c182f48b41ff5472c07bf1dd2f361dab1ff048 100644 (file)
@@ -34,6 +34,8 @@ struct sd_dhcp_route {
         struct in_addr dst_addr;
         struct in_addr gw_addr;
         unsigned char dst_prefixlen;
+
+        uint8_t option;
 };
 
 struct sd_dhcp_raw_option {
index 78b8e058b45b92902f00cab2b14183d26b79c46d..2e88e39878b0ba303250af8b1866d53ad613a993 100644 (file)
@@ -471,6 +471,7 @@ static int lease_parse_routes(
                 struct sd_dhcp_route *route = *routes + *routes_size;
                 int r;
 
+                route->option = SD_DHCP_OPTION_STATIC_ROUTE;
                 r = in4_addr_default_prefixlen((struct in_addr*) option, &route->dst_prefixlen);
                 if (r < 0) {
                         log_debug("Failed to determine destination prefix length from class based IP, ignoring");
@@ -514,6 +515,7 @@ static int lease_parse_classless_routes(
                         return -ENOMEM;
 
                 route = *routes + *routes_size;
+                route->option = SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE;
 
                 dst_octets = (*option == 0 ? 0 : ((*option - 1) / 8) + 1);
                 route->dst_prefixlen = *option;
index 0b46deb00936577339f8a94922d46ea19518cf50..ecb96cdb57afb348402ac6600137e410b0d37ce6 100644 (file)
@@ -71,8 +71,9 @@ static int route_scope_from_address(const Route *route, const struct in_addr *se
 }
 
 static int link_set_dhcp_routes(Link *link) {
-        struct in_addr gateway, address;
         _cleanup_free_ sd_dhcp_route **static_routes = NULL;
+        bool classless_route = false, static_route = false;
+        struct in_addr gateway, address;
         int r, n, i;
         uint32_t table;
 
@@ -101,9 +102,22 @@ static int link_set_dhcp_routes(Link *link) {
         if (n < 0)
                 log_link_debug_errno(link, n, "DHCP error: could not get routes: %m");
 
+        for (i = 0; i < n; i++) {
+                if (static_routes[i]->option == SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE)
+                        classless_route = true;
+
+                if (static_routes[i]->option == SD_DHCP_OPTION_STATIC_ROUTE)
+                        static_route = true;
+        }
+
         for (i = 0; i < n; i++) {
                 _cleanup_route_free_ Route *route = NULL;
 
+                /* if the DHCP server returns both a Classless Static Routes option and a Static Routes option,
+                   the DHCP client MUST ignore the Static Routes option. */
+                if (classless_route && static_routes[i]->option == SD_DHCP_OPTION_STATIC_ROUTE)
+                        continue;
+
                 r = route_new(&route);
                 if (r < 0)
                         return log_link_error_errno(link, r, "Could not allocate route: %m");
@@ -132,7 +146,10 @@ static int link_set_dhcp_routes(Link *link) {
 
         /* According to RFC 3442: If the DHCP server returns both a Classless Static Routes option and
            a Router option, the DHCP client MUST ignore the Router option. */
-        if (r >= 0 && link->dhcp4_messages <= 0) {
+        if (classless_route && static_route)
+                log_link_warning(link, "Classless static routes received from DHCP server: ignoring static-route option and router option");
+
+        if (r >= 0 && !classless_route) {
                 _cleanup_route_free_ Route *route = NULL;
                 _cleanup_route_free_ Route *route_gw = NULL;