2014-10-02 09:57:50 +02:00
|
|
|
#!/bin/sh
|
2014-08-08 21:09:54 +02:00
|
|
|
|
2015-10-20 10:04:20 +02:00
|
|
|
. /lib/functions.sh
|
2015-11-19 09:37:30 +01:00
|
|
|
. /lib/functions/network.sh
|
|
|
|
. /lib/mwan3/mwan3.sh
|
2014-08-08 21:09:54 +02:00
|
|
|
|
2014-10-02 09:57:50 +02:00
|
|
|
help()
|
2015-03-17 19:57:49 +01:00
|
|
|
{
|
|
|
|
cat <<EOF
|
|
|
|
Syntax: mwan3 [command]
|
|
|
|
|
|
|
|
Available commands:
|
2014-10-02 09:57:50 +02:00
|
|
|
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
|
2016-07-21 12:52:05 +02:00
|
|
|
ifup <iface> Load rules and routes for specific interface
|
|
|
|
ifdown <iface> Unload rules and routes for specific interface
|
|
|
|
interfaces Show interfaces status
|
|
|
|
policies Show currently active policy
|
|
|
|
connected Show directly connected networks
|
|
|
|
rules Show active rules
|
|
|
|
status Show all status
|
2014-08-08 21:09:54 +02:00
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
ifdown()
|
|
|
|
{
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "Error: Expecting interface. Usage: mwan3 ifdown <interface>" && exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$2" ]; then
|
|
|
|
echo "Error: Too many arguments. Usage: mwan3 ifdown <interface>" && exit 0
|
|
|
|
fi
|
|
|
|
|
2015-11-19 09:37:30 +01:00
|
|
|
ACTION=ifdown INTERFACE=$1 /sbin/hotplug-call iface
|
|
|
|
|
2017-07-31 11:46:21 +02:00
|
|
|
kill $(pgrep -f "mwan3track $1 $2") &> /dev/null
|
2017-07-24 10:20:46 +02:00
|
|
|
mwan3_track_clean $1
|
2014-08-08 21:09:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ifup()
|
|
|
|
{
|
2014-08-10 13:18:54 +02:00
|
|
|
local device enabled
|
|
|
|
|
2014-08-08 21:09:54 +02:00
|
|
|
config_load mwan3
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "Expecting interface. Usage: mwan3 ifup <interface>" && exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$2" ]; then
|
|
|
|
echo "Too many arguments. Usage: mwan3 ifup <interface>" && exit 0
|
|
|
|
fi
|
2015-03-17 19:57:49 +01:00
|
|
|
|
2018-02-05 10:15:03 +01:00
|
|
|
config_get_bool enabled globals 'enabled' 0
|
|
|
|
[ ${enabled} -gt 0 ] || {
|
|
|
|
echo "Warning: mwan3 is global disabled. Usage: /etc/init.d/mwan3 start"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2014-08-08 21:09:54 +02:00
|
|
|
config_get enabled "$1" enabled 0
|
|
|
|
|
2015-07-21 15:04:01 +02:00
|
|
|
device=$(uci -p /var/state get network.$1.ifname) &> /dev/null
|
2015-03-17 19:57:49 +01:00
|
|
|
|
2014-08-08 21:09:54 +02:00
|
|
|
if [ -n "$device" ] ; then
|
|
|
|
[ "$enabled" -eq 1 ] && ACTION=ifup INTERFACE=$1 DEVICE=$device /sbin/hotplug-call iface
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
interfaces()
|
|
|
|
{
|
2014-08-10 13:18:54 +02:00
|
|
|
config_load mwan3
|
|
|
|
|
2014-08-08 21:09:54 +02:00
|
|
|
echo "Interface status:"
|
2015-11-19 09:37:30 +01:00
|
|
|
config_foreach mwan3_report_iface_status interface
|
2014-08-08 21:09:54 +02:00
|
|
|
echo -e
|
|
|
|
}
|
|
|
|
|
|
|
|
policies()
|
|
|
|
{
|
2015-11-19 09:37:30 +01:00
|
|
|
echo "Current ipv4 policies:"
|
|
|
|
mwan3_report_policies_v4
|
2015-12-17 11:50:18 +01:00
|
|
|
echo -e
|
2015-11-19 09:37:30 +01:00
|
|
|
echo "Current ipv6 policies:"
|
|
|
|
mwan3_report_policies_v6
|
2015-12-17 11:50:18 +01:00
|
|
|
echo -e
|
2015-11-19 09:37:30 +01:00
|
|
|
}
|
2014-08-08 21:09:54 +02:00
|
|
|
|
2015-11-19 09:37:30 +01:00
|
|
|
connected()
|
|
|
|
{
|
|
|
|
echo "Directly connected ipv4 networks:"
|
|
|
|
mwan3_report_connected_v4
|
|
|
|
echo -e
|
|
|
|
echo "Directly connected ipv6 networks:"
|
|
|
|
mwan3_report_connected_v6
|
|
|
|
echo -e
|
2014-08-08 21:09:54 +02:00
|
|
|
}
|
2015-11-19 09:37:30 +01:00
|
|
|
|
2014-08-08 21:09:54 +02:00
|
|
|
rules()
|
|
|
|
{
|
2015-11-19 09:37:30 +01:00
|
|
|
echo "Active ipv4 user rules:"
|
|
|
|
mwan3_report_rules_v4
|
|
|
|
echo -e
|
|
|
|
echo "Active ipv6 user rules:"
|
|
|
|
mwan3_report_rules_v6
|
|
|
|
echo -e
|
2014-08-08 21:09:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
status()
|
|
|
|
{
|
|
|
|
interfaces
|
|
|
|
policies
|
2015-11-19 09:37:30 +01:00
|
|
|
connected
|
2014-08-08 21:09:54 +02:00
|
|
|
rules
|
|
|
|
}
|
|
|
|
|
|
|
|
start()
|
|
|
|
{
|
2018-02-05 10:15:03 +01:00
|
|
|
local enabled
|
|
|
|
|
2014-08-08 21:09:54 +02:00
|
|
|
config_load mwan3
|
2018-02-05 10:15:03 +01:00
|
|
|
config_get_bool enabled globals 'enabled' 0
|
|
|
|
[ ${enabled} -gt 0 ] || {
|
|
|
|
echo "Warning: mwan3 is global disabled. Usage: /etc/init.d/mwan3 start"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2014-08-08 21:09:54 +02:00
|
|
|
config_foreach ifup interface
|
|
|
|
}
|
|
|
|
|
|
|
|
stop()
|
|
|
|
{
|
2018-01-31 11:58:38 +01:00
|
|
|
local ipset route rule table IP IPT pid
|
2014-08-08 21:09:54 +02:00
|
|
|
|
2018-01-31 11:58:38 +01:00
|
|
|
for pid in $(pgrep -f "mwan3track"); do
|
|
|
|
kill -TERM "$pid" > /dev/null 2>&1
|
|
|
|
sleep 1
|
|
|
|
kill -KILL "$pid" > /dev/null 2>&1
|
|
|
|
done
|
2014-08-08 21:09:54 +02:00
|
|
|
|
2017-07-24 10:20:46 +02:00
|
|
|
config_load mwan3
|
|
|
|
config_foreach mwan3_track_clean interface
|
|
|
|
|
2015-11-19 09:37:30 +01:00
|
|
|
for IP in "$IP4" "$IP6"; do
|
2014-08-08 21:09:54 +02:00
|
|
|
|
2018-03-14 11:57:02 +01:00
|
|
|
for route in $(seq 1 $MWAN3_INTERFACE_MAX); do
|
2015-11-19 09:37:30 +01:00
|
|
|
$IP route flush table $route &> /dev/null
|
|
|
|
done
|
|
|
|
|
|
|
|
for rule in $($IP rule list | egrep '^[1-2][0-9]{3}\:' | cut -d ':' -f 1); do
|
|
|
|
$IP rule del pref $rule &> /dev/null
|
|
|
|
done
|
2014-08-08 21:09:54 +02:00
|
|
|
done
|
|
|
|
|
2015-11-19 09:37:30 +01:00
|
|
|
for IPT in "$IPT4" "$IPT6"; do
|
2014-08-08 21:09:54 +02:00
|
|
|
|
2015-11-19 09:37:30 +01:00
|
|
|
$IPT -D PREROUTING -j mwan3_hook &> /dev/null
|
|
|
|
$IPT -D OUTPUT -j mwan3_hook &> /dev/null
|
2014-08-08 21:09:54 +02:00
|
|
|
|
2015-11-19 09:37:30 +01:00
|
|
|
for table in $($IPT -S | awk '{print $2}' | grep mwan3 | sort -u); do
|
|
|
|
$IPT -F $table &> /dev/null
|
|
|
|
done
|
|
|
|
|
|
|
|
for table in $($IPT -S | awk '{print $2}' | grep mwan3 | sort -u); do
|
|
|
|
$IPT -X $table &> /dev/null
|
|
|
|
done
|
2014-08-08 21:09:54 +02:00
|
|
|
done
|
2015-03-17 19:57:49 +01:00
|
|
|
|
2015-12-17 11:50:18 +01:00
|
|
|
for ipset in $($IPS -n list | grep mwan3_); do
|
|
|
|
$IPS -q destroy $ipset
|
|
|
|
done
|
|
|
|
|
|
|
|
for ipset in $($IPS -n list | grep mwan3 | grep -E '_v4|_v6'); do
|
|
|
|
$IPS -q destroy $ipset
|
2015-03-17 19:57:49 +01:00
|
|
|
done
|
2017-07-24 10:20:46 +02:00
|
|
|
|
|
|
|
mwan3_lock_clean
|
mwan3: fix interface-bound traffic when interface is offline
This commit fixed what 6d99b602 was supposed to fix without affecting
interface-bound traffic.
Before 6d99b602 interface-bound traffic was working normally as long
as at least one interface was online. However when the last interface
went offline, it was impossible to ping and such state was
unrecoverable.
Commit 6d99b602 fixed unrecoverable offline state problem (it was
possible to ping -I iface) but messed inteface-bound traffic. Traffic
with interface source address was not working if the interface was in
"offline" state, even if another interface was online.
The problem was caused by an inconsistent "offline" interface state:
iptables-related rules were kept while routing table and policy were
deleted.
The idea behind this commit is to:
1. Keep all the rules for each interface (iptables, routing table,
policy) regardless of its state. This ensures consistency,
2. Make interface state hotplug events affect only iptables'
mwan3_policy_* rules. Interface-related iptables, routing table
and policy is removed only when mwan3 is manually stopped.
To make such changes possible, it's necessary to change the way
mwan3_policy_* rule generator keeps track of interface state hotplug
events.
Until now, it checked for the existence of custom interface-related
routing table (table id 1, 2, 3, ...). Clearly we can no longer rely
on that so each interface state is stored explicitly in file.
Signed-off-by: Marcin Jurkowski <marcin1j@gmail.com>
2017-09-03 00:56:09 +02:00
|
|
|
rm -rf $MWAN3_STATUS_DIR $MWAN3TRACK_STATUS_DIR
|
2014-08-08 21:09:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
restart() {
|
|
|
|
stop
|
|
|
|
start
|
|
|
|
}
|
2014-10-02 09:57:50 +02:00
|
|
|
|
2014-10-07 11:23:02 +02:00
|
|
|
case "$1" in
|
2015-11-19 09:37:30 +01:00
|
|
|
ifup|ifdown|interfaces|policies|connected|rules|status|start|stop|restart)
|
2018-02-02 14:56:18 +01:00
|
|
|
mwan3_init
|
2014-10-07 11:23:02 +02:00
|
|
|
$*
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
help
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|