[NETFILTER]: nf_conntrack: simplify protocol locking
Now that we don't use nf_conntrack_lock anymore but a single mutex for all protocol handling, no need to release and grab it again for sysctl registration. Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
ac5357ebac
commit
0661cca9c2
@@ -164,13 +164,11 @@ static int nf_ct_l3proto_register_sysctl(struct nf_conntrack_l3proto *l3proto)
|
|||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
#ifdef CONFIG_SYSCTL
|
#ifdef CONFIG_SYSCTL
|
||||||
mutex_lock(&nf_ct_proto_mutex);
|
|
||||||
if (l3proto->ctl_table != NULL) {
|
if (l3proto->ctl_table != NULL) {
|
||||||
err = nf_ct_register_sysctl(&l3proto->ctl_table_header,
|
err = nf_ct_register_sysctl(&l3proto->ctl_table_header,
|
||||||
l3proto->ctl_table_path,
|
l3proto->ctl_table_path,
|
||||||
l3proto->ctl_table, NULL);
|
l3proto->ctl_table, NULL);
|
||||||
}
|
}
|
||||||
mutex_unlock(&nf_ct_proto_mutex);
|
|
||||||
#endif
|
#endif
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -178,11 +176,9 @@ static int nf_ct_l3proto_register_sysctl(struct nf_conntrack_l3proto *l3proto)
|
|||||||
static void nf_ct_l3proto_unregister_sysctl(struct nf_conntrack_l3proto *l3proto)
|
static void nf_ct_l3proto_unregister_sysctl(struct nf_conntrack_l3proto *l3proto)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_SYSCTL
|
#ifdef CONFIG_SYSCTL
|
||||||
mutex_lock(&nf_ct_proto_mutex);
|
|
||||||
if (l3proto->ctl_table_header != NULL)
|
if (l3proto->ctl_table_header != NULL)
|
||||||
nf_ct_unregister_sysctl(&l3proto->ctl_table_header,
|
nf_ct_unregister_sysctl(&l3proto->ctl_table_header,
|
||||||
l3proto->ctl_table, NULL);
|
l3proto->ctl_table, NULL);
|
||||||
mutex_unlock(&nf_ct_proto_mutex);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,27 +186,23 @@ int nf_conntrack_l3proto_register(struct nf_conntrack_l3proto *proto)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (proto->l3proto >= AF_MAX) {
|
if (proto->l3proto >= AF_MAX)
|
||||||
ret = -EBUSY;
|
return -EBUSY;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
mutex_lock(&nf_ct_proto_mutex);
|
mutex_lock(&nf_ct_proto_mutex);
|
||||||
if (nf_ct_l3protos[proto->l3proto] != &nf_conntrack_l3proto_generic) {
|
if (nf_ct_l3protos[proto->l3proto] != &nf_conntrack_l3proto_generic) {
|
||||||
ret = -EBUSY;
|
ret = -EBUSY;
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
rcu_assign_pointer(nf_ct_l3protos[proto->l3proto], proto);
|
|
||||||
mutex_unlock(&nf_ct_proto_mutex);
|
|
||||||
|
|
||||||
ret = nf_ct_l3proto_register_sysctl(proto);
|
ret = nf_ct_l3proto_register_sysctl(proto);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
nf_conntrack_l3proto_unregister(proto);
|
goto out_unlock;
|
||||||
return ret;
|
|
||||||
|
rcu_assign_pointer(nf_ct_l3protos[proto->l3proto], proto);
|
||||||
|
|
||||||
out_unlock:
|
out_unlock:
|
||||||
mutex_unlock(&nf_ct_proto_mutex);
|
mutex_unlock(&nf_ct_proto_mutex);
|
||||||
out:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(nf_conntrack_l3proto_register);
|
EXPORT_SYMBOL_GPL(nf_conntrack_l3proto_register);
|
||||||
@@ -223,10 +215,10 @@ void nf_conntrack_l3proto_unregister(struct nf_conntrack_l3proto *proto)
|
|||||||
BUG_ON(nf_ct_l3protos[proto->l3proto] != proto);
|
BUG_ON(nf_ct_l3protos[proto->l3proto] != proto);
|
||||||
rcu_assign_pointer(nf_ct_l3protos[proto->l3proto],
|
rcu_assign_pointer(nf_ct_l3protos[proto->l3proto],
|
||||||
&nf_conntrack_l3proto_generic);
|
&nf_conntrack_l3proto_generic);
|
||||||
mutex_unlock(&nf_ct_proto_mutex);
|
|
||||||
synchronize_rcu();
|
|
||||||
|
|
||||||
nf_ct_l3proto_unregister_sysctl(proto);
|
nf_ct_l3proto_unregister_sysctl(proto);
|
||||||
|
mutex_unlock(&nf_ct_proto_mutex);
|
||||||
|
|
||||||
|
synchronize_rcu();
|
||||||
|
|
||||||
/* Remove all contrack entries for this protocol */
|
/* Remove all contrack entries for this protocol */
|
||||||
nf_ct_iterate_cleanup(kill_l3proto, proto);
|
nf_ct_iterate_cleanup(kill_l3proto, proto);
|
||||||
@@ -238,7 +230,6 @@ static int nf_ct_l4proto_register_sysctl(struct nf_conntrack_l4proto *l4proto)
|
|||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
#ifdef CONFIG_SYSCTL
|
#ifdef CONFIG_SYSCTL
|
||||||
mutex_lock(&nf_ct_proto_mutex);
|
|
||||||
if (l4proto->ctl_table != NULL) {
|
if (l4proto->ctl_table != NULL) {
|
||||||
err = nf_ct_register_sysctl(l4proto->ctl_table_header,
|
err = nf_ct_register_sysctl(l4proto->ctl_table_header,
|
||||||
nf_net_netfilter_sysctl_path,
|
nf_net_netfilter_sysctl_path,
|
||||||
@@ -260,7 +251,6 @@ static int nf_ct_l4proto_register_sysctl(struct nf_conntrack_l4proto *l4proto)
|
|||||||
}
|
}
|
||||||
#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
|
#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
|
||||||
out:
|
out:
|
||||||
mutex_unlock(&nf_ct_proto_mutex);
|
|
||||||
#endif /* CONFIG_SYSCTL */
|
#endif /* CONFIG_SYSCTL */
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -268,7 +258,6 @@ out:
|
|||||||
static void nf_ct_l4proto_unregister_sysctl(struct nf_conntrack_l4proto *l4proto)
|
static void nf_ct_l4proto_unregister_sysctl(struct nf_conntrack_l4proto *l4proto)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_SYSCTL
|
#ifdef CONFIG_SYSCTL
|
||||||
mutex_lock(&nf_ct_proto_mutex);
|
|
||||||
if (l4proto->ctl_table_header != NULL &&
|
if (l4proto->ctl_table_header != NULL &&
|
||||||
*l4proto->ctl_table_header != NULL)
|
*l4proto->ctl_table_header != NULL)
|
||||||
nf_ct_unregister_sysctl(l4proto->ctl_table_header,
|
nf_ct_unregister_sysctl(l4proto->ctl_table_header,
|
||||||
@@ -279,7 +268,6 @@ static void nf_ct_l4proto_unregister_sysctl(struct nf_conntrack_l4proto *l4proto
|
|||||||
nf_ct_unregister_sysctl(&l4proto->ctl_compat_table_header,
|
nf_ct_unregister_sysctl(&l4proto->ctl_compat_table_header,
|
||||||
l4proto->ctl_compat_table, NULL);
|
l4proto->ctl_compat_table, NULL);
|
||||||
#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
|
#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
|
||||||
mutex_unlock(&nf_ct_proto_mutex);
|
|
||||||
#endif /* CONFIG_SYSCTL */
|
#endif /* CONFIG_SYSCTL */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,10 +277,8 @@ int nf_conntrack_l4proto_register(struct nf_conntrack_l4proto *l4proto)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (l4proto->l3proto >= PF_MAX) {
|
if (l4proto->l3proto >= PF_MAX)
|
||||||
ret = -EBUSY;
|
return -EBUSY;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
mutex_lock(&nf_ct_proto_mutex);
|
mutex_lock(&nf_ct_proto_mutex);
|
||||||
retry:
|
retry:
|
||||||
@@ -331,17 +317,14 @@ retry:
|
|||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
|
|
||||||
rcu_assign_pointer(nf_ct_protos[l4proto->l3proto][l4proto->l4proto], l4proto);
|
|
||||||
mutex_unlock(&nf_ct_proto_mutex);
|
|
||||||
|
|
||||||
ret = nf_ct_l4proto_register_sysctl(l4proto);
|
ret = nf_ct_l4proto_register_sysctl(l4proto);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
nf_conntrack_l4proto_unregister(l4proto);
|
goto out_unlock;
|
||||||
return ret;
|
|
||||||
|
rcu_assign_pointer(nf_ct_protos[l4proto->l3proto][l4proto->l4proto], l4proto);
|
||||||
|
|
||||||
out_unlock:
|
out_unlock:
|
||||||
mutex_unlock(&nf_ct_proto_mutex);
|
mutex_unlock(&nf_ct_proto_mutex);
|
||||||
out:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_register);
|
EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_register);
|
||||||
@@ -354,10 +337,10 @@ void nf_conntrack_l4proto_unregister(struct nf_conntrack_l4proto *l4proto)
|
|||||||
BUG_ON(nf_ct_protos[l4proto->l3proto][l4proto->l4proto] != l4proto);
|
BUG_ON(nf_ct_protos[l4proto->l3proto][l4proto->l4proto] != l4proto);
|
||||||
rcu_assign_pointer(nf_ct_protos[l4proto->l3proto][l4proto->l4proto],
|
rcu_assign_pointer(nf_ct_protos[l4proto->l3proto][l4proto->l4proto],
|
||||||
&nf_conntrack_l4proto_generic);
|
&nf_conntrack_l4proto_generic);
|
||||||
mutex_unlock(&nf_ct_proto_mutex);
|
|
||||||
synchronize_rcu();
|
|
||||||
|
|
||||||
nf_ct_l4proto_unregister_sysctl(l4proto);
|
nf_ct_l4proto_unregister_sysctl(l4proto);
|
||||||
|
mutex_unlock(&nf_ct_proto_mutex);
|
||||||
|
|
||||||
|
synchronize_rcu();
|
||||||
|
|
||||||
/* Remove all contrack entries for this protocol */
|
/* Remove all contrack entries for this protocol */
|
||||||
nf_ct_iterate_cleanup(kill_l4proto, l4proto);
|
nf_ct_iterate_cleanup(kill_l4proto, l4proto);
|
||||||
|
Reference in New Issue
Block a user