Commit 519fbd87 authored by YOSHIFUJI Hideaki's avatar YOSHIFUJI Hideaki Committed by David S. Miller

[IPV6]: ROUTE: Clean-up cow'ing in ip6_route_{intput,output}().

Signed-off-by: default avatarYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e40cf353
...@@ -72,6 +72,7 @@ ...@@ -72,6 +72,7 @@
#define RT6_TRACE(x...) do { ; } while (0) #define RT6_TRACE(x...) do { ; } while (0)
#endif #endif
#define CLONE_OFFLINK_ROUTE 0
static int ip6_rt_max_size = 4096; static int ip6_rt_max_size = 4096;
static int ip6_rt_gc_min_interval = HZ / 2; static int ip6_rt_gc_min_interval = HZ / 2;
...@@ -465,9 +466,10 @@ if (rt == &ip6_null_entry && strict) { \ ...@@ -465,9 +466,10 @@ if (rt == &ip6_null_entry && strict) { \
void ip6_route_input(struct sk_buff *skb) void ip6_route_input(struct sk_buff *skb)
{ {
struct fib6_node *fn; struct fib6_node *fn;
struct rt6_info *rt; struct rt6_info *rt, *nrt;
int strict; int strict;
int attempts = 3; int attempts = 3;
int err;
strict = ipv6_addr_type(&skb->nh.ipv6h->daddr) & (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL); strict = ipv6_addr_type(&skb->nh.ipv6h->daddr) & (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL);
...@@ -492,51 +494,53 @@ restart: ...@@ -492,51 +494,53 @@ restart:
dst_hold(&rt->u.dst); dst_hold(&rt->u.dst);
read_unlock_bh(&rt6_lock); read_unlock_bh(&rt6_lock);
if (!rt->rt6i_nexthop && !(rt->rt6i_flags & RTF_NONEXTHOP)) { if (!rt->rt6i_nexthop && !(rt->rt6i_flags & RTF_NONEXTHOP))
struct rt6_info *nrt; nrt = rt6_alloc_cow(rt, &skb->nh.ipv6h->daddr, &skb->nh.ipv6h->saddr);
int err; else {
#if CLONE_OFFLINK_ROUTE
nrt = rt6_alloc_cow(rt, &skb->nh.ipv6h->daddr, nrt = rt6_alloc_clone(rt, &skb->nh.ipv6h->daddr);
&skb->nh.ipv6h->saddr); #else
goto out2;
dst_release(&rt->u.dst); #endif
rt = nrt ? : &ip6_null_entry; }
dst_hold(&rt->u.dst); dst_release(&rt->u.dst);
if (nrt) { rt = nrt ? : &ip6_null_entry;
err = ip6_ins_rt(nrt, NULL, NULL,
&NETLINK_CB(skb));
if (!err)
goto out2;
}
if (--attempts <= 0) dst_hold(&rt->u.dst);
if (nrt) {
err = ip6_ins_rt(nrt, NULL, NULL, &NETLINK_CB(skb));
if (!err)
goto out2; goto out2;
/* Race condition! In the gap, when rt6_lock was
released someone could insert this route. Relookup.
*/
dst_release(&rt->u.dst);
goto relookup;
} }
if (--attempts <= 0)
goto out2;
/*
* Race condition! In the gap, when rt6_lock was
* released someone could insert this route. Relookup.
*/
dst_release(&rt->u.dst);
goto relookup;
out:
dst_hold(&rt->u.dst);
read_unlock_bh(&rt6_lock);
out2: out2:
rt->u.dst.lastuse = jiffies; rt->u.dst.lastuse = jiffies;
rt->u.dst.__use++; rt->u.dst.__use++;
skb->dst = (struct dst_entry *) rt; skb->dst = (struct dst_entry *) rt;
return; return;
out:
dst_hold(&rt->u.dst);
read_unlock_bh(&rt6_lock);
goto out2;
} }
struct dst_entry * ip6_route_output(struct sock *sk, struct flowi *fl) struct dst_entry * ip6_route_output(struct sock *sk, struct flowi *fl)
{ {
struct fib6_node *fn; struct fib6_node *fn;
struct rt6_info *rt; struct rt6_info *rt, *nrt;
int strict; int strict;
int attempts = 3; int attempts = 3;
int err;
strict = ipv6_addr_type(&fl->fl6_dst) & (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL); strict = ipv6_addr_type(&fl->fl6_dst) & (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL);
...@@ -564,40 +568,43 @@ restart: ...@@ -564,40 +568,43 @@ restart:
dst_hold(&rt->u.dst); dst_hold(&rt->u.dst);
read_unlock_bh(&rt6_lock); read_unlock_bh(&rt6_lock);
if (!rt->rt6i_nexthop && !(rt->rt6i_flags & RTF_NONEXTHOP)) { if (!rt->rt6i_nexthop && !(rt->rt6i_flags & RTF_NONEXTHOP))
struct rt6_info *nrt;
int err;
nrt = rt6_alloc_cow(rt, &fl->fl6_dst, &fl->fl6_src); nrt = rt6_alloc_cow(rt, &fl->fl6_dst, &fl->fl6_src);
else {
#if CLONE_OFFLINK_ROUTE
nrt = rt6_alloc_clone(rt, &fl->fl6_dst);
#else
goto out2;
#endif
}
dst_release(&rt->u.dst); dst_release(&rt->u.dst);
rt = nrt ? : &ip6_null_entry; rt = nrt ? : &ip6_null_entry;
dst_hold(&rt->u.dst);
if (nrt) {
err = ip6_ins_rt(nrt, NULL, NULL, NULL);
if (!err)
goto out2;
}
if (--attempts <= 0) dst_hold(&rt->u.dst);
if (nrt) {
err = ip6_ins_rt(nrt, NULL, NULL, NULL);
if (!err)
goto out2; goto out2;
/* Race condition! In the gap, when rt6_lock was
released someone could insert this route. Relookup.
*/
dst_release(&rt->u.dst);
goto relookup;
} }
if (--attempts <= 0)
goto out2;
/*
* Race condition! In the gap, when rt6_lock was
* released someone could insert this route. Relookup.
*/
dst_release(&rt->u.dst);
goto relookup;
out:
dst_hold(&rt->u.dst);
read_unlock_bh(&rt6_lock);
out2: out2:
rt->u.dst.lastuse = jiffies; rt->u.dst.lastuse = jiffies;
rt->u.dst.__use++; rt->u.dst.__use++;
return &rt->u.dst; return &rt->u.dst;
out:
dst_hold(&rt->u.dst);
read_unlock_bh(&rt6_lock);
goto out2;
} }
......
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