44 lines
1.2 KiB
Bash
Executable File
44 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
set -Eeuo pipefail
|
|
IFACE=$1
|
|
|
|
if [ ${#IFACE} -gt 14 ]; then
|
|
echo "interface name too long, mac 14 char: $IFACE"
|
|
exit 10
|
|
fi
|
|
|
|
source /etc/libvirt/hooks/$IFACE
|
|
|
|
if ! [[ $CLUSTER =~ ^[0-9]+$ ]]; then
|
|
echo "CLUSTER seems not to be valid"
|
|
exit 10
|
|
fi
|
|
|
|
LOOPBACKIP=$(ip -4 addr show dev lo | grep -Po 'inet \K[\d.]+' | grep -v "^127.0.0.1$")
|
|
BRIDGE=br${CLUSTER}
|
|
VIF=vxlan${CLUSTER}
|
|
[ -z ${PARENTIF:=""} ] || VIF=vlan${CLUSTER} ### if we have a parentif set we're just going to handle it as a legacy old school vlan
|
|
|
|
ip link set up ${IFACE}
|
|
|
|
if ! ip link show dev ${VIF} &>/dev/null; then
|
|
if [ -z ${PARENTIF:=""} ]
|
|
then
|
|
ip link add ${VIF} type vxlan id ${CLUSTER} dstport 4789 local ${LOOPBACKIP} nolearning
|
|
else
|
|
ip link add link ${PARENTIF} name ${VIF} type vlan protocol 802.1q id ${CLUSTER}
|
|
fi
|
|
ip link set up ${VIF}
|
|
fi
|
|
|
|
if ! ip link show dev ${BRIDGE} &>/dev/null; then
|
|
brctl addbr ${BRIDGE}
|
|
brctl stp ${BRIDGE} off
|
|
brctl addif ${BRIDGE} ${VIF}
|
|
ip link set up dev ${BRIDGE}
|
|
bridge vlan del dev ${BRIDGE} vid 1 self
|
|
echo 1 >/sys/class/net/${BRIDGE}/bridge/vlan_filtering
|
|
fi
|
|
|
|
brctl addif ${BRIDGE} ${IFACE}
|