update 2024-06-04 00:21:57

This commit is contained in:
kenzok8 2024-06-04 00:21:57 +08:00
parent f7ac405956
commit 9c2ebf34a5
8 changed files with 451 additions and 410 deletions

View File

@ -8,8 +8,8 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=mwan3 PKG_NAME:=mwan3
PKG_VERSION:=2.8.8 PKG_VERSION:=2.8.12
PKG_RELEASE:=2 PKG_RELEASE:=1
PKG_MAINTAINER:=Florian Eckert <fe@dev.tdt.de> PKG_MAINTAINER:=Florian Eckert <fe@dev.tdt.de>
PKG_LICENSE:=GPL-2.0 PKG_LICENSE:=GPL-2.0

View File

@ -18,6 +18,12 @@ config rule 'https'
option proto 'tcp' option proto 'tcp'
option use_policy 'balanced' option use_policy 'balanced'
config rule 'default_rule' config rule 'default_rule_v4'
option dest_ip '0.0.0.0/0' option dest_ip '0.0.0.0/0'
option use_policy 'balanced' option use_policy 'balanced'
option family 'ipv4'
config rule 'default_rule_v6'
option dest_ip '::/0'
option use_policy 'balanced'
option family 'ipv6'

View File

@ -9,24 +9,29 @@
[ -n "$INTERFACE" ] || exit 2 [ -n "$INTERFACE" ] || exit 2
if [ "$ACTION" == "ifup" ]; then if [ "$ACTION" == "ifup" ]; then
[ -n "$DEVICE" ] || exit 3 [ -n "$DEVICE" ] || exit 3
fi fi
mwan3_lock "$ACTION" "$INTERFACE"
config_load mwan3 config_load mwan3
config_get_bool enabled globals 'enabled' '0' config_get_bool enabled globals 'enabled' '0'
[ ${enabled} -gt 0 ] || exit 0 [ "${enabled}" -gt 0 ] || {
mwan3_unlock "$ACTION" "$INTERFACE"
exit 0
}
mwan3_lock "$ACTION" "$INTERFACE"
mwan3_init mwan3_init
mwan3_set_connected_iptables mwan3_set_connected_iptables
mwan3_set_custom_ipset mwan3_set_custom_ipset
mwan3_unlock "$ACTION" "$INTERFACE"
config_get enabled $INTERFACE enabled 0
config_get initial_state $INTERFACE initial_state "online" config_get initial_state $INTERFACE initial_state "online"
[ "$enabled" == "1" ] || exit 0 config_get_bool enabled $INTERFACE 'enabled' '0'
[ "${enabled}" -eq 1 ] || {
mwan3_unlock "$ACTION" "$INTERFACE"
exit 0
}
if [ "$ACTION" == "ifup" ]; then if [ "$ACTION" = "ifup" ]; then
config_get family $INTERFACE family ipv4 config_get family $INTERFACE family ipv4
if [ "$family" = "ipv4" ]; then if [ "$family" = "ipv4" ]; then
ubus call network.interface.${INTERFACE}_4 status &>/dev/null ubus call network.interface.${INTERFACE}_4 status &>/dev/null
@ -58,7 +63,6 @@ else
running=1 running=1
fi fi
mwan3_lock "$ACTION" "$INTERFACE"
$LOG notice "Execute "$ACTION" event on interface $INTERFACE (${DEVICE:-unknown})" $LOG notice "Execute "$ACTION" event on interface $INTERFACE (${DEVICE:-unknown})"
case "$ACTION" in case "$ACTION" in
@ -68,7 +72,7 @@ case "$ACTION" in
mwan3_create_iface_iptables $INTERFACE $DEVICE mwan3_create_iface_iptables $INTERFACE $DEVICE
mwan3_create_iface_rules $INTERFACE $DEVICE mwan3_create_iface_rules $INTERFACE $DEVICE
mwan3_create_iface_route $INTERFACE $DEVICE mwan3_create_iface_route $INTERFACE $DEVICE
if [ ${running} -eq 1 -a "${status}" = "online" ]; then if [ "${running}" -eq 1 ] && [ "${status}" = "online" ]; then
$LOG notice "Starting tracker on interface $INTERFACE (${DEVICE:-unknown})" $LOG notice "Starting tracker on interface $INTERFACE (${DEVICE:-unknown})"
mwan3_set_iface_hotplug_state $INTERFACE "online" mwan3_set_iface_hotplug_state $INTERFACE "online"
mwan3_track $INTERFACE $DEVICE "online" "$src_ip" mwan3_track $INTERFACE $DEVICE "online" "$src_ip"

View File

@ -4,19 +4,24 @@
. /lib/functions/network.sh . /lib/functions/network.sh
. /lib/mwan3/mwan3.sh . /lib/mwan3/mwan3.sh
mwan3_lock "$ACTION" "mwan3rtmon"
config_load mwan3 config_load mwan3
config_get_bool enabled globals 'enabled' '0' config_get_bool enabled globals 'enabled' '0'
[ ${enabled} -gt 0 ] || exit 0 [ "${enabled}" -gt 0 ] || {
if [ "$ACTION" == "ifup" ]; then
mwan3_lock "$ACTION" "mwan3rtmon"
mwan3_rtmon
mwan3_unlock "$ACTION" "mwan3rtmon" mwan3_unlock "$ACTION" "mwan3rtmon"
exit 0
}
if [ "$ACTION" = "ifup" ]; then
mwan3_rtmon
fi fi
config_get enabled $INTERFACE enabled 0 config_get_bool enabled "$INTERFACE" 'enabled' '0'
[ "${enabled}" = "0" ] || { [ "${enabled}" -eq 0 ] || {
mwan3_flush_conntrack "$INTERFACE" "$ACTION" mwan3_flush_conntrack "$INTERFACE" "$ACTION"
} }
mwan3_unlock "$ACTION" "mwan3rtmon"
exit 0 exit 0

View File

@ -2,13 +2,25 @@
[ -f "/etc/mwan3.user" ] && { [ -f "/etc/mwan3.user" ] && {
. /lib/functions.sh . /lib/functions.sh
. /lib/mwan3/mwan3.sh
mwan3_lock "$ACTION" "user"
config_load mwan3 config_load mwan3
config_get_bool enabled globals 'enabled' '0' config_get_bool enabled globals 'enabled' '0'
[ ${enabled} -gt 0 ] || exit 0 [ "${enabled}" -gt 0 ] || {
mwan3_unlock "$ACTION" "user"
exit 0
}
config_get_bool enabled "$INTERFACE" enabled 0
[ "${enabled}" -eq 1 ] || {
mwan3_unlock "$ACTION" "user"
exit 0
}
mwan3_unlock "$ACTION" "user"
config_get enabled "$INTERFACE" enabled 0
[ "${enabled}" = "1" ] || exit 0
env -i ACTION="$ACTION" INTERFACE="$INTERFACE" DEVICE="$DEVICE" \ env -i ACTION="$ACTION" INTERFACE="$INTERFACE" DEVICE="$DEVICE" \
/bin/sh /etc/mwan3.user /bin/sh /etc/mwan3.user
} }

View File

@ -10,17 +10,22 @@ boot() {
rc_procd start_service rc_procd start_service
} }
# FIXME
# fd 1000 is an inherited lock file descriptor for preventing concurrent
# init script executions. Close it here to prevent the mwan3 daemon from
# inheriting it further to avoid holding the lock indefinitely.
reload_service() { reload_service() {
/usr/sbin/mwan3 restart /usr/sbin/mwan3 restart 1000>&-
} }
start_service() { start_service() {
[ -n "${mwan3_boot}" ] && return 0 [ -n "${mwan3_boot}" ] && return 0
/usr/sbin/mwan3 start /usr/sbin/mwan3 start 1000>&-
} }
stop_service() { stop_service() {
/usr/sbin/mwan3 stop /usr/sbin/mwan3 stop 1000>&-
} }
service_triggers() { service_triggers() {

File diff suppressed because it is too large Load Diff

View File

@ -45,30 +45,39 @@ ifup()
{ {
local device enabled up l3_device status local device enabled up l3_device status
mwan3_lock "command" "mwan3"
config_load mwan3 config_load mwan3
config_get_bool enabled globals 'enabled' 0 config_get_bool enabled globals 'enabled' 0
[ ${enabled} -gt 0 ] || { [ ${enabled} -gt 0 ] || {
echo "The service mwan3 is global disabled." echo "The service mwan3 is global disabled."
echo "Please execute \"/etc/init.d/mwan3 start\" first." echo "Please execute \"/etc/init.d/mwan3 start\" first."
mwan3_unlock "command" "mwan3"
exit 1 exit 1
} }
if [ -z "$1" ]; then if [ -z "$1" ]; then
echo "Expecting interface. Usage: mwan3 ifup <interface>" && exit 0 echo "Expecting interface. Usage: mwan3 ifup <interface>"
mwan3_unlock "command" "mwan3"
exit 0
fi fi
if [ -n "$2" ]; then if [ -n "$2" ]; then
echo "Too many arguments. Usage: mwan3 ifup <interface>" && exit 0 echo "Too many arguments. Usage: mwan3 ifup <interface>"
mwan3_unlock "command" "mwan3"
exit 0
fi fi
config_get enabled "$1" enabled 0
mwan3_unlock "command" "mwan3"
status=$(ubus -S call network.interface.$1 status) status=$(ubus -S call network.interface.$1 status)
[ -n "$status" ] && { [ -n "$status" ] && {
json_load "$status" json_load "$status"
json_get_vars up l3_device json_get_vars up l3_device
} }
config_get enabled "$1" enabled 0
if [ "$up" = "1" ] \ if [ "$up" = "1" ] \
&& [ -n "$l3_device" ] \ && [ -n "$l3_device" ] \
&& [ "$enabled" = "1" ]; then && [ "$enabled" = "1" ]; then
@ -90,6 +99,7 @@ policies()
echo "Current ipv4 policies:" echo "Current ipv4 policies:"
mwan3_report_policies_v4 mwan3_report_policies_v4
echo -e echo -e
[ $NO_IPV6 -ne 0 ] && return
echo "Current ipv6 policies:" echo "Current ipv6 policies:"
mwan3_report_policies_v6 mwan3_report_policies_v6
echo -e echo -e
@ -100,6 +110,7 @@ connected()
echo "Directly connected ipv4 networks:" echo "Directly connected ipv4 networks:"
mwan3_report_connected_v4 mwan3_report_connected_v4
echo -e echo -e
[ $NO_IPV6 -ne 0 ] && return
echo "Directly connected ipv6 networks:" echo "Directly connected ipv6 networks:"
mwan3_report_connected_v6 mwan3_report_connected_v6
echo -e echo -e
@ -110,6 +121,7 @@ rules()
echo "Active ipv4 user rules:" echo "Active ipv4 user rules:"
mwan3_report_rules_v4 mwan3_report_rules_v4
echo -e echo -e
[ $NO_IPV6 -ne 0 ] && return
echo "Active ipv6 user rules:" echo "Active ipv6 user rules:"
mwan3_report_rules_v6 mwan3_report_rules_v6
echo -e echo -e
@ -127,7 +139,9 @@ start()
{ {
local enabled local enabled
mwan3_lock "command" "mwan3"
uci_toggle_state mwan3 globals enabled "1" uci_toggle_state mwan3 globals enabled "1"
mwan3_unlock "command" "mwan3"
config_load mwan3 config_load mwan3
config_foreach ifup interface config_foreach ifup interface
@ -138,16 +152,23 @@ stop()
local ipset route rule table IP IPT pid local ipset route rule table IP IPT pid
mwan3_lock "command" "mwan3" mwan3_lock "command" "mwan3"
uci_toggle_state mwan3 globals enabled "0"
for pid in $(pgrep -f "mwan3rtmon"); do for pid in $(pgrep -f "mwan3rtmon"); do
kill -TERM "$pid" > /dev/null 2>&1 kill -TERM "$pid" > /dev/null 2>&1
sleep 1
kill -KILL "$pid" > /dev/null 2>&1
done done
for pid in $(pgrep -f "mwan3track"); do for pid in $(pgrep -f "mwan3track"); do
kill -TERM "$pid" > /dev/null 2>&1 kill -TERM "$pid" > /dev/null 2>&1
sleep 1 done
sleep 1
for pid in $(pgrep -f "mwan3rtmon"); do
kill -KILL "$pid" > /dev/null 2>&1
done
for pid in $(pgrep -f "mwan3track"); do
kill -KILL "$pid" > /dev/null 2>&1 kill -KILL "$pid" > /dev/null 2>&1
done done
@ -155,7 +176,7 @@ stop()
config_foreach mwan3_track_clean interface config_foreach mwan3_track_clean interface
for IP in "$IP4" "$IP6"; do for IP in "$IP4" "$IP6"; do
[ "$IP" = "$IP6" ] && [ $NO_IPV6 -ne 0 ] && continue
for route in $(seq 1 $MWAN3_INTERFACE_MAX); do for route in $(seq 1 $MWAN3_INTERFACE_MAX); do
$IP route flush table $route &> /dev/null $IP route flush table $route &> /dev/null
done done
@ -166,7 +187,7 @@ stop()
done done
for IPT in "$IPT4" "$IPT6"; do for IPT in "$IPT4" "$IPT6"; do
[ "$IPT" = "$IPT6" ] && [ $NO_IPV6 -ne 0 ] && continue
$IPT -D PREROUTING -j mwan3_hook &> /dev/null $IPT -D PREROUTING -j mwan3_hook &> /dev/null
$IPT -D OUTPUT -j mwan3_hook &> /dev/null $IPT -D OUTPUT -j mwan3_hook &> /dev/null
@ -189,10 +210,7 @@ stop()
mwan3_unlock "command" "mwan3" mwan3_unlock "command" "mwan3"
mwan3_lock_clean
rm -rf $MWAN3_STATUS_DIR $MWAN3TRACK_STATUS_DIR rm -rf $MWAN3_STATUS_DIR $MWAN3TRACK_STATUS_DIR
uci_toggle_state mwan3 globals enabled "0"
} }
restart() { restart() {