Skip to content

Commit

Permalink
luci-mod-network: Make MAC check functions generic.
Browse files Browse the repository at this point in the history
Also remove a reassigned so.validate function (dead code).

Signed-off-by: Paul Donald <newtwen@gmail.com>
  • Loading branch information
systemcrash committed Nov 20, 2023
1 parent 1e9dcdf commit dbbe8f2
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@ function validateServerSpec(sid, s) {
return true;
}

function isValidMAC(sid, s) {
if (s == null || s == '')
return true;

var macaddrs = L.toArray(s);

for (var i = 0; i < macaddrs.length; i++)
if (!macaddrs[i].match(/^([a-fA-F0-9]{2}|\*):([a-fA-F0-9]{2}:|\*:){4}(?:[a-fA-F0-9]{2}|\*)$/))
return _('Expecting a valid MAC address, optionally including wildcards');

return true;
}

function validateMACAddr(pools, sid, s) {
if (s == null || s == '')
return true;
Expand Down Expand Up @@ -225,7 +238,7 @@ function validateMACAddr(pools, sid, s) {
}
}

return true;
return isValidMAC(sid, s);
}

return view.extend({
Expand Down Expand Up @@ -863,15 +876,6 @@ return view.extend({
_('The hardware address(es) of this entry/host, separated by spaces.') + '<br /><br />' +
_('In DHCPv4, it is possible to include more than one mac address. This allows an IP address to be associated with multiple macaddrs, and dnsmasq abandons a DHCP lease to one of the macaddrs when another asks for a lease. It only works reliably if only one of the macaddrs is active at any time.'));
//As a special case, in DHCPv4, it is possible to include more than one hardware address. eg: --dhcp-host=11:22:33:44:55:66,12:34:56:78:90:12,192.168.0.2 This allows an IP address to be associated with multiple hardware addresses, and gives dnsmasq permission to abandon a DHCP lease to one of the hardware addresses when another one asks for a lease
so.validate = function(section_id, value) {
var macaddrs = L.toArray(value);

for (var i = 0; i < macaddrs.length; i++)
if (!macaddrs[i].match(/^([a-fA-F0-9]{2}|\*):([a-fA-F0-9]{2}:|\*:){4}(?:[a-fA-F0-9]{2}|\*)$/))
return _('Expecting a valid MAC address, optionally including wildcards');

return true;
};
so.rmempty = true;
so.cfgvalue = function(section) {
var macs = L.toArray(uci.get('dhcp', section, 'mac')),
Expand Down

0 comments on commit dbbe8f2

Please sign in to comment.