mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-20 19:44:56 +02:00
Compare commits
96 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
30fb410003 | ||
![]() |
3ea761a1ed | ||
![]() |
4603d3e0f4 | ||
![]() |
b0b2b5a74c | ||
![]() |
082d42fb21 | ||
![]() |
b1f0e118a0 | ||
![]() |
56fba3ecff | ||
![]() |
9057fb48f3 | ||
![]() |
e19f91ddb4 | ||
![]() |
256ac1a4f6 | ||
![]() |
b91dbd03c7 | ||
![]() |
254c6926d3 | ||
![]() |
2e78cf03a4 | ||
![]() |
bf63a25a64 | ||
![]() |
94656621ed | ||
![]() |
95d4f9e113 | ||
![]() |
123e1a14e9 | ||
![]() |
f4f3f98609 | ||
![]() |
9b1c7c1c04 | ||
![]() |
ed8e496750 | ||
![]() |
5339fcc65b | ||
![]() |
2265c1b854 | ||
![]() |
2c574f992d | ||
![]() |
3a24468a68 | ||
![]() |
7682cc8c34 | ||
![]() |
215b3c5b12 | ||
![]() |
4dbb36b723 | ||
![]() |
10f951e61d | ||
![]() |
a4c50ae405 | ||
![]() |
38d89983ca | ||
![]() |
25985650a9 | ||
![]() |
4de9ff1505 | ||
![]() |
46b7cf206b | ||
![]() |
29d10e11fa | ||
![]() |
60a26f1dea | ||
![]() |
cdf90737be | ||
![]() |
5713415014 | ||
![]() |
230bc1f327 | ||
![]() |
d360f5578c | ||
![]() |
dd32060f6a | ||
![]() |
d5eb4e586c | ||
![]() |
1b4b4347c5 | ||
![]() |
2f37af43c5 | ||
![]() |
56e5970c64 | ||
![]() |
2b76b68c65 | ||
![]() |
d2eeac4c32 | ||
![]() |
0e9037b000 | ||
![]() |
0a6091b64a | ||
![]() |
b565a85fb6 | ||
![]() |
89c80f5981 | ||
![]() |
8579fd2b3b | ||
![]() |
0a836e9677 | ||
![]() |
90b0f3a51f | ||
![]() |
89d1b808b9 | ||
![]() |
c839e87bbb | ||
![]() |
a587f9526d | ||
![]() |
1874fcd519 | ||
![]() |
21ea7b76ec | ||
![]() |
ee8da2b1ac | ||
![]() |
19a4359368 | ||
![]() |
1b379667d3 | ||
![]() |
cd410aefe7 | ||
![]() |
e4b5cef8f0 | ||
![]() |
a8af97b8fa | ||
![]() |
db234c30cd | ||
![]() |
2e6fb73e85 | ||
![]() |
6024758b28 | ||
![]() |
69f3f21a32 | ||
![]() |
7af1b9737c | ||
![]() |
f5e95f35a7 | ||
![]() |
80bed0655f | ||
![]() |
bc6aaf74d8 | ||
![]() |
192243483a | ||
![]() |
e3114d60d5 | ||
![]() |
e6f20befad | ||
![]() |
5038e160f8 | ||
![]() |
a6289ec3ff | ||
![]() |
01e7128a80 | ||
![]() |
1dc2a1c2de | ||
![]() |
60b6b1dbef | ||
![]() |
fcb19403bc | ||
![]() |
f89f10bbe9 | ||
![]() |
a9358542fe | ||
![]() |
237fe7c660 | ||
![]() |
939fc901c1 | ||
![]() |
a4a077ff86 | ||
![]() |
bccf64d820 | ||
![]() |
7e3e156d92 | ||
![]() |
8f70b9a99d | ||
![]() |
e277360bcd | ||
![]() |
672f12b2a6 | ||
![]() |
8788b6c096 | ||
![]() |
96ce5ec488 | ||
![]() |
5e22c9c592 | ||
![]() |
01f97bfdd1 | ||
![]() |
1324442bce |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,6 +3,7 @@
|
|||||||
*.lo
|
*.lo
|
||||||
*.loT
|
*.loT
|
||||||
*.o
|
*.o
|
||||||
|
.cache.mk
|
||||||
.deps/
|
.deps/
|
||||||
.dirstamp
|
.dirstamp
|
||||||
.libs/
|
.libs/
|
||||||
|
7
INSTALL
7
INSTALL
@@ -12,16 +12,17 @@ in combination with the kernel's Kbuild system.
|
|||||||
Supported configurations for this release
|
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
|
with prepared build/output directory
|
||||||
- CONFIG_NF_CONNTRACK
|
- CONFIG_NF_CONNTRACK
|
||||||
- CONFIG_NF_CONNTRACK_MARK enabled =y or as module (=m)
|
- CONFIG_NF_CONNTRACK_MARK enabled =y or as module (=m)
|
||||||
- CONFIG_CONNECTOR y/m if you wish to receive userspace
|
- CONFIG_CONNECTOR y/m if you wish to receive userspace
|
||||||
notifications from pknock through netlink/connector
|
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
|
Selecting extensions
|
||||||
|
34
configure.ac
34
configure.ac
@@ -1,4 +1,4 @@
|
|||||||
AC_INIT([xtables-addons], [2.6])
|
AC_INIT([xtables-addons], [3.1])
|
||||||
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])
|
||||||
@@ -26,7 +26,7 @@ fi
|
|||||||
|
|
||||||
AC_CHECK_HEADERS([linux/netfilter/x_tables.h], [],
|
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])])
|
[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)"
|
xtlibdir="$(pkg-config --variable=xtlibdir xtables)"
|
||||||
|
|
||||||
AC_ARG_WITH([xtlibdir],
|
AC_ARG_WITH([xtlibdir],
|
||||||
@@ -44,29 +44,23 @@ regular_CFLAGS="-Wall -Waggregate-return -Wmissing-declarations \
|
|||||||
|
|
||||||
if test -n "$kbuilddir"; then
|
if test -n "$kbuilddir"; then
|
||||||
AC_MSG_CHECKING([kernel version that we will build against])
|
AC_MSG_CHECKING([kernel version that we will build against])
|
||||||
krel="$(make -sC "$kbuilddir" M=$PWD kernelrelease)";
|
krel="$(make -sC "$kbuilddir" M=$PWD kernelrelease | $AWK -v 'FS=[[^0-9.]]' '{print $1; exit}')"
|
||||||
kmajor="${krel%%[[^0-9]]*}";
|
save_IFS="$IFS"
|
||||||
kmajor="$(($kmajor+0))";
|
IFS='.'
|
||||||
krel="${krel:${#kmajor}}";
|
set x $krel
|
||||||
krel="${krel#.}";
|
IFS="$save_IFS"
|
||||||
kminor="${krel%%[[^0-9]]*}";
|
kmajor="$(($2+0))"
|
||||||
kminor="$(($kminor+0))";
|
kminor="$(($3+0))"
|
||||||
krel="${krel:${#kminor}}";
|
kmicro="$(($4+0))"
|
||||||
krel="${krel#.}";
|
kstable="$(($5+0))"
|
||||||
kmicro="${krel%%[[^0-9]]*}";
|
|
||||||
kmicro="$(($kmicro+0))";
|
|
||||||
krel="${krel:${#kmicro}}";
|
|
||||||
krel="${krel#.}";
|
|
||||||
kstable="${krel%%[[^0-9]]*}";
|
|
||||||
kstable="$(($kstable+0))";
|
|
||||||
if test -z "$kmajor" -o -z "$kminor" -o -z "$kmicro"; then
|
if test -z "$kmajor" -o -z "$kminor" -o -z "$kmicro"; 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 3 -o "$kmajor" -eq 3 -a "$kminor" -gt 17; then
|
if test "$kmajor" -gt 4 -o "$kmajor" -eq 4 -a "$kminor" -gt 18; 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 3 -a "$kminor" -ge 7; then
|
elif test "$kmajor" -eq 4 -a "$kminor" -ge 18; then
|
||||||
:;
|
:
|
||||||
else
|
else
|
||||||
echo "WARNING: That kernel version is not officially supported.";
|
echo "WARNING: That kernel version is not officially supported.";
|
||||||
fi;
|
fi;
|
||||||
|
@@ -3,10 +3,82 @@ HEAD
|
|||||||
====
|
====
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
==================
|
||||||
|
Enhancements:
|
||||||
|
- support for Linux up to 4.14
|
||||||
|
Fixes:
|
||||||
|
- xt_DNETMAP: fix some reports from PVSStudio (a static checker)
|
||||||
|
|
||||||
|
|
||||||
|
v2.13 (2017-06-29)
|
||||||
|
==================
|
||||||
|
Enhancements:
|
||||||
|
- support for Linux up to 4.12
|
||||||
|
- xt_condition: namespace support
|
||||||
|
Fixes:
|
||||||
|
- xt_geoip: check for allocation overflow
|
||||||
|
- xt_DNETMAP: fix a buffer overflow
|
||||||
|
|
||||||
|
|
||||||
|
v2.12 (2017-01-11)
|
||||||
|
==================
|
||||||
|
Enhancements:
|
||||||
|
- support for Linux up to 4.10
|
||||||
|
|
||||||
|
|
||||||
|
v2.11 (2016-05-20)
|
||||||
|
==================
|
||||||
|
Enhancements:
|
||||||
|
- support for Linux 4.5, 4.6
|
||||||
|
- xt_ECHO: tentatively support responding to fragments
|
||||||
|
|
||||||
|
|
||||||
|
v2.10 (2015-11-20)
|
||||||
|
==================
|
||||||
|
Enhancements:
|
||||||
|
- Support for Linux 4.4
|
||||||
|
Fixes:
|
||||||
|
- xt_ACCOUNT: call free_page with the right amount of pages
|
||||||
|
|
||||||
|
|
||||||
|
v2.9 (2015-10-12)
|
||||||
|
=================
|
||||||
|
Enhancements:
|
||||||
|
- Support for Linux 4.3
|
||||||
|
|
||||||
|
|
||||||
|
v2.8 (2015-08-19)
|
||||||
|
=================
|
||||||
|
Enhancements:
|
||||||
|
- Support for Linux 4.2
|
||||||
|
- Enable xt_ECHO for Linux 4.0+
|
||||||
|
|
||||||
|
|
||||||
|
v2.7 (2015-07-06)
|
||||||
|
=================
|
||||||
|
Enhancements:
|
||||||
|
- Support for Linux up to 4.1
|
||||||
|
|
||||||
|
|
||||||
v2.6 (2014-09-29)
|
v2.6 (2014-09-29)
|
||||||
=================
|
=================
|
||||||
Enhancements:
|
Enhancements:
|
||||||
- Support for Linux 3.16, 3.17
|
- Support for Linux up to 3.17
|
||||||
Fixes:
|
Fixes:
|
||||||
- xt_pknock: UDP SPA mode erroneously returned an error saying
|
- xt_pknock: UDP SPA mode erroneously returned an error saying
|
||||||
crypto was unavailable
|
crypto was unavailable
|
||||||
@@ -15,14 +87,14 @@ Fixes:
|
|||||||
v2.5 (2014-04-18)
|
v2.5 (2014-04-18)
|
||||||
=================
|
=================
|
||||||
Enhancements:
|
Enhancements:
|
||||||
- Support for Linux 3.14 and 3.15
|
- Support for Linux up to 3.15
|
||||||
- xt_quota2: introduce support for network namespaces
|
- xt_quota2: introduce support for network namespaces
|
||||||
|
|
||||||
|
|
||||||
v2.4 (2014-01-09)
|
v2.4 (2014-01-09)
|
||||||
=================
|
=================
|
||||||
Enhancements:
|
Enhancements:
|
||||||
- Support for Linux 3.13
|
- Support for Linux up to 3.13
|
||||||
Changes:
|
Changes:
|
||||||
- remove unmaintained RAWSNAT/RAWDNAT code
|
- remove unmaintained RAWSNAT/RAWDNAT code
|
||||||
- remove unused parts of compat_xtables that served Linux <3.7
|
- remove unused parts of compat_xtables that served Linux <3.7
|
||||||
@@ -69,514 +141,5 @@ Changes:
|
|||||||
Enhancements:
|
Enhancements:
|
||||||
- Support for Linux 3.7
|
- Support for Linux 3.7
|
||||||
|
|
||||||
If you want to use Xtables-addons with kernels older than 3.7,
|
If you want to use Xtables-addons with kernels older than 4.15,
|
||||||
use the addons 1.x series, which continues to be maintained for
|
use the addons 2.x series.
|
||||||
the time being.
|
|
||||||
|
|
||||||
|
|
||||||
v1.47.1 (2010-10-15)
|
|
||||||
====================
|
|
||||||
Enhancements:
|
|
||||||
- xt_psd gained IPv6 support
|
|
||||||
Notes for this release:
|
|
||||||
- Linux 3.7+ is expressly unsupported by this release.
|
|
||||||
|
|
||||||
|
|
||||||
v1.46 (2012-08-23)
|
|
||||||
==================
|
|
||||||
Fixes:
|
|
||||||
- length2, SYSRQ, RAWNAT: preinitialize values for ipv6_find_hdr
|
|
||||||
- TARPIT: fix memory leak when tarpit_generic() fails
|
|
||||||
- build: remove extraneous closing bracket in configure.ac
|
|
||||||
- doc: update xt_SYSRQ.man to reflect that the full IPv6 address is needed
|
|
||||||
Enhancements:
|
|
||||||
- Support for Linux 3.6
|
|
||||||
|
|
||||||
|
|
||||||
v1.45 (2012-07-16)
|
|
||||||
==================
|
|
||||||
Fixes:
|
|
||||||
- build: export missing functions
|
|
||||||
(fixes: "WARNING 'xtnu_ipv6_find_hdr' [xt_TARPIT.ko] not found")
|
|
||||||
- build: avoid use of unexported functions
|
|
||||||
(fixes: "WARNING 'ipv6_find_hdr' [xt_TARPIT.ko] not found"
|
|
||||||
in <= linux-2.6.37)
|
|
||||||
|
|
||||||
|
|
||||||
v1.44 (2012-07-15)
|
|
||||||
==================
|
|
||||||
Fixes:
|
|
||||||
- SYSRQ: fix double target initialization at module load
|
|
||||||
- build: do not attempt to build IPv6 parts if CONFIG_IP6_NF_IPTABLES=n
|
|
||||||
Enhancements:
|
|
||||||
- TARPIT gained IPv6 support
|
|
||||||
|
|
||||||
|
|
||||||
v1.43 (2012-06-30)
|
|
||||||
==================
|
|
||||||
Fixes:
|
|
||||||
- xt_psd: avoid crash due to curr->next corruption
|
|
||||||
Changes:
|
|
||||||
- xt_psd: reject invalid match options
|
|
||||||
Enhancements:
|
|
||||||
- Support for Linux 3.5
|
|
||||||
- DNETMAP: new type: static binding
|
|
||||||
- DNETMAP: new persistent flag option for prefix
|
|
||||||
- DNETMAP: add write support to procfs interface
|
|
||||||
|
|
||||||
|
|
||||||
v1.42 (2012-04-05)
|
|
||||||
==================
|
|
||||||
Fixes:
|
|
||||||
- compat_xtables: fixed mistranslation of checkentry return values
|
|
||||||
(affected kernels < 2.6.23)
|
|
||||||
- xt_SYSRQ: fix compile error when crypto is turned off
|
|
||||||
Changes:
|
|
||||||
- ipset6-genl has been dropped from the tree;
|
|
||||||
the libmnl build-time dependency is thus no longer needed
|
|
||||||
Enhancements:
|
|
||||||
- Support for Linux 3.3, 3.4
|
|
||||||
|
|
||||||
|
|
||||||
v1.41 (2012-01-04)
|
|
||||||
==================
|
|
||||||
Changes:
|
|
||||||
- Deactivate build of ipset-genl by default.
|
|
||||||
I think the original ipset package can now take over, given there are
|
|
||||||
a handful of kernels (2.6.39 onwards) that do not need patching.
|
|
||||||
Enhancements:
|
|
||||||
- Support for Linux 3.2
|
|
||||||
|
|
||||||
|
|
||||||
v1.40 (2011-11-30)
|
|
||||||
==================
|
|
||||||
Fixes:
|
|
||||||
- build: the code actually requires at least iptables 1.4.5 (would yield a
|
|
||||||
compile error otherwise), make sure configure checks for it; update INSTALL
|
|
||||||
- xt_ECHO: fix kernel warning about RTAX_HOPLIMIT being used
|
|
||||||
- xt_ipv4options: fix an infinite loop
|
|
||||||
Changes:
|
|
||||||
- xt_ECHO: now calculates UDP checksum
|
|
||||||
- Linux kernel versions below 2.6.32 are no longer officially
|
|
||||||
supported, and will not be part of compilation testing.
|
|
||||||
- update to ipset 6.10
|
|
||||||
Enhancements:
|
|
||||||
- xt_ECHO: IPv6 support
|
|
||||||
|
|
||||||
|
|
||||||
v1.39 (2011-09-21)
|
|
||||||
==================
|
|
||||||
Fixes:
|
|
||||||
- libxt_ACCOUNT: fix compilation after missing libxtables_CFLAGS
|
|
||||||
- build: fix compilation after missing libxtables_CFLAGS in submodules
|
|
||||||
- build: add missing linux/version.h includes where needed
|
|
||||||
Changes:
|
|
||||||
- Remove unsupported ipset 4.x from the Xtables-addons distribution
|
|
||||||
- ipset: move ipset_errcode from src to library to avoid undefined reference
|
|
||||||
- update to ipset 6.9.1
|
|
||||||
|
|
||||||
|
|
||||||
v1.38 (2011-08-20)
|
|
||||||
==================
|
|
||||||
- xt_CHECKSUM: abort build when the feature is already provided by mainline
|
|
||||||
- xt_SYSRQ: fix UDPLITE header lookup in IPv6
|
|
||||||
- xt_TARPIT: fix kernel warning about RTAX_HOPLIMIT being used
|
|
||||||
- xt_TEE: abort build when the feature is already provided by mainline
|
|
||||||
- xt_ipp2p: support UDPLITE
|
|
||||||
- xt_pknock: support UDPLITE
|
|
||||||
- xt_psd: restore functionality with UDP
|
|
||||||
- xt_psd: support UDPLITE
|
|
||||||
- update to ipset 6.8
|
|
||||||
- support for Linux 3.1
|
|
||||||
|
|
||||||
|
|
||||||
v1.37 (2011-06-25)
|
|
||||||
==================
|
|
||||||
Fixes:
|
|
||||||
- xt_SYSRQ: make IPv6 trigger work again
|
|
||||||
- xt_SYSRQ: improve security: include host address in digest
|
|
||||||
- xt_TARPIT: fix a kernel oops in --reset mode
|
|
||||||
|
|
||||||
|
|
||||||
v1.36 (2011-06-03)
|
|
||||||
==================
|
|
||||||
Changes:
|
|
||||||
- xt_geoip: avoid recursive function calls
|
|
||||||
- xt_TARPIT: unlock for use in all tables
|
|
||||||
- xt_TARPIT: honeypot and reset modes
|
|
||||||
- update to ipset 6.7
|
|
||||||
- support for Linux 3.0
|
|
||||||
|
|
||||||
|
|
||||||
v1.35 (2011-04-11)
|
|
||||||
==================
|
|
||||||
Enhancements:
|
|
||||||
- update to ipset 6.3
|
|
||||||
* allow "new" as a commad alias to "create"
|
|
||||||
* resolving IP addresses did not work at listing/saving sets, fixed
|
|
||||||
* check ICMP and ICMPv6 with the set match and target in the testsuite
|
|
||||||
* avoid possible syntax clashing at saving hostnames
|
|
||||||
* fix linking with CONFIG_IPV6=n
|
|
||||||
* sctp, udplite support for the hash:*port* types
|
|
||||||
- ipset-genl: handle EAGAIN return value emitted from autoloader
|
|
||||||
- ipset-genl: resolve nfgenmsg remains and fix spurious protocol abort
|
|
||||||
|
|
||||||
|
|
||||||
v1.34 (2011-04-07)
|
|
||||||
==================
|
|
||||||
Fixes:
|
|
||||||
- xt_pknock: avoid crash when hash TFM could not be allocated
|
|
||||||
- xt_pknock: avoid inversion of rule lookup that led to warnings
|
|
||||||
- xt_DNETMAP: add missing module alias
|
|
||||||
- xt_DNETMAP: support for kernels below 2.6.34
|
|
||||||
Changes:
|
|
||||||
- Linux kernel versions below 2.6.29 are no longer officially
|
|
||||||
supported, and will not be part of compilation testing.
|
|
||||||
|
|
||||||
|
|
||||||
v1.33 (2011-02-02)
|
|
||||||
==================
|
|
||||||
Fixes:
|
|
||||||
- build: restore functionality of `configure --without-kbuild`
|
|
||||||
- build: fix objdir builds for ipset-5 (xt-a specific)
|
|
||||||
- build: fix missing inclusion of dependency rules
|
|
||||||
- xt_LOGMARK: fix detection of untracked connection for Linux >= 2.6.36
|
|
||||||
Enhancements:
|
|
||||||
- IPv6 support for xt_geoip
|
|
||||||
- Update to ipset 5.3
|
|
||||||
* make IPv4 and IPv6 address handling similar
|
|
||||||
* show correct line numbers in restore output for parser errors
|
|
||||||
- Update to ipset 5.4
|
|
||||||
* fixed ICMP and ICMPv6 handling
|
|
||||||
* fixed trailing whitespaces and pr_* messages
|
|
||||||
* fixed module loading at create/header commands
|
|
||||||
- build: support for Linux up to 2.6.38
|
|
||||||
- build: preliminary support for iptables 1.4.11
|
|
||||||
|
|
||||||
|
|
||||||
v1.32 (2011-01-04)
|
|
||||||
==================
|
|
||||||
Fixes:
|
|
||||||
- Update to ipset 4.5
|
|
||||||
* the iptreemap type used wrong gfp flags when deleting entries
|
|
||||||
- Include ipset 5.2 with genetlink patch (beta)
|
|
||||||
* no kernel patch needed, but requires Linux >= 2.6.35
|
|
||||||
and thus needs to be manually enabled in mconfig
|
|
||||||
|
|
||||||
|
|
||||||
v1.31 (2010-11-05)
|
|
||||||
==================
|
|
||||||
Fixes:
|
|
||||||
- build: improve detection of kernel version and error handling
|
|
||||||
Changes:
|
|
||||||
- build: automatically derive Xtables module directory, thus
|
|
||||||
--with-xtlibdir is no longer needed for ./configure in most cases
|
|
||||||
(If I still see a distro using it, I will scold you for not
|
|
||||||
reading this changelog.)
|
|
||||||
Enhancements:
|
|
||||||
- LOGMARK: print remaining lifetime of cts
|
|
||||||
- xt_iface: allow matching against incoming/outgoing interface
|
|
||||||
- libxt_gradm: match packets based on status of grsecurity RBAC
|
|
||||||
(userspace part only - xt_gradm is in the grsec patch)
|
|
||||||
|
|
||||||
|
|
||||||
v1.30 (2010-010-02)
|
|
||||||
===================
|
|
||||||
Fixes:
|
|
||||||
- update to ipset 4.4
|
|
||||||
* ipport{,ip,net}hash did not work with mixed "src" and "dst"
|
|
||||||
destination parameters
|
|
||||||
Changes:
|
|
||||||
- deactivate building xt_TEE and xt_CHECKSUM by default, as these have been
|
|
||||||
merged upstream in Linux 2.6.35 and 2.6.36, respectively.
|
|
||||||
Distros still wishing to build this need to enable it in their build
|
|
||||||
script, e.g. perl -i -pe 's{^build_TEE=.*}{build_TEE=m}' mconfig;
|
|
||||||
|
|
||||||
|
|
||||||
v1.29 (2010-09-29)
|
|
||||||
==================
|
|
||||||
- compat_xtables: return bool for match_check and target_check in 2.6.23..34
|
|
||||||
- ipset: enable building of ip_set_ipport{ip,net}hash.ko
|
|
||||||
- support for Linux 2.6.36
|
|
||||||
- SYSRQ: resolve compile error with Linux 2.6.36
|
|
||||||
- TEE: resolve compile error with Linux 2.6.36
|
|
||||||
- add workaround for broken linux-glibc-devel 2.6.34 userspace headers
|
|
||||||
("implicit declaration of function 'ALIGN'")
|
|
||||||
|
|
||||||
|
|
||||||
v1.28 (2010-07-24)
|
|
||||||
==================
|
|
||||||
- RAWNAT: IPv6 variants erroneously rejected masks /33-/128
|
|
||||||
- new target xt_CHECKSUM
|
|
||||||
- xt_length2: add support for IPv6 jumbograms
|
|
||||||
- xt_geoip: fix possible out-of-bounds access
|
|
||||||
- import xt_geoip database scripts
|
|
||||||
|
|
||||||
|
|
||||||
v1.27 (2010-05-16)
|
|
||||||
==================
|
|
||||||
- further updates for the upcoming 2.6.35 changes
|
|
||||||
|
|
||||||
|
|
||||||
v1.26 (2010-04-30)
|
|
||||||
==================
|
|
||||||
- compat_xtables: fix 2.6.34 compile error due to a typo
|
|
||||||
|
|
||||||
|
|
||||||
v1.25 (2010-04-26)
|
|
||||||
==================
|
|
||||||
- TEE: do rechecksumming in PREROUTING too
|
|
||||||
- TEE: decrease TTL on cloned packet
|
|
||||||
- TEE: set dont-fragment on cloned packets
|
|
||||||
- TEE: free skb when route lookup failed
|
|
||||||
- TEE: do not limit use to mangle table
|
|
||||||
- TEE: do not retain iif and mark on cloned packet
|
|
||||||
- TEE: new loop detection logic
|
|
||||||
- TEE: use less expensive pskb_copy
|
|
||||||
- condition: remove unnecessary RCU protection
|
|
||||||
|
|
||||||
|
|
||||||
v1.24 (2010-03-17)
|
|
||||||
==================
|
|
||||||
- build: fix build of userspace modules against old (pre-2.6.25)
|
|
||||||
headers from linux-glibc-devel (/usr/include/linux)
|
|
||||||
- ipp2p: updated bittorent command recognition
|
|
||||||
- SYSRQ: let module load when crypto is unavailable
|
|
||||||
- SYSRQ: allow processing of UDP-Lite
|
|
||||||
|
|
||||||
|
|
||||||
v1.23 (2010-02-24)
|
|
||||||
==================
|
|
||||||
- build: support for Linux 2.6.34
|
|
||||||
- build: remove unused --with-ksource option
|
|
||||||
- build: remove unneeded --with-xtables option
|
|
||||||
- build: fix compilations in RAWNAT, SYSRQ and length2 when CONFIG_IPV6=n
|
|
||||||
- ipset: update to 4.2
|
|
||||||
- ECHO: fix compilation w.r.t. skb_dst
|
|
||||||
|
|
||||||
|
|
||||||
v1.22 (2010-01-22)
|
|
||||||
==================
|
|
||||||
- compat_xtables: support for 2.6.33 skb_iif changes
|
|
||||||
- geoip: for FHS compliance use /usr/share/xt_geoip instead of /var/geoip
|
|
||||||
- ipset: enable build of ip_set_setlist.ko
|
|
||||||
- quota2: add the --no-change mode
|
|
||||||
|
|
||||||
|
|
||||||
v1.21 (2009-12-09)
|
|
||||||
==================
|
|
||||||
- ACCOUNT: avoid collision with arp_tables setsockopt numbers
|
|
||||||
- doc: fix option mismatch --gw/--gateway in libxt_TEE.man
|
|
||||||
|
|
||||||
|
|
||||||
v1.20 (2009-11-19)
|
|
||||||
==================
|
|
||||||
- ipp2p: add more boundary checks
|
|
||||||
- ipp2p: fix Gnutelle line ending detection
|
|
||||||
- LOGMARK: remove unknown options from manpage
|
|
||||||
- ACCOUNT: endianess-correctness
|
|
||||||
- ipset: install manpage
|
|
||||||
- ipset: fast forward to v4.1
|
|
||||||
|
|
||||||
|
|
||||||
v1.19 (2009-10-12)
|
|
||||||
==================
|
|
||||||
- build: compile fixes for 2.6.31-rt
|
|
||||||
- build: support for Linux 2.6.32
|
|
||||||
- ipp2p: try to address underflows
|
|
||||||
- psd: avoid potential crash when dealing with non-linear skbs
|
|
||||||
- merge xt_ACCOUNT userspace utilities
|
|
||||||
- added reworked xt_pknock module
|
|
||||||
Changes from pknock v0.5:
|
|
||||||
- pknock: "strict" and "checkip" flags were not displayed in `iptables -L`
|
|
||||||
- pknock: the GC expire time's lower bound is now the default gc time
|
|
||||||
(65000 msec) to avoid rendering anti-spoof protection in SPA mode useless
|
|
||||||
- pknock: avoid crash on memory allocation failure and fix memleak
|
|
||||||
- pknock: avoid fillup of peer table during DDoS
|
|
||||||
- pknock: automatic closing of ports
|
|
||||||
- pknock: make non-zero time mandatory for TCP mode
|
|
||||||
- pknock: display only pknock mode and state relevant information in procfs
|
|
||||||
- pknock: check interknock time only for !ST_ALLOWED peers
|
|
||||||
- pknock: preserve time/autoclose values for rules added in
|
|
||||||
reverse/arbitrary order
|
|
||||||
- pknock: add a manpage
|
|
||||||
|
|
||||||
|
|
||||||
v1.18 (2009-09-09)
|
|
||||||
==================
|
|
||||||
- build: support for Linux 2.6.31
|
|
||||||
- ipset: fast forward to v3.2
|
|
||||||
- quota2: support anonymous counters
|
|
||||||
- quota2: reduce memory footprint for anonymous counters
|
|
||||||
- quota2: extend locked period during cleanup (locking bugfix)
|
|
||||||
- quota2: use strtoull instead of strtoul
|
|
||||||
- merged xt_ACCOUNT module
|
|
||||||
- merged xt_psd module
|
|
||||||
|
|
||||||
|
|
||||||
v1.17 (2009-06-16)
|
|
||||||
==================
|
|
||||||
- IPMARK: print missing --shift parameter
|
|
||||||
- build: use readlink -f in extensions/ipset/
|
|
||||||
- build: support for Linux 2.6.30
|
|
||||||
|
|
||||||
|
|
||||||
v1.16 (2009-05-27)
|
|
||||||
==================
|
|
||||||
- RAWNAT: make iptable_rawpost compile with 2.6.30-rc5
|
|
||||||
- ipset: fast forward to 3.0
|
|
||||||
|
|
||||||
|
|
||||||
v1.15 (2009-04-30)
|
|
||||||
==================
|
|
||||||
- build: add kernel version check to configure
|
|
||||||
- condition: compile fix for 2.6.30-rc
|
|
||||||
- condition: fix intrapositional negation sign
|
|
||||||
- fuzzy: fix bogus comparison logic leftover from move to new 1.4.3 API
|
|
||||||
- ipp2p: fix bogus varargs call
|
|
||||||
- ipp2p: fix typo in error message
|
|
||||||
- added "iface" match
|
|
||||||
- added rawpost table (for use with RAWNAT)
|
|
||||||
- added RAWSNAT/RAWDNAT targets
|
|
||||||
|
|
||||||
|
|
||||||
v1.14 (2009-03-31)
|
|
||||||
==================
|
|
||||||
- fuzzy: need to account for kernel-level modified variables in .userspacesize
|
|
||||||
- geoip: remove XT_ALIGN from .userspacesize when used with offsetof
|
|
||||||
- SYSRQ: ignore non-UDP packets
|
|
||||||
- SYSRQ: do proper L4 header access in IPv6 code
|
|
||||||
(must not use tcp/udp_hdr in input path)
|
|
||||||
- add "STEAL" target
|
|
||||||
- dhcpmac: rename from dhcpaddr
|
|
||||||
|
|
||||||
|
|
||||||
v1.13 (2009-03-23)
|
|
||||||
==================
|
|
||||||
- added a reworked ipv4options match
|
|
||||||
- upgrade to iptables 1.4.3 API
|
|
||||||
|
|
||||||
|
|
||||||
v1.12 (2009-03-07)
|
|
||||||
==================
|
|
||||||
- ipset: fix for compilation with 2.6.29-rt
|
|
||||||
- ipset: fast forward to 2.5.0
|
|
||||||
- rename xt_portscan to xt_lscan ("low-level scan") because
|
|
||||||
"portscan" as a word caused confusion
|
|
||||||
- xt_LOGMARK: print incoming interface index
|
|
||||||
- revert "TEE: do not use TOS for routing"
|
|
||||||
- xt_TEE: resolve unknown symbol error with CONFIG_IPV6=n
|
|
||||||
- xt_TEE: enable routing by iif, nfmark and flowlabel
|
|
||||||
|
|
||||||
|
|
||||||
v1.10 (2009-02-18)
|
|
||||||
==================
|
|
||||||
- compat: compile fixes for 2.6.29
|
|
||||||
- ipset: upgrade to ipset 2.4.9
|
|
||||||
|
|
||||||
|
|
||||||
v1.9 (2009-01-30)
|
|
||||||
=================
|
|
||||||
- add the xt_length2 extension
|
|
||||||
- xt_TEE: remove intrapositional '!' support
|
|
||||||
- ipset: upgrade to ipset 2.4.7
|
|
||||||
|
|
||||||
|
|
||||||
v1.8 (2009-01-10)
|
|
||||||
=================
|
|
||||||
- xt_TEE: IPv6 support
|
|
||||||
- xt_TEE: do not include TOS value in routing decision
|
|
||||||
- xt_TEE: fix switch-case inversion for name/IP display
|
|
||||||
- xt_ipp2p: update manpages and help text
|
|
||||||
- xt_ipp2p: remove log flooding
|
|
||||||
- xt_portscan: update manpage about --grscan option caveats
|
|
||||||
|
|
||||||
|
|
||||||
v1.7 (2008-12-25)
|
|
||||||
=================
|
|
||||||
- xt_ECHO: compile fix
|
|
||||||
- avoid the use of "_init" which led to compile errors on some installations
|
|
||||||
- build: do not unconditionally install ipset
|
|
||||||
- doc: add manpages for xt_ECHO and xt_TEE
|
|
||||||
- xt_ipp2p: kazaa detection code cleanup
|
|
||||||
- xt_ipp2p: fix newline inspection in kazaa detection
|
|
||||||
- xt_ipp2p: ensure better array bounds checking
|
|
||||||
- xt_SYSRQ: improve security by hashing password
|
|
||||||
|
|
||||||
|
|
||||||
v1.6 (2008-11-18)
|
|
||||||
=================
|
|
||||||
- build: support for Linux 2.6.17
|
|
||||||
- build: compile fixes for 2.6.18 and 2.6.19
|
|
||||||
- xt_ECHO: resolve compile errors in xt_ECHO
|
|
||||||
- xt_ipp2p: parenthesize unaligned-access macros
|
|
||||||
|
|
||||||
|
|
||||||
v1.5.7 (2008-09-01)
|
|
||||||
===================
|
|
||||||
- API layer: fix use of uninitialized 'hotdrop' variable
|
|
||||||
- API layer: move to pskb-based signatures
|
|
||||||
- xt_SYSRQ: compile fixes for Linux <= 2.6.19
|
|
||||||
- ipset: adjust semaphore.h include for Linux >= 2.6.27
|
|
||||||
- build: automatically run `depmod -a` on installation
|
|
||||||
- add reworked xt_fuzzy module
|
|
||||||
- add DHCP address match and mangle module
|
|
||||||
- xt_portscan: IPv6 support
|
|
||||||
- xt_SYSRQ: add missing module aliases
|
|
||||||
|
|
||||||
|
|
||||||
v1.5.5 (2008-08-03)
|
|
||||||
===================
|
|
||||||
- manpage updates for xt_CHAOS, xt_IPMARK; README updates
|
|
||||||
- build: properly recognize external Kbuild/Mbuild files
|
|
||||||
- build: remove dependency on CONFIG_NETWORK_SECMARK
|
|
||||||
- add the xt_SYSRQ target
|
|
||||||
- add the xt_quota2 extension
|
|
||||||
- import ipset extension group
|
|
||||||
|
|
||||||
|
|
||||||
v1.5.4.1 (2008-04-26)
|
|
||||||
=====================
|
|
||||||
- build: fix compile error for 2.6.18-stable
|
|
||||||
|
|
||||||
|
|
||||||
v1.5.4 (2008-04-09)
|
|
||||||
===================
|
|
||||||
- build: support building multiple files with one config option
|
|
||||||
- API layer: add check for pskb relocation
|
|
||||||
- doc: generate manpages
|
|
||||||
- xt_ECHO: catch skb_linearize out-of-memory condition
|
|
||||||
- xt_LOGMARK: add hook= and ctdir= fields in dump
|
|
||||||
- xt_LOGMARK: fix comma output in ctstatus= list
|
|
||||||
- xt_TEE: fix address copying bug
|
|
||||||
- xt_TEE: make skb writable before attempting checksum update
|
|
||||||
- add reworked xt_condition match
|
|
||||||
- add reworked xt_ipp2p match
|
|
||||||
- add reworked xt_IPMARK target
|
|
||||||
|
|
||||||
|
|
||||||
v1.5.3 (2008-03-22)
|
|
||||||
===================
|
|
||||||
- support for Linux 2.6.18
|
|
||||||
- add xt_ECHO sample target
|
|
||||||
- add reworked xt_geoip match
|
|
||||||
|
|
||||||
|
|
||||||
v1.5.2 (2008-03-04)
|
|
||||||
===================
|
|
||||||
- build: support for GNU make < 3.81 which does not have $(realpath)
|
|
||||||
|
|
||||||
|
|
||||||
v1.5.1 (2008-02-21)
|
|
||||||
===================
|
|
||||||
- build: allow user to select what extensions to compile and install
|
|
||||||
- build: allow external proejcts to be downloaded into the tree
|
|
||||||
- xt_LOGMARK: dump classify mark, ctstate and ctstatus
|
|
||||||
- add xt_CHAOS, xt_DELUDE and xt_portscan from Chaostables
|
|
||||||
|
|
||||||
|
|
||||||
v1.5.0 (2008-02-11)
|
|
||||||
===================
|
|
||||||
Initial release with:
|
|
||||||
- extensions: xt_LOGMARK, xt_TARPIT, xt_TEE
|
|
||||||
- support for Linux >= 2.6.19
|
|
||||||
|
@@ -200,13 +200,19 @@ int main(int argc, char *argv[])
|
|||||||
while ((entry = ipt_ACCOUNT_get_next_entry(&ctx)) != NULL)
|
while ((entry = ipt_ACCOUNT_get_next_entry(&ctx)) != NULL)
|
||||||
{
|
{
|
||||||
if (doCSV)
|
if (doCSV)
|
||||||
printf("%s;%u;%u;%u;%u\n",
|
printf("%s;%llu;%llu;%llu;%llu\n",
|
||||||
addr_to_dotted(entry->ip), entry->src_packets, entry->src_bytes,
|
addr_to_dotted(entry->ip),
|
||||||
entry->dst_packets, entry->dst_bytes);
|
(unsigned long long)entry->src_packets,
|
||||||
|
(unsigned long long)entry->src_bytes,
|
||||||
|
(unsigned long long)entry->dst_packets,
|
||||||
|
(unsigned long long)entry->dst_bytes);
|
||||||
else
|
else
|
||||||
printf("IP: %s SRC packets: %u bytes: %u DST packets: %u bytes: %u\n",
|
printf("IP: %s SRC packets: %llu bytes: %llu DST packets: %llu bytes: %llu\n",
|
||||||
addr_to_dotted(entry->ip), entry->src_packets, entry->src_bytes,
|
addr_to_dotted(entry->ip),
|
||||||
entry->dst_packets, entry->dst_bytes);
|
(unsigned long long)entry->src_packets,
|
||||||
|
(unsigned long long)entry->src_bytes,
|
||||||
|
(unsigned long long)entry->dst_packets,
|
||||||
|
(unsigned long long)entry->dst_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doContinue)
|
if (doContinue)
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
//#define DEBUG 1
|
//#define DEBUG 1
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/version.h>
|
#include <linux/version.h>
|
||||||
|
#include <net/net_namespace.h>
|
||||||
#include <linux/skbuff.h>
|
#include <linux/skbuff.h>
|
||||||
#include <linux/ip.h>
|
#include <linux/ip.h>
|
||||||
#include <net/icmp.h>
|
#include <net/icmp.h>
|
||||||
@@ -29,6 +30,7 @@
|
|||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
#include <linux/spinlock.h>
|
#include <linux/spinlock.h>
|
||||||
#include <asm/uaccess.h>
|
#include <asm/uaccess.h>
|
||||||
|
#include <net/netns/generic.h>
|
||||||
|
|
||||||
#include <net/route.h>
|
#include <net/route.h>
|
||||||
#include "xt_ACCOUNT.h"
|
#include "xt_ACCOUNT.h"
|
||||||
@@ -73,13 +75,13 @@ struct ipt_acc_handle {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Used for every IP entry
|
/* Used for every IP entry
|
||||||
Size is 16 bytes so that 256 (class C network) * 16
|
Size is 32 bytes so that 256 (class C network) * 16
|
||||||
fits in one kernel (zero) page */
|
fits in a double kernel (zero) page (two consecutive kernel pages)*/
|
||||||
struct ipt_acc_ip {
|
struct ipt_acc_ip {
|
||||||
uint32_t src_packets;
|
uint64_t src_packets;
|
||||||
uint32_t src_bytes;
|
uint64_t src_bytes;
|
||||||
uint32_t dst_packets;
|
uint64_t dst_packets;
|
||||||
uint32_t dst_bytes;
|
uint64_t dst_bytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -100,25 +102,28 @@ struct ipt_acc_mask_8 {
|
|||||||
struct ipt_acc_mask_16 *mask_16[256];
|
struct ipt_acc_mask_16 *mask_16[256];
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct ipt_acc_table *ipt_acc_tables;
|
static int ipt_acc_net_id __read_mostly;
|
||||||
static struct ipt_acc_handle *ipt_acc_handles;
|
|
||||||
static void *ipt_acc_tmpbuf;
|
|
||||||
|
|
||||||
/* Spinlock used for manipulating the current accounting tables/data */
|
struct ipt_acc_net {
|
||||||
static DEFINE_SPINLOCK(ipt_acc_lock);
|
/* Spinlock used for manipulating the current accounting tables/data */
|
||||||
/* Mutex (semaphore) used for manipulating userspace handles/snapshot data */
|
spinlock_t ipt_acc_lock;
|
||||||
static struct semaphore ipt_acc_userspace_mutex;
|
|
||||||
|
|
||||||
/* Allocates a page and clears it */
|
/* Mutex (semaphore) used for manipulating userspace handles/snapshot data */
|
||||||
|
struct semaphore ipt_acc_userspace_mutex;
|
||||||
|
|
||||||
|
struct ipt_acc_table *ipt_acc_tables;
|
||||||
|
struct ipt_acc_handle *ipt_acc_handles;
|
||||||
|
void *ipt_acc_tmpbuf;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Allocates a page pair and clears it */
|
||||||
static void *ipt_acc_zalloc_page(void)
|
static void *ipt_acc_zalloc_page(void)
|
||||||
{
|
{
|
||||||
// Don't use get_zeroed_page until it's fixed in the kernel.
|
// Don't use get_zeroed_page until it's fixed in the kernel.
|
||||||
// get_zeroed_page(GFP_ATOMIC)
|
// get_zeroed_page(GFP_ATOMIC)
|
||||||
void *mem = (void *)__get_free_page(GFP_ATOMIC);
|
void *mem = (void *)__get_free_pages(GFP_ATOMIC, 2);
|
||||||
if (mem) {
|
if (mem != NULL)
|
||||||
memset (mem, 0, PAGE_SIZE);
|
memset(mem, 0, 2 *PAGE_SIZE);
|
||||||
}
|
|
||||||
|
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +136,7 @@ static void ipt_acc_data_free(void *data, uint8_t depth)
|
|||||||
|
|
||||||
/* Free for 8 bit network */
|
/* Free for 8 bit network */
|
||||||
if (depth == 0) {
|
if (depth == 0) {
|
||||||
free_page((unsigned long)data);
|
free_pages((unsigned long)data, 2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,12 +144,10 @@ static void ipt_acc_data_free(void *data, uint8_t depth)
|
|||||||
if (depth == 1) {
|
if (depth == 1) {
|
||||||
struct ipt_acc_mask_16 *mask_16 = data;
|
struct ipt_acc_mask_16 *mask_16 = data;
|
||||||
unsigned int b;
|
unsigned int b;
|
||||||
for (b = 0; b <= 255; b++) {
|
for (b = 0; b <= 255; ++b)
|
||||||
if (mask_16->mask_24[b]) {
|
if (mask_16->mask_24[b])
|
||||||
free_page((unsigned long)mask_16->mask_24[b]);
|
free_pages((unsigned long)mask_16->mask_24[b], 2);
|
||||||
}
|
free_pages((unsigned long)data, 2);
|
||||||
}
|
|
||||||
free_page((unsigned long)data);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,15 +159,13 @@ static void ipt_acc_data_free(void *data, uint8_t depth)
|
|||||||
struct ipt_acc_mask_16 *mask_16 =
|
struct ipt_acc_mask_16 *mask_16 =
|
||||||
((struct ipt_acc_mask_8 *)data)->mask_16[a];
|
((struct ipt_acc_mask_8 *)data)->mask_16[a];
|
||||||
|
|
||||||
for (b = 0; b <= 255; b++) {
|
for (b = 0; b <= 255; ++b)
|
||||||
if (mask_16->mask_24[b]) {
|
if (mask_16->mask_24[b])
|
||||||
free_page((unsigned long)mask_16->mask_24[b]);
|
free_pages((unsigned long)mask_16->mask_24[b], 2);
|
||||||
}
|
free_pages((unsigned long)mask_16, 2);
|
||||||
}
|
|
||||||
free_page((unsigned long)mask_16);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free_page((unsigned long)data);
|
free_pages((unsigned long)data, 2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +176,8 @@ static void ipt_acc_data_free(void *data, uint8_t depth)
|
|||||||
|
|
||||||
/* Look for existing table / insert new one.
|
/* Look for existing table / insert new one.
|
||||||
Return internal ID or -1 on error */
|
Return internal ID or -1 on error */
|
||||||
static int ipt_acc_table_insert(const char *name, __be32 ip, __be32 netmask)
|
static int ipt_acc_table_insert(struct ipt_acc_table *ipt_acc_tables,
|
||||||
|
const char *name, __be32 ip, __be32 netmask)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
@@ -262,13 +264,15 @@ static int ipt_acc_table_insert(const char *name, __be32 ip, __be32 netmask)
|
|||||||
|
|
||||||
static int ipt_acc_checkentry(const struct xt_tgchk_param *par)
|
static int ipt_acc_checkentry(const struct xt_tgchk_param *par)
|
||||||
{
|
{
|
||||||
|
struct ipt_acc_net *ian = net_generic(par->net, ipt_acc_net_id);
|
||||||
struct ipt_acc_info *info = par->targinfo;
|
struct ipt_acc_info *info = par->targinfo;
|
||||||
int table_nr;
|
int table_nr;
|
||||||
|
|
||||||
spin_lock_bh(&ipt_acc_lock);
|
spin_lock_bh(&ian->ipt_acc_lock);
|
||||||
table_nr = ipt_acc_table_insert(info->table_name, info->net_ip,
|
table_nr = ipt_acc_table_insert(ian->ipt_acc_tables,
|
||||||
|
info->table_name, info->net_ip,
|
||||||
info->net_mask);
|
info->net_mask);
|
||||||
spin_unlock_bh(&ipt_acc_lock);
|
spin_unlock_bh(&ian->ipt_acc_lock);
|
||||||
|
|
||||||
if (table_nr == -1) {
|
if (table_nr == -1) {
|
||||||
printk("ACCOUNT: Table insert problem. Aborting\n");
|
printk("ACCOUNT: Table insert problem. Aborting\n");
|
||||||
@@ -283,10 +287,11 @@ static int ipt_acc_checkentry(const struct xt_tgchk_param *par)
|
|||||||
|
|
||||||
static void ipt_acc_destroy(const struct xt_tgdtor_param *par)
|
static void ipt_acc_destroy(const struct xt_tgdtor_param *par)
|
||||||
{
|
{
|
||||||
|
struct ipt_acc_net *ian = net_generic(par->net, ipt_acc_net_id);
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
struct ipt_acc_info *info = par->targinfo;
|
struct ipt_acc_info *info = par->targinfo;
|
||||||
|
|
||||||
spin_lock_bh(&ipt_acc_lock);
|
spin_lock_bh(&ian->ipt_acc_lock);
|
||||||
|
|
||||||
pr_debug("ACCOUNT: ipt_acc_deleteentry called for table: %s (#%d)\n",
|
pr_debug("ACCOUNT: ipt_acc_deleteentry called for table: %s (#%d)\n",
|
||||||
info->table_name, info->table_nr);
|
info->table_name, info->table_nr);
|
||||||
@@ -295,31 +300,31 @@ static void ipt_acc_destroy(const struct xt_tgdtor_param *par)
|
|||||||
|
|
||||||
/* Look for table */
|
/* Look for table */
|
||||||
for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
|
for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
|
||||||
if (strncmp(ipt_acc_tables[i].name, info->table_name,
|
if (strncmp(ian->ipt_acc_tables[i].name, info->table_name,
|
||||||
ACCOUNT_TABLE_NAME_LEN) == 0) {
|
ACCOUNT_TABLE_NAME_LEN) == 0) {
|
||||||
pr_debug("ACCOUNT: Found table at slot: %d\n", i);
|
pr_debug("ACCOUNT: Found table at slot: %d\n", i);
|
||||||
|
|
||||||
ipt_acc_tables[i].refcount--;
|
ian->ipt_acc_tables[i].refcount--;
|
||||||
pr_debug("ACCOUNT: Refcount left: %d\n",
|
pr_debug("ACCOUNT: Refcount left: %d\n",
|
||||||
ipt_acc_tables[i].refcount);
|
ian->ipt_acc_tables[i].refcount);
|
||||||
|
|
||||||
/* Table not needed anymore? */
|
/* Table not needed anymore? */
|
||||||
if (ipt_acc_tables[i].refcount == 0) {
|
if (ian->ipt_acc_tables[i].refcount == 0) {
|
||||||
pr_debug("ACCOUNT: Destroying table at slot: %d\n", i);
|
pr_debug("ACCOUNT: Destroying table at slot: %d\n", i);
|
||||||
ipt_acc_data_free(ipt_acc_tables[i].data,
|
ipt_acc_data_free(ian->ipt_acc_tables[i].data,
|
||||||
ipt_acc_tables[i].depth);
|
ian->ipt_acc_tables[i].depth);
|
||||||
memset(&ipt_acc_tables[i], 0,
|
memset(&ian->ipt_acc_tables[i], 0,
|
||||||
sizeof(struct ipt_acc_table));
|
sizeof(struct ipt_acc_table));
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock_bh(&ipt_acc_lock);
|
spin_unlock_bh(&ian->ipt_acc_lock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Table not found */
|
/* Table not found */
|
||||||
printk("ACCOUNT: Table %s not found for destroy\n", info->table_name);
|
printk("ACCOUNT: Table %s not found for destroy\n", info->table_name);
|
||||||
spin_unlock_bh(&ipt_acc_lock);
|
spin_unlock_bh(&ian->ipt_acc_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ipt_acc_depth0_insert(struct ipt_acc_mask_24 *mask_24,
|
static void ipt_acc_depth0_insert(struct ipt_acc_mask_24 *mask_24,
|
||||||
@@ -477,6 +482,8 @@ static void ipt_acc_depth2_insert(struct ipt_acc_mask_8 *mask_8,
|
|||||||
static unsigned int
|
static unsigned int
|
||||||
ipt_acc_target(struct sk_buff *skb, const struct xt_action_param *par)
|
ipt_acc_target(struct sk_buff *skb, const struct xt_action_param *par)
|
||||||
{
|
{
|
||||||
|
struct ipt_acc_net *ian = net_generic(par->state->net, ipt_acc_net_id);
|
||||||
|
struct ipt_acc_table *ipt_acc_tables = ian->ipt_acc_tables;
|
||||||
const struct ipt_acc_info *info =
|
const struct ipt_acc_info *info =
|
||||||
par->targinfo;
|
par->targinfo;
|
||||||
|
|
||||||
@@ -484,13 +491,13 @@ ipt_acc_target(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
__be32 dst_ip = ip_hdr(skb)->daddr;
|
__be32 dst_ip = ip_hdr(skb)->daddr;
|
||||||
uint32_t size = ntohs(ip_hdr(skb)->tot_len);
|
uint32_t size = ntohs(ip_hdr(skb)->tot_len);
|
||||||
|
|
||||||
spin_lock_bh(&ipt_acc_lock);
|
spin_lock_bh(&ian->ipt_acc_lock);
|
||||||
|
|
||||||
if (ipt_acc_tables[info->table_nr].name[0] == 0) {
|
if (ipt_acc_tables[info->table_nr].name[0] == 0) {
|
||||||
printk("ACCOUNT: ipt_acc_target: Invalid table id %u. "
|
printk("ACCOUNT: ipt_acc_target: Invalid table id %u. "
|
||||||
"IPs %u.%u.%u.%u/%u.%u.%u.%u\n", info->table_nr,
|
"IPs %u.%u.%u.%u/%u.%u.%u.%u\n", info->table_nr,
|
||||||
NIPQUAD(src_ip), NIPQUAD(dst_ip));
|
NIPQUAD(src_ip), NIPQUAD(dst_ip));
|
||||||
spin_unlock_bh(&ipt_acc_lock);
|
spin_unlock_bh(&ian->ipt_acc_lock);
|
||||||
return XT_CONTINUE;
|
return XT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,7 +509,7 @@ ipt_acc_target(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
ipt_acc_tables[info->table_nr].ip,
|
ipt_acc_tables[info->table_nr].ip,
|
||||||
ipt_acc_tables[info->table_nr].netmask,
|
ipt_acc_tables[info->table_nr].netmask,
|
||||||
src_ip, dst_ip, size, &ipt_acc_tables[info->table_nr].itemcount);
|
src_ip, dst_ip, size, &ipt_acc_tables[info->table_nr].itemcount);
|
||||||
spin_unlock_bh(&ipt_acc_lock);
|
spin_unlock_bh(&ian->ipt_acc_lock);
|
||||||
return XT_CONTINUE;
|
return XT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -513,7 +520,7 @@ ipt_acc_target(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
ipt_acc_tables[info->table_nr].ip,
|
ipt_acc_tables[info->table_nr].ip,
|
||||||
ipt_acc_tables[info->table_nr].netmask,
|
ipt_acc_tables[info->table_nr].netmask,
|
||||||
src_ip, dst_ip, size, &ipt_acc_tables[info->table_nr].itemcount);
|
src_ip, dst_ip, size, &ipt_acc_tables[info->table_nr].itemcount);
|
||||||
spin_unlock_bh(&ipt_acc_lock);
|
spin_unlock_bh(&ian->ipt_acc_lock);
|
||||||
return XT_CONTINUE;
|
return XT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,7 +531,7 @@ ipt_acc_target(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
ipt_acc_tables[info->table_nr].ip,
|
ipt_acc_tables[info->table_nr].ip,
|
||||||
ipt_acc_tables[info->table_nr].netmask,
|
ipt_acc_tables[info->table_nr].netmask,
|
||||||
src_ip, dst_ip, size, &ipt_acc_tables[info->table_nr].itemcount);
|
src_ip, dst_ip, size, &ipt_acc_tables[info->table_nr].itemcount);
|
||||||
spin_unlock_bh(&ipt_acc_lock);
|
spin_unlock_bh(&ian->ipt_acc_lock);
|
||||||
return XT_CONTINUE;
|
return XT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -532,13 +539,13 @@ ipt_acc_target(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
"Table id %u. IPs %u.%u.%u.%u/%u.%u.%u.%u\n",
|
"Table id %u. IPs %u.%u.%u.%u/%u.%u.%u.%u\n",
|
||||||
info->table_nr, NIPQUAD(src_ip), NIPQUAD(dst_ip));
|
info->table_nr, NIPQUAD(src_ip), NIPQUAD(dst_ip));
|
||||||
|
|
||||||
spin_unlock_bh(&ipt_acc_lock);
|
spin_unlock_bh(&ian->ipt_acc_lock);
|
||||||
return XT_CONTINUE;
|
return XT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Functions dealing with "handles":
|
Functions dealing with "handles":
|
||||||
Handles are snapshots of a accounting state.
|
Handles are snapshots of an accounting state.
|
||||||
|
|
||||||
read snapshots are only for debugging the code
|
read snapshots are only for debugging the code
|
||||||
and are very expensive concerning speed/memory
|
and are very expensive concerning speed/memory
|
||||||
@@ -553,7 +560,7 @@ ipt_acc_target(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
but there could be two or more applications accessing the data
|
but there could be two or more applications accessing the data
|
||||||
at the same time.
|
at the same time.
|
||||||
*/
|
*/
|
||||||
static int ipt_acc_handle_find_slot(void)
|
static int ipt_acc_handle_find_slot(struct ipt_acc_handle *ipt_acc_handles)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
/* Insert new table */
|
/* Insert new table */
|
||||||
@@ -573,7 +580,8 @@ static int ipt_acc_handle_find_slot(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ipt_acc_handle_free(unsigned int handle)
|
static int ipt_acc_handle_free(struct ipt_acc_handle *ipt_acc_handles,
|
||||||
|
unsigned int handle)
|
||||||
{
|
{
|
||||||
if (handle >= ACCOUNT_MAX_HANDLES) {
|
if (handle >= ACCOUNT_MAX_HANDLES) {
|
||||||
printk("ACCOUNT: Invalid handle for ipt_acc_handle_free() specified:"
|
printk("ACCOUNT: Invalid handle for ipt_acc_handle_free() specified:"
|
||||||
@@ -589,7 +597,8 @@ static int ipt_acc_handle_free(unsigned int handle)
|
|||||||
|
|
||||||
/* Prepare data for read without flush. Use only for debugging!
|
/* Prepare data for read without flush. Use only for debugging!
|
||||||
Real applications should use read&flush as it's way more efficent */
|
Real applications should use read&flush as it's way more efficent */
|
||||||
static int ipt_acc_handle_prepare_read(char *tablename,
|
static int ipt_acc_handle_prepare_read(struct ipt_acc_table *ipt_acc_tables,
|
||||||
|
char *tablename,
|
||||||
struct ipt_acc_handle *dest, uint32_t *count)
|
struct ipt_acc_handle *dest, uint32_t *count)
|
||||||
{
|
{
|
||||||
int table_nr = -1;
|
int table_nr = -1;
|
||||||
@@ -631,18 +640,18 @@ static int ipt_acc_handle_prepare_read(char *tablename,
|
|||||||
unsigned int b;
|
unsigned int b;
|
||||||
|
|
||||||
for (b = 0; b <= 255; b++) {
|
for (b = 0; b <= 255; b++) {
|
||||||
if (src_16->mask_24[b]) {
|
if (src_16->mask_24[b] == NULL)
|
||||||
if ((network_16->mask_24[b] =
|
continue;
|
||||||
ipt_acc_zalloc_page()) == NULL) {
|
if ((network_16->mask_24[b] =
|
||||||
printk("ACCOUNT: out of memory during copy of 16 bit "
|
ipt_acc_zalloc_page()) == NULL) {
|
||||||
"network in ipt_acc_handle_prepare_read()\n");
|
printk("ACCOUNT: out of memory during copy of 16 bit "
|
||||||
ipt_acc_data_free(dest->data, depth);
|
"network in ipt_acc_handle_prepare_read()\n");
|
||||||
return -1;
|
ipt_acc_data_free(dest->data, depth);
|
||||||
}
|
return -1;
|
||||||
|
|
||||||
memcpy(network_16->mask_24[b], src_16->mask_24[b],
|
|
||||||
sizeof(struct ipt_acc_mask_24));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(network_16->mask_24[b], src_16->mask_24[b],
|
||||||
|
sizeof(struct ipt_acc_mask_24));
|
||||||
}
|
}
|
||||||
} else if (depth == 2) {
|
} else if (depth == 2) {
|
||||||
struct ipt_acc_mask_8 *src_8 =
|
struct ipt_acc_mask_8 *src_8 =
|
||||||
@@ -652,35 +661,35 @@ static int ipt_acc_handle_prepare_read(char *tablename,
|
|||||||
unsigned int a, b;
|
unsigned int a, b;
|
||||||
|
|
||||||
for (a = 0; a <= 255; a++) {
|
for (a = 0; a <= 255; a++) {
|
||||||
if (src_8->mask_16[a]) {
|
if (src_8->mask_16[a] == NULL)
|
||||||
if ((network_8->mask_16[a] =
|
continue;
|
||||||
|
if ((network_8->mask_16[a] =
|
||||||
|
ipt_acc_zalloc_page()) == NULL) {
|
||||||
|
printk("ACCOUNT: out of memory during copy of 24 bit network"
|
||||||
|
" in ipt_acc_handle_prepare_read()\n");
|
||||||
|
ipt_acc_data_free(dest->data, depth);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(network_8->mask_16[a], src_8->mask_16[a],
|
||||||
|
sizeof(struct ipt_acc_mask_16));
|
||||||
|
|
||||||
|
src_16 = src_8->mask_16[a];
|
||||||
|
network_16 = network_8->mask_16[a];
|
||||||
|
|
||||||
|
for (b = 0; b <= 255; b++) {
|
||||||
|
if (src_16->mask_24[b] == NULL)
|
||||||
|
continue;
|
||||||
|
if ((network_16->mask_24[b] =
|
||||||
ipt_acc_zalloc_page()) == NULL) {
|
ipt_acc_zalloc_page()) == NULL) {
|
||||||
printk("ACCOUNT: out of memory during copy of 24 bit network"
|
printk("ACCOUNT: out of memory during copy of 16 bit"
|
||||||
" in ipt_acc_handle_prepare_read()\n");
|
" network in ipt_acc_handle_prepare_read()\n");
|
||||||
ipt_acc_data_free(dest->data, depth);
|
ipt_acc_data_free(dest->data, depth);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(network_8->mask_16[a], src_8->mask_16[a],
|
memcpy(network_16->mask_24[b], src_16->mask_24[b],
|
||||||
sizeof(struct ipt_acc_mask_16));
|
sizeof(struct ipt_acc_mask_24));
|
||||||
|
|
||||||
src_16 = src_8->mask_16[a];
|
|
||||||
network_16 = network_8->mask_16[a];
|
|
||||||
|
|
||||||
for (b = 0; b <= 255; b++) {
|
|
||||||
if (src_16->mask_24[b]) {
|
|
||||||
if ((network_16->mask_24[b] =
|
|
||||||
ipt_acc_zalloc_page()) == NULL) {
|
|
||||||
printk("ACCOUNT: out of memory during copy of 16 bit"
|
|
||||||
" network in ipt_acc_handle_prepare_read()\n");
|
|
||||||
ipt_acc_data_free(dest->data, depth);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(network_16->mask_24[b], src_16->mask_24[b],
|
|
||||||
sizeof(struct ipt_acc_mask_24));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -691,7 +700,8 @@ static int ipt_acc_handle_prepare_read(char *tablename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare data for read and flush it */
|
/* Prepare data for read and flush it */
|
||||||
static int ipt_acc_handle_prepare_read_flush(char *tablename,
|
static int ipt_acc_handle_prepare_read_flush(struct ipt_acc_table *ipt_acc_tables,
|
||||||
|
char *tablename,
|
||||||
struct ipt_acc_handle *dest, uint32_t *count)
|
struct ipt_acc_handle *dest, uint32_t *count)
|
||||||
{
|
{
|
||||||
int table_nr;
|
int table_nr;
|
||||||
@@ -732,7 +742,8 @@ static int ipt_acc_handle_prepare_read_flush(char *tablename,
|
|||||||
/* Copy 8 bit network data into a prepared buffer.
|
/* Copy 8 bit network data into a prepared buffer.
|
||||||
We only copy entries != 0 to increase performance.
|
We only copy entries != 0 to increase performance.
|
||||||
*/
|
*/
|
||||||
static int ipt_acc_handle_copy_data(void *to_user, unsigned long *to_user_pos,
|
static int ipt_acc_handle_copy_data(struct ipt_acc_net *ian,
|
||||||
|
void *to_user, unsigned long *to_user_pos,
|
||||||
unsigned long *tmpbuf_pos,
|
unsigned long *tmpbuf_pos,
|
||||||
struct ipt_acc_mask_24 *data,
|
struct ipt_acc_mask_24 *data,
|
||||||
uint32_t net_ip, uint32_t net_OR_mask)
|
uint32_t net_ip, uint32_t net_OR_mask)
|
||||||
@@ -742,25 +753,26 @@ static int ipt_acc_handle_copy_data(void *to_user, unsigned long *to_user_pos,
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i <= 255; i++) {
|
for (i = 0; i <= 255; i++) {
|
||||||
if (data->ip[i].src_packets || data->ip[i].dst_packets) {
|
if (data->ip[i].src_packets == 0 &&
|
||||||
handle_ip.ip = net_ip | net_OR_mask | i;
|
data->ip[i].dst_packets == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
handle_ip.src_packets = data->ip[i].src_packets;
|
handle_ip.ip = net_ip | net_OR_mask | i;
|
||||||
handle_ip.src_bytes = data->ip[i].src_bytes;
|
handle_ip.src_packets = data->ip[i].src_packets;
|
||||||
handle_ip.dst_packets = data->ip[i].dst_packets;
|
handle_ip.src_bytes = data->ip[i].src_bytes;
|
||||||
handle_ip.dst_bytes = data->ip[i].dst_bytes;
|
handle_ip.dst_packets = data->ip[i].dst_packets;
|
||||||
|
handle_ip.dst_bytes = data->ip[i].dst_bytes;
|
||||||
|
|
||||||
/* Temporary buffer full? Flush to userspace */
|
/* Temporary buffer full? Flush to userspace */
|
||||||
if (*tmpbuf_pos + handle_ip_size >= PAGE_SIZE) {
|
if (*tmpbuf_pos + handle_ip_size >= PAGE_SIZE) {
|
||||||
if (copy_to_user(to_user + *to_user_pos, ipt_acc_tmpbuf,
|
if (copy_to_user(to_user + *to_user_pos, ian->ipt_acc_tmpbuf,
|
||||||
*tmpbuf_pos))
|
*tmpbuf_pos))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
*to_user_pos = *to_user_pos + *tmpbuf_pos;
|
*to_user_pos = *to_user_pos + *tmpbuf_pos;
|
||||||
*tmpbuf_pos = 0;
|
*tmpbuf_pos = 0;
|
||||||
}
|
|
||||||
memcpy(ipt_acc_tmpbuf + *tmpbuf_pos, &handle_ip, handle_ip_size);
|
|
||||||
*tmpbuf_pos += handle_ip_size;
|
|
||||||
}
|
}
|
||||||
|
memcpy(ian->ipt_acc_tmpbuf + *tmpbuf_pos, &handle_ip, handle_ip_size);
|
||||||
|
*tmpbuf_pos += handle_ip_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -770,7 +782,8 @@ static int ipt_acc_handle_copy_data(void *to_user, unsigned long *to_user_pos,
|
|||||||
We only copy entries != 0 to increase performance.
|
We only copy entries != 0 to increase performance.
|
||||||
Overwrites ipt_acc_tmpbuf.
|
Overwrites ipt_acc_tmpbuf.
|
||||||
*/
|
*/
|
||||||
static int ipt_acc_handle_get_data(uint32_t handle, void *to_user)
|
static int ipt_acc_handle_get_data(struct ipt_acc_net *ian,
|
||||||
|
uint32_t handle, void *to_user)
|
||||||
{
|
{
|
||||||
unsigned long to_user_pos = 0, tmpbuf_pos = 0;
|
unsigned long to_user_pos = 0, tmpbuf_pos = 0;
|
||||||
uint32_t net_ip;
|
uint32_t net_ip;
|
||||||
@@ -782,25 +795,25 @@ static int ipt_acc_handle_get_data(uint32_t handle, void *to_user)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ipt_acc_handles[handle].data == NULL) {
|
if (ian->ipt_acc_handles[handle].data == NULL) {
|
||||||
printk("ACCOUNT: handle %u is BROKEN: Contains no data\n", handle);
|
printk("ACCOUNT: handle %u is BROKEN: Contains no data\n", handle);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
net_ip = ntohl(ipt_acc_handles[handle].ip);
|
net_ip = ntohl(ian->ipt_acc_handles[handle].ip);
|
||||||
depth = ipt_acc_handles[handle].depth;
|
depth = ian->ipt_acc_handles[handle].depth;
|
||||||
|
|
||||||
/* 8 bit network */
|
/* 8 bit network */
|
||||||
if (depth == 0) {
|
if (depth == 0) {
|
||||||
struct ipt_acc_mask_24 *network =
|
struct ipt_acc_mask_24 *network =
|
||||||
ipt_acc_handles[handle].data;
|
ian->ipt_acc_handles[handle].data;
|
||||||
if (ipt_acc_handle_copy_data(to_user, &to_user_pos, &tmpbuf_pos,
|
if (ipt_acc_handle_copy_data(ian, to_user, &to_user_pos, &tmpbuf_pos,
|
||||||
network, net_ip, 0))
|
network, net_ip, 0))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Flush remaining data to userspace */
|
/* Flush remaining data to userspace */
|
||||||
if (tmpbuf_pos)
|
if (tmpbuf_pos)
|
||||||
if (copy_to_user(to_user + to_user_pos, ipt_acc_tmpbuf, tmpbuf_pos))
|
if (copy_to_user(to_user + to_user_pos, ian->ipt_acc_tmpbuf, tmpbuf_pos))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -809,13 +822,13 @@ static int ipt_acc_handle_get_data(uint32_t handle, void *to_user)
|
|||||||
/* 16 bit network */
|
/* 16 bit network */
|
||||||
if (depth == 1) {
|
if (depth == 1) {
|
||||||
struct ipt_acc_mask_16 *network_16 =
|
struct ipt_acc_mask_16 *network_16 =
|
||||||
ipt_acc_handles[handle].data;
|
ian->ipt_acc_handles[handle].data;
|
||||||
unsigned int b;
|
unsigned int b;
|
||||||
for (b = 0; b <= 255; b++) {
|
for (b = 0; b <= 255; b++) {
|
||||||
if (network_16->mask_24[b]) {
|
if (network_16->mask_24[b]) {
|
||||||
struct ipt_acc_mask_24 *network =
|
struct ipt_acc_mask_24 *network =
|
||||||
network_16->mask_24[b];
|
network_16->mask_24[b];
|
||||||
if (ipt_acc_handle_copy_data(to_user, &to_user_pos,
|
if (ipt_acc_handle_copy_data(ian, to_user, &to_user_pos,
|
||||||
&tmpbuf_pos, network, net_ip, (b << 8)))
|
&tmpbuf_pos, network, net_ip, (b << 8)))
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -823,7 +836,7 @@ static int ipt_acc_handle_get_data(uint32_t handle, void *to_user)
|
|||||||
|
|
||||||
/* Flush remaining data to userspace */
|
/* Flush remaining data to userspace */
|
||||||
if (tmpbuf_pos)
|
if (tmpbuf_pos)
|
||||||
if (copy_to_user(to_user + to_user_pos, ipt_acc_tmpbuf, tmpbuf_pos))
|
if (copy_to_user(to_user + to_user_pos, ian->ipt_acc_tmpbuf, tmpbuf_pos))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -832,7 +845,7 @@ static int ipt_acc_handle_get_data(uint32_t handle, void *to_user)
|
|||||||
/* 24 bit network */
|
/* 24 bit network */
|
||||||
if (depth == 2) {
|
if (depth == 2) {
|
||||||
struct ipt_acc_mask_8 *network_8 =
|
struct ipt_acc_mask_8 *network_8 =
|
||||||
ipt_acc_handles[handle].data;
|
ian->ipt_acc_handles[handle].data;
|
||||||
unsigned int a, b;
|
unsigned int a, b;
|
||||||
for (a = 0; a <= 255; a++) {
|
for (a = 0; a <= 255; a++) {
|
||||||
if (network_8->mask_16[a]) {
|
if (network_8->mask_16[a]) {
|
||||||
@@ -842,7 +855,7 @@ static int ipt_acc_handle_get_data(uint32_t handle, void *to_user)
|
|||||||
if (network_16->mask_24[b]) {
|
if (network_16->mask_24[b]) {
|
||||||
struct ipt_acc_mask_24 *network =
|
struct ipt_acc_mask_24 *network =
|
||||||
network_16->mask_24[b];
|
network_16->mask_24[b];
|
||||||
if (ipt_acc_handle_copy_data(to_user,
|
if (ipt_acc_handle_copy_data(ian, to_user,
|
||||||
&to_user_pos, &tmpbuf_pos,
|
&to_user_pos, &tmpbuf_pos,
|
||||||
network, net_ip, (a << 16) | (b << 8)))
|
network, net_ip, (a << 16) | (b << 8)))
|
||||||
return -1;
|
return -1;
|
||||||
@@ -853,7 +866,7 @@ static int ipt_acc_handle_get_data(uint32_t handle, void *to_user)
|
|||||||
|
|
||||||
/* Flush remaining data to userspace */
|
/* Flush remaining data to userspace */
|
||||||
if (tmpbuf_pos)
|
if (tmpbuf_pos)
|
||||||
if (copy_to_user(to_user + to_user_pos, ipt_acc_tmpbuf, tmpbuf_pos))
|
if (copy_to_user(to_user + to_user_pos, ian->ipt_acc_tmpbuf, tmpbuf_pos))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -865,6 +878,8 @@ static int ipt_acc_handle_get_data(uint32_t handle, void *to_user)
|
|||||||
static int ipt_acc_set_ctl(struct sock *sk, int cmd,
|
static int ipt_acc_set_ctl(struct sock *sk, int cmd,
|
||||||
void *user, unsigned int len)
|
void *user, unsigned int len)
|
||||||
{
|
{
|
||||||
|
struct net *net = sock_net(sk);
|
||||||
|
struct ipt_acc_net *ian = net_generic(net, ipt_acc_net_id);
|
||||||
struct ipt_acc_handle_sockopt handle;
|
struct ipt_acc_handle_sockopt handle;
|
||||||
int ret = -EINVAL;
|
int ret = -EINVAL;
|
||||||
|
|
||||||
@@ -886,16 +901,16 @@ static int ipt_acc_set_ctl(struct sock *sk, int cmd,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
down(&ipt_acc_userspace_mutex);
|
down(&ian->ipt_acc_userspace_mutex);
|
||||||
ret = ipt_acc_handle_free(handle.handle_nr);
|
ret = ipt_acc_handle_free(ian->ipt_acc_handles, handle.handle_nr);
|
||||||
up(&ipt_acc_userspace_mutex);
|
up(&ian->ipt_acc_userspace_mutex);
|
||||||
break;
|
break;
|
||||||
case IPT_SO_SET_ACCOUNT_HANDLE_FREE_ALL: {
|
case IPT_SO_SET_ACCOUNT_HANDLE_FREE_ALL: {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
down(&ipt_acc_userspace_mutex);
|
down(&ian->ipt_acc_userspace_mutex);
|
||||||
for (i = 0; i < ACCOUNT_MAX_HANDLES; i++)
|
for (i = 0; i < ACCOUNT_MAX_HANDLES; i++)
|
||||||
ipt_acc_handle_free(i);
|
ipt_acc_handle_free(ian->ipt_acc_handles, i);
|
||||||
up(&ipt_acc_userspace_mutex);
|
up(&ian->ipt_acc_userspace_mutex);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -908,6 +923,8 @@ static int ipt_acc_set_ctl(struct sock *sk, int cmd,
|
|||||||
|
|
||||||
static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len)
|
static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len)
|
||||||
{
|
{
|
||||||
|
struct net *net = sock_net(sk);
|
||||||
|
struct ipt_acc_net *ian = net_generic(net, ipt_acc_net_id);
|
||||||
struct ipt_acc_handle_sockopt handle;
|
struct ipt_acc_handle_sockopt handle;
|
||||||
int ret = -EINVAL;
|
int ret = -EINVAL;
|
||||||
|
|
||||||
@@ -932,28 +949,28 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock_bh(&ipt_acc_lock);
|
spin_lock_bh(&ian->ipt_acc_lock);
|
||||||
if (cmd == IPT_SO_GET_ACCOUNT_PREPARE_READ_FLUSH)
|
if (cmd == IPT_SO_GET_ACCOUNT_PREPARE_READ_FLUSH)
|
||||||
ret = ipt_acc_handle_prepare_read_flush(
|
ret = ipt_acc_handle_prepare_read_flush(
|
||||||
handle.name, &dest, &handle.itemcount);
|
ian->ipt_acc_tables, handle.name, &dest, &handle.itemcount);
|
||||||
else
|
else
|
||||||
ret = ipt_acc_handle_prepare_read(
|
ret = ipt_acc_handle_prepare_read(
|
||||||
handle.name, &dest, &handle.itemcount);
|
ian->ipt_acc_tables, handle.name, &dest, &handle.itemcount);
|
||||||
spin_unlock_bh(&ipt_acc_lock);
|
spin_unlock_bh(&ian->ipt_acc_lock);
|
||||||
// Error occured during prepare_read?
|
// Error occured during prepare_read?
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
/* Allocate a userspace handle */
|
/* Allocate a userspace handle */
|
||||||
down(&ipt_acc_userspace_mutex);
|
down(&ian->ipt_acc_userspace_mutex);
|
||||||
if ((handle.handle_nr = ipt_acc_handle_find_slot()) == -1) {
|
if ((handle.handle_nr = ipt_acc_handle_find_slot(ian->ipt_acc_handles)) == -1) {
|
||||||
ipt_acc_data_free(dest.data, dest.depth);
|
ipt_acc_data_free(dest.data, dest.depth);
|
||||||
up(&ipt_acc_userspace_mutex);
|
up(&ian->ipt_acc_userspace_mutex);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
memcpy(&ipt_acc_handles[handle.handle_nr], &dest,
|
memcpy(&ian->ipt_acc_handles[handle.handle_nr], &dest,
|
||||||
sizeof(struct ipt_acc_handle));
|
sizeof(struct ipt_acc_handle));
|
||||||
up(&ipt_acc_userspace_mutex);
|
up(&ian->ipt_acc_userspace_mutex);
|
||||||
|
|
||||||
if (copy_to_user(user, &handle,
|
if (copy_to_user(user, &handle,
|
||||||
sizeof(struct ipt_acc_handle_sockopt))) {
|
sizeof(struct ipt_acc_handle_sockopt))) {
|
||||||
@@ -982,19 +999,19 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*len < ipt_acc_handles[handle.handle_nr].itemcount
|
if (*len < ian->ipt_acc_handles[handle.handle_nr].itemcount
|
||||||
* sizeof(struct ipt_acc_handle_ip)) {
|
* sizeof(struct ipt_acc_handle_ip)) {
|
||||||
printk("ACCOUNT: ipt_acc_get_ctl: not enough space (%u < %zu)"
|
printk("ACCOUNT: ipt_acc_get_ctl: not enough space (%u < %zu)"
|
||||||
" to store data from IPT_SO_GET_ACCOUNT_GET_DATA\n",
|
" to store data from IPT_SO_GET_ACCOUNT_GET_DATA\n",
|
||||||
*len, ipt_acc_handles[handle.handle_nr].itemcount
|
*len, ian->ipt_acc_handles[handle.handle_nr].itemcount
|
||||||
* sizeof(struct ipt_acc_handle_ip));
|
* sizeof(struct ipt_acc_handle_ip));
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
down(&ipt_acc_userspace_mutex);
|
down(&ian->ipt_acc_userspace_mutex);
|
||||||
ret = ipt_acc_handle_get_data(handle.handle_nr, user);
|
ret = ipt_acc_handle_get_data(ian, handle.handle_nr, user);
|
||||||
up(&ipt_acc_userspace_mutex);
|
up(&ian->ipt_acc_userspace_mutex);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printk("ACCOUNT: ipt_acc_get_ctl: ipt_acc_handle_get_data"
|
printk("ACCOUNT: ipt_acc_get_ctl: ipt_acc_handle_get_data"
|
||||||
" failed for handle %u\n", handle.handle_nr);
|
" failed for handle %u\n", handle.handle_nr);
|
||||||
@@ -1014,11 +1031,11 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len)
|
|||||||
|
|
||||||
/* Find out how many handles are in use */
|
/* Find out how many handles are in use */
|
||||||
handle.itemcount = 0;
|
handle.itemcount = 0;
|
||||||
down(&ipt_acc_userspace_mutex);
|
down(&ian->ipt_acc_userspace_mutex);
|
||||||
for (i = 0; i < ACCOUNT_MAX_HANDLES; i++)
|
for (i = 0; i < ACCOUNT_MAX_HANDLES; i++)
|
||||||
if (ipt_acc_handles[i].data)
|
if (ian->ipt_acc_handles[i].data)
|
||||||
handle.itemcount++;
|
handle.itemcount++;
|
||||||
up(&ipt_acc_userspace_mutex);
|
up(&ian->ipt_acc_userspace_mutex);
|
||||||
|
|
||||||
if (copy_to_user(user, &handle,
|
if (copy_to_user(user, &handle,
|
||||||
sizeof(struct ipt_acc_handle_sockopt))) {
|
sizeof(struct ipt_acc_handle_sockopt))) {
|
||||||
@@ -1032,38 +1049,38 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len)
|
|||||||
uint32_t size = 0, i, name_len;
|
uint32_t size = 0, i, name_len;
|
||||||
char *tnames;
|
char *tnames;
|
||||||
|
|
||||||
spin_lock_bh(&ipt_acc_lock);
|
spin_lock_bh(&ian->ipt_acc_lock);
|
||||||
|
|
||||||
/* Determine size of table names */
|
/* Determine size of table names */
|
||||||
for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
|
for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
|
||||||
if (ipt_acc_tables[i].name[0] != 0)
|
if (ian->ipt_acc_tables[i].name[0] != 0)
|
||||||
size += strlen(ipt_acc_tables[i].name) + 1;
|
size += strlen(ian->ipt_acc_tables[i].name) + 1;
|
||||||
}
|
}
|
||||||
size += 1; /* Terminating NULL character */
|
size += 1; /* Terminating NULL character */
|
||||||
|
|
||||||
if (*len < size || size > PAGE_SIZE) {
|
if (*len < size || size > PAGE_SIZE) {
|
||||||
spin_unlock_bh(&ipt_acc_lock);
|
spin_unlock_bh(&ian->ipt_acc_lock);
|
||||||
printk("ACCOUNT: ipt_acc_get_ctl: not enough space (%u < %u < %lu)"
|
printk("ACCOUNT: ipt_acc_get_ctl: not enough space (%u < %u < %lu)"
|
||||||
" to store table names\n", *len, size, PAGE_SIZE);
|
" to store table names\n", *len, size, PAGE_SIZE);
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Copy table names to userspace */
|
/* Copy table names to userspace */
|
||||||
tnames = ipt_acc_tmpbuf;
|
tnames = ian->ipt_acc_tmpbuf;
|
||||||
for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
|
for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
|
||||||
if (ipt_acc_tables[i].name[0] != 0) {
|
if (ian->ipt_acc_tables[i].name[0] != 0) {
|
||||||
name_len = strlen(ipt_acc_tables[i].name) + 1;
|
name_len = strlen(ian->ipt_acc_tables[i].name) + 1;
|
||||||
memcpy(tnames, ipt_acc_tables[i].name, name_len);
|
memcpy(tnames, ian->ipt_acc_tables[i].name, name_len);
|
||||||
tnames += name_len;
|
tnames += name_len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
spin_unlock_bh(&ipt_acc_lock);
|
spin_unlock_bh(&ian->ipt_acc_lock);
|
||||||
|
|
||||||
/* Terminating NULL character */
|
/* Terminating NULL character */
|
||||||
*tnames = 0;
|
*tnames = 0;
|
||||||
|
|
||||||
/* Transfer to userspace */
|
/* Transfer to userspace */
|
||||||
if (copy_to_user(user, ipt_acc_tmpbuf, size))
|
if (copy_to_user(user, ian->ipt_acc_tmpbuf, size))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@@ -1076,6 +1093,59 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int __net_init ipt_acc_net_init(struct net *net)
|
||||||
|
{
|
||||||
|
struct ipt_acc_net *ian = net_generic(net, ipt_acc_net_id);
|
||||||
|
|
||||||
|
memset(ian, 0, sizeof(*ian));
|
||||||
|
sema_init(&ian->ipt_acc_userspace_mutex, 1);
|
||||||
|
|
||||||
|
ian->ipt_acc_tables = kcalloc(ACCOUNT_MAX_TABLES,
|
||||||
|
sizeof(struct ipt_acc_table), GFP_KERNEL);
|
||||||
|
if (ian->ipt_acc_tables == NULL) {
|
||||||
|
printk("ACCOUNT: Out of memory allocating account_tables structure");
|
||||||
|
goto error_cleanup;
|
||||||
|
}
|
||||||
|
ian->ipt_acc_handles = kcalloc(ACCOUNT_MAX_HANDLES,
|
||||||
|
sizeof(struct ipt_acc_handle), GFP_KERNEL);
|
||||||
|
if (ian->ipt_acc_handles == NULL) {
|
||||||
|
printk("ACCOUNT: Out of memory allocating account_handles structure");
|
||||||
|
goto error_cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Allocate one page as temporary storage */
|
||||||
|
ian->ipt_acc_tmpbuf = (void *)__get_free_pages(GFP_KERNEL, 2);
|
||||||
|
if (ian->ipt_acc_tmpbuf == NULL) {
|
||||||
|
printk("ACCOUNT: Out of memory for temporary buffer page\n");
|
||||||
|
goto error_cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
error_cleanup:
|
||||||
|
kfree(ian->ipt_acc_tables);
|
||||||
|
kfree(ian->ipt_acc_handles);
|
||||||
|
free_pages((unsigned long)ian->ipt_acc_tmpbuf, 2);
|
||||||
|
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __net_exit ipt_acc_net_exit(struct net *net)
|
||||||
|
{
|
||||||
|
struct ipt_acc_net *ian = net_generic(net, ipt_acc_net_id);
|
||||||
|
|
||||||
|
kfree(ian->ipt_acc_tables);
|
||||||
|
kfree(ian->ipt_acc_handles);
|
||||||
|
free_pages((unsigned long)ian->ipt_acc_tmpbuf, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct pernet_operations ipt_acc_net_ops = {
|
||||||
|
.init = ipt_acc_net_init,
|
||||||
|
.exit = ipt_acc_net_exit,
|
||||||
|
.id = &ipt_acc_net_id,
|
||||||
|
.size = sizeof(struct ipt_acc_net),
|
||||||
|
};
|
||||||
|
|
||||||
static struct xt_target xt_acc_reg __read_mostly = {
|
static struct xt_target xt_acc_reg __read_mostly = {
|
||||||
.name = "ACCOUNT",
|
.name = "ACCOUNT",
|
||||||
.revision = 1,
|
.revision = 1,
|
||||||
@@ -1099,63 +1169,41 @@ static struct nf_sockopt_ops ipt_acc_sockopts = {
|
|||||||
|
|
||||||
static int __init account_tg_init(void)
|
static int __init account_tg_init(void)
|
||||||
{
|
{
|
||||||
sema_init(&ipt_acc_userspace_mutex, 1);
|
int ret;
|
||||||
|
|
||||||
if ((ipt_acc_tables =
|
ret = register_pernet_subsys(&ipt_acc_net_ops);
|
||||||
kmalloc(ACCOUNT_MAX_TABLES *
|
if (ret < 0) {
|
||||||
sizeof(struct ipt_acc_table), GFP_KERNEL)) == NULL) {
|
pr_err("ACCOUNT: cannot register per net operations.\n");
|
||||||
printk("ACCOUNT: Out of memory allocating account_tables structure");
|
goto error_out;
|
||||||
goto error_cleanup;
|
|
||||||
}
|
|
||||||
memset(ipt_acc_tables, 0,
|
|
||||||
ACCOUNT_MAX_TABLES * sizeof(struct ipt_acc_table));
|
|
||||||
|
|
||||||
if ((ipt_acc_handles =
|
|
||||||
kmalloc(ACCOUNT_MAX_HANDLES *
|
|
||||||
sizeof(struct ipt_acc_handle), GFP_KERNEL)) == NULL) {
|
|
||||||
printk("ACCOUNT: Out of memory allocating account_handles structure");
|
|
||||||
goto error_cleanup;
|
|
||||||
}
|
|
||||||
memset(ipt_acc_handles, 0,
|
|
||||||
ACCOUNT_MAX_HANDLES * sizeof(struct ipt_acc_handle));
|
|
||||||
|
|
||||||
/* Allocate one page as temporary storage */
|
|
||||||
if ((ipt_acc_tmpbuf = (void*)__get_free_page(GFP_KERNEL)) == NULL) {
|
|
||||||
printk("ACCOUNT: Out of memory for temporary buffer page\n");
|
|
||||||
goto error_cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register setsockopt */
|
/* Register setsockopt */
|
||||||
if (nf_register_sockopt(&ipt_acc_sockopts) < 0) {
|
ret = nf_register_sockopt(&ipt_acc_sockopts);
|
||||||
printk("ACCOUNT: Can't register sockopts. Aborting\n");
|
if (ret < 0) {
|
||||||
goto error_cleanup;
|
pr_err("ACCOUNT: cannot register sockopts.\n");
|
||||||
|
goto unreg_pernet;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xt_register_target(&xt_acc_reg))
|
ret = xt_register_target(&xt_acc_reg);
|
||||||
goto error_cleanup;
|
if (ret < 0) {
|
||||||
|
pr_err("ACCOUNT: cannot register sockopts.\n");
|
||||||
|
goto unreg_sockopt;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_cleanup:
|
unreg_sockopt:
|
||||||
if (ipt_acc_tables)
|
nf_unregister_sockopt(&ipt_acc_sockopts);
|
||||||
kfree(ipt_acc_tables);
|
unreg_pernet:
|
||||||
if (ipt_acc_handles)
|
unregister_pernet_subsys(&ipt_acc_net_ops);
|
||||||
kfree(ipt_acc_handles);
|
error_out:
|
||||||
if (ipt_acc_tmpbuf)
|
return ret;
|
||||||
free_page((unsigned long)ipt_acc_tmpbuf);
|
|
||||||
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit account_tg_exit(void)
|
static void __exit account_tg_exit(void)
|
||||||
{
|
{
|
||||||
xt_unregister_target(&xt_acc_reg);
|
xt_unregister_target(&xt_acc_reg);
|
||||||
|
|
||||||
nf_unregister_sockopt(&ipt_acc_sockopts);
|
nf_unregister_sockopt(&ipt_acc_sockopts);
|
||||||
|
unregister_pernet_subsys(&ipt_acc_net_ops);
|
||||||
kfree(ipt_acc_tables);
|
|
||||||
kfree(ipt_acc_handles);
|
|
||||||
free_page((unsigned long)ipt_acc_tmpbuf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(account_tg_init);
|
module_init(account_tg_init);
|
||||||
|
@@ -59,11 +59,11 @@ struct ipt_acc_handle_sockopt {
|
|||||||
Used for every IP when returning data
|
Used for every IP when returning data
|
||||||
*/
|
*/
|
||||||
struct ipt_acc_handle_ip {
|
struct ipt_acc_handle_ip {
|
||||||
__be32 ip;
|
__be32 ip, __dummy;
|
||||||
uint32_t src_packets;
|
uint64_t src_packets;
|
||||||
uint32_t src_bytes;
|
uint64_t src_bytes;
|
||||||
uint32_t dst_packets;
|
uint64_t dst_packets;
|
||||||
uint32_t dst_bytes;
|
uint64_t dst_bytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _IPT_ACCOUNT_H */
|
#endif /* _IPT_ACCOUNT_H */
|
||||||
|
@@ -10,9 +10,7 @@ obj-${build_CHAOS} += xt_CHAOS.o
|
|||||||
obj-${build_DELUDE} += xt_DELUDE.o
|
obj-${build_DELUDE} += xt_DELUDE.o
|
||||||
obj-${build_DHCPMAC} += xt_DHCPMAC.o
|
obj-${build_DHCPMAC} += xt_DHCPMAC.o
|
||||||
obj-${build_DNETMAP} += xt_DNETMAP.o
|
obj-${build_DNETMAP} += xt_DNETMAP.o
|
||||||
ifeq (${VERSION},3)
|
|
||||||
obj-${build_ECHO} += xt_ECHO.o
|
obj-${build_ECHO} += xt_ECHO.o
|
||||||
endif
|
|
||||||
obj-${build_IPMARK} += xt_IPMARK.o
|
obj-${build_IPMARK} += xt_IPMARK.o
|
||||||
obj-${build_LOGMARK} += xt_LOGMARK.o
|
obj-${build_LOGMARK} += xt_LOGMARK.o
|
||||||
obj-${build_SYSRQ} += xt_SYSRQ.o
|
obj-${build_SYSRQ} += xt_SYSRQ.o
|
||||||
|
@@ -8,12 +8,8 @@
|
|||||||
|
|
||||||
#define DEBUGP Use__pr_debug__instead
|
#define DEBUGP Use__pr_debug__instead
|
||||||
|
|
||||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0)
|
||||||
# warning Kernels below 3.7 not supported.
|
# warning Kernels below 4.15 not supported.
|
||||||
#endif
|
|
||||||
|
|
||||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0)
|
|
||||||
# define prandom_u32() random32()
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
|
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
|
||||||
@@ -35,7 +31,7 @@
|
|||||||
ntohs((addr).s6_addr16[5]), \
|
ntohs((addr).s6_addr16[5]), \
|
||||||
ntohs((addr).s6_addr16[6]), \
|
ntohs((addr).s6_addr16[6]), \
|
||||||
ntohs((addr).s6_addr16[7])
|
ntohs((addr).s6_addr16[7])
|
||||||
# define NIP6_FMT "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x"
|
# define NIP6_FMT "%04hx:%04hx:%04hx:%04hx:%04hx:%04hx:%04hx:%04hx"
|
||||||
#endif
|
#endif
|
||||||
#if !defined(NIPQUAD) && !defined(NIPQUAD_FMT)
|
#if !defined(NIPQUAD) && !defined(NIPQUAD_FMT)
|
||||||
# define NIPQUAD(addr) \
|
# define NIPQUAD(addr) \
|
||||||
@@ -43,34 +39,16 @@
|
|||||||
((const unsigned char *)&addr)[1], \
|
((const unsigned char *)&addr)[1], \
|
||||||
((const unsigned char *)&addr)[2], \
|
((const unsigned char *)&addr)[2], \
|
||||||
((const unsigned char *)&addr)[3]
|
((const unsigned char *)&addr)[3]
|
||||||
# define NIPQUAD_FMT "%u.%u.%u.%u"
|
# define NIPQUAD_FMT "%hhu.%hhu.%hhu.%hhu"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
|
static inline struct net *par_net(const struct xt_action_param *par)
|
||||||
static inline struct inode *file_inode(struct file *f)
|
|
||||||
{
|
{
|
||||||
return f->f_path.dentry->d_inode;
|
return par->state->net;
|
||||||
}
|
|
||||||
#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)
|
#ifndef NF_CT_ASSERT
|
||||||
{
|
# define NF_CT_ASSERT(x) WARN_ON(!(x))
|
||||||
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
|
#endif
|
||||||
|
|
||||||
#endif /* _XTABLES_COMPAT_H */
|
#endif /* _XTABLES_COMPAT_H */
|
||||||
|
@@ -49,6 +49,38 @@ static struct option geoip_opts[] = {
|
|||||||
{NULL},
|
{NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#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)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
geoip_get_subnets(const char *code, uint32_t *count, uint8_t nfproto)
|
geoip_get_subnets(const char *code, uint32_t *count, uint8_t nfproto)
|
||||||
{
|
{
|
||||||
@@ -56,21 +88,15 @@ geoip_get_subnets(const char *code, uint32_t *count, uint8_t nfproto)
|
|||||||
struct stat sb;
|
struct stat sb;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int fd;
|
int fd;
|
||||||
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||||
|
unsigned int n;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Use simple integer vector files */
|
/* Use simple integer vector files */
|
||||||
if (nfproto == NFPROTO_IPV6) {
|
if (nfproto == NFPROTO_IPV6)
|
||||||
#if __BYTE_ORDER == _BIG_ENDIAN
|
snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/%s.iv6", code);
|
||||||
snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/BE/%s.iv6", code);
|
else
|
||||||
#else
|
snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/%s.iv4", code);
|
||||||
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 ((fd = open(buf, O_RDONLY)) < 0) {
|
if ((fd = open(buf, O_RDONLY)) < 0) {
|
||||||
fprintf(stderr, "Could not open %s: %s\n", buf, strerror(errno));
|
fprintf(stderr, "Could not open %s: %s\n", buf, strerror(errno));
|
||||||
@@ -98,6 +124,25 @@ geoip_get_subnets(const char *code, uint32_t *count, uint8_t nfproto)
|
|||||||
xtables_error(OTHER_PROBLEM, "geoip: insufficient memory");
|
xtables_error(OTHER_PROBLEM, "geoip: insufficient memory");
|
||||||
read(fd, subnets, sb.st_size);
|
read(fd, subnets, sb.st_size);
|
||||||
close(fd);
|
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;
|
return subnets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
extensions/pknock/gen_hmac.py
Normal file
17
extensions/pknock/gen_hmac.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from Crypto.Hash import SHA256
|
||||||
|
from Crypto.Hash import MD5
|
||||||
|
import sys
|
||||||
|
import hmac
|
||||||
|
import struct
|
||||||
|
import socket
|
||||||
|
from time import time
|
||||||
|
|
||||||
|
def gen_hmac(secret, ip):
|
||||||
|
epoch_mins = (long)(time()/60)
|
||||||
|
s = hmac.HMAC(secret, digestmod = SHA256)
|
||||||
|
s.update(socket.inet_aton(socket.gethostbyname(ip)))
|
||||||
|
s.update(struct.pack("i", epoch_mins)) # "i" is for integer
|
||||||
|
print s.hexdigest()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
gen_hmac(sys.argv[1], sys.argv[2])
|
6
extensions/pknock/knock.sh
Executable file
6
extensions/pknock/knock.sh
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
if [ "$#" -ne 4 ]; then
|
||||||
|
echo "usage: $0 <IP src> <IP dst> <PORT dst> <secret>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
python gen_hmac.py "$4" "$1" | socat - "udp-sendto:$2:$3,bind=$1"
|
@@ -62,8 +62,6 @@ Specifying \fB--autoclose 0\fP means that no automatic close will be performed a
|
|||||||
xt_pknock is capable of sending information about successful matches
|
xt_pknock is capable of sending information about successful matches
|
||||||
via a netlink socket to userspace, should you need to implement your own
|
via a netlink socket to userspace, should you need to implement your own
|
||||||
way of receiving and handling portknock notifications.
|
way of receiving and handling portknock notifications.
|
||||||
Be sure to read the documentation in the doc/pknock/ directory,
|
|
||||||
or visit the original site \(em http://portknocko.berlios.de/ .
|
|
||||||
.PP
|
.PP
|
||||||
\fBTCP mode\fP:
|
\fBTCP mode\fP:
|
||||||
.PP
|
.PP
|
||||||
|
@@ -19,16 +19,14 @@
|
|||||||
#include <linux/spinlock.h>
|
#include <linux/spinlock.h>
|
||||||
#include <linux/jhash.h>
|
#include <linux/jhash.h>
|
||||||
#include <linux/random.h>
|
#include <linux/random.h>
|
||||||
#include <linux/crypto.h>
|
|
||||||
#include <linux/proc_fs.h>
|
#include <linux/proc_fs.h>
|
||||||
#include <linux/scatterlist.h>
|
|
||||||
#include <linux/spinlock.h>
|
#include <linux/spinlock.h>
|
||||||
#include <linux/jiffies.h>
|
#include <linux/jiffies.h>
|
||||||
#include <linux/timer.h>
|
#include <linux/timer.h>
|
||||||
#include <linux/seq_file.h>
|
#include <linux/seq_file.h>
|
||||||
#include <linux/connector.h>
|
#include <linux/connector.h>
|
||||||
|
|
||||||
#include <linux/netfilter/x_tables.h>
|
#include <linux/netfilter/x_tables.h>
|
||||||
|
#include <crypto/hash.h>
|
||||||
#include "xt_pknock.h"
|
#include "xt_pknock.h"
|
||||||
#include "compat_xtables.h"
|
#include "compat_xtables.h"
|
||||||
|
|
||||||
@@ -111,9 +109,9 @@ static DEFINE_SPINLOCK(list_lock);
|
|||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
const char *algo;
|
const char *algo;
|
||||||
struct crypto_hash *tfm;
|
struct crypto_shash *tfm;
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
struct hash_desc desc;
|
struct shash_desc desc;
|
||||||
} crypto = {
|
} crypto = {
|
||||||
.algo = "hmac(sha256)",
|
.algo = "hmac(sha256)",
|
||||||
.tfm = NULL,
|
.tfm = NULL,
|
||||||
@@ -359,11 +357,10 @@ has_logged_during_this_minute(const struct peer *peer)
|
|||||||
*
|
*
|
||||||
* @r: rule
|
* @r: rule
|
||||||
*/
|
*/
|
||||||
static void
|
static void peer_gc(struct timer_list *tl)
|
||||||
peer_gc(unsigned long r)
|
|
||||||
{
|
{
|
||||||
unsigned int i;
|
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 peer *peer;
|
||||||
struct list_head *pos, *n;
|
struct list_head *pos, *n;
|
||||||
|
|
||||||
@@ -470,11 +467,7 @@ add_rule(struct xt_pknock_mtinfo *info)
|
|||||||
rule->peer_head = alloc_hashtable(peer_hashsize);
|
rule->peer_head = alloc_hashtable(peer_hashsize);
|
||||||
if (rule->peer_head == NULL)
|
if (rule->peer_head == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
timer_setup(&rule->timer, peer_gc, 0);
|
||||||
init_timer(&rule->timer);
|
|
||||||
rule->timer.function = peer_gc;
|
|
||||||
rule->timer.data = (unsigned long)rule;
|
|
||||||
|
|
||||||
rule->status_proc = proc_create_data(info->rule_name, 0, pde,
|
rule->status_proc = proc_create_data(info->rule_name, 0, pde,
|
||||||
&pknock_proc_ops, rule);
|
&pknock_proc_ops, rule);
|
||||||
if (rule->status_proc == NULL)
|
if (rule->status_proc == NULL)
|
||||||
@@ -621,9 +614,10 @@ static void add_peer(struct peer *peer, struct xt_pknock_rule *rule)
|
|||||||
*/
|
*/
|
||||||
static void remove_peer(struct peer *peer)
|
static void remove_peer(struct peer *peer)
|
||||||
{
|
{
|
||||||
|
if (peer == NULL)
|
||||||
|
return;
|
||||||
list_del(&peer->head);
|
list_del(&peer->head);
|
||||||
if (peer != NULL)
|
kfree(peer);
|
||||||
kfree(peer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -700,13 +694,7 @@ msg_to_userspace_nl(const struct xt_pknock_mtinfo *info,
|
|||||||
scnprintf(msg.rule_name, info->rule_name_len + 1, info->rule_name);
|
scnprintf(msg.rule_name, info->rule_name_len + 1, info->rule_name);
|
||||||
|
|
||||||
memcpy(m + 1, &msg, m->len);
|
memcpy(m + 1, &msg, m->len);
|
||||||
|
|
||||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 15, 0)
|
|
||||||
cn_netlink_send(m, 0, multicast_group, GFP_ATOMIC);
|
cn_netlink_send(m, 0, multicast_group, GFP_ATOMIC);
|
||||||
#else
|
|
||||||
cn_netlink_send(m, multicast_group, GFP_ATOMIC);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
kfree(m);
|
kfree(m);
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
@@ -744,7 +732,6 @@ static bool
|
|||||||
has_secret(const unsigned char *secret, unsigned int secret_len, uint32_t ipsrc,
|
has_secret(const unsigned char *secret, unsigned int secret_len, uint32_t ipsrc,
|
||||||
const unsigned char *payload, unsigned int payload_len)
|
const unsigned char *payload, unsigned int payload_len)
|
||||||
{
|
{
|
||||||
struct scatterlist sg[2];
|
|
||||||
char result[64]; // 64 bytes * 8 = 512 bits
|
char result[64]; // 64 bytes * 8 = 512 bits
|
||||||
char *hexresult;
|
char *hexresult;
|
||||||
unsigned int hexa_size;
|
unsigned int hexa_size;
|
||||||
@@ -775,11 +762,7 @@ has_secret(const unsigned char *secret, unsigned int secret_len, uint32_t ipsrc,
|
|||||||
|
|
||||||
epoch_min = get_seconds() / 60;
|
epoch_min = get_seconds() / 60;
|
||||||
|
|
||||||
sg_init_table(sg, ARRAY_SIZE(sg));
|
ret = crypto_shash_setkey(crypto.tfm, secret, secret_len);
|
||||||
sg_set_buf(&sg[0], &ipsrc, sizeof(ipsrc));
|
|
||||||
sg_set_buf(&sg[1], &epoch_min, sizeof(epoch_min));
|
|
||||||
|
|
||||||
ret = crypto_hash_setkey(crypto.tfm, secret, secret_len);
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
printk("crypto_hash_setkey() failed ret=%d\n", ret);
|
printk("crypto_hash_setkey() failed ret=%d\n", ret);
|
||||||
goto out;
|
goto out;
|
||||||
@@ -790,10 +773,10 @@ has_secret(const unsigned char *secret, unsigned int secret_len, uint32_t ipsrc,
|
|||||||
* 4 bytes IP (32 bits) +
|
* 4 bytes IP (32 bits) +
|
||||||
* 4 bytes int epoch_min (32 bits)
|
* 4 bytes int epoch_min (32 bits)
|
||||||
*/
|
*/
|
||||||
ret = crypto_hash_digest(&crypto.desc, sg,
|
if ((ret = crypto_shash_update(&crypto.desc, (const void *)&ipsrc, sizeof(ipsrc))) != 0 ||
|
||||||
sizeof(ipsrc) + sizeof(epoch_min), result);
|
(ret = crypto_shash_update(&crypto.desc, (const void *)&epoch_min, sizeof(epoch_min))) != 0 ||
|
||||||
if (ret != 0) {
|
(ret = crypto_shash_final(&crypto.desc, result)) != 0) {
|
||||||
printk("crypto_hash_digest() failed ret=%d\n", ret);
|
printk("crypto_shash_update/final() failed ret=%d\n", ret);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1133,14 +1116,14 @@ static int __init xt_pknock_mt_init(void)
|
|||||||
return -ENXIO;
|
return -ENXIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
crypto.tfm = crypto_alloc_hash(crypto.algo, 0, CRYPTO_ALG_ASYNC);
|
crypto.tfm = crypto_alloc_shash(crypto.algo, 0, 0);
|
||||||
if (IS_ERR(crypto.tfm)) {
|
if (IS_ERR(crypto.tfm)) {
|
||||||
printk(KERN_ERR PKNOCK "failed to load transform for %s\n",
|
printk(KERN_ERR PKNOCK "failed to load transform for %s\n",
|
||||||
crypto.algo);
|
crypto.algo);
|
||||||
return PTR_ERR(crypto.tfm);
|
return PTR_ERR(crypto.tfm);
|
||||||
}
|
}
|
||||||
|
|
||||||
crypto.size = crypto_hash_digestsize(crypto.tfm);
|
crypto.size = crypto_shash_digestsize(crypto.tfm);
|
||||||
crypto.desc.tfm = crypto.tfm;
|
crypto.desc.tfm = crypto.tfm;
|
||||||
crypto.desc.flags = 0;
|
crypto.desc.flags = 0;
|
||||||
|
|
||||||
@@ -1158,7 +1141,7 @@ static void __exit xt_pknock_mt_exit(void)
|
|||||||
xt_unregister_match(&xt_pknock_mt_reg);
|
xt_unregister_match(&xt_pknock_mt_reg);
|
||||||
kfree(rule_hashtable);
|
kfree(rule_hashtable);
|
||||||
if (crypto.tfm != NULL)
|
if (crypto.tfm != NULL)
|
||||||
crypto_free_hash(crypto.tfm);
|
crypto_free_shash(crypto.tfm);
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(xt_pknock_mt_init);
|
module_init(xt_pknock_mt_init);
|
||||||
|
@@ -58,8 +58,7 @@ xt_chaos_total(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
|
|
||||||
{
|
{
|
||||||
struct xt_action_param local_par;
|
struct xt_action_param local_par;
|
||||||
local_par.in = par->in,
|
local_par.state = par->state;
|
||||||
local_par.out = par->out,
|
|
||||||
local_par.match = xm_tcp;
|
local_par.match = xm_tcp;
|
||||||
local_par.matchinfo = &tcp_params;
|
local_par.matchinfo = &tcp_params;
|
||||||
local_par.fragoff = fragoff;
|
local_par.fragoff = fragoff;
|
||||||
@@ -74,12 +73,9 @@ xt_chaos_total(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
destiny = (info->variant == XTCHAOS_TARPIT) ? xt_tarpit : xt_delude;
|
destiny = (info->variant == XTCHAOS_TARPIT) ? xt_tarpit : xt_delude;
|
||||||
{
|
{
|
||||||
struct xt_action_param local_par;
|
struct xt_action_param local_par;
|
||||||
local_par.in = par->in;
|
local_par.state = par->state;
|
||||||
local_par.out = par->out;
|
|
||||||
local_par.hooknum = par->hooknum;
|
|
||||||
local_par.target = destiny;
|
local_par.target = destiny;
|
||||||
local_par.targinfo = par->targinfo;
|
local_par.targinfo = par->targinfo;
|
||||||
local_par.family = par->family;
|
|
||||||
destiny->target(skb, &local_par);
|
destiny->target(skb, &local_par);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,18 +96,15 @@ chaos_tg(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
|
|
||||||
if ((unsigned int)prandom_u32() <= reject_percentage) {
|
if ((unsigned int)prandom_u32() <= reject_percentage) {
|
||||||
struct xt_action_param local_par;
|
struct xt_action_param local_par;
|
||||||
local_par.in = par->in;
|
local_par.state = par->state;
|
||||||
local_par.out = par->out;
|
|
||||||
local_par.hooknum = par->hooknum;
|
|
||||||
local_par.target = xt_reject;
|
local_par.target = xt_reject;
|
||||||
local_par.targinfo = &reject_params;
|
local_par.targinfo = &reject_params;
|
||||||
return xt_reject->target(skb, &local_par);
|
return xt_reject->target(skb, &local_par);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TARPIT/DELUDE may not be called from the OUTPUT chain */
|
/* TARPIT/DELUDE may not be called from the OUTPUT chain */
|
||||||
if (iph->protocol == IPPROTO_TCP &&
|
if (iph->protocol == IPPROTO_TCP && info->variant != XTCHAOS_NORMAL &&
|
||||||
info->variant != XTCHAOS_NORMAL &&
|
par->state->hook != NF_INET_LOCAL_OUT)
|
||||||
par->hooknum != NF_INET_LOCAL_OUT)
|
|
||||||
xt_chaos_total(skb, par);
|
xt_chaos_total(skb, par);
|
||||||
|
|
||||||
return NF_DROP;
|
return NF_DROP;
|
||||||
|
@@ -25,7 +25,8 @@
|
|||||||
#include "compat_xtables.h"
|
#include "compat_xtables.h"
|
||||||
#define PFX KBUILD_MODNAME ": "
|
#define PFX KBUILD_MODNAME ": "
|
||||||
|
|
||||||
static void delude_send_reset(struct sk_buff *oldskb, unsigned int hook)
|
static void delude_send_reset(struct net *net, struct sk_buff *oldskb,
|
||||||
|
unsigned int hook)
|
||||||
{
|
{
|
||||||
struct tcphdr _otcph, *tcph;
|
struct tcphdr _otcph, *tcph;
|
||||||
const struct tcphdr *oth;
|
const struct tcphdr *oth;
|
||||||
@@ -78,7 +79,7 @@ static void delude_send_reset(struct sk_buff *oldskb, unsigned int hook)
|
|||||||
tcph->doff = sizeof(struct tcphdr) / 4;
|
tcph->doff = sizeof(struct tcphdr) / 4;
|
||||||
|
|
||||||
/* DELUDE essential part */
|
/* DELUDE essential part */
|
||||||
if (oth->syn && !oth->ack && !oth->rst && !oth->fin) {
|
if (oth->syn && !oth->ack && !oth->fin) {
|
||||||
tcph->syn = true;
|
tcph->syn = true;
|
||||||
tcph->seq = 0;
|
tcph->seq = 0;
|
||||||
tcph->ack = true;
|
tcph->ack = true;
|
||||||
@@ -107,7 +108,7 @@ static void delude_send_reset(struct sk_buff *oldskb, unsigned int hook)
|
|||||||
addr_type = RTN_UNSPEC;
|
addr_type = RTN_UNSPEC;
|
||||||
#ifdef CONFIG_BRIDGE_NETFILTER
|
#ifdef CONFIG_BRIDGE_NETFILTER
|
||||||
if (hook != NF_INET_FORWARD || (nskb->nf_bridge != NULL &&
|
if (hook != NF_INET_FORWARD || (nskb->nf_bridge != NULL &&
|
||||||
nskb->nf_bridge->mask & BRNF_BRIDGED))
|
nskb->nf_bridge->physoutdev))
|
||||||
#else
|
#else
|
||||||
if (hook != NF_INET_FORWARD)
|
if (hook != NF_INET_FORWARD)
|
||||||
#endif
|
#endif
|
||||||
@@ -116,7 +117,7 @@ static void delude_send_reset(struct sk_buff *oldskb, unsigned int hook)
|
|||||||
/* ip_route_me_harder expects skb->dst to be set */
|
/* ip_route_me_harder expects skb->dst to be set */
|
||||||
skb_dst_set(nskb, dst_clone(skb_dst(oldskb)));
|
skb_dst_set(nskb, dst_clone(skb_dst(oldskb)));
|
||||||
|
|
||||||
if (ip_route_me_harder(nskb, addr_type))
|
if (ip_route_me_harder(net, nskb, addr_type))
|
||||||
goto free_nskb;
|
goto free_nskb;
|
||||||
else
|
else
|
||||||
niph = ip_hdr(nskb);
|
niph = ip_hdr(nskb);
|
||||||
@@ -130,7 +131,7 @@ static void delude_send_reset(struct sk_buff *oldskb, unsigned int hook)
|
|||||||
|
|
||||||
nf_ct_attach(nskb, oldskb);
|
nf_ct_attach(nskb, oldskb);
|
||||||
|
|
||||||
ip_local_out(nskb);
|
ip_local_out(net, nskb->sk, nskb);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
free_nskb:
|
free_nskb:
|
||||||
@@ -145,7 +146,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
|
* 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.
|
* actually want to have a connection open, we are still going to drop it.
|
||||||
*/
|
*/
|
||||||
delude_send_reset(skb, par->hooknum);
|
delude_send_reset(par_net(par), skb, par->state->hook);
|
||||||
return NF_DROP;
|
return NF_DROP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,9 +34,9 @@ static void ether_set(unsigned char *addr, const unsigned char *op,
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < ETH_ALEN && mask > 0; ++i) {
|
for (i = 0; i < ETH_ALEN && mask > 0; ++i) {
|
||||||
lo_mask = mask % 8;
|
lo_mask = (mask >= 8) ? 8 : mask;
|
||||||
/* FF << 4 >> 4 = 0F */
|
/* FF << 4 >> 4 = 0F */
|
||||||
lo_mask = ~(uint8_t)0U << lo_mask >> lo_mask;
|
lo_mask = (uint8_t)(~0U << lo_mask) >> lo_mask;
|
||||||
addr[i] &= lo_mask;
|
addr[i] &= lo_mask;
|
||||||
addr[i] |= op[i] & ~lo_mask;
|
addr[i] |= op[i] & ~lo_mask;
|
||||||
if (mask >= 8)
|
if (mask >= 8)
|
||||||
@@ -55,9 +55,9 @@ static bool ether_cmp(const unsigned char *lh, const unsigned char *rh,
|
|||||||
#define ZMACHEX(s) s[0], s[1], s[2], s[3], s[4], s[5]
|
#define ZMACHEX(s) s[0], s[1], s[2], s[3], s[4], s[5]
|
||||||
|
|
||||||
for (i = 0; i < ETH_ALEN && mask > 0; ++i) {
|
for (i = 0; i < ETH_ALEN && mask > 0; ++i) {
|
||||||
lo_mask = mask % 8;
|
lo_mask = (mask >= 8) ? 8 : mask;
|
||||||
/* ~(0xFF << 4 >> 4) = ~0x0F = 0xF0 */
|
/* ~(0xFF << 4 >> 4) = ~0x0F = 0xF0 */
|
||||||
lo_mask = ~(~(uint8_t)0U << lo_mask >> lo_mask);
|
lo_mask = ~((uint8_t)(~0U << lo_mask) >> lo_mask);
|
||||||
if ((lh[i] ^ rh[i]) & lo_mask)
|
if ((lh[i] ^ rh[i]) & lo_mask)
|
||||||
return false;
|
return false;
|
||||||
if (mask >= 8)
|
if (mask >= 8)
|
||||||
@@ -110,13 +110,12 @@ dhcpmac_tg(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
return NF_DROP;
|
return NF_DROP;
|
||||||
|
|
||||||
for (i = 0; i < sizeof(dh->chaddr); i += 2)
|
for (i = 0; i < sizeof(dh->chaddr); i += 2)
|
||||||
csum_replace2(&udph->check, *(const __be16 *)dh->chaddr, 0);
|
csum_replace2(&udph->check, *(const __be16 *)(dh->chaddr + i), 0);
|
||||||
|
|
||||||
memset(dh->chaddr, 0, sizeof(dh->chaddr));
|
|
||||||
ether_set(dh->chaddr, info->addr, info->mask);
|
ether_set(dh->chaddr, info->addr, info->mask);
|
||||||
|
|
||||||
for (i = 0; i < sizeof(dh->chaddr); i += 2)
|
for (i = 0; i < sizeof(dh->chaddr); i += 2)
|
||||||
csum_replace2(&udph->check, 0, *(const __be16 *)dh->chaddr);
|
csum_replace2(&udph->check, 0, *(const __be16 *)(dh->chaddr + i));
|
||||||
|
|
||||||
return XT_CONTINUE;
|
return XT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include <linux/netfilter.h>
|
#include <linux/netfilter.h>
|
||||||
#include <linux/netfilter_ipv4.h>
|
#include <linux/netfilter_ipv4.h>
|
||||||
#include <linux/netfilter/x_tables.h>
|
#include <linux/netfilter/x_tables.h>
|
||||||
|
#include <linux/proc_fs.h>
|
||||||
#include <linux/seq_file.h>
|
#include <linux/seq_file.h>
|
||||||
#include <linux/uidgid.h>
|
#include <linux/uidgid.h>
|
||||||
#include <linux/version.h>
|
#include <linux/version.h>
|
||||||
@@ -80,7 +81,7 @@ struct dnetmap_entry {
|
|||||||
|
|
||||||
struct dnetmap_prefix {
|
struct dnetmap_prefix {
|
||||||
struct nf_nat_range prefix;
|
struct nf_nat_range prefix;
|
||||||
char prefix_str[16];
|
char prefix_str[20];
|
||||||
#ifdef CONFIG_PROC_FS
|
#ifdef CONFIG_PROC_FS
|
||||||
char proc_str_data[20];
|
char proc_str_data[20];
|
||||||
char proc_str_stat[25];
|
char proc_str_stat[25];
|
||||||
@@ -355,27 +356,28 @@ out:
|
|||||||
static unsigned int
|
static unsigned int
|
||||||
dnetmap_tg(struct sk_buff *skb, const struct xt_action_param *par)
|
dnetmap_tg(struct sk_buff *skb, const struct xt_action_param *par)
|
||||||
{
|
{
|
||||||
struct net *net = dev_net(par->in ? par->in : par->out);
|
struct net *net = dev_net(par->state->in ? par->state->in : par->state->out);
|
||||||
struct dnetmap_net *dnetmap_net = dnetmap_pernet(net);
|
struct dnetmap_net *dnetmap_net = dnetmap_pernet(net);
|
||||||
struct nf_conn *ct;
|
struct nf_conn *ct;
|
||||||
enum ip_conntrack_info ctinfo;
|
enum ip_conntrack_info ctinfo;
|
||||||
__be32 prenat_ip, postnat_ip, prenat_ip_prev;
|
__be32 prenat_ip, postnat_ip, prenat_ip_prev;
|
||||||
const struct xt_DNETMAP_tginfo *tginfo = par->targinfo;
|
const struct xt_DNETMAP_tginfo *tginfo = par->targinfo;
|
||||||
const struct nf_nat_range *mr = &tginfo->prefix;
|
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;
|
struct nf_nat_range newrange;
|
||||||
|
#endif
|
||||||
struct dnetmap_entry *e;
|
struct dnetmap_entry *e;
|
||||||
struct dnetmap_prefix *p;
|
struct dnetmap_prefix *p;
|
||||||
__s32 jttl;
|
__s32 jttl;
|
||||||
|
unsigned int hooknum = par->state->hook;
|
||||||
NF_CT_ASSERT(par->hooknum == NF_INET_POST_ROUTING ||
|
|
||||||
par->hooknum == NF_INET_LOCAL_OUT ||
|
|
||||||
par->hooknum == NF_INET_PRE_ROUTING);
|
|
||||||
ct = nf_ct_get(skb, &ctinfo);
|
ct = nf_ct_get(skb, &ctinfo);
|
||||||
|
|
||||||
jttl = tginfo->flags & XT_DNETMAP_TTL ? tginfo->ttl * HZ : jtimeout;
|
jttl = tginfo->flags & XT_DNETMAP_TTL ? tginfo->ttl * HZ : jtimeout;
|
||||||
|
|
||||||
/* in prerouting we try to map postnat-ip to prenat-ip */
|
/* in prerouting we try to map postnat-ip to prenat-ip */
|
||||||
if (par->hooknum == NF_INET_PRE_ROUTING) {
|
if (hooknum == NF_INET_PRE_ROUTING) {
|
||||||
postnat_ip = ip_hdr(skb)->daddr;
|
postnat_ip = ip_hdr(skb)->daddr;
|
||||||
|
|
||||||
spin_lock_bh(&dnetmap_lock);
|
spin_lock_bh(&dnetmap_lock);
|
||||||
@@ -388,7 +390,7 @@ dnetmap_tg(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
/* if prefix is specified, we check if
|
/* if prefix is specified, we check if
|
||||||
it matches lookedup entry */
|
it matches lookedup entry */
|
||||||
if (tginfo->flags & XT_DNETMAP_PREFIX)
|
if (tginfo->flags & XT_DNETMAP_PREFIX)
|
||||||
if (memcmp(mr, &e->prefix, sizeof(*mr)))
|
if (memcmp(mr, &e->prefix->prefix, sizeof(*mr)))
|
||||||
goto no_rev_map;
|
goto no_rev_map;
|
||||||
/* don't reset ttl if flag is set */
|
/* don't reset ttl if flag is set */
|
||||||
if (jttl >= 0 && (! (e->flags & XT_DNETMAP_STATIC) ) ) {
|
if (jttl >= 0 && (! (e->flags & XT_DNETMAP_STATIC) ) ) {
|
||||||
@@ -406,7 +408,7 @@ dnetmap_tg(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
newrange.min_proto = mr->min_proto;
|
newrange.min_proto = mr->min_proto;
|
||||||
newrange.max_proto = mr->max_proto;
|
newrange.max_proto = mr->max_proto;
|
||||||
return nf_nat_setup_info(ct, &newrange,
|
return nf_nat_setup_info(ct, &newrange,
|
||||||
HOOK2MANIP(par->hooknum));
|
HOOK2MANIP(hooknum));
|
||||||
}
|
}
|
||||||
|
|
||||||
prenat_ip = ip_hdr(skb)->saddr;
|
prenat_ip = ip_hdr(skb)->saddr;
|
||||||
@@ -494,8 +496,7 @@ bind_new_prefix:
|
|||||||
newrange.max_addr.ip = postnat_ip;
|
newrange.max_addr.ip = postnat_ip;
|
||||||
newrange.min_proto = mr->min_proto;
|
newrange.min_proto = mr->min_proto;
|
||||||
newrange.max_proto = mr->max_proto;
|
newrange.max_proto = mr->max_proto;
|
||||||
return nf_nat_setup_info(ct, &newrange, HOOK2MANIP(par->hooknum));
|
return nf_nat_setup_info(ct, &newrange, HOOK2MANIP(par->state->hook));
|
||||||
|
|
||||||
no_rev_map:
|
no_rev_map:
|
||||||
no_free_ip:
|
no_free_ip:
|
||||||
spin_unlock_bh(&dnetmap_lock);
|
spin_unlock_bh(&dnetmap_lock);
|
||||||
|
@@ -35,7 +35,7 @@ echo_tg6(struct sk_buff *oldskb, const struct xt_action_param *par)
|
|||||||
void *payload;
|
void *payload;
|
||||||
struct flowi6 fl;
|
struct flowi6 fl;
|
||||||
struct dst_entry *dst = NULL;
|
struct dst_entry *dst = NULL;
|
||||||
struct net *net = dev_net((par->in != NULL) ? par->in : par->out);
|
struct net *net = dev_net((par->state->in != NULL) ? par->state->in : par->state->out);
|
||||||
|
|
||||||
/* This allows us to do the copy operation in fewer lines of code. */
|
/* This allows us to do the copy operation in fewer lines of code. */
|
||||||
if (skb_linearize(oldskb) < 0)
|
if (skb_linearize(oldskb) < 0)
|
||||||
@@ -76,6 +76,7 @@ echo_tg6(struct sk_buff *oldskb, const struct xt_action_param *par)
|
|||||||
payload = skb_header_pointer(oldskb, par->thoff +
|
payload = skb_header_pointer(oldskb, par->thoff +
|
||||||
sizeof(*oldudp), data_len, NULL);
|
sizeof(*oldudp), data_len, NULL);
|
||||||
memcpy(skb_put(newskb, data_len), payload, data_len);
|
memcpy(skb_put(newskb, data_len), payload, data_len);
|
||||||
|
newip->payload_len = htons(newskb->len);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/*
|
/*
|
||||||
@@ -112,7 +113,7 @@ echo_tg6(struct sk_buff *oldskb, const struct xt_action_param *par)
|
|||||||
goto free_nskb;
|
goto free_nskb;
|
||||||
|
|
||||||
nf_ct_attach(newskb, oldskb);
|
nf_ct_attach(newskb, oldskb);
|
||||||
ip6_local_out(newskb);
|
ip6_local_out(par_net(par), newskb->sk, newskb);
|
||||||
return NF_DROP;
|
return NF_DROP;
|
||||||
|
|
||||||
free_nskb:
|
free_nskb:
|
||||||
@@ -156,8 +157,8 @@ echo_tg4(struct sk_buff *oldskb, const struct xt_action_param *par)
|
|||||||
newip->version = oldip->version;
|
newip->version = oldip->version;
|
||||||
newip->ihl = sizeof(*newip) / 4;
|
newip->ihl = sizeof(*newip) / 4;
|
||||||
newip->tos = oldip->tos;
|
newip->tos = oldip->tos;
|
||||||
newip->id = 0;
|
newip->id = oldip->id;
|
||||||
newip->frag_off = htons(IP_DF);
|
newip->frag_off = 0;
|
||||||
newip->protocol = oldip->protocol;
|
newip->protocol = oldip->protocol;
|
||||||
newip->check = 0;
|
newip->check = 0;
|
||||||
newip->saddr = oldip->daddr;
|
newip->saddr = oldip->daddr;
|
||||||
@@ -173,6 +174,7 @@ echo_tg4(struct sk_buff *oldskb, const struct xt_action_param *par)
|
|||||||
payload = skb_header_pointer(oldskb, par->thoff +
|
payload = skb_header_pointer(oldskb, par->thoff +
|
||||||
sizeof(*oldudp), data_len, NULL);
|
sizeof(*oldudp), data_len, NULL);
|
||||||
memcpy(skb_put(newskb, data_len), payload, data_len);
|
memcpy(skb_put(newskb, data_len), payload, data_len);
|
||||||
|
newip->tot_len = htons(newskb->len);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/*
|
/*
|
||||||
@@ -190,7 +192,7 @@ echo_tg4(struct sk_buff *oldskb, const struct xt_action_param *par)
|
|||||||
/* ip_route_me_harder expects the skb's dst to be set */
|
/* ip_route_me_harder expects the skb's dst to be set */
|
||||||
skb_dst_set(newskb, dst_clone(skb_dst(oldskb)));
|
skb_dst_set(newskb, dst_clone(skb_dst(oldskb)));
|
||||||
|
|
||||||
if (ip_route_me_harder(newskb, RTN_UNSPEC) != 0)
|
if (ip_route_me_harder(par_net(par), newskb, RTN_UNSPEC) != 0)
|
||||||
goto free_nskb;
|
goto free_nskb;
|
||||||
|
|
||||||
newip->ttl = ip4_dst_hoplimit(skb_dst(newskb));
|
newip->ttl = ip4_dst_hoplimit(skb_dst(newskb));
|
||||||
@@ -201,7 +203,7 @@ echo_tg4(struct sk_buff *oldskb, const struct xt_action_param *par)
|
|||||||
goto free_nskb;
|
goto free_nskb;
|
||||||
|
|
||||||
nf_ct_attach(newskb, oldskb);
|
nf_ct_attach(newskb, oldskb);
|
||||||
ip_local_out(newskb);
|
ip_local_out(par_net(par), newskb->sk, newskb);
|
||||||
return NF_DROP;
|
return NF_DROP;
|
||||||
|
|
||||||
free_nskb:
|
free_nskb:
|
||||||
|
@@ -52,14 +52,19 @@ static void logmark_ct(const struct nf_conn *ct, enum ip_conntrack_info ctinfo)
|
|||||||
printk("EXPECTED");
|
printk("EXPECTED");
|
||||||
prev = true;
|
prev = true;
|
||||||
}
|
}
|
||||||
if (ct->status & IPS_SEEN_REPLY)
|
if (ct->status & IPS_SEEN_REPLY) {
|
||||||
printk("%s""SEEN_REPLY", prev++ ? "," : "");
|
printk("%s""SEEN_REPLY", prev ? "," : "");
|
||||||
if (ct->status & IPS_ASSURED)
|
prev = true;
|
||||||
printk("%s""ASSURED", prev++ ? "," : "");
|
}
|
||||||
if (ct->status & IPS_CONFIRMED)
|
if (ct->status & IPS_ASSURED) {
|
||||||
printk("%s""CONFIRMED", prev++ ? "," : "");
|
printk("%s""ASSURED", prev ? "," : "");
|
||||||
printk(" lifetime=%lus",
|
prev = true;
|
||||||
(jiffies - ct->timeout.expires) / HZ);
|
}
|
||||||
|
if (ct->status & IPS_CONFIRMED) {
|
||||||
|
printk("%s""CONFIRMED", prev ? "," : "");
|
||||||
|
prev = true;
|
||||||
|
}
|
||||||
|
printk(" lifetime=%lus", nf_ct_expires(ct) / HZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int
|
static unsigned int
|
||||||
@@ -72,15 +77,13 @@ logmark_tg(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
printk("<%u>%.*s""iif=%d hook=%s nfmark=0x%x "
|
printk("<%u>%.*s""iif=%d hook=%s nfmark=0x%x "
|
||||||
"secmark=0x%x classify=0x%x",
|
"secmark=0x%x classify=0x%x",
|
||||||
info->level, (unsigned int)sizeof(info->prefix), info->prefix,
|
info->level, (unsigned int)sizeof(info->prefix), info->prefix,
|
||||||
skb_ifindex(skb), hook_names[par->hooknum],
|
skb_ifindex(skb), hook_names[par->state->hook],
|
||||||
skb_nfmark(skb), skb_secmark(skb), skb->priority);
|
skb_nfmark(skb), skb_secmark(skb), skb->priority);
|
||||||
|
|
||||||
ct = nf_ct_get(skb, &ctinfo);
|
ct = nf_ct_get(skb, &ctinfo);
|
||||||
printk(" ctdir=%s", dir_names[ctinfo >= IP_CT_IS_REPLY]);
|
printk(" ctdir=%s", dir_names[ctinfo >= IP_CT_IS_REPLY]);
|
||||||
if (ct == NULL)
|
if (ct == NULL)
|
||||||
printk(" ct=NULL ctmark=NULL ctstate=INVALID ctstatus=NONE");
|
printk(" ct=NULL ctmark=NULL ctstate=INVALID ctstatus=NONE");
|
||||||
else if (nf_ct_is_untracked(ct))
|
|
||||||
printk(" ct=UNTRACKED ctmark=NULL ctstate=UNTRACKED ctstatus=NONE");
|
|
||||||
else
|
else
|
||||||
logmark_ct(ct, ctinfo);
|
logmark_ct(ct, ctinfo);
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* "SYSRQ" target extension for Xtables
|
* "SYSRQ" target extension for Xtables
|
||||||
* Copyright © Jan Engelhardt, 2008 - 2012
|
* Copyright Jan Engelhardt, 2016
|
||||||
*
|
*
|
||||||
* Based upon the ipt_SYSRQ idea by Marek Zalem <marek [at] terminus sk>
|
* Based upon the ipt_SYSRQ idea by Marek Zalem <marek [at] terminus sk>
|
||||||
*
|
*
|
||||||
@@ -21,8 +21,7 @@
|
|||||||
#include <linux/netfilter_ipv4/ip_tables.h>
|
#include <linux/netfilter_ipv4/ip_tables.h>
|
||||||
#include <linux/netfilter_ipv6/ip6_tables.h>
|
#include <linux/netfilter_ipv6/ip6_tables.h>
|
||||||
#include <linux/netfilter/x_tables.h>
|
#include <linux/netfilter/x_tables.h>
|
||||||
#include <linux/crypto.h>
|
#include <crypto/hash.h>
|
||||||
#include <linux/scatterlist.h>
|
|
||||||
#include <net/ip.h>
|
#include <net/ip.h>
|
||||||
#include <net/ipv6.h>
|
#include <net/ipv6.h>
|
||||||
#include "compat_xtables.h"
|
#include "compat_xtables.h"
|
||||||
@@ -50,7 +49,7 @@ MODULE_PARM_DESC(seqno, "sequence number for remote sysrq");
|
|||||||
MODULE_PARM_DESC(debug, "debugging: 0=off, 1=on");
|
MODULE_PARM_DESC(debug, "debugging: 0=off, 1=on");
|
||||||
|
|
||||||
#ifdef WITH_CRYPTO
|
#ifdef WITH_CRYPTO
|
||||||
static struct crypto_hash *sysrq_tfm;
|
static struct crypto_shash *sysrq_tfm;
|
||||||
static int sysrq_digest_size;
|
static int sysrq_digest_size;
|
||||||
static unsigned char *sysrq_digest_password;
|
static unsigned char *sysrq_digest_password;
|
||||||
static unsigned char *sysrq_digest;
|
static unsigned char *sysrq_digest;
|
||||||
@@ -75,8 +74,7 @@ static unsigned int sysrq_tg(const void *pdata, uint16_t len)
|
|||||||
{
|
{
|
||||||
const char *data = pdata;
|
const char *data = pdata;
|
||||||
int i, n;
|
int i, n;
|
||||||
struct scatterlist sg[2];
|
struct shash_desc desc;
|
||||||
struct hash_desc desc;
|
|
||||||
int ret;
|
int ret;
|
||||||
long new_seqno = 0;
|
long new_seqno = 0;
|
||||||
|
|
||||||
@@ -117,15 +115,15 @@ static unsigned int sysrq_tg(const void *pdata, uint16_t len)
|
|||||||
|
|
||||||
desc.tfm = sysrq_tfm;
|
desc.tfm = sysrq_tfm;
|
||||||
desc.flags = 0;
|
desc.flags = 0;
|
||||||
ret = crypto_hash_init(&desc);
|
ret = crypto_shash_init(&desc);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
goto hash_fail;
|
goto hash_fail;
|
||||||
sg_init_table(sg, 2);
|
if (crypto_shash_update(&desc, data, n) != 0)
|
||||||
sg_set_buf(&sg[0], data, n);
|
goto hash_fail;
|
||||||
i = strlen(sysrq_digest_password);
|
if (crypto_shash_update(&desc, sysrq_digest_password,
|
||||||
sg_set_buf(&sg[1], sysrq_digest_password, i);
|
strlen(sysrq_digest_password)) != 0)
|
||||||
ret = crypto_hash_digest(&desc, sg, n + i, sysrq_digest);
|
goto hash_fail;
|
||||||
if (ret != 0)
|
if (crypto_shash_final(&desc, sysrq_digest) != 0)
|
||||||
goto hash_fail;
|
goto hash_fail;
|
||||||
|
|
||||||
for (i = 0; i < sysrq_digest_size; ++i) {
|
for (i = 0; i < sysrq_digest_size; ++i) {
|
||||||
@@ -303,7 +301,7 @@ static void sysrq_crypto_exit(void)
|
|||||||
{
|
{
|
||||||
#ifdef WITH_CRYPTO
|
#ifdef WITH_CRYPTO
|
||||||
if (sysrq_tfm)
|
if (sysrq_tfm)
|
||||||
crypto_free_hash(sysrq_tfm);
|
crypto_free_shash(sysrq_tfm);
|
||||||
if (sysrq_digest)
|
if (sysrq_digest)
|
||||||
kfree(sysrq_digest);
|
kfree(sysrq_digest);
|
||||||
if (sysrq_hexdigest)
|
if (sysrq_hexdigest)
|
||||||
@@ -319,7 +317,7 @@ static int __init sysrq_crypto_init(void)
|
|||||||
struct timeval now;
|
struct timeval now;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
sysrq_tfm = crypto_alloc_hash(sysrq_hash, 0, CRYPTO_ALG_ASYNC);
|
sysrq_tfm = crypto_alloc_shash(sysrq_hash, 0, 0);
|
||||||
if (IS_ERR(sysrq_tfm)) {
|
if (IS_ERR(sysrq_tfm)) {
|
||||||
printk(KERN_WARNING KBUILD_MODNAME
|
printk(KERN_WARNING KBUILD_MODNAME
|
||||||
": Error: Could not find or load %s hash\n",
|
": Error: Could not find or load %s hash\n",
|
||||||
@@ -328,7 +326,7 @@ static int __init sysrq_crypto_init(void)
|
|||||||
sysrq_tfm = NULL;
|
sysrq_tfm = NULL;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
sysrq_digest_size = crypto_hash_digestsize(sysrq_tfm);
|
sysrq_digest_size = crypto_shash_digestsize(sysrq_tfm);
|
||||||
sysrq_digest = kmalloc(sysrq_digest_size, GFP_KERNEL);
|
sysrq_digest = kmalloc(sysrq_digest_size, GFP_KERNEL);
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
if (sysrq_digest == NULL)
|
if (sysrq_digest == NULL)
|
||||||
@@ -371,7 +369,7 @@ static void __exit sysrq_tg_exit(void)
|
|||||||
module_init(sysrq_tg_init);
|
module_init(sysrq_tg_init);
|
||||||
module_exit(sysrq_tg_exit);
|
module_exit(sysrq_tg_exit);
|
||||||
MODULE_DESCRIPTION("Xtables: triggering SYSRQ remotely");
|
MODULE_DESCRIPTION("Xtables: triggering SYSRQ remotely");
|
||||||
MODULE_AUTHOR("Jan Engelhardt ");
|
MODULE_AUTHOR("Jan Engelhardt");
|
||||||
MODULE_AUTHOR("John Haxby <john.haxby@oracle.com");
|
MODULE_AUTHOR("John Haxby <john.haxby@oracle.com");
|
||||||
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
||||||
MODULE_ALIAS("ipt_SYSRQ");
|
MODULE_ALIAS("ipt_SYSRQ");
|
||||||
|
@@ -170,8 +170,8 @@ static bool tarpit_generic(struct tcphdr *tcph, const struct tcphdr *oth,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tarpit_tcp4(struct sk_buff *oldskb, unsigned int hook,
|
static void tarpit_tcp4(struct net *net, struct sk_buff *oldskb,
|
||||||
unsigned int mode)
|
unsigned int hook, unsigned int mode)
|
||||||
{
|
{
|
||||||
struct tcphdr _otcph, *tcph;
|
struct tcphdr _otcph, *tcph;
|
||||||
const struct tcphdr *oth;
|
const struct tcphdr *oth;
|
||||||
@@ -250,13 +250,13 @@ static void tarpit_tcp4(struct sk_buff *oldskb, unsigned int hook,
|
|||||||
|
|
||||||
#ifdef CONFIG_BRIDGE_NETFILTER
|
#ifdef CONFIG_BRIDGE_NETFILTER
|
||||||
if (hook != NF_INET_FORWARD || (nskb->nf_bridge != NULL &&
|
if (hook != NF_INET_FORWARD || (nskb->nf_bridge != NULL &&
|
||||||
nskb->nf_bridge->mask & BRNF_BRIDGED))
|
nskb->nf_bridge->physoutdev != NULL))
|
||||||
#else
|
#else
|
||||||
if (hook != NF_INET_FORWARD)
|
if (hook != NF_INET_FORWARD)
|
||||||
#endif
|
#endif
|
||||||
addr_type = RTN_LOCAL;
|
addr_type = RTN_LOCAL;
|
||||||
|
|
||||||
if (ip_route_me_harder(nskb, addr_type))
|
if (ip_route_me_harder(net, nskb, addr_type))
|
||||||
goto free_nskb;
|
goto free_nskb;
|
||||||
else
|
else
|
||||||
niph = ip_hdr(nskb);
|
niph = ip_hdr(nskb);
|
||||||
@@ -278,8 +278,7 @@ static void tarpit_tcp4(struct sk_buff *oldskb, unsigned int hook,
|
|||||||
goto free_nskb;
|
goto free_nskb;
|
||||||
|
|
||||||
nf_ct_attach(nskb, oldskb);
|
nf_ct_attach(nskb, oldskb);
|
||||||
|
NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, net, nskb->sk, nskb, NULL,
|
||||||
NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, nskb, NULL,
|
|
||||||
skb_dst(nskb)->dev, dst_output);
|
skb_dst(nskb)->dev, dst_output);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -288,8 +287,8 @@ static void tarpit_tcp4(struct sk_buff *oldskb, unsigned int hook,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_IPV6
|
#ifdef WITH_IPV6
|
||||||
static void tarpit_tcp6(struct sk_buff *oldskb, unsigned int hook,
|
static void tarpit_tcp6(struct net *net, struct sk_buff *oldskb,
|
||||||
unsigned int mode)
|
unsigned int hook, unsigned int mode)
|
||||||
{
|
{
|
||||||
struct sk_buff *nskb;
|
struct sk_buff *nskb;
|
||||||
struct tcphdr *tcph, oth;
|
struct tcphdr *tcph, oth;
|
||||||
@@ -387,14 +386,13 @@ static void tarpit_tcp6(struct sk_buff *oldskb, unsigned int hook,
|
|||||||
IPPROTO_TCP,
|
IPPROTO_TCP,
|
||||||
csum_partial(tcph, sizeof(struct tcphdr), 0));
|
csum_partial(tcph, sizeof(struct tcphdr), 0));
|
||||||
|
|
||||||
if (ip6_route_me_harder(nskb))
|
if (ip6_route_me_harder(net, nskb))
|
||||||
goto free_nskb;
|
goto free_nskb;
|
||||||
|
|
||||||
nskb->ip_summed = CHECKSUM_NONE;
|
nskb->ip_summed = CHECKSUM_NONE;
|
||||||
|
|
||||||
nf_ct_attach(nskb, oldskb);
|
nf_ct_attach(nskb, oldskb);
|
||||||
|
NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, net, nskb->sk, nskb, NULL,
|
||||||
NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, nskb, NULL,
|
|
||||||
skb_dst(nskb)->dev, dst_output);
|
skb_dst(nskb)->dev, dst_output);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -433,8 +431,7 @@ tarpit_tg4(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
/* We are not interested in fragments */
|
/* We are not interested in fragments */
|
||||||
if (iph->frag_off & htons(IP_OFFSET))
|
if (iph->frag_off & htons(IP_OFFSET))
|
||||||
return NF_DROP;
|
return NF_DROP;
|
||||||
|
tarpit_tcp4(par_net(par), skb, par->state->hook, info->variant);
|
||||||
tarpit_tcp4(skb, par->hooknum, info->variant);
|
|
||||||
return NF_DROP;
|
return NF_DROP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,8 +472,7 @@ tarpit_tg6(struct sk_buff *skb, const struct xt_action_param *par)
|
|||||||
pr_debug("addr is not unicast.\n");
|
pr_debug("addr is not unicast.\n");
|
||||||
return NF_DROP;
|
return NF_DROP;
|
||||||
}
|
}
|
||||||
|
tarpit_tcp6(par_net(par), skb, par->state->hook, info->variant);
|
||||||
tarpit_tcp6(skb, par->hooknum, info->variant);
|
|
||||||
return NF_DROP;
|
return NF_DROP;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
* Authors:
|
* Authors:
|
||||||
* Stephane Ouellette <ouellettes [at] videotron ca>, 2002-10-22
|
* Stephane Ouellette <ouellettes [at] videotron ca>, 2002-10-22
|
||||||
* Massimiliano Hofer <max [at] nucleus it>, 2006-05-15
|
* Massimiliano Hofer <max [at] nucleus it>, 2006-05-15
|
||||||
|
* Grzegorz Kuczyński <grzegorz.kuczynski [at] koba pl>, 2017-02-27
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License; either version 2
|
* under the terms of the GNU General Public License; either version 2
|
||||||
@@ -21,6 +22,8 @@
|
|||||||
#include <linux/version.h>
|
#include <linux/version.h>
|
||||||
#include <linux/netfilter/x_tables.h>
|
#include <linux/netfilter/x_tables.h>
|
||||||
#include <asm/uaccess.h>
|
#include <asm/uaccess.h>
|
||||||
|
#include <net/net_namespace.h>
|
||||||
|
#include <net/netns/generic.h>
|
||||||
#include "xt_condition.h"
|
#include "xt_condition.h"
|
||||||
#include "compat_xtables.h"
|
#include "compat_xtables.h"
|
||||||
|
|
||||||
@@ -59,14 +62,25 @@ struct condition_variable {
|
|||||||
/* to the conditions' list. */
|
/* to the conditions' list. */
|
||||||
static DEFINE_MUTEX(proc_lock);
|
static DEFINE_MUTEX(proc_lock);
|
||||||
|
|
||||||
static LIST_HEAD(conditions_list);
|
struct condition_net {
|
||||||
static struct proc_dir_entry *proc_net_condition;
|
struct list_head conditions_list;
|
||||||
|
struct proc_dir_entry *proc_net_condition;
|
||||||
|
bool after_clear;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int condition_net_id;
|
||||||
|
|
||||||
|
static inline struct condition_net *condition_pernet(struct net *net)
|
||||||
|
{
|
||||||
|
return net_generic(net, condition_net_id);
|
||||||
|
}
|
||||||
|
|
||||||
static int condition_proc_show(struct seq_file *m, void *data)
|
static int condition_proc_show(struct seq_file *m, void *data)
|
||||||
{
|
{
|
||||||
const struct condition_variable *var = m->private;
|
const struct condition_variable *var = m->private;
|
||||||
|
|
||||||
return seq_printf(m, var->enabled ? "1\n" : "0\n");
|
seq_printf(m, var->enabled ? "1\n" : "0\n");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int condition_proc_open(struct inode *inode, struct file *file)
|
static int condition_proc_open(struct inode *inode, struct file *file)
|
||||||
@@ -118,6 +132,7 @@ static int condition_mt_check(const struct xt_mtchk_param *par)
|
|||||||
{
|
{
|
||||||
struct xt_condition_mtinfo *info = par->matchinfo;
|
struct xt_condition_mtinfo *info = par->matchinfo;
|
||||||
struct condition_variable *var;
|
struct condition_variable *var;
|
||||||
|
struct condition_net *condition_net = condition_pernet(par->net);
|
||||||
|
|
||||||
/* Forbid certain names */
|
/* Forbid certain names */
|
||||||
if (*info->name == '\0' || *info->name == '.' ||
|
if (*info->name == '\0' || *info->name == '.' ||
|
||||||
@@ -133,7 +148,7 @@ static int condition_mt_check(const struct xt_mtchk_param *par)
|
|||||||
* or increase the reference counter.
|
* or increase the reference counter.
|
||||||
*/
|
*/
|
||||||
mutex_lock(&proc_lock);
|
mutex_lock(&proc_lock);
|
||||||
list_for_each_entry(var, &conditions_list, list) {
|
list_for_each_entry(var, &condition_net->conditions_list, list) {
|
||||||
if (strcmp(info->name, var->name) == 0) {
|
if (strcmp(info->name, var->name) == 0) {
|
||||||
var->refcount++;
|
var->refcount++;
|
||||||
mutex_unlock(&proc_lock);
|
mutex_unlock(&proc_lock);
|
||||||
@@ -152,7 +167,7 @@ static int condition_mt_check(const struct xt_mtchk_param *par)
|
|||||||
memcpy(var->name, info->name, sizeof(info->name));
|
memcpy(var->name, info->name, sizeof(info->name));
|
||||||
/* Create the condition variable's proc file entry. */
|
/* Create the condition variable's proc file entry. */
|
||||||
var->status_proc = proc_create_data(info->name, condition_list_perms,
|
var->status_proc = proc_create_data(info->name, condition_list_perms,
|
||||||
proc_net_condition, &condition_proc_fops, var);
|
condition_net->proc_net_condition, &condition_proc_fops, var);
|
||||||
if (var->status_proc == NULL) {
|
if (var->status_proc == NULL) {
|
||||||
kfree(var);
|
kfree(var);
|
||||||
mutex_unlock(&proc_lock);
|
mutex_unlock(&proc_lock);
|
||||||
@@ -165,7 +180,7 @@ static int condition_mt_check(const struct xt_mtchk_param *par)
|
|||||||
var->refcount = 1;
|
var->refcount = 1;
|
||||||
var->enabled = false;
|
var->enabled = false;
|
||||||
wmb();
|
wmb();
|
||||||
list_add(&var->list, &conditions_list);
|
list_add(&var->list, &condition_net->conditions_list);
|
||||||
mutex_unlock(&proc_lock);
|
mutex_unlock(&proc_lock);
|
||||||
info->condvar = var;
|
info->condvar = var;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -175,11 +190,15 @@ static void condition_mt_destroy(const struct xt_mtdtor_param *par)
|
|||||||
{
|
{
|
||||||
const struct xt_condition_mtinfo *info = par->matchinfo;
|
const struct xt_condition_mtinfo *info = par->matchinfo;
|
||||||
struct condition_variable *var = info->condvar;
|
struct condition_variable *var = info->condvar;
|
||||||
|
struct condition_net *cnet = condition_pernet(par->net);
|
||||||
|
|
||||||
|
if (cnet->after_clear)
|
||||||
|
return;
|
||||||
|
|
||||||
mutex_lock(&proc_lock);
|
mutex_lock(&proc_lock);
|
||||||
if (--var->refcount == 0) {
|
if (--var->refcount == 0) {
|
||||||
list_del(&var->list);
|
list_del(&var->list);
|
||||||
proc_remove(var->status_proc);
|
remove_proc_entry(var->name, cnet->proc_net_condition);
|
||||||
mutex_unlock(&proc_lock);
|
mutex_unlock(&proc_lock);
|
||||||
kfree(var);
|
kfree(var);
|
||||||
return;
|
return;
|
||||||
@@ -212,18 +231,54 @@ static struct xt_match condition_mt_reg[] __read_mostly = {
|
|||||||
|
|
||||||
static const char *const dir_name = "nf_condition";
|
static const char *const dir_name = "nf_condition";
|
||||||
|
|
||||||
|
static int __net_init condition_net_init(struct net *net)
|
||||||
|
{
|
||||||
|
struct condition_net *condition_net = condition_pernet(net);
|
||||||
|
INIT_LIST_HEAD(&condition_net->conditions_list);
|
||||||
|
condition_net->proc_net_condition = proc_mkdir(dir_name, net->proc_net);
|
||||||
|
if (condition_net->proc_net_condition == NULL)
|
||||||
|
return -EACCES;
|
||||||
|
condition_net->after_clear = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __net_exit condition_net_exit(struct net *net)
|
||||||
|
{
|
||||||
|
struct condition_net *condition_net = condition_pernet(net);
|
||||||
|
struct list_head *pos, *q;
|
||||||
|
struct condition_variable *var = NULL;
|
||||||
|
|
||||||
|
remove_proc_subtree(dir_name, net->proc_net);
|
||||||
|
mutex_lock(&proc_lock);
|
||||||
|
list_for_each_safe(pos, q, &condition_net->conditions_list) {
|
||||||
|
var = list_entry(pos, struct condition_variable, list);
|
||||||
|
list_del(pos);
|
||||||
|
kfree(var);
|
||||||
|
}
|
||||||
|
mutex_unlock(&proc_lock);
|
||||||
|
condition_net->after_clear = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct pernet_operations condition_net_ops = {
|
||||||
|
.init = condition_net_init,
|
||||||
|
.exit = condition_net_exit,
|
||||||
|
.id = &condition_net_id,
|
||||||
|
.size = sizeof(struct condition_net),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static int __init condition_mt_init(void)
|
static int __init condition_mt_init(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
mutex_init(&proc_lock);
|
mutex_init(&proc_lock);
|
||||||
proc_net_condition = proc_mkdir(dir_name, init_net.proc_net);
|
ret = register_pernet_subsys(&condition_net_ops);
|
||||||
if (proc_net_condition == NULL)
|
if (ret != 0)
|
||||||
return -EACCES;
|
return ret;
|
||||||
|
|
||||||
ret = xt_register_matches(condition_mt_reg, ARRAY_SIZE(condition_mt_reg));
|
ret = xt_register_matches(condition_mt_reg, ARRAY_SIZE(condition_mt_reg));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
remove_proc_entry(dir_name, init_net.proc_net);
|
unregister_pernet_subsys(&condition_net_ops);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,7 +288,7 @@ static int __init condition_mt_init(void)
|
|||||||
static void __exit condition_mt_exit(void)
|
static void __exit condition_mt_exit(void)
|
||||||
{
|
{
|
||||||
xt_unregister_matches(condition_mt_reg, ARRAY_SIZE(condition_mt_reg));
|
xt_unregister_matches(condition_mt_reg, ARRAY_SIZE(condition_mt_reg));
|
||||||
remove_proc_entry(dir_name, init_net.proc_net);
|
unregister_pernet_subsys(&condition_net_ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(condition_mt_init);
|
module_init(condition_mt_init);
|
||||||
|
@@ -75,7 +75,8 @@ geoip_add_node(const struct geoip_country_user __user *umem_ptr,
|
|||||||
|
|
||||||
if (copy_from_user(&umem, umem_ptr, sizeof(umem)) != 0)
|
if (copy_from_user(&umem, umem_ptr, sizeof(umem)) != 0)
|
||||||
return ERR_PTR(-EFAULT);
|
return ERR_PTR(-EFAULT);
|
||||||
|
if (umem.count > SIZE_MAX / geoproto_size[proto])
|
||||||
|
return ERR_PTR(-E2BIG);
|
||||||
p = kmalloc(sizeof(struct geoip_country_kernel), GFP_KERNEL);
|
p = kmalloc(sizeof(struct geoip_country_kernel), GFP_KERNEL);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
@@ -45,9 +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)
|
const struct xt_action_param *par, struct net_device **put)
|
||||||
{
|
{
|
||||||
if (info->flags & XT_IFACE_DEV_IN)
|
if (info->flags & XT_IFACE_DEV_IN)
|
||||||
return par->in;
|
return par->state->in;
|
||||||
else if (info->flags & XT_IFACE_DEV_OUT)
|
else if (info->flags & XT_IFACE_DEV_OUT)
|
||||||
return par->out;
|
return par->state->out;
|
||||||
return *put = dev_get_by_name(&init_net, info->ifname);
|
return *put = dev_get_by_name(&init_net, info->ifname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -511,7 +511,7 @@ search_bittorrent(const unsigned char *payload, const unsigned int plen)
|
|||||||
* but *must have* one (or more) of strings listed below (true for scrape and announce)
|
* but *must have* one (or more) of strings listed below (true for scrape and announce)
|
||||||
*/
|
*/
|
||||||
if (memcmp(payload, "GET /", 5) == 0) {
|
if (memcmp(payload, "GET /", 5) == 0) {
|
||||||
if (HX_memmem(payload, plen, "info_hash=", 9) != NULL)
|
if (HX_memmem(payload, plen, "info_hash=", 10) != NULL)
|
||||||
return IPP2P_BIT * 100 + 1;
|
return IPP2P_BIT * 100 + 1;
|
||||||
if (HX_memmem(payload, plen, "peer_id=", 8) != NULL)
|
if (HX_memmem(payload, plen, "peer_id=", 8) != NULL)
|
||||||
return IPP2P_BIT * 100 + 2;
|
return IPP2P_BIT * 100 + 2;
|
||||||
|
@@ -204,7 +204,7 @@ lscan_mt(const struct sk_buff *skb, struct xt_action_param *par)
|
|||||||
unsigned int n;
|
unsigned int n;
|
||||||
|
|
||||||
n = lscan_mt_full(ctdata->mark & connmark_mask, ctstate,
|
n = lscan_mt_full(ctdata->mark & connmark_mask, ctstate,
|
||||||
par->in == init_net.loopback_dev, tcph,
|
par->state->in == init_net.loopback_dev, tcph,
|
||||||
skb->len - par->thoff - 4 * tcph->doff);
|
skb->len - par->thoff - 4 * tcph->doff);
|
||||||
|
|
||||||
ctdata->mark = (ctdata->mark & ~connmark_mask) | n;
|
ctdata->mark = (ctdata->mark & ~connmark_mask) | n;
|
||||||
|
@@ -45,12 +45,12 @@ MODULE_ALIAS("ip6t_psd");
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Keep track of up to LIST_SIZE source addresses, using a hash table of
|
* Keep track of up to LIST_SIZE source addresses, using a hash table of
|
||||||
* HASH_SIZE entries for faster lookups, but limiting hash collisions to
|
* PSD_HASH_SIZE entries for faster lookups, but limiting hash collisions to
|
||||||
* HASH_MAX source addresses per the same hash value.
|
* HASH_MAX source addresses per the same hash value.
|
||||||
*/
|
*/
|
||||||
#define LIST_SIZE 0x100
|
#define LIST_SIZE 0x100
|
||||||
#define HASH_LOG 9
|
#define HASH_LOG 9
|
||||||
#define HASH_SIZE (1 << HASH_LOG)
|
#define PSD_HASH_SIZE (1 << HASH_LOG)
|
||||||
#define HASH_MAX 0x10
|
#define HASH_MAX 0x10
|
||||||
|
|
||||||
#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
|
#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE)
|
||||||
@@ -108,7 +108,7 @@ struct host6 {
|
|||||||
static struct {
|
static struct {
|
||||||
spinlock_t lock;
|
spinlock_t lock;
|
||||||
struct host4 list[LIST_SIZE];
|
struct host4 list[LIST_SIZE];
|
||||||
struct host *hash[HASH_SIZE];
|
struct host *hash[PSD_HASH_SIZE];
|
||||||
int index;
|
int index;
|
||||||
} state;
|
} state;
|
||||||
|
|
||||||
@@ -143,13 +143,12 @@ static bool state6_alloc_mem(void)
|
|||||||
if (state6.list == NULL)
|
if (state6.list == NULL)
|
||||||
return false;
|
return false;
|
||||||
memset(state6.list, 0, LIST_SIZE * sizeof(struct host6));
|
memset(state6.list, 0, LIST_SIZE * sizeof(struct host6));
|
||||||
|
state6.hash = vmalloc(PSD_HASH_SIZE * sizeof(struct host *));
|
||||||
state6.hash = vmalloc(HASH_SIZE * sizeof(struct host*));
|
|
||||||
if (state6.hash == NULL) {
|
if (state6.hash == NULL) {
|
||||||
vfree(state6.list);
|
vfree(state6.list);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
memset(state6.hash, 0, HASH_SIZE * sizeof(struct host *));
|
memset(state6.hash, 0, PSD_HASH_SIZE * sizeof(struct host *));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -167,8 +166,7 @@ static unsigned int hashfunc(__be32 addr)
|
|||||||
do {
|
do {
|
||||||
hash ^= value;
|
hash ^= value;
|
||||||
} while ((value >>= HASH_LOG) != 0);
|
} while ((value >>= HASH_LOG) != 0);
|
||||||
|
return hash & (PSD_HASH_SIZE - 1);
|
||||||
return hash & (HASH_SIZE - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned int hashfunc6(const struct in6_addr *addr)
|
static inline unsigned int hashfunc6(const struct in6_addr *addr)
|
||||||
|
@@ -64,12 +64,11 @@ module_param_named(gid, quota_list_gid, uint, S_IRUGO | S_IWUSR);
|
|||||||
static int quota_proc_show(struct seq_file *m, void *data)
|
static int quota_proc_show(struct seq_file *m, void *data)
|
||||||
{
|
{
|
||||||
struct xt_quota_counter *e = m->private;
|
struct xt_quota_counter *e = m->private;
|
||||||
int ret;
|
|
||||||
|
|
||||||
spin_lock_bh(&e->lock);
|
spin_lock_bh(&e->lock);
|
||||||
ret = seq_printf(m, "%llu\n", e->quota);
|
seq_printf(m, "%llu\n", e->quota);
|
||||||
spin_unlock_bh(&e->lock);
|
spin_unlock_bh(&e->lock);
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int quota_proc_open(struct inode *inode, struct file *file)
|
static int quota_proc_open(struct inode *inode, struct file *file)
|
||||||
@@ -82,7 +81,7 @@ quota_proc_write(struct file *file, const char __user *input,
|
|||||||
size_t size, loff_t *loff)
|
size_t size, loff_t *loff)
|
||||||
{
|
{
|
||||||
struct xt_quota_counter *e = PDE_DATA(file_inode(file));
|
struct xt_quota_counter *e = PDE_DATA(file_inode(file));
|
||||||
char buf[sizeof("18446744073709551616")];
|
char buf[sizeof("+-18446744073709551616")];
|
||||||
|
|
||||||
if (size > sizeof(buf))
|
if (size > sizeof(buf))
|
||||||
size = sizeof(buf);
|
size = sizeof(buf);
|
||||||
@@ -92,9 +91,29 @@ quota_proc_write(struct file *file, const char __user *input,
|
|||||||
if (size < sizeof(buf))
|
if (size < sizeof(buf))
|
||||||
buf[size] = '\0';
|
buf[size] = '\0';
|
||||||
|
|
||||||
spin_lock_bh(&e->lock);
|
if (*buf == '+') {
|
||||||
e->quota = simple_strtoull(buf, NULL, 0);
|
int64_t temp = simple_strtoll(buf + 1, NULL, 0);
|
||||||
spin_unlock_bh(&e->lock);
|
spin_lock_bh(&e->lock);
|
||||||
|
/* Do not let quota become negative if @tmp is very negative */
|
||||||
|
if (temp > 0 || -temp < e->quota)
|
||||||
|
e->quota += temp;
|
||||||
|
else
|
||||||
|
e->quota = 0;
|
||||||
|
spin_unlock_bh(&e->lock);
|
||||||
|
} else if (*buf == '-') {
|
||||||
|
int64_t temp = simple_strtoll(buf + 1, NULL, 0);
|
||||||
|
spin_lock_bh(&e->lock);
|
||||||
|
/* Do not let quota become negative if @tmp is very big */
|
||||||
|
if (temp < 0 || temp < e->quota)
|
||||||
|
e->quota -= temp;
|
||||||
|
else
|
||||||
|
e->quota = 0;
|
||||||
|
spin_unlock_bh(&e->lock);
|
||||||
|
} else {
|
||||||
|
spin_lock_bh(&e->lock);
|
||||||
|
e->quota = simple_strtoull(buf, NULL, 0);
|
||||||
|
spin_unlock_bh(&e->lock);
|
||||||
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,10 +1,13 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
#
|
#
|
||||||
# Converter for MaxMind CSV database to binary, for xt_geoip
|
# Converter for MaxMind CSV database to binary, for xt_geoip
|
||||||
# Copyright © Jan Engelhardt, 2008-2011
|
# Copyright Jan Engelhardt, 2008-2011
|
||||||
|
# Copyright Philip Prindeville, 2018
|
||||||
#
|
#
|
||||||
use Getopt::Long;
|
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 Text::CSV_XS; # or trade for Text::CSV
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
@@ -24,41 +27,208 @@ 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;
|
exit 1;
|
||||||
}
|
}
|
||||||
foreach (qw(LE BE)) {
|
|
||||||
my $dir = "$target_dir/$_";
|
my %countryId;
|
||||||
if (!-e $dir && !mkdir($dir)) {
|
my %countryName;
|
||||||
print STDERR "Could not mkdir $dir: $!\n";
|
|
||||||
exit 1;
|
my $dir = findVersion();
|
||||||
}
|
|
||||||
}
|
&loadCountries();
|
||||||
|
|
||||||
&dump(&collect());
|
&dump(&collect());
|
||||||
|
|
||||||
|
sub findVersion
|
||||||
|
{
|
||||||
|
my @dirs = ();
|
||||||
|
|
||||||
|
opendir(my $dh, '.') || die "Can't open .: $!\n";
|
||||||
|
|
||||||
|
while (readdir $dh) {
|
||||||
|
if ($_ =~ m/^GeoLite2-Country-CSV_\d{8}$/) {
|
||||||
|
push(@dirs, $_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir $dh;
|
||||||
|
|
||||||
|
@dirs = sort @dirs;
|
||||||
|
return pop(@dirs);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub loadCountries
|
||||||
|
{
|
||||||
|
my $file = "$dir/GeoLite2-Country-Locations-en.csv";
|
||||||
|
|
||||||
|
sub id; sub cc; sub long; sub ct; sub cn;
|
||||||
|
|
||||||
|
%countryId = ();
|
||||||
|
%countryName = ();
|
||||||
|
|
||||||
|
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 %country;
|
my ($file, $fh, $row);
|
||||||
|
my (%country, %header);
|
||||||
|
|
||||||
|
sub net; sub id; sub rid; sub proxy; sub sat;
|
||||||
|
|
||||||
|
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 = "$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)) {
|
||||||
|
my ($cc, $cidr);
|
||||||
|
|
||||||
|
$cc = lookupCountry($row->[id], $row->[rid], $row->[proxy], $row->[sat]);
|
||||||
|
$cidr = $row->[net];
|
||||||
|
$country{$cc}->{pool_v4}->add($cidr);
|
||||||
|
|
||||||
while (my $row = $csv->getline(*ARGV)) {
|
|
||||||
if (!defined($country{$row->[4]})) {
|
|
||||||
$country{$row->[4]} = {
|
|
||||||
name => $row->[5],
|
|
||||||
pool_v4 => [],
|
|
||||||
pool_v6 => [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
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 ($. % 4096 == 0) {
|
if ($. % 4096 == 0) {
|
||||||
print STDERR "\r\e[2K$. entries";
|
print STDERR "\r\e[2K$. entries";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print STDERR "\r\e[2K$. entries total\n";
|
print STDERR "\r\e[2K$. entries total\n";
|
||||||
|
|
||||||
|
close($fh);
|
||||||
|
|
||||||
|
# clean up the namespace
|
||||||
|
undef &net; undef &id; undef &rid; undef &proxy; undef &sat;
|
||||||
|
|
||||||
|
$file = "$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +236,7 @@ sub dump
|
|||||||
{
|
{
|
||||||
my $country = shift @_;
|
my $country = shift @_;
|
||||||
|
|
||||||
foreach my $iso_code (sort keys %$country) {
|
foreach my $iso_code (sort keys %{$country}) {
|
||||||
&dump_one($iso_code, $country->{$iso_code});
|
&dump_one($iso_code, $country->{$iso_code});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,68 +244,41 @@ sub dump
|
|||||||
sub dump_one
|
sub dump_one
|
||||||
{
|
{
|
||||||
my($iso_code, $country) = @_;
|
my($iso_code, $country) = @_;
|
||||||
my($file, $fh_le, $fh_be);
|
my @ranges;
|
||||||
|
|
||||||
printf "%5u IPv6 ranges for %s %s\n",
|
@ranges = $country->{pool_v4}->list_range();
|
||||||
scalar(@{$country->{pool_v6}}),
|
|
||||||
$iso_code, $country->{name};
|
|
||||||
|
|
||||||
$file = "$target_dir/LE/".uc($iso_code).".iv6";
|
writeCountry($iso_code, $country->{name}, AF_INET, @ranges);
|
||||||
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;
|
|
||||||
|
|
||||||
printf "%5u IPv4 ranges for %s %s\n",
|
@ranges = $country->{pool_v6}->list_range();
|
||||||
scalar(@{$country->{pool_v4}}),
|
|
||||||
$iso_code, $country->{name};
|
|
||||||
|
|
||||||
$file = "$target_dir/LE/".uc($iso_code).".iv4";
|
writeCountry($iso_code, $country->{name}, AF_INET6, @ranges);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub ip6_pack
|
sub writeCountry
|
||||||
{
|
{
|
||||||
my $addr = shift @_;
|
my ($iso_code, $name, $family, @ranges) = @_;
|
||||||
$addr =~ s{::}{:!:};
|
my $fh;
|
||||||
my @addr = split(/:/, $addr);
|
|
||||||
my @e = (0) x 8;
|
printf "%5u IPv%s ranges for %s %s\n",
|
||||||
foreach (@addr) {
|
scalar(@ranges),
|
||||||
if ($_ eq "!") {
|
($family == AF_INET ? '4' : '6'),
|
||||||
$_ = join(':', @e[0..(8-scalar(@addr))]);
|
$iso_code, $name;
|
||||||
}
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
@addr = split(/:/, join(':', @addr));
|
|
||||||
$_ = hex($_) foreach @addr;
|
binmode($fh);
|
||||||
return pack("n*", @addr);
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub ip6_swap
|
|
||||||
{
|
|
||||||
return pack("V*", unpack("N*", shift @_));
|
|
||||||
}
|
|
||||||
|
@@ -5,7 +5,7 @@ xt_geoip_build \(em convert GeoIP.csv to packed format for xt_geoip
|
|||||||
.SH Syntax
|
.SH Syntax
|
||||||
.PP
|
.PP
|
||||||
\fI/usr/libexec/xt_geoip/\fP\fBxt_geoip_build\fP [\fB\-D\fP
|
\fI/usr/libexec/xt_geoip/\fP\fBxt_geoip_build\fP [\fB\-D\fP
|
||||||
\fItarget_dir\fP] [\fIfile\fP...]
|
\fItarget_dir\fP]
|
||||||
.SH Description
|
.SH Description
|
||||||
.PP
|
.PP
|
||||||
xt_geoip_build is used to build packed raw representations of the range
|
xt_geoip_build is used to build packed raw representations of the range
|
||||||
@@ -16,7 +16,12 @@ 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
|
also ordered, as xt_geoip relies on this property for its bisection approach to
|
||||||
work.
|
work.
|
||||||
.PP
|
.PP
|
||||||
Input is processed from the listed files, or if none is given, from stdin.
|
It expects to find a directory named
|
||||||
|
.IR GeoLite2-Country-CSV_YYYYMMDD
|
||||||
|
in the current directory, and will select the most recent if multiple
|
||||||
|
instances are found. The
|
||||||
|
.IR xt_geoip_dl
|
||||||
|
script can be used to populate this directory.
|
||||||
.PP
|
.PP
|
||||||
Since the script is usually installed to the libexec directory of the
|
Since the script is usually installed to the libexec directory of the
|
||||||
xtables-addons package and this is outside $PATH (on purpose), invoking the
|
xtables-addons package and this is outside $PATH (on purpose), invoking the
|
||||||
|
@@ -1,8 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
rm -f GeoIPv6.csv GeoIPv6.csv.gz GeoIPCountryCSV.zip GeoIPCountryWhois.csv;
|
rm -rf GeoLite2-Country-CSV_*
|
||||||
wget \
|
|
||||||
http://geolite.maxmind.com/download/geoip/database/GeoIPv6.csv.gz \
|
wget -q http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country-CSV.zip
|
||||||
http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip;
|
unzip -q GeoLite2-Country-CSV.zip
|
||||||
gzip -d GeoIPv6.csv.gz;
|
rm -f GeoLite2-Country-CSV.zip
|
||||||
unzip GeoIPCountryCSV.zip;
|
|
||||||
|
93
geoip/xt_geoip_fetch
Executable file
93
geoip/xt_geoip_fetch
Executable file
@@ -0,0 +1,93 @@
|
|||||||
|
#!/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 = inet_ntop(AF_INET, substr($buffer, 0, AF_INET_SIZE));
|
||||||
|
my $end = inet_ntop(AF_INET, substr($buffer, AF_INET_SIZE));
|
||||||
|
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 = inet_ntop(AF_INET6, substr($buffer, 0, AF_INET6_SIZE));
|
||||||
|
my $end = inet_ntop(AF_INET6, substr($buffer, AF_INET6_SIZE));
|
||||||
|
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;
|
@@ -1,4 +1,4 @@
|
|||||||
.TH xtables-addons 8 "Red October" "" "v2.6 (2014-09-29)"
|
.TH xtables-addons 8 "Windows" "" "v3.1 (2018-08-14)"
|
||||||
.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