From 3036b089451e8a8b503d2bcb61076eb0fd71c717 Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Thu, 9 Feb 2023 09:40:54 +0100 Subject: [PATCH] board/common: Split out iface renaming from swup The factory config part of swup will now only run when in unmanaged mode. --- board/common/rootfs/etc/finit.d/10-infix.conf | 2 + board/common/rootfs/etc/finit.d/swup.conf | 2 - board/common/rootfs/lib/infix/nameif | 46 +++++++++ board/common/rootfs/lib/infix/swup | 94 +++++-------------- 4 files changed, 74 insertions(+), 70 deletions(-) create mode 100644 board/common/rootfs/etc/finit.d/10-infix.conf delete mode 100644 board/common/rootfs/etc/finit.d/swup.conf create mode 100755 board/common/rootfs/lib/infix/nameif diff --git a/board/common/rootfs/etc/finit.d/10-infix.conf b/board/common/rootfs/etc/finit.d/10-infix.conf new file mode 100644 index 00000000..be44296a --- /dev/null +++ b/board/common/rootfs/etc/finit.d/10-infix.conf @@ -0,0 +1,2 @@ +run [S] /lib/infix/nameif -- Probing network interfaces +run [S] /lib/infix/swup -- diff --git a/board/common/rootfs/etc/finit.d/swup.conf b/board/common/rootfs/etc/finit.d/swup.conf deleted file mode 100644 index 9d1d3b1e..00000000 --- a/board/common/rootfs/etc/finit.d/swup.conf +++ /dev/null @@ -1,2 +0,0 @@ -task [S] /lib/infix/swup -- Probing switch - diff --git a/board/common/rootfs/lib/infix/nameif b/board/common/rootfs/lib/infix/nameif new file mode 100755 index 00000000..1667b657 --- /dev/null +++ b/board/common/rootfs/lib/infix/nameif @@ -0,0 +1,46 @@ +#!/bin/sh +# Find any switch ports, classify and rename to Infix std +# + +ident=$(basename "$0") +num=0 + +# Perform any interface renames as dictated by, first, any Qemu +# override (for testing), and then the user specific /etc/mactab +for file in /sys/firmware/qemu_fw_cfg/by_name/opt/mactab/raw /etc/mactab; do + if [ -f $file ]; then + logger -k -p user.notice -t "$ident" "calling nameif -c $file" + nameif -c $file -s + fi +done + +# Find CPU interfaces used for connecting to a switch managed by DSA +for netif in /sys/class/net/*; do + iface=$(basename "$netif") + [ -f "/sys/class/net/$iface/dsa/tagging" ] || continue + + # Disable SLAAC frames and such, that's for the port interfaces, and + # bring it up so we get link events from the ports to the bridge. + sysctl -q "net.ipv6.conf.$iface.disable_ipv6=1" + + dsa="dsa$num" + logger -k -p user.notice -t "$ident" "Found DSA interface, renaming $iface -> $dsa" + ip link set dev "$iface" name $dsa + num=$((num + 1)) +done + +# Find and mark all switch ports +ports=$(devlink port 2>/dev/null | awk '/flavour physical/{print $5}') +for iface in $ports; do + ip link set "$iface" group port +done + +# Testing, e.g., using /etc/mactab may use TAP devices to create +# emulated switch ports, make sure to mark them as well +ports=$(ip -json link | jq -r '.[].ifname | match("^e[[:digit:]]+").string') +for iface in $ports; do + ip link set "$iface" group port +done + +# At least loopback in iface group +ip link set lo group iface diff --git a/board/common/rootfs/lib/infix/swup b/board/common/rootfs/lib/infix/swup index 06154e97..24e0889e 100755 --- a/board/common/rootfs/lib/infix/swup +++ b/board/common/rootfs/lib/infix/swup @@ -1,77 +1,35 @@ #!/bin/sh -# Find any switch ports, classify and rename to Infix std -# -ident=$(basename "$0") -num=0 - -# Perform any interface renames as dictated by, first, any Qemu -# override (for testing), and then the user specific /etc/mactab -for file in /sys/firmware/qemu_fw_cfg/by_name/opt/mactab/raw /etc/mactab; do - if [ -f $file ]; then - logger -k -p user.notice -t "$ident" "calling nameif -c $file" - nameif -c $file -s - fi -done - -# Find CPU interfaces used for connecting to a switch managed by DSA -for netif in /sys/class/net/*; do - iface=$(basename "$netif") - [ -f "/sys/class/net/$iface/dsa/tagging" ] || continue - - # Disable SLAAC frames and such, that's for the port interfaces, and - # bring it up so we get link events from the ports to the bridge. - sysctl -q "net.ipv6.conf.$iface.disable_ipv6=1" - - dsa="dsa$num" - logger -k -p user.notice -t "$ident" "Found DSA interface, renaming $iface -> $dsa" - ip link set dev "$iface" name $dsa - num=$((num + 1)) -done - -# Find and mark all switch ports -ports=$(devlink port 2>/dev/null | awk '/flavour physical/{print $5}') -for iface in $ports; do - ip link set "$iface" group port -done - -# Testing, e.g., using /etc/mactab may use TAP devices to create -# emulated switch ports, make sure to mark them as well -ports=$(ip -json link | jq -r '.[].ifname | match("^e[[:digit:]]+").string') -for iface in $ports; do - ip link set "$iface" group port -done - -# At least loopback in iface group -ip link set lo group iface +# Only create a default config on unmanaged nodes. +initctl cond get boot/etc || exit 0 # Factory default: all switch ports in VLAN 1 of br0 # need to check for 'length > 0' because ip command # outputs empty json objects for non-port group ifs ports=$(ip -json link show group port | jq -r '.[].ifname | select(length > 0)' | tr "\n" " ") -if [ ! -f /etc/network/interfaces.d/br0 ] && [ -n "$ports" ]; then - touch /etc/network/interfaces.d/br0 - for port in $ports; do - cat <<-EOF >>/etc/network/interfaces.d/br0 - iface $port - bridge-access 1 - post-up ip link set $port group port - EOF - done - cat <<-EOF >>/etc/network/interfaces.d/br0 +[ -f /etc/network/interfaces.d/br0 ] || [ -z "$ports" ] && exit 0 - auto br0 - iface br0 - bridge-ports $ports - bridge-vlan-aware yes - bridge-stp on - bridge-vids 1 - - auto vlan1 - iface vlan1 inet dhcp - vlan-id 1 - vlan-raw-device br0 - post-up ip link set vlan1 group iface +touch /etc/network/interfaces.d/br0 +for port in $ports; do + cat <<-EOF >>/etc/network/interfaces.d/br0 + iface $port + bridge-access 1 + post-up ip link set $port group port EOF - ip link set vlan1 group iface -fi +done +cat <<-EOF >>/etc/network/interfaces.d/br0 + + auto br0 + iface br0 + bridge-ports $ports + bridge-vlan-aware yes + bridge-stp on + bridge-vids 1 + + auto vlan1 + iface vlan1 inet dhcp + vlan-id 1 + vlan-raw-device br0 + post-up ip link set vlan1 group iface +EOF +ip link set vlan1 group iface