Repository navigation
feat: opt-in small-segment ServerHello (network.client-mss) - #580
AndreyOsipuk wants to merge 6 commits into
Conversation
Some DPI boxes (seen on a Russian ISP) recognise the FakeTLS ServerHello when it arrives in full-size TCP segments and then block the server ip:port, but let it through when the same bytes come in small segments, as with a client MSS of 92. Keeping a small MSS for the whole session is slow and costs a lot of packets per second, so only the ServerHello is split. [network] client-mss (0 disables, 48..1460) and client-mss-bulk (0 or 536..65495, 1400 by default): - bulk > 0: TCP_MAXSEG = bulk on the listening socket; the ServerHello is written in chunks that fit one segment at MSS = client-mss, each chunk only after the previous one has left the socket queue (tcpi_notsent_bytes = 0), otherwise the kernel merges chunks when it hits the congestion window or autocorking; - bulk = 0: TCP_MAXSEG = client-mss on the listening socket for the whole session, like iptables TCPMSS on the client SYN. The order cannot be reversed (small MSS on the listener, then a larger one): on an established connection setsockopt(TCP_MAXSEG) does not change the segment size, mss_clamp is fixed during the TCP handshake (listener 92, then 1400 - tcpi_snd_mss stays at 80). Linux only, a no-op elsewhere. Disabled by default.
|
Integration note: I checked this patch together with current #577 on a clean upstream clone. They conflict in internal/utils/net_listener.go and internal/cli/run_proxy.go because both add a third NewListener argument (MSS here, logger in #577). Please reconcile that listener signature when updating this branch. For review, the remaining network checks should include a slow/non-reading client respecting the ServerHello deadline, PROXY protocol/wrapper connections, and observed packet sizing; loopback tests alone do not establish the DPI effect across networks. This remains for @9seconds to review. |
…enerMSS NewListener no longer takes the listener MSS. utils.SetListenerMSS sets TCP_MAXSEG on the already listening socket right after NewListener and before the PROXY protocol wrapper; accepted connections inherit it the same way. This keeps the listener constructor free for other changes.
… client-mss The small-segment ServerHello writer now waits until the same handshake deadline that is set on the client socket, so a client that never reads cannot hold the stream past the handshake timeout. Tests: a non-reading client with a tiny receive window (writer and full proxy), the handshake behind the PROXY protocol listener (v1 and v2), tcpi_rcv_mss as an unprivileged signal of the largest received segment, and an AF_PACKET loopback capture that checks every ServerHello segment (skipped without CAP_NET_RAW).
|
Thanks for checking the two together. In 00657fc I removed the competing parameter: f4b7e78 adds the network tests you asked for:
As you say, loopback tests do not show the DPI effect across networks; that part needs field data and is up to @9seconds. |
|
Merged current master (with #577 and #578) into the branch; the head is now e087c25. It merged without conflicts, as expected after the |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #580 +/- ##
==========================================
+ Coverage 68.31% 69.39% +1.08%
==========================================
Files 112 118 +6
Lines 4087 4261 +174
==========================================
+ Hits 2792 2957 +165
+ Misses 1146 1143 -3
- Partials 149 161 +12 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
… queue Without MSG_EOR the kernel may collapse adjacent small skbs on retransmission (tcp_retrans_collapse is on by default), so on a lossy path the retransmitted ServerHello left in full-size segments. Polling tcpi_notsent_bytes between writes did not prevent that. Each chunk is now one sendmsg(MSG_EOR|MSG_NOSIGNAL) through RawConn. EAGAIN waits on the poller under the handshake deadline, EINTR retries, and a partial send finishes the current chunk, so chunk boundaries stay fixed. Tests: a fake sendmsg checks the flags and boundaries of every call, including partial sends, EINTR and EAGAIN; a full send buffer on a real socket; and a retransmission test that drops incoming packets with a socket BPF filter and checks that retransmitted segments are not larger than a chunk (fails on the previous code: 1360 bytes in 3 segments).
|
Reworked the splitting in 51c758e: each chunk now goes out with |
Some DPI boxes recognise the FakeTLS ServerHello when it arrives in full-size TCP segments and then block the server
ip:port, but let the same bytes through when they come in small segments. We hit this on a Russian ISP (Rostelecom): replaying a real ClientHello of Telegram iOS against mtg, only 3 of 8 handshakes completed and the port got banned; with the ServerHello split into 80-byte segments all 8 of 8 completed and the port was not banned. Keeping a small MSS for the whole session works too, but it is slow and multiplies packets per second, so this PR splits only the ServerHello.Disabled by default:
How it works (Linux only, a no-op with a warning elsewhere):
client-mss-bulk > 0: the listening socket getsTCP_MAXSEG = client-mss-bulk; accepted connections inherit it. The ServerHello is written in chunks that fit one segment at MSS =client-mss(minus the timestamps option when it is negotiated: 80 bytes for 92), and each next chunk is written only after the previous one has left the socket queue (tcpi_notsent_bytes == 0). Without that wait the kernel merges chunks once it hits the congestion window or autocorking: at 100 ms RTT 4 KB written in 80-byte chunks left in 13 segments, with the wait in 52. The wait is bounded by the handshake timeout. After the ServerHello nothing changes, the rest of the session uses full-size segments.client-mss-bulk = 0:TCP_MAXSEG = client-msson the listening socket for the whole session, the same asiptables ... TCPMSS --set-msson the client SYN (client-mssmust then be at least 88, the kernel minimum).*net.TCPConnis used); for a non-TCP connection the ServerHello is written as before.Why not "a small MSS on the listener, then raise it with
setsockopt(TCP_MAXSEG)" (or the other way round): on Linux the segment size is fixed during the TCP handshake (mss_clamp), andsetsockopt(TCP_MAXSEG)on an established connection only changesuser_mss, which no longer affects outgoing segments. Checked on 6.12: listener MSS 92, thensetsockopt1400 -tcpi_snd_mssstays at 80. There is a test for this (TestTCPMaxSegCannotBeRaisedAfterAccept). Hence the bulk MSS goes on the listener and only the ServerHello is split in user space.The idea and the option names follow
client_mss/client_mss_bulkin telemt. This is a separate implementation in Go; the chunking mechanism differs (here the socket MSS is not touched after accept, chunks are paced bytcpi_notsent_bytes).Documented in
example.config.toml. The listener options are read at start.Tests (Linux, real loopback sockets):
tcpi_snd_mss>= 1000; chunks are not merged when the client has a 2 KB receive window and does not read for 300 ms; a realfake.SendServerHellothrough the writer is parsed as three TLS records; PROXY protocol unwrapping; fallback for non-TCP;TCP_MAXSEGis advertised in the SYN-ACK, 0 keeps the default, too small values are rejected, and the MSS cannot be raised after accept;client-mssthe ServerHello (3-4.5 KB, the size is randomised) arrives in 2 segments, withclient-mss = 92in about 50-60;client-mss-bulk = 0, defaults) and the mapping of the options to listener/ServerHello MSS.gofmt,go vet ./...,go test -race ./...,GOOS=windows go build ./...,GOOS=darwin go vet ./...andgolangci-lint run(v2.12.2) pass.