From 6d96b218cafe7f73d551efafd44732a9db3409fd Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 28 Apr 2023 19:43:06 +0200 Subject: [PATCH] board/classic: generate interfaces.d, set hostname from qemu_fw_cfg Signed-off-by: Joachim Wiberg --- .../rootfs/etc/network/interfaces.d/eth0 | 3 - board/classic/rootfs/lib/infix/swup | 62 ++++++++++++++----- 2 files changed, 46 insertions(+), 19 deletions(-) delete mode 100644 board/classic/rootfs/etc/network/interfaces.d/eth0 diff --git a/board/classic/rootfs/etc/network/interfaces.d/eth0 b/board/classic/rootfs/etc/network/interfaces.d/eth0 deleted file mode 100644 index 030e443c..00000000 --- a/board/classic/rootfs/etc/network/interfaces.d/eth0 +++ /dev/null @@ -1,3 +0,0 @@ -auto eth0 -iface eth0 inet dhcp - pre-up ip link set eth0 group iface diff --git a/board/classic/rootfs/lib/infix/swup b/board/classic/rootfs/lib/infix/swup index d23ba44a..385e35e5 100755 --- a/board/classic/rootfs/lib/infix/swup +++ b/board/classic/rootfs/lib/infix/swup @@ -1,23 +1,27 @@ #!/bin/sh +# Factory default: +# 1) all switch ports in VLAN 1 of br0 +# 2) no switch ports => DHCP on eth0 +# 3) no eth0 -# 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" " ") -[ -f /etc/network/interfaces.d/br0 ] || [ -z "$ports" ] && exit 0 +create_bridge() +{ + nm=$1 + shift + ports=$@ -touch /etc/network/interfaces.d/br0 -for port in $ports; do - cat <<-EOF >>/etc/network/interfaces.d/br0 + touch "/etc/network/interfaces.d/$nm" + for port in $ports; do + cat <<-EOF >>"/etc/network/interfaces.d/$nm" iface $port bridge-access 1 post-up ip link set $port group port - EOF -done -cat <<-EOF >>/etc/network/interfaces.d/br0 + EOF + done + cat <<-EOF >> "/etc/network/interfaces.d/$nm" - auto br0 - iface br0 + auto $nm + iface $nm bridge-ports $ports bridge-vlan-aware yes bridge-stp on @@ -26,7 +30,33 @@ cat <<-EOF >>/etc/network/interfaces.d/br0 auto vlan1 iface vlan1 inet dhcp vlan-id 1 - vlan-raw-device br0 + vlan-raw-device $nm post-up ip link set vlan1 group iface -EOF -ip link set vlan1 group iface + EOF + ip link set vlan1 group iface +} + +# Check if already set up +[ -z "$(ls -A /etc/network/interfaces.d/)" ] || exit 0 + +# Check for custom hostname from Qemu/Qeneth +nm=$(cat /sys/firmware/qemu_fw_cfg/by_name/opt/hostname/raw) +if [ -n "$nm" ]; then + hostnm "$nm" +fi + +# 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 [ -n "$ports" ]; then + create_bridge br0 $ports +else + ifaces=$(ip -json addr show |jq -r '.[] | select(.link_type=="ether").ifname') + for iface in $ifaces; do + cat <<-EOF > "/etc/network/interfaces.d/$iface" + auto $iface + iface $iface inet dhcp + pre-up ip link set $iface group iface + EOF + done +fi