Eu escrevi um script que verifica as interfaces em relação a /sys
para determinar se elas são membros da ponte e, em seguida, rejeitam a ponte. O VyOS usa netplugd
para monitorar interfaces e, por alguma razão, meu script o confunde (provavelmente escreverei uma questão separada para isso), mas acho que é uma boa solução geral.
#!/bin/bash
## This script will bounce a br interface if a member interface goes down.
## This will cause router BGP timers to reset, making outages last only seconds instead of minutes.
##
## This script is called by netplug on Vyos:
## /etc/netplug/linkdown.d/my-brdown
##
## Version History
## 1.0 - Initial version
##
LOCKDIR=/var/run/my-bridge-ctl
# Since we only have one br, not going to implement this right now.
#IGNORE_BRIDGES=()
IFACE=$1
#Remove the lock directory
function cleanup {
if rmdir $LOCKDIR; then
logger -is -t "my-bridge-ctl" -p "kern.info" "Finished"
else
logger -is -t "my-bridge-ctl" -p "kern.error" "Failed to remove lock directory '$LOCKDIR'"
exit 1
fi
}
if mkdir $LOCKDIR; then
#Ensure that if we "grabbed a lock", we release it
#Works for SIGTERM and SIGINT(Ctrl-C)
trap "cleanup" EXIT
logger -is -t "my-bridge-ctl" -p "kern.info" "Acquired lock, running"
# Processing starts here
IFACE_DESC=$(<"/sys/class/net/${IFACE}/ifalias")
IFACE_BR_DIR="/sys/class/net/${IFACE}/brport"
if [ ! -d "$IFACE_BR_DIR" ]; then
logger -is -t "my-bridge-ctl" -p "kern.warning" "Interface ${IFACE} (${IFACE_DESC-no desc}) went down. Not a member of a bridge. Skipping."
else
IFACE_BR_LINK=$(realpath "/sys/class/net/${IFACE}/master")
IFACE_BR_NAME=$(basename $IFACE_BR_LINK)
IFACE_BR_DESC=$(<"${IFACE_BR_LINK}/ifalias")
logger -is -t "my-bridge-ctl" -p "kern.warning" "Interface ${IFACE} (${IFACE_DESC:-no desc}) went down. Member of bridge ${IFACE_BR_NAME} (${IFACE_BR_DESC:-no desc})."
# TODO: Insert IGNORE_BRIDGE check here
find "${IFACE_BR_LINK}/brif" -type l -print0 | while IFS= read -r -d $'#!/bin/bash
## This script will bounce a br interface if a member interface goes down.
## This will cause router BGP timers to reset, making outages last only seconds instead of minutes.
##
## This script is called by netplug on Vyos:
## /etc/netplug/linkdown.d/my-brdown
##
## Version History
## 1.0 - Initial version
##
LOCKDIR=/var/run/my-bridge-ctl
# Since we only have one br, not going to implement this right now.
#IGNORE_BRIDGES=()
IFACE=$1
#Remove the lock directory
function cleanup {
if rmdir $LOCKDIR; then
logger -is -t "my-bridge-ctl" -p "kern.info" "Finished"
else
logger -is -t "my-bridge-ctl" -p "kern.error" "Failed to remove lock directory '$LOCKDIR'"
exit 1
fi
}
if mkdir $LOCKDIR; then
#Ensure that if we "grabbed a lock", we release it
#Works for SIGTERM and SIGINT(Ctrl-C)
trap "cleanup" EXIT
logger -is -t "my-bridge-ctl" -p "kern.info" "Acquired lock, running"
# Processing starts here
IFACE_DESC=$(<"/sys/class/net/${IFACE}/ifalias")
IFACE_BR_DIR="/sys/class/net/${IFACE}/brport"
if [ ! -d "$IFACE_BR_DIR" ]; then
logger -is -t "my-bridge-ctl" -p "kern.warning" "Interface ${IFACE} (${IFACE_DESC-no desc}) went down. Not a member of a bridge. Skipping."
else
IFACE_BR_LINK=$(realpath "/sys/class/net/${IFACE}/master")
IFACE_BR_NAME=$(basename $IFACE_BR_LINK)
IFACE_BR_DESC=$(<"${IFACE_BR_LINK}/ifalias")
logger -is -t "my-bridge-ctl" -p "kern.warning" "Interface ${IFACE} (${IFACE_DESC:-no desc}) went down. Member of bridge ${IFACE_BR_NAME} (${IFACE_BR_DESC:-no desc})."
# TODO: Insert IGNORE_BRIDGE check here
find "${IFACE_BR_LINK}/brif" -type l -print0 | while IFS= read -r -d $'%pre%' IFACE_BR_MEMBER_LINK; do
IFACE_BR_MEMBER_NAME=$(basename $IFACE_BR_MEMBER_LINK)
logger -is -t "my-bridge-ctl" -p "kern.info" "Handling ${IFACE_BR_NAME} member interface ${IFACE_BR_MEMBER_NAME} (${IFACE_BR_MEMBER_LINK})."
# Actually do the bounce
ip link set dev ${IFACE_BR_MEMBER_NAME} down && sleep 2 && ip link set dev ${IFACE_BR_MEMBER_NAME} up
logger -is -t "my-bridge-ctl" -p "kern.info" "Interface ${IFACE_BR_MEMBER_NAME} bounced."
done
fi
sleep 5
else
logger -is -t "my-bridge-ctl" -p "kern.info" "Could not create lock directory '$LOCKDIR'"
exit 1
fi
' IFACE_BR_MEMBER_LINK; do
IFACE_BR_MEMBER_NAME=$(basename $IFACE_BR_MEMBER_LINK)
logger -is -t "my-bridge-ctl" -p "kern.info" "Handling ${IFACE_BR_NAME} member interface ${IFACE_BR_MEMBER_NAME} (${IFACE_BR_MEMBER_LINK})."
# Actually do the bounce
ip link set dev ${IFACE_BR_MEMBER_NAME} down && sleep 2 && ip link set dev ${IFACE_BR_MEMBER_NAME} up
logger -is -t "my-bridge-ctl" -p "kern.info" "Interface ${IFACE_BR_MEMBER_NAME} bounced."
done
fi
sleep 5
else
logger -is -t "my-bridge-ctl" -p "kern.info" "Could not create lock directory '$LOCKDIR'"
exit 1
fi