Compare commits

..

88 Commits
v2.14 ... v3.10

Author SHA1 Message Date
Jan Engelhardt
37f19c6b96 Xtables-addons 3.10 2020-07-28 10:02:34 +02:00
Jeremy Sowden
73b96e25e4 doc: fix quoted string in libxt_DNETMAP manpage
In roff, lines beginning with a single quote are control lines.  In the
libxt_DNETMAP man-page there is a single-quoted string at the beginning
of a line, which troff tries and fails to interpret as a macro:

	troff: <standard input>:49: warning: macro 'S'' not defined

This means that the line is not output.

Replace the single quotes with the appropriate escape-sequences.

Fixes: v2.3~9 ("doc: spelling and grammar corrections to DNETMAP")
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
2020-07-28 10:02:26 +02:00
Philip Prindeville
ca84ee8e15 geoip: add quiet flag to xt_geoip_build
Conceivably someone might want to run a refresh of the geoip database
from within a script, particularly an unattended script such as a cron
job. Do not generate output in that case.

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2020-05-26 14:58:04 +02:00
Jan Engelhardt
c9ba3507fc geoip: add -s option to xt_geoip_build 2020-05-12 22:49:37 +02:00
Jan Engelhardt
b87366bb83 geoip: replace xt_geoip_build's -S option by new option -i
The Maxmind DB came with potentially multiple files, but DBIP is
currently just one. Drop the -S argument and instead introduce -i.
2020-05-12 22:47:00 +02:00
Jan Engelhardt
8bbb0cb3eb geoip: set +x again on xt_geoip_build 2020-05-12 22:38:32 +02:00
Jan Engelhardt
b4629f46c6 build: do install xt_geoip_fetch.1 2020-05-01 23:07:16 +02:00
Philip Prindeville
f7f18f0c4f geoip: install and document xt_geoip_fetch
Add a man page for xt_geoip_fetch.1 and include it as part of
the installed scripts.

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2020-05-01 23:04:55 +02:00
Jan Engelhardt
9193adc835 geoip: pipe wget right into gzip
Skip over creating temporary files.
2020-04-21 12:01:52 +02:00
Philip Prindeville
74fcd4a2ae geoip: simplify unpacking start/end tuples from database
Use unpack() to separate start/end instead of substr().

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2020-04-21 12:00:54 +02:00
Philip Prindeville
4b43df69f5 geoip: update download script for DBIP database
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2020-04-21 12:00:50 +02:00
Jan Engelhardt
4c68c774c8 Xtables-addons 3.9 2020-02-25 07:35:08 +01:00
Jan Engelhardt
0888357642 build: avoid configure warning for Linux 4.15
Commit 4603d3e0f4 and others
erroneously changed the acceptance range from >=4.15 to >=4.17.
Return to previous state.
2020-02-25 07:30:01 +01:00
Jan Engelhardt
d31067b32e Support for Linux 5.6 procfs API 2020-02-25 07:28:23 +01:00
Jan Engelhardt
fc44fcb94f Xtables-addons 3.8 2020-02-03 12:02:34 +01:00
Arjen de Korte
26f5bcbdbb geoip: adjust builder script for DBIP service
Maxmind databases are no longer libre.
2020-02-01 15:51:54 +01:00
Jan Engelhardt
061fc794b5 Xtables-addons 3.7 2019-12-01 11:30:53 +01:00
Jeremy Sowden
bf1ca298ae xt_geoip: fix in6_addr little-endian byte swapping
The Perl script that builds the GeoIP DBs uses inet_pton(3) to convert
the addresses to network byte order. This converts

  "1234:5678::90ab:cdef"

to:

  0x12 0x34 0x56 0x78 .. 0xcd 0xef, interpreted by an LE machine
  accessing this in uint32_t-sized chunks as
  8765:4321::fedc:ba09

The kernel module compares the addresses in packets with the ranges from
the DB in host byte order using binary search. It uses 32-bit swaps
when converting the addresses.

libxt_geoip, however, which the module uses to load the ranges from the
DB and convert them from NBO to HBO, uses 16-bit swaps to do so, and
this means that:

  1234:5678::90ab:cdef

becomes:

  4321:8765::ba09:fedc

Obviously, this is inconsistent with the kernel module and DB build
script and breaks the binary search.

Fixes: b91dbd03c7 ("geoip: store database in network byte order")
Reported-by: "Thomas B. Clark" <kernel@clark.bz>
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
2019-12-01 11:29:40 +01:00
Jeremy Sowden
6e5edc8372 build: update max. supported kernel version
The maximum supported version is reported as 5.3. Bump to 5.4.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
2019-12-01 11:02:38 +01:00
Jan Engelhardt
7ad14b7150 Xtables-addons 3.6 2019-11-20 22:50:04 +01:00
Paolo Pisati
0cc51e6b35 build: add support for Linux 5.4 2019-11-20 22:45:18 +01:00
Jan Engelhardt
fa7bcbfb9b Xtables-addons 3.5 2019-09-10 11:14:13 +02:00
Jan Engelhardt
d86101e470 Merge MR-14 2019-09-10 11:12:30 +02:00
Jan Engelhardt
00114dea3d Xtables-addons 3.4 2019-09-06 10:43:58 +02:00
Jeremy Sowden
d4c2aac5f8 xt_pknock, xt_SYSRQ: do not set shash_desc::flags.
shash_desc::flags was removed from the kernel in 5.1.

That assignment was actually superfluous anyway, because crypto.desc
is zero-initialized when crypto is initialized (xt_pknock.c, ll.
110ff.).

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
2019-09-06 10:34:36 +02:00
Jan Engelhardt
5622c5f024 treewide: replace skb_make_writable
skb_make_writable was removed in v5.3-rc1~140^2~370^2~1 .
Replace it with skb_ensure_writable that was introduced in
v3.19-rc1~118^2~153^2~2 .
2019-09-06 10:34:36 +02:00
Jan Engelhardt
358991306c xt_PROTO: style fixes 2019-09-06 10:34:35 +02:00
Jan Engelhardt
2bbdcb1d58 Merge MR-11 2019-09-06 10:34:29 +02:00
Jeremy Sowden
b14728691d xt_DHCPMAC: replace skb_make_writable with skb_ensure_writable
skb_make_writable was removed from the kernel in
v5.3-rc1~140^2~370^2~1 , and its callers were converted to use
skb_ensure_writable. Updated dhcpmac_tg() accordingly.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
2019-09-06 10:28:37 +02:00
rantal
708f883635 add support for Linux 5.0 for DELUDE and TARPIT 2019-08-14 18:40:07 +00:00
Aron Xu
f822b8bc1b Add man page items for xt_PROTO
Signed-off-by: Aron Xu <happyaron.xu@gmail.com>
2019-05-07 03:31:24 +08:00
Aron Xu
4205900d9b Enable xt_PROTO in build system
Signed-off-by: Aron Xu <happyaron.xu@gmail.com>
2019-05-07 03:24:43 +08:00
Miao Wang
266638e41e Add xt_PROTO extension
Signed-off-by: Aron Xu <happyaron.xu@gmail.com>
2019-05-07 03:24:43 +08:00
Jan Engelhardt
ebcd176822 Xtables-addons 3.3 2019-03-07 10:24:08 +01:00
Jan Engelhardt
6b47d09a36 build: remove xa-download-more script
This mechanism has not seen any use in recent years (the "sources"
file is still the same) — drop it.
2019-03-07 10:20:05 +01:00
Jan Engelhardt
1849c47ae8 doc: update README and changelog 2019-03-07 10:18:43 +01:00
PGNet Dev
68d895f75c xt_SYSRQ: replace do_gettimeofday
Linux kernel commit v4.20-rc1-18-ge4b92b108c6c removed
do_gettimeofday in favor of ktime_get_real_ts64 introduced in
v3.16-rc5-59-gd6d29896c665 .
2019-03-07 10:07:28 +01:00
Jan Engelhardt
53b6b862cc Merge MR-10 2018-11-17 12:32:56 +01:00
Nataniel Santos
ed10cb9c17 xt_ACCOUNT: make table limit configurable
Add parameter option in module xt_ACCOUNT.ko to accept. Change in the
ACCOUN_MAX_TABLES table without the need to recompile the module.

References: MR-8
2018-11-17 12:13:00 +01:00
Jan Engelhardt
5903f4bcfc Xtables-addons 3.2 2018-09-07 15:04:28 +02:00
Jan Engelhardt
5e19871613 geoip: build tool should not rely on directory name
Fix this:

	GeoLite2-Country-CSV_20180905$ /usr/lib/xtables-addons/xt_geoip_build

	Use of uninitialized value $dir in concatenation (.) or string at
	/usr/lib/xtables-addons/xt_geoip_build line 59.
	Couldn't open list country names

Do not rely on any directory names (they change). Use the current
directory as the default source directory, similar to the older
xt_geoip_build (well, *.csv was passed as arguments).
2018-09-07 15:03:20 +02:00
Jan Engelhardt
30fb410003 Xtables-addons 3.1 2018-08-14 14:31:10 +02:00
Jan Engelhardt
3ea761a1ed build: add support for Linux 4.18 2018-08-14 14:29:30 +02:00
Jan Engelhardt
4603d3e0f4 build: add support for Linux 4.17 2018-08-14 14:23:04 +02:00
Jan Engelhardt
b0b2b5a74c build: fix 4.16 warning 2018-08-14 14:22:40 +02:00
Jan Engelhardt
082d42fb21 build: match documented and coded build requirements 2018-08-14 14:22:17 +02:00
Jan Engelhardt
b1f0e118a0 doc: add 3.0 headline in changelog 2018-08-14 14:15:07 +02:00
Philip Prindeville
56fba3ecff geoip: simplify handling table column names
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2018-04-30 09:41:29 +02:00
Philip Prindeville
9057fb48f3 geoip: add database query tool for use with ipsets
Add a tool for retrieiving the IPv4 or IPv6 (or both!) CIDR ranges
for a given country, which can then be injected into an ipset if
one doesn't want to use (or have available) the xt_geoip extension.

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2018-04-30 09:41:21 +02:00
Philip Prindeville
e19f91ddb4 geoip: update man page for xt_geoip_build
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2018-04-30 09:40:54 +02:00
Philip Prindeville
256ac1a4f6 geoip: adapt to GeoLite2 database
Requires Net::CIDR::Lite for manipulating CIDR blocks, aggregation, etc.
since database is stored as subnet/mask pairs and may require compaction
into ranges (which can combine adjacent subnets).

We don't use Net::CIDR because it's a clunkier interface.

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2018-04-30 09:40:51 +02:00
Philip Prindeville
b91dbd03c7 geoip: store database in network byte order
This allows a single database to be built and distributed as a
package that is accepted by both big- and little-endian hosts.

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2018-02-19 01:42:29 +01:00
Jan Engelhardt
254c6926d3 Xtables-addons 3.0 2018-02-12 15:17:10 +01:00
Jan Engelhardt
2e78cf03a4 build: support for Linux 4.16 2018-02-12 15:10:47 +01:00
Jan Engelhardt
bf63a25a64 build: remove support for Linux 4.14 2018-02-12 15:09:52 +01:00
Jan Engelhardt
94656621ed build: remove support for Linux 4.13 2018-02-12 15:09:41 +01:00
Jan Engelhardt
95d4f9e113 build: remove support for Linux 4.12 2018-02-12 15:09:32 +01:00
Jan Engelhardt
123e1a14e9 build: remove support for Linux 4.11 2018-02-12 15:09:25 +01:00
Jan Engelhardt
f4f3f98609 build: remove support for Linux 4.10 2018-02-12 15:09:15 +01:00
Jan Engelhardt
9b1c7c1c04 build: remove support for Linux 4.9 2018-02-12 14:59:44 +01:00
Jan Engelhardt
ed8e496750 build: remove support for Linux 4.8 2018-02-12 14:57:21 +01:00
Jan Engelhardt
5339fcc65b build: remove support for Linux 4.7 2018-02-12 14:56:57 +01:00
Jan Engelhardt
2265c1b854 build: remove support for Linux 4.6 2018-02-12 14:56:40 +01:00
Jan Engelhardt
2c574f992d build: remove support for Linux 4.5 2018-02-12 14:56:24 +01:00
Jan Engelhardt
3a24468a68 build: remove support for Linux 4.4 2018-02-12 14:56:05 +01:00
Jan Engelhardt
7682cc8c34 build: remove support for Linux 4.3 2018-02-12 14:55:45 +01:00
Jan Engelhardt
215b3c5b12 build: remove support for Linux 4.2 2018-02-12 14:54:26 +01:00
Jan Engelhardt
4dbb36b723 build: remove support for Linux 4.1 2018-02-12 14:53:25 +01:00
Jan Engelhardt
10f951e61d build: remove support for Linux 4.0 2018-02-12 14:53:01 +01:00
Jan Engelhardt
a4c50ae405 build: remove support for Linux 3.19 2018-02-12 14:50:33 +01:00
Jan Engelhardt
38d89983ca build: remove support for Linux 3.18 2018-02-12 14:49:20 +01:00
Jan Engelhardt
25985650a9 build: remove support for Linux 3.17 2018-02-12 14:48:53 +01:00
Jan Engelhardt
4de9ff1505 build: remove support for Linux 3.16 2018-02-12 14:48:34 +01:00
Jan Engelhardt
46b7cf206b build: remove support for Linux 3.15 2018-02-12 14:47:58 +01:00
Jan Engelhardt
29d10e11fa build: remove support for Linux 3.14 2018-02-12 14:46:50 +01:00
Jan Engelhardt
60a26f1dea build: remove support for Linux 3.13 2018-02-12 14:45:55 +01:00
Jan Engelhardt
cdf90737be build: remove support for Linux 3.12 2018-02-12 14:45:41 +01:00
Jan Engelhardt
5713415014 build: remove support for Linux 3.11 2018-02-12 14:45:30 +01:00
Jan Engelhardt
230bc1f327 build: remove support for Linux 3.10 2018-02-12 14:45:14 +01:00
Jan Engelhardt
d360f5578c build: remove support for Linux 3.9 2018-02-12 14:45:00 +01:00
Jan Engelhardt
dd32060f6a build: remove support for Linux 3.8 2018-02-12 14:40:30 +01:00
Jan Engelhardt
d5eb4e586c build: remove support for Linux 3.7 2018-02-12 14:39:36 +01:00
Jan Engelhardt
1b4b4347c5 geoip: apply consistent style to xt_geoip_build 2018-02-12 13:58:18 +01:00
Philip Prindeville
2f37af43c5 geoip: selective endianness catalog generation 2018-02-12 13:56:48 +01:00
Jan Engelhardt
56e5970c64 xt_pknock: don't split function heads 2018-01-05 01:36:12 +01:00
Marcelo Henrique Cerri
2b76b68c65 build: support for Linux 4.15
Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
2018-01-05 01:35:12 +01:00
Seth Forshee
d2eeac4c32 build: (additional) support for Linux 4.14
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
2018-01-05 01:35:07 +01:00
Philip Prindeville
425a035959 xt_geoip: fix typo in error message
Make both instances of the same message (about invalid country codes)
be consistent with each other.  If you have scripts which capture and
collate error messages, then having consistent strings to match against
is a win.

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2017-11-02 21:14:00 -06:00
39 changed files with 756 additions and 490 deletions

2
.gitignore vendored
View File

@@ -2,7 +2,9 @@
*.la
*.lo
*.loT
*.mod
*.o
.cache.mk
.deps/
.dirstamp
.libs/

View File

@@ -12,16 +12,17 @@ in combination with the kernel's Kbuild system.
Supported configurations for this release
=========================================
* iptables >= 1.4.5
* iptables >= 1.6.0
* kernel-devel >= 3.7
* kernel-devel >= 4.15
with prepared build/output directory
- CONFIG_NF_CONNTRACK
- CONFIG_NF_CONNTRACK_MARK enabled =y or as module (=m)
- CONFIG_CONNECTOR y/m if you wish to receive userspace
notifications from pknock through netlink/connector
(Use xtables-addons-1.x if you need support for Linux < 3.7.)
(Use xtables-addons-1.x if you need support for Linux < 3.7.
Use xtables-addons-2.x if you need support for Linux < 4.15.)
Selecting extensions

54
README
View File

@@ -1,57 +1,15 @@
Xtables-addons
==============
Xtables-addons is the proclaimed successor to patch-o-matic(-ng). It
contains extensions that were not accepted in the main Xtables
package.
Xtables-addons is a set of extensions that were not accepted in the
Linux kernel and/or main Xtables/iptables package.
Xtables-addons is different from patch-o-matic in that you do not
have to patch or recompile either kernel or Xtables(iptables). But
please see the INSTALL file for the minimum requirements of this
package.
All code imported from patch-o-matic has been reviewed and all
apparent bugs like binary stability across multiarches, missing
sanity checks and incorrect endianess handling have been fixed,
simplified, and sped up.
It superseded the earlier patch-o-matic(-ng) package in that no
patching and/or recompilation of either the kernel or
Xtables/iptables is required. However, do see the INSTALL file for
the minimum requirements of Xtables-addons.
Included in this package
========================
- xt_ACCOUNT 1.16, libxt_ACCOUNT 1.3
Inclusion into a kernel tree
============================
External extensions
===================
The program "xa-download-more" can be used to download more
extensions from 3rd parties into the source tree. The URLs are listed
in the "sources" file. If the "sources" file contains an entry like
http://foobar.org/xa/
xa-download-more will inspect http://foobar.org/xa/xa-index.txt for
files to download. That file may contain
foobar.tar.bz2
and xa-download-more will then retrieve and unpack
http://foobar.org/xa/foobar.tar.bz2.
Files that should be contained in the tarball are an mconfig and
Kbuild files to control building the extension, libxt_foobar.c for
the userspace extension and xt_foobar.c for the kernel extension.
mconfig.foobar
extensions/Kbuild.foobar
extensions/Mbuild.foobar
extensions/libxt_foobar.c
extensions/libxt_foobar.man
extensions/xt_foobar.c
extensions/xt_foobar.h

View File

@@ -1,4 +1,4 @@
AC_INIT([xtables-addons], [2.14])
AC_INIT([xtables-addons], [3.10])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
@@ -26,7 +26,7 @@ fi
AC_CHECK_HEADERS([linux/netfilter/x_tables.h], [],
[AC_MSG_ERROR([You need to have linux/netfilter/x_tables.h, see INSTALL file for details])])
PKG_CHECK_MODULES([libxtables], [xtables >= 1.4.5])
PKG_CHECK_MODULES([libxtables], [xtables >= 1.6.0])
xtlibdir="$(pkg-config --variable=xtlibdir xtables)"
AC_ARG_WITH([xtlibdir],
@@ -57,12 +57,12 @@ if test -n "$kbuilddir"; then
echo "WARNING: Version detection did not succeed. Continue at own luck.";
else
echo "$kmajor.$kminor.$kmicro.$kstable in $kbuilddir";
if test "$kmajor" -gt 4 -o "$kmajor" -eq 4 -a "$kminor" -gt 12; then
if test "$kmajor" -gt 5 -o "$kmajor" -eq 5 -a "$kminor" -gt 8; then
echo "WARNING: That kernel version is not officially supported yet. Continue at own luck.";
elif test "$kmajor" -eq 4 -a "$kminor" -le 10; then
:;
elif test "$kmajor" -eq 3 -a "$kminor" -ge 7; then
:;
elif test "$kmajor" -eq 5 -a "$kminor" -ge 0; then
:
elif test "$kmajor" -eq 4 -a "$kminor" -ge 15; then
:
else
echo "WARNING: That kernel version is not officially supported.";
fi;

View File

@@ -1,6 +1,71 @@
v3.10 (2020-07-28)
==================
- Support for up to Linux 5.8
HEAD
====
v3.9 (2020-02-25)
=================
- Support for Linux 5.6 procfs changes
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)
=================
Enhancements:
- support for up to Linux 5.3
- xt_PROTO module
v3.3 (2019-03-07)
=================
Enhancements:
- support for Linux 5.0
v3.2 (2018-09-07)
=================
Changes:
- rework xt_geoip_build to scan the immediate directory for .csv,
not to scan for GeoLite2-Country-CSV_\d+.
v3.1 (2018-08-14)
=================
Enhancements:
- support for Linux 4.17, 4.18
v3.0 (2018-02-12)
=================
Enhancements:
- support for Linux 4.15, 4.16
Changes:
- remove support for Linux 3.7--4.14
v2.14 (2017-11-22)
@@ -127,5 +192,5 @@ Changes:
Enhancements:
- Support for Linux 3.7
If you want to use Xtables-addons with kernels older than 3.7,
use the addons 1.x series (maintained but without new features).
If you want to use Xtables-addons with kernels older than 4.15,
use the addons 2.x series.

View File

@@ -40,6 +40,9 @@
#error "ipt_ACCOUNT needs at least a PAGE_SIZE of 4096"
#endif
static unsigned int max_tables_limit = 128;
module_param(max_tables_limit, uint, 0);
/**
* Internal table structure, generated by check_entry()
* @name: name of the table
@@ -185,7 +188,7 @@ static int ipt_acc_table_insert(struct ipt_acc_table *ipt_acc_tables,
name, NIPQUAD(ip), NIPQUAD(netmask));
/* Look for existing table */
for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
for (i = 0; i < max_tables_limit; i++) {
if (strncmp(ipt_acc_tables[i].name, name,
ACCOUNT_TABLE_NAME_LEN) == 0) {
pr_debug("ACCOUNT: Found existing slot: %d - "
@@ -209,7 +212,7 @@ static int ipt_acc_table_insert(struct ipt_acc_table *ipt_acc_tables,
}
/* Insert new table */
for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
for (i = 0; i < max_tables_limit; i++) {
/* Found free slot */
if (ipt_acc_tables[i].name[0] == 0) {
unsigned int netsize = 0;
@@ -258,7 +261,7 @@ static int ipt_acc_table_insert(struct ipt_acc_table *ipt_acc_tables,
/* No free slot found */
printk("ACCOUNT: No free table slot found (max: %d). "
"Please increase ACCOUNT_MAX_TABLES.\n", ACCOUNT_MAX_TABLES);
"Please increase the \"max_tables_limit\" module parameter.\n", max_tables_limit);
return -1;
}
@@ -299,7 +302,7 @@ static void ipt_acc_destroy(const struct xt_tgdtor_param *par)
info->table_nr = -1; /* Set back to original state */
/* Look for table */
for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
for (i = 0; i < max_tables_limit; i++) {
if (strncmp(ian->ipt_acc_tables[i].name, info->table_name,
ACCOUNT_TABLE_NAME_LEN) == 0) {
pr_debug("ACCOUNT: Found table at slot: %d\n", i);
@@ -482,16 +485,7 @@ static void ipt_acc_depth2_insert(struct ipt_acc_mask_8 *mask_8,
static unsigned int
ipt_acc_target(struct sk_buff *skb, const struct xt_action_param *par)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
struct ipt_acc_net *ian = net_generic(par->state->net, ipt_acc_net_id);
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0)
struct ipt_acc_net *ian = net_generic(par->net, ipt_acc_net_id);
#else
struct net *net = dev_net(par->in ? par->in : par->out);
struct ipt_acc_net *ian = net_generic(net, ipt_acc_net_id);
#endif
#endif
struct ipt_acc_table *ipt_acc_tables = ian->ipt_acc_tables;
const struct ipt_acc_info *info =
par->targinfo;
@@ -613,12 +607,12 @@ static int ipt_acc_handle_prepare_read(struct ipt_acc_table *ipt_acc_tables,
int table_nr = -1;
uint8_t depth;
for (table_nr = 0; table_nr < ACCOUNT_MAX_TABLES; table_nr++)
for (table_nr = 0; table_nr < max_tables_limit; table_nr++)
if (strncmp(ipt_acc_tables[table_nr].name, tablename,
ACCOUNT_TABLE_NAME_LEN) == 0)
break;
if (table_nr == ACCOUNT_MAX_TABLES) {
if (table_nr == max_tables_limit) {
printk("ACCOUNT: ipt_acc_handle_prepare_read(): "
"Table %s not found\n", tablename);
return -1;
@@ -716,12 +710,12 @@ static int ipt_acc_handle_prepare_read_flush(struct ipt_acc_table *ipt_acc_table
int table_nr;
void *new_data_page;
for (table_nr = 0; table_nr < ACCOUNT_MAX_TABLES; table_nr++)
for (table_nr = 0; table_nr < max_tables_limit; table_nr++)
if (strncmp(ipt_acc_tables[table_nr].name, tablename,
ACCOUNT_TABLE_NAME_LEN) == 0)
break;
if (table_nr == ACCOUNT_MAX_TABLES) {
if (table_nr == max_tables_limit) {
printk("ACCOUNT: ipt_acc_handle_prepare_read_flush(): "
"Table %s not found\n", tablename);
return -1;
@@ -1061,7 +1055,7 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len)
spin_lock_bh(&ian->ipt_acc_lock);
/* Determine size of table names */
for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
for (i = 0; i < max_tables_limit; i++) {
if (ian->ipt_acc_tables[i].name[0] != 0)
size += strlen(ian->ipt_acc_tables[i].name) + 1;
}
@@ -1076,7 +1070,7 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len)
}
/* Copy table names to userspace */
tnames = ian->ipt_acc_tmpbuf;
for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
for (i = 0; i < max_tables_limit; i++) {
if (ian->ipt_acc_tables[i].name[0] != 0) {
name_len = strlen(ian->ipt_acc_tables[i].name) + 1;
memcpy(tnames, ian->ipt_acc_tables[i].name, name_len);
@@ -1109,7 +1103,7 @@ static int __net_init ipt_acc_net_init(struct net *net)
memset(ian, 0, sizeof(*ian));
sema_init(&ian->ipt_acc_userspace_mutex, 1);
ian->ipt_acc_tables = kcalloc(ACCOUNT_MAX_TABLES,
ian->ipt_acc_tables = kcalloc(max_tables_limit,
sizeof(struct ipt_acc_table), GFP_KERNEL);
if (ian->ipt_acc_tables == NULL) {
printk("ACCOUNT: Out of memory allocating account_tables structure");

View File

@@ -34,7 +34,6 @@
#define IPT_SO_GET_ACCOUNT_GET_TABLE_NAMES (SO_ACCOUNT_BASE_CTL + 8)
#define IPT_SO_GET_ACCOUNT_MAX IPT_SO_GET_ACCOUNT_GET_TABLE_NAMES
#define ACCOUNT_MAX_TABLES 128
#define ACCOUNT_TABLE_NAME_LEN 32
#define ACCOUNT_MAX_HANDLES 10

View File

@@ -13,6 +13,7 @@ obj-${build_DNETMAP} += xt_DNETMAP.o
obj-${build_ECHO} += xt_ECHO.o
obj-${build_IPMARK} += xt_IPMARK.o
obj-${build_LOGMARK} += xt_LOGMARK.o
obj-${build_PROTO} += xt_PROTO.o
obj-${build_SYSRQ} += xt_SYSRQ.o
obj-${build_TARPIT} += xt_TARPIT.o
obj-${build_condition} += xt_condition.o

View File

@@ -8,6 +8,7 @@ obj-${build_DNETMAP} += libxt_DNETMAP.so
obj-${build_ECHO} += libxt_ECHO.so
obj-${build_IPMARK} += libxt_IPMARK.so
obj-${build_LOGMARK} += libxt_LOGMARK.so
obj-${build_PROTO} += libxt_PROTO.so
obj-${build_SYSRQ} += libxt_SYSRQ.so
obj-${build_TARPIT} += libxt_TARPIT.so
obj-${build_condition} += libxt_condition.so

View File

@@ -8,12 +8,8 @@
#define DEBUGP Use__pr_debug__instead
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
# warning Kernels below 3.7 not supported.
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0)
# define prandom_u32() random32()
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0)
# warning Kernels below 4.15 not supported.
#endif
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
@@ -46,51 +42,22 @@
# define NIPQUAD_FMT "%hhu.%hhu.%hhu.%hhu"
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
static inline struct inode *file_inode(struct file *f)
{
return f->f_path.dentry->d_inode;
}
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
static inline void proc_set_user(struct proc_dir_entry *de,
typeof(de->uid) uid, typeof(de->gid) gid)
{
de->uid = uid;
de->gid = gid;
}
static inline void *PDE_DATA(struct inode *inode)
{
return PDE(inode)->data;
}
static inline void proc_remove(struct proc_dir_entry *de)
{
if (de != NULL)
remove_proc_entry(de->name, de->parent);
}
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0)
# define ip6_local_out(xnet, xsk, xskb) ip6_local_out(xskb)
# define ip6_route_me_harder(xnet, xskb) ip6_route_me_harder(xskb)
# define ip_local_out(xnet, xsk, xskb) ip_local_out(xskb)
# define ip_route_me_harder(xnet, xskb, xaddrtype) ip_route_me_harder((xskb), (xaddrtype))
#endif
static inline struct net *par_net(const struct xt_action_param *par)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
return par->state->net;
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
return par->net;
#else
return dev_net((par->in != NULL) ? par->in : par->out);
#endif
#endif
}
#ifndef NF_CT_ASSERT
# define NF_CT_ASSERT(x) WARN_ON(!(x))
#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 */

View File

@@ -46,7 +46,7 @@ Contains the binding table for the given \fIsubnet/mask\fP. Each line contains
\fBprenat address\fR, \fBpostnat address\fR, \fBttl\fR (seconds until the entry
times out), \fBlasthit\fR (last hit to the entry in seconds relative to system
boot time). Please note that the \fBttl\fR and \fBlasthit\fR entries contain an
'\fBS\fR' in case of a static binding.
\(oq\fBS\fR\(cq in case of a static binding.
.TP
\fB/proc/net/xt_DNETMAP/\fR\fIsubnet\fR\fB_\fR\fImask\fR\fB_stat\fR
Contains statistics for a given \fIsubnet/mask\fP. The line contains four

105
extensions/libxt_PROTO.c Normal file
View File

@@ -0,0 +1,105 @@
/*
* PROTO Target module
* This program is distributed under the terms of GNU GPL
*/
#include <stdio.h>
#include <xtables.h>
#include "xt_PROTO.h"
enum {
O_PROTO_SET = 0,
O_PROTO_STOP_AT_FRAG = 1,
O_PROTO_STOP_AT_AUTH = 2,
F_PROTO_SET = 1 << O_PROTO_SET,
F_PROTO_STOP_AT_FRAG = 1 << O_PROTO_STOP_AT_FRAG,
F_PROTO_STOP_AT_AUTH = 1 << O_PROTO_STOP_AT_AUTH,
};
#define s struct xt_PROTO_info
static const struct xt_option_entry PROTO_opts[] = {
{.name = "proto-set", .type = XTTYPE_UINT8, .id = O_PROTO_SET,
.flags = XTOPT_PUT | XTOPT_MAND, XTOPT_POINTER(s, proto)},
{.name = "stop-at-frag", .type = XTTYPE_NONE, .id = O_PROTO_STOP_AT_FRAG},
{.name = "stop-at-auth", .type = XTTYPE_NONE, .id = O_PROTO_STOP_AT_AUTH},
XTOPT_TABLEEND,
};
#undef s
static void PROTO_help(void)
{
printf(
"PROTO target options\n"
" --proto-set value Set protocol to <value 0-255>\n"
);
}
static void PROTO_parse(struct xt_option_call *cb)
{
struct xt_PROTO_info *info = cb->data;
xtables_option_parse(cb);
switch (cb->entry->id) {
case O_PROTO_SET:
info->mode |= 1 << XT_PROTO_SET;
break;
case O_PROTO_STOP_AT_FRAG:
info->mode |= 1 << XT_PROTO_STOP_AT_FRAG;
break;
case O_PROTO_STOP_AT_AUTH:
info->mode |= 1 << XT_PROTO_STOP_AT_AUTH;
break;
}
}
static void PROTO_check(struct xt_fcheck_call *cb)
{
if (!(cb->xflags & F_PROTO_SET))
xtables_error(PARAMETER_PROBLEM,
"PROTO: You must specify the proto to be set");
}
static void PROTO_save(const void *ip, const struct xt_entry_target *target)
{
const struct xt_PROTO_info *info = (void *)target->data;
if (info->mode & (1 << XT_PROTO_SET))
printf(" --proto-set %u", info->proto);
if (info->mode & (1 << XT_PROTO_STOP_AT_FRAG))
printf(" --stop-at-frag");
if (info->mode & (1 << XT_PROTO_STOP_AT_AUTH))
printf(" --stop-at-auth");
}
static void PROTO_print(const void *ip, const struct xt_entry_target *target,
int numeric)
{
const struct xt_PROTO_info *info = (void *)target->data;
printf(" PROTO ");
if (info->mode & (1 << XT_PROTO_SET))
printf("set to %u", info->proto);
if (info->mode & (1 << XT_PROTO_STOP_AT_FRAG))
printf(" stop-at-frag");
if (info->mode & (1 << XT_PROTO_STOP_AT_AUTH))
printf(" stop-at-auth");
}
static struct xtables_target proto_tg_reg = {
.name = "PROTO",
.version = XTABLES_VERSION,
.family = NFPROTO_UNSPEC,
.size = XT_ALIGN(sizeof(struct xt_PROTO_info)),
.userspacesize = XT_ALIGN(sizeof(struct xt_PROTO_info)),
.help = PROTO_help,
.print = PROTO_print,
.save = PROTO_save,
.x6_parse = PROTO_parse,
.x6_fcheck = PROTO_check,
.x6_options = PROTO_opts,
};
static __attribute__((constructor)) void _init(void)
{
xtables_register_target(&proto_tg_reg);
}

View File

@@ -0,0 +1,30 @@
.PP
The PROTO target modifies the protocol number in IP packet header.
.TP
\fB\-\-proto-set\fP \fIproto_num\fP
This option is mandatory. \fIproto_num\fP is the protocol number to which you want to
modify the packets.
.TP
\fB\-\-stop-at-frag\fP
This option is only valid for IPv6 rules. When specifying this option, the
fragment extension header will be seen as a non-extension header.
.TP
\fB\-\-stop-at-auth\fP
This option is only valid for IPv6 rules. When specifying this option, the
authentication extension header will be seen as a non-extension header.
.PP
For IPv4 packets, the \fBProtocol\fP field is modified and the checksum is
re-calculated.
.PP
For IPv6 packets, the scenario can be more complex due to the introduction of
the extension headers mechanism. By default, the PROTO target will scan the IPv6
packet, finding the last extension header and modify its \fBNext-header\fP field.
Normally, the following headers will be seen as an extension header:
\fINEXTHDR_HOP\fP,
\fINEXTHDR_ROUTING\fP,
\fINEXTHDR_FRAGMENT\fP,
\fINEXTHDR_AUTH\fP,
\fINEXTHDR_DEST\fP.
.PP
For fragmented packets, only the first fragment is processed and other fragments
are not touched.

View File

@@ -49,6 +49,26 @@ static struct option geoip_opts[] = {
{NULL},
};
#if __BYTE_ORDER == __LITTLE_ENDIAN
static void geoip_swap_le32(uint32_t *buf)
{
unsigned char *p = (void *)buf;
uint32_t n = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24);
p[0] = (n >> 24) & 0xff;
p[1] = (n >> 16) & 0xff;
p[2] = (n >> 8) & 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
static void *
geoip_get_subnets(const char *code, uint32_t *count, uint8_t nfproto)
{
@@ -56,21 +76,15 @@ geoip_get_subnets(const char *code, uint32_t *count, uint8_t nfproto)
struct stat sb;
char buf[256];
int fd;
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned int n;
#endif
/* Use simple integer vector files */
if (nfproto == NFPROTO_IPV6) {
#if __BYTE_ORDER == _BIG_ENDIAN
snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/BE/%s.iv6", code);
#else
snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/LE/%s.iv6", code);
#endif
} else {
#if __BYTE_ORDER == _BIG_ENDIAN
snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/BE/%s.iv4", code);
#else
snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/LE/%s.iv4", code);
#endif
}
if (nfproto == NFPROTO_IPV6)
snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/%s.iv6", code);
else
snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/%s.iv4", code);
if ((fd = open(buf, O_RDONLY)) < 0) {
fprintf(stderr, "Could not open %s: %s\n", buf, strerror(errno));
@@ -98,6 +112,25 @@ geoip_get_subnets(const char *code, uint32_t *count, uint8_t nfproto)
xtables_error(OTHER_PROBLEM, "geoip: insufficient memory");
read(fd, subnets, sb.st_size);
close(fd);
#if __BYTE_ORDER == __LITTLE_ENDIAN
for (n = 0; n < *count; ++n) {
switch (nfproto) {
case NFPROTO_IPV6: {
struct geoip_subnet6 *gs6 = &(((struct geoip_subnet6 *)subnets)[n]);
geoip_swap_in6(&gs6->begin);
geoip_swap_in6(&gs6->end);
break;
}
case NFPROTO_IPV4: {
struct geoip_subnet4 *gs4 = &(((struct geoip_subnet4 *)subnets)[n]);
geoip_swap_le32(&gs4->begin);
geoip_swap_le32(&gs4->end);
break;
}
}
}
#endif
return subnets;
}
@@ -135,7 +168,7 @@ check_geoip_cc(char *cc, u_int16_t cc_used[], u_int8_t count)
cc[i] = toupper(cc[i]);
else
xtables_error(PARAMETER_PROBLEM,
"geoip: invalid country code '%s'", cc);
"geoip: invalid country code '%s'", cc);
/* Convert chars into a single 16 bit integer.
* FIXME: This assumes that a country code is

View File

@@ -295,12 +295,11 @@ pknock_proc_open(struct inode *inode, struct file *file)
return ret;
}
static const struct file_operations pknock_proc_ops = {
.owner = THIS_MODULE,
.open = pknock_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release
static const struct proc_ops pknock_proc_ops = {
.proc_open = pknock_proc_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_release = seq_release,
};
/**
@@ -357,11 +356,10 @@ has_logged_during_this_minute(const struct peer *peer)
*
* @r: rule
*/
static void
peer_gc(unsigned long r)
static void peer_gc(struct timer_list *tl)
{
unsigned int i;
struct xt_pknock_rule *rule = (struct xt_pknock_rule *)r;
struct xt_pknock_rule *rule = from_timer(rule, tl, timer);
struct peer *peer;
struct list_head *pos, *n;
@@ -468,11 +466,7 @@ add_rule(struct xt_pknock_mtinfo *info)
rule->peer_head = alloc_hashtable(peer_hashsize);
if (rule->peer_head == NULL)
goto out;
init_timer(&rule->timer);
rule->timer.function = peer_gc;
rule->timer.data = (unsigned long)rule;
timer_setup(&rule->timer, peer_gc, 0);
rule->status_proc = proc_create_data(info->rule_name, 0, pde,
&pknock_proc_ops, rule);
if (rule->status_proc == NULL)
@@ -699,13 +693,7 @@ msg_to_userspace_nl(const struct xt_pknock_mtinfo *info,
scnprintf(msg.rule_name, info->rule_name_len + 1, info->rule_name);
memcpy(m + 1, &msg, m->len);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 15, 0)
cn_netlink_send(m, 0, multicast_group, GFP_ATOMIC);
#else
cn_netlink_send(m, multicast_group, GFP_ATOMIC);
#endif
kfree(m);
#endif
return true;
@@ -1136,7 +1124,6 @@ static int __init xt_pknock_mt_init(void)
crypto.size = crypto_shash_digestsize(crypto.tfm);
crypto.desc.tfm = crypto.tfm;
crypto.desc.flags = 0;
pde = proc_mkdir("xt_pknock", init_net.proc_net);
if (pde == NULL) {

View File

@@ -58,12 +58,7 @@ xt_chaos_total(struct sk_buff *skb, const struct xt_action_param *par)
{
struct xt_action_param local_par;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
local_par.state = par->state;
#else
local_par.in = par->in,
local_par.out = par->out,
#endif
local_par.match = xm_tcp;
local_par.matchinfo = &tcp_params;
local_par.fragoff = fragoff;
@@ -78,14 +73,7 @@ xt_chaos_total(struct sk_buff *skb, const struct xt_action_param *par)
destiny = (info->variant == XTCHAOS_TARPIT) ? xt_tarpit : xt_delude;
{
struct xt_action_param local_par;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
local_par.state = par->state;
#else
local_par.in = par->in;
local_par.out = par->out;
local_par.hooknum = par->hooknum;
local_par.family = par->family;
#endif
local_par.target = destiny;
local_par.targinfo = par->targinfo;
destiny->target(skb, &local_par);
@@ -108,27 +96,15 @@ chaos_tg(struct sk_buff *skb, const struct xt_action_param *par)
if ((unsigned int)prandom_u32() <= reject_percentage) {
struct xt_action_param local_par;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
local_par.state = par->state;
#else
local_par.in = par->in;
local_par.out = par->out;
local_par.hooknum = par->hooknum;
#endif
local_par.target = xt_reject;
local_par.targinfo = &reject_params;
return xt_reject->target(skb, &local_par);
}
/* TARPIT/DELUDE may not be called from the OUTPUT chain */
if (iph->protocol == IPPROTO_TCP &&
info->variant != XTCHAOS_NORMAL &&
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
par->state->hook
#else
par->hooknum
#endif
!= NF_INET_LOCAL_OUT)
if (iph->protocol == IPPROTO_TCP && info->variant != XTCHAOS_NORMAL &&
par->state->hook != NF_INET_LOCAL_OUT)
xt_chaos_total(skb, par);
return NF_DROP;

View File

@@ -107,12 +107,12 @@ static void delude_send_reset(struct net *net, struct sk_buff *oldskb,
addr_type = RTN_UNSPEC;
#ifdef CONFIG_BRIDGE_NETFILTER
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
if (hook != NF_INET_FORWARD || (nskb->nf_bridge != NULL &&
nskb->nf_bridge->physoutdev))
#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 &&
nskb->nf_bridge->mask & BRNF_BRIDGED))
nskb->nf_bridge->physoutdev))
#endif
#else
if (hook != NF_INET_FORWARD)
@@ -151,13 +151,7 @@ delude_tg(struct sk_buff *skb, const struct xt_action_param *par)
* a problem, as that is supported since Linux 2.6.35. But since we do not
* actually want to have a connection open, we are still going to drop it.
*/
delude_send_reset(par_net(par), skb,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
par->state->hook
#else
par->hooknum
#endif
);
delude_send_reset(par_net(par), skb, par->state->hook);
return NF_DROP;
}

View File

@@ -96,7 +96,8 @@ dhcpmac_tg(struct sk_buff *skb, const struct xt_action_param *par)
struct udphdr udpbuf, *udph;
unsigned int i;
if (!skb_make_writable(skb, 0))
if (skb_ensure_writable(skb, ip_hdrlen(skb) + sizeof(udpbuf) +
sizeof(dhcpbuf)))
return NF_DROP;
udph = skb_header_pointer(skb, ip_hdrlen(skb),

View File

@@ -115,7 +115,7 @@ static DEFINE_SPINLOCK(dnetmap_lock);
static DEFINE_MUTEX(dnetmap_mutex);
#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
static inline unsigned int dnetmap_entry_hash(const __be32 addr)
@@ -356,26 +356,22 @@ out:
static unsigned int
dnetmap_tg(struct sk_buff *skb, const struct xt_action_param *par)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
struct net *net = dev_net(par->state->in ? par->state->in : par->state->out);
#else
struct net *net = dev_net(par->in ? par->in : par->out);
#endif
struct dnetmap_net *dnetmap_net = dnetmap_pernet(net);
struct nf_conn *ct;
enum ip_conntrack_info ctinfo;
__be32 prenat_ip, postnat_ip, prenat_ip_prev;
const struct xt_DNETMAP_tginfo *tginfo = par->targinfo;
const struct nf_nat_range *mr = &tginfo->prefix;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0)
struct nf_nat_range2 newrange;
#else
struct nf_nat_range newrange;
#endif
struct dnetmap_entry *e;
struct dnetmap_prefix *p;
__s32 jttl;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
unsigned int hooknum = par->state->hook;
#else
unsigned int hooknum = par->hooknum;
#endif
ct = nf_ct_get(skb, &ctinfo);
jttl = tginfo->flags & XT_DNETMAP_TTL ? tginfo->ttl * HZ : jtimeout;
@@ -500,12 +496,7 @@ bind_new_prefix:
newrange.max_addr.ip = postnat_ip;
newrange.min_proto = mr->min_proto;
newrange.max_proto = mr->max_proto;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
return nf_nat_setup_info(ct, &newrange, HOOK2MANIP(par->state->hook));
#else
return nf_nat_setup_info(ct, &newrange, HOOK2MANIP(par->hooknum));
#endif
no_rev_map:
no_free_ip:
spin_unlock_bh(&dnetmap_lock);
@@ -777,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 = {
.open = dnetmap_seq_open,
.read = seq_read,
.write = dnetmap_tg_proc_write,
.release = seq_release_private,
.owner = THIS_MODULE,
static const struct proc_ops dnetmap_tg_fops = {
.proc_open = dnetmap_seq_open,
.proc_read = seq_read,
.proc_write = dnetmap_tg_proc_write,
.proc_release = seq_release_private,
};
/* for statistics */
@@ -826,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));
}
static const struct file_operations dnetmap_stat_proc_fops = {
.open = dnetmap_stat_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
static const struct proc_ops dnetmap_stat_proc_fops = {
.proc_open = dnetmap_stat_proc_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_release = single_release,
};
static int __net_init dnetmap_proc_net_init(struct net *net)

View File

@@ -35,11 +35,7 @@ echo_tg6(struct sk_buff *oldskb, const struct xt_action_param *par)
void *payload;
struct flowi6 fl;
struct dst_entry *dst = NULL;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
struct net *net = dev_net((par->state->in != NULL) ? par->state->in : par->state->out);
#else
struct net *net = dev_net((par->in != NULL) ? par->in : par->out);
#endif
/* This allows us to do the copy operation in fewer lines of code. */
if (skb_linearize(oldskb) < 0)

View File

@@ -64,12 +64,7 @@ static void logmark_ct(const struct nf_conn *ct, enum ip_conntrack_info ctinfo)
printk("%s""CONFIRMED", prev ? "," : "");
prev = true;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,9,0)
printk(" lifetime=%lus", nf_ct_expires(ct) / HZ);
#else
printk(" lifetime=%lus",
(jiffies - ct->timeout.expires) / HZ);
#endif
}
static unsigned int
@@ -82,21 +77,13 @@ logmark_tg(struct sk_buff *skb, const struct xt_action_param *par)
printk("<%u>%.*s""iif=%d hook=%s nfmark=0x%x "
"secmark=0x%x classify=0x%x",
info->level, (unsigned int)sizeof(info->prefix), info->prefix,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
skb_ifindex(skb), hook_names[par->state->hook],
#else
skb_ifindex(skb), hook_names[par->hooknum],
#endif
skb_nfmark(skb), skb_secmark(skb), skb->priority);
ct = nf_ct_get(skb, &ctinfo);
printk(" ctdir=%s", dir_names[ctinfo >= IP_CT_IS_REPLY]);
if (ct == NULL)
printk(" ct=NULL ctmark=NULL ctstate=INVALID ctstatus=NONE");
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0)
else if (nf_ct_is_untracked(ct))
printk(" ct=UNTRACKED ctmark=NULL ctstate=UNTRACKED ctstatus=NONE");
#endif
else
logmark_ct(ct, ctinfo);

156
extensions/xt_PROTO.c Normal file
View File

@@ -0,0 +1,156 @@
/*
* Protocol modification target for IP tables
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <net/ipv6.h>
#include <net/checksum.h>
#include <linux/netfilter/x_tables.h>
#include "xt_PROTO.h"
MODULE_AUTHOR("Shanker Wang <i@innull.com>");
MODULE_DESCRIPTION("Xtables: Protocol field modification target");
MODULE_LICENSE("GPL");
static unsigned int
proto_tg(struct sk_buff *skb, const struct xt_action_param *par)
{
struct iphdr *iph;
const struct xt_PROTO_info *info = par->targinfo;
int new_proto;
if (skb_ensure_writable(skb, skb->len))
return NF_DROP;
iph = ip_hdr(skb);
new_proto = iph->protocol;
if (info->mode & (1 << XT_PROTO_SET))
new_proto = info->proto;
if (new_proto != iph->protocol) {
csum_replace2(&iph->check, htons(iph->protocol & 0xff),
htons(new_proto & 0xff));
iph->protocol = new_proto;
}
return XT_CONTINUE;
}
static unsigned int
proto_tg6(struct sk_buff *skb, const struct xt_action_param *par)
{
struct ipv6hdr *ip6h;
const struct xt_PROTO_info *info = par->targinfo;
u8 *nexthdr;
unsigned int hdr_offset;
__be16 *fp;
if (skb_ensure_writable(skb, skb->len))
return NF_DROP;
ip6h = ipv6_hdr(skb);
nexthdr = &ip6h->nexthdr;
hdr_offset = sizeof(struct ipv6hdr);
for (;;) {
struct ipv6_opt_hdr _opthdr, *opthp;
unsigned int hdrlen;
unsigned short _frag_off;
if (!ipv6_ext_hdr(*nexthdr) || *nexthdr == NEXTHDR_NONE)
break;
opthp = skb_header_pointer(skb, skb_network_offset(skb) + hdr_offset, sizeof(_opthdr), &_opthdr);
if (!opthp)
return NF_DROP;
if (*nexthdr == NEXTHDR_FRAGMENT) {
if (info->mode & (1 << XT_PROTO_STOP_AT_FRAG))
break;
fp = skb_header_pointer(skb, skb_network_offset(skb) +
hdr_offset + offsetof(struct frag_hdr, frag_off),
sizeof(_frag_off), &_frag_off);
if (!fp)
return NF_DROP;
_frag_off = ntohs(*fp) & ~0x7;
if (_frag_off) { // if the packet is not the first fragment
if (!ipv6_ext_hdr(opthp->nexthdr) || opthp->nexthdr == NEXTHDR_NONE ||
(info->mode & (1 << XT_PROTO_STOP_AT_AUTH) && opthp->nexthdr == NEXTHDR_AUTH)) {
nexthdr = &((struct ipv6_opt_hdr *)(skb_network_header(skb) + hdr_offset))->nexthdr;
break;
} else {
return XT_CONTINUE;
}
}
hdrlen = 8;
} else if(*nexthdr == NEXTHDR_AUTH) {
if (info->mode & (1 << XT_PROTO_STOP_AT_AUTH))
break;
hdrlen = (opthp->hdrlen + 2) << 2;
} else {
hdrlen = ipv6_optlen(opthp);
}
nexthdr = &((struct ipv6_opt_hdr *)(skb_network_header(skb) + hdr_offset))->nexthdr;
hdr_offset += hdrlen;
}
if (info->mode & (1 << XT_PROTO_SET))
*nexthdr = info->proto;
return XT_CONTINUE;
}
static int proto_tg_check(const struct xt_tgchk_param *par)
{
const struct xt_PROTO_info *info = par->targinfo;
if ((info->mode & (1 << XT_PROTO_SET)) == 0) {
pr_info_ratelimited("Did not specify any proto to set\n");
return -EINVAL;
}
if (par->family != NFPROTO_IPV6 && (info->mode & ((1 << XT_PROTO_STOP_AT_FRAG) | (1 << XT_PROTO_STOP_AT_AUTH))) != 0) {
pr_info_ratelimited("Must not specify stop-at-frag and stop-at-auth on non-ipv6 targets\n");
return -EPROTOTYPE;
}
return 0;
}
static struct xt_target proto_tg_reg[] __read_mostly = {
{
.name = "PROTO",
.revision = 0,
.family = NFPROTO_IPV4,
.target = proto_tg,
.targetsize = sizeof(struct xt_PROTO_info),
.table = "mangle",
.checkentry = proto_tg_check,
.me = THIS_MODULE,
},
{
.name = "PROTO",
.revision = 0,
.family = NFPROTO_IPV6,
.target = proto_tg6,
.targetsize = sizeof(struct xt_PROTO_info),
.table = "mangle",
.checkentry = proto_tg_check,
.me = THIS_MODULE,
},
};
static int __init proto_tg_init(void)
{
return xt_register_targets(proto_tg_reg, ARRAY_SIZE(proto_tg_reg));
}
static void __exit proto_tg_exit(void)
{
xt_unregister_targets(proto_tg_reg, ARRAY_SIZE(proto_tg_reg));
}
module_init(proto_tg_init);
module_exit(proto_tg_exit);
MODULE_ALIAS("ipt_PROTO");
MODULE_ALIAS("ip6t_PROTO");

20
extensions/xt_PROTO.h Normal file
View File

@@ -0,0 +1,20 @@
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/* Protocol modification module for IP tables */
#ifndef _XT_PROTO_H
#define _XT_PROTO_H
#include <linux/types.h>
enum {
XT_PROTO_SET = 0,
XT_PROTO_STOP_AT_FRAG = 1,
XT_PROTO_STOP_AT_AUTH = 2
};
struct xt_PROTO_info {
__u8 mode;
__u8 proto;
};
#endif

View File

@@ -114,7 +114,6 @@ static unsigned int sysrq_tg(const void *pdata, uint16_t len)
}
desc.tfm = sysrq_tfm;
desc.flags = 0;
ret = crypto_shash_init(&desc);
if (ret != 0)
goto hash_fail;
@@ -314,7 +313,7 @@ static void sysrq_crypto_exit(void)
static int __init sysrq_crypto_init(void)
{
#if defined(WITH_CRYPTO)
struct timeval now;
struct timespec64 now;
int ret;
sysrq_tfm = crypto_alloc_shash(sysrq_hash, 0, 0);
@@ -339,7 +338,7 @@ static int __init sysrq_crypto_init(void)
sizeof(sysrq_password), GFP_KERNEL);
if (sysrq_digest_password == NULL)
goto fail;
do_gettimeofday(&now);
ktime_get_real_ts64(&now);
sysrq_seqno = now.tv_sec;
return 0;

View File

@@ -205,7 +205,11 @@ static void tarpit_tcp4(struct net *net, struct sk_buff *oldskb,
return;
/* 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);
#endif
skb_nfmark(nskb) = 0;
skb_init_secmark(nskb);
skb_shinfo(nskb)->gso_size = 0;
@@ -249,12 +253,12 @@ static void tarpit_tcp4(struct net *net, struct sk_buff *oldskb,
niph->id = ~oldhdr->id + 1;
#ifdef CONFIG_BRIDGE_NETFILTER
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
if (hook != NF_INET_FORWARD || (nskb->nf_bridge != NULL &&
nskb->nf_bridge->physoutdev != NULL))
#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 &&
nskb->nf_bridge->mask & BRNF_BRIDGED))
nskb->nf_bridge->physoutdev != NULL))
#endif
#else
if (hook != NF_INET_FORWARD)
@@ -283,17 +287,8 @@ static void tarpit_tcp4(struct net *net, struct sk_buff *oldskb,
goto free_nskb;
nf_ct_attach(nskb, oldskb);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, net, nskb->sk, nskb, NULL,
skb_dst(nskb)->dev, dst_output);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, nskb->sk, nskb, NULL,
skb_dst(nskb)->dev, dst_output_sk);
#else
NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, nskb, NULL,
skb_dst(nskb)->dev, dst_output);
#endif
return;
free_nskb:
@@ -355,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 */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)
nf_reset_ct(nskb);
#else
nf_reset(nskb);
#endif
skb_nfmark(nskb) = 0;
skb_init_secmark(nskb);
skb_shinfo(nskb)->gso_size = 0;
@@ -406,17 +405,8 @@ static void tarpit_tcp6(struct net *net, struct sk_buff *oldskb,
nskb->ip_summed = CHECKSUM_NONE;
nf_ct_attach(nskb, oldskb);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, net, nskb->sk, nskb, NULL,
skb_dst(nskb)->dev, dst_output);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, nskb->sk, nskb, NULL,
skb_dst(nskb)->dev, dst_output_sk);
#else
NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, nskb, NULL,
skb_dst(nskb)->dev, dst_output);
#endif
return;
free_nskb:
@@ -454,12 +444,7 @@ tarpit_tg4(struct sk_buff *skb, const struct xt_action_param *par)
/* We are not interested in fragments */
if (iph->frag_off & htons(IP_OFFSET))
return NF_DROP;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
tarpit_tcp4(par_net(par), skb, par->state->hook, info->variant);
#else
tarpit_tcp4(par_net(par), skb, par->hooknum, info->variant);
#endif
return NF_DROP;
}
@@ -500,12 +485,7 @@ tarpit_tg6(struct sk_buff *skb, const struct xt_action_param *par)
pr_debug("addr is not unicast.\n");
return NF_DROP;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
tarpit_tcp6(par_net(par), skb, par->state->hook, info->variant);
#else
tarpit_tcp6(par_net(par), skb, par->hooknum, info->variant);
#endif
return NF_DROP;
}
#endif

View File

@@ -111,12 +111,12 @@ condition_proc_write(struct file *file, const char __user *buffer,
return length;
}
static const struct file_operations condition_proc_fops = {
.open = condition_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.write = condition_proc_write,
.release = single_release,
static const struct proc_ops condition_proc_fops = {
.proc_open = condition_proc_open,
.proc_read = seq_read,
.proc_write = condition_proc_write,
.proc_lseek = seq_lseek,
.proc_release = single_release,
};
static bool

View File

@@ -45,17 +45,9 @@ static const struct net_device *iface_get(const struct xt_iface_mtinfo *info,
const struct xt_action_param *par, struct net_device **put)
{
if (info->flags & XT_IFACE_DEV_IN)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
return par->state->in;
#else
return par->in;
#endif
else if (info->flags & XT_IFACE_DEV_OUT)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
return par->state->out;
#else
return par->out;
#endif
return *put = dev_get_by_name(&init_net, info->ifname);
}

View File

@@ -204,11 +204,7 @@ lscan_mt(const struct sk_buff *skb, struct xt_action_param *par)
unsigned int n;
n = lscan_mt_full(ctdata->mark & connmark_mask, ctstate,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
par->state->in == init_net.loopback_dev, tcph,
#else
par->in == init_net.loopback_dev, tcph,
#endif
skb->len - par->thoff - 4 * tcph->doff);
ctdata->mark = (ctdata->mark & ~connmark_mask) | n;

View File

@@ -117,12 +117,12 @@ quota_proc_write(struct file *file, const char __user *input,
return size;
}
static const struct file_operations quota_proc_fops = {
.open = quota_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.write = quota_proc_write,
.release = single_release,
static const struct proc_ops quota_proc_fops = {
.proc_open = quota_proc_open,
.proc_read = seq_read,
.proc_write = quota_proc_write,
.proc_lseek = seq_lseek,
.proc_release = single_release,
};
static struct xt_quota_counter *

View File

@@ -1,5 +1,7 @@
# -*- Makefile -*-
bin_SCRIPTS = xt_geoip_fetch
pkglibexec_SCRIPTS = xt_geoip_build xt_geoip_dl
man1_MANS = xt_geoip_build.1 xt_geoip_dl.1
man1_MANS = xt_geoip_build.1 xt_geoip_dl.1 xt_geoip_fetch.1

View File

@@ -1,10 +1,14 @@
#!/usr/bin/perl
#
# Converter for MaxMind CSV database to binary, for xt_geoip
# Copyright © Jan Engelhardt, 2008-2011
# Converter for DBIP (Country Lite) CSV database to binary, for xt_geoip
# Copyright Jan Engelhardt, 2008-2011
# Copyright Philip Prindeville, 2018
# Copyright Arjen de Korte, 2020
#
use Getopt::Long;
use IO::Handle;
use Net::CIDR::Lite;
use Socket qw(AF_INET AF_INET6 inet_pton);
use warnings;
use Text::CSV_XS; # or trade for Text::CSV
use strict;
@@ -13,52 +17,62 @@ my $csv = Text::CSV_XS->new({
binary => 1,
eol => $/,
}); # or Text::CSV
my $quiet = 0;
my $input_file = "dbip-country-lite.csv";
my $target_dir = ".";
&Getopt::Long::Configure(qw(bundling));
&GetOptions(
"D=s" => \$target_dir,
"i=s" => \$input_file,
"q" => \$quiet,
"s" => sub { $target_dir = "/usr/share/xt_geoip"; },
);
if (!-d $target_dir) {
print STDERR "Target directory $target_dir does not exist.\n";
print STDERR "Target directory \"$target_dir\" does not exist.\n";
exit 1;
}
foreach (qw(LE BE)) {
my $dir = "$target_dir/$_";
if (!-e $dir && !mkdir($dir)) {
print STDERR "Could not mkdir $dir: $!\n";
exit 1;
}
}
&dump(&collect());
sub collect
{
my %country;
my ($file, $fh, $row);
my (%country);
if ($input_file eq "-") {
open($fh, "<&STDIN");
} else {
open($fh, "<", $input_file) || die "Cannot open $input_file: $!\n";
}
while (my $row = $csv->getline(*ARGV)) {
if (!defined($country{$row->[4]})) {
$country{$row->[4]} = {
name => $row->[5],
pool_v4 => [],
pool_v6 => [],
};
while ($row = $csv->getline($fh)) {
my ($cc, $range);
$cc = $row->[2];
$range = $row->[0] . "-" . $row->[1];
if (!exists($country{$cc})) {
$country{$cc} = { pool_v4 => Net::CIDR::Lite->new(), pool_v6 => Net::CIDR::Lite->new() };
}
my $c = $country{$row->[4]};
if ($row->[0] =~ /:/) {
push(@{$c->{pool_v6}},
[&ip6_pack($row->[0]), &ip6_pack($row->[1])]);
} else {
push(@{$c->{pool_v4}}, [$row->[2], $row->[3]]);
if (index($range, '.') > 0) {
$country{$cc}->{pool_v4}->add_range($range);
}
if ($. % 4096 == 0) {
if (index($range, ':') > 0) {
$country{$cc}->{pool_v6}->add_range($range);
}
if (!$quiet && $. % 4096 == 0) {
print STDERR "\r\e[2K$. entries";
}
}
print STDERR "\r\e[2K$. entries total\n";
print STDERR "\r\e[2K$. entries total\n" unless ($quiet);
close($fh);
return \%country;
}
@@ -66,7 +80,7 @@ sub dump
{
my $country = shift @_;
foreach my $iso_code (sort keys %$country) {
foreach my $iso_code (sort keys %{$country}) {
&dump_one($iso_code, $country->{$iso_code});
}
}
@@ -74,68 +88,40 @@ sub dump
sub dump_one
{
my($iso_code, $country) = @_;
my($file, $fh_le, $fh_be);
my @ranges;
printf "%5u IPv6 ranges for %s %s\n",
scalar(@{$country->{pool_v6}}),
$iso_code, $country->{name};
@ranges = $country->{pool_v4}->list_range();
$file = "$target_dir/LE/".uc($iso_code).".iv6";
if (!open($fh_le, "> $file")) {
print STDERR "Error opening $file: $!\n";
exit 1;
}
$file = "$target_dir/BE/".uc($iso_code).".iv6";
if (!open($fh_be, "> $file")) {
print STDERR "Error opening $file: $!\n";
exit 1;
}
foreach my $range (@{$country->{pool_v6}}) {
print $fh_be $range->[0], $range->[1];
print $fh_le &ip6_swap($range->[0]), &ip6_swap($range->[1]);
}
close $fh_le;
close $fh_be;
writeCountry($iso_code, AF_INET, @ranges);
printf "%5u IPv4 ranges for %s %s\n",
scalar(@{$country->{pool_v4}}),
$iso_code, $country->{name};
@ranges = $country->{pool_v6}->list_range();
$file = "$target_dir/LE/".uc($iso_code).".iv4";
if (!open($fh_le, "> $file")) {
print STDERR "Error opening $file: $!\n";
exit 1;
}
$file = "$target_dir/BE/".uc($iso_code).".iv4";
if (!open($fh_be, "> $file")) {
print STDERR "Error opening $file: $!\n";
exit 1;
}
foreach my $range (@{$country->{pool_v4}}) {
print $fh_le pack("VV", $range->[0], $range->[1]);
print $fh_be pack("NN", $range->[0], $range->[1]);
}
close $fh_le;
close $fh_be;
writeCountry($iso_code, AF_INET6, @ranges);
}
sub ip6_pack
sub writeCountry
{
my $addr = shift @_;
$addr =~ s{::}{:!:};
my @addr = split(/:/, $addr);
my @e = (0) x 8;
foreach (@addr) {
if ($_ eq "!") {
$_ = join(':', @e[0..(8-scalar(@addr))]);
}
}
@addr = split(/:/, join(':', @addr));
$_ = hex($_) foreach @addr;
return pack("n*", @addr);
}
my ($iso_code, $family, @ranges) = @_;
my $fh;
sub ip6_swap
{
return pack("V*", unpack("N*", shift @_));
printf "%5u IPv%s ranges for %s\n",
scalar(@ranges),
($family == AF_INET ? '4' : '6'),
$iso_code unless ($quiet);
my $file = "$target_dir/".uc($iso_code).".iv".($family == AF_INET ? '4' : '6');
if (!open($fh, '>', $file)) {
print STDERR "Error opening $file: $!\n";
exit 1;
}
binmode($fh);
foreach my $range (@ranges) {
my ($start, $end) = split('-', $range);
$start = inet_pton($family, $start);
$end = inet_pton($family, $end);
print $fh $start, $end;
}
close $fh;
}

View File

@@ -5,7 +5,7 @@ xt_geoip_build \(em convert GeoIP.csv to packed format for xt_geoip
.SH Syntax
.PP
\fI/usr/libexec/xt_geoip/\fP\fBxt_geoip_build\fP [\fB\-D\fP
\fItarget_dir\fP] [\fIfile\fP...]
\fItarget_dir\fP] [\fB\-i\fP \fIinput_file\fP]
.SH Description
.PP
xt_geoip_build is used to build packed raw representations of the range
@@ -16,20 +16,26 @@ required to be loaded into memory. The ranges in the packed database files are
also ordered, as xt_geoip relies on this property for its bisection approach to
work.
.PP
Input is processed from the listed files, or if none is given, from stdin.
.PP
Since the script is usually installed to the libexec directory of the
xtables-addons package and this is outside $PATH (on purpose), invoking the
script requires it to be called with a path.
.PP Options
.TP
\fB\-D\fP \fItarget_dir\fP
Specify a target directory into which the files are to be put.
Specifies the target directory into which the files are to be put. Defaults to ".".
.TP
\fB\-i\fP \fIinput_file\fP
Specifies the source location of the DBIP CSV file. Defaults to
"dbip-country-lite.csv". Use "-" to read from stdin.
.TP
\fB\-s\fP
"System mode". Equivalent to \fB\-D /usr/share/xt_geoip\fP.
.SH Application
.PP
Shell commands to build the databases and put them to where they are expected:
Shell commands to build the databases and put them to where they are expected
(usually run as root):
.PP
xt_geoip_build \-D /usr/share/xt_geoip
xt_geoip_build \-s
.SH See also
.PP
xt_geoip_dl(1)

View File

@@ -1,8 +1,5 @@
#!/bin/sh
rm -f GeoIPv6.csv GeoIPv6.csv.gz GeoIPCountryCSV.zip GeoIPCountryWhois.csv;
wget \
http://geolite.maxmind.com/download/geoip/database/GeoIPv6.csv.gz \
http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip;
gzip -d GeoIPv6.csv.gz;
unzip GeoIPCountryCSV.zip;
timestamp=$(date "+%Y-%m")
wget -q "https://download.db-ip.com/free/dbip-country-lite-$timestamp.csv.gz" -O- | \
gzip -cd >dbip-country-lite.csv

95
geoip/xt_geoip_fetch Executable file
View File

@@ -0,0 +1,95 @@
#!/usr/bin/perl
#
# Utility to query GeoIP database
# Copyright Philip Prindeville, 2018
#
use Getopt::Long;
use Socket qw(AF_INET AF_INET6 inet_ntop);
use warnings;
use strict;
sub AF_INET_SIZE() { 4 }
sub AF_INET6_SIZE() { 16 }
my $target_dir = ".";
my $ipv4 = 0;
my $ipv6 = 0;
&Getopt::Long::Configure(qw(bundling));
&GetOptions(
"D=s" => \$target_dir,
"4" => \$ipv4,
"6" => \$ipv6,
);
if (!-d $target_dir) {
print STDERR "Target directory $target_dir does not exit.\n";
exit 1;
}
# if neither specified, assume both
if (! $ipv4 && ! $ipv6) {
$ipv4 = $ipv6 = 1;
}
foreach my $cc (@ARGV) {
if ($cc !~ m/^([a-z]{2}|a[12]|o1)$/i) {
print STDERR "Invalid country code '$cc'\n";
exit 1;
}
my $file = $target_dir . '/' . uc($cc) . '.iv4';
if (! -f $file) {
printf STDERR "Can't find data for country '$cc'\n";
exit 1;
}
my ($contents, $buffer, $bytes, $fh);
if ($ipv4) {
open($fh, '<', $file) || die "Couldn't open file for '$cc'\n";
binmode($fh);
while (($bytes = read($fh, $buffer, AF_INET_SIZE * 2)) == AF_INET_SIZE * 2) {
my ($start, $end) = unpack('a4a4', $buffer);
$start = inet_ntop(AF_INET, $start);
$end = inet_ntop(AF_INET, $end);
print $start, '-', $end, "\n";
}
close($fh);
if (! defined $bytes) {
printf STDERR "Error reading file for '$cc'\n";
exit 1;
} elsif ($bytes != 0) {
printf STDERR "Short read on file for '$cc'\n";
exit 1;
}
}
substr($file, -1) = '6';
if ($ipv6) {
open($fh, '<', $file) || die "Couldn't open file for '$cc'\n";
binmode($fh);
while (($bytes = read($fh, $buffer, AF_INET6_SIZE * 2)) == AF_INET6_SIZE * 2) {
my ($start, $end) = unpack('a16a16', $buffer);
$start = inet_ntop(AF_INET6, $start);
$end = inet_ntop(AF_INET6, $end);
print $start, '-', $end, "\n";
}
close($fh);
if (! defined $bytes) {
printf STDERR "Error reading file for '$cc'\n";
exit 1;
} elsif ($bytes != 0) {
printf STDERR "Short read on file for '$cc'\n";
exit 1;
}
}
}
exit 0;

35
geoip/xt_geoip_fetch.1 Normal file
View File

@@ -0,0 +1,35 @@
.TH xt_geoip_fetch 1 "2020-04-30" "xtables-addons" "xtables-addons"
.SH Name
.PP
xt_geoip_fetch \(em dump a country database to stdout
.SH Syntax
.PP
\fBxt_geoip_fetch\fP [\fB\-D\fP
\fIdatabase_dir\fP] [\fB-4\fP] [\fB-6\fP] \fIcc\fP [ \fIcc\fP ... ]
.SH Description
.PP
xt_geoip_fetch unpacks a country's IPv4 or IPv6 databases and dumps
them to standard output as a sorted, non-overlaping list of ranges (which
is how they're represented in the database) suitable for browsing or
further processing.
.PP Options
.TP
\fB\-D\fP \fIdatabase_dir\fP
Specifies the directory into which the files have been put. Defaults to ".".
.TP
\fB-4\fP
Specifies IPv4 data only.
.TP
\fB-6\fP
Specifies IPv6 data only.
.TP
\fIcc\fP [ \fIcc\fP ... ]
The ISO-3166 country code names of the desired countries' databases.
.SH Application
.PP
Shell command to dump the list of Swiss IPv6 address ranges:
.PP
xt_geoip_fetch \-D /usr/share/xt_geoip \-6 ch
.SH See also
.PP
xt_geoip_build(1)

View File

@@ -8,6 +8,7 @@ build_DNETMAP=m
build_ECHO=m
build_IPMARK=m
build_LOGMARK=m
build_PROTO=m
build_SYSRQ=m
build_TARPIT=m
build_condition=m

View File

@@ -1,3 +0,0 @@
#
# Source URLs for external patchlets
#

View File

@@ -1,83 +0,0 @@
#!/usr/bin/perl -w
use HTTP::Request;
use LWP::UserAgent;
use strict;
&main(\@ARGV);
sub main
{
local *FH;
if (!-d "downloads") {
if (!mkdir("downloads")) {
die "Could not create downloads/ directory";
}
}
open(FH, "<sources");
while (defined($_ = <FH>)) {
chomp $_;
$_ =~ s/#.*//gs;
$_ =~ s/^\s+|\s+$//gs;
if (length($_) == 0) {
next;
}
&process_index($_);
}
close FH;
}
sub process_index
{
my $top = shift @_;
my($agent, $res, $url);
local *FH;
$agent = LWP::UserAgent->new();
$agent->env_proxy();
$url = &slash_remove("$top/xa-index.txt");
print " GET $url\n";
$res = $agent->get($url);
if (!$res->is_success()) {
print STDERR " `-> ", $res->status_line(), "\n";
return;
}
foreach my $ext (split(/\s+/, $res->content())) {
my($ex_url, $ex_res);
$ex_url = &slash_remove("$top/$ext");
print " GET $ex_url\n";
$ex_res = $agent->mirror($ex_url, "downloads/$ext");
if ($ex_res->code() == 304) {
# "Not modified" = up to date
next;
}
if (!$ex_res->is_success()) {
print STDERR " `-> ", $ex_res->status_line(), "\n";
next;
}
print " UNPACK downloads/$ext\n";
system "tar", "-xjf", "downloads/$ext";
}
}
sub slash_remove
{
my $s = shift @_;
$s =~ s{(\w+://)(.*)}{$1.&slash_remove2($2)}eg;
return $s;
}
sub slash_remove2
{
my $s = shift @_;
$s =~ s{/+}{/}g;
return $s;
}

View File

@@ -1,4 +1,4 @@
.TH xtables-addons 8 "" "" "v2.14 (2017-11-22)"
.TH xtables-addons 8 "" "" "v3.9 (2020-02-25)"
.SH Name
Xtables-addons \(em additional extensions for iptables, ip6tables, etc.
.SH Targets