Skip to content

Commit

Permalink
netfilter: nf_log: Introduce nft_log_dereference() macro
Browse files Browse the repository at this point in the history
Wrap up a common call pattern in an easier to handle call.

Signed-off-by: Marcelo Ricardo Leitner <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
  • Loading branch information
marceloleitner authored and ummakynes committed Oct 30, 2014
1 parent e9105f1 commit 0c26ed1
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions net/netfilter/nf_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
static struct nf_logger __rcu *loggers[NFPROTO_NUMPROTO][NF_LOG_TYPE_MAX] __read_mostly;
static DEFINE_MUTEX(nf_log_mutex);

#define nft_log_dereference(logger) \
rcu_dereference_protected(logger, lockdep_is_held(&nf_log_mutex))

static struct nf_logger *__find_logger(int pf, const char *str_logger)
{
struct nf_logger *log;
Expand All @@ -28,8 +31,7 @@ static struct nf_logger *__find_logger(int pf, const char *str_logger)
if (loggers[pf][i] == NULL)
continue;

log = rcu_dereference_protected(loggers[pf][i],
lockdep_is_held(&nf_log_mutex));
log = nft_log_dereference(loggers[pf][i]);
if (!strncasecmp(str_logger, log->name, strlen(log->name)))
return log;
}
Expand All @@ -45,8 +47,7 @@ void nf_log_set(struct net *net, u_int8_t pf, const struct nf_logger *logger)
return;

mutex_lock(&nf_log_mutex);
log = rcu_dereference_protected(net->nf.nf_loggers[pf],
lockdep_is_held(&nf_log_mutex));
log = nft_log_dereference(net->nf.nf_loggers[pf]);
if (log == NULL)
rcu_assign_pointer(net->nf.nf_loggers[pf], logger);

Expand All @@ -61,8 +62,7 @@ void nf_log_unset(struct net *net, const struct nf_logger *logger)

mutex_lock(&nf_log_mutex);
for (i = 0; i < NFPROTO_NUMPROTO; i++) {
log = rcu_dereference_protected(net->nf.nf_loggers[i],
lockdep_is_held(&nf_log_mutex));
log = nft_log_dereference(net->nf.nf_loggers[i]);
if (log == logger)
RCU_INIT_POINTER(net->nf.nf_loggers[i], NULL);
}
Expand Down Expand Up @@ -297,8 +297,7 @@ static int seq_show(struct seq_file *s, void *v)
int i, ret;
struct net *net = seq_file_net(s);

logger = rcu_dereference_protected(net->nf.nf_loggers[*pos],
lockdep_is_held(&nf_log_mutex));
logger = nft_log_dereference(net->nf.nf_loggers[*pos]);

if (!logger)
ret = seq_printf(s, "%2lld NONE (", *pos);
Expand All @@ -312,8 +311,7 @@ static int seq_show(struct seq_file *s, void *v)
if (loggers[*pos][i] == NULL)
continue;

logger = rcu_dereference_protected(loggers[*pos][i],
lockdep_is_held(&nf_log_mutex));
logger = nft_log_dereference(loggers[*pos][i]);
ret = seq_printf(s, "%s", logger->name);
if (ret < 0)
return ret;
Expand Down Expand Up @@ -385,8 +383,7 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
mutex_unlock(&nf_log_mutex);
} else {
mutex_lock(&nf_log_mutex);
logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
lockdep_is_held(&nf_log_mutex));
logger = nft_log_dereference(net->nf.nf_loggers[tindex]);
if (!logger)
table->data = "NONE";
else
Expand Down

0 comments on commit 0c26ed1

Please sign in to comment.