diff options
author | Eric Dumazet <edumazet@google.com> | 2015-04-28 18:28:18 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-04-29 17:10:37 -0400 |
commit | bdd1f9edacb5f5835d1e6276571bbbe5b88ded48 (patch) | |
tree | bee07eb61b32918398a04cc171327b45cf14408d /net | |
parent | 0df48c26d8418c5c9fba63fac15b660d70ca2f1c (diff) |
tcp: add tcpi_bytes_received to tcp_info
This patch tracks total number of payload bytes received on a TCP socket.
This is the sum of all changes done to tp->rcv_nxt
RFC4898 named this : tcpEStatsAppHCThruOctetsReceived
This is a 64bit field, and can be fetched both from TCP_INFO
getsockopt() if one has a handle on a TCP socket, or from inet_diag
netlink facility (iproute2/ss patch will follow)
Note that tp->bytes_received was placed near tp->rcv_nxt for
best data locality and minimal performance impact.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Yuchung Cheng <ycheng@google.com>
Cc: Matt Mathis <mattmathis@google.com>
Cc: Eric Salo <salo@google.com>
Cc: Martin Lau <kafai@fb.com>
Cc: Chris Rapier <rapier@psc.edu>
Acked-by: Yuchung Cheng <ycheng@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/ipv4/tcp.c | 1 | ||||
-rw-r--r-- | net/ipv4/tcp_fastopen.c | 1 | ||||
-rw-r--r-- | net/ipv4/tcp_input.c | 17 |
3 files changed, 15 insertions, 4 deletions
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 4bf0e8ca7b5b..99fcc0b22c92 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c | |||
@@ -2666,6 +2666,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info) | |||
2666 | 2666 | ||
2667 | spin_lock_bh(&sk->sk_lock.slock); | 2667 | spin_lock_bh(&sk->sk_lock.slock); |
2668 | info->tcpi_bytes_acked = tp->bytes_acked; | 2668 | info->tcpi_bytes_acked = tp->bytes_acked; |
2669 | info->tcpi_bytes_received = tp->bytes_received; | ||
2669 | spin_unlock_bh(&sk->sk_lock.slock); | 2670 | spin_unlock_bh(&sk->sk_lock.slock); |
2670 | } | 2671 | } |
2671 | EXPORT_SYMBOL_GPL(tcp_get_info); | 2672 | EXPORT_SYMBOL_GPL(tcp_get_info); |
diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c index e3d87aca6be8..3c673d5e6cff 100644 --- a/net/ipv4/tcp_fastopen.c +++ b/net/ipv4/tcp_fastopen.c | |||
@@ -206,6 +206,7 @@ static bool tcp_fastopen_create_child(struct sock *sk, | |||
206 | skb_set_owner_r(skb2, child); | 206 | skb_set_owner_r(skb2, child); |
207 | __skb_queue_tail(&child->sk_receive_queue, skb2); | 207 | __skb_queue_tail(&child->sk_receive_queue, skb2); |
208 | tp->syn_data_acked = 1; | 208 | tp->syn_data_acked = 1; |
209 | tp->bytes_received = end_seq - TCP_SKB_CB(skb)->seq - 1; | ||
209 | } else { | 210 | } else { |
210 | end_seq = TCP_SKB_CB(skb)->seq + 1; | 211 | end_seq = TCP_SKB_CB(skb)->seq + 1; |
211 | } | 212 | } |
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 378d3f4d4dc3..7e6962bcfc30 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c | |||
@@ -3289,6 +3289,15 @@ static void tcp_snd_una_update(struct tcp_sock *tp, u32 ack) | |||
3289 | tp->snd_una = ack; | 3289 | tp->snd_una = ack; |
3290 | } | 3290 | } |
3291 | 3291 | ||
3292 | /* If we update tp->rcv_nxt, also update tp->bytes_received */ | ||
3293 | static void tcp_rcv_nxt_update(struct tcp_sock *tp, u32 seq) | ||
3294 | { | ||
3295 | u32 delta = seq - tp->rcv_nxt; | ||
3296 | |||
3297 | tp->bytes_received += delta; | ||
3298 | tp->rcv_nxt = seq; | ||
3299 | } | ||
3300 | |||
3292 | /* Update our send window. | 3301 | /* Update our send window. |
3293 | * | 3302 | * |
3294 | * Window update algorithm, described in RFC793/RFC1122 (used in linux-2.2 | 3303 | * Window update algorithm, described in RFC793/RFC1122 (used in linux-2.2 |
@@ -4245,7 +4254,7 @@ static void tcp_ofo_queue(struct sock *sk) | |||
4245 | 4254 | ||
4246 | tail = skb_peek_tail(&sk->sk_receive_queue); | 4255 | tail = skb_peek_tail(&sk->sk_receive_queue); |
4247 | eaten = tail && tcp_try_coalesce(sk, tail, skb, &fragstolen); | 4256 | eaten = tail && tcp_try_coalesce(sk, tail, skb, &fragstolen); |
4248 | tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq; | 4257 | tcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)->end_seq); |
4249 | if (!eaten) | 4258 | if (!eaten) |
4250 | __skb_queue_tail(&sk->sk_receive_queue, skb); | 4259 | __skb_queue_tail(&sk->sk_receive_queue, skb); |
4251 | if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) | 4260 | if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) |
@@ -4413,7 +4422,7 @@ static int __must_check tcp_queue_rcv(struct sock *sk, struct sk_buff *skb, int | |||
4413 | __skb_pull(skb, hdrlen); | 4422 | __skb_pull(skb, hdrlen); |
4414 | eaten = (tail && | 4423 | eaten = (tail && |
4415 | tcp_try_coalesce(sk, tail, skb, fragstolen)) ? 1 : 0; | 4424 | tcp_try_coalesce(sk, tail, skb, fragstolen)) ? 1 : 0; |
4416 | tcp_sk(sk)->rcv_nxt = TCP_SKB_CB(skb)->end_seq; | 4425 | tcp_rcv_nxt_update(tcp_sk(sk), TCP_SKB_CB(skb)->end_seq); |
4417 | if (!eaten) { | 4426 | if (!eaten) { |
4418 | __skb_queue_tail(&sk->sk_receive_queue, skb); | 4427 | __skb_queue_tail(&sk->sk_receive_queue, skb); |
4419 | skb_set_owner_r(skb, sk); | 4428 | skb_set_owner_r(skb, sk); |
@@ -4506,7 +4515,7 @@ queue_and_out: | |||
4506 | 4515 | ||
4507 | eaten = tcp_queue_rcv(sk, skb, 0, &fragstolen); | 4516 | eaten = tcp_queue_rcv(sk, skb, 0, &fragstolen); |
4508 | } | 4517 | } |
4509 | tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq; | 4518 | tcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)->end_seq); |
4510 | if (skb->len) | 4519 | if (skb->len) |
4511 | tcp_event_data_recv(sk, skb); | 4520 | tcp_event_data_recv(sk, skb); |
4512 | if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) | 4521 | if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) |
@@ -5254,7 +5263,7 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb, | |||
5254 | tcp_rcv_rtt_measure_ts(sk, skb); | 5263 | tcp_rcv_rtt_measure_ts(sk, skb); |
5255 | 5264 | ||
5256 | __skb_pull(skb, tcp_header_len); | 5265 | __skb_pull(skb, tcp_header_len); |
5257 | tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq; | 5266 | tcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)->end_seq); |
5258 | NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPHPHITSTOUSER); | 5267 | NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPHPHITSTOUSER); |
5259 | eaten = 1; | 5268 | eaten = 1; |
5260 | } | 5269 | } |