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>
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 980030d4..68cee35 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -154,25 +154,30 @@
static u32 *ipv4_cow_metrics(struct dst_entry *dst, unsigned long old)
{
- u32 *p = kmalloc(sizeof(u32) * RTAX_MAX, GFP_ATOMIC);
+ struct rtable *rt = (struct rtable *) dst;
+ struct inet_peer *peer;
+ u32 *p = NULL;
- if (p) {
+ if (!rt->peer)
+ rt_bind_peer(rt, 1);
+
+ peer = rt->peer;
+ if (peer) {
u32 *old_p = __DST_METRICS_PTR(old);
unsigned long prev, new;
- memcpy(p, old_p, sizeof(u32) * RTAX_MAX);
+ 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) {
- kfree(p);
p = __DST_METRICS_PTR(prev);
if (prev & DST_METRICS_READ_ONLY)
p = NULL;
} else {
- struct rtable *rt = (struct rtable *) dst;
-
if (rt->fi) {
fib_info_put(rt->fi);
rt->fi = NULL;
@@ -1753,7 +1758,6 @@
struct rtable *rt = (struct rtable *) dst;
struct inet_peer *peer = rt->peer;
- dst_destroy_metrics_generic(dst);
if (rt->fi) {
fib_info_put(rt->fi);
rt->fi = NULL;