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