From: Steffen Klassert <steffen.klassert@secunet.com>
To: David Miller <davem@davemloft.net>
Cc: timo.teras@iki.fi, netdev@vger.kernel.org
Subject: [PATCH 1/4] inetpeer: Allocate the peer metrics dynamically
Date: Thu, 2 Feb 2012 11:12:15 +0100 [thread overview]
Message-ID: <20120202101215.GD23142@secunet.com> (raw)
In-Reply-To: <20120202101141.GC23142@secunet.com>
We do a dynamic allocation of the peer metrics in order
to be able to reset the peer metrics by exchanging a rcu
pointer. This is done with separate patches.
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
include/net/inetpeer.h | 13 +++++++++++--
net/ipv4/inetpeer.c | 14 ++++++++++++--
net/ipv4/route.c | 7 ++++---
net/ipv6/route.c | 2 +-
4 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
index 06b795d..6bb8060 100644
--- a/include/net/inetpeer.h
+++ b/include/net/inetpeer.h
@@ -27,13 +27,17 @@ struct inetpeer_addr {
__u16 family;
};
+struct inetpeer_metrics {
+ u32 m[RTAX_MAX];
+};
+
struct inet_peer {
/* group together avl_left,avl_right,v4daddr to speedup lookups */
struct inet_peer __rcu *avl_left, *avl_right;
struct inetpeer_addr daddr;
__u32 avl_height;
- u32 metrics[RTAX_MAX];
+ struct inetpeer_metrics *metrics;
u32 rate_tokens; /* rate limiting for ICMP */
int redirect_genid;
unsigned long rate_last;
@@ -68,7 +72,12 @@ void inet_initpeers(void) __init;
static inline bool inet_metrics_new(const struct inet_peer *p)
{
- return p->metrics[RTAX_LOCK-1] == INETPEER_METRICS_NEW;
+ return p->metrics->m[RTAX_LOCK-1] == INETPEER_METRICS_NEW;
+}
+
+static inline u32 *inetpeer_metrics(const struct inet_peer *p)
+{
+ return p->metrics->m;
}
/* can be called with or without local BH being disabled */
diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index bf4a9c4..92071a4 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -315,7 +315,9 @@ do { \
static void inetpeer_free_rcu(struct rcu_head *head)
{
- kmem_cache_free(peer_cachep, container_of(head, struct inet_peer, rcu));
+ struct inet_peer *p = container_of(head, struct inet_peer, rcu);
+ kfree(p->metrics);
+ kmem_cache_free(peer_cachep, p);
}
static void unlink_from_pool(struct inet_peer *p, struct inet_peer_base *base,
@@ -434,6 +436,13 @@ relookup:
}
p = create ? kmem_cache_alloc(peer_cachep, GFP_ATOMIC) : NULL;
if (p) {
+ p->metrics = kmalloc(sizeof(struct inetpeer_metrics),
+ GFP_ATOMIC);
+ if (!p->metrics) {
+ kmem_cache_free(peer_cachep, p);
+ goto out;
+ }
+
p->daddr = *daddr;
atomic_set(&p->refcnt, 1);
atomic_set(&p->rid, 0);
@@ -442,7 +451,7 @@ relookup:
secure_ip_id(daddr->addr.a4) :
secure_ipv6_id(daddr->addr.a6));
p->tcp_ts_stamp = 0;
- p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
+ p->metrics->m[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
p->rate_tokens = 0;
p->rate_last = 0;
p->pmtu_expires = 0;
@@ -455,6 +464,7 @@ relookup:
link_to_pool(p, base);
base->total++;
}
+out:
write_sequnlock_bh(&base->lock);
return p;
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index bcacf54..5099d35 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -169,7 +169,7 @@ static u32 *ipv4_cow_metrics(struct dst_entry *dst, unsigned long old)
u32 *old_p = __DST_METRICS_PTR(old);
unsigned long prev, new;
- p = peer->metrics;
+ p = inetpeer_metrics(peer);
if (inet_metrics_new(peer))
memcpy(p, old_p, sizeof(u32) * RTAX_MAX);
@@ -1951,11 +1951,12 @@ static void rt_init_metrics(struct rtable *rt, const struct flowi4 *fl4,
rt->peer = peer = inet_getpeer_v4(rt->rt_dst, create);
if (peer) {
+ u32 *peer_metrics = inetpeer_metrics(peer);
rt->rt_peer_genid = rt_peer_genid();
if (inet_metrics_new(peer))
- memcpy(peer->metrics, fi->fib_metrics,
+ memcpy(peer_metrics, fi->fib_metrics,
sizeof(u32) * RTAX_MAX);
- dst_init_metrics(&rt->dst, peer->metrics, false);
+ dst_init_metrics(&rt->dst, peer_metrics, false);
check_peer_pmtu(&rt->dst, peer);
if (peer->redirect_genid != redirect_genid)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 8c2e3ab..ea13565 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -105,7 +105,7 @@ static u32 *ipv6_cow_metrics(struct dst_entry *dst, unsigned long old)
u32 *old_p = __DST_METRICS_PTR(old);
unsigned long prev, new;
- p = peer->metrics;
+ p = inetpeer_metrics(peer);
if (inet_metrics_new(peer))
memcpy(p, old_p, sizeof(u32) * RTAX_MAX);
--
1.7.0.4
next prev parent reply other threads:[~2012-02-02 10:12 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-02 10:11 [PATCH 0/4] Fix routing metrics Steffen Klassert
2012-02-02 10:12 ` Steffen Klassert [this message]
2012-02-02 10:12 ` [PATCH 2/4] net: Unlink the inetpeer metrics from dst_entry Steffen Klassert
2012-02-02 10:13 ` [PATCH 3/4] inetpeer: protect the inetpeerpeer metrics with rcu Steffen Klassert
2012-02-02 10:14 ` [PATCH 4/4] route: Invalidate the peer metrics along with the routing cache Steffen Klassert
2012-02-06 20:29 ` [PATCH 0/4] Fix routing metrics David Miller
2012-02-08 7:30 ` Steffen Klassert
2012-02-08 20:18 ` David Miller
2012-02-09 12:44 ` Steffen Klassert
2012-02-09 18:40 ` David Miller
2012-02-10 6:50 ` Steffen Klassert
2012-02-10 7:38 ` David Miller
2012-02-10 7:51 ` Steffen Klassert
2012-02-10 8:12 ` David Miller
2012-02-10 8:44 ` Steffen Klassert
2012-02-10 18:25 ` David Miller
2012-02-21 6:19 ` Steffen Klassert
2012-02-21 6:36 ` David Miller
2012-02-21 8:18 ` Steffen Klassert
2012-02-21 19:24 ` David Miller
2012-02-24 9:08 ` Steffen Klassert
2012-02-24 9:13 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120202101215.GD23142@secunet.com \
--to=steffen.klassert@secunet.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=timo.teras@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.