xtables-addons: fix kernel 4.19 support

This commit is contained in:
coolsnowwolf 2019-04-18 10:19:37 +08:00
parent 5f037bcd7d
commit 907e8b7ebc
5 changed files with 136 additions and 12 deletions

View File

@ -10,7 +10,7 @@ include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=xtables-addons
PKG_VERSION:=2.14
PKG_RELEASE:=4
PKG_RELEASE:=6
PKG_HASH:=d215a9a8b8e66aae04b982fa2e1228e8a71e7dfe42320df99e34e5000cbdf152
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz

View File

@ -0,0 +1,50 @@
From 2b76b68c65c97fc11409088c3c30993324df8500 Mon Sep 17 00:00:00 2001
From: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Date: Thu, 4 Jan 2018 18:50:50 +0100
Subject: [PATCH] build: support for Linux 4.15
Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
---
extensions/pknock/xt_pknock.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/extensions/pknock/xt_pknock.c b/extensions/pknock/xt_pknock.c
index 6fbdea4..31d4bc8 100644
--- a/extensions/pknock/xt_pknock.c
+++ b/extensions/pknock/xt_pknock.c
@@ -358,10 +358,20 @@ has_logged_during_this_minute(const struct peer *peer)
* @r: rule
*/
static void
-peer_gc(unsigned long r)
+peer_gc(
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
+ struct timer_list *tl
+#else
+ unsigned long r
+#endif
+)
{
unsigned int i;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
+ struct xt_pknock_rule *rule = from_timer(rule, tl, timer);
+#else
struct xt_pknock_rule *rule = (struct xt_pknock_rule *)r;
+#endif
struct peer *peer;
struct list_head *pos, *n;
@@ -469,9 +479,13 @@ add_rule(struct xt_pknock_mtinfo *info)
if (rule->peer_head == NULL)
goto out;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
+ timer_setup(&rule->timer, peer_gc, 0);
+#else
init_timer(&rule->timer);
rule->timer.function = peer_gc;
rule->timer.data = (unsigned long)rule;
+#endif
rule->status_proc = proc_create_data(info->rule_name, 0, pde,
&pknock_proc_ops, rule);

View File

@ -0,0 +1,25 @@
From 3ea761a1ed338241fbc79bef8e433307e108b6cd Mon Sep 17 00:00:00 2001
From: Jan Engelhardt <jengelh@inai.de>
Date: Tue, 14 Aug 2018 14:29:30 +0200
Subject: [PATCH] build: add support for Linux 4.18
---
extensions/xt_DNETMAP.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/extensions/xt_DNETMAP.c b/extensions/xt_DNETMAP.c
index 1b415c3..de7d4ec 100644
--- a/extensions/xt_DNETMAP.c
+++ b/extensions/xt_DNETMAP.c
@@ -367,7 +367,11 @@ dnetmap_tg(struct sk_buff *skb, const struct xt_action_param *par)
__be32 prenat_ip, postnat_ip, prenat_ip_prev;
const struct xt_DNETMAP_tginfo *tginfo = par->targinfo;
const struct nf_nat_range *mr = &tginfo->prefix;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0)
+ struct nf_nat_range2 newrange;
+#else
struct nf_nat_range newrange;
+#endif
struct dnetmap_entry *e;
struct dnetmap_prefix *p;
__s32 jttl;

View File

@ -235,7 +235,7 @@
+#endif /* _NETFILTER_MIME_H */
--- /dev/null
+++ b/extensions/rtsp/nf_conntrack_rtsp.c
@@ -0,0 +1,732 @@
@@ -0,0 +1,761 @@
+/*
+ * RTSP extension for IP connection tracking
+ * (C) 2003 by Tom Marshall <tmarshall at real.com>
@ -257,6 +257,9 @@
+ * 2018-04-18: Hans Dedecker <dedeckeh at gmail.com>
+ * - update RTP expected connection source IP based on SOURCE
+ * in the SETUP reply message
+ * 2018-08-03: Alin Nastac <alin.nastac at gmail.com>
+ * Hans Dedecker <dedeckeh at gmail.com>
+ * - parse non-standard destination=address:port format
+ *
+ * based on ip_conntrack_irc.c
+ *
@ -287,6 +290,7 @@
+#include <net/netfilter/nf_conntrack.h>
+#include <net/netfilter/nf_conntrack_expect.h>
+#include <net/netfilter/nf_conntrack_helper.h>
+#include <net/netfilter/nf_conntrack_zones.h>
+#include "nf_conntrack_rtsp.h"
+
+#define NF_NEED_STRNCASECMP
@ -500,6 +504,29 @@
+ -1, NULL))
+ pr_debug("source found : %pI4\n",
+ &prtspexp->srvaddr.ip);
+ } else if (nextfieldoff - off > 12 && strncmp(ptran+off, "destination=", 12) == 0) {
+ const char *psep;
+ u_int16_t port;
+
+ off += 12;
+
+ if (in4_pton(ptran+off, nextfieldoff - off - 1, (u8 *)&prtspexp->cltaddr.in, -1, NULL)) {
+ pr_debug("destination found : %pI4\n", &prtspexp->cltaddr.ip);
+
+ /*
+ * Some RTSP clients(mostly STBs) use non-standard destination parameters:
+ * destination=address:port
+ */
+ psep = memchr(ptran+off, ':', nextfieldoff-off);
+ if (psep != NULL && nf_strtou16(psep + 1, &port)) {
+ if (prtspexp->loport != 0 && prtspexp->loport != port)
+ pr_debug("multiple ports found, port %hu ignored\n", port);
+ else {
+ pr_debug("lo port found : %hu\n", port);
+ prtspexp->loport = prtspexp->hiport = port;
+ }
+ }
+ }
+ }
+
+ /*
@ -878,6 +905,8 @@
+ ret = help_in(skb, rb_ptr, datalen, ct, ctinfo);
+#endif
+ break;
+ default:
+ break;
+ }
+
+ spin_unlock_bh(&rtsp_buffer_lock);
@ -970,7 +999,7 @@
+module_exit(fini);
--- /dev/null
+++ b/extensions/rtsp/nf_conntrack_rtsp.h
@@ -0,0 +1,73 @@
@@ -0,0 +1,74 @@
+/*
+ * RTSP extension for IP connection tracking.
+ * (C) 2003 by Tom Marshall <tmarshall at real.com>
@ -1022,6 +1051,7 @@
+ u_int16_t loport; /* Port that was requested, low or first */
+ u_int16_t hiport; /* Port that was requested, high or second */
+ union nf_inet_addr srvaddr; /* src address in SETUP reply */
+ union nf_inet_addr cltaddr; /* destination address */
+#if 0
+ uint method; /* RTSP method */
+ uint cseq; /* CSeq from request */
@ -1046,7 +1076,7 @@
+#endif /* _IP_CONNTRACK_RTSP_H */
--- /dev/null
+++ b/extensions/rtsp/nf_nat_rtsp.c
@@ -0,0 +1,617 @@
@@ -0,0 +1,636 @@
+/*
+ * RTSP extension for TCP NAT alteration
+ * (C) 2003 by Tom Marshall <tmarshall at real.com>
@ -1206,9 +1236,9 @@
+ struct nf_conntrack_tuple *rtp_t;
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
+ char szextaddr[INET6_ADDRSTRLEN];
+ char szextaddr[INET6_ADDRSTRLEN + 16];
+#else
+ char szextaddr[INET_ADDRSTRLEN];
+ char szextaddr[INET_ADDRSTRLEN + 16];
+#endif
+ uint extaddrlen;
+ int is_stun;
@ -1341,8 +1371,9 @@
+
+ pfieldend = memchr(ptran+off, ';', nextparamoff-off);
+ nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
+ SKIP_WSPACE(ptran, nextfieldoff, off);
+
+ if (dstact != DSTACT_NONE && strncmp(ptran+off, "destination=", 12) == 0) {
+ if (dstact != DSTACT_NONE && nextfieldoff - off > 12 && strncmp(ptran+off, "destination=", 12) == 0) {
+ if (strncmp(ptran+off+12, szextaddr, extaddrlen) == 0)
+ is_stun = 1;
+
@ -1353,12 +1384,28 @@
+ uint dstreplen = 0;
+ diff = dstlen;
+ if (dstact == DSTACT_AUTO && !is_stun) {
+ pr_debug("RTSP: replace dst addr\n");
+ const char* psep = memchr(ptran+off, ':', dstlen);
+ u_int16_t port;
+
+ dstoff += 12;
+ dstlen -= 13;
+ pdstrep = szextaddr;
+ dstreplen = extaddrlen;
+ diff = nextfieldoff-off-13-extaddrlen;
+
+ if (psep != NULL && nf_strtou16(psep + 1, &port)) {
+ pr_debug("RTSP: replace dst addr&port\n");
+
+ if (port != prtspexp->loport) {
+ pr_debug("multiple ports found, port %hu ignored\n", port);
+ dstreplen = extaddrlen;
+ } else {
+ sprintf(szextaddr+extaddrlen, ":%s", rbuf1);
+ dstreplen = extaddrlen+1+rbuf1len;
+ }
+ } else {
+ pr_debug("RTSP: replace dst addr\n");
+ dstreplen = extaddrlen;
+ }
+ diff = nextfieldoff-off-13-dstreplen;
+ }
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
@ -1396,7 +1443,7 @@
+ pfieldend = memchr(ptran+off, ';', nextparamoff-off);
+ nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
+
+ if (strncmp(ptran+off, "client_port=", 12) == 0) {
+ if (nextfieldoff - off > 12 && strncmp(ptran+off, "client_port=", 12) == 0) {
+ u_int16_t port;
+ uint numlen;
+ uint origoff;
@ -1583,7 +1630,9 @@
+
+static void nf_nat_rtsp_expected(struct nf_conn* ct, struct nf_conntrack_expect *exp)
+{
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) || LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,18,0)
+ struct nf_nat_range2 range;
+#elif LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) || LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
+ struct nf_nat_range range;
+#else
+ struct nf_nat_ipv4_range range;