]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/core/dst.c
[NET]: Make device event notification network namespace safe
[linux-2.6-omap-h63xx.git] / net / core / dst.c
index 1a5e49da0e77bdaaaaebf5369a97153ff75f4918..32267a16e01e0a2999f6f4ea0a444afdf879e293 100644 (file)
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/netdevice.h>
-#include <linux/sched.h>
 #include <linux/skbuff.h>
 #include <linux/string.h>
 #include <linux/types.h>
+#include <net/net_namespace.h>
 
 #include <net/dst.h>
 
@@ -29,7 +29,7 @@
  * 4) All operations modify state, so a spinlock is used.
  */
 static struct dst_entry        *dst_garbage_list;
-#if RT_CACHE_DEBUG >= 2 
+#if RT_CACHE_DEBUG >= 2
 static atomic_t                         dst_total = ATOMIC_INIT(0);
 #endif
 static DEFINE_SPINLOCK(dst_lock);
@@ -99,19 +99,20 @@ static void dst_run_gc(unsigned long dummy)
        printk("dst_total: %d/%d %ld\n",
               atomic_read(&dst_total), delayed,  dst_gc_timer_expires);
 #endif
-       mod_timer(&dst_gc_timer, jiffies + dst_gc_timer_expires);
+       /* if the next desired timer is more than 4 seconds in the future
+        * then round the timer to whole seconds
+        */
+       if (dst_gc_timer_expires > 4*HZ)
+               mod_timer(&dst_gc_timer,
+                       round_jiffies(jiffies + dst_gc_timer_expires));
+       else
+               mod_timer(&dst_gc_timer, jiffies + dst_gc_timer_expires);
 
 out:
        spin_unlock(&dst_lock);
 }
 
-static int dst_discard_in(struct sk_buff *skb)
-{
-       kfree_skb(skb);
-       return 0;
-}
-
-static int dst_discard_out(struct sk_buff *skb)
+static int dst_discard(struct sk_buff *skb)
 {
        kfree_skb(skb);
        return 0;
@@ -125,17 +126,15 @@ void * dst_alloc(struct dst_ops * ops)
                if (ops->gc())
                        return NULL;
        }
-       dst = kmem_cache_alloc(ops->kmem_cachep, SLAB_ATOMIC);
+       dst = kmem_cache_zalloc(ops->kmem_cachep, GFP_ATOMIC);
        if (!dst)
                return NULL;
-       memset(dst, 0, ops->entry_size);
        atomic_set(&dst->__refcnt, 0);
        dst->ops = ops;
        dst->lastuse = jiffies;
        dst->path = dst;
-       dst->input = dst_discard_in;
-       dst->output = dst_discard_out;
-#if RT_CACHE_DEBUG >= 2 
+       dst->input = dst->output = dst_discard;
+#if RT_CACHE_DEBUG >= 2
        atomic_inc(&dst_total);
 #endif
        atomic_inc(&ops->entries);
@@ -148,8 +147,7 @@ static void ___dst_free(struct dst_entry * dst)
           protocol module is unloaded.
         */
        if (dst->dev == NULL || !(dst->dev->flags&IFF_UP)) {
-               dst->input = dst_discard_in;
-               dst->output = dst_discard_out;
+               dst->input = dst->output = dst_discard;
        }
        dst->obsolete = 2;
 }
@@ -196,7 +194,7 @@ again:
                dst->ops->destroy(dst);
        if (dst->dev)
                dev_put(dst->dev);
-#if RT_CACHE_DEBUG >= 2 
+#if RT_CACHE_DEBUG >= 2
        atomic_dec(&dst_total);
 #endif
        kmem_cache_free(dst->ops->kmem_cachep, dst);
@@ -237,8 +235,7 @@ static inline void dst_ifdown(struct dst_entry *dst, struct net_device *dev,
                return;
 
        if (!unregister) {
-               dst->input = dst_discard_in;
-               dst->output = dst_discard_out;
+               dst->input = dst->output = dst_discard;
        } else {
                dst->dev = &loopback_dev;
                dev_hold(&loopback_dev);
@@ -256,6 +253,9 @@ static int dst_dev_event(struct notifier_block *this, unsigned long event, void
        struct net_device *dev = ptr;
        struct dst_entry *dst;
 
+       if (dev->nd_net != &init_net)
+               return NOTIFY_DONE;
+
        switch (event) {
        case NETDEV_UNREGISTER:
        case NETDEV_DOWN: