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>
9 #include <net/netfilter/nf_log.h>
11 #include "nf_internals.h"
13 /* Internal logging interface, which relies on the real
16 #define NF_LOG_PREFIXLEN 128
18 static struct nf_logger *nf_loggers[NPROTO];
19 static DEFINE_MUTEX(nf_log_mutex);
21 /* return EBUSY if somebody else is registered, EEXIST if the same logger
22 * is registred, 0 on success. */
23 int nf_log_register(int pf, struct nf_logger *logger)
30 /* Any setup of logging members must be done before
31 * substituting pointer. */
32 ret = mutex_lock_interruptible(&nf_log_mutex);
37 rcu_assign_pointer(nf_loggers[pf], logger);
38 else if (nf_loggers[pf] == logger)
43 mutex_unlock(&nf_log_mutex);
46 EXPORT_SYMBOL(nf_log_register);
48 void nf_log_unregister_pf(int pf)
52 mutex_lock(&nf_log_mutex);
53 rcu_assign_pointer(nf_loggers[pf], NULL);
54 mutex_unlock(&nf_log_mutex);
56 /* Give time to concurrent readers. */
59 EXPORT_SYMBOL(nf_log_unregister_pf);
61 void nf_log_unregister(struct nf_logger *logger)
65 mutex_lock(&nf_log_mutex);
66 for (i = 0; i < NPROTO; i++) {
67 if (nf_loggers[i] == logger)
68 rcu_assign_pointer(nf_loggers[i], NULL);
70 mutex_unlock(&nf_log_mutex);
74 EXPORT_SYMBOL(nf_log_unregister);
76 void nf_log_packet(int pf,
78 const struct sk_buff *skb,
79 const struct net_device *in,
80 const struct net_device *out,
81 struct nf_loginfo *loginfo,
85 char prefix[NF_LOG_PREFIXLEN];
86 struct nf_logger *logger;
89 logger = rcu_dereference(nf_loggers[pf]);
92 vsnprintf(prefix, sizeof(prefix), fmt, args);
94 /* We must read logging before nf_logfn[pf] */
95 logger->logfn(pf, hooknum, skb, in, out, loginfo, prefix);
96 } else if (net_ratelimit()) {
97 printk(KERN_WARNING "nf_log_packet: can\'t log since "
98 "no backend logging module loaded in! Please either "
99 "load one, or disable logging explicitly\n");
103 EXPORT_SYMBOL(nf_log_packet);
105 #ifdef CONFIG_PROC_FS
106 static void *seq_start(struct seq_file *seq, loff_t *pos)
116 static void *seq_next(struct seq_file *s, void *v, loff_t *pos)
126 static void seq_stop(struct seq_file *s, void *v)
131 static int seq_show(struct seq_file *s, void *v)
134 const struct nf_logger *logger;
136 logger = rcu_dereference(nf_loggers[*pos]);
139 return seq_printf(s, "%2lld NONE\n", *pos);
141 return seq_printf(s, "%2lld %s\n", *pos, logger->name);
144 static const struct seq_operations nflog_seq_ops = {
151 static int nflog_open(struct inode *inode, struct file *file)
153 return seq_open(file, &nflog_seq_ops);
156 static const struct file_operations nflog_file_ops = {
157 .owner = THIS_MODULE,
161 .release = seq_release,
167 int __init netfilter_log_init(void)
169 #ifdef CONFIG_PROC_FS
170 struct proc_dir_entry *pde;
172 pde = create_proc_entry("nf_log", S_IRUGO, proc_net_netfilter);
176 pde->proc_fops = &nflog_file_ops;