Skip to content

Commit 65cddae

Browse files
committed
Added static-wan-routes-monitor service
1 parent a11c3f2 commit 65cddae

File tree

13 files changed

+147
-39
lines changed

13 files changed

+147
-39
lines changed

build/common/001-Variables

+1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ apply_service_changes() {
256256
restart nginx $SRV_nginx
257257
restart firewall $SRV_firewall
258258
restart network $SRV_network reload
259+
restart static-wan-routes-monitor 1
259260
restart watchdog-tch 1 start
260261
fi
261262
}

build/common/015-Restore

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if [ $RESTORE = y ]; then
88

99
restore_www V
1010

11-
for f in /etc/config/tch_gui_unhide /etc/tch-gui-unhide.ignored_release /etc/tch-gui-unhide.theme /etc/hotplug.d/iface/10-bqos /etc/init.d/bqos /usr/sbin/bqos /etc/hotplug.d/iface/60-add-IPv6-DNS-intercept-exceptions /etc/hotplug.d/iface/70-WAN-LEDs;do
11+
for f in /etc/config/tch_gui_unhide /etc/tch-gui-unhide.ignored_release /etc/tch-gui-unhide.theme /etc/hotplug.d/iface/10-bqos /etc/init.d/bqos /usr/sbin/bqos /etc/hotplug.d/iface/60-add-IPv6-DNS-intercept-exceptions /etc/hotplug.d/iface/70-WAN-LEDs /etc/init.d/static-wan-routes-monitor;do
1212
if [ -f "$f" ]; then
1313
if [ "$(dirname $f)" = "/etc/init.d" ]; then
1414
echo -e "[$SCRIPT]: Disabling and stopping $f"

build/common/095-Network

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ done
2424

2525
if [ "$(exec_uci -q get network.config.wan_mode)" = "bridge" ]; then
2626
if [ -z "$(exec_uci -q get network.lan6)" ]; then
27-
echo -e "[$SCRIPT]: Creating missing lan6 interface "
27+
echo -e "[$SCRIPT]: Creating missing lan6 interface"
2828
exec_uci set network.lan6=interface
2929
exec_uci set network.lan6.defaultreqopts='0'
3030
exec_uci set network.lan6.forceprefix='0'
@@ -48,3 +48,8 @@ if grep -q "kill -9 \`ps | grep parseopt60 | awk '{print \$1}' | head -n 1\`; /u
4848
echo -e "[$SCRIPT]: Fix '/usr/bin/parseopt60: not found' error"
4949
sed -e "s#kill -9 \`ps | grep parseopt60 | awk '{print \$1}' | head -n 1\`; /usr/bin/parseopt60 &#( & )#" -i /etc/udhcpc.user
5050
fi
51+
52+
if ! /etc/init.d/static-wan-routes-monitor enabled; then
53+
echo -e "[$SCRIPT]: Enabling static WAN routes monitor service"
54+
/etc/init.d/static-wan-routes-monitor enable
55+
fi

src/common/broadband/www/cards/002_broadband.lp

+2-13
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ local ui_helper = require("web.ui_helper")
88
local content_helper = require("web.content_helper")
99

1010
-- could be in bridge mode and fail if included in wan_data
11-
local proxy = require("datamodel")
1211
local isBridgedMode = require("bridgedmode_helper").isBridgedMode()
13-
local wan_proto = proxy.get("[email protected]")
14-
local static = wan_proto and wan_proto[1].value == "static"
1512

1613
-- wan status data
1714
local wan_data = {
@@ -39,10 +36,6 @@ if WS_en == "1" then
3936
if WS_L3 == "" then
4037
WS_L3 = "NONE"
4138
end
42-
if static then
43-
WS_State = "static"
44-
WS_Text = T"WAN Sensing enabled on STATIC IP"
45-
end
4639
else
4740
WS_Text = T"WAN Sensing disabled"
4841
WS_State = "Disabled"
@@ -52,7 +45,6 @@ local WS_light_map = {
5245
Disabled = "off",
5346
None = "orange",
5447
Enabled = "green",
55-
static = "red",
5648
}
5749

5850
local session = ngx.ctx.session
@@ -67,12 +59,9 @@ ngx.print('\
6759
ui_helper.createCardHeader(T"Broadband",modalPath,nil,nil,{icon={class="icon-link"}}),'\
6860
<div id="broadband-card-throughput"><div class="throughput"><span title="Raw throughput including protocol overhead"></span></div></div>\
6961
<div class="content card_bg mirror" data-bg-text="&#xf0c1;">\
70-
');
71-
if (WS_en == "1" or not static) and not isBridgedMode then
72-
ngx.print( ui_helper.createSimpleLight(nil,WS_Text,{ light = { class = WS_light_map[WS_State] } }) )
73-
end
62+
',ui_helper.createSimpleLight(nil,WS_Text,{ light = { class = WS_light_map[WS_State] } }))
7463
if WS_en == "1" then
75-
ngx.print( format('<p class="subinfos">L2: <strong>%s</strong> L3: <strong>%s</strong></p>',WS_L2,WS_L3) )
64+
ngx.print(format('<p class="subinfos">L2: <strong>%s</strong> L3: <strong>%s</strong></p>',WS_L2,WS_L3))
7665
end
7766
ngx.print('\
7867
<div id="broadband-card-content">\

src/common/broadband/www/docroot/modals/broadband-modal.lp

-10
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,6 @@ if not tabdata.current.ajax then
104104

105105
html[#html + 1] = ui_helper.createAlertBlock(T"WAN Sensing sets the connection mode automatically when enabled.",info_box)
106106
html[#html+1] = ui_helper.createSwitch(T"WAN Sensing","wsens",content["wsens"],wsensswitchclass)
107-
local proxy = require("datamodel")
108-
local wan_proto = proxy.get("[email protected]")
109-
if wan_proto and wan_proto[1].value == "static" then
110-
local danger_box = {
111-
alert = {
112-
class = "alert alert-danger monitor-wsens monitor-1",
113-
}
114-
}
115-
html[#html + 1] = ui_helper.createAlertBlock(T"WARNING: Static IP Connections are INCOMPATIBLE with WAN Sensing!",danger_box)
116-
end
117107
if content["wsens"] == "1" then
118108
html[#html + 1] = ui_helper.createAlertBlock(T"Disable WAN Sensing to set the connection mode manually.<br/>After saving the change, the connection mode options will be shown.",info_box)
119109
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh /etc/rc.common
2+
3+
USE_PROCD=1
4+
5+
START=95
6+
STOP=01
7+
8+
__INTERFACES=""
9+
10+
find_static_wan_iface() {
11+
local cfg="$1"
12+
if [ "$cfg" = "wan" -o "$cfg" = "wan6" ]; then
13+
local enabled proto ifname gateway
14+
15+
config_get proto "$cfg" proto
16+
config_get ifname "$cfg" ifname
17+
config_get gateway "$cfg" gateway
18+
19+
if [ "$proto" = "static" -a -n "$ifname" -a -n "$gateway" ]; then
20+
__INTERFACES="$__INTERFACES $ifname,$gateway"
21+
fi
22+
fi
23+
}
24+
25+
config_load network
26+
config_foreach find_static_wan_iface interface
27+
28+
start_service() {
29+
if [ -n "$__INTERFACES" ]; then
30+
procd_open_instance
31+
procd_set_param command $(which lua) /usr/share/tch-gui-unhide/static-wan-routes-monitor.lua $__INTERFACES
32+
procd_set_param stdout 1
33+
procd_set_param stderr 1
34+
procd_close_instance
35+
fi
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env lua
2+
3+
local logger,posix,ubus,uloop = require("tch.logger"),require("tch.posix"),require('ubus'),require('uloop')
4+
local log = logger.new("static-wan-routes-monitor",3,posix.LOG_DAEMON)
5+
local ipairs = ipairs
6+
7+
local monitored = {}
8+
for _,pair in ipairs(arg or {}) do
9+
local interface,gateway = string.match(pair,"([^,]+),(.+)")
10+
if interface then
11+
if not monitored[interface] then
12+
monitored[interface] = { }
13+
end
14+
monitored[interface][#monitored[interface]+1] = gateway
15+
log:notice("Adding monitoring for static WAN interface on "..interface.." (gateway = "..gateway..")")
16+
end
17+
end
18+
19+
local conn = ubus.connect()
20+
if conn then
21+
log:notice("Connected to ubusd")
22+
23+
local function fix_default_routes(interface,gateway,action)
24+
local family = "4"
25+
local metric = "1"
26+
if string.find(gateway,":") then
27+
family = "6"
28+
metric = "512"
29+
end
30+
if action == "down" then
31+
local cmd,err = io.popen("ip -"..family.." route show default dev "..interface)
32+
if cmd then
33+
for line in cmd:lines() do
34+
local remove_cmd = "ip -"..family.." route del "..line
35+
log:notice(remove_cmd)
36+
os.execute(remove_cmd)
37+
end
38+
cmd:close()
39+
else
40+
log:error("Failed to retrieve IPv"..family.." routes for interface "..interface..": "..err)
41+
end
42+
else -- up
43+
local add_cmd = "ip -"..family.." route add default via "..gateway.." dev "..interface.." proto static metric "..metric
44+
log:notice(add_cmd)
45+
os.execute(add_cmd)
46+
end
47+
end
48+
49+
uloop.init()
50+
51+
local events = {}
52+
events['network.link'] = function(data)
53+
if data then
54+
if monitored[data.interface] then
55+
log:notice("Interface "..data.interface.." is "..data.action)
56+
for _,gateway in pairs(monitored[data.interface]) do
57+
if gateway then
58+
fix_default_routes(data.interface,gateway,data.action)
59+
end
60+
end
61+
else
62+
log:notice("Interface "..data.interface.." is "..data.action.." (Ignored)")
63+
end
64+
end
65+
end
66+
conn:listen(events)
67+
68+
log:notice("Waiting for network.link events...")
69+
while true do
70+
uloop.run()
71+
end
72+
else
73+
log:error("Failed to connect to ubusd - aborting")
74+
os.exit(2)
75+
end
76+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
^network%.[^%.]+%.wan6?%. /etc/init.d/static-wan-routes-monitor restart

src/common/internet/www/docroot/modals/internet-modal.lp

+7-11
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,11 @@ if not tabdata.current.ajax then
6262
["data-value"] = "SWITCH_MODE",
6363
}
6464
}
65-
local static_attr = {
66-
alert = {
67-
class = "alert-info monitor-newmode monitor-static"
68-
},
69-
}
7065

7166
local html = {}
7267
html[#html+1] = '<fieldset id="conn_mode" class="advanced hide">'
7368
html[#html+1] = '<legend>'..T"Connection Mode"..'</legend>'
7469
html[#html+1] = ui_helper.createInputRadio(T"Mode","newmode",mode_options,mode_current,mode_attributes)
75-
local wsens = proxy.get("uci.wansensing.global.enable")
76-
if wsens and wsens[1].value == "1" then
77-
html[#html+1] = ui_helper.createAlertBlock(T("WARNING: Static IP Connections are INCOMPATIBLE with WAN Sensing! WAN Sensing will be DISABLED when saving Static IP Mode configuration."),static_attr)
78-
end
7970
html[#html+1] = ui_helper.createButton("",T"Switch Connection Mode","icon-cog",mode_button)
8071
html[#html+1] = '</fieldset>'
8172
ngx.print(html)
@@ -85,8 +76,13 @@ lp.setpath("/www/snippets/")
8576
lp.include(tabdata.current.view)
8677

8778
if not tabdata.current.ajax then
88-
ngx.print('\
79+
ngx.print('\
8980
</form>\
9081
</div>\
91-
'); ngx.print(ui_helper.createFooter());
82+
');
83+
ngx.print(ui_helper.createFooter());
84+
local args = ngx.req.get_post_args()
85+
if args.action == "SWITCH_MODE" then
86+
ngx.print('<script language ="javascript">$(document).ready(function(){$("#modal-no-change").hide(); $("#modal-changes").show();});</script>')
87+
end
9288
end

src/common/internet/www/snippets/internet-static-routed.lp

+14
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ local mapValid = {
121121
}
122122

123123
local content,helpmsg = post_helper.handleQuery(mapParams,mapValid)
124+
if not helpmsg then helpmsg = {} end
124125

125126
local supervision_support = proxy.get("uci.supervision.global.enabled")
126127
local supervision_modes = {
@@ -147,6 +148,19 @@ if content.wanIpAddrParam == "" then
147148
content.wanNetmaskParam = post_helper.cidr2mask(untaint(proxy.get("[email protected]")[1].value))
148149
content.wanGatewayParam = proxy.get("[email protected]")[1].value
149150
end
151+
if content.uci_wan6_addr == "" then
152+
local ipv6addr = proxy.get("[email protected]","[email protected]")
153+
if ipv6addr then
154+
if ipv6addr[1].value ~= "" then
155+
content.uci_wan6_addr = ipv6addr[1].value
156+
else
157+
content.uci_wan6_addr = ipv6addr[2].value
158+
end
159+
content.uci_wan6_gw = proxy.get("[email protected]")[1].value
160+
content.uci_wan6_prefix = proxy.get("[email protected]")[1].value
161+
content.uci_wan6_auto = "0"
162+
end
163+
end
150164

151165
if content.uci_wan_auto ~= "0" then
152166
content.uci_wan_auto = "1"

utilities/reset-to-factory-defaults-with-root

+1-1
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ if [ -n "$FIRMWARE" ]; then
786786
pinholehelper \
787787
qos qos_tch \
788788
ra redirecthelper rsyncd \
789-
samba samba-nmbd socat supervision sync-adguard-home-data sysntpd \
789+
samba samba-nmbd socat static-wan-routes-monitor supervision sync-adguard-home-data sysntpd \
790790
telemetry-daemon tls-thor tod trafficmon transformer tproxy \
791791
uhttpd \
792792
wansensing wfa-testsuite-daemon wifi-doctor-agent wol \

utilities/restore-config/.sha256

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cb9c3f4854ed78ba5095ba83aef1dcd4606e29a037f58c2e99816961d6aa6721 000-core.sh
2-
44ab0fcbf7dffcc3aeba823d3fe6e84c1000859581a78e14b46a3cab4ef11588 050-services.sh
2+
86ab988d549ed4916f76d854845be4e24b818a9deb6fb5ab7b09954ce74e1276 050-services.sh
33
a27d848f8cbbcb6786411145d3fb4f65644cc8fa883c048cfc711422487e21cc 099-extensions.sh
44
e58ae3a3d259ebcdcfe3d2efc2cb3a87a4432be9832efa06ea475aa0671cf20a 100-root.sh
55
164391b5278b262bc5ff929bafbcb5da4c0e6bf51899abf1753eb5f137f51c28 150-system.sh

utilities/restore-config/050-services.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services="watchdog-tch \
1717
pinholehelper \
1818
qos qos_tch \
1919
ra redirecthelper rsyncd \
20-
samba samba-nmbd socat supervision sync-adguard-home-data sysntpd \
20+
samba samba-nmbd socat static-wan-routes-monitor supervision sync-adguard-home-data sysntpd \
2121
telemetry-daemon tls-thor tod trafficmon transformer tproxy \
2222
uhttpd \
2323
wansensing wfa-testsuite-daemon wifi-doctor-agent wol \

0 commit comments

Comments
 (0)