Skip to content

Commit 4fe6185

Browse files
committed
netfilter: conntrack: un-inline nf_ct_ecache_ext_add
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2111270 Upstream Status: commit b0a7ab4 commit b0a7ab4 Author: Florian Westphal <[email protected]> Date: Mon Apr 25 15:15:42 2022 +0200 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 <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: Florian Westphal <[email protected]>
1 parent f75b8da commit 4fe6185

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
@@ -1709,7 +1709,9 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,
17091709
struct nf_conn *ct;
17101710
struct nf_conn_help *help;
17111711
struct nf_conntrack_tuple repl_tuple;
1712+
#ifdef CONFIG_NF_CONNTRACK_EVENTS
17121713
struct nf_conntrack_ecache *ecache;
1714+
#endif
17131715
struct nf_conntrack_expect *exp = NULL;
17141716
const struct nf_conntrack_zone *zone;
17151717
struct nf_conn_timeout *timeout_ext;
@@ -1742,10 +1744,16 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,
17421744
nf_ct_tstamp_ext_add(ct, GFP_ATOMIC);
17431745
nf_ct_labels_ext_add(ct);
17441746

1747+
#ifdef CONFIG_NF_CONNTRACK_EVENTS
17451748
ecache = tmpl ? nf_ct_ecache_find(tmpl) : NULL;
1746-
nf_ct_ecache_ext_add(ct, ecache ? ecache->ctmask : 0,
1747-
ecache ? ecache->expmask : 0,
1748-
GFP_ATOMIC);
1749+
1750+
if (!nf_ct_ecache_ext_add(ct, ecache ? ecache->ctmask : 0,
1751+
ecache ? ecache->expmask : 0,
1752+
GFP_ATOMIC)) {
1753+
nf_conntrack_free(ct);
1754+
return ERR_PTR(-ENOMEM);
1755+
}
1756+
#endif
17491757

17501758
cnet = nf_ct_pernet(net);
17511759
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)