summaryrefslogtreecommitdiff
path: root/sys/compat/linux/linux_socket.c
AgeCommit message (Collapse)Author
2025-10-15linux: add translation for MCAST_JOIN_GROUP family of socket optionsGleb Smirnoff
Differential Revision: https://reviews.freebsd.org/D52937
2025-09-17linux: getsockopt(): Simplify exporting groups a bitOlivier Certner
No functional change (intended). Go through conversion to a 'l_gid_t' before copying out in order to cope with differing group types (except for not representable values, of course). This is what is done, e.g., for getgroups() in 'linux_misc.c'. As Linux's group type is the same as ours on all architectures, we could as well just stop bothering and copy out our memory representation, eliminating the loop here. Whatever the choice, though, it has to be consistent here and there. Introduce 'out' of type 'l_gid_t' to avoid performing "by hand" array arithmetics when copying out. MFC after: 5 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D52280
2025-03-10linux: Handle IP_RECVTOS cmsg typeAlex S
This unbreaks apps using GameNetworkingSockets from Valve.
2025-03-10linux: Fix a typo in linux_recvmsg_commonAlex S
We are supposed to check the result of bsd_to_linux_sockopt_level here rather than its input.
2024-11-13linux sendfile: Fix handling of non-blocking socketsMark Johnston
FreeBSD sendfile() may perform a partial transfer and return EAGAIN if the socket is non-blocking. Linux sendfile() expects no error in this case, so squash EAGAIN. PR: 282495 Tested by: pieter@krikkit.xyz MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D47447
2024-04-30Fix new users of MAXPHYS and hide it from the kernel namespaceAndrew Gallatin
In cd8537910406, kib made maxphys a load-time tunable. This made the #define MAXPHYS in sys/param.h almost entirely obsolete, as it could now be overridden by kern.maxphys at boot time, or by opt_maxphys.h. However, decades of tradition have led to several new, incorrect, uses of MAXPHYS in other parts of the kernel, mostly by seasoned developers. I've corrected those uses here in a mechanical fashion, and verified that it fixes a bug in the md driver that I was experiencing. Since using MAXPHYS is such an easy mistake to make, it is best to hide it from the kernel namespace. So I've moved its definition to _maxphys.h, which is now included in param.h only for userspace. That brings up the fact that lots of userspace programs use MAXPHYS for different reasons, most of them probably wrong. Userspace consumers that really need to know the value of maxphys should probably be changed to use the kern.maxphys sysctl. But that's outside the scope of this change. Reviewed by: imp, jkim, kib, markj Fixes: 30038a8b4efc ("md: Get rid of the pbuf zone") Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D44986
2024-04-22linux: ignore setsockopt(IPV6_RECVERR)Lexi Winter
Under Linux, the socket options IP_RECVERR and IPV6_RECVERR are used to receive socket errors via a dedicated 'error queue' which can be retrieved via recvmsg(). FreeBSD does not support this functionality. For IPv4, the sysctl compat.linux.ignore_ip_recverr can be set to 1 to silently ignore attempts to set IP_RECVERR and return success to the application, which is wrong, but is required for (among other things) a functional DNS client in recent versions of glibc. Add support for ignoring IPV6_RECVERR, controlled by the same sysctl. This fixes DNS in Linux when using IPv6 resolvers. Reviewed by: imp, Jose Luis Duran Pull Request: https://github.com/freebsd/freebsd-src/pull/1118
2024-03-29linux: use sa_family_t for address family conversionsGleb Smirnoff
Express "conversion failed" with maximum possible value. This allows to reduce number of size/signedness conversion in the code that utilizes the functions. PR: 274536 Reviewed by: melifaro Differential Revision: https://reviews.freebsd.org/D44375
2023-12-26linux/netlink: don't override sopt levelGleb Smirnoff
This override effectively prevents correct entering of netlink protocol specific pr_ctloutput in sosetopt(). Reviewed by: melifaro Differential Revision: https://reviews.freebsd.org/D42520
2023-11-30sockets: don't malloc/free sockaddr memory on getpeername/getsocknameGleb Smirnoff
Just like it was done for accept(2) in cfb1e92912b4, use same approach for two simplier syscalls that return socket addresses. Although, these two syscalls aren't performance critical, this change generalizes some code between 3 syscalls trimming code size. Following example of accept(2), provide VNET-aware and INVARIANT-checking wrappers sopeeraddr() and sosockaddr() around protosw methods. Reviewed by: tuexen Differential Revision: https://reviews.freebsd.org/D42694
2023-11-30sockets: don't malloc/free sockaddr memory on accept(2)Gleb Smirnoff
Let the accept functions provide stack memory for protocols to fill it in. Generic code should provide sockaddr_storage, specialized code may provide smaller structure. While rewriting accept(2) make 'addrlen' a true in/out parameter, reporting required length in case if provided length was insufficient. Our manual page accept(2) and POSIX don't explicitly require that, but one can read the text as they do. Linux also does that. Update tests accordingly. Reviewed by: rscheff, tuexen, zlei, dchagin Differential Revision: https://reviews.freebsd.org/D42635
2023-08-20linux(4): Replace linux32_copyiniov by freebsd32_copyiniovDmitry Chagin
MFC after: 1 month
2023-08-19linux(4): Return EAGAIN instead of ENOBUFS for non-blocking sockets in sendfileDmitry Chagin
MFC after: 1 month
2023-08-19linux(4): Allow in fd to be a socket in sendfileDmitry Chagin
In this case sendfile fallback is used. MFC after: 1 month
2023-08-18linux(4): Remove sys/cdefs.h inclusion where it's not needed due to 685dc743Dmitry Chagin
2023-08-17linux(4): Drop bogus __arm__ condition due to lack of 32-bit arm supportDmitry Chagin
MFC after: 1 month
2023-08-17linux(4): Don't miss error from underlying in sendfileDmitry Chagin
MFC after: 1 month
2023-08-17linux(4): Add sendfile fallback for non-socket fdsJames McLaughlin
Before Linux 2.6.33, out_fd must refer to a socket. Since Linux 2.6.33 it can be any file. The patch was originally provided by James McLaughlin and adapted by me for copy_file_range. PR: 262535 Differential revision: https://reviews.freebsd.org/D34555 MFC after: 1 month
2023-08-17linux(4): Use native off_t for fo_sendfile callDmitry Chagin
MFC after: 1 month
2023-08-16sys: Remove $FreeBSD$: one-line .c patternWarner Losh
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-14linux(4): Fix MSG_CTRUNC handling in recvmsg()Dmitry Chagin
The MSG_CTRUNC flag of the msg_flags member of the message header is set uppon successful completition if the control data was truncated. Upon return from a successful call msg_controllen should contain the length of the control message sequence. Fixes: 0eda2cea MFC after: 1 week
2023-08-14linux(4): Add a comment explaining udata freeing on errorDmitry Chagin
MFC after: 1 week
2023-08-14linux(4): Refactor recvmsgDmitry Chagin
As the amount of handled anxiliary messages grows move they handlers into a separate functions. MFC after: 1 week
2023-08-14linux(4): Skip unsupported anxiliary messageDmitry Chagin
Instead of returning error, skip unsupported anxiliary messages and fail if no one handled. MFC after: 1 week
2023-08-14linux(4): Improve readability of recvmsg control buffer copyout codeDmitry Chagin
MFC after: 1 week
2023-08-14linux(4): Drop bogus empty line in linux_socket.cDmitry Chagin
MFC after: 1 week
2023-08-14linux(4): Fix control message size calculation againDmitry Chagin
It looks Linux recvmsg allows msg_controllen size less then CMSG_SPACE buffer, at least for case with one cmsghdr. Glibc misc/tst-scm_rights test succed on Ubuntu 23.04 Fixes: 67116c69 "linux(4): Fix control message size calculation" MFC after: 1 week
2023-07-29linux(4): Fix control message size calculationDmitry Chagin
To determine the size in bytes needed to hold a control message and its contents of length len, CMSG_SPACE should be used. Reviewed by: Differential Revision: https://reviews.freebsd.org/D41224 MFC after: 1 week
2023-05-12spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
2023-03-04linux(4): Rename struct l_ifreq members names to avoid conflicts with FreeBSDDmitry Chagin
For now we are using mixed names to access struct ifreq members, some of Linux (ifr_name, ifr_ifindex), others of FreeBSD. To avoid conflicts switch to use FreeBSD names. Reviewed by: jhibbits Differential Revision: https://reviews.freebsd.org/D38792
2023-02-14linux(4): Rename linux_timer.h to linux_time.hDmitry Chagin
To avoid confusing people, rename linux_timer.h to linux_time.h, as linux_timer.c is the implementation of timer syscalls only, while linux_time.c contains implementation of all stuff declared in linux_time.h. MFC after: 2 weeks
2023-02-14linux(4): Cleanup includes under compat/linuxDmitry Chagin
Cleanup unneeded includes, sort the rest according to style(9). No functional changes. MFC after: 2 weeks
2023-02-14linux(4): Cleanup sys/uio.h where linux_uitl.h is includedDmitry Chagin
MFC after: 2 weeks
2023-02-12linux(4): Get rid of the opt_compat.h include.Dmitry Chagin
Since e013e369 COMPAT_LINUX, COMPAT_LINUX32 build options are removed, so include of opt_compat.h is no more needed. MFC after: 2 weeks
2022-10-01linuxolator: add netlink supportAlexander V. Chernikov
Add the glue code to support netlink in Linuxolator. linux_common(4) now depends on netlink(4). All netlink protocol constants are consistent with the Linux version. However, certain OS-specific constants such as AF_INET6, interface flags or default routing table id, are different between FreeBSD and Linux. Thus, it may be needed to rewrite some message parts or even rewrite the whole message, adding or removing some TLVs. The core netlink implementation code provides efficient rewriting callbacks which Linuxolator now uses. Reviewed by: dchagin Differential Revision: https://reviews.freebsd.org/D36361 MFC after: 2 months
2022-09-10Add getsockMateusz Guzik
All but one consumers of getsock_cap only pass 4 arguments. Take advantage of it.
2022-05-28linux(4): Handle multiple mbufs in a control message chain in recvmsgDmitry Chagin
PR: 230274 MFC after: 2 weeks
2022-05-28linux(4): Ratelimit message about unupported cmsgDmitry Chagin
MFC after: 2 weeks
2022-05-28linux(4): Handle IP_ORIGDSTADDR socket option for IPPROTO_IP protocol levelDmitry Chagin
MFC after: 2 weeks
2022-05-28linux(4): Overwrite SO_TIMESTAMP counterpartDmitry Chagin
A socket cannot mix SO_TIMESTAMP and SO_TIMESTAMPNS: the two modes are mutually exclusive. MFC after: 2 weeks
2022-05-28linux(4): Refactor linux_common_recvmsg()Dmitry Chagin
To improve readability lower nesting level, better naming for variables. No functional changes. MFC after: 2 weeks
2022-05-28linux(4): Handle SO_TIMESTAMPNS socket optionDmitry Chagin
The SO_TIMESTAMPNS enables or disables the receiving of the SCM_TIMESTAMPNS control message. The cmsg_data field is a struct timespec. To distinguish between SO_TIMESTAMP and SO_TIMESTAMPNS in the recvmsg() map the last one to the SO_BINTIME and convert bintime to the timespec. In the rest, implementation is identical to the SO_TIMESTAMP. MFC after: 2 weeks
2022-05-28linux(4): Handle 64-bit SO_TIMESTAMP for 32-bit binariesDmitry Chagin
To solve y2k38 problem in the recvmsg syscall the new SO_TIMESTAMP constant were added on v5.1 Linux kernel. So, old 32-bit binaries that knows only 32-bit time_t uses the old value of the constant, and binaries that knows 64-bit time_t uses the new constant. To determine what size of time_t type is expected by the user-space, store requested value (SO_TIMESTAMP) in the process emuldata structure. MFC after: 2 weeks
2022-05-28linux(4): For future use replace malloc type for l_sockaddr by M_LINUXDmitry Chagin
MFC after: 2 weeks
2022-05-28linux(4): Improve recvmsg() readabilityDmitry Chagin
To improve recvmsg() readability SCM_ handlers moved to a separate functions. MFC after: 2 weeks
2022-05-28linux(4): Avoid EISCONN if addr is specified for sendto()Dmitry Chagin
If the socket is in a connected state, the target address should be ignored. MFC after: 2 weeks
2022-05-28linux(4): Fix SO_LINGER l_onoff valueDmitry Chagin
On Linux l_onoff should be 1 when linger is used. MFC after: 2 weeks
2022-05-28linux(4): Add a helper to copyout getsockopt valueDmitry Chagin
For getsockopt(), optlen is a value-result argument, which is modified on return to indicate the actual size of the value returned. For some cases this was missed, fixed. MFC after: 2 weeks
2022-05-28linux(4): Check the socket before any others sanity checksDmitry Chagin
Strictly speaking, this check is performed by the kern_recvit(), but in the Linux emulation layer before calling the kernel we do other sanity checks and conversions from Linux types to the native types. This changes an order of the error returning that is critical for some buggy Linux applications. For recvmmsg() syscall this fixes a panic in case when the user-supplied vlen value is 0, then error is not initialized and garbage passed to the bsd_to_linux_errno(). MFC after: 2 weeks
2022-05-08linux(4): Add a helper intended for copying timespec's from the userspace.Dmitry Chagin
There are many places where we copyin Linux timespec from the userspace and then convert it to the kernel timespec. To avoid code duplication add a tiny halper for doing this. MFC after: 2 weeks