mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-08 13:44:56 +02:00
geoip: put IPv4 geoip data into its own map
This commit is contained in:
@@ -58,9 +58,9 @@ static struct geoip_subnet *geoip_get_subnets(const char *code, uint32_t *count)
|
|||||||
|
|
||||||
/* Use simple integer vector files */
|
/* Use simple integer vector files */
|
||||||
#if __BYTE_ORDER == _BIG_ENDIAN
|
#if __BYTE_ORDER == _BIG_ENDIAN
|
||||||
snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/BE/%s.iv0", code);
|
snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/BE/%s.iv4", code);
|
||||||
#else
|
#else
|
||||||
snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/LE/%s.iv0", code);
|
snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/LE/%s.iv4", code);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((fd = open(buf, O_RDONLY)) < 0) {
|
if ((fd = open(buf, O_RDONLY)) < 0) {
|
||||||
|
@@ -33,9 +33,12 @@ foreach (qw(LE BE)) {
|
|||||||
|
|
||||||
while (my $row = $csv->getline(*ARGV)) {
|
while (my $row = $csv->getline(*ARGV)) {
|
||||||
if (!defined($country{$row->[4]})) {
|
if (!defined($country{$row->[4]})) {
|
||||||
$country{$row->[4]} = {name => $row->[5], pool => []};
|
$country{$row->[4]} = {
|
||||||
|
name => $row->[5],
|
||||||
|
pool_v4 => [],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
my $c = $country{$row->[4]}{pool};
|
my $c = $country{$row->[4]}{pool_v4};
|
||||||
push(@$c, [$row->[2], $row->[3]]);
|
push(@$c, [$row->[2], $row->[3]]);
|
||||||
if ($. % 4096 == 0) {
|
if ($. % 4096 == 0) {
|
||||||
print STDERR "\r\e[2K$. entries";
|
print STDERR "\r\e[2K$. entries";
|
||||||
@@ -47,21 +50,21 @@ print STDERR "\r\e[2K$. entries total\n";
|
|||||||
foreach my $iso_code (sort keys %country) {
|
foreach my $iso_code (sort keys %country) {
|
||||||
my($file, $fh_le, $fh_be);
|
my($file, $fh_le, $fh_be);
|
||||||
|
|
||||||
printf "%5u ranges for %s %s\n",
|
printf "%5u IPv4 ranges for %s %s\n",
|
||||||
scalar(@{$country{$iso_code}{pool}}),
|
scalar(@{$country{$iso_code}{pool_v4}}),
|
||||||
$iso_code, $country{$iso_code}{name};
|
$iso_code, $country{$iso_code}{name};
|
||||||
|
|
||||||
$file = "$target_dir/LE/".uc($iso_code).".iv0";
|
$file = "$target_dir/LE/".uc($iso_code).".iv4";
|
||||||
if (!open($fh_le, "> $file")) {
|
if (!open($fh_le, "> $file")) {
|
||||||
print STDERR "Error opening $file: $!\n";
|
print STDERR "Error opening $file: $!\n";
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
$file = "$target_dir/BE/".uc($iso_code).".iv0";
|
$file = "$target_dir/BE/".uc($iso_code).".iv4";
|
||||||
if (!open($fh_be, "> $file")) {
|
if (!open($fh_be, "> $file")) {
|
||||||
print STDERR "Error opening $file: $!\n";
|
print STDERR "Error opening $file: $!\n";
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
foreach my $range (@{$country{$iso_code}{pool}}) {
|
foreach my $range (@{$country{$iso_code}{pool_v4}}) {
|
||||||
print $fh_le pack("VV", $range->[0], $range->[1]);
|
print $fh_le pack("VV", $range->[0], $range->[1]);
|
||||||
print $fh_be pack("NN", $range->[0], $range->[1]);
|
print $fh_be pack("NN", $range->[0], $range->[1]);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user