]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - net/ipv6/netfilter/ip6_queue.c
[NET] IPV6: Fix whitespace errors.
[mirror_ubuntu-artful-kernel.git] / net / ipv6 / netfilter / ip6_queue.c
CommitLineData
1da177e4
LT
1/*
2 * This is a module which is used for queueing IPv6 packets and
3 * communicating with userspace via netlink.
4 *
5 * (C) 2001 Fernando Anton, this code is GPL.
6 * IPv64 Project - Work based in IPv64 draft by Arturo Azcorra.
7 * Universidad Carlos III de Madrid - Leganes (Madrid) - Spain
8 * Universidad Politecnica de Alcala de Henares - Alcala de H. (Madrid) - Spain
9 * email: fanton@it.uc3m.es
10 *
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.
14 *
15 * 2001-11-06: First try. Working with ip_queue.c for IPv4 and trying
16 * to adapt it to IPv6
17 * HEAVILY based in ipqueue.c by James Morris. It's just
18 * a little modified version of it, so he's nearly the
19 * real coder of this.
20 * Few changes needed, mainly the hard_routing code and
21 * the netlink socket protocol (we're NETLINK_IP6_FW).
22 * 2002-06-25: Code cleanup. [JM: ported cleanup over from ip_queue.c]
23 * 2005-02-04: Added /proc counter for dropped packets; fixed so
24 * packets aren't delivered to user space if they're going
25 * to be dropped.
26 */
27#include <linux/module.h>
28#include <linux/skbuff.h>
29#include <linux/init.h>
30#include <linux/ipv6.h>
31#include <linux/notifier.h>
32#include <linux/netdevice.h>
33#include <linux/netfilter.h>
34#include <linux/netlink.h>
35#include <linux/spinlock.h>
36#include <linux/sysctl.h>
37#include <linux/proc_fs.h>
4a3e2f71 38#include <linux/mutex.h>
1da177e4
LT
39#include <net/sock.h>
40#include <net/ipv6.h>
41#include <net/ip6_route.h>
42#include <linux/netfilter_ipv4/ip_queue.h>
43#include <linux/netfilter_ipv4/ip_tables.h>
44#include <linux/netfilter_ipv6/ip6_tables.h>
45
46#define IPQ_QMAX_DEFAULT 1024
47#define IPQ_PROC_FS_NAME "ip6_queue"
48#define NET_IPQ_QMAX 2088
49#define NET_IPQ_QMAX_NAME "ip6_queue_maxlen"
50
1da177e4
LT
51struct ipq_queue_entry {
52 struct list_head list;
53 struct nf_info *info;
54 struct sk_buff *skb;
1da177e4
LT
55};
56
57typedef int (*ipq_cmpfn)(struct ipq_queue_entry *, unsigned long);
58
1192e403 59static unsigned char copy_mode __read_mostly = IPQ_COPY_NONE;
94aec08e 60static unsigned int queue_maxlen __read_mostly = IPQ_QMAX_DEFAULT;
1da177e4 61static DEFINE_RWLOCK(queue_lock);
1192e403
BH
62static int peer_pid __read_mostly;
63static unsigned int copy_range __read_mostly;
1da177e4
LT
64static unsigned int queue_total;
65static unsigned int queue_dropped = 0;
66static unsigned int queue_user_dropped = 0;
1192e403 67static struct sock *ipqnl __read_mostly;
1da177e4 68static LIST_HEAD(queue_list);
4a3e2f71 69static DEFINE_MUTEX(ipqnl_mutex);
1da177e4
LT
70
71static void
72ipq_issue_verdict(struct ipq_queue_entry *entry, int verdict)
73{
4c1217de 74 local_bh_disable();
1da177e4 75 nf_reinject(entry->skb, entry->info, verdict);
4c1217de 76 local_bh_enable();
1da177e4
LT
77 kfree(entry);
78}
79
80static inline void
81__ipq_enqueue_entry(struct ipq_queue_entry *entry)
82{
83 list_add(&entry->list, &queue_list);
84 queue_total++;
85}
86
87/*
88 * Find and return a queued entry matched by cmpfn, or return the last
89 * entry if cmpfn is NULL.
90 */
91static inline struct ipq_queue_entry *
92__ipq_find_entry(ipq_cmpfn cmpfn, unsigned long data)
93{
94 struct list_head *p;
95
96 list_for_each_prev(p, &queue_list) {
97 struct ipq_queue_entry *entry = (struct ipq_queue_entry *)p;
1ab1457c 98
1da177e4
LT
99 if (!cmpfn || cmpfn(entry, data))
100 return entry;
101 }
102 return NULL;
103}
104
105static inline void
106__ipq_dequeue_entry(struct ipq_queue_entry *entry)
107{
108 list_del(&entry->list);
109 queue_total--;
110}
111
112static inline struct ipq_queue_entry *
113__ipq_find_dequeue_entry(ipq_cmpfn cmpfn, unsigned long data)
114{
115 struct ipq_queue_entry *entry;
116
117 entry = __ipq_find_entry(cmpfn, data);
118 if (entry == NULL)
119 return NULL;
120
121 __ipq_dequeue_entry(entry);
122 return entry;
123}
124
125
126static inline void
127__ipq_flush(int verdict)
128{
129 struct ipq_queue_entry *entry;
1ab1457c 130
1da177e4
LT
131 while ((entry = __ipq_find_dequeue_entry(NULL, 0)))
132 ipq_issue_verdict(entry, verdict);
133}
134
135static inline int
136__ipq_set_mode(unsigned char mode, unsigned int range)
137{
138 int status = 0;
1ab1457c 139
1da177e4
LT
140 switch(mode) {
141 case IPQ_COPY_NONE:
142 case IPQ_COPY_META:
143 copy_mode = mode;
144 copy_range = 0;
145 break;
1ab1457c 146
1da177e4
LT
147 case IPQ_COPY_PACKET:
148 copy_mode = mode;
149 copy_range = range;
150 if (copy_range > 0xFFFF)
151 copy_range = 0xFFFF;
152 break;
1ab1457c 153
1da177e4
LT
154 default:
155 status = -EINVAL;
156
157 }
158 return status;
159}
160
161static inline void
162__ipq_reset(void)
163{
164 peer_pid = 0;
165 net_disable_timestamp();
166 __ipq_set_mode(IPQ_COPY_NONE, 0);
167 __ipq_flush(NF_DROP);
168}
169
170static struct ipq_queue_entry *
171ipq_find_dequeue_entry(ipq_cmpfn cmpfn, unsigned long data)
172{
173 struct ipq_queue_entry *entry;
1ab1457c 174
1da177e4
LT
175 write_lock_bh(&queue_lock);
176 entry = __ipq_find_dequeue_entry(cmpfn, data);
177 write_unlock_bh(&queue_lock);
178 return entry;
179}
180
181static void
182ipq_flush(int verdict)
183{
184 write_lock_bh(&queue_lock);
185 __ipq_flush(verdict);
186 write_unlock_bh(&queue_lock);
187}
188
189static struct sk_buff *
190ipq_build_packet_message(struct ipq_queue_entry *entry, int *errp)
191{
192 unsigned char *old_tail;
193 size_t size = 0;
194 size_t data_len = 0;
195 struct sk_buff *skb;
196 struct ipq_packet_msg *pmsg;
197 struct nlmsghdr *nlh;
198
199 read_lock_bh(&queue_lock);
1ab1457c 200
1da177e4
LT
201 switch (copy_mode) {
202 case IPQ_COPY_META:
203 case IPQ_COPY_NONE:
204 size = NLMSG_SPACE(sizeof(*pmsg));
205 data_len = 0;
206 break;
1ab1457c 207
1da177e4 208 case IPQ_COPY_PACKET:
84fa7933
PM
209 if ((entry->skb->ip_summed == CHECKSUM_PARTIAL ||
210 entry->skb->ip_summed == CHECKSUM_COMPLETE) &&
211 (*errp = skb_checksum_help(entry->skb))) {
66a79a19
PM
212 read_unlock_bh(&queue_lock);
213 return NULL;
214 }
1da177e4
LT
215 if (copy_range == 0 || copy_range > entry->skb->len)
216 data_len = entry->skb->len;
217 else
218 data_len = copy_range;
1ab1457c 219
1da177e4
LT
220 size = NLMSG_SPACE(sizeof(*pmsg) + data_len);
221 break;
1ab1457c 222
1da177e4
LT
223 default:
224 *errp = -EINVAL;
225 read_unlock_bh(&queue_lock);
226 return NULL;
227 }
228
229 read_unlock_bh(&queue_lock);
230
231 skb = alloc_skb(size, GFP_ATOMIC);
232 if (!skb)
233 goto nlmsg_failure;
1ab1457c 234
1da177e4
LT
235 old_tail= skb->tail;
236 nlh = NLMSG_PUT(skb, 0, 0, IPQM_PACKET, size - sizeof(*nlh));
237 pmsg = NLMSG_DATA(nlh);
238 memset(pmsg, 0, sizeof(*pmsg));
239
240 pmsg->packet_id = (unsigned long )entry;
241 pmsg->data_len = data_len;
325ed823
HX
242 pmsg->timestamp_sec = entry->skb->tstamp.off_sec;
243 pmsg->timestamp_usec = entry->skb->tstamp.off_usec;
82e91ffe 244 pmsg->mark = entry->skb->mark;
1da177e4
LT
245 pmsg->hook = entry->info->hook;
246 pmsg->hw_protocol = entry->skb->protocol;
1ab1457c 247
1da177e4
LT
248 if (entry->info->indev)
249 strcpy(pmsg->indev_name, entry->info->indev->name);
250 else
251 pmsg->indev_name[0] = '\0';
1ab1457c 252
1da177e4
LT
253 if (entry->info->outdev)
254 strcpy(pmsg->outdev_name, entry->info->outdev->name);
255 else
256 pmsg->outdev_name[0] = '\0';
1ab1457c 257
1da177e4
LT
258 if (entry->info->indev && entry->skb->dev) {
259 pmsg->hw_type = entry->skb->dev->type;
260 if (entry->skb->dev->hard_header_parse)
261 pmsg->hw_addrlen =
262 entry->skb->dev->hard_header_parse(entry->skb,
1ab1457c 263 pmsg->hw_addr);
1da177e4 264 }
1ab1457c 265
1da177e4
LT
266 if (data_len)
267 if (skb_copy_bits(entry->skb, 0, pmsg->payload, data_len))
268 BUG();
1ab1457c 269
1da177e4
LT
270 nlh->nlmsg_len = skb->tail - old_tail;
271 return skb;
272
273nlmsg_failure:
274 if (skb)
275 kfree_skb(skb);
276 *errp = -EINVAL;
277 printk(KERN_ERR "ip6_queue: error creating packet message\n");
278 return NULL;
279}
280
281static int
1ab1457c 282ipq_enqueue_packet(struct sk_buff *skb, struct nf_info *info,
0ab43f84 283 unsigned int queuenum, void *data)
1da177e4
LT
284{
285 int status = -EINVAL;
286 struct sk_buff *nskb;
287 struct ipq_queue_entry *entry;
288
289 if (copy_mode == IPQ_COPY_NONE)
290 return -EAGAIN;
291
292 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
293 if (entry == NULL) {
294 printk(KERN_ERR "ip6_queue: OOM in ipq_enqueue_packet()\n");
295 return -ENOMEM;
296 }
297
298 entry->info = info;
299 entry->skb = skb;
300
1da177e4
LT
301 nskb = ipq_build_packet_message(entry, &status);
302 if (nskb == NULL)
303 goto err_out_free;
1ab1457c 304
1da177e4 305 write_lock_bh(&queue_lock);
1ab1457c 306
1da177e4 307 if (!peer_pid)
1ab1457c 308 goto err_out_free_nskb;
1da177e4
LT
309
310 if (queue_total >= queue_maxlen) {
1ab1457c 311 queue_dropped++;
1da177e4
LT
312 status = -ENOSPC;
313 if (net_ratelimit())
1ab1457c 314 printk (KERN_WARNING "ip6_queue: fill at %d entries, "
1da177e4
LT
315 "dropping packet(s). Dropped: %d\n", queue_total,
316 queue_dropped);
317 goto err_out_free_nskb;
318 }
319
1ab1457c 320 /* netlink_unicast will either free the nskb or attach it to a socket */
1da177e4
LT
321 status = netlink_unicast(ipqnl, nskb, peer_pid, MSG_DONTWAIT);
322 if (status < 0) {
1ab1457c 323 queue_user_dropped++;
1da177e4
LT
324 goto err_out_unlock;
325 }
1ab1457c 326
1da177e4
LT
327 __ipq_enqueue_entry(entry);
328
329 write_unlock_bh(&queue_lock);
330 return status;
1ab1457c 331
1da177e4 332err_out_free_nskb:
1ab1457c
YH
333 kfree_skb(nskb);
334
1da177e4
LT
335err_out_unlock:
336 write_unlock_bh(&queue_lock);
337
338err_out_free:
339 kfree(entry);
340 return status;
341}
342
343static int
344ipq_mangle_ipv6(ipq_verdict_msg_t *v, struct ipq_queue_entry *e)
345{
346 int diff;
347 struct ipv6hdr *user_iph = (struct ipv6hdr *)v->payload;
348
349 if (v->data_len < sizeof(*user_iph))
350 return 0;
351 diff = v->data_len - e->skb->len;
d8a585d7
PM
352 if (diff < 0) {
353 if (pskb_trim(e->skb, v->data_len))
354 return -ENOMEM;
355 } else if (diff > 0) {
1da177e4
LT
356 if (v->data_len > 0xFFFF)
357 return -EINVAL;
358 if (diff > skb_tailroom(e->skb)) {
359 struct sk_buff *newskb;
1ab1457c 360
1da177e4 361 newskb = skb_copy_expand(e->skb,
1ab1457c
YH
362 skb_headroom(e->skb),
363 diff,
364 GFP_ATOMIC);
1da177e4
LT
365 if (newskb == NULL) {
366 printk(KERN_WARNING "ip6_queue: OOM "
367 "in mangle, dropping packet\n");
368 return -ENOMEM;
369 }
370 if (e->skb->sk)
371 skb_set_owner_w(newskb, e->skb->sk);
372 kfree_skb(e->skb);
373 e->skb = newskb;
374 }
375 skb_put(e->skb, diff);
376 }
089af26c 377 if (!skb_make_writable(&e->skb, v->data_len))
1da177e4
LT
378 return -ENOMEM;
379 memcpy(e->skb->data, v->payload, v->data_len);
66a79a19 380 e->skb->ip_summed = CHECKSUM_NONE;
1da177e4 381
1da177e4
LT
382 return 0;
383}
384
385static inline int
386id_cmp(struct ipq_queue_entry *e, unsigned long id)
387{
388 return (id == (unsigned long )e);
389}
390
391static int
392ipq_set_verdict(struct ipq_verdict_msg *vmsg, unsigned int len)
393{
394 struct ipq_queue_entry *entry;
395
396 if (vmsg->value > NF_MAX_VERDICT)
397 return -EINVAL;
398
399 entry = ipq_find_dequeue_entry(id_cmp, vmsg->id);
400 if (entry == NULL)
401 return -ENOENT;
402 else {
403 int verdict = vmsg->value;
1ab1457c 404
1da177e4
LT
405 if (vmsg->data_len && vmsg->data_len == len)
406 if (ipq_mangle_ipv6(vmsg, entry) < 0)
407 verdict = NF_DROP;
1ab1457c 408
1da177e4
LT
409 ipq_issue_verdict(entry, verdict);
410 return 0;
411 }
412}
413
414static int
415ipq_set_mode(unsigned char mode, unsigned int range)
416{
417 int status;
418
419 write_lock_bh(&queue_lock);
420 status = __ipq_set_mode(mode, range);
421 write_unlock_bh(&queue_lock);
422 return status;
423}
424
425static int
426ipq_receive_peer(struct ipq_peer_msg *pmsg,
1ab1457c 427 unsigned char type, unsigned int len)
1da177e4
LT
428{
429 int status = 0;
430
431 if (len < sizeof(*pmsg))
432 return -EINVAL;
433
434 switch (type) {
435 case IPQM_MODE:
436 status = ipq_set_mode(pmsg->msg.mode.value,
1ab1457c 437 pmsg->msg.mode.range);
1da177e4 438 break;
1ab1457c 439
1da177e4
LT
440 case IPQM_VERDICT:
441 if (pmsg->msg.verdict.value > NF_MAX_VERDICT)
442 status = -EINVAL;
443 else
444 status = ipq_set_verdict(&pmsg->msg.verdict,
1ab1457c 445 len - sizeof(*pmsg));
1da177e4
LT
446 break;
447 default:
448 status = -EINVAL;
449 }
450 return status;
451}
452
453static int
454dev_cmp(struct ipq_queue_entry *entry, unsigned long ifindex)
455{
456 if (entry->info->indev)
457 if (entry->info->indev->ifindex == ifindex)
458 return 1;
1ab1457c 459
1da177e4
LT
460 if (entry->info->outdev)
461 if (entry->info->outdev->ifindex == ifindex)
462 return 1;
463
464 return 0;
465}
466
467static void
468ipq_dev_drop(int ifindex)
469{
470 struct ipq_queue_entry *entry;
1ab1457c 471
1da177e4
LT
472 while ((entry = ipq_find_dequeue_entry(dev_cmp, ifindex)) != NULL)
473 ipq_issue_verdict(entry, NF_DROP);
474}
475
476#define RCV_SKB_FAIL(err) do { netlink_ack(skb, nlh, (err)); return; } while (0)
477
478static inline void
479ipq_rcv_skb(struct sk_buff *skb)
480{
481 int status, type, pid, flags, nlmsglen, skblen;
482 struct nlmsghdr *nlh;
483
484 skblen = skb->len;
485 if (skblen < sizeof(*nlh))
486 return;
487
488 nlh = (struct nlmsghdr *)skb->data;
489 nlmsglen = nlh->nlmsg_len;
490 if (nlmsglen < sizeof(*nlh) || skblen < nlmsglen)
491 return;
492
493 pid = nlh->nlmsg_pid;
494 flags = nlh->nlmsg_flags;
1ab1457c 495
1da177e4
LT
496 if(pid <= 0 || !(flags & NLM_F_REQUEST) || flags & NLM_F_MULTI)
497 RCV_SKB_FAIL(-EINVAL);
1ab1457c 498
1da177e4
LT
499 if (flags & MSG_TRUNC)
500 RCV_SKB_FAIL(-ECOMM);
1ab1457c 501
1da177e4
LT
502 type = nlh->nlmsg_type;
503 if (type < NLMSG_NOOP || type >= IPQM_MAX)
504 RCV_SKB_FAIL(-EINVAL);
1ab1457c 505
1da177e4
LT
506 if (type <= IPQM_BASE)
507 return;
1ab1457c 508
c7bdb545 509 if (security_netlink_recv(skb, CAP_NET_ADMIN))
1ab1457c 510 RCV_SKB_FAIL(-EPERM);
1da177e4
LT
511
512 write_lock_bh(&queue_lock);
1ab1457c 513
1da177e4
LT
514 if (peer_pid) {
515 if (peer_pid != pid) {
516 write_unlock_bh(&queue_lock);
517 RCV_SKB_FAIL(-EBUSY);
518 }
519 } else {
520 net_enable_timestamp();
521 peer_pid = pid;
522 }
1ab1457c 523
1da177e4 524 write_unlock_bh(&queue_lock);
1ab1457c 525
1da177e4 526 status = ipq_receive_peer(NLMSG_DATA(nlh), type,
1ab1457c 527 nlmsglen - NLMSG_LENGTH(0));
1da177e4
LT
528 if (status < 0)
529 RCV_SKB_FAIL(status);
1ab1457c 530
1da177e4
LT
531 if (flags & NLM_F_ACK)
532 netlink_ack(skb, nlh, 0);
1ab1457c 533 return;
1da177e4
LT
534}
535
536static void
537ipq_rcv_sk(struct sock *sk, int len)
538{
2a0a6ebe
HX
539 struct sk_buff *skb;
540 unsigned int qlen;
1da177e4 541
4a3e2f71 542 mutex_lock(&ipqnl_mutex);
1ab1457c 543
2a0a6ebe
HX
544 for (qlen = skb_queue_len(&sk->sk_receive_queue); qlen; qlen--) {
545 skb = skb_dequeue(&sk->sk_receive_queue);
546 ipq_rcv_skb(skb);
547 kfree_skb(skb);
548 }
1ab1457c 549
4a3e2f71 550 mutex_unlock(&ipqnl_mutex);
1da177e4
LT
551}
552
553static int
554ipq_rcv_dev_event(struct notifier_block *this,
1ab1457c 555 unsigned long event, void *ptr)
1da177e4
LT
556{
557 struct net_device *dev = ptr;
558
559 /* Drop any packets associated with the downed device */
560 if (event == NETDEV_DOWN)
561 ipq_dev_drop(dev->ifindex);
562 return NOTIFY_DONE;
563}
564
565static struct notifier_block ipq_dev_notifier = {
566 .notifier_call = ipq_rcv_dev_event,
567};
568
569static int
570ipq_rcv_nl_event(struct notifier_block *this,
1ab1457c 571 unsigned long event, void *ptr)
1da177e4
LT
572{
573 struct netlink_notify *n = ptr;
574
575 if (event == NETLINK_URELEASE &&
576 n->protocol == NETLINK_IP6_FW && n->pid) {
577 write_lock_bh(&queue_lock);
578 if (n->pid == peer_pid)
579 __ipq_reset();
580 write_unlock_bh(&queue_lock);
581 }
582 return NOTIFY_DONE;
583}
584
585static struct notifier_block ipq_nl_notifier = {
586 .notifier_call = ipq_rcv_nl_event,
587};
588
589static struct ctl_table_header *ipq_sysctl_header;
590
591static ctl_table ipq_table[] = {
592 {
593 .ctl_name = NET_IPQ_QMAX,
594 .procname = NET_IPQ_QMAX_NAME,
595 .data = &queue_maxlen,
596 .maxlen = sizeof(queue_maxlen),
597 .mode = 0644,
598 .proc_handler = proc_dointvec
599 },
1ab1457c 600 { .ctl_name = 0 }
1da177e4
LT
601};
602
603static ctl_table ipq_dir_table[] = {
604 {
605 .ctl_name = NET_IPV6,
606 .procname = "ipv6",
607 .mode = 0555,
608 .child = ipq_table
609 },
610 { .ctl_name = 0 }
611};
612
613static ctl_table ipq_root_table[] = {
614 {
615 .ctl_name = CTL_NET,
616 .procname = "net",
617 .mode = 0555,
618 .child = ipq_dir_table
619 },
620 { .ctl_name = 0 }
621};
622
76592584 623#ifdef CONFIG_PROC_FS
1da177e4
LT
624static int
625ipq_get_info(char *buffer, char **start, off_t offset, int length)
626{
627 int len;
628
629 read_lock_bh(&queue_lock);
1ab1457c 630
1da177e4 631 len = sprintf(buffer,
1ab1457c
YH
632 "Peer PID : %d\n"
633 "Copy mode : %hu\n"
634 "Copy range : %u\n"
635 "Queue length : %u\n"
636 "Queue max. length : %u\n"
1da177e4
LT
637 "Queue dropped : %u\n"
638 "Netfilter dropped : %u\n",
1ab1457c
YH
639 peer_pid,
640 copy_mode,
641 copy_range,
642 queue_total,
643 queue_maxlen,
1da177e4
LT
644 queue_dropped,
645 queue_user_dropped);
646
647 read_unlock_bh(&queue_lock);
1ab1457c 648
1da177e4
LT
649 *start = buffer + offset;
650 len -= offset;
651 if (len > length)
652 len = length;
653 else if (len < 0)
654 len = 0;
655 return len;
656}
76592584 657#endif /* CONFIG_PROC_FS */
1da177e4 658
bbd86b9f
HW
659static struct nf_queue_handler nfqh = {
660 .name = "ip6_queue",
661 .outfn = &ipq_enqueue_packet,
662};
663
32292a7f 664static int __init ip6_queue_init(void)
1da177e4
LT
665{
666 int status = -ENOMEM;
667 struct proc_dir_entry *proc;
1ab1457c 668
1da177e4 669 netlink_register_notifier(&ipq_nl_notifier);
06628607 670 ipqnl = netlink_kernel_create(NETLINK_IP6_FW, 0, ipq_rcv_sk,
1ab1457c 671 THIS_MODULE);
1da177e4
LT
672 if (ipqnl == NULL) {
673 printk(KERN_ERR "ip6_queue: failed to create netlink socket\n");
674 goto cleanup_netlink_notifier;
675 }
676
677 proc = proc_net_create(IPQ_PROC_FS_NAME, 0, ipq_get_info);
678 if (proc)
679 proc->owner = THIS_MODULE;
680 else {
681 printk(KERN_ERR "ip6_queue: failed to create proc entry\n");
682 goto cleanup_ipqnl;
683 }
1ab1457c 684
1da177e4
LT
685 register_netdevice_notifier(&ipq_dev_notifier);
686 ipq_sysctl_header = register_sysctl_table(ipq_root_table, 0);
1ab1457c 687
bbd86b9f 688 status = nf_register_queue_handler(PF_INET6, &nfqh);
1da177e4
LT
689 if (status < 0) {
690 printk(KERN_ERR "ip6_queue: failed to register queue handler\n");
691 goto cleanup_sysctl;
692 }
693 return status;
694
1da177e4
LT
695cleanup_sysctl:
696 unregister_sysctl_table(ipq_sysctl_header);
697 unregister_netdevice_notifier(&ipq_dev_notifier);
698 proc_net_remove(IPQ_PROC_FS_NAME);
1ab1457c 699
1da177e4
LT
700cleanup_ipqnl:
701 sock_release(ipqnl->sk_socket);
4a3e2f71
AV
702 mutex_lock(&ipqnl_mutex);
703 mutex_unlock(&ipqnl_mutex);
1ab1457c 704
1da177e4
LT
705cleanup_netlink_notifier:
706 netlink_unregister_notifier(&ipq_nl_notifier);
707 return status;
708}
709
65b4b4e8 710static void __exit ip6_queue_fini(void)
1da177e4 711{
32292a7f
PM
712 nf_unregister_queue_handlers(&nfqh);
713 synchronize_net();
714 ipq_flush(NF_DROP);
715
716 unregister_sysctl_table(ipq_sysctl_header);
717 unregister_netdevice_notifier(&ipq_dev_notifier);
718 proc_net_remove(IPQ_PROC_FS_NAME);
719
720 sock_release(ipqnl->sk_socket);
721 mutex_lock(&ipqnl_mutex);
722 mutex_unlock(&ipqnl_mutex);
723
724 netlink_unregister_notifier(&ipq_nl_notifier);
1da177e4
LT
725}
726
727MODULE_DESCRIPTION("IPv6 packet queue handler");
728MODULE_LICENSE("GPL");
729
65b4b4e8
AM
730module_init(ip6_queue_init);
731module_exit(ip6_queue_fini);