Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 48102
b: refs/heads/master
c: 9b73534
h: refs/heads/master
v: v3
  • Loading branch information
Patrick McHardy authored and David S. Miller committed Feb 12, 2007
1 parent 3650492 commit 73f4c7e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9dc6aa5fcfc104becd86c89c5e7ec90e840e0163
refs/heads/master: 9b73534dc57fa2fd5ef567586adb83c16e88a52f
26 changes: 15 additions & 11 deletions trunk/net/netfilter/nf_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,31 @@
#define NF_LOG_PREFIXLEN 128

static struct nf_logger *nf_logging[NPROTO]; /* = NULL */
static DEFINE_SPINLOCK(nf_log_lock);
static DEFINE_MUTEX(nf_log_mutex);

/* return EBUSY if somebody else is registered, EEXIST if the same logger
* is registred, 0 on success. */
int nf_log_register(int pf, struct nf_logger *logger)
{
int ret = -EBUSY;
int ret;

if (pf >= NPROTO)
return -EINVAL;

/* Any setup of logging members must be done before
* substituting pointer. */
spin_lock(&nf_log_lock);
if (!nf_logging[pf]) {
ret = mutex_lock_interruptible(&nf_log_mutex);
if (ret < 0)
return ret;

if (!nf_logging[pf])
rcu_assign_pointer(nf_logging[pf], logger);
ret = 0;
} else if (nf_logging[pf] == logger)
else if (nf_logging[pf] == logger)
ret = -EEXIST;
else
ret = -EBUSY;

spin_unlock(&nf_log_lock);
mutex_unlock(&nf_log_mutex);
return ret;
}
EXPORT_SYMBOL(nf_log_register);
Expand All @@ -44,9 +48,9 @@ void nf_log_unregister_pf(int pf)
{
if (pf >= NPROTO)
return;
spin_lock(&nf_log_lock);
mutex_lock(&nf_log_mutex);
rcu_assign_pointer(nf_logging[pf], NULL);
spin_unlock(&nf_log_lock);
mutex_unlock(&nf_log_mutex);

/* Give time to concurrent readers. */
synchronize_rcu();
Expand All @@ -57,12 +61,12 @@ void nf_log_unregister_logger(struct nf_logger *logger)
{
int i;

spin_lock(&nf_log_lock);
mutex_lock(&nf_log_mutex);
for (i = 0; i < NPROTO; i++) {
if (nf_logging[i] == logger)
rcu_assign_pointer(nf_logging[i], NULL);
}
spin_unlock(&nf_log_lock);
mutex_unlock(&nf_log_mutex);

synchronize_rcu();
}
Expand Down

0 comments on commit 73f4c7e

Please sign in to comment.