Commit 5ada5527 authored by David S. Miller's avatar David S. Miller

ipv4: Simplify output route creation call sequence.

There's a lot of redundancy and unnecessary stack frames
in the output route creation path.

1) Make __mkroute_output() return error pointers.

2) Eliminate ip_mkroute_output() entirely, made possible by #1.

3) Call __mkroute_output() directly and handling the returning error
   pointers in ip_route_output_slow().
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cf0bdefd
...@@ -2323,33 +2323,32 @@ int ip_route_input_common(struct sk_buff *skb, __be32 daddr, __be32 saddr, ...@@ -2323,33 +2323,32 @@ int ip_route_input_common(struct sk_buff *skb, __be32 daddr, __be32 saddr,
EXPORT_SYMBOL(ip_route_input_common); EXPORT_SYMBOL(ip_route_input_common);
/* called with rcu_read_lock() */ /* called with rcu_read_lock() */
static int __mkroute_output(struct rtable **result, static struct rtable *__mkroute_output(struct fib_result *res,
struct fib_result *res,
const struct flowi *fl, const struct flowi *fl,
const struct flowi *oldflp, const struct flowi *oldflp,
struct net_device *dev_out, struct net_device *dev_out,
unsigned flags) unsigned int flags)
{ {
struct rtable *rth;
struct in_device *in_dev;
u32 tos = RT_FL_TOS(oldflp); u32 tos = RT_FL_TOS(oldflp);
struct in_device *in_dev;
struct rtable *rth;
if (ipv4_is_loopback(fl->fl4_src) && !(dev_out->flags & IFF_LOOPBACK)) if (ipv4_is_loopback(fl->fl4_src) && !(dev_out->flags & IFF_LOOPBACK))
return -EINVAL; return ERR_PTR(-EINVAL);
if (ipv4_is_lbcast(fl->fl4_dst)) if (ipv4_is_lbcast(fl->fl4_dst))
res->type = RTN_BROADCAST; res->type = RTN_BROADCAST;
else if (ipv4_is_multicast(fl->fl4_dst)) else if (ipv4_is_multicast(fl->fl4_dst))
res->type = RTN_MULTICAST; res->type = RTN_MULTICAST;
else if (ipv4_is_zeronet(fl->fl4_dst)) else if (ipv4_is_zeronet(fl->fl4_dst))
return -EINVAL; return ERR_PTR(-EINVAL);
if (dev_out->flags & IFF_LOOPBACK) if (dev_out->flags & IFF_LOOPBACK)
flags |= RTCF_LOCAL; flags |= RTCF_LOCAL;
in_dev = __in_dev_get_rcu(dev_out); in_dev = __in_dev_get_rcu(dev_out);
if (!in_dev) if (!in_dev)
return -EINVAL; return ERR_PTR(-EINVAL);
if (res->type == RTN_BROADCAST) { if (res->type == RTN_BROADCAST) {
flags |= RTCF_BROADCAST | RTCF_LOCAL; flags |= RTCF_BROADCAST | RTCF_LOCAL;
...@@ -2370,7 +2369,7 @@ static int __mkroute_output(struct rtable **result, ...@@ -2370,7 +2369,7 @@ static int __mkroute_output(struct rtable **result,
rth = dst_alloc(&ipv4_dst_ops); rth = dst_alloc(&ipv4_dst_ops);
if (!rth) if (!rth)
return -ENOBUFS; return ERR_PTR(-ENOBUFS);
atomic_set(&rth->dst.__refcnt, 1); atomic_set(&rth->dst.__refcnt, 1);
rth->dst.flags= DST_HOST; rth->dst.flags= DST_HOST;
...@@ -2425,28 +2424,7 @@ static int __mkroute_output(struct rtable **result, ...@@ -2425,28 +2424,7 @@ static int __mkroute_output(struct rtable **result,
rt_set_nexthop(rth, res, 0); rt_set_nexthop(rth, res, 0);
rth->rt_flags = flags; rth->rt_flags = flags;
*result = rth; return rth;
return 0;
}
/* called with rcu_read_lock() */
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,
rt_genid(dev_net(dev_out)));
err = rt_intern_hash(hash, rth, rp, NULL, oldflp->oif);
}
return err;
} }
/* /*
...@@ -2469,6 +2447,7 @@ static int ip_route_output_slow(struct net *net, struct rtable **rp, ...@@ -2469,6 +2447,7 @@ static int ip_route_output_slow(struct net *net, struct rtable **rp,
struct fib_result res; struct fib_result res;
unsigned int flags = 0; unsigned int flags = 0;
struct net_device *dev_out = NULL; struct net_device *dev_out = NULL;
struct rtable *rth;
int err; int err;
...@@ -2627,7 +2606,16 @@ static int ip_route_output_slow(struct net *net, struct rtable **rp, ...@@ -2627,7 +2606,16 @@ static int ip_route_output_slow(struct net *net, struct rtable **rp,
make_route: make_route:
err = ip_mkroute_output(rp, &res, &fl, oldflp, dev_out, flags); rth = __mkroute_output(&res, &fl, oldflp, dev_out, flags);
if (IS_ERR(rth))
err = PTR_ERR(rth);
else {
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);
}
out: return err; out: return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment