From 1dfbcbd8b47623dfc783d86e22fe49000751d61f Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Tue, 8 Oct 2019 14:37:19 +0200 Subject: [PATCH] connman: move host and resolver configuration to separate service Setup system hostname, /etc/resolv.conf and /etc/hosts in a service that can be run independently of connman. The volatile etc files are created in /run/libreelec instead of /run/connman so they can be modified similarily to standard linux installations with a writable /etc. Connman can then hook into that and move resolv.conf management to /run/connman/resolv.conf when it's started. If kernel IP configuration is used the resolv info from the kernel will be used to create resolv.conf. Users can also provide their own resolv.conf file in /storage/.config/resolv.conf which takes precedence over ther kernel info. If no resolv.conf info is present a fallback with use the Google nameservers is created (as before). Loopback network interface setup has been removed, this is already set up by systemd. Signed-off-by: Matthias Reichl --- packages/network/connman/package.mk | 9 ------- .../network/connman/scripts/connman-setup | 8 ++++++ .../network/connman/system.d/connman.service | 6 +---- .../systemd}/config/hosts.conf | 0 packages/sysutils/systemd/package.mk | 6 +++++ .../systemd/scripts/network-base-setup | 26 +++++++++++++++++++ .../systemd/system.d/network-base.service | 12 +++++++++ 7 files changed, 53 insertions(+), 14 deletions(-) rename packages/{network/connman => sysutils/systemd}/config/hosts.conf (100%) create mode 100755 packages/sysutils/systemd/scripts/network-base-setup create mode 100644 packages/sysutils/systemd/system.d/network-base.service diff --git a/packages/network/connman/package.mk b/packages/network/connman/package.mk index 369b99d995..0e38192bbf 100644 --- a/packages/network/connman/package.mk +++ b/packages/network/connman/package.mk @@ -71,12 +71,6 @@ post_makeinstall_target() { mkdir -p $INSTALL/usr/lib/connman cp -P $PKG_DIR/scripts/connman-setup $INSTALL/usr/lib/connman - mkdir -p $INSTALL/etc - ln -sf /run/connman/resolv.conf $INSTALL/etc/resolv.conf - - # /etc/hosts must be writeable - ln -sf /run/connman/hosts $INSTALL/etc/hosts - mkdir -p $INSTALL/etc/connman cp ../src/main.conf $INSTALL/etc/connman sed -i $INSTALL/etc/connman/main.conf \ @@ -90,9 +84,6 @@ post_makeinstall_target() { -e "s|^# PersistentTetheringMode.*|PersistentTetheringMode = true|g" \ -e "s|^# NetworkInterfaceBlacklist = vmnet,vboxnet,virbr,ifb|NetworkInterfaceBlacklist = vmnet,vboxnet,virbr,ifb,docker,veth,zt|g" - mkdir -p $INSTALL/usr/config - cp $PKG_DIR/config/hosts.conf $INSTALL/usr/config - mkdir -p $INSTALL/usr/share/connman/ cp $PKG_DIR/config/settings $INSTALL/usr/share/connman/ } diff --git a/packages/network/connman/scripts/connman-setup b/packages/network/connman/scripts/connman-setup index b6388ed37e..16bc279ad2 100755 --- a/packages/network/connman/scripts/connman-setup +++ b/packages/network/connman/scripts/connman-setup @@ -15,3 +15,11 @@ else export CONNMAN_MAIN="--config=/etc/connman/main.conf" fi + +# switch resolv.conf management to connman and use current contents +# as a fallback +if [ -f /run/libreelec/resolv.conf ]; then + cat /run/libreelec/resolv.conf > /run/connman/resolv.conf +fi +rm -f /run/libreelec/resolv.conf +ln -s /run/connman/resolv.conf /run/libreelec/resolv.conf diff --git a/packages/network/connman/system.d/connman.service b/packages/network/connman/system.d/connman.service index f65dfa8e98..e9711abb77 100644 --- a/packages/network/connman/system.d/connman.service +++ b/packages/network/connman/system.d/connman.service @@ -3,7 +3,7 @@ Description=Connection service DefaultDependencies=false Conflicts=shutdown.target Before=network.target multi-user.target shutdown.target -After=dbus.service +After=dbus.service network-base.service Wants=network.target [Service] @@ -11,10 +11,6 @@ Type=dbus BusName=net.connman Restart=on-failure EnvironmentFile=-/run/libreelec/debug/connman.conf -ExecStartPre=-/bin/sh -c "echo -e 'nameserver 8.8.8.8\nnameserver 8.8.4.4' > /etc/resolv.conf" -ExecStartPre=-/bin/sh -c "cat /storage/.cache/hostname > /proc/sys/kernel/hostname" -ExecStartPre=-/bin/sh -c "cat /storage/.config/hosts.conf > /etc/hosts" -ExecStartPre=/sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0 up ExecStart=/bin/sh -c ". /usr/lib/connman/connman-setup; exec /usr/sbin/connmand -nr $CONNMAN_MAIN $CONNMAN_DEBUG" StandardOutput=null RestartSec=2 diff --git a/packages/network/connman/config/hosts.conf b/packages/sysutils/systemd/config/hosts.conf similarity index 100% rename from packages/network/connman/config/hosts.conf rename to packages/sysutils/systemd/config/hosts.conf diff --git a/packages/sysutils/systemd/package.mk b/packages/sysutils/systemd/package.mk index 77a6061699..6509c13ce0 100644 --- a/packages/sysutils/systemd/package.mk +++ b/packages/sysutils/systemd/package.mk @@ -211,6 +211,11 @@ post_makeinstall_target() { mkdir -p $INSTALL/usr/sbin cp $PKG_DIR/scripts/kernel-overlays-setup $INSTALL/usr/sbin + cp $PKG_DIR/scripts/network-base-setup $INSTALL/usr/sbin + + # /etc/resolv.conf and /etc/hosts must be writable + ln -sf /run/libreelec/resolv.conf $INSTALL/etc/resolv.conf + ln -sf /run/libreelec/hosts $INSTALL/etc/hosts # provide 'halt', 'shutdown', 'reboot' & co. ln -sf /usr/bin/systemctl $INSTALL/usr/sbin/halt @@ -272,4 +277,5 @@ post_install() { enable_service kernel-overlays.service enable_service hwdb.service enable_service cpufreq.service + enable_service network-base.service } diff --git a/packages/sysutils/systemd/scripts/network-base-setup b/packages/sysutils/systemd/scripts/network-base-setup new file mode 100755 index 0000000000..58b0ec557e --- /dev/null +++ b/packages/sysutils/systemd/scripts/network-base-setup @@ -0,0 +1,26 @@ +#!/bin/sh + +# setup hostname +if [ -f /storage/.cache/hostname ]; then + cat /storage/.cache/hostname > /proc/sys/kernel/hostname +fi + +# setup /etc/hosts +rm -f /run/libreelec/hosts +if [ -f /storage/.config/hosts.conf ]; then + cat /storage/.config/hosts.conf > /run/libreelec/hosts +fi + +# setup /etc/resolv.conf +rm -f /run/libreelec/resolv.conf +if [ -f /storage/.config/resolv.conf ]; then + cat /storage/.config/resolv.conf > /run/libreelec/resolv.conf +elif [ -f /dev/.kernel_ipconfig -a -f /proc/net/pnp ]; then + cat /proc/net/pnp > /run/libreelec/resolv.conf +else + cat << EOF > /run/libreelec/resolv.conf +nameserver 8.8.8.8 +nameserver 8.8.4.4 +EOF +fi + diff --git a/packages/sysutils/systemd/system.d/network-base.service b/packages/sysutils/systemd/system.d/network-base.service new file mode 100644 index 0000000000..bc2c15947c --- /dev/null +++ b/packages/sysutils/systemd/system.d/network-base.service @@ -0,0 +1,12 @@ +[Unit] +Description=Base Network Configuration +DefaultDependencies=no +After=local-fs.target systemd-tmpfiles-setup.service userconfig.service + +[Service] +Type=oneshot +ExecStart=/usr/sbin/network-base-setup +RemainAfterExit=yes + +[Install] +WantedBy=network.target