summaryrefslogtreecommitdiffstats
path: root/core/modules/dhcpc-busybox
diff options
context:
space:
mode:
authorSimon Rettberg2021-07-16 17:27:59 +0200
committerSimon Rettberg2021-07-16 17:27:59 +0200
commitc29500c7b461603790126f7591fcb6dc3b9634e7 (patch)
tree274f978a440628cef0c6bbbdc4656e74c4686263 /core/modules/dhcpc-busybox
parent[vmware-common] fix english (diff)
downloadmltk-c29500c7b461603790126f7591fcb6dc3b9634e7.tar.gz
mltk-c29500c7b461603790126f7591fcb6dc3b9634e7.tar.xz
mltk-c29500c7b461603790126f7591fcb6dc3b9634e7.zip
[dhcpc-busybox] Add option to ignore secondary interfaces, improve
.... resolv.conf awk generator
Diffstat (limited to 'core/modules/dhcpc-busybox')
-rw-r--r--core/modules/dhcpc-busybox/data/etc/systemd/system/udhcpc@.service7
-rwxr-xr-xcore/modules/dhcpc-busybox/data/opt/openslx/scripts/systemd-udhcpc34
-rwxr-xr-xcore/modules/dhcpc-busybox/data/opt/openslx/scripts/systemd-udhcpc++34
-rwxr-xr-xcore/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx85
4 files changed, 84 insertions, 76 deletions
diff --git a/core/modules/dhcpc-busybox/data/etc/systemd/system/udhcpc@.service b/core/modules/dhcpc-busybox/data/etc/systemd/system/udhcpc@.service
index d797dd4b..cfab7923 100644
--- a/core/modules/dhcpc-busybox/data/etc/systemd/system/udhcpc@.service
+++ b/core/modules/dhcpc-busybox/data/etc/systemd/system/udhcpc@.service
@@ -3,8 +3,7 @@ Description=DHCP Client for %i
After=systemd-tmpfiles-setup.service
[Service]
-Type=forking
-PIDFile=/run/udhcpc/udhcpc.%i.pid
-ExecStart=/opt/openslx/scripts/systemd-udhcpc++ %i
-ExecStopPost=/opt/openslx/bin/rm /run/udhcpc/udhcpc.%i.pid
+Type=simple
+ExecStart=/opt/openslx/scripts/systemd-udhcpc %i
+Restart=on-failure
diff --git a/core/modules/dhcpc-busybox/data/opt/openslx/scripts/systemd-udhcpc b/core/modules/dhcpc-busybox/data/opt/openslx/scripts/systemd-udhcpc
new file mode 100755
index 00000000..49d0180d
--- /dev/null
+++ b/core/modules/dhcpc-busybox/data/opt/openslx/scripts/systemd-udhcpc
@@ -0,0 +1,34 @@
+#!/bin/bash
+# For arrays
+
+net_if="$1"
+net_ip="$(ip addr show dev "${net_if}" | grep -m1 '^\s*inet ' | awk -F " " '{print $2}' | awk -F "/" '{print $1}')"
+
+declare -a udhcpc_opts
+if [ -n "$net_ip" ]; then
+ udhcpc_opts+=( "-r" "$net_ip" )
+fi
+
+. /opt/openslx/config
+primary="${SLX_BRIDGE:-br0}"
+
+if [ "${SLX_DHCP_SECONDARY:-yes}" != "yes" ]; then
+ echo "No DHCP on other NICs requested. Doing nothing."
+ exit 0
+fi
+
+if [ "$primary" = "$net_if" ] && [ "$SLX_NET_DHCP_UUID" = "yes" ]; then
+ uid="$( dmidecode -s system-uuid | sed -r 's/^(..)(..)(..)(..)-(..)(..)-(..)(..)-(....)-/00\4\3\2\1\6\5\8\7\9/' )"
+ if [ "${#uid}" = 34 ]; then
+ echo "Using SMBIOS uid for DHCP"
+ udhcpc_opts+=( "-x" "0x3d:$uid" )
+ fi
+fi
+
+exec /opt/openslx/sbin/udhcpc "${udhcpc_opts[@]}" \
+ -O domain -O nissrv -O nisdomain -O wpad -O search -O wins \
+ -s /opt/openslx/scripts/udhcpc-openslx \
+ -i "${net_if}" -f -t 8
+
+slxlog "udhcpc" "Could not run 'udhcpc ${udhcpc_opts[*]}' on ${net_if}."
+exit 1
diff --git a/core/modules/dhcpc-busybox/data/opt/openslx/scripts/systemd-udhcpc++ b/core/modules/dhcpc-busybox/data/opt/openslx/scripts/systemd-udhcpc++
deleted file mode 100755
index 7d7dfc68..00000000
--- a/core/modules/dhcpc-busybox/data/opt/openslx/scripts/systemd-udhcpc++
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/bash
-# For arrays
-
-net_if="$1"
-net_ip="$(ip addr show dev "${net_if}" | grep -m1 '^\s*inet ' | awk -F " " '{print $2}' | awk -F "/" '{print $1}')"
-
-declare -a udhcpc_opts
-if [ -n "$net_ip" ]; then
- udhcpc_opts+=( "-r" "$net_ip" )
-fi
-
-. /opt/openslx/config
-primary="br0"
-[ -n "$SLX_BRIDGE" ] && primary="$SLX_BRIDGE"
-
-if [ "$primary" = "$net_if" ] && [ "$SLX_NET_DHCP_UUID" = "yes" ]; then
- uid=$(dmidecode -s system-uuid | sed -r 's/^(..)(..)(..)(..)-(..)(..)-(..)(..)-(....)-/00\4\3\2\1\6\5\8\7\9/')
- if [ "${#uid}" = 34 ]; then
- echo "Using SMBIOS uid for DHCP"
- udhcpc_opts+=( "-x" "0x3d:$uid" )
- fi
-fi
-
-mkdir -p /run/udhcpc || echo "Could not create '/run/udhcpc'."
-
-/opt/openslx/sbin/udhcpc "${udhcpc_opts[@]}" -O domain -O nissrv -O nisdomain -O wpad -O search -O wins -t 8 -s /opt/openslx/scripts/udhcpc-openslx -i "${net_if}" -p "/run/udhcpc/udhcpc.${net_if}.pid"
-ret=$?
-
-if [ "${ret}" != 0 ]; then
- slxlog "udhcpc" "Could not run 'udhcpc ${udhcpc_opts[*]}' on ${net_if}."
-fi
-
-exit "${ret}"
-
diff --git a/core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx b/core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx
index c034efb5..3a35dccb 100755
--- a/core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx
+++ b/core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx
@@ -20,33 +20,55 @@
. /opt/openslx/config
-primary="br0"
-[ -n "$SLX_BRIDGE" ] && primary="$SLX_BRIDGE"
+declare -rg primary="${SLX_BRIDGE:-br0}"
-RESOLV_CONF="/opt/openslx/resolv.conf"
-THIS_RESOLV="/run/network/${interface}.resolv"
+declare -rg RESOLV_CONF="/opt/openslx/resolv.conf"
+declare -rg THIS_RESOLV="/run/network/${interface}.resolv"
rebuild_resolv_conf () {
# Don't do anything if the active resolv.conf is not ours
# Also this will not run resolvconf update.d... No idea if we should still do so...
[ -L "/etc/resolv.conf" ] || return 0
- [ "x$(readlink "/etc/resolv.conf")" == "x${RESOLV_CONF}" ] || return 0
- # Maybe make this smarter some time, if anyone is using clients that are on multiple networks at once etc...
- # This is a little braindead but should work most of the time
- # See man resolv.conf -> only the last "search" line is valid, thus we merge them
- sort -u /run/network/*.resolv \
+ [ "$(readlink -f "/etc/resolv.conf")" = "${RESOLV_CONF}" ] || return 0
+ # Use extglob trickery to make sure br0/$primary stuff comes first
+ shopt -s extglob
+ # Then print them in a first-come-first-served manner.
+ # Print nameserver entries one per line, print only first domain value,
+ # group everything else together into one line.
+ # Skip domain entirely if any search lines are found.
+ cat "/tmp/$primary.resolv" /tmp/!("$primary").resolv \
| awk '{
- if ( $1 == "search" )
- search[++idx] = $2
- else
+ if ( $1 ~ /^[a-z]+$/ ) {
+ for (i = 2; i <= NF; ++i) {
+ if (done[$1][$i])
+ continue
+ done[$1][$i] = 1
+ output[$1][++idx] = $i
+ }
+ } else {
print $0
}
- END {
- printf "%s", "search"
- for (s in search)
- printf " %s", search[s]
- }' \
+ }
+ END {
+ for (s in output) {
+ if (s == "nameserver") {
+ for (t in output[s]) {
+ print s " " output[s][t]
+ }
+ } else if (s == "domain" && isarray(output["search"])) {
+ } else {
+ printf "%s", s
+ for (t in output[s]) {
+ printf " %s", output[s][t]
+ if (s == "domain")
+ break
+ }
+ print ""
+ }
+ }
+ }' \
> "$RESOLV_CONF" 2> /dev/null
+ shopt -u extglob
# add support for resolv.conf update scripts // see man(8) resolvconf
for s in /etc/resolvconf/update.d/*.sh; do
@@ -55,11 +77,11 @@ rebuild_resolv_conf () {
}
escape_search() {
- echo "$@" | sed -e 's/[]\/()$*.^|[]/\\&/g'
+ sed -e 's/[]\/()$*.^|[]/\\&/g' <<<"$@"
}
escape_replace() {
- echo "$@" | sed -e 's/[\/&]/\\&/g'
+ sed -e 's/[\/&]/\\&/g' <<<"$@"
}
check_env() {
@@ -143,17 +165,9 @@ case "$1" in
echo "nameserver $i" >> "${conf_file}"
done
- if [ -x "/sbin/resolvconf" ] && [ -L "/etc/resolv.conf" ] && [ -d "/etc/resolvconf/update.d" ]; then
- # Automatic handling :-)
- resolvconf --create-runtime-directories
- resolvconf --enable-updates
- < "$conf_file" resolvconf -a "${interface}.udhcpc"
- rm -- "$conf_file"
- else
- # Manual handling required :-(
- mv -f "$conf_file" "$THIS_RESOLV"
- rebuild_resolv_conf
- fi
+ # Manual handling required :-(
+ mv -f "$conf_file" "$THIS_RESOLV"
+ rebuild_resolv_conf
# Things that should only happen for the main interface that was used for booting
@@ -265,14 +279,9 @@ case "$1" in
sed -i "/^$(escape_search "$ip")(\s|$)/d" /etc/hosts
fi
- if [ -x /sbin/resolvconf ] && [ -L /etc/resolv.conf ] && [ -d /etc/resolvconf/update.d ]; then
- # Automatic handling :-)
- resolvconf -d "${interface}.udhcpc"
- else
- # Manual handling required :-(
- rm -f -- "$THIS_RESOLV"
- rebuild_resolv_conf
- fi
+ # Manual handling required :-(
+ rm -f -- "$THIS_RESOLV"
+ rebuild_resolv_conf
;;
leasefail)