Skip to content

Commit 1a441a9

Browse files
w1ldptrdavem330
authored andcommitted
netfilter: flowtable: cache info of last offload
Modify flow table offload to cache the last ct info status that was passed to the driver offload callbacks by extending enum nf_flow_flags with new "NF_FLOW_HW_ESTABLISHED" flag. Set the flag if ctinfo was 'established' during last act_ct meta actions fill call. This infrastructure change is necessary to optimize promoting of UDP connections from 'new' to 'established' in following patches in this series. Signed-off-by: Vlad Buslov <vladbu@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8f84780 commit 1a441a9

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

include/net/netfilter/nf_flow_table.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct nf_flowtable_type {
5757
struct net_device *dev,
5858
enum flow_block_command cmd);
5959
int (*action)(struct net *net,
60-
const struct flow_offload *flow,
60+
struct flow_offload *flow,
6161
enum flow_offload_tuple_dir dir,
6262
struct nf_flow_rule *flow_rule);
6363
void (*free)(struct nf_flowtable *ft);
@@ -165,6 +165,7 @@ enum nf_flow_flags {
165165
NF_FLOW_HW_DEAD,
166166
NF_FLOW_HW_PENDING,
167167
NF_FLOW_HW_BIDIRECTIONAL,
168+
NF_FLOW_HW_ESTABLISHED,
168169
};
169170

170171
enum flow_offload_type {
@@ -313,10 +314,10 @@ void nf_flow_table_offload_flush_cleanup(struct nf_flowtable *flowtable);
313314
int nf_flow_table_offload_setup(struct nf_flowtable *flowtable,
314315
struct net_device *dev,
315316
enum flow_block_command cmd);
316-
int nf_flow_rule_route_ipv4(struct net *net, const struct flow_offload *flow,
317+
int nf_flow_rule_route_ipv4(struct net *net, struct flow_offload *flow,
317318
enum flow_offload_tuple_dir dir,
318319
struct nf_flow_rule *flow_rule);
319-
int nf_flow_rule_route_ipv6(struct net *net, const struct flow_offload *flow,
320+
int nf_flow_rule_route_ipv6(struct net *net, struct flow_offload *flow,
320321
enum flow_offload_tuple_dir dir,
321322
struct nf_flow_rule *flow_rule);
322323

net/netfilter/nf_flow_table_inet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb,
3939
}
4040

4141
static int nf_flow_rule_route_inet(struct net *net,
42-
const struct flow_offload *flow,
42+
struct flow_offload *flow,
4343
enum flow_offload_tuple_dir dir,
4444
struct nf_flow_rule *flow_rule)
4545
{

net/netfilter/nf_flow_table_offload.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ nf_flow_rule_route_common(struct net *net, const struct flow_offload *flow,
679679
return 0;
680680
}
681681

682-
int nf_flow_rule_route_ipv4(struct net *net, const struct flow_offload *flow,
682+
int nf_flow_rule_route_ipv4(struct net *net, struct flow_offload *flow,
683683
enum flow_offload_tuple_dir dir,
684684
struct nf_flow_rule *flow_rule)
685685
{
@@ -704,7 +704,7 @@ int nf_flow_rule_route_ipv4(struct net *net, const struct flow_offload *flow,
704704
}
705705
EXPORT_SYMBOL_GPL(nf_flow_rule_route_ipv4);
706706

707-
int nf_flow_rule_route_ipv6(struct net *net, const struct flow_offload *flow,
707+
int nf_flow_rule_route_ipv6(struct net *net, struct flow_offload *flow,
708708
enum flow_offload_tuple_dir dir,
709709
struct nf_flow_rule *flow_rule)
710710
{
@@ -735,7 +735,7 @@ nf_flow_offload_rule_alloc(struct net *net,
735735
{
736736
const struct nf_flowtable *flowtable = offload->flowtable;
737737
const struct flow_offload_tuple *tuple, *other_tuple;
738-
const struct flow_offload *flow = offload->flow;
738+
struct flow_offload *flow = offload->flow;
739739
struct dst_entry *other_dst = NULL;
740740
struct nf_flow_rule *flow_rule;
741741
int err = -ENOMEM;

net/sched/act_ct.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,18 @@ tcf_ct_flow_table_add_action_nat_udp(const struct nf_conntrack_tuple *tuple,
170170

171171
static void tcf_ct_flow_table_add_action_meta(struct nf_conn *ct,
172172
enum ip_conntrack_dir dir,
173+
enum ip_conntrack_info ctinfo,
173174
struct flow_action *action)
174175
{
175176
struct nf_conn_labels *ct_labels;
176177
struct flow_action_entry *entry;
177-
enum ip_conntrack_info ctinfo;
178178
u32 *act_ct_labels;
179179

180180
entry = tcf_ct_flow_table_flow_action_get_next(action);
181181
entry->id = FLOW_ACTION_CT_METADATA;
182182
#if IS_ENABLED(CONFIG_NF_CONNTRACK_MARK)
183183
entry->ct_metadata.mark = READ_ONCE(ct->mark);
184184
#endif
185-
ctinfo = dir == IP_CT_DIR_ORIGINAL ? IP_CT_ESTABLISHED :
186-
IP_CT_ESTABLISHED_REPLY;
187185
/* aligns with the CT reference on the SKB nf_ct_set */
188186
entry->ct_metadata.cookie = (unsigned long)ct | ctinfo;
189187
entry->ct_metadata.orig_dir = dir == IP_CT_DIR_ORIGINAL;
@@ -237,22 +235,26 @@ static int tcf_ct_flow_table_add_action_nat(struct net *net,
237235
}
238236

239237
static int tcf_ct_flow_table_fill_actions(struct net *net,
240-
const struct flow_offload *flow,
238+
struct flow_offload *flow,
241239
enum flow_offload_tuple_dir tdir,
242240
struct nf_flow_rule *flow_rule)
243241
{
244242
struct flow_action *action = &flow_rule->rule->action;
245243
int num_entries = action->num_entries;
246244
struct nf_conn *ct = flow->ct;
245+
enum ip_conntrack_info ctinfo;
247246
enum ip_conntrack_dir dir;
248247
int i, err;
249248

250249
switch (tdir) {
251250
case FLOW_OFFLOAD_DIR_ORIGINAL:
252251
dir = IP_CT_DIR_ORIGINAL;
252+
ctinfo = IP_CT_ESTABLISHED;
253+
set_bit(NF_FLOW_HW_ESTABLISHED, &flow->flags);
253254
break;
254255
case FLOW_OFFLOAD_DIR_REPLY:
255256
dir = IP_CT_DIR_REPLY;
257+
ctinfo = IP_CT_ESTABLISHED_REPLY;
256258
break;
257259
default:
258260
return -EOPNOTSUPP;
@@ -262,7 +264,7 @@ static int tcf_ct_flow_table_fill_actions(struct net *net,
262264
if (err)
263265
goto err_nat;
264266

265-
tcf_ct_flow_table_add_action_meta(ct, dir, action);
267+
tcf_ct_flow_table_add_action_meta(ct, dir, ctinfo, action);
266268
return 0;
267269

268270
err_nat:

0 commit comments

Comments
 (0)