--- ------ extra functions ------ --
-
-function interfaceCheck() -- find issues with too many interfaces, reliability and metric
- uci.cursor():foreach("mwan3", "interface",
- function (section)
- local interfaceName = section[".name"]
- interfaceNumber = interfaceNumber+1 -- count number of mwan interfaces configured
- -- create list of metrics for none and duplicate checking
- local metricValue = ut.trim(sys.exec("uci -p /var/state get network." .. interfaceName .. ".metric"))
- if metricValue == "" then
- errorFound = 1
- errorNoMetricList = errorNoMetricList .. interfaceName .. " "
- else
- metricList = metricList .. interfaceName .. " " .. metricValue .. "\n"
- end
- -- check if any interfaces have a higher reliability requirement than tracking IPs configured
- local trackingNumber = tonumber(ut.trim(sys.exec("echo $(uci -p /var/state get mwan3." .. interfaceName .. ".track_ip) | wc -w")))
- if trackingNumber > 0 then
- local reliabilityNumber = tonumber(ut.trim(sys.exec("uci -p /var/state get mwan3." .. interfaceName .. ".reliability")))
- if reliabilityNumber and reliabilityNumber > trackingNumber then
- errorFound = 1
- errorReliabilityList = errorReliabilityList .. interfaceName .. " "
- end
- end
- -- check if any interfaces are not properly configured in /etc/config/network or have no default route in main routing table
- if ut.trim(sys.exec("uci -p /var/state get network." .. interfaceName)) == "interface" then
- local interfaceDevice = ut.trim(sys.exec("uci -p /var/state get network." .. interfaceName .. ".ifname"))
- if interfaceDevice == "uci: Entry not found" or interfaceDevice == "" then
- errorFound = 1
- errorNetConfigList = errorNetConfigList .. interfaceName .. " "
- errorRouteList = errorRouteList .. interfaceName .. " "
- else
- local routeCheck = ut.trim(sys.exec("route -n | awk '{if ($8 == \"" .. interfaceDevice .. "\" && $1 == \"0.0.0.0\" && $3 == \"0.0.0.0\") print $1}'"))
- if routeCheck == "" then
- errorFound = 1
- errorRouteList = errorRouteList .. interfaceName .. " "
- end
- end
- else
- errorFound = 1
- errorNetConfigList = errorNetConfigList .. interfaceName .. " "
- errorRouteList = errorRouteList .. interfaceName .. " "
- end
- end
- )
- -- check if any interfaces have duplicate metrics
- local metricDuplicateNumbers = sys.exec("echo '" .. metricList .. "' | awk '{print $2}' | uniq -d")
- if metricDuplicateNumbers ~= "" then
- errorFound = 1
- local metricDuplicates = ""
- for line in metricDuplicateNumbers:gmatch("[^\r\n]+") do
- metricDuplicates = sys.exec("echo '" .. metricList .. "' | grep '" .. line .. "' | awk '{print $1}'")
- errorDuplicateMetricList = errorDuplicateMetricList .. metricDuplicates
- end
- errorDuplicateMetricList = sys.exec("echo '" .. errorDuplicateMetricList .. "' | tr '\n' ' '")
- end
-end