--- bin/dhcpd.pl 2009/07/26 15:16:52 6 +++ bin/dhcpd.pl 2009/07/27 22:18:51 12 @@ -14,8 +14,7 @@ my $debug = shift @ARGV; -our ( $server_ip, $next_file ); -require "config.pl"; +our ( $server_ip, $file, $next_file ); my $sock = IO::Socket::INET->new( LocalPort => 67, @@ -38,7 +37,8 @@ my $ip = $_mac2ip->{$mac}; return $ip if $ip; - $ip = "10.0.0.$_ip"; + $ip = $server_ip; + $ip =~ s{\.\d+$}{.$_ip}; $_mac2ip->{$mac} = $ip; $_ip++; @@ -52,6 +52,8 @@ while (1) { + require "config.pl"; # refresh config + print "waiting for DHCP requests on ",$sock->sockhost,":",$sock->sockport,"\n"; my $buf; @@ -72,8 +74,13 @@ my $mac = substr($dhcp->chaddr(),0,$dhcp->hlen()*2); my $ip = client_ip($mac); - my $file = $next_file; - $file = 'undionly.kpxe' if ! $file || $dhcp->getOptionValue(DHO_USER_CLASS()) ne 'gPXE'; + if ( ! $file ) { + if ( $dhcp->getOptionValue(DHO_USER_CLASS()) ne 'gPXE' ) { + $file = 'undionly.kpxe'; + } else { + $file = $next_file; + } + } my $packet = new Net::DHCP::Packet( Op => BOOTREPLY(),