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;
warn $audit->{error};
}
- CouchDB::audit( $audit->{type}, $audit );
+ CouchDB::audit( @type, $audit );
# system("arp -s $ip $mac"),