/[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 129 by dpavlin, Mon Aug 3 20:53:46 2009 UTC revision 160 by dpavlin, Thu Aug 6 18:09:17 2009 UTC
# Line 40  my $addr = $server::ip_from; Line 40  my $addr = $server::ip_from;
40  sub client_ip {  sub client_ip {
41          my ( $mac ) = @_;          my ( $mac ) = @_;
42    
43          my $conf = "$server::base_dir/conf/$server::ip";          my $conf = $server::conf;
44          mkdir $conf unless -e $conf;          mkdir $conf unless -e $conf;
45    
46          if ( -e "$conf/mac/$mac" ) {          if ( -e "$conf/mac/$mac" ) {
# Line 49  sub client_ip { Line 49  sub client_ip {
49                  return $ip;                  return $ip;
50          }          }
51    
         mkdir $_ foreach grep { ! -e $_ } map { "$conf/$_" } ( 'ip', 'mac' );  
   
52          my $p = Net::Ping->new;          my $p = Net::Ping->new;
53    
54          my $prefix = $server::ip;          my $prefix = $server::ip;
55          $prefix =~ s{\.\d+$}{.};          $prefix =~ s{\.\d+$}{.};
56          my $ip = $prefix . $addr;          my $ip = $prefix . $addr;
57          while ( -e "conf/ip/$ip" || $p->ping( $ip ) ) {  
58            while ( -e "$conf/ip/$ip" || $p->ping( $ip ) ) {
59                  $ip = $prefix . $addr++;                  $ip = $prefix . $addr++;
60                  die "all addresses allocated!" if $addr == $server::ip_to;                  die "all addresses allocated!" if $addr == $server::ip_to;
61          }          }
62    
63          write_file "$conf/mac/$mac", $ip;          write_file "$conf/mac/$mac", $ip;
64          if ( -l "$conf/ip/$ip" && readlink "$conf/ip/$ip" ne "$conf/mac/$mac") {  
65                  unlink     "$conf/ip/$ip";          my $ip_path = "$conf/ip/$ip";
66                  symlink    "$conf/mac/$mac", "$conf/ip/$ip";          mkdir $ip_path unless -e $ip_path;
67                  warn "$mac IP changed to $ip";  
68          }          if ( -l "$ip_path/mac" && readlink "$ip_path/mac" ne "$conf/mac/$mac" ) {
69                    warn "$mac IP changed from ", readlink "$ip_path/mac", " to $ip";
70                    unlink "$ip_path/mac";
71            };
72            symlink "$conf/mac/$mac", "$ip_path/mac";
73    
74          print "$mac NEW $ip\n";          print "$mac NEW $ip\n";
75    
# Line 76  sub client_ip { Line 79  sub client_ip {
79  use log;  use log;
80  use config;  use config;
81  use pxelinux;  use pxelinux;
82    use client;
83    
84  our $file;  our $file;
85  our $transaction = 0; # FIXME predictible transaction numbers  our $transaction = 0; # FIXME predictible transaction numbers
# Line 126  sub process_packet { Line 130  sub process_packet {
130                  Giaddr  => $dhcp->giaddr(),                  Giaddr  => $dhcp->giaddr(),
131                  Chaddr  => $dhcp->chaddr(),                  Chaddr  => $dhcp->chaddr(),
132                  File    => $file,                  File    => $file,
133                    DHO_DHCP_SERVER_IDENTIFIER()    => $server::ip, # busybox/udhcpc needs it but doesn't request
134          };          };
135    
136            my $options = {
137                    DHO_SUBNET_MASK()       => $server::netmask,
138                    DHO_ROUTERS()           => $server::ip,
139                    DHO_DOMAIN_NAME()       => $server::domain_name,
140                    DHO_NAME_SERVERS()      => $server::ip,
141                    DHO_DOMAIN_NAME_SERVERS() => $server::ip,
142                    DHO_HOST_NAME()         => client::conf( $ip, 'hostname' ),
143                    DHO_BROADCAST_ADDRESS() => $server::bcast,
144    #               DHO_NTP_SERVERS() => '',
145            };
146    
147            my @requested = split(/\s/, $dhcp->getOptionValue(DHO_DHCP_PARAMETER_REQUEST_LIST));
148            warn "options ",dump( $options ), ' requested: ',dump( @requested );
149            foreach ( @requested ) {
150                    $packet->{$_} = $options->{$_} if defined $options->{$_};
151            }
152    
153          foreach my $opt ( 'magic', 'config_file', 'path_prefix', 'reboot_time' ) {          foreach my $opt ( 'magic', 'config_file', 'path_prefix', 'reboot_time' ) {
154                  my $DH0 = eval 'DHO_PXELINUX_' . uc $opt;                  my $DH0 = eval 'DHO_PXELINUX_' . uc $opt;
155                  warn "DH0: $@" if $@;                  warn "DH0: $@" if $@;
# Line 150  sub process_packet { Line 172  sub process_packet {
172                  if ( $ip eq $requested_ip ) {                  if ( $ip eq $requested_ip ) {
173                          $packet->{DHO_DHCP_MESSAGE_TYPE()}      = DHCPACK();                          $packet->{DHO_DHCP_MESSAGE_TYPE()}      = DHCPACK();
174                          $packet->{DHO_DHCP_LEASE_TIME()}        = 5 * 60; # 5 min                          $packet->{DHO_DHCP_LEASE_TIME()}        = 5 * 60; # 5 min
 #                       $packet->{DHO_DHCP_SERVER_IDENTIFIER()} = $server::ip;          # FIXME  
                         $packet->{DHO_SUBNET_MASK()}            = '255.255.255.0';  
                         $packet->{DHO_ROUTERS()}                = $server::ip;  
 #                       $packet->{DHO_DOMAIN_NAME()}            = 'pxelator.lan';  
 #                       $packet->{DHO_NAME_SERVERS()}           = $server::ip;  
175  #                       $packet->{DHO_ROOT_PATH()}              = '/exports/foobar';  #                       $packet->{DHO_ROOT_PATH()}              = '/exports/foobar';
176                  } else {                  } else {
177                          $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPNAK();                          $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPNAK();
# Line 166  sub process_packet { Line 183  sub process_packet {
183                  log::mac $mac, "$messagetype igored (bootp?)";                  log::mac $mac, "$messagetype igored (bootp?)";
184          }          }
185    
186          warn ">> $mac == $ip server: $server::ip", $file ? " file: $file\n" : "\n" if $debug;          warn "packet ",dump( $packet );
187    
188  warn "## created packet ", dump( $packet );          warn ">> $mac == $ip server: $server::ip", $file ? " file: $file\n" : "\n" if $debug;
189    
190          $packet = new Net::DHCP::Packet( %$packet );          $packet = new Net::DHCP::Packet( %$packet );
191          warn "send ",$packet->toString() if $debug;          warn "send ",$packet->toString() if $debug;

Legend:
Removed from v.129  
changed lines
  Added in v.160

  ViewVC Help
Powered by ViewVC 1.1.26