Browse Source

Merge pull request #5491 from TDT-AG/pr/20180123-mwan3-add-service

mwan3: add init script to enable/disable mwan3
lilik-openwrt-22.03
Hannu Nyman 7 years ago
committed by GitHub
parent
commit
fed12673b2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 110 additions and 30 deletions
  1. +1
    -1
      net/mwan3/Makefile
  2. +3
    -0
      net/mwan3/files/etc/hotplug.d/iface/14-mwan3
  3. +8
    -4
      net/mwan3/files/etc/hotplug.d/iface/15-mwan3
  4. +3
    -0
      net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user
  5. +32
    -0
      net/mwan3/files/etc/init.d/mwan3
  6. +40
    -21
      net/mwan3/files/lib/mwan3/mwan3.sh
  7. +21
    -2
      net/mwan3/files/usr/sbin/mwan3
  8. +2
    -2
      net/mwan3/files/usr/sbin/mwan3track

+ 1
- 1
net/mwan3/Makefile View File

@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=mwan3 PKG_NAME:=mwan3
PKG_VERSION:=2.6.9
PKG_VERSION:=2.6.10
PKG_RELEASE:=1 PKG_RELEASE:=1
PKG_MAINTAINER:=Florian Eckert <fe@dev.tdt.de> PKG_MAINTAINER:=Florian Eckert <fe@dev.tdt.de>
PKG_LICENSE:=GPLv2 PKG_LICENSE:=GPLv2


+ 3
- 0
net/mwan3/files/etc/hotplug.d/iface/14-mwan3 View File

@ -12,6 +12,9 @@ if [ "$ACTION" = "ifup" ]; then
fi fi
config_load mwan3 config_load mwan3
config_get_bool enabled globals 'enabled' '0'
[ ${enabled} -gt 0 ] || exit 0
config_get local_source globals local_source 'none' config_get local_source globals local_source 'none'
[ "${local_source}" = "none" ] && { [ "${local_source}" = "none" ] && {
exit 0 exit 0


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

@ -12,15 +12,19 @@ if [ "$ACTION" == "ifup" ]; then
[ -n "$DEVICE" ] || exit 3 [ -n "$DEVICE" ] || exit 3
fi fi
mwan3_lock
mwan3_set_connected_iptables
mwan3_unlock
config_load mwan3 config_load mwan3
config_get_bool enabled globals 'enabled' '0'
[ ${enabled} -gt 0 ] || exit 0
config_get enabled $INTERFACE enabled 0 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 [ "$enabled" == "1" ] || exit 0
mwan3_lock
mwan3_init
mwan3_set_connected_iptables
mwan3_unlock
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


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

@ -4,6 +4,9 @@
. /lib/functions.sh . /lib/functions.sh
config_load mwan3 config_load mwan3
config_get_bool enabled globals 'enabled' '0'
[ ${enabled} -gt 0 ] || exit 0
config_get enabled "$INTERFACE" enabled 0 config_get enabled "$INTERFACE" enabled 0
[ "${enabled}" = "1" ] || exit 0 [ "${enabled}" = "1" ] || exit 0
env -i ACTION="$ACTION" INTERFACE="$INTERFACE" DEVICE="$DEVICE" \ env -i ACTION="$ACTION" INTERFACE="$INTERFACE" DEVICE="$DEVICE" \


+ 32
- 0
net/mwan3/files/etc/init.d/mwan3 View File

@ -0,0 +1,32 @@
#!/bin/sh /etc/rc.common
START=19
reload() {
local enabled
config_load mwan3
config_get_bool enabled globals 'enabled' 0
[ ${enabled} -gt 0 ] || {
echo "Warning: mwan3 is global disabled. Usage: /etc/init.d/mwan3 start"
exit 0
}
mwan3 restart
}
boot() {
. /lib/config/uci.sh
uci_toggle_state mwan3 globals enabled "1"
}
start() {
. /lib/config/uci.sh
uci_toggle_state mwan3 globals enabled "1"
mwan3 start
}
stop() {
. /lib/config/uci.sh
uci_toggle_state mwan3 globals enabled "0"
mwan3 stop
}

+ 40
- 21
net/mwan3/files/lib/mwan3/mwan3.sh View File

@ -11,17 +11,14 @@ CONNTRACK_FILE="/proc/net/nf_conntrack"
MWAN3_STATUS_DIR="/var/run/mwan3" MWAN3_STATUS_DIR="/var/run/mwan3"
MWAN3TRACK_STATUS_DIR="/var/run/mwan3track" MWAN3TRACK_STATUS_DIR="/var/run/mwan3track"
DEFAULT_LOWEST_METRIC=256 DEFAULT_LOWEST_METRIC=256
MMX_MASK=""
MMX_DEFAULT=""
MMX_BLACKHOLE=""
MM_BLACKHOLE=""
MMX_UNREACHABLE=""
MM_UNREACHABLE=""
[ -d $MWAN3_STATUS_DIR ] || mkdir -p $MWAN3_STATUS_DIR/iface_state
# mwan3's MARKing mask (at least 3 bits should be set)
if [ -e "${MWAN3_STATUS_DIR}/mmx_mask" ]; then
MMX_MASK=$(cat "${MWAN3_STATUS_DIR}/mmx_mask")
else
config_load mwan3
config_get MMX_MASK globals mmx_mask '0xff00'
echo "$MMX_MASK" > "${MWAN3_STATUS_DIR}/mmx_mask"
$LOG notice "Using firewall mask ${MMX_MASK}"
fi
# counts how many bits are set to 1 # counts how many bits are set to 1
# n&(n-1) clears the lowest bit set to 1 # n&(n-1) clears the lowest bit set to 1
@ -58,16 +55,34 @@ mwan3_id2mask()
printf "0x%x" $result printf "0x%x" $result
} }
# mark mask constants
MM_BIT_CNT=$(mwan3_count_one_bits MMX_MASK)
MM_DEFAULT=$(((1<<MM_BIT_CNT)-1))
MM_BLACKHOLE=$(($MM_DEFAULT-2))
MM_UNREACHABLE=$(($MM_DEFAULT-1))
mwan3_init()
{
local bitcnt
local mmdefault mmblackhole mmunreachable
[ -d $MWAN3_STATUS_DIR ] || mkdir -p $MWAN3_STATUS_DIR/iface_state
# MMX_DEFAULT should equal MMX_MASK
MMX_DEFAULT=$(mwan3_id2mask MM_DEFAULT MMX_MASK)
MMX_BLACKHOLE=$(mwan3_id2mask MM_BLACKHOLE MMX_MASK)
MMX_UNREACHABLE=$(mwan3_id2mask MM_UNREACHABLE MMX_MASK)
# mwan3's MARKing mask (at least 3 bits should be set)
if [ -e "${MWAN3_STATUS_DIR}/mmx_mask" ]; then
MMX_MASK=$(cat "${MWAN3_STATUS_DIR}/mmx_mask")
else
config_load mwan3
config_get MMX_MASK globals mmx_mask '0xff00'
echo "$MMX_MASK" > "${MWAN3_STATUS_DIR}/mmx_mask"
$LOG notice "Using firewall mask ${MMX_MASK}"
fi
# mark mask constants
bitcnt=$(mwan3_count_one_bits MMX_MASK)
mmdefault=$(((1<<bitcnt)-1))
MM_BLACKHOLE=$(($mmdefault-2))
MM_UNREACHABLE=$(($mmdefault-1))
# MMX_DEFAULT should equal MMX_MASK
MMX_DEFAULT=$(mwan3_id2mask mmdefault MMX_MASK)
MMX_BLACKHOLE=$(mwan3_id2mask MM_BLACKHOLE MMX_MASK)
MMX_UNREACHABLE=$(mwan3_id2mask MM_UNREACHABLE MMX_MASK)
}
mwan3_lock() { mwan3_lock() {
lock /var/run/mwan3.lock lock /var/run/mwan3.lock
@ -446,7 +461,7 @@ mwan3_delete_iface_ipset_entries()
mwan3_track() mwan3_track()
{ {
local track_ip track_ips
local track_ip track_ips pid
mwan3_list_track_ips() mwan3_list_track_ips()
{ {
@ -454,7 +469,11 @@ mwan3_track()
} }
config_list_foreach $1 track_ip mwan3_list_track_ips config_list_foreach $1 track_ip mwan3_list_track_ips
kill $(pgrep -f "mwan3track $1 $2") &> /dev/null
for pid in $(pgrep -f "mwan3track $1 $2"); do
kill -TERM "$pid" > /dev/null 2>&1
sleep 1
kill -KILL "$pid" > /dev/null 2>&1
done
if [ -n "$track_ips" ]; then if [ -n "$track_ips" ]; then
[ -x /usr/sbin/mwan3track ] && /usr/sbin/mwan3track "$1" "$2" "$3" "$4" $track_ips & [ -x /usr/sbin/mwan3track ] && /usr/sbin/mwan3track "$1" "$2" "$3" "$4" $track_ips &
fi fi


+ 21
- 2
net/mwan3/files/usr/sbin/mwan3 View File

@ -54,6 +54,12 @@ ifup()
echo "Too many arguments. Usage: mwan3 ifup <interface>" && exit 0 echo "Too many arguments. Usage: mwan3 ifup <interface>" && exit 0
fi fi
config_get_bool enabled globals 'enabled' 0
[ ${enabled} -gt 0 ] || {
echo "Warning: mwan3 is global disabled. Usage: /etc/init.d/mwan3 start"
exit 0
}
config_get enabled "$1" enabled 0 config_get enabled "$1" enabled 0
device=$(uci -p /var/state get network.$1.ifname) &> /dev/null device=$(uci -p /var/state get network.$1.ifname) &> /dev/null
@ -112,15 +118,27 @@ status()
start() start()
{ {
local enabled
config_load mwan3 config_load mwan3
config_get_bool enabled globals 'enabled' 0
[ ${enabled} -gt 0 ] || {
echo "Warning: mwan3 is global disabled. Usage: /etc/init.d/mwan3 start"
exit 0
}
config_foreach ifup interface config_foreach ifup interface
} }
stop() stop()
{ {
local ipset route rule table IP IPT
local ipset route rule table IP IPT pid
killall mwan3track &> /dev/null
for pid in $(pgrep -f "mwan3track"); do
kill -TERM "$pid" > /dev/null 2>&1
sleep 1
kill -KILL "$pid" > /dev/null 2>&1
done
config_load mwan3 config_load mwan3
config_foreach mwan3_track_clean interface config_foreach mwan3_track_clean interface
@ -169,6 +187,7 @@ restart() {
case "$1" in case "$1" in
ifup|ifdown|interfaces|policies|connected|rules|status|start|stop|restart) ifup|ifdown|interfaces|policies|connected|rules|status|start|stop|restart)
mwan3_init
$* $*
;; ;;
*) *)


+ 2
- 2
net/mwan3/files/usr/sbin/mwan3track View File

@ -62,8 +62,8 @@ main() {
STATUS=$3 STATUS=$3
SRC_IP=$4 SRC_IP=$4
mkdir -p /var/run/mwan3track/$1 mkdir -p /var/run/mwan3track/$1
trap clean_up SIGINT SIGTERM
trap if_down SIGUSR1
trap clean_up TERM
trap if_down USR1
config_load mwan3 config_load mwan3
config_get track_method $1 track_method ping config_get track_method $1 track_method ping


Loading…
Cancel
Save