From: Susant Sahani <145210+ssahani@users.noreply.github.com> Date: Fri, 19 Jan 2018 23:42:45 +0000 (+0530) Subject: networkd: ignore Static Routes option when Classless Static Routes is given (#7807) X-Git-Tag: v237~76 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8cdc46e7bad6bb8b1fd34b5ad9d95894e0b6b4eb;p=thirdparty%2Fsystemd.git networkd: ignore Static Routes option when Classless Static Routes is given (#7807) 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 --- diff --git a/src/libsystemd-network/dhcp-lease-internal.h b/src/libsystemd-network/dhcp-lease-internal.h index ac5cc47efdc..65c182f48b4 100644 --- a/src/libsystemd-network/dhcp-lease-internal.h +++ b/src/libsystemd-network/dhcp-lease-internal.h @@ -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 { diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c index 78b8e058b45..2e88e39878b 100644 --- a/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libsystemd-network/sd-dhcp-lease.c @@ -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; diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index 0b46deb0093..ecb96cdb57a 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -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;