/[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 413 by dpavlin, Wed Sep 9 14:27:02 2009 UTC revision 428 by dpavlin, Sun Sep 13 10:53:41 2009 UTC
# Line 79  our $transaction = 0; # FIXME predictibl Line 79  our $transaction = 0; # FIXME predictibl
79  sub process_packet {  sub process_packet {
80          my $sock = shift;          my $sock = shift;
81    
         server->refresh;  
   
82          my $buf;          my $buf;
83          $sock->recv($buf, 1024);          $sock->recv($buf, 1024);
84          my $size = 'empty';          my $size = 'empty';
# Line 176  sub process_packet { Line 174  sub process_packet {
174    
175          my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE());          my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE());
176    
177            my @type;
178    
179          if ($messagetype eq DHCPDISCOVER()) {          if ($messagetype eq DHCPDISCOVER()) {
                 $audit->{type} = 'discover';  
180                  $packet->{Comment} = $dhcp->comment();                  $packet->{Comment} = $dhcp->comment();
181                  $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPOFFER();                  $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPOFFER();
182                    @type = qw( discover offer );
183          } elsif ($messagetype eq DHCPREQUEST()) {          } elsif ($messagetype eq DHCPREQUEST()) {
184                  my $requested_ip = $dhcp->getOptionValue(DHO_DHCP_REQUESTED_ADDRESS());                  @type = qw( request );
185                  $audit->{type} = 'request';                  my $requested_ip = $dhcp->getOptionValue(DHO_DHCP_REQUESTED_ADDRESS()) || $dhcp->ciaddr();
186                  if ( $ip eq $requested_ip ) {                  if ( $ip eq $requested_ip ) {
187                          $packet->{DHO_DHCP_MESSAGE_TYPE()}      = DHCPACK();                          $packet->{DHO_DHCP_MESSAGE_TYPE()}      = DHCPACK();
188                          $packet->{DHO_DHCP_LEASE_TIME()}        = 5 * 60; # 5 min                          $packet->{DHO_DHCP_LEASE_TIME()}        = 5 * 60; # 5 min
189  #                       $packet->{DHO_ROOT_PATH()}              = '/exports/foobar';  #                       $packet->{DHO_ROOT_PATH()}              = '/exports/foobar';
190                            $type[1] = 'ack';
191                  } else {                  } else {
192                          $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPNAK();                          $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPNAK();
193                          $packet->{DHO_DHCP_MESSAGE()} = "Bad request, expected $ip";                          $packet->{DHO_DHCP_MESSAGE()} = "Bad request, expected $ip got $requested_ip";
194                            $type[1] = 'nak';
195                  }                  }
196          } elsif ($messagetype eq DHCPINFORM()) {          } elsif ($messagetype eq DHCPINFORM()) {
197                  $audit->{type} = 'inform';                  @type = qw( inform ignored );
198          } else {          } else {
199                  $audit->{type} = sprintf('ignored %x', $messagetype);                  @type = ( $messagetype, 'ignored' );
200          }          }
201    
202          warn ">> $mac == $ip server: $server::ip", $file ? " file: $file\n" : "\n" if $debug;          warn "# type ",dump @type;
203            $audit->{type} = [ @type ];
204    
205          $audit->{response} = $packet;          $audit->{response} = $packet;
206    
207          $packet = new Net::DHCP::Packet( %$packet );          $packet = new Net::DHCP::Packet( %$packet );
# Line 211  sub process_packet { Line 215  sub process_packet {
215                          LocalPort => 67,                          LocalPort => 67,
216                          Proto => "udp",                          Proto => "udp",
217                          Broadcast => 1,                          Broadcast => 1,
218                          PeerAddr => '255.255.255.255',  #                       PeerAddr => '255.255.255.255',
219                            PeerAddr => $server::bcast,
220                          PeerPort => 68,                          PeerPort => 68,
221                          Reuse => 1,                          Reuse => 1,
222                  ) or die "socket: $@";                  ) or die "socket: $@";
223    
224                  $reply->send( $buff, 0 ) or die "Error sending: $!\n";                  $reply->send( $buff, 0 ) or die "Error sending: $!\n";
225                    warn ">> $mac == $ip server: $server::ip", $file ? " file: $file\n" : "\n";
226          } else {          } else {
227                  $audit->{error} = "$ip our of our range $server::ip $server::netmask";                  $audit->{error} = "$ip our of our range $server::ip $server::netmask";
228                  warn $audit->{error};                  warn $audit->{error};
229          }          }
230    
231          CouchDB::audit( $audit->{type}, $audit );          CouchDB::audit( @type, $audit );
232    
233  #       system("arp -s $ip $mac"),  #       system("arp -s $ip $mac"),
234    
# Line 247  sub start { Line 253  sub start {
253          CouchDB::audit( 'start', { addr => $sock->sockhost, port => $sock->sockport } );          CouchDB::audit( 'start', { addr => $sock->sockhost, port => $sock->sockport } );
254    
255          while (1) {          while (1) {
256                    server->refresh;
257                  process_packet $sock;                  process_packet $sock;
258          }          }
259  }  }

Legend:
Removed from v.413  
changed lines
  Added in v.428

  ViewVC Help
Powered by ViewVC 1.1.26