summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChen Qi <Qi.Chen@windriver.com>2022-11-18 21:38:55 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-11-22 12:26:45 +0000
commit1be02b42d939d77fae460667088277660a77188a (patch)
treea26f43f46daf6826f92d3236f80a20061ecce7e7
parentbc462b0fcc218434d135ce554ac828f39e6799de (diff)
downloadpoky-1be02b42d939d77fae460667088277660a77188a.tar.gz
dhcpcd: fix to work with systemd
Currently, dhcpcd does not work well with systemd. When using dhcpcd to configure network, the /etc/resolv.conf contents are not correct. This issue could easily be reproduced by using 'qemu + slirp' to start a systemd based image and using dhcpcd to configure network. The expected 'nameserver 10.0.2.3' is not in /etc/resolv.conf. The root cause of this problem is that dhcpcd assumes the resolvconf should recognize .protocol suffix[1]. But systemd's resolvconf (which is a symlink to resolvectl) has a limited support for traditional resolvconf interface[2], and "may not work with all clients"[3]. This of cource includes the clients that use the .protocol suffix. The current situation is: 1. systemd is not going to support the .protocol suffix in the foreseeable near future[4]. 2. dhcpcd does not want to merge systemd specific patch and insists systemd needs to consider the .protocol suffix[5][6]. It's a normal thing that people have different opinions. As a build system that supports such combination, however, we do need to come up with a solution to fix this typical integration problem, making dhcpcd and systemd work together. This patch solves this integration problem by relying on dhcpcd's ability to manage its own resolv.conf contents. But instead of letting it to write to /etc/resolv.conf directly, we supply the generated contents to resolvconf. In this way, the resolvconf still stands in the central place and dhcpcd remains a supplier to it. And the /etc/resolv.conf can get the correct contents. With this patch, dhcpcd could work with both sysvinit and systemd. [1] https://man.archlinux.org/man/resolvconf.8.en [2] https://man.archlinux.org/man/resolvectl.1#COMPATIBILITY_WITH_RESOLVCONF(8) [3] https://wiki.archlinux.org/title/systemd-resolved [4] https://github.com/systemd/systemd/issues/25032 [5] https://github.com/NetworkConfiguration/dhcpcd/pull/152 [6] https://github.com/NetworkConfiguration/dhcpcd/issues/146 (From OE-Core rev: 935ae419f51d911c73f5dc7b4a2e5e9a7b206985) Signed-off-by: Chen Qi <Qi.Chen@windriver.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-connectivity/dhcpcd/dhcpcd_9.4.1.bb1
-rw-r--r--meta/recipes-connectivity/dhcpcd/files/0001-20-resolv.conf-improve-the-sitation-of-working-with-.patch82
2 files changed, 83 insertions, 0 deletions
diff --git a/meta/recipes-connectivity/dhcpcd/dhcpcd_9.4.1.bb b/meta/recipes-connectivity/dhcpcd/dhcpcd_9.4.1.bb
index ab6ffe986c..1d03de09c8 100644
--- a/meta/recipes-connectivity/dhcpcd/dhcpcd_9.4.1.bb
+++ b/meta/recipes-connectivity/dhcpcd/dhcpcd_9.4.1.bb
@@ -13,6 +13,7 @@ UPSTREAM_CHECK_URI = "https://roy.marples.name/downloads/dhcpcd/"
13 13
14SRC_URI = "https://roy.marples.name/downloads/${BPN}/${BPN}-${PV}.tar.xz \ 14SRC_URI = "https://roy.marples.name/downloads/${BPN}/${BPN}-${PV}.tar.xz \
15 file://0001-remove-INCLUDEDIR-to-prevent-build-issues.patch \ 15 file://0001-remove-INCLUDEDIR-to-prevent-build-issues.patch \
16 file://0001-20-resolv.conf-improve-the-sitation-of-working-with-.patch \
16 file://dhcpcd.service \ 17 file://dhcpcd.service \
17 file://dhcpcd@.service \ 18 file://dhcpcd@.service \
18 " 19 "
diff --git a/meta/recipes-connectivity/dhcpcd/files/0001-20-resolv.conf-improve-the-sitation-of-working-with-.patch b/meta/recipes-connectivity/dhcpcd/files/0001-20-resolv.conf-improve-the-sitation-of-working-with-.patch
new file mode 100644
index 0000000000..6f90c88249
--- /dev/null
+++ b/meta/recipes-connectivity/dhcpcd/files/0001-20-resolv.conf-improve-the-sitation-of-working-with-.patch
@@ -0,0 +1,82 @@
1From 02acc4d875ee81e6fd19ef66d69c9f55b4b4a7e7 Mon Sep 17 00:00:00 2001
2From: Chen Qi <Qi.Chen@windriver.com>
3Date: Wed, 9 Nov 2022 16:33:18 +0800
4Subject: [PATCH] 20-resolv.conf: improve the sitation of working with systemd
5
6systemd's resolvconf implementation ignores the protocol part.
7See https://github.com/systemd/systemd/issues/25032.
8
9When using 'dhcp server + dns server + dhcpcd + systemd', we
10get an integration issue, that is dhcpcd runs 'resolvconf -d eth0.ra',
11yet systemd's resolvconf treats it as eth0. This will delete the
12DNS information set by 'resolvconf -a eth0.dhcp'.
13
14Fortunately, 20-resolv.conf has the ability to build the resolv.conf
15file contents itself. We can just pass the generated contents to
16systemd's resolvconf. This way, the DNS information is not incorrectly
17deleted. Also, it does not cause behavior regression for dhcpcd
18in other cases.
19
20Upstream-Status: Inappropriate [OE Specific]
21This patch has been rejected by dhcpcd upstream.
22See details in https://github.com/NetworkConfiguration/dhcpcd/pull/152
23
24Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
25---
26 hooks/20-resolv.conf | 17 +++++++++++++----
27 1 file changed, 13 insertions(+), 4 deletions(-)
28
29diff --git a/hooks/20-resolv.conf b/hooks/20-resolv.conf
30index 504a6c53..eb6e5845 100644
31--- a/hooks/20-resolv.conf
32+++ b/hooks/20-resolv.conf
33@@ -11,8 +11,12 @@ nocarrier_roaming_dir="$state_dir/roaming"
34 NL="
35 "
36 : ${resolvconf:=resolvconf}
37+resolvconf_from_systemd=false
38 if type "$resolvconf" >/dev/null 2>&1; then
39 have_resolvconf=true
40+ if [ $(basename $(readlink -f $(which $resolvconf))) = resolvectl ]; then
41+ resolvconf_from_systemd=true
42+ fi
43 else
44 have_resolvconf=false
45 fi
46@@ -69,8 +73,13 @@ build_resolv_conf()
47 else
48 echo "# /etc/resolv.conf.tail can replace this line" >> "$cf"
49 fi
50- if change_file /etc/resolv.conf "$cf"; then
51- chmod 644 /etc/resolv.conf
52+ if $resolvconf_from_systemd; then
53+ [ -n "$ifmetric" ] && export IF_METRIC="$ifmetric"
54+ "$resolvconf" -a "$ifname" <"$cf"
55+ else
56+ if change_file /etc/resolv.conf "$cf"; then
57+ chmod 644 /etc/resolv.conf
58+ fi
59 fi
60 rm -f "$cf"
61 }
62@@ -170,7 +179,7 @@ add_resolv_conf()
63 for x in ${new_domain_name_servers}; do
64 conf="${conf}nameserver $x$NL"
65 done
66- if $have_resolvconf; then
67+ if $have_resolvconf && ! $resolvconf_from_systemd; then
68 [ -n "$ifmetric" ] && export IF_METRIC="$ifmetric"
69 printf %s "$conf" | "$resolvconf" -a "$ifname"
70 return $?
71@@ -186,7 +195,7 @@ add_resolv_conf()
72
73 remove_resolv_conf()
74 {
75- if $have_resolvconf; then
76+ if $have_resolvconf && ($if_down || ! $resolvconf_from_systemd); then
77 "$resolvconf" -d "$ifname" -f
78 else
79 if [ -e "$resolv_conf_dir/$ifname" ]; then
80--
812.17.1
82