netfilter: nfnetlink_queue: add skb info attribute
[linux-3.10.git] / net / netfilter / nfnetlink_queue_core.c
1 /*
2  * This is a module which is used for queueing packets and communicating with
3  * userspace via nfnetlink.
4  *
5  * (C) 2005 by Harald Welte <laforge@netfilter.org>
6  * (C) 2007 by Patrick McHardy <kaber@trash.net>
7  *
8  * Based on the old ipv4-only ip_queue.c:
9  * (C) 2000-2002 James Morris <jmorris@intercode.com.au>
10  * (C) 2003-2005 Netfilter Core Team <coreteam@netfilter.org>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License version 2 as
14  * published by the Free Software Foundation.
15  *
16  */
17 #include <linux/module.h>
18 #include <linux/skbuff.h>
19 #include <linux/init.h>
20 #include <linux/spinlock.h>
21 #include <linux/slab.h>
22 #include <linux/notifier.h>
23 #include <linux/netdevice.h>
24 #include <linux/netfilter.h>
25 #include <linux/proc_fs.h>
26 #include <linux/netfilter_ipv4.h>
27 #include <linux/netfilter_ipv6.h>
28 #include <linux/netfilter/nfnetlink.h>
29 #include <linux/netfilter/nfnetlink_queue.h>
30 #include <linux/list.h>
31 #include <net/sock.h>
32 #include <net/netfilter/nf_queue.h>
33 #include <net/netns/generic.h>
34 #include <net/netfilter/nfnetlink_queue.h>
35
36 #include <linux/atomic.h>
37
38 #ifdef CONFIG_BRIDGE_NETFILTER
39 #include "../bridge/br_private.h"
40 #endif
41
42 #define NFQNL_QMAX_DEFAULT 1024
43
44 struct nfqnl_instance {
45         struct hlist_node hlist;                /* global list of queues */
46         struct rcu_head rcu;
47
48         int peer_portid;
49         unsigned int queue_maxlen;
50         unsigned int copy_range;
51         unsigned int queue_dropped;
52         unsigned int queue_user_dropped;
53
54
55         u_int16_t queue_num;                    /* number of this queue */
56         u_int8_t copy_mode;
57         u_int32_t flags;                        /* Set using NFQA_CFG_FLAGS */
58 /*
59  * Following fields are dirtied for each queued packet,
60  * keep them in same cache line if possible.
61  */
62         spinlock_t      lock;
63         unsigned int    queue_total;
64         unsigned int    id_sequence;            /* 'sequence' of pkt ids */
65         struct list_head queue_list;            /* packets in queue */
66 };
67
68 typedef int (*nfqnl_cmpfn)(struct nf_queue_entry *, unsigned long);
69
70 static int nfnl_queue_net_id __read_mostly;
71
72 #define INSTANCE_BUCKETS        16
73 struct nfnl_queue_net {
74         spinlock_t instances_lock;
75         struct hlist_head instance_table[INSTANCE_BUCKETS];
76 };
77
78 static struct nfnl_queue_net *nfnl_queue_pernet(struct net *net)
79 {
80         return net_generic(net, nfnl_queue_net_id);
81 }
82
83 static inline u_int8_t instance_hashfn(u_int16_t queue_num)
84 {
85         return ((queue_num >> 8) ^ queue_num) % INSTANCE_BUCKETS;
86 }
87
88 static struct nfqnl_instance *
89 instance_lookup(struct nfnl_queue_net *q, u_int16_t queue_num)
90 {
91         struct hlist_head *head;
92         struct nfqnl_instance *inst;
93
94         head = &q->instance_table[instance_hashfn(queue_num)];
95         hlist_for_each_entry_rcu(inst, head, hlist) {
96                 if (inst->queue_num == queue_num)
97                         return inst;
98         }
99         return NULL;
100 }
101
102 static struct nfqnl_instance *
103 instance_create(struct nfnl_queue_net *q, u_int16_t queue_num,
104                 int portid)
105 {
106         struct nfqnl_instance *inst;
107         unsigned int h;
108         int err;
109
110         spin_lock(&q->instances_lock);
111         if (instance_lookup(q, queue_num)) {
112                 err = -EEXIST;
113                 goto out_unlock;
114         }
115
116         inst = kzalloc(sizeof(*inst), GFP_ATOMIC);
117         if (!inst) {
118                 err = -ENOMEM;
119                 goto out_unlock;
120         }
121
122         inst->queue_num = queue_num;
123         inst->peer_portid = portid;
124         inst->queue_maxlen = NFQNL_QMAX_DEFAULT;
125         inst->copy_range = 0xffff;
126         inst->copy_mode = NFQNL_COPY_NONE;
127         spin_lock_init(&inst->lock);
128         INIT_LIST_HEAD(&inst->queue_list);
129
130         if (!try_module_get(THIS_MODULE)) {
131                 err = -EAGAIN;
132                 goto out_free;
133         }
134
135         h = instance_hashfn(queue_num);
136         hlist_add_head_rcu(&inst->hlist, &q->instance_table[h]);
137
138         spin_unlock(&q->instances_lock);
139
140         return inst;
141
142 out_free:
143         kfree(inst);
144 out_unlock:
145         spin_unlock(&q->instances_lock);
146         return ERR_PTR(err);
147 }
148
149 static void nfqnl_flush(struct nfqnl_instance *queue, nfqnl_cmpfn cmpfn,
150                         unsigned long data);
151
152 static void
153 instance_destroy_rcu(struct rcu_head *head)
154 {
155         struct nfqnl_instance *inst = container_of(head, struct nfqnl_instance,
156                                                    rcu);
157
158         nfqnl_flush(inst, NULL, 0);
159         kfree(inst);
160         module_put(THIS_MODULE);
161 }
162
163 static void
164 __instance_destroy(struct nfqnl_instance *inst)
165 {
166         hlist_del_rcu(&inst->hlist);
167         call_rcu(&inst->rcu, instance_destroy_rcu);
168 }
169
170 static void
171 instance_destroy(struct nfnl_queue_net *q, struct nfqnl_instance *inst)
172 {
173         spin_lock(&q->instances_lock);
174         __instance_destroy(inst);
175         spin_unlock(&q->instances_lock);
176 }
177
178 static inline void
179 __enqueue_entry(struct nfqnl_instance *queue, struct nf_queue_entry *entry)
180 {
181        list_add_tail(&entry->list, &queue->queue_list);
182        queue->queue_total++;
183 }
184
185 static void
186 __dequeue_entry(struct nfqnl_instance *queue, struct nf_queue_entry *entry)
187 {
188         list_del(&entry->list);
189         queue->queue_total--;
190 }
191
192 static struct nf_queue_entry *
193 find_dequeue_entry(struct nfqnl_instance *queue, unsigned int id)
194 {
195         struct nf_queue_entry *entry = NULL, *i;
196
197         spin_lock_bh(&queue->lock);
198
199         list_for_each_entry(i, &queue->queue_list, list) {
200                 if (i->id == id) {
201                         entry = i;
202                         break;
203                 }
204         }
205
206         if (entry)
207                 __dequeue_entry(queue, entry);
208
209         spin_unlock_bh(&queue->lock);
210
211         return entry;
212 }
213
214 static void
215 nfqnl_flush(struct nfqnl_instance *queue, nfqnl_cmpfn cmpfn, unsigned long data)
216 {
217         struct nf_queue_entry *entry, *next;
218
219         spin_lock_bh(&queue->lock);
220         list_for_each_entry_safe(entry, next, &queue->queue_list, list) {
221                 if (!cmpfn || cmpfn(entry, data)) {
222                         list_del(&entry->list);
223                         queue->queue_total--;
224                         nf_reinject(entry, NF_DROP);
225                 }
226         }
227         spin_unlock_bh(&queue->lock);
228 }
229
230 static void
231 nfqnl_zcopy(struct sk_buff *to, const struct sk_buff *from, int len, int hlen)
232 {
233         int i, j = 0;
234         int plen = 0; /* length of skb->head fragment */
235         struct page *page;
236         unsigned int offset;
237
238         /* dont bother with small payloads */
239         if (len <= skb_tailroom(to)) {
240                 skb_copy_bits(from, 0, skb_put(to, len), len);
241                 return;
242         }
243
244         if (hlen) {
245                 skb_copy_bits(from, 0, skb_put(to, hlen), hlen);
246                 len -= hlen;
247         } else {
248                 plen = min_t(int, skb_headlen(from), len);
249                 if (plen) {
250                         page = virt_to_head_page(from->head);
251                         offset = from->data - (unsigned char *)page_address(page);
252                         __skb_fill_page_desc(to, 0, page, offset, plen);
253                         get_page(page);
254                         j = 1;
255                         len -= plen;
256                 }
257         }
258
259         to->truesize += len + plen;
260         to->len += len + plen;
261         to->data_len += len + plen;
262
263         for (i = 0; i < skb_shinfo(from)->nr_frags; i++) {
264                 if (!len)
265                         break;
266                 skb_shinfo(to)->frags[j] = skb_shinfo(from)->frags[i];
267                 skb_shinfo(to)->frags[j].size = min_t(int, skb_shinfo(to)->frags[j].size, len);
268                 len -= skb_shinfo(to)->frags[j].size;
269                 skb_frag_ref(to, j);
270                 j++;
271         }
272         skb_shinfo(to)->nr_frags = j;
273 }
274
275 static int nfqnl_put_packet_info(struct sk_buff *nlskb, struct sk_buff *packet)
276 {
277         __u32 flags = 0;
278
279         if (packet->ip_summed == CHECKSUM_PARTIAL)
280                 flags = NFQA_SKB_CSUMNOTREADY;
281         if (skb_is_gso(packet))
282                 flags |= NFQA_SKB_GSO;
283
284         return flags ? nla_put_be32(nlskb, NFQA_SKB_INFO, htonl(flags)) : 0;
285 }
286
287 static struct sk_buff *
288 nfqnl_build_packet_message(struct nfqnl_instance *queue,
289                            struct nf_queue_entry *entry,
290                            __be32 **packet_id_ptr)
291 {
292         size_t size;
293         size_t data_len = 0, cap_len = 0;
294         int hlen = 0;
295         struct sk_buff *skb;
296         struct nlattr *nla;
297         struct nfqnl_msg_packet_hdr *pmsg;
298         struct nlmsghdr *nlh;
299         struct nfgenmsg *nfmsg;
300         struct sk_buff *entskb = entry->skb;
301         struct net_device *indev;
302         struct net_device *outdev;
303         struct nf_conn *ct = NULL;
304         enum ip_conntrack_info uninitialized_var(ctinfo);
305
306         size =    nlmsg_total_size(sizeof(struct nfgenmsg))
307                 + nla_total_size(sizeof(struct nfqnl_msg_packet_hdr))
308                 + nla_total_size(sizeof(u_int32_t))     /* ifindex */
309                 + nla_total_size(sizeof(u_int32_t))     /* ifindex */
310 #ifdef CONFIG_BRIDGE_NETFILTER
311                 + nla_total_size(sizeof(u_int32_t))     /* ifindex */
312                 + nla_total_size(sizeof(u_int32_t))     /* ifindex */
313 #endif
314                 + nla_total_size(sizeof(u_int32_t))     /* mark */
315                 + nla_total_size(sizeof(struct nfqnl_msg_packet_hw))
316                 + nla_total_size(sizeof(u_int32_t))     /* skbinfo */
317                 + nla_total_size(sizeof(u_int32_t));    /* cap_len */
318
319         if (entskb->tstamp.tv64)
320                 size += nla_total_size(sizeof(struct nfqnl_msg_packet_timestamp));
321
322         outdev = entry->outdev;
323
324         switch ((enum nfqnl_config_mode)ACCESS_ONCE(queue->copy_mode)) {
325         case NFQNL_COPY_META:
326         case NFQNL_COPY_NONE:
327                 break;
328
329         case NFQNL_COPY_PACKET:
330                 if (entskb->ip_summed == CHECKSUM_PARTIAL &&
331                     skb_checksum_help(entskb))
332                         return NULL;
333
334                 data_len = ACCESS_ONCE(queue->copy_range);
335                 if (data_len == 0 || data_len > entskb->len)
336                         data_len = entskb->len;
337
338
339                 if (!entskb->head_frag ||
340                     skb_headlen(entskb) < L1_CACHE_BYTES ||
341                     skb_shinfo(entskb)->nr_frags >= MAX_SKB_FRAGS)
342                         hlen = skb_headlen(entskb);
343
344                 if (skb_has_frag_list(entskb))
345                         hlen = entskb->len;
346                 hlen = min_t(int, data_len, hlen);
347                 size += sizeof(struct nlattr) + hlen;
348                 cap_len = entskb->len;
349                 break;
350         }
351
352         if (queue->flags & NFQA_CFG_F_CONNTRACK)
353                 ct = nfqnl_ct_get(entskb, &size, &ctinfo);
354
355         skb = nfnetlink_alloc_skb(&init_net, size, queue->peer_portid,
356                                   GFP_ATOMIC);
357         if (!skb)
358                 return NULL;
359
360         nlh = nlmsg_put(skb, 0, 0,
361                         NFNL_SUBSYS_QUEUE << 8 | NFQNL_MSG_PACKET,
362                         sizeof(struct nfgenmsg), 0);
363         if (!nlh) {
364                 kfree_skb(skb);
365                 return NULL;
366         }
367         nfmsg = nlmsg_data(nlh);
368         nfmsg->nfgen_family = entry->pf;
369         nfmsg->version = NFNETLINK_V0;
370         nfmsg->res_id = htons(queue->queue_num);
371
372         nla = __nla_reserve(skb, NFQA_PACKET_HDR, sizeof(*pmsg));
373         pmsg = nla_data(nla);
374         pmsg->hw_protocol       = entskb->protocol;
375         pmsg->hook              = entry->hook;
376         *packet_id_ptr          = &pmsg->packet_id;
377
378         indev = entry->indev;
379         if (indev) {
380 #ifndef CONFIG_BRIDGE_NETFILTER
381                 if (nla_put_be32(skb, NFQA_IFINDEX_INDEV, htonl(indev->ifindex)))
382                         goto nla_put_failure;
383 #else
384                 if (entry->pf == PF_BRIDGE) {
385                         /* Case 1: indev is physical input device, we need to
386                          * look for bridge group (when called from
387                          * netfilter_bridge) */
388                         if (nla_put_be32(skb, NFQA_IFINDEX_PHYSINDEV,
389                                          htonl(indev->ifindex)) ||
390                         /* this is the bridge group "brX" */
391                         /* rcu_read_lock()ed by __nf_queue */
392                             nla_put_be32(skb, NFQA_IFINDEX_INDEV,
393                                          htonl(br_port_get_rcu(indev)->br->dev->ifindex)))
394                                 goto nla_put_failure;
395                 } else {
396                         /* Case 2: indev is bridge group, we need to look for
397                          * physical device (when called from ipv4) */
398                         if (nla_put_be32(skb, NFQA_IFINDEX_INDEV,
399                                          htonl(indev->ifindex)))
400                                 goto nla_put_failure;
401                         if (entskb->nf_bridge && entskb->nf_bridge->physindev &&
402                             nla_put_be32(skb, NFQA_IFINDEX_PHYSINDEV,
403                                          htonl(entskb->nf_bridge->physindev->ifindex)))
404                                 goto nla_put_failure;
405                 }
406 #endif
407         }
408
409         if (outdev) {
410 #ifndef CONFIG_BRIDGE_NETFILTER
411                 if (nla_put_be32(skb, NFQA_IFINDEX_OUTDEV, htonl(outdev->ifindex)))
412                         goto nla_put_failure;
413 #else
414                 if (entry->pf == PF_BRIDGE) {
415                         /* Case 1: outdev is physical output device, we need to
416                          * look for bridge group (when called from
417                          * netfilter_bridge) */
418                         if (nla_put_be32(skb, NFQA_IFINDEX_PHYSOUTDEV,
419                                          htonl(outdev->ifindex)) ||
420                         /* this is the bridge group "brX" */
421                         /* rcu_read_lock()ed by __nf_queue */
422                             nla_put_be32(skb, NFQA_IFINDEX_OUTDEV,
423                                          htonl(br_port_get_rcu(outdev)->br->dev->ifindex)))
424                                 goto nla_put_failure;
425                 } else {
426                         /* Case 2: outdev is bridge group, we need to look for
427                          * physical output device (when called from ipv4) */
428                         if (nla_put_be32(skb, NFQA_IFINDEX_OUTDEV,
429                                          htonl(outdev->ifindex)))
430                                 goto nla_put_failure;
431                         if (entskb->nf_bridge && entskb->nf_bridge->physoutdev &&
432                             nla_put_be32(skb, NFQA_IFINDEX_PHYSOUTDEV,
433                                          htonl(entskb->nf_bridge->physoutdev->ifindex)))
434                                 goto nla_put_failure;
435                 }
436 #endif
437         }
438
439         if (entskb->mark &&
440             nla_put_be32(skb, NFQA_MARK, htonl(entskb->mark)))
441                 goto nla_put_failure;
442
443         if (indev && entskb->dev &&
444             entskb->mac_header != entskb->network_header) {
445                 struct nfqnl_msg_packet_hw phw;
446                 int len = dev_parse_header(entskb, phw.hw_addr);
447                 if (len) {
448                         phw.hw_addrlen = htons(len);
449                         if (nla_put(skb, NFQA_HWADDR, sizeof(phw), &phw))
450                                 goto nla_put_failure;
451                 }
452         }
453
454         if (entskb->tstamp.tv64) {
455                 struct nfqnl_msg_packet_timestamp ts;
456                 struct timeval tv = ktime_to_timeval(entskb->tstamp);
457                 ts.sec = cpu_to_be64(tv.tv_sec);
458                 ts.usec = cpu_to_be64(tv.tv_usec);
459
460                 if (nla_put(skb, NFQA_TIMESTAMP, sizeof(ts), &ts))
461                         goto nla_put_failure;
462         }
463
464         if (ct && nfqnl_ct_put(skb, ct, ctinfo) < 0)
465                 goto nla_put_failure;
466
467         if (cap_len > 0 && nla_put_be32(skb, NFQA_CAP_LEN, htonl(cap_len)))
468                 goto nla_put_failure;
469
470         if (nfqnl_put_packet_info(skb, entskb))
471                 goto nla_put_failure;
472
473         if (data_len) {
474                 struct nlattr *nla;
475
476                 if (skb_tailroom(skb) < sizeof(*nla) + hlen)
477                         goto nla_put_failure;
478
479                 nla = (struct nlattr *)skb_put(skb, sizeof(*nla));
480                 nla->nla_type = NFQA_PAYLOAD;
481                 nla->nla_len = nla_attr_size(data_len);
482
483                 nfqnl_zcopy(skb, entskb, data_len, hlen);
484         }
485
486         nlh->nlmsg_len = skb->len;
487         return skb;
488
489 nla_put_failure:
490         kfree_skb(skb);
491         net_err_ratelimited("nf_queue: error creating packet message\n");
492         return NULL;
493 }
494
495 static int
496 __nfqnl_enqueue_packet(struct net *net, struct nfqnl_instance *queue,
497                         struct nf_queue_entry *entry)
498 {
499         struct sk_buff *nskb;
500         int err = -ENOBUFS;
501         __be32 *packet_id_ptr;
502         int failopen = 0;
503
504         nskb = nfqnl_build_packet_message(queue, entry, &packet_id_ptr);
505         if (nskb == NULL) {
506                 err = -ENOMEM;
507                 goto err_out;
508         }
509         spin_lock_bh(&queue->lock);
510
511         if (!queue->peer_portid) {
512                 err = -EINVAL;
513                 goto err_out_free_nskb;
514         }
515         if (queue->queue_total >= queue->queue_maxlen) {
516                 if (queue->flags & NFQA_CFG_F_FAIL_OPEN) {
517                         failopen = 1;
518                         err = 0;
519                 } else {
520                         queue->queue_dropped++;
521                         net_warn_ratelimited("nf_queue: full at %d entries, dropping packets(s)\n",
522                                              queue->queue_total);
523                 }
524                 goto err_out_free_nskb;
525         }
526         entry->id = ++queue->id_sequence;
527         *packet_id_ptr = htonl(entry->id);
528
529         /* nfnetlink_unicast will either free the nskb or add it to a socket */
530         err = nfnetlink_unicast(nskb, net, queue->peer_portid, MSG_DONTWAIT);
531         if (err < 0) {
532                 queue->queue_user_dropped++;
533                 goto err_out_unlock;
534         }
535
536         __enqueue_entry(queue, entry);
537
538         spin_unlock_bh(&queue->lock);
539         return 0;
540
541 err_out_free_nskb:
542         kfree_skb(nskb);
543 err_out_unlock:
544         spin_unlock_bh(&queue->lock);
545         if (failopen)
546                 nf_reinject(entry, NF_ACCEPT);
547 err_out:
548         return err;
549 }
550
551 static struct nf_queue_entry *
552 nf_queue_entry_dup(struct nf_queue_entry *e)
553 {
554         struct nf_queue_entry *entry = kmemdup(e, e->size, GFP_ATOMIC);
555         if (entry) {
556                 if (nf_queue_entry_get_refs(entry))
557                         return entry;
558                 kfree(entry);
559         }
560         return NULL;
561 }
562
563 #ifdef CONFIG_BRIDGE_NETFILTER
564 /* When called from bridge netfilter, skb->data must point to MAC header
565  * before calling skb_gso_segment(). Else, original MAC header is lost
566  * and segmented skbs will be sent to wrong destination.
567  */
568 static void nf_bridge_adjust_skb_data(struct sk_buff *skb)
569 {
570         if (skb->nf_bridge)
571                 __skb_push(skb, skb->network_header - skb->mac_header);
572 }
573
574 static void nf_bridge_adjust_segmented_data(struct sk_buff *skb)
575 {
576         if (skb->nf_bridge)
577                 __skb_pull(skb, skb->network_header - skb->mac_header);
578 }
579 #else
580 #define nf_bridge_adjust_skb_data(s) do {} while (0)
581 #define nf_bridge_adjust_segmented_data(s) do {} while (0)
582 #endif
583
584 static void free_entry(struct nf_queue_entry *entry)
585 {
586         nf_queue_entry_release_refs(entry);
587         kfree(entry);
588 }
589
590 static int
591 __nfqnl_enqueue_packet_gso(struct net *net, struct nfqnl_instance *queue,
592                            struct sk_buff *skb, struct nf_queue_entry *entry)
593 {
594         int ret = -ENOMEM;
595         struct nf_queue_entry *entry_seg;
596
597         nf_bridge_adjust_segmented_data(skb);
598
599         if (skb->next == NULL) { /* last packet, no need to copy entry */
600                 struct sk_buff *gso_skb = entry->skb;
601                 entry->skb = skb;
602                 ret = __nfqnl_enqueue_packet(net, queue, entry);
603                 if (ret)
604                         entry->skb = gso_skb;
605                 return ret;
606         }
607
608         skb->next = NULL;
609
610         entry_seg = nf_queue_entry_dup(entry);
611         if (entry_seg) {
612                 entry_seg->skb = skb;
613                 ret = __nfqnl_enqueue_packet(net, queue, entry_seg);
614                 if (ret)
615                         free_entry(entry_seg);
616         }
617         return ret;
618 }
619
620 static int
621 nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
622 {
623         unsigned int queued;
624         struct nfqnl_instance *queue;
625         struct sk_buff *skb, *segs;
626         int err = -ENOBUFS;
627         struct net *net = dev_net(entry->indev ?
628                                   entry->indev : entry->outdev);
629         struct nfnl_queue_net *q = nfnl_queue_pernet(net);
630
631         /* rcu_read_lock()ed by nf_hook_slow() */
632         queue = instance_lookup(q, queuenum);
633         if (!queue)
634                 return -ESRCH;
635
636         if (queue->copy_mode == NFQNL_COPY_NONE)
637                 return -EINVAL;
638
639         if (!skb_is_gso(entry->skb))
640                 return __nfqnl_enqueue_packet(net, queue, entry);
641
642         skb = entry->skb;
643
644         switch (entry->pf) {
645         case NFPROTO_IPV4:
646                 skb->protocol = htons(ETH_P_IP);
647                 break;
648         case NFPROTO_IPV6:
649                 skb->protocol = htons(ETH_P_IPV6);
650                 break;
651         }
652
653         nf_bridge_adjust_skb_data(skb);
654         segs = skb_gso_segment(skb, 0);
655         /* Does not use PTR_ERR to limit the number of error codes that can be
656          * returned by nf_queue.  For instance, callers rely on -ECANCELED to
657          * mean 'ignore this hook'.
658          */
659         if (IS_ERR(segs))
660                 goto out_err;
661         queued = 0;
662         err = 0;
663         do {
664                 struct sk_buff *nskb = segs->next;
665                 if (err == 0)
666                         err = __nfqnl_enqueue_packet_gso(net, queue,
667                                                         segs, entry);
668                 if (err == 0)
669                         queued++;
670                 else
671                         kfree_skb(segs);
672                 segs = nskb;
673         } while (segs);
674
675         if (queued) {
676                 if (err) /* some segments are already queued */
677                         free_entry(entry);
678                 kfree_skb(skb);
679                 return 0;
680         }
681  out_err:
682         nf_bridge_adjust_segmented_data(skb);
683         return err;
684 }
685
686 static int
687 nfqnl_mangle(void *data, int data_len, struct nf_queue_entry *e, int diff)
688 {
689         struct sk_buff *nskb;
690
691         if (diff < 0) {
692                 if (pskb_trim(e->skb, data_len))
693                         return -ENOMEM;
694         } else if (diff > 0) {
695                 if (data_len > 0xFFFF)
696                         return -EINVAL;
697                 if (diff > skb_tailroom(e->skb)) {
698                         nskb = skb_copy_expand(e->skb, skb_headroom(e->skb),
699                                                diff, GFP_ATOMIC);
700                         if (!nskb) {
701                                 printk(KERN_WARNING "nf_queue: OOM "
702                                       "in mangle, dropping packet\n");
703                                 return -ENOMEM;
704                         }
705                         kfree_skb(e->skb);
706                         e->skb = nskb;
707                 }
708                 skb_put(e->skb, diff);
709         }
710         if (!skb_make_writable(e->skb, data_len))
711                 return -ENOMEM;
712         skb_copy_to_linear_data(e->skb, data, data_len);
713         e->skb->ip_summed = CHECKSUM_NONE;
714         return 0;
715 }
716
717 static int
718 nfqnl_set_mode(struct nfqnl_instance *queue,
719                unsigned char mode, unsigned int range)
720 {
721         int status = 0;
722
723         spin_lock_bh(&queue->lock);
724         switch (mode) {
725         case NFQNL_COPY_NONE:
726         case NFQNL_COPY_META:
727                 queue->copy_mode = mode;
728                 queue->copy_range = 0;
729                 break;
730
731         case NFQNL_COPY_PACKET:
732                 queue->copy_mode = mode;
733                 /* We're using struct nlattr which has 16bit nla_len. Note that
734                  * nla_len includes the header length. Thus, the maximum packet
735                  * length that we support is 65531 bytes. We send truncated
736                  * packets if the specified length is larger than that.
737                  */
738                 if (range > 0xffff - NLA_HDRLEN)
739                         queue->copy_range = 0xffff - NLA_HDRLEN;
740                 else
741                         queue->copy_range = range;
742                 break;
743
744         default:
745                 status = -EINVAL;
746
747         }
748         spin_unlock_bh(&queue->lock);
749
750         return status;
751 }
752
753 static int
754 dev_cmp(struct nf_queue_entry *entry, unsigned long ifindex)
755 {
756         if (entry->indev)
757                 if (entry->indev->ifindex == ifindex)
758                         return 1;
759         if (entry->outdev)
760                 if (entry->outdev->ifindex == ifindex)
761                         return 1;
762 #ifdef CONFIG_BRIDGE_NETFILTER
763         if (entry->skb->nf_bridge) {
764                 if (entry->skb->nf_bridge->physindev &&
765                     entry->skb->nf_bridge->physindev->ifindex == ifindex)
766                         return 1;
767                 if (entry->skb->nf_bridge->physoutdev &&
768                     entry->skb->nf_bridge->physoutdev->ifindex == ifindex)
769                         return 1;
770         }
771 #endif
772         return 0;
773 }
774
775 /* drop all packets with either indev or outdev == ifindex from all queue
776  * instances */
777 static void
778 nfqnl_dev_drop(struct net *net, int ifindex)
779 {
780         int i;
781         struct nfnl_queue_net *q = nfnl_queue_pernet(net);
782
783         rcu_read_lock();
784
785         for (i = 0; i < INSTANCE_BUCKETS; i++) {
786                 struct nfqnl_instance *inst;
787                 struct hlist_head *head = &q->instance_table[i];
788
789                 hlist_for_each_entry_rcu(inst, head, hlist)
790                         nfqnl_flush(inst, dev_cmp, ifindex);
791         }
792
793         rcu_read_unlock();
794 }
795
796 #define RCV_SKB_FAIL(err) do { netlink_ack(skb, nlh, (err)); return; } while (0)
797
798 static int
799 nfqnl_rcv_dev_event(struct notifier_block *this,
800                     unsigned long event, void *ptr)
801 {
802         struct net_device *dev = ptr;
803
804         /* Drop any packets associated with the downed device */
805         if (event == NETDEV_DOWN)
806                 nfqnl_dev_drop(dev_net(dev), dev->ifindex);
807         return NOTIFY_DONE;
808 }
809
810 static struct notifier_block nfqnl_dev_notifier = {
811         .notifier_call  = nfqnl_rcv_dev_event,
812 };
813
814 static int
815 nfqnl_rcv_nl_event(struct notifier_block *this,
816                    unsigned long event, void *ptr)
817 {
818         struct netlink_notify *n = ptr;
819         struct nfnl_queue_net *q = nfnl_queue_pernet(n->net);
820
821         if (event == NETLINK_URELEASE && n->protocol == NETLINK_NETFILTER) {
822                 int i;
823
824                 /* destroy all instances for this portid */
825                 spin_lock(&q->instances_lock);
826                 for (i = 0; i < INSTANCE_BUCKETS; i++) {
827                         struct hlist_node *t2;
828                         struct nfqnl_instance *inst;
829                         struct hlist_head *head = &q->instance_table[i];
830
831                         hlist_for_each_entry_safe(inst, t2, head, hlist) {
832                                 if (n->portid == inst->peer_portid)
833                                         __instance_destroy(inst);
834                         }
835                 }
836                 spin_unlock(&q->instances_lock);
837         }
838         return NOTIFY_DONE;
839 }
840
841 static struct notifier_block nfqnl_rtnl_notifier = {
842         .notifier_call  = nfqnl_rcv_nl_event,
843 };
844
845 static const struct nla_policy nfqa_verdict_policy[NFQA_MAX+1] = {
846         [NFQA_VERDICT_HDR]      = { .len = sizeof(struct nfqnl_msg_verdict_hdr) },
847         [NFQA_MARK]             = { .type = NLA_U32 },
848         [NFQA_PAYLOAD]          = { .type = NLA_UNSPEC },
849         [NFQA_CT]               = { .type = NLA_UNSPEC },
850 };
851
852 static const struct nla_policy nfqa_verdict_batch_policy[NFQA_MAX+1] = {
853         [NFQA_VERDICT_HDR]      = { .len = sizeof(struct nfqnl_msg_verdict_hdr) },
854         [NFQA_MARK]             = { .type = NLA_U32 },
855 };
856
857 static struct nfqnl_instance *
858 verdict_instance_lookup(struct nfnl_queue_net *q, u16 queue_num, int nlportid)
859 {
860         struct nfqnl_instance *queue;
861
862         queue = instance_lookup(q, queue_num);
863         if (!queue)
864                 return ERR_PTR(-ENODEV);
865
866         if (queue->peer_portid != nlportid)
867                 return ERR_PTR(-EPERM);
868
869         return queue;
870 }
871
872 static struct nfqnl_msg_verdict_hdr*
873 verdicthdr_get(const struct nlattr * const nfqa[])
874 {
875         struct nfqnl_msg_verdict_hdr *vhdr;
876         unsigned int verdict;
877
878         if (!nfqa[NFQA_VERDICT_HDR])
879                 return NULL;
880
881         vhdr = nla_data(nfqa[NFQA_VERDICT_HDR]);
882         verdict = ntohl(vhdr->verdict) & NF_VERDICT_MASK;
883         if (verdict > NF_MAX_VERDICT || verdict == NF_STOLEN)
884                 return NULL;
885         return vhdr;
886 }
887
888 static int nfq_id_after(unsigned int id, unsigned int max)
889 {
890         return (int)(id - max) > 0;
891 }
892
893 static int
894 nfqnl_recv_verdict_batch(struct sock *ctnl, struct sk_buff *skb,
895                    const struct nlmsghdr *nlh,
896                    const struct nlattr * const nfqa[])
897 {
898         struct nfgenmsg *nfmsg = nlmsg_data(nlh);
899         struct nf_queue_entry *entry, *tmp;
900         unsigned int verdict, maxid;
901         struct nfqnl_msg_verdict_hdr *vhdr;
902         struct nfqnl_instance *queue;
903         LIST_HEAD(batch_list);
904         u16 queue_num = ntohs(nfmsg->res_id);
905
906         struct net *net = sock_net(ctnl);
907         struct nfnl_queue_net *q = nfnl_queue_pernet(net);
908
909         queue = verdict_instance_lookup(q, queue_num,
910                                         NETLINK_CB(skb).portid);
911         if (IS_ERR(queue))
912                 return PTR_ERR(queue);
913
914         vhdr = verdicthdr_get(nfqa);
915         if (!vhdr)
916                 return -EINVAL;
917
918         verdict = ntohl(vhdr->verdict);
919         maxid = ntohl(vhdr->id);
920
921         spin_lock_bh(&queue->lock);
922
923         list_for_each_entry_safe(entry, tmp, &queue->queue_list, list) {
924                 if (nfq_id_after(entry->id, maxid))
925                         break;
926                 __dequeue_entry(queue, entry);
927                 list_add_tail(&entry->list, &batch_list);
928         }
929
930         spin_unlock_bh(&queue->lock);
931
932         if (list_empty(&batch_list))
933                 return -ENOENT;
934
935         list_for_each_entry_safe(entry, tmp, &batch_list, list) {
936                 if (nfqa[NFQA_MARK])
937                         entry->skb->mark = ntohl(nla_get_be32(nfqa[NFQA_MARK]));
938                 nf_reinject(entry, verdict);
939         }
940         return 0;
941 }
942
943 static int
944 nfqnl_recv_verdict(struct sock *ctnl, struct sk_buff *skb,
945                    const struct nlmsghdr *nlh,
946                    const struct nlattr * const nfqa[])
947 {
948         struct nfgenmsg *nfmsg = nlmsg_data(nlh);
949         u_int16_t queue_num = ntohs(nfmsg->res_id);
950
951         struct nfqnl_msg_verdict_hdr *vhdr;
952         struct nfqnl_instance *queue;
953         unsigned int verdict;
954         struct nf_queue_entry *entry;
955         enum ip_conntrack_info uninitialized_var(ctinfo);
956         struct nf_conn *ct = NULL;
957
958         struct net *net = sock_net(ctnl);
959         struct nfnl_queue_net *q = nfnl_queue_pernet(net);
960
961         queue = instance_lookup(q, queue_num);
962         if (!queue)
963                 queue = verdict_instance_lookup(q, queue_num,
964                                                 NETLINK_CB(skb).portid);
965         if (IS_ERR(queue))
966                 return PTR_ERR(queue);
967
968         vhdr = verdicthdr_get(nfqa);
969         if (!vhdr)
970                 return -EINVAL;
971
972         verdict = ntohl(vhdr->verdict);
973
974         entry = find_dequeue_entry(queue, ntohl(vhdr->id));
975         if (entry == NULL)
976                 return -ENOENT;
977
978         rcu_read_lock();
979         if (nfqa[NFQA_CT] && (queue->flags & NFQA_CFG_F_CONNTRACK))
980                 ct = nfqnl_ct_parse(entry->skb, nfqa[NFQA_CT], &ctinfo);
981
982         if (nfqa[NFQA_PAYLOAD]) {
983                 u16 payload_len = nla_len(nfqa[NFQA_PAYLOAD]);
984                 int diff = payload_len - entry->skb->len;
985
986                 if (nfqnl_mangle(nla_data(nfqa[NFQA_PAYLOAD]),
987                                  payload_len, entry, diff) < 0)
988                         verdict = NF_DROP;
989
990                 if (ct)
991                         nfqnl_ct_seq_adjust(skb, ct, ctinfo, diff);
992         }
993         rcu_read_unlock();
994
995         if (nfqa[NFQA_MARK])
996                 entry->skb->mark = ntohl(nla_get_be32(nfqa[NFQA_MARK]));
997
998         nf_reinject(entry, verdict);
999         return 0;
1000 }
1001
1002 static int
1003 nfqnl_recv_unsupp(struct sock *ctnl, struct sk_buff *skb,
1004                   const struct nlmsghdr *nlh,
1005                   const struct nlattr * const nfqa[])
1006 {
1007         return -ENOTSUPP;
1008 }
1009
1010 static const struct nla_policy nfqa_cfg_policy[NFQA_CFG_MAX+1] = {
1011         [NFQA_CFG_CMD]          = { .len = sizeof(struct nfqnl_msg_config_cmd) },
1012         [NFQA_CFG_PARAMS]       = { .len = sizeof(struct nfqnl_msg_config_params) },
1013 };
1014
1015 static const struct nf_queue_handler nfqh = {
1016         .outfn  = &nfqnl_enqueue_packet,
1017 };
1018
1019 static int
1020 nfqnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
1021                   const struct nlmsghdr *nlh,
1022                   const struct nlattr * const nfqa[])
1023 {
1024         struct nfgenmsg *nfmsg = nlmsg_data(nlh);
1025         u_int16_t queue_num = ntohs(nfmsg->res_id);
1026         struct nfqnl_instance *queue;
1027         struct nfqnl_msg_config_cmd *cmd = NULL;
1028         struct net *net = sock_net(ctnl);
1029         struct nfnl_queue_net *q = nfnl_queue_pernet(net);
1030         int ret = 0;
1031
1032         if (nfqa[NFQA_CFG_CMD]) {
1033                 cmd = nla_data(nfqa[NFQA_CFG_CMD]);
1034
1035                 /* Obsolete commands without queue context */
1036                 switch (cmd->command) {
1037                 case NFQNL_CFG_CMD_PF_BIND: return 0;
1038                 case NFQNL_CFG_CMD_PF_UNBIND: return 0;
1039                 }
1040         }
1041
1042         rcu_read_lock();
1043         queue = instance_lookup(q, queue_num);
1044         if (queue && queue->peer_portid != NETLINK_CB(skb).portid) {
1045                 ret = -EPERM;
1046                 goto err_out_unlock;
1047         }
1048
1049         if (cmd != NULL) {
1050                 switch (cmd->command) {
1051                 case NFQNL_CFG_CMD_BIND:
1052                         if (queue) {
1053                                 ret = -EBUSY;
1054                                 goto err_out_unlock;
1055                         }
1056                         queue = instance_create(q, queue_num,
1057                                                 NETLINK_CB(skb).portid);
1058                         if (IS_ERR(queue)) {
1059                                 ret = PTR_ERR(queue);
1060                                 goto err_out_unlock;
1061                         }
1062                         break;
1063                 case NFQNL_CFG_CMD_UNBIND:
1064                         if (!queue) {
1065                                 ret = -ENODEV;
1066                                 goto err_out_unlock;
1067                         }
1068                         instance_destroy(q, queue);
1069                         break;
1070                 case NFQNL_CFG_CMD_PF_BIND:
1071                 case NFQNL_CFG_CMD_PF_UNBIND:
1072                         break;
1073                 default:
1074                         ret = -ENOTSUPP;
1075                         break;
1076                 }
1077         }
1078
1079         if (nfqa[NFQA_CFG_PARAMS]) {
1080                 struct nfqnl_msg_config_params *params;
1081
1082                 if (!queue) {
1083                         ret = -ENODEV;
1084                         goto err_out_unlock;
1085                 }
1086                 params = nla_data(nfqa[NFQA_CFG_PARAMS]);
1087                 nfqnl_set_mode(queue, params->copy_mode,
1088                                 ntohl(params->copy_range));
1089         }
1090
1091         if (nfqa[NFQA_CFG_QUEUE_MAXLEN]) {
1092                 __be32 *queue_maxlen;
1093
1094                 if (!queue) {
1095                         ret = -ENODEV;
1096                         goto err_out_unlock;
1097                 }
1098                 queue_maxlen = nla_data(nfqa[NFQA_CFG_QUEUE_MAXLEN]);
1099                 spin_lock_bh(&queue->lock);
1100                 queue->queue_maxlen = ntohl(*queue_maxlen);
1101                 spin_unlock_bh(&queue->lock);
1102         }
1103
1104         if (nfqa[NFQA_CFG_FLAGS]) {
1105                 __u32 flags, mask;
1106
1107                 if (!queue) {
1108                         ret = -ENODEV;
1109                         goto err_out_unlock;
1110                 }
1111
1112                 if (!nfqa[NFQA_CFG_MASK]) {
1113                         /* A mask is needed to specify which flags are being
1114                          * changed.
1115                          */
1116                         ret = -EINVAL;
1117                         goto err_out_unlock;
1118                 }
1119
1120                 flags = ntohl(nla_get_be32(nfqa[NFQA_CFG_FLAGS]));
1121                 mask = ntohl(nla_get_be32(nfqa[NFQA_CFG_MASK]));
1122
1123                 if (flags >= NFQA_CFG_F_MAX) {
1124                         ret = -EOPNOTSUPP;
1125                         goto err_out_unlock;
1126                 }
1127
1128                 spin_lock_bh(&queue->lock);
1129                 queue->flags &= ~mask;
1130                 queue->flags |= flags & mask;
1131                 spin_unlock_bh(&queue->lock);
1132         }
1133
1134 err_out_unlock:
1135         rcu_read_unlock();
1136         return ret;
1137 }
1138
1139 static const struct nfnl_callback nfqnl_cb[NFQNL_MSG_MAX] = {
1140         [NFQNL_MSG_PACKET]      = { .call_rcu = nfqnl_recv_unsupp,
1141                                     .attr_count = NFQA_MAX, },
1142         [NFQNL_MSG_VERDICT]     = { .call_rcu = nfqnl_recv_verdict,
1143                                     .attr_count = NFQA_MAX,
1144                                     .policy = nfqa_verdict_policy },
1145         [NFQNL_MSG_CONFIG]      = { .call = nfqnl_recv_config,
1146                                     .attr_count = NFQA_CFG_MAX,
1147                                     .policy = nfqa_cfg_policy },
1148         [NFQNL_MSG_VERDICT_BATCH]={ .call_rcu = nfqnl_recv_verdict_batch,
1149                                     .attr_count = NFQA_MAX,
1150                                     .policy = nfqa_verdict_batch_policy },
1151 };
1152
1153 static const struct nfnetlink_subsystem nfqnl_subsys = {
1154         .name           = "nf_queue",
1155         .subsys_id      = NFNL_SUBSYS_QUEUE,
1156         .cb_count       = NFQNL_MSG_MAX,
1157         .cb             = nfqnl_cb,
1158 };
1159
1160 #ifdef CONFIG_PROC_FS
1161 struct iter_state {
1162         struct seq_net_private p;
1163         unsigned int bucket;
1164 };
1165
1166 static struct hlist_node *get_first(struct seq_file *seq)
1167 {
1168         struct iter_state *st = seq->private;
1169         struct net *net;
1170         struct nfnl_queue_net *q;
1171
1172         if (!st)
1173                 return NULL;
1174
1175         net = seq_file_net(seq);
1176         q = nfnl_queue_pernet(net);
1177         for (st->bucket = 0; st->bucket < INSTANCE_BUCKETS; st->bucket++) {
1178                 if (!hlist_empty(&q->instance_table[st->bucket]))
1179                         return q->instance_table[st->bucket].first;
1180         }
1181         return NULL;
1182 }
1183
1184 static struct hlist_node *get_next(struct seq_file *seq, struct hlist_node *h)
1185 {
1186         struct iter_state *st = seq->private;
1187         struct net *net = seq_file_net(seq);
1188
1189         h = h->next;
1190         while (!h) {
1191                 struct nfnl_queue_net *q;
1192
1193                 if (++st->bucket >= INSTANCE_BUCKETS)
1194                         return NULL;
1195
1196                 q = nfnl_queue_pernet(net);
1197                 h = q->instance_table[st->bucket].first;
1198         }
1199         return h;
1200 }
1201
1202 static struct hlist_node *get_idx(struct seq_file *seq, loff_t pos)
1203 {
1204         struct hlist_node *head;
1205         head = get_first(seq);
1206
1207         if (head)
1208                 while (pos && (head = get_next(seq, head)))
1209                         pos--;
1210         return pos ? NULL : head;
1211 }
1212
1213 static void *seq_start(struct seq_file *s, loff_t *pos)
1214         __acquires(nfnl_queue_pernet(seq_file_net(s))->instances_lock)
1215 {
1216         spin_lock(&nfnl_queue_pernet(seq_file_net(s))->instances_lock);
1217         return get_idx(s, *pos);
1218 }
1219
1220 static void *seq_next(struct seq_file *s, void *v, loff_t *pos)
1221 {
1222         (*pos)++;
1223         return get_next(s, v);
1224 }
1225
1226 static void seq_stop(struct seq_file *s, void *v)
1227         __releases(nfnl_queue_pernet(seq_file_net(s))->instances_lock)
1228 {
1229         spin_unlock(&nfnl_queue_pernet(seq_file_net(s))->instances_lock);
1230 }
1231
1232 static int seq_show(struct seq_file *s, void *v)
1233 {
1234         const struct nfqnl_instance *inst = v;
1235
1236         return seq_printf(s, "%5d %6d %5d %1d %5d %5d %5d %8d %2d\n",
1237                           inst->queue_num,
1238                           inst->peer_portid, inst->queue_total,
1239                           inst->copy_mode, inst->copy_range,
1240                           inst->queue_dropped, inst->queue_user_dropped,
1241                           inst->id_sequence, 1);
1242 }
1243
1244 static const struct seq_operations nfqnl_seq_ops = {
1245         .start  = seq_start,
1246         .next   = seq_next,
1247         .stop   = seq_stop,
1248         .show   = seq_show,
1249 };
1250
1251 static int nfqnl_open(struct inode *inode, struct file *file)
1252 {
1253         return seq_open_net(inode, file, &nfqnl_seq_ops,
1254                         sizeof(struct iter_state));
1255 }
1256
1257 static const struct file_operations nfqnl_file_ops = {
1258         .owner   = THIS_MODULE,
1259         .open    = nfqnl_open,
1260         .read    = seq_read,
1261         .llseek  = seq_lseek,
1262         .release = seq_release_net,
1263 };
1264
1265 #endif /* PROC_FS */
1266
1267 static int __net_init nfnl_queue_net_init(struct net *net)
1268 {
1269         unsigned int i;
1270         struct nfnl_queue_net *q = nfnl_queue_pernet(net);
1271
1272         for (i = 0; i < INSTANCE_BUCKETS; i++)
1273                 INIT_HLIST_HEAD(&q->instance_table[i]);
1274
1275         spin_lock_init(&q->instances_lock);
1276
1277 #ifdef CONFIG_PROC_FS
1278         if (!proc_create("nfnetlink_queue", 0440,
1279                          net->nf.proc_netfilter, &nfqnl_file_ops))
1280                 return -ENOMEM;
1281 #endif
1282         return 0;
1283 }
1284
1285 static void __net_exit nfnl_queue_net_exit(struct net *net)
1286 {
1287         remove_proc_entry("nfnetlink_queue", net->nf.proc_netfilter);
1288 }
1289
1290 static struct pernet_operations nfnl_queue_net_ops = {
1291         .init   = nfnl_queue_net_init,
1292         .exit   = nfnl_queue_net_exit,
1293         .id     = &nfnl_queue_net_id,
1294         .size   = sizeof(struct nfnl_queue_net),
1295 };
1296
1297 static int __init nfnetlink_queue_init(void)
1298 {
1299         int status = -ENOMEM;
1300
1301         netlink_register_notifier(&nfqnl_rtnl_notifier);
1302         status = nfnetlink_subsys_register(&nfqnl_subsys);
1303         if (status < 0) {
1304                 pr_err("nf_queue: failed to create netlink socket\n");
1305                 goto cleanup_netlink_notifier;
1306         }
1307
1308         status = register_pernet_subsys(&nfnl_queue_net_ops);
1309         if (status < 0) {
1310                 pr_err("nf_queue: failed to register pernet ops\n");
1311                 goto cleanup_subsys;
1312         }
1313         register_netdevice_notifier(&nfqnl_dev_notifier);
1314         nf_register_queue_handler(&nfqh);
1315         return status;
1316
1317 cleanup_subsys:
1318         nfnetlink_subsys_unregister(&nfqnl_subsys);
1319 cleanup_netlink_notifier:
1320         netlink_unregister_notifier(&nfqnl_rtnl_notifier);
1321         return status;
1322 }
1323
1324 static void __exit nfnetlink_queue_fini(void)
1325 {
1326         nf_unregister_queue_handler();
1327         unregister_netdevice_notifier(&nfqnl_dev_notifier);
1328         unregister_pernet_subsys(&nfnl_queue_net_ops);
1329         nfnetlink_subsys_unregister(&nfqnl_subsys);
1330         netlink_unregister_notifier(&nfqnl_rtnl_notifier);
1331
1332         rcu_barrier(); /* Wait for completion of call_rcu()'s */
1333 }
1334
1335 MODULE_DESCRIPTION("netfilter packet queue handler");
1336 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
1337 MODULE_LICENSE("GPL");
1338 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_QUEUE);
1339
1340 module_init(nfnetlink_queue_init);
1341 module_exit(nfnetlink_queue_fini);