Merge ~ddstreet/ubuntu/+source/systemd:lp1867375-f-ucd into ~ubuntu-core-dev/ubuntu/+source/systemd:ubuntu-focal

Proposed by Dan Streetman on 2020-04-22
Status: Merged
Merge reported by: Dan Streetman
Merged at revision: e49f3f69047ddbd0cd6bb482ffe53e73b37cdc39
Proposed branch: ~ddstreet/ubuntu/+source/systemd:lp1867375-f-ucd
Merge into: ~ubuntu-core-dev/ubuntu/+source/systemd:ubuntu-focal
Diff against target: 703 lines (+659/-0)
7 files modified
debian/patches/lp1867375/0001-network-add-a-flag-to-ignore-gateway-provided-by-DHC.patch (+97/-0)
debian/patches/lp1867375/0002-test-network-add-a-test-case-for-DHCPv4.UseGateway-n.patch (+56/-0)
debian/patches/lp1867375/0003-network-change-UseGateway-default-to-UseRoutes-setti.patch (+77/-0)
debian/patches/lp1867375/0004-test-modify-add-tests-for-UseRoutes-and-UseGateway-c.patch (+187/-0)
debian/patches/lp1867375/0005-network-honor-SetDNSRoutes-even-if-UseGateway-False.patch (+162/-0)
debian/patches/lp1867375/0006-test-verify-RoutesToDNS-is-independent-of-UseGateway.patch (+74/-0)
debian/patches/series (+6/-0)
Reviewer Review Type Date Requested Status
Dimitri John Ledkov 2020-04-22 Pending
Review via email: mp+382806@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/patches/lp1867375/0001-network-add-a-flag-to-ignore-gateway-provided-by-DHC.patch b/debian/patches/lp1867375/0001-network-add-a-flag-to-ignore-gateway-provided-by-DHC.patch
2new file mode 100644
3index 0000000..7b35237
4--- /dev/null
5+++ b/debian/patches/lp1867375/0001-network-add-a-flag-to-ignore-gateway-provided-by-DHC.patch
6@@ -0,0 +1,97 @@
7+From b453122789ec4c6f39e6ceb9900e0e80a6abeb99 Mon Sep 17 00:00:00 2001
8+From: Yu Watanabe <watanabe.yu+github@gmail.com>
9+Date: Mon, 16 Mar 2020 18:55:10 +0900
10+Subject: [PATCH 1/2] network: add a flag to ignore gateway provided by DHCP
11+ server
12+Origin: upstream, https://github.com/systemd/systemd/pull/15136
13+Bug: https://github.com/systemd/systemd/issues/15117
14+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1867375
15+
16+Closes #15117.
17+---
18+ man/systemd.network.xml | 8 +++++++-
19+ src/network/networkd-dhcp4.c | 5 ++++-
20+ src/network/networkd-network-gperf.gperf | 1 +
21+ src/network/networkd-network.c | 1 +
22+ src/network/networkd-network.h | 1 +
23+ test/fuzz/fuzz-network-parser/directives.network | 1 +
24+ 6 files changed, 15 insertions(+), 2 deletions(-)
25+
26+--- a/man/systemd.network.xml
27++++ b/man/systemd.network.xml
28+@@ -1474,7 +1474,13 @@
29+ "link" scope will be used. For anything else, scope defaults to "global".</para>
30+ </listitem>
31+ </varlistentry>
32+-
33++ <varlistentry>
34++ <term><varname>UseGateway=</varname></term>
35++ <listitem>
36++ <para>When true (the default), the gateway will be requested from the DHCP server and added to the
37++ routing table with a metric of 1024, and a scope of "link".</para>
38++ </listitem>
39++ </varlistentry>
40+ <varlistentry>
41+ <term><varname>UseTimezone=</varname></term>
42+
43+--- a/src/network/networkd-dhcp4.c
44++++ b/src/network/networkd-dhcp4.c
45+@@ -323,6 +323,9 @@ static int link_set_dhcp_routes(Link *li
46+ }
47+ }
48+
49++ if (!link->network->dhcp_use_gateway)
50++ return 0;
51++
52+ r = sd_dhcp_lease_get_router(link->dhcp_lease, &router);
53+ if (IN_SET(r, 0, -ENODATA))
54+ log_link_info(link, "DHCP: No gateway received from DHCP server.");
55+@@ -451,7 +454,7 @@ static int dhcp_remove_router(Link *link
56+ assert(link);
57+ assert(address);
58+
59+- if (!link->network->dhcp_use_routes)
60++ if (!link->network->dhcp_use_gateway)
61+ return 0;
62+
63+ r = sd_dhcp_lease_get_router(lease, &router);
64+--- a/src/network/networkd-network-gperf.gperf
65++++ b/src/network/networkd-network-gperf.gperf
66+@@ -162,6 +162,7 @@ DHCPv4.UseMTU,
67+ DHCPv4.UseHostname, config_parse_bool, 0, offsetof(Network, dhcp_use_hostname)
68+ DHCPv4.UseDomains, config_parse_dhcp_use_domains, 0, offsetof(Network, dhcp_use_domains)
69+ DHCPv4.UseRoutes, config_parse_bool, 0, offsetof(Network, dhcp_use_routes)
70++DHCPv4.UseGateway, config_parse_bool, 0, offsetof(Network, dhcp_use_gateway)
71+ DHCPv4.RequestOptions, config_parse_dhcp_request_options, 0, 0
72+ DHCPv4.Anonymize, config_parse_bool, 0, offsetof(Network, dhcp_anonymize)
73+ DHCPv4.SendHostname, config_parse_bool, 0, offsetof(Network, dhcp_send_hostname)
74+--- a/src/network/networkd-network.c
75++++ b/src/network/networkd-network.c
76+@@ -383,6 +383,7 @@ int network_load_one(Manager *manager, O
77+ .dhcp_use_dns = true,
78+ .dhcp_use_hostname = true,
79+ .dhcp_use_routes = true,
80++ .dhcp_use_gateway = true,
81+ /* NOTE: this var might be overwritten by network_apply_anonymize_if_set */
82+ .dhcp_send_hostname = true,
83+ .dhcp_send_release = true,
84+--- a/src/network/networkd-network.h
85++++ b/src/network/networkd-network.h
86+@@ -110,6 +110,7 @@ struct Network {
87+ bool dhcp_use_sip;
88+ bool dhcp_use_mtu;
89+ bool dhcp_use_routes;
90++ bool dhcp_use_gateway;
91+ bool dhcp_use_timezone;
92+ bool rapid_commit;
93+ bool dhcp_use_hostname;
94+--- a/test/fuzz/fuzz-network-parser/directives.network
95++++ b/test/fuzz/fuzz-network-parser/directives.network
96+@@ -73,6 +73,7 @@ UseDNS=
97+ RoutesToDNS=
98+ UseDomains=
99+ UseRoutes=
100++UseGateway=
101+ IAID=
102+ UserClass=
103+ UseNTP=
104diff --git a/debian/patches/lp1867375/0002-test-network-add-a-test-case-for-DHCPv4.UseGateway-n.patch b/debian/patches/lp1867375/0002-test-network-add-a-test-case-for-DHCPv4.UseGateway-n.patch
105new file mode 100644
106index 0000000..629c455
107--- /dev/null
108+++ b/debian/patches/lp1867375/0002-test-network-add-a-test-case-for-DHCPv4.UseGateway-n.patch
109@@ -0,0 +1,56 @@
110+From 0d7bd445d26590aad7b05040c9d8423fcd6e5d4f Mon Sep 17 00:00:00 2001
111+From: Yu Watanabe <watanabe.yu+github@gmail.com>
112+Date: Mon, 16 Mar 2020 19:08:36 +0900
113+Subject: [PATCH 2/2] test-network: add a test case for DHCPv4.UseGateway=no
114+Origin: upstream, https://github.com/systemd/systemd/pull/15136
115+Bug: https://github.com/systemd/systemd/issues/15117
116+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1867375
117+
118+---
119+ .../conf/dhcp-client-ipv4-use-gateway-no.network | 9 +++++++++
120+ test/test-network/systemd-networkd-tests.py | 14 ++++++++++++++
121+ 2 files changed, 23 insertions(+)
122+ create mode 100644 test/test-network/conf/dhcp-client-ipv4-use-gateway-no.network
123+
124+--- /dev/null
125++++ b/test/test-network/conf/dhcp-client-ipv4-use-gateway-no.network
126+@@ -0,0 +1,9 @@
127++[Match]
128++Name=veth99
129++
130++[Network]
131++DHCP=ipv4
132++IPv6AcceptRA=false
133++
134++[DHCPv4]
135++UseGateway=no
136+--- a/test/test-network/systemd-networkd-tests.py
137++++ b/test/test-network/systemd-networkd-tests.py
138+@@ -2826,6 +2826,7 @@ class NetworkdDHCPClientTests(unittest.T
139+ 'dhcp-client-ipv4-dhcp-settings.network',
140+ 'dhcp-client-ipv4-only-ipv6-disabled.network',
141+ 'dhcp-client-ipv4-only.network',
142++ 'dhcp-client-ipv4-use-gateway-no.network',
143+ 'dhcp-client-ipv4-use-routes-no.network',
144+ 'dhcp-client-ipv6-only.network',
145+ 'dhcp-client-ipv6-rapid-commit.network',
146+@@ -2945,6 +2946,19 @@ class NetworkdDHCPClientTests(unittest.T
147+ self.assertRegex(output, r'default via 192.168.5.1 proto dhcp src 192.168.5.181 metric 1024')
148+ self.assertRegex(output, r'192.168.5.1 proto dhcp scope link src 192.168.5.181 metric 1024')
149+
150++ def test_dhcp_client_ipv4_use_gateway_no(self):
151++ copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-use-gateway-no.network')
152++
153++ start_networkd()
154++ self.wait_online(['veth-peer:carrier'])
155++ start_dnsmasq(additional_options='--dhcp-option=option:dns-server,192.168.5.6,192.168.5.7', lease_time='2m')
156++ self.wait_online(['veth99:routable', 'veth-peer:routable'])
157++
158++ output = check_output('ip route show dev veth99')
159++ print(output)
160++ self.assertRegex(output, r'192.168.5.0/24 via 192.168.5.5 proto dhcp src 192.168.5.181 metric 1024')
161++ self.assertNotRegex(output, r'default via 192.168.5.1')
162++
163+ def test_dhcp_client_ipv4_ipv6(self):
164+ copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network',
165+ 'dhcp-client-ipv4-only.network')
166diff --git a/debian/patches/lp1867375/0003-network-change-UseGateway-default-to-UseRoutes-setti.patch b/debian/patches/lp1867375/0003-network-change-UseGateway-default-to-UseRoutes-setti.patch
167new file mode 100644
168index 0000000..9e0c3d9
169--- /dev/null
170+++ b/debian/patches/lp1867375/0003-network-change-UseGateway-default-to-UseRoutes-setti.patch
171@@ -0,0 +1,77 @@
172+From 589397a27759bd650b3674029cb0ef73347c913b Mon Sep 17 00:00:00 2001
173+From: Dan Streetman <ddstreet@canonical.com>
174+Date: Wed, 15 Apr 2020 14:40:21 -0400
175+Subject: [PATCH 1/4] network: change UseGateway= default to UseRoutes= setting
176+Origin: upstream, https://github.com/systemd/systemd/pull/15443
177+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1867375
178+
179+Anyone previously using the UseRoutes=false parameter expected their
180+dhcp4-provided gateway route to be ignored, as well. However, with
181+the introduction of the UseGateway= parameter, this is no longer true.
182+
183+In order to keep backwards compatibility, this sets the UseGateway=
184+default value to whatever UseRoutes= has been set to.
185+---
186+ man/systemd.network.xml | 5 +++--
187+ src/network/networkd-network-gperf.gperf | 2 +-
188+ src/network/networkd-network.c | 5 ++++-
189+ src/network/networkd-network.h | 2 +-
190+ 4 files changed, 9 insertions(+), 5 deletions(-)
191+
192+--- a/man/systemd.network.xml
193++++ b/man/systemd.network.xml
194+@@ -1477,8 +1477,9 @@
195+ <varlistentry>
196+ <term><varname>UseGateway=</varname></term>
197+ <listitem>
198+- <para>When true (the default), the gateway will be requested from the DHCP server and added to the
199+- routing table with a metric of 1024, and a scope of "link".</para>
200++ <para>When true, the gateway will be requested from the DHCP server and added to the routing table with a
201++ metric of 1024, and a scope of "link". When unset, the value specified with <option>UseRoutes=</option>
202++ is used.</para>
203+ </listitem>
204+ </varlistentry>
205+ <varlistentry>
206+--- a/src/network/networkd-network-gperf.gperf
207++++ b/src/network/networkd-network-gperf.gperf
208+@@ -162,7 +162,7 @@ DHCPv4.UseMTU,
209+ DHCPv4.UseHostname, config_parse_bool, 0, offsetof(Network, dhcp_use_hostname)
210+ DHCPv4.UseDomains, config_parse_dhcp_use_domains, 0, offsetof(Network, dhcp_use_domains)
211+ DHCPv4.UseRoutes, config_parse_bool, 0, offsetof(Network, dhcp_use_routes)
212+-DHCPv4.UseGateway, config_parse_bool, 0, offsetof(Network, dhcp_use_gateway)
213++DHCPv4.UseGateway, config_parse_tristate, 0, offsetof(Network, dhcp_use_gateway)
214+ DHCPv4.RequestOptions, config_parse_dhcp_request_options, 0, 0
215+ DHCPv4.Anonymize, config_parse_bool, 0, offsetof(Network, dhcp_anonymize)
216+ DHCPv4.SendHostname, config_parse_bool, 0, offsetof(Network, dhcp_send_hostname)
217+--- a/src/network/networkd-network.c
218++++ b/src/network/networkd-network.c
219+@@ -265,6 +265,9 @@ int network_verify(Network *network) {
220+ network->dhcp_use_mtu = false;
221+ }
222+
223++ if (network->dhcp_use_gateway < 0)
224++ network->dhcp_use_gateway = network->dhcp_use_routes;
225++
226+ if (network->dhcp_critical >= 0) {
227+ if (network->keep_configuration >= 0)
228+ log_warning("%s: Both KeepConfiguration= and deprecated CriticalConnection= are set. "
229+@@ -383,7 +386,7 @@ int network_load_one(Manager *manager, O
230+ .dhcp_use_dns = true,
231+ .dhcp_use_hostname = true,
232+ .dhcp_use_routes = true,
233+- .dhcp_use_gateway = true,
234++ .dhcp_use_gateway = -1,
235+ /* NOTE: this var might be overwritten by network_apply_anonymize_if_set */
236+ .dhcp_send_hostname = true,
237+ .dhcp_send_release = true,
238+--- a/src/network/networkd-network.h
239++++ b/src/network/networkd-network.h
240+@@ -110,7 +110,7 @@ struct Network {
241+ bool dhcp_use_sip;
242+ bool dhcp_use_mtu;
243+ bool dhcp_use_routes;
244+- bool dhcp_use_gateway;
245++ int dhcp_use_gateway;
246+ bool dhcp_use_timezone;
247+ bool rapid_commit;
248+ bool dhcp_use_hostname;
249diff --git a/debian/patches/lp1867375/0004-test-modify-add-tests-for-UseRoutes-and-UseGateway-c.patch b/debian/patches/lp1867375/0004-test-modify-add-tests-for-UseRoutes-and-UseGateway-c.patch
250new file mode 100644
251index 0000000..6bb2c41
252--- /dev/null
253+++ b/debian/patches/lp1867375/0004-test-modify-add-tests-for-UseRoutes-and-UseGateway-c.patch
254@@ -0,0 +1,187 @@
255+From 7c0d36ff5fc31d00e26661fd2ad45291ed0eb6f7 Mon Sep 17 00:00:00 2001
256+From: Dan Streetman <ddstreet@canonical.com>
257+Date: Wed, 15 Apr 2020 16:26:20 -0400
258+Subject: [PATCH 2/4] test: modify/add tests for UseRoutes= and UseGateway=
259+ configuration
260+Origin: upstream, https://github.com/systemd/systemd/pull/15443
261+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1867375
262+
263+The last commit changed the UseGateway= default to the value of UseRoutes=
264+so the tests need to check for all combinations of the two parameters.
265+---
266+ .../dhcp-client-ipv4-use-routes-no.network | 9 ---
267+ ...lient-ipv4-use-routes-use-gateway.network} | 2 +-
268+ .../use-gateway-False.conf | 2 +
269+ .../use-gateway-True.conf | 2 +
270+ .../use-routes-False.conf | 2 +
271+ .../use-routes-True.conf | 2 +
272+ test/test-network/systemd-networkd-tests.py | 58 +++++++++++++------
273+ 7 files changed, 48 insertions(+), 29 deletions(-)
274+ delete mode 100644 test/test-network/conf/dhcp-client-ipv4-use-routes-no.network
275+ rename test/test-network/conf/{dhcp-client-ipv4-use-gateway-no.network => dhcp-client-ipv4-use-routes-use-gateway.network} (81%)
276+ create mode 100644 test/test-network/conf/dhcp-client-ipv4-use-routes-use-gateway.network.d/use-gateway-False.conf
277+ create mode 100644 test/test-network/conf/dhcp-client-ipv4-use-routes-use-gateway.network.d/use-gateway-True.conf
278+ create mode 100644 test/test-network/conf/dhcp-client-ipv4-use-routes-use-gateway.network.d/use-routes-False.conf
279+ create mode 100644 test/test-network/conf/dhcp-client-ipv4-use-routes-use-gateway.network.d/use-routes-True.conf
280+
281+--- a/test/test-network/conf/dhcp-client-ipv4-use-routes-no.network
282++++ /dev/null
283+@@ -1,9 +0,0 @@
284+-[Match]
285+-Name=veth99
286+-
287+-[Network]
288+-DHCP=ipv4
289+-IPv6AcceptRA=false
290+-
291+-[DHCPv4]
292+-UseRoutes=no
293+--- a/test/test-network/conf/dhcp-client-ipv4-use-gateway-no.network
294++++ /dev/null
295+@@ -1,9 +0,0 @@
296+-[Match]
297+-Name=veth99
298+-
299+-[Network]
300+-DHCP=ipv4
301+-IPv6AcceptRA=false
302+-
303+-[DHCPv4]
304+-UseGateway=no
305+--- /dev/null
306++++ b/test/test-network/conf/dhcp-client-ipv4-use-routes-use-gateway.network
307+@@ -0,0 +1,9 @@
308++[Match]
309++Name=veth99
310++
311++[Network]
312++DHCP=ipv4
313++IPv6AcceptRA=false
314++
315++[DHCPv4]
316++RoutesToDNS=yes
317+--- /dev/null
318++++ b/test/test-network/conf/dhcp-client-ipv4-use-routes-use-gateway.network.d/use-gateway-False.conf
319+@@ -0,0 +1,2 @@
320++[DHCPv4]
321++UseGateway=no
322+--- /dev/null
323++++ b/test/test-network/conf/dhcp-client-ipv4-use-routes-use-gateway.network.d/use-gateway-True.conf
324+@@ -0,0 +1,2 @@
325++[DHCPv4]
326++UseGateway=yes
327+--- /dev/null
328++++ b/test/test-network/conf/dhcp-client-ipv4-use-routes-use-gateway.network.d/use-routes-False.conf
329+@@ -0,0 +1,2 @@
330++[DHCPv4]
331++UseRoutes=no
332+--- /dev/null
333++++ b/test/test-network/conf/dhcp-client-ipv4-use-routes-use-gateway.network.d/use-routes-True.conf
334+@@ -0,0 +1,2 @@
335++[DHCPv4]
336++UseRoutes=yes
337+--- a/test/test-network/systemd-networkd-tests.py
338++++ b/test/test-network/systemd-networkd-tests.py
339+@@ -3,6 +3,7 @@
340+ # systemd-networkd tests
341+
342+ import argparse
343++import itertools
344+ import os
345+ import re
346+ import shutil
347+@@ -2826,8 +2827,7 @@ class NetworkdDHCPClientTests(unittest.T
348+ 'dhcp-client-ipv4-dhcp-settings.network',
349+ 'dhcp-client-ipv4-only-ipv6-disabled.network',
350+ 'dhcp-client-ipv4-only.network',
351+- 'dhcp-client-ipv4-use-gateway-no.network',
352+- 'dhcp-client-ipv4-use-routes-no.network',
353++ 'dhcp-client-ipv4-use-routes-use-gateway.network',
354+ 'dhcp-client-ipv6-only.network',
355+ 'dhcp-client-ipv6-rapid-commit.network',
356+ 'dhcp-client-keep-configuration-dhcp-on-stop.network',
357+@@ -2842,7 +2842,6 @@ class NetworkdDHCPClientTests(unittest.T
358+ 'dhcp-client-use-dns-no.network',
359+ 'dhcp-client-use-dns-yes.network',
360+ 'dhcp-client-use-domains.network',
361+- 'dhcp-client-use-routes-no.network',
362+ 'dhcp-client-vrf.network',
363+ 'dhcp-client-with-ipv4ll-fallback-with-dhcp-server.network',
364+ 'dhcp-client-with-ipv4ll-fallback-without-dhcp-server.network',
365+@@ -2851,7 +2850,6 @@ class NetworkdDHCPClientTests(unittest.T
366+ 'dhcp-server-decline.network',
367+ 'dhcp-server-veth-peer.network',
368+ 'dhcp-v4-server-veth-peer.network',
369+- 'dhcp-client-use-domains.network',
370+ 'static.network']
371+
372+ def setUp(self):
373+@@ -2932,8 +2930,21 @@ class NetworkdDHCPClientTests(unittest.T
374+ self.assertRegex(output, r'192.168.5.7 proto dhcp scope link src 192.168.5.181 metric 1024')
375+ self.assertRegex(output, r'192.168.5.8 proto dhcp scope link src 192.168.5.181 metric 1024')
376+
377+- def test_dhcp_client_ipv4_use_routes_no(self):
378+- copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-use-routes-no.network')
379++ def test_dhcp_client_ipv4_use_routes_gateway(self):
380++ for (routes, gateway) in itertools.product([True, False, None], repeat=2):
381++ self.setUp()
382++ with self.subTest(routes=routes, gateway=gateway):
383++ self._test_dhcp_client_ipv4_use_routes_gateway(routes, gateway)
384++ self.tearDown()
385++
386++ def _test_dhcp_client_ipv4_use_routes_gateway(self, routes, gateway):
387++ testunit = 'dhcp-client-ipv4-use-routes-use-gateway.network'
388++ testunits = ['25-veth.netdev', 'dhcp-server-veth-peer.network', testunit]
389++ if routes != None:
390++ testunits.append(f'{testunit}.d/use-routes-{routes}.conf');
391++ if gateway != None:
392++ testunits.append(f'{testunit}.d/use-gateway-{gateway}.conf');
393++ copy_unit_to_networkd_unit_path(*testunits, dropins=False)
394+
395+ start_networkd()
396+ self.wait_online(['veth-peer:carrier'])
397+@@ -2942,22 +2953,31 @@ class NetworkdDHCPClientTests(unittest.T
398+
399+ output = check_output('ip route show dev veth99')
400+ print(output)
401+- self.assertNotRegex(output, r'192.168.5.5')
402+- self.assertRegex(output, r'default via 192.168.5.1 proto dhcp src 192.168.5.181 metric 1024')
403+- self.assertRegex(output, r'192.168.5.1 proto dhcp scope link src 192.168.5.181 metric 1024')
404+
405+- def test_dhcp_client_ipv4_use_gateway_no(self):
406+- copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-use-gateway-no.network')
407++ # UseRoutes= defaults to true
408++ useroutes = routes in [True, None]
409++ # UseGateway= defaults to useroutes
410++ usegateway = useroutes if gateway == None else gateway
411++
412++ # Check UseRoutes=
413++ if useroutes:
414++ self.assertRegex(output, r'192.168.5.0/24 via 192.168.5.5 proto dhcp src 192.168.5.181 metric 1024')
415++ else:
416++ self.assertNotRegex(output, r'192.168.5.5')
417+
418+- start_networkd()
419+- self.wait_online(['veth-peer:carrier'])
420+- start_dnsmasq(additional_options='--dhcp-option=option:dns-server,192.168.5.6,192.168.5.7', lease_time='2m')
421+- self.wait_online(['veth99:routable', 'veth-peer:routable'])
422++ # Check UseGateway=
423++ if usegateway:
424++ self.assertRegex(output, r'default via 192.168.5.1 proto dhcp src 192.168.5.181 metric 1024')
425++ else:
426++ self.assertNotRegex(output, r'default via 192.168.5.1')
427+
428+- output = check_output('ip route show dev veth99')
429+- print(output)
430+- self.assertRegex(output, r'192.168.5.0/24 via 192.168.5.5 proto dhcp src 192.168.5.181 metric 1024')
431+- self.assertNotRegex(output, r'default via 192.168.5.1')
432++ # check for routes to DNS server, only if using gateway
433++ if usegateway:
434++ self.assertRegex(output, r'192.168.5.6 proto dhcp scope link src 192.168.5.181 metric 1024')
435++ self.assertRegex(output, r'192.168.5.7 proto dhcp scope link src 192.168.5.181 metric 1024')
436++ else:
437++ self.assertNotRegex(output, r'192.168.5.6')
438++ self.assertNotRegex(output, r'192.168.5.7')
439+
440+ def test_dhcp_client_ipv4_ipv6(self):
441+ copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv6-only.network',
442diff --git a/debian/patches/lp1867375/0005-network-honor-SetDNSRoutes-even-if-UseGateway-False.patch b/debian/patches/lp1867375/0005-network-honor-SetDNSRoutes-even-if-UseGateway-False.patch
443new file mode 100644
444index 0000000..2acf6ee
445--- /dev/null
446+++ b/debian/patches/lp1867375/0005-network-honor-SetDNSRoutes-even-if-UseGateway-False.patch
447@@ -0,0 +1,162 @@
448+From 244490f5e0a98f83190e92033fbdaa1bbcd9b000 Mon Sep 17 00:00:00 2001
449+From: Dan Streetman <ddstreet@canonical.com>
450+Date: Wed, 15 Apr 2020 18:05:14 -0400
451+Subject: [PATCH 3/4] network: honor SetDNSRoutes= even if UseGateway=False
452+Origin: upstream, https://github.com/systemd/systemd/pull/15443
453+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1867375
454+
455+---
456+ src/network/networkd-dhcp4.c | 129 +++++++++++++++++------------------
457+ 1 file changed, 64 insertions(+), 65 deletions(-)
458+
459+--- a/src/network/networkd-dhcp4.c
460++++ b/src/network/networkd-dhcp4.c
461+@@ -323,78 +323,77 @@ static int link_set_dhcp_routes(Link *li
462+ }
463+ }
464+
465+- if (!link->network->dhcp_use_gateway)
466+- return 0;
467+-
468+- r = sd_dhcp_lease_get_router(link->dhcp_lease, &router);
469+- if (IN_SET(r, 0, -ENODATA))
470+- log_link_info(link, "DHCP: No gateway received from DHCP server.");
471+- else if (r < 0)
472+- log_link_warning_errno(link, r, "DHCP error: could not get gateway: %m");
473+- else if (in4_addr_is_null(&router[0]))
474+- log_link_info(link, "DHCP: Received gateway is null.");
475+-
476+- /* According to RFC 3442: If the DHCP server returns both a Classless Static Routes option and
477+- a Router option, the DHCP client MUST ignore the Router option. */
478+- if (classless_route && static_route)
479+- log_link_warning(link, "Classless static routes received from DHCP server: ignoring static-route option and router option");
480+-
481+- if (r > 0 && !classless_route && !in4_addr_is_null(&router[0])) {
482+- _cleanup_(route_freep) Route *route = NULL, *route_gw = NULL;
483+-
484+- r = route_new(&route_gw);
485+- if (r < 0)
486+- return log_link_error_errno(link, r, "Could not allocate route: %m");
487+-
488+- /* The dhcp netmask may mask out the gateway. Add an explicit
489+- * route for the gw host so that we can route no matter the
490+- * netmask or existing kernel route tables. */
491+- route_gw->family = AF_INET;
492+- route_gw->dst.in = router[0];
493+- route_gw->dst_prefixlen = 32;
494+- route_gw->prefsrc.in = address;
495+- route_gw->scope = RT_SCOPE_LINK;
496+- route_gw->protocol = RTPROT_DHCP;
497+- route_gw->priority = link->network->dhcp_route_metric;
498+- route_gw->table = table;
499+- route_gw->mtu = link->network->dhcp_route_mtu;
500+-
501+- r = dhcp_route_configure(&route_gw, link);
502+- if (r < 0)
503+- return log_link_error_errno(link, r, "Could not set host route: %m");
504+-
505+- r = route_new(&route);
506+- if (r < 0)
507+- return log_link_error_errno(link, r, "Could not allocate route: %m");
508+-
509+- route->family = AF_INET;
510+- route->gw.in = router[0];
511+- route->prefsrc.in = address;
512+- route->protocol = RTPROT_DHCP;
513+- route->priority = link->network->dhcp_route_metric;
514+- route->table = table;
515+- route->mtu = link->network->dhcp_route_mtu;
516+-
517+- r = dhcp_route_configure(&route, link);
518+- if (r < 0)
519+- return log_link_error_errno(link, r, "Could not set router: %m");
520+- }
521++ if (link->network->dhcp_use_gateway) {
522++ r = sd_dhcp_lease_get_router(link->dhcp_lease, &router);
523++ if (IN_SET(r, 0, -ENODATA))
524++ log_link_info(link, "DHCP: No gateway received from DHCP server.");
525++ else if (r < 0)
526++ log_link_warning_errno(link, r, "DHCP error: could not get gateway: %m");
527++ else if (in4_addr_is_null(&router[0]))
528++ log_link_info(link, "DHCP: Received gateway is null.");
529++
530++ /* According to RFC 3442: If the DHCP server returns both a Classless Static Routes option and
531++ a Router option, the DHCP client MUST ignore the Router option. */
532++ if (classless_route && static_route)
533++ log_link_warning(link, "Classless static routes received from DHCP server: ignoring static-route option and router option");
534++
535++ if (r > 0 && !classless_route && !in4_addr_is_null(&router[0])) {
536++ _cleanup_(route_freep) Route *route = NULL, *route_gw = NULL;
537++
538++ r = route_new(&route_gw);
539++ if (r < 0)
540++ return log_link_error_errno(link, r, "Could not allocate route: %m");
541++
542++ /* The dhcp netmask may mask out the gateway. Add an explicit
543++ * route for the gw host so that we can route no matter the
544++ * netmask or existing kernel route tables. */
545++ route_gw->family = AF_INET;
546++ route_gw->dst.in = router[0];
547++ route_gw->dst_prefixlen = 32;
548++ route_gw->prefsrc.in = address;
549++ route_gw->scope = RT_SCOPE_LINK;
550++ route_gw->protocol = RTPROT_DHCP;
551++ route_gw->priority = link->network->dhcp_route_metric;
552++ route_gw->table = table;
553++ route_gw->mtu = link->network->dhcp_route_mtu;
554++
555++ r = dhcp_route_configure(&route_gw, link);
556++ if (r < 0)
557++ return log_link_error_errno(link, r, "Could not set host route: %m");
558++
559++ r = route_new(&route);
560++ if (r < 0)
561++ return log_link_error_errno(link, r, "Could not allocate route: %m");
562++
563++ route->family = AF_INET;
564++ route->gw.in = router[0];
565++ route->prefsrc.in = address;
566++ route->protocol = RTPROT_DHCP;
567++ route->priority = link->network->dhcp_route_metric;
568++ route->table = table;
569++ route->mtu = link->network->dhcp_route_mtu;
570++
571++ r = dhcp_route_configure(&route, link);
572++ if (r < 0)
573++ return log_link_error_errno(link, r, "Could not set router: %m");
574++ }
575+
576+- Route *rt;
577+- LIST_FOREACH(routes, rt, link->network->static_routes) {
578+- if (!rt->gateway_from_dhcp)
579+- continue;
580+-
581+- if (rt->family != AF_INET)
582+- continue;
583+-
584+- rt->gw.in = router[0];
585+-
586+- r = route_configure(rt, link, dhcp4_route_handler);
587+- if (r < 0)
588+- return log_link_error_errno(link, r, "Could not set gateway: %m");
589+- if (r > 0)
590+- link->dhcp4_messages++;
591++ Route *rt;
592++ LIST_FOREACH(routes, rt, link->network->static_routes) {
593++ if (!rt->gateway_from_dhcp)
594++ continue;
595++
596++ if (rt->family != AF_INET)
597++ continue;
598++
599++ rt->gw.in = router[0];
600++
601++ r = route_configure(rt, link, dhcp4_route_handler);
602++ if (r < 0)
603++ return log_link_error_errno(link, r, "Could not set gateway: %m");
604++ if (r > 0)
605++ link->dhcp4_messages++;
606++ }
607+ }
608+
609+ return link_set_dns_routes(link, &address);
610diff --git a/debian/patches/lp1867375/0006-test-verify-RoutesToDNS-is-independent-of-UseGateway.patch b/debian/patches/lp1867375/0006-test-verify-RoutesToDNS-is-independent-of-UseGateway.patch
611new file mode 100644
612index 0000000..ad3d89c
613--- /dev/null
614+++ b/debian/patches/lp1867375/0006-test-verify-RoutesToDNS-is-independent-of-UseGateway.patch
615@@ -0,0 +1,74 @@
616+From 06c2b0c76bf7e2756f8e9ef18765c85dee99ae14 Mon Sep 17 00:00:00 2001
617+From: Dan Streetman <ddstreet@canonical.com>
618+Date: Wed, 15 Apr 2020 18:30:33 -0400
619+Subject: [PATCH 4/4] test: verify RoutesToDNS= is independent of UseGateway=
620+Origin: upstream, https://github.com/systemd/systemd/pull/15443
621+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1867375
622+
623+---
624+ ...dhcp-client-ipv4-use-routes-use-gateway.network | 3 ---
625+ .../use-dns-routes-False.conf | 2 ++
626+ .../use-dns-routes-True.conf | 2 ++
627+ test/test-network/systemd-networkd-tests.py | 14 ++++++++------
628+ 4 files changed, 12 insertions(+), 9 deletions(-)
629+ create mode 100644 test/test-network/conf/dhcp-client-ipv4-use-routes-use-gateway.network.d/use-dns-routes-False.conf
630+ create mode 100644 test/test-network/conf/dhcp-client-ipv4-use-routes-use-gateway.network.d/use-dns-routes-True.conf
631+
632+--- a/test/test-network/conf/dhcp-client-ipv4-use-routes-use-gateway.network
633++++ b/test/test-network/conf/dhcp-client-ipv4-use-routes-use-gateway.network
634+@@ -4,6 +4,3 @@ Name=veth99
635+ [Network]
636+ DHCP=ipv4
637+ IPv6AcceptRA=false
638+-
639+-[DHCPv4]
640+-RoutesToDNS=yes
641+--- /dev/null
642++++ b/test/test-network/conf/dhcp-client-ipv4-use-routes-use-gateway.network.d/use-dns-routes-False.conf
643+@@ -0,0 +1,2 @@
644++[DHCPv4]
645++RoutesToDNS=no
646+--- /dev/null
647++++ b/test/test-network/conf/dhcp-client-ipv4-use-routes-use-gateway.network.d/use-dns-routes-True.conf
648+@@ -0,0 +1,2 @@
649++[DHCPv4]
650++RoutesToDNS=yes
651+--- a/test/test-network/systemd-networkd-tests.py
652++++ b/test/test-network/systemd-networkd-tests.py
653+@@ -2931,19 +2931,21 @@ class NetworkdDHCPClientTests(unittest.T
654+ self.assertRegex(output, r'192.168.5.8 proto dhcp scope link src 192.168.5.181 metric 1024')
655+
656+ def test_dhcp_client_ipv4_use_routes_gateway(self):
657+- for (routes, gateway) in itertools.product([True, False, None], repeat=2):
658++ for (routes, gateway, dnsroutes) in itertools.product([True, False, None], repeat=3):
659+ self.setUp()
660+- with self.subTest(routes=routes, gateway=gateway):
661+- self._test_dhcp_client_ipv4_use_routes_gateway(routes, gateway)
662++ with self.subTest(routes=routes, gateway=gateway, dnsroutes=dnsroutes):
663++ self._test_dhcp_client_ipv4_use_routes_gateway(routes, gateway, dnsroutes)
664+ self.tearDown()
665+
666+- def _test_dhcp_client_ipv4_use_routes_gateway(self, routes, gateway):
667++ def _test_dhcp_client_ipv4_use_routes_gateway(self, routes, gateway, dnsroutes):
668+ testunit = 'dhcp-client-ipv4-use-routes-use-gateway.network'
669+ testunits = ['25-veth.netdev', 'dhcp-server-veth-peer.network', testunit]
670+ if routes != None:
671+ testunits.append(f'{testunit}.d/use-routes-{routes}.conf');
672+ if gateway != None:
673+ testunits.append(f'{testunit}.d/use-gateway-{gateway}.conf');
674++ if dnsroutes != None:
675++ testunits.append(f'{testunit}.d/use-dns-routes-{dnsroutes}.conf');
676+ copy_unit_to_networkd_unit_path(*testunits, dropins=False)
677+
678+ start_networkd()
679+@@ -2971,8 +2973,8 @@ class NetworkdDHCPClientTests(unittest.T
680+ else:
681+ self.assertNotRegex(output, r'default via 192.168.5.1')
682+
683+- # check for routes to DNS server, only if using gateway
684+- if usegateway:
685++ # Check RoutesToDNS=, which defaults to false
686++ if dnsroutes:
687+ self.assertRegex(output, r'192.168.5.6 proto dhcp scope link src 192.168.5.181 metric 1024')
688+ self.assertRegex(output, r'192.168.5.7 proto dhcp scope link src 192.168.5.181 metric 1024')
689+ else:
690diff --git a/debian/patches/series b/debian/patches/series
691index 1d215c3..cdef5d9 100644
692--- a/debian/patches/series
693+++ b/debian/patches/series
694@@ -59,3 +59,9 @@ Revert-network-if-sys-is-rw-then-udev-should-be-around.patch
695 network-Set-link-state-to-LINK_STATE_PENDING-instead-of-t.patch
696 riscv64-seccomp.patch
697 dhcp-Allow-setting-request-options-again.patch
698+lp1867375/0001-network-add-a-flag-to-ignore-gateway-provided-by-DHC.patch
699+lp1867375/0002-test-network-add-a-test-case-for-DHCPv4.UseGateway-n.patch
700+lp1867375/0003-network-change-UseGateway-default-to-UseRoutes-setti.patch
701+lp1867375/0004-test-modify-add-tests-for-UseRoutes-and-UseGateway-c.patch
702+lp1867375/0005-network-honor-SetDNSRoutes-even-if-UseGateway-False.patch
703+lp1867375/0006-test-verify-RoutesToDNS-is-independent-of-UseGateway.patch

Subscribers

People subscribed via source and target branches