diff options
author | David S. Miller <davem@davemloft.net> | 2011-01-27 14:58:42 -0800 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-01-27 14:59:31 -0800 |
commit | 065825402c058f4a123ddc53dbbe864cc5caaf64 (patch) | |
tree | 7d0d5122a5315c5850a0b01ed7349e9eebf794e2 /net/ipv6 | |
parent | 1397e171f143878dd16ad5f8c99f7b9440cc8911 (diff) |
net: Store ipv4/ipv6 COW'd metrics in inetpeer cache.
Please note that the IPSEC dst entry metrics keep using
the generic metrics COW'ing mechanism using kmalloc/kfree.
This gives the IPSEC routes an opportunity to use metrics
which are unique to their encapsulated paths.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6')
-rw-r--r-- | net/ipv6/route.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 691798c169a..72609f1c615 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -97,6 +97,36 @@ static struct rt6_info *rt6_get_route_info(struct net *net, struct in6_addr *gwaddr, int ifindex); #endif +static u32 *ipv6_cow_metrics(struct dst_entry *dst, unsigned long old) +{ + struct rt6_info *rt = (struct rt6_info *) dst; + struct inet_peer *peer; + u32 *p = NULL; + + if (!rt->rt6i_peer) + rt6_bind_peer(rt, 1); + + peer = rt->rt6i_peer; + if (peer) { + u32 *old_p = __DST_METRICS_PTR(old); + unsigned long prev, new; + + p = peer->metrics; + if (inet_metrics_new(peer)) + memcpy(p, old_p, sizeof(u32) * RTAX_MAX); + + new = (unsigned long) p; + prev = cmpxchg(&dst->_metrics, old, new); + + if (prev != old) { + p = __DST_METRICS_PTR(prev); + if (prev & DST_METRICS_READ_ONLY) + p = NULL; + } + } + return p; +} + static struct dst_ops ip6_dst_ops_template = { .family = AF_INET6, .protocol = cpu_to_be16(ETH_P_IPV6), @@ -105,7 +135,7 @@ static struct dst_ops ip6_dst_ops_template = { .check = ip6_dst_check, .default_advmss = ip6_default_advmss, .default_mtu = ip6_default_mtu, - .cow_metrics = dst_cow_metrics_generic, + .cow_metrics = ipv6_cow_metrics, .destroy = ip6_dst_destroy, .ifdown = ip6_dst_ifdown, .negative_advice = ip6_negative_advice, @@ -198,7 +228,6 @@ static void ip6_dst_destroy(struct dst_entry *dst) rt->rt6i_idev = NULL; in6_dev_put(idev); } - dst_destroy_metrics_generic(dst); if (peer) { rt->rt6i_peer = NULL; inet_putpeer(peer); |