Skip to content

Commit

Permalink
lime-system: rewrite network.scandevices() for better scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
G10h4ck committed Dec 25, 2014
1 parent d73a0a7 commit 2466516
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions packages/lime-system/files/usr/lib/lua/lime/network.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function network.clean()

uci:delete("network", "globals", "ula_prefix")
uci:delete("network", "wan", "ifname")
uci:delete("network", "lan", "ifname")

--! Delete interfaces and devices generated by LiMe
uci:foreach("network", "interface", function(s) if utils.stringStarts( s[".name"], network.limeIfNamePrefix ) then uci:delete("network", s[".name"]) end end)
Expand All @@ -123,26 +124,51 @@ end
function network.scandevices()
local devices = {}

--! Scan for plain ethernet interfaces and switch_vlan interfaces
local stdOut = io.popen("ls -1 /sys/class/net/")
for dev in stdOut:lines() do
function dev_parser(dev)
if dev:match("^eth%d+$") then
local insert = true
for d,_ in pairs(devices) do if d:match("^"..dev..".%d+$") then insert = false ; break; end end
if insert then devices[dev] = dev end
end

if dev:match("^eth%d+%.%d+$") then
local rawif = dev:match("^eth%d+")
local rawif = dev:match("^eth%d+")
devices[rawif] = nil
devices[dev] = dev
end

if dev:match("^wlan%d+_%w+$") then
devices[dev] = dev
end
end

function owrt_ifname_parser(section)
local ifn = section["ifname"]
if ( type(ifn) == "string" ) then dev_parser(ifn) end
if ( type(ifn) == "table" ) then for _,v in pairs(ifn) do dev_parser(v) end end
end
stdOut:close()

--! Scan for plain wireless interfaces
function owrt_switch_vlan_parser(section)
local rawif_index = section["device"]:match("%d+$")
local vlan_index = section["vlan"]
local kernel_visible = section["ports"]:match("0t")
if kernel_visible then dev_parser("eth"..rawif_index.."."..vlan_index) end
end

--! Scrape from uci wireless
local uci = libuci:cursor()
uci:foreach("wireless", "wifi-iface", function(s) table.insert(devices, s["ifname"]) end)
uci:foreach("wireless", "wifi-iface", owrt_ifname_parser)

--! Scrape from uci network
uci:foreach("network", "interface", owrt_ifname_parser)

--! Scrape switch_vlan form uci
uci:foreach("network", "switch_vlan", owrt_switch_vlan_parser)

--! Scrape from /sys/class/net/
local stdOut = io.popen("ls -1 /sys/class/net/")
for dev in stdOut:lines() do dev_parser(dev) end
stdOut:close()

return devices
end
Expand Down

0 comments on commit 2466516

Please sign in to comment.