From: Josh Hunt <johunt@akamai.com>
To: davem@davemloft.net, arnd@arndb.de
Cc: edumazet@google.com, soheil@google.com, willemb@google.com,
pabeni@redhat.com, linux-arch@vger.kernel.org,
netdev@vger.kernel.org, Josh Hunt <johunt@akamai.com>
Subject: [RFC PATCH] sock: add SO_RCVQUEUE_SIZE getsockopt
Date: Mon, 13 Mar 2017 11:59:46 -0400 [thread overview]
Message-ID: <1489420786-19547-1-git-send-email-johunt@akamai.com> (raw)
Allows application to read the amount of data sitting in the receive
queue.
Signed-off-by: Josh Hunt <johunt@akamai.com>
---
A team here is looking for a way to get the amount of data in a UDP socket's
receive queue. It seems like this should be SIOCINQ, but for UDP sockets that
returns the size of the next pending datagram. I implemented the patch below,
but am wondering if this is the right place for this change? I was debating
between this or a new UDP ioctl.
include/net/sock.h | 7 ++++++-
include/uapi/asm-generic/socket.h | 2 ++
net/core/sock.c | 4 ++++
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index 5e59976..bcfed2ae 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -854,6 +854,11 @@ static inline void __sk_add_backlog(struct sock *sk, struct sk_buff *skb)
skb->next = NULL;
}
+static unsigned int sk_rcvqueue_size(const struct sock *sk)
+{
+ return sk->sk_backlog.len + atomic_read(&sk->sk_rmem_alloc);
+}
+
/*
* Take into account size of receive queue and backlog queue
* Do not take into account this skb truesize,
@@ -861,7 +866,7 @@ static inline void __sk_add_backlog(struct sock *sk, struct sk_buff *skb)
*/
static inline bool sk_rcvqueues_full(const struct sock *sk, unsigned int limit)
{
- unsigned int qsize = sk->sk_backlog.len + atomic_read(&sk->sk_rmem_alloc);
+ unsigned int qsize = sk_rcvqueue_size(sk);
return qsize > limit;
}
diff --git a/include/uapi/asm-generic/socket.h b/include/uapi/asm-generic/socket.h
index 2c748dd..36b8cd5 100644
--- a/include/uapi/asm-generic/socket.h
+++ b/include/uapi/asm-generic/socket.h
@@ -94,4 +94,6 @@
#define SCM_TIMESTAMPING_OPT_STATS 54
+#define SO_RCVQUEUE_SIZE 55
+
#endif /* __ASM_GENERIC_SOCKET_H */
diff --git a/net/core/sock.c b/net/core/sock.c
index f6fd79f..fa69864 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1269,6 +1269,10 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
v.val = sk->sk_incoming_cpu;
break;
+ case SO_RCVQUEUE_SIZE:
+ v.val = sk_rcvqueue_size(sk);
+ break;
+
default:
/* We implement the SO_SNDLOWAT etc to not be settable
* (1003.1g 7).
--
1.9.1
next reply other threads:[~2017-03-13 15:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-13 15:59 Josh Hunt [this message]
2017-03-13 15:59 ` [RFC PATCH] sock: add SO_RCVQUEUE_SIZE getsockopt Josh Hunt
2017-03-13 16:12 ` Eric Dumazet
2017-03-13 16:12 ` Eric Dumazet
2017-03-13 17:38 ` Josh Hunt
2017-03-13 17:38 ` Josh Hunt
2017-03-13 19:39 ` David Miller
2017-03-13 23:34 ` Josh Hunt
2017-03-13 23:34 ` Josh Hunt
2017-03-14 0:10 ` David Miller
2017-03-14 22:11 ` Josh Hunt
2017-03-14 1:31 ` Eric Dumazet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1489420786-19547-1-git-send-email-johunt@akamai.com \
--to=johunt@akamai.com \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=linux-arch@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=soheil@google.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).