Commit 452edd59 authored by David S. Miller's avatar David S. Miller

xfrm: Return dst directly from xfrm_lookup()

Instead of on the stack.
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3872b284
...@@ -426,15 +426,17 @@ enum { ...@@ -426,15 +426,17 @@ enum {
struct flowi; struct flowi;
#ifndef CONFIG_XFRM #ifndef CONFIG_XFRM
static inline int xfrm_lookup(struct net *net, struct dst_entry **dst_p, static inline struct dst_entry *xfrm_lookup(struct net *net,
struct dst_entry *dst_orig,
const struct flowi *fl, struct sock *sk, const struct flowi *fl, struct sock *sk,
int flags) int flags)
{ {
return 0; return dst_orig;
} }
#else #else
extern int xfrm_lookup(struct net *net, struct dst_entry **dst_p, extern struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
const struct flowi *fl, struct sock *sk, int flags); const struct flowi *fl, struct sock *sk,
int flags);
#endif #endif
#endif #endif
......
...@@ -1222,7 +1222,11 @@ static int dn_route_output_key(struct dst_entry **pprt, struct flowi *flp, int f ...@@ -1222,7 +1222,11 @@ static int dn_route_output_key(struct dst_entry **pprt, struct flowi *flp, int f
err = __dn_route_output_key(pprt, flp, flags); err = __dn_route_output_key(pprt, flp, flags);
if (err == 0 && flp->proto) { if (err == 0 && flp->proto) {
err = xfrm_lookup(&init_net, pprt, flp, NULL, 0); *pprt = xfrm_lookup(&init_net, *pprt, flp, NULL, 0);
if (IS_ERR(*pprt)) {
err = PTR_ERR(*pprt);
*pprt = NULL;
}
} }
return err; return err;
} }
...@@ -1235,7 +1239,11 @@ int dn_route_output_sock(struct dst_entry **pprt, struct flowi *fl, struct sock ...@@ -1235,7 +1239,11 @@ int dn_route_output_sock(struct dst_entry **pprt, struct flowi *fl, struct sock
if (err == 0 && fl->proto) { if (err == 0 && fl->proto) {
if (!(flags & MSG_DONTWAIT)) if (!(flags & MSG_DONTWAIT))
fl->flags |= FLOWI_FLAG_CAN_SLEEP; fl->flags |= FLOWI_FLAG_CAN_SLEEP;
err = xfrm_lookup(&init_net, pprt, fl, sk, 0); *pprt = xfrm_lookup(&init_net, *pprt, fl, sk, 0);
if (IS_ERR(*pprt)) {
err = PTR_ERR(*pprt);
*pprt = NULL;
}
} }
return err; return err;
} }
......
...@@ -398,18 +398,14 @@ static struct rtable *icmp_route_lookup(struct net *net, struct sk_buff *skb_in, ...@@ -398,18 +398,14 @@ static struct rtable *icmp_route_lookup(struct net *net, struct sk_buff *skb_in,
if (!fl.fl4_src) if (!fl.fl4_src)
fl.fl4_src = rt->rt_src; fl.fl4_src = rt->rt_src;
err = xfrm_lookup(net, (struct dst_entry **)&rt, &fl, NULL, 0); rt = (struct rtable *) xfrm_lookup(net, &rt->dst, &fl, NULL, 0);
switch (err) { if (!IS_ERR(rt)) {
case 0:
if (rt != rt2) if (rt != rt2)
return rt; return rt;
break; } else if (PTR_ERR(rt) == -EPERM) {
case -EPERM:
rt = NULL; rt = NULL;
break; } else
default: return rt;
return ERR_PTR(err);
}
err = xfrm_decode_session_reverse(skb_in, &fl, AF_INET); err = xfrm_decode_session_reverse(skb_in, &fl, AF_INET);
if (err) if (err)
...@@ -438,22 +434,18 @@ static struct rtable *icmp_route_lookup(struct net *net, struct sk_buff *skb_in, ...@@ -438,22 +434,18 @@ static struct rtable *icmp_route_lookup(struct net *net, struct sk_buff *skb_in,
if (err) if (err)
goto relookup_failed; goto relookup_failed;
err = xfrm_lookup(net, (struct dst_entry **)&rt2, &fl, NULL, rt2 = (struct rtable *) xfrm_lookup(net, &rt2->dst, &fl, NULL, XFRM_LOOKUP_ICMP);
XFRM_LOOKUP_ICMP); if (!IS_ERR(rt2)) {
switch (err) {
case 0:
dst_release(&rt->dst); dst_release(&rt->dst);
rt = rt2; rt = rt2;
break; } else if (PTR_ERR(rt2) == -EPERM) {
case -EPERM: if (rt)
return ERR_PTR(err); dst_release(&rt->dst);
default: return rt2;
if (!rt) } else {
return ERR_PTR(err); err = PTR_ERR(rt2);
break; goto relookup_failed;
} }
return rt; return rt;
relookup_failed: relookup_failed:
......
...@@ -69,7 +69,8 @@ int ip_route_me_harder(struct sk_buff *skb, unsigned addr_type) ...@@ -69,7 +69,8 @@ int ip_route_me_harder(struct sk_buff *skb, unsigned addr_type)
xfrm_decode_session(skb, &fl, AF_INET) == 0) { xfrm_decode_session(skb, &fl, AF_INET) == 0) {
struct dst_entry *dst = skb_dst(skb); struct dst_entry *dst = skb_dst(skb);
skb_dst_set(skb, NULL); skb_dst_set(skb, NULL);
if (xfrm_lookup(net, &dst, &fl, skb->sk, 0)) dst = xfrm_lookup(net, dst, &fl, skb->sk, 0);
if (IS_ERR(dst))
return -1; return -1;
skb_dst_set(skb, dst); skb_dst_set(skb, dst);
} }
...@@ -102,7 +103,8 @@ int ip_xfrm_me_harder(struct sk_buff *skb) ...@@ -102,7 +103,8 @@ int ip_xfrm_me_harder(struct sk_buff *skb)
dst = ((struct xfrm_dst *)dst)->route; dst = ((struct xfrm_dst *)dst)->route;
dst_hold(dst); dst_hold(dst);
if (xfrm_lookup(dev_net(dst->dev), &dst, &fl, skb->sk, 0) < 0) dst = xfrm_lookup(dev_net(dst->dev), dst, &fl, skb->sk, 0);
if (IS_ERR(dst))
return -1; return -1;
skb_dst_drop(skb); skb_dst_drop(skb);
......
...@@ -2730,7 +2730,12 @@ int ip_route_output_flow(struct net *net, struct rtable **rp, struct flowi *flp, ...@@ -2730,7 +2730,12 @@ int ip_route_output_flow(struct net *net, struct rtable **rp, struct flowi *flp,
flp->fl4_src = (*rp)->rt_src; flp->fl4_src = (*rp)->rt_src;
if (!flp->fl4_dst) if (!flp->fl4_dst)
flp->fl4_dst = (*rp)->rt_dst; flp->fl4_dst = (*rp)->rt_dst;
return xfrm_lookup(net, (struct dst_entry **)rp, flp, sk, 0); *rp = (struct rtable *) xfrm_lookup(net, &(*rp)->dst, flp, sk, 0);
if (IS_ERR(*rp)) {
err = PTR_ERR(*rp);
*rp = NULL;
return err;
}
} }
return 0; return 0;
......
...@@ -324,17 +324,15 @@ static struct dst_entry *icmpv6_route_lookup(struct net *net, struct sk_buff *sk ...@@ -324,17 +324,15 @@ static struct dst_entry *icmpv6_route_lookup(struct net *net, struct sk_buff *sk
/* No need to clone since we're just using its address. */ /* No need to clone since we're just using its address. */
dst2 = dst; dst2 = dst;
err = xfrm_lookup(net, &dst, fl, sk, 0); dst = xfrm_lookup(net, dst, fl, sk, 0);
switch (err) { if (!IS_ERR(dst)) {
case 0:
if (dst != dst2) if (dst != dst2)
return dst; return dst;
break; } else {
case -EPERM: if (PTR_ERR(dst) == -EPERM)
dst = NULL; dst = NULL;
break; else
default: return dst;
return ERR_PTR(err);
} }
err = xfrm_decode_session_reverse(skb, &fl2, AF_INET6); err = xfrm_decode_session_reverse(skb, &fl2, AF_INET6);
...@@ -345,16 +343,16 @@ static struct dst_entry *icmpv6_route_lookup(struct net *net, struct sk_buff *sk ...@@ -345,16 +343,16 @@ static struct dst_entry *icmpv6_route_lookup(struct net *net, struct sk_buff *sk
if (err) if (err)
goto relookup_failed; goto relookup_failed;
err = xfrm_lookup(net, &dst2, &fl2, sk, XFRM_LOOKUP_ICMP); dst2 = xfrm_lookup(net, dst2, &fl2, sk, XFRM_LOOKUP_ICMP);
switch (err) { if (!IS_ERR(dst2)) {
case 0:
dst_release(dst); dst_release(dst);
dst = dst2; dst = dst2;
break; } else {
case -EPERM: err = PTR_ERR(dst2);
if (err == -EPERM) {
dst_release(dst); dst_release(dst);
return ERR_PTR(err); return dst2;
default: } else
goto relookup_failed; goto relookup_failed;
} }
...@@ -560,7 +558,8 @@ static void icmpv6_echo_reply(struct sk_buff *skb) ...@@ -560,7 +558,8 @@ static void icmpv6_echo_reply(struct sk_buff *skb)
err = ip6_dst_lookup(sk, &dst, &fl); err = ip6_dst_lookup(sk, &dst, &fl);
if (err) if (err)
goto out; goto out;
if ((err = xfrm_lookup(net, &dst, &fl, sk, 0)) < 0) dst = xfrm_lookup(net, dst, &fl, sk, 0);
if (IS_ERR(dst))
goto out; goto out;
if (ipv6_addr_is_multicast(&fl.fl6_dst)) if (ipv6_addr_is_multicast(&fl.fl6_dst))
......
...@@ -1028,10 +1028,7 @@ struct dst_entry *ip6_dst_lookup_flow(struct sock *sk, struct flowi *fl, ...@@ -1028,10 +1028,7 @@ struct dst_entry *ip6_dst_lookup_flow(struct sock *sk, struct flowi *fl,
if (can_sleep) if (can_sleep)
fl->flags |= FLOWI_FLAG_CAN_SLEEP; fl->flags |= FLOWI_FLAG_CAN_SLEEP;
err = xfrm_lookup(sock_net(sk), &dst, fl, sk, 0); return xfrm_lookup(sock_net(sk), dst, fl, sk, 0);
if (err)
return ERR_PTR(err);
return dst;
} }
EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow); EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow);
...@@ -1067,10 +1064,7 @@ struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi *fl, ...@@ -1067,10 +1064,7 @@ struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi *fl,
if (can_sleep) if (can_sleep)
fl->flags |= FLOWI_FLAG_CAN_SLEEP; fl->flags |= FLOWI_FLAG_CAN_SLEEP;
err = xfrm_lookup(sock_net(sk), &dst, fl, sk, 0); return xfrm_lookup(sock_net(sk), dst, fl, sk, 0);
if (err)
return ERR_PTR(err);
return dst;
} }
EXPORT_SYMBOL_GPL(ip6_sk_dst_lookup_flow); EXPORT_SYMBOL_GPL(ip6_sk_dst_lookup_flow);
......
...@@ -903,8 +903,14 @@ static int ip6_tnl_xmit2(struct sk_buff *skb, ...@@ -903,8 +903,14 @@ static int ip6_tnl_xmit2(struct sk_buff *skb,
else { else {
dst = ip6_route_output(net, NULL, fl); dst = ip6_route_output(net, NULL, fl);
if (dst->error || xfrm_lookup(net, &dst, fl, NULL, 0) < 0) if (dst->error)
goto tx_err_link_failure; goto tx_err_link_failure;
dst = xfrm_lookup(net, dst, fl, NULL, 0);
if (IS_ERR(dst)) {
err = PTR_ERR(dst);
dst = NULL;
goto tx_err_link_failure;
}
} }
tdev = dst->dev; tdev = dst->dev;
......
...@@ -1429,7 +1429,12 @@ static void mld_sendpack(struct sk_buff *skb) ...@@ -1429,7 +1429,12 @@ static void mld_sendpack(struct sk_buff *skb)
&ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr, &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr,
skb->dev->ifindex); skb->dev->ifindex);
err = xfrm_lookup(net, &dst, &fl, NULL, 0); dst = xfrm_lookup(net, dst, &fl, NULL, 0);
err = 0;
if (IS_ERR(dst)) {
err = PTR_ERR(dst);
dst = NULL;
}
skb_dst_set(skb, dst); skb_dst_set(skb, dst);
if (err) if (err)
goto err_out; goto err_out;
...@@ -1796,9 +1801,11 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type) ...@@ -1796,9 +1801,11 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
&ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr, &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr,
skb->dev->ifindex); skb->dev->ifindex);
err = xfrm_lookup(net, &dst, &fl, NULL, 0); dst = xfrm_lookup(net, dst, &fl, NULL, 0);
if (err) if (IS_ERR(dst)) {
err = PTR_ERR(dst);
goto err_out; goto err_out;
}
skb_dst_set(skb, dst); skb_dst_set(skb, dst);
err = NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, skb, NULL, skb->dev, err = NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, skb, NULL, skb->dev,
......
...@@ -529,8 +529,8 @@ void ndisc_send_skb(struct sk_buff *skb, ...@@ -529,8 +529,8 @@ void ndisc_send_skb(struct sk_buff *skb,
return; return;
} }
err = xfrm_lookup(net, &dst, &fl, NULL, 0); dst = xfrm_lookup(net, dst, &fl, NULL, 0);
if (err < 0) { if (IS_ERR(dst)) {
kfree_skb(skb); kfree_skb(skb);
return; return;
} }
...@@ -1542,8 +1542,8 @@ void ndisc_send_redirect(struct sk_buff *skb, struct neighbour *neigh, ...@@ -1542,8 +1542,8 @@ void ndisc_send_redirect(struct sk_buff *skb, struct neighbour *neigh,
if (dst == NULL) if (dst == NULL)
return; return;
err = xfrm_lookup(net, &dst, &fl, NULL, 0); dst = xfrm_lookup(net, dst, &fl, NULL, 0);
if (err) if (IS_ERR(dst))
return; return;
rt = (struct rt6_info *) dst; rt = (struct rt6_info *) dst;
......
...@@ -39,7 +39,8 @@ int ip6_route_me_harder(struct sk_buff *skb) ...@@ -39,7 +39,8 @@ int ip6_route_me_harder(struct sk_buff *skb)
if (!(IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED) && if (!(IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED) &&
xfrm_decode_session(skb, &fl, AF_INET6) == 0) { xfrm_decode_session(skb, &fl, AF_INET6) == 0) {
skb_dst_set(skb, NULL); skb_dst_set(skb, NULL);
if (xfrm_lookup(net, &dst, &fl, skb->sk, 0)) dst = xfrm_lookup(net, dst, &fl, skb->sk, 0);
if (IS_ERR(dst))
return -1; return -1;
skb_dst_set(skb, dst); skb_dst_set(skb, dst);
} }
......
...@@ -101,7 +101,8 @@ static void send_reset(struct net *net, struct sk_buff *oldskb) ...@@ -101,7 +101,8 @@ static void send_reset(struct net *net, struct sk_buff *oldskb)
dst_release(dst); dst_release(dst);
return; return;
} }
if (xfrm_lookup(net, &dst, &fl, NULL, 0)) dst = xfrm_lookup(net, dst, &fl, NULL, 0);
if (IS_ERR(dst))
return; return;
hh_len = (dst->dev->hard_header_len + 15)&~15; hh_len = (dst->dev->hard_header_len + 15)&~15;
......
...@@ -218,8 +218,13 @@ __ip_vs_route_output_v6(struct net *net, struct in6_addr *daddr, ...@@ -218,8 +218,13 @@ __ip_vs_route_output_v6(struct net *net, struct in6_addr *daddr,
ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev, ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
&fl.fl6_dst, 0, &fl.fl6_src) < 0) &fl.fl6_dst, 0, &fl.fl6_src) < 0)
goto out_err; goto out_err;
if (do_xfrm && xfrm_lookup(net, &dst, &fl, NULL, 0) < 0) if (do_xfrm) {
dst = xfrm_lookup(net, dst, &fl, NULL, 0);
if (IS_ERR(dst)) {
dst = NULL;
goto out_err; goto out_err;
}
}
ipv6_addr_copy(ret_saddr, &fl.fl6_src); ipv6_addr_copy(ret_saddr, &fl.fl6_src);
return dst; return dst;
......
...@@ -1757,14 +1757,14 @@ static struct dst_entry *make_blackhole(struct net *net, u16 family, ...@@ -1757,14 +1757,14 @@ static struct dst_entry *make_blackhole(struct net *net, u16 family,
* At the moment we eat a raw IP route. Mostly to speed up lookups * At the moment we eat a raw IP route. Mostly to speed up lookups
* on interfaces with disabled IPsec. * on interfaces with disabled IPsec.
*/ */
int xfrm_lookup(struct net *net, struct dst_entry **dst_p, struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
const struct flowi *fl, const struct flowi *fl,
struct sock *sk, int flags) struct sock *sk, int flags)
{ {
struct xfrm_policy *pols[XFRM_POLICY_TYPE_MAX]; struct xfrm_policy *pols[XFRM_POLICY_TYPE_MAX];
struct flow_cache_object *flo; struct flow_cache_object *flo;
struct xfrm_dst *xdst; struct xfrm_dst *xdst;
struct dst_entry *dst, *dst_orig = *dst_p, *route; struct dst_entry *dst, *route;
u16 family = dst_orig->ops->family; u16 family = dst_orig->ops->family;
u8 dir = policy_to_flow_dir(XFRM_POLICY_OUT); u8 dir = policy_to_flow_dir(XFRM_POLICY_OUT);
int i, err, num_pols, num_xfrms = 0, drop_pols = 0; int i, err, num_pols, num_xfrms = 0, drop_pols = 0;
...@@ -1847,11 +1847,7 @@ int xfrm_lookup(struct net *net, struct dst_entry **dst_p, ...@@ -1847,11 +1847,7 @@ int xfrm_lookup(struct net *net, struct dst_entry **dst_p,
xfrm_pols_put(pols, drop_pols); xfrm_pols_put(pols, drop_pols);
XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTNOSTATES); XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTNOSTATES);
dst = make_blackhole(net, family, dst_orig); return make_blackhole(net, family, dst_orig);
if (IS_ERR(dst))
return PTR_ERR(dst);
*dst_p = dst;
return 0;
} }
if (fl->flags & FLOWI_FLAG_CAN_SLEEP) { if (fl->flags & FLOWI_FLAG_CAN_SLEEP) {
DECLARE_WAITQUEUE(wait, current); DECLARE_WAITQUEUE(wait, current);
...@@ -1895,27 +1891,28 @@ int xfrm_lookup(struct net *net, struct dst_entry **dst_p, ...@@ -1895,27 +1891,28 @@ int xfrm_lookup(struct net *net, struct dst_entry **dst_p,
goto error; goto error;
} else if (num_xfrms > 0) { } else if (num_xfrms > 0) {
/* Flow transformed */ /* Flow transformed */
*dst_p = dst;
dst_release(dst_orig); dst_release(dst_orig);
} else { } else {
/* Flow passes untransformed */ /* Flow passes untransformed */
dst_release(dst); dst_release(dst);
dst = dst_orig;
} }
ok: ok:
xfrm_pols_put(pols, drop_pols); xfrm_pols_put(pols, drop_pols);
return 0; return dst;
nopol: nopol:
if (!(flags & XFRM_LOOKUP_ICMP)) if (!(flags & XFRM_LOOKUP_ICMP)) {
dst = dst_orig;
goto ok; goto ok;
}
err = -ENOENT; err = -ENOENT;
error: error:
dst_release(dst); dst_release(dst);
dropdst: dropdst:
dst_release(dst_orig); dst_release(dst_orig);
*dst_p = NULL;
xfrm_pols_put(pols, drop_pols); xfrm_pols_put(pols, drop_pols);
return err; return ERR_PTR(err);
} }
EXPORT_SYMBOL(xfrm_lookup); EXPORT_SYMBOL(xfrm_lookup);
...@@ -2175,7 +2172,7 @@ int __xfrm_route_forward(struct sk_buff *skb, unsigned short family) ...@@ -2175,7 +2172,7 @@ int __xfrm_route_forward(struct sk_buff *skb, unsigned short family)
struct net *net = dev_net(skb->dev); struct net *net = dev_net(skb->dev);
struct flowi fl; struct flowi fl;
struct dst_entry *dst; struct dst_entry *dst;
int res; int res = 0;
if (xfrm_decode_session(skb, &fl, family) < 0) { if (xfrm_decode_session(skb, &fl, family) < 0) {
XFRM_INC_STATS(net, LINUX_MIB_XFRMFWDHDRERROR); XFRM_INC_STATS(net, LINUX_MIB_XFRMFWDHDRERROR);
...@@ -2183,9 +2180,12 @@ int __xfrm_route_forward(struct sk_buff *skb, unsigned short family) ...@@ -2183,9 +2180,12 @@ int __xfrm_route_forward(struct sk_buff *skb, unsigned short family)
} }
skb_dst_force(skb); skb_dst_force(skb);
dst = skb_dst(skb);
res = xfrm_lookup(net, &dst, &fl, NULL, 0) == 0; dst = xfrm_lookup(net, skb_dst(skb), &fl, NULL, 0);
if (IS_ERR(dst)) {
res = 1;
dst = NULL;
}
skb_dst_set(skb, dst); skb_dst_set(skb, dst);
return res; return res;
} }
......
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