Skip to content

Commit 8543e6e

Browse files
committed
netfilter: flowtable: simplify route logic
jira LE-1907 Rebuild_History Non-Buildable kernel-5.14.0-427.40.1.el9_4 commit-author Pablo Neira Ayuso <pablo@netfilter.org> commit fa502c8 Grab reference to dst from skbuff earlier to simplify route caching. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Florian Westphal <fw@strlen.de> (cherry picked from commit fa502c8) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent e905e5b commit 8543e6e

File tree

3 files changed

+13
-27
lines changed

3 files changed

+13
-27
lines changed

include/net/netfilter/nf_flow_table.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ nf_flow_table_offload_del_cb(struct nf_flowtable *flow_table,
274274
flow_table->type->put(flow_table);
275275
}
276276

277-
int flow_offload_route_init(struct flow_offload *flow,
278-
const struct nf_flow_route *route);
277+
void flow_offload_route_init(struct flow_offload *flow,
278+
const struct nf_flow_route *route);
279279

280280
int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow);
281281
void flow_offload_refresh(struct nf_flowtable *flow_table,

net/netfilter/nf_flow_table_core.c

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ static int flow_offload_fill_route(struct flow_offload *flow,
124124
break;
125125
case FLOW_OFFLOAD_XMIT_XFRM:
126126
case FLOW_OFFLOAD_XMIT_NEIGH:
127-
if (!dst_hold_safe(route->tuple[dir].dst))
128-
return -1;
129-
130127
flow_tuple->dst_cache = dst;
131128
flow_tuple->dst_cookie = flow_offload_dst_cookie(flow_tuple);
132129
break;
@@ -147,27 +144,12 @@ static void nft_flow_dst_release(struct flow_offload *flow,
147144
dst_release(flow->tuplehash[dir].tuple.dst_cache);
148145
}
149146

150-
int flow_offload_route_init(struct flow_offload *flow,
147+
void flow_offload_route_init(struct flow_offload *flow,
151148
const struct nf_flow_route *route)
152149
{
153-
int err;
154-
155-
err = flow_offload_fill_route(flow, route, FLOW_OFFLOAD_DIR_ORIGINAL);
156-
if (err < 0)
157-
return err;
158-
159-
err = flow_offload_fill_route(flow, route, FLOW_OFFLOAD_DIR_REPLY);
160-
if (err < 0)
161-
goto err_route_reply;
162-
150+
flow_offload_fill_route(flow, route, FLOW_OFFLOAD_DIR_ORIGINAL);
151+
flow_offload_fill_route(flow, route, FLOW_OFFLOAD_DIR_REPLY);
163152
flow->type = NF_FLOW_OFFLOAD_ROUTE;
164-
165-
return 0;
166-
167-
err_route_reply:
168-
nft_flow_dst_release(flow, FLOW_OFFLOAD_DIR_ORIGINAL);
169-
170-
return err;
171153
}
172154
EXPORT_SYMBOL_GPL(flow_offload_route_init);
173155

net/netfilter/nft_flow_offload.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,14 @@ static int nft_flow_route(const struct nft_pktinfo *pkt,
240240
break;
241241
}
242242

243+
if (!dst_hold_safe(this_dst))
244+
return -ENOENT;
245+
243246
nf_route(nft_net(pkt), &other_dst, &fl, false, nft_pf(pkt));
244-
if (!other_dst)
247+
if (!other_dst) {
248+
dst_release(this_dst);
245249
return -ENOENT;
250+
}
246251

247252
nft_default_forward_path(route, this_dst, dir);
248253
nft_default_forward_path(route, other_dst, !dir);
@@ -326,8 +331,7 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,
326331
if (!flow)
327332
goto err_flow_alloc;
328333

329-
if (flow_offload_route_init(flow, &route) < 0)
330-
goto err_flow_add;
334+
flow_offload_route_init(flow, &route);
331335

332336
if (tcph) {
333337
ct->proto.tcp.seen[0].flags |= IP_CT_TCP_FLAG_BE_LIBERAL;
@@ -338,12 +342,12 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,
338342
if (ret < 0)
339343
goto err_flow_add;
340344

341-
dst_release(route.tuple[!dir].dst);
342345
return;
343346

344347
err_flow_add:
345348
flow_offload_free(flow);
346349
err_flow_alloc:
350+
dst_release(route.tuple[dir].dst);
347351
dst_release(route.tuple[!dir].dst);
348352
err_flow_route:
349353
clear_bit(IPS_OFFLOAD_BIT, &ct->status);

0 commit comments

Comments
 (0)