Patchwork [1/1] add SIOBKLGQ command to unix socket ioctl

login
register
mail settings
Submitter Roberto De Ioris
Date March 16, 2012, 6:49 a.m.
Message ID <1331880579-22416-1-git-send-email-roberto@unbit.it>
Download mbox | patch
Permalink /patch/147148/
State Changes Requested
Delegated to: David Miller
Headers show

Comments

Roberto De Ioris - March 16, 2012, 6:49 a.m.
Signed-off-by: Roberto De Ioris <roberto@unbit.it>
---
 include/linux/sockios.h |    1 +
 net/socket.c            |    1 +
 net/unix/af_unix.c      |   15 +++++++++++++++
 3 files changed, 17 insertions(+), 0 deletions(-)

Patch

diff --git a/include/linux/sockios.h b/include/linux/sockios.h
index 7997a50..b179613 100644
--- a/include/linux/sockios.h
+++ b/include/linux/sockios.h
@@ -23,6 +23,7 @@ 
 /* Linux-specific socket ioctls */
 #define SIOCINQ		FIONREAD
 #define SIOCOUTQ	TIOCOUTQ        /* output queue size (not sent + not acked) */
+#define SIOBKLGQ	0x8908
 
 /* Routing table calls. */
 #define SIOCADDRT	0x890B		/* add routing table entry	*/
diff --git a/net/socket.c b/net/socket.c
index 28a96af..d188f18 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -3186,6 +3186,7 @@  static int compat_sock_ioctl_trans(struct file *file, struct socket *sock,
 	case SIOCSIFVLAN:
 	case SIOCADDDLCI:
 	case SIOCDELDLCI:
+	case SIOBKLGQ:
 		return sock_ioctl(file, cmd, arg);
 
 	case SIOCGIFFLAGS:
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 85d3bb7..d2797e9 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2095,6 +2095,21 @@  static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 		amount = unix_outq_len(sk);
 		err = put_user(amount, (int __user *)arg);
 		break;
+	case SIOBKLGQ:
+		if (sk->sk_state != TCP_LISTEN) {
+			err = -EINVAL;
+			break;
+		}
+		if (sk->sk_type != SOCK_STREAM &&
+			sk->sk_type != SOCK_SEQPACKET) {
+			err = -EINVAL;
+			break;
+		}
+		spin_lock(&sk->sk_receive_queue.lock);
+		amount = (long) skb_queue_len(&sock->sk->sk_receive_queue);
+		spin_unlock(&sk->sk_receive_queue.lock);
+		err = put_user(amount, (int __user *)arg);
+		break;
 	case SIOCINQ:
 		amount = unix_inq_len(sk);
 		if (amount < 0)