hw-test/scripts/setup-netdev

86 lines
2.2 KiB
Text
Raw Normal View History

2017-01-25 22:30:16 -06:00
#!/bin/bash
source scan-netdev
modprobe bonding
# All vlans are using netmask /22
2021-11-02 23:24:25 -05:00
MASK=22
2023-02-24 13:20:16 -06:00
#CTLPLANE=10 # ctlplane vlan #Fixme: hardcoded
2021-09-08 22:15:57 -05:00
SPEED=25000
MTU=9000
2017-01-25 22:30:16 -06:00
2021-11-02 23:24:25 -05:00
for VLAN in {10..4000} ; do # Most vLANs
2017-01-25 22:30:16 -06:00
if [[ -f /etc/netdev/vlan.$VLAN.csv ]] ; then
VLAN_CONF=`grep $SERVER_SERIAL \
/etc/netdev/vlan.$VLAN.csv`
2021-09-07 06:25:01 -05:00
else
VLAN_CONF=
2017-01-25 22:30:16 -06:00
fi
2021-09-08 22:15:57 -05:00
[[ -z $VLAN_CONF ]] && continue
2017-01-25 22:30:16 -06:00
MY_HOSTNAME=`hostname`
2021-09-08 22:15:57 -05:00
#HOSTNAME,SERIAL,IP_ADDRESS,BOND,MODE,SLAVE0,SLAVE1,GW
2021-09-07 06:25:01 -05:00
VLAN_HOSTNAME=`cut -d ',' -f 1 <<< $VLAN_CONF`
2017-01-25 22:30:16 -06:00
if [[ -n $VLAN_HOSTNAME ]] ; then
if [[ "$MY_HOSTNAME" != "$VLAN_HOSTNAME" ]] ; then
hostname $VLAN_HOSTNAME
fi
fi
2021-09-07 06:25:01 -05:00
VLAN_IP=`cut -d ',' -f 3 <<< $VLAN_CONF`
VLAN_BOND=`cut -d ',' -f 4 <<< $VLAN_CONF`
BOND_MODE=`cut -d ',' -f 5 <<< $VLAN_CONF`
SLAVE_0=`cut -d ',' -f 6 <<< $VLAN_CONF`
SLAVE_1=`cut -d ',' -f 7 <<< $VLAN_CONF`
2021-09-08 22:15:57 -05:00
[[ -z $VLAN_BOND ]] && continue
2017-01-25 22:30:16 -06:00
if [[ ! -d /sys/class/net/$VLAN_BOND ]] ; then
if [[ ! -f /sys/class/net/bonding_masters ]] ; then
echo "Missing bonding_masters special file"
exit 22
fi
echo "+$VLAN_BOND" \
> /sys/class/net/bonding_masters
sleep 3
if [[ ! -d /sys/class/net/$VLAN_BOND ]] ; then
echo "$VLAN_BOND not available"
exit 23
fi
2021-09-09 05:30:05 -05:00
MY_MODE=`cut -d ' ' -f 2 /sys/class/net/$VLAN_BOND/bonding/mode`
if [[ "$MY_MODE" != "$BOND_MODE" ]] ; then
echo $BOND_MODE \
> /sys/class/net/$VLAN_BOND/bonding/mode
sleep 2
fi
ip link set $VLAN_BOND up
[[ -n $MTU ]] && ip link set $VLAN_BOND mtu $MTU
2021-11-24 13:25:09 -06:00
AUTONEG=`cut -d ',' -f 8 <<< $VLAN_CONF | grep 'A'`
if [[ -z $AUTONEG ]] ; then
AUTONEG_FLAGS='autoneg off';
else
AUTONEG_FLAGS='';
fi
2021-09-22 15:11:41 -05:00
if [[ -n $SPEED ]] ; then
2021-11-24 13:25:09 -06:00
ethtool -s $SLAVE_0 $AUTONEG_FLAGS speed $SPEED duplex full
ethtool -s $SLAVE_1 $AUTONEG_FLAGS speed $SPEED duplex full
2021-09-22 15:11:41 -05:00
fi
sleep 5
2021-09-09 05:30:05 -05:00
ifenslave $VLAN_BOND $SLAVE_0 $SLAVE_1
sleep 5
2017-01-25 22:30:16 -06:00
fi
2021-11-24 13:25:09 -06:00
UNTAGGED=`cut -d ',' -f 8 <<< $VLAN_CONF | grep 'U'`
if [[ -n $UNTAGGED ]] ; then
2017-01-25 22:30:16 -06:00
ip addr add $VLAN_IP/$MASK dev $VLAN_BOND
else
ip link add link $VLAN_BOND \
name $VLAN_BOND.$VLAN \
type vlan id $VLAN
ip link set $VLAN_BOND.$VLAN up
ip addr add $VLAN_IP/$MASK dev $VLAN_BOND.$VLAN
fi
GATEWAY=`cut -d ',' -f 9 <<< $VLAN_CONF`
if [[ -n $GATEWAY ]] ; then
ip route add default via $GATEWAY
fi
2017-01-25 22:30:16 -06:00
done
systemctl restart sshd