Page MenuHomeFreeBSD

sockets: implement MSG_TRUNC recv/recvmsg flag
ClosedPublic

Authored by melifaro on Jul 25 2022, 7:48 PM.
Tags
None
Referenced Files
Unknown Object (File)
Oct 1 2024, 4:16 AM
Unknown Object (File)
Sep 27 2024, 5:51 AM
Unknown Object (File)
Sep 23 2024, 8:44 PM
Unknown Object (File)
Sep 23 2024, 9:50 AM
Unknown Object (File)
Sep 22 2024, 9:14 PM
Unknown Object (File)
Sep 18 2024, 6:15 PM
Unknown Object (File)
Sep 17 2024, 12:08 PM
Unknown Object (File)
Sep 16 2024, 12:53 PM

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
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 46554
Build 43443: arc lint + arc unit

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