/[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 153 by dpavlin, Wed Aug 5 23:22:17 2009 UTC revision 167 by dpavlin, Thu Aug 6 20:14:43 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 54  sub client_ip { Line 54  sub client_ip {
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    
58          while ( -e "$conf/ip/$ip" || $p->ping( $ip ) ) {          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;
# Line 61  sub client_ip { Line 62  sub client_ip {
62    
63          write_file "$conf/mac/$mac", $ip;          write_file "$conf/mac/$mac", $ip;
64    
65          if ( -l "$conf/ip/$ip" && readlink "$conf/ip/$ip" ne "$conf/mac/$mac" ) {          my $ip_path = "$conf/ip/$ip";
66                  unlink     "$conf/ip/$ip";          mkdir $ip_path unless -e $ip_path;
67                  warn "$mac IP changed from ", readlink "$conf/ip/$ip", " 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", "$conf/ip/$ip";          symlink "$conf/mac/$mac", "$ip_path/mac";
73    
74          print "$mac NEW $ip\n";          print "$mac NEW $ip\n";
75    
# Line 75  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 125  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 ) if $debug;
149    
150            my @missing;
151            foreach ( @requested ) {
152                    if ( defined $options->{$_} ) {
153                            $packet->{$_} = $options->{$_};
154                    } else {
155                            push @missing, $_;
156                    }
157            }
158    
159            warn "W: options requested but missing: ",dump( @missing );
160    
161          foreach my $opt ( 'magic', 'config_file', 'path_prefix', 'reboot_time' ) {          foreach my $opt ( 'magic', 'config_file', 'path_prefix', 'reboot_time' ) {
162                  my $DH0 = eval 'DHO_PXELINUX_' . uc $opt;                  my $DH0 = eval 'DHO_PXELINUX_' . uc $opt;
163                  warn "DH0: $@" if $@;                  warn "DH0: $@" if $@;
164                  my $v = eval "\$pxelinux::$opt";                  my $v = eval "\$pxelinux::$opt";
165                  warn "v: $@" if $@;                  warn "v: $@" if $@;
166                  next unless defined $v;                  next unless defined $v;
167                  warn "pxelinux dhcp option $opt = $DH0 = $v";                  warn "pxelinux dhcp option $opt = $DH0 = $v\n" if $debug;
168                  $packet->{ $DH0 } = $v;                  $packet->{ $DH0 } = $v;
169          }          }
170    
# Line 149  sub process_packet { Line 180  sub process_packet {
180                  if ( $ip eq $requested_ip ) {                  if ( $ip eq $requested_ip ) {
181                          $packet->{DHO_DHCP_MESSAGE_TYPE()}      = DHCPACK();                          $packet->{DHO_DHCP_MESSAGE_TYPE()}      = DHCPACK();
182                          $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;  
183  #                       $packet->{DHO_ROOT_PATH()}              = '/exports/foobar';  #                       $packet->{DHO_ROOT_PATH()}              = '/exports/foobar';
184                  } else {                  } else {
185                          $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPNAK();                          $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPNAK();
# Line 167  sub process_packet { Line 193  sub process_packet {
193    
194          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;
195    
 warn "## created packet ", dump( $packet );  
   
196          $packet = new Net::DHCP::Packet( %$packet );          $packet = new Net::DHCP::Packet( %$packet );
197          warn "send ",$packet->toString() if $debug;          warn "send ",$packet->toString() if $debug;
198    

Legend:
Removed from v.153  
changed lines
  Added in v.167

  ViewVC Help
Powered by ViewVC 1.1.26