Browse Source

Merge pull request #13853 from TDT-AG/pr/20201104-mwan3

mwan3: code cleanup and fixes
lilik-openwrt-22.03
Florian Eckert 4 years ago
committed by GitHub
parent
commit
9e424325b5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 67 additions and 52 deletions
  1. +43
    -3
      net/mwan3/Makefile
  2. +8
    -12
      net/mwan3/files/etc/hotplug.d/iface/15-mwan3
  3. +3
    -4
      net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user
  4. +1
    -8
      net/mwan3/files/etc/init.d/mwan3
  5. +6
    -16
      net/mwan3/files/lib/mwan3/mwan3.sh
  6. +0
    -0
      net/mwan3/files/usr/libexec/rpcd/mwan3
  7. +1
    -1
      net/mwan3/files/usr/sbin/mwan3
  8. +0
    -4
      net/mwan3/files/usr/sbin/mwan3rtmon
  9. +5
    -4
      net/mwan3/files/usr/sbin/mwan3track

+ 43
- 3
net/mwan3/Makefile View File

@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=mwan3
PKG_VERSION:=2.10.1
PKG_VERSION:=2.10.2
PKG_RELEASE:=1
PKG_MAINTAINER:=Florian Eckert <fe@dev.tdt.de>
PKG_LICENSE:=GPL-2.0
@ -63,12 +63,52 @@ exit 0
endef
define Build/Compile
$(TARGET_CC) $(CFLAGS) $(LDFLAGS) $(FPIC) -shared -o $(PKG_BUILD_DIR)/libwrap_mwan3_sockopt.so.1.0 $(if $(CONFIG_IPV6),-DCONFIG_IPV6) $(PKG_BUILD_DIR)/sockopt_wrap.c -ldl
$(TARGET_CC) $(CFLAGS) $(LDFLAGS) $(FPIC) \
-shared \
-o $(PKG_BUILD_DIR)/libwrap_mwan3_sockopt.so.1.0 \
$(if $(CONFIG_IPV6),-DCONFIG_IPV6) \
$(PKG_BUILD_DIR)/sockopt_wrap.c \
-ldl
endef
define Package/mwan3/install
$(CP) ./files/* $(1)
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/etc/config/mwan3 \
$(1)/etc/config/
$(INSTALL_DIR) $(1)/etc/hotplug.d/iface
$(INSTALL_DATA) ./files/etc/hotplug.d/iface/15-mwan3 \
$(1)/etc/hotplug.d/iface/
$(INSTALL_DATA) ./files/etc/hotplug.d/iface/16-mwan3-user \
$(1)/etc/hotplug.d/iface/
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/etc/init.d/mwan3 \
$(1)/etc/init.d/
$(INSTALL_DIR) $(1)/lib/mwan3
$(INSTALL_DATA) ./files/lib/mwan3/common.sh \
$(1)/lib/mwan3/
$(INSTALL_DATA) ./files/lib/mwan3/mwan3.sh \
$(1)/lib/mwan3/
$(INSTALL_DIR) $(1)/usr/libexec/rpcd
$(INSTALL_BIN) ./files/usr/libexec/rpcd/mwan3 \
$(1)/usr/libexec/rpcd/
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) ./files/usr/sbin/mwan3 \
$(1)/usr/sbin/
$(INSTALL_BIN) ./files/usr/sbin/mwan3rtmon \
$(1)/usr/sbin/
$(INSTALL_BIN) ./files/usr/sbin/mwan3track \
$(1)/usr/sbin/
$(CP) $(PKG_BUILD_DIR)/libwrap_mwan3_sockopt.so.1.0 $(1)/lib/mwan3/
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_DATA) ./files/etc/uci-defaults/mwan3-migrate-flush_conntrack \
$(1)/etc/uci-defaults/
endef
$(eval $(call BuildPackage,mwan3))

+ 8
- 12
net/mwan3/files/etc/hotplug.d/iface/15-mwan3 View File

@ -3,9 +3,12 @@
. /lib/functions.sh
. /lib/functions/network.sh
. /lib/mwan3/mwan3.sh
. /usr/share/libubox/jshn.sh
. /lib/mwan3/common.sh
initscript=/etc/init.d/mwan3
. /lib/functions/procd.sh
SCRIPTNAME="mwan3-hotplug"
[ "$ACTION" = "ifup" ] || [ "$ACTION" = "ifdown" ] || [ "$ACTION" = "connected" ] || [ "$ACTION" = "disconnected" ] || exit 1
[ -n "$INTERFACE" ] || exit 2
@ -16,18 +19,17 @@ if { [ "$ACTION" = "ifup" ] || [ "$ACTION" = "connected" ] ; } && [ -z "$DEVICE"
exit 3
fi
[ "$MWAN3_STARTUP" = 1 ] || mwan3_lock "$ACTION" "$INTERFACE"
[ "$MWAN3_STARTUP" = 1 ] || procd_lock
config_load mwan3
/etc/init.d/mwan3 running || {
[ "$MWAN3_STARTUP" = 1 ] || mwan3_unlock "$ACTION" "$INTERFACE"
[ "$MWAN3_STARTUP" = "init" ] || procd_lock
LOG notice "mwan3 hotplug $ACTION on $INTERFACE not called because globally disabled"
mwan3_flush_conntrack "$INTERFACE" "$ACTION"
exit 0
}
$IPT4 -S mwan3_hook &>/dev/null || {
mwan3_unlock "$ACTION" "$INTERFACE"
LOG warn "hotplug called on $INTERFACE before mwan3 has been set up"
exit 0
}
@ -44,7 +46,6 @@ fi
config_get_bool enabled $INTERFACE 'enabled' '0'
[ "${enabled}" -eq 1 ] || {
[ "$MWAN3_STARTUP" = 1 ] || mwan3_unlock "$ACTION" "$INTERFACE"
LOG notice "mwan3 hotplug on $INTERFACE not called because interface disabled"
exit 0
}
@ -57,11 +58,6 @@ else
status=online
fi
if [ "$ACTION" = ifup ] || [ "$ACTION" = ifdown ]; then
initscript=/etc/init.d/mwan3
. /lib/functions/procd.sh
fi
LOG notice "Execute $ACTION event on interface $INTERFACE (${DEVICE:-unknown})"
case "$ACTION" in
@ -73,8 +69,9 @@ case "$ACTION" in
mwan3_create_iface_iptables $INTERFACE $DEVICE
mwan3_create_iface_rules $INTERFACE $DEVICE
mwan3_set_iface_hotplug_state $INTERFACE "$status"
if [ "$MWAN3_STARTUP" != 1 ]; then
if [ "$MWAN3_STARTUP" = "cmd" ]; then
mwan3_create_iface_route $INTERFACE $DEVICE
mwan3_set_general_rules
[ "$status" = "online" ] && mwan3_set_policies_iptables
fi
[ "$ACTION" = ifup ] && procd_running mwan3 "track_$INTERFACE" && procd_send_signal mwan3 "track_$INTERFACE" USR2
@ -93,5 +90,4 @@ case "$ACTION" in
mwan3_set_policies_iptables
;;
esac
[ "$MWAN3_STARTUP" = 1 ] || mwan3_unlock "$ACTION" "$INTERFACE"
exit 0

+ 3
- 4
net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user View File

@ -3,11 +3,12 @@
[ -f "/etc/mwan3.user" ] && {
. /lib/functions.sh
. /lib/mwan3/mwan3.sh
initscript=/etc/init.d/mwan3
. /lib/functions/procd.sh
[ "$MWAN3_SHUTDOWN" != 1 ] && mwan3_lock "$ACTION" "$DEVICE-user"
[ "$MWAN3_SHUTDOWN" != 1 ] && procd_lock
[ "$MWAN3_SHUTDOWN" != 1 ] && ! /etc/init.d/mwan3 running && {
mwan3_unlock "$ACTION" "$DEVICE-user"
exit 0
}
@ -19,8 +20,6 @@
exit 0
}
[ "$MWAN3_SHUTDOWN" != 1 ] && mwan3_unlock "$ACTION" "$DEVICE-user"
env -i ACTION="$ACTION" INTERFACE="$INTERFACE" DEVICE="$DEVICE" \
/bin/sh /etc/mwan3.user
}


+ 1
- 8
net/mwan3/files/etc/init.d/mwan3 View File

@ -31,20 +31,16 @@ start_service() {
mwan3_init
config_foreach start_tracker interface
mwan3_lock "command" "mwan3"
mwan3_update_iface_to_table
mwan3_set_connected_ipset
mwan3_set_custom_ipset
mwan3_set_general_rules
mwan3_set_general_iptables
config_foreach mwan3_ifup interface 1
config_foreach mwan3_ifup interface "init"
wait $hotplug_pids
mwan3_set_policies_iptables
mwan3_set_user_rules
mwan3_unlock "command" "mwan3"
procd_open_instance rtmon_ipv4
procd_set_param command /usr/sbin/mwan3rtmon ipv4
procd_set_param respawn
@ -61,8 +57,6 @@ start_service() {
stop_service() {
local ipset rule IP IPTR IPT family table tid
mwan3_lock "command" "mwan3"
config_load mwan3
mwan3_init
config_foreach mwan3_interface_shutdown interface
@ -108,7 +102,6 @@ stop_service() {
rm -rf $MWAN3_STATUS_DIR $MWAN3TRACK_STATUS_DIR
mwan3_unlock "command" "mwan3"
}
reload_service() {


+ 6
- 16
net/mwan3/files/lib/mwan3/mwan3.sh View File

@ -103,16 +103,6 @@ mwan3_count_one_bits()
echo $count
}
mwan3_lock() {
lock /var/run/mwan3.lock
#LOG debug "$1 $2 (lock)"
}
mwan3_unlock() {
#LOG debug "$1 $2 (unlock)"
lock -u /var/run/mwan3.lock
}
mwan3_get_iface_id()
{
local _tmp
@ -965,12 +955,12 @@ mwan3_interface_shutdown()
mwan3_ifup()
{
local up l3_device status interface true_iface mwan3_startup
local interface=$1
local caller=$2
interface=$1
mwan3_startup=$2
local up l3_device status true_iface
if [ "${mwan3_startup}" != 1 ]; then
if [ "${caller}" = "cmd" ]; then
# It is not necessary to obtain a lock here, because it is obtained in the hotplug
# script, but we still want to do the check to print a useful error message
/etc/init.d/mwan3 running || {
@ -989,7 +979,7 @@ mwan3_ifup()
}
hotplug_startup()
{
env -i MWAN3_STARTUP=$mwan3_startup ACTION=ifup \
env -i MWAN3_STARTUP=$caller ACTION=ifup \
INTERFACE=$interface DEVICE=$l3_device \
sh /etc/hotplug.d/iface/15-mwan3
}
@ -998,7 +988,7 @@ mwan3_ifup()
return
fi
if [ "${mwan3_startup}" = 1 ]; then
if [ "${caller}" = "init" ]; then
hotplug_startup &
hotplug_pids="$hotplug_pids $!"
else


+ 0
- 0
net/mwan3/files/usr/libexec/rpcd/mwan3 View File


+ 1
- 1
net/mwan3/files/usr/sbin/mwan3 View File

@ -54,7 +54,7 @@ ifup() {
exit 0
fi
mwan3_ifup "$1"
mwan3_ifup "$1" "cmd"
}
interfaces()


+ 0
- 4
net/mwan3/files/usr/sbin/mwan3rtmon View File

@ -159,16 +159,13 @@ main()
IP="$IP4"
fi
mwan3_init
mwan3_lock "mwan3rtmon" "start"
sh -c "echo \$\$; exec $IP monitor route" | {
read -r monitor_pid
trap_with_arg func_trap "$monitor_pid" SIGINT SIGTERM SIGKILL
while IFS='' read -r line; do
[ -z "${line##*table*}" ] && continue
LOG debug "handling route update $family '$line'"
mwan3_lock "service" "mwan3rtmon"
mwan3_rtmon_route_handle "$line" "$family"
mwan3_unlock "service" "mwan3rtmon"
done
} &
child=$!
@ -176,7 +173,6 @@ main()
trap_with_arg func_trap "$child" SIGINT SIGTERM SIGKILL
mwan3_set_connected_${family}
mwan3_add_all_routes ${family}
mwan3_unlock "mwan3rtmon" "start"
kill -SIGCONT $child
wait $!
}


+ 5
- 4
net/mwan3/files/usr/sbin/mwan3track View File

@ -9,9 +9,6 @@ DEVICE=""
IFDOWN_EVENT=0
IFUP_EVENT=0
TRACK_OUTPUT=$MWAN3TRACK_STATUS_DIR/$INTERFACE/TRACK_OUTPUT
mwan3_init
stop_subprocs() {
[ -n "$SLEEP_PID" ] && kill "$SLEEP_PID" && unset SLEEP_PID
@ -169,6 +166,10 @@ main() {
INTERFACE=$1
STATUS=""
STARTED=0
TRACK_OUTPUT=$MWAN3TRACK_STATUS_DIR/$INTERFACE/TRACK_OUTPUT
mwan3_init
mkdir -p $MWAN3TRACK_STATUS_DIR/$INTERFACE
trap clean_up TERM
@ -345,7 +346,7 @@ main() {
get_uptime > $MWAN3TRACK_STATUS_DIR/$INTERFACE/TIME
host_up_count=0
if [ "${IFDOWN_EVENT}" -ne 0 ] && [ "${IFUP_EVENT}" -ne 0 ]; then
if [ "${IFDOWN_EVENT}" -eq 0 ] && [ "${IFUP_EVENT}" -eq 0 ]; then
sleep "${sleep_time}" &
SLEEP_PID=$!
wait


Loading…
Cancel
Save