Skip to content

Commit

Permalink
netfilter: introduce nf_conntrack_helper_put helper function
Browse files Browse the repository at this point in the history
And convert module_put invocation to nf_conntrack_helper_put, this is
prepared for the followup patch, which will add a refcnt for cthelper,
so we can reject the deleting request when cthelper is in use.

Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Liping Zhang authored and Pablo Neira Ayuso committed May 15, 2017
1 parent d110a39 commit d91fc59
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions include/net/netfilter/nf_conntrack_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ struct nf_conntrack_helper *__nf_conntrack_helper_find(const char *name,
struct nf_conntrack_helper *nf_conntrack_helper_try_module_get(const char *name,
u16 l3num,
u8 protonum);
void nf_conntrack_helper_put(struct nf_conntrack_helper *helper);

void nf_ct_helper_init(struct nf_conntrack_helper *helper,
u16 l3num, u16 protonum, const char *name,
u16 default_port, u16 spec_port, u32 id,
Expand Down
6 changes: 6 additions & 0 deletions net/netfilter/nf_conntrack_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ nf_conntrack_helper_try_module_get(const char *name, u16 l3num, u8 protonum)
}
EXPORT_SYMBOL_GPL(nf_conntrack_helper_try_module_get);

void nf_conntrack_helper_put(struct nf_conntrack_helper *helper)
{
module_put(helper->me);
}
EXPORT_SYMBOL_GPL(nf_conntrack_helper_put);

struct nf_conn_help *
nf_ct_helper_ext_add(struct nf_conn *ct,
struct nf_conntrack_helper *helper, gfp_t gfp)
Expand Down
4 changes: 2 additions & 2 deletions net/netfilter/nft_ct.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,9 @@ static void nft_ct_helper_obj_destroy(struct nft_object *obj)
struct nft_ct_helper_obj *priv = nft_obj_data(obj);

if (priv->helper4)
module_put(priv->helper4->me);
nf_conntrack_helper_put(priv->helper4);
if (priv->helper6)
module_put(priv->helper6->me);
nf_conntrack_helper_put(priv->helper6);
}

static void nft_ct_helper_obj_eval(struct nft_object *obj,
Expand Down
6 changes: 3 additions & 3 deletions net/netfilter/xt_CT.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ xt_ct_set_helper(struct nf_conn *ct, const char *helper_name,

help = nf_ct_helper_ext_add(ct, helper, GFP_KERNEL);
if (help == NULL) {
module_put(helper->me);
nf_conntrack_helper_put(helper);
return -ENOMEM;
}

Expand Down Expand Up @@ -263,7 +263,7 @@ static int xt_ct_tg_check(const struct xt_tgchk_param *par,
err4:
help = nfct_help(ct);
if (help)
module_put(help->helper->me);
nf_conntrack_helper_put(help->helper);
err3:
nf_ct_tmpl_free(ct);
err2:
Expand Down Expand Up @@ -346,7 +346,7 @@ static void xt_ct_tg_destroy(const struct xt_tgdtor_param *par,
if (ct) {
help = nfct_help(ct);
if (help)
module_put(help->helper->me);
nf_conntrack_helper_put(help->helper);

nf_ct_netns_put(par->net, par->family);

Expand Down
4 changes: 2 additions & 2 deletions net/openvswitch/conntrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ static int ovs_ct_add_helper(struct ovs_conntrack_info *info, const char *name,

help = nf_ct_helper_ext_add(info->ct, helper, GFP_KERNEL);
if (!help) {
module_put(helper->me);
nf_conntrack_helper_put(helper);
return -ENOMEM;
}

Expand Down Expand Up @@ -1584,7 +1584,7 @@ void ovs_ct_free_action(const struct nlattr *a)
static void __ovs_ct_free_action(struct ovs_conntrack_info *ct_info)
{
if (ct_info->helper)
module_put(ct_info->helper->me);
nf_conntrack_helper_put(ct_info->helper);
if (ct_info->ct)
nf_ct_tmpl_free(ct_info->ct);
}
Expand Down

0 comments on commit d91fc59

Please sign in to comment.