Commit 0c26ed1c authored by Marcelo Leitner's avatar Marcelo Leitner Committed by Pablo Neira Ayuso

netfilter: nf_log: Introduce nft_log_dereference() macro

Wrap up a common call pattern in an easier to handle call.
Signed-off-by: default avatarMarcelo Ricardo Leitner <mleitner@redhat.com>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent e9105f1b
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
static struct nf_logger __rcu *loggers[NFPROTO_NUMPROTO][NF_LOG_TYPE_MAX] __read_mostly; static struct nf_logger __rcu *loggers[NFPROTO_NUMPROTO][NF_LOG_TYPE_MAX] __read_mostly;
static DEFINE_MUTEX(nf_log_mutex); 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) static struct nf_logger *__find_logger(int pf, const char *str_logger)
{ {
struct nf_logger *log; struct nf_logger *log;
...@@ -28,8 +31,7 @@ static struct nf_logger *__find_logger(int pf, const char *str_logger) ...@@ -28,8 +31,7 @@ static struct nf_logger *__find_logger(int pf, const char *str_logger)
if (loggers[pf][i] == NULL) if (loggers[pf][i] == NULL)
continue; continue;
log = rcu_dereference_protected(loggers[pf][i], log = nft_log_dereference(loggers[pf][i]);
lockdep_is_held(&nf_log_mutex));
if (!strncasecmp(str_logger, log->name, strlen(log->name))) if (!strncasecmp(str_logger, log->name, strlen(log->name)))
return log; return log;
} }
...@@ -45,8 +47,7 @@ void nf_log_set(struct net *net, u_int8_t pf, const struct nf_logger *logger) ...@@ -45,8 +47,7 @@ void nf_log_set(struct net *net, u_int8_t pf, const struct nf_logger *logger)
return; return;
mutex_lock(&nf_log_mutex); mutex_lock(&nf_log_mutex);
log = rcu_dereference_protected(net->nf.nf_loggers[pf], log = nft_log_dereference(net->nf.nf_loggers[pf]);
lockdep_is_held(&nf_log_mutex));
if (log == NULL) if (log == NULL)
rcu_assign_pointer(net->nf.nf_loggers[pf], logger); rcu_assign_pointer(net->nf.nf_loggers[pf], logger);
...@@ -61,8 +62,7 @@ void nf_log_unset(struct net *net, const struct nf_logger *logger) ...@@ -61,8 +62,7 @@ void nf_log_unset(struct net *net, const struct nf_logger *logger)
mutex_lock(&nf_log_mutex); mutex_lock(&nf_log_mutex);
for (i = 0; i < NFPROTO_NUMPROTO; i++) { for (i = 0; i < NFPROTO_NUMPROTO; i++) {
log = rcu_dereference_protected(net->nf.nf_loggers[i], log = nft_log_dereference(net->nf.nf_loggers[i]);
lockdep_is_held(&nf_log_mutex));
if (log == logger) if (log == logger)
RCU_INIT_POINTER(net->nf.nf_loggers[i], NULL); RCU_INIT_POINTER(net->nf.nf_loggers[i], NULL);
} }
...@@ -297,8 +297,7 @@ static int seq_show(struct seq_file *s, void *v) ...@@ -297,8 +297,7 @@ static int seq_show(struct seq_file *s, void *v)
int i, ret; int i, ret;
struct net *net = seq_file_net(s); struct net *net = seq_file_net(s);
logger = rcu_dereference_protected(net->nf.nf_loggers[*pos], logger = nft_log_dereference(net->nf.nf_loggers[*pos]);
lockdep_is_held(&nf_log_mutex));
if (!logger) if (!logger)
ret = seq_printf(s, "%2lld NONE (", *pos); ret = seq_printf(s, "%2lld NONE (", *pos);
...@@ -312,8 +311,7 @@ static int seq_show(struct seq_file *s, void *v) ...@@ -312,8 +311,7 @@ static int seq_show(struct seq_file *s, void *v)
if (loggers[*pos][i] == NULL) if (loggers[*pos][i] == NULL)
continue; continue;
logger = rcu_dereference_protected(loggers[*pos][i], logger = nft_log_dereference(loggers[*pos][i]);
lockdep_is_held(&nf_log_mutex));
ret = seq_printf(s, "%s", logger->name); ret = seq_printf(s, "%s", logger->name);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -385,8 +383,7 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write, ...@@ -385,8 +383,7 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
mutex_unlock(&nf_log_mutex); mutex_unlock(&nf_log_mutex);
} else { } else {
mutex_lock(&nf_log_mutex); mutex_lock(&nf_log_mutex);
logger = rcu_dereference_protected(net->nf.nf_loggers[tindex], logger = nft_log_dereference(net->nf.nf_loggers[tindex]);
lockdep_is_held(&nf_log_mutex));
if (!logger) if (!logger)
table->data = "NONE"; table->data = "NONE";
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment