Commit d53e3fc3 authored by Liping Zhang's avatar Liping Zhang Committed by Pablo Neira Ayuso

netfilter: use nf_conntrack_helpers_register when possible

amanda_helper, nf_conntrack_helper_ras and nf_conntrack_helper_q931 are
all arrays, so we can use nf_conntrack_helpers_register to register
the ct helper, this will help us to eliminate some "goto errX"
statements.

Also introduce h323_helper_init/exit helper function to register the ct
helpers, this is prepared for the followup patch, which will add net
namespace support for ct helper.
Signed-off-by: default avatarLiping Zhang <zlpnobody@gmail.com>
Acked-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 2becbbc5
...@@ -197,8 +197,8 @@ static void __exit nf_conntrack_amanda_fini(void) ...@@ -197,8 +197,8 @@ static void __exit nf_conntrack_amanda_fini(void)
{ {
int i; int i;
nf_conntrack_helper_unregister(&amanda_helper[0]); nf_conntrack_helpers_unregister(amanda_helper,
nf_conntrack_helper_unregister(&amanda_helper[1]); ARRAY_SIZE(amanda_helper));
for (i = 0; i < ARRAY_SIZE(search); i++) for (i = 0; i < ARRAY_SIZE(search); i++)
textsearch_destroy(search[i].ts); textsearch_destroy(search[i].ts);
} }
...@@ -218,16 +218,12 @@ static int __init nf_conntrack_amanda_init(void) ...@@ -218,16 +218,12 @@ static int __init nf_conntrack_amanda_init(void)
goto err1; goto err1;
} }
} }
ret = nf_conntrack_helper_register(&amanda_helper[0]); ret = nf_conntrack_helpers_register(amanda_helper,
ARRAY_SIZE(amanda_helper));
if (ret < 0) if (ret < 0)
goto err1; goto err1;
ret = nf_conntrack_helper_register(&amanda_helper[1]);
if (ret < 0)
goto err2;
return 0; return 0;
err2:
nf_conntrack_helper_unregister(&amanda_helper[0]);
err1: err1:
while (--i >= 0) while (--i >= 0)
textsearch_destroy(search[i].ts); textsearch_destroy(search[i].ts);
......
...@@ -1815,14 +1815,44 @@ static struct nf_conntrack_helper nf_conntrack_helper_ras[] __read_mostly = { ...@@ -1815,14 +1815,44 @@ static struct nf_conntrack_helper nf_conntrack_helper_ras[] __read_mostly = {
}, },
}; };
static int __init h323_helper_init(void)
{
int ret;
ret = nf_conntrack_helper_register(&nf_conntrack_helper_h245);
if (ret < 0)
return ret;
ret = nf_conntrack_helpers_register(nf_conntrack_helper_q931,
ARRAY_SIZE(nf_conntrack_helper_q931));
if (ret < 0)
goto err1;
ret = nf_conntrack_helpers_register(nf_conntrack_helper_ras,
ARRAY_SIZE(nf_conntrack_helper_ras));
if (ret < 0)
goto err2;
return 0;
err2:
nf_conntrack_helpers_unregister(nf_conntrack_helper_q931,
ARRAY_SIZE(nf_conntrack_helper_q931));
err1:
nf_conntrack_helper_unregister(&nf_conntrack_helper_h245);
return ret;
}
static void __exit h323_helper_exit(void)
{
nf_conntrack_helpers_unregister(nf_conntrack_helper_ras,
ARRAY_SIZE(nf_conntrack_helper_ras));
nf_conntrack_helpers_unregister(nf_conntrack_helper_q931,
ARRAY_SIZE(nf_conntrack_helper_q931));
nf_conntrack_helper_unregister(&nf_conntrack_helper_h245);
}
/****************************************************************************/ /****************************************************************************/
static void __exit nf_conntrack_h323_fini(void) static void __exit nf_conntrack_h323_fini(void)
{ {
nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[1]); h323_helper_exit();
nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[0]);
nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[1]);
nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[0]);
nf_conntrack_helper_unregister(&nf_conntrack_helper_h245);
kfree(h323_buffer); kfree(h323_buffer);
pr_debug("nf_ct_h323: fini\n"); pr_debug("nf_ct_h323: fini\n");
} }
...@@ -1837,32 +1867,11 @@ static int __init nf_conntrack_h323_init(void) ...@@ -1837,32 +1867,11 @@ static int __init nf_conntrack_h323_init(void)
h323_buffer = kmalloc(65536, GFP_KERNEL); h323_buffer = kmalloc(65536, GFP_KERNEL);
if (!h323_buffer) if (!h323_buffer)
return -ENOMEM; return -ENOMEM;
ret = nf_conntrack_helper_register(&nf_conntrack_helper_h245); ret = h323_helper_init();
if (ret < 0) if (ret < 0)
goto err1; goto err1;
ret = nf_conntrack_helper_register(&nf_conntrack_helper_q931[0]);
if (ret < 0)
goto err2;
ret = nf_conntrack_helper_register(&nf_conntrack_helper_q931[1]);
if (ret < 0)
goto err3;
ret = nf_conntrack_helper_register(&nf_conntrack_helper_ras[0]);
if (ret < 0)
goto err4;
ret = nf_conntrack_helper_register(&nf_conntrack_helper_ras[1]);
if (ret < 0)
goto err5;
pr_debug("nf_ct_h323: init success\n"); pr_debug("nf_ct_h323: init success\n");
return 0; return 0;
err5:
nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[0]);
err4:
nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[1]);
err3:
nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[0]);
err2:
nf_conntrack_helper_unregister(&nf_conntrack_helper_h245);
err1: err1:
kfree(h323_buffer); kfree(h323_buffer);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment