56 |
print "RENEW $mac $ip\n"; |
print "RENEW $mac $ip\n"; |
57 |
client::save_ip_mac( $ip, $mac ); |
client::save_ip_mac( $ip, $mac ); |
58 |
return $ip; |
return $ip; |
59 |
} elsif ( in_our_range( $request_ip ) ) { |
} elsif ( ip::in_dhcp_range( $request_ip ) || $request_ip eq '0.0.0.0' ) { |
60 |
$ip = client::next_ip( $mac ); |
$ip = client::next_ip( $mac ); |
61 |
print "NEW $mac $ip\n"; |
print "NEW $mac $ip\n"; |
62 |
} else { |
} else { |
76 |
our $file; |
our $file; |
77 |
our $transaction = 0; # FIXME predictible transaction numbers |
our $transaction = 0; # FIXME predictible transaction numbers |
78 |
|
|
|
sub ip2bin { pack('C*', split(/\./, $_[0])) }; |
|
|
sub in_our_range { |
|
|
my $ip = shift; |
|
|
return 1 if $ip eq '0.0.0.0'; |
|
|
return 1 if ( |
|
|
( ip2bin($ip) & ip2bin($server::netmask) ) |
|
|
eq |
|
|
( ip2bin($server::ip) & ip2bin($server::netmask) ) |
|
|
); |
|
|
} |
|
|
|
|
79 |
sub process_packet { |
sub process_packet { |
80 |
my $sock = shift; |
my $sock = shift; |
81 |
|
|
203 |
$packet = new Net::DHCP::Packet( %$packet ); |
$packet = new Net::DHCP::Packet( %$packet ); |
204 |
warn "send ",$packet->toString() if $debug; |
warn "send ",$packet->toString() if $debug; |
205 |
|
|
206 |
if ( in_our_range( $ip ) ) { |
if ( ip::in_dhcp_range( $ip ) ) { |
207 |
my $buff = $packet->serialize(); |
my $buff = $packet->serialize(); |
208 |
|
|
209 |
my $reply = IO::Socket::INET->new( |
my $reply = IO::Socket::INET->new( |
219 |
$reply->send( $buff, 0 ) or die "Error sending: $!\n"; |
$reply->send( $buff, 0 ) or die "Error sending: $!\n"; |
220 |
} else { |
} else { |
221 |
$audit->{error} = "$ip our of our range $server::ip $server::netmask"; |
$audit->{error} = "$ip our of our range $server::ip $server::netmask"; |
222 |
|
warn $audit->{error}; |
223 |
} |
} |
224 |
|
|
225 |
CouchDB::audit( $audit->{type}, $audit ); |
CouchDB::audit( $audit->{type}, $audit ); |