2 * This is a module which is used for queueing packets and communicating with
3 * userspace via nfetlink.
5 * (C) 2005 by Harald Welte <laforge@netfilter.org>
7 * Based on the old ipv4-only ip_queue.c:
8 * (C) 2000-2002 James Morris <jmorris@intercode.com.au>
9 * (C) 2003-2005 Netfilter Core Team <coreteam@netfilter.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/module.h>
17 #include <linux/skbuff.h>
18 #include <linux/init.h>
19 #include <linux/spinlock.h>
20 #include <linux/notifier.h>
21 #include <linux/netdevice.h>
22 #include <linux/netfilter.h>
23 #include <linux/proc_fs.h>
24 #include <linux/netfilter_ipv4.h>
25 #include <linux/netfilter_ipv6.h>
26 #include <linux/netfilter/nfnetlink.h>
27 #include <linux/netfilter/nfnetlink_queue.h>
28 #include <linux/list.h>
31 #include <asm/atomic.h>
33 #define NFQNL_QMAX_DEFAULT 1024
36 #define QDEBUG(x, args ...) printk(KERN_DEBUG "%s(%d):%s(): " x, \
37 __FILE__, __LINE__, __FUNCTION__, \
40 #define QDEBUG(x, ...)
43 struct nfqnl_queue_entry {
44 struct list_head list;
50 struct nfqnl_instance {
51 struct hlist_node hlist; /* global list of queues */
55 unsigned int queue_maxlen;
56 unsigned int copy_range;
57 unsigned int queue_total;
58 unsigned int queue_dropped;
59 unsigned int queue_user_dropped;
61 atomic_t id_sequence; /* 'sequence' of pkt ids */
63 u_int16_t queue_num; /* number of this queue */
68 struct list_head queue_list; /* packets in queue */
71 typedef int (*nfqnl_cmpfn)(struct nfqnl_queue_entry *, unsigned long);
73 static DEFINE_RWLOCK(instances_lock);
75 u_int64_t htonll(u_int64_t in)
80 for (i = 0; i < sizeof(u_int64_t); i++)
81 ((u_int8_t *)&out)[sizeof(u_int64_t)-1] = ((u_int8_t *)&in)[i];
86 #define INSTANCE_BUCKETS 16
87 static struct hlist_head instance_table[INSTANCE_BUCKETS];
89 static inline u_int8_t instance_hashfn(u_int16_t queue_num)
91 return ((queue_num >> 8) | queue_num) % INSTANCE_BUCKETS;
94 static struct nfqnl_instance *
95 __instance_lookup(u_int16_t queue_num)
97 struct hlist_head *head;
98 struct hlist_node *pos;
99 struct nfqnl_instance *inst;
101 head = &instance_table[instance_hashfn(queue_num)];
102 hlist_for_each_entry(inst, pos, head, hlist) {
103 if (inst->queue_num == queue_num)
109 static struct nfqnl_instance *
110 instance_lookup_get(u_int16_t queue_num)
112 struct nfqnl_instance *inst;
114 read_lock_bh(&instances_lock);
115 inst = __instance_lookup(queue_num);
117 atomic_inc(&inst->use);
118 read_unlock_bh(&instances_lock);
124 instance_put(struct nfqnl_instance *inst)
126 if (inst && atomic_dec_and_test(&inst->use)) {
127 QDEBUG("kfree(inst=%p)\n", inst);
132 static struct nfqnl_instance *
133 instance_create(u_int16_t queue_num, int pid)
135 struct nfqnl_instance *inst;
137 QDEBUG("entering for queue_num=%u, pid=%d\n", queue_num, pid);
139 write_lock_bh(&instances_lock);
140 if (__instance_lookup(queue_num)) {
142 QDEBUG("aborting, instance already exists\n");
146 inst = kmalloc(sizeof(*inst), GFP_ATOMIC);
150 memset(inst, 0, sizeof(*inst));
151 inst->queue_num = queue_num;
152 inst->peer_pid = pid;
153 inst->queue_maxlen = NFQNL_QMAX_DEFAULT;
154 inst->copy_range = 0xfffff;
155 inst->copy_mode = NFQNL_COPY_NONE;
156 atomic_set(&inst->id_sequence, 0);
157 /* needs to be two, since we _put() after creation */
158 atomic_set(&inst->use, 2);
159 inst->lock = SPIN_LOCK_UNLOCKED;
160 INIT_LIST_HEAD(&inst->queue_list);
162 if (!try_module_get(THIS_MODULE))
165 hlist_add_head(&inst->hlist,
166 &instance_table[instance_hashfn(queue_num)]);
168 write_unlock_bh(&instances_lock);
170 QDEBUG("successfully created new instance\n");
177 write_unlock_bh(&instances_lock);
181 static void nfqnl_flush(struct nfqnl_instance *queue, int verdict);
184 _instance_destroy2(struct nfqnl_instance *inst, int lock)
186 /* first pull it out of the global list */
188 write_lock_bh(&instances_lock);
190 QDEBUG("removing instance %p (queuenum=%u) from hash\n",
191 inst, inst->queue_num);
192 hlist_del(&inst->hlist);
195 write_unlock_bh(&instances_lock);
197 /* then flush all pending skbs from the queue */
198 nfqnl_flush(inst, NF_DROP);
200 /* and finally put the refcount */
203 module_put(THIS_MODULE);
207 __instance_destroy(struct nfqnl_instance *inst)
209 _instance_destroy2(inst, 0);
213 instance_destroy(struct nfqnl_instance *inst)
215 _instance_destroy2(inst, 1);
221 issue_verdict(struct nfqnl_queue_entry *entry, int verdict)
223 QDEBUG("entering for entry %p, verdict %u\n", entry, verdict);
225 /* TCP input path (and probably other bits) assume to be called
226 * from softirq context, not from syscall, like issue_verdict is
227 * called. TCP input path deadlocks with locks taken from timer
228 * softirq, e.g. We therefore emulate this by local_bh_disable() */
231 nf_reinject(entry->skb, entry->info, verdict);
238 __enqueue_entry(struct nfqnl_instance *queue,
239 struct nfqnl_queue_entry *entry)
241 list_add(&entry->list, &queue->queue_list);
242 queue->queue_total++;
246 * Find and return a queued entry matched by cmpfn, or return the last
247 * entry if cmpfn is NULL.
249 static inline struct nfqnl_queue_entry *
250 __find_entry(struct nfqnl_instance *queue, nfqnl_cmpfn cmpfn,
255 list_for_each_prev(p, &queue->queue_list) {
256 struct nfqnl_queue_entry *entry = (struct nfqnl_queue_entry *)p;
258 if (!cmpfn || cmpfn(entry, data))
265 __dequeue_entry(struct nfqnl_instance *q, struct nfqnl_queue_entry *entry)
267 list_del(&entry->list);
271 static inline struct nfqnl_queue_entry *
272 __find_dequeue_entry(struct nfqnl_instance *queue,
273 nfqnl_cmpfn cmpfn, unsigned long data)
275 struct nfqnl_queue_entry *entry;
277 entry = __find_entry(queue, cmpfn, data);
281 __dequeue_entry(queue, entry);
287 __nfqnl_flush(struct nfqnl_instance *queue, int verdict)
289 struct nfqnl_queue_entry *entry;
291 while ((entry = __find_dequeue_entry(queue, NULL, 0)))
292 issue_verdict(entry, verdict);
296 __nfqnl_set_mode(struct nfqnl_instance *queue,
297 unsigned char mode, unsigned int range)
302 case NFQNL_COPY_NONE:
303 case NFQNL_COPY_META:
304 queue->copy_mode = mode;
305 queue->copy_range = 0;
308 case NFQNL_COPY_PACKET:
309 queue->copy_mode = mode;
310 /* we're using struct nfattr which has 16bit nfa_len */
312 queue->copy_range = 0xffff;
314 queue->copy_range = range;
324 static struct nfqnl_queue_entry *
325 find_dequeue_entry(struct nfqnl_instance *queue,
326 nfqnl_cmpfn cmpfn, unsigned long data)
328 struct nfqnl_queue_entry *entry;
330 spin_lock_bh(&queue->lock);
331 entry = __find_dequeue_entry(queue, cmpfn, data);
332 spin_unlock_bh(&queue->lock);
338 nfqnl_flush(struct nfqnl_instance *queue, int verdict)
340 spin_lock_bh(&queue->lock);
341 __nfqnl_flush(queue, verdict);
342 spin_unlock_bh(&queue->lock);
345 static struct sk_buff *
346 nfqnl_build_packet_message(struct nfqnl_instance *queue,
347 struct nfqnl_queue_entry *entry, int *errp)
349 unsigned char *old_tail;
353 struct nfqnl_msg_packet_hdr pmsg;
354 struct nlmsghdr *nlh;
355 struct nfgenmsg *nfmsg;
356 unsigned int tmp_uint;
360 /* all macros expand to constant values at compile time */
361 size = NLMSG_SPACE(sizeof(struct nfqnl_msg_packet_hdr))
362 + NLMSG_SPACE(sizeof(u_int32_t)) /* ifindex */
363 + NLMSG_SPACE(sizeof(u_int32_t)) /* ifindex */
364 + NLMSG_SPACE(sizeof(u_int32_t)) /* mark */
365 + NLMSG_SPACE(sizeof(struct nfqnl_msg_packet_hw))
366 + NLMSG_SPACE(sizeof(struct nfqnl_msg_packet_timestamp));
368 spin_lock_bh(&queue->lock);
370 switch (queue->copy_mode) {
371 case NFQNL_COPY_META:
372 case NFQNL_COPY_NONE:
376 case NFQNL_COPY_PACKET:
377 if (queue->copy_range == 0
378 || queue->copy_range > entry->skb->len)
379 data_len = entry->skb->len;
381 data_len = queue->copy_range;
383 size += NLMSG_SPACE(data_len);
388 spin_unlock_bh(&queue->lock);
392 spin_unlock_bh(&queue->lock);
394 skb = alloc_skb(size, GFP_ATOMIC);
399 nlh = NLMSG_PUT(skb, 0, 0,
400 NFNL_SUBSYS_QUEUE << 8 | NFQNL_MSG_PACKET,
401 sizeof(struct nfgenmsg));
402 nfmsg = NLMSG_DATA(nlh);
403 nfmsg->nfgen_family = entry->info->pf;
404 nfmsg->version = NFNETLINK_V0;
405 nfmsg->res_id = htons(queue->queue_num);
407 pmsg.packet_id = htonl(entry->id);
408 pmsg.hw_protocol = htons(entry->skb->protocol);
409 pmsg.hook = entry->info->hook;
411 NFA_PUT(skb, NFQA_PACKET_HDR, sizeof(pmsg), &pmsg);
413 if (entry->info->indev) {
414 tmp_uint = htonl(entry->info->indev->ifindex);
415 NFA_PUT(skb, NFQA_IFINDEX_INDEV, sizeof(tmp_uint), &tmp_uint);
418 if (entry->info->outdev) {
419 tmp_uint = htonl(entry->info->outdev->ifindex);
420 NFA_PUT(skb, NFQA_IFINDEX_OUTDEV, sizeof(tmp_uint), &tmp_uint);
423 if (entry->skb->nfmark) {
424 tmp_uint = htonl(entry->skb->nfmark);
425 NFA_PUT(skb, NFQA_MARK, sizeof(u_int32_t), &tmp_uint);
428 if (entry->info->indev && entry->skb->dev
429 && entry->skb->dev->hard_header_parse) {
430 struct nfqnl_msg_packet_hw phw;
433 entry->skb->dev->hard_header_parse(entry->skb,
435 phw.hw_addrlen = htons(phw.hw_addrlen);
436 NFA_PUT(skb, NFQA_HWADDR, sizeof(phw), &phw);
439 if (entry->skb->stamp.tv_sec) {
440 struct nfqnl_msg_packet_timestamp ts;
442 ts.sec = htonll(entry->skb->stamp.tv_sec);
443 ts.usec = htonll(entry->skb->stamp.tv_usec);
445 NFA_PUT(skb, NFQA_TIMESTAMP, sizeof(ts), &ts);
450 int size = NFA_LENGTH(data_len);
452 if (skb_tailroom(skb) < (int)NFA_SPACE(data_len)) {
453 printk(KERN_WARNING "nf_queue: no tailroom!\n");
457 nfa = (struct nfattr *)skb_put(skb, NFA_ALIGN(size));
458 nfa->nfa_type = NFQA_PAYLOAD;
461 if (skb_copy_bits(entry->skb, 0, NFA_DATA(nfa), data_len))
465 nlh->nlmsg_len = skb->tail - old_tail;
474 printk(KERN_ERR "nf_queue: error creating packet message\n");
479 nfqnl_enqueue_packet(struct sk_buff *skb, struct nf_info *info,
480 unsigned int queuenum, void *data)
482 int status = -EINVAL;
483 struct sk_buff *nskb;
484 struct nfqnl_instance *queue;
485 struct nfqnl_queue_entry *entry;
489 queue = instance_lookup_get(queuenum);
491 QDEBUG("no queue instance matching\n");
495 if (queue->copy_mode == NFQNL_COPY_NONE) {
496 QDEBUG("mode COPY_NONE, aborting\n");
501 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
505 "nf_queue: OOM in nfqnl_enqueue_packet()\n");
512 entry->id = atomic_inc_return(&queue->id_sequence);
514 nskb = nfqnl_build_packet_message(queue, entry, &status);
518 spin_lock_bh(&queue->lock);
520 if (!queue->peer_pid)
521 goto err_out_free_nskb;
523 if (queue->queue_total >= queue->queue_maxlen) {
524 queue->queue_dropped++;
527 printk(KERN_WARNING "ip_queue: full at %d entries, "
528 "dropping packets(s). Dropped: %d\n",
529 queue->queue_total, queue->queue_dropped);
530 goto err_out_free_nskb;
533 /* nfnetlink_unicast will either free the nskb or add it to a socket */
534 status = nfnetlink_unicast(nskb, queue->peer_pid, MSG_DONTWAIT);
536 queue->queue_user_dropped++;
540 __enqueue_entry(queue, entry);
542 spin_unlock_bh(&queue->lock);
550 spin_unlock_bh(&queue->lock);
560 nfqnl_mangle(void *data, int data_len, struct nfqnl_queue_entry *e)
564 diff = data_len - e->skb->len;
566 skb_trim(e->skb, data_len);
568 if (data_len > 0xFFFF)
570 if (diff > skb_tailroom(e->skb)) {
571 struct sk_buff *newskb;
573 newskb = skb_copy_expand(e->skb,
574 skb_headroom(e->skb),
577 if (newskb == NULL) {
578 printk(KERN_WARNING "ip_queue: OOM "
579 "in mangle, dropping packet\n");
583 skb_set_owner_w(newskb, e->skb->sk);
587 skb_put(e->skb, diff);
589 if (!skb_make_writable(&e->skb, data_len))
591 memcpy(e->skb->data, data, data_len);
597 id_cmp(struct nfqnl_queue_entry *e, unsigned long id)
599 return (id == e->id);
603 nfqnl_set_mode(struct nfqnl_instance *queue,
604 unsigned char mode, unsigned int range)
608 spin_lock_bh(&queue->lock);
609 status = __nfqnl_set_mode(queue, mode, range);
610 spin_unlock_bh(&queue->lock);
616 dev_cmp(struct nfqnl_queue_entry *entry, unsigned long ifindex)
618 if (entry->info->indev)
619 if (entry->info->indev->ifindex == ifindex)
622 if (entry->info->outdev)
623 if (entry->info->outdev->ifindex == ifindex)
629 /* drop all packets with either indev or outdev == ifindex from all queue
632 nfqnl_dev_drop(int ifindex)
636 QDEBUG("entering for ifindex %u\n", ifindex);
638 /* this only looks like we have to hold the readlock for a way too long
639 * time, issue_verdict(), nf_reinject(), ... - but we always only
640 * issue NF_DROP, which is processed directly in nf_reinject() */
641 read_lock_bh(&instances_lock);
643 for (i = 0; i < INSTANCE_BUCKETS; i++) {
644 struct hlist_node *tmp;
645 struct nfqnl_instance *inst;
646 struct hlist_head *head = &instance_table[i];
648 hlist_for_each_entry(inst, tmp, head, hlist) {
649 struct nfqnl_queue_entry *entry;
650 while ((entry = find_dequeue_entry(inst, dev_cmp,
652 issue_verdict(entry, NF_DROP);
656 read_unlock_bh(&instances_lock);
659 #define RCV_SKB_FAIL(err) do { netlink_ack(skb, nlh, (err)); return; } while (0)
662 nfqnl_rcv_dev_event(struct notifier_block *this,
663 unsigned long event, void *ptr)
665 struct net_device *dev = ptr;
667 /* Drop any packets associated with the downed device */
668 if (event == NETDEV_DOWN)
669 nfqnl_dev_drop(dev->ifindex);
673 static struct notifier_block nfqnl_dev_notifier = {
674 .notifier_call = nfqnl_rcv_dev_event,
678 nfqnl_rcv_nl_event(struct notifier_block *this,
679 unsigned long event, void *ptr)
681 struct netlink_notify *n = ptr;
683 if (event == NETLINK_URELEASE &&
684 n->protocol == NETLINK_NETFILTER && n->pid) {
687 /* destroy all instances for this pid */
688 write_lock_bh(&instances_lock);
689 for (i = 0; i < INSTANCE_BUCKETS; i++) {
690 struct hlist_node *tmp, *t2;
691 struct nfqnl_instance *inst;
692 struct hlist_head *head = &instance_table[i];
694 hlist_for_each_entry_safe(inst, tmp, t2, head, hlist) {
695 if (n->pid == inst->peer_pid)
696 __instance_destroy(inst);
699 write_unlock_bh(&instances_lock);
704 static struct notifier_block nfqnl_rtnl_notifier = {
705 .notifier_call = nfqnl_rcv_nl_event,
708 static const int nfqa_verdict_min[NFQA_MAX] = {
709 [NFQA_VERDICT_HDR-1] = sizeof(struct nfqnl_msg_verdict_hdr),
710 [NFQA_MARK-1] = sizeof(u_int32_t),
711 [NFQA_PAYLOAD-1] = 0,
715 nfqnl_recv_verdict(struct sock *ctnl, struct sk_buff *skb,
716 struct nlmsghdr *nlh, struct nfattr *nfqa[], int *errp)
718 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
719 u_int16_t queue_num = ntohs(nfmsg->res_id);
721 struct nfqnl_msg_verdict_hdr *vhdr;
722 struct nfqnl_instance *queue;
723 unsigned int verdict;
724 struct nfqnl_queue_entry *entry;
727 if (nfattr_bad_size(nfqa, NFQA_MAX, nfqa_verdict_min)) {
728 QDEBUG("bad attribute size\n");
732 queue = instance_lookup_get(queue_num);
736 if (queue->peer_pid != NETLINK_CB(skb).pid) {
741 if (!nfqa[NFQA_VERDICT_HDR-1]) {
746 vhdr = NFA_DATA(nfqa[NFQA_VERDICT_HDR-1]);
747 verdict = ntohl(vhdr->verdict);
749 if ((verdict & NF_VERDICT_MASK) > NF_MAX_VERDICT) {
754 entry = find_dequeue_entry(queue, id_cmp, ntohl(vhdr->id));
760 if (nfqa[NFQA_PAYLOAD-1]) {
761 if (nfqnl_mangle(NFA_DATA(nfqa[NFQA_PAYLOAD-1]),
762 NFA_PAYLOAD(nfqa[NFQA_PAYLOAD-1]), entry) < 0)
766 if (nfqa[NFQA_MARK-1])
767 skb->nfmark = ntohl(*(u_int32_t *)NFA_DATA(nfqa[NFQA_MARK-1]));
769 issue_verdict(entry, verdict);
779 nfqnl_recv_unsupp(struct sock *ctnl, struct sk_buff *skb,
780 struct nlmsghdr *nlh, struct nfattr *nfqa[], int *errp)
785 static const int nfqa_cfg_min[NFQA_CFG_MAX] = {
786 [NFQA_CFG_CMD-1] = sizeof(struct nfqnl_msg_config_cmd),
787 [NFQA_CFG_PARAMS-1] = sizeof(struct nfqnl_msg_config_params),
791 nfqnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
792 struct nlmsghdr *nlh, struct nfattr *nfqa[], int *errp)
794 struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
795 u_int16_t queue_num = ntohs(nfmsg->res_id);
796 struct nfqnl_instance *queue;
799 QDEBUG("entering for msg %u\n", NFNL_MSG_TYPE(nlh->nlmsg_type));
801 if (nfattr_bad_size(nfqa, NFQA_CFG_MAX, nfqa_cfg_min)) {
802 QDEBUG("bad attribute size\n");
806 queue = instance_lookup_get(queue_num);
807 if (nfqa[NFQA_CFG_CMD-1]) {
808 struct nfqnl_msg_config_cmd *cmd;
809 cmd = NFA_DATA(nfqa[NFQA_CFG_CMD-1]);
810 QDEBUG("found CFG_CMD\n");
812 switch (cmd->command) {
813 case NFQNL_CFG_CMD_BIND:
817 queue = instance_create(queue_num, NETLINK_CB(skb).pid);
821 case NFQNL_CFG_CMD_UNBIND:
825 if (queue->peer_pid != NETLINK_CB(skb).pid) {
830 instance_destroy(queue);
832 case NFQNL_CFG_CMD_PF_BIND:
833 QDEBUG("registering queue handler for pf=%u\n",
835 ret = nf_register_queue_handler(ntohs(cmd->pf),
836 nfqnl_enqueue_packet,
840 case NFQNL_CFG_CMD_PF_UNBIND:
841 QDEBUG("unregistering queue handler for pf=%u\n",
843 /* This is a bug and a feature. We can unregister
844 * other handlers(!) */
845 ret = nf_unregister_queue_handler(ntohs(cmd->pf));
853 QDEBUG("no config command, and no instance ENOENT\n");
858 if (queue->peer_pid != NETLINK_CB(skb).pid) {
859 QDEBUG("no config command, and wrong pid\n");
865 if (nfqa[NFQA_CFG_PARAMS-1]) {
866 struct nfqnl_msg_config_params *params;
867 params = NFA_DATA(nfqa[NFQA_CFG_PARAMS-1]);
869 nfqnl_set_mode(queue, params->copy_mode,
870 ntohl(params->copy_range));
878 static struct nfnl_callback nfqnl_cb[NFQNL_MSG_MAX] = {
879 [NFQNL_MSG_PACKET] = { .call = nfqnl_recv_unsupp,
880 .attr_count = NFQA_MAX,
881 .cap_required = CAP_NET_ADMIN },
882 [NFQNL_MSG_VERDICT] = { .call = nfqnl_recv_verdict,
883 .attr_count = NFQA_MAX,
884 .cap_required = CAP_NET_ADMIN },
885 [NFQNL_MSG_CONFIG] = { .call = nfqnl_recv_config,
886 .attr_count = NFQA_CFG_MAX,
887 .cap_required = CAP_NET_ADMIN },
890 static struct nfnetlink_subsystem nfqnl_subsys = {
892 .subsys_id = NFNL_SUBSYS_QUEUE,
893 .cb_count = NFQNL_MSG_MAX,
897 #ifdef CONFIG_PROC_FS
902 static struct hlist_node *get_first(struct seq_file *seq)
904 struct iter_state *st = seq->private;
909 for (st->bucket = 0; st->bucket < INSTANCE_BUCKETS; st->bucket++) {
910 if (!hlist_empty(&instance_table[st->bucket]))
911 return instance_table[st->bucket].first;
916 static struct hlist_node *get_next(struct seq_file *seq, struct hlist_node *h)
918 struct iter_state *st = seq->private;
922 if (++st->bucket >= INSTANCE_BUCKETS)
925 h = instance_table[st->bucket].first;
930 static struct hlist_node *get_idx(struct seq_file *seq, loff_t pos)
932 struct hlist_node *head;
933 head = get_first(seq);
936 while (pos && (head = get_next(seq, head)))
938 return pos ? NULL : head;
941 static void *seq_start(struct seq_file *seq, loff_t *pos)
943 read_lock_bh(&instances_lock);
944 return get_idx(seq, *pos);
947 static void *seq_next(struct seq_file *s, void *v, loff_t *pos)
950 return get_next(s, v);
953 static void seq_stop(struct seq_file *s, void *v)
955 read_unlock_bh(&instances_lock);
958 static int seq_show(struct seq_file *s, void *v)
960 const struct nfqnl_instance *inst = v;
962 return seq_printf(s, "%5d %6d %5d %1d %5d %5d %5d %8d %2d\n",
964 inst->peer_pid, inst->queue_total,
965 inst->copy_mode, inst->copy_range,
966 inst->queue_dropped, inst->queue_user_dropped,
967 atomic_read(&inst->id_sequence),
968 atomic_read(&inst->use));
971 static struct seq_operations nfqnl_seq_ops = {
978 static int nfqnl_open(struct inode *inode, struct file *file)
980 struct seq_file *seq;
981 struct iter_state *is;
984 is = kmalloc(sizeof(*is), GFP_KERNEL);
987 memset(is, 0, sizeof(*is));
988 ret = seq_open(file, &nfqnl_seq_ops);
991 seq = file->private_data;
999 static struct file_operations nfqnl_file_ops = {
1000 .owner = THIS_MODULE,
1003 .llseek = seq_lseek,
1004 .release = seq_release_private,
1007 #endif /* PROC_FS */
1010 init_or_cleanup(int init)
1012 int i, status = -ENOMEM;
1013 #ifdef CONFIG_PROC_FS
1014 struct proc_dir_entry *proc_nfqueue;
1020 for (i = 0; i < INSTANCE_BUCKETS; i++)
1021 INIT_HLIST_HEAD(&instance_table[i]);
1023 netlink_register_notifier(&nfqnl_rtnl_notifier);
1024 status = nfnetlink_subsys_register(&nfqnl_subsys);
1026 printk(KERN_ERR "nf_queue: failed to create netlink socket\n");
1027 goto cleanup_netlink_notifier;
1030 #ifdef CONFIG_PROC_FS
1031 proc_nfqueue = create_proc_entry("nfnetlink_queue", 0440,
1032 proc_net_netfilter);
1034 goto cleanup_subsys;
1035 proc_nfqueue->proc_fops = &nfqnl_file_ops;
1038 register_netdevice_notifier(&nfqnl_dev_notifier);
1043 nf_unregister_queue_handlers(nfqnl_enqueue_packet);
1044 unregister_netdevice_notifier(&nfqnl_dev_notifier);
1045 #ifdef CONFIG_PROC_FS
1046 remove_proc_entry("nfnetlink_queue", proc_net_netfilter);
1049 nfnetlink_subsys_unregister(&nfqnl_subsys);
1050 cleanup_netlink_notifier:
1051 netlink_unregister_notifier(&nfqnl_rtnl_notifier);
1055 static int __init init(void)
1058 return init_or_cleanup(1);
1061 static void __exit fini(void)
1066 MODULE_DESCRIPTION("netfilter packet queue handler");
1067 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
1068 MODULE_LICENSE("GPL");
1069 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_QUEUE);