Add factory default, all switch ports in group VLAN 1 on br0

This change checks¹ if the system does not have a br0 interface, creates
a default one consisting of all switch ports in VLAN 1 of br0.

On top of br0 a vlan1 management interface is created with DHCP address.

For emulation and test purposes, a way to supply tap interfaces from
Qemu, and pass off as if they were regular switch ports, is added.
____
¹ obviously a better way to detect a factory-reset device is needed,
  not all systems running infix will need or want a br0 interface.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-01-03 18:25:18 +01:00
parent ec3c6e245a
commit ccba72b083
4 changed files with 44 additions and 6 deletions
+2
View File
@@ -129,6 +129,8 @@ CONFIG_UEVENT_HELPER=y
CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
CONFIG_DEVTMPFS=y
CONFIG_DEVTMPFS_MOUNT=y
CONFIG_FW_CFG_SYSFS=y
CONFIG_FW_CFG_SYSFS_CMDLINE=y
CONFIG_MTD=y
CONFIG_MTD_BLOCK=y
CONFIG_MTD_BLOCK2MTD=y
+2
View File
@@ -61,6 +61,8 @@ CONFIG_NET_9P_VIRTIO=y
CONFIG_PCI=y
CONFIG_DEVTMPFS=y
CONFIG_DEVTMPFS_MOUNT=y
CONFIG_FW_CFG_SYSFS=y
CONFIG_FW_CFG_SYSFS_CMDLINE=y
CONFIG_VIRTIO_BLK=y
CONFIG_BLK_DEV_SD=y
CONFIG_SCSI_VIRTIO=y
+35 -5
View File
@@ -5,11 +5,14 @@
ident=$(basename "$0")
num=0
# Perform any interface renames as dictated by /etc/mactab.
if [ -f /etc/mactab ]; then
logger -k -p user.notice -t "$ident" "calling nameif -c /etc/mactab"
nameif -s
fi
# 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
@@ -37,3 +40,30 @@ 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
# 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
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
EOF
fi
+5 -1
View File
@@ -71,9 +71,13 @@ net_args()
echo -n "-nic bridge,br=$QEMU_NET_BRIDGE_DEV,model=$QEMU_NET_MODEL "
elif [ "$QEMU_NET_TAP" = "y" ]; then
QEMU_NET_TAP_N=${QEMU_NET_TAP_N:-1}
mactab=$(dirname "$QEMU_ROOTFS")/mactab
rm "$mactab"
for i in $(seq 0 $(($QEMU_NET_TAP_N - 1))); do
echo -n "-nic tap,ifname=qtap$i,script=no,model=$QEMU_NET_MODEL "
echo "e$i 52:54:00:12:34:$((56 + i))" >>"$mactab"
echo -n "-nic tap,ifname=qtap$i,script=no,model=$QEMU_NET_MODEL "
done
echo -n "-fw_cfg name=opt/mactab,file="$mactab" "
elif [ "$QEMU_NET_USER" = "y" ]; then
[ "$QEMU_NET_USER_OPTS" ] && QEMU_NET_USER_OPTS="$QEMU_NET_USER_OPTS,"