2020-07-26 09:05:46 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-08-24 16:52:10 +00:00
|
|
|
[ -z "$IF_METRIC" ] && IF_METRIC="1"
|
2020-08-20 08:59:43 +00:00
|
|
|
[ -n "$IF_VRF_TABLE" ] && VRF_TABLE="table $IF_VRF_TABLE"
|
2020-08-20 10:40:38 +00:00
|
|
|
[ -n "$IF_METRIC" ] && METRIC="metric $IF_METRIC"
|
2020-08-20 08:59:43 +00:00
|
|
|
|
2020-07-26 09:05:46 +00:00
|
|
|
addr_family() {
|
|
|
|
if [ "$1" != "${1#*[0-9].[0-9]}" ]; then
|
|
|
|
echo "-4"
|
|
|
|
elif [ "$1" != "${1#*:[0-9a-fA-F]}" ]; then
|
|
|
|
echo "-6"
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-07-26 10:13:25 +00:00
|
|
|
configure_addresses() {
|
|
|
|
for i in $(ifquery -p address -i $INTERFACES_FILE $IFACE); do
|
|
|
|
addrfam=$(addr_family $i)
|
|
|
|
${MOCK} ip $addrfam addr $1 $i dev $IFACE
|
|
|
|
done
|
|
|
|
}
|
2020-07-26 09:05:46 +00:00
|
|
|
|
2020-07-26 10:13:25 +00:00
|
|
|
configure_gateways() {
|
|
|
|
for i in $(ifquery -p gateway -i $INTERFACES_FILE $IFACE); do
|
|
|
|
addrfam=$(addr_family $i)
|
2020-08-20 10:40:38 +00:00
|
|
|
${MOCK} ip $addrfam route $1 default via $i $VRF_TABLE $METRIC
|
2020-07-26 10:13:25 +00:00
|
|
|
done
|
|
|
|
}
|
2020-07-26 09:05:46 +00:00
|
|
|
|
2020-07-26 10:18:57 +00:00
|
|
|
[ -z "$VERBOSE" ] || set -x
|
|
|
|
|
2020-07-26 10:13:25 +00:00
|
|
|
case "$PHASE" in
|
|
|
|
up)
|
|
|
|
configure_addresses add
|
|
|
|
configure_gateways add
|
|
|
|
;;
|
|
|
|
down)
|
|
|
|
configure_gateways del
|
|
|
|
configure_addresses del
|
|
|
|
;;
|
|
|
|
*) exit 0 ;;
|
|
|
|
esac
|