Skip to content

Commit b0a7ab4

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: conntrack: un-inline nf_ct_ecache_ext_add
Only called when new ct is allocated or the extension isn't present. This function will be extended, place this in the conntrack module instead of inlining. The callers already depend on nf_conntrack module. Return value is changed to bool, noone used the returned pointer. Make sure that the core drops the newly allocated conntrack if the extension is requested but can't be added. This makes it necessary to ifdef the section, as the stub always returns false we'd drop every new conntrack if the the ecache extension is disabled in kconfig. Add from data path (xt_CT, nft_ct) is unchanged. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 2794cdb commit b0a7ab4

File tree

3 files changed

+38
-28
lines changed

3 files changed

+38
-28
lines changed

include/net/netfilter/nf_conntrack_ecache.h

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,6 @@ nf_ct_ecache_find(const struct nf_conn *ct)
3636
#endif
3737
}
3838

39-
static inline struct nf_conntrack_ecache *
40-
nf_ct_ecache_ext_add(struct nf_conn *ct, u16 ctmask, u16 expmask, gfp_t gfp)
41-
{
42-
#ifdef CONFIG_NF_CONNTRACK_EVENTS
43-
struct net *net = nf_ct_net(ct);
44-
struct nf_conntrack_ecache *e;
45-
46-
if (!ctmask && !expmask && net->ct.sysctl_events) {
47-
ctmask = ~0;
48-
expmask = ~0;
49-
}
50-
if (!ctmask && !expmask)
51-
return NULL;
52-
53-
e = nf_ct_ext_add(ct, NF_CT_EXT_ECACHE, gfp);
54-
if (e) {
55-
e->ctmask = ctmask;
56-
e->expmask = expmask;
57-
}
58-
return e;
59-
#else
60-
return NULL;
61-
#endif
62-
}
63-
6439
#ifdef CONFIG_NF_CONNTRACK_EVENTS
6540

6641
/* This structure is passed to event handler */
@@ -89,6 +64,7 @@ void nf_ct_deliver_cached_events(struct nf_conn *ct);
8964
int nf_conntrack_eventmask_report(unsigned int eventmask, struct nf_conn *ct,
9065
u32 portid, int report);
9166

67+
bool nf_ct_ecache_ext_add(struct nf_conn *ct, u16 ctmask, u16 expmask, gfp_t gfp);
9268
#else
9369

9470
static inline void nf_ct_deliver_cached_events(const struct nf_conn *ct)
@@ -103,6 +79,10 @@ static inline int nf_conntrack_eventmask_report(unsigned int eventmask,
10379
return 0;
10480
}
10581

82+
static inline bool nf_ct_ecache_ext_add(struct nf_conn *ct, u16 ctmask, u16 expmask, gfp_t gfp)
83+
{
84+
return false;
85+
}
10686
#endif
10787

10888
static inline void

net/netfilter/nf_conntrack_core.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,9 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,
16981698
struct nf_conn *ct;
16991699
struct nf_conn_help *help;
17001700
struct nf_conntrack_tuple repl_tuple;
1701+
#ifdef CONFIG_NF_CONNTRACK_EVENTS
17011702
struct nf_conntrack_ecache *ecache;
1703+
#endif
17021704
struct nf_conntrack_expect *exp = NULL;
17031705
const struct nf_conntrack_zone *zone;
17041706
struct nf_conn_timeout *timeout_ext;
@@ -1731,10 +1733,16 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,
17311733
nf_ct_tstamp_ext_add(ct, GFP_ATOMIC);
17321734
nf_ct_labels_ext_add(ct);
17331735

1736+
#ifdef CONFIG_NF_CONNTRACK_EVENTS
17341737
ecache = tmpl ? nf_ct_ecache_find(tmpl) : NULL;
1735-
nf_ct_ecache_ext_add(ct, ecache ? ecache->ctmask : 0,
1736-
ecache ? ecache->expmask : 0,
1737-
GFP_ATOMIC);
1738+
1739+
if (!nf_ct_ecache_ext_add(ct, ecache ? ecache->ctmask : 0,
1740+
ecache ? ecache->expmask : 0,
1741+
GFP_ATOMIC)) {
1742+
nf_conntrack_free(ct);
1743+
return ERR_PTR(-ENOMEM);
1744+
}
1745+
#endif
17381746

17391747
cnet = nf_ct_pernet(net);
17401748
if (cnet->expect_count) {

net/netfilter/nf_conntrack_ecache.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,28 @@ void nf_conntrack_ecache_work(struct net *net, enum nf_ct_ecache_state state)
297297
}
298298
}
299299

300+
bool nf_ct_ecache_ext_add(struct nf_conn *ct, u16 ctmask, u16 expmask, gfp_t gfp)
301+
{
302+
struct net *net = nf_ct_net(ct);
303+
struct nf_conntrack_ecache *e;
304+
305+
if (!ctmask && !expmask && net->ct.sysctl_events) {
306+
ctmask = ~0;
307+
expmask = ~0;
308+
}
309+
if (!ctmask && !expmask)
310+
return false;
311+
312+
e = nf_ct_ext_add(ct, NF_CT_EXT_ECACHE, gfp);
313+
if (e) {
314+
e->ctmask = ctmask;
315+
e->expmask = expmask;
316+
}
317+
318+
return e != NULL;
319+
}
320+
EXPORT_SYMBOL_GPL(nf_ct_ecache_ext_add);
321+
300322
#define NF_CT_EVENTS_DEFAULT 1
301323
static int nf_ct_events __read_mostly = NF_CT_EVENTS_DEFAULT;
302324

0 commit comments

Comments
 (0)