opnsense-src/lib/libc
Mark Johnston 93ff7dbaea socket: Implement SO_SPLICE
This is a feature which allows one to splice two TCP sockets together
such that data which arrives on one socket is automatically pushed into
the send buffer of the spliced socket.  This can be used to make TCP
proxying more efficient as it eliminates the need to copy data into and
out of userspace.

The interface is copied from OpenBSD, and this implementation aims to be
compatible.  Splicing is enabled by setting the SO_SPLICE socket option.
When spliced, data that arrives on the receive buffer is automatically
forwarded to the other socket.  In particular, splicing is a
unidirectional operation; to splice a socket pair in both directions,
SO_SPLICE needs to be applied to both sockets.  More concretely, when
setting the option one passes the following struct:

    struct splice {
	    int fd;
	    off_t max;
	    struct timveval idle;
    };

where "fd" refers to the socket to which the first socket is to be
spliced, and two setsockopt(SO_SPLICE) calls are required to set up a
bi-directional splice.

select(), poll() and kevent() do not return when data arrives in the
receive buffer of a spliced socket, as such data is expected to be
removed automatically once space is available in the corresponding send
buffer.  Userspace can perform I/O on spliced sockets, but it will be
unpredictably interleaved with splice I/O.

A splice can be configured to unsplice once a certain number of bytes
have been transmitted, or after a given time period.  Once unspliced,
the socket behaves normally from userspace's perspective.  The number of
bytes transmitted via the splice can be retrieved using
getsockopt(SO_SPLICE); this works after unsplicing as well, up until the
socket is closed or spliced again.  Userspace can also manually trigger
unsplicing by splicing to -1.

Splicing work is handled by dedicated threads, similar to KTLS.  A
worker thread is assigned at splice creation time.  At some point it
would be nice to have a direct dispatch mode, wherein the thread which
places data into a receive buffer is also responsible for pushing it
into the sink, but this requires tighter integration with the protocol
stack in order to avoid reentrancy problems.

Currently, sowakeup() and related functions will signal the worker
thread assigned to a spliced socket.  so_splice_xfer() does the hard
work of moving data between socket buffers.

Co-authored by:	gallatin
Reviewed by:	brooks (interface bits)
MFC after:	3 months
Sponsored by:	Klara, Inc.
Sponsored by:	Stormshield
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D46411

(cherry picked from commit a1da7dc1cdad8c000622a7b23ff5994ccfe9cac6)
2024-10-17 15:48:36 +00:00
..
aarch64 libc/aarch64: Remove an unneeded weak symbol 2024-09-02 08:49:39 +00:00
amd64 lib/libc/amd64/string: fix overread condition in memccpy 2024-08-07 16:18:40 +02:00
arm libc: rename arm and i386 Ovfork.S to vfork.S 2024-01-02 16:58:42 +00:00
capability capsicum: introduce cap_rights_is_empty Function 2024-06-05 11:55:17 -04:00
compat-43 libc: Remove empty comments in Symbol.map 2023-12-13 22:08:13 +00:00
csu libc: Purge unneeded cdefs.h 2023-11-26 21:20:09 -07:00
db libc: Remove empty comments in Symbol.map 2023-12-13 22:08:13 +00:00
gdtoa libc: Remove empty comments in Symbol.map 2023-12-13 22:08:13 +00:00
gen sysctl.3: document missing oids from kern.proc. node 2024-10-10 12:10:33 +03:00
gmon libc: Remove empty comments in Symbol.map 2023-12-13 22:08:13 +00:00
i386 libc: rename arm and i386 Ovfork.S to vfork.S 2024-01-02 16:58:42 +00:00
iconv libc: Remove empty comments in Symbol.map 2023-12-13 22:08:13 +00:00
include libc_private.h: use private namespace name for size_t 2024-04-30 04:14:52 +03:00
inet libc: Remove empty comments in Symbol.map 2023-12-13 22:08:13 +00:00
isc libc: Purge unneeded cdefs.h 2023-11-26 21:20:09 -07:00
locale libc: remove some obsolete VCS data 2023-12-13 23:08:50 +00:00
md Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
nameser libc: Remove empty comments in Symbol.map 2023-12-13 22:08:13 +00:00
net libc/getnameinfo: stop adding NI_NUMERICHOST where inappropriate 2024-09-28 10:35:11 +00:00
nls libc: Remove empty comments in Symbol.map 2023-12-13 22:08:13 +00:00
posix1e libc: correct some memory leaks in acl_to_text(3) and acl_to_text_np(3) 2023-12-20 10:29:55 +02:00
powerpc libc: centralize a few numeric symbols 2023-12-13 22:08:14 +00:00
powerpc64 libc: centralize a few numeric symbols 2023-12-13 22:08:14 +00:00
powerpcspe libc/<arch>/sys/Makefile.inc: remove cruft 2023-12-13 22:08:13 +00:00
quad libc: Remove empty comments in Symbol.map 2023-12-13 22:08:13 +00:00
regex regex: mixed sets are misidentified as singletons 2024-09-25 15:42:25 -05:00
resolv libc: Remove empty comments in Symbol.map 2023-12-13 22:08:13 +00:00
riscv libc: don't needlessly add vfork.o to NOASM 2024-01-02 16:58:54 +00:00
rpc libc: move NIS xdr_* symbols from rpc's to yp's Symbol.map 2024-05-29 11:40:18 -04:00
secure libc: Remove empty comments in Symbol.map 2023-12-13 22:08:13 +00:00
softfloat libc: Remove empty comments in Symbol.map 2023-12-13 22:08:13 +00:00
stdio printf(): Save errno earlier. 2024-10-06 09:12:49 +00:00
stdlib jemalloc: set LG_VADDR to 64 on amd64 2024-10-15 18:06:44 +03:00
stdtime libc: Improve description of mktime() / timegm(). 2024-04-04 11:41:41 +02:00
string libc: make strerror_rl() usable for libc 2024-04-30 03:48:10 +03:00
sys socket: Implement SO_SPLICE 2024-10-17 15:48:36 +00:00
tests regex: mixed sets are misidentified as singletons 2024-09-25 15:42:25 -05:00
uuid libc: Remove empty comments in Symbol.map 2023-12-13 22:08:13 +00:00
x86 pkru.3: Fix a typo in the manual page 2024-01-23 07:43:42 +01:00
xdr xdr(3): Fix a few typos in source code comments 2024-03-26 06:55:55 +01:00
yp libc: move NIS xdr_* symbols from rpc's to yp's Symbol.map 2024-05-29 11:40:18 -04:00
libc.ldscript Remove $FreeBSD$: one-line .c comment pattern 2023-08-16 11:54:29 -06:00
libc_nossp.ldscript Remove $FreeBSD$: one-line .c comment pattern 2023-08-16 11:54:29 -06:00
Makefile lib{c,lzma,z}: remove -DSYMBOL_VERSIONING from CFLAGS 2023-12-13 22:08:13 +00:00
Makefile.depend Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
Makefile.depend.options Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
Versions.def Create namespace for the symbols added during 15-CURRENT cycle 2024-01-31 01:14:38 -06:00