diff options
author | Eric Dumazet <edumazet@google.com> | 2012-10-18 05:14:12 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-10-18 15:34:31 -0400 |
commit | a3374c42aa5f7237e87ff3b0622018636b0c847e (patch) | |
tree | 8a9232aed518f5ce9acb862fc125aacc5cd7cebd /net/ipv4/tcp.c | |
parent | c6846ee148e07e4cfae4de486532efb02d238938 (diff) |
tcp: fix FIONREAD/SIOCINQ
tcp_ioctl() tries to take into account if tcp socket received a FIN
to report correct number bytes in receive queue.
But its flaky because if the application ate the last skb,
we return 1 instead of 0.
Correct way to detect that FIN was received is to test SOCK_DONE.
Reported-by: Elliot Hughes <enh@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Neal Cardwell <ncardwell@google.com>
Cc: Tom Herbert <therbert@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp.c')
-rw-r--r-- | net/ipv4/tcp.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index f32c02e2a543..b7c2f439b54f 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c | |||
@@ -549,14 +549,12 @@ int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg) | |||
549 | !tp->urg_data || | 549 | !tp->urg_data || |
550 | before(tp->urg_seq, tp->copied_seq) || | 550 | before(tp->urg_seq, tp->copied_seq) || |
551 | !before(tp->urg_seq, tp->rcv_nxt)) { | 551 | !before(tp->urg_seq, tp->rcv_nxt)) { |
552 | struct sk_buff *skb; | ||
553 | 552 | ||
554 | answ = tp->rcv_nxt - tp->copied_seq; | 553 | answ = tp->rcv_nxt - tp->copied_seq; |
555 | 554 | ||
556 | /* Subtract 1, if FIN is in queue. */ | 555 | /* Subtract 1, if FIN was received */ |
557 | skb = skb_peek_tail(&sk->sk_receive_queue); | 556 | if (answ && sock_flag(sk, SOCK_DONE)) |
558 | if (answ && skb) | 557 | answ--; |
559 | answ -= tcp_hdr(skb)->fin; | ||
560 | } else | 558 | } else |
561 | answ = tp->urg_seq - tp->copied_seq; | 559 | answ = tp->urg_seq - tp->copied_seq; |
562 | release_sock(sk); | 560 | release_sock(sk); |