Commit Graph
100 Commits
Author SHA1 Message Date
Vladimir Dubrovin 61b5ae5e0b socks: a host name with control bytes or spaces is refused where it is read 2026-11-18 20:20:46 +03:00
Vladimir Dubrovin 83269785df smtpp: a login name of a port alone names no destination 2026-11-18 20:20:22 +03:00
Vladimir Dubrovin 51559e12c4 tcptoudp, udptotcp: tunnels between TCP and UDP
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Has been cancelled
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Has been cancelled
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Has been cancelled
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Has been cancelled
C/C++ CI cmake / ubuntu-latest (wolfSSL) (push) Has been cancelled
Datagrams on a TCP connection, each with a two byte length in network
order in front of it, which is how udptunnel (the rfc1036 one) and
ProxyGuard (eduVPN) put them there, the framing alone or after a
handshake: udptunnel's 32 bytes, or ProxyGuard's HTTP Upgrade for
UoTLV/1 answered with 101 Switching Protocols.

tcptoudp takes the connections, a UDP socket of its own to the target
for each, the handshake a client speaks recognised by its first bytes
and answered; a parent the ACL gives is a SOCKS5 UDP relay, as for
udppm. udptotcp takes the datagrams, each client a session of the
service's with a TCP connection of its own, connected as the service's
loop sees it writable (dnspr asks a name server over TCP the same way);
-m sends udptunnel's handshake to the target, -m2 ProxyGuard's, -m0
(the default) none, so both ends of either tool are stood in for.

The service names take two places of the string table, the default
configuration path moving two later (stringtable[27]).

Built by the Makefiles and CMake, with the standalone binaries, and
installed by them; a case of the test suite speaks all three handshakes.
2026-11-15 16:03:15 +03:00
Vladimir Dubrovin 79583d7aa7 proxy: credentials of an earlier request not inherited by the next 2026-11-13 18:01:47 +03:00
Vladimir Dubrovin 796eff444a httpsrv: credentials of an earlier request not inherited by the next 2026-11-13 17:16:25 +03:00
Vladimir Dubrovin 57b94b209b tlspr: a ServerHello too short for the extensions length refused (#1286)
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Has been cancelled
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Has been cancelled
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Has been cancelled
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Has been cancelled
C/C++ CI cmake / ubuntu-latest (wolfSSL) (push) Has been cancelled
2026-11-10 15:20:13 +03:00
Vladimir Dubrovin 3040de2b55 httpsrv: a limit exceeded answered with 503, not ignored
Authorization reports 10 when a limit of the service was exceeded,
which every other child answers with 503; the http server took it as
success and answered the request anyway. It now says 503 for itself,
after the body of the request is drained as any answer here does.

(cherry picked from commit 5a2e9d27c3)
2026-11-08 14:54:57 +03:00
Vladimir Dubrovin c687380776 httpsrv: a dot-dot segment of a path refused, with either separator
A path ending in a backslashed dot-dot, or carrying one in a form the
checks did not name, was taken as it stood. Any dot-dot segment is now
refused wherever it is and whichever separator carries it, and a path
ending in a bare dot of either kind.

(cherry picked from commit c0eb7a65c6)
2026-11-08 14:54:57 +03:00
Vladimir Dubrovin a00c0823f5 pcre: a rule with no ACL a match data of its own, not itself
A rule whose ACL was missing was handed to the filters as the
connection's data, which they read as a match data block and freed:
a pointer into the configuration, dereferenced as another type and
given back to malloc. A rule without an ACL now skips the check and
goes on with a block of its own, and nothing a filter is given is
ever the rule itself.

(cherry picked from commit a7e5a8b48b)
2026-11-08 14:54:57 +03:00
Vladimir Dubrovin 01600e46d6 pcre: a match data of the connection's own, not of the rule's
Every connection matching a pcre rule matched on the one match data
block of the rule, which pcre2_match() writes into: two connections
matching at the same time wrote the same block, a race that corrupts
memory and brings the process down after a while under load. A
connection that passes the rule's ACL now makes a match data block of
its own when it starts and frees it when it ends; the match context is
kept, as it is only read while matching.
2026-11-02 12:26:55 +03:00
Vladimir Dubrovin 0cf5dfc6a3 Windows: the loop's socket results in the type the socket calls return
ssize_t does not exist under MSVC, and the socket function table
already spells its send and recv results int there and ssize_t
elsewhere. That type is now named SOCKRET, beside SASIZETYPE, and the
event loop's copies of it use the name, so the MSVC build compiles
again.
2026-11-02 12:11:09 +03:00
Vladimir Dubrovin 235f899668 help: the features of the build listed, and the tests skip what they need
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Has been cancelled
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Has been cancelled
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Has been cancelled
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Has been cancelled
C/C++ CI cmake / ubuntu-latest (wolfSSL) (push) Has been cancelled
3proxy --help (and the usage message of a bad invocation) now lists
what the build was made with: TLS and its backend, RADIUS, PCRE, IPv6,
UNIX sockets, the built-in HTTP server, transparency, ODBC and the
optional proxy services. The test runner reads the list before the
first case and the cases state the features they need with
t.skip_unless(), so a build without a feature skips its cases instead
of failing them; a binary too old to report anything skips the cases
with needs and runs the rest.
2026-10-30 14:17:54 +03:00
Vladimir Dubrovin 83045b0443 radius: the reply hashed with the secret, and taken only from the server asked
The reply digest copied the shared secret right after the received
bytes, so a reply of 4100 bytes with a secret of 17 or more characters
wrote up to 47 bytes of it past the reply buffer on the stack, before
the reply was authenticated. The digest is now taken over the reply
and the secret in place, with nothing written past the reply, and it
fails closed when the hash cannot be made. A reply is also taken only
from the address and port of the server the request went to, and only
when its identifier and length field match the request, all before any
digest work; the reply's sender was never checked before.
2026-10-30 13:56:06 +03:00
Vladimir Dubrovin 06a534ee53 resolve: the PTR answer of dnsname walked inside its record data
The label walk of a DNS PTR answer ran to the end of the whole message,
not to the end of the record's data, and took a compression pointer for
a label length, so it could write past the end of the answer buffer on
the stack. An answer of 3841 bytes or more reached past the buffer
itself. A record that ended exactly at the end of the message was also
read one byte past it. The walk now stops at the end of the record's
data, a name that does not end there, or one that is compressed or
empty is not accepted, and the answer loop reads nothing past the
message.
2026-10-30 12:50:30 +03:00
Vladimir Dubrovin bb52a5fb0e Bench: the four versions against every proxy, 30 October results
3proxy 0.9.9.2, 1.0.2, devel (c3702866) and the experimental head (5de7ae2)
against nginx (with and without proxy_half_close), haproxy (plain and
splice-auto), envoy, squid, tinyproxy and dante on the M4 and the Skylake
host: the plain suite and the mix over a shaped link (20 Mbit/s, 5 ms,
0.5% loss), three runs a cell, proxy memory capped at 6 GB (--prx-mem-mb,
new). dante re-measured on the SOCKS scenarios only; its mix behaviour
stays in its own smaller-pool table. RESULTS.md rebuilt around six uniform
tables: throughput, memory and errors, p75/p90/p99.
2026-10-30 12:21:40 +03:00
Vladimir DubrovinandClaude Opus 5.5 5de7ae2dac Buffers: a pool of mapped pages, buffers of 16384 bytes
A connection's buffers came from malloc(), which keeps what it is given
back: a buffer let go while the connection waits (HTTP keep-alive, an
idle relay) left its memory with the process. They now come from a
pool of memory mapped for them, in chunks aligned to their size, the
first unit of a chunk its header. A unit is a page, or a buffer if pages
are smaller: with pages of 4 or 16 KB a buffer is a unit of its own,
with pages of 64 KB a unit holds four. Free units are kept for the next
buffer, the most recently freed first; more than 64 and an eighth of
those in use, and the least recently freed are given back to the system
(MADV_DONTNEED on Linux, MADV_FREE_REUSABLE on macOS, MADV_FREE
elsewhere, MEM_RESET on Windows), and a chunk given back whole is
unmapped. Built for AddressSanitizer the buffers stay malloc()'s, which
it checks for overruns, unless WITHBUFPOOL is defined; the pool then
poisons the free ones.

Buffers are 16384 bytes, not 16384 + 64: a size of pages. The 64 bytes
were room for a TLS record's header, which tlspr needs to have a record
whole; tlspr now takes a larger buffer when a record does not fit, up to
TLS's largest (5 + 16384 + 2048), given back once it is emptied, and
relays read the whole buffer again, a record at most as before. A record
larger than the buffer set with -b is no longer refused.

HTTP proxy, 2000 idle keep-alive connections, after a request (Linux
container): 39.6 KB a connection before, 19.5 KB now; a thread a
connection, 44.2 KB before, 24.1 KB now; a TCP relay, 13.0 KB before,
11.6 KB now.

Incompatible for plugins: CLIENTBUFSIZE is 16384; clibufdata and
srvbufdata are the pool's, never to be passed to free() or realloc().
bufpoolinit() is called before any service starts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 17:16:41 +03:00
Vladimir DubrovinandClaude Opus 5.5 a6402010a4 Relays: the size of a splice() pipe given to a service, -b,SIZE
-b, which made a service read less at once into a connection's buffer,
takes the size of its pipes after a comma: -b,262144, -b8192,32768.
From 4096 to 64M (MAXPIPESIZE); a pipe the system will not make so
large (pipe-max-size for an unprivileged process) is not used, and the
data is copied, as with -DPIPESIZE, which stays the default for a
service given none. sockmap() and the callbacks' relay fill a pipe up
to the service's size (SRVPIPESIZE()), and only a pipe of other than
64K costs an fcntl() as it is made.

The man page tells of -b, which it did not before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 13:20:42 +03:00
Vladimir DubrovinandClaude Opus 5.5 add40b1d85 HTTP proxy: no NTLM left
NTLM authentication of proxy clients was gone but for what was left of
it: the 407 answer offering NTLM before Basic (12, under NOCRYPT, which
nothing else used) and the one for its handshake (13), sent by nothing,
and the prototypes of genchallenge() and mschap(), defined nowhere. The
strings after them in proxy_stringtable move up two: 403 with <pre> is
12, 503 13, 401 of the FTP server 14, 100 Continue 15.

rus.3ps, StringsPlugin's translation, follows: the two strings go, the
403 with <pre> is UTF-8 as the rest, the XML of the running services
has its Content-disposition, and the table of counters the columns of
its rows (Action and #/Description were one).

NT: passwords, MD4 hashes as Windows keeps them, stay. The documents
no longer tell to give proxy -n to turn off NTLM.

Plugin binary compatibility: a plugin indexing proxy_stringtable finds
the strings from 12 on two places earlier, and a .3ps file of its own
with the NTLM strings has two more than 3proxy (StringsPlugin warns).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 12:02:27 +03:00
Vladimir DubrovinandClaude Opus 5.5 e396da2696 StringsPlugin: a line's end cut off without reading past it
load_string() put a NUL where a line read from the file had its CR or
LF, and stepped over it as well as over the character after: past the
line's NUL terminator, into what was left in the buffer from longer
lines before, or past its end, writing NULs wherever it found CR or LF.
The line is cut at its first CR or LF instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 12:01:35 +03:00
Vladimir DubrovinandClaude Opus 5.5 c846b4950d Relays, SOCKS: no tracing of their own
sockmap() under WITHLOG, and the SOCKS proxy under SOCKSTRACE, wrote
what they did to the log or to stderr, a build for debugging asking for
it: some 200 lines in the middle of the code, never built otherwise.
They go.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 11:57:37 +03:00
Vladimir DubrovinandClaude Opus 5.5 d762833a6b Builds: no Solaris makefile, no generic Unix makefile, no gethostbyname()
Names are resolved with getaddrinfo(), thread-safe everywhere: what was
left of gethostbyname() (my_gethostbyname() over gethostbyname_r(), in
its glibc and Solaris forms, GETHOSTBYNAME_R, the mutex for the plain
one) served only the IPv4-only resolver already gone. Makefile.Solaris
(Sun's compiler, _SOLARIS) and Makefile.unix go: CMake builds for the
other systems; the documents say so, and their examples use
Makefile.FreeBSD.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 11:57:10 +03:00
Vladimir DubrovinandClaude Opus 5.5 ed49f9ab77 Windows: no Windows CE, no Windows 9x
Windows CE (_WINCE: WinMain() and its window, the command line made
into argv, the paths and functions it went without) and Windows 9x
(--install and --remove through the RunServices key of the registry,
which is what GetVersionEx() was asked for) are no longer built for.
--install and --remove use the Service Manager alone; Winsock 2.2 is
asked for, which WSAPoll() needs, rather than 1.1.

The service command of a configuration, deprecated, still does
nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 11:56:05 +03:00
Vladimir DubrovinandClaude Opus 5.5 fa3807c6f1 Builds: no Open Watcom, no build without IPv6, no select()
The Win32 "lite" build with Open Watcom (Makefile.watcom, its release
workflow, the CMake branch for it) was the only one built without IPv6
(NOIPV6), without fibers and event loops, with a select() of its own
for poll() (mypoll()), and with the calling conventions of Watcom's
pragmas in the plugins. They are gone with it: every build has IPv6,
and polls with poll() on Unix and WSAPoll() on Windows, which were
what every other build asked for (WITH_POLL, WITH_WSAPOLL, the
3PROXY_USE_POLL and 3PROXY_USE_WSAPOLL options of CMake, FD_SETSIZE
for select()). getip(), the IPv4-only resolver of NOIPV6, goes too.

Plugin binary compatibility: plugins built with Open Watcom, and their
calling convention, are no longer supported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 11:54:51 +03:00
Vladimir DubrovinandClaude Opus 5.5 055d274f50 Event loops: no sleep on a loop accepting connections
tcpnext() and srvspawn() slept a little after accept() failed for want
of descriptors or memory, and after a client's memory could not be had,
with usleep(): accepting on a fiber of a loop, that held up every client
of the loop. srvsleep() waits in the loop there (sockpoll() with no
sockets), as tcploop() already did waiting for a slot, and sleeps as
before in a thread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 11:52:20 +03:00
Vladimir DubrovinandClaude Opus 5.5 9025c8483f Event loops: connections accepted on a loop
A service whose clients are served on loops took them in a thread of
its own, woken by the system for each and handing it to a loop: some
5000 switches of threads in 5 seconds under the mix-http benchmark.
Its tcploop() now runs on a fiber of the first loop (loopcall(),
tcploopcall()), its thread waiting for it to return, so connections
are accepted where they are polled for: some 40 switches.

On a loop, a connection taken, the next one is tried at once, until
accept() finds none (EAGAIN, now NEXT_RETRY without a log line), 64 at
most before the others of the loop are let go first (fiberlater(),
which resumes the fiber in the loop's next turn: a poll of a socket
known to be ready does not yield). Waiting for a slot of maxchild does
not block the loop: the slot is tried again every 100 ms.

The listening socket is polled through a dup() of its own: a loop knows
a socket by its number, and on a reload the socket handed over is
polled by the service taking it over too, whose wait would replace this
one's. Not on Windows, where a socket has no dup(), nor with -r.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 11:50:02 +03:00
Vladimir DubrovinandClaude Opus 5.5 023eb8f830 Event loops: served on by default, the data relayed by the loops
loopmode is cb unless a configuration says otherwise, as -L2 had it
for a service: its clients on event loops, a connection's data relayed
by the loop itself where nothing but the sockets is between its sides.
A service whose clients cannot share a thread (threadperclient: PAM,
LDAP, FilePlugin, names resolved by the system, -ne) or listening for
connections back (-R) still gives each a thread, as do the standalone
services and builds without fibers. loopmode on and -L keep the loops
with the relay on the client's stack; loopmode off and -L0 a thread
for each client.

The man page tells of cb. tests/run.py --loopmode takes the mode
(cb, on, off) to give every configuration, with two loops; the Linux
workflow runs the suite once more with a thread for each client, which
is no longer what a configuration gets by default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 11:49:51 +03:00
Vladimir DubrovinandClaude Opus 5.5 143158e97f Relays: the size of a splice() pipe chosen at build time
sockmap() and the callbacks' relay each had their own 64K for what a
pipe is given at most (MAXSPLICE, CBSPLICE). It is PIPESIZE now, one
for both, 64K as before: what a pipe holds unless asked otherwise.
Built with -DPIPESIZE=<bytes>, pipes are made that large with
F_SETPIPE_SZ (pipenew()); one the system will not make so large is not
used, and the data is copied, as when there is no pipe to be had.

Measured on ARM and Intel (mix-http, mix-relay), 16K and 32K were
slower, 128K and 256K no faster than 64K, which stays the default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 11:49:38 +03:00
Vladimir DubrovinandClaude Opus 5.5 17a5287fce Fibers: stacks of their own size, not a thread's
A fiber's stack was a thread's, PTHREAD_STACK_MIN included: 128K on
arm64 glibc, which is there for a thread's signals, and a loop's thread
takes none. It is BASESTACKSIZE with the service's stacksize added, and
the room kept for wolfSSL's handshake (TLSSTACKSIZE), as a thread's but
for that. Only reserved either way: measured with OpenSSL, a fiber holds
8K to 12K of it, TLS handshakes included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 19:46:10 +03:00
Vladimir DubrovinandClaude Opus 5.5 7e3182ae89 Event loops: the C library's resolver run on the thread's stack
glibc's getaddrinfo() sizes what it takes with alloca(), IPv6 most, by
the thread's stack, not by the fiber's it may be called on: a client
moved to a new configuration on a reload goes on on its fiber, and the
new configuration's services may resolve with the system resolver,
which otherwise is never called on a loop (threadperclient). A fiber
yields to have it called on the loop thread's own stack
(onthreadstack()), and goes on with its answer; the loop waits for it
as the fiber would have.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 19:46:10 +03:00
Vladimir DubrovinandClaude Opus 5.5 f2cc447f73 Relays: no buffers made again after a connection's last mapping
sockmap() made both buffers again as it returned, for whatever came
after it, and the callbacks before the end: after the last mapping there
is only the end, the log line and a refusal sent from a buffer of its
own, with no use for them. They are made again only for a mapping that
is not the last, and for a fiber mapping on after a reload; the
functions reading a side's buffer make it if it is not there, and a
worker taken from the pool for its next connection gets its own again.

proxy.c's other last mappings, a CONNECT through a parent and an answer
ending as the server closes, are marked so too (maplast(), proxytail),
as the CONNECT of its own was: their end, and with callbacks the fiber,
is the loop's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 19:12:49 +03:00
Vladimir DubrovinandClaude Opus 5.5 f991edbb3a Event loops: readiness asked again of the system in one poll()
A fiber's wait asks the system again what each socket was reported ready
for and answered with once already: one poll() for each of them, two for
an HTTP connection kept alive waiting on both of its sides. They are
asked all at once now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 18:38:20 +03:00
Vladimir DubrovinandClaude Opus 5.5 5ed8e8cee4 HTTP proxy: the host's name asked of the system once
Forwarded and Via asked gethostname(), a uname() syscall, for each
request. The name is kept, asked again after a reload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 18:38:20 +03:00
Vladimir DubrovinandClaude Opus 5.5 7718745f53 HTTP proxy: what came of the body with the headers goes with them
An answer's headers were sent by themselves, and what hdrread() had read
of the body after them by sockmap() next: two segments where one does,
for most small answers. The headers, still where hdrread() put them in
the server's buffer, move up against the body, and go with what of it
was read in one send; an answer whose whole body came with its headers
is not mapped at all. Not for chunked answers, answers with no body, or
where a data filter is to see the body; the bytes were counted as they
were read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 18:38:20 +03:00
Vladimir DubrovinandClaude Opus 5.5 9b7bda5da2 HTTP proxy: no buffers held while waiting for the next request
A connection kept alive waited for its next request holding both of its
buffers, empty: most of the memory of an HTTP proxy under load. They are
let go before the wait and made again as something comes, but for a
request httpsrv keeps there to hand over.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 18:38:02 +03:00
Vladimir DubrovinandClaude Opus 5.5 cbc7245925 Relays: buffers let go while spliced on a connection's last mapping
sockmap() of fibers and threads kept both buffers for as long as it
mapped, even with a direction spliced. On a connection's last mapping
(maptail set), as the callbacks already do, a direction spliced lets its
empty buffer go: bufdrop(), shared with the callbacks now. It is made
again before a read into it, back to copying or draining what TLS held,
and both are there again once sockmap() returns, for whatever comes
after it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 18:37:52 +03:00
Vladimir DubrovinandClaude Opus 5.5 1201031404 UDP services: an event loop of their own from loop.c
A UDP service's thread waited for its sockets with an epoll set of its
own on Linux and poll() over every socket on each turn elsewhere. It
runs a loop of loop.c now: epoll, kqueue or AFD, the sockets registered
once and changed as the sessions change, everywhere. The handlers are
called by the loop as a socket is ready, a datagram read before the
socket is polled again; the sessions ended meanwhile are let go after
the turn, as before. The deadlines keep their heap.

A session is allocated with what the loop waits for, private to
mainudp.c. The standalone udppm is linked with loop.c.

Plugins: struct udpsession loses regctrl and regevents.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 16:28:38 +03:00
Vladimir DubrovinandClaude Opus 5.5 a5806b70ae Logs: a loop's thread does not write a log itself
A logger whose thread could not be started is written by its clients
themselves. A client of a loop, a fiber or a callback on the loop's
thread, would hold the loop while a database or a server takes its
line, so on a loop's thread the line is dropped instead, counted as the
log's lines dropped are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 16:28:38 +03:00
Vladimir DubrovinandClaude Opus 5.5 270b02293e Loggers: no blocks flag
A logger's lines are written by a thread of its own, its clients only
queueing them, so a logger whose writes wait cannot hold a client's
thread or a loop: its blocks flag, giving its services a thread for each
client, is gone. ODBC was the logger setting it; its services are served
on loops now too. Only a logger whose thread could not be started is
written by its clients themselves, as before.

Plugins: struct logtype loses its last member, blocks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 15:32:01 +03:00
Vladimir DubrovinandClaude Opus 5.5 e09e20e71c Event loops on Windows: AFD polls completed to a port
A loop waits for sockets with the polls of AFD, the driver under
Windows' sockets, as epoll and kqueue do elsewhere: each socket's poll is
given to \Device\Afd once and completes to the loop's I/O completion
port, which a message from another thread is posted to as well. WSAPoll()
stays the backend with LOOP_POLL and for Watcom and Windows CE.

A poll reports once and has to be made again. Edge-triggered sockets, the
registrations of fibers' sockets, are polled again for what an operation
has found them not to be ready for: loopagain(), called where readiness
known is found gone, a no-op with epoll and kqueue. A poll in flight for
less than wanted is cancelled and made again as it completes; one of a
socket deleted is freed as it completes.

With it the sockets of fibers stay registered on Windows too (SOCKREGS):
the Windows socket functions tell the loop of a socket found not ready
and of one closed, as the Unix ones do, and registrations are kept by the
handle divided by 4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 14:40:42 +03:00
Vladimir DubrovinandClaude Opus 5.5 b7037f1159 Windows: an error set where socket errors are read
errno is WSAGetLastError() on Windows, but seterrno3() set the C
library's errno there: the EAGAIN of a TLS read or write wanting the
socket again was not seen as one, and the error left was whatever the
socket call before had set. seterrno3() sets the socket error now.

socks.c assigned errno directly, which does not build on Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 14:40:42 +03:00
Vladimir DubrovinandClaude Opus 5.5 63cfcafbc5 Event loops: started once when services' first clients come at once
loopsstart() runs on the thread of the service whose client is the first
one to be served on a loop, not on the configuration's thread: two
services given their first clients at the same time could each initialize
its mutex, take it, and start loops of their own. A loop of the second
array was then given to a thread of the first one as well: two threads
ran one loop, and its timers and fibers were taken by both (crashes in
the timers' heap, seen on Windows under load).

The mutex is a global one now, made at startup with the others.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 14:40:30 +03:00
Vladimir DubrovinandClaude Opus 5.5 97ab683654 Event loops: a relayed client released once
The ends of a client relayed as callbacks called releaseparam() and
then freeparam(), which releases it again: the connection limits' slot
was given back twice (see the commit before). freeparam() alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 00:03:23 +03:00
Vladimir DubrovinandClaude Opus 5.5 e0a05f343f connlim: a connection's slot given back once
releaseparam() gave the connection limits' slot back without clearing
param->connlim: a second call, made on the event loops' end of a relayed
client, gave it back again, letting one more connection in for each
such end while another held its slot, or, with no connlimconf, followed
param->srv, cleared by the first call. It is cleared now.

A UDP session taken over by the new service on a reload gave its slot
back but kept connlim set, so the new service's authorization did not
count it, and its end gave it back a second time. It is counted again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 00:03:23 +03:00
Vladimir DubrovinandClaude Opus 5.5 7963494b1c Event loops: a relayed client's buffers given back while empty
A connection's two data buffers are malloc()'d with it (bufalloc())
instead of being part of struct clientparam, which is CLIENTBUFSIZE*2
smaller. The callbacks' relay of a client whose fiber gave up its stack
frees a side's buffer while it is empty and makes it again to read, and
gives both back before sockmap() or the child's tail goes on: a pool of
idle relayed connections holds no buffers. Fibers and threads keep
theirs as before.

mix scenarios, callbacks (-L -L2), peak memory before/after, throughput
the same:
  Intel: relay 972/632 MB, connect 981/581, socks 992/594
  ARM:   relay 1000/673 MB, connect 1000/615, socks 1020/629

struct clientparam's clibufdata and srvbufdata are pointers now:
plugins built against the old structure are not compatible.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 23:47:24 +03:00
Vladimir DubrovinandClaude Opus 5.5 80c3863055 ftppr: the server's answer to USER reaches the client (#1284)
A server which logs in on USER alone (230, anonymous FTP often does) or
refuses it had its answer read but not handed back: ftplogin() gave the
length of what it read only for the answer to PASS. The client, told
331 by ftppr and waiting for the answer to its PASS, waited until the
time out. The answer to USER is the client's now when there is no PASS.

The test case logs in through ftppr to a server answering 230, a
multiline 230, 331 then 230, 530, and 331 then 530.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 22:43:16 +03:00
Vladimir DubrovinandClaude Opus 5.5 1b6d4925b3 Event loops: the callbacks' relay splices again
A way with no length to keep to (CBALL) was counted down as data was
written, so the check for it failed after the first write: the run of
large reads that switches to splice() never got past one, and a stream
was copied all along. Not counted down any more.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 13:14:55 +03:00
Vladimir DubrovinandClaude Opus 5.5 5f892b38d8 proxy: a CONNECT's request line the tail's own, not a copy
A client whose fiber gave up its stack while relayed never comes back to
the end of proxychild(), which frees what it allocated: the request line
and the FTP base were lost with each CONNECT, the tail having a copy of
the line. The line is the tail's now, taken back if mapping returns, and
the FTP base is freed before mapping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 00:16:29 +03:00
Vladimir DubrovinandClaude Opus 5.5 90d798eaaf Event loops: CONNECT of the HTTP proxy and SOCKS, pop3p, imapp, smtpp
give up their fiber while relayed

The children for which mapping is their last thing set their tail too:

- socks, for CONNECT: its log line; the request's buffer is freed before
  mapping, nothing needing it after;
- proxy, for CONNECT: the status page its end sends for the result
  where one is, now proxystatus() for both, and the log line of its
  request, a copy of which is the tail's. Not in a request httpsrv hands
  over, whose end is httpsrv's;
- pop3p, imapp (with a copy of its tag), smtpp (its command freed before
  mapping): the log line and the error reply their ends send.

A tail may wait now, sending to the client: once mapping is over the end
of a client whose fiber gave up its stack runs on a fiber taken again
for it, which, after a reload, has sockmap() go on with the mapping
first. Only with no stack to be had is it ended there, logged with no
tail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 00:04:39 +03:00
Vladimir DubrovinandClaude Opus 5.5 973fc89d58 Event loops: a fiber's stack given back while its client is relayed
A child for which mapping is the last thing it does (tcppm, tlspr) sets
maptail, what it does once mapping is over as its own end would: its
log line, prepared before for tlspr. Relayed by the loop, the client's
fiber then gives up its stack at once: left in the middle of the
child's code, never to be resumed, it is started over from the start of
its stack for the next client (fiberreset), or freed where it cannot be
(Windows). Once mapping is over the loop ends the client as the child
and its fiber would: the result, the tail, the connection released and
freed. After a reload, which sockmap() is to see to, the client is
given a fiber again for sockmap() to go on with the mapping, then its
end. Not while a reload is pending: sockmap() sees to it on the fiber.

The callbacks' state is no longer on the fiber's stack but allocated.

clientparam has maptail and maptaildata: plugins are to be built again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 23:25:33 +03:00
Vladimir DubrovinandClaude Opus 5.5 be1ae65c4f Event loops: the callbacks' relay for all sockmap() maps
What was left to sockmap() is relayed by the callbacks too:

- bandwidth limits: the pause bandlimfunc asks for after data moved is
  a timer, the sockets' events waiting for it;
- grace (-g): small reads many times this second, either way, pause
  for the grace delay before more, as sockmap() waits before polling;
- traffic limits (maxtrafin, maxtrafout): the mapping ends with 10;
- dumps to the log (logdumpsrv, logdumpcli) as the counts pass them;
- control sockets (ctrlsock, ctrlsocksrv): registered with the loop,
  anything from them or their end ends the mapping;
- data filters, before data is sent, which may take another buffer
  for it, a buffer of a filter given back once empty (bufrelease);
- the filters before the data, run once on the fiber: TLS begins
  there. TLS, or anything else between the socket functions and the
  socket, is read whatever the socket says when _prepoll() says it
  holds data already, and copied, not spliced;
- back to copying after more than splicestreak spliced reads in a
  row smaller than splicesmall, once the pipe is through, and from
  copying to splice only for data of no known length, as sockmap().

A pipe still holding data is closed on every end of the mapping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 22:55:03 +03:00
Vladimir DubrovinandClaude Opus 5.5 8fea43015c Event loops: on a reload the callbacks' relay reads no more
Given back to sockmap() once its pipes were empty, the relay of the
callbacks went on filling them meanwhile: a steady stream kept them
from emptying, and the connection from going by the newest rules.
Once a reload is seen nothing more is read, the pipes are emptied
within LINGER_TO, or the connection ends as timed out, and sockmap()
takes over as soon as they are, not with the next event.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 21:38:35 +03:00
Vladimir DubrovinandClaude Opus 5.5 e0a6932704 Event loops: the callbacks' pipes emptied before sockmap() takes over
On a reload the relay of the callbacks gives the connection back to
sockmap(), which knows nothing of what its pipes hold, nor of how much
of a body of known length has already gone through: what was in a pipe
would have come out of order, and the whole length of a body been read
again, into what follows it. The pipes are emptied first, the relay
going on meanwhile, and the length left of a body is the one sockmap()
is given.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 21:27:21 +03:00
Vladimir DubrovinandClaude Opus 5.5 f486242638 Event loops: splice() in the callbacks' relay
Each way of the relay, the client's data and the server's, splices as
sockmap() does where it may: from the start when told to (-s1, -s2,
-s3) or for a body of known length of splicemin or more, and with -s
(automatic) once splicestreak reads in a row have been as large. Not
back to copying once spliced, as sockmap() is: a draft. What a way has
buffered goes first, its pipe is used once that is through; a pipe
left holding data is closed, as sockmap() does. The relay is reworked
around one way, the same code both ways.

The callback's hook is given what sockmap() was given to splice, less
what its filters forbid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 21:19:37 +03:00
Vladimir DubrovinandClaude Opus 5.5 875e47a230 Event loops: bodies of known length relayed by the callbacks too
A body of known length (waitclient64, waitserver64), the HTTP proxy's
requests and answers, was left to sockmap(). The relay of the callbacks
moves it as sockmap() does: that way only, as much as it has left, the
other way not at all, and ends with 98 or 99 once it is all through.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 21:03:58 +03:00
Vladimir DubrovinandClaude Opus 5.5 82387caf2f Event loops: the callbacks' relay given back to sockmap() on a reload
sockmap() has a connection go by the newest configuration's rules after
a reload (reattachfunc), which may end it. The relay of the callbacks
did not, and a connection the new rules refuse went on. Once the
configuration is newer than the connection, it is given back to
sockmap() as it is, which does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 19:59:44 +03:00
Vladimir DubrovinandClaude Opus 5.5 23e83a6b02 Event loops: sockmap() as callbacks, a draft (-L2, loopmode cb)
The data of a connection mapped by a fiber of a loop is relayed by the
loop itself, on its own stack: the sockets registered with it call back
a relay moving what they are ready for, a read and a write each way a
round, up to 16 rounds before the rest waits for the loop's next turn.
The fiber, parked meanwhile, is resumed once the mapping is over, as
sockmap() would end it, with its result: the idle timeout, shortened to
LINGER_TO once a side has ended, half-close or not as the service has
it, errors, and data left.

Only a plain relay: with filters, limits of bandwidth or traffic,
grace, dumps to the log, TLS or anything else between the socket
functions of the system, a control socket or a body of known length,
sockmap() maps it itself. No splice() yet: data is copied, so it
compares with -s0. The fiber keeps its stack.

For benchmarks: -L2 on a service (with -L for the count of loops), or
loopmode cb.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 19:51:38 +03:00
Vladimir DubrovinandClaude Opus 5.5 9f27d2cbfb -B: the TLS ClientHello split at the SNI, which -s is taken for splice
tlspr splits the ClientHello it passes in the middle of the server name
(SNI) when the service has s_option, set by -s. In builds with splice()
(Linux, the default there) -s is splice for every service but UDP ones,
admin and httpsrv, so the split was never made, and the How-To's SNI
break did nothing on Linux.

-B sets it whatever the build: for TCP services but admin and httpsrv,
where s_option has a meaning of its own. -s still does it where it is
not splice. The How-To, 3proxy.cfg(5) and tlspr(8) give -B.

Fixes #1283

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 18:52:39 +03:00
Vladimir DubrovinandClaude Opus 5.5 23b9619da1 bench: 75th percentile latency, loops for -L, BENCH_WORKERS
The CSV has p50, p75, p90 and p99 now, for wrk (its --latency
distribution) and for the mix load generator alike; report.py puts in
the table those the results have.

3proxy with -L among its options is given as many event loops as the
proxy has CPUs, as envoy is given workers; BENCH_WORKERS sets that
count for both whatever the CPUs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 18:24:50 +03:00
Vladimir DubrovinandClaude Opus 5.5 1fb4a313c5 Event loops: readiness answered once is asked again, bit by bit
What a socket was reported ready for is trusted once: answered again
with nothing reported since, the system is asked with poll(). Counted
per socket, the count was set back by any wait, even one woken by its
timer with nothing reported, and by any event of the socket, even for
the other direction. sockmap(), finding nothing to do after an answer,
sleeps in such a wait: the readiness found not to be there, a splice()
into a full pipe given the socket's, was trusted again after each
sleep, until it gave up after 11 turns with 93. Under load every third
session of a relay or a CONNECT ended so in the middle of its data.

What was answered and not reported since is now kept per bit: an event
makes its own bits fresh, a wait answers with what it found, and those
are asked again next time.

poll() of the BSDs and macOS tells a socket we shut down for sending
as hung up, which the loop does not (see loop.c): asking it, that is
dropped, or httpsrv lingering for the client's end found it hung up
and not readable, and turned until its time was out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 17:53:28 +03:00
Vladimir DubrovinandClaude Opus 5.5 c188f14192 Outgoing connections bound with IP_BIND_ADDRESS_NO_PORT
The socket of a connection to the destination is bound to the external
address before connect(), with port 0 unless a range is given. bind()
then takes an ephemeral port for the socket alone: not one in use
towards another destination, nor one of a connection still closing in
TIME_WAIT, which connect() would reuse. With many connections the range
runs out and bind() fails, result 12, or searches long for a port: 7 ms
a call was seen. The more connections are open at once, the sooner:
with event loops, serving more of them at once, the client of every
tenth connection or so of a saturated relay got its end at once.

Where the system has IP_BIND_ADDRESS_NO_PORT (Linux 4.2), the port is
left to connect() for a socket that is going to connect: chosen for
the pair with the destination, together with IP_LOCAL_PORT_RANGE when
a range is given.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 16:33:39 +03:00
Vladimir DubrovinandClaude Opus 5.5 9cdac1cb60 splice() pipes closed with fdclose(), the loop forgetting them first
sockmap waits on its splice() pipes as on its sockets, and on an event
loop a pipe waited on is registered there like a socket. They were
closed with close(), past the socket functions, so the loop kept the
registration of a closed descriptor, which epoll and kqueue drop on the
close: a socket given the same number later was taken for it, never
registered, and its fiber waited on it forever. fdclose() tells the
loop first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 12:54:46 +03:00
Vladimir DubrovinandClaude Opus 5.5 7b873b80b1 Event loops: sockets registered once, readiness kept until not found
A fiber waiting on a socket registered it with its loop and took it
off again on every wait: two epoll_ctl() calls a wait, some 39 for an
exchange of the mix benchmark, about an eighth of the proxy's time. A
socket is now registered once, edge-triggered for reading and writing,
until it is closed, and the loop keeps what it was reported ready for
until an operation finds it not to be: read, write, accept, connect,
splice() from a pipe and TLS tell it so through fiberblockfunc, the
close through fiberclosefunc. A wait for what a socket is known to be
ready for is answered at once, with no system call and no switch; only
with none of them ready does the fiber wait in its loop. Readiness is
trusted once: answered again with nothing reported or found since, what
was there may have been taken without its end being found, and the
system is asked with poll(). epoll and kqueue only; with poll() each
wait still registers its sockets.

What takes readability for an end rather than reading, the control
connection of a UDP association, the client waiting for a SOCKS BIND,
the server between requests of a kept-alive HTTP connection, asks
first with sockreadable(), a peek below any TLS layer.

kqueue: the end of either side, the peer's or our own shutdown, is
readable or writable, not a hang up, which poll() reports only with
both: kept, it made a wait for the answer after our shutdown return
at once, and sockmap give up with 93.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 12:41:47 +03:00
Vladimir DubrovinandClaude Opus 5.5 43f40569d4 Sockets closed without SO_LINGER
Client, outgoing and FTP data sockets, and the inetd socket of a
standalone service, were given SO_LINGER, the client's for the long
string timeout (60 seconds by default), the outgoing one's for the
LINGER timeout. It kept nothing from being lost: without it the system
sends what is queued after the close all the same, and the time running
out reset the connection, losing what was still queued. All it did was
make close() wait for the peer to acknowledge the data, holding the
connection's thread and maxconn slot meanwhile, and, for clients served
on an event loop, every client of the loop: with one loop it was idle a
quarter of the time in a benchmark of many short exchanges.

The LINGER timeout keeps its use: how long a half-closed connection
waits for the rest of its data, and how long httpsrv reads what is left
of a request before closing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 01:00:48 +03:00
Vladimir DubrovinandClaude Opus 5.5 c55f736a0d Clients of TCP services on event loops, served by fibers
With -L, or loopmode on for the services which follow, the clients of a
TCP service are served on event loops: loops threads (by default one
for each CPU) each run a loop, and each client is given in turn to one
of them, which serves it on a fiber with the same code a thread runs.
Its waits in sockpoll() wait in the loop, its sockets and a timer
registered there, and the fiber goes on once one is ready or the time
is out; a sleep is a timer alone. A client costs a stack, as large as
its thread's would be, and no thread. The loops start with the first
client served on one and run as long as the process; each keeps up to
256 idle fibers for its next clients.

srvspawn() posts the client to its loop once it is counted, what is
posted made before so that posting cannot fail. A service whose clients
cannot share a thread (threadperclient), or listening for connections
back (-R), all of its clients waiting for one socket, which a loop
waits for once, keeps a thread for each client, as does every service
of a build or a processor without fibers, and the standalone services.

tests/run.py --loopmode runs every configuration with loopmode on, on
two loops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 23:00:16 +03:00
Vladimir DubrovinandClaude Opus 5.5 e250f98598 Event loop on Windows: the wake connection only our own
Another local process could connect to the listening socket the wake
connection is made over before ours, and be accepted instead, leaving
the loop impossible to wake. Only the connection from our own socket is
taken; another is closed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 22:27:26 +03:00
Vladimir DubrovinandClaude Opus 5.5 835ce04295 Event loop on Windows: woken over a loopback TCP connection
WSAPoll() never reported the UDP socket which sent to itself to wake the
loop: a message from another thread waited for the timeout, and
loopstop() did not end looprun(). The loop is woken over a TCP
connection on the loopback instead, as its sockets are reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 22:17:19 +03:00
Vladimir DubrovinandClaude Opus 5.5 30f6043160 Event loop: what is due called when waiting fails; units on Windows
looponce() called nothing due when waiting for the sockets failed,
returning at once: a caller waiting for a timer turned forever. What is
due is called all the same, and on Windows WSAEINTR is no failure, not
errno. looptest reports any failure to wait with its error; fibertest
starts Winsock, its loop could not be made without, and recurses into
half of a fiber's stack rather than most of it, which Windows takes
more of. The units case shows what a test which never finished wrote.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 22:03:20 +03:00
Vladimir DubrovinandClaude Opus 5.5 4e1455b419 Fibers: stacks a thread switches to and back
src/fiber.c, not used yet: a fiber runs a function on a stack of its
own, yielding back to the thread which resumed it, for a thread to
serve many clients with code written as if each had a thread.

The switch is our own on x86-64 (System V), aarch64, i386, arm (ARM or
Thumb code, with or without a floating point unit) and mips o32 (with
soft, 32 or 64 bit floating point registers, position independent or
not), Windows' fibers on Windows. It saves the registers a function
has to keep and swaps the stack. Elsewhere there are no fibers
(WITH_FIBERS is not defined), nor where x86-64 Linux checks returns
against a shadow stack, which fiberusable() tells: each client has a
thread there.

Stacks are mapped with a guard page below them. A fiber whose function
returned is started again with another, its stack kept. Switches are
annotated for AddressSanitizer.

tests/fibertest.c tests them: yielding and resuming, the integer and
floating point registers a function keeps across switches both ways, a
thousand fibers resumed at random each keeping its stack, recursion
deep in a stack, fibers sleeping on the event loop's timers. The units
case, which was the loop case, runs it with looptest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 21:51:40 +03:00
Vladimir DubrovinandClaude Opus 5.5 cc98c498fe An event loop: sockets and timers for one thread
src/loop.c, not used yet: one thread waiting for many sockets and
timers, calling back what waits for them, for clients to be served by
a thread each serves many of.

Sockets are waited for with epoll on Linux, kqueue on the BSDs and
macOS, poll() (WSAPoll() on Windows) elsewhere or with LOOP_POLL,
level-triggered; one with nothing to wait for is taken from the system,
or an error or a hang up would be reported all the same. One deleted
while the sockets ready are being called is not called.

Timers wait in a wheel of 1024 one-second slots. One due within a turn
waits at the head of the slot of its second, all there due in the same
second; one due later behind them, in the order of their seconds, or,
if due before the last there, at the head of the last slot of the
turn, looked at again then. Moving a timer later costs nothing while
it waits in the wheel: it is looked at when its old deadline comes and
moved then. When its slot comes a timer due within the second waits in
a heap, so it fires to the millisecond, as does one set within the
second. The clock is monotonic.

Another thread posts to the loop, waking it with an eventfd, a pipe, or
on Windows a UDP socket sending to itself.

tests/looptest.c tests it on its own, timers on a clock of its own
through several turns of the wheel: built by CMake, run by the loop
case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 21:30:13 +03:00
Vladimir DubrovinandClaude Opus 5.5 fdebdb16dc tests: SOCKS BIND
The proxy accepts the connection expected and joins it with the
client both ways, and refuses one from another address than the one
asked for. socks_bind() and socks_bind_peer() in the harness make the
request and read the second reply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 20:54:51 +03:00
Vladimir DubrovinandClaude Opus 5.5 fea5bae665 Services: threadperclient when names are resolved by the system
A service resolving names with the C library, sysresolve or by default
with no name server given or found, waits for it other than in
sockpoll(): each client has a thread. sysresolves() tells it for a
resolve mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 20:48:42 +03:00
Vladimir DubrovinandClaude Opus 5.5 0d6b2950f0 Sockets read after a wait are non-blocking, and a read finding nothing waits again
A wait may end with nothing to read: a TLS record not yet whole, a
connection gone before it is accepted, and, once clients share a
thread, nothing more than a chance to try. Where a read or an accept()
followed a wait on a blocking socket, or ended the operation when it
found nothing, the socket is non-blocking and the wait is made again:
the listening sockets of SOCKS BIND and of FTP passive mode, httpsrv
reading what is left of a request body, and the RADIUS client, which
reads with sockrecvfrom().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 20:34:46 +03:00
Vladimir DubrovinandClaude Opus 5.5 7718ffa9f7 ftppr: the data socket towards the client from the socket functions
It was made with socket(): in the main network namespace rather than
the -ni one the client is reached in, and past the socket functions of
the service, which the rest of its life went through.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 20:34:46 +03:00
Vladimir DubrovinandClaude Opus 5.5 126c7d00ec Connect back: a connection one client takes leaves the others waiting
The clients of a -R service all wait for the connection back on the
same listening socket, which was blocking: one connection woke them
all, one took it, and the others were left in accept() until the next,
past their time out and through a reload. The socket is non-blocking,
and an accept() which finds nothing, the connection taken by another
client or gone, is not one of the client's tries. nonblock() makes a
socket non-blocking, acceptagain() tells such an accept().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 20:34:46 +03:00
Vladimir DubrovinandClaude Opus 5.5 bfd812f0b8 A client's sleeps wait in sockpoll()
The bandwidth limiter between HTTP requests and httpsrv's delay slept
with usleep(); they are waits of sockpoll() with no fds, to be made
other than by sleeping once a client is served by an event loop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 20:34:32 +03:00
Vladimir DubrovinandClaude Opus 5.5 df993b5304 Services: threadperclient with PAM, LDAP or Windows authentication
struct auth has blocks, for an authentication waiting other than in
sockpoll(): PamAuth, LdapPlugin and WindowsAuthentication set it, and a
service authenticating with one of them gives each client a thread.

Incompatible for plugins, which have to be built again with the same
version of 3proxy: struct auth has blocks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 20:06:39 +03:00
Vladimir DubrovinandClaude Opus 5.5 5d3f1e9567 doc/changelog/2/0/0: 2.0 changes so far
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 19:54:16 +03:00
Vladimir DubrovinandClaude Opus 5.5 3e7f749eb6 Services: threadperclient, a thread for each client where one is needed
A flag of the service for what cannot share a thread between clients,
once clients can be served otherwise: what waits other than in
sockpoll(), or a thread which may be unable to serve another client.
It is set for a service
- with FilePlugin, whose _prepoll writes files and sends them;
- with a -ne network namespace: a thread which failed to come back from
  it to the main namespace is not to serve another client;
- writing to an ODBC log, should the log have no thread of its own to
  write it: struct logtype has blocks, for a log waiting other than in
  sockpoll().

Nothing serves clients otherwise yet: as before, each has a thread.

Incompatible for plugins, which have to be built again with the same
version of 3proxy: struct srvparam has threadperclient, struct logtype
has blocks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 19:54:03 +03:00
Vladimir DubrovinandClaude Opus 5.5 b4bbcb9e9a Socket functions: _poll becomes _prepoll, which never waits
A layer over the sockets, TLS or a plugin's, no longer waits itself.
Its _prepoll only tells what it knows without asking the system: the
fds it knows to be ready, data TLS has already decrypted, or, returning
0, that the sockets have to be polled, for events it may rewrite: a
TLS read waiting for its socket to be writable. The wait is
sockpoll()'s, which calls _prepoll first and then polls, so that a wait
can be made other than with poll() in one place: a client of an event
loop is to wait in the loop. Whatever a rewritten wait gets is given to
the caller as what it asked for, its chance to try again, and the
events it asked for are given back. With no fds sockpoll() sleeps,
which WSAPoll() would refuse.

TLS remembers what a read or a write it could not do waits for. A read
needing to write, or a write to read, was an error which ended the
connection, as when TLS 1.3 answers a key update while the socket
cannot take more; it now waits for what TLS needs, as one needing what
it was asked for always did.

Incompatible for plugins, which have to be built again with the same
version of 3proxy, the structures they share not kept compatible:
- struct sockfuncs has _prepoll(state, fds, nfds) in place of
  _poll(state, fds, nfds, timeout). A plugin replacing _poll replaces
  _prepoll: it must not wait, returns the number of fds it set revents
  of (events then left as they are), 0 for the fds to be polled (with
  events as it leaves them, revents left to the poll) or -1, and calls
  the _prepoll it replaced when it has nothing to say itself.
- Waiting for sockets is sockpoll(sf, state, fds, nfds, timeout), not
  so._poll() of the socket functions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 19:54:03 +03:00
Vladimir DubrovinandClaude Opus 5.5 718798c7fc FilePlugin: socksend() given no clientparam, not a TLS state for one
socksend() takes the client's parameters, and was passed the socket
functions' state instead: NULL, the global functions used then, as
intended, but on a TLS connection the state of its TLS layer, which
socksend() read as a clientparam.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 19:25:38 +03:00
Vladimir Dubrovin 532408a1b4 Release as 1.1.0-pre1 2026-10-24 16:18:42 +03:00
Vladimir DubrovinandClaude Opus 5.5 451b9b4c28 Release builds on Ubuntu 26.04: rpm signing, GNU install for OpenWrt
ubuntu-latest is 26.04 now. Its rpm 6 runs %__gpg_sign_cmd without
taking the word after %{__gpg} for argv[0], as rpm 4 does, so the
command of our own broke there; rpm's own is given the passphrase file
and the digest through %_gpg_sign_cmd_extra_args and %_gpg_digest_algo
instead, which both read. Each rpm is then checked by the rpm of the EL
release it is for, against 3proxy-release-key.asc.

The OpenWrt SDK refuses an install which is not GNU's. 26.04 has the
Rust coreutils, and GNU's as gnuinstall and the like: gnuinstall is
linked as install ahead in PATH. ipk also reads DEVEL when there is no
RELEASE, so it can be run on the development branch.

workflow_dispatch takes a sign input, to sign the packages as a release
does without uploading anything.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 15:42:20 +03:00
Vladimir DubrovinandClaude Opus 5.5 9ce5de971f Release workflows: a minimal set for a release of the development branch
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ubuntu-latest (wolfSSL) (push) Waiting to run
A release whose tree has DEVEL and no RELEASE is one of the development
branch (release-kind.yml, called by the workflows below). For it only
the Windows x64 zip, the x86_64 and arm64 deb packages and the rpm for
EL 9 and 10 (x86_64 and arm64) are built and added to the release: no
Docker images, no source tarball, no ipk, armhf, watcom, win32 or
Windows arm64 builds. docker.yml makes it a prerelease, not "Latest",
which also keeps it out of the package repository 3proxy.github.io
builds from releases.

The packaging reads the version from RELEASE or DEVEL. rpm names the
source archive and its directory after the spec's Version, which for
2.0.0-devel is 2.0.0~devel, so that %setup finds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 20:10:59 +03:00
Vladimir DubrovinandClaude Opus 5.5 7fab9c488d Reattach: a new service's slot for its next client taken before it is found
A TCP service keeps one of its maxconn slots for the next client it
accepts, but took it only once its thread reached the accept loop. A
reload puts the new service on its listener (mainclaim(), in the thread
reading the configuration) before its thread even starts, and the
clients of the old services move to it as soon as they see it there: in
that window they could take every slot, the one it keeps included. The
reattach test, with maxconn 2, then had both of two downloads go on
instead of one, now and then on a loaded runner, every time with a
300 ms sleep put in the window.

mainclaim() takes the slot first; srvrun() takes it over, and
srvdiscard() gives it back for a service which never ran.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 20:00:29 +03:00
Vladimir DubrovinandClaude Opus 5.5 2052dc0a4f Logs: a thread and a queue for each log; build-time defaults
Once 3proxy runs (after the first configuration is in force, so after a
daemon's fork), each logger has a thread of its own writing from a
queue, and a client never waits for a log: ODBC, RADIUS, a full disk or
a pipe nobody reads hold up only that log's thread.

A queued line is fixed size: the part of struct clientparam logging
reads (everything before the filters: addresses, counters, names and
credentials, which hold no pointer it follows but srv), the time it was
logged, and its text, 256 bytes inline or a copy of its own if longer.
The thread formats it: struct tm is per call now, timechanged() and
dologname() included, and the type's format() takes the time.

minlogqueue (64) slots are allocated as the thread starts and kept,
maxlogqueue (4096) lines are queued at most. A line which finds the
queue full is dropped and counted on the last one queued; once that is
written, "Log X has its queue full, N records dropped" goes to where
errors go. A log which fails is no longer written to the error log
instead: its lines are dropped and counted while it is retried every
minute, and the count is told when it is open again, or when it was
reopened after failed writes.

A service which ended is stopped at once (srvstop(): sockets, listener,
its clients gone), but freed (srvrelease()) through its log's queue,
behind the lines which refer to it and to its configuration: the event
is part of struct srvparam, so a full queue never drops it. logfinish()
writes what is queued, 10 seconds at most, also as 3proxy exits on Unix.
Standalone services write as before, as each line comes.

LOGQUEUEMIN, LOGQUEUEMAX, DEFAULT_MAXCHILD, DEFAULT_POOLMAX,
DEFAULT_POOLTIMEOUT and POOLPERSERVICE (the automatic thread pool cap
for each service, which was 32 in the code) can be set with -D at build
time.

Tests: a log nobody reads (a FIFO) holds no client up, drops past its
queue and says so, and lines queued for a service a reload removed are
written as it formatted them; /dev/full says what it dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 19:41:48 +03:00
Vladimir DubrovinandClaude Opus 5.5 a3c417c82a Logs: the error of opening a log returned, not passed in errno
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ubuntu-latest (wolfSSL) (push) Waiting to run
On Windows proxy.h makes errno WSAGetLastError(), which cannot be
assigned, so the Windows build failed, and the error of fopen() would
not have been read there either. A type's init returns the errno value
(the C library's, read with _get_errno() on Windows), and logget() gives
it to its caller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 17:20:56 +03:00
Vladimir DubrovinandClaude Opus 5.5 30e2e34dd6 Sockets: sends with MSG_NOSIGNAL where the system has it
A peer gone is then an error of the send rather than SIGPIPE. SIGPIPE
stays ignored for what cannot pass the flag: TLS writes and splice().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 16:23:04 +03:00
Vladimir DubrovinandClaude Opus 5.5 83d8138818 Tests: udploop's silence counted from the last answer
The last datagram's time was taken after the sleep following it, half a
second and a slow runner's overshoot late, so a session ending on time
looked early. The test resolver no longer raises when its socket is
closed under it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 13:56:38 +03:00
Vladimir DubrovinandClaude Opus 5.5 e619a105b4 MITM: a serial number of its own when wolfSSL cannot copy the source's
wolfSSL built with WOLFSSL_QT, as Ubuntu 26.04's 5.9.1 is, returns a
serial number without the ASN.1 header its X509_set_serialNumber()
requires, so every certificate copy failed. The copy then gets a
positive serial number from the hash of the source certificate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 13:56:38 +03:00
Vladimir DubrovinandClaude Opus 5.5 f9b56fc15d SIGPIPE ignored before any service starts, and in standalone services
3proxy ignored SIGPIPE only after readconfig(), which starts the
services: a client gone while written to in the meantime killed the
process (as auto's case saw on macOS). Standalone services never ignored
it. Sends pass no MSG_NOSIGNAL, so this is the only guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 13:56:38 +03:00
Vladimir DubrovinandClaude Opus 5.5 477a2d3822 Logs: an ODBC log named by its data source, user and password its parameters
The string up to the first comma names an ODBC log; the user and the
password are kept apart as its parameters, never shown, and do not tell
logs apart. Another log or -l naming the same data source with other
parameters gives them to the logger, which reconnects with them. The
password is whatever follows the comma after the user.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 13:08:06 +03:00
Vladimir DubrovinandClaude Opus 5.5 e87ffcd7e1 Logs: no ODBC user and password in messages about a log
A log string is shown only up to its first comma, where an ODBC string
goes on with the user and the password: in the message on a log which
failed, and in the errors on a log or -l which cannot be opened.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 11:47:23 +03:00
Vladimir DubrovinandClaude Opus 5.5 d613750b94 Logs: a logger for each log string, shared and closed once unused
A logger (struct logger) is identified by the string log or -l gives it:
"" stdout, "/dev/null" none, "@IDENT" syslog, "&DSN" ODBC, "radius",
anything else a file. Each type (struct logtype) has init, formatting of
a connection into a buffer, writing, close, and a periodic tick for
rotation and flushing; ODBC and RADIUS register their types from 3proxy,
which alone has them. Services and configurations hold the logger they
use; the last to let go closes it, except the standard ones (none,
stdout, stderr, syslog), which are opened at startup and kept.

-l takes every log type now, and a file named by several services or by
both log and -l is opened once. rotate and archiver are bound to the
logger of the last log command when its configuration comes into force,
and every file logger is rotated by the main loop.

Errors with no connection go to a new stderr logger; after daemon, or as
a Windows service, stdout logging writes nothing and errors go to the
last log configured. A log whose writes keep failing is closed and
reopened; while it cannot be, its lines go to stderr and it is retried
every minute. ODBC's own reconnection throttle gives way to this.

Formatting (logbuf) is separate from counting traffic and clearing the
statistics, done once by logdo(), the services' log function, so a later
step can format or copy a connection's line and write it from a thread
of its own. dologname() and timechanged() move to log.c, which the
standalone services link as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 11:44:55 +03:00
Vladimir DubrovinandClaude Opus 5.5 57818ad497 UDP loop: deadlines in a heap, on a monotonic clock
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ubuntu-latest (wolfSSL) (push) Waiting to run
The loop went through every session three times a turn: for the nearest
deadline, to register its sockets with epoll, and for the deadlines come
and the sessions ended. A datagram cost as much as the sessions there
were, idle ones too.

- The deadlines are in a binary heap, the nearest at its top: the wait
  is until the top, and the sessions timed out are taken from the top
  down to the first not due. A datagram only moves a session's deadline
  later, which leaves the heap as it is: the session is looked at again
  when its old deadline comes, and put back where its deadline is then,
  once in its timeout however many datagrams it had. A deadline set
  earlier by a handler goes up the heap.
- A session ended is put on a list and let go at the end of the turn,
  and its sockets are registered with epoll after the loop or a handler
  had it, not every session every turn.
- Deadlines are milliseconds of monotime(), CLOCK_MONOTONIC (the
  performance counter on Windows), which the time of day being set does
  not move: before, a clock set back kept sessions for as long, and one
  set forward ended them all. The loop reads it once a turn, in u->now.

With epoll, a datagram costs the same with 20000 idle sessions as with
none (38-40 us of the proxy's CPU a round trip, ARM), where it took 59
before. poll() elsewhere still builds its set every turn.

Tests: a session heard from every half second lives through two seconds
of idle timeout, and ends two seconds after the last datagram.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 23:53:06 +03:00
Vladimir DubrovinandClaude Opus 5.5 f69eb13e9a sockrecvfrom: poll again when a readable socket has nothing to read
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ubuntu-latest (wolfSSL) (push) Waiting to run
sockrecvfrom() polled once and then read in a loop for as long as the
read failed with EAGAIN. Over TLS a socket is readable when only a part
of a record has come, and the read fails with EAGAIN until the rest
does: a client sending half a record and then nothing kept a thread
taking all of a CPU, and the read never timed out. On EAGAIN the socket
is now polled again, the read repeated at once only for EINTR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 16:03:21 +03:00
Vladimir DubrovinandClaude Opus 5.5 2514fb3dbf TLS: a part of a record read ahead is not pending data
SSL_has_pending() is true when only a part of a record has been read
ahead, which is no data yet. ssl_poll() took it for data: poll()
returned at once, over and over and without its timeout, until the rest
came, so a peer sending half a record kept a thread spinning and its
connection from timing out. ssl_pending() is now true only when
decrypted data waits, or when what was read ahead makes a whole record
(an SSL_peek() of one byte, the sockets not blocking); otherwise the
socket is polled for the rest.

splice() over kernel TLS still needs to know of any byte OpenSSL holds,
a part of a record too: ssl_buffered() tells it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 12:05:02 +03:00
Vladimir DubrovinandClaude Opus 5.5 3d20e1104e resolver: per service, defaultresolve, fakeresolve or sysresolve
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ubuntu-latest (wolfSSL) (push) Waiting to run
Each service resolves names the way the last of defaultresolve (the name
servers in force, configured or the system's with the hosts file),
fakeresolve (127.0.0.2) and sysresolve (the C library) read before it
says; the last one in the configuration also applies outside services.
defaultresolve is the new command, and the default.

The name servers and the hosts file no longer depend on the mode: nserver
lines, or the system's, are always in force, so dnspr keeps forwarding;
with fakeresolve it does not, as before. fakeresolver moves to common.c,
which the standalone services link without resolve.c.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 18:45:48 +03:00
Vladimir DubrovinandClaude Opus 5.5 994526dbc4 resolver: sysresolve, names resolved by the system routines
The command keeps the C library's resolution which a configuration
without nserver had before the system's name servers became the
default: no hosts file imported. nserver lines, if any, are still
there for dnspr to forward to. Of sysresolve and fakeresolve the last
given applies.

Tests: sysdns, with sysresolve dnspr has no hosts file names and a
name is resolved through the system routines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 19:02:37 +03:00
Vladimir DubrovinandClaude Opus 5.5 d5e78a0900 resolver: the system's name servers and hosts file by default
Without nserver (or fakeresolve) names were resolved by the C library.
3proxy's own resolver is now the default, with the system's name
servers: up to 3 from /etc/resolv.conf, on Windows from the registry
(set for the system, set for an interface with an address, Tcpip6
interfaces, then those DHCP gave). With none found, the C library as
before. nserver takes up to 3 as well (MAXNSERVERS), a fourth is
warned about.

The name servers in force belong to the process, not a configuration:
nserver lines are kept aside while a configuration is read and replace
them only once it is committed, so a reload resolves with those in
force until then. Resolutions and dnspr read a copy of them.

The system's are read at start, before the configuration and a chroot
in it, and are in force while it is read, so its host names resolve
with them; read again at a commit, and checked every 5 seconds from
the main loop while the default is in force. What cannot be read then
(within a chroot) stays as last read.

The hosts file, read with them, is imported into tables of its own
while the default is in force: its first address of a family for a
name. A name is looked up as one nsrecord made first, then the hosts
file, then the name cache, then name servers. A changed file replaces
what was imported. No name cache is made for it: without nscache
nothing is cached, as before.

The name cache's keys are host names of any case now: DNS names are.

Tests: sysdns, a name of the hosts file answered by dnspr without
nserver, in any case, and not with one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 18:49:21 +03:00
Vladimir DubrovinandClaude Opus 5.5 8517a5675b proxy: no variable named small, a macro for char on Windows
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Has been cancelled
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Has been cancelled
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Has been cancelled
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Has been cancelled
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Has been cancelled
C/C++ CI cmake / ubuntu-latest (wolfSSL) (push) Has been cancelled
rpcndr.h, which windows.h brings in, defines small as char, so the
buffer the rest of a request is read into, unsigned char small[256],
did not compile with MSVC. Renamed, and the splice heuristic's small
in mainconf.c too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 16:50:42 +03:00