summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/root
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2023-08-24 16:44:40 +0200
committerJo-Philipp Wich <jo@mein.io>2023-08-24 16:48:01 +0200
commit98e37433e7f33b3e2ee751250e04b194a0aa6a0b (patch)
tree494077c8f15a92f325d87e5b193f0baeb54f6468 /modules/luci-base/root
parent727c0895a4e73f42a3fe50178f2926c61b7c5b95 (diff)
luci-base: rpc: add call to enumerate builtin ethernet ports
Add a new luci/getBuiltinEthernetPorts RPC call which returns a consolidated list of known ethernet ports found in `/etc/board.json`. Add an x86/64 specific workaround which attempts to enumerate missing ethernet devices too. Ref: #6534, #6538 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/root')
-rw-r--r--modules/luci-base/root/usr/share/rpcd/ucode/luci45
1 files changed, 44 insertions, 1 deletions
diff --git a/modules/luci-base/root/usr/share/rpcd/ucode/luci b/modules/luci-base/root/usr/share/rpcd/ucode/luci
index 35f592578b..3c4fea4691 100644
--- a/modules/luci-base/root/usr/share/rpcd/ucode/luci
+++ b/modules/luci-base/root/usr/share/rpcd/ucode/luci
@@ -8,7 +8,7 @@ import { cursor } from 'uci';
import { init_list, init_index, init_enabled, init_action, conntrack_list, process_list } from 'luci.sys';
import { revision, branch } from 'luci.version';
-import { statvfs } from 'luci.core';
+import { statvfs, uname } from 'luci.core';
import timezones from 'luci.zoneinfo';
@@ -538,6 +538,49 @@ const methods = {
call: function() {
return { result: process_list() };
}
+ },
+
+ getBuiltinEthernetPorts: {
+ call: function() {
+ let fd = open('/etc/board.json', 'r');
+ let board = fd ? json(fd) : {};
+ let ports = [];
+
+ for (let k in [ 'lan', 'wan' ]) {
+ if (!board?.network?.[k])
+ continue;
+
+ if (type(board.network[k].ports) == 'array') {
+ for (let ifname in board.network[k].ports) {
+ push(ports, { role: k, device: ifname });
+ }
+ }
+ else if (type(board.network[k].device) == 'string') {
+ push(ports, { role: k, device: board.network[k].device });
+ }
+ }
+
+ /* Workaround for targets that do not enumerate all netdevs in board.json */
+ if (uname().machine in [ 'x86_64' ] &&
+ match(ports[0]?.device, /^eth\d+$/)) {
+ let bus = readlink(`/sys/class/net/${ports[0].device}/device/subsystem`);
+
+ for (let netdev in lsdir('/sys/class/net')) {
+ if (!match(netdev, /^eth\d+$/))
+ continue;
+
+ if (length(filter(ports, port => port.device == netdev)))
+ continue;
+
+ if (readlink(`/sys/class/net/${netdev}/device/subsystem`) != bus)
+ continue;
+
+ push(ports, { role: 'unknown', device: netdev });
+ }
+ }
+
+ return { result: ports };
+ }
}
};