2018-07-26 03:57:41 -05:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
2018-10-05 13:29:12 -05:00
|
|
|
set -x
|
2018-07-26 03:57:41 -05:00
|
|
|
IFACE=$1
|
|
|
|
|
2018-10-05 13:29:12 -05:00
|
|
|
source /etc/libvirt/hooks/$IFACE
|
|
|
|
echo CLUSTER=$CLUSTER
|
|
|
|
echo IP=$IP
|
|
|
|
|
2018-07-26 03:57:41 -05:00
|
|
|
maxprefixv6=64
|
2018-10-05 13:29:12 -05:00
|
|
|
maxprefixv4=25
|
2018-07-26 03:57:41 -05:00
|
|
|
|
|
|
|
publicmac=52:54:00:00:00:11
|
|
|
|
|
|
|
|
|
|
|
|
if [ -z $IP ]; then
|
|
|
|
echo "got nothing back from the API"
|
|
|
|
exit 10
|
|
|
|
fi
|
|
|
|
|
|
|
|
eui64() {
|
|
|
|
local macaddr="$1"
|
|
|
|
printf "%02x%s" $(( 16#${macaddr:0:2} ^ 2#00000010 )) "${macaddr:2}" \
|
|
|
|
| sed -E -e 's/([0-9a-zA-Z]{2})*/0x\0|/g' \
|
|
|
|
| tr -d ':\n' \
|
|
|
|
| xargs -d '|' \
|
|
|
|
printf "fe80::%02x%02x:%02xff:fe%02x:%02x%02x"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ip link set up ${IFACE}
|
|
|
|
arp -i ${IFACE} -Ds 169.254.0.1 ${IFACE} netmask 255.255.255.255 pub
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IFS=',' read -ra IPS <<< "$IP"
|
|
|
|
for IP in "${IPS[@]}"; do
|
2018-10-05 13:29:12 -05:00
|
|
|
echo $IP
|
2018-10-08 11:22:22 -05:00
|
|
|
if [[ $IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/([0-9]{2})$ ]]; then ### we got a IPv4 prefix < maxprefixv4
|
|
|
|
echo matched ${BASH_REMATCH[1]}
|
2018-07-26 03:57:41 -05:00
|
|
|
if [ ${BASH_REMATCH[1]} -lt $maxprefixv4 ]; then
|
|
|
|
echo "we don't support such a big customer net?"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${BASH_REMATCH[1]} -gt 32 ]; then
|
|
|
|
echo "prefix is invalid"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "we got IPv4 with prefix ${BASH_REMATCH[0]}"
|
|
|
|
ip route add ${IP} dev ${IFACE}
|
|
|
|
|
|
|
|
elif [[ $IP =~ ^2604:bbc0:[0-9,a-f,:]{1,444}/([0-9]{2,3})$ ]]; then ### we got a PIv6 prefix < masprefixv6
|
|
|
|
|
|
|
|
if [ ${BASH_REMATCH[1]} -lt $maxprefixv6 ]; then
|
|
|
|
echo "we don't support such a big customer net?"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${BASH_REMATCH[1]} -gt 128 ]; then
|
|
|
|
echo "prefix is invalid"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "we got IPv6 with prefix ${BASH_REMATCH[0]}"
|
|
|
|
ip route add ${IP} dev ${IFACE} via $(eui64 $publicmac)
|
|
|
|
|
|
|
|
else ### don't know what we have but something we can't work with
|
|
|
|
echo "Unable to detect with what prefix I'm working with"
|
|
|
|
fi
|
|
|
|
done
|