1*4882a593SmuzhiyunFrom 02acc4d875ee81e6fd19ef66d69c9f55b4b4a7e7 Mon Sep 17 00:00:00 2001 2*4882a593SmuzhiyunFrom: Chen Qi <Qi.Chen@windriver.com> 3*4882a593SmuzhiyunDate: Wed, 9 Nov 2022 16:33:18 +0800 4*4882a593SmuzhiyunSubject: [PATCH] 20-resolv.conf: improve the sitation of working with systemd 5*4882a593Smuzhiyun 6*4882a593Smuzhiyunsystemd's resolvconf implementation ignores the protocol part. 7*4882a593SmuzhiyunSee https://github.com/systemd/systemd/issues/25032. 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunWhen using 'dhcp server + dns server + dhcpcd + systemd', we 10*4882a593Smuzhiyunget an integration issue, that is dhcpcd runs 'resolvconf -d eth0.ra', 11*4882a593Smuzhiyunyet systemd's resolvconf treats it as eth0. This will delete the 12*4882a593SmuzhiyunDNS information set by 'resolvconf -a eth0.dhcp'. 13*4882a593Smuzhiyun 14*4882a593SmuzhiyunFortunately, 20-resolv.conf has the ability to build the resolv.conf 15*4882a593Smuzhiyunfile contents itself. We can just pass the generated contents to 16*4882a593Smuzhiyunsystemd's resolvconf. This way, the DNS information is not incorrectly 17*4882a593Smuzhiyundeleted. Also, it does not cause behavior regression for dhcpcd 18*4882a593Smuzhiyunin other cases. 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunUpstream-Status: Inappropriate [OE Specific] 21*4882a593SmuzhiyunThis patch has been rejected by dhcpcd upstream. 22*4882a593SmuzhiyunSee details in https://github.com/NetworkConfiguration/dhcpcd/pull/152 23*4882a593Smuzhiyun 24*4882a593SmuzhiyunSigned-off-by: Chen Qi <Qi.Chen@windriver.com> 25*4882a593Smuzhiyun--- 26*4882a593Smuzhiyun hooks/20-resolv.conf | 17 +++++++++++++---- 27*4882a593Smuzhiyun 1 file changed, 13 insertions(+), 4 deletions(-) 28*4882a593Smuzhiyun 29*4882a593Smuzhiyundiff --git a/hooks/20-resolv.conf b/hooks/20-resolv.conf 30*4882a593Smuzhiyunindex 504a6c53..eb6e5845 100644 31*4882a593Smuzhiyun--- a/hooks/20-resolv.conf 32*4882a593Smuzhiyun+++ b/hooks/20-resolv.conf 33*4882a593Smuzhiyun@@ -11,8 +11,12 @@ nocarrier_roaming_dir="$state_dir/roaming" 34*4882a593Smuzhiyun NL=" 35*4882a593Smuzhiyun " 36*4882a593Smuzhiyun : ${resolvconf:=resolvconf} 37*4882a593Smuzhiyun+resolvconf_from_systemd=false 38*4882a593Smuzhiyun if type "$resolvconf" >/dev/null 2>&1; then 39*4882a593Smuzhiyun have_resolvconf=true 40*4882a593Smuzhiyun+ if [ $(basename $(readlink -f $(which $resolvconf))) = resolvectl ]; then 41*4882a593Smuzhiyun+ resolvconf_from_systemd=true 42*4882a593Smuzhiyun+ fi 43*4882a593Smuzhiyun else 44*4882a593Smuzhiyun have_resolvconf=false 45*4882a593Smuzhiyun fi 46*4882a593Smuzhiyun@@ -69,8 +73,13 @@ build_resolv_conf() 47*4882a593Smuzhiyun else 48*4882a593Smuzhiyun echo "# /etc/resolv.conf.tail can replace this line" >> "$cf" 49*4882a593Smuzhiyun fi 50*4882a593Smuzhiyun- if change_file /etc/resolv.conf "$cf"; then 51*4882a593Smuzhiyun- chmod 644 /etc/resolv.conf 52*4882a593Smuzhiyun+ if $resolvconf_from_systemd; then 53*4882a593Smuzhiyun+ [ -n "$ifmetric" ] && export IF_METRIC="$ifmetric" 54*4882a593Smuzhiyun+ "$resolvconf" -a "$ifname" <"$cf" 55*4882a593Smuzhiyun+ else 56*4882a593Smuzhiyun+ if change_file /etc/resolv.conf "$cf"; then 57*4882a593Smuzhiyun+ chmod 644 /etc/resolv.conf 58*4882a593Smuzhiyun+ fi 59*4882a593Smuzhiyun fi 60*4882a593Smuzhiyun rm -f "$cf" 61*4882a593Smuzhiyun } 62*4882a593Smuzhiyun@@ -170,7 +179,7 @@ add_resolv_conf() 63*4882a593Smuzhiyun for x in ${new_domain_name_servers}; do 64*4882a593Smuzhiyun conf="${conf}nameserver $x$NL" 65*4882a593Smuzhiyun done 66*4882a593Smuzhiyun- if $have_resolvconf; then 67*4882a593Smuzhiyun+ if $have_resolvconf && ! $resolvconf_from_systemd; then 68*4882a593Smuzhiyun [ -n "$ifmetric" ] && export IF_METRIC="$ifmetric" 69*4882a593Smuzhiyun printf %s "$conf" | "$resolvconf" -a "$ifname" 70*4882a593Smuzhiyun return $? 71*4882a593Smuzhiyun@@ -186,7 +195,7 @@ add_resolv_conf() 72*4882a593Smuzhiyun 73*4882a593Smuzhiyun remove_resolv_conf() 74*4882a593Smuzhiyun { 75*4882a593Smuzhiyun- if $have_resolvconf; then 76*4882a593Smuzhiyun+ if $have_resolvconf && ($if_down || ! $resolvconf_from_systemd); then 77*4882a593Smuzhiyun "$resolvconf" -d "$ifname" -f 78*4882a593Smuzhiyun else 79*4882a593Smuzhiyun if [ -e "$resolv_conf_dir/$ifname" ]; then 80*4882a593Smuzhiyun-- 81*4882a593Smuzhiyun2.17.1 82*4882a593Smuzhiyun 83