netfilter: conntrack: simplify init/uninit of L4 protocol trackers
modify registration and deregistration of layer-4 protocol trackers to facilitate inclusion of new elements into the current list of builtin protocols. Both builtin (TCP, UDP, ICMP) and non-builtin (DCCP, GRE, SCTP, UDPlite) layer-4 protocol trackers usually register/deregister themselves using consecutive calls to nf_ct_l4proto_{,pernet}_{,un}register(...). This sequence is interrupted and rolled back in case of error; in order to simplify addition of builtin protocols, the input of the above functions has been modified to allow registering/unregistering multiple protocols. Signed-off-by: Davide Caratti <dcaratti@redhat.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
This commit is contained in:

committed by
Pablo Neira Ayuso

parent
4e24877e61
commit
0e54d2179f
@@ -336,47 +336,34 @@ MODULE_ALIAS("nf_conntrack-" __stringify(AF_INET));
|
||||
MODULE_ALIAS("ip_conntrack");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
static struct nf_conntrack_l4proto *builtin_l4proto4[] = {
|
||||
&nf_conntrack_l4proto_tcp4,
|
||||
&nf_conntrack_l4proto_udp4,
|
||||
&nf_conntrack_l4proto_icmp,
|
||||
};
|
||||
|
||||
static int ipv4_net_init(struct net *net)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret = nf_ct_l4proto_pernet_register(net, &nf_conntrack_l4proto_tcp4);
|
||||
if (ret < 0) {
|
||||
pr_err("nf_conntrack_tcp4: pernet registration failed\n");
|
||||
goto out_tcp;
|
||||
}
|
||||
ret = nf_ct_l4proto_pernet_register(net, &nf_conntrack_l4proto_udp4);
|
||||
if (ret < 0) {
|
||||
pr_err("nf_conntrack_udp4: pernet registration failed\n");
|
||||
goto out_udp;
|
||||
}
|
||||
ret = nf_ct_l4proto_pernet_register(net, &nf_conntrack_l4proto_icmp);
|
||||
if (ret < 0) {
|
||||
pr_err("nf_conntrack_icmp4: pernet registration failed\n");
|
||||
goto out_icmp;
|
||||
}
|
||||
ret = nf_ct_l4proto_pernet_register(net, builtin_l4proto4,
|
||||
ARRAY_SIZE(builtin_l4proto4));
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
ret = nf_ct_l3proto_pernet_register(net, &nf_conntrack_l3proto_ipv4);
|
||||
if (ret < 0) {
|
||||
pr_err("nf_conntrack_ipv4: pernet registration failed\n");
|
||||
goto out_ipv4;
|
||||
nf_ct_l4proto_pernet_unregister(net, builtin_l4proto4,
|
||||
ARRAY_SIZE(builtin_l4proto4));
|
||||
}
|
||||
return 0;
|
||||
out_ipv4:
|
||||
nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_icmp);
|
||||
out_icmp:
|
||||
nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_udp4);
|
||||
out_udp:
|
||||
nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_tcp4);
|
||||
out_tcp:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void ipv4_net_exit(struct net *net)
|
||||
{
|
||||
nf_ct_l3proto_pernet_unregister(net, &nf_conntrack_l3proto_ipv4);
|
||||
nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_icmp);
|
||||
nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_udp4);
|
||||
nf_ct_l4proto_pernet_unregister(net, &nf_conntrack_l4proto_tcp4);
|
||||
nf_ct_l4proto_pernet_unregister(net, builtin_l4proto4,
|
||||
ARRAY_SIZE(builtin_l4proto4));
|
||||
}
|
||||
|
||||
static struct pernet_operations ipv4_net_ops = {
|
||||
@@ -410,37 +397,21 @@ static int __init nf_conntrack_l3proto_ipv4_init(void)
|
||||
goto cleanup_pernet;
|
||||
}
|
||||
|
||||
ret = nf_ct_l4proto_register(&nf_conntrack_l4proto_tcp4);
|
||||
if (ret < 0) {
|
||||
pr_err("nf_conntrack_ipv4: can't register tcp4 proto.\n");
|
||||
ret = nf_ct_l4proto_register(builtin_l4proto4,
|
||||
ARRAY_SIZE(builtin_l4proto4));
|
||||
if (ret < 0)
|
||||
goto cleanup_hooks;
|
||||
}
|
||||
|
||||
ret = nf_ct_l4proto_register(&nf_conntrack_l4proto_udp4);
|
||||
if (ret < 0) {
|
||||
pr_err("nf_conntrack_ipv4: can't register udp4 proto.\n");
|
||||
goto cleanup_tcp4;
|
||||
}
|
||||
|
||||
ret = nf_ct_l4proto_register(&nf_conntrack_l4proto_icmp);
|
||||
if (ret < 0) {
|
||||
pr_err("nf_conntrack_ipv4: can't register icmpv4 proto.\n");
|
||||
goto cleanup_udp4;
|
||||
}
|
||||
|
||||
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_icmpv4;
|
||||
goto cleanup_l4proto;
|
||||
}
|
||||
|
||||
return ret;
|
||||
cleanup_icmpv4:
|
||||
nf_ct_l4proto_unregister(&nf_conntrack_l4proto_icmp);
|
||||
cleanup_udp4:
|
||||
nf_ct_l4proto_unregister(&nf_conntrack_l4proto_udp4);
|
||||
cleanup_tcp4:
|
||||
nf_ct_l4proto_unregister(&nf_conntrack_l4proto_tcp4);
|
||||
cleanup_l4proto:
|
||||
nf_ct_l4proto_unregister(builtin_l4proto4,
|
||||
ARRAY_SIZE(builtin_l4proto4));
|
||||
cleanup_hooks:
|
||||
nf_unregister_hooks(ipv4_conntrack_ops, ARRAY_SIZE(ipv4_conntrack_ops));
|
||||
cleanup_pernet:
|
||||
@@ -454,9 +425,8 @@ static void __exit nf_conntrack_l3proto_ipv4_fini(void)
|
||||
{
|
||||
synchronize_net();
|
||||
nf_ct_l3proto_unregister(&nf_conntrack_l3proto_ipv4);
|
||||
nf_ct_l4proto_unregister(&nf_conntrack_l4proto_icmp);
|
||||
nf_ct_l4proto_unregister(&nf_conntrack_l4proto_udp4);
|
||||
nf_ct_l4proto_unregister(&nf_conntrack_l4proto_tcp4);
|
||||
nf_ct_l4proto_unregister(builtin_l4proto4,
|
||||
ARRAY_SIZE(builtin_l4proto4));
|
||||
nf_unregister_hooks(ipv4_conntrack_ops, ARRAY_SIZE(ipv4_conntrack_ops));
|
||||
unregister_pernet_subsys(&ipv4_net_ops);
|
||||
nf_unregister_sockopt(&so_getorigdst);
|
||||
|
Reference in New Issue
Block a user