1 #include <linux/config.h>
2 #include <linux/kernel.h>
3 #include <linux/init.h>
4 #include <linux/module.h>
5 #include <linux/proc_fs.h>
6 #include <linux/skbuff.h>
7 #include <linux/netfilter.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_logging[NPROTO]; /* = NULL */
18 static DEFINE_SPINLOCK(nf_log_lock);
20 int nf_log_register(int pf, struct nf_logger *logger)
24 /* Any setup of logging members must be done before
25 * substituting pointer. */
26 spin_lock(&nf_log_lock);
27 if (!nf_logging[pf]) {
28 rcu_assign_pointer(nf_logging[pf], logger);
31 spin_unlock(&nf_log_lock);
34 EXPORT_SYMBOL(nf_log_register);
36 void nf_log_unregister_pf(int pf)
38 spin_lock(&nf_log_lock);
39 nf_logging[pf] = NULL;
40 spin_unlock(&nf_log_lock);
42 /* Give time to concurrent readers. */
45 EXPORT_SYMBOL(nf_log_unregister_pf);
47 void nf_log_unregister_logger(struct nf_logger *logger)
51 spin_lock(&nf_log_lock);
52 for (i = 0; i < NPROTO; i++) {
53 if (nf_logging[i] == logger)
56 spin_unlock(&nf_log_lock);
60 EXPORT_SYMBOL(nf_log_unregister_logger);
62 void nf_log_packet(int pf,
64 const struct sk_buff *skb,
65 const struct net_device *in,
66 const struct net_device *out,
67 struct nf_loginfo *loginfo,
71 char prefix[NF_LOG_PREFIXLEN];
72 struct nf_logger *logger;
75 logger = rcu_dereference(nf_logging[pf]);
78 vsnprintf(prefix, sizeof(prefix), fmt, args);
80 /* We must read logging before nf_logfn[pf] */
81 logger->logfn(pf, hooknum, skb, in, out, loginfo, prefix);
82 } else if (net_ratelimit()) {
83 printk(KERN_WARNING "nf_log_packet: can\'t log since "
84 "no backend logging module loaded in! Please either "
85 "load one, or disable logging explicitly\n");
89 EXPORT_SYMBOL(nf_log_packet);
92 static void *seq_start(struct seq_file *seq, loff_t *pos)
102 static void *seq_next(struct seq_file *s, void *v, loff_t *pos)
112 static void seq_stop(struct seq_file *s, void *v)
117 static int seq_show(struct seq_file *s, void *v)
120 const struct nf_logger *logger;
122 logger = rcu_dereference(nf_logging[*pos]);
125 return seq_printf(s, "%2lld NONE\n", *pos);
127 return seq_printf(s, "%2lld %s\n", *pos, logger->name);
130 static struct seq_operations nflog_seq_ops = {
137 static int nflog_open(struct inode *inode, struct file *file)
139 return seq_open(file, &nflog_seq_ops);
142 static struct file_operations nflog_file_ops = {
143 .owner = THIS_MODULE,
147 .release = seq_release,
153 int __init netfilter_log_init(void)
155 #ifdef CONFIG_PROC_FS
156 struct proc_dir_entry *pde;
157 pde = create_proc_entry("nf_log", S_IRUGO, proc_net_netfilter);
162 pde->proc_fops = &nflog_file_ops;