luci-mod-network: fix tagging/pvid state parsing in bridge-vlan ports
authorJo-Philipp Wich <[email protected]>
Thu, 17 Jun 2021 15:33:49 +0000 (17:33 +0200)
committerJo-Philipp Wich <[email protected]>
Thu, 17 Jun 2021 15:33:49 +0000 (17:33 +0200)
The previous code naively looked for a `t` in the entire port spec,
wrongly matching untagged ports having a `t` in their name, such
as `eth0`.

Rework the logic to be more strict when parsing the port member
specification to avoid this issue.

Signed-off-by: Jo-Philipp Wich <[email protected]>
modules/luci-mod-network/htdocs/luci-static/resources/tools/network.js

index 67fe4b9cef3af054c7a44b9b7887423c10b24490..bba0e80f870350a8dc9fc440bc9f3d7bde1cc16f 100644 (file)
@@ -264,15 +264,20 @@ var cbiTagValue = form.Value.extend({
        },
 
        cfgvalue: function(section_id) {
-               var pname = this.port,
-                   spec = L.toArray(uci.get('network', section_id, 'ports')).filter(function(p) { return p.replace(/:[ut*]+$/, '') == pname })[0];
-
-               if (spec && spec.match(/t/))
-                       return spec.match(/\*/) ? ['t', '*'] : ['t'];
-               else if (spec)
-                       return spec.match(/\*/) ? ['u', '*'] : ['u'];
-               else
-                       return ['-'];
+               var ports = L.toArray(uci.get('network', section_id, 'ports'));
+
+               for (var i = 0; i < ports.length; i++) {
+                       var s = ports[i].split(/:/);
+
+                       if (s[0] != this.port)
+                               continue;
+
+                       var t = s[1].match(/t/) ? 't' : 'u';
+
+                       return s[1].match(/\*/) ? [t, '*'] : [t];
+               }
+
+               return ['-'];
        },
 
        write: function(section_id, value) {