ipv4: pass current value of rt_genid into rt_hash
[safe/jmp/linux-2.6] / net / ipv4 / route.c
index eab8d75..e4e37ed 100644 (file)
@@ -5,8 +5,6 @@
  *
  *             ROUTE - implementation of the IP router.
  *
- * Version:    $Id: route.c,v 1.103 2002/01/12 07:44:09 davem Exp $
- *
  * Authors:    Ross Biro
  *             Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  *             Alan Cox, <gw4pts@gw4pts.ampr.org>
@@ -134,7 +132,6 @@ 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;
 
 /*
  *     Interface to generic destination cache.
@@ -160,7 +157,7 @@ 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,
+       .local_out =            __ip_local_out,
        .entry_size =           sizeof(struct rtable),
        .entries =              ATOMIC_INIT(0),
 };
@@ -259,16 +256,15 @@ 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 unsigned int rt_hash_code(u32 daddr, u32 saddr)
+static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
+               int genid)
 {
-       return jhash_2words(daddr, saddr, atomic_read(&rt_genid))
+       return jhash_3words((__force u32)(__be32)(daddr),
+                           (__force u32)(__be32)(saddr),
+                           idx, genid)
                & rt_hash_mask;
 }
 
-#define rt_hash(daddr, saddr, idx) \
-       rt_hash_code((__force u32)(__be32)(daddr),\
-                    (__force u32)(__be32)(saddr) ^ ((idx) << 5))
-
 #ifdef CONFIG_PROC_FS
 struct rt_cache_iter_state {
        struct seq_net_private p;
@@ -369,10 +365,10 @@ static int rt_cache_seq_show(struct seq_file *seq, void *v)
                           "HHUptod\tSpecDst");
        else {
                struct rtable *r = v;
-               char temp[256];
+               int len;
 
-               sprintf(temp, "%s\t%08lX\t%08lX\t%8X\t%d\t%u\t%d\t"
-                             "%08lX\t%d\t%u\t%u\t%02X\t%d\t%1d\t%08X",
+               seq_printf(seq, "%s\t%08lX\t%08lX\t%8X\t%d\t%u\t%d\t"
+                             "%08lX\t%d\t%u\t%u\t%02X\t%d\t%1d\t%08X%n",
                        r->u.dst.dev ? r->u.dst.dev->name : "*",
                        (unsigned long)r->rt_dst, (unsigned long)r->rt_gateway,
                        r->rt_flags, atomic_read(&r->u.dst.__refcnt),
@@ -386,8 +382,9 @@ static int rt_cache_seq_show(struct seq_file *seq, void *v)
                        r->u.dst.hh ? atomic_read(&r->u.dst.hh->hh_refcnt) : -1,
                        r->u.dst.hh ? (r->u.dst.hh->hh_output ==
                                       dev_queue_xmit) : 0,
-                       r->rt_spec_dst);
-               seq_printf(seq, "%-127s\n", temp);
+                       r->rt_spec_dst, &len);
+
+               seq_printf(seq, "%*s\n", 127 - len, "");
        }
        return 0;
 }
@@ -600,18 +597,18 @@ static inline int ip_rt_proc_init(void)
 }
 #endif /* CONFIG_PROC_FS */
 
-static __inline__ void rt_free(struct rtable *rt)
+static inline void rt_free(struct rtable *rt)
 {
        call_rcu_bh(&rt->u.dst.rcu_head, dst_rcu_free);
 }
 
-static __inline__ void rt_drop(struct rtable *rt)
+static inline void rt_drop(struct rtable *rt)
 {
        ip_rt_put(rt);
        call_rcu_bh(&rt->u.dst.rcu_head, dst_rcu_free);
 }
 
-static __inline__ int rt_fast_clean(struct rtable *rth)
+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 */
@@ -619,7 +616,7 @@ static __inline__ int rt_fast_clean(struct rtable *rth)
                rth->fl.iif && rth->u.dst.rt_next;
 }
 
-static __inline__ int rt_valuable(struct rtable *rth)
+static inline int rt_valuable(struct rtable *rth)
 {
        return (rth->rt_flags & (RTCF_REDIRECTED | RTCF_NOTIFY)) ||
                rth->u.dst.expires;
@@ -782,7 +779,7 @@ static void rt_worker_func(struct work_struct *work)
  * 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)
+static void rt_cache_invalidate(struct net *net)
 {
        unsigned char shuffle;
 
@@ -794,9 +791,9 @@ static void rt_cache_invalidate(void)
  * delay < 0  : invalidate cache (fast : entries will be deleted later)
  * delay >= 0 : invalidate & flush cache (can be long)
  */
-void rt_cache_flush(int delay)
+void rt_cache_flush(struct net *net, int delay)
 {
-       rt_cache_invalidate();
+       rt_cache_invalidate(net);
        if (delay >= 0)
                rt_do_flush(!in_softirq());
 }
@@ -804,10 +801,11 @@ void rt_cache_flush(int delay)
 /*
  * We change rt_genid and let gc do the cleanup
  */
-static void rt_secret_rebuild(unsigned long dummy)
+static void rt_secret_rebuild(unsigned long __net)
 {
-       rt_cache_invalidate();
-       mod_timer(&rt_secret_timer, jiffies + ip_rt_secret_interval);
+       struct net *net = (struct net *)__net;
+       rt_cache_invalidate(net);
+       mod_timer(&net->ipv4.rt_secret_timer, jiffies + ip_rt_secret_interval);
 }
 
 /*
@@ -1061,10 +1059,10 @@ restart:
 #if RT_CACHE_DEBUG >= 2
        if (rt->u.dst.rt_next) {
                struct rtable *trt;
-               printk(KERN_DEBUG "rt_cache @%02x: %u.%u.%u.%u", hash,
+               printk(KERN_DEBUG "rt_cache @%02x: " NIPQUAD_FMT, hash,
                       NIPQUAD(rt->rt_dst));
                for (trt = rt->u.dst.rt_next; trt; trt = trt->u.dst.rt_next)
-                       printk(" . %u.%u.%u.%u", NIPQUAD(trt->rt_dst));
+                       printk(" . " NIPQUAD_FMT, NIPQUAD(trt->rt_dst));
                printk("\n");
        }
 #endif
@@ -1183,7 +1181,8 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
 
        for (i = 0; i < 2; i++) {
                for (k = 0; k < 2; k++) {
-                       unsigned hash = rt_hash(daddr, skeys[i], ikeys[k]);
+                       unsigned hash = rt_hash(daddr, skeys[i], ikeys[k],
+                                               atomic_read(&rt_genid));
 
                        rthp=&rt_hash_table[hash].chain;
 
@@ -1196,7 +1195,7 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
                                    rth->fl.oif != ikeys[k] ||
                                    rth->fl.iif != 0 ||
                                    rth->rt_genid != atomic_read(&rt_genid) ||
-                                   dev_net(rth->u.dst.dev) != net) {
+                                   !net_eq(dev_net(rth->u.dst.dev), net)) {
                                        rthp = &rth->u.dst.rt_next;
                                        continue;
                                }
@@ -1277,9 +1276,9 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
 reject_redirect:
 #ifdef CONFIG_IP_ROUTE_VERBOSE
        if (IN_DEV_LOG_MARTIANS(in_dev) && net_ratelimit())
-               printk(KERN_INFO "Redirect from %u.%u.%u.%u on %s about "
-                       "%u.%u.%u.%u ignored.\n"
-                       "  Advised path = %u.%u.%u.%u -> %u.%u.%u.%u\n",
+               printk(KERN_INFO "Redirect from " NIPQUAD_FMT " on %s about "
+                       NIPQUAD_FMT " ignored.\n"
+                       "  Advised path = " NIPQUAD_FMT " -> " NIPQUAD_FMT "\n",
                       NIPQUAD(old_gw), dev->name, NIPQUAD(new_gw),
                       NIPQUAD(saddr), NIPQUAD(daddr));
 #endif
@@ -1298,10 +1297,11 @@ static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst)
                } else if ((rt->rt_flags & RTCF_REDIRECTED) ||
                           rt->u.dst.expires) {
                        unsigned hash = rt_hash(rt->fl.fl4_dst, rt->fl.fl4_src,
-                                               rt->fl.oif);
+                                               rt->fl.oif,
+                                               atomic_read(&rt_genid));
 #if RT_CACHE_DEBUG >= 1
                        printk(KERN_DEBUG "ipv4_negative_advice: redirect to "
-                                         "%u.%u.%u.%u/%02x dropped\n",
+                                         NIPQUAD_FMT "/%02x dropped\n",
                                NIPQUAD(rt->rt_dst), rt->fl.fl4_tos);
 #endif
                        rt_del(hash, rt);
@@ -1366,8 +1366,8 @@ void ip_rt_send_redirect(struct sk_buff *skb)
                if (IN_DEV_LOG_MARTIANS(in_dev) &&
                    rt->u.dst.rate_tokens == ip_rt_redirect_number &&
                    net_ratelimit())
-                       printk(KERN_WARNING "host %u.%u.%u.%u/if%d ignores "
-                               "redirects for %u.%u.%u.%u to %u.%u.%u.%u.\n",
+                       printk(KERN_WARNING "host " NIPQUAD_FMT "/if%d ignores "
+                               "redirects for " NIPQUAD_FMT " to " NIPQUAD_FMT ".\n",
                                NIPQUAD(rt->rt_src), rt->rt_iif,
                                NIPQUAD(rt->rt_dst), NIPQUAD(rt->rt_gateway));
 #endif
@@ -1420,7 +1420,7 @@ out:      kfree_skb(skb);
 static const unsigned short mtu_plateau[] =
 {32000, 17914, 8166, 4352, 2002, 1492, 576, 296, 216, 128 };
 
-static __inline__ unsigned short guess_mtu(unsigned short old_mtu)
+static inline unsigned short guess_mtu(unsigned short old_mtu)
 {
        int i;
 
@@ -1431,11 +1431,13 @@ static __inline__ unsigned short guess_mtu(unsigned short old_mtu)
 }
 
 unsigned short ip_rt_frag_needed(struct net *net, struct iphdr *iph,
-                                unsigned short new_mtu)
+                                unsigned short new_mtu,
+                                struct net_device *dev)
 {
-       int i;
+       int i, k;
        unsigned short old_mtu = ntohs(iph->tot_len);
        struct rtable *rth;
+       int  ikeys[2] = { dev->ifindex, 0 };
        __be32  skeys[2] = { iph->saddr, 0, };
        __be32  daddr = iph->daddr;
        unsigned short est_mtu = 0;
@@ -1443,34 +1445,39 @@ unsigned short ip_rt_frag_needed(struct net *net, struct iphdr *iph,
        if (ipv4_config.no_pmtu_disc)
                return 0;
 
-       for (i = 0; i < 2; i++) {
-               unsigned hash = rt_hash(daddr, skeys[i], 0);
+       for (k = 0; k < 2; k++) {
+               for (i = 0; i < 2; i++) {
+                       unsigned hash = rt_hash(daddr, skeys[i], ikeys[k],
+                                               atomic_read(&rt_genid));
 
-               rcu_read_lock();
-               for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
-                    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)) &&
-                           dev_net(rth->u.dst.dev) == net &&
-                           rth->rt_genid == atomic_read(&rt_genid)) {
+                       rcu_read_lock();
+                       for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
+                            rth = rcu_dereference(rth->u.dst.rt_next)) {
                                unsigned short mtu = new_mtu;
 
+                               if (rth->fl.fl4_dst != daddr ||
+                                   rth->fl.fl4_src != skeys[i] ||
+                                   rth->rt_dst != daddr ||
+                                   rth->rt_src != iph->saddr ||
+                                   rth->fl.oif != ikeys[k] ||
+                                   rth->fl.iif != 0 ||
+                                   dst_metric_locked(&rth->u.dst, RTAX_MTU) ||
+                                   !net_eq(dev_net(rth->u.dst.dev), net) ||
+                                   rth->rt_genid != atomic_read(&rt_genid))
+                                       continue;
+
                                if (new_mtu < 68 || new_mtu >= old_mtu) {
 
                                        /* BSD 4.2 compatibility hack :-( */
                                        if (mtu == 0 &&
-                                           old_mtu >= rth->u.dst.metrics[RTAX_MTU-1] &&
+                                           old_mtu >= dst_metric(&rth->u.dst, RTAX_MTU) &&
                                            old_mtu >= 68 + (iph->ihl << 2))
                                                old_mtu -= iph->ihl << 2;
 
                                        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 <= dst_metric(&rth->u.dst, RTAX_MTU)) {
+                                       if (mtu < dst_metric(&rth->u.dst, RTAX_MTU)) {
                                                dst_confirm(&rth->u.dst);
                                                if (mtu < ip_rt_min_pmtu) {
                                                        mtu = ip_rt_min_pmtu;
@@ -1484,15 +1491,15 @@ unsigned short ip_rt_frag_needed(struct net *net, struct iphdr *iph,
                                        est_mtu = mtu;
                                }
                        }
+                       rcu_read_unlock();
                }
-               rcu_read_unlock();
        }
        return est_mtu ? : new_mtu;
 }
 
 static void ip_rt_update_pmtu(struct dst_entry *dst, u32 mtu)
 {
-       if (dst->metrics[RTAX_MTU-1] > mtu && mtu >= 68 &&
+       if (dst_metric(dst, RTAX_MTU) > mtu && mtu >= 68 &&
            !(dst_metric_locked(dst, RTAX_MTU))) {
                if (mtu < ip_rt_min_pmtu) {
                        mtu = ip_rt_min_pmtu;
@@ -1554,7 +1561,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",
+       printk(KERN_DEBUG "ip_rt_bug: " NIPQUAD_FMT " -> " NIPQUAD_FMT ", %s\n",
                NIPQUAD(ip_hdr(skb)->saddr), NIPQUAD(ip_hdr(skb)->daddr),
                skb->dev ? skb->dev->name : "?");
        kfree_skb(skb);
@@ -1608,7 +1615,7 @@ static void rt_set_nexthop(struct rtable *rt, struct fib_result *res, u32 itag)
                       sizeof(rt->u.dst.metrics));
                if (fi->fib_mtu == 0) {
                        rt->u.dst.metrics[RTAX_MTU-1] = rt->u.dst.dev->mtu;
-                       if (rt->u.dst.metrics[RTAX_LOCK-1] & (1 << RTAX_MTU) &&
+                       if (dst_metric_locked(&rt->u.dst, RTAX_MTU) &&
                            rt->rt_gateway != rt->rt_dst &&
                            rt->u.dst.dev->mtu > 576)
                                rt->u.dst.metrics[RTAX_MTU-1] = 576;
@@ -1619,14 +1626,14 @@ static void rt_set_nexthop(struct rtable *rt, struct fib_result *res, u32 itag)
        } else
                rt->u.dst.metrics[RTAX_MTU-1]= rt->u.dst.dev->mtu;
 
-       if (rt->u.dst.metrics[RTAX_HOPLIMIT-1] == 0)
+       if (dst_metric(&rt->u.dst, RTAX_HOPLIMIT) == 0)
                rt->u.dst.metrics[RTAX_HOPLIMIT-1] = sysctl_ip_default_ttl;
-       if (rt->u.dst.metrics[RTAX_MTU-1] > IP_MAX_MTU)
+       if (dst_metric(&rt->u.dst, RTAX_MTU) > IP_MAX_MTU)
                rt->u.dst.metrics[RTAX_MTU-1] = IP_MAX_MTU;
-       if (rt->u.dst.metrics[RTAX_ADVMSS-1] == 0)
+       if (dst_metric(&rt->u.dst, RTAX_ADVMSS) == 0)
                rt->u.dst.metrics[RTAX_ADVMSS-1] = max_t(unsigned int, rt->u.dst.dev->mtu - 40,
                                       ip_rt_min_advmss);
-       if (rt->u.dst.metrics[RTAX_ADVMSS-1] > 65535 - 40)
+       if (dst_metric(&rt->u.dst, RTAX_ADVMSS) > 65535 - 40)
                rt->u.dst.metrics[RTAX_ADVMSS-1] = 65535 - 40;
 
 #ifdef CONFIG_NET_CLS_ROUTE
@@ -1706,7 +1713,7 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
        RT_CACHE_STAT_INC(in_slow_mc);
 
        in_dev_put(in_dev);
-       hash = rt_hash(daddr, saddr, dev->ifindex);
+       hash = rt_hash(daddr, saddr, dev->ifindex, atomic_read(&rt_genid));
        return rt_intern_hash(hash, rth, &skb->rtable);
 
 e_nobufs:
@@ -1732,8 +1739,8 @@ static void ip_handle_martian_source(struct net_device *dev,
                 *      RFC1812 recommendation, if source is martian,
                 *      the only hint is MAC header.
                 */
-               printk(KERN_WARNING "martian source %u.%u.%u.%u from "
-                       "%u.%u.%u.%u, on dev %s\n",
+               printk(KERN_WARNING "martian source " NIPQUAD_FMT " from "
+                       NIPQUAD_FMT", on dev %s\n",
                        NIPQUAD(daddr), NIPQUAD(saddr), dev->name);
                if (dev->hard_header_len && skb_mac_header_was_set(skb)) {
                        int i;
@@ -1750,11 +1757,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,
-                                 __be32 daddr, __be32 saddr, u32 tos,
-                                 struct rtable **result)
+static 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 *rth;
@@ -1787,7 +1794,7 @@ static inline int __mkroute_input(struct sk_buff *skb,
        if (err)
                flags |= RTCF_DIRECTSRC;
 
-       if (out_dev == in_dev && err && !(flags & RTCF_MASQ) &&
+       if (out_dev == in_dev && err &&
            (IN_DEV_SHARED_MEDIA(out_dev) ||
             inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
                flags |= RTCF_DOREDIRECT;
@@ -1846,11 +1853,11 @@ static inline int __mkroute_input(struct sk_buff *skb,
        return err;
 }
 
-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)
+static 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;
@@ -1867,7 +1874,7 @@ static inline int ip_mkroute_input(struct sk_buff *skb,
                return err;
 
        /* put it into the cache */
-       hash = rt_hash(daddr, saddr, fl->iif);
+       hash = rt_hash(daddr, saddr, fl->iif, atomic_read(&rt_genid));
        return rt_intern_hash(hash, rth, &skb->rtable);
 }
 
@@ -2023,7 +2030,7 @@ local_input:
                rth->rt_flags   &= ~RTCF_LOCAL;
        }
        rth->rt_type    = res.type;
-       hash = rt_hash(daddr, saddr, fl.iif);
+       hash = rt_hash(daddr, saddr, fl.iif, atomic_read(&rt_genid));
        err = rt_intern_hash(hash, rth, &skb->rtable);
        goto done;
 
@@ -2042,8 +2049,8 @@ martian_destination:
        RT_CACHE_STAT_INC(in_martian_dst);
 #ifdef CONFIG_IP_ROUTE_VERBOSE
        if (IN_DEV_LOG_MARTIANS(in_dev) && net_ratelimit())
-               printk(KERN_WARNING "martian destination %u.%u.%u.%u from "
-                       "%u.%u.%u.%u, dev %s\n",
+               printk(KERN_WARNING "martian destination " NIPQUAD_FMT " from "
+                       NIPQUAD_FMT ", dev %s\n",
                        NIPQUAD(daddr), NIPQUAD(saddr), dev->name);
 #endif
 
@@ -2074,18 +2081,18 @@ int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
 
        net = dev_net(dev);
        tos &= IPTOS_RT_MASK;
-       hash = rt_hash(daddr, saddr, iif);
+       hash = rt_hash(daddr, saddr, iif, atomic_read(&rt_genid));
 
        rcu_read_lock();
        for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
             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 &&
+               if (((rth->fl.fl4_dst ^ daddr) |
+                    (rth->fl.fl4_src ^ saddr) |
+                    (rth->fl.iif ^ iif) |
+                    rth->fl.oif |
+                    (rth->fl.fl4_tos ^ tos)) == 0 &&
                    rth->fl.mark == skb->mark &&
-                   rth->fl.fl4_tos == tos &&
-                   dev_net(rth->u.dst.dev) == net &&
+                   net_eq(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);
@@ -2132,12 +2139,12 @@ int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
        return ip_route_input_slow(skb, daddr, saddr, tos, dev);
 }
 
-static inline int __mkroute_output(struct rtable **result,
-                                  struct fib_result* res,
-                                  const struct flowi *fl,
-                                  const struct flowi *oldflp,
-                                  struct net_device *dev_out,
-                                  unsigned flags)
+static int __mkroute_output(struct rtable **result,
+                           struct fib_result *res,
+                           const struct flowi *fl,
+                           const struct flowi *oldflp,
+                           struct net_device *dev_out,
+                           unsigned flags)
 {
        struct rtable *rth;
        struct in_device *in_dev;
@@ -2252,18 +2259,19 @@ static inline int __mkroute_output(struct rtable **result,
        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)
+static 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);
        unsigned hash;
        if (err == 0) {
-               hash = rt_hash(oldflp->fl4_dst, oldflp->fl4_src, oldflp->oif);
+               hash = rt_hash(oldflp->fl4_dst, oldflp->fl4_src, oldflp->oif,
+                              atomic_read(&rt_genid));
                err = rt_intern_hash(hash, rth, rp);
        }
 
@@ -2475,7 +2483,8 @@ int __ip_route_output_key(struct net *net, struct rtable **rp,
        unsigned hash;
        struct rtable *rth;
 
-       hash = rt_hash(flp->fl4_dst, flp->fl4_src, flp->oif);
+       hash = rt_hash(flp->fl4_dst, flp->fl4_src, flp->oif,
+                      atomic_read(&rt_genid));
 
        rcu_read_lock_bh();
        for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
@@ -2487,7 +2496,7 @@ int __ip_route_output_key(struct net *net, struct rtable **rp,
                    rth->fl.mark == flp->mark &&
                    !((rth->fl.fl4_tos ^ flp->fl4_tos) &
                            (IPTOS_RT_MASK | RTO_ONLINK)) &&
-                   dev_net(rth->u.dst.dev) == net &&
+                   net_eq(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);
@@ -2796,7 +2805,7 @@ int ip_rt_dump(struct sk_buff *skb,  struct netlink_callback *cb)
                rcu_read_lock_bh();
                for (rt = rcu_dereference(rt_hash_table[h].chain), idx = 0; rt;
                     rt = rcu_dereference(rt->u.dst.rt_next), idx++) {
-                       if (dev_net(rt->u.dst.dev) != net || idx < s_idx)
+                       if (!net_eq(dev_net(rt->u.dst.dev), net) || idx < s_idx)
                                continue;
                        if (rt->rt_genid != atomic_read(&rt_genid))
                                continue;
@@ -2822,19 +2831,27 @@ done:
 
 void ip_rt_multicast_event(struct in_device *in_dev)
 {
-       rt_cache_flush(0);
+       rt_cache_flush(dev_net(in_dev->dev), 0);
 }
 
 #ifdef CONFIG_SYSCTL
-static int flush_delay;
-
 static int ipv4_sysctl_rtcache_flush(ctl_table *ctl, int write,
                                        struct file *filp, void __user *buffer,
                                        size_t *lenp, loff_t *ppos)
 {
        if (write) {
+               int flush_delay;
+               struct net *net;
+               static DEFINE_MUTEX(flush_mutex);
+
+               mutex_lock(&flush_mutex);
+               ctl->data = &flush_delay;
                proc_dointvec(ctl, write, filp, buffer, lenp, ppos);
-               rt_cache_flush(flush_delay);
+               ctl->data = NULL;
+               mutex_unlock(&flush_mutex);
+
+               net = (struct net *)ctl->extra1;
+               rt_cache_flush(net, flush_delay);
                return 0;
        }
 
@@ -2850,25 +2867,18 @@ static int ipv4_sysctl_rtcache_flush_strategy(ctl_table *table,
                                                size_t newlen)
 {
        int delay;
+       struct net *net;
        if (newlen != sizeof(int))
                return -EINVAL;
        if (get_user(delay, (int __user *)newval))
                return -EFAULT;
-       rt_cache_flush(delay);
+       net = (struct net *)table->extra1;
+       rt_cache_flush(net, delay);
        return 0;
 }
 
 ctl_table ipv4_route_table[] = {
        {
-               .ctl_name       = NET_IPV4_ROUTE_FLUSH,
-               .procname       = "flush",
-               .data           = &flush_delay,
-               .maxlen         = sizeof(int),
-               .mode           = 0200,
-               .proc_handler   = &ipv4_sysctl_rtcache_flush,
-               .strategy       = &ipv4_sysctl_rtcache_flush_strategy,
-       },
-       {
                .ctl_name       = NET_IPV4_ROUTE_GC_THRESH,
                .procname       = "gc_thresh",
                .data           = &ipv4_dst_ops.gc_thresh,
@@ -3006,8 +3016,93 @@ ctl_table ipv4_route_table[] = {
        },
        { .ctl_name = 0 }
 };
+
+static __net_initdata struct ctl_path ipv4_route_path[] = {
+       { .procname = "net", .ctl_name = CTL_NET, },
+       { .procname = "ipv4", .ctl_name = NET_IPV4, },
+       { .procname = "route", .ctl_name = NET_IPV4_ROUTE, },
+       { },
+};
+
+
+static struct ctl_table ipv4_route_flush_table[] = {
+       {
+               .ctl_name       = NET_IPV4_ROUTE_FLUSH,
+               .procname       = "flush",
+               .maxlen         = sizeof(int),
+               .mode           = 0200,
+               .proc_handler   = &ipv4_sysctl_rtcache_flush,
+               .strategy       = &ipv4_sysctl_rtcache_flush_strategy,
+       },
+       { .ctl_name = 0 },
+};
+
+static __net_init int sysctl_route_net_init(struct net *net)
+{
+       struct ctl_table *tbl;
+
+       tbl = ipv4_route_flush_table;
+       if (net != &init_net) {
+               tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
+               if (tbl == NULL)
+                       goto err_dup;
+       }
+       tbl[0].extra1 = net;
+
+       net->ipv4.route_hdr =
+               register_net_sysctl_table(net, ipv4_route_path, tbl);
+       if (net->ipv4.route_hdr == NULL)
+               goto err_reg;
+       return 0;
+
+err_reg:
+       if (tbl != ipv4_route_flush_table)
+               kfree(tbl);
+err_dup:
+       return -ENOMEM;
+}
+
+static __net_exit void sysctl_route_net_exit(struct net *net)
+{
+       struct ctl_table *tbl;
+
+       tbl = net->ipv4.route_hdr->ctl_table_arg;
+       unregister_net_sysctl_table(net->ipv4.route_hdr);
+       BUG_ON(tbl == ipv4_route_flush_table);
+       kfree(tbl);
+}
+
+static __net_initdata struct pernet_operations sysctl_route_ops = {
+       .init = sysctl_route_net_init,
+       .exit = sysctl_route_net_exit,
+};
 #endif
 
+
+static __net_init int rt_secret_timer_init(struct net *net)
+{
+       net->ipv4.rt_secret_timer.function = rt_secret_rebuild;
+       net->ipv4.rt_secret_timer.data = (unsigned long)net;
+       init_timer_deferrable(&net->ipv4.rt_secret_timer);
+
+       net->ipv4.rt_secret_timer.expires =
+               jiffies + net_random() % ip_rt_secret_interval +
+               ip_rt_secret_interval;
+       add_timer(&net->ipv4.rt_secret_timer);
+       return 0;
+}
+
+static __net_exit void rt_secret_timer_exit(struct net *net)
+{
+       del_timer_sync(&net->ipv4.rt_secret_timer);
+}
+
+static __net_initdata struct pernet_operations rt_secret_timer_ops = {
+       .init = rt_secret_timer_init,
+       .exit = rt_secret_timer_exit,
+};
+
+
 #ifdef CONFIG_NET_CLS_ROUTE
 struct ip_rt_acct *ip_rt_acct __read_mostly;
 #endif /* CONFIG_NET_CLS_ROUTE */
@@ -3060,17 +3155,14 @@ int __init ip_rt_init(void)
        devinet_init();
        ip_fib_init();
 
-       setup_timer(&rt_secret_timer, rt_secret_rebuild, 0);
-
        /* All the timers, started at system startup tend
           to synchronize. Perturb it a bit.
         */
        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);
+       if (register_pernet_subsys(&rt_secret_timer_ops))
+               printk(KERN_ERR "Unable to setup rt_secret_timer\n");
 
        if (ip_rt_proc_init())
                printk(KERN_ERR "Unable to create route proc files\n");
@@ -3080,6 +3172,9 @@ int __init ip_rt_init(void)
 #endif
        rtnl_register(PF_INET, RTM_GETROUTE, inet_rtm_getroute, NULL);
 
+#ifdef CONFIG_SYSCTL
+       register_pernet_subsys(&sysctl_route_ops);
+#endif
        return rc;
 }