From 144e2f384068f39d70f678835009270aacba7074 Mon Sep 17 00:00:00 2001
From: Vladimir Dubrovin <3proxy@3proxy.ru>
Date: Mon, 12 Oct 2026 13:27:16 +0300
Subject: [PATCH] Build splice support on linux, fix standalone portmappers
building with cmake
---
CMakeLists.txt | 11 ++++++-----
Makefile.Linux | 8 ++++----
doc/html/man5/3proxy.cfg.5.html | 11 +++++------
man/3proxy.cfg.5 | 9 ++++-----
4 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1b324a1..1d76991 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -51,7 +51,7 @@ option(3PROXY_USE_OPENSSL "Enable TLS/SSL support via OpenSSL (fallback when wol
option(3PROXY_USE_PCRE2 "Enable PCRE2 regex filtering" ON)
option(3PROXY_USE_PAM "Enable PAM/PamAuth" ON)
option(3PROXY_USE_ODBC "Enable ODBC support (Unix only, always ON on Windows)" OFF)
-option(3PROXY_USE_SPLICE "Build Linux splice() support, slower than read/write for most traffic (Linux only)" OFF)
+option(3PROXY_USE_SPLICE "Build Linux splice() support, used by services given -s (Linux only)" ON)
option(3PROXY_USE_POLL "Use poll() instead of select() (Unix only)" ON)
option(3PROXY_USE_WSAPOLL "Use WSAPoll instead of select() (Windows only)" ON)
option(3PROXY_USE_NETFILTER "Enable Linux netfilter support (Linux only)" ON)
@@ -664,10 +664,7 @@ foreach(PROXY_NAME proxy socks pop3p imapp smtpp ftppr tcppm udppm tlspr)
${CMAKE_CURRENT_SOURCE_DIR}/src
)
- target_compile_definitions(${PROXY_NAME} PRIVATE
- WITHMAIN
- NOPORTMAP
- )
+ target_compile_definitions(${PROXY_NAME} PRIVATE WITHMAIN)
if(NOT PROXY_NAME STREQUAL "udppm")
target_compile_definitions(${PROXY_NAME} PRIVATE NOUDPMAIN)
@@ -679,8 +676,12 @@ foreach(PROXY_NAME proxy socks pop3p imapp smtpp ftppr tcppm udppm tlspr)
target_compile_definitions(${PROXY_NAME} PRIVATE ANONYMOUS)
endif()
+ # port mappers take port, host and port as arguments, the others options
+ # only; one of the two is defined, as in src/Makefile.inc
if(PROXY_NAME STREQUAL "tcppm" OR PROXY_NAME STREQUAL "udppm" OR PROXY_NAME STREQUAL "tlspr")
target_compile_definitions(${PROXY_NAME} PRIVATE PORTMAP)
+ else()
+ target_compile_definitions(${PROXY_NAME} PRIVATE NOPORTMAP)
endif()
if(WIN32)
diff --git a/Makefile.Linux b/Makefile.Linux
index e399f60..62706ca 100644
--- a/Makefile.Linux
+++ b/Makefile.Linux
@@ -4,9 +4,9 @@
# add -DWITH_ODBC to CFLAGS and -lodbc to LIBS to compile with ODBC
# library support. Add -DSAFESQL for poorely written ODBC library / drivers.
#
-# Linux splice() support is not built by default, it is slower than the
-# read/write path for most traffic. Add -DWITHSPLICE to CFLAGS to build it,
-# it must additionally be enabled per service with the -s option.
+# Linux splice() support is built, but used only by services given the -s
+# option: it is faster for large transfers and slower for small requests.
+# Remove -DWITHSPLICE from CFLAGS to build without it.
BUILDDIR = ../bin/
PREFIX ?= 3proxy_
@@ -14,7 +14,7 @@ CRYPT_PREFIX ?= $(PREFIX)
CC ?= gcc
CFLAGS ?= -O3 -flto
-CFLAGS += -fno-strict-aliasing -c -pthread -D_GNU_SOURCE -DGETHOSTBYNAME_R -D_THREAD_SAFE -D_REENTRANT -DFD_SETSIZE=4096 -DWITH_POLL -DWITH_NETFILTER -D WITH_UN
+CFLAGS += -fno-strict-aliasing -c -pthread -DWITHSPLICE -D_GNU_SOURCE -DGETHOSTBYNAME_R -D_THREAD_SAFE -D_REENTRANT -DFD_SETSIZE=4096 -DWITH_POLL -DWITH_NETFILTER -D WITH_UN
COUT = -o
LN ?= ${CC}
DCFLAGS ?= -fPIC
diff --git a/doc/html/man5/3proxy.cfg.5.html b/doc/html/man5/3proxy.cfg.5.html
index a32e730..b87e0f4 100644
--- a/doc/html/man5/3proxy.cfg.5.html
+++ b/doc/html/man5/3proxy.cfg.5.html
@@ -216,12 +216,11 @@ second. Useful to minimize polling
-s
(for admin) secure, allow only secure operations, currently
only traffic counters view without ability to reset.
-(for TCP services, Linux) enable splice(). splice() is not
-built by default and is disabled even when built, because
-current Linux does not implement SPLICE_F_MOVE, so no real
-zero-copy takes place and the read/write path is faster for
-most traffic. Rebuild with -DWITHSPLICE to make -s
-available, -s0 disables it explicitly.
+(for TCP services, Linux) enable splice(). It is built on
+Linux by default, but off unless -s is given: splice() is
+faster for large transfers and the read/write path for small
+requests. -s0 disables it explicitly; build without
+-DWITHSPLICE to leave it out.
-C
(for TCP services) a connection closed by any of the sides
terminates the session, buffered data is delivered before
diff --git a/man/3proxy.cfg.5 b/man/3proxy.cfg.5
index 0d33895..0920fe6 100644
--- a/man/3proxy.cfg.5
+++ b/man/3proxy.cfg.5
@@ -194,11 +194,10 @@ delay GRACE_DELAY milliseconds before polling if average polling size is below G
(for admin) secure, allow only secure operations, currently only traffic counters
view without ability to reset.
.br
- (for TCP services, Linux) enable splice(). splice() is not built by default and
-is disabled even when built, because current Linux does not implement
-SPLICE_F_MOVE, so no real zero-copy takes place and the read/write path is faster
-for most traffic. Rebuild with -DWITHSPLICE to make -s available, -s0 disables it
-explicitly.
+ (for TCP services, Linux) enable splice(). It is built on Linux by default,
+but off unless -s is given: splice() is faster for large transfers and the
+read/write path for small requests. -s0 disables it explicitly; build without
+-DWITHSPLICE to leave it out.
.br
.B -C
(for TCP services) a connection closed by any of the sides terminates the