$IPT -F mwan3_rules
}
+mwan3_set_general_rules()
+{
+ if [ -z "$($IP rule list | awk '$1 == "2253:"')" ]; then
+ $IP rule add pref 2253 fwmark 0xfd00/0xff00 blackhole
+ fi
+
+ if [ -z "$($IP rule list | awk '$1 == "2254:"')" ]; then
+ $IP rule add pref 2254 fwmark 0xfe00/0xff00 unreachable
+ fi
+}
+
mwan3_set_connected_iptables()
{
local connected_networks
$IP rule del pref $(($iface_id+2000))
done
- while [ -n "$($IP rule list | awk '$1 == "2253:"')" ]; do
- $IP rule del pref 2253
- done
-
- while [ -n "$($IP rule list | awk '$1 == "2254:"')" ]; do
- $IP rule del pref 2254
- done
-
[ $ACTION == "ifup" ] && $IP rule add pref $(($iface_id+1000)) iif $DEVICE lookup main
[ $ACTION == "ifup" ] && $IP rule add pref $(($iface_id+2000)) fwmark $(($iface_id*256))/0xff00 lookup $iface_id
- $IP rule add pref 2253 fwmark 0xfd00/0xff00 blackhole
- $IP rule add pref 2254 fwmark 0xfe00/0xff00 unreachable
}
mwan3_track()
}
config_list_foreach $INTERFACE track_ip mwan3_list_track_ips
+ if [ -e /var/run/mwan3track-$INTERFACE.pid ] ; then
+ kill $(cat /var/run/mwan3track-$INTERFACE.pid) &> /dev/null
+ rm /var/run/mwan3track-$INTERFACE.pid &> /dev/null
+ fi
+
if [ -n "$track_ips" ]; then
config_get reliability $INTERFACE reliability 1
config_get count $INTERFACE count 1
sleep 1
let counter++
if [ "$counter" -ge 10 ]; then
- $LOG warn "Could not find gateway for interface $INTERFACE (${DEVICE:-unknown})" && return 0
+ $LOG warn "Could not find gateway for interface $INTERFACE ($DEVICE)" && return 0
fi
done
$LOG notice "$ACTION interface $INTERFACE (${DEVICE:-unknown})"
mwan3_set_general_iptables
+ mwan3_set_general_rules
mwan3_set_iface_iptables
mwan3_set_iface_route
mwan3_set_iface_rules
config_foreach mwan3_set_user_rules_iptables rule
}
-local IP IPT LOG
-
+[ -n "$ACTION" ] || exit 0
[ -n "$INTERFACE" ] || exit 0
if [ $ACTION == "ifup" ]; then
[ -n "$DEVICE" ] || exit 0
fi
+local IP IPT LOG
+
IP="/usr/sbin/ip -4"
IPT="/usr/sbin/iptables -t mangle -w"
LOG="/usr/bin/logger -t mwan3 -p"
-#!/bin/sh /etc/rc.common
+#!/bin/sh
+. /lib/functions.sh
-. /lib/network/config.sh
+IP="/usr/sbin/ip -4"
+IPT="/usr/sbin/iptables -t mangle -w"
-extra_help() {
- cat <<EOF
+help()
+{
+ cat <<EOF
+Syntax: mwan3 [command]
+
+Available commands:
+ start Load iptables rules, ip rules and ip routes
+ stop Unload iptables rules, ip rules and ip routes
+ restart Reload iptables rules, ip rules and ip routes
+ ifup <iface> Load rules and routes for specific interface
+ ifdown <iface> Unload rules and routes for specific interface
+ interfaces Show interfaces status
+ policies Show policies status
+ rules Show rules status
+ status Show all status
- ifup <iface> Start service on interface
- ifdown <iface> Stop service on interface
- interfaces Show interfaces status
- policies Show policies status
- rules Show rules status
- status Show all status
EOF
}
-EXTRA_COMMANDS="ifdown ifup interfaces policies rules status"
-EXTRA_HELP="$(extra_help)"
-IP="/usr/sbin/ip -4"
-IPT="/usr/sbin/iptables -t mangle -w"
-
ifdown()
{
if [ -z "$1" ]; then
stop
start
}
+
+action=${1:-help}
+$action