mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-20 19:44:56 +02:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4c68c774c8 | ||
![]() |
0888357642 | ||
![]() |
d31067b32e | ||
![]() |
fc44fcb94f | ||
![]() |
26f5bcbdbb | ||
![]() |
061fc794b5 | ||
![]() |
bf1ca298ae | ||
![]() |
6e5edc8372 | ||
![]() |
7ad14b7150 | ||
![]() |
0cc51e6b35 | ||
![]() |
fa7bcbfb9b | ||
![]() |
d86101e470 | ||
![]() |
708f883635 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
|||||||
*.la
|
*.la
|
||||||
*.lo
|
*.lo
|
||||||
*.loT
|
*.loT
|
||||||
|
*.mod
|
||||||
*.o
|
*.o
|
||||||
.cache.mk
|
.cache.mk
|
||||||
.deps/
|
.deps/
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
AC_INIT([xtables-addons], [3.4])
|
AC_INIT([xtables-addons], [3.9])
|
||||||
AC_CONFIG_AUX_DIR([build-aux])
|
AC_CONFIG_AUX_DIR([build-aux])
|
||||||
AC_CONFIG_HEADERS([config.h])
|
AC_CONFIG_HEADERS([config.h])
|
||||||
AC_CONFIG_MACRO_DIR([m4])
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
@@ -57,11 +57,11 @@ if test -n "$kbuilddir"; then
|
|||||||
echo "WARNING: Version detection did not succeed. Continue at own luck.";
|
echo "WARNING: Version detection did not succeed. Continue at own luck.";
|
||||||
else
|
else
|
||||||
echo "$kmajor.$kminor.$kmicro.$kstable in $kbuilddir";
|
echo "$kmajor.$kminor.$kmicro.$kstable in $kbuilddir";
|
||||||
if test "$kmajor" -gt 5 -o "$kmajor" -eq 5 -a "$kminor" -gt 3; then
|
if test "$kmajor" -gt 5 -o "$kmajor" -eq 5 -a "$kminor" -gt 6; then
|
||||||
echo "WARNING: That kernel version is not officially supported yet. Continue at own luck.";
|
echo "WARNING: That kernel version is not officially supported yet. Continue at own luck.";
|
||||||
elif test "$kmajor" -eq 5 -a "$kminor" -ge 0; then
|
elif test "$kmajor" -eq 5 -a "$kminor" -ge 0; then
|
||||||
:
|
:
|
||||||
elif test "$kmajor" -eq 4 -a "$kminor" -ge 18; then
|
elif test "$kmajor" -eq 4 -a "$kminor" -ge 15; then
|
||||||
:
|
:
|
||||||
else
|
else
|
||||||
echo "WARNING: That kernel version is not officially supported.";
|
echo "WARNING: That kernel version is not officially supported.";
|
||||||
|
@@ -1,6 +1,32 @@
|
|||||||
|
v3.9 (2020-02-25)
|
||||||
|
=================
|
||||||
|
- Support for Linux 5.6 procfs changes
|
||||||
|
|
||||||
HEAD
|
|
||||||
====
|
v3.8 (2020-02-03)
|
||||||
|
=================
|
||||||
|
- Support for Linux 5.5
|
||||||
|
- xt_geoip_build now expects the DBIP format as input,
|
||||||
|
Maxmind is thrown out.
|
||||||
|
|
||||||
|
|
||||||
|
v3.7 (2019-12-01)
|
||||||
|
=================
|
||||||
|
Fixes:
|
||||||
|
- xt_geoip: fix in6_addr little-endian byte swapping
|
||||||
|
|
||||||
|
|
||||||
|
v3.6 (2019-11-20)
|
||||||
|
=================
|
||||||
|
Enhancements:
|
||||||
|
- support for up to Linux 5.4
|
||||||
|
|
||||||
|
|
||||||
|
v3.5 (2019-09-10)
|
||||||
|
=================
|
||||||
|
Enhancements:
|
||||||
|
- xt_DELUDE, xt_TARPIT: added additional code needed to work with
|
||||||
|
bridges from Linux 5.0 onwards.
|
||||||
|
|
||||||
|
|
||||||
v3.4 (2019-09-06)
|
v3.4 (2019-09-06)
|
||||||
|
@@ -51,4 +51,13 @@ static inline struct net *par_net(const struct xt_action_param *par)
|
|||||||
# define NF_CT_ASSERT(x) WARN_ON(!(x))
|
# define NF_CT_ASSERT(x) WARN_ON(!(x))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
|
||||||
|
# define proc_ops file_operations
|
||||||
|
# define proc_open open
|
||||||
|
# define proc_read read
|
||||||
|
# define proc_write write
|
||||||
|
# define proc_lseek llseek
|
||||||
|
# define proc_release release
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _XTABLES_COMPAT_H */
|
#endif /* _XTABLES_COMPAT_H */
|
||||||
|
@@ -50,26 +50,6 @@ static struct option geoip_opts[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||||
static void geoip_swap_le16(uint16_t *buf)
|
|
||||||
{
|
|
||||||
unsigned char *p = (void *)buf;
|
|
||||||
uint16_t n= p[0] + (p[1] << 8);
|
|
||||||
p[0] = (n >> 8) & 0xff;
|
|
||||||
p[1] = n & 0xff;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void geoip_swap_in6(struct in6_addr *in6)
|
|
||||||
{
|
|
||||||
geoip_swap_le16(&in6->s6_addr16[0]);
|
|
||||||
geoip_swap_le16(&in6->s6_addr16[1]);
|
|
||||||
geoip_swap_le16(&in6->s6_addr16[2]);
|
|
||||||
geoip_swap_le16(&in6->s6_addr16[3]);
|
|
||||||
geoip_swap_le16(&in6->s6_addr16[4]);
|
|
||||||
geoip_swap_le16(&in6->s6_addr16[5]);
|
|
||||||
geoip_swap_le16(&in6->s6_addr16[6]);
|
|
||||||
geoip_swap_le16(&in6->s6_addr16[7]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void geoip_swap_le32(uint32_t *buf)
|
static void geoip_swap_le32(uint32_t *buf)
|
||||||
{
|
{
|
||||||
unsigned char *p = (void *)buf;
|
unsigned char *p = (void *)buf;
|
||||||
@@ -79,6 +59,14 @@ static void geoip_swap_le32(uint32_t *buf)
|
|||||||
p[2] = (n >> 8) & 0xff;
|
p[2] = (n >> 8) & 0xff;
|
||||||
p[3] = n & 0xff;
|
p[3] = n & 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void geoip_swap_in6(struct in6_addr *in6)
|
||||||
|
{
|
||||||
|
geoip_swap_le32(&in6->s6_addr32[0]);
|
||||||
|
geoip_swap_le32(&in6->s6_addr32[1]);
|
||||||
|
geoip_swap_le32(&in6->s6_addr32[2]);
|
||||||
|
geoip_swap_le32(&in6->s6_addr32[3]);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
|
@@ -295,12 +295,11 @@ pknock_proc_open(struct inode *inode, struct file *file)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct file_operations pknock_proc_ops = {
|
static const struct proc_ops pknock_proc_ops = {
|
||||||
.owner = THIS_MODULE,
|
.proc_open = pknock_proc_open,
|
||||||
.open = pknock_proc_open,
|
.proc_read = seq_read,
|
||||||
.read = seq_read,
|
.proc_lseek = seq_lseek,
|
||||||
.llseek = seq_lseek,
|
.proc_release = seq_release,
|
||||||
.release = seq_release
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -107,8 +107,13 @@ static void delude_send_reset(struct net *net, struct sk_buff *oldskb,
|
|||||||
|
|
||||||
addr_type = RTN_UNSPEC;
|
addr_type = RTN_UNSPEC;
|
||||||
#ifdef CONFIG_BRIDGE_NETFILTER
|
#ifdef CONFIG_BRIDGE_NETFILTER
|
||||||
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
|
||||||
|
if (hook != NF_INET_FORWARD || ((struct nf_bridge_info *)skb_ext_find(nskb, SKB_EXT_BRIDGE_NF) != NULL &&
|
||||||
|
((struct nf_bridge_info *)skb_ext_find(nskb, SKB_EXT_BRIDGE_NF))->physoutdev))
|
||||||
|
#else
|
||||||
if (hook != NF_INET_FORWARD || (nskb->nf_bridge != NULL &&
|
if (hook != NF_INET_FORWARD || (nskb->nf_bridge != NULL &&
|
||||||
nskb->nf_bridge->physoutdev))
|
nskb->nf_bridge->physoutdev))
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
if (hook != NF_INET_FORWARD)
|
if (hook != NF_INET_FORWARD)
|
||||||
#endif
|
#endif
|
||||||
|
@@ -115,7 +115,7 @@ static DEFINE_SPINLOCK(dnetmap_lock);
|
|||||||
static DEFINE_MUTEX(dnetmap_mutex);
|
static DEFINE_MUTEX(dnetmap_mutex);
|
||||||
|
|
||||||
#ifdef CONFIG_PROC_FS
|
#ifdef CONFIG_PROC_FS
|
||||||
static const struct file_operations dnetmap_tg_fops, dnetmap_stat_proc_fops;
|
static const struct proc_ops dnetmap_tg_fops, dnetmap_stat_proc_fops;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline unsigned int dnetmap_entry_hash(const __be32 addr)
|
static inline unsigned int dnetmap_entry_hash(const __be32 addr)
|
||||||
@@ -768,12 +768,11 @@ dnetmap_tg_proc_write(struct file *file, const char __user *input,size_t size, l
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const struct file_operations dnetmap_tg_fops = {
|
static const struct proc_ops dnetmap_tg_fops = {
|
||||||
.open = dnetmap_seq_open,
|
.proc_open = dnetmap_seq_open,
|
||||||
.read = seq_read,
|
.proc_read = seq_read,
|
||||||
.write = dnetmap_tg_proc_write,
|
.proc_write = dnetmap_tg_proc_write,
|
||||||
.release = seq_release_private,
|
.proc_release = seq_release_private,
|
||||||
.owner = THIS_MODULE,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* for statistics */
|
/* for statistics */
|
||||||
@@ -817,11 +816,11 @@ static int dnetmap_stat_proc_open(struct inode *inode, struct file *file)
|
|||||||
return single_open(file, dnetmap_stat_proc_show, PDE_DATA(inode));
|
return single_open(file, dnetmap_stat_proc_show, PDE_DATA(inode));
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct file_operations dnetmap_stat_proc_fops = {
|
static const struct proc_ops dnetmap_stat_proc_fops = {
|
||||||
.open = dnetmap_stat_proc_open,
|
.proc_open = dnetmap_stat_proc_open,
|
||||||
.read = seq_read,
|
.proc_read = seq_read,
|
||||||
.llseek = seq_lseek,
|
.proc_lseek = seq_lseek,
|
||||||
.release = single_release,
|
.proc_release = single_release,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __net_init dnetmap_proc_net_init(struct net *net)
|
static int __net_init dnetmap_proc_net_init(struct net *net)
|
||||||
|
@@ -205,7 +205,11 @@ static void tarpit_tcp4(struct net *net, struct sk_buff *oldskb,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* This packet will not be the same as the other: clear nf fields */
|
/* This packet will not be the same as the other: clear nf fields */
|
||||||
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)
|
||||||
|
nf_reset_ct(nskb);
|
||||||
|
#else
|
||||||
nf_reset(nskb);
|
nf_reset(nskb);
|
||||||
|
#endif
|
||||||
skb_nfmark(nskb) = 0;
|
skb_nfmark(nskb) = 0;
|
||||||
skb_init_secmark(nskb);
|
skb_init_secmark(nskb);
|
||||||
skb_shinfo(nskb)->gso_size = 0;
|
skb_shinfo(nskb)->gso_size = 0;
|
||||||
@@ -249,8 +253,13 @@ static void tarpit_tcp4(struct net *net, struct sk_buff *oldskb,
|
|||||||
niph->id = ~oldhdr->id + 1;
|
niph->id = ~oldhdr->id + 1;
|
||||||
|
|
||||||
#ifdef CONFIG_BRIDGE_NETFILTER
|
#ifdef CONFIG_BRIDGE_NETFILTER
|
||||||
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
|
||||||
|
if (hook != NF_INET_FORWARD || ((struct nf_bridge_info *)skb_ext_find(nskb, SKB_EXT_BRIDGE_NF) != NULL &&
|
||||||
|
((struct nf_bridge_info *)skb_ext_find(nskb, SKB_EXT_BRIDGE_NF))->physoutdev))
|
||||||
|
#else
|
||||||
if (hook != NF_INET_FORWARD || (nskb->nf_bridge != NULL &&
|
if (hook != NF_INET_FORWARD || (nskb->nf_bridge != NULL &&
|
||||||
nskb->nf_bridge->physoutdev != NULL))
|
nskb->nf_bridge->physoutdev != NULL))
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
if (hook != NF_INET_FORWARD)
|
if (hook != NF_INET_FORWARD)
|
||||||
#endif
|
#endif
|
||||||
@@ -341,7 +350,11 @@ static void tarpit_tcp6(struct net *net, struct sk_buff *oldskb,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* This packet will not be the same as the other: clear nf fields */
|
/* This packet will not be the same as the other: clear nf fields */
|
||||||
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)
|
||||||
|
nf_reset_ct(nskb);
|
||||||
|
#else
|
||||||
nf_reset(nskb);
|
nf_reset(nskb);
|
||||||
|
#endif
|
||||||
skb_nfmark(nskb) = 0;
|
skb_nfmark(nskb) = 0;
|
||||||
skb_init_secmark(nskb);
|
skb_init_secmark(nskb);
|
||||||
skb_shinfo(nskb)->gso_size = 0;
|
skb_shinfo(nskb)->gso_size = 0;
|
||||||
|
@@ -111,12 +111,12 @@ condition_proc_write(struct file *file, const char __user *buffer,
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct file_operations condition_proc_fops = {
|
static const struct proc_ops condition_proc_fops = {
|
||||||
.open = condition_proc_open,
|
.proc_open = condition_proc_open,
|
||||||
.read = seq_read,
|
.proc_read = seq_read,
|
||||||
.llseek = seq_lseek,
|
.proc_write = condition_proc_write,
|
||||||
.write = condition_proc_write,
|
.proc_lseek = seq_lseek,
|
||||||
.release = single_release,
|
.proc_release = single_release,
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@@ -117,12 +117,12 @@ quota_proc_write(struct file *file, const char __user *input,
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct file_operations quota_proc_fops = {
|
static const struct proc_ops quota_proc_fops = {
|
||||||
.open = quota_proc_open,
|
.proc_open = quota_proc_open,
|
||||||
.read = seq_read,
|
.proc_read = seq_read,
|
||||||
.llseek = seq_lseek,
|
.proc_write = quota_proc_write,
|
||||||
.write = quota_proc_write,
|
.proc_lseek = seq_lseek,
|
||||||
.release = single_release,
|
.proc_release = single_release,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct xt_quota_counter *
|
static struct xt_quota_counter *
|
||||||
|
189
geoip/xt_geoip_build
Executable file → Normal file
189
geoip/xt_geoip_build
Executable file → Normal file
@@ -1,8 +1,9 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
#
|
#
|
||||||
# Converter for MaxMind (GeoLite2) CSV database to binary, for xt_geoip
|
# Converter for DBIP (Country Lite) CSV database to binary, for xt_geoip
|
||||||
# Copyright Jan Engelhardt, 2008-2011
|
# Copyright Jan Engelhardt, 2008-2011
|
||||||
# Copyright Philip Prindeville, 2018
|
# Copyright Philip Prindeville, 2018
|
||||||
|
# Copyright Arjen de Korte, 2020
|
||||||
#
|
#
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
use Net::CIDR::Lite;
|
use Net::CIDR::Lite;
|
||||||
@@ -34,136 +35,33 @@ if (!-d $target_dir) {
|
|||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
my %countryId;
|
|
||||||
my %countryName;
|
|
||||||
&loadCountries();
|
|
||||||
&dump(&collect());
|
&dump(&collect());
|
||||||
|
|
||||||
sub loadCountries
|
|
||||||
{
|
|
||||||
sub id; sub cc; sub long; sub ct; sub cn;
|
|
||||||
|
|
||||||
%countryId = ();
|
|
||||||
%countryName = ();
|
|
||||||
|
|
||||||
my $file = "$source_dir/GeoLite2-Country-Locations-en.csv";
|
|
||||||
open(my $fh, '<', $file) || die "Couldn't open list country names\n";
|
|
||||||
|
|
||||||
# first line is headers
|
|
||||||
my $row = $csv->getline($fh);
|
|
||||||
|
|
||||||
my %header = map { ($row->[$_], $_); } (0..$#{$row});
|
|
||||||
|
|
||||||
my %pairs = (
|
|
||||||
country_iso_code => 'ISO Country Code',
|
|
||||||
geoname_id => 'ID',
|
|
||||||
country_name => 'Country Name',
|
|
||||||
continent_code => 'Continent Code',
|
|
||||||
continent_name => 'Continent Name',
|
|
||||||
);
|
|
||||||
|
|
||||||
# verify that the columns we need are present
|
|
||||||
map { die "Table has no $pairs{$_} column\n" unless (exists $header{$_}); } keys %pairs;
|
|
||||||
|
|
||||||
my %remapping = (
|
|
||||||
id => 'geoname_id',
|
|
||||||
cc => 'country_iso_code',
|
|
||||||
long => 'country_name',
|
|
||||||
ct => 'continent_code',
|
|
||||||
cn => 'continent_name',
|
|
||||||
);
|
|
||||||
|
|
||||||
# now create a function which returns the value of that column #
|
|
||||||
map { eval "sub $_ () { \$header{\$remapping{$_}}; }" ; } keys %remapping;
|
|
||||||
|
|
||||||
while (my $row = $csv->getline($fh)) {
|
|
||||||
if ($row->[cc] eq '' && $row->[long] eq '') {
|
|
||||||
$countryId{$row->[id]} = $row->[ct];
|
|
||||||
$countryName{$row->[ct]} = $row->[cn];
|
|
||||||
} else {
|
|
||||||
$countryId{$row->[id]} = $row->[cc];
|
|
||||||
$countryName{$row->[cc]} = $row->[long];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$countryName{A1} = 'Anonymous Proxy';
|
|
||||||
$countryName{A2} = 'Satellite Provider';
|
|
||||||
$countryName{O1} = 'Other Country';
|
|
||||||
|
|
||||||
close($fh);
|
|
||||||
|
|
||||||
# clean up the namespace
|
|
||||||
undef &id; undef &cc; undef &long; undef &ct; undef &cn;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub lookupCountry
|
|
||||||
{
|
|
||||||
my ($id, $rid, $proxy, $sat) = @_;
|
|
||||||
|
|
||||||
if ($proxy) {
|
|
||||||
return 'A1';
|
|
||||||
} elsif ($sat) {
|
|
||||||
return 'A2';
|
|
||||||
}
|
|
||||||
$id ||= $rid;
|
|
||||||
if ($id eq '') {
|
|
||||||
return 'O1';
|
|
||||||
}
|
|
||||||
die "Unknown id: $id line $.\n" unless (exists $countryId{$id});
|
|
||||||
return $countryId{$id};
|
|
||||||
}
|
|
||||||
|
|
||||||
sub collect
|
sub collect
|
||||||
{
|
{
|
||||||
my ($file, $fh, $row);
|
my ($file, $fh, $row);
|
||||||
my (%country, %header);
|
my (%country);
|
||||||
|
|
||||||
sub net; sub id; sub rid; sub proxy; sub sat;
|
$file = "$source_dir/dbip-country-lite.csv";
|
||||||
|
open($fh, '<', $file) || die "Can't open DBIP database\n";
|
||||||
my %pairs = (
|
|
||||||
network => 'Network',
|
|
||||||
registered_country_geoname_id => 'Registered Country ID',
|
|
||||||
geoname_id => 'Country ID',
|
|
||||||
is_anonymous_proxy => 'Anonymous Proxy',
|
|
||||||
is_satellite_provider => 'Satellite',
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach (sort keys %countryName) {
|
|
||||||
$country{$_} = {
|
|
||||||
name => $countryName{$_},
|
|
||||||
pool_v4 => Net::CIDR::Lite->new(),
|
|
||||||
pool_v6 => Net::CIDR::Lite->new(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
$file = "$source_dir/GeoLite2-Country-Blocks-IPv4.csv";
|
|
||||||
open($fh, '<', $file) || die "Can't open IPv4 database\n";
|
|
||||||
|
|
||||||
# first line is headers
|
|
||||||
$row = $csv->getline($fh);
|
|
||||||
|
|
||||||
%header = map { ($row->[$_], $_); } (0..$#{$row});
|
|
||||||
|
|
||||||
# verify that the columns we need are present
|
|
||||||
map { die "Table has no %pairs{$_} column\n" unless (exists $header{$_}); } keys %pairs;
|
|
||||||
|
|
||||||
my %remapping = (
|
|
||||||
net => 'network',
|
|
||||||
id => 'geoname_id',
|
|
||||||
rid => 'registered_country_geoname_id',
|
|
||||||
proxy => 'is_anonymous_proxy',
|
|
||||||
sat => 'is_satellite_provider',
|
|
||||||
);
|
|
||||||
|
|
||||||
# now create a function which returns the value of that column #
|
|
||||||
map { eval "sub $_ () { \$header{\$remapping{$_}}; }" ; } keys %remapping;
|
|
||||||
|
|
||||||
while ($row = $csv->getline($fh)) {
|
while ($row = $csv->getline($fh)) {
|
||||||
my ($cc, $cidr);
|
my ($cc, $range);
|
||||||
|
|
||||||
$cc = lookupCountry($row->[id], $row->[rid], $row->[proxy], $row->[sat]);
|
$cc = $row->[2];
|
||||||
$cidr = $row->[net];
|
$range = $row->[0] . "-" . $row->[1];
|
||||||
$country{$cc}->{pool_v4}->add($cidr);
|
|
||||||
|
if (!exists($country{$cc})) {
|
||||||
|
$country{$cc} = { pool_v4 => Net::CIDR::Lite->new(), pool_v6 => Net::CIDR::Lite->new() };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index($range, '.') > 0) {
|
||||||
|
$country{$cc}->{pool_v4}->add_range($range);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index($range, ':') > 0) {
|
||||||
|
$country{$cc}->{pool_v6}->add_range($range);
|
||||||
|
}
|
||||||
|
|
||||||
if ($. % 4096 == 0) {
|
if ($. % 4096 == 0) {
|
||||||
print STDERR "\r\e[2K$. entries";
|
print STDERR "\r\e[2K$. entries";
|
||||||
@@ -174,43 +72,6 @@ sub collect
|
|||||||
|
|
||||||
close($fh);
|
close($fh);
|
||||||
|
|
||||||
# clean up the namespace
|
|
||||||
undef &net; undef &id; undef &rid; undef &proxy; undef &sat;
|
|
||||||
|
|
||||||
$file = "$source_dir/GeoLite2-Country-Blocks-IPv6.csv";
|
|
||||||
open($fh, '<', $file) || die "Can't open IPv6 database\n";
|
|
||||||
|
|
||||||
# first line is headers
|
|
||||||
$row = $csv->getline($fh);
|
|
||||||
|
|
||||||
%header = map { ($row->[$_], $_); } (0..$#{$row});
|
|
||||||
|
|
||||||
# verify that the columns we need are present
|
|
||||||
map { die "Table has no %pairs{$_} column\n" unless (exists $header{$_}); } keys %pairs;
|
|
||||||
|
|
||||||
# unlikely the IPv6 table has different columns, but just to be sure
|
|
||||||
# create a function which returns the value of that column #
|
|
||||||
map { eval "sub $_ () { \$header{\$remapping{$_}}; }" ; } keys %remapping;
|
|
||||||
|
|
||||||
while ($row = $csv->getline($fh)) {
|
|
||||||
my ($cc, $cidr);
|
|
||||||
|
|
||||||
$cc = lookupCountry($row->[id], $row->[rid], $row->[proxy], $row->[sat]);
|
|
||||||
$cidr = $row->[net];
|
|
||||||
$country{$cc}->{pool_v6}->add($cidr);
|
|
||||||
|
|
||||||
if ($. % 4096 == 0) {
|
|
||||||
print STDERR "\r\e[2K$. entries";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
print STDERR "\r\e[2K$. entries total\n";
|
|
||||||
|
|
||||||
close($fh);
|
|
||||||
|
|
||||||
# clean up the namespace
|
|
||||||
undef &net; undef &id; undef &rid; undef &proxy; undef &sat;
|
|
||||||
|
|
||||||
return \%country;
|
return \%country;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,22 +91,22 @@ sub dump_one
|
|||||||
|
|
||||||
@ranges = $country->{pool_v4}->list_range();
|
@ranges = $country->{pool_v4}->list_range();
|
||||||
|
|
||||||
writeCountry($iso_code, $country->{name}, AF_INET, @ranges);
|
writeCountry($iso_code, AF_INET, @ranges);
|
||||||
|
|
||||||
@ranges = $country->{pool_v6}->list_range();
|
@ranges = $country->{pool_v6}->list_range();
|
||||||
|
|
||||||
writeCountry($iso_code, $country->{name}, AF_INET6, @ranges);
|
writeCountry($iso_code, AF_INET6, @ranges);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub writeCountry
|
sub writeCountry
|
||||||
{
|
{
|
||||||
my ($iso_code, $name, $family, @ranges) = @_;
|
my ($iso_code, $family, @ranges) = @_;
|
||||||
my $fh;
|
my $fh;
|
||||||
|
|
||||||
printf "%5u IPv%s ranges for %s %s\n",
|
printf "%5u IPv%s ranges for %s\n",
|
||||||
scalar(@ranges),
|
scalar(@ranges),
|
||||||
($family == AF_INET ? '4' : '6'),
|
($family == AF_INET ? '4' : '6'),
|
||||||
$iso_code, $name;
|
$iso_code;
|
||||||
|
|
||||||
my $file = "$target_dir/".uc($iso_code).".iv".($family == AF_INET ? '4' : '6');
|
my $file = "$target_dir/".uc($iso_code).".iv".($family == AF_INET ? '4' : '6');
|
||||||
if (!open($fh, '>', $file)) {
|
if (!open($fh, '>', $file)) {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
.TH xtables-addons 8 "" "" "v3.4 (2019-09-06)"
|
.TH xtables-addons 8 "" "" "v3.9 (2020-02-25)"
|
||||||
.SH Name
|
.SH Name
|
||||||
Xtables-addons \(em additional extensions for iptables, ip6tables, etc.
|
Xtables-addons \(em additional extensions for iptables, ip6tables, etc.
|
||||||
.SH Targets
|
.SH Targets
|
||||||
|
Reference in New Issue
Block a user