From f71e1379d6292a94e4b3661fa3aa36cb0150c253 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Sat, 11 Feb 2017 23:22:46 +0100 Subject: [PATCH] dhcp: dhclient: reset the request list if conf file contains 'request' After commit 2049e97d9e43 ("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: 2049e97d9e4325b3e7416b1552df837000276d6e https://bugzilla.gnome.org/show_bug.cgi?id=778430 --- src/dhcp/nm-dhcp-dhclient-utils.c | 4 ++++ src/dhcp/tests/test-dhcp-dhclient.c | 1 + 2 files changed, 5 insertions(+) diff --git a/src/dhcp/nm-dhcp-dhclient-utils.c b/src/dhcp/nm-dhcp-dhclient-utils.c index 8cc25ab5a..f36451b2c 100644 --- a/src/dhcp/nm-dhcp-dhclient-utils.c +++ b/src/dhcp/nm-dhcp-dhclient-utils.c @@ -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]); diff --git a/src/dhcp/tests/test-dhcp-dhclient.c b/src/dhcp/tests/test-dhcp-dhclient.c index 82f0c080b..f4cf9c9ff 100644 --- a/src/dhcp/tests/test-dhcp-dhclient.c +++ b/src/dhcp/tests/test-dhcp-dhclient.c @@ -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"