From: Eric Dumazet <eric.dumazet@gmail.com>
To: David Miller <davem@davemloft.net>
Cc: piergiorgio.beruto@gmail.com, netdev@vger.kernel.org,
Michael Kerrisk <mtk.manpages@gmail.com>
Subject: [PATCH net-next] af_unix: MSG_TRUNC support for dgram sockets
Date: Wed, 22 Feb 2012 10:24:55 +0100 [thread overview]
Message-ID: <1329902695.18384.101.camel@edumazet-laptop> (raw)
In-Reply-To: <20120215.145511.1269077904303781879.davem@davemloft.net>
Piergiorgio Beruto expressed the need to fetch size of first datagram in
queue for AF_UNIX sockets and suggested a patch against SIOCINQ ioctl.
I suggested instead to implement MSG_TRUNC support as a recv() input
flag, as already done for RAW, UDP & NETLINK sockets.
len = recv(fd, &byte, 1, MSG_PEEK | MSG_TRUNC);
MSG_TRUNC asks recv() to return the real length of the packet, even when
is was longer than the passed buffer.
There is risk that a userland application used MSG_TRUNC by accident
(since it had no effect on af_unix sockets) and this might break after
this patch.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Tested-by: Piergiorgio Beruto <piergiorgio.beruto@gmail.com>
CC: Michael Kerrisk <mtk.manpages@gmail.com>
---
net/unix/af_unix.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 0be4d24..8ee85aa 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1845,7 +1845,7 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
if (UNIXCB(skb).fp)
siocb->scm->fp = scm_fp_dup(UNIXCB(skb).fp);
}
- err = size;
+ err = (flags & MSG_TRUNC) ? skb->len - skip : size;
scm_recv(sock, msg, siocb->scm, flags);
next prev parent reply other threads:[~2012-02-22 9:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-14 22:05 Possible bugfix for AF_UNIX, SOCK_SEQPACKET sockets Piergiorgio Beruto
2012-02-15 6:25 ` Eric Dumazet
2012-02-15 10:43 ` Piergiorgio Beruto
2012-02-15 12:42 ` Eric Dumazet
2012-02-15 17:36 ` Piergiorgio Beruto
2012-02-15 18:16 ` Eric Dumazet
2012-02-15 19:55 ` David Miller
2012-02-18 21:23 ` Piergiorgio Beruto
2012-02-22 9:24 ` Eric Dumazet [this message]
2012-02-22 19:50 ` [PATCH net-next] af_unix: MSG_TRUNC support for dgram sockets David Miller
2012-12-20 16:50 ` Michael Kerrisk (man-pages)
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=1329902695.18384.101.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=davem@davemloft.net \
--cc=mtk.manpages@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=piergiorgio.beruto@gmail.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