Skip to content

Commit 1391e06

Browse files
author
Xin Long
committed
net: move add ct helper function to nf_conntrack_helper for ovs and tc
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2106859 Tested: compile only commit f96cba2 Author: Xin Long <lucien.xin@gmail.com> Date: Sun Nov 6 15:34:15 2022 -0500 net: move add ct helper function to nf_conntrack_helper for ovs and tc Move ovs_ct_add_helper from openvswitch to nf_conntrack_helper and rename as nf_ct_add_helper, so that it can be used in TC act_ct in the next patch. Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: Xin Long <lucien.xin@gmail.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Xin Long <lxin@redhat.com>
1 parent d1fffd8 commit 1391e06

File tree

3 files changed

+38
-39
lines changed

3 files changed

+38
-39
lines changed

include/net/netfilter/nf_conntrack_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,
117117

118118
int nf_ct_helper(struct sk_buff *skb, struct nf_conn *ct,
119119
enum ip_conntrack_info ctinfo, u16 proto);
120+
int nf_ct_add_helper(struct nf_conn *ct, const char *name, u8 family,
121+
u8 proto, bool nat, struct nf_conntrack_helper **hp);
120122

121123
void nf_ct_helper_destroy(struct nf_conn *ct);
122124

net/netfilter/nf_conntrack_helper.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,37 @@ int nf_ct_helper(struct sk_buff *skb, struct nf_conn *ct,
356356
}
357357
EXPORT_SYMBOL_GPL(nf_ct_helper);
358358

359+
int nf_ct_add_helper(struct nf_conn *ct, const char *name, u8 family,
360+
u8 proto, bool nat, struct nf_conntrack_helper **hp)
361+
{
362+
struct nf_conntrack_helper *helper;
363+
struct nf_conn_help *help;
364+
int ret = 0;
365+
366+
helper = nf_conntrack_helper_try_module_get(name, family, proto);
367+
if (!helper)
368+
return -EINVAL;
369+
370+
help = nf_ct_helper_ext_add(ct, GFP_KERNEL);
371+
if (!help) {
372+
nf_conntrack_helper_put(helper);
373+
return -ENOMEM;
374+
}
375+
#if IS_ENABLED(CONFIG_NF_NAT)
376+
if (nat) {
377+
ret = nf_nat_helper_try_module_get(name, family, proto);
378+
if (ret) {
379+
nf_conntrack_helper_put(helper);
380+
return ret;
381+
}
382+
}
383+
#endif
384+
rcu_assign_pointer(help->helper, helper);
385+
*hp = helper;
386+
return ret;
387+
}
388+
EXPORT_SYMBOL_GPL(nf_ct_add_helper);
389+
359390
/* appropriate ct lock protecting must be taken by caller */
360391
static int unhelp(struct nf_conn *ct, void *me)
361392
{

net/openvswitch/conntrack.c

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,43 +1291,6 @@ int ovs_ct_clear(struct sk_buff *skb, struct sw_flow_key *key)
12911291
return 0;
12921292
}
12931293

1294-
static int ovs_ct_add_helper(struct ovs_conntrack_info *info, const char *name,
1295-
const struct sw_flow_key *key, bool log)
1296-
{
1297-
struct nf_conntrack_helper *helper;
1298-
struct nf_conn_help *help;
1299-
int ret = 0;
1300-
1301-
helper = nf_conntrack_helper_try_module_get(name, info->family,
1302-
key->ip.proto);
1303-
if (!helper) {
1304-
OVS_NLERR(log, "Unknown helper \"%s\"", name);
1305-
return -EINVAL;
1306-
}
1307-
1308-
help = nf_ct_helper_ext_add(info->ct, GFP_KERNEL);
1309-
if (!help) {
1310-
nf_conntrack_helper_put(helper);
1311-
return -ENOMEM;
1312-
}
1313-
1314-
#if IS_ENABLED(CONFIG_NF_NAT)
1315-
if (info->nat) {
1316-
ret = nf_nat_helper_try_module_get(name, info->family,
1317-
key->ip.proto);
1318-
if (ret) {
1319-
nf_conntrack_helper_put(helper);
1320-
OVS_NLERR(log, "Failed to load \"%s\" NAT helper, error: %d",
1321-
name, ret);
1322-
return ret;
1323-
}
1324-
}
1325-
#endif
1326-
rcu_assign_pointer(help->helper, helper);
1327-
info->helper = helper;
1328-
return ret;
1329-
}
1330-
13311294
#if IS_ENABLED(CONFIG_NF_NAT)
13321295
static int parse_nat(const struct nlattr *attr,
13331296
struct ovs_conntrack_info *info, bool log)
@@ -1661,9 +1624,12 @@ int ovs_ct_copy_action(struct net *net, const struct nlattr *attr,
16611624
}
16621625

16631626
if (helper) {
1664-
err = ovs_ct_add_helper(&ct_info, helper, key, log);
1665-
if (err)
1627+
err = nf_ct_add_helper(ct_info.ct, helper, ct_info.family,
1628+
key->ip.proto, ct_info.nat, &ct_info.helper);
1629+
if (err) {
1630+
OVS_NLERR(log, "Failed to add %s helper %d", helper, err);
16661631
goto err_free_ct;
1632+
}
16671633
}
16681634

16691635
err = ovs_nla_add_action(sfa, OVS_ACTION_ATTR_CT, &ct_info,

0 commit comments

Comments
 (0)