[NETFILTER]: add /proc/net/netfilter interface to nf_queue
authorHarald Welte <laforge@netfilter.org>
Wed, 10 Aug 2005 03:23:11 +0000 (20:23 -0700)
committerDavid S. Miller <davem@sunset.davemloft.net>
Mon, 29 Aug 2005 22:51:18 +0000 (15:51 -0700)
This patch adds a /proc/net/netfilter/nf_queue file, similar to the
recently-added /proc/net/netfilter/nf_log.  It indicates which queue
handler is registered to which protocol family.  This is useful since
there are now multiple queue handlers in the treee (ip[6]_queue,
nfnetlink_queue).

Signed-off-by: Harald Welte <laforge@netfilter.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/netfilter.h
net/ipv4/netfilter/ip_queue.c
net/ipv6/netfilter/ip6_queue.c
net/netfilter/nf_log.c
net/netfilter/nf_queue.c
net/netfilter/nfnetlink_queue.c

index 815583af06c217b917a60f5bb606d58f4fdc68bf..bf430fcbe3641476f895d1c9224e01b448cdb569 100644 (file)
@@ -225,13 +225,16 @@ int nf_getsockopt(struct sock *sk, int pf, int optval, char __user *opt,
                  int *len);
 
 /* Packet queuing */
-typedef int (*nf_queue_outfn_t)(struct sk_buff *skb, 
-                                struct nf_info *info,
-                               unsigned int queuenum, void *data);
+struct nf_queue_handler {
+       int (*outfn)(struct sk_buff *skb, struct nf_info *info,
+                    unsigned int queuenum, void *data);
+       void *data;
+       char *name;
+};
 extern int nf_register_queue_handler(int pf, 
-                                     nf_queue_outfn_t outfn, void *data);
+                                     struct nf_queue_handler *qh);
 extern int nf_unregister_queue_handler(int pf);
-extern void nf_unregister_queue_handlers(nf_queue_outfn_t outfn);
+extern void nf_unregister_queue_handlers(struct nf_queue_handler *qh);
 extern void nf_reinject(struct sk_buff *skb,
                        struct nf_info *info,
                        unsigned int verdict);
index 629de649f13019808c5150c64ca71b49fcc8e68b..1c49833e00a9c959b632c771d36c12e99e6d7ab0 100644 (file)
@@ -656,6 +656,11 @@ ipq_get_info(char *buffer, char **start, off_t offset, int length)
 }
 #endif /* CONFIG_PROC_FS */
 
+static struct nf_queue_handler nfqh = {
+       .name   = "ip_queue",
+       .outfn  = &ipq_enqueue_packet,
+};
+
 static int
 init_or_cleanup(int init)
 {
@@ -684,7 +689,7 @@ init_or_cleanup(int init)
        register_netdevice_notifier(&ipq_dev_notifier);
        ipq_sysctl_header = register_sysctl_table(ipq_root_table, 0);
        
-       status = nf_register_queue_handler(PF_INET, ipq_enqueue_packet, NULL);
+       status = nf_register_queue_handler(PF_INET, &nfqh);
        if (status < 0) {
                printk(KERN_ERR "ip_queue: failed to register queue handler\n");
                goto cleanup_sysctl;
@@ -692,7 +697,7 @@ init_or_cleanup(int init)
        return status;
 
 cleanup:
-       nf_unregister_queue_handlers(&ipq_enqueue_packet);
+       nf_unregister_queue_handlers(&nfqh);
        synchronize_net();
        ipq_flush(NF_DROP);
        
index 56ffec3568fa907392126e5ad0de4eaea5dd7a08..7ecb91e24a34673b9b18cbb53a5465feae7fce63 100644 (file)
@@ -652,6 +652,11 @@ ipq_get_info(char *buffer, char **start, off_t offset, int length)
        return len;
 }
 
+static struct nf_queue_handler nfqh = {
+       .name   = "ip6_queue",
+       .outfn  = &ipq_enqueue_packet,
+};
+
 static int
 init_or_cleanup(int init)
 {
@@ -679,7 +684,7 @@ init_or_cleanup(int init)
        register_netdevice_notifier(&ipq_dev_notifier);
        ipq_sysctl_header = register_sysctl_table(ipq_root_table, 0);
        
-       status = nf_register_queue_handler(PF_INET6, ipq_enqueue_packet, NULL);
+       status = nf_register_queue_handler(PF_INET6, &nfqh);
        if (status < 0) {
                printk(KERN_ERR "ip6_queue: failed to register queue handler\n");
                goto cleanup_sysctl;
@@ -687,7 +692,7 @@ init_or_cleanup(int init)
        return status;
 
 cleanup:
-       nf_unregister_queue_handlers(&ipq_enqueue_packet);
+       nf_unregister_queue_handlers(&nfqh);
        synchronize_net();
        ipq_flush(NF_DROP);
        
index ec58c4d2c6678ac4f571e0969876f296b1e150c2..31a9d63921d68fcef2e759bc7979ffd65b512525 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/proc_fs.h>
 #include <linux/skbuff.h>
 #include <linux/netfilter.h>
+#include <linux/seq_file.h>
 #include <net/protocol.h>
 
 #include "nf_internals.h"
index 5586f843ed45f302a7dcfc3383f682b058b3c1b0..8a67bde8b6400b97b8b06bc4d16afa84ec0c37b7 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/proc_fs.h>
 #include <linux/skbuff.h>
 #include <linux/netfilter.h>
+#include <linux/seq_file.h>
 #include <net/protocol.h>
 
 #include "nf_internals.h"
  * long term mutex.  The handler must provide an an outfn() to accept packets
  * for queueing and must reinject all packets it receives, no matter what.
  */
-static struct nf_queue_handler_t {
-       nf_queue_outfn_t outfn;
-       void *data;
-} queue_handler[NPROTO];
-
+static struct nf_queue_handler *queue_handler[NPROTO];
 static struct nf_queue_rerouter *queue_rerouter;
 
 static DEFINE_RWLOCK(queue_handler_lock);
 
-
-int nf_register_queue_handler(int pf, nf_queue_outfn_t outfn, void *data)
+int nf_register_queue_handler(int pf, struct nf_queue_handler *qh)
 {      
        int ret;
 
@@ -32,11 +28,10 @@ int nf_register_queue_handler(int pf, nf_queue_outfn_t outfn, void *data)
                return -EINVAL;
 
        write_lock_bh(&queue_handler_lock);
-       if (queue_handler[pf].outfn)
+       if (queue_handler[pf])
                ret = -EBUSY;
        else {
-               queue_handler[pf].outfn = outfn;
-               queue_handler[pf].data = data;
+               queue_handler[pf] = qh;
                ret = 0;
        }
        write_unlock_bh(&queue_handler_lock);
@@ -52,8 +47,7 @@ int nf_unregister_queue_handler(int pf)
                return -EINVAL;
 
        write_lock_bh(&queue_handler_lock);
-       queue_handler[pf].outfn = NULL;
-       queue_handler[pf].data = NULL;
+       queue_handler[pf] = NULL;
        write_unlock_bh(&queue_handler_lock);
        
        return 0;
@@ -85,16 +79,14 @@ int nf_unregister_queue_rerouter(int pf)
 }
 EXPORT_SYMBOL_GPL(nf_unregister_queue_rerouter);
 
-void nf_unregister_queue_handlers(nf_queue_outfn_t outfn)
+void nf_unregister_queue_handlers(struct nf_queue_handler *qh)
 {
        int pf;
 
        write_lock_bh(&queue_handler_lock);
        for (pf = 0; pf < NPROTO; pf++)  {
-               if (queue_handler[pf].outfn == outfn) {
-                       queue_handler[pf].outfn = NULL;
-                       queue_handler[pf].data = NULL;
-               }
+               if (queue_handler[pf] == qh)
+                       queue_handler[pf] = NULL;
        }
        write_unlock_bh(&queue_handler_lock);
 }
@@ -121,7 +113,7 @@ int nf_queue(struct sk_buff **skb,
 
        /* QUEUE == DROP if noone is waiting, to be safe. */
        read_lock(&queue_handler_lock);
-       if (!queue_handler[pf].outfn) {
+       if (!queue_handler[pf]->outfn) {
                read_unlock(&queue_handler_lock);
                kfree_skb(*skb);
                return 1;
@@ -162,8 +154,8 @@ int nf_queue(struct sk_buff **skb,
        if (queue_rerouter[pf].save)
                queue_rerouter[pf].save(*skb, info);
 
-       status = queue_handler[pf].outfn(*skb, info, queuenum,
-                                        queue_handler[pf].data);
+       status = queue_handler[pf]->outfn(*skb, info, queuenum,
+                                         queue_handler[pf]->data);
 
        if (status >= 0 && queue_rerouter[pf].reroute)
                status = queue_rerouter[pf].reroute(skb, info);
@@ -259,13 +251,87 @@ void nf_reinject(struct sk_buff *skb, struct nf_info *info,
 }
 EXPORT_SYMBOL(nf_reinject);
 
+#ifdef CONFIG_PROC_FS
+static void *seq_start(struct seq_file *seq, loff_t *pos)
+{
+       if (*pos >= NPROTO)
+               return NULL;
+
+       return pos;
+}
+
+static void *seq_next(struct seq_file *s, void *v, loff_t *pos)
+{
+       (*pos)++;
+
+       if (*pos >= NPROTO)
+               return NULL;
+
+       return pos;
+}
+
+static void seq_stop(struct seq_file *s, void *v)
+{
+
+}
+
+static int seq_show(struct seq_file *s, void *v)
+{
+       int ret;
+       loff_t *pos = v;
+       struct nf_queue_handler *qh;
+
+       read_lock_bh(&queue_handler_lock);
+       qh = queue_handler[*pos];
+       if (!qh)
+               ret = seq_printf(s, "%2lld NONE\n", *pos);
+       else
+               ret = seq_printf(s, "%2lld %s\n", *pos, qh->name);
+       read_unlock_bh(&queue_handler_lock);
+
+       return ret;
+}
+
+static struct seq_operations nfqueue_seq_ops = {
+       .start  = seq_start,
+       .next   = seq_next,
+       .stop   = seq_stop,
+       .show   = seq_show,
+};
+
+static int nfqueue_open(struct inode *inode, struct file *file)
+{
+       return seq_open(file, &nfqueue_seq_ops);
+}
+
+static struct file_operations nfqueue_file_ops = {
+       .owner   = THIS_MODULE,
+       .open    = nfqueue_open,
+       .read    = seq_read,
+       .llseek  = seq_lseek,
+       .release = seq_release,
+};
+#endif /* PROC_FS */
+
+
 int __init netfilter_queue_init(void)
 {
+#ifdef CONFIG_PROC_FS
+       struct proc_dir_entry *pde;
+#endif
        queue_rerouter = kmalloc(NPROTO * sizeof(struct nf_queue_rerouter),
                                 GFP_KERNEL);
        if (!queue_rerouter)
                return -ENOMEM;
 
+#ifdef CONFIG_PROC_FS
+       pde = create_proc_entry("nf_queue", S_IRUGO, proc_net_netfilter);
+       if (!pde) {
+               kfree(queue_rerouter);
+               return -1;
+       }
+       pde->proc_fops = &nfqueue_file_ops;
+#endif
        memset(queue_rerouter, 0, NPROTO * sizeof(struct nf_queue_rerouter));
 
        return 0;
index bf9223084b4a78786e8b2cdf10f5ebbfd41b01e4..741686ff71d868500f09105e909f2c486efa8296 100644 (file)
@@ -845,6 +845,11 @@ static const int nfqa_cfg_min[NFQA_CFG_MAX] = {
        [NFQA_CFG_PARAMS-1]     = sizeof(struct nfqnl_msg_config_params),
 };
 
+static struct nf_queue_handler nfqh = {
+       .name   = "nf_queue",
+       .outfn  = &nfqnl_enqueue_packet,
+};
+
 static int
 nfqnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
                  struct nlmsghdr *nlh, struct nfattr *nfqa[], int *errp)
@@ -890,10 +895,7 @@ nfqnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
                case NFQNL_CFG_CMD_PF_BIND:
                        QDEBUG("registering queue handler for pf=%u\n",
                                ntohs(cmd->pf));
-                       ret = nf_register_queue_handler(ntohs(cmd->pf),
-                                                       nfqnl_enqueue_packet,
-                                                       NULL);
-
+                       ret = nf_register_queue_handler(ntohs(cmd->pf), &nfqh);
                        break;
                case NFQNL_CFG_CMD_PF_UNBIND:
                        QDEBUG("unregistering queue handler for pf=%u\n",
@@ -1098,7 +1100,7 @@ init_or_cleanup(int init)
        return status;
 
 cleanup:
-       nf_unregister_queue_handlers(nfqnl_enqueue_packet);
+       nf_unregister_queue_handlers(&nfqh);
        unregister_netdevice_notifier(&nfqnl_dev_notifier);
 #ifdef CONFIG_PROC_FS
        remove_proc_entry("nfnetlink_queue", proc_net_netfilter);