File: 0007-Fix-build-on-v5.15-ct_event.patch

package info (click to toggle)
iptables-netflow 2.6-7.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,632 kB
  • sloc: ansic: 6,831; sh: 896; ruby: 619; makefile: 239
file content (138 lines) | stat: -rw-r--r-- 5,083 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
From 6a55739a9bf9fb890dbd1aa338057f394b766ab8 Mon Sep 17 00:00:00 2001
From: ABC <abc@openwall.com>
Date: Thu, 25 Nov 2021 21:07:29 +0300
Subject: [PATCH 07/17] Fix build on v5.15 (ct_event)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

    CC [M]  ipt_NETFLOW.o
  ipt_NETFLOW.c: In function ‘netflow_conntrack_event’:
  ipt_NETFLOW.c:4622:31: error: ‘struct nf_ct_event_notifier’ has no member named ‘fcn’
   4622 |                 ret = notifier->fcn(events, item);
	|                               ^~
  ipt_NETFLOW.c: At top level:
  ipt_NETFLOW.c:4687:10: error: ‘struct nf_ct_event_notifier’ has no member named ‘fcn’
   4687 |         .fcn = netflow_conntrack_event
	|          ^~~
  ipt_NETFLOW.c:4687:16: error: initialization of ‘int (*)(unsigned int,  const struct nf_ct_event *)’ from incompatible pointer type ‘int (*)(const unsigned int,  struct nf_ct_event *)’ [-Werror=incompatible-pointer-types]
   4687 |         .fcn = netflow_conntrack_event
	|                ^~~~~~~~~~~~~~~~~~~~~~~
  ipt_NETFLOW.c:4687:16: note: (near initialization for ‘ctnl_notifier.ct_event’)
  ipt_NETFLOW.c: In function ‘unset_notifier_cb’:
  ipt_NETFLOW.c:5455:25: error: too many arguments to function ‘nf_conntrack_unregister_notifier’
   5455 |                         nf_conntrack_unregister_notifier(NET_ARG &ctnl_notifier);
	|                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  In file included from ./include/net/netfilter/nf_conntrack_core.h:18,
		   from ipt_NETFLOW.c:68:
  ./include/net/netfilter/nf_conntrack_ecache.h:88:6: note: declared here
     88 | void nf_conntrack_unregister_notifier(struct net *net);
	|      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reported-by: https://github.com/rcmcronny
Fixes: #186
---
 compat.h       |  4 ++++
 gen_compat_def | 16 ++++++++++++++++
 ipt_NETFLOW.c  | 16 +++++++++++-----
 3 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/compat.h b/compat.h
index c498bb8..6be9d6b 100644
--- a/compat.h
+++ b/compat.h
@@ -781,4 +781,8 @@ struct module *find_module(const char *name)
 # endif
 #endif
 
+#ifndef HAVE_NF_CT_EVENT_NOTIFIER_CT_EVENT
+# define ct_event fcn
+#endif
+
 #endif /* COMPAT_NETFLOW_H */
diff --git a/gen_compat_def b/gen_compat_def
index 011eb0c..35803a2 100755
--- a/gen_compat_def
+++ b/gen_compat_def
@@ -90,6 +90,20 @@ kbuild_test_struct() {
 	EOF
 }
 
+# Test that struct have member
+kbuild_test_member() {
+  echo -n "Test member $* " >&2
+  structname=${1%.*}
+  member=${1#*.}
+  def=${1^^}
+  def=${def//./_}
+  kbuild_test_compile $def "struct $1" ${2-} <<-EOF
+	#include <linux/module.h>
+	${2:+#include <$2>}
+	MODULE_LICENSE("GPL");
+	typeof(((struct $structname*)0)->$member) test;
+	EOF
+}
 echo "// Autogenerated for $KDIR"
 echo
 
@@ -110,6 +124,8 @@ kbuild_test_symbol put_unaligned_be24 asm/unaligned.h
 # totalram_pages changed from atomic to inline function.
 kbuild_test_symbol totalram_pages linux/mm.h
 kbuild_test_ref    totalram_pages linux/mm.h
+# b86c0e6429da ("netfilter: ecache: prepare for event notifier merge")
+kbuild_test_member nf_ct_event_notifier.ct_event net/netfilter/nf_conntrack_ecache.h
 
 echo "// End of compat_def.h"
 
diff --git a/ipt_NETFLOW.c b/ipt_NETFLOW.c
index 8f70a1a..e14a36f 100644
--- a/ipt_NETFLOW.c
+++ b/ipt_NETFLOW.c
@@ -4597,7 +4597,7 @@ static void rate_timer_calc(
 #ifdef CONFIG_NF_NAT_NEEDED
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)
 static struct nf_ct_event_notifier *saved_event_cb __read_mostly = NULL;
-static int netflow_conntrack_event(const unsigned int events, struct nf_ct_event *item)
+static int netflow_conntrack_event(const unsigned int events, const struct nf_ct_event *item)
 #else
 static int netflow_conntrack_event(struct notifier_block *this, unsigned long events, void *ptr)
 #endif
@@ -4619,7 +4619,7 @@ static int netflow_conntrack_event(struct notifier_block *this, unsigned long ev
 	/* Call netlink first. */
 	notifier = rcu_dereference(saved_event_cb);
 	if (likely(notifier))
-		ret = notifier->fcn(events, item);
+		ret = notifier->ct_event(events, item);
 #endif
 	if (unlikely(!natevents))
 		return ret;
@@ -4684,7 +4684,7 @@ static struct notifier_block ctnl_notifier = {
 };
 #else
 static struct nf_ct_event_notifier ctnl_notifier = {
-	.fcn = netflow_conntrack_event
+	.ct_event = netflow_conntrack_event
 };
 #endif /* since 2.6.31 */
 #endif /* CONFIG_NF_NAT_NEEDED */
@@ -5451,9 +5451,15 @@ static void unset_notifier_cb(NET_STRUCT)
 
 	notifier = rcu_dereference(nf_conntrack_event_cb);
 	if (notifier == &ctnl_notifier) {
-		if (saved_event_cb == NULL)
+		if (saved_event_cb == NULL) {
+#ifdef HAVE_NF_CT_EVENT_NOTIFIER_CT_EVENT
+			/* b86c0e6429da ("netfilter: ecache: prepare for event
+			 * notifier merge") */
+			nf_conntrack_unregister_notifier(net);
+#else
 			nf_conntrack_unregister_notifier(NET_ARG &ctnl_notifier);
-		else
+#endif
+		} else
 			rcu_assign_pointer(nf_conntrack_event_cb, saved_event_cb);
 	} else
 		printk(KERN_ERR "ipt_NETFLOW: natevents already disabled.\n");
-- 
2.39.5