Skip to content

Commit

Permalink
networkd: if the DHCP server returns both a Classless Static Routes
Browse files Browse the repository at this point in the history
   option and a Static Routes option, the DHCP client MUST ignore the
   Static Routes option.

Closes systemd#7792
  • Loading branch information
Susant Sahani committed Jan 4, 2018
1 parent 8481e3e commit 765b7bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/libsystemd-network/dhcp-lease-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/libsystemd-network/sd-dhcp-lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 13 additions & 2 deletions src/network/networkd-dhcp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
struct in_addr gateway, address;
bool classless_route = false;
int r, n, i;
uint32_t table;

Expand Down Expand Up @@ -101,9 +102,19 @@ 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;
}

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");
Expand Down Expand Up @@ -132,7 +143,7 @@ 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 (r >= 0 && !classless_route) {
_cleanup_route_free_ Route *route = NULL;
_cleanup_route_free_ Route *route_gw = NULL;

Expand Down

0 comments on commit 765b7bc

Please sign in to comment.