1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 00:51:24 +03:00

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
This commit is contained in:
Susant Sahani 2018-01-20 05:12:45 +05:30 committed by Yu Watanabe
parent c3de717e51
commit 8cdc46e7ba
3 changed files with 23 additions and 2 deletions

View File

@ -34,6 +34,8 @@ struct sd_dhcp_route {
struct in_addr dst_addr; struct in_addr dst_addr;
struct in_addr gw_addr; struct in_addr gw_addr;
unsigned char dst_prefixlen; unsigned char dst_prefixlen;
uint8_t option;
}; };
struct sd_dhcp_raw_option { struct sd_dhcp_raw_option {

View File

@ -471,6 +471,7 @@ static int lease_parse_routes(
struct sd_dhcp_route *route = *routes + *routes_size; struct sd_dhcp_route *route = *routes + *routes_size;
int r; int r;
route->option = SD_DHCP_OPTION_STATIC_ROUTE;
r = in4_addr_default_prefixlen((struct in_addr*) option, &route->dst_prefixlen); r = in4_addr_default_prefixlen((struct in_addr*) option, &route->dst_prefixlen);
if (r < 0) { if (r < 0) {
log_debug("Failed to determine destination prefix length from class based IP, ignoring"); 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; return -ENOMEM;
route = *routes + *routes_size; route = *routes + *routes_size;
route->option = SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE;
dst_octets = (*option == 0 ? 0 : ((*option - 1) / 8) + 1); dst_octets = (*option == 0 ? 0 : ((*option - 1) / 8) + 1);
route->dst_prefixlen = *option; route->dst_prefixlen = *option;

View 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) { static int link_set_dhcp_routes(Link *link) {
struct in_addr gateway, address;
_cleanup_free_ sd_dhcp_route **static_routes = NULL; _cleanup_free_ sd_dhcp_route **static_routes = NULL;
bool classless_route = false, static_route = false;
struct in_addr gateway, address;
int r, n, i; int r, n, i;
uint32_t table; uint32_t table;
@ -101,9 +102,22 @@ static int link_set_dhcp_routes(Link *link) {
if (n < 0) if (n < 0)
log_link_debug_errno(link, n, "DHCP error: could not get routes: %m"); 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++) { for (i = 0; i < n; i++) {
_cleanup_route_free_ Route *route = NULL; _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); r = route_new(&route);
if (r < 0) if (r < 0)
return log_link_error_errno(link, r, "Could not allocate route: %m"); 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 /* 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. */ 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 = NULL;
_cleanup_route_free_ Route *route_gw = NULL; _cleanup_route_free_ Route *route_gw = NULL;