2020-07-26 09:05:46 +00:00
|
|
|
#!/bin/sh
|
2020-10-06 02:29:54 +00:00
|
|
|
[ -z "${VERBOSE}" ] || set -x
|
|
|
|
|
|
|
|
[ -z "${IF_METRIC}" ] && IF_METRIC="1"
|
|
|
|
[ -n "${IF_VRF_TABLE}" ] && VRF_TABLE="table ${IF_VRF_TABLE}"
|
|
|
|
[ -n "${IF_VRF_MEMBER}" ] && VRF_TABLE="vrf ${IF_VRF_MEMBER}"
|
|
|
|
[ -n "${IF_METRIC}" ] && METRIC="metric ${IF_METRIC}"
|
2020-10-03 02:26:23 +00:00
|
|
|
|
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() {
|
2020-10-06 02:29:54 +00:00
|
|
|
for addr in ${IF_ADDRESSES}; do
|
|
|
|
addrfam=$(addr_family ${addr})
|
2020-10-06 01:38:02 +00:00
|
|
|
if [ "${IF_POINT_TO_POINT}" -a "${addrfam}" = "-4" ]; then
|
|
|
|
PEER="peer ${IF_POINT_TO_POINT}"
|
2020-10-03 02:26:23 +00:00
|
|
|
else
|
|
|
|
PEER=""
|
|
|
|
fi
|
|
|
|
|
2021-04-20 01:01:21 +00:00
|
|
|
${MOCK} ip "${addrfam}" addr add "${addr}" ${PEER} dev "${IFACE}"
|
2020-07-26 10:13:25 +00:00
|
|
|
done
|
|
|
|
}
|
2020-07-26 09:05:46 +00:00
|
|
|
|
2020-07-26 10:13:25 +00:00
|
|
|
configure_gateways() {
|
2020-10-06 02:29:54 +00:00
|
|
|
for gw in ${IF_GATEWAYS}; do
|
|
|
|
addrfam=$(addr_family ${gw})
|
2021-04-20 01:01:21 +00:00
|
|
|
${MOCK} ip "${addrfam}" route add default via "${gw}" ${VRF_TABLE} ${METRIC} dev "${IFACE}"
|
2020-07-26 10:13:25 +00:00
|
|
|
done
|
|
|
|
}
|
2020-07-26 09:05:46 +00:00
|
|
|
|
2021-04-20 01:01:21 +00:00
|
|
|
flush() {
|
|
|
|
cmd="addr"
|
|
|
|
arg="dev ${IFACE}"
|
|
|
|
|
|
|
|
${MOCK} ip ${cmd} flush ${arg}
|
|
|
|
}
|
|
|
|
|
2020-07-26 10:13:25 +00:00
|
|
|
case "$PHASE" in
|
|
|
|
up)
|
|
|
|
configure_addresses add
|
|
|
|
configure_gateways add
|
|
|
|
;;
|
|
|
|
down)
|
2021-04-20 01:01:21 +00:00
|
|
|
flush
|
2020-07-26 10:13:25 +00:00
|
|
|
;;
|
|
|
|
*) exit 0 ;;
|
|
|
|
esac
|