/[pxelator]/lib/PXElator/dhcpd.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/PXElator/dhcpd.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 45 by dpavlin, Wed Jul 29 22:04:58 2009 UTC revision 69 by dpavlin, Thu Jul 30 22:44:21 2009 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  package dhcpd;
2    
3  =head1 dhcpd  =head1 dhcpd
4    
# Line 26  use Net::DHCP::Packet; Line 26  use Net::DHCP::Packet;
26  use Net::DHCP::Constants 0.67;  use Net::DHCP::Constants 0.67;
27    
28  use server;  use server;
29    my $debug = server::debug;
30  use pxe;  use pxe;
31    
 my $debug = 1;  
   
32  if ( ! $server::ip ) {  if ( ! $server::ip ) {
33          my $server_ip = `/sbin/ifconfig`;          my $server_ip = `/sbin/ifconfig`;
34          $server_ip =~ s/^.+?addr:([\d\.]+).*$/$1/gs;          $server_ip =~ s/^.+?addr:([\d\.]+).*$/$1/gs;
# Line 43  my $addr = $server::ip_from; Line 42  my $addr = $server::ip_from;
42  sub client_ip {  sub client_ip {
43          my ( $mac ) = @_;          my ( $mac ) = @_;
44    
45          my $conf = "conf/$server::ip";          my $conf = "$server::base_dir/conf/$server::ip";
46          mkdir $conf unless -e $conf;          mkdir $conf unless -e $conf;
47    
48          if ( -e "$conf/mac/$mac" ) {          if ( -e "$conf/mac/$mac" ) {
# Line 92  sub process_packet { Line 91  sub process_packet {
91          my $dhcp = Net::DHCP::Packet->new($buf);          my $dhcp = Net::DHCP::Packet->new($buf);
92          $dhcp->comment( $transaction++ );          $dhcp->comment( $transaction++ );
93    
94          warn "recv: ", $dhcp->toString;          warn "recv: ", $dhcp->toString if $debug;
95    
96          my $mac = substr($dhcp->chaddr(),0,$dhcp->hlen()*2);          my $mac = substr($dhcp->chaddr(),0,$dhcp->hlen()*2);
97          my $ip = client_ip($mac);          my $ip = client_ip($mac);
# Line 122  sub process_packet { Line 121  sub process_packet {
121                  File    => $pxe::file,                  File    => $pxe::file,
122          };          };
123    
124            pxe::config_for_ip( $ip );
125    
126          my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE());          my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE());
127    
128          if ($messagetype eq DHCPDISCOVER()) {          if ($messagetype eq DHCPDISCOVER()) {
# Line 153  sub process_packet { Line 154  sub process_packet {
154          warn ">> $mac == $ip server: $server::ip", $pxe::file ? " pxe file: $pxe::file\n" : "\n";          warn ">> $mac == $ip server: $server::ip", $pxe::file ? " pxe file: $pxe::file\n" : "\n";
155    
156          $packet = new Net::DHCP::Packet( %$packet );          $packet = new Net::DHCP::Packet( %$packet );
157          warn "## ",$packet->toString(),"\n" if $debug;          warn "send ",$packet->toString() if $debug;
158    
159          my $reply = IO::Socket::INET->new(          my $reply = IO::Socket::INET->new(
160                  LocalAddr => $server::ip,                  LocalAddr => $server::ip,

Legend:
Removed from v.45  
changed lines
  Added in v.69

  ViewVC Help
Powered by ViewVC 1.1.26