/[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 110 by dpavlin, Sun Aug 2 02:04:00 2009 UTC revision 146 by dpavlin, Wed Aug 5 12:45:29 2009 UTC
# Line 19  use IO::Socket::INET; Line 19  use IO::Socket::INET;
19  use File::Slurp;  use File::Slurp;
20  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
21  use Net::Ping;  use Net::Ping;
 use Module::Refresh;  
22    
23  use lib '..';  use lib '..';
24  use Net::DHCP::Packet;  use Net::DHCP::Packet;
# Line 57  sub client_ip { Line 56  sub client_ip {
56          my $prefix = $server::ip;          my $prefix = $server::ip;
57          $prefix =~ s{\.\d+$}{.};          $prefix =~ s{\.\d+$}{.};
58          my $ip = $prefix . $addr;          my $ip = $prefix . $addr;
59          while ( -e "conf/ip/$ip" || $p->ping( $ip ) ) {          while ( -e "$conf/ip/$ip" || $p->ping( $ip ) ) {
60                  $ip = $prefix . $addr++;                  $ip = $prefix . $addr++;
61                  die "all addresses allocated!" if $addr == $server::ip_to;                  die "all addresses allocated!" if $addr == $server::ip_to;
62          }          }
63    
64          write_file "$conf/mac/$mac", $ip;          write_file "$conf/mac/$mac", $ip;
65          if ( -l "$conf/ip/$ip" && readlink "$conf/ip/$ip" ne "$conf/mac/$mac") {  
66            if ( -l "$conf/ip/$ip" && readlink "$conf/ip/$ip" ne "$conf/mac/$mac" ) {
67                  unlink     "$conf/ip/$ip";                  unlink     "$conf/ip/$ip";
68                  symlink    "$conf/mac/$mac", "$conf/ip/$ip";                  warn "$mac IP changed from ", readlink "$conf/ip/$ip", " to $ip";
69                  warn "$mac IP changed to $ip";          };
70          }          symlink    "$conf/mac/$mac", "$conf/ip/$ip";
71    
72          print "$mac NEW $ip\n";          print "$mac NEW $ip\n";
73    
# Line 76  sub client_ip { Line 76  sub client_ip {
76    
77  use log;  use log;
78  use config;  use config;
79    use pxelinux;
80    
81  our $file;  our $file;
82  our $transaction = 0; # FIXME predictible transaction numbers  our $transaction = 0; # FIXME predictible transaction numbers
# Line 83  our $transaction = 0; # FIXME predictibl Line 84  our $transaction = 0; # FIXME predictibl
84  sub process_packet {  sub process_packet {
85          my $sock = shift;          my $sock = shift;
86    
87            server->refresh;
88    
89          my $buf;          my $buf;
90          $sock->recv($buf, 1024);          $sock->recv($buf, 1024);
91          my $size = 'empty';          my $size = 'empty';
# Line 126  sub process_packet { Line 129  sub process_packet {
129                  File    => $file,                  File    => $file,
130          };          };
131    
132            foreach my $opt ( 'magic', 'config_file', 'path_prefix', 'reboot_time' ) {
133                    my $DH0 = eval 'DHO_PXELINUX_' . uc $opt;
134                    warn "DH0: $@" if $@;
135                    my $v = eval "\$pxelinux::$opt";
136                    warn "v: $@" if $@;
137                    next unless defined $v;
138                    warn "pxelinux dhcp option $opt = $DH0 = $v";
139                    $packet->{ $DH0 } = $v;
140            }
141    
142          my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE());          my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE());
143    
144          if ($messagetype eq DHCPDISCOVER()) {          if ($messagetype eq DHCPDISCOVER()) {
# Line 141  sub process_packet { Line 154  sub process_packet {
154  #                       $packet->{DHO_DHCP_SERVER_IDENTIFIER()} = $server::ip;          # FIXME  #                       $packet->{DHO_DHCP_SERVER_IDENTIFIER()} = $server::ip;          # FIXME
155                          $packet->{DHO_SUBNET_MASK()}            = '255.255.255.0';                          $packet->{DHO_SUBNET_MASK()}            = '255.255.255.0';
156                          $packet->{DHO_ROUTERS()}                = $server::ip;                          $packet->{DHO_ROUTERS()}                = $server::ip;
157  #                       $packet->{DHO_DOMAIN_NAME()}            = 'pxelator.lan';                          $packet->{DHO_DOMAIN_NAME()}            = 'pxelator.lan';
158  #                       $packet->{DHO_NAME_SERVERS()}           = $server::ip;                          $packet->{DHO_NAME_SERVERS()}           = $server::ip;
159  #                       $packet->{DHO_ROOT_PATH()}              = '/exports/foobar';  #                       $packet->{DHO_ROOT_PATH()}              = '/exports/foobar';
160                  } else {                  } else {
161                          $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPNAK();                          $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPNAK();
# Line 156  sub process_packet { Line 169  sub process_packet {
169    
170          warn ">> $mac == $ip server: $server::ip", $file ? " file: $file\n" : "\n" if $debug;          warn ">> $mac == $ip server: $server::ip", $file ? " file: $file\n" : "\n" if $debug;
171    
172    warn "## created packet ", dump( $packet );
173    
174          $packet = new Net::DHCP::Packet( %$packet );          $packet = new Net::DHCP::Packet( %$packet );
175          warn "send ",$packet->toString() if $debug;          warn "send ",$packet->toString() if $debug;
176    
# Line 193  sub start { Line 208  sub start {
208          print "DHCP listen on ",$sock->sockhost,":",$sock->sockport,"\n";          print "DHCP listen on ",$sock->sockhost,":",$sock->sockport,"\n";
209    
210          while (1) {          while (1) {
                 Module::Refresh->refresh;  
211                  process_packet $sock;                  process_packet $sock;
212          }          }
213  }  }

Legend:
Removed from v.110  
changed lines
  Added in v.146

  ViewVC Help
Powered by ViewVC 1.1.26