]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/netfilter/nf_queue.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/hpa/linux...
[linux-2.6-omap-h63xx.git] / net / netfilter / nf_queue.c
index 662a869593bff6ea852180428b8ac0dbf8af1692..a481a349f7bf6b5e29d00e75343f5a5934b47f1a 100644 (file)
 
 #include "nf_internals.h"
 
-/* 
+/*
  * A queue handler may be registered for each protocol.  Each is protected by
  * long term mutex.  The handler must provide an an outfn() to accept packets
  * for queueing and must reinject all packets it receives, no matter what.
  */
 static struct nf_queue_handler *queue_handler[NPROTO];
 
-static DEFINE_RWLOCK(queue_handler_lock);
+static DEFINE_MUTEX(queue_handler_mutex);
 
 /* return EBUSY when somebody else is registered, return EEXIST if the
  * same handler is registered, return 0 in case of success. */
 int nf_register_queue_handler(int pf, struct nf_queue_handler *qh)
-{      
+{
        int ret;
 
        if (pf >= NPROTO)
                return -EINVAL;
 
-       write_lock_bh(&queue_handler_lock);
+       mutex_lock(&queue_handler_mutex);
        if (queue_handler[pf] == qh)
                ret = -EEXIST;
        else if (queue_handler[pf])
                ret = -EBUSY;
        else {
-               queue_handler[pf] = qh;
+               rcu_assign_pointer(queue_handler[pf], qh);
                ret = 0;
        }
-       write_unlock_bh(&queue_handler_lock);
+       mutex_unlock(&queue_handler_mutex);
 
        return ret;
 }
 EXPORT_SYMBOL(nf_register_queue_handler);
 
 /* The caller must flush their queue before this */
-int nf_unregister_queue_handler(int pf)
+int nf_unregister_queue_handler(int pf, struct nf_queue_handler *qh)
 {
        if (pf >= NPROTO)
                return -EINVAL;
 
-       write_lock_bh(&queue_handler_lock);
-       queue_handler[pf] = NULL;
-       write_unlock_bh(&queue_handler_lock);
-       
+       mutex_lock(&queue_handler_mutex);
+       if (queue_handler[pf] != qh) {
+               mutex_unlock(&queue_handler_mutex);
+               return -EINVAL;
+       }
+
+       rcu_assign_pointer(queue_handler[pf], NULL);
+       mutex_unlock(&queue_handler_mutex);
+
+       synchronize_rcu();
+
        return 0;
 }
 EXPORT_SYMBOL(nf_unregister_queue_handler);
@@ -61,26 +68,28 @@ void nf_unregister_queue_handlers(struct nf_queue_handler *qh)
 {
        int pf;
 
-       write_lock_bh(&queue_handler_lock);
+       mutex_lock(&queue_handler_mutex);
        for (pf = 0; pf < NPROTO; pf++)  {
                if (queue_handler[pf] == qh)
-                       queue_handler[pf] = NULL;
+                       rcu_assign_pointer(queue_handler[pf], NULL);
        }
-       write_unlock_bh(&queue_handler_lock);
+       mutex_unlock(&queue_handler_mutex);
+
+       synchronize_rcu();
 }
 EXPORT_SYMBOL_GPL(nf_unregister_queue_handlers);
 
-/* 
- * Any packet that leaves via this function must come back 
+/*
+ * Any packet that leaves via this function must come back
  * through nf_reinject().
  */
-int nf_queue(struct sk_buff **skb, 
-            struct list_head *elem, 
-            int pf, unsigned int hook,
-            struct net_device *indev,
-            struct net_device *outdev,
-            int (*okfn)(struct sk_buff *),
-            unsigned int queuenum)
+static int __nf_queue(struct sk_buff *skb,
+                     struct list_head *elem,
+                     int pf, unsigned int hook,
+                     struct net_device *indev,
+                     struct net_device *outdev,
+                     int (*okfn)(struct sk_buff *),
+                     unsigned int queuenum)
 {
        int status;
        struct nf_info *info;
@@ -89,19 +98,22 @@ int nf_queue(struct sk_buff **skb,
        struct net_device *physoutdev = NULL;
 #endif
        struct nf_afinfo *afinfo;
+       struct nf_queue_handler *qh;
 
        /* QUEUE == DROP if noone is waiting, to be safe. */
-       read_lock(&queue_handler_lock);
-       if (!queue_handler[pf]) {
-               read_unlock(&queue_handler_lock);
-               kfree_skb(*skb);
+       rcu_read_lock();
+
+       qh = rcu_dereference(queue_handler[pf]);
+       if (!qh) {
+               rcu_read_unlock();
+               kfree_skb(skb);
                return 1;
        }
 
        afinfo = nf_get_afinfo(pf);
        if (!afinfo) {
-               read_unlock(&queue_handler_lock);
-               kfree_skb(*skb);
+               rcu_read_unlock();
+               kfree_skb(skb);
                return 1;
        }
 
@@ -109,18 +121,18 @@ int nf_queue(struct sk_buff **skb,
        if (!info) {
                if (net_ratelimit())
                        printk(KERN_ERR "OOM queueing packet %p\n",
-                              *skb);
-               read_unlock(&queue_handler_lock);
-               kfree_skb(*skb);
+                              skb);
+               rcu_read_unlock();
+               kfree_skb(skb);
                return 1;
        }
 
-       *info = (struct nf_info) { 
+       *info = (struct nf_info) {
                (struct nf_hook_ops *)elem, pf, hook, indev, outdev, okfn };
 
        /* If it's going away, ignore hook. */
        if (!try_module_get(info->elem->owner)) {
-               read_unlock(&queue_handler_lock);
+               rcu_read_unlock();
                kfree(info);
                return 0;
        }
@@ -130,18 +142,17 @@ int nf_queue(struct sk_buff **skb,
        if (outdev) dev_hold(outdev);
 
 #ifdef CONFIG_BRIDGE_NETFILTER
-       if ((*skb)->nf_bridge) {
-               physindev = (*skb)->nf_bridge->physindev;
+       if (skb->nf_bridge) {
+               physindev = skb->nf_bridge->physindev;
                if (physindev) dev_hold(physindev);
-               physoutdev = (*skb)->nf_bridge->physoutdev;
+               physoutdev = skb->nf_bridge->physoutdev;
                if (physoutdev) dev_hold(physoutdev);
        }
 #endif
-       afinfo->saveroute(*skb, info);
-       status = queue_handler[pf]->outfn(*skb, info, queuenum,
-                                         queue_handler[pf]->data);
+       afinfo->saveroute(skb, info);
+       status = qh->outfn(skb, info, queuenum, qh->data);
 
-       read_unlock(&queue_handler_lock);
+       rcu_read_unlock();
 
        if (status < 0) {
                /* James M doesn't say fuck enough. */
@@ -153,7 +164,7 @@ int nf_queue(struct sk_buff **skb,
 #endif
                module_put(info->elem->owner);
                kfree(info);
-               kfree_skb(*skb);
+               kfree_skb(skb);
 
                return 1;
        }
@@ -161,6 +172,46 @@ int nf_queue(struct sk_buff **skb,
        return 1;
 }
 
+int nf_queue(struct sk_buff *skb,
+            struct list_head *elem,
+            int pf, unsigned int hook,
+            struct net_device *indev,
+            struct net_device *outdev,
+            int (*okfn)(struct sk_buff *),
+            unsigned int queuenum)
+{
+       struct sk_buff *segs;
+
+       if (!skb_is_gso(skb))
+               return __nf_queue(skb, elem, pf, hook, indev, outdev, okfn,
+                                 queuenum);
+
+       switch (pf) {
+       case AF_INET:
+               skb->protocol = htons(ETH_P_IP);
+               break;
+       case AF_INET6:
+               skb->protocol = htons(ETH_P_IPV6);
+               break;
+       }
+
+       segs = skb_gso_segment(skb, 0);
+       kfree_skb(skb);
+       if (unlikely(IS_ERR(segs)))
+               return 1;
+
+       do {
+               struct sk_buff *nskb = segs->next;
+
+               segs->next = NULL;
+               if (!__nf_queue(segs, elem, pf, hook, indev, outdev, okfn,
+                               queuenum))
+                       kfree_skb(segs);
+               segs = nskb;
+       } while (segs);
+       return 1;
+}
+
 void nf_reinject(struct sk_buff *skb, struct nf_info *info,
                 unsigned int verdict)
 {
@@ -186,10 +237,10 @@ void nf_reinject(struct sk_buff *skb, struct nf_info *info,
        module_put(info->elem->owner);
 
        list_for_each_rcu(i, &nf_hooks[info->pf][info->hook]) {
-               if (i == elem) 
-                       break;
-       }
-  
+               if (i == elem)
+                       break;
+       }
+
        if (i == &nf_hooks[info->pf][info->hook]) {
                /* The module which sent it to userspace is gone. */
                NFDEBUG("%s: module disappeared, dropping packet.\n",
@@ -212,7 +263,7 @@ void nf_reinject(struct sk_buff *skb, struct nf_info *info,
        if (verdict == NF_ACCEPT) {
        next_hook:
                verdict = nf_iterate(&nf_hooks[info->pf][info->hook],
-                                    &skb, info->hook, 
+                                    &skb, info->hook,
                                     info->indev, info->outdev, &elem,
                                     info->okfn, INT_MIN);
        }
@@ -224,9 +275,9 @@ void nf_reinject(struct sk_buff *skb, struct nf_info *info,
        case NF_STOLEN:
                break;
        case NF_QUEUE:
-               if (!nf_queue(&skb, elem, info->pf, info->hook, 
-                             info->indev, info->outdev, info->okfn,
-                             verdict >> NF_VERDICT_BITS))
+               if (!__nf_queue(skb, elem, info->pf, info->hook,
+                               info->indev, info->outdev, info->okfn,
+                               verdict >> NF_VERDICT_BITS))
                        goto next_hook;
                break;
        default:
@@ -268,18 +319,18 @@ static int seq_show(struct seq_file *s, void *v)
        loff_t *pos = v;
        struct nf_queue_handler *qh;
 
-       read_lock_bh(&queue_handler_lock);
-       qh = queue_handler[*pos];
+       rcu_read_lock();
+       qh = rcu_dereference(queue_handler[*pos]);
        if (!qh)
                ret = seq_printf(s, "%2lld NONE\n", *pos);
        else
                ret = seq_printf(s, "%2lld %s\n", *pos, qh->name);
-       read_unlock_bh(&queue_handler_lock);
+       rcu_read_unlock();
 
        return ret;
 }
 
-static struct seq_operations nfqueue_seq_ops = {
+static const struct seq_operations nfqueue_seq_ops = {
        .start  = seq_start,
        .next   = seq_next,
        .stop   = seq_stop,
@@ -291,7 +342,7 @@ static int nfqueue_open(struct inode *inode, struct file *file)
        return seq_open(file, &nfqueue_seq_ops);
 }
 
-static struct file_operations nfqueue_file_ops = {
+static const struct file_operations nfqueue_file_ops = {
        .owner   = THIS_MODULE,
        .open    = nfqueue_open,
        .read    = seq_read,