Commit f71e1379 authored by Beniamino Galvani's avatar Beniamino Galvani

dhcp: dhclient: reset the request list if conf file contains 'request'

After commit 2049e97d ("dhcp: refactor parsing of 'request' and
'also request' options") NM parses all the existing 'request' and
'also request' from the original configuration file and appends them
as 'also request' to avoid duplicates and conflicts.

So if the original file contains 'request x' (which means "request
only option x instead of builtin defaults"), we would translate it
into 'also request x', which appends the option to the builtin
defaults, causing duplicates in the DHCP request as dhclient seems not
smart enough to sanitize the list by itself.

To fix this, ensure that the request list is reset if the
configuration file contains a 'request'.

Fixes: 2049e97d

https://bugzilla.gnome.org/show_bug.cgi?id=778430
parent 5a03de70
......@@ -245,6 +245,7 @@ nm_dhcp_dhclient_create_config (const char *interface,
{
GString *new_contents;
GPtrArray *fqdn_opts, *reqs;
gboolean reset_reqlist = FALSE;
int i;
g_return_val_if_fail (!anycast_addr || nm_utils_hwaddr_valid (anycast_addr, ETH_ALEN), NULL);
......@@ -302,6 +303,7 @@ nm_dhcp_dhclient_create_config (const char *interface,
in_req = TRUE;
p += strlen (REQ_TAG);
g_ptr_array_set_size (reqs, 0);
reset_reqlist = TRUE;
}
/* Save all request options for later use */
......@@ -345,6 +347,8 @@ nm_dhcp_dhclient_create_config (const char *interface,
add_request (reqs, "ntp-servers");
}
if (reset_reqlist)
g_string_append (new_contents, "request; # override dhclient defaults\n");
/* And add it to the dhclient configuration */
for (i = 0; i < reqs->len; i++)
g_string_append_printf (new_contents, "also request %s;\n", (char *) reqs->pdata[i]);
......
......@@ -511,6 +511,7 @@ static const char *existing_req_expected = \
"option ms-classless-static-routes code 249 = array of unsigned integer 8;\n"
"option wpad code 252 = string;\n"
"\n"
"request; # override dhclient defaults\n"
"also request another-thing;\n"
"also request yet-another-thing;\n"
"also request rfc3442-classless-static-routes;\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment