From b9b279c4cc4c59e995afd4008e1ff4ea2091d25d Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sat, 5 Jun 2021 18:41:39 +0200 Subject: [PATCH] luci-mod-network: allow device declarations and device configs to coexist It is legal to have two device sections referring to the same netdev if one section is a declaration (a section setting option type) and the other is a configuration (a section not specifying a type but matching an existing netdev). Support this case in LuCI since it might be required for some complex device setups. Additionally, fix the device type determination for device configuration sections without type, those should be treated as ethernet (a.k.a. simple device) configuration instead of falling back to the underlying netdev device type. Signed-off-by: Jo-Philipp Wich (cherry picked from commit a6c0ad00b28a5d3f91338b50f7e69fbd45f2154e) --- .../htdocs/luci-static/resources/tools/network.js | 15 ++++++++++----- .../resources/view/network/interfaces.js | 7 ++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/modules/luci-mod-network/htdocs/luci-static/resources/tools/network.js b/modules/luci-mod-network/htdocs/luci-static/resources/tools/network.js index 80b4b2b343..d008feb56a 100644 --- a/modules/luci-mod-network/htdocs/luci-static/resources/tools/network.js +++ b/modules/luci-mod-network/htdocs/luci-static/resources/tools/network.js @@ -46,11 +46,15 @@ function validateQoSMap(section_id, value) { return true; } -function deviceSectionExists(section_id, devname, devtype) { +function deviceSectionExists(section_id, devname, ignore_type_match) { var exists = false; uci.sections('network', 'device', function(ss) { - exists = exists || (ss['.name'] != section_id && ss.name == devname && (!devtype || devtype == ss.type)); + exists = exists || ( + ss['.name'] != section_id && + ss.name == devname && + (!ignore_type_match || !ignore_type_match.test(ss.type || '')) + ); }); return exists; @@ -409,10 +413,11 @@ return baseclass.extend({ o.ucioption = 'name'; o.write = o.remove = setIfActive; o.filter = function(section_id, value) { - return !deviceSectionExists(section_id, value); + return !deviceSectionExists(section_id, value, /^(?:bridge|8021q|8021ad|macvlan|veth)$/); }; o.validate = function(section_id, value) { - return deviceSectionExists(section_id, value) ? _('A configuration for the device "%s" already exists').format(value) : true; + return deviceSectionExists(section_id, value, /^(?:bridge|8021q|8021ad|macvlan|veth)$/) + ? _('A configuration for the device "%s" already exists').format(value) : true; }; o.depends('type', ''); @@ -479,7 +484,7 @@ return baseclass.extend({ o.ucioption = 'name'; o.write = o.remove = setIfActive; o.validate = function(section_id, value) { - return deviceSectionExists(section_id, value) ? _('The device name "%s" is already taken').format(value) : true; + return deviceSectionExists(section_id, value, /^$/) ? _('The device name "%s" is already taken').format(value) : true; }; o.depends({ type: '', '!reverse': true }); diff --git a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js index 2adf2b870e..9b2c9bfd5d 100644 --- a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js +++ b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js @@ -1313,10 +1313,11 @@ return view.extend({ } function getDevType(section_id) { - var cfgtype = uci.get('network', section_id, 'type'), - dev = getDevice(section_id); + var dev = getDevice(section_id), + cfg = uci.get('network', section_id), + type = cfg ? (uci.get('network', section_id, 'type') || 'ethernet') : (dev ? dev.getType() : ''); - switch (cfgtype || (dev ? dev.getType() : '')) { + switch (type) { case '': return null;