diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2014-10-19 23:49:54 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2014-10-19 23:49:54 +0300 |
commit | 44bf6638158e4171b33fcdf9183a9e6c132518dc (patch) | |
tree | edbe6c2c70052c9b646a35db00197f76c1f42a70 | |
parent | 03c30147c1c6149af9f8070b7a92b8d0c8d18c42 (diff) | |
download | dnstools-44bf6638158e4171b33fcdf9183a9e6c132518dc.tar.gz dnstools-44bf6638158e4171b33fcdf9183a9e6c132518dc.tar.bz2 |
whoseip: bugfixes
* whoseip/Whoseip/DB.pm (ipdb_insert_unlocked): Insert into the last
page in the chain.
(ipdb_save_page): Preserve the leaf page chain.
* whoseip/whoseip.pl (cidr_to_range): Start iterating from list tail.
-rw-r--r-- | whoseip/Whoseip/DB.pm | 17 | ||||
-rw-r--r-- | whoseip/whoseip.pl | 3 |
2 files changed, 11 insertions, 9 deletions
diff --git a/whoseip/Whoseip/DB.pm b/whoseip/Whoseip/DB.pm index fed7cd9..21a4192 100644 --- a/whoseip/Whoseip/DB.pm +++ b/whoseip/Whoseip/DB.pm @@ -414,6 +414,7 @@ sub ipdb_save_page($$) { if $dbf->{debug} > 1; $nextpage = ipdb_alloc_page($dbf, IPDB_PAGE_LEAF, nocache => 1); + $nextpage->{next} = $page->{next}; $page->{next} = $nextpage->{off}; @{$nextpage->{tab}} = @{$page->{tab}}[$i .. $#{$page->{tab}}]; $nextpage->{dirty} = 1; @@ -812,8 +813,8 @@ sub ipdb_lookup($$) { Inserts into the database I<$cidr> and the corresponding country code I<$country> and additional data I<$hashref>. -Currently, I<$cidr> must be in the form B<I<Net-address>/I<Netmask-length>>. - +Currently, I<$cidr> must be in the form B<I<Net-address>/I<Netmask-length>>. + =cut sub ipdb_insert_unlocked { my ($dbf, $cidr, $country, $href) = @_; @@ -855,11 +856,13 @@ sub ipdb_insert_unlocked { } if ($page->{tab}[LEAF_IDX]) { - print STDERR "ipdb_insert: loading leaf page from $page->{tab}[LEAF_IDX]\n" - if $dbf->{debug}; - $page = ipdb_cache_get($dbf, $page->{tab}[LEAF_IDX]); - croak "$dbf->{filename}: index page found where leaf was expected" - unless $page->{type} == IPDB_PAGE_LEAF; + for (my $off = $page->{tab}[LEAF_IDX]; $off; $off = $page->{next}) { + print STDERR "ipdb_insert: loading leaf page from $off\n" + if $dbf->{debug}; + $page = ipdb_cache_get($dbf, $off); + croak "$dbf->{filename}: index page found where leaf was expected" + unless $page->{type} == IPDB_PAGE_LEAF; + } } else { print STDERR "ipdb_insert: creating leaf page\n" if $dbf->{debug}; diff --git a/whoseip/whoseip.pl b/whoseip/whoseip.pl index 8070fb8..2464155 100644 --- a/whoseip/whoseip.pl +++ b/whoseip/whoseip.pl @@ -162,13 +162,12 @@ sub cidr_to_range { Net::CIDR::cidr2range($_) } split /,/, shift; - for (my $i = 1; $i <= $#a; $i++) { + for (my $i = $#a; $i > 0; $i--) { if ($a[$i]->[0] == $a[$i-1]->[1] + 1) { $a[$i-1]->[1] = $a[$i]->[1]; splice @a, $i, 1; } } - return join ',', map { inet_ntoa(pack('N', $_->[0])) . '-' . inet_ntoa(pack('N', $_->[1])) } @a; } |