fix dhcp client address so we don't send nak any more when client allready
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 12 Sep 2009 22:18:34 +0000 (22:18 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 12 Sep 2009 22:18:34 +0000 (22:18 +0000)
knows his ip address

create two element type which include message type from request and response

lib/PXElator/dhcpd.pm

index 196e248..ac96512 100644 (file)
@@ -176,27 +176,34 @@ sub process_packet {
 
        my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE());
 
+       my @type;
+
        if ($messagetype eq DHCPDISCOVER()) {
-               $audit->{type} = 'discover';
                $packet->{Comment} = $dhcp->comment();
                $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPOFFER();
+               @type = qw( discover offser );
        } elsif ($messagetype eq DHCPREQUEST()) {
-               my $requested_ip = $dhcp->getOptionValue(DHO_DHCP_REQUESTED_ADDRESS());
-               $audit->{type} = 'request';
+               @type = qw( request );
+               my $requested_ip = $dhcp->getOptionValue(DHO_DHCP_REQUESTED_ADDRESS()) || $dhcp->ciaddr();
                if ( $ip eq $requested_ip ) {
                        $packet->{DHO_DHCP_MESSAGE_TYPE()}      = DHCPACK();
                        $packet->{DHO_DHCP_LEASE_TIME()}        = 5 * 60; # 5 min
 #                      $packet->{DHO_ROOT_PATH()}              = '/exports/foobar';
+                       $type[1] = 'ack';
                } else {
                        $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPNAK();
-                       $packet->{DHO_DHCP_MESSAGE()} = "Bad request, expected $ip";
+                       $packet->{DHO_DHCP_MESSAGE()} = "Bad request, expected $ip got $requested_ip";
+                       $type[1] = 'nak';
                }
        } elsif ($messagetype eq DHCPINFORM()) {
-               $audit->{type} = 'inform';
+               @type = qw( inform ignored );
        } else {
-               $audit->{type} = sprintf('ignored %x', $messagetype);
+               @type = ( $messagetype, 'ignored' );
        }
 
+       warn "# type ",dump @type;
+       $audit->{type} = [ @type ];
+
        warn ">> $mac == $ip server: $server::ip", $file ? " file: $file\n" : "\n" if $debug;
        $audit->{response} = $packet;
 
@@ -222,7 +229,7 @@ sub process_packet {
                warn $audit->{error};
        }
 
-       CouchDB::audit( $audit->{type}, $audit );
+       CouchDB::audit( @type, $audit );
 
 #      system("arp -s $ip $mac"),