* [PATCH net-next v2] tcp: metrics: Handle v6/v4-mapped sockets in tcp-metrics
@ 2014-01-22 12:58 Christoph Paasch
2014-01-22 14:49 ` Eric Dumazet
2014-01-23 20:49 ` David Miller
0 siblings, 2 replies; 4+ messages in thread
From: Christoph Paasch @ 2014-01-22 12:58 UTC (permalink / raw)
To: David Miller; +Cc: netdev
A socket may be v6/v4-mapped. In that case sk->sk_family is AF_INET6,
but the IP being used is actually an IPv4-address.
Current's tcp-metrics will thus represent it as an IPv6-address:
root@server:~# ip tcp_metrics
::ffff:10.1.1.2 age 22.920sec rtt 18750us rttvar 15000us cwnd 10
10.1.1.2 age 47.970sec rtt 16250us rttvar 10000us cwnd 10
This patch modifies the tcp-metrics so that they are able to handle the
v6/v4-mapped sockets correctly.
Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
---
v2: Respin to net-next.
net/ipv4/tcp_metrics.c | 64 +++++++++++++++++++++++++++++++-------------------
1 file changed, 40 insertions(+), 24 deletions(-)
diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c
index fa950941de65..9923cebf5709 100644
--- a/net/ipv4/tcp_metrics.c
+++ b/net/ipv4/tcp_metrics.c
@@ -274,24 +274,32 @@ static struct tcp_metrics_block *__tcp_get_metrics_tw(struct inet_timewait_sock
unsigned int hash;
struct net *net;
- saddr.family = tw->tw_family;
- daddr.family = tw->tw_family;
- switch (daddr.family) {
- case AF_INET:
+ if (tw->tw_family == AF_INET) {
+ saddr.family = AF_INET;
saddr.addr.a4 = tw->tw_rcv_saddr;
+ daddr.family = AF_INET;
daddr.addr.a4 = tw->tw_daddr;
hash = (__force unsigned int) daddr.addr.a4;
- break;
+ }
#if IS_ENABLED(CONFIG_IPV6)
- case AF_INET6:
- *(struct in6_addr *)saddr.addr.a6 = tw->tw_v6_rcv_saddr;
- *(struct in6_addr *)daddr.addr.a6 = tw->tw_v6_daddr;
- hash = ipv6_addr_hash(&tw->tw_v6_daddr);
- break;
+ else if (tw->tw_family == AF_INET6) {
+ if (ipv6_addr_v4mapped(&tw->tw_v6_daddr)) {
+ saddr.family = AF_INET;
+ saddr.addr.a4 = tw->tw_rcv_saddr;
+ daddr.family = AF_INET;
+ daddr.addr.a4 = tw->tw_daddr;
+ hash = (__force unsigned int) daddr.addr.a4;
+ } else {
+ saddr.family = AF_INET6;
+ *(struct in6_addr *)saddr.addr.a6 = tw->tw_v6_rcv_saddr;
+ daddr.family = AF_INET6;
+ *(struct in6_addr *)daddr.addr.a6 = tw->tw_v6_daddr;
+ hash = ipv6_addr_hash(&tw->tw_v6_daddr);
+ }
+ }
#endif
- default:
+ else
return NULL;
- }
net = twsk_net(tw);
hash = hash_32(hash, net->ipv4.tcp_metrics_hash_log);
@@ -314,24 +322,32 @@ static struct tcp_metrics_block *tcp_get_metrics(struct sock *sk,
unsigned int hash;
struct net *net;
- saddr.family = sk->sk_family;
- daddr.family = sk->sk_family;
- switch (daddr.family) {
- case AF_INET:
+ if (sk->sk_family == AF_INET) {
+ saddr.family = AF_INET;
saddr.addr.a4 = inet_sk(sk)->inet_saddr;
+ daddr.family = AF_INET;
daddr.addr.a4 = inet_sk(sk)->inet_daddr;
hash = (__force unsigned int) daddr.addr.a4;
- break;
+ }
#if IS_ENABLED(CONFIG_IPV6)
- case AF_INET6:
- *(struct in6_addr *)saddr.addr.a6 = sk->sk_v6_rcv_saddr;
- *(struct in6_addr *)daddr.addr.a6 = sk->sk_v6_daddr;
- hash = ipv6_addr_hash(&sk->sk_v6_daddr);
- break;
+ else if (sk->sk_family = AF_INET6) {
+ if (ipv6_addr_v4mapped(&sk->sk_v6_daddr)) {
+ saddr.family = AF_INET;
+ saddr.addr.a4 = inet_sk(sk)->inet_saddr;
+ daddr.family = AF_INET;
+ daddr.addr.a4 = inet_sk(sk)->inet_daddr;
+ hash = (__force unsigned int) daddr.addr.a4;
+ } else {
+ saddr.family = AF_INET6;
+ *(struct in6_addr *)saddr.addr.a6 = sk->sk_v6_rcv_saddr;
+ daddr.family = AF_INET6;
+ *(struct in6_addr *)daddr.addr.a6 = sk->sk_v6_daddr;
+ hash = ipv6_addr_hash(&sk->sk_v6_daddr);
+ }
+ }
#endif
- default:
+ else
return NULL;
- }
net = dev_net(dst->dev);
hash = hash_32(hash, net->ipv4.tcp_metrics_hash_log);
--
1.8.3.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net-next v2] tcp: metrics: Handle v6/v4-mapped sockets in tcp-metrics
2014-01-22 12:58 [PATCH net-next v2] tcp: metrics: Handle v6/v4-mapped sockets in tcp-metrics Christoph Paasch
@ 2014-01-22 14:49 ` Eric Dumazet
2014-01-23 20:49 ` David Miller
1 sibling, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2014-01-22 14:49 UTC (permalink / raw)
To: Christoph Paasch; +Cc: David Miller, netdev
On Wed, 2014-01-22 at 13:58 +0100, Christoph Paasch wrote:
> A socket may be v6/v4-mapped. In that case sk->sk_family is AF_INET6,
> but the IP being used is actually an IPv4-address.
> Current's tcp-metrics will thus represent it as an IPv6-address:
>
> root@server:~# ip tcp_metrics
> ::ffff:10.1.1.2 age 22.920sec rtt 18750us rttvar 15000us cwnd 10
> 10.1.1.2 age 47.970sec rtt 16250us rttvar 10000us cwnd 10
>
> This patch modifies the tcp-metrics so that they are able to handle the
> v6/v4-mapped sockets correctly.
>
> Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
> ---
Acked-by: Eric Dumazet <edumazet@google.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v2] tcp: metrics: Handle v6/v4-mapped sockets in tcp-metrics
2014-01-22 12:58 [PATCH net-next v2] tcp: metrics: Handle v6/v4-mapped sockets in tcp-metrics Christoph Paasch
2014-01-22 14:49 ` Eric Dumazet
@ 2014-01-23 20:49 ` David Miller
2014-01-23 23:26 ` Christoph Paasch
1 sibling, 1 reply; 4+ messages in thread
From: David Miller @ 2014-01-23 20:49 UTC (permalink / raw)
To: christoph.paasch; +Cc: netdev
From: Christoph Paasch <christoph.paasch@uclouvain.be>
Date: Wed, 22 Jan 2014 13:58:44 +0100
> A socket may be v6/v4-mapped. In that case sk->sk_family is AF_INET6,
> but the IP being used is actually an IPv4-address.
> Current's tcp-metrics will thus represent it as an IPv6-address:
>
> root@server:~# ip tcp_metrics
> ::ffff:10.1.1.2 age 22.920sec rtt 18750us rttvar 15000us cwnd 10
> 10.1.1.2 age 47.970sec rtt 16250us rttvar 10000us cwnd 10
>
> This patch modifies the tcp-metrics so that they are able to handle the
> v6/v4-mapped sockets correctly.
>
> Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Applied, but I guess you didn't look at the build warnings, nor thoroughly
test this:
> + else if (sk->sk_family = AF_INET6) {
That's an assignment, not a straight test, and the compiler warns
about it.
I fixed it when I applied this, but please don't be so sloppy in the
future.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net-next v2] tcp: metrics: Handle v6/v4-mapped sockets in tcp-metrics
2014-01-23 20:49 ` David Miller
@ 2014-01-23 23:26 ` Christoph Paasch
0 siblings, 0 replies; 4+ messages in thread
From: Christoph Paasch @ 2014-01-23 23:26 UTC (permalink / raw)
To: David Miller; +Cc: netdev
On 23/01/14 - 12:49:26, David Miller wrote:
> From: Christoph Paasch <christoph.paasch@uclouvain.be>
> Date: Wed, 22 Jan 2014 13:58:44 +0100
>
> > A socket may be v6/v4-mapped. In that case sk->sk_family is AF_INET6,
> > but the IP being used is actually an IPv4-address.
> > Current's tcp-metrics will thus represent it as an IPv6-address:
> >
> > root@server:~# ip tcp_metrics
> > ::ffff:10.1.1.2 age 22.920sec rtt 18750us rttvar 15000us cwnd 10
> > 10.1.1.2 age 47.970sec rtt 16250us rttvar 10000us cwnd 10
> >
> > This patch modifies the tcp-metrics so that they are able to handle the
> > v6/v4-mapped sockets correctly.
> >
> > Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
>
> Applied, but I guess you didn't look at the build warnings, nor thoroughly
> test this:
>
> > + else if (sk->sk_family = AF_INET6) {
>
> That's an assignment, not a straight test, and the compiler warns
> about it.
>
> I fixed it when I applied this, but please don't be so sloppy in the
> future.
Ouch, I'm really sorry. Thanks for fixing it.
I did actually test it and it worked, because if sk_family is not AF_INET
then it can only be AF_INET6 and so the assignment won't change sk_family
and the if condition will be true.
Anyways, I will pay more attention in the future.
Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-01-23 23:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-22 12:58 [PATCH net-next v2] tcp: metrics: Handle v6/v4-mapped sockets in tcp-metrics Christoph Paasch
2014-01-22 14:49 ` Eric Dumazet
2014-01-23 20:49 ` David Miller
2014-01-23 23:26 ` Christoph Paasch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).