Files
2026-02-20 23:14:19 +03:00

69 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
set -eux pipefail
# containerlab needs some time to setup links
sleep $CONTAINERLAB_TIMEOUT
if [ "$ROLE" = "switch" ]; then
echo "Configuring as switch with MAC=$MAC"
if [ "$VLAN" = "yes" ]; then
ip link add name br0 type bridge vlan_filtering 1
else
ip link add name br0 type bridge
fi
ip link set dev br0 address $MAC
ip link set br0 up
for i in eth1 eth2 eth3 eth4; do
ip link set $i master br0
ip link set $i up
done
if [ "$VLAN" = "yes" ]; then
bridge vlan add dev eth1 vid 10 pvid untagged
bridge vlan add dev eth2 vid 20 pvid untagged
bridge vlan add dev eth4 vid 10,20
fi
echo "Switch setup complete"
elif [ "$ROLE" = "bridge" ]; then
echo "Configuring as bridge with MAC=$MAC"
if [ "$VLAN" = "yes" ]; then
ip link add name br0 type bridge vlan_filtering 1
else
ip link add name br0 type bridge
fi
ip link set dev br0 address $MAC
ip link set br0 up
ip link set eth1 master br0
ip link set eth2 master br0
ip link set eth1 up
ip link set eth2 up
if [ "$VLAN" = "yes" ]; then
bridge vlan add dev eth1 vid 10,20
bridge vlan add dev eth2 vid 10,20
fi
echo "Bridge setup complete"
elif [ "$ROLE" = "host" ]; then
echo "Configuring as host with MAC=$MAC"
ip link set dev eth1 down
ip link set dev eth1 address $MAC
ip link set dev eth1 up
echo "Host setup complete"
else
echo "Unknown ROLE: $ROLE"
fi
sleep infinity