Commit a5443028 authored by Christoph Paasch's avatar Christoph Paasch Committed by David S. Miller

tcp: metrics: Add source-address to tcp-metrics

We add the source-address to the tcp-metrics, so that different metrics
will be used per source/destination-pair. We use the destination-hash to
store the metric inside the hash-table. That way, deleting and dumping
via "ip tcp_metrics" is easy.
Signed-off-by: default avatarChristoph Paasch <christoph.paasch@uclouvain.be>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 324fd55a
...@@ -31,6 +31,7 @@ struct tcp_fastopen_metrics { ...@@ -31,6 +31,7 @@ struct tcp_fastopen_metrics {
struct tcp_metrics_block { struct tcp_metrics_block {
struct tcp_metrics_block __rcu *tcpm_next; struct tcp_metrics_block __rcu *tcpm_next;
struct inetpeer_addr tcpm_saddr;
struct inetpeer_addr tcpm_daddr; struct inetpeer_addr tcpm_daddr;
unsigned long tcpm_stamp; unsigned long tcpm_stamp;
u32 tcpm_ts; u32 tcpm_ts;
...@@ -131,6 +132,7 @@ static void tcpm_suck_dst(struct tcp_metrics_block *tm, struct dst_entry *dst, ...@@ -131,6 +132,7 @@ static void tcpm_suck_dst(struct tcp_metrics_block *tm, struct dst_entry *dst,
} }
static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst, static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst,
struct inetpeer_addr *saddr,
struct inetpeer_addr *daddr, struct inetpeer_addr *daddr,
unsigned int hash, unsigned int hash,
bool reclaim) bool reclaim)
...@@ -155,6 +157,7 @@ static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst, ...@@ -155,6 +157,7 @@ static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst,
if (!tm) if (!tm)
goto out_unlock; goto out_unlock;
} }
tm->tcpm_saddr = *saddr;
tm->tcpm_daddr = *daddr; tm->tcpm_daddr = *daddr;
tcpm_suck_dst(tm, dst, true); tcpm_suck_dst(tm, dst, true);
...@@ -189,7 +192,8 @@ static struct tcp_metrics_block *tcp_get_encode(struct tcp_metrics_block *tm, in ...@@ -189,7 +192,8 @@ static struct tcp_metrics_block *tcp_get_encode(struct tcp_metrics_block *tm, in
return NULL; return NULL;
} }
static struct tcp_metrics_block *__tcp_get_metrics(const struct inetpeer_addr *daddr, static struct tcp_metrics_block *__tcp_get_metrics(const struct inetpeer_addr *saddr,
const struct inetpeer_addr *daddr,
struct net *net, unsigned int hash) struct net *net, unsigned int hash)
{ {
struct tcp_metrics_block *tm; struct tcp_metrics_block *tm;
...@@ -197,7 +201,8 @@ static struct tcp_metrics_block *__tcp_get_metrics(const struct inetpeer_addr *d ...@@ -197,7 +201,8 @@ static struct tcp_metrics_block *__tcp_get_metrics(const struct inetpeer_addr *d
for (tm = rcu_dereference(net->ipv4.tcp_metrics_hash[hash].chain); tm; for (tm = rcu_dereference(net->ipv4.tcp_metrics_hash[hash].chain); tm;
tm = rcu_dereference(tm->tcpm_next)) { tm = rcu_dereference(tm->tcpm_next)) {
if (addr_same(&tm->tcpm_daddr, daddr)) if (addr_same(&tm->tcpm_saddr, saddr) &&
addr_same(&tm->tcpm_daddr, daddr))
break; break;
depth++; depth++;
} }
...@@ -208,18 +213,21 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req, ...@@ -208,18 +213,21 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req,
struct dst_entry *dst) struct dst_entry *dst)
{ {
struct tcp_metrics_block *tm; struct tcp_metrics_block *tm;
struct inetpeer_addr daddr; struct inetpeer_addr saddr, daddr;
unsigned int hash; unsigned int hash;
struct net *net; struct net *net;
saddr.family = req->rsk_ops->family;
daddr.family = req->rsk_ops->family; daddr.family = req->rsk_ops->family;
switch (daddr.family) { switch (daddr.family) {
case AF_INET: case AF_INET:
saddr.addr.a4 = inet_rsk(req)->ir_loc_addr;
daddr.addr.a4 = inet_rsk(req)->ir_rmt_addr; daddr.addr.a4 = inet_rsk(req)->ir_rmt_addr;
hash = (__force unsigned int) daddr.addr.a4; hash = (__force unsigned int) daddr.addr.a4;
break; break;
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
case AF_INET6: case AF_INET6:
*(struct in6_addr *)saddr.addr.a6 = inet_rsk(req)->ir_v6_loc_addr;
*(struct in6_addr *)daddr.addr.a6 = inet_rsk(req)->ir_v6_rmt_addr; *(struct in6_addr *)daddr.addr.a6 = inet_rsk(req)->ir_v6_rmt_addr;
hash = ipv6_addr_hash(&inet_rsk(req)->ir_v6_rmt_addr); hash = ipv6_addr_hash(&inet_rsk(req)->ir_v6_rmt_addr);
break; break;
...@@ -233,7 +241,8 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req, ...@@ -233,7 +241,8 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req,
for (tm = rcu_dereference(net->ipv4.tcp_metrics_hash[hash].chain); tm; for (tm = rcu_dereference(net->ipv4.tcp_metrics_hash[hash].chain); tm;
tm = rcu_dereference(tm->tcpm_next)) { tm = rcu_dereference(tm->tcpm_next)) {
if (addr_same(&tm->tcpm_daddr, &daddr)) if (addr_same(&tm->tcpm_saddr, &saddr) &&
addr_same(&tm->tcpm_daddr, &daddr))
break; break;
} }
tcpm_check_stamp(tm, dst); tcpm_check_stamp(tm, dst);
...@@ -243,18 +252,21 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req, ...@@ -243,18 +252,21 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req,
static struct tcp_metrics_block *__tcp_get_metrics_tw(struct inet_timewait_sock *tw) static struct tcp_metrics_block *__tcp_get_metrics_tw(struct inet_timewait_sock *tw)
{ {
struct tcp_metrics_block *tm; struct tcp_metrics_block *tm;
struct inetpeer_addr daddr; struct inetpeer_addr saddr, daddr;
unsigned int hash; unsigned int hash;
struct net *net; struct net *net;
saddr.family = tw->tw_family;
daddr.family = tw->tw_family; daddr.family = tw->tw_family;
switch (daddr.family) { switch (daddr.family) {
case AF_INET: case AF_INET:
saddr.addr.a4 = tw->tw_rcv_saddr;
daddr.addr.a4 = tw->tw_daddr; daddr.addr.a4 = tw->tw_daddr;
hash = (__force unsigned int) daddr.addr.a4; hash = (__force unsigned int) daddr.addr.a4;
break; break;
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
case AF_INET6: case AF_INET6:
*(struct in6_addr *)saddr.addr.a6 = tw->tw_v6_rcv_saddr;
*(struct in6_addr *)daddr.addr.a6 = tw->tw_v6_daddr; *(struct in6_addr *)daddr.addr.a6 = tw->tw_v6_daddr;
hash = ipv6_addr_hash(&tw->tw_v6_daddr); hash = ipv6_addr_hash(&tw->tw_v6_daddr);
break; break;
...@@ -268,7 +280,8 @@ static struct tcp_metrics_block *__tcp_get_metrics_tw(struct inet_timewait_sock ...@@ -268,7 +280,8 @@ static struct tcp_metrics_block *__tcp_get_metrics_tw(struct inet_timewait_sock
for (tm = rcu_dereference(net->ipv4.tcp_metrics_hash[hash].chain); tm; for (tm = rcu_dereference(net->ipv4.tcp_metrics_hash[hash].chain); tm;
tm = rcu_dereference(tm->tcpm_next)) { tm = rcu_dereference(tm->tcpm_next)) {
if (addr_same(&tm->tcpm_daddr, &daddr)) if (addr_same(&tm->tcpm_saddr, &saddr) &&
addr_same(&tm->tcpm_daddr, &daddr))
break; break;
} }
return tm; return tm;
...@@ -279,19 +292,22 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk, ...@@ -279,19 +292,22 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,
bool create) bool create)
{ {
struct tcp_metrics_block *tm; struct tcp_metrics_block *tm;
struct inetpeer_addr daddr; struct inetpeer_addr saddr, daddr;
unsigned int hash; unsigned int hash;
struct net *net; struct net *net;
bool reclaim; bool reclaim;
saddr.family = sk->sk_family;
daddr.family = sk->sk_family; daddr.family = sk->sk_family;
switch (daddr.family) { switch (daddr.family) {
case AF_INET: case AF_INET:
saddr.addr.a4 = inet_sk(sk)->inet_saddr;
daddr.addr.a4 = inet_sk(sk)->inet_daddr; daddr.addr.a4 = inet_sk(sk)->inet_daddr;
hash = (__force unsigned int) daddr.addr.a4; hash = (__force unsigned int) daddr.addr.a4;
break; break;
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
case AF_INET6: case AF_INET6:
*(struct in6_addr *)saddr.addr.a6 = sk->sk_v6_rcv_saddr;
*(struct in6_addr *)daddr.addr.a6 = sk->sk_v6_daddr; *(struct in6_addr *)daddr.addr.a6 = sk->sk_v6_daddr;
hash = ipv6_addr_hash(&sk->sk_v6_daddr); hash = ipv6_addr_hash(&sk->sk_v6_daddr);
break; break;
...@@ -303,14 +319,14 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk, ...@@ -303,14 +319,14 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,
net = dev_net(dst->dev); net = dev_net(dst->dev);
hash = hash_32(hash, net->ipv4.tcp_metrics_hash_log); hash = hash_32(hash, net->ipv4.tcp_metrics_hash_log);
tm = __tcp_get_metrics(&daddr, net, hash); tm = __tcp_get_metrics(&saddr, &daddr, net, hash);
reclaim = false; reclaim = false;
if (tm == TCP_METRICS_RECLAIM_PTR) { if (tm == TCP_METRICS_RECLAIM_PTR) {
reclaim = true; reclaim = true;
tm = NULL; tm = NULL;
} }
if (!tm && create) if (!tm && create)
tm = tcpm_new(dst, &daddr, hash, reclaim); tm = tcpm_new(dst, &saddr, &daddr, hash, reclaim);
else else
tcpm_check_stamp(tm, dst); tcpm_check_stamp(tm, dst);
......
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