/[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 201 by dpavlin, Tue Aug 11 23:38:53 2009 UTC revision 207 by dpavlin, Wed Aug 12 22:56:45 2009 UTC
# Line 23  use lib '..'; Line 23  use lib '..';
23  use Net::DHCP::Packet;  use Net::DHCP::Packet;
24  use Net::DHCP::Constants 0.67;  use Net::DHCP::Constants 0.67;
25    
26    use CouchDB;
27    
28  use server;  use server;
29  my $debug = server::debug;  my $debug = server::debug;
30    
# Line 87  sub process_packet { Line 89  sub process_packet {
89          my $hostname = $dhcp->getOptionValue(DHO_HOST_NAME);          my $hostname = $dhcp->getOptionValue(DHO_HOST_NAME);
90          print "$ip ", client::conf( $ip => 'hostname', default => $hostname ), " >> /etc/hosts\n";          print "$ip ", client::conf( $ip => 'hostname', default => $hostname ), " >> /etc/hosts\n";
91    
92            my $audit = { mac => $mac, ip => $ip, hostname => $hostname };
93            CouchDB::audit( 'request', $audit );
94    
95  =for later  =for later
96    
97          my $user_class = $dhcp->getOptionValue(DHO_USER_CLASS());          my $user_class = $dhcp->getOptionValue(DHO_USER_CLASS());
# Line 139  sub process_packet { Line 144  sub process_packet {
144          }          }
145    
146          warn "W: options requested but missing: ",dump( @missing ),$/;          warn "W: options requested but missing: ",dump( @missing ),$/;
147            $audit->{requested} = [ @requested ];
148            $audit->{missing}   = [ @missing   ];
149    
150          foreach my $opt ( 'magic', 'config_file', 'path_prefix', 'reboot_time' ) {          foreach my $opt ( 'magic', 'config_file', 'path_prefix', 'reboot_time' ) {
151                  my $DH0 = eval 'DHO_PXELINUX_' . uc $opt;                  my $DH0 = eval 'DHO_PXELINUX_' . uc $opt;
# Line 153  sub process_packet { Line 160  sub process_packet {
160          my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE());          my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE());
161    
162          if ($messagetype eq DHCPDISCOVER()) {          if ($messagetype eq DHCPDISCOVER()) {
163                  log::mac $mac, "DHCP DISCOVER";                  $audit->{type} = 'discover';
164                  $packet->{Comment} = $dhcp->comment();                  $packet->{Comment} = $dhcp->comment();
165                  $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPOFFER();                  $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPOFFER();
166          } elsif ($messagetype eq DHCPREQUEST()) {          } elsif ($messagetype eq DHCPREQUEST()) {
167                  my $requested_ip = $dhcp->getOptionValue(DHO_DHCP_REQUESTED_ADDRESS());                  my $requested_ip = $dhcp->getOptionValue(DHO_DHCP_REQUESTED_ADDRESS());
168                  log::mac $mac, "DHCP REQUEST $requested_ip $ip $file";                  $audit->{type} = 'request';
169                  if ( $ip eq $requested_ip ) {                  if ( $ip eq $requested_ip ) {
170                          $packet->{DHO_DHCP_MESSAGE_TYPE()}      = DHCPACK();                          $packet->{DHO_DHCP_MESSAGE_TYPE()}      = DHCPACK();
171                          $packet->{DHO_DHCP_LEASE_TIME()}        = 5 * 60; # 5 min                          $packet->{DHO_DHCP_LEASE_TIME()}        = 5 * 60; # 5 min
# Line 168  sub process_packet { Line 175  sub process_packet {
175                          $packet->{DHO_DHCP_MESSAGE()} = "Bad request, expected $ip";                          $packet->{DHO_DHCP_MESSAGE()} = "Bad request, expected $ip";
176                  }                  }
177          } elsif ($messagetype eq DHCPINFORM()) {          } elsif ($messagetype eq DHCPINFORM()) {
178                  log::mac $mac, "DHCP INFORM ignored";                  $audit->{type} = 'inform';
179          } else {          } else {
180                  log::mac $mac, "$messagetype igored (bootp?)";                  $audit->{type} = sprintf('ignored %x', $messagetype);
181          }          }
182    
183          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;
184            $audit->{response} = $packet;
185    
186          $packet = new Net::DHCP::Packet( %$packet );          $packet = new Net::DHCP::Packet( %$packet );
187          warn "send ",$packet->toString() if $debug;          warn "send ",$packet->toString() if $debug;
188    
189            CouchDB::audit( 'response', $audit );
190    
191          my $reply = IO::Socket::INET->new(          my $reply = IO::Socket::INET->new(
192                  LocalAddr => $server::ip,                  LocalAddr => $server::ip,
193                  LocalPort => 67,                  LocalPort => 67,
# Line 211  sub start { Line 221  sub start {
221    
222          print "DHCP listen on ",$sock->sockhost,":",$sock->sockport,"\n";          print "DHCP listen on ",$sock->sockhost,":",$sock->sockport,"\n";
223    
224            CouchDB::audit( 'start', { 'listen' => { addr => $sock->sockhost, port => $sock->sockport } } );
225    
226          while (1) {          while (1) {
227                  process_packet $sock;                  process_packet $sock;
228          }          }

Legend:
Removed from v.201  
changed lines
  Added in v.207

  ViewVC Help
Powered by ViewVC 1.1.26