Commit d72367b6f36e557f122beefaa8c6b80eb1c7f245

Authored by Harald Welte
Committed by David S. Miller
1 parent bbd86b9fc4

[NETFILTER]: more verbose return codes from nf_{log,queue}

This adds EEXIST to distinguish between the following return values:
0: 	nobody was registered, registration successful
EEXIST:	the exact same handler was already registered, no registration
	required
EBUSY:	somebody else is registered, registration unsuccessful.

Signed-off-by: Harald Welte <laforge@netfilter.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 2 changed files with 10 additions and 2 deletions Side-by-side Diff

net/netfilter/nf_log.c
... ... @@ -18,6 +18,8 @@
18 18 static struct nf_logger *nf_logging[NPROTO]; /* = NULL */
19 19 static DEFINE_SPINLOCK(nf_log_lock);
20 20  
  21 +/* return EBUSY if somebody else is registered, EEXIST if the same logger
  22 + * is registred, 0 on success. */
21 23 int nf_log_register(int pf, struct nf_logger *logger)
22 24 {
23 25 int ret = -EBUSY;
... ... @@ -28,7 +30,9 @@
28 30 if (!nf_logging[pf]) {
29 31 rcu_assign_pointer(nf_logging[pf], logger);
30 32 ret = 0;
31   - }
  33 + } else if (nf_logging[pf] == logger)
  34 + ret = -EEXIST;
  35 +
32 36 spin_unlock(&nf_log_lock);
33 37 return ret;
34 38 }
net/netfilter/nf_queue.c
... ... @@ -20,6 +20,8 @@
20 20  
21 21 static DEFINE_RWLOCK(queue_handler_lock);
22 22  
  23 +/* return EBUSY when somebody else is registered, return EEXIST if the
  24 + * same handler is registered, return 0 in case of success. */
23 25 int nf_register_queue_handler(int pf, struct nf_queue_handler *qh)
24 26 {
25 27 int ret;
... ... @@ -28,7 +30,9 @@
28 30 return -EINVAL;
29 31  
30 32 write_lock_bh(&queue_handler_lock);
31   - if (queue_handler[pf])
  33 + if (queue_handler[pf] == qh)
  34 + ret = -EEXIST;
  35 + else if (queue_handler[pf])
32 36 ret = -EBUSY;
33 37 else {
34 38 queue_handler[pf] = qh;