]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - net/ipv4/route.c
ipv4: Remove flowi from struct rtable.
[mv-sheeva.git] / net / ipv4 / route.c
index 79a287181025423420fe63bb9cb788ba1da249e4..92a24ea34c1b22a243585c7c1657603416d97e42 100644 (file)
@@ -424,7 +424,7 @@ static int rt_cache_seq_show(struct seq_file *seq, void *v)
                        dst_metric(&r->dst, RTAX_WINDOW),
                        (int)((dst_metric(&r->dst, RTAX_RTT) >> 3) +
                              dst_metric(&r->dst, RTAX_RTTVAR)),
-                       r->fl.fl4_tos,
+                       r->rt_tos,
                        r->dst.hh ? atomic_read(&r->dst.hh->hh_refcnt) : -1,
                        r->dst.hh ? (r->dst.hh->hh_output ==
                                       dev_queue_xmit) : 0,
@@ -711,22 +711,22 @@ static inline bool rt_caching(const struct net *net)
                net->ipv4.sysctl_rt_cache_rebuild_count;
 }
 
-static inline bool compare_hash_inputs(const struct flowi *fl1,
-                                       const struct flowi *fl2)
+static inline bool compare_hash_inputs(const struct rtable *rt1,
+                                      const struct rtable *rt2)
 {
-       return ((((__force u32)fl1->fl4_dst ^ (__force u32)fl2->fl4_dst) |
-               ((__force u32)fl1->fl4_src ^ (__force u32)fl2->fl4_src) |
-               (fl1->iif ^ fl2->iif)) == 0);
+       return ((((__force u32)rt1->rt_key_dst ^ (__force u32)rt2->rt_key_dst) |
+               ((__force u32)rt1->rt_key_src ^ (__force u32)rt2->rt_key_src) |
+               (rt1->rt_iif ^ rt2->rt_iif)) == 0);
 }
 
-static inline int compare_keys(struct flowi *fl1, struct flowi *fl2)
+static inline int compare_keys(struct rtable *rt1, struct rtable *rt2)
 {
-       return (((__force u32)fl1->fl4_dst ^ (__force u32)fl2->fl4_dst) |
-               ((__force u32)fl1->fl4_src ^ (__force u32)fl2->fl4_src) |
-               (fl1->mark ^ fl2->mark) |
-               (*(u16 *)&fl1->fl4_tos ^ *(u16 *)&fl2->fl4_tos) |
-               (fl1->oif ^ fl2->oif) |
-               (fl1->iif ^ fl2->iif)) == 0;
+       return (((__force u32)rt1->rt_key_dst ^ (__force u32)rt2->rt_key_dst) |
+               ((__force u32)rt1->rt_key_src ^ (__force u32)rt2->rt_key_src) |
+               (rt1->rt_mark ^ rt2->rt_mark) |
+               (rt1->rt_tos ^ rt2->rt_tos) |
+               (rt1->rt_oif ^ rt2->rt_oif) |
+               (rt1->rt_iif ^ rt2->rt_iif)) == 0;
 }
 
 static inline int compare_netns(struct rtable *rt1, struct rtable *rt2)
@@ -813,7 +813,7 @@ static int has_noalias(const struct rtable *head, const struct rtable *rth)
        const struct rtable *aux = head;
 
        while (aux != rth) {
-               if (compare_hash_inputs(&aux->fl, &rth->fl))
+               if (compare_hash_inputs(aux, rth))
                        return 0;
                aux = rcu_dereference_protected(aux->dst.rt_next, 1);
        }
@@ -1014,8 +1014,8 @@ static int slow_chain_length(const struct rtable *head)
        return length >> FRACT_BITS;
 }
 
-static int rt_intern_hash(unsigned hash, struct rtable *rt,
-                         struct rtable **rp, struct sk_buff *skb, int ifindex)
+static struct rtable *rt_intern_hash(unsigned hash, struct rtable *rt,
+                                    struct sk_buff *skb, int ifindex)
 {
        struct rtable   *rth, *cand;
        struct rtable __rcu **rthp, **candp;
@@ -1056,7 +1056,7 @@ restart:
                                        printk(KERN_WARNING
                                            "Neighbour table failure & not caching routes.\n");
                                ip_rt_put(rt);
-                               return err;
+                               return ERR_PTR(err);
                        }
                }
 
@@ -1073,7 +1073,7 @@ restart:
                        rt_free(rth);
                        continue;
                }
-               if (compare_keys(&rth->fl, &rt->fl) && compare_netns(rth, rt)) {
+               if (compare_keys(rth, rt) && compare_netns(rth, rt)) {
                        /* Put it first */
                        *rthp = rth->dst.rt_next;
                        /*
@@ -1093,11 +1093,9 @@ restart:
                        spin_unlock_bh(rt_hash_lock_addr(hash));
 
                        rt_drop(rt);
-                       if (rp)
-                               *rp = rth;
-                       else
+                       if (skb)
                                skb_dst_set(skb, &rth->dst);
-                       return 0;
+                       return rth;
                }
 
                if (!atomic_read(&rth->dst.__refcnt)) {
@@ -1138,7 +1136,7 @@ restart:
                        rt_emergency_hash_rebuild(net);
                        spin_unlock_bh(rt_hash_lock_addr(hash));
 
-                       hash = rt_hash(rt->fl.fl4_dst, rt->fl.fl4_src,
+                       hash = rt_hash(rt->rt_key_dst, rt->rt_key_src,
                                        ifindex, rt_genid(net));
                        goto restart;
                }
@@ -1154,7 +1152,7 @@ restart:
 
                        if (err != -ENOBUFS) {
                                rt_drop(rt);
-                               return err;
+                               return ERR_PTR(err);
                        }
 
                        /* Neighbour tables are full and nothing
@@ -1175,7 +1173,7 @@ restart:
                        if (net_ratelimit())
                                printk(KERN_WARNING "ipv4: Neighbour table overflow.\n");
                        rt_drop(rt);
-                       return -ENOBUFS;
+                       return ERR_PTR(-ENOBUFS);
                }
        }
 
@@ -1201,11 +1199,9 @@ restart:
        spin_unlock_bh(rt_hash_lock_addr(hash));
 
 skip_hashing:
-       if (rp)
-               *rp = rt;
-       else
+       if (skb)
                skb_dst_set(skb, &rt->dst);
-       return 0;
+       return rt;
 }
 
 static atomic_t __rt_peer_genid = ATOMIC_INIT(0);
@@ -1348,12 +1344,12 @@ static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst)
                        ip_rt_put(rt);
                        ret = NULL;
                } else if (rt->rt_flags & RTCF_REDIRECTED) {
-                       unsigned hash = rt_hash(rt->fl.fl4_dst, rt->fl.fl4_src,
-                                               rt->fl.oif,
+                       unsigned hash = rt_hash(rt->rt_key_dst, rt->rt_key_src,
+                                               rt->rt_oif,
                                                rt_genid(dev_net(dst->dev)));
 #if RT_CACHE_DEBUG >= 1
                        printk(KERN_DEBUG "ipv4_negative_advice: redirect to %pI4/%02x dropped\n",
-                               &rt->rt_dst, rt->fl.fl4_tos);
+                               &rt->rt_dst, rt->rt_tos);
 #endif
                        rt_del(hash, rt);
                        ret = NULL;
@@ -1701,8 +1697,17 @@ void ip_rt_get_source(u8 *addr, struct rtable *rt)
        if (rt_is_output_route(rt))
                src = rt->rt_src;
        else {
+               struct flowi fl = {
+                       .fl4_dst = rt->rt_key_dst,
+                       .fl4_src = rt->rt_key_src,
+                       .fl4_tos = rt->rt_tos,
+                       .oif = rt->rt_oif,
+                       .iif = rt->rt_iif,
+                       .mark = rt->rt_mark,
+               };
+
                rcu_read_lock();
-               if (fib_lookup(dev_net(rt->dst.dev), &rt->fl, &res) == 0)
+               if (fib_lookup(dev_net(rt->dst.dev), &fl, &res) == 0)
                        src = FIB_RES_PREFSRC(res);
                else
                        src = inet_select_addr(rt->dst.dev, rt->rt_gateway,
@@ -1752,7 +1757,8 @@ static unsigned int ipv4_default_mtu(const struct dst_entry *dst)
        return mtu;
 }
 
-static void rt_init_metrics(struct rtable *rt, struct fib_info *fi)
+static void rt_init_metrics(struct rtable *rt, const struct flowi *oldflp,
+                           struct fib_info *fi)
 {
        struct inet_peer *peer;
        int create = 0;
@@ -1760,12 +1766,12 @@ static void rt_init_metrics(struct rtable *rt, struct fib_info *fi)
        /* If a peer entry exists for this destination, we must hook
         * it up in order to get at cached metrics.
         */
-       if (rt->fl.flags & FLOWI_FLAG_PRECOW_METRICS)
+       if (oldflp && (oldflp->flags & FLOWI_FLAG_PRECOW_METRICS))
                create = 1;
 
-       rt_bind_peer(rt, create);
-       peer = rt->peer;
+       rt->peer = peer = inet_getpeer_v4(rt->rt_dst, create);
        if (peer) {
+               rt->rt_peer_genid = rt_peer_genid();
                if (inet_metrics_new(peer))
                        memcpy(peer->metrics, fi->fib_metrics,
                               sizeof(u32) * RTAX_MAX);
@@ -1787,16 +1793,17 @@ static void rt_init_metrics(struct rtable *rt, struct fib_info *fi)
        }
 }
 
-static void rt_set_nexthop(struct rtable *rt, struct fib_result *res, u32 itag)
+static void rt_set_nexthop(struct rtable *rt, const struct flowi *oldflp,
+                          const struct fib_result *res,
+                          struct fib_info *fi, u16 type, u32 itag)
 {
        struct dst_entry *dst = &rt->dst;
-       struct fib_info *fi = res->fi;
 
        if (fi) {
                if (FIB_RES_GW(*res) &&
                    FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
                        rt->rt_gateway = FIB_RES_GW(*res);
-               rt_init_metrics(rt, fi);
+               rt_init_metrics(rt, oldflp, fi);
 #ifdef CONFIG_IP_ROUTE_CLASSID
                dst->tclassid = FIB_RES_NH(*res).nh_tclassid;
 #endif
@@ -1813,17 +1820,15 @@ 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 = type;
 }
 
 static struct rtable *rt_dst_alloc(bool nopolicy, bool noxfrm)
 {
-       struct rtable *rt = dst_alloc(&ipv4_dst_ops);
+       struct rtable *rt = dst_alloc(&ipv4_dst_ops, 1);
        if (rt) {
                rt->dst.obsolete = -1;
 
-               atomic_set(&rt->dst.__refcnt, 1);
-
                rt->dst.flags = DST_HOST |
                        (nopolicy ? DST_NOPOLICY : 0) |
                        (noxfrm ? DST_NOXFRM : 0);
@@ -1867,20 +1872,19 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
 
        rth->dst.output = ip_rt_bug;
 
-       rth->fl.fl4_dst = daddr;
+       rth->rt_key_dst = daddr;
        rth->rt_dst     = daddr;
-       rth->fl.fl4_tos = tos;
-       rth->fl.mark    = skb->mark;
-       rth->fl.fl4_src = saddr;
+       rth->rt_tos     = tos;
+       rth->rt_mark    = skb->mark;
+       rth->rt_key_src = saddr;
        rth->rt_src     = saddr;
 #ifdef CONFIG_IP_ROUTE_CLASSID
        rth->dst.tclassid = itag;
 #endif
-       rth->rt_iif     =
-       rth->fl.iif     = dev->ifindex;
+       rth->rt_iif     = dev->ifindex;
        rth->dst.dev    = init_net.loopback_dev;
        dev_hold(rth->dst.dev);
-       rth->fl.oif     = 0;
+       rth->rt_oif     = 0;
        rth->rt_gateway = daddr;
        rth->rt_spec_dst= spec_dst;
        rth->rt_genid   = rt_genid(dev_net(dev));
@@ -1898,7 +1902,10 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
        RT_CACHE_STAT_INC(in_slow_mc);
 
        hash = rt_hash(daddr, saddr, dev->ifindex, rt_genid(dev_net(dev)));
-       return rt_intern_hash(hash, rth, NULL, skb, dev->ifindex);
+       rth = rt_intern_hash(hash, rth, skb, dev->ifindex);
+       err = 0;
+       if (IS_ERR(rth))
+               err = PTR_ERR(rth);
 
 e_nobufs:
        return -ENOBUFS;
@@ -1941,7 +1948,7 @@ static void ip_handle_martian_source(struct net_device *dev,
 
 /* called in rcu_read_lock() section */
 static int __mkroute_input(struct sk_buff *skb,
-                          struct fib_result *res,
+                          const struct fib_result *res,
                           struct in_device *in_dev,
                           __be32 daddr, __be32 saddr, u32 tos,
                           struct rtable **result)
@@ -2002,25 +2009,24 @@ static int __mkroute_input(struct sk_buff *skb,
                goto cleanup;
        }
 
-       rth->fl.fl4_dst = daddr;
+       rth->rt_key_dst = daddr;
        rth->rt_dst     = daddr;
-       rth->fl.fl4_tos = tos;
-       rth->fl.mark    = skb->mark;
-       rth->fl.fl4_src = saddr;
+       rth->rt_tos     = tos;
+       rth->rt_mark    = skb->mark;
+       rth->rt_key_src = saddr;
        rth->rt_src     = saddr;
        rth->rt_gateway = daddr;
-       rth->rt_iif     =
-               rth->fl.iif     = in_dev->dev->ifindex;
+       rth->rt_iif     = in_dev->dev->ifindex;
        rth->dst.dev    = (out_dev)->dev;
        dev_hold(rth->dst.dev);
-       rth->fl.oif     = 0;
+       rth->rt_oif     = 0;
        rth->rt_spec_dst= spec_dst;
 
        rth->dst.input = ip_forward;
        rth->dst.output = ip_output;
        rth->rt_genid = rt_genid(dev_net(rth->dst.dev));
 
-       rt_set_nexthop(rth, res, itag);
+       rt_set_nexthop(rth, NULL, res, res->fi, res->type, itag);
 
        rth->rt_flags = flags;
 
@@ -2053,7 +2059,10 @@ static int ip_mkroute_input(struct sk_buff *skb,
        /* put it into the cache */
        hash = rt_hash(daddr, saddr, fl->iif,
                       rt_genid(dev_net(rth->dst.dev)));
-       return rt_intern_hash(hash, rth, NULL, skb, fl->iif);
+       rth = rt_intern_hash(hash, rth, skb, fl->iif);
+       if (IS_ERR(rth))
+               return PTR_ERR(rth);
+       return 0;
 }
 
 /*
@@ -2172,17 +2181,16 @@ local_input:
        rth->dst.output= ip_rt_bug;
        rth->rt_genid = rt_genid(net);
 
-       rth->fl.fl4_dst = daddr;
+       rth->rt_key_dst = daddr;
        rth->rt_dst     = daddr;
-       rth->fl.fl4_tos = tos;
-       rth->fl.mark    = skb->mark;
-       rth->fl.fl4_src = saddr;
+       rth->rt_tos     = tos;
+       rth->rt_mark    = skb->mark;
+       rth->rt_key_src = saddr;
        rth->rt_src     = saddr;
 #ifdef CONFIG_IP_ROUTE_CLASSID
        rth->dst.tclassid = itag;
 #endif
-       rth->rt_iif     =
-       rth->fl.iif     = dev->ifindex;
+       rth->rt_iif     = dev->ifindex;
        rth->dst.dev    = net->loopback_dev;
        dev_hold(rth->dst.dev);
        rth->rt_gateway = daddr;
@@ -2196,7 +2204,10 @@ local_input:
        }
        rth->rt_type    = res.type;
        hash = rt_hash(daddr, saddr, fl.iif, rt_genid(net));
-       err = rt_intern_hash(hash, rth, NULL, skb, fl.iif);
+       rth = rt_intern_hash(hash, rth, skb, fl.iif);
+       err = 0;
+       if (IS_ERR(rth))
+               err = PTR_ERR(rth);
        goto out;
 
 no_route:
@@ -2258,12 +2269,12 @@ int ip_route_input_common(struct sk_buff *skb, __be32 daddr, __be32 saddr,
 
        for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
             rth = rcu_dereference(rth->dst.rt_next)) {
-               if ((((__force u32)rth->fl.fl4_dst ^ (__force u32)daddr) |
-                    ((__force u32)rth->fl.fl4_src ^ (__force u32)saddr) |
-                    (rth->fl.iif ^ iif) |
-                    rth->fl.oif |
-                    (rth->fl.fl4_tos ^ tos)) == 0 &&
-                   rth->fl.mark == skb->mark &&
+               if ((((__force u32)rth->rt_key_dst ^ (__force u32)daddr) |
+                    ((__force u32)rth->rt_key_src ^ (__force u32)saddr) |
+                    (rth->rt_iif ^ iif) |
+                    rth->rt_oif |
+                    (rth->rt_tos ^ tos)) == 0 &&
+                   rth->rt_mark == skb->mark &&
                    net_eq(dev_net(rth->dst.dev), net) &&
                    !rt_is_expired(rth)) {
                        if (noref) {
@@ -2321,23 +2332,25 @@ skip_cache:
 EXPORT_SYMBOL(ip_route_input_common);
 
 /* called with rcu_read_lock() */
-static struct rtable *__mkroute_output(struct fib_result *res,
+static struct rtable *__mkroute_output(const struct fib_result *res,
                                       const struct flowi *fl,
                                       const struct flowi *oldflp,
                                       struct net_device *dev_out,
                                       unsigned int flags)
 {
+       struct fib_info *fi = res->fi;
        u32 tos = RT_FL_TOS(oldflp);
        struct in_device *in_dev;
+       u16 type = res->type;
        struct rtable *rth;
 
        if (ipv4_is_loopback(fl->fl4_src) && !(dev_out->flags & IFF_LOOPBACK))
                return ERR_PTR(-EINVAL);
 
        if (ipv4_is_lbcast(fl->fl4_dst))
-               res->type = RTN_BROADCAST;
+               type = RTN_BROADCAST;
        else if (ipv4_is_multicast(fl->fl4_dst))
-               res->type = RTN_MULTICAST;
+               type = RTN_MULTICAST;
        else if (ipv4_is_zeronet(fl->fl4_dst))
                return ERR_PTR(-EINVAL);
 
@@ -2348,10 +2361,10 @@ static struct rtable *__mkroute_output(struct fib_result *res,
        if (!in_dev)
                return ERR_PTR(-EINVAL);
 
-       if (res->type == RTN_BROADCAST) {
+       if (type == RTN_BROADCAST) {
                flags |= RTCF_BROADCAST | RTCF_LOCAL;
-               res->fi = NULL;
-       } else if (res->type == RTN_MULTICAST) {
+               fi = NULL;
+       } else if (type == RTN_MULTICAST) {
                flags |= RTCF_MULTICAST | RTCF_LOCAL;
                if (!ip_check_mc(in_dev, oldflp->fl4_dst, oldflp->fl4_src,
                                 oldflp->proto))
@@ -2360,8 +2373,8 @@ static struct rtable *__mkroute_output(struct fib_result *res,
                 * default one, but do not gateway in this case.
                 * Yes, it is hack.
                 */
-               if (res->fi && res->prefixlen < 4)
-                       res->fi = NULL;
+               if (fi && res->prefixlen < 4)
+                       fi = NULL;
        }
 
        rth = rt_dst_alloc(IN_DEV_CONF_GET(in_dev, NOPOLICY),
@@ -2369,14 +2382,14 @@ static struct rtable *__mkroute_output(struct fib_result *res,
        if (!rth)
                return ERR_PTR(-ENOBUFS);
 
-       rth->fl.fl4_dst = oldflp->fl4_dst;
-       rth->fl.fl4_tos = tos;
-       rth->fl.fl4_src = oldflp->fl4_src;
-       rth->fl.oif     = oldflp->oif;
-       rth->fl.mark    = oldflp->mark;
+       rth->rt_key_dst = oldflp->fl4_dst;
+       rth->rt_tos     = tos;
+       rth->rt_key_src = oldflp->fl4_src;
+       rth->rt_oif     = oldflp->oif;
+       rth->rt_mark    = oldflp->mark;
        rth->rt_dst     = fl->fl4_dst;
        rth->rt_src     = fl->fl4_src;
-       rth->rt_iif     = oldflp->oif ? : dev_out->ifindex;
+       rth->rt_iif     = 0;
        /* get references to the devices that are to be hold by the routing
           cache entry */
        rth->dst.dev    = dev_out;
@@ -2401,7 +2414,7 @@ static struct rtable *__mkroute_output(struct fib_result *res,
                        RT_CACHE_STAT_INC(out_slow_mc);
                }
 #ifdef CONFIG_IP_MROUTE
-               if (res->type == RTN_MULTICAST) {
+               if (type == RTN_MULTICAST) {
                        if (IN_DEV_MFORWARD(in_dev) &&
                            !ipv4_is_local_multicast(oldflp->fl4_dst)) {
                                rth->dst.input = ip_mr_input;
@@ -2411,7 +2424,7 @@ static struct rtable *__mkroute_output(struct fib_result *res,
 #endif
        }
 
-       rt_set_nexthop(rth, res, 0);
+       rt_set_nexthop(rth, oldflp, res, fi, type, 0);
 
        rth->rt_flags = flags;
        return rth;
@@ -2422,33 +2435,33 @@ static struct rtable *__mkroute_output(struct fib_result *res,
  * called with rcu_read_lock();
  */
 
-static int ip_route_output_slow(struct net *net, struct rtable **rp,
-                               const struct flowi *oldflp)
+static struct rtable *ip_route_output_slow(struct net *net,
+                                          const struct flowi *oldflp)
 {
        u32 tos = RT_FL_TOS(oldflp);
-       struct flowi fl = { .fl4_dst = oldflp->fl4_dst,
-                           .fl4_src = oldflp->fl4_src,
-                           .fl4_tos = tos & IPTOS_RT_MASK,
-                           .fl4_scope = ((tos & RTO_ONLINK) ?
-                                         RT_SCOPE_LINK : RT_SCOPE_UNIVERSE),
-                           .mark = oldflp->mark,
-                           .iif = net->loopback_dev->ifindex,
-                           .oif = oldflp->oif };
+       struct flowi fl;
        struct fib_result res;
        unsigned int flags = 0;
        struct net_device *dev_out = NULL;
        struct rtable *rth;
-       int err;
-
 
        res.fi          = NULL;
 #ifdef CONFIG_IP_MULTIPLE_TABLES
        res.r           = NULL;
 #endif
 
+       fl.oif = oldflp->oif;
+       fl.iif = net->loopback_dev->ifindex;
+       fl.mark = oldflp->mark;
+       fl.fl4_dst = oldflp->fl4_dst;
+       fl.fl4_src = oldflp->fl4_src;
+       fl.fl4_tos = tos & IPTOS_RT_MASK;
+       fl.fl4_scope = ((tos & RTO_ONLINK) ?
+                       RT_SCOPE_LINK : RT_SCOPE_UNIVERSE);
+
        rcu_read_lock();
        if (oldflp->fl4_src) {
-               err = -EINVAL;
+               rth = ERR_PTR(-EINVAL);
                if (ipv4_is_multicast(oldflp->fl4_src) ||
                    ipv4_is_lbcast(oldflp->fl4_src) ||
                    ipv4_is_zeronet(oldflp->fl4_src))
@@ -2499,13 +2512,13 @@ static int ip_route_output_slow(struct net *net, struct rtable **rp,
 
        if (oldflp->oif) {
                dev_out = dev_get_by_index_rcu(net, oldflp->oif);
-               err = -ENODEV;
+               rth = ERR_PTR(-ENODEV);
                if (dev_out == NULL)
                        goto out;
 
                /* RACE: Check return value of inet_select_addr instead. */
                if (!(dev_out->flags & IFF_UP) || !__in_dev_get_rcu(dev_out)) {
-                       err = -ENETUNREACH;
+                       rth = ERR_PTR(-ENETUNREACH);
                        goto out;
                }
                if (ipv4_is_local_multicast(oldflp->fl4_dst) ||
@@ -2563,7 +2576,7 @@ static int ip_route_output_slow(struct net *net, struct rtable **rp,
                        res.type = RTN_UNICAST;
                        goto make_route;
                }
-               err = -ENETUNREACH;
+               rth = ERR_PTR(-ENETUNREACH);
                goto out;
        }
 
@@ -2598,23 +2611,20 @@ static int ip_route_output_slow(struct net *net, struct rtable **rp,
 
 make_route:
        rth = __mkroute_output(&res, &fl, oldflp, dev_out, flags);
-       if (IS_ERR(rth))
-               err = PTR_ERR(rth);
-       else {
+       if (!IS_ERR(rth)) {
                unsigned int hash;
 
                hash = rt_hash(oldflp->fl4_dst, oldflp->fl4_src, oldflp->oif,
                               rt_genid(dev_net(dev_out)));
-               err = rt_intern_hash(hash, rth, rp, NULL, oldflp->oif);
+               rth = rt_intern_hash(hash, rth, NULL, oldflp->oif);
        }
 
 out:
        rcu_read_unlock();
-       return err;
+       return rth;
 }
 
-int __ip_route_output_key(struct net *net, struct rtable **rp,
-                         const struct flowi *flp)
+struct rtable *__ip_route_output_key(struct net *net, const struct flowi *flp)
 {
        struct rtable *rth;
        unsigned int hash;
@@ -2627,27 +2637,26 @@ int __ip_route_output_key(struct net *net, struct rtable **rp,
        rcu_read_lock_bh();
        for (rth = rcu_dereference_bh(rt_hash_table[hash].chain); rth;
                rth = rcu_dereference_bh(rth->dst.rt_next)) {
-               if (rth->fl.fl4_dst == flp->fl4_dst &&
-                   rth->fl.fl4_src == flp->fl4_src &&
+               if (rth->rt_key_dst == flp->fl4_dst &&
+                   rth->rt_key_src == flp->fl4_src &&
                    rt_is_output_route(rth) &&
-                   rth->fl.oif == flp->oif &&
-                   rth->fl.mark == flp->mark &&
-                   !((rth->fl.fl4_tos ^ flp->fl4_tos) &
+                   rth->rt_oif == flp->oif &&
+                   rth->rt_mark == flp->mark &&
+                   !((rth->rt_tos ^ flp->fl4_tos) &
                            (IPTOS_RT_MASK | RTO_ONLINK)) &&
                    net_eq(dev_net(rth->dst.dev), net) &&
                    !rt_is_expired(rth)) {
                        dst_use(&rth->dst, jiffies);
                        RT_CACHE_STAT_INC(out_hit);
                        rcu_read_unlock_bh();
-                       *rp = rth;
-                       return 0;
+                       return rth;
                }
                RT_CACHE_STAT_INC(out_hlist_search);
        }
        rcu_read_unlock_bh();
 
 slow_output:
-       return ip_route_output_slow(net, rp, flp);
+       return ip_route_output_slow(net, flp);
 }
 EXPORT_SYMBOL_GPL(__ip_route_output_key);
 
@@ -2671,20 +2680,18 @@ static struct dst_ops ipv4_dst_blackhole_ops = {
        .destroy                =       ipv4_dst_destroy,
        .check                  =       ipv4_blackhole_dst_check,
        .default_mtu            =       ipv4_blackhole_default_mtu,
+       .default_advmss         =       ipv4_default_advmss,
        .update_pmtu            =       ipv4_rt_blackhole_update_pmtu,
 };
 
-
-static int ipv4_dst_blackhole(struct net *net, struct rtable **rp, struct flowi *flp)
+struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_orig)
 {
-       struct rtable *ort = *rp;
-       struct rtable *rt = (struct rtable *)
-               dst_alloc(&ipv4_dst_blackhole_ops);
+       struct rtable *rt = dst_alloc(&ipv4_dst_blackhole_ops, 1);
+       struct rtable *ort = (struct rtable *) dst_orig;
 
        if (rt) {
                struct dst_entry *new = &rt->dst;
 
-               atomic_set(&new->__refcnt, 1);
                new->__use = 1;
                new->input = dst_discard;
                new->output = dst_discard;
@@ -2694,7 +2701,12 @@ static int ipv4_dst_blackhole(struct net *net, struct rtable **rp, struct flowi
                if (new->dev)
                        dev_hold(new->dev);
 
-               rt->fl = ort->fl;
+               rt->rt_key_dst = ort->rt_key_dst;
+               rt->rt_key_src = ort->rt_key_src;
+               rt->rt_tos = ort->rt_tos;
+               rt->rt_iif = ort->rt_iif;
+               rt->rt_oif = ort->rt_oif;
+               rt->rt_mark = ort->rt_mark;
 
                rt->rt_genid = rt_genid(net);
                rt->rt_flags = ort->rt_flags;
@@ -2714,42 +2726,31 @@ static int ipv4_dst_blackhole(struct net *net, struct rtable **rp, struct flowi
                dst_free(new);
        }
 
-       dst_release(&(*rp)->dst);
-       *rp = rt;
-       return rt ? 0 : -ENOMEM;
+       dst_release(dst_orig);
+
+       return rt ? &rt->dst : ERR_PTR(-ENOMEM);
 }
 
-int ip_route_output_flow(struct net *net, struct rtable **rp, struct flowi *flp,
-                        struct sock *sk, int flags)
+struct rtable *ip_route_output_flow(struct net *net, struct flowi *flp,
+                                   struct sock *sk)
 {
-       int err;
+       struct rtable *rt = __ip_route_output_key(net, flp);
 
-       if ((err = __ip_route_output_key(net, rp, flp)) != 0)
-               return err;
+       if (IS_ERR(rt))
+               return rt;
 
        if (flp->proto) {
                if (!flp->fl4_src)
-                       flp->fl4_src = (*rp)->rt_src;
+                       flp->fl4_src = rt->rt_src;
                if (!flp->fl4_dst)
-                       flp->fl4_dst = (*rp)->rt_dst;
-               err = __xfrm_lookup(net, (struct dst_entry **)rp, flp, sk,
-                                   flags ? XFRM_LOOKUP_WAIT : 0);
-               if (err == -EREMOTE)
-                       err = ipv4_dst_blackhole(net, rp, flp);
-
-               return err;
+                       flp->fl4_dst = rt->rt_dst;
+               rt = (struct rtable *) xfrm_lookup(net, &rt->dst, flp, sk, 0);
        }
 
-       return 0;
+       return rt;
 }
 EXPORT_SYMBOL_GPL(ip_route_output_flow);
 
-int ip_route_output_key(struct net *net, struct rtable **rp, struct flowi *flp)
-{
-       return ip_route_output_flow(net, rp, flp, NULL, 0);
-}
-EXPORT_SYMBOL(ip_route_output_key);
-
 static int rt_fill_info(struct net *net,
                        struct sk_buff *skb, u32 pid, u32 seq, int event,
                        int nowait, unsigned int flags)
@@ -2768,7 +2769,7 @@ static int rt_fill_info(struct net *net,
        r->rtm_family    = AF_INET;
        r->rtm_dst_len  = 32;
        r->rtm_src_len  = 0;
-       r->rtm_tos      = rt->fl.fl4_tos;
+       r->rtm_tos      = rt->rt_tos;
        r->rtm_table    = RT_TABLE_MAIN;
        NLA_PUT_U32(skb, RTA_TABLE, RT_TABLE_MAIN);
        r->rtm_type     = rt->rt_type;
@@ -2780,9 +2781,9 @@ static int rt_fill_info(struct net *net,
 
        NLA_PUT_BE32(skb, RTA_DST, rt->rt_dst);
 
-       if (rt->fl.fl4_src) {
+       if (rt->rt_key_src) {
                r->rtm_src_len = 32;
-               NLA_PUT_BE32(skb, RTA_SRC, rt->fl.fl4_src);
+               NLA_PUT_BE32(skb, RTA_SRC, rt->rt_key_src);
        }
        if (rt->dst.dev)
                NLA_PUT_U32(skb, RTA_OIF, rt->dst.dev->ifindex);
@@ -2792,7 +2793,7 @@ static int rt_fill_info(struct net *net,
 #endif
        if (rt_is_input_route(rt))
                NLA_PUT_BE32(skb, RTA_PREFSRC, rt->rt_spec_dst);
-       else if (rt->rt_src != rt->fl.fl4_src)
+       else if (rt->rt_src != rt->rt_key_src)
                NLA_PUT_BE32(skb, RTA_PREFSRC, rt->rt_src);
 
        if (rt->rt_dst != rt->rt_gateway)
@@ -2801,8 +2802,8 @@ static int rt_fill_info(struct net *net,
        if (rtnetlink_put_metrics(skb, dst_metrics_ptr(&rt->dst)) < 0)
                goto nla_put_failure;
 
-       if (rt->fl.mark)
-               NLA_PUT_BE32(skb, RTA_MARK, rt->fl.mark);
+       if (rt->rt_mark)
+               NLA_PUT_BE32(skb, RTA_MARK, rt->rt_mark);
 
        error = rt->dst.error;
        expires = (rt->peer && rt->peer->pmtu_expires) ?
@@ -2836,7 +2837,7 @@ static int rt_fill_info(struct net *net,
                        }
                } else
 #endif
-                       NLA_PUT_U32(skb, RTA_IIF, rt->fl.iif);
+                       NLA_PUT_U32(skb, RTA_IIF, rt->rt_iif);
        }
 
        if (rtnl_put_cacheinfo(skb, &rt->dst, id, ts, tsage,
@@ -2917,7 +2918,11 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void
                        .oif = tb[RTA_OIF] ? nla_get_u32(tb[RTA_OIF]) : 0,
                        .mark = mark,
                };
-               err = ip_route_output_key(net, &rt, &fl);
+               rt = ip_route_output_key(net, &fl);
+
+               err = 0;
+               if (IS_ERR(rt))
+                       err = PTR_ERR(rt);
        }
 
        if (err)