diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-06-16 09:47:47 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-06-16 09:52:36 +0200 |
commit | 8effea58d7281fd4f2b6c31d534195dba27a850b (patch) | |
tree | 2c6c008c8d082dea24930a58f746048aa27a0e1c /modules/luci-base/htdocs/luci-static | |
parent | dae17ede361a76be3a06737b88e00dc04e75b055 (diff) |
luci-base: network.js: consider uci config for Device.getType()/getParent()
For network devices declared in uci but not yet created by netifd, the
runtime status information will be unavailable, causing methods such as
`getType()` to assume plain ethernet interfaces and `getParent()` to fail
resolving parent devices.
Fall back to infer the information from uci configuration settings in such
cases to give accurate type hints to callers.
In particular, this prevents LuCI from turning wireless target networks
containing a to-be-created bridge device into bridges themselves.
Fixes: https://github.com/openwrt/packages/issues/18768
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/htdocs/luci-static')
-rw-r--r-- | modules/luci-base/htdocs/luci-static/resources/network.js | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/network.js b/modules/luci-base/htdocs/luci-static/resources/network.js index 8c9ee255ff..864cbba52c 100644 --- a/modules/luci-base/htdocs/luci-static/resources/network.js +++ b/modules/luci-base/htdocs/luci-static/resources/network.js @@ -2852,6 +2852,15 @@ Device = baseclass.extend(/** @lends LuCI.network.Device.prototype */ { this.device = this.device || device; this.dev = Object.assign({}, _state.netdevs[this.device]); this.network = network; + + var conf; + + uci.sections('network', 'device', function(s) { + if (s.name == device) + conf = s; + }); + + this.config = Object.assign({}, conf); }, _devstate: function(/* ... */) { @@ -2946,6 +2955,10 @@ Device = baseclass.extend(/** @lends LuCI.network.Device.prototype */ { return 'vlan'; else if (this.dev.devtype == 'dsa' || _state.isSwitch[this.device]) return 'switch'; + else if (this.config.type == '8021q' || this.config.type == '8021ad') + return 'vlan'; + else if (this.config.type == 'bridge') + return 'bridge'; else return 'ethernet'; }, @@ -3245,7 +3258,13 @@ Device = baseclass.extend(/** @lends LuCI.network.Device.prototype */ { * ordinary ethernet interfaces. */ getParent: function() { - return this.dev.parent ? Network.prototype.instantiateDevice(this.dev.parent) : null; + if (this.dev.parent) + return Network.prototype.instantiateDevice(this.dev.parent); + + if ((this.config.type == '8021q' || this.config.type == '802ad') && typeof(this.config.ifname) == 'string') + return Network.prototype.instantiateDevice(this.config.ifname); + + return null; } }); |