#!/bin/sh [ -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}" 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 } configure_addresses() { for addr in ${IF_ADDRESSES}; do addrfam=$(addr_family ${addr}) if [ "${IF_POINT_TO_POINT}" -a "${addrfam}" = "-4" ]; then PEER="peer ${IF_POINT_TO_POINT}" else PEER="" fi if [ -z "${MOCK}" -a "${1}" = "del" ]; then # When having multiple addresses set from the same prefix they might/will(?) be configured # as 'secondary' and implicitly removed when removing the non-secondary address. This # leads ip complaining about not being able to remove the secondaries as they are already # gone. So we ignore errors while deconfiguring addresses as they liked occur when removing # a vanish address anyway. ${MOCK} ip "${addrfam}" addr "${1}" "${addr}" ${PEER} dev "${IFACE}" 2>/dev/null else ${MOCK} ip "${addrfam}" addr "${1}" "${addr}" ${PEER} dev "${IFACE}" fi done } configure_gateways() { for gw in ${IF_GATEWAYS}; do addrfam=$(addr_family ${gw}) ${MOCK} ip "${addrfam}" route "${1}" default via "${gw}" ${VRF_TABLE} ${METRIC} dev "${IFACE}" done } case "$PHASE" in up) configure_addresses add configure_gateways add ;; down) configure_gateways del configure_addresses del ;; *) exit 0 ;; esac