61 lines
1.5 KiB
Bash
Executable File
61 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
# /etc/bewan/scripts/waneth-down
|
|
# called when cable is unplugged of WAN ethernet port
|
|
|
|
WANETHID=${WANETHID:-}
|
|
if [ "$WANETHID" = '' ]; then
|
|
WANETHID=${1:-}
|
|
fi
|
|
|
|
. /etc/bewan/scripts/globals
|
|
. /etc/bewan/lib/base
|
|
. /etc/bewan/lib/phy
|
|
|
|
main_waneth_down() {
|
|
base_log "$SCRIPTD/waneth-down" debug
|
|
|
|
# Take onchange mutex
|
|
base_enter_critical 'onchange'
|
|
|
|
# Get config parameters after taking lock, else parameters could be outdated
|
|
base_call_initd 'setparam'
|
|
|
|
# Check the associated phy state
|
|
local phy_state=''
|
|
retrieve_phy_state WANEthernetInterface ${WANETHID}
|
|
|
|
if [ "$phy_state" -eq "0" ] && [ -f $WANETHD/wanethup_${WANETHID} ]; then
|
|
base_log "$SCRIPTD/waneth-down entered" debug
|
|
|
|
# Power down phy to avoid dhcp client to do ip-up if user plugged a cable again
|
|
power_updown_phy WANEthernetInterface 1 0
|
|
|
|
# Remove flag file
|
|
rm -f $WANETHD/wanethup_${WANETHID}
|
|
|
|
NOIPT=1
|
|
for script in `find /etc/bewan/waneth-down.d -follow -type f 2>/dev/null | sort`; do
|
|
base_log "$script down $WANETHID" debug
|
|
. $script down $WANETHID
|
|
done
|
|
|
|
# Restart netfilter
|
|
IPPROTO=
|
|
ARG=restart
|
|
base_call_initd 'fwrules iptables ip6tables'
|
|
|
|
base_call_initd 'inittab'
|
|
|
|
# Power up phy
|
|
power_updown_phy WANEthernetInterface 1 1
|
|
|
|
# Exit waneth-up-down critical section
|
|
base_log "$SCRIPTD/waneth-down exited" debug
|
|
fi
|
|
|
|
# Release onchange mutex
|
|
base_exit_critical 'onchange'
|
|
}
|
|
|
|
main_waneth_down
|