cleanup $file and move it to dhcpd, added config::ip_for to refresh it
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 2 Aug 2009 02:04:00 +0000 (02:04 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 2 Aug 2009 02:04:00 +0000 (02:04 +0000)
lib/PXElator/config.pm
lib/PXElator/dhcpd.pm
lib/PXElator/tftpd.pm

index 0c42481..3910e72 100644 (file)
@@ -18,4 +18,10 @@ sub shared {
        return $value;
 }
 
+sub for_ip {
+       my $ip = shift;
+       $tftp::dir = "$server::base_dir/tftp/live-helper/tftpboot";
+       $dhcpd::file = "pxelinux.0";
+}
+
 1;
index 0c41be5..20ee6e4 100644 (file)
@@ -27,7 +27,6 @@ use Net::DHCP::Constants 0.67;
 
 use server;
 my $debug = server::debug;
-use pxe;
 
 if ( ! $server::ip ) {
        my $server_ip = `/sbin/ifconfig`;
@@ -35,7 +34,7 @@ if ( ! $server::ip ) {
        $server::ip = $server_ip;
 }
 
-warn "server ip $server::ip file: $pxe::file range: $server::ip_from - $server::ip_to\n";
+warn "server ip $server::ip range: $server::ip_from - $server::ip_to\n";
 
 my $addr = $server::ip_from;
 
@@ -75,6 +74,10 @@ sub client_ip {
        return $ip;
 }
 
+use log;
+use config;
+
+our $file;
 our $transaction = 0; # FIXME predictible transaction numbers
 
 sub process_packet {
@@ -108,6 +111,8 @@ sub process_packet {
 
 =cut
 
+       config::for_ip( $ip );
+
        my $packet = {
                Op              => BOOTREPLY(),
                Hops    => $dhcp->hops(),
@@ -118,11 +123,9 @@ sub process_packet {
                Siaddr  => $server::ip,
                Giaddr  => $dhcp->giaddr(),
                Chaddr  => $dhcp->chaddr(),
-               File    => $pxe::file,
+               File    => $file,
        };
 
-       pxe::config_for_ip( $ip );
-
        my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE());
 
        if ($messagetype eq DHCPDISCOVER()) {
@@ -131,7 +134,7 @@ sub process_packet {
                $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPOFFER();
        } elsif ($messagetype eq DHCPREQUEST()) {
                my $requested_ip = $dhcp->getOptionValue(DHO_DHCP_REQUESTED_ADDRESS());
-               log::mac $mac, "DHCP REQUEST $requested_ip $ip $pxe::file";
+               log::mac $mac, "DHCP REQUEST $requested_ip $ip $file";
                if ( $ip eq $requested_ip ) {
                        $packet->{DHO_DHCP_MESSAGE_TYPE()}      = DHCPACK();
                        $packet->{DHO_DHCP_LEASE_TIME()}        = 5 * 60; # 5 min
@@ -151,7 +154,7 @@ sub process_packet {
                log::mac $mac, "$messagetype igored (bootp?)";
        }
 
-       warn ">> $mac == $ip server: $server::ip", $pxe::file ? " pxe file: $pxe::file\n" : "\n" if $debug;
+       warn ">> $mac == $ip server: $server::ip", $file ? " file: $file\n" : "\n" if $debug;
 
        $packet = new Net::DHCP::Packet( %$packet );
        warn "send ",$packet->toString() if $debug;
index 59fc938..ae2fac3 100644 (file)
@@ -41,6 +41,8 @@ sub tftp_request {
 
        warn 'request: ', dump( $request ) if $debug;
 
+       config::for_ip();
+
        if ( $request->{RootDir} ne $dir ) {
                $request->{RootDir} = $dir;
                warn "new root: $dir";