NetworkManager/0001-dhcp-interface-parsing.patch
2017-07-18 11:03:01 +02:00

159 lines
5.7 KiB
Diff

From 810d243f3ebfe46e78024b239da19ac0cf150801 Mon Sep 17 00:00:00 2001
From: Jonathan Kang <jonathan121537@gmail.com>
Date: Thu, 6 Jul 2017 16:20:25 +0800
Subject: [PATCH 1/2] dhcp/dhclient: improve "interface" statement parsing
In commit d405cfd9089f9552969e6a3e1a1c4550fc3c1695, parsing "interface"
statement is introduced. But it leads to uncommplete parsing of the
"request" entry, if one of the lines in "request" entry is prefixed with
word "interface". For example, the default configuration of openSUSE
distribution:
request subnet-mask, broadcast-address, routers,
rfc3442-classless-static-routes,
interface-mtu, host-name, domain-name, domain-search,
domain-name-servers, nis-domain, nis-servers,
nds-context, nds-servers, nds-tree-name,
netbios-name-servers, netbios-dd-server,
netbios-node-type, netbios-scope, ntp-servers;
Fixes: d405cfd9089f9552969e6a3e1a1c4550fc3c1695
https://bugzilla.opensuse.org/show_bug.cgi?id=1047004
https://mail.gnome.org/archives/networkmanager-list/2017-July/msg00015.html
(cherry picked from commit 3646ed083dda590de1e991915048905b8c784cdd)
(cherry picked from commit 7200906a6202285a97969fea8dea86d5dce9cddf)
---
src/dhcp/nm-dhcp-dhclient-utils.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/dhcp/nm-dhcp-dhclient-utils.c b/src/dhcp/nm-dhcp-dhclient-utils.c
index 216319b..28c290c 100644
--- a/src/dhcp/nm-dhcp-dhclient-utils.c
+++ b/src/dhcp/nm-dhcp-dhclient-utils.c
@@ -296,7 +296,8 @@ nm_dhcp_dhclient_create_config (const char *interface,
continue;
if ( !intf[0]
- && g_str_has_prefix (p, "interface")) {
+ && g_str_has_prefix (p, "interface")
+ && !in_req) {
if (read_interface (p, intf, sizeof (intf)))
continue;
}
--
2.9.3
From 3f2821e1d95c0acb6aebd7d91ae5457c1739b664 Mon Sep 17 00:00:00 2001
From: Thomas Haller <thaller@redhat.com>
Date: Mon, 10 Jul 2017 11:40:43 +0200
Subject: [PATCH 2/2] dhcp/tests: add test parsing dhclient config
(cherry picked from commit 0c23191b01fb0582d8f3d470f463afdabc2fdf46)
(cherry picked from commit beeb8df9ac93ad432c9533362d862c0c2466cd5e)
---
src/dhcp/tests/test-dhcp-dhclient.c | 70 ++++++++++++++++++++++++++++++++-----
1 file changed, 62 insertions(+), 8 deletions(-)
diff --git a/src/dhcp/tests/test-dhcp-dhclient.c b/src/dhcp/tests/test-dhcp-dhclient.c
index 40a3e07..3c9760a 100644
--- a/src/dhcp/tests/test-dhcp-dhclient.c
+++ b/src/dhcp/tests/test-dhcp-dhclient.c
@@ -66,17 +66,16 @@ test_config (const char *orig,
&new_client_id);
g_assert (new != NULL);
-#if DEBUG
- if ( strlen (new) != strlen (expected)
- || strcmp (new, expected)) {
- g_message ("\n- NEW ---------------------------------\n"
+ if (!nm_streq (new, expected)) {
+ g_message ("\n* OLD ---------------------------------\n"
"%s"
- "+ EXPECTED ++++++++++++++++++++++++++++++\n"
+ "\n- NEW -----------------------------------\n"
"%s"
- "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
- new, expected);
+ "\n+ EXPECTED ++++++++++++++++++++++++++++++\n"
+ "%s"
+ "\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
+ orig, new, expected);
}
-#endif
g_assert_cmpstr (new, ==, expected);
if (expected_new_client_id) {
@@ -831,6 +830,60 @@ test_interface2 (void)
NULL);
}
+static void
+test_config_req_intf (void)
+{
+ static const char *const orig = \
+ "request subnet-mask, broadcast-address, routers,\n"
+ " rfc3442-classless-static-routes,\n"
+ " interface-mtu, host-name, domain-name, domain-search,\n"
+ " domain-name-servers, nis-domain, nis-servers,\n"
+ " nds-context, nds-servers, nds-tree-name,\n"
+ " netbios-name-servers, netbios-dd-server,\n"
+ " netbios-node-type, netbios-scope, ntp-servers;\n"
+ "";
+ static const char *const expected = \
+ "# Created by NetworkManager\n"
+ "# Merged from /path/to/dhclient.conf\n"
+ "\n"
+ "\n"
+ "option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;\n"
+ "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 subnet-mask;\n"
+ "also request broadcast-address;\n"
+ "also request routers;\n"
+ "also request rfc3442-classless-static-routes;\n"
+ "also request interface-mtu;\n"
+ "also request host-name;\n"
+ "also request domain-name;\n"
+ "also request domain-search;\n"
+ "also request domain-name-servers;\n"
+ "also request nis-domain;\n"
+ "also request nis-servers;\n"
+ "also request nds-context;\n"
+ "also request nds-servers;\n"
+ "also request nds-tree-name;\n"
+ "also request netbios-name-servers;\n"
+ "also request netbios-dd-server;\n"
+ "also request netbios-node-type;\n"
+ "also request netbios-scope;\n"
+ "also request ntp-servers;\n"
+ "also request ms-classless-static-routes;\n"
+ "also request static-routes;\n"
+ "also request wpad;\n"
+ "\n";
+
+ test_config (orig, expected,
+ FALSE, NULL, FALSE,
+ NULL,
+ NULL,
+ "eth0",
+ NULL);
+}
+
/*****************************************************************************/
static void
@@ -982,6 +1035,7 @@ main (int argc, char **argv)
g_test_add_func ("/dhcp/dhclient/duids", test_duids);
g_test_add_func ("/dhcp/dhclient/interface/1", test_interface1);
g_test_add_func ("/dhcp/dhclient/interface/2", test_interface2);
+ g_test_add_func ("/dhcp/dhclient/config/req_intf", test_config_req_intf);
g_test_add_func ("/dhcp/dhclient/read_duid_from_leasefile", test_read_duid_from_leasefile);
g_test_add_func ("/dhcp/dhclient/read_commented_duid_from_leasefile", test_read_commented_duid_from_leasefile);
--
2.9.3