Hi, here is the most recent diff for the libc part of send and recvmmsg. This requires a libc minor bump and therefore should be coordinated after snapshots are building normally again.
To my understanding the minor bump itself should not cause problems in ports anymore. mbuhl Index: lib/libc/Symbols.list =================================================================== RCS file: /cvs/src/lib/libc/Symbols.list,v retrieving revision 1.75 diff -u -p -r1.75 Symbols.list --- lib/libc/Symbols.list 2 Aug 2022 16:45:00 -0000 1.75 +++ lib/libc/Symbols.list 6 Sep 2022 09:36:40 -0000 @@ -175,6 +175,7 @@ _thread_sys_readlinkat _thread_sys_readv _thread_sys_reboot _thread_sys_recvfrom +_thread_sys_recvmmsg _thread_sys_recvmsg _thread_sys_rename _thread_sys_renameat @@ -184,6 +185,7 @@ _thread_sys_sched_yield _thread_sys_select _thread_sys_semget _thread_sys_semop +_thread_sys_sendmmsg _thread_sys_sendmsg _thread_sys_sendsyslog _thread_sys_sendto @@ -372,6 +374,7 @@ readlinkat readv reboot recvfrom +recvmmsg recvmsg rename renameat @@ -383,6 +386,7 @@ select semctl semget semop +sendmmsg sendmsg sendsyslog sendto Index: lib/libc/shlib_version =================================================================== RCS file: /cvs/src/lib/libc/shlib_version,v retrieving revision 1.210 diff -u -p -r1.210 shlib_version --- lib/libc/shlib_version 2 Jun 2021 07:29:03 -0000 1.210 +++ lib/libc/shlib_version 5 Sep 2022 11:57:10 -0000 @@ -1,4 +1,4 @@ major=96 -minor=1 +minor=2 # note: If changes were made to include/thread_private.h or if system calls # were added/changed then librthread/shlib_version must also be updated. Index: lib/libc/hidden/sys/socket.h =================================================================== RCS file: /cvs/src/lib/libc/hidden/sys/socket.h,v retrieving revision 1.4 diff -u -p -r1.4 socket.h --- lib/libc/hidden/sys/socket.h 7 May 2016 19:05:22 -0000 1.4 +++ lib/libc/hidden/sys/socket.h 6 Sep 2022 09:36:49 -0000 @@ -33,9 +33,11 @@ PROTO_NORMAL(listen); PROTO_NORMAL(recv); PROTO_CANCEL(recvfrom); PROTO_CANCEL(recvmsg); +PROTO_CANCEL(recvmmsg); PROTO_NORMAL(send); -PROTO_CANCEL(sendmsg); PROTO_CANCEL(sendto); +PROTO_CANCEL(sendmsg); +PROTO_CANCEL(sendmmsg); PROTO_NORMAL(setrtable); PROTO_NORMAL(setsockopt); PROTO_NORMAL(shutdown); Index: lib/libc/sys/Makefile.inc =================================================================== RCS file: /cvs/src/lib/libc/sys/Makefile.inc,v retrieving revision 1.163 diff -u -p -r1.163 Makefile.inc --- lib/libc/sys/Makefile.inc 17 Jul 2022 03:04:27 -0000 1.163 +++ lib/libc/sys/Makefile.inc 6 Sep 2022 09:37:18 -0000 @@ -34,8 +34,8 @@ CANCEL= accept accept4 \ nanosleep \ open openat \ poll ppoll pread preadv pselect pwrite pwritev \ - read readv recvfrom recvmsg \ - select sendmsg sendto \ + read readv recvfrom recvmsg recvmmsg \ + select sendto sendmsg sendmmsg \ wait4 write writev SRCS+= ${CANCEL:%=w_%.c} Index: lib/libc/sys/recv.2 =================================================================== RCS file: /cvs/src/lib/libc/sys/recv.2,v retrieving revision 1.48 diff -u -p -r1.48 recv.2 --- lib/libc/sys/recv.2 21 Nov 2021 23:44:55 -0000 1.48 +++ lib/libc/sys/recv.2 5 Sep 2022 14:59:00 -0000 @@ -46,15 +46,35 @@ .Fn recvfrom "int s" "void *buf" "size_t len" "int flags" "struct sockaddr *from" "socklen_t *fromlen" .Ft ssize_t .Fn recvmsg "int s" "struct msghdr *msg" "int flags" +.Ft int +.Fn recvmmsg "int s" "struct mmsghdr *mmsg" "unsigned int vlen" "int flags" "struct timespec *timeout" .Sh DESCRIPTION -.Fn recvfrom +.Fn recv , +.Fn recvfrom , +.Fn recvmsg , and -.Fn recvmsg +.Fn recvmmsg are used to receive messages from a socket, -.Fa s , -and may be used to receive +.Fa s . +.Fn recv +is normally used only on a +.Em connected +socket (see +.Xr connect 2 ). +.Fn recvfrom , +.Fn recvmsg , +and +.Fn recvmmsg +may be used to receive data on a socket whether or not it is connection-oriented. .Pp +.Fn recv +is identical to +.Fn recvfrom +with a null +.Fa from +parameter. +.Pp If .Fa from is non-null and the socket is not connection-oriented, @@ -66,25 +86,6 @@ the buffer associated with and modified on return to indicate the actual size of the address stored there. .Pp -The -.Fn recv -call is normally used only on a -.Em connected -socket (see -.Xr connect 2 ) -and is identical to -.Fn recvfrom -with a null -.Fa from -parameter. -.Pp -On successful completion, all three routines return the number of -message bytes read. -If a message is too long to fit in the supplied -buffer, excess bytes may be discarded depending on the type of socket -the message is received from (see -.Xr socket 2 ) . -.Pp If no messages are available at the socket, the receive call waits for a message to arrive, unless the socket is nonblocking (see @@ -158,6 +159,8 @@ The .Dv MSG_CMSG_CLOEXEC requests that any file descriptors received as ancillary data with .Fn recvmsg +and +.Fn recvmmsg (see below) have their close-on-exec flag set. .Pp @@ -249,13 +252,67 @@ Indicates that the packet was received a .It Dv MSG_MCAST Indicates that the packet was received as multicast. .El +.Pp +The +.Fn recvmmsg +call uses an array of the +.Fa mmsghdr +structure of length +.Fa vlen +to group multiple +.Fa msghdr +structures into a single system call. +.Fa vlen +is capped at maximum +.Dv 1024 +messages that are received in a single call. +The +.Fa flags +field allows setting +.Dv MSG_WAITFORONE +to wait for one +.Fa msghdr , +and set +.Dv MSG_DONTWAIT +for all subsequent messages. +A provided +.Fa timeout +limits the time spent in the function but it does not limit the +time spent in lower parts of the kernel. +.Pp +The +.Fa mmsghdr +structure has the following form, as defined in +.In sys/socket.h : +.Bd -literal +struct mmsghdr { + struct msghdr msg_hdr; + unsigned int msg_len; +}; +.Ed +.Pp +Here +.Fa msg_len +indicated the number of bytes received for each +.Fa msg_hdr +member. .Sh RETURN VALUES -These calls return the number of bytes received, or \-1 if an error occurred. -.Sh ERRORS +The .Fn recv , .Fn recvfrom , and .Fn recvmsg +calls return the number of bytes received, or \-1 if an error occurred. +The +.Fn recvmmsg +call returns the number of messages received, or \-1 +if an error occurred before the first message has been received. +.Sh ERRORS +.Fn recv , +.Fn recvfrom , +.Fn recvmsg , +and +.Fn recvmmsg fail if: .Bl -tag -width "[EHOSTUNREACH]" .It Bq Er EBADF @@ -310,6 +367,8 @@ was larger than .Pp And .Fn recvmsg +and +.Fn recvmmsg may return one of the following errors: .Bl -tag -width Er .It Bq Er EINVAL @@ -364,6 +423,10 @@ The .Fn recv function call appeared in .Bx 4.1c . +The +.Fn recvmmsg +syscall first appeared in Linux 2.6.33 and was added to +.Ox 7.2 . .Sh CAVEATS Calling .Fn recvmsg Index: lib/libc/sys/send.2 =================================================================== RCS file: /cvs/src/lib/libc/sys/send.2,v retrieving revision 1.34 diff -u -p -r1.34 send.2 --- lib/libc/sys/send.2 11 Jan 2019 06:10:13 -0000 1.34 +++ lib/libc/sys/send.2 5 Sep 2022 14:59:10 -0000 @@ -36,7 +36,8 @@ .Sh NAME .Nm send , .Nm sendto , -.Nm sendmsg +.Nm sendmsg , +.Nm sendmmsg .Nd send a message from a socket .Sh SYNOPSIS .In sys/socket.h @@ -46,19 +47,23 @@ .Fn sendto "int s" "const void *msg" "size_t len" "int flags" "const struct sockaddr *to" "socklen_t tolen" .Ft ssize_t .Fn sendmsg "int s" "const struct msghdr *msg" "int flags" +.Ft int +.Fn sendmmsg "int s" "const struct mmsghdr *mmsg" "unsigned int vlen" "int flags" .Sh DESCRIPTION .Fn send , .Fn sendto , +.Fn sendmsg , and -.Fn sendmsg +.Fn sendmmsg are used to transmit a message to another socket. .Fn send may be used only when the socket is in a .Em connected state, while -.Fn sendto +.Fn sendto , +.Fn sendmsg , and -.Fn sendmsg +.Fn sendmmsg may be used at any time. .Pp The address of the target is given by @@ -127,10 +132,21 @@ See .Xr recv 2 for a description of the .Fa msghdr -structure. +and +.Fa mmsghdr +structures. .Sh RETURN VALUES -The call returns the number of characters sent, or \-1 +The +.Fn send , +.Fn sendto , +and +.Fn sendmsg +calls return the number of characters sent, or \-1 if an error occurred. +The +.Fn sendmmsg +call returns the number of messages sent, or \-1 +if an error occurred before the first message has been sent. .Sh ERRORS .Fn send , .Fn sendto , @@ -267,3 +283,7 @@ The .Fn send function call appeared in .Bx 4.1c . +The +.Fn sendmmsg +syscall first appeared in Linux 3.0 and was added to +.Ox 7.2 . Index: lib/libc/sys/w_recvmmsg.c =================================================================== RCS file: lib/libc/sys/w_recvmmsg.c diff -N lib/libc/sys/w_recvmmsg.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libc/sys/w_recvmmsg.c 6 Sep 2022 09:42:08 -0000 @@ -0,0 +1,32 @@ +/* $OpenBSD$ */ +/* + * Copyright (c) 2022 Moritz Buhl <mb...@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/socket.h> +#include "cancel.h" + +int +recvmmsg(int fd, struct mmsghdr *mmsg, unsigned int vlen, int flags, + struct timespec *ts) +{ + int ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(recvmmsg)(fd, mmsg, vlen, flags, ts); + LEAVE_CANCEL_POINT(ret == -1); + return (ret); +} +DEF_CANCEL(recvmmsg); Index: lib/libc/sys/w_sendmmsg.c =================================================================== RCS file: lib/libc/sys/w_sendmmsg.c diff -N lib/libc/sys/w_sendmmsg.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libc/sys/w_sendmmsg.c 6 Sep 2022 09:42:01 -0000 @@ -0,0 +1,31 @@ +/* $OpenBSD$ */ +/* + * Copyright (c) 2022 Moritz Buhl <mb...@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/socket.h> +#include "cancel.h" + +int +sendmmsg(int s, struct mmsghdr *mmsg, unsigned int vlen, int flags) +{ + int ret; + + ENTER_CANCEL_POINT(1); + ret = HIDDEN(sendmmsg)(s, mmsg, vlen, flags); + LEAVE_CANCEL_POINT(ret <= 0); + return (ret); +} +DEF_CANCEL(sendmmsg);