From a254d4aaed7b9a85216ca13423fcb1ed1b2262bf Mon Sep 17 00:00:00 2001 From: "Ycarus (Yannick Chabanois)" Date: Thu, 25 Feb 2021 14:25:52 +0100 Subject: [PATCH] Add check for duplicate mac --- .../luasrc/view/openmptcprouter/wanstatus.htm | 14 +++++++--- .../root/usr/libexec/rpcd/openmptcprouter | 26 +++++++++++++++++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/luci-app-openmptcprouter/luasrc/view/openmptcprouter/wanstatus.htm b/luci-app-openmptcprouter/luasrc/view/openmptcprouter/wanstatus.htm index 794dccb31..4a3421d3b 100644 --- a/luci-app-openmptcprouter/luasrc/view/openmptcprouter/wanstatus.htm +++ b/luci-app-openmptcprouter/luasrc/view/openmptcprouter/wanstatus.htm @@ -455,6 +455,7 @@ local statuslogo = ucic:get("openmptcprouter","settings","statuslogo") or "openm var multipath_available = mArray.wans[i].multipath_available; var multipath_state = mArray.wans[i].multipath_state; var duplicateif = mArray.wans[i].duplicateif; + var duplicatemac = mArray.wans[i].duplicatemac; // Generate template if(mArray.openmptcprouter.remote_from_lease == true && mArray.wans.length == 1) { @@ -547,12 +548,12 @@ local statuslogo = ucic:get("openmptcprouter","settings","statuslogo") or "openm if(gateway == '' && gateway6 == '') { statusMessage += '<%:No gateway defined%>' + '
'; - } else if(gw_ping == 'DOWN') + } else if(gateway != '' && gw_ping == 'DOWN') { statusMessage += '<%:Gateway DOWN%>' + '
'; - } else if(gw_ping6 == 'DOWN') + } else if(gateway6 != '' && gw_ping6 == 'DOWN') { - statusMessage += '<%:Gateway DOWN%>' + '
'; + statusMessage += '<%:Gateway IPv6 DOWN%>' + '
'; } else if(multipath_available == 'ERROR') { statusMessage += '<%:Multipath seems to be blocked on the connection%>' + '
'; @@ -566,7 +567,7 @@ local statuslogo = ucic:get("openmptcprouter","settings","statuslogo") or "openm statusMessage += '<%:Wan IP and gateway are identical%>' + '
'; statusMessageClass = "error"; } - if (stat == 'Offline' && ip6addr != '' && ipaddr == mArray.wans[i].gateway6) + if (stat == 'Offline' && ip6addr != '' && ip6addr == mArray.wans[i].gateway6) { statusMessage += '<%:Wan IP and gateway are identical%>' + '
'; statusMessageClass = "error"; @@ -595,6 +596,11 @@ local statuslogo = ucic:get("openmptcprouter","settings","statuslogo") or "openm statusMessage += '<%:Network interface duplicated%>' + '
'; statusMessageClass = "error"; } + if(duplicatemac) + { + statusMessage += '<%:Network interface MAC address duplicated%>' + '
'; + statusMessageClass = "error"; + } if(ipv6_discover == 'DETECTED') { statusMessage += '<%:IPv6 route received%>' + '
' diff --git a/luci-app-openmptcprouter/root/usr/libexec/rpcd/openmptcprouter b/luci-app-openmptcprouter/root/usr/libexec/rpcd/openmptcprouter index 858ae5798..0708e3f03 100755 --- a/luci-app-openmptcprouter/root/usr/libexec/rpcd/openmptcprouter +++ b/luci-app-openmptcprouter/root/usr/libexec/rpcd/openmptcprouter @@ -1105,6 +1105,7 @@ function interfaces_status() mArray.wans = {} mArray.tunnels = {} allintf = {} + allmac = {} uci:foreach("network", "interface", function (section) local interface = section[".name"] @@ -1117,6 +1118,7 @@ function interfaces_status() local enabled = section["auto"] local proto = section["proto"] or "" local ipv6 = section["ipv6"] or "0" + local mac = section ["macaddr"] or "" --if not ipaddr or not gateway then return end -- Don't show if0 in the overview @@ -1140,6 +1142,16 @@ function interfaces_status() end end + duplicatemac = false + if mac ~= "" and mac ~= nil and not (section["ifname"] ~= nil and section["ifname"]:match("^@.*")) then + if allmac[mac] then + connectivity = "ERROR" + duplicatemac = true + else + allmac[mac] = true + end + end + --if multipath == "off" and not ifname:match("^tun.*") then return end if multipath == "off" then return end @@ -1237,7 +1249,7 @@ function interfaces_status() if gateway ~= "" then local gw_ping_test = "" if ifname ~= "" and ifname ~= nil then - gw_ping_test = ut.trim(sys.exec("ping -w 1 -c 1 -I " .. ifname .. " " .. gateway .. " | grep '100% packet loss'")) + gw_ping_test = ut.trim(sys.exec("ping -w 1 -c 1 -B -I " .. ifname .. " " .. gateway .. " | grep '100% packet loss'")) else gw_ping_test = ut.trim(sys.exec("ping -w 1 -c 1 " .. gateway .. " | grep '100% packet loss'")) end @@ -1247,11 +1259,13 @@ function interfaces_status() connectivity = "WARNING" end end + else + gw_ping = "DOWN" end if gateway6 ~= "" then local gw_ping6_test = "" if ifname ~= "" and ifname ~= nil then - gw_ping6_test = ut.trim(sys.exec("ping -w 1 -c 1 -I " .. ifname .. " " .. gateway6 .. " | grep '100% packet loss'")) + gw_ping6_test = ut.trim(sys.exec("ping -w 1 -c 1 -B -I " .. ifname .. " " .. gateway6 .. " | grep '100% packet loss'")) else gw_ping6_test = ut.trim(sys.exec("ping -w 1 -c 1 " .. gateway6 .. " | grep '100% packet loss'")) end @@ -1261,6 +1275,8 @@ function interfaces_status() connectivity = "WARNING" end end + else + gw_ping6 = "DOWN" end end if uci:get("openmptcprouter", interface, "manufacturer") == "huawei" then @@ -1346,6 +1362,10 @@ function interfaces_status() multipath_available = "NO CHECK" end + local zonewan = "NO" + if ut.trim(sys.exec("uci -q get firewall.zone_wan.networks | grep '" .. interface .. "'")) ~= "" then + zonewan = "OK" + end -- Detect if WAN get an IPv6 local ipv6_discover = "NONE" @@ -1449,6 +1469,7 @@ function interfaces_status() multipath_available = multipath_available, multipath_state = current_multipath_state, duplicateif = duplicateif, + duplicatemac = duplicatemac, signal = signal, operator = operator, phonenumber = phonenumber, @@ -1457,6 +1478,7 @@ function interfaces_status() proto = proto, rx = rx, tx = tx, + zonewan = zonewan, } if ifname ~= nil and ifname:match("^tun.*") then table.insert(mArray.tunnels, data);