1 #include <linux/kernel.h>
2 #include <linux/init.h>
3 #include <linux/module.h>
4 #include <linux/proc_fs.h>
5 #include <linux/skbuff.h>
6 #include <linux/netfilter.h>
7 #include <linux/seq_file.h>
8 #include <net/protocol.h>
10 #include "nf_internals.h"
12 /* Internal logging interface, which relies on the real
15 #define NF_LOG_PREFIXLEN 128
17 static struct nf_logger *nf_loggers[NPROTO];
18 static DEFINE_MUTEX(nf_log_mutex);
20 /* return EBUSY if somebody else is registered, EEXIST if the same logger
21 * is registred, 0 on success. */
22 int nf_log_register(int pf, struct nf_logger *logger)
29 /* Any setup of logging members must be done before
30 * substituting pointer. */
31 ret = mutex_lock_interruptible(&nf_log_mutex);
36 rcu_assign_pointer(nf_loggers[pf], logger);
37 else if (nf_loggers[pf] == logger)
42 mutex_unlock(&nf_log_mutex);
45 EXPORT_SYMBOL(nf_log_register);
47 void nf_log_unregister_pf(int pf)
51 mutex_lock(&nf_log_mutex);
52 rcu_assign_pointer(nf_loggers[pf], NULL);
53 mutex_unlock(&nf_log_mutex);
55 /* Give time to concurrent readers. */
58 EXPORT_SYMBOL(nf_log_unregister_pf);
60 void nf_log_unregister(struct nf_logger *logger)
64 mutex_lock(&nf_log_mutex);
65 for (i = 0; i < NPROTO; i++) {
66 if (nf_loggers[i] == logger)
67 rcu_assign_pointer(nf_loggers[i], NULL);
69 mutex_unlock(&nf_log_mutex);
73 EXPORT_SYMBOL(nf_log_unregister);
75 void nf_log_packet(int pf,
77 const struct sk_buff *skb,
78 const struct net_device *in,
79 const struct net_device *out,
80 struct nf_loginfo *loginfo,
84 char prefix[NF_LOG_PREFIXLEN];
85 struct nf_logger *logger;
88 logger = rcu_dereference(nf_loggers[pf]);
91 vsnprintf(prefix, sizeof(prefix), fmt, args);
93 /* We must read logging before nf_logfn[pf] */
94 logger->logfn(pf, hooknum, skb, in, out, loginfo, prefix);
95 } else if (net_ratelimit()) {
96 printk(KERN_WARNING "nf_log_packet: can\'t log since "
97 "no backend logging module loaded in! Please either "
98 "load one, or disable logging explicitly\n");
102 EXPORT_SYMBOL(nf_log_packet);
104 #ifdef CONFIG_PROC_FS
105 static void *seq_start(struct seq_file *seq, loff_t *pos)
115 static void *seq_next(struct seq_file *s, void *v, loff_t *pos)
125 static void seq_stop(struct seq_file *s, void *v)
130 static int seq_show(struct seq_file *s, void *v)
133 const struct nf_logger *logger;
135 logger = rcu_dereference(nf_loggers[*pos]);
138 return seq_printf(s, "%2lld NONE\n", *pos);
140 return seq_printf(s, "%2lld %s\n", *pos, logger->name);
143 static struct seq_operations nflog_seq_ops = {
150 static int nflog_open(struct inode *inode, struct file *file)
152 return seq_open(file, &nflog_seq_ops);
155 static const struct file_operations nflog_file_ops = {
156 .owner = THIS_MODULE,
160 .release = seq_release,
166 int __init netfilter_log_init(void)
168 #ifdef CONFIG_PROC_FS
169 struct proc_dir_entry *pde;
171 pde = create_proc_entry("nf_log", S_IRUGO, proc_net_netfilter);
175 pde->proc_fops = &nflog_file_ops;