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 <hias@horus.com>
This commit is contained in:
Matthias Reichl 2019-10-08 14:37:19 +02:00
parent 3be49f5d07
commit 4159f97316
7 changed files with 53 additions and 14 deletions

View File

@ -59,12 +59,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 \
@ -78,9 +72,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/
}

View File

@ -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

View File

@ -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

View File

@ -208,6 +208,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
@ -268,4 +273,5 @@ post_install() {
enable_service usercache.service
enable_service kernel-overlays.service
enable_service hwdb.service
enable_service network-base.service
}

View File

@ -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

View File

@ -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