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)
Feb 11 2024, 4:06 AM
Unknown Object (File)
Feb 11 2024, 4:06 AM
Unknown Object (File)
Feb 11 2024, 4:06 AM
Unknown Object (File)
Jan 26 2024, 2:39 AM
Unknown Object (File)
Jan 3 2024, 10:51 AM
Unknown Object (File)
Dec 24 2023, 5:21 PM
Unknown Object (File)
Dec 23 2023, 1:35 AM
Unknown Object (File)
Dec 12 2023, 1:51 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