Bug 176322 - [libc] MSG_TRUNC does not return real length of the packet in recv()
Summary: [libc] MSG_TRUNC does not return real length of the packet in recv()
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: Alexander V. Chernikov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-21 14:00 UTC by ramya
Modified: 2023-06-13 06:48 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ramya 2013-02-21 14:00:00 UTC
Hello,

recv() in Linux 2.6 kernel has a fix for returning the original length
of the packet even when the packet is truncated using the MSG_TRUNC flag. 

However, is there a fix for this in FREEBSD???
recv() does not return the original length of the packet in freebsd. 
I need to get the original length of the packet on freebsd.

Please HELP !!!!

Thanks,
Ramya
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:00:12 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 2 Alexander V. Chernikov freebsd_committer freebsd_triage 2022-07-28 10:49:22 UTC
https://reviews.freebsd.org/D35909 adds the required bits for handling MSG_TRUNC
Comment 3 commit-hook freebsd_committer freebsd_triage 2022-07-30 18:47:24 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=be1f485d7d6bebc53b055cc165a11ada0ab5fb17

commit be1f485d7d6bebc53b055cc165a11ada0ab5fb17
Author:     Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2022-07-25 19:46:40 +0000
Commit:     Alexander V. Chernikov <melifaro@FreeBSD.org>
CommitDate: 2022-07-30 18:21:51 +0000

    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

 lib/libc/sys/recv.2                     |  12 +++
 sys/kern/uipc_socket.c                  |  13 ++-
 sys/kern/uipc_usrreq.c                  |  29 ++++--
 tests/sys/kern/Makefile                 |   1 +
 tests/sys/kern/socket_msg_trunc.c (new) | 169 ++++++++++++++++++++++++++++++++
 5 files changed, 212 insertions(+), 12 deletions(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2023-02-09 18:02:52 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=adaf752192c165b66875e81db62d274a09591d0c

commit adaf752192c165b66875e81db62d274a09591d0c
Author:     Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2022-07-25 19:46:40 +0000
Commit:     Alexander V. Chernikov <melifaro@FreeBSD.org>
CommitDate: 2023-02-09 18:01:49 +0000

    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)

 lib/libc/sys/recv.2                     |  12 +++
 sys/kern/uipc_socket.c                  |  13 ++-
 tests/sys/kern/Makefile                 |   1 +
 tests/sys/kern/socket_msg_trunc.c (new) | 169 ++++++++++++++++++++++++++++++++
 4 files changed, 191 insertions(+), 4 deletions(-)