HomeFreeBSD

sockets: add MSG_TRUNC flag handling for recvfrom()/recvmsg().

Description

sockets: add MSG_TRUNC flag handling for recvfrom()/recvmsg().

Implement Linux-variant of MSG_TRUNC input 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,
resulting in returning the full packet size regarless of the input
buffer 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 commit implements the MSG_TRUNC support for SOCK_DGRAM sockets (udp, unix and all soreceive_generic() users).

PR: kern/176322
Reviewed by: pauamma(doc)
Differential Revision: https://reviews.freebsd.org/D35909
MFC after: 1 month

(cherry picked from commit be1f485d7d6bebc53b055cc165a11ada0ab5fb17)

Details

Provenance
melifaroAuthored on Jul 25 2022, 7:46 PM
Differential Revision
D35909: sockets: implement MSG_TRUNC recv/recvmsg flag
Parents
rG43a04e3a0a74: md5/tests: extend md5 test
Branches
Unknown
Tags
Unknown