From b86213a66f510bc9ca8378387319391114fad1ed Mon Sep 17 00:00:00 2001 From: Tim Wilkinson Date: Tue, 31 May 2022 19:54:02 -0700 Subject: [PATCH] LQM fixes 6 (#379) --- files/usr/local/bin/mgr/lqm.lua | 20 +++++++++++--------- files/www/cgi-bin/ports | 3 --- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/files/usr/local/bin/mgr/lqm.lua b/files/usr/local/bin/mgr/lqm.lua index 067791b6..6d378a86 100755 --- a/files/usr/local/bin/mgr/lqm.lua +++ b/files/usr/local/bin/mgr/lqm.lua @@ -110,15 +110,14 @@ end function update_block(track) if should_block(track) then - if not track.blocked then - track.blocked = true - os.execute("/usr/sbin/iptables -D input_lqm -p udp --destination-port 698 -m mac --mac-source " .. track.mac .. " -j DROP 2> /dev/null") + track.blocked = true + if os.execute("/usr/sbin/iptables -C input_lqm -p udp --destination-port 698 -m mac --mac-source " .. track.mac .. " -j DROP 2> /dev/null") ~= 0 then os.execute("/usr/sbin/iptables -I input_lqm -p udp --destination-port 698 -m mac --mac-source " .. track.mac .. " -j DROP 2> /dev/null") return "blocked" end else - if track.blocked then - track.blocked = false + track.blocked = false + if os.execute("/usr/sbin/iptables -C input_lqm -p udp --destination-port 698 -m mac --mac-source " .. track.mac .. " -j DROP 2> /dev/null") == 0 then os.execute("/usr/sbin/iptables -D input_lqm -p udp --destination-port 698 -m mac --mac-source " .. track.mac .. " -j DROP 2> /dev/null") return "unblocked" end @@ -126,6 +125,11 @@ function update_block(track) return "unchanged" end +function force_remove_block(track) + track.blocked = false + os.execute("/usr/sbin/iptables -D input_lqm -p udp --destination-port 698 -m mac --mac-source " .. track.mac .. " -j DROP 2> /dev/null") +end + -- Distance in meters between two points function calc_distance(lat1, lon1, lat2, lon2) local r2 = 12742000 -- diameter earth (meters) @@ -522,7 +526,7 @@ function lqm() track.blocks.user = false for val in string.gmatch(config.user_blocks, "([^,]+)") do - if val == track.mac then + if val:gsub("%s+", ""):gsub("-", ":"):upper() == track.mac then track.blocks.user = true break end @@ -612,9 +616,7 @@ function lqm() -- Remove any trackers which are too old or if they disconnect when first seen if ((now > track.lastseen + lastseen_timeout) or (not is_connected(track) and track.firstseen + pending_timeout > now)) then - track.blocked = true; - track.blocks = {} - update_block(track) + force_remove_block(track) tracker[track.mac] = nil end end diff --git a/files/www/cgi-bin/ports b/files/www/cgi-bin/ports index 28e905cb..264bef32 100755 --- a/files/www/cgi-bin/ports +++ b/files/www/cgi-bin/ports @@ -839,9 +839,6 @@ if parms.button_save and not (#port_err > 0 or #dhcp_err > 0 or #dmz_err > 0 or if not luci.sys.init.reload("firewall") then err("problem with port setup") end - if os.execute("/etc/init.d/manager restart") ~= 0 then - err("problem with manager") - end -- This "luci.sys.init.restart("olsrd")" doesnt do the same thing so we have to call restart directly if os.execute("/etc/init.d/olsrd restart") ~= 0 then err("problem with olsr setup")