luci-base: migrate luci/getNetworkDevices to C plugin
authorJo-Philipp Wich <jo@mein.io>
Thu, 31 Oct 2019 13:57:27 +0000 (14:57 +0100)
committerJo-Philipp Wich <jo@mein.io>
Fri, 1 Nov 2019 11:03:33 +0000 (12:03 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/network.js
modules/luci-base/root/usr/libexec/rpcd/luci
modules/luci-base/root/usr/share/rpcd/acl.d/luci-base.json

index eaa4b3bb9fdd9fb1db12778455e60fbcbe1ebba3..728433bbe984d8d02f5a0e3b05794903acf5ffed 100644 (file)
@@ -45,7 +45,7 @@ var iface_patterns_wireless = [
 var iface_patterns_virtual = [ ];
 
 var callLuciNetworkDevices = rpc.declare({
-       object: 'luci',
+       object: 'luci-rpc',
        method: 'getNetworkDevices',
        expect: { '': {} }
 });
index da36270a1745331944b5d1bc4c0ba7b0c573525c..ae504fd3e3a09763722da2b3d3481d4c24789756 100755 (executable)
@@ -186,69 +186,6 @@ local methods = {
                end
        },
 
-       getNetworkDevices = {
-               call = function(args)
-                       local dir = fs.dir("/sys/class/net")
-                       local result = { }
-                       if dir then
-                               local dev
-                               for dev in dir do
-                                       if not result[dev] then
-                                               result[dev] = { name = dev }
-                                       end
-
-                                       if fs.access("/sys/class/net/"..dev.."/master") then
-                                               local brname = fs.basename(fs.readlink("/sys/class/net/"..dev.."/master"))
-                                               if not result[brname] then
-                                                       result[brname] = { name = brname }
-                                               end
-
-                                               if not result[brname].ports then
-                                                       result[brname].ports = { }
-                                               end
-
-                                               result[brname].ports[#result[brname].ports+1] = dev
-                                       elseif fs.access("/sys/class/net/"..dev.."/bridge") then
-                                               if not result[dev].ports then
-                                                       result[dev].ports = { }
-                                               end
-
-                                               result[dev].id = readfile("/sys/class/net/"..dev.."/bridge/bridge_id")
-                                               result[dev].stp = (readfile("/sys/class/net/"..dev.."/bridge/stp_state") ~= "0")
-                                               result[dev].bridge = true
-                                       end
-
-                                       local opr = readfile("/sys/class/net/"..dev.."/operstate")
-
-                                       result[dev].up = (opr == "up" or opr == "unknown")
-                                       result[dev].type = tonumber(readfile("/sys/class/net/"..dev.."/type"))
-                                       result[dev].name = dev
-
-                                       local mtu = tonumber(readfile("/sys/class/net/"..dev.."/mtu"))
-                                       if mtu and mtu > 0 then
-                                               result[dev].mtu = mtu
-                                       end
-
-                                       local qlen = tonumber(readfile("/sys/class/net/"..dev.."/tx_queue_len"))
-                                       if qlen and qlen > 0 then
-                                               result[dev].qlen = qlen
-                                       end
-
-                                       local master = fs.readlink("/sys/class/net/"..dev.."/master")
-                                       if master then
-                                               result[dev].master = fs.basename(master)
-                                       end
-
-                                       local mac = readfile("/sys/class/net/"..dev.."/address")
-                                       if mac and #mac == 17 then
-                                               result[dev].mac = mac
-                                       end
-                               end
-                       end
-                       return result
-               end
-       },
-
        getConntrackHelpers = {
                call = function()
                        local ok, fd = pcall(io.open, "/usr/share/fw3/helpers.conf", "r")
index 912707a8446b03f67496fd5d7977bdc5c7f0353b..8b47aa83f30fb359cb4c3467e418b7749eb89d72 100644 (file)
@@ -41,8 +41,8 @@
                        "ubus": {
                                "file": [ "list", "read", "stat" ],
                                "iwinfo": [ "assoclist", "freqlist", "txpowerlist", "countrylist" ],
-                               "luci": [ "getDUIDHints", "getIfaddrs", "getInitList", "getLocaltime", "getTimezones", "getLEDs", "getNetworkDevices", "getUSBDevices", "getSwconfigFeatures", "getSwconfigPortState", "getBlockDevices", "getMountPoints" ],
-                               "luci-rpc": [ "getBoardJSON", "getDHCPLeases", "getHostHints", "getWirelessDevices" ],
+                               "luci": [ "getDUIDHints", "getIfaddrs", "getInitList", "getLocaltime", "getTimezones", "getLEDs", "getUSBDevices", "getSwconfigFeatures", "getSwconfigPortState", "getBlockDevices", "getMountPoints" ],
+                               "luci-rpc": [ "getBoardJSON", "getDHCPLeases", "getHostHints", "getNetworkDevices", "getWirelessDevices" ],
                                "network.device": [ "status" ],
                                "network.interface": [ "dump" ],
                                "network": [ "get_proto_handlers" ],