Browse Source

netfilter: introduce nf_conntrack_helper_put helper function

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>
Liping Zhang 8 years ago
parent
commit
d91fc59cd7

+ 2 - 0
include/net/netfilter/nf_conntrack_helper.h

@@ -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,
 struct nf_conntrack_helper *nf_conntrack_helper_try_module_get(const char *name,
 							       u16 l3num,
 							       u16 l3num,
 							       u8 protonum);
 							       u8 protonum);
+void nf_conntrack_helper_put(struct nf_conntrack_helper *helper);
+
 void nf_ct_helper_init(struct nf_conntrack_helper *helper,
 void nf_ct_helper_init(struct nf_conntrack_helper *helper,
 		       u16 l3num, u16 protonum, const char *name,
 		       u16 l3num, u16 protonum, const char *name,
 		       u16 default_port, u16 spec_port, u32 id,
 		       u16 default_port, u16 spec_port, u32 id,

+ 6 - 0
net/netfilter/nf_conntrack_helper.c

@@ -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);
 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 *
 struct nf_conn_help *
 nf_ct_helper_ext_add(struct nf_conn *ct,
 nf_ct_helper_ext_add(struct nf_conn *ct,
 		     struct nf_conntrack_helper *helper, gfp_t gfp)
 		     struct nf_conntrack_helper *helper, gfp_t gfp)

+ 2 - 2
net/netfilter/nft_ct.c

@@ -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);
 	struct nft_ct_helper_obj *priv = nft_obj_data(obj);
 
 
 	if (priv->helper4)
 	if (priv->helper4)
-		module_put(priv->helper4->me);
+		nf_conntrack_helper_put(priv->helper4);
 	if (priv->helper6)
 	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,
 static void nft_ct_helper_obj_eval(struct nft_object *obj,

+ 3 - 3
net/netfilter/xt_CT.c

@@ -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);
 	help = nf_ct_helper_ext_add(ct, helper, GFP_KERNEL);
 	if (help == NULL) {
 	if (help == NULL) {
-		module_put(helper->me);
+		nf_conntrack_helper_put(helper);
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
 
 
@@ -263,7 +263,7 @@ out:
 err4:
 err4:
 	help = nfct_help(ct);
 	help = nfct_help(ct);
 	if (help)
 	if (help)
-		module_put(help->helper->me);
+		nf_conntrack_helper_put(help->helper);
 err3:
 err3:
 	nf_ct_tmpl_free(ct);
 	nf_ct_tmpl_free(ct);
 err2:
 err2:
@@ -346,7 +346,7 @@ static void xt_ct_tg_destroy(const struct xt_tgdtor_param *par,
 	if (ct) {
 	if (ct) {
 		help = nfct_help(ct);
 		help = nfct_help(ct);
 		if (help)
 		if (help)
-			module_put(help->helper->me);
+			nf_conntrack_helper_put(help->helper);
 
 
 		nf_ct_netns_put(par->net, par->family);
 		nf_ct_netns_put(par->net, par->family);
 
 

+ 2 - 2
net/openvswitch/conntrack.c

@@ -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);
 	help = nf_ct_helper_ext_add(info->ct, helper, GFP_KERNEL);
 	if (!help) {
 	if (!help) {
-		module_put(helper->me);
+		nf_conntrack_helper_put(helper);
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
 
 
@@ -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)
 static void __ovs_ct_free_action(struct ovs_conntrack_info *ct_info)
 {
 {
 	if (ct_info->helper)
 	if (ct_info->helper)
-		module_put(ct_info->helper->me);
+		nf_conntrack_helper_put(ct_info->helper);
 	if (ct_info->ct)
 	if (ct_info->ct)
 		nf_ct_tmpl_free(ct_info->ct);
 		nf_ct_tmpl_free(ct_info->ct);
 }
 }