|
@ -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 |
|
|