Commit 56b5adfb authored by David S. Miller's avatar David S. Miller Committed by Linus Torvalds

[AF_UNIX]: Fix SIOCINQ for STREAM and SEQPACKET.

We should report the total bytes in the whole receive
queue, not just the first packet, in these cases.

Reported by Uwe Bonnes.
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bf19cf14
...@@ -1850,15 +1850,22 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -1850,15 +1850,22 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
case SIOCINQ: case SIOCINQ:
{ {
struct sk_buff *skb; struct sk_buff *skb;
if (sk->sk_state == TCP_LISTEN) { if (sk->sk_state == TCP_LISTEN) {
err = -EINVAL; err = -EINVAL;
break; break;
} }
spin_lock(&sk->sk_receive_queue.lock); spin_lock(&sk->sk_receive_queue.lock);
skb = skb_peek(&sk->sk_receive_queue); if (sk->sk_type == SOCK_STREAM ||
if (skb) sk->sk_type == SOCK_SEQPACKET) {
amount=skb->len; skb_queue_walk(&sk->sk_receive_queue, skb)
amount += skb->len;
} else {
skb = skb_peek(&sk->sk_receive_queue);
if (skb)
amount=skb->len;
}
spin_unlock(&sk->sk_receive_queue.lock); spin_unlock(&sk->sk_receive_queue.lock);
err = put_user(amount, (int __user *)arg); err = put_user(amount, (int __user *)arg);
break; break;
......
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