Skip to content

Commit b32d2f3

Browse files
ummakynesdavem330
authored andcommitted
netfilter: nf_flow_table: move conntrack object to struct flow_offload
Simplify this code by storing the pointer to conntrack object in the flow_offload structure. Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4717b05 commit b32d2f3

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

include/net/netfilter/nf_flow_table.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct flow_offload_tuple_rhash {
7272

7373
struct flow_offload {
7474
struct flow_offload_tuple_rhash tuplehash[FLOW_OFFLOAD_DIR_MAX];
75+
struct nf_conn *ct;
7576
u32 flags;
7677
union {
7778
/* Your private driver data here. */

net/netfilter/nf_flow_table_core.c

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
struct flow_offload_entry {
1818
struct flow_offload flow;
19-
struct nf_conn *ct;
2019
struct rcu_head rcu_head;
2120
};
2221

@@ -79,7 +78,7 @@ flow_offload_alloc(struct nf_conn *ct, struct nf_flow_route *route)
7978
if (!dst_hold_safe(route->tuple[FLOW_OFFLOAD_DIR_REPLY].dst))
8079
goto err_dst_cache_reply;
8180

82-
entry->ct = ct;
81+
flow->ct = ct;
8382

8483
flow_offload_fill_dir(flow, ct, route, FLOW_OFFLOAD_DIR_ORIGINAL);
8584
flow_offload_fill_dir(flow, ct, route, FLOW_OFFLOAD_DIR_REPLY);
@@ -158,8 +157,8 @@ void flow_offload_free(struct flow_offload *flow)
158157
dst_release(flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].tuple.dst_cache);
159158
e = container_of(flow, struct flow_offload_entry, flow);
160159
if (flow->flags & FLOW_OFFLOAD_DYING)
161-
nf_ct_delete(e->ct, 0, 0);
162-
nf_ct_put(e->ct);
160+
nf_ct_delete(flow->ct, 0, 0);
161+
nf_ct_put(flow->ct);
163162
kfree_rcu(e, rcu_head);
164163
}
165164
EXPORT_SYMBOL_GPL(flow_offload_free);
@@ -232,34 +231,28 @@ static inline bool nf_flow_has_expired(const struct flow_offload *flow)
232231
static void flow_offload_del(struct nf_flowtable *flow_table,
233232
struct flow_offload *flow)
234233
{
235-
struct flow_offload_entry *e;
236-
237234
rhashtable_remove_fast(&flow_table->rhashtable,
238235
&flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].node,
239236
nf_flow_offload_rhash_params);
240237
rhashtable_remove_fast(&flow_table->rhashtable,
241238
&flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].node,
242239
nf_flow_offload_rhash_params);
243240

244-
e = container_of(flow, struct flow_offload_entry, flow);
245-
clear_bit(IPS_OFFLOAD_BIT, &e->ct->status);
241+
clear_bit(IPS_OFFLOAD_BIT, &flow->ct->status);
246242

247243
if (nf_flow_has_expired(flow))
248-
flow_offload_fixup_ct(e->ct);
244+
flow_offload_fixup_ct(flow->ct);
249245
else if (flow->flags & FLOW_OFFLOAD_TEARDOWN)
250-
flow_offload_fixup_ct_timeout(e->ct);
246+
flow_offload_fixup_ct_timeout(flow->ct);
251247

252248
flow_offload_free(flow);
253249
}
254250

255251
void flow_offload_teardown(struct flow_offload *flow)
256252
{
257-
struct flow_offload_entry *e;
258-
259253
flow->flags |= FLOW_OFFLOAD_TEARDOWN;
260254

261-
e = container_of(flow, struct flow_offload_entry, flow);
262-
flow_offload_fixup_ct_state(e->ct);
255+
flow_offload_fixup_ct_state(flow->ct);
263256
}
264257
EXPORT_SYMBOL_GPL(flow_offload_teardown);
265258

@@ -269,7 +262,6 @@ flow_offload_lookup(struct nf_flowtable *flow_table,
269262
{
270263
struct flow_offload_tuple_rhash *tuplehash;
271264
struct flow_offload *flow;
272-
struct flow_offload_entry *e;
273265
int dir;
274266

275267
tuplehash = rhashtable_lookup(&flow_table->rhashtable, tuple,
@@ -282,8 +274,7 @@ flow_offload_lookup(struct nf_flowtable *flow_table,
282274
if (flow->flags & (FLOW_OFFLOAD_DYING | FLOW_OFFLOAD_TEARDOWN))
283275
return NULL;
284276

285-
e = container_of(flow, struct flow_offload_entry, flow);
286-
if (unlikely(nf_ct_is_dying(e->ct)))
277+
if (unlikely(nf_ct_is_dying(flow->ct)))
287278
return NULL;
288279

289280
return tuplehash;
@@ -327,10 +318,8 @@ nf_flow_table_iterate(struct nf_flowtable *flow_table,
327318
static void nf_flow_offload_gc_step(struct flow_offload *flow, void *data)
328319
{
329320
struct nf_flowtable *flow_table = data;
330-
struct flow_offload_entry *e;
331321

332-
e = container_of(flow, struct flow_offload_entry, flow);
333-
if (nf_flow_has_expired(flow) || nf_ct_is_dying(e->ct) ||
322+
if (nf_flow_has_expired(flow) || nf_ct_is_dying(flow->ct) ||
334323
(flow->flags & (FLOW_OFFLOAD_DYING | FLOW_OFFLOAD_TEARDOWN)))
335324
flow_offload_del(flow_table, flow);
336325
}
@@ -485,15 +474,13 @@ EXPORT_SYMBOL_GPL(nf_flow_table_init);
485474
static void nf_flow_table_do_cleanup(struct flow_offload *flow, void *data)
486475
{
487476
struct net_device *dev = data;
488-
struct flow_offload_entry *e;
489-
490-
e = container_of(flow, struct flow_offload_entry, flow);
491477

492478
if (!dev) {
493479
flow_offload_teardown(flow);
494480
return;
495481
}
496-
if (net_eq(nf_ct_net(e->ct), dev_net(dev)) &&
482+
483+
if (net_eq(nf_ct_net(flow->ct), dev_net(dev)) &&
497484
(flow->tuplehash[0].tuple.iifidx == dev->ifindex ||
498485
flow->tuplehash[1].tuple.iifidx == dev->ifindex))
499486
flow_offload_dead(flow);

0 commit comments

Comments
 (0)