Skip to content

Commit 885ee74

Browse files
xemuldavem330
authored andcommitted
af_unix: Move CINQ/COUTQ code to helpers
Currently tcp diag reports rqlen and wqlen values similar to how the CINQ/COUTQ iotcls do. To make unix diag report these values in the same way move the respective code into helpers. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 257b529 commit 885ee74

File tree

2 files changed

+39
-23
lines changed

2 files changed

+39
-23
lines changed

include/net/af_unix.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ struct unix_sock {
6666

6767
#define peer_wait peer_wq.wait
6868

69+
long unix_inq_len(struct sock *sk);
70+
long unix_outq_len(struct sock *sk);
71+
6972
#ifdef CONFIG_SYSCTL
7073
extern int unix_sysctl_register(struct net *net);
7174
extern void unix_sysctl_unregister(struct net *net);

net/unix/af_unix.c

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,6 +2065,36 @@ static int unix_shutdown(struct socket *sock, int mode)
20652065
return 0;
20662066
}
20672067

2068+
long unix_inq_len(struct sock *sk)
2069+
{
2070+
struct sk_buff *skb;
2071+
long amount = 0;
2072+
2073+
if (sk->sk_state == TCP_LISTEN)
2074+
return -EINVAL;
2075+
2076+
spin_lock(&sk->sk_receive_queue.lock);
2077+
if (sk->sk_type == SOCK_STREAM ||
2078+
sk->sk_type == SOCK_SEQPACKET) {
2079+
skb_queue_walk(&sk->sk_receive_queue, skb)
2080+
amount += skb->len;
2081+
} else {
2082+
skb = skb_peek(&sk->sk_receive_queue);
2083+
if (skb)
2084+
amount = skb->len;
2085+
}
2086+
spin_unlock(&sk->sk_receive_queue.lock);
2087+
2088+
return amount;
2089+
}
2090+
EXPORT_SYMBOL_GPL(unix_inq_len);
2091+
2092+
long unix_outq_len(struct sock *sk)
2093+
{
2094+
return sk_wmem_alloc_get(sk);
2095+
}
2096+
EXPORT_SYMBOL_GPL(unix_outq_len);
2097+
20682098
static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
20692099
{
20702100
struct sock *sk = sock->sk;
@@ -2073,33 +2103,16 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
20732103

20742104
switch (cmd) {
20752105
case SIOCOUTQ:
2076-
amount = sk_wmem_alloc_get(sk);
2106+
amount = unix_outq_len(sk);
20772107
err = put_user(amount, (int __user *)arg);
20782108
break;
20792109
case SIOCINQ:
2080-
{
2081-
struct sk_buff *skb;
2082-
2083-
if (sk->sk_state == TCP_LISTEN) {
2084-
err = -EINVAL;
2085-
break;
2086-
}
2087-
2088-
spin_lock(&sk->sk_receive_queue.lock);
2089-
if (sk->sk_type == SOCK_STREAM ||
2090-
sk->sk_type == SOCK_SEQPACKET) {
2091-
skb_queue_walk(&sk->sk_receive_queue, skb)
2092-
amount += skb->len;
2093-
} else {
2094-
skb = skb_peek(&sk->sk_receive_queue);
2095-
if (skb)
2096-
amount = skb->len;
2097-
}
2098-
spin_unlock(&sk->sk_receive_queue.lock);
2110+
amount = unix_inq_len(sk);
2111+
if (amount < 0)
2112+
err = amount;
2113+
else
20992114
err = put_user(amount, (int __user *)arg);
2100-
break;
2101-
}
2102-
2115+
break;
21032116
default:
21042117
err = -ENOIOCTLCMD;
21052118
break;

0 commit comments

Comments
 (0)