diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index 2e7d2ec99..b3ea84d90 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 -PKG_VERSION:=2.7.5 +PKG_VERSION:=2.7.6 PKG_RELEASE:=1 PKG_MAINTAINER:=Florian Eckert PKG_LICENSE:=GPLv2 diff --git a/net/mwan3/files/etc/config/mwan3 b/net/mwan3/files/etc/config/mwan3 index 966601eee..3f64b99d4 100644 --- a/net/mwan3/files/etc/config/mwan3 +++ b/net/mwan3/files/etc/config/mwan3 @@ -1,7 +1,6 @@ config globals 'globals' option mmx_mask '0x3F00' - option local_source 'none' option rtmon_interval '5' config interface 'wan' diff --git a/net/mwan3/files/etc/hotplug.d/iface/13-mwan3 b/net/mwan3/files/etc/hotplug.d/iface/13-mwan3 deleted file mode 100644 index c21e1db98..000000000 --- a/net/mwan3/files/etc/hotplug.d/iface/13-mwan3 +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/sh - -. /lib/functions.sh -. /lib/functions/network.sh -. /lib/mwan3/mwan3.sh - -LOG="logger -t mwan3[$$] -p" - -[ "$ACTION" = "connected" -o "$ACTION" = "disconnected" ] || exit 1 -[ -n "$INTERFACE" ] || exit 2 - -if [ "$ACTION" = "connected" ]; then - [ -n "$DEVICE" ] || exit 3 -fi - -config_load mwan3 -config_get_bool enabled globals 'enabled' '0' -config_get local_source globals 'local_source' 'none' -[ ${enabled} = "1" ] || exit 0 -[ ${local_source} = "none" ] || exit 0 - -config_get enabled $INTERFACE enabled 0 -config_get online_metric $INTERFACE online_metric 0 -[ "$enabled" == "1" ] || exit 0 - -if [ "$online_metric" = 0 ]; then - $LOG notice "No online metric for interface "$INTERFACE" found" - exit 0 -fi - -mwan3_add_failover_metric() { - local iface="$1" - local device="$2" - local metric="$3" - - local route_args - - config_get family $iface family ipv4 - - if [ "$family" == "ipv4" ]; then - if ubus call network.interface.${iface}_4 status 1>/dev/null 2>&1; then - network_get_gateway route_args ${iface}_4 - else - network_get_gateway route_args $iface - fi - - if [ -n "$route_args" -a "$route_args" != "0.0.0.0" ]; then - route_args="via $route_args" - else - route_args="" - fi - - $IP4 route add default $route_args dev $device proto static metric $metric 1>/dev/null 2>&1 - fi - - if [ "$family" == "ipv6" ]; then - if ubus call network.interface.${iface}_6 status 1>/dev/null 2>&1; then - network_get_gateway6 route_args ${iface}_6 - else - network_get_gateway6 route_args $iface - fi - - if [ -n "$route_args" -a "$route_args" != "::" ]; then - route_args="via $route_args" - else - route_args="" - fi - - $IP6 route add default $route_args dev $device proto static metric $metric 1>/dev/null 2>&1 - fi -} - -mwan3_del_failover_metric() { - local iface="$1" - local device="$2" - local metric="$3" - - config_get family $iface family ipv4 - - if [ "$family" == "ipv4" ]; then - $IP4 route del default dev $device proto static metric $metric 1>/dev/null 2>&1 - fi - - if [ "$family" == "ipv6" ]; then - $IP6 route del default dev $device proto static metric $metric 1>/dev/null 2>&1 - fi -} - -case "$ACTION" in - connected) - mwan3_add_failover_metric "$INTERFACE" "$DEVICE" "$online_metric" - ;; - disconnected) - mwan3_del_failover_metric "$INTERFACE" "$DEVICE" "$online_metric" - ;; -esac - -exit 0 diff --git a/net/mwan3/files/etc/hotplug.d/iface/14-mwan3 b/net/mwan3/files/etc/hotplug.d/iface/14-mwan3 deleted file mode 100644 index 4f8e0be16..000000000 --- a/net/mwan3/files/etc/hotplug.d/iface/14-mwan3 +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh - -. /lib/functions.sh -. /lib/mwan3/mwan3.sh -. /lib/functions/network.sh - -[ "$ACTION" = "ifup" -o "$ACTION" = "ifdown" ] || exit 1 -[ -n "$INTERFACE" ] || exit 2 - -if [ "$ACTION" = "ifup" ]; then - [ -n "$DEVICE" ] || exit 3 -fi - -config_load mwan3 -config_get_bool enabled globals 'enabled' '0' -[ ${enabled} -gt 0 ] || exit 0 - -config_get local_source globals local_source 'none' -[ "${local_source}" = "none" ] && { - exit 0 -} - -[ "${local_source}" = "$INTERFACE" ] || { - exit 0 -} - -mwan3_lock -src_ip=$(uci_get_state mwan3 globals src_ip) -[ "${src_ip}" != "" ] && { - ip route del default via "${src_ip}" dev lo 1>/dev/null 2>&1 - ip addr del "${src_ip}/32" dev lo 1>/dev/null 2>&1 -} - -sleep 1 - -[ "$ACTION" = "ifup" ] && { - network_get_ipaddr src_ip "${local_source}" - if [ "${src_ip}" = "" ]; then - $LOG warn "Unable to set source ip for own initiated traffic (${local_source})" - else - ip addr add "${src_ip}/32" dev lo - ip route add default via "${src_ip}" dev lo - uci_toggle_state mwan3 globals src_ip "${src_ip}" - fi -} -mwan3_unlock - -exit 0 diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index 42e08beb9..89ef06841 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -1219,25 +1219,3 @@ mwan3_track_clean() fi } } - -mwan3_online_metric_clean() { - local iface="$1" - - local online_metric ifname - - config_get family $iface family ipv4 - config_get online_metric $iface online_metric "" - ifname=$(uci_get_state network $iface ifname) - - if [ "$family" == "ipv4" ] \ - && [ "$online_metric" != "" ] \ - && [ "$ifname" != "" ]; then - $IP4 route del default dev $ifname proto static metric $online_metric 1>/dev/null 2>&1 - fi - - if [ "$family" == "ipv6" ] \ - && [ "$online_metric" != "" ] \ - && [ "$ifname" != "" ]; then - $IP6 route del default dev $ifname proto static metric $online_metric 1>/dev/null 2>&1 - fi -} diff --git a/net/mwan3/files/usr/libexec/rpcd/mwan3 b/net/mwan3/files/usr/libexec/rpcd/mwan3 index dc4eeb6df..d31ee63bc 100755 --- a/net/mwan3/files/usr/libexec/rpcd/mwan3 +++ b/net/mwan3/files/usr/libexec/rpcd/mwan3 @@ -31,6 +31,44 @@ report_connected_v6() { fi } +report_policies() { + local ipt="$1" + local policy="$2" + + local percent total_weight weight iface + + total_weight=$($ipt -S $policy | grep -v '.*--comment "out .*" .*$' | cut -s -d'"' -f2 | head -1 | awk '{print $3}') + + for iface in $($ipt -S $policy | grep -v '.*--comment "out .*" .*$' | cut -s -d'"' -f2 | awk '{print $1}'); do + weight=$($ipt -S $policy | grep -v '.*--comment "out .*" .*$' | cut -s -d'"' -f2 | awk '$1 == "'$iface'"' | awk '{print $2}') + percent=$(($weight*100/$total_weight)) + json_add_object + json_add_string interface "$iface" + json_add_int percent "$percent" + json_close_object + done +} + +report_policies_v4() { + local policy + + for policy in $($IPT4 -S | awk '{print $2}' | grep mwan3_policy_ | sort -u); do + json_add_array "${policy##*mwan3_policy_}" + report_policies "$IPT4" "$policy" + json_close_array + done +} + +report_policies_v6() { + local policy + + for policy in $($IPT6 -S | awk '{print $2}' | grep mwan3_policy_ | sort -u); do + json_add_array "${policy##*mwan3_policy_}" + report_policies "$IPT6" "$policy" + json_close_array + done +} + get_mwan3_status() { local iface="${1}" local iface_select="${2}" @@ -100,6 +138,7 @@ main () { json_add_object "status" json_add_string "section" "x" json_add_string "interface" "x" + json_add_string "policies" "x" json_close_object json_dump ;; @@ -130,6 +169,16 @@ main () { json_close_array json_close_object ;; + policies) + json_add_object policies + json_add_object ipv4 + report_policies_v4 + json_close_object + json_add_object ipv6 + report_policies_v6 + json_close_object + json_close_object + ;; *) # interfaces json_add_object interfaces @@ -144,6 +193,15 @@ main () { report_connected_v6 json_close_array json_close_object + # policies + json_add_object policies + json_add_object ipv4 + report_policies_v4 + json_close_object + json_add_object ipv6 + report_policies_v6 + json_close_object + json_close_object ;; esac json_dump diff --git a/net/mwan3/files/usr/sbin/mwan3 b/net/mwan3/files/usr/sbin/mwan3 index 139da3d25..4ad3bc391 100755 --- a/net/mwan3/files/usr/sbin/mwan3 +++ b/net/mwan3/files/usr/sbin/mwan3 @@ -175,7 +175,6 @@ stop() config_load mwan3 config_foreach mwan3_track_clean interface - config_foreach mwan3_online_metric_clean interface for IP in "$IP4" "$IP6"; do