Better host clash checking
authorJamie Cameron <jcameron@webmin.com>
Fri, 6 Aug 2010 07:51:58 +0000 (00:51 -0700)
committerJamie Cameron <jcameron@webmin.com>
Fri, 6 Aug 2010 07:51:58 +0000 (00:51 -0700)
dhcpd/CHANGELOG
dhcpd/dhcpd-lib.pl
dhcpd/save_host.cgi

index 61fc25c..7975fcc 100644 (file)
@@ -38,3 +38,4 @@ When applying the configuration fails with an error mentioning a line in the con
 ---- Changes since 1.510 ----
 Added support for multi-value options, thanks to a patch from Luke Suchocki.
 Also added support for multi-value options within a bracketed expression.
+Hostname, IP address and MAC address clashes are now only checked for in the same shared network.
index 0117834..c0afd89 100755 (executable)
@@ -593,6 +593,32 @@ local ($sr, $hr) = &get_subnets_and_hosts();
 return @{$hr};
 }
 
+sub get_host_shared_network
+{
+local ($h) = @_;
+local $shar;
+while($h) {
+       if ($h->{'name'} eq 'shared-network') {
+               return $h;
+               }
+       $h = $h->{'parent'};
+       }
+return undef;
+}
+
+sub get_my_shared_network_hosts
+{
+local ($h) = @_;
+local $shar = &get_host_shared_network($h);
+local @rv;
+foreach my $oh (&get_hosts()) {
+       if (&get_host_shared_network($oh) eq $shar) {
+               push(@rv, $oh);
+               }
+       }
+return @rv;
+}
+
 # hash that links objtypes shortcuts with object names
 %obj_names2types = qw(host hst group grp subnet sub shared-network sha);
 
index 2d84217..b6a1ff3 100755 (executable)
@@ -55,7 +55,7 @@ else {
        # Check for a hostname clash
        if (($in{'new'} || $in{'name'} ne $host->{'values'}->[0]) &&
            $access{'uniq_hst'}) {
-               foreach $h (&get_hosts()) {
+               foreach $h (&get_my_shared_network_hosts($npar)) {
                         &error("$text{'eacl_np'} $text{'eacl_uniq'}")
                                 if (lc($h->{'values'}->[0]) eq lc($in{'name'}));
                         }
@@ -68,7 +68,7 @@ else {
                                      : &find("hardware", $host->{'members'});
                if ((!$oldhard || $in{'hardware'} ne $oldhard->{'values'}->[1])
                    && $access{'uniq_hst'}) {
-                       foreach $h (&get_hosts()) {
+                       foreach $h (&get_my_shared_network_hosts($npar)) {
                                $chard = &find("hardware", $h->{'members'});
                                &error("$text{'eacl_np'} $text{'eacl_uniqh'}")
                                        if ($chard && lc($chard->{'values'}->[1]) eq lc($in{'hardware'}));
@@ -96,7 +96,7 @@ else {
                if ((!$oldfixed ||
                    $in{'fixed-address'} ne $oldfixed->{'values'}->[0])
                    && $access{'uniq_hst'}) {
-                       foreach $h (&get_hosts()) {
+                       foreach $h (&get_my_shared_network_hosts($npar)) {
                                $cfixed = &find("fixed-address",
                                                $h->{'members'});
                                &error("$text{'eacl_np'} $text{'eacl_uniqi'}")