Page MenuHomeFreeBSD

sockets: implement MSG_TRUNC recv/recvmsg flag
ClosedPublic

Authored by melifaro on Jul 25 2022, 7:48 PM.
Tags
None
Referenced Files
F96146787: D35909.diff
Mon, Sep 23, 8:44 PM
F96025402: D35909.diff
Mon, Sep 23, 9:50 AM
Unknown Object (File)
Sun, Sep 22, 9:14 PM
Unknown Object (File)
Wed, Sep 18, 6:15 PM
Unknown Object (File)
Tue, Sep 17, 12:08 PM
Unknown Object (File)
Mon, Sep 16, 12:53 PM
Unknown Object (File)
Sun, Sep 15, 4:23 AM
Unknown Object (File)
Sun, Sep 15, 3:35 AM

Details

Summary

Implement Linux-variant of MSG_TRUNC flag used in recv(), recvfrom() and recvmsg().

Posix defines MSG_TRUNC as an output flag, indicating packet/datagram truncation. Linux extended it a while (~15+ years) ago to act as input flag, making the returned number of bytes being the full packet size.

It's a (relatively) popular pattern to do recvmsg( MSG_PEEK | MSG_TRUNC) to get the packet size, allocate the buffer and issue another call to fetch the packet. In particular, it's popular in userland netlink code, which is the primary driving factor of this change.

This diff implements the aforementioned behaviour for SOCK_DGRAM sockets (udp, unix, all soreceive_generic() users).

Test Plan
20:09 [2] m@devel0 s kyua debug -k /usr/tests/sys/netinet/Kyuafile socket_afinet:socket_afinet_unix_recv_trunc
socket_afinet:socket_afinet_unix_recv_trunc  ->  passed
20:09 [2] m@devel0 s kyua debug -k /usr/tests/sys/netinet/Kyuafile socket_afinet:socket_afinet_udp_recv_trunc
socket_afinet:socket_afinet_udp_recv_trunc  ->  passed

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

melifaro retitled this revision from sockets: implement MSG_TRUNC socket option. to sockets: implement MSG_TRUNC recv/recvmsg flag.Jul 25 2022, 8:09 PM
melifaro edited the summary of this revision. (Show Details)
melifaro edited the test plan for this revision. (Show Details)
melifaro added a reviewer: network.

Both are minor and can be changed on commit. (And as always, I can't review the C source.)

lib/libc/sys/recv.2
31

Bump.

190
This revision is now accepted and ready to land.Jul 26 2022, 10:12 PM

Fix mbuf leak & MSG_TRUNC flag clearning, address comments.

This revision now requires review to proceed.Jul 28 2022, 11:55 AM
This revision is now accepted and ready to land.Jul 29 2022, 10:22 PM