Commit 6330750d authored by Gao feng's avatar Gao feng Committed by Pablo Neira Ayuso

netfilter: nf_conntrack: refactor l3proto support for netns

Move the code that register/unregister l3proto to the
module_init/exit context.

Given that we have to modify some interfaces to accomodate
these changes, it is a good time to use shorter function names
for this using the nf_ct_* prefix instead of nf_conntrack_*,
that is:

nf_ct_l3proto_register
nf_ct_l3proto_pernet_register
nf_ct_l3proto_unregister
nf_ct_l3proto_pernet_unregister

We same many line breaks with it.
Signed-off-by: default avatarGao feng <gaofeng@cn.fujitsu.com>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 04d87001
...@@ -76,11 +76,16 @@ struct nf_conntrack_l3proto { ...@@ -76,11 +76,16 @@ struct nf_conntrack_l3proto {
extern struct nf_conntrack_l3proto __rcu *nf_ct_l3protos[AF_MAX]; extern struct nf_conntrack_l3proto __rcu *nf_ct_l3protos[AF_MAX];
/* Protocol registration. */ /* Protocol pernet registration. */
extern int nf_conntrack_l3proto_register(struct net *net, extern int nf_ct_l3proto_pernet_register(struct net *net,
struct nf_conntrack_l3proto *proto); struct nf_conntrack_l3proto *proto);
extern void nf_conntrack_l3proto_unregister(struct net *net, extern void nf_ct_l3proto_pernet_unregister(struct net *net,
struct nf_conntrack_l3proto *proto); struct nf_conntrack_l3proto *proto);
/* Protocol global registration. */
extern int nf_ct_l3proto_register(struct nf_conntrack_l3proto *proto);
extern void nf_ct_l3proto_unregister(struct nf_conntrack_l3proto *proto);
extern struct nf_conntrack_l3proto *nf_ct_l3proto_find_get(u_int16_t l3proto); extern struct nf_conntrack_l3proto *nf_ct_l3proto_find_get(u_int16_t l3proto);
extern void nf_ct_l3proto_put(struct nf_conntrack_l3proto *p); extern void nf_ct_l3proto_put(struct nf_conntrack_l3proto *p);
......
...@@ -438,10 +438,9 @@ static int ipv4_net_init(struct net *net) ...@@ -438,10 +438,9 @@ static int ipv4_net_init(struct net *net)
pr_err("nf_conntrack_l4proto_icmp4 :protocol register failed\n"); pr_err("nf_conntrack_l4proto_icmp4 :protocol register failed\n");
goto out_icmp; goto out_icmp;
} }
ret = nf_conntrack_l3proto_register(net, ret = nf_ct_l3proto_pernet_register(net, &nf_conntrack_l3proto_ipv4);
&nf_conntrack_l3proto_ipv4);
if (ret < 0) { if (ret < 0) {
pr_err("nf_conntrack_l3proto_ipv4 :protocol register failed\n"); pr_err("nf_conntrack_ipv4: pernet registration failed\n");
goto out_ipv4; goto out_ipv4;
} }
return 0; return 0;
...@@ -460,8 +459,7 @@ static int ipv4_net_init(struct net *net) ...@@ -460,8 +459,7 @@ static int ipv4_net_init(struct net *net)
static void ipv4_net_exit(struct net *net) static void ipv4_net_exit(struct net *net)
{ {
nf_conntrack_l3proto_unregister(net, nf_ct_l3proto_pernet_unregister(net, &nf_conntrack_l3proto_ipv4);
&nf_conntrack_l3proto_ipv4);
nf_conntrack_l4proto_unregister(net, nf_conntrack_l4proto_unregister(net,
&nf_conntrack_l4proto_icmp); &nf_conntrack_l4proto_icmp);
nf_conntrack_l4proto_unregister(net, nf_conntrack_l4proto_unregister(net,
...@@ -500,16 +498,25 @@ static int __init nf_conntrack_l3proto_ipv4_init(void) ...@@ -500,16 +498,25 @@ static int __init nf_conntrack_l3proto_ipv4_init(void)
pr_err("nf_conntrack_ipv4: can't register hooks.\n"); pr_err("nf_conntrack_ipv4: can't register hooks.\n");
goto cleanup_pernet; goto cleanup_pernet;
} }
ret = nf_ct_l3proto_register(&nf_conntrack_l3proto_ipv4);
if (ret < 0) {
pr_err("nf_conntrack_ipv4: can't register ipv4 proto.\n");
goto cleanup_hooks;
}
#if defined(CONFIG_PROC_FS) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT) #if defined(CONFIG_PROC_FS) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
ret = nf_conntrack_ipv4_compat_init(); ret = nf_conntrack_ipv4_compat_init();
if (ret < 0) if (ret < 0)
goto cleanup_hooks; goto cleanup_proto;
#endif #endif
return ret; return ret;
#if defined(CONFIG_PROC_FS) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT) #if defined(CONFIG_PROC_FS) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
cleanup_proto:
nf_ct_l3proto_unregister(&nf_conntrack_l3proto_ipv4);
#endif
cleanup_hooks: cleanup_hooks:
nf_unregister_hooks(ipv4_conntrack_ops, ARRAY_SIZE(ipv4_conntrack_ops)); nf_unregister_hooks(ipv4_conntrack_ops, ARRAY_SIZE(ipv4_conntrack_ops));
#endif
cleanup_pernet: cleanup_pernet:
unregister_pernet_subsys(&ipv4_net_ops); unregister_pernet_subsys(&ipv4_net_ops);
cleanup_sockopt: cleanup_sockopt:
...@@ -523,6 +530,7 @@ static void __exit nf_conntrack_l3proto_ipv4_fini(void) ...@@ -523,6 +530,7 @@ static void __exit nf_conntrack_l3proto_ipv4_fini(void)
#if defined(CONFIG_PROC_FS) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT) #if defined(CONFIG_PROC_FS) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
nf_conntrack_ipv4_compat_fini(); nf_conntrack_ipv4_compat_fini();
#endif #endif
nf_ct_l3proto_unregister(&nf_conntrack_l3proto_ipv4);
nf_unregister_hooks(ipv4_conntrack_ops, ARRAY_SIZE(ipv4_conntrack_ops)); nf_unregister_hooks(ipv4_conntrack_ops, ARRAY_SIZE(ipv4_conntrack_ops));
unregister_pernet_subsys(&ipv4_net_ops); unregister_pernet_subsys(&ipv4_net_ops);
nf_unregister_sockopt(&so_getorigdst); nf_unregister_sockopt(&so_getorigdst);
......
...@@ -439,10 +439,9 @@ static int ipv6_net_init(struct net *net) ...@@ -439,10 +439,9 @@ static int ipv6_net_init(struct net *net)
printk(KERN_ERR "nf_conntrack_l4proto_icmp6: protocol register failed\n"); printk(KERN_ERR "nf_conntrack_l4proto_icmp6: protocol register failed\n");
goto cleanup_udp6; goto cleanup_udp6;
} }
ret = nf_conntrack_l3proto_register(net, ret = nf_ct_l3proto_pernet_register(net, &nf_conntrack_l3proto_ipv6);
&nf_conntrack_l3proto_ipv6);
if (ret < 0) { if (ret < 0) {
printk(KERN_ERR "nf_conntrack_l3proto_ipv6: protocol register failed\n"); pr_err("nf_conntrack_ipv6: pernet registration failed.\n");
goto cleanup_icmpv6; goto cleanup_icmpv6;
} }
return 0; return 0;
...@@ -461,8 +460,7 @@ static int ipv6_net_init(struct net *net) ...@@ -461,8 +460,7 @@ static int ipv6_net_init(struct net *net)
static void ipv6_net_exit(struct net *net) static void ipv6_net_exit(struct net *net)
{ {
nf_conntrack_l3proto_unregister(net, nf_ct_l3proto_pernet_unregister(net, &nf_conntrack_l3proto_ipv6);
&nf_conntrack_l3proto_ipv6);
nf_conntrack_l4proto_unregister(net, nf_conntrack_l4proto_unregister(net,
&nf_conntrack_l4proto_icmpv6); &nf_conntrack_l4proto_icmpv6);
nf_conntrack_l4proto_unregister(net, nf_conntrack_l4proto_unregister(net,
...@@ -491,19 +489,28 @@ static int __init nf_conntrack_l3proto_ipv6_init(void) ...@@ -491,19 +489,28 @@ static int __init nf_conntrack_l3proto_ipv6_init(void)
ret = register_pernet_subsys(&ipv6_net_ops); ret = register_pernet_subsys(&ipv6_net_ops);
if (ret < 0) if (ret < 0)
goto cleanup_pernet; goto cleanup_sockopt;
ret = nf_register_hooks(ipv6_conntrack_ops, ret = nf_register_hooks(ipv6_conntrack_ops,
ARRAY_SIZE(ipv6_conntrack_ops)); ARRAY_SIZE(ipv6_conntrack_ops));
if (ret < 0) { if (ret < 0) {
pr_err("nf_conntrack_ipv6: can't register pre-routing defrag " pr_err("nf_conntrack_ipv6: can't register pre-routing defrag "
"hook.\n"); "hook.\n");
goto cleanup_ipv6; goto cleanup_pernet;
}
ret = nf_ct_l3proto_register(&nf_conntrack_l3proto_ipv6);
if (ret < 0) {
pr_err("nf_conntrack_ipv6: can't register ipv6 proto.\n");
goto cleanup_hooks;
} }
return ret; return ret;
cleanup_ipv6: cleanup_hooks:
unregister_pernet_subsys(&ipv6_net_ops); nf_unregister_hooks(ipv6_conntrack_ops, ARRAY_SIZE(ipv6_conntrack_ops));
cleanup_pernet: cleanup_pernet:
unregister_pernet_subsys(&ipv6_net_ops);
cleanup_sockopt:
nf_unregister_sockopt(&so_getorigdst6); nf_unregister_sockopt(&so_getorigdst6);
return ret; return ret;
} }
...@@ -511,6 +518,7 @@ static int __init nf_conntrack_l3proto_ipv6_init(void) ...@@ -511,6 +518,7 @@ static int __init nf_conntrack_l3proto_ipv6_init(void)
static void __exit nf_conntrack_l3proto_ipv6_fini(void) static void __exit nf_conntrack_l3proto_ipv6_fini(void)
{ {
synchronize_net(); synchronize_net();
nf_ct_l3proto_unregister(&nf_conntrack_l3proto_ipv6);
nf_unregister_hooks(ipv6_conntrack_ops, ARRAY_SIZE(ipv6_conntrack_ops)); nf_unregister_hooks(ipv6_conntrack_ops, ARRAY_SIZE(ipv6_conntrack_ops));
unregister_pernet_subsys(&ipv6_net_ops); unregister_pernet_subsys(&ipv6_net_ops);
nf_unregister_sockopt(&so_getorigdst6); nf_unregister_sockopt(&so_getorigdst6);
......
...@@ -212,8 +212,7 @@ static void nf_ct_l3proto_unregister_sysctl(struct net *net, ...@@ -212,8 +212,7 @@ static void nf_ct_l3proto_unregister_sysctl(struct net *net,
#endif #endif
} }
static int int nf_ct_l3proto_register(struct nf_conntrack_l3proto *proto)
nf_conntrack_l3proto_register_net(struct nf_conntrack_l3proto *proto)
{ {
int ret = 0; int ret = 0;
struct nf_conntrack_l3proto *old; struct nf_conntrack_l3proto *old;
...@@ -242,8 +241,9 @@ nf_conntrack_l3proto_register_net(struct nf_conntrack_l3proto *proto) ...@@ -242,8 +241,9 @@ nf_conntrack_l3proto_register_net(struct nf_conntrack_l3proto *proto)
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(nf_ct_l3proto_register);
int nf_conntrack_l3proto_register(struct net *net, int nf_ct_l3proto_pernet_register(struct net *net,
struct nf_conntrack_l3proto *proto) struct nf_conntrack_l3proto *proto)
{ {
int ret = 0; int ret = 0;
...@@ -254,22 +254,11 @@ int nf_conntrack_l3proto_register(struct net *net, ...@@ -254,22 +254,11 @@ int nf_conntrack_l3proto_register(struct net *net,
return ret; return ret;
} }
ret = nf_ct_l3proto_register_sysctl(net, proto); return nf_ct_l3proto_register_sysctl(net, proto);
if (ret < 0)
return ret;
if (net == &init_net) {
ret = nf_conntrack_l3proto_register_net(proto);
if (ret < 0)
nf_ct_l3proto_unregister_sysctl(net, proto);
}
return ret;
} }
EXPORT_SYMBOL_GPL(nf_conntrack_l3proto_register); EXPORT_SYMBOL_GPL(nf_ct_l3proto_pernet_register);
static void void nf_ct_l3proto_unregister(struct nf_conntrack_l3proto *proto)
nf_conntrack_l3proto_unregister_net(struct nf_conntrack_l3proto *proto)
{ {
BUG_ON(proto->l3proto >= AF_MAX); BUG_ON(proto->l3proto >= AF_MAX);
...@@ -283,19 +272,17 @@ nf_conntrack_l3proto_unregister_net(struct nf_conntrack_l3proto *proto) ...@@ -283,19 +272,17 @@ nf_conntrack_l3proto_unregister_net(struct nf_conntrack_l3proto *proto)
synchronize_rcu(); synchronize_rcu();
} }
EXPORT_SYMBOL_GPL(nf_ct_l3proto_unregister);
void nf_conntrack_l3proto_unregister(struct net *net, void nf_ct_l3proto_pernet_unregister(struct net *net,
struct nf_conntrack_l3proto *proto) struct nf_conntrack_l3proto *proto)
{ {
if (net == &init_net)
nf_conntrack_l3proto_unregister_net(proto);
nf_ct_l3proto_unregister_sysctl(net, proto); nf_ct_l3proto_unregister_sysctl(net, proto);
/* Remove all contrack entries for this protocol */ /* Remove all contrack entries for this protocol */
nf_ct_iterate_cleanup(net, kill_l3proto, proto); nf_ct_iterate_cleanup(net, kill_l3proto, proto);
} }
EXPORT_SYMBOL_GPL(nf_conntrack_l3proto_unregister); EXPORT_SYMBOL_GPL(nf_ct_l3proto_pernet_unregister);
static struct nf_proto_net *nf_ct_l4proto_net(struct net *net, static struct nf_proto_net *nf_ct_l4proto_net(struct net *net,
struct nf_conntrack_l4proto *l4proto) struct nf_conntrack_l4proto *l4proto)
......
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