From e93987fe060be4c076552c87d35d622e458344c0 Mon Sep 17 00:00:00 2001 From: Steve AB7PA <69524416+ab7pa@users.noreply.github.com> Date: Thu, 17 Jun 2021 12:48:19 -0700 Subject: [PATCH] api: add RF IP for non-RF links (#124) * api: add RF IP for non-RF links Add the RF IP address for non-RF linked devices. This allows the services to be displayed for non-RF Current Neighbors. * remove case manipulation --- files/usr/lib/lua/aredn/info.lua | 12 ++--- files/usr/lib/lua/aredn/olsr.lua | 90 +++++++++++++++++--------------- files/www/cgi-bin/api | 8 +-- 3 files changed, 57 insertions(+), 53 deletions(-) diff --git a/files/usr/lib/lua/aredn/info.lua b/files/usr/lib/lua/aredn/info.lua index 07f3bf16..3b515b49 100755 --- a/files/usr/lib/lua/aredn/info.lua +++ b/files/usr/lib/lua/aredn/info.lua @@ -327,8 +327,8 @@ function model.all_hosts() local ip, name=string.match(data,"^([%x%.%:]+)%s+(%S.*)\t%s*$") if ip and name then if not string.match(name,"^(dtdlink[.]).*") then - if not string.match(name,"^(mid[0-9][.]).*") then - host['name']=name:upper() + if not string.match(name,"^(mid%d+[.]).*") then + host['name']=name host['ip']=ip table.insert(hosts,host) end @@ -517,7 +517,7 @@ function model.getLocalCnxType(hostname) return "Loopback" elseif string.match(hostname,"dtdlink") then return "DTD" - elseif hostname == string.lower( model.getNodeName() ) then + elseif hostname:lower() == string.lower( model.getNodeName() ) then return "RF" else return "LAN" @@ -531,9 +531,7 @@ function model.getLocalHosts() local hosts, line if nixio.fs.access("/etc/hosts") then for line in io.lines("/etc/hosts") do - line = line:lower() - -- line is not a comment - local data = line:match("^([^#;]+)[#;]*(.*)$") + local data = line:match("^([^#;]+)[#;]*(.*)$") -- line is not a comment if data then local hostname, entries local ip, entries = data:match("^%s*([%[%]%x%.%:]+)%s+(%S.-%S)%s*$") @@ -548,7 +546,7 @@ function model.getLocalHosts() for hostname in entries:gmatch("%S+") do hostname = string.gsub(hostname,".local.mesh$","") entry["cnxtype"] = model.getLocalCnxType(hostname) - entry["hostnames"][index] = hostname:upper() + entry["hostnames"][index] = hostname index = index + 1 end hosts = hosts or { } diff --git a/files/usr/lib/lua/aredn/olsr.lua b/files/usr/lib/lua/aredn/olsr.lua index 7995f878..eca66735 100755 --- a/files/usr/lib/lua/aredn/olsr.lua +++ b/files/usr/lib/lua/aredn/olsr.lua @@ -66,55 +66,61 @@ end function model.getCurrentNeighbors(RFinfo) local RFinfo = RFinfo or false local info={} - local links=model.getOLSRLinks() + local links=model.getOLSRLinks() -- Get info for all current neighbors for k,v in pairs(links) do local host - local remip=v['remoteIP'] - local remhost=nslookup(remip) - info[remip]={} - info[remip]['olsrInterface']=v['olsrInterface'] - info[remip]['linkType']= model.getOLSRInterfaceType(v['olsrInterface']) -- RF or DTD or TUN - info[remip]['linkQuality']=v['linkQuality'] - info[remip]['neighborLinkQuality']=v['neighborLinkQuality'] - if remhost ~= nil then - host = string.lower(remhost) - end - if host ~= nil then - host = string.gsub(host,"mid%d+.", "") + local linkip=v['remoteIP'] + + info[linkip]={} + info[linkip]['olsrInterface']=v['olsrInterface'] + info[linkip]['linkType']= model.getOLSRInterfaceType(v['olsrInterface']) -- RF or DTD or TUN + info[linkip]['linkQuality']=v['linkQuality'] + info[linkip]['neighborLinkQuality']=v['neighborLinkQuality'] + + local linkhost=nslookup(linkip) -- TOTO: stop using nslookup? use /var/run/olsr_hosts + if linkhost~=nil then + host = string.gsub(linkhost,"mid%d+.", "") host = string.gsub(host,"dtdlink%.", "") host = string.gsub(host,".local.mesh$","") - info[remip]['hostname']=host - else - info[remip]['hostname']=remip - end - - if info[remip]['linkType'] == "RF" and RFinfo then - -- get additional info for RF link - require("iwinfo") + info[linkip]['hostname']=host + else + info[linkip]['hostname']=linkip + end + if info[linkip]['linkType'] == "RF" and RFinfo then -- get additional info for RF link + require("iwinfo") + info[linkip]["rfip"] = linkip local radio = ai.getMeshRadioDevice() local bandwidth = tonumber(ai.getChannelBW(radio)) - local wlan=get_ifname('wifi') - local RFneighbors=iwinfo['nl80211'].assoclist(wlan) - local mac2node=mac2host() - for i, mac_host in pairs(mac2node) do - local mac=string.match(mac_host, "^(.-)\-") - mac=mac:upper() - local node=string.match(mac_host, "\-(.*)") - if host == node or remip == node then - for stn in pairs(RFneighbors) do - stnInfo=iwinfo['nl80211'].assoclist(wlan)[mac] - if stnInfo ~= nil then - info[remip]["signal"]=tonumber(stnInfo.signal) - info[remip]["noise"]=tonumber(stnInfo.noise) - info[remip]["tx_rate"]=adjust_rate(stnInfo.tx_rate/1000,bandwidth) - info[remip]["rx_rate"]=adjust_rate(stnInfo.rx_rate/1000,bandwidth) - info[remip]["expected_throughput"]=adjust_rate(stnInfo.expected_throughput/1000,bandwidth) - end - end - end - end - end + local wlan=get_ifname('wifi') + local RFneighbors=iwinfo['nl80211'].assoclist(wlan) + local mac2node=mac2host() + for i, mac_host in pairs(mac2node) do + local mac=string.match(mac_host, "^(.-)\-") + mac=mac:upper() + local node=string.match(mac_host, "\-(.*)") -- add error checking here? + if node == "" then node=linkhost end + if linkhost == node or linkip == node then + for stn in pairs(RFneighbors) do + stnInfo=iwinfo['nl80211'].assoclist(wlan)[mac] + if stnInfo ~= nil then + info[linkip]["signal"]=tonumber(stnInfo.signal) + info[linkip]["noise"]=tonumber(stnInfo.noise) + info[linkip]["tx_rate"]=adjust_rate(stnInfo.tx_rate/1000,bandwidth) + info[linkip]["rx_rate"]=adjust_rate(stnInfo.rx_rate/1000,bandwidth) + info[linkip]["expected_throughput"]=adjust_rate(stnInfo.expected_throughput/1000,bandwidth) + end + end + end + end + else -- Get RF IP for non-RF nodes to display services keyed to RF IP + local allhosts=ai.all_hosts() + for k,v in pairs(allhosts) do + if linkhost == v['name'] or host == v['name'] then + info[linkip]["rfip"]=v['ip'] + end + end + end end return info end diff --git a/files/www/cgi-bin/api b/files/www/cgi-bin/api index 3c97519d..82152243 100755 --- a/files/www/cgi-bin/api +++ b/files/www/cgi-bin/api @@ -123,17 +123,17 @@ end function getRemoteNodes() local info={} - + local mynode = aredn_info.getNodeName() local allhosts = aredn_info.all_hosts() local cn = aredn_olsr.getCurrentNeighbors() local routes = aredn_olsr.getOLSRRoutes() for k, v in pairs(allhosts) do - local node={} + local node={} -- skip currentneighbors, myself, and MID*. entries for cnk, cnv in pairs(cn) do - if not (cnk == allhosts[k].ip or allhosts[k].name == mynode or (allhosts[k].name:match("^MID%d+%.") ~= nil)) then - node=allhosts[k] + if not (cnk == allhosts[k].ip or allhosts[k].name == mynode or (allhosts[k].name:match("^mid%d+%.") ~= nil)) then + node=allhosts[k] end end