Repository navigation
Expand file tree
/
Copy pathhack-conntrack-events.patch
More file actions
142 lines (127 loc) · 5.39 KB
/
Copy pathhack-conntrack-events.patch
File metadata and controls
142 lines (127 loc) · 5.39 KB
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
139
140
141
142
commit 0bff241af47f293d27b908ab82a4e2ec5d62385f
Author: Ed W <lists@wildgooses.com>
Date: Wed Oct 24 23:11:44 2012 +0100
incredibly nasty hack for nDPI + conntrack/netlink
In recent kernels, only one listener can register for
notification of conntrack events. This is done for
performance reasons and no other in kernel module cares.
This incredibly nasty hack allows a second listener to
register for conntrack notifications.
Use at your peril. No warranty included...
diff --git a/include/net/netfilter/nf_conntrack_ecache.h b/include/net/netfilter/nf_conntrack_ecache.h
index a88fb69..d39af41 100644
--- a/include/net/netfilter/nf_conntrack_ecache.h
+++ b/include/net/netfilter/nf_conntrack_ecache.h
@@ -78,7 +78,8 @@ nf_conntrack_event_cache(enum ip_conntrack_events event, struct nf_conn *ct)
struct net *net = nf_ct_net(ct);
struct nf_conntrack_ecache *e;
- if (net->ct.nf_conntrack_event_cb == NULL)
+ if ( (net->ct.nf_conntrack_event_cb == NULL) &&
+ (net->ct.nf_conntrack_event_cb_2 == NULL) )
return;
e = nf_ct_ecache_find(ct);
@@ -97,11 +98,14 @@ nf_conntrack_eventmask_report(unsigned int eventmask,
int ret = 0;
struct net *net = nf_ct_net(ct);
struct nf_ct_event_notifier *notify;
+ struct nf_ct_event_notifier *notify_2;
struct nf_conntrack_ecache *e;
rcu_read_lock();
+ /* Incredibly nasty duplication in order to hack second event */
notify = rcu_dereference(net->ct.nf_conntrack_event_cb);
- if (notify == NULL)
+ notify_2 = rcu_dereference(net->ct.nf_conntrack_event_cb_2);
+ if ((notify == NULL) && (notify_2 == NULL))
goto out_unlock;
e = nf_ct_ecache_find(ct);
@@ -120,7 +124,8 @@ nf_conntrack_eventmask_report(unsigned int eventmask,
if (!((eventmask | missed) & e->ctmask))
goto out_unlock;
- ret = notify->fcn(eventmask | missed, &item);
+ ret = min( notify ? notify->fcn(eventmask | missed, &item) : 0,
+ notify_2 ? notify_2->fcn(eventmask | missed, &item) : 0 );
if (unlikely(ret < 0 || missed)) {
spin_lock_bh(&ct->lock);
if (ret < 0) {
diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
index 7a911ec..24a78d3 100644
--- a/include/net/netns/conntrack.h
+++ b/include/net/netns/conntrack.h
@@ -19,6 +19,7 @@ struct netns_ct {
struct hlist_nulls_head dying;
struct ip_conntrack_stat __percpu *stat;
struct nf_ct_event_notifier __rcu *nf_conntrack_event_cb;
+ struct nf_ct_event_notifier __rcu *nf_conntrack_event_cb_2;
struct nf_exp_event_notifier __rcu *nf_expect_event_cb;
int sysctl_events;
unsigned int sysctl_events_retry_timeout;
diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
index 14af632..9535ab7 100644
--- a/net/netfilter/nf_conntrack_ecache.c
+++ b/net/netfilter/nf_conntrack_ecache.c
@@ -33,12 +33,15 @@ void nf_ct_deliver_cached_events(struct nf_conn *ct)
{
struct net *net = nf_ct_net(ct);
unsigned long events;
+ /* Incredibly nasty duplication in order to hack second event */
struct nf_ct_event_notifier *notify;
+ struct nf_ct_event_notifier *notify_2;
struct nf_conntrack_ecache *e;
rcu_read_lock();
notify = rcu_dereference(net->ct.nf_conntrack_event_cb);
- if (notify == NULL)
+ notify_2 = rcu_dereference(net->ct.nf_conntrack_event_cb_2);
+ if ( (notify == NULL) && (notify_2 == NULL) )
goto out_unlock;
e = nf_ct_ecache_find(ct);
@@ -62,7 +65,8 @@ void nf_ct_deliver_cached_events(struct nf_conn *ct)
if (!((events | missed) & e->ctmask))
goto out_unlock;
- ret = notify->fcn(events | missed, &item);
+ ret = min( notify ? notify->fcn(events | missed, &item) : 0,
+ notify_2 ? notify_2->fcn(events | missed, &item) : 0);
if (unlikely(ret < 0 || missed)) {
spin_lock_bh(&ct->lock);
if (ret < 0)
@@ -83,15 +87,21 @@ int nf_conntrack_register_notifier(struct net *net,
{
int ret = 0;
struct nf_ct_event_notifier *notify;
+ struct nf_ct_event_notifier *notify_2;
mutex_lock(&nf_ct_ecache_mutex);
notify = rcu_dereference_protected(net->ct.nf_conntrack_event_cb,
lockdep_is_held(&nf_ct_ecache_mutex));
- if (notify != NULL) {
+ notify_2 = rcu_dereference_protected(net->ct.nf_conntrack_event_cb_2,
+ lockdep_is_held(&nf_ct_ecache_mutex));
+ if ( (notify != NULL) && (notify_2 != NULL) ) {
ret = -EBUSY;
goto out_unlock;
}
- rcu_assign_pointer(net->ct.nf_conntrack_event_cb, new);
+ if (notify == NULL)
+ rcu_assign_pointer(net->ct.nf_conntrack_event_cb, new);
+ else
+ rcu_assign_pointer(net->ct.nf_conntrack_event_cb_2, new);
mutex_unlock(&nf_ct_ecache_mutex);
return ret;
@@ -105,12 +115,18 @@ void nf_conntrack_unregister_notifier(struct net *net,
struct nf_ct_event_notifier *new)
{
struct nf_ct_event_notifier *notify;
+ struct nf_ct_event_notifier *notify_2;
mutex_lock(&nf_ct_ecache_mutex);
notify = rcu_dereference_protected(net->ct.nf_conntrack_event_cb,
lockdep_is_held(&nf_ct_ecache_mutex));
- BUG_ON(notify != new);
- RCU_INIT_POINTER(net->ct.nf_conntrack_event_cb, NULL);
+ notify_2 = rcu_dereference_protected(net->ct.nf_conntrack_event_cb_2,
+ lockdep_is_held(&nf_ct_ecache_mutex));
+ BUG_ON((notify != new) || (notify_2 != new));
+ if (notify == new)
+ RCU_INIT_POINTER(net->ct.nf_conntrack_event_cb, NULL);
+ else
+ RCU_INIT_POINTER(net->ct.nf_conntrack_event_cb_2, NULL);
mutex_unlock(&nf_ct_ecache_mutex);
}
EXPORT_SYMBOL_GPL(nf_conntrack_unregister_notifier);