From 432b6a8d9e29212965dd8692221927df4759a4b4 Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Tue, 8 Oct 2019 13:49:41 +0200 Subject: [PATCH 1/5] busybox: create marker file if kernel ip configuration is used Signed-off-by: Matthias Reichl --- packages/sysutils/busybox/scripts/init | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/sysutils/busybox/scripts/init b/packages/sysutils/busybox/scripts/init index 07bf67901f..d843c7dda4 100755 --- a/packages/sysutils/busybox/scripts/init +++ b/packages/sysutils/busybox/scripts/init @@ -1065,6 +1065,9 @@ for arg in $(cat /proc/cmdline); do bigfont=*) BIGFONT="${arg#*=}" ;; + ip=*) + KERNEL_IPCONFIG="yes" + ;; esac done @@ -1133,6 +1136,10 @@ if [ "$FLASH_NETBOOT" = "yes" ]; then echo "" > /sysroot/dev/.flash_netboot fi +if [ "$KERNEL_IPCONFIG" = "yes" ]; then + echo "" > /sysroot/dev/.kernel_ipconfig +fi + # swap can not be used over nfs.(see scripts/mount-swap) if [ "$STORAGE_NETBOOT" = "yes" ]; then echo "" > /sysroot/dev/.storage_netboot From 1dfbcbd8b47623dfc783d86e22fe49000751d61f Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Tue, 8 Oct 2019 14:37:19 +0200 Subject: [PATCH 2/5] 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 From 4b262d4612b484682795d19dbdbaded252eed31a Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Tue, 8 Oct 2019 14:39:21 +0200 Subject: [PATCH 3/5] connman: disable service if ip configuration is used Signed-off-by: Matthias Reichl --- packages/network/connman/system.d/connman.service | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/network/connman/system.d/connman.service b/packages/network/connman/system.d/connman.service index e9711abb77..7ae77172e8 100644 --- a/packages/network/connman/system.d/connman.service +++ b/packages/network/connman/system.d/connman.service @@ -5,6 +5,7 @@ Conflicts=shutdown.target Before=network.target multi-user.target shutdown.target After=dbus.service network-base.service Wants=network.target +ConditionPathExists=!/dev/.kernel_ipconfig [Service] Type=dbus From 750dd4add292baa117e86d9ecce94a1eb1ef05af Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Tue, 8 Oct 2019 15:24:32 +0200 Subject: [PATCH 4/5] systemd: enable systemd-timesyncd when using kernel ip configuration connman's NTP client can't be used if it's not managing the network interface so use systemd's timesyncd as we already build it. timesyncd is automatically configured to use the NTP servers provided by kernel ip config, if they are missing the default fallback NTP servers (currently the ones from Google) are used. Users can also provide timesyncd configuration files via /storage/.config/timesyncd.conf.d/ eg to change the (fallback) servers. Signed-off-by: Matthias Reichl --- .../systemd/config/timesyncd.conf.d/README | 86 +++++++++++++++++++ packages/sysutils/systemd/package.mk | 4 + .../systemd/scripts/systemd-timesyncd-setup | 22 +++++ .../system.d/systemd-timesyncd-setup.service | 12 +++ .../depend-on-kernel-ip-config.conf | 3 + 5 files changed, 127 insertions(+) create mode 100644 packages/sysutils/systemd/config/timesyncd.conf.d/README create mode 100755 packages/sysutils/systemd/scripts/systemd-timesyncd-setup create mode 100644 packages/sysutils/systemd/system.d/systemd-timesyncd-setup.service create mode 100644 packages/sysutils/systemd/system.d/systemd-timesyncd.service.d/depend-on-kernel-ip-config.conf diff --git a/packages/sysutils/systemd/config/timesyncd.conf.d/README b/packages/sysutils/systemd/config/timesyncd.conf.d/README new file mode 100644 index 0000000000..17537eb0c4 --- /dev/null +++ b/packages/sysutils/systemd/config/timesyncd.conf.d/README @@ -0,0 +1,86 @@ +TIMESYNCD.CONF(5) timesyncd.conf TIMESYNCD.CONF(5) + +NAME + timesyncd.conf, timesyncd.conf.d - Network Time Synchronization + configuration files + +SYNOPSIS + /etc/systemd/timesyncd.conf + + /etc/systemd/timesyncd.conf.d/*.conf + + /run/systemd/timesyncd.conf.d/*.conf + + /usr/lib/systemd/timesyncd.conf.d/*.conf + +DESCRIPTION + These configuration files control NTP network time synchronization. See + systemd.syntax(5) for a general description of the syntax. + +CONFIGURATION DIRECTORIES AND PRECEDENCE + The default configuration is defined during compilation, so a + configuration file is only needed when it is necessary to deviate from + those defaults. By default, the configuration file in /etc/systemd/ + contains commented out entries showing the defaults as a guide to the + administrator. This file can be edited to create local overrides. + + When packages need to customize the configuration, they can install + configuration snippets in /usr/lib/systemd/*.conf.d/. Files in /etc/ + are reserved for the local administrator, who may use this logic to + override the configuration files installed by vendor packages. The main + configuration file is read before any of the configuration directories, + and has the lowest precedence; entries in a file in any configuration + directory override entries in the single configuration file. Files in + the *.conf.d/ configuration subdirectories are sorted by their filename + in lexicographic order, regardless of which of the subdirectories they + reside in. When multiple files specify the same option, for options + which accept just a single value, the entry in the file with the + lexicographically latest name takes precedence. For options which + accept a list of values, entries are collected as they occur in files + sorted lexicographically. It is recommended to prefix all filenames in + those subdirectories with a two-digit number and a dash, to simplify + the ordering of the files. + + To disable a configuration file supplied by the vendor, the recommended + way is to place a symlink to /dev/null in the configuration directory + in /etc/, with the same filename as the vendor configuration file. + +OPTIONS + The following settings are configured in the "[Time]" section: + + NTP= + A space-separated list of NTP server host names or IP addresses. + During runtime this list is combined with any per-interface NTP + servers acquired from systemd-networkd.service(8). + systemd-timesyncd will contact all configured system or + per-interface servers in turn until one is found that responds. + When the empty string is assigned, the list of NTP servers is + reset, and all assignments prior to this one will have no effect. + This setting defaults to an empty list. + + FallbackNTP= + A space-separated list of NTP server host names or IP addresses to + be used as the fallback NTP servers. Any per-interface NTP servers + obtained from systemd-networkd.service(8) take precedence over this + setting, as do any servers set via NTP= above. This setting is + hence only used if no other NTP server information is known. When + the empty string is assigned, the list of NTP servers is reset, and + all assignments prior to this one will have no effect. If this + option is not given, a compiled-in list of NTP servers is used + instead. + + RootDistanceMaxSec= + Maximum acceptable root distance. Takes a time value (in seconds). + Defaults to 5 seconds. + + PollIntervalMinSec=, PollIntervalMaxSec= + The minimum and maximum poll intervals for NTP messages. Each + setting takes a time value (in seconds). PollIntervalMinSec= must + not be smaller than 16 seconds. PollIntervalMaxSec= must be larger + than PollIntervalMinSec=. PollIntervalMinSec= defaults to 32 + seconds, and PollIntervalMaxSec= defaults to 2048 seconds. + +SEE ALSO + systemd(1), systemd-timesyncd.service(8), systemd-networkd.service(8) + +systemd 241 TIMESYNCD.CONF(5) diff --git a/packages/sysutils/systemd/package.mk b/packages/sysutils/systemd/package.mk index 6509c13ce0..2ce026fa3e 100644 --- a/packages/sysutils/systemd/package.mk +++ b/packages/sysutils/systemd/package.mk @@ -212,6 +212,7 @@ 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 + cp $PKG_DIR/scripts/systemd-timesyncd-setup $INSTALL/usr/sbin # /etc/resolv.conf and /etc/hosts must be writable ln -sf /run/libreelec/resolv.conf $INSTALL/etc/resolv.conf @@ -238,6 +239,7 @@ post_makeinstall_target() { ln -sf /storage/.config/logind.conf.d $INSTALL/etc/systemd/logind.conf.d safe_remove $INSTALL/etc/systemd/sleep.conf.d ln -sf /storage/.config/sleep.conf.d $INSTALL/etc/systemd/sleep.conf.d + ln -sf /storage/.config/timesyncd.conf.d $INSTALL/etc/systemd/timesyncd.conf.d safe_remove $INSTALL/etc/sysctl.d ln -sf /storage/.config/sysctl.d $INSTALL/etc/sysctl.d safe_remove $INSTALL/etc/tmpfiles.d @@ -278,4 +280,6 @@ post_install() { enable_service hwdb.service enable_service cpufreq.service enable_service network-base.service + enable_service systemd-timesyncd.service + enable_service systemd-timesyncd-setup.service } diff --git a/packages/sysutils/systemd/scripts/systemd-timesyncd-setup b/packages/sysutils/systemd/scripts/systemd-timesyncd-setup new file mode 100755 index 0000000000..eb9494ca5e --- /dev/null +++ b/packages/sysutils/systemd/scripts/systemd-timesyncd-setup @@ -0,0 +1,22 @@ +#!/bin/sh +KERNEL_NTP="${1:-/proc/net/ipconfig/ntp_servers}" +NTP_SERVERS="" +if [ -f /proc/net/ipconfig/ntp_servers ]; then + for srv in $(cat /proc/net/ipconfig/ntp_servers); do + if [ -n "$srv" -a "$srv" != "0.0.0.0" ]; then + if [ -z "$NTP_SERVERS" ]; then + NTP_SERVERS="$srv" + else + NTP_SERVERS="${NTP_SERVERS} $srv" + fi + fi + done + if [ -n "$NTP_SERVERS" ]; then + mkdir -p /run/systemd/timesyncd.conf.d/ + cat << EOF > /run/systemd/timesyncd.conf.d/kernel-ntp-servers.conf +[Time] +NTP=$NTP_SERVERS +EOF + fi +fi + diff --git a/packages/sysutils/systemd/system.d/systemd-timesyncd-setup.service b/packages/sysutils/systemd/system.d/systemd-timesyncd-setup.service new file mode 100644 index 0000000000..852492e3e9 --- /dev/null +++ b/packages/sysutils/systemd/system.d/systemd-timesyncd-setup.service @@ -0,0 +1,12 @@ +[Unit] +Description=Setup NTP servers for timesyncd +DefaultDependencies=no +After=systemd-remount-fs.service systemd-sysusers.service + +[Service] +Type=oneshot +ExecStart=/usr/sbin/systemd-timesyncd-setup +RemainAfterExit=yes + +[Install] +WantedBy=sysinit.target diff --git a/packages/sysutils/systemd/system.d/systemd-timesyncd.service.d/depend-on-kernel-ip-config.conf b/packages/sysutils/systemd/system.d/systemd-timesyncd.service.d/depend-on-kernel-ip-config.conf new file mode 100644 index 0000000000..7a50036ce5 --- /dev/null +++ b/packages/sysutils/systemd/system.d/systemd-timesyncd.service.d/depend-on-kernel-ip-config.conf @@ -0,0 +1,3 @@ +[Unit] +ConditionPathExists=/dev/.kernel_ipconfig +After=systemd-timesyncd-setup.service network-base.service From 886bb0164af900891c501edd48e676fab00a5077 Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Tue, 8 Oct 2019 16:51:47 +0200 Subject: [PATCH 5/5] disable network online services when using kernel ip configuration Also drop Requisite on connman.service as it's not really needed (connman and network online services all have conditions on !/dev/.kernel_ipconfig) and it causes a dependency failed message as Requisites are evaluated before conditions. Signed-off-by: Matthias Reichl --- packages/mediacenter/kodi/system.d/kodi-waitonnetwork.service | 2 +- packages/network/connman/system.d/network-online.service | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mediacenter/kodi/system.d/kodi-waitonnetwork.service b/packages/mediacenter/kodi/system.d/kodi-waitonnetwork.service index 555b8108a0..1c5a15e2c3 100644 --- a/packages/mediacenter/kodi/system.d/kodi-waitonnetwork.service +++ b/packages/mediacenter/kodi/system.d/kodi-waitonnetwork.service @@ -1,11 +1,11 @@ [Unit] Description=Wait on network -Requisite=connman.service After=connman.service Before=network-online.target DefaultDependencies=no Conflicts=shutdown.target ConditionPathExists=/storage/.cache/libreelec/network_wait +ConditionPathExists=!/dev/.kernel_ipconfig [Service] Type=oneshot diff --git a/packages/network/connman/system.d/network-online.service b/packages/network/connman/system.d/network-online.service index a6d42403f9..935f638938 100644 --- a/packages/network/connman/system.d/network-online.service +++ b/packages/network/connman/system.d/network-online.service @@ -1,10 +1,10 @@ [Unit] Description=Wait for network to be configured by ConnMan -Requisite=connman.service After=connman.service Before=network-online.target DefaultDependencies=no Conflicts=shutdown.target +ConditionPathExists=!/dev/.kernel_ipconfig [Service] Type=oneshot