From aea69f68f12695a4b5f85e235a21ec2f3a4679f4 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Fri, 6 Aug 2010 00:51:58 -0700 Subject: [PATCH] Better host clash checking --- dhcpd/CHANGELOG | 1 + dhcpd/dhcpd-lib.pl | 26 ++++++++++++++++++++++++++ dhcpd/save_host.cgi | 6 +++--- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/dhcpd/CHANGELOG b/dhcpd/CHANGELOG index 61fc25c50..7975fcc19 100644 --- a/dhcpd/CHANGELOG +++ b/dhcpd/CHANGELOG @@ -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. diff --git a/dhcpd/dhcpd-lib.pl b/dhcpd/dhcpd-lib.pl index 011783466..c0afd8979 100755 --- a/dhcpd/dhcpd-lib.pl +++ b/dhcpd/dhcpd-lib.pl @@ -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); diff --git a/dhcpd/save_host.cgi b/dhcpd/save_host.cgi index 2d8421736..b6a1ff3b8 100755 --- a/dhcpd/save_host.cgi +++ b/dhcpd/save_host.cgi @@ -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'}")