Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 38 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | struct ipq_queue_entry { |
| 52 | struct list_head list; |
| 53 | struct nf_info *info; |
| 54 | struct sk_buff *skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | typedef int (*ipq_cmpfn)(struct ipq_queue_entry *, unsigned long); |
| 58 | |
Brian Haley | 1192e40 | 2006-09-20 12:03:46 -0700 | [diff] [blame] | 59 | static unsigned char copy_mode __read_mostly = IPQ_COPY_NONE; |
Brian Haley | 94aec08 | 2006-09-18 00:05:22 -0700 | [diff] [blame] | 60 | static unsigned int queue_maxlen __read_mostly = IPQ_QMAX_DEFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | static DEFINE_RWLOCK(queue_lock); |
Brian Haley | 1192e40 | 2006-09-20 12:03:46 -0700 | [diff] [blame] | 62 | static int peer_pid __read_mostly; |
| 63 | static unsigned int copy_range __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | static unsigned int queue_total; |
| 65 | static unsigned int queue_dropped = 0; |
| 66 | static unsigned int queue_user_dropped = 0; |
Brian Haley | 1192e40 | 2006-09-20 12:03:46 -0700 | [diff] [blame] | 67 | static struct sock *ipqnl __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | static LIST_HEAD(queue_list); |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 69 | static DEFINE_MUTEX(ipqnl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | static void |
| 72 | ipq_issue_verdict(struct ipq_queue_entry *entry, int verdict) |
| 73 | { |
Patrick McHardy | 4c1217d | 2005-07-22 12:49:30 -0700 | [diff] [blame] | 74 | local_bh_disable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | nf_reinject(entry->skb, entry->info, verdict); |
Patrick McHardy | 4c1217d | 2005-07-22 12:49:30 -0700 | [diff] [blame] | 76 | local_bh_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | kfree(entry); |
| 78 | } |
| 79 | |
| 80 | static 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 | */ |
| 91 | static 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; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | if (!cmpfn || cmpfn(entry, data)) |
| 100 | return entry; |
| 101 | } |
| 102 | return NULL; |
| 103 | } |
| 104 | |
| 105 | static inline void |
| 106 | __ipq_dequeue_entry(struct ipq_queue_entry *entry) |
| 107 | { |
| 108 | list_del(&entry->list); |
| 109 | queue_total--; |
| 110 | } |
| 111 | |
| 112 | static 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 | |
| 126 | static inline void |
| 127 | __ipq_flush(int verdict) |
| 128 | { |
| 129 | struct ipq_queue_entry *entry; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | while ((entry = __ipq_find_dequeue_entry(NULL, 0))) |
| 132 | ipq_issue_verdict(entry, verdict); |
| 133 | } |
| 134 | |
| 135 | static inline int |
| 136 | __ipq_set_mode(unsigned char mode, unsigned int range) |
| 137 | { |
| 138 | int status = 0; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | switch(mode) { |
| 141 | case IPQ_COPY_NONE: |
| 142 | case IPQ_COPY_META: |
| 143 | copy_mode = mode; |
| 144 | copy_range = 0; |
| 145 | break; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | case IPQ_COPY_PACKET: |
| 148 | copy_mode = mode; |
| 149 | copy_range = range; |
| 150 | if (copy_range > 0xFFFF) |
| 151 | copy_range = 0xFFFF; |
| 152 | break; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | default: |
| 155 | status = -EINVAL; |
| 156 | |
| 157 | } |
| 158 | return status; |
| 159 | } |
| 160 | |
| 161 | static 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 | |
| 170 | static struct ipq_queue_entry * |
| 171 | ipq_find_dequeue_entry(ipq_cmpfn cmpfn, unsigned long data) |
| 172 | { |
| 173 | struct ipq_queue_entry *entry; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 181 | static void |
| 182 | ipq_flush(int verdict) |
| 183 | { |
| 184 | write_lock_bh(&queue_lock); |
| 185 | __ipq_flush(verdict); |
| 186 | write_unlock_bh(&queue_lock); |
| 187 | } |
| 188 | |
| 189 | static struct sk_buff * |
| 190 | ipq_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; |
Eric Dumazet | b7aa0bf | 2007-04-19 16:16:32 -0700 | [diff] [blame] | 198 | struct timeval tv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | read_lock_bh(&queue_lock); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | switch (copy_mode) { |
| 203 | case IPQ_COPY_META: |
| 204 | case IPQ_COPY_NONE: |
| 205 | size = NLMSG_SPACE(sizeof(*pmsg)); |
| 206 | data_len = 0; |
| 207 | break; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | case IPQ_COPY_PACKET: |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 210 | if ((entry->skb->ip_summed == CHECKSUM_PARTIAL || |
| 211 | entry->skb->ip_summed == CHECKSUM_COMPLETE) && |
| 212 | (*errp = skb_checksum_help(entry->skb))) { |
Patrick McHardy | 66a79a1 | 2005-08-23 10:10:35 -0700 | [diff] [blame] | 213 | read_unlock_bh(&queue_lock); |
| 214 | return NULL; |
| 215 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | if (copy_range == 0 || copy_range > entry->skb->len) |
| 217 | data_len = entry->skb->len; |
| 218 | else |
| 219 | data_len = copy_range; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | size = NLMSG_SPACE(sizeof(*pmsg) + data_len); |
| 222 | break; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | default: |
| 225 | *errp = -EINVAL; |
| 226 | read_unlock_bh(&queue_lock); |
| 227 | return NULL; |
| 228 | } |
| 229 | |
| 230 | read_unlock_bh(&queue_lock); |
| 231 | |
| 232 | skb = alloc_skb(size, GFP_ATOMIC); |
| 233 | if (!skb) |
| 234 | goto nlmsg_failure; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | old_tail= skb->tail; |
| 237 | nlh = NLMSG_PUT(skb, 0, 0, IPQM_PACKET, size - sizeof(*nlh)); |
| 238 | pmsg = NLMSG_DATA(nlh); |
| 239 | memset(pmsg, 0, sizeof(*pmsg)); |
| 240 | |
| 241 | pmsg->packet_id = (unsigned long )entry; |
| 242 | pmsg->data_len = data_len; |
Eric Dumazet | b7aa0bf | 2007-04-19 16:16:32 -0700 | [diff] [blame] | 243 | tv = ktime_to_timeval(entry->skb->tstamp); |
| 244 | pmsg->timestamp_sec = tv.tv_sec; |
| 245 | pmsg->timestamp_usec = tv.tv_usec; |
Thomas Graf | 82e91ff | 2006-11-09 15:19:14 -0800 | [diff] [blame] | 246 | pmsg->mark = entry->skb->mark; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | pmsg->hook = entry->info->hook; |
| 248 | pmsg->hw_protocol = entry->skb->protocol; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | if (entry->info->indev) |
| 251 | strcpy(pmsg->indev_name, entry->info->indev->name); |
| 252 | else |
| 253 | pmsg->indev_name[0] = '\0'; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | if (entry->info->outdev) |
| 256 | strcpy(pmsg->outdev_name, entry->info->outdev->name); |
| 257 | else |
| 258 | pmsg->outdev_name[0] = '\0'; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | if (entry->info->indev && entry->skb->dev) { |
| 261 | pmsg->hw_type = entry->skb->dev->type; |
| 262 | if (entry->skb->dev->hard_header_parse) |
| 263 | pmsg->hw_addrlen = |
| 264 | entry->skb->dev->hard_header_parse(entry->skb, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 265 | pmsg->hw_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | if (data_len) |
| 269 | if (skb_copy_bits(entry->skb, 0, pmsg->payload, data_len)) |
| 270 | BUG(); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | nlh->nlmsg_len = skb->tail - old_tail; |
| 273 | return skb; |
| 274 | |
| 275 | nlmsg_failure: |
| 276 | if (skb) |
| 277 | kfree_skb(skb); |
| 278 | *errp = -EINVAL; |
| 279 | printk(KERN_ERR "ip6_queue: error creating packet message\n"); |
| 280 | return NULL; |
| 281 | } |
| 282 | |
| 283 | static int |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 284 | ipq_enqueue_packet(struct sk_buff *skb, struct nf_info *info, |
Harald Welte | 0ab43f8 | 2005-08-09 19:43:44 -0700 | [diff] [blame] | 285 | unsigned int queuenum, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | { |
| 287 | int status = -EINVAL; |
| 288 | struct sk_buff *nskb; |
| 289 | struct ipq_queue_entry *entry; |
| 290 | |
| 291 | if (copy_mode == IPQ_COPY_NONE) |
| 292 | return -EAGAIN; |
| 293 | |
| 294 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 295 | if (entry == NULL) { |
| 296 | printk(KERN_ERR "ip6_queue: OOM in ipq_enqueue_packet()\n"); |
| 297 | return -ENOMEM; |
| 298 | } |
| 299 | |
| 300 | entry->info = info; |
| 301 | entry->skb = skb; |
| 302 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | nskb = ipq_build_packet_message(entry, &status); |
| 304 | if (nskb == NULL) |
| 305 | goto err_out_free; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | write_lock_bh(&queue_lock); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | if (!peer_pid) |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 310 | goto err_out_free_nskb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
| 312 | if (queue_total >= queue_maxlen) { |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 313 | queue_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | status = -ENOSPC; |
| 315 | if (net_ratelimit()) |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 316 | printk (KERN_WARNING "ip6_queue: fill at %d entries, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | "dropping packet(s). Dropped: %d\n", queue_total, |
| 318 | queue_dropped); |
| 319 | goto err_out_free_nskb; |
| 320 | } |
| 321 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 322 | /* netlink_unicast will either free the nskb or attach it to a socket */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | status = netlink_unicast(ipqnl, nskb, peer_pid, MSG_DONTWAIT); |
| 324 | if (status < 0) { |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 325 | queue_user_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | goto err_out_unlock; |
| 327 | } |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | __ipq_enqueue_entry(entry); |
| 330 | |
| 331 | write_unlock_bh(&queue_lock); |
| 332 | return status; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | err_out_free_nskb: |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 335 | kfree_skb(nskb); |
| 336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | err_out_unlock: |
| 338 | write_unlock_bh(&queue_lock); |
| 339 | |
| 340 | err_out_free: |
| 341 | kfree(entry); |
| 342 | return status; |
| 343 | } |
| 344 | |
| 345 | static int |
| 346 | ipq_mangle_ipv6(ipq_verdict_msg_t *v, struct ipq_queue_entry *e) |
| 347 | { |
| 348 | int diff; |
| 349 | struct ipv6hdr *user_iph = (struct ipv6hdr *)v->payload; |
| 350 | |
| 351 | if (v->data_len < sizeof(*user_iph)) |
| 352 | return 0; |
| 353 | diff = v->data_len - e->skb->len; |
Patrick McHardy | d8a585d | 2006-11-14 19:48:09 -0800 | [diff] [blame] | 354 | if (diff < 0) { |
| 355 | if (pskb_trim(e->skb, v->data_len)) |
| 356 | return -ENOMEM; |
| 357 | } else if (diff > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | if (v->data_len > 0xFFFF) |
| 359 | return -EINVAL; |
| 360 | if (diff > skb_tailroom(e->skb)) { |
| 361 | struct sk_buff *newskb; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | newskb = skb_copy_expand(e->skb, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 364 | skb_headroom(e->skb), |
| 365 | diff, |
| 366 | GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | if (newskb == NULL) { |
| 368 | printk(KERN_WARNING "ip6_queue: OOM " |
| 369 | "in mangle, dropping packet\n"); |
| 370 | return -ENOMEM; |
| 371 | } |
| 372 | if (e->skb->sk) |
| 373 | skb_set_owner_w(newskb, e->skb->sk); |
| 374 | kfree_skb(e->skb); |
| 375 | e->skb = newskb; |
| 376 | } |
| 377 | skb_put(e->skb, diff); |
| 378 | } |
Harald Welte | 089af26 | 2005-08-09 19:37:23 -0700 | [diff] [blame] | 379 | if (!skb_make_writable(&e->skb, v->data_len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | return -ENOMEM; |
| 381 | memcpy(e->skb->data, v->payload, v->data_len); |
Patrick McHardy | 66a79a1 | 2005-08-23 10:10:35 -0700 | [diff] [blame] | 382 | e->skb->ip_summed = CHECKSUM_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | static inline int |
| 388 | id_cmp(struct ipq_queue_entry *e, unsigned long id) |
| 389 | { |
| 390 | return (id == (unsigned long )e); |
| 391 | } |
| 392 | |
| 393 | static int |
| 394 | ipq_set_verdict(struct ipq_verdict_msg *vmsg, unsigned int len) |
| 395 | { |
| 396 | struct ipq_queue_entry *entry; |
| 397 | |
| 398 | if (vmsg->value > NF_MAX_VERDICT) |
| 399 | return -EINVAL; |
| 400 | |
| 401 | entry = ipq_find_dequeue_entry(id_cmp, vmsg->id); |
| 402 | if (entry == NULL) |
| 403 | return -ENOENT; |
| 404 | else { |
| 405 | int verdict = vmsg->value; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | if (vmsg->data_len && vmsg->data_len == len) |
| 408 | if (ipq_mangle_ipv6(vmsg, entry) < 0) |
| 409 | verdict = NF_DROP; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | ipq_issue_verdict(entry, verdict); |
| 412 | return 0; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | static int |
| 417 | ipq_set_mode(unsigned char mode, unsigned int range) |
| 418 | { |
| 419 | int status; |
| 420 | |
| 421 | write_lock_bh(&queue_lock); |
| 422 | status = __ipq_set_mode(mode, range); |
| 423 | write_unlock_bh(&queue_lock); |
| 424 | return status; |
| 425 | } |
| 426 | |
| 427 | static int |
| 428 | ipq_receive_peer(struct ipq_peer_msg *pmsg, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 429 | unsigned char type, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | { |
| 431 | int status = 0; |
| 432 | |
| 433 | if (len < sizeof(*pmsg)) |
| 434 | return -EINVAL; |
| 435 | |
| 436 | switch (type) { |
| 437 | case IPQM_MODE: |
| 438 | status = ipq_set_mode(pmsg->msg.mode.value, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 439 | pmsg->msg.mode.range); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | break; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 441 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | case IPQM_VERDICT: |
| 443 | if (pmsg->msg.verdict.value > NF_MAX_VERDICT) |
| 444 | status = -EINVAL; |
| 445 | else |
| 446 | status = ipq_set_verdict(&pmsg->msg.verdict, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 447 | len - sizeof(*pmsg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | break; |
| 449 | default: |
| 450 | status = -EINVAL; |
| 451 | } |
| 452 | return status; |
| 453 | } |
| 454 | |
| 455 | static int |
| 456 | dev_cmp(struct ipq_queue_entry *entry, unsigned long ifindex) |
| 457 | { |
| 458 | if (entry->info->indev) |
| 459 | if (entry->info->indev->ifindex == ifindex) |
| 460 | return 1; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | if (entry->info->outdev) |
| 463 | if (entry->info->outdev->ifindex == ifindex) |
| 464 | return 1; |
| 465 | |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | static void |
| 470 | ipq_dev_drop(int ifindex) |
| 471 | { |
| 472 | struct ipq_queue_entry *entry; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | while ((entry = ipq_find_dequeue_entry(dev_cmp, ifindex)) != NULL) |
| 475 | ipq_issue_verdict(entry, NF_DROP); |
| 476 | } |
| 477 | |
| 478 | #define RCV_SKB_FAIL(err) do { netlink_ack(skb, nlh, (err)); return; } while (0) |
| 479 | |
| 480 | static inline void |
| 481 | ipq_rcv_skb(struct sk_buff *skb) |
| 482 | { |
| 483 | int status, type, pid, flags, nlmsglen, skblen; |
| 484 | struct nlmsghdr *nlh; |
| 485 | |
| 486 | skblen = skb->len; |
| 487 | if (skblen < sizeof(*nlh)) |
| 488 | return; |
| 489 | |
| 490 | nlh = (struct nlmsghdr *)skb->data; |
| 491 | nlmsglen = nlh->nlmsg_len; |
| 492 | if (nlmsglen < sizeof(*nlh) || skblen < nlmsglen) |
| 493 | return; |
| 494 | |
| 495 | pid = nlh->nlmsg_pid; |
| 496 | flags = nlh->nlmsg_flags; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | if(pid <= 0 || !(flags & NLM_F_REQUEST) || flags & NLM_F_MULTI) |
| 499 | RCV_SKB_FAIL(-EINVAL); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | if (flags & MSG_TRUNC) |
| 502 | RCV_SKB_FAIL(-ECOMM); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | type = nlh->nlmsg_type; |
| 505 | if (type < NLMSG_NOOP || type >= IPQM_MAX) |
| 506 | RCV_SKB_FAIL(-EINVAL); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | if (type <= IPQM_BASE) |
| 509 | return; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 510 | |
Darrel Goeddel | c7bdb54 | 2006-06-27 13:26:11 -0700 | [diff] [blame] | 511 | if (security_netlink_recv(skb, CAP_NET_ADMIN)) |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 512 | RCV_SKB_FAIL(-EPERM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
| 514 | write_lock_bh(&queue_lock); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | if (peer_pid) { |
| 517 | if (peer_pid != pid) { |
| 518 | write_unlock_bh(&queue_lock); |
| 519 | RCV_SKB_FAIL(-EBUSY); |
| 520 | } |
| 521 | } else { |
| 522 | net_enable_timestamp(); |
| 523 | peer_pid = pid; |
| 524 | } |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | write_unlock_bh(&queue_lock); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 527 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | status = ipq_receive_peer(NLMSG_DATA(nlh), type, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 529 | nlmsglen - NLMSG_LENGTH(0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | if (status < 0) |
| 531 | RCV_SKB_FAIL(status); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | if (flags & NLM_F_ACK) |
| 534 | netlink_ack(skb, nlh, 0); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 535 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | static void |
| 539 | ipq_rcv_sk(struct sock *sk, int len) |
| 540 | { |
Herbert Xu | 2a0a6eb | 2005-05-03 14:55:09 -0700 | [diff] [blame] | 541 | struct sk_buff *skb; |
| 542 | unsigned int qlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 544 | mutex_lock(&ipqnl_mutex); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 545 | |
Herbert Xu | 2a0a6eb | 2005-05-03 14:55:09 -0700 | [diff] [blame] | 546 | for (qlen = skb_queue_len(&sk->sk_receive_queue); qlen; qlen--) { |
| 547 | skb = skb_dequeue(&sk->sk_receive_queue); |
| 548 | ipq_rcv_skb(skb); |
| 549 | kfree_skb(skb); |
| 550 | } |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 551 | |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 552 | mutex_unlock(&ipqnl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | static int |
| 556 | ipq_rcv_dev_event(struct notifier_block *this, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 557 | unsigned long event, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | { |
| 559 | struct net_device *dev = ptr; |
| 560 | |
| 561 | /* Drop any packets associated with the downed device */ |
| 562 | if (event == NETDEV_DOWN) |
| 563 | ipq_dev_drop(dev->ifindex); |
| 564 | return NOTIFY_DONE; |
| 565 | } |
| 566 | |
| 567 | static struct notifier_block ipq_dev_notifier = { |
| 568 | .notifier_call = ipq_rcv_dev_event, |
| 569 | }; |
| 570 | |
| 571 | static int |
| 572 | ipq_rcv_nl_event(struct notifier_block *this, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 573 | unsigned long event, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | { |
| 575 | struct netlink_notify *n = ptr; |
| 576 | |
| 577 | if (event == NETLINK_URELEASE && |
| 578 | n->protocol == NETLINK_IP6_FW && n->pid) { |
| 579 | write_lock_bh(&queue_lock); |
| 580 | if (n->pid == peer_pid) |
| 581 | __ipq_reset(); |
| 582 | write_unlock_bh(&queue_lock); |
| 583 | } |
| 584 | return NOTIFY_DONE; |
| 585 | } |
| 586 | |
| 587 | static struct notifier_block ipq_nl_notifier = { |
| 588 | .notifier_call = ipq_rcv_nl_event, |
| 589 | }; |
| 590 | |
| 591 | static struct ctl_table_header *ipq_sysctl_header; |
| 592 | |
| 593 | static ctl_table ipq_table[] = { |
| 594 | { |
| 595 | .ctl_name = NET_IPQ_QMAX, |
| 596 | .procname = NET_IPQ_QMAX_NAME, |
| 597 | .data = &queue_maxlen, |
| 598 | .maxlen = sizeof(queue_maxlen), |
| 599 | .mode = 0644, |
| 600 | .proc_handler = proc_dointvec |
| 601 | }, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 602 | { .ctl_name = 0 } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | }; |
| 604 | |
| 605 | static ctl_table ipq_dir_table[] = { |
| 606 | { |
| 607 | .ctl_name = NET_IPV6, |
| 608 | .procname = "ipv6", |
| 609 | .mode = 0555, |
| 610 | .child = ipq_table |
| 611 | }, |
| 612 | { .ctl_name = 0 } |
| 613 | }; |
| 614 | |
| 615 | static ctl_table ipq_root_table[] = { |
| 616 | { |
| 617 | .ctl_name = CTL_NET, |
| 618 | .procname = "net", |
| 619 | .mode = 0555, |
| 620 | .child = ipq_dir_table |
| 621 | }, |
| 622 | { .ctl_name = 0 } |
| 623 | }; |
| 624 | |
Patrick McHardy | 7659258 | 2006-11-29 02:35:42 +0100 | [diff] [blame] | 625 | #ifdef CONFIG_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | static int |
| 627 | ipq_get_info(char *buffer, char **start, off_t offset, int length) |
| 628 | { |
| 629 | int len; |
| 630 | |
| 631 | read_lock_bh(&queue_lock); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | len = sprintf(buffer, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 634 | "Peer PID : %d\n" |
| 635 | "Copy mode : %hu\n" |
| 636 | "Copy range : %u\n" |
| 637 | "Queue length : %u\n" |
| 638 | "Queue max. length : %u\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | "Queue dropped : %u\n" |
| 640 | "Netfilter dropped : %u\n", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 641 | peer_pid, |
| 642 | copy_mode, |
| 643 | copy_range, |
| 644 | queue_total, |
| 645 | queue_maxlen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | queue_dropped, |
| 647 | queue_user_dropped); |
| 648 | |
| 649 | read_unlock_bh(&queue_lock); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 650 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | *start = buffer + offset; |
| 652 | len -= offset; |
| 653 | if (len > length) |
| 654 | len = length; |
| 655 | else if (len < 0) |
| 656 | len = 0; |
| 657 | return len; |
| 658 | } |
Patrick McHardy | 7659258 | 2006-11-29 02:35:42 +0100 | [diff] [blame] | 659 | #endif /* CONFIG_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
Harald Welte | bbd86b9f | 2005-08-09 20:23:11 -0700 | [diff] [blame] | 661 | static struct nf_queue_handler nfqh = { |
| 662 | .name = "ip6_queue", |
| 663 | .outfn = &ipq_enqueue_packet, |
| 664 | }; |
| 665 | |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 666 | static int __init ip6_queue_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | { |
| 668 | int status = -ENOMEM; |
| 669 | struct proc_dir_entry *proc; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | netlink_register_notifier(&ipq_nl_notifier); |
Patrick McHardy | 0662860 | 2005-08-15 12:33:26 -0700 | [diff] [blame] | 672 | ipqnl = netlink_kernel_create(NETLINK_IP6_FW, 0, ipq_rcv_sk, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 673 | THIS_MODULE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | if (ipqnl == NULL) { |
| 675 | printk(KERN_ERR "ip6_queue: failed to create netlink socket\n"); |
| 676 | goto cleanup_netlink_notifier; |
| 677 | } |
| 678 | |
| 679 | proc = proc_net_create(IPQ_PROC_FS_NAME, 0, ipq_get_info); |
| 680 | if (proc) |
| 681 | proc->owner = THIS_MODULE; |
| 682 | else { |
| 683 | printk(KERN_ERR "ip6_queue: failed to create proc entry\n"); |
| 684 | goto cleanup_ipqnl; |
| 685 | } |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | register_netdevice_notifier(&ipq_dev_notifier); |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 688 | ipq_sysctl_header = register_sysctl_table(ipq_root_table); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 689 | |
Harald Welte | bbd86b9f | 2005-08-09 20:23:11 -0700 | [diff] [blame] | 690 | status = nf_register_queue_handler(PF_INET6, &nfqh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | if (status < 0) { |
| 692 | printk(KERN_ERR "ip6_queue: failed to register queue handler\n"); |
| 693 | goto cleanup_sysctl; |
| 694 | } |
| 695 | return status; |
| 696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | cleanup_sysctl: |
| 698 | unregister_sysctl_table(ipq_sysctl_header); |
| 699 | unregister_netdevice_notifier(&ipq_dev_notifier); |
| 700 | proc_net_remove(IPQ_PROC_FS_NAME); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 701 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | cleanup_ipqnl: |
| 703 | sock_release(ipqnl->sk_socket); |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 704 | mutex_lock(&ipqnl_mutex); |
| 705 | mutex_unlock(&ipqnl_mutex); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | cleanup_netlink_notifier: |
| 708 | netlink_unregister_notifier(&ipq_nl_notifier); |
| 709 | return status; |
| 710 | } |
| 711 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 712 | static void __exit ip6_queue_fini(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | { |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 714 | nf_unregister_queue_handlers(&nfqh); |
| 715 | synchronize_net(); |
| 716 | ipq_flush(NF_DROP); |
| 717 | |
| 718 | unregister_sysctl_table(ipq_sysctl_header); |
| 719 | unregister_netdevice_notifier(&ipq_dev_notifier); |
| 720 | proc_net_remove(IPQ_PROC_FS_NAME); |
| 721 | |
| 722 | sock_release(ipqnl->sk_socket); |
| 723 | mutex_lock(&ipqnl_mutex); |
| 724 | mutex_unlock(&ipqnl_mutex); |
| 725 | |
| 726 | netlink_unregister_notifier(&ipq_nl_notifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | MODULE_DESCRIPTION("IPv6 packet queue handler"); |
| 730 | MODULE_LICENSE("GPL"); |
| 731 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 732 | module_init(ip6_queue_init); |
| 733 | module_exit(ip6_queue_fini); |