luci-mod-network: don't accidentally reset macvlan device names
authorJo-Philipp Wich <jo@mein.io>
Tue, 1 Jun 2021 12:35:31 +0000 (14:35 +0200)
committerJo-Philipp Wich <jo@mein.io>
Sat, 12 Jun 2021 17:23:06 +0000 (19:23 +0200)
Fixes: #5081
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 671c94b034db9d7470d5f1e681b919158de205f6)

modules/luci-mod-network/htdocs/luci-static/resources/tools/network.js

index 199cd0f152e3da45fa95961bea816fe660babd54..80b4b2b34308ec6abfd2d1b492536e361eb50f79 100644 (file)
@@ -423,17 +423,19 @@ return baseclass.extend({
                o.default = (dev ? dev.getName() : '').match(/^.+\.\d+$/) ? dev.getName().replace(/\.\d+$/, '') : '';
                o.ucioption = 'ifname';
                o.validate = function(section_id, value) {
-                       var type = this.section.formvalue(section_id, 'type'),
-                           name = this.section.getUIElement(section_id, 'name_complex');
+                       if (isNew) {
+                               var type = this.section.formvalue(section_id, 'type'),
+                                   name = this.section.getUIElement(section_id, 'name_complex');
 
-                       if (type == 'macvlan' && value && name && !name.isChanged()) {
-                               var i = 0;
+                               if (type == 'macvlan' && value && name && !name.isChanged()) {
+                                       var i = 0;
 
-                               while (deviceSectionExists(section_id, '%smac%d'.format(value, i)))
-                                       i++;
+                                       while (deviceSectionExists(section_id, '%smac%d'.format(value, i)))
+                                               i++;
 
-                               name.setValue('%smac%d'.format(value, i));
-                               name.triggerValidation();
+                                       name.setValue('%smac%d'.format(value, i));
+                                       name.triggerValidation();
+                               }
                        }
 
                        return true;