--- lib/PXElator/dhcpd.pm 2009/08/05 23:22:17 153 +++ lib/PXElator/dhcpd.pm 2009/08/06 15:15:53 156 @@ -40,7 +40,7 @@ sub client_ip { my ( $mac ) = @_; - my $conf = "$server::base_dir/conf/$server::ip"; + my $conf = $server::conf; mkdir $conf unless -e $conf; if ( -e "$conf/mac/$mac" ) { @@ -54,6 +54,7 @@ my $prefix = $server::ip; $prefix =~ s{\.\d+$}{.}; my $ip = $prefix . $addr; + while ( -e "$conf/ip/$ip" || $p->ping( $ip ) ) { $ip = $prefix . $addr++; die "all addresses allocated!" if $addr == $server::ip_to; @@ -61,11 +62,14 @@ write_file "$conf/mac/$mac", $ip; - if ( -l "$conf/ip/$ip" && readlink "$conf/ip/$ip" ne "$conf/mac/$mac" ) { - unlink "$conf/ip/$ip"; - warn "$mac IP changed from ", readlink "$conf/ip/$ip", " to $ip"; + my $ip_path = "$conf/ip/$ip"; + mkdir $ip_path unless -e $ip_path; + + if ( -l "$ip_path/mac" && readlink "$ip_path/mac" ne "$conf/mac/$mac" ) { + warn "$mac IP changed from ", readlink "$ip_path/mac", " to $ip"; + unlink "$ip_path/mac"; }; - symlink "$conf/mac/$mac", "$conf/ip/$ip"; + symlink "$conf/mac/$mac", "$ip_path/mac"; print "$mac NEW $ip\n";