176 |
|
|
177 |
my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE()); |
my $messagetype = $dhcp->getOptionValue(DHO_DHCP_MESSAGE_TYPE()); |
178 |
|
|
179 |
|
my @type; |
180 |
|
|
181 |
if ($messagetype eq DHCPDISCOVER()) { |
if ($messagetype eq DHCPDISCOVER()) { |
|
$audit->{type} = 'discover'; |
|
182 |
$packet->{Comment} = $dhcp->comment(); |
$packet->{Comment} = $dhcp->comment(); |
183 |
$packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPOFFER(); |
$packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPOFFER(); |
184 |
|
@type = qw( discover offser ); |
185 |
} elsif ($messagetype eq DHCPREQUEST()) { |
} elsif ($messagetype eq DHCPREQUEST()) { |
186 |
my $requested_ip = $dhcp->getOptionValue(DHO_DHCP_REQUESTED_ADDRESS()); |
@type = qw( request ); |
187 |
$audit->{type} = 'request'; |
my $requested_ip = $dhcp->getOptionValue(DHO_DHCP_REQUESTED_ADDRESS()) || $dhcp->ciaddr(); |
188 |
if ( $ip eq $requested_ip ) { |
if ( $ip eq $requested_ip ) { |
189 |
$packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPACK(); |
$packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPACK(); |
190 |
$packet->{DHO_DHCP_LEASE_TIME()} = 5 * 60; # 5 min |
$packet->{DHO_DHCP_LEASE_TIME()} = 5 * 60; # 5 min |
191 |
# $packet->{DHO_ROOT_PATH()} = '/exports/foobar'; |
# $packet->{DHO_ROOT_PATH()} = '/exports/foobar'; |
192 |
|
$type[1] = 'ack'; |
193 |
} else { |
} else { |
194 |
$packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPNAK(); |
$packet->{DHO_DHCP_MESSAGE_TYPE()} = DHCPNAK(); |
195 |
$packet->{DHO_DHCP_MESSAGE()} = "Bad request, expected $ip"; |
$packet->{DHO_DHCP_MESSAGE()} = "Bad request, expected $ip got $requested_ip"; |
196 |
|
$type[1] = 'nak'; |
197 |
} |
} |
198 |
} elsif ($messagetype eq DHCPINFORM()) { |
} elsif ($messagetype eq DHCPINFORM()) { |
199 |
$audit->{type} = 'inform'; |
@type = qw( inform ignored ); |
200 |
} else { |
} else { |
201 |
$audit->{type} = sprintf('ignored %x', $messagetype); |
@type = ( $messagetype, 'ignored' ); |
202 |
} |
} |
203 |
|
|
204 |
|
warn "# type ",dump @type; |
205 |
|
$audit->{type} = [ @type ]; |
206 |
|
|
207 |
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; |
208 |
$audit->{response} = $packet; |
$audit->{response} = $packet; |
209 |
|
|
229 |
warn $audit->{error}; |
warn $audit->{error}; |
230 |
} |
} |
231 |
|
|
232 |
CouchDB::audit( $audit->{type}, $audit ); |
CouchDB::audit( @type, $audit ); |
233 |
|
|
234 |
# system("arp -s $ip $mac"), |
# system("arp -s $ip $mac"), |
235 |
|
|