|
@@ -4,6 +4,7 @@
|
|
#include <linux/module.h>
|
|
#include <linux/module.h>
|
|
#include <linux/skbuff.h>
|
|
#include <linux/skbuff.h>
|
|
#include <linux/netfilter.h>
|
|
#include <linux/netfilter.h>
|
|
|
|
+#include <linux/mutex.h>
|
|
#include <net/sock.h>
|
|
#include <net/sock.h>
|
|
|
|
|
|
#include "nf_internals.h"
|
|
#include "nf_internals.h"
|
|
@@ -11,7 +12,7 @@
|
|
/* Sockopts only registered and called from user context, so
|
|
/* Sockopts only registered and called from user context, so
|
|
net locking would be overkill. Also, [gs]etsockopt calls may
|
|
net locking would be overkill. Also, [gs]etsockopt calls may
|
|
sleep. */
|
|
sleep. */
|
|
-static DECLARE_MUTEX(nf_sockopt_mutex);
|
|
|
|
|
|
+static DEFINE_MUTEX(nf_sockopt_mutex);
|
|
static LIST_HEAD(nf_sockopts);
|
|
static LIST_HEAD(nf_sockopts);
|
|
|
|
|
|
/* Do exclusive ranges overlap? */
|
|
/* Do exclusive ranges overlap? */
|
|
@@ -26,7 +27,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
|
|
struct list_head *i;
|
|
struct list_head *i;
|
|
int ret = 0;
|
|
int ret = 0;
|
|
|
|
|
|
- if (down_interruptible(&nf_sockopt_mutex) != 0)
|
|
|
|
|
|
+ if (mutex_lock_interruptible(&nf_sockopt_mutex) != 0)
|
|
return -EINTR;
|
|
return -EINTR;
|
|
|
|
|
|
list_for_each(i, &nf_sockopts) {
|
|
list_for_each(i, &nf_sockopts) {
|
|
@@ -48,7 +49,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
|
|
|
|
|
|
list_add(®->list, &nf_sockopts);
|
|
list_add(®->list, &nf_sockopts);
|
|
out:
|
|
out:
|
|
- up(&nf_sockopt_mutex);
|
|
|
|
|
|
+ mutex_unlock(&nf_sockopt_mutex);
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(nf_register_sockopt);
|
|
EXPORT_SYMBOL(nf_register_sockopt);
|
|
@@ -57,18 +58,18 @@ void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
|
|
{
|
|
{
|
|
/* No point being interruptible: we're probably in cleanup_module() */
|
|
/* No point being interruptible: we're probably in cleanup_module() */
|
|
restart:
|
|
restart:
|
|
- down(&nf_sockopt_mutex);
|
|
|
|
|
|
+ mutex_lock(&nf_sockopt_mutex);
|
|
if (reg->use != 0) {
|
|
if (reg->use != 0) {
|
|
/* To be woken by nf_sockopt call... */
|
|
/* To be woken by nf_sockopt call... */
|
|
/* FIXME: Stuart Young's name appears gratuitously. */
|
|
/* FIXME: Stuart Young's name appears gratuitously. */
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
|
reg->cleanup_task = current;
|
|
reg->cleanup_task = current;
|
|
- up(&nf_sockopt_mutex);
|
|
|
|
|
|
+ mutex_unlock(&nf_sockopt_mutex);
|
|
schedule();
|
|
schedule();
|
|
goto restart;
|
|
goto restart;
|
|
}
|
|
}
|
|
list_del(®->list);
|
|
list_del(®->list);
|
|
- up(&nf_sockopt_mutex);
|
|
|
|
|
|
+ mutex_unlock(&nf_sockopt_mutex);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(nf_unregister_sockopt);
|
|
EXPORT_SYMBOL(nf_unregister_sockopt);
|
|
|
|
|
|
@@ -80,7 +81,7 @@ static int nf_sockopt(struct sock *sk, int pf, int val,
|
|
struct nf_sockopt_ops *ops;
|
|
struct nf_sockopt_ops *ops;
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
- if (down_interruptible(&nf_sockopt_mutex) != 0)
|
|
|
|
|
|
+ if (mutex_lock_interruptible(&nf_sockopt_mutex) != 0)
|
|
return -EINTR;
|
|
return -EINTR;
|
|
|
|
|
|
list_for_each(i, &nf_sockopts) {
|
|
list_for_each(i, &nf_sockopts) {
|
|
@@ -90,7 +91,7 @@ static int nf_sockopt(struct sock *sk, int pf, int val,
|
|
if (val >= ops->get_optmin
|
|
if (val >= ops->get_optmin
|
|
&& val < ops->get_optmax) {
|
|
&& val < ops->get_optmax) {
|
|
ops->use++;
|
|
ops->use++;
|
|
- up(&nf_sockopt_mutex);
|
|
|
|
|
|
+ mutex_unlock(&nf_sockopt_mutex);
|
|
ret = ops->get(sk, val, opt, len);
|
|
ret = ops->get(sk, val, opt, len);
|
|
goto out;
|
|
goto out;
|
|
}
|
|
}
|
|
@@ -98,22 +99,22 @@ static int nf_sockopt(struct sock *sk, int pf, int val,
|
|
if (val >= ops->set_optmin
|
|
if (val >= ops->set_optmin
|
|
&& val < ops->set_optmax) {
|
|
&& val < ops->set_optmax) {
|
|
ops->use++;
|
|
ops->use++;
|
|
- up(&nf_sockopt_mutex);
|
|
|
|
|
|
+ mutex_unlock(&nf_sockopt_mutex);
|
|
ret = ops->set(sk, val, opt, *len);
|
|
ret = ops->set(sk, val, opt, *len);
|
|
goto out;
|
|
goto out;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- up(&nf_sockopt_mutex);
|
|
|
|
|
|
+ mutex_unlock(&nf_sockopt_mutex);
|
|
return -ENOPROTOOPT;
|
|
return -ENOPROTOOPT;
|
|
|
|
|
|
out:
|
|
out:
|
|
- down(&nf_sockopt_mutex);
|
|
|
|
|
|
+ mutex_lock(&nf_sockopt_mutex);
|
|
ops->use--;
|
|
ops->use--;
|
|
if (ops->cleanup_task)
|
|
if (ops->cleanup_task)
|
|
wake_up_process(ops->cleanup_task);
|
|
wake_up_process(ops->cleanup_task);
|
|
- up(&nf_sockopt_mutex);
|
|
|
|
|
|
+ mutex_unlock(&nf_sockopt_mutex);
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|