diff --git a/luci-app-modem/luasrc/controller/modem.lua b/luci-app-modem/luasrc/controller/modem.lua index 80f3bf2..50dd35d 100644 --- a/luci-app-modem/luasrc/controller/modem.lua +++ b/luci-app-modem/luasrc/controller/modem.lua @@ -13,7 +13,8 @@ function index() end entry({"admin", "network", "modem"}, alias("admin", "network", "modem", "modem_info"), translate("Modem"), 100).dependent = true - + --mwan配置 + entry({"admin", "network", "modem", "mwan_config"}, cbi("modem/mwan_config"), translate("Mwan Config"), 1).leaf = true --模块信息 entry({"admin", "network", "modem", "modem_info"}, template("modem/modem_info"), translate("Modem Information"),10).leaf = true entry({"admin", "network", "modem", "get_at_port"}, call("getATPort"), nil).leaf = true diff --git a/luci-app-modem/luasrc/model/cbi/modem/mwan_config.lua b/luci-app-modem/luasrc/model/cbi/modem/mwan_config.lua new file mode 100644 index 0000000..a4ca046 --- /dev/null +++ b/luci-app-modem/luasrc/model/cbi/modem/mwan_config.lua @@ -0,0 +1,89 @@ + + +local d = require "luci.dispatcher" +local uci = luci.model.uci.cursor() +local sys = require "luci.sys" +local script_path="/usr/share/modem/" + +m = Map("modem_mwan") +m.title = translate("Mwan Config") +m.description = translate("Check and modify the mwan configuration") +s = m:section(NamedSection, "global", "global", translate("gloal Config")) +s.anonymous = true +s.addremove = false +enable_mwan = s:option(Flag, "enable_mwan", translate("Enable MWAN")) +sticky = s:option(Flag,"sticky_mode",translate("sticky mode")) +sticky.default = 0 +sticky.description = translate("same source ip address will always use the same wan interface") +sticky_timeout = s:option(Value,"sticky_timeout",translate("sticky timeout")) +sticky_timeout.default = 300 +sticky_timeout.datatype = "uinteger" +sticky_timeout:depends("sticky_mode",1) + +s = m:section(NamedSection, "ipv4", "ipv4", translate("IPV4 Config")) +s.anonymous = true +s.addremove = false +--设置mwan策略 0:不使用 1:使用(作为后备) 2:使用(作为主要) 3:使用(作为负载均衡) +o = s:option(ListValue, "mwan_policy", translate("MWAN Policy")) +o:value("0", translate("Not Use")) +o:value("1", translate("Use(WWAN As Backup)")) +o:value("2", translate("Use(WWAN As Main)")) +o:value("3", translate("Use(WWAN For Load Balance)")) + +--设置mwan 有线wan端口 +o = s:option(Value, "wan_ifname", translate("WAN Interface")) +o.rmempty = ture +o.description = translate("Please enter the WAN interface name") +o.template = "cbi/network_netlist" +o.widget = "optional" +o.nocreate = true +o.unspecified = true + +--设置mwan wwan端口 +o = s:option(Value, "wwan_ifname", translate("WWAN Interface")) +o.rmempty = ture +o.description = translate("Please enter the WWAN interface name") +o.template = "cbi/network_netlist" +o.widget = "optional" +o.nocreate = true +o.unspecified = true +o = s:option(DynamicList, 'track_ip', translate('track_ip')) +o.datatype = 'host' + +-- m.title = translate("Mwan Config") +-- m.description = translate("Check and modify the mwan configuration") +-- s = m:section(NamedSection, "ipv6", "ipv6", translate("IPV6 Config")) +-- s.anonymous = true +-- s.addremove = false + + + + +-- --设置mwan策略 0:不使用 1:使用(作为后备) 2:使用(作为主要) 3:使用(作为负载均衡) +-- o = s:option(ListValue, "mwan_policy", translate("MWAN Policy")) +-- o:value("0", translate("Not Use")) +-- o:value("1", translate("Use(WWAN As Backup)")) +-- o:value("2", translate("Use(WWAN As Main)")) +-- o:value("3", translate("Use(WWAN For Load Balance)")) + +-- --设置mwan 有线wan端口 +-- o = s:option(Value, "wan_ifname", translate("WAN Interface")) +-- o.rmempty = ture +-- o.description = translate("Please enter the WAN interface name") +-- o.template = "cbi/network_netlist" +-- o.widget = "optional" +-- o.nocreate = true +-- o.unspecified = true + +-- --设置mwan wwan端口 +-- o = s:option(Value, "wwan_ifname", translate("WWAN Interface")) +-- o.rmempty = ture +-- o.description = translate("Please enter the WWAN interface name") +-- o.template = "cbi/network_netlist" +-- o.widget = "optional" +-- o.nocreate = true +-- o.unspecified = true + +-- o = s:option(DynamicList, 'track_ip', translate('track_ip')) +-- o.datatype = 'host' +return m diff --git a/luci-app-modem/root/etc/config/modem_mwan b/luci-app-modem/root/etc/config/modem_mwan new file mode 100644 index 0000000..28d02b3 --- /dev/null +++ b/luci-app-modem/root/etc/config/modem_mwan @@ -0,0 +1,10 @@ +config ipv4 'ipv4' + option wan_ifname 'wan' + option wwan_ifname 'wwan_5g_0' + list track_ip 'test.ustc.edu.cn' + list track_ip 'cip.cc' + list track_ip '208.67.222.222' + list track_ip '208.67.220.220' + +config global 'global' + option enable_mwan '0' diff --git a/luci-app-modem/root/etc/init.d/modem_mwan b/luci-app-modem/root/etc/init.d/modem_mwan new file mode 100755 index 0000000..e137c45 --- /dev/null +++ b/luci-app-modem/root/etc/init.d/modem_mwan @@ -0,0 +1,53 @@ +#!/bin/sh /etc/rc.common +USE_PROCD=1 +START=30 + +set_rule() +{ + proto=$1 + policy=$2 + case $policy in + 0) + cmd="stop" + ;; + 1) + cmd="wan" + ;; + 2) + cmd="wwan" + ;; + 3) + cmd="lb" + ;; + *) + cmd="stop" + ;; + esac + logger -t modem_mwan "before set $proto $cmd" + /usr/share/modem/modem_mwan.sh $proto $cmd + logger -t modem_mwan "set $proto $cmd" + +} + + + + +start_service() { + logger -t modem_mwan "start modem_mwan" + config_load modem_mwan + config_get enable global enable_mwan 0 + if [ "$enable" = "0" ]; then + stop_service + fi + config_get v4 ipv4 mwan_policy 0 + set_rule ipv4 $v4 +} + +stop_service() { + /usr/share/modem/modem_mwan.sh ipv4 stop + /usr/share/modem/modem_mwan.sh ipv4 disable +} + +service_triggers() { + procd_add_reload_trigger 'modem_mwan' +} diff --git a/luci-app-modem/root/etc/uci-defaults/luci-app-modem b/luci-app-modem/root/etc/uci-defaults/luci-app-modem index 39b7c9f..79481ae 100644 --- a/luci-app-modem/root/etc/uci-defaults/luci-app-modem +++ b/luci-app-modem/root/etc/uci-defaults/luci-app-modem @@ -16,6 +16,8 @@ uci -q batch <<-EOF >/dev/null delete ucitrack.@modem[-1] add ucitrack modem set ucitrack.@modem[-1].init=modem + add ucitrack modem + set ucitrack.@modem_mwan[-1].init=modem_mwan commit ucitrack EOF diff --git a/luci-app-modem/root/usr/share/modem/modem_mwan.sh b/luci-app-modem/root/usr/share/modem/modem_mwan.sh new file mode 100755 index 0000000..84bfaec --- /dev/null +++ b/luci-app-modem/root/usr/share/modem/modem_mwan.sh @@ -0,0 +1,192 @@ +#! /bin/sh +. /lib/functions.sh +family=$1 +config_load modem_mwan +config_get wan "$family" wan_ifname +config_get wwan "$family" wwan_ifname +config_get track_ip "$family" track_ip +config_get sticky_mode global sticky_mode +config_get sticky_timeout global sticky_timeout + +append_if(){ + interface=$1 + track_ip=$2 + uci batch <