luci-mod-network: issue with breakdown of dnsmasq after duplication of static IP... 4709/head
authorOleksandr Pastushkov <oleks.pastushkov@gmail.com>
Sun, 3 Jan 2021 22:58:56 +0000 (00:58 +0200)
committerOleksandr Pastushkov <oleks.pastushkov@gmail.com>
Mon, 4 Jan 2021 00:07:45 +0000 (02:07 +0200)
Before this commit, assigning the same static IP address to two
different hosts disabled dnsmasq.

Logic of adding a new static lease was modified. If user try to assign a
new MAC address to already reserved IP, old lease will be modified (list
of MAC addresses will be extended by new MAC) instead of creation a new lease with the same IP.

Signed-off-by: Oleksandr Pastushkov <oleks.pastushkov@gmail.com>
modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js

index 541c2fca1b8e42302b87ade25967f2f7421f9c8e..bfc4d176860690c221d93d4918523d7b0a52a86e 100644 (file)
@@ -469,6 +469,25 @@ return view.extend({
                        so.value(mac, hint ? '%s (%s)'.format(mac, hint) : mac);
                });
 
+               so.write = function(section, value) {
+                       var ip = this.map.lookupOption('ip', section)[0].formvalue(section);
+                       var hosts = uci.sections('dhcp', 'host');
+                       var section_removed = false;
+
+                       for (var i = 0; i < hosts.length; i++) {
+                               if (ip == hosts[i].ip) {
+                                       uci.set('dhcp', hosts[i]['.name'], 'mac', [hosts[i].mac, value].join(' '));
+                                       uci.remove('dhcp', section);
+                                       section_removed = true;
+                                       break;
+                               }
+                       }
+
+                       if (!section_removed) {
+                               uci.set('dhcp', section, 'mac', value);
+                       }
+               }
+
                so = ss.option(form.Value, 'ip', _('<abbr title="Internet Protocol Version 4">IPv4</abbr>-Address'));
                so.datatype = 'or(ip4addr,"ignore")';
                so.validate = function(section, value) {