summaryrefslogtreecommitdiffstats
path: root/core/modules/dhcpc-busybox
diff options
context:
space:
mode:
authorSimon Rettberg2022-02-21 18:25:18 +0100
committerSimon Rettberg2022-02-21 18:25:18 +0100
commit67bfedfe52ed2063ba3f0bff1cb71b1e807f4b89 (patch)
tree62d1ace8873b07b043b8784982d78f6b43ab4344 /core/modules/dhcpc-busybox
parent[debug-report-bwlp] Add brctl show (diff)
downloadmltk-67bfedfe52ed2063ba3f0bff1cb71b1e807f4b89.tar.gz
mltk-67bfedfe52ed2063ba3f0bff1cb71b1e807f4b89.tar.xz
mltk-67bfedfe52ed2063ba3f0bff1cb71b1e807f4b89.zip
[dhcp-busybox] Add service to create additional bridges
Diffstat (limited to 'core/modules/dhcpc-busybox')
-rw-r--r--core/modules/dhcpc-busybox/data/etc/systemd/system/bridge-additional-nics.service10
l---------core/modules/dhcpc-busybox/data/etc/systemd/system/network.target.wants/bridge-additional-nics.service1
-rwxr-xr-xcore/modules/dhcpc-busybox/data/opt/openslx/scripts/systemd-bridge_additional_nics50
3 files changed, 61 insertions, 0 deletions
diff --git a/core/modules/dhcpc-busybox/data/etc/systemd/system/bridge-additional-nics.service b/core/modules/dhcpc-busybox/data/etc/systemd/system/bridge-additional-nics.service
new file mode 100644
index 00000000..df36e015
--- /dev/null
+++ b/core/modules/dhcpc-busybox/data/etc/systemd/system/bridge-additional-nics.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=Setup bridges for addition network interfaces
+Wants=systemd-udevd.service
+After=systemd-udev-settle.service systemd-udevd.service
+Before=network.target
+
+[Service]
+Type=oneshot
+ExecStart=/opt/openslx/scripts/systemd-bridge_additional_nics
+RemainAfterExit=true
diff --git a/core/modules/dhcpc-busybox/data/etc/systemd/system/network.target.wants/bridge-additional-nics.service b/core/modules/dhcpc-busybox/data/etc/systemd/system/network.target.wants/bridge-additional-nics.service
new file mode 120000
index 00000000..948dc5d7
--- /dev/null
+++ b/core/modules/dhcpc-busybox/data/etc/systemd/system/network.target.wants/bridge-additional-nics.service
@@ -0,0 +1 @@
+../bridge-additional-nics.service \ No newline at end of file
diff --git a/core/modules/dhcpc-busybox/data/opt/openslx/scripts/systemd-bridge_additional_nics b/core/modules/dhcpc-busybox/data/opt/openslx/scripts/systemd-bridge_additional_nics
new file mode 100755
index 00000000..295483f9
--- /dev/null
+++ b/core/modules/dhcpc-busybox/data/opt/openslx/scripts/systemd-bridge_additional_nics
@@ -0,0 +1,50 @@
+#!/bin/bash
+#
+# Small script scanning sysfs for physical network interfaces
+# and creating additional network bridges 'br-nic-[0-9]'.
+
+. /opt/openslx/config
+
+# do nothing if not netbooted
+[ -z "$SLX_PXE_NETIF" ] && exit 0
+# or feature disabled
+[ "$SLX_BRIDGE_OTHER_NICS" != "yes" ] && exit 0
+
+declare -g id=1
+for nic in /sys/class/net/*; do
+ # The presence of this symlink pointing to the physical device
+ # seems to be the better way to detect them.
+ [ -h "${nic}/device" ] || continue
+
+ # do not handle the primary interface
+ [ "$SLX_PXE_NETIF" = "${nic##*/}" ] && continue
+
+ # physical nic found, create a bridge with the same MAC
+ bridge="br-nic-${id}"
+ mac="$(cat "${nic}/address")"
+ if ! [[ $mac =~ ^([0-9a-f]{2}:){5}[0-9a-f]{2}$ ]]; then
+ echo "'$mac' does not seem like a valid MAC address."
+ continue
+ fi
+
+ (
+ set -e
+ brctl addbr "$bridge"
+ brctl stp "$bridge" 0
+ ip link set addr "$mac" "$bridge"
+ ip link set dev "${nic##*/}" up
+ brctl addif "$bridge" "${nic##*/}"
+ ip link set dev "$bridge" up
+ )
+ ret=$?
+ if [ "$ret" != 0 ]; then
+ echo "Failed to setup additional bridge '$bridge' for '$nic'."
+ brctl delbr "$bridge"
+ continue
+ fi
+
+ # all fine, increase counter and continue
+ (( id++ ))
+done
+
+exit 0