]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - net/ipv4/route.c
[NET] NETNS: Omit seq_net_private->net without CONFIG_NET_NS.
[linux-2.6.git] / net / ipv4 / route.c
index c41ddba02e9d3553dac0f4aca6d7c5c8b9975584..eab8d75e522259d24c7fac019e39d8fe4621c214 100644 (file)
@@ -20,7 +20,7 @@
  *             (rco@di.uminho.pt)      Routing table insertion and update
  *             Linus Torvalds  :       Rewrote bits to be sensible
  *             Alan Cox        :       Added BSD route gw semantics
- *             Alan Cox        :       Super /proc >4K 
+ *             Alan Cox        :       Super /proc >4K
  *             Alan Cox        :       MTU in route table
  *             Alan Cox        :       MSS actually. Also added the window
  *                                     clamper.
@@ -38,7 +38,7 @@
  *             Alan Cox        :       Faster /proc handling
  *     Alexey Kuznetsov        :       Massive rework to support tree based routing,
  *                                     routing caches and better behaviour.
- *             
+ *
  *             Olaf Erb        :       irtt wasn't being copied right.
  *             Bjorn Ekwall    :       Kerneld route support.
  *             Alan Cox        :       Multicast fixed (I hope)
@@ -70,7 +70,6 @@
 #include <linux/bitops.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
-#include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/bootmem.h>
 #include <linux/string.h>
@@ -82,8 +81,8 @@
 #include <linux/netdevice.h>
 #include <linux/proc_fs.h>
 #include <linux/init.h>
+#include <linux/workqueue.h>
 #include <linux/skbuff.h>
-#include <linux/rtnetlink.h>
 #include <linux/inetdevice.h>
 #include <linux/igmp.h>
 #include <linux/pkt_sched.h>
@@ -93,6 +92,8 @@
 #include <linux/jhash.h>
 #include <linux/rcupdate.h>
 #include <linux/times.h>
+#include <net/dst.h>
+#include <net/net_namespace.h>
 #include <net/protocol.h>
 #include <net/ip.h>
 #include <net/route.h>
 #include <net/tcp.h>
 #include <net/icmp.h>
 #include <net/xfrm.h>
-#include <net/ip_mp_alg.h>
 #include <net/netevent.h>
+#include <net/rtnetlink.h>
 #ifdef CONFIG_SYSCTL
 #include <linux/sysctl.h>
 #endif
 
 #define RT_GC_TIMEOUT (300*HZ)
 
-static int ip_rt_min_delay             = 2 * HZ;
-static int ip_rt_max_delay             = 10 * HZ;
 static int ip_rt_max_size;
-static int ip_rt_gc_timeout            = RT_GC_TIMEOUT;
-static int ip_rt_gc_interval           = 60 * HZ;
-static int ip_rt_gc_min_interval       = HZ / 2;
-static int ip_rt_redirect_number       = 9;
-static int ip_rt_redirect_load         = HZ / 50;
-static int ip_rt_redirect_silence      = ((HZ / 50) << (9 + 1));
-static int ip_rt_error_cost            = HZ;
-static int ip_rt_error_burst           = 5 * HZ;
-static int ip_rt_gc_elasticity         = 8;
-static int ip_rt_mtu_expires           = 10 * 60 * HZ;
-static int ip_rt_min_pmtu              = 512 + 20 + 20;
-static int ip_rt_min_advmss            = 256;
-static int ip_rt_secret_interval       = 10 * 60 * HZ;
-static unsigned long rt_deadline;
-
-#define RTprint(a...)  printk(KERN_DEBUG a)
-
-static struct timer_list rt_flush_timer;
-static struct timer_list rt_periodic_timer;
+static int ip_rt_gc_timeout __read_mostly      = RT_GC_TIMEOUT;
+static int ip_rt_gc_interval __read_mostly     = 60 * HZ;
+static int ip_rt_gc_min_interval __read_mostly = HZ / 2;
+static int ip_rt_redirect_number __read_mostly = 9;
+static int ip_rt_redirect_load __read_mostly   = HZ / 50;
+static int ip_rt_redirect_silence __read_mostly        = ((HZ / 50) << (9 + 1));
+static int ip_rt_error_cost __read_mostly      = HZ;
+static int ip_rt_error_burst __read_mostly     = 5 * HZ;
+static int ip_rt_gc_elasticity __read_mostly   = 8;
+static int ip_rt_mtu_expires __read_mostly     = 10 * 60 * HZ;
+static int ip_rt_min_pmtu __read_mostly                = 512 + 20 + 20;
+static int ip_rt_min_advmss __read_mostly      = 256;
+static int ip_rt_secret_interval __read_mostly = 10 * 60 * HZ;
+
+static void rt_worker_func(struct work_struct *work);
+static DECLARE_DELAYED_WORK(expires_work, rt_worker_func);
 static struct timer_list rt_secret_timer;
 
 /*
@@ -151,7 +147,7 @@ static void          ipv4_dst_ifdown(struct dst_entry *dst,
 static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst);
 static void             ipv4_link_failure(struct sk_buff *skb);
 static void             ip_rt_update_pmtu(struct dst_entry *dst, u32 mtu);
-static int rt_garbage_collect(void);
+static int rt_garbage_collect(struct dst_ops *ops);
 
 
 static struct dst_ops ipv4_dst_ops = {
@@ -164,12 +160,14 @@ static struct dst_ops ipv4_dst_ops = {
        .negative_advice =      ipv4_negative_advice,
        .link_failure =         ipv4_link_failure,
        .update_pmtu =          ip_rt_update_pmtu,
+       .local_out =            ip_local_out,
        .entry_size =           sizeof(struct rtable),
+       .entries =              ATOMIC_INIT(0),
 };
 
 #define ECN_OR_COST(class)     TC_PRIO_##class
 
-__u8 ip_tos2prio[16] = {
+const __u8 ip_tos2prio[16] = {
        TC_PRIO_BESTEFFORT,
        ECN_OR_COST(FILLER),
        TC_PRIO_BESTEFFORT,
@@ -231,34 +229,40 @@ struct rt_hash_bucket {
 
 static spinlock_t      *rt_hash_locks;
 # define rt_hash_lock_addr(slot) &rt_hash_locks[(slot) & (RT_HASH_LOCK_SZ - 1)]
-# define rt_hash_lock_init()   { \
-               int i; \
-               rt_hash_locks = kmalloc(sizeof(spinlock_t) * RT_HASH_LOCK_SZ, GFP_KERNEL); \
-               if (!rt_hash_locks) panic("IP: failed to allocate rt_hash_locks\n"); \
-               for (i = 0; i < RT_HASH_LOCK_SZ; i++) \
-                       spin_lock_init(&rt_hash_locks[i]); \
-               }
+
+static __init void rt_hash_lock_init(void)
+{
+       int i;
+
+       rt_hash_locks = kmalloc(sizeof(spinlock_t) * RT_HASH_LOCK_SZ,
+                       GFP_KERNEL);
+       if (!rt_hash_locks)
+               panic("IP: failed to allocate rt_hash_locks\n");
+
+       for (i = 0; i < RT_HASH_LOCK_SZ; i++)
+               spin_lock_init(&rt_hash_locks[i]);
+}
 #else
 # define rt_hash_lock_addr(slot) NULL
-# define rt_hash_lock_init()
+
+static inline void rt_hash_lock_init(void)
+{
+}
 #endif
 
-static struct rt_hash_bucket   *rt_hash_table;
-static unsigned                        rt_hash_mask;
-static int                     rt_hash_log;
-static unsigned int            rt_hash_rnd;
+static struct rt_hash_bucket   *rt_hash_table __read_mostly;
+static unsigned                        rt_hash_mask __read_mostly;
+static unsigned int            rt_hash_log  __read_mostly;
+static atomic_t                        rt_genid __read_mostly;
 
 static DEFINE_PER_CPU(struct rt_cache_stat, rt_cache_stat);
 #define RT_CACHE_STAT_INC(field) \
        (__raw_get_cpu_var(rt_cache_stat).field++)
 
-static int rt_intern_hash(unsigned hash, struct rtable *rth,
-                               struct rtable **res);
-
 static unsigned int rt_hash_code(u32 daddr, u32 saddr)
 {
-       return (jhash_2words(daddr, saddr, rt_hash_rnd)
-               & rt_hash_mask);
+       return jhash_2words(daddr, saddr, atomic_read(&rt_genid))
+               & rt_hash_mask;
 }
 
 #define rt_hash(daddr, saddr, idx) \
@@ -267,29 +271,35 @@ static unsigned int rt_hash_code(u32 daddr, u32 saddr)
 
 #ifdef CONFIG_PROC_FS
 struct rt_cache_iter_state {
+       struct seq_net_private p;
        int bucket;
+       int genid;
 };
 
 static struct rtable *rt_cache_get_first(struct seq_file *seq)
 {
-       struct rtable *r = NULL;
        struct rt_cache_iter_state *st = seq->private;
+       struct rtable *r = NULL;
 
        for (st->bucket = rt_hash_mask; st->bucket >= 0; --st->bucket) {
                rcu_read_lock_bh();
-               r = rt_hash_table[st->bucket].chain;
-               if (r)
-                       break;
+               r = rcu_dereference(rt_hash_table[st->bucket].chain);
+               while (r) {
+                       if (dev_net(r->u.dst.dev) == seq_file_net(seq) &&
+                           r->rt_genid == st->genid)
+                               return r;
+                       r = rcu_dereference(r->u.dst.rt_next);
+               }
                rcu_read_unlock_bh();
        }
        return r;
 }
 
-static struct rtable *rt_cache_get_next(struct seq_file *seq, struct rtable *r)
+static struct rtable *__rt_cache_get_next(struct seq_file *seq,
+                                         struct rtable *r)
 {
-       struct rt_cache_iter_state *st = rcu_dereference(seq->private);
-
-       r = r->u.rt_next;
+       struct rt_cache_iter_state *st = seq->private;
+       r = r->u.dst.rt_next;
        while (!r) {
                rcu_read_unlock_bh();
                if (--st->bucket < 0)
@@ -297,6 +307,19 @@ static struct rtable *rt_cache_get_next(struct seq_file *seq, struct rtable *r)
                rcu_read_lock_bh();
                r = rt_hash_table[st->bucket].chain;
        }
+       return rcu_dereference(r);
+}
+
+static struct rtable *rt_cache_get_next(struct seq_file *seq,
+                                       struct rtable *r)
+{
+       struct rt_cache_iter_state *st = seq->private;
+       while ((r = __rt_cache_get_next(seq, r)) != NULL) {
+               if (dev_net(r->u.dst.dev) != seq_file_net(seq))
+                       continue;
+               if (r->rt_genid == st->genid)
+                       break;
+       }
        return r;
 }
 
@@ -312,12 +335,16 @@ static struct rtable *rt_cache_get_idx(struct seq_file *seq, loff_t pos)
 
 static void *rt_cache_seq_start(struct seq_file *seq, loff_t *pos)
 {
-       return *pos ? rt_cache_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
+       struct rt_cache_iter_state *st = seq->private;
+       if (*pos)
+               return rt_cache_get_idx(seq, *pos - 1);
+       st->genid = atomic_read(&rt_genid);
+       return SEQ_START_TOKEN;
 }
 
 static void *rt_cache_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 {
-       struct rtable *r = NULL;
+       struct rtable *r;
 
        if (v == SEQ_START_TOKEN)
                r = rt_cache_get_first(seq);
@@ -361,11 +388,11 @@ static int rt_cache_seq_show(struct seq_file *seq, void *v)
                                       dev_queue_xmit) : 0,
                        r->rt_spec_dst);
                seq_printf(seq, "%-127s\n", temp);
-        }
-       return 0;
+       }
+       return 0;
 }
 
-static struct seq_operations rt_cache_seq_ops = {
+static const struct seq_operations rt_cache_seq_ops = {
        .start  = rt_cache_seq_start,
        .next   = rt_cache_seq_next,
        .stop   = rt_cache_seq_stop,
@@ -374,31 +401,16 @@ static struct seq_operations rt_cache_seq_ops = {
 
 static int rt_cache_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       struct rt_cache_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
-
-       if (!s)
-               goto out;
-       rc = seq_open(file, &rt_cache_seq_ops);
-       if (rc)
-               goto out_kfree;
-       seq          = file->private_data;
-       seq->private = s;
-       memset(s, 0, sizeof(*s));
-out:
-       return rc;
-out_kfree:
-       kfree(s);
-       goto out;
+       return seq_open_net(inode, file, &rt_cache_seq_ops,
+                       sizeof(struct rt_cache_iter_state));
 }
 
-static struct file_operations rt_cache_seq_fops = {
+static const struct file_operations rt_cache_seq_fops = {
        .owner   = THIS_MODULE,
        .open    = rt_cache_seq_open,
        .read    = seq_read,
        .llseek  = seq_lseek,
-       .release = seq_release_private,
+       .release = seq_release_net,
 };
 
 
@@ -429,7 +441,7 @@ static void *rt_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
                return &per_cpu(rt_cache_stat, cpu);
        }
        return NULL;
-       
+
 }
 
 static void rt_cpu_seq_stop(struct seq_file *seq, void *v)
@@ -445,7 +457,7 @@ static int rt_cpu_seq_show(struct seq_file *seq, void *v)
                seq_printf(seq, "entries  in_hit in_slow_tot in_slow_mc in_no_route in_brd in_martian_dst in_martian_src  out_hit out_slow_tot out_slow_mc  gc_total gc_ignored gc_goal_miss gc_dst_overflow in_hlist_search out_hlist_search\n");
                return 0;
        }
-       
+
        seq_printf(seq,"%08x  %08x %08x %08x %08x %08x %08x %08x "
                   " %08x %08x %08x %08x %08x %08x %08x %08x %08x \n",
                   atomic_read(&ipv4_dst_ops.entries),
@@ -459,7 +471,7 @@ static int rt_cpu_seq_show(struct seq_file *seq, void *v)
 
                   st->out_hit,
                   st->out_slow_tot,
-                  st->out_slow_mc, 
+                  st->out_slow_mc,
 
                   st->gc_total,
                   st->gc_ignored,
@@ -471,7 +483,7 @@ static int rt_cpu_seq_show(struct seq_file *seq, void *v)
        return 0;
 }
 
-static struct seq_operations rt_cpu_seq_ops = {
+static const struct seq_operations rt_cpu_seq_ops = {
        .start  = rt_cpu_seq_start,
        .next   = rt_cpu_seq_next,
        .stop   = rt_cpu_seq_stop,
@@ -484,7 +496,7 @@ static int rt_cpu_seq_open(struct inode *inode, struct file *file)
        return seq_open(file, &rt_cpu_seq_ops);
 }
 
-static struct file_operations rt_cpu_seq_fops = {
+static const struct file_operations rt_cpu_seq_fops = {
        .owner   = THIS_MODULE,
        .open    = rt_cpu_seq_open,
        .read    = seq_read,
@@ -492,17 +504,109 @@ static struct file_operations rt_cpu_seq_fops = {
        .release = seq_release,
 };
 
+#ifdef CONFIG_NET_CLS_ROUTE
+static int ip_rt_acct_read(char *buffer, char **start, off_t offset,
+                          int length, int *eof, void *data)
+{
+       unsigned int i;
+
+       if ((offset & 3) || (length & 3))
+               return -EIO;
+
+       if (offset >= sizeof(struct ip_rt_acct) * 256) {
+               *eof = 1;
+               return 0;
+       }
+
+       if (offset + length >= sizeof(struct ip_rt_acct) * 256) {
+               length = sizeof(struct ip_rt_acct) * 256 - offset;
+               *eof = 1;
+       }
+
+       offset /= sizeof(u32);
+
+       if (length > 0) {
+               u32 *dst = (u32 *) buffer;
+
+               *start = buffer;
+               memset(dst, 0, length);
+
+               for_each_possible_cpu(i) {
+                       unsigned int j;
+                       u32 *src;
+
+                       src = ((u32 *) per_cpu_ptr(ip_rt_acct, i)) + offset;
+                       for (j = 0; j < length/4; j++)
+                               dst[j] += src[j];
+               }
+       }
+       return length;
+}
+#endif
+
+static int __net_init ip_rt_do_proc_init(struct net *net)
+{
+       struct proc_dir_entry *pde;
+
+       pde = proc_net_fops_create(net, "rt_cache", S_IRUGO,
+                       &rt_cache_seq_fops);
+       if (!pde)
+               goto err1;
+
+       pde = proc_create("rt_cache", S_IRUGO,
+                         net->proc_net_stat, &rt_cpu_seq_fops);
+       if (!pde)
+               goto err2;
+
+#ifdef CONFIG_NET_CLS_ROUTE
+       pde = create_proc_read_entry("rt_acct", 0, net->proc_net,
+                       ip_rt_acct_read, NULL);
+       if (!pde)
+               goto err3;
+#endif
+       return 0;
+
+#ifdef CONFIG_NET_CLS_ROUTE
+err3:
+       remove_proc_entry("rt_cache", net->proc_net_stat);
+#endif
+err2:
+       remove_proc_entry("rt_cache", net->proc_net);
+err1:
+       return -ENOMEM;
+}
+
+static void __net_exit ip_rt_do_proc_exit(struct net *net)
+{
+       remove_proc_entry("rt_cache", net->proc_net_stat);
+       remove_proc_entry("rt_cache", net->proc_net);
+       remove_proc_entry("rt_acct", net->proc_net);
+}
+
+static struct pernet_operations ip_rt_proc_ops __net_initdata =  {
+       .init = ip_rt_do_proc_init,
+       .exit = ip_rt_do_proc_exit,
+};
+
+static int __init ip_rt_proc_init(void)
+{
+       return register_pernet_subsys(&ip_rt_proc_ops);
+}
+
+#else
+static inline int ip_rt_proc_init(void)
+{
+       return 0;
+}
 #endif /* CONFIG_PROC_FS */
-  
+
 static __inline__ void rt_free(struct rtable *rt)
 {
-       multipath_remove(rt);
        call_rcu_bh(&rt->u.dst.rcu_head, dst_rcu_free);
 }
 
 static __inline__ void rt_drop(struct rtable *rt)
 {
-       multipath_remove(rt);
        ip_rt_put(rt);
        call_rcu_bh(&rt->u.dst.rcu_head, dst_rcu_free);
 }
@@ -512,7 +616,7 @@ static __inline__ int rt_fast_clean(struct rtable *rth)
        /* Kill broadcast/multicast entries very aggresively, if they
           collide in hash table with more useful entries */
        return (rth->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST)) &&
-               rth->fl.iif && rth->u.rt_next;
+               rth->fl.iif && rth->u.dst.rt_next;
 }
 
 static __inline__ int rt_valuable(struct rtable *rth)
@@ -566,199 +670,144 @@ static inline u32 rt_score(struct rtable *rt)
 
 static inline int compare_keys(struct flowi *fl1, struct flowi *fl2)
 {
-       return memcmp(&fl1->nl_u.ip4_u, &fl2->nl_u.ip4_u, sizeof(fl1->nl_u.ip4_u)) == 0 &&
-              fl1->oif     == fl2->oif &&
-              fl1->iif     == fl2->iif;
+       return ((__force u32)((fl1->nl_u.ip4_u.daddr ^ fl2->nl_u.ip4_u.daddr) |
+               (fl1->nl_u.ip4_u.saddr ^ fl2->nl_u.ip4_u.saddr)) |
+               (fl1->mark ^ fl2->mark) |
+               (*(u16 *)&fl1->nl_u.ip4_u.tos ^
+                *(u16 *)&fl2->nl_u.ip4_u.tos) |
+               (fl1->oif ^ fl2->oif) |
+               (fl1->iif ^ fl2->iif)) == 0;
 }
 
-#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
-static struct rtable **rt_remove_balanced_route(struct rtable **chain_head,
-                                               struct rtable *expentry,
-                                               int *removed_count)
+static inline int compare_netns(struct rtable *rt1, struct rtable *rt2)
 {
-       int passedexpired = 0;
-       struct rtable **nextstep = NULL;
-       struct rtable **rthp = chain_head;
-       struct rtable *rth;
+       return dev_net(rt1->u.dst.dev) == dev_net(rt2->u.dst.dev);
+}
 
-       if (removed_count)
-               *removed_count = 0;
+/*
+ * Perform a full scan of hash table and free all entries.
+ * Can be called by a softirq or a process.
+ * In the later case, we want to be reschedule if necessary
+ */
+static void rt_do_flush(int process_context)
+{
+       unsigned int i;
+       struct rtable *rth, *next;
 
-       while ((rth = *rthp) != NULL) {
-               if (rth == expentry)
-                       passedexpired = 1;
+       for (i = 0; i <= rt_hash_mask; i++) {
+               if (process_context && need_resched())
+                       cond_resched();
+               rth = rt_hash_table[i].chain;
+               if (!rth)
+                       continue;
 
-               if (((*rthp)->u.dst.flags & DST_BALANCED) != 0  &&
-                   compare_keys(&(*rthp)->fl, &expentry->fl)) {
-                       if (*rthp == expentry) {
-                               *rthp = rth->u.rt_next;
-                               continue;
-                       } else {
-                               *rthp = rth->u.rt_next;
-                               rt_free(rth);
-                               if (removed_count)
-                                       ++(*removed_count);
-                       }
-               } else {
-                       if (!((*rthp)->u.dst.flags & DST_BALANCED) &&
-                           passedexpired && !nextstep)
-                               nextstep = &rth->u.rt_next;
+               spin_lock_bh(rt_hash_lock_addr(i));
+               rth = rt_hash_table[i].chain;
+               rt_hash_table[i].chain = NULL;
+               spin_unlock_bh(rt_hash_lock_addr(i));
 
-                       rthp = &rth->u.rt_next;
+               for (; rth; rth = next) {
+                       next = rth->u.dst.rt_next;
+                       rt_free(rth);
                }
        }
-
-       rt_free(expentry);
-       if (removed_count)
-               ++(*removed_count);
-
-       return nextstep;
 }
-#endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
 
-
-/* This runs via a timer and thus is always in BH context. */
-static void rt_check_expire(unsigned long dummy)
+static void rt_check_expire(void)
 {
        static unsigned int rover;
        unsigned int i = rover, goal;
        struct rtable *rth, **rthp;
-       unsigned long now = jiffies;
        u64 mult;
 
        mult = ((u64)ip_rt_gc_interval) << rt_hash_log;
        if (ip_rt_gc_timeout > 1)
                do_div(mult, ip_rt_gc_timeout);
        goal = (unsigned int)mult;
-       if (goal > rt_hash_mask) goal = rt_hash_mask + 1;
+       if (goal > rt_hash_mask)
+               goal = rt_hash_mask + 1;
        for (; goal > 0; goal--) {
                unsigned long tmo = ip_rt_gc_timeout;
 
                i = (i + 1) & rt_hash_mask;
                rthp = &rt_hash_table[i].chain;
 
-               if (*rthp == 0)
+               if (need_resched())
+                       cond_resched();
+
+               if (*rthp == NULL)
                        continue;
-               spin_lock(rt_hash_lock_addr(i));
+               spin_lock_bh(rt_hash_lock_addr(i));
                while ((rth = *rthp) != NULL) {
+                       if (rth->rt_genid != atomic_read(&rt_genid)) {
+                               *rthp = rth->u.dst.rt_next;
+                               rt_free(rth);
+                               continue;
+                       }
                        if (rth->u.dst.expires) {
                                /* Entry is expired even if it is in use */
-                               if (time_before_eq(now, rth->u.dst.expires)) {
+                               if (time_before_eq(jiffies, rth->u.dst.expires)) {
                                        tmo >>= 1;
-                                       rthp = &rth->u.rt_next;
+                                       rthp = &rth->u.dst.rt_next;
                                        continue;
                                }
                        } else if (!rt_may_expire(rth, tmo, ip_rt_gc_timeout)) {
                                tmo >>= 1;
-                               rthp = &rth->u.rt_next;
+                               rthp = &rth->u.dst.rt_next;
                                continue;
                        }
 
                        /* Cleanup aged off entries. */
-#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
-                       /* remove all related balanced entries if necessary */
-                       if (rth->u.dst.flags & DST_BALANCED) {
-                               rthp = rt_remove_balanced_route(
-                                       &rt_hash_table[i].chain,
-                                       rth, NULL);
-                               if (!rthp)
-                                       break;
-                       } else {
-                               *rthp = rth->u.rt_next;
-                               rt_free(rth);
-                       }
-#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
-                       *rthp = rth->u.rt_next;
-                       rt_free(rth);
-#endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
+                       *rthp = rth->u.dst.rt_next;
+                       rt_free(rth);
                }
-               spin_unlock(rt_hash_lock_addr(i));
-
-               /* Fallback loop breaker. */
-               if (time_after(jiffies, now))
-                       break;
+               spin_unlock_bh(rt_hash_lock_addr(i));
        }
        rover = i;
-       mod_timer(&rt_periodic_timer, jiffies + ip_rt_gc_interval);
 }
 
-/* This can run from both BH and non-BH contexts, the latter
- * in the case of a forced flush event.
+/*
+ * rt_worker_func() is run in process context.
+ * we call rt_check_expire() to scan part of the hash table
  */
-static void rt_run_flush(unsigned long dummy)
+static void rt_worker_func(struct work_struct *work)
 {
-       int i;
-       struct rtable *rth, *next;
-
-       rt_deadline = 0;
-
-       get_random_bytes(&rt_hash_rnd, 4);
+       rt_check_expire();
+       schedule_delayed_work(&expires_work, ip_rt_gc_interval);
+}
 
-       for (i = rt_hash_mask; i >= 0; i--) {
-               spin_lock_bh(rt_hash_lock_addr(i));
-               rth = rt_hash_table[i].chain;
-               if (rth)
-                       rt_hash_table[i].chain = NULL;
-               spin_unlock_bh(rt_hash_lock_addr(i));
+/*
+ * Pertubation of rt_genid by a small quantity [1..256]
+ * Using 8 bits of shuffling ensure we can call rt_cache_invalidate()
+ * many times (2^24) without giving recent rt_genid.
+ * Jenkins hash is strong enough that litle changes of rt_genid are OK.
+ */
+static void rt_cache_invalidate(void)
+{
+       unsigned char shuffle;
 
-               for (; rth; rth = next) {
-                       next = rth->u.rt_next;
-                       rt_free(rth);
-               }
-       }
+       get_random_bytes(&shuffle, sizeof(shuffle));
+       atomic_add(shuffle + 1U, &rt_genid);
 }
 
-static DEFINE_SPINLOCK(rt_flush_lock);
-
+/*
+ * delay < 0  : invalidate cache (fast : entries will be deleted later)
+ * delay >= 0 : invalidate & flush cache (can be long)
+ */
 void rt_cache_flush(int delay)
 {
-       unsigned long now = jiffies;
-       int user_mode = !in_softirq();
-
-       if (delay < 0)
-               delay = ip_rt_min_delay;
-
-       /* flush existing multipath state*/
-       multipath_flush();
-
-       spin_lock_bh(&rt_flush_lock);
-
-       if (del_timer(&rt_flush_timer) && delay > 0 && rt_deadline) {
-               long tmo = (long)(rt_deadline - now);
-
-               /* If flush timer is already running
-                  and flush request is not immediate (delay > 0):
-
-                  if deadline is not achieved, prolongate timer to "delay",
-                  otherwise fire it at deadline time.
-                */
-
-               if (user_mode && tmo < ip_rt_max_delay-ip_rt_min_delay)
-                       tmo = 0;
-               
-               if (delay > tmo)
-                       delay = tmo;
-       }
-
-       if (delay <= 0) {
-               spin_unlock_bh(&rt_flush_lock);
-               rt_run_flush(0);
-               return;
-       }
-
-       if (rt_deadline == 0)
-               rt_deadline = now + ip_rt_max_delay;
-
-       mod_timer(&rt_flush_timer, now+delay);
-       spin_unlock_bh(&rt_flush_lock);
+       rt_cache_invalidate();
+       if (delay >= 0)
+               rt_do_flush(!in_softirq());
 }
 
+/*
+ * We change rt_genid and let gc do the cleanup
+ */
 static void rt_secret_rebuild(unsigned long dummy)
 {
-       unsigned long now = jiffies;
-
-       rt_cache_flush(0);
-       mod_timer(&rt_secret_timer, now + ip_rt_secret_interval);
+       rt_cache_invalidate();
+       mod_timer(&rt_secret_timer, jiffies + ip_rt_secret_interval);
 }
 
 /*
@@ -774,7 +823,7 @@ static void rt_secret_rebuild(unsigned long dummy)
    and when load increases it reduces to limit cache size.
  */
 
-static int rt_garbage_collect(void)
+static int rt_garbage_collect(struct dst_ops *ops)
 {
        static unsigned long expire = RT_GC_TIMEOUT;
        static unsigned long last_gc;
@@ -805,14 +854,14 @@ static int rt_garbage_collect(void)
                        equilibrium = ipv4_dst_ops.gc_thresh;
                goal = atomic_read(&ipv4_dst_ops.entries) - equilibrium;
                if (goal > 0) {
-                       equilibrium += min_t(unsigned int, goal / 2, rt_hash_mask + 1);
+                       equilibrium += min_t(unsigned int, goal >> 1, rt_hash_mask + 1);
                        goal = atomic_read(&ipv4_dst_ops.entries) - equilibrium;
                }
        } else {
                /* We are in dangerous area. Try to reduce cache really
                 * aggressively.
                 */
-               goal = max_t(unsigned int, goal / 2, rt_hash_mask + 1);
+               goal = max_t(unsigned int, goal >> 1, rt_hash_mask + 1);
                equilibrium = atomic_read(&ipv4_dst_ops.entries) - goal;
        }
 
@@ -834,35 +883,15 @@ static int rt_garbage_collect(void)
                        rthp = &rt_hash_table[k].chain;
                        spin_lock_bh(rt_hash_lock_addr(k));
                        while ((rth = *rthp) != NULL) {
-                               if (!rt_may_expire(rth, tmo, expire)) {
+                               if (rth->rt_genid == atomic_read(&rt_genid) &&
+                                       !rt_may_expire(rth, tmo, expire)) {
                                        tmo >>= 1;
-                                       rthp = &rth->u.rt_next;
+                                       rthp = &rth->u.dst.rt_next;
                                        continue;
                                }
-#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
-                               /* remove all related balanced entries
-                                * if necessary
-                                */
-                               if (rth->u.dst.flags & DST_BALANCED) {
-                                       int r;
-
-                                       rthp = rt_remove_balanced_route(
-                                               &rt_hash_table[k].chain,
-                                               rth,
-                                               &r);
-                                       goal -= r;
-                                       if (!rthp)
-                                               break;
-                               } else {
-                                       *rthp = rth->u.rt_next;
-                                       rt_free(rth);
-                                       goal--;
-                               }
-#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
-                               *rthp = rth->u.rt_next;
+                               *rthp = rth->u.dst.rt_next;
                                rt_free(rth);
                                goal--;
-#endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
                        }
                        spin_unlock_bh(rt_hash_lock_addr(k));
                        if (goal <= 0)
@@ -936,20 +965,20 @@ restart:
 
        spin_lock_bh(rt_hash_lock_addr(hash));
        while ((rth = *rthp) != NULL) {
-#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
-               if (!(rth->u.dst.flags & DST_BALANCED) &&
-                   compare_keys(&rth->fl, &rt->fl)) {
-#else
-               if (compare_keys(&rth->fl, &rt->fl)) {
-#endif
+               if (rth->rt_genid != atomic_read(&rt_genid)) {
+                       *rthp = rth->u.dst.rt_next;
+                       rt_free(rth);
+                       continue;
+               }
+               if (compare_keys(&rth->fl, &rt->fl) && compare_netns(rth, rt)) {
                        /* Put it first */
-                       *rthp = rth->u.rt_next;
+                       *rthp = rth->u.dst.rt_next;
                        /*
                         * Since lookup is lockfree, the deletion
                         * must be visible to another weakly ordered CPU before
                         * the insertion at the start of the hash chain.
                         */
-                       rcu_assign_pointer(rth->u.rt_next,
+                       rcu_assign_pointer(rth->u.dst.rt_next,
                                           rt_hash_table[hash].chain);
                        /*
                         * Since lookup is lockfree, the update writes
@@ -957,9 +986,7 @@ restart:
                         */
                        rcu_assign_pointer(rt_hash_table[hash].chain, rth);
 
-                       rth->u.dst.__use++;
-                       dst_hold(&rth->u.dst);
-                       rth->u.dst.lastuse = now;
+                       dst_use(&rth->u.dst, now);
                        spin_unlock_bh(rt_hash_lock_addr(hash));
 
                        rt_drop(rt);
@@ -979,7 +1006,7 @@ restart:
 
                chain_length++;
 
-               rthp = &rth->u.rt_next;
+               rthp = &rth->u.dst.rt_next;
        }
 
        if (cand) {
@@ -990,7 +1017,7 @@ restart:
                 * only 2 entries per bucket. We will see.
                 */
                if (chain_length > ip_rt_gc_elasticity) {
-                       *candp = cand->u.rt_next;
+                       *candp = cand->u.dst.rt_next;
                        rt_free(cand);
                }
        }
@@ -1017,7 +1044,7 @@ restart:
                                int saved_int = ip_rt_gc_min_interval;
                                ip_rt_gc_elasticity     = 1;
                                ip_rt_gc_min_interval   = 0;
-                               rt_garbage_collect();
+                               rt_garbage_collect(&ipv4_dst_ops);
                                ip_rt_gc_min_interval   = saved_int;
                                ip_rt_gc_elasticity     = saved_elasticity;
                                goto restart;
@@ -1030,13 +1057,13 @@ restart:
                }
        }
 
-       rt->u.rt_next = rt_hash_table[hash].chain;
+       rt->u.dst.rt_next = rt_hash_table[hash].chain;
 #if RT_CACHE_DEBUG >= 2
-       if (rt->u.rt_next) {
+       if (rt->u.dst.rt_next) {
                struct rtable *trt;
                printk(KERN_DEBUG "rt_cache @%02x: %u.%u.%u.%u", hash,
                       NIPQUAD(rt->rt_dst));
-               for (trt = rt->u.rt_next; trt; trt = trt->u.rt_next)
+               for (trt = rt->u.dst.rt_next; trt; trt = trt->u.dst.rt_next)
                        printk(" . %u.%u.%u.%u", NIPQUAD(trt->rt_dst));
                printk("\n");
        }
@@ -1100,7 +1127,7 @@ void __ip_select_ident(struct iphdr *iph, struct dst_entry *dst, int more)
                        return;
                }
        } else
-               printk(KERN_DEBUG "rt_bind_peer(0) @%p\n", 
+               printk(KERN_DEBUG "rt_bind_peer(0) @%p\n",
                       __builtin_return_address(0));
 
        ip_select_fb_ident(iph);
@@ -1108,17 +1135,19 @@ void __ip_select_ident(struct iphdr *iph, struct dst_entry *dst, int more)
 
 static void rt_del(unsigned hash, struct rtable *rt)
 {
-       struct rtable **rthp;
+       struct rtable **rthp, *aux;
 
+       rthp = &rt_hash_table[hash].chain;
        spin_lock_bh(rt_hash_lock_addr(hash));
        ip_rt_put(rt);
-       for (rthp = &rt_hash_table[hash].chain; *rthp;
-            rthp = &(*rthp)->u.rt_next)
-               if (*rthp == rt) {
-                       *rthp = rt->u.rt_next;
-                       rt_free(rt);
-                       break;
+       while ((aux = *rthp) != NULL) {
+               if (aux == rt || (aux->rt_genid != atomic_read(&rt_genid))) {
+                       *rthp = aux->u.dst.rt_next;
+                       rt_free(aux);
+                       continue;
                }
+               rthp = &aux->u.dst.rt_next;
+       }
        spin_unlock_bh(rt_hash_lock_addr(hash));
 }
 
@@ -1131,12 +1160,15 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
        __be32  skeys[2] = { saddr, 0 };
        int  ikeys[2] = { dev->ifindex, 0 };
        struct netevent_redirect netevent;
+       struct net *net;
 
        if (!in_dev)
                return;
 
+       net = dev_net(dev);
        if (new_gw == old_gw || !IN_DEV_RX_REDIRECTS(in_dev)
-           || MULTICAST(new_gw) || BADCLASS(new_gw) || ZERONET(new_gw))
+           || ipv4_is_multicast(new_gw) || ipv4_is_lbcast(new_gw)
+           || ipv4_is_zeronet(new_gw))
                goto reject_redirect;
 
        if (!IN_DEV_SHARED_MEDIA(in_dev)) {
@@ -1145,7 +1177,7 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
                if (IN_DEV_SEC_REDIRECTS(in_dev) && ip_fib_check_default(new_gw, dev))
                        goto reject_redirect;
        } else {
-               if (inet_addr_type(new_gw) != RTN_UNICAST)
+               if (inet_addr_type(net, new_gw) != RTN_UNICAST)
                        goto reject_redirect;
        }
 
@@ -1162,8 +1194,10 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
                                if (rth->fl.fl4_dst != daddr ||
                                    rth->fl.fl4_src != skeys[i] ||
                                    rth->fl.oif != ikeys[k] ||
-                                   rth->fl.iif != 0) {
-                                       rthp = &rth->u.rt_next;
+                                   rth->fl.iif != 0 ||
+                                   rth->rt_genid != atomic_read(&rt_genid) ||
+                                   dev_net(rth->u.dst.dev) != net) {
+                                       rthp = &rth->u.dst.rt_next;
                                        continue;
                                }
 
@@ -1186,7 +1220,7 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
 
                                /* Copy all the information. */
                                *rt = *rth;
-                               INIT_RCU_HEAD(&rt->u.dst.rcu_head);
+                               INIT_RCU_HEAD(&rt->u.dst.rcu_head);
                                rt->u.dst.__use         = 1;
                                atomic_set(&rt->u.dst.__refcnt, 1);
                                rt->u.dst.child         = NULL;
@@ -1200,7 +1234,7 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
                                rt->u.dst.neighbour     = NULL;
                                rt->u.dst.hh            = NULL;
                                rt->u.dst.xfrm          = NULL;
-
+                               rt->rt_genid            = atomic_read(&rt_genid);
                                rt->rt_flags            |= RTCF_REDIRECTED;
 
                                /* Gateway is different ... */
@@ -1221,11 +1255,11 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
                                        rt_drop(rt);
                                        goto do_next;
                                }
-                               
+
                                netevent.old = &rth->u.dst;
                                netevent.new = &rt->u.dst;
-                               call_netevent_notifiers(NETEVENT_REDIRECT, 
-                                                       &netevent);
+                               call_netevent_notifiers(NETEVENT_REDIRECT,
+                                                       &netevent);
 
                                rt_del(hash, rth);
                                if (!rt_intern_hash(hash, rt, &rt))
@@ -1254,7 +1288,7 @@ reject_redirect:
 
 static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst)
 {
-       struct rtable *rt = (struct rtable*)dst;
+       struct rtable *rt = (struct rtable *)dst;
        struct dst_entry *ret = dst;
 
        if (rt) {
@@ -1266,7 +1300,7 @@ static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst)
                        unsigned hash = rt_hash(rt->fl.fl4_dst, rt->fl.fl4_src,
                                                rt->fl.oif);
 #if RT_CACHE_DEBUG >= 1
-                       printk(KERN_DEBUG "ip_rt_advice: redirect to "
+                       printk(KERN_DEBUG "ipv4_negative_advice: redirect to "
                                          "%u.%u.%u.%u/%02x dropped\n",
                                NIPQUAD(rt->rt_dst), rt->fl.fl4_tos);
 #endif
@@ -1295,7 +1329,7 @@ static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst)
 
 void ip_rt_send_redirect(struct sk_buff *skb)
 {
-       struct rtable *rt = (struct rtable*)skb->dst;
+       struct rtable *rt = skb->rtable;
        struct in_device *in_dev = in_dev_get(rt->u.dst.dev);
 
        if (!in_dev)
@@ -1321,7 +1355,8 @@ void ip_rt_send_redirect(struct sk_buff *skb)
        /* Check for load limit; set rate_last to the latest sent
         * redirect.
         */
-       if (time_after(jiffies,
+       if (rt->u.dst.rate_tokens == 0 ||
+           time_after(jiffies,
                       (rt->u.dst.rate_last +
                        (ip_rt_redirect_load << rt->u.dst.rate_tokens)))) {
                icmp_send(skb, ICMP_REDIRECT, ICMP_REDIR_HOST, rt->rt_gateway);
@@ -1338,12 +1373,12 @@ void ip_rt_send_redirect(struct sk_buff *skb)
 #endif
        }
 out:
-        in_dev_put(in_dev);
+       in_dev_put(in_dev);
 }
 
 static int ip_error(struct sk_buff *skb)
 {
-       struct rtable *rt = (struct rtable*)skb->dst;
+       struct rtable *rt = skb->rtable;
        unsigned long now;
        int code;
 
@@ -1356,6 +1391,7 @@ static int ip_error(struct sk_buff *skb)
                        break;
                case ENETUNREACH:
                        code = ICMP_NET_UNREACH;
+                       IP_INC_STATS_BH(IPSTATS_MIB_INNOROUTES);
                        break;
                case EACCES:
                        code = ICMP_PKT_FILTERED;
@@ -1374,7 +1410,7 @@ static int ip_error(struct sk_buff *skb)
 
 out:   kfree_skb(skb);
        return 0;
-} 
+}
 
 /*
  *     The last two values are not from the RFC but
@@ -1387,14 +1423,15 @@ static const unsigned short mtu_plateau[] =
 static __inline__ unsigned short guess_mtu(unsigned short old_mtu)
 {
        int i;
-       
+
        for (i = 0; i < ARRAY_SIZE(mtu_plateau); i++)
                if (old_mtu > mtu_plateau[i])
                        return mtu_plateau[i];
        return 68;
 }
 
-unsigned short ip_rt_frag_needed(struct iphdr *iph, unsigned short new_mtu)
+unsigned short ip_rt_frag_needed(struct net *net, struct iphdr *iph,
+                                unsigned short new_mtu)
 {
        int i;
        unsigned short old_mtu = ntohs(iph->tot_len);
@@ -1411,13 +1448,15 @@ unsigned short ip_rt_frag_needed(struct iphdr *iph, unsigned short new_mtu)
 
                rcu_read_lock();
                for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
-                    rth = rcu_dereference(rth->u.rt_next)) {
+                    rth = rcu_dereference(rth->u.dst.rt_next)) {
                        if (rth->fl.fl4_dst == daddr &&
                            rth->fl.fl4_src == skeys[i] &&
                            rth->rt_dst  == daddr &&
                            rth->rt_src  == iph->saddr &&
                            rth->fl.iif == 0 &&
-                           !(dst_metric_locked(&rth->u.dst, RTAX_MTU))) {
+                           !(dst_metric_locked(&rth->u.dst, RTAX_MTU)) &&
+                           dev_net(rth->u.dst.dev) == net &&
+                           rth->rt_genid == atomic_read(&rt_genid)) {
                                unsigned short mtu = new_mtu;
 
                                if (new_mtu < 68 || new_mtu >= old_mtu) {
@@ -1431,7 +1470,7 @@ unsigned short ip_rt_frag_needed(struct iphdr *iph, unsigned short new_mtu)
                                        mtu = guess_mtu(old_mtu);
                                }
                                if (mtu <= rth->u.dst.metrics[RTAX_MTU-1]) {
-                                       if (mtu < rth->u.dst.metrics[RTAX_MTU-1]) { 
+                                       if (mtu < rth->u.dst.metrics[RTAX_MTU-1]) {
                                                dst_confirm(&rth->u.dst);
                                                if (mtu < ip_rt_min_pmtu) {
                                                        mtu = ip_rt_min_pmtu;
@@ -1492,8 +1531,9 @@ static void ipv4_dst_ifdown(struct dst_entry *dst, struct net_device *dev,
 {
        struct rtable *rt = (struct rtable *) dst;
        struct in_device *idev = rt->idev;
-       if (dev != &loopback_dev && idev && idev->dev == dev) {
-               struct in_device *loopback_idev = in_dev_get(&loopback_dev);
+       if (dev != dev_net(dev)->loopback_dev && idev && idev->dev == dev) {
+               struct in_device *loopback_idev =
+                       in_dev_get(dev_net(dev)->loopback_dev);
                if (loopback_idev) {
                        rt->idev = loopback_idev;
                        in_dev_put(idev);
@@ -1507,7 +1547,7 @@ static void ipv4_link_failure(struct sk_buff *skb)
 
        icmp_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0);
 
-       rt = (struct rtable *) skb->dst;
+       rt = skb->rtable;
        if (rt)
                dst_set_expires(&rt->u.dst, 0);
 }
@@ -1515,7 +1555,7 @@ static void ipv4_link_failure(struct sk_buff *skb)
 static int ip_rt_bug(struct sk_buff *skb)
 {
        printk(KERN_DEBUG "ip_rt_bug: %u.%u.%u.%u -> %u.%u.%u.%u, %s\n",
-               NIPQUAD(skb->nh.iph->saddr), NIPQUAD(skb->nh.iph->daddr),
+               NIPQUAD(ip_hdr(skb)->saddr), NIPQUAD(ip_hdr(skb)->daddr),
                skb->dev ? skb->dev->name : "?");
        kfree_skb(skb);
        return 0;
@@ -1537,7 +1577,7 @@ void ip_rt_get_source(u8 *addr, struct rtable *rt)
 
        if (rt->fl.iif == 0)
                src = rt->rt_src;
-       else if (fib_lookup(&rt->fl, &res) == 0) {
+       else if (fib_lookup(dev_net(rt->u.dst.dev), &rt->fl, &res) == 0) {
                src = FIB_RES_PREFSRC(res);
                fib_res_put(&res);
        } else
@@ -1595,7 +1635,7 @@ static void rt_set_nexthop(struct rtable *rt, struct fib_result *res, u32 itag)
 #endif
        set_class_tag(rt, itag);
 #endif
-        rt->rt_type = res->type;
+       rt->rt_type = res->type;
 }
 
 static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
@@ -1612,12 +1652,12 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
        if (in_dev == NULL)
                return -EINVAL;
 
-       if (MULTICAST(saddr) || BADCLASS(saddr) || LOOPBACK(saddr) ||
-           skb->protocol != htons(ETH_P_IP))
+       if (ipv4_is_multicast(saddr) || ipv4_is_lbcast(saddr) ||
+           ipv4_is_loopback(saddr) || skb->protocol != htons(ETH_P_IP))
                goto e_inval;
 
-       if (ZERONET(saddr)) {
-               if (!LOCAL_MCAST(daddr))
+       if (ipv4_is_zeronet(saddr)) {
+               if (!ipv4_is_local_multicast(daddr))
                        goto e_inval;
                spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK);
        } else if (fib_validate_source(saddr, 0, tos, 0,
@@ -1632,14 +1672,12 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
 
        atomic_set(&rth->u.dst.__refcnt, 1);
        rth->u.dst.flags= DST_HOST;
-       if (in_dev->cnf.no_policy)
+       if (IN_DEV_CONF_GET(in_dev, NOPOLICY))
                rth->u.dst.flags |= DST_NOPOLICY;
        rth->fl.fl4_dst = daddr;
        rth->rt_dst     = daddr;
        rth->fl.fl4_tos = tos;
-#ifdef CONFIG_IP_ROUTE_FWMARK
-       rth->fl.fl4_fwmark= skb->nfmark;
-#endif
+       rth->fl.mark    = skb->mark;
        rth->fl.fl4_src = saddr;
        rth->rt_src     = saddr;
 #ifdef CONFIG_NET_CLS_ROUTE
@@ -1647,28 +1685,29 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
 #endif
        rth->rt_iif     =
        rth->fl.iif     = dev->ifindex;
-       rth->u.dst.dev  = &loopback_dev;
+       rth->u.dst.dev  = init_net.loopback_dev;
        dev_hold(rth->u.dst.dev);
        rth->idev       = in_dev_get(rth->u.dst.dev);
        rth->fl.oif     = 0;
        rth->rt_gateway = daddr;
        rth->rt_spec_dst= spec_dst;
-       rth->rt_type    = RTN_MULTICAST;
+       rth->rt_genid   = atomic_read(&rt_genid);
        rth->rt_flags   = RTCF_MULTICAST;
+       rth->rt_type    = RTN_MULTICAST;
        if (our) {
                rth->u.dst.input= ip_local_deliver;
                rth->rt_flags |= RTCF_LOCAL;
        }
 
 #ifdef CONFIG_IP_MROUTE
-       if (!LOCAL_MCAST(daddr) && IN_DEV_MFORWARD(in_dev))
+       if (!ipv4_is_local_multicast(daddr) && IN_DEV_MFORWARD(in_dev))
                rth->u.dst.input = ip_mr_input;
 #endif
        RT_CACHE_STAT_INC(in_slow_mc);
 
        in_dev_put(in_dev);
        hash = rt_hash(daddr, saddr, dev->ifindex);
-       return rt_intern_hash(hash, rth, (struct rtable**) &skb->dst);
+       return rt_intern_hash(hash, rth, &skb->rtable);
 
 e_nobufs:
        in_dev_put(in_dev);
@@ -1696,9 +1735,9 @@ static void ip_handle_martian_source(struct net_device *dev,
                printk(KERN_WARNING "martian source %u.%u.%u.%u from "
                        "%u.%u.%u.%u, on dev %s\n",
                        NIPQUAD(daddr), NIPQUAD(saddr), dev->name);
-               if (dev->hard_header_len && skb->mac.raw) {
+               if (dev->hard_header_len && skb_mac_header_was_set(skb)) {
                        int i;
-                       unsigned char *p = skb->mac.raw;
+                       const unsigned char *p = skb_mac_header(skb);
                        printk(KERN_WARNING "ll header: ");
                        for (i = 0; i < dev->hard_header_len; i++, p++) {
                                printk("%02x", *p);
@@ -1711,11 +1750,11 @@ static void ip_handle_martian_source(struct net_device *dev,
 #endif
 }
 
-static inline int __mkroute_input(struct sk_buff *skb, 
-                                 struct fib_result* res, 
-                                 struct in_device *in_dev, 
+static inline int __mkroute_input(struct sk_buff *skb,
+                                 struct fib_result* res,
+                                 struct in_device *in_dev,
                                  __be32 daddr, __be32 saddr, u32 tos,
-                                 struct rtable **result) 
+                                 struct rtable **result)
 {
 
        struct rtable *rth;
@@ -1735,12 +1774,12 @@ static inline int __mkroute_input(struct sk_buff *skb,
        }
 
 
-       err = fib_validate_source(saddr, daddr, tos, FIB_RES_OIF(*res), 
+       err = fib_validate_source(saddr, daddr, tos, FIB_RES_OIF(*res),
                                  in_dev->dev, &spec_dst, &itag);
        if (err < 0) {
-               ip_handle_martian_source(in_dev->dev, in_dev, skb, daddr, 
+               ip_handle_martian_source(in_dev->dev, in_dev, skb, daddr,
                                         saddr);
-               
+
                err = -EINVAL;
                goto cleanup;
        }
@@ -1748,7 +1787,7 @@ static inline int __mkroute_input(struct sk_buff *skb,
        if (err)
                flags |= RTCF_DIRECTSRC;
 
-       if (out_dev == in_dev && err && !(flags & (RTCF_NAT | RTCF_MASQ)) &&
+       if (out_dev == in_dev && err && !(flags & RTCF_MASQ) &&
            (IN_DEV_SHARED_MEDIA(out_dev) ||
             inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
                flags |= RTCF_DOREDIRECT;
@@ -1757,7 +1796,7 @@ static inline int __mkroute_input(struct sk_buff *skb,
                /* Not IP (i.e. ARP). Do not create route, if it is
                 * invalid for proxy arp. DNAT routes are always valid.
                 */
-               if (out_dev == in_dev && !(flags & RTCF_DNAT)) {
+               if (out_dev == in_dev) {
                        err = -EINVAL;
                        goto cleanup;
                }
@@ -1772,20 +1811,14 @@ static inline int __mkroute_input(struct sk_buff *skb,
 
        atomic_set(&rth->u.dst.__refcnt, 1);
        rth->u.dst.flags= DST_HOST;
-#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
-       if (res->fi->fib_nhs > 1)
-               rth->u.dst.flags |= DST_BALANCED;
-#endif
-       if (in_dev->cnf.no_policy)
+       if (IN_DEV_CONF_GET(in_dev, NOPOLICY))
                rth->u.dst.flags |= DST_NOPOLICY;
-       if (in_dev->cnf.no_xfrm)
+       if (IN_DEV_CONF_GET(out_dev, NOXFRM))
                rth->u.dst.flags |= DST_NOXFRM;
        rth->fl.fl4_dst = daddr;
        rth->rt_dst     = daddr;
        rth->fl.fl4_tos = tos;
-#ifdef CONFIG_IP_ROUTE_FWMARK
-       rth->fl.fl4_fwmark= skb->nfmark;
-#endif
+       rth->fl.mark    = skb->mark;
        rth->fl.fl4_src = saddr;
        rth->rt_src     = saddr;
        rth->rt_gateway = daddr;
@@ -1799,6 +1832,7 @@ static inline int __mkroute_input(struct sk_buff *skb,
 
        rth->u.dst.input = ip_forward;
        rth->u.dst.output = ip_output;
+       rth->rt_genid = atomic_read(&rt_genid);
 
        rt_set_nexthop(rth, res, itag);
 
@@ -1810,13 +1844,13 @@ static inline int __mkroute_input(struct sk_buff *skb,
        /* release the working reference to the output device */
        in_dev_put(out_dev);
        return err;
-}                                              
+}
 
-static inline int ip_mkroute_input_def(struct sk_buff *skb, 
-                                      struct fib_result* res, 
-                                      const struct flowi *fl,
-                                      struct in_device *in_dev,
-                                      __be32 daddr, __be32 saddr, u32 tos)
+static inline int ip_mkroute_input(struct sk_buff *skb,
+                                  struct fib_result* res,
+                                  const struct flowi *fl,
+                                  struct in_device *in_dev,
+                                  __be32 daddr, __be32 saddr, u32 tos)
 {
        struct rtable* rth = NULL;
        int err;
@@ -1834,66 +1868,9 @@ static inline int ip_mkroute_input_def(struct sk_buff *skb,
 
        /* put it into the cache */
        hash = rt_hash(daddr, saddr, fl->iif);
-       return rt_intern_hash(hash, rth, (struct rtable**)&skb->dst);   
-}
-
-static inline int ip_mkroute_input(struct sk_buff *skb, 
-                                  struct fib_result* res, 
-                                  const struct flowi *fl,
-                                  struct in_device *in_dev,
-                                  __be32 daddr, __be32 saddr, u32 tos)
-{
-#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
-       struct rtable* rth = NULL, *rtres;
-       unsigned char hop, hopcount;
-       int err = -EINVAL;
-       unsigned int hash;
-
-       if (res->fi)
-               hopcount = res->fi->fib_nhs;
-       else
-               hopcount = 1;
-
-       /* distinguish between multipath and singlepath */
-       if (hopcount < 2)
-               return ip_mkroute_input_def(skb, res, fl, in_dev, daddr,
-                                           saddr, tos);
-       
-       /* add all alternatives to the routing cache */
-       for (hop = 0; hop < hopcount; hop++) {
-               res->nh_sel = hop;
-
-               /* put reference to previous result */
-               if (hop)
-                       ip_rt_put(rtres);
-
-               /* create a routing cache entry */
-               err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos,
-                                     &rth);
-               if (err)
-                       return err;
-
-               /* put it into the cache */
-               hash = rt_hash(daddr, saddr, fl->iif);
-               err = rt_intern_hash(hash, rth, &rtres);
-               if (err)
-                       return err;
-
-               /* forward hop information to multipath impl. */
-               multipath_set_nhinfo(rth,
-                                    FIB_RES_NETWORK(*res),
-                                    FIB_RES_NETMASK(*res),
-                                    res->prefixlen,
-                                    &FIB_RES_NH(*res));
-       }
-       skb->dst = &rtres->u.dst;
-       return err;
-#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED  */
-       return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos);
-#endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED  */
+       return rt_intern_hash(hash, rth, &skb->rtable);
 }
 
-
 /*
  *     NOTE. We drop all the packets that has local source
  *     addresses, because every properly looped back packet
@@ -1914,10 +1891,8 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
                                        .saddr = saddr,
                                        .tos = tos,
                                        .scope = RT_SCOPE_UNIVERSE,
-#ifdef CONFIG_IP_ROUTE_FWMARK
-                                       .fwmark = skb->nfmark
-#endif
                                      } },
+                           .mark = skb->mark,
                            .iif = dev->ifindex };
        unsigned        flags = 0;
        u32             itag = 0;
@@ -1926,6 +1901,7 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
        __be32          spec_dst;
        int             err = -EINVAL;
        int             free_res = 0;
+       struct net    * net = dev_net(dev);
 
        /* IP on this device is disabled. */
 
@@ -1936,7 +1912,8 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
           by fib_lookup.
         */
 
-       if (MULTICAST(saddr) || BADCLASS(saddr) || LOOPBACK(saddr))
+       if (ipv4_is_multicast(saddr) || ipv4_is_lbcast(saddr) ||
+           ipv4_is_loopback(saddr))
                goto martian_source;
 
        if (daddr == htonl(0xFFFFFFFF) || (saddr == 0 && daddr == 0))
@@ -1945,16 +1922,17 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
        /* Accept zero addresses only to limited broadcast;
         * I even do not know to fix it or not. Waiting for complains :-)
         */
-       if (ZERONET(saddr))
+       if (ipv4_is_zeronet(saddr))
                goto martian_source;
 
-       if (BADCLASS(daddr) || ZERONET(daddr) || LOOPBACK(daddr))
+       if (ipv4_is_lbcast(daddr) || ipv4_is_zeronet(daddr) ||
+           ipv4_is_loopback(daddr))
                goto martian_destination;
 
        /*
         *      Now we are ready to route packet.
         */
-       if ((err = fib_lookup(&fl, &res)) != 0) {
+       if ((err = fib_lookup(net, &fl, &res)) != 0) {
                if (!IN_DEV_FORWARD(in_dev))
                        goto e_hostunreach;
                goto no_route;
@@ -1969,7 +1947,7 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
        if (res.type == RTN_LOCAL) {
                int result;
                result = fib_validate_source(saddr, daddr, tos,
-                                            loopback_dev.ifindex,
+                                            net->loopback_dev->ifindex,
                                             dev, &spec_dst, &itag);
                if (result < 0)
                        goto martian_source;
@@ -1985,11 +1963,6 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
                goto martian_destination;
 
        err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos);
-       if (err == -ENOBUFS)
-               goto e_nobufs;
-       if (err == -EINVAL)
-               goto e_inval;
-       
 done:
        in_dev_put(in_dev);
        if (free_res)
@@ -2000,7 +1973,7 @@ brd_input:
        if (skb->protocol != htons(ETH_P_IP))
                goto e_inval;
 
-       if (ZERONET(saddr))
+       if (ipv4_is_zeronet(saddr))
                spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK);
        else {
                err = fib_validate_source(saddr, 0, tos, 0, dev, &spec_dst,
@@ -2020,17 +1993,16 @@ local_input:
                goto e_nobufs;
 
        rth->u.dst.output= ip_rt_bug;
+       rth->rt_genid = atomic_read(&rt_genid);
 
        atomic_set(&rth->u.dst.__refcnt, 1);
        rth->u.dst.flags= DST_HOST;
-       if (in_dev->cnf.no_policy)
+       if (IN_DEV_CONF_GET(in_dev, NOPOLICY))
                rth->u.dst.flags |= DST_NOPOLICY;
        rth->fl.fl4_dst = daddr;
        rth->rt_dst     = daddr;
        rth->fl.fl4_tos = tos;
-#ifdef CONFIG_IP_ROUTE_FWMARK
-       rth->fl.fl4_fwmark= skb->nfmark;
-#endif
+       rth->fl.mark    = skb->mark;
        rth->fl.fl4_src = saddr;
        rth->rt_src     = saddr;
 #ifdef CONFIG_NET_CLS_ROUTE
@@ -2038,7 +2010,7 @@ local_input:
 #endif
        rth->rt_iif     =
        rth->fl.iif     = dev->ifindex;
-       rth->u.dst.dev  = &loopback_dev;
+       rth->u.dst.dev  = net->loopback_dev;
        dev_hold(rth->u.dst.dev);
        rth->idev       = in_dev_get(rth->u.dst.dev);
        rth->rt_gateway = daddr;
@@ -2052,13 +2024,15 @@ local_input:
        }
        rth->rt_type    = res.type;
        hash = rt_hash(daddr, saddr, fl.iif);
-       err = rt_intern_hash(hash, rth, (struct rtable**)&skb->dst);
+       err = rt_intern_hash(hash, rth, &skb->rtable);
        goto done;
 
 no_route:
        RT_CACHE_STAT_INC(in_no_route);
        spec_dst = inet_select_addr(dev, 0, RT_SCOPE_UNIVERSE);
        res.type = RTN_UNREACHABLE;
+       if (err == -ESRCH)
+               err = -ENETUNREACH;
        goto local_input;
 
        /*
@@ -2074,8 +2048,8 @@ martian_destination:
 #endif
 
 e_hostunreach:
-        err = -EHOSTUNREACH;
-        goto done;
+       err = -EHOSTUNREACH;
+       goto done;
 
 e_inval:
        err = -EINVAL;
@@ -2096,27 +2070,27 @@ int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
        struct rtable * rth;
        unsigned        hash;
        int iif = dev->ifindex;
+       struct net *net;
 
+       net = dev_net(dev);
        tos &= IPTOS_RT_MASK;
        hash = rt_hash(daddr, saddr, iif);
 
        rcu_read_lock();
        for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
-            rth = rcu_dereference(rth->u.rt_next)) {
+            rth = rcu_dereference(rth->u.dst.rt_next)) {
                if (rth->fl.fl4_dst == daddr &&
                    rth->fl.fl4_src == saddr &&
                    rth->fl.iif == iif &&
                    rth->fl.oif == 0 &&
-#ifdef CONFIG_IP_ROUTE_FWMARK
-                   rth->fl.fl4_fwmark == skb->nfmark &&
-#endif
-                   rth->fl.fl4_tos == tos) {
-                       rth->u.dst.lastuse = jiffies;
-                       dst_hold(&rth->u.dst);
-                       rth->u.dst.__use++;
+                   rth->fl.mark == skb->mark &&
+                   rth->fl.fl4_tos == tos &&
+                   dev_net(rth->u.dst.dev) == net &&
+                   rth->rt_genid == atomic_read(&rt_genid)) {
+                       dst_use(&rth->u.dst, jiffies);
                        RT_CACHE_STAT_INC(in_hit);
                        rcu_read_unlock();
-                       skb->dst = (struct dst_entry*)rth;
+                       skb->rtable = rth;
                        return 0;
                }
                RT_CACHE_STAT_INC(in_hlist_search);
@@ -2134,16 +2108,17 @@ int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
           Note, that multicast routers are not affected, because
           route cache entry is created eventually.
         */
-       if (MULTICAST(daddr)) {
+       if (ipv4_is_multicast(daddr)) {
                struct in_device *in_dev;
 
                rcu_read_lock();
                if ((in_dev = __in_dev_get_rcu(dev)) != NULL) {
                        int our = ip_check_mc(in_dev, daddr, saddr,
-                               skb->nh.iph->protocol);
+                               ip_hdr(skb)->protocol);
                        if (our
 #ifdef CONFIG_IP_MROUTE
-                           || (!LOCAL_MCAST(daddr) && IN_DEV_MFORWARD(in_dev))
+                           || (!ipv4_is_local_multicast(daddr) &&
+                               IN_DEV_MFORWARD(in_dev))
 #endif
                            ) {
                                rcu_read_unlock();
@@ -2158,25 +2133,25 @@ int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
 }
 
 static inline int __mkroute_output(struct rtable **result,
-                                  struct fib_result* res, 
+                                  struct fib_result* res,
                                   const struct flowi *fl,
-                                  const struct flowi *oldflp, 
-                                  struct net_device *dev_out, 
-                                  unsigned flags) 
+                                  const struct flowi *oldflp,
+                                  struct net_device *dev_out,
+                                  unsigned flags)
 {
        struct rtable *rth;
        struct in_device *in_dev;
        u32 tos = RT_FL_TOS(oldflp);
        int err = 0;
 
-       if (LOOPBACK(fl->fl4_src) && !(dev_out->flags&IFF_LOOPBACK))
+       if (ipv4_is_loopback(fl->fl4_src) && !(dev_out->flags&IFF_LOOPBACK))
                return -EINVAL;
 
        if (fl->fl4_dst == htonl(0xFFFFFFFF))
                res->type = RTN_BROADCAST;
-       else if (MULTICAST(fl->fl4_dst))
+       else if (ipv4_is_multicast(fl->fl4_dst))
                res->type = RTN_MULTICAST;
-       else if (BADCLASS(fl->fl4_dst) || ZERONET(fl->fl4_dst))
+       else if (ipv4_is_lbcast(fl->fl4_dst) || ipv4_is_zeronet(fl->fl4_dst))
                return -EINVAL;
 
        if (dev_out->flags & IFF_LOOPBACK)
@@ -2195,7 +2170,7 @@ static inline int __mkroute_output(struct rtable **result,
                }
        } else if (res->type == RTN_MULTICAST) {
                flags |= RTCF_MULTICAST|RTCF_LOCAL;
-               if (!ip_check_mc(in_dev, oldflp->fl4_dst, oldflp->fl4_src, 
+               if (!ip_check_mc(in_dev, oldflp->fl4_dst, oldflp->fl4_src,
                                 oldflp->proto))
                        flags &= ~RTCF_LOCAL;
                /* If multicast route do not exist use
@@ -2213,33 +2188,24 @@ static inline int __mkroute_output(struct rtable **result,
        if (!rth) {
                err = -ENOBUFS;
                goto cleanup;
-       }               
+       }
 
        atomic_set(&rth->u.dst.__refcnt, 1);
        rth->u.dst.flags= DST_HOST;
-#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
-       if (res->fi) {
-               rth->rt_multipath_alg = res->fi->fib_mp_alg;
-               if (res->fi->fib_nhs > 1)
-                       rth->u.dst.flags |= DST_BALANCED;
-       }
-#endif
-       if (in_dev->cnf.no_xfrm)
+       if (IN_DEV_CONF_GET(in_dev, NOXFRM))
                rth->u.dst.flags |= DST_NOXFRM;
-       if (in_dev->cnf.no_policy)
+       if (IN_DEV_CONF_GET(in_dev, NOPOLICY))
                rth->u.dst.flags |= DST_NOPOLICY;
 
        rth->fl.fl4_dst = oldflp->fl4_dst;
        rth->fl.fl4_tos = tos;
        rth->fl.fl4_src = oldflp->fl4_src;
        rth->fl.oif     = oldflp->oif;
-#ifdef CONFIG_IP_ROUTE_FWMARK
-       rth->fl.fl4_fwmark= oldflp->fl4_fwmark;
-#endif
+       rth->fl.mark    = oldflp->mark;
        rth->rt_dst     = fl->fl4_dst;
        rth->rt_src     = fl->fl4_src;
        rth->rt_iif     = oldflp->oif ? : dev_out->ifindex;
-       /* get references to the devices that are to be hold by the routing 
+       /* get references to the devices that are to be hold by the routing
           cache entry */
        rth->u.dst.dev  = dev_out;
        dev_hold(dev_out);
@@ -2248,6 +2214,7 @@ static inline int __mkroute_output(struct rtable **result,
        rth->rt_spec_dst= fl->fl4_src;
 
        rth->u.dst.output=ip_output;
+       rth->rt_genid = atomic_read(&rt_genid);
 
        RT_CACHE_STAT_INC(out_slow_tot);
 
@@ -2257,7 +2224,7 @@ static inline int __mkroute_output(struct rtable **result,
        }
        if (flags & (RTCF_BROADCAST | RTCF_MULTICAST)) {
                rth->rt_spec_dst = fl->fl4_src;
-               if (flags & RTCF_LOCAL && 
+               if (flags & RTCF_LOCAL &&
                    !(dev_out->flags & IFF_LOOPBACK)) {
                        rth->u.dst.output = ip_mc_output;
                        RT_CACHE_STAT_INC(out_slow_mc);
@@ -2265,7 +2232,7 @@ static inline int __mkroute_output(struct rtable **result,
 #ifdef CONFIG_IP_MROUTE
                if (res->type == RTN_MULTICAST) {
                        if (IN_DEV_MFORWARD(in_dev) &&
-                           !LOCAL_MCAST(oldflp->fl4_dst)) {
+                           !ipv4_is_local_multicast(oldflp->fl4_dst)) {
                                rth->u.dst.input = ip_mr_input;
                                rth->u.dst.output = ip_mc_output;
                        }
@@ -2285,12 +2252,12 @@ static inline int __mkroute_output(struct rtable **result,
        return err;
 }
 
-static inline int ip_mkroute_output_def(struct rtable **rp,
-                                       struct fib_result* res,
-                                       const struct flowi *fl,
-                                       const struct flowi *oldflp,
-                                       struct net_device *dev_out,
-                                       unsigned flags)
+static inline int ip_mkroute_output(struct rtable **rp,
+                                   struct fib_result* res,
+                                   const struct flowi *fl,
+                                   const struct flowi *oldflp,
+                                   struct net_device *dev_out,
+                                   unsigned flags)
 {
        struct rtable *rth = NULL;
        int err = __mkroute_output(&rth, res, fl, oldflp, dev_out, flags);
@@ -2299,77 +2266,16 @@ static inline int ip_mkroute_output_def(struct rtable **rp,
                hash = rt_hash(oldflp->fl4_dst, oldflp->fl4_src, oldflp->oif);
                err = rt_intern_hash(hash, rth, rp);
        }
-       
-       return err;
-}
-
-static inline int ip_mkroute_output(struct rtable** rp,
-                                   struct fib_result* res,
-                                   const struct flowi *fl,
-                                   const struct flowi *oldflp,
-                                   struct net_device *dev_out,
-                                   unsigned flags)
-{
-#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
-       unsigned char hop;
-       unsigned hash;
-       int err = -EINVAL;
-       struct rtable *rth = NULL;
-
-       if (res->fi && res->fi->fib_nhs > 1) {
-               unsigned char hopcount = res->fi->fib_nhs;
 
-               for (hop = 0; hop < hopcount; hop++) {
-                       struct net_device *dev2nexthop;
-
-                       res->nh_sel = hop;
-
-                       /* hold a work reference to the output device */
-                       dev2nexthop = FIB_RES_DEV(*res);
-                       dev_hold(dev2nexthop);
-
-                       /* put reference to previous result */
-                       if (hop)
-                               ip_rt_put(*rp);
-
-                       err = __mkroute_output(&rth, res, fl, oldflp,
-                                              dev2nexthop, flags);
-
-                       if (err != 0)
-                               goto cleanup;
-
-                       hash = rt_hash(oldflp->fl4_dst, oldflp->fl4_src,
-                                       oldflp->oif);
-                       err = rt_intern_hash(hash, rth, rp);
-
-                       /* forward hop information to multipath impl. */
-                       multipath_set_nhinfo(rth,
-                                            FIB_RES_NETWORK(*res),
-                                            FIB_RES_NETMASK(*res),
-                                            res->prefixlen,
-                                            &FIB_RES_NH(*res));
-               cleanup:
-                       /* release work reference to output device */
-                       dev_put(dev2nexthop);
-
-                       if (err != 0)
-                               return err;
-               }
-               return err;
-       } else {
-               return ip_mkroute_output_def(rp, res, fl, oldflp, dev_out,
-                                            flags);
-       }
-#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
-       return ip_mkroute_output_def(rp, res, fl, oldflp, dev_out, flags);
-#endif
+       return err;
 }
 
 /*
  * Major route resolver routine.
  */
 
-static int ip_route_output_slow(struct rtable **rp, const struct flowi *oldflp)
+static int ip_route_output_slow(struct net *net, struct rtable **rp,
+                               const struct flowi *oldflp)
 {
        u32 tos = RT_FL_TOS(oldflp);
        struct flowi fl = { .nl_u = { .ip4_u =
@@ -2379,11 +2285,9 @@ static int ip_route_output_slow(struct rtable **rp, const struct flowi *oldflp)
                                        .scope = ((tos & RTO_ONLINK) ?
                                                  RT_SCOPE_LINK :
                                                  RT_SCOPE_UNIVERSE),
-#ifdef CONFIG_IP_ROUTE_FWMARK
-                                       .fwmark = oldflp->fl4_fwmark
-#endif
                                      } },
-                           .iif = loopback_dev.ifindex,
+                           .mark = oldflp->mark,
+                           .iif = net->loopback_dev->ifindex,
                            .oif = oldflp->oif };
        struct fib_result res;
        unsigned flags = 0;
@@ -2399,26 +2303,27 @@ static int ip_route_output_slow(struct rtable **rp, const struct flowi *oldflp)
 
        if (oldflp->fl4_src) {
                err = -EINVAL;
-               if (MULTICAST(oldflp->fl4_src) ||
-                   BADCLASS(oldflp->fl4_src) ||
-                   ZERONET(oldflp->fl4_src))
+               if (ipv4_is_multicast(oldflp->fl4_src) ||
+                   ipv4_is_lbcast(oldflp->fl4_src) ||
+                   ipv4_is_zeronet(oldflp->fl4_src))
                        goto out;
 
                /* It is equivalent to inet_addr_type(saddr) == RTN_LOCAL */
-               dev_out = ip_dev_find(oldflp->fl4_src);
+               dev_out = ip_dev_find(net, oldflp->fl4_src);
                if (dev_out == NULL)
                        goto out;
 
                /* I removed check for oif == dev_out->oif here.
                   It was wrong for two reasons:
-                  1. ip_dev_find(saddr) can return wrong iface, if saddr is
-                     assigned to multiple interfaces.
+                  1. ip_dev_find(net, saddr) can return wrong iface, if saddr
+                     is assigned to multiple interfaces.
                   2. Moreover, we are allowed to send packets with saddr
                      of another iface. --ANK
                 */
 
                if (oldflp->oif == 0
-                   && (MULTICAST(oldflp->fl4_dst) || oldflp->fl4_dst == htonl(0xFFFFFFFF))) {
+                   && (ipv4_is_multicast(oldflp->fl4_dst) ||
+                       oldflp->fl4_dst == htonl(0xFFFFFFFF))) {
                        /* Special hack: user can direct multicasts
                           and limited broadcast via necessary interface
                           without fiddling with IP_MULTICAST_IF or IP_PKTINFO.
@@ -2444,7 +2349,7 @@ static int ip_route_output_slow(struct rtable **rp, const struct flowi *oldflp)
 
 
        if (oldflp->oif) {
-               dev_out = dev_get_by_index(oldflp->oif);
+               dev_out = dev_get_by_index(net, oldflp->oif);
                err = -ENODEV;
                if (dev_out == NULL)
                        goto out;
@@ -2455,14 +2360,15 @@ static int ip_route_output_slow(struct rtable **rp, const struct flowi *oldflp)
                        goto out;       /* Wrong error code */
                }
 
-               if (LOCAL_MCAST(oldflp->fl4_dst) || oldflp->fl4_dst == htonl(0xFFFFFFFF)) {
+               if (ipv4_is_local_multicast(oldflp->fl4_dst) ||
+                   oldflp->fl4_dst == htonl(0xFFFFFFFF)) {
                        if (!fl.fl4_src)
                                fl.fl4_src = inet_select_addr(dev_out, 0,
                                                              RT_SCOPE_LINK);
                        goto make_route;
                }
                if (!fl.fl4_src) {
-                       if (MULTICAST(oldflp->fl4_dst))
+                       if (ipv4_is_multicast(oldflp->fl4_dst))
                                fl.fl4_src = inet_select_addr(dev_out, 0,
                                                              fl.fl4_scope);
                        else if (!oldflp->fl4_dst)
@@ -2477,15 +2383,15 @@ static int ip_route_output_slow(struct rtable **rp, const struct flowi *oldflp)
                        fl.fl4_dst = fl.fl4_src = htonl(INADDR_LOOPBACK);
                if (dev_out)
                        dev_put(dev_out);
-               dev_out = &loopback_dev;
+               dev_out = net->loopback_dev;
                dev_hold(dev_out);
-               fl.oif = loopback_dev.ifindex;
+               fl.oif = net->loopback_dev->ifindex;
                res.type = RTN_LOCAL;
                flags |= RTCF_LOCAL;
                goto make_route;
        }
 
-       if (fib_lookup(&fl, &res)) {
+       if (fib_lookup(net, &fl, &res)) {
                res.fi = NULL;
                if (oldflp->oif) {
                        /* Apparently, routing tables are wrong. Assume,
@@ -2524,7 +2430,7 @@ static int ip_route_output_slow(struct rtable **rp, const struct flowi *oldflp)
                        fl.fl4_src = fl.fl4_dst;
                if (dev_out)
                        dev_put(dev_out);
-               dev_out = &loopback_dev;
+               dev_out = net->loopback_dev;
                dev_hold(dev_out);
                fl.oif = dev_out->ifindex;
                if (res.fi)
@@ -2540,7 +2446,7 @@ static int ip_route_output_slow(struct rtable **rp, const struct flowi *oldflp)
        else
 #endif
        if (!res.prefixlen && res.type == RTN_UNICAST && !fl.oif)
-               fib_select_default(&fl, &res);
+               fib_select_default(net, &fl, &res);
 
        if (!fl.fl4_src)
                fl.fl4_src = FIB_RES_PREFSRC(res);
@@ -2563,7 +2469,8 @@ make_route:
 out:   return err;
 }
 
-int __ip_route_output_key(struct rtable **rp, const struct flowi *flp)
+int __ip_route_output_key(struct net *net, struct rtable **rp,
+                         const struct flowi *flp)
 {
        unsigned hash;
        struct rtable *rth;
@@ -2572,30 +2479,17 @@ int __ip_route_output_key(struct rtable **rp, const struct flowi *flp)
 
        rcu_read_lock_bh();
        for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
-               rth = rcu_dereference(rth->u.rt_next)) {
+               rth = rcu_dereference(rth->u.dst.rt_next)) {
                if (rth->fl.fl4_dst == flp->fl4_dst &&
                    rth->fl.fl4_src == flp->fl4_src &&
                    rth->fl.iif == 0 &&
                    rth->fl.oif == flp->oif &&
-#ifdef CONFIG_IP_ROUTE_FWMARK
-                   rth->fl.fl4_fwmark == flp->fl4_fwmark &&
-#endif
+                   rth->fl.mark == flp->mark &&
                    !((rth->fl.fl4_tos ^ flp->fl4_tos) &
-                           (IPTOS_RT_MASK | RTO_ONLINK))) {
-
-                       /* check for multipath routes and choose one if
-                        * necessary
-                        */
-                       if (multipath_select_route(flp, rth, rp)) {
-                               dst_hold(&(*rp)->u.dst);
-                               RT_CACHE_STAT_INC(out_hit);
-                               rcu_read_unlock_bh();
-                               return 0;
-                       }
-
-                       rth->u.dst.lastuse = jiffies;
-                       dst_hold(&rth->u.dst);
-                       rth->u.dst.__use++;
+                           (IPTOS_RT_MASK | RTO_ONLINK)) &&
+                   dev_net(rth->u.dst.dev) == net &&
+                   rth->rt_genid == atomic_read(&rt_genid)) {
+                       dst_use(&rth->u.dst, jiffies);
                        RT_CACHE_STAT_INC(out_hit);
                        rcu_read_unlock_bh();
                        *rp = rth;
@@ -2605,16 +2499,76 @@ int __ip_route_output_key(struct rtable **rp, const struct flowi *flp)
        }
        rcu_read_unlock_bh();
 
-       return ip_route_output_slow(rp, flp);
+       return ip_route_output_slow(net, rp, flp);
 }
 
 EXPORT_SYMBOL_GPL(__ip_route_output_key);
 
-int ip_route_output_flow(struct rtable **rp, struct flowi *flp, struct sock *sk, int flags)
+static void ipv4_rt_blackhole_update_pmtu(struct dst_entry *dst, u32 mtu)
+{
+}
+
+static struct dst_ops ipv4_dst_blackhole_ops = {
+       .family                 =       AF_INET,
+       .protocol               =       __constant_htons(ETH_P_IP),
+       .destroy                =       ipv4_dst_destroy,
+       .check                  =       ipv4_dst_check,
+       .update_pmtu            =       ipv4_rt_blackhole_update_pmtu,
+       .entry_size             =       sizeof(struct rtable),
+       .entries                =       ATOMIC_INIT(0),
+};
+
+
+static int ipv4_dst_blackhole(struct rtable **rp, struct flowi *flp)
+{
+       struct rtable *ort = *rp;
+       struct rtable *rt = (struct rtable *)
+               dst_alloc(&ipv4_dst_blackhole_ops);
+
+       if (rt) {
+               struct dst_entry *new = &rt->u.dst;
+
+               atomic_set(&new->__refcnt, 1);
+               new->__use = 1;
+               new->input = dst_discard;
+               new->output = dst_discard;
+               memcpy(new->metrics, ort->u.dst.metrics, RTAX_MAX*sizeof(u32));
+
+               new->dev = ort->u.dst.dev;
+               if (new->dev)
+                       dev_hold(new->dev);
+
+               rt->fl = ort->fl;
+
+               rt->idev = ort->idev;
+               if (rt->idev)
+                       in_dev_hold(rt->idev);
+               rt->rt_genid = atomic_read(&rt_genid);
+               rt->rt_flags = ort->rt_flags;
+               rt->rt_type = ort->rt_type;
+               rt->rt_dst = ort->rt_dst;
+               rt->rt_src = ort->rt_src;
+               rt->rt_iif = ort->rt_iif;
+               rt->rt_gateway = ort->rt_gateway;
+               rt->rt_spec_dst = ort->rt_spec_dst;
+               rt->peer = ort->peer;
+               if (rt->peer)
+                       atomic_inc(&rt->peer->refcnt);
+
+               dst_free(new);
+       }
+
+       dst_release(&(*rp)->u.dst);
+       *rp = rt;
+       return (rt ? 0 : -ENOMEM);
+}
+
+int ip_route_output_flow(struct net *net, struct rtable **rp, struct flowi *flp,
+                        struct sock *sk, int flags)
 {
        int err;
 
-       if ((err = __ip_route_output_key(rp, flp)) != 0)
+       if ((err = __ip_route_output_key(net, rp, flp)) != 0)
                return err;
 
        if (flp->proto) {
@@ -2622,7 +2576,12 @@ int ip_route_output_flow(struct rtable **rp, struct flowi *flp, struct sock *sk,
                        flp->fl4_src = (*rp)->rt_src;
                if (!flp->fl4_dst)
                        flp->fl4_dst = (*rp)->rt_dst;
-               return xfrm_lookup((struct dst_entry **)rp, flp, sk, flags);
+               err = __xfrm_lookup((struct dst_entry **)rp, flp, sk,
+                                   flags ? XFRM_LOOKUP_WAIT : 0);
+               if (err == -EREMOTE)
+                       err = ipv4_dst_blackhole(rp, flp);
+
+               return err;
        }
 
        return 0;
@@ -2630,22 +2589,23 @@ int ip_route_output_flow(struct rtable **rp, struct flowi *flp, struct sock *sk,
 
 EXPORT_SYMBOL_GPL(ip_route_output_flow);
 
-int ip_route_output_key(struct rtable **rp, struct flowi *flp)
+int ip_route_output_key(struct net *net, struct rtable **rp, struct flowi *flp)
 {
-       return ip_route_output_flow(rp, flp, NULL, 0);
+       return ip_route_output_flow(net, rp, flp, NULL, 0);
 }
 
 static int rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
                        int nowait, unsigned int flags)
 {
-       struct rtable *rt = (struct rtable*)skb->dst;
+       struct rtable *rt = skb->rtable;
        struct rtmsg *r;
        struct nlmsghdr *nlh;
-       struct rta_cacheinfo ci;
+       long expires;
+       u32 id = 0, ts = 0, tsage = 0, error;
 
        nlh = nlmsg_put(skb, pid, seq, event, sizeof(*r), flags);
        if (nlh == NULL)
-               return -ENOBUFS;
+               return -EMSGSIZE;
 
        r = nlmsg_data(nlh);
        r->rtm_family    = AF_INET;
@@ -2672,10 +2632,6 @@ static int rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
 #ifdef CONFIG_NET_CLS_ROUTE
        if (rt->u.dst.tclassid)
                NLA_PUT_U32(skb, RTA_FLOW, rt->u.dst.tclassid);
-#endif
-#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
-       if (rt->rt_multipath_alg != IP_MP_ALG_NONE)
-               NLA_PUT_U32(skb, RTA_MP_ALGO, rt->rt_multipath_alg);
 #endif
        if (rt->fl.iif)
                NLA_PUT_BE32(skb, RTA_PREFSRC, rt->rt_spec_dst);
@@ -2688,20 +2644,13 @@ static int rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
        if (rtnetlink_put_metrics(skb, rt->u.dst.metrics) < 0)
                goto nla_put_failure;
 
-       ci.rta_lastuse  = jiffies_to_clock_t(jiffies - rt->u.dst.lastuse);
-       ci.rta_used     = rt->u.dst.__use;
-       ci.rta_clntref  = atomic_read(&rt->u.dst.__refcnt);
-       if (rt->u.dst.expires)
-               ci.rta_expires = jiffies_to_clock_t(rt->u.dst.expires - jiffies);
-       else
-               ci.rta_expires = 0;
-       ci.rta_error    = rt->u.dst.error;
-       ci.rta_id       = ci.rta_ts = ci.rta_tsage = 0;
+       error = rt->u.dst.error;
+       expires = rt->u.dst.expires ? rt->u.dst.expires - jiffies : 0;
        if (rt->peer) {
-               ci.rta_id = rt->peer->ip_id_count;
+               id = rt->peer->ip_id_count;
                if (rt->peer->tcp_ts_stamp) {
-                       ci.rta_ts = rt->peer->tcp_ts;
-                       ci.rta_tsage = xtime.tv_sec - rt->peer->tcp_ts_stamp;
+                       ts = rt->peer->tcp_ts;
+                       tsage = get_seconds() - rt->peer->tcp_ts_stamp;
                }
        }
 
@@ -2709,8 +2658,8 @@ static int rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
 #ifdef CONFIG_IP_MROUTE
                __be32 dst = rt->rt_dst;
 
-               if (MULTICAST(dst) && !LOCAL_MCAST(dst) &&
-                   ipv4_devconf.mc_forwarding) {
+               if (ipv4_is_multicast(dst) && !ipv4_is_local_multicast(dst) &&
+                   IPV4_DEVCONF_ALL(&init_net, MC_FORWARDING)) {
                        int err = ipmr_get_route(skb, r, nowait);
                        if (err <= 0) {
                                if (!nowait) {
@@ -2720,7 +2669,7 @@ static int rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
                                } else {
                                        if (err == -EMSGSIZE)
                                                goto nla_put_failure;
-                                       ci.rta_error = err;
+                                       error = err;
                                }
                        }
                } else
@@ -2728,16 +2677,20 @@ static int rt_fill_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
                        NLA_PUT_U32(skb, RTA_IIF, rt->fl.iif);
        }
 
-       NLA_PUT(skb, RTA_CACHEINFO, sizeof(ci), &ci);
+       if (rtnl_put_cacheinfo(skb, &rt->u.dst, id, ts, tsage,
+                              expires, error) < 0)
+               goto nla_put_failure;
 
        return nlmsg_end(skb, nlh);
 
 nla_put_failure:
-       return nlmsg_cancel(skb, nlh);
+       nlmsg_cancel(skb, nlh);
+       return -EMSGSIZE;
 }
 
-int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg)
+static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg)
 {
+       struct net *net = sock_net(in_skb->sk);
        struct rtmsg *rtm;
        struct nlattr *tb[RTA_MAX+1];
        struct rtable *rt = NULL;
@@ -2762,10 +2715,11 @@ int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg)
        /* Reserve room for dummy headers, this skb can pass
           through good chunk of routing engine.
         */
-       skb->mac.raw = skb->nh.raw = skb->data;
+       skb_reset_mac_header(skb);
+       skb_reset_network_header(skb);
 
        /* Bugfix: need to give ip_route_input enough of an IP header to not gag. */
-       skb->nh.iph->protocol = IPPROTO_ICMP;
+       ip_hdr(skb)->protocol = IPPROTO_ICMP;
        skb_reserve(skb, MAX_HEADER + sizeof(struct iphdr));
 
        src = tb[RTA_SRC] ? nla_get_be32(tb[RTA_SRC]) : 0;
@@ -2775,7 +2729,7 @@ int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg)
        if (iif) {
                struct net_device *dev;
 
-               dev = __dev_get_by_index(iif);
+               dev = __dev_get_by_index(net, iif);
                if (dev == NULL) {
                        err = -ENODEV;
                        goto errout_free;
@@ -2787,7 +2741,7 @@ int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg)
                err = ip_route_input(skb, dst, src, rtm->rtm_tos, dev);
                local_bh_enable();
 
-               rt = (struct rtable*) skb->dst;
+               rt = skb->rtable;
                if (err == 0 && rt->u.dst.error)
                        err = -rt->u.dst.error;
        } else {
@@ -2801,22 +2755,22 @@ int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg)
                        },
                        .oif = tb[RTA_OIF] ? nla_get_u32(tb[RTA_OIF]) : 0,
                };
-               err = ip_route_output_key(&rt, &fl);
+               err = ip_route_output_key(net, &rt, &fl);
        }
 
        if (err)
                goto errout_free;
 
-       skb->dst = &rt->u.dst;
+       skb->rtable = rt;
        if (rtm->rtm_flags & RTM_F_NOTIFY)
                rt->rt_flags |= RTCF_NOTIFY;
 
        err = rt_fill_info(skb, NETLINK_CB(in_skb).pid, nlh->nlmsg_seq,
-                               RTM_NEWROUTE, 0, 0);
+                          RTM_NEWROUTE, 0, 0);
        if (err <= 0)
                goto errout_free;
 
-       err = rtnl_unicast(skb, NETLINK_CB(in_skb).pid);
+       err = rtnl_unicast(skb, net, NETLINK_CB(in_skb).pid);
 errout:
        return err;
 
@@ -2830,21 +2784,25 @@ int ip_rt_dump(struct sk_buff *skb,  struct netlink_callback *cb)
        struct rtable *rt;
        int h, s_h;
        int idx, s_idx;
+       struct net *net;
+
+       net = sock_net(skb->sk);
 
        s_h = cb->args[0];
+       if (s_h < 0)
+               s_h = 0;
        s_idx = idx = cb->args[1];
-       for (h = 0; h <= rt_hash_mask; h++) {
-               if (h < s_h) continue;
-               if (h > s_h)
-                       s_idx = 0;
+       for (h = s_h; h <= rt_hash_mask; h++) {
                rcu_read_lock_bh();
                for (rt = rcu_dereference(rt_hash_table[h].chain), idx = 0; rt;
-                    rt = rcu_dereference(rt->u.rt_next), idx++) {
-                       if (idx < s_idx)
+                    rt = rcu_dereference(rt->u.dst.rt_next), idx++) {
+                       if (dev_net(rt->u.dst.dev) != net || idx < s_idx)
+                               continue;
+                       if (rt->rt_genid != atomic_read(&rt_genid))
                                continue;
                        skb->dst = dst_clone(&rt->u.dst);
                        if (rt_fill_info(skb, NETLINK_CB(cb->skb).pid,
-                                        cb->nlh->nlmsg_seq, RTM_NEWROUTE, 
+                                        cb->nlh->nlmsg_seq, RTM_NEWROUTE,
                                         1, NLM_F_MULTI) <= 0) {
                                dst_release(xchg(&skb->dst, NULL));
                                rcu_read_unlock_bh();
@@ -2853,6 +2811,7 @@ int ip_rt_dump(struct sk_buff *skb,  struct netlink_callback *cb)
                        dst_release(xchg(&skb->dst, NULL));
                }
                rcu_read_unlock_bh();
+               s_idx = 0;
        }
 
 done:
@@ -2877,7 +2836,7 @@ static int ipv4_sysctl_rtcache_flush(ctl_table *ctl, int write,
                proc_dointvec(ctl, write, filp, buffer, lenp, ppos);
                rt_cache_flush(flush_delay);
                return 0;
-       } 
+       }
 
        return -EINVAL;
 }
@@ -2888,20 +2847,19 @@ static int ipv4_sysctl_rtcache_flush_strategy(ctl_table *table,
                                                void __user *oldval,
                                                size_t __user *oldlenp,
                                                void __user *newval,
-                                               size_t newlen,
-                                               void **context)
+                                               size_t newlen)
 {
        int delay;
        if (newlen != sizeof(int))
                return -EINVAL;
        if (get_user(delay, (int __user *)newval))
-               return -EFAULT; 
-       rt_cache_flush(delay); 
+               return -EFAULT;
+       rt_cache_flush(delay);
        return 0;
 }
 
 ctl_table ipv4_route_table[] = {
-        {
+       {
                .ctl_name       = NET_IPV4_ROUTE_FLUSH,
                .procname       = "flush",
                .data           = &flush_delay,
@@ -2910,24 +2868,6 @@ ctl_table ipv4_route_table[] = {
                .proc_handler   = &ipv4_sysctl_rtcache_flush,
                .strategy       = &ipv4_sysctl_rtcache_flush_strategy,
        },
-       {
-               .ctl_name       = NET_IPV4_ROUTE_MIN_DELAY,
-               .procname       = "min_delay",
-               .data           = &ip_rt_min_delay,
-               .maxlen         = sizeof(int),
-               .mode           = 0644,
-               .proc_handler   = &proc_dointvec_jiffies,
-               .strategy       = &sysctl_jiffies,
-       },
-       {
-               .ctl_name       = NET_IPV4_ROUTE_MAX_DELAY,
-               .procname       = "max_delay",
-               .data           = &ip_rt_max_delay,
-               .maxlen         = sizeof(int),
-               .mode           = 0644,
-               .proc_handler   = &proc_dointvec_jiffies,
-               .strategy       = &sysctl_jiffies,
-       },
        {
                .ctl_name       = NET_IPV4_ROUTE_GC_THRESH,
                .procname       = "gc_thresh",
@@ -2946,7 +2886,7 @@ ctl_table ipv4_route_table[] = {
        },
        {
                /*  Deprecated. Use gc_min_interval_ms */
+
                .ctl_name       = NET_IPV4_ROUTE_GC_MIN_INTERVAL,
                .procname       = "gc_min_interval",
                .data           = &ip_rt_gc_min_interval,
@@ -3069,55 +3009,7 @@ ctl_table ipv4_route_table[] = {
 #endif
 
 #ifdef CONFIG_NET_CLS_ROUTE
-struct ip_rt_acct *ip_rt_acct;
-
-/* This code sucks.  But you should have seen it before! --RR */
-
-/* IP route accounting ptr for this logical cpu number. */
-#define IP_RT_ACCT_CPU(i) (ip_rt_acct + i * 256)
-
-#ifdef CONFIG_PROC_FS
-static int ip_rt_acct_read(char *buffer, char **start, off_t offset,
-                          int length, int *eof, void *data)
-{
-       unsigned int i;
-
-       if ((offset & 3) || (length & 3))
-               return -EIO;
-
-       if (offset >= sizeof(struct ip_rt_acct) * 256) {
-               *eof = 1;
-               return 0;
-       }
-
-       if (offset + length >= sizeof(struct ip_rt_acct) * 256) {
-               length = sizeof(struct ip_rt_acct) * 256 - offset;
-               *eof = 1;
-       }
-
-       offset /= sizeof(u32);
-
-       if (length > 0) {
-               u32 *src = ((u32 *) IP_RT_ACCT_CPU(0)) + offset;
-               u32 *dst = (u32 *) buffer;
-
-               /* Copy first cpu. */
-               *start = buffer;
-               memcpy(dst, src, length);
-
-               /* Add the other cpus in, one int at a time */
-               for_each_possible_cpu(i) {
-                       unsigned int j;
-
-                       src = ((u32 *) IP_RT_ACCT_CPU(i)) + offset;
-
-                       for (j = 0; j < length/4; j++)
-                               dst[j] += src[j];
-               }
-       }
-       return length;
-}
-#endif /* CONFIG_PROC_FS */
+struct ip_rt_acct *ip_rt_acct __read_mostly;
 #endif /* CONFIG_NET_CLS_ROUTE */
 
 static __initdata unsigned long rhash_entries;
@@ -3134,25 +3026,20 @@ int __init ip_rt_init(void)
 {
        int rc = 0;
 
-       rt_hash_rnd = (int) ((num_physpages ^ (num_physpages>>8)) ^
-                            (jiffies ^ (jiffies >> 7)));
+       atomic_set(&rt_genid, (int) ((num_physpages ^ (num_physpages>>8)) ^
+                            (jiffies ^ (jiffies >> 7))));
 
 #ifdef CONFIG_NET_CLS_ROUTE
-       {
-       int order;
-       for (order = 0;
-            (PAGE_SIZE << order) < 256 * sizeof(struct ip_rt_acct) * NR_CPUS; order++)
-               /* NOTHING */;
-       ip_rt_acct = (struct ip_rt_acct *)__get_free_pages(GFP_KERNEL, order);
+       ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct));
        if (!ip_rt_acct)
                panic("IP: failed to allocate ip_rt_acct\n");
-       memset(ip_rt_acct, 0, PAGE_SIZE << order);
-       }
 #endif
 
        ipv4_dst_ops.kmem_cachep =
                kmem_cache_create("ip_dst_cache", sizeof(struct rtable), 0,
-                                 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
+                                 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
+
+       ipv4_dst_blackhole_ops.kmem_cachep = ipv4_dst_ops.kmem_cachep;
 
        rt_hash_table = (struct rt_hash_bucket *)
                alloc_large_system_hash("IP route cache",
@@ -3173,42 +3060,26 @@ int __init ip_rt_init(void)
        devinet_init();
        ip_fib_init();
 
-       init_timer(&rt_flush_timer);
-       rt_flush_timer.function = rt_run_flush;
-       init_timer(&rt_periodic_timer);
-       rt_periodic_timer.function = rt_check_expire;
-       init_timer(&rt_secret_timer);
-       rt_secret_timer.function = rt_secret_rebuild;
+       setup_timer(&rt_secret_timer, rt_secret_rebuild, 0);
 
        /* All the timers, started at system startup tend
           to synchronize. Perturb it a bit.
         */
-       rt_periodic_timer.expires = jiffies + net_random() % ip_rt_gc_interval +
-                                       ip_rt_gc_interval;
-       add_timer(&rt_periodic_timer);
+       schedule_delayed_work(&expires_work,
+               net_random() % ip_rt_gc_interval + ip_rt_gc_interval);
 
        rt_secret_timer.expires = jiffies + net_random() % ip_rt_secret_interval +
                ip_rt_secret_interval;
        add_timer(&rt_secret_timer);
 
-#ifdef CONFIG_PROC_FS
-       {
-       struct proc_dir_entry *rtstat_pde = NULL; /* keep gcc happy */
-       if (!proc_net_fops_create("rt_cache", S_IRUGO, &rt_cache_seq_fops) ||
-           !(rtstat_pde = create_proc_entry("rt_cache", S_IRUGO, 
-                                            proc_net_stat))) {
-               return -ENOMEM;
-       }
-       rtstat_pde->proc_fops = &rt_cpu_seq_fops;
-       }
-#ifdef CONFIG_NET_CLS_ROUTE
-       create_proc_read_entry("rt_acct", 0, proc_net, ip_rt_acct_read, NULL);
-#endif
-#endif
+       if (ip_rt_proc_init())
+               printk(KERN_ERR "Unable to create route proc files\n");
 #ifdef CONFIG_XFRM
        xfrm_init();
        xfrm4_init();
 #endif
+       rtnl_register(PF_INET, RTM_GETROUTE, inet_rtm_getroute, NULL);
+
        return rc;
 }