--- lib/PXElator/dhcpd.pm 2009/08/11 23:38:53 201 +++ lib/PXElator/dhcpd.pm 2009/08/12 22:56:45 207 @@ -23,6 +23,8 @@ use Net::DHCP::Packet; use Net::DHCP::Constants 0.67; +use CouchDB; + use server; my $debug = server::debug; @@ -87,6 +89,9 @@ my $hostname = $dhcp->getOptionValue(DHO_HOST_NAME); print "$ip ", client::conf( $ip => 'hostname', default => $hostname ), " >> /etc/hosts\n"; + my $audit = { mac => $mac, ip => $ip, hostname => $hostname }; + CouchDB::audit( 'request', $audit ); + =for later my $user_class = $dhcp->getOptionValue(DHO_USER_CLASS()); @@ -139,6 +144,8 @@ } warn "W: options requested but missing: ",dump( @missing ),$/; + $audit->{requested} = [ @requested ]; + $audit->{missing} = [ @missing ]; foreach my $opt ( 'magic', 'config_file', 'path_prefix', 'reboot_time' ) { my $DH0 = eval 'DHO_PXELINUX_' . uc $opt; @@ -153,12 +160,12 @@ my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE()); if ($messagetype eq DHCPDISCOVER()) { - log::mac $mac, "DHCP DISCOVER"; + $audit->{type} = 'discover'; $packet->{Comment} = $dhcp->comment(); $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPOFFER(); } elsif ($messagetype eq DHCPREQUEST()) { my $requested_ip = $dhcp->getOptionValue(DHO_DHCP_REQUESTED_ADDRESS()); - log::mac $mac, "DHCP REQUEST $requested_ip $ip $file"; + $audit->{type} = 'request'; if ( $ip eq $requested_ip ) { $packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPACK(); $packet->{DHO_DHCP_LEASE_TIME()} = 5 * 60; # 5 min @@ -168,16 +175,19 @@ $packet->{DHO_DHCP_MESSAGE()} = "Bad request, expected $ip"; } } elsif ($messagetype eq DHCPINFORM()) { - log::mac $mac, "DHCP INFORM ignored"; + $audit->{type} = 'inform'; } else { - log::mac $mac, "$messagetype igored (bootp?)"; + $audit->{type} = sprintf('ignored %x', $messagetype); } warn ">> $mac == $ip server: $server::ip", $file ? " file: $file\n" : "\n" if $debug; + $audit->{response} = $packet; $packet = new Net::DHCP::Packet( %$packet ); warn "send ",$packet->toString() if $debug; + CouchDB::audit( 'response', $audit ); + my $reply = IO::Socket::INET->new( LocalAddr => $server::ip, LocalPort => 67, @@ -211,6 +221,8 @@ print "DHCP listen on ",$sock->sockhost,":",$sock->sockport,"\n"; + CouchDB::audit( 'start', { 'listen' => { addr => $sock->sockhost, port => $sock->sockport } } ); + while (1) { process_packet $sock; }