Зеркало Leadaxe/sing-tun-lx — сабмодуль ядра sing-box-lx. GPLv3.
Find a file
Leadaxe d31d20ba58 system stack: self-heal the TCP forwarder accept loop (sing-box-lx SPEC 040)
Upstream acceptLoop treats any Accept error as terminal and silently
returns, leaving the stack alive but every new TCP SYN NAT-rewritten onto
a dead port (instant RST) until a full restart. When the listener fd is
closed out from under the stack (a stray close on a reused fd number from
another runtime in the same process), all new TCP dies forever while
UDP/QUIC/DNS keep working.

- System.Close() now marks a deliberate shutdown first; acceptLoop still
  exits quietly on it.
- Any other Accept error is logged (the errno names the killer path),
  the listener is recreated on the same address, the forwarder port is
  republished atomically, and the loop keeps serving.
- If the rebind fails, the loop logs an error and gives up - no worse
  than upstream.
- acceptRecoveries counter is kept as telemetry.

tcpPort/tcpPort6 become atomic (written by the heal path, read from the
tunLoop dispatch/NAT path); listener replacement is serialized against
Close() with a mutex.
2026-08-05 16:57:11 +03:00
.github Fix lint errors 2026-07-27 10:23:30 +08:00
gtcpip Fix lint errors 2026-07-27 23:11:48 +08:00
internal Update gvisor to 20260727.0 2026-08-05 08:12:00 +08:00
ping Fix lint errors 2026-07-27 23:11:48 +08:00
.gitignore Update .gitignore 2026-06-22 16:16:28 +08:00
.golangci.yml Fix lint errors 2026-07-27 10:23:30 +08:00
flow.go Add stateless DNS hijack 2026-07-27 23:11:49 +08:00
flow_dispatch.go Fix deadlock between flow judgement and close 2026-07-29 13:45:28 +08:00
flow_dns.go Add stateless DNS hijack 2026-07-27 23:11:49 +08:00
flow_mtu.go Minor fixes 2026-07-27 23:11:48 +08:00
flow_nat.go Add flow PortWithSelectorRange 2026-07-27 23:11:48 +08:00
flow_parse.go Add flow dispatcher 2026-07-27 23:11:48 +08:00
flow_reject.go Add flow dispatcher 2026-07-27 23:11:48 +08:00
flow_rewrite.go Add flow dispatcher 2026-07-27 23:11:48 +08:00
go.mod Update gvisor to 20260727.0 2026-08-05 08:12:00 +08:00
go.sum Update gvisor to 20260727.0 2026-08-05 08:12:00 +08:00
LICENSE Init commit 2022-07-11 17:15:22 +08:00
Makefile Fix lint errors 2026-07-27 10:23:30 +08:00
monitor.go Support multiple registered interfaces in interface monitor 2026-06-03 10:35:01 +08:00
monitor_android.go Minor fixes 2026-07-27 23:11:48 +08:00
monitor_darwin.go Better atomic using 2025-03-19 20:37:02 +08:00
monitor_linux.go Fix redirect routes 2026-07-27 23:11:22 +08:00
monitor_linux_default.go Improve error messages for Linux TUN and redirect operations 2026-03-15 14:43:38 +08:00
monitor_other.go Add mixed stack 2023-08-12 19:38:06 +08:00
monitor_shared.go Minor fixes 2026-07-27 23:11:48 +08:00
monitor_windows.go Better atomic using 2025-03-19 20:37:02 +08:00
netns_linux.go Add netns support 2026-07-27 23:11:48 +08:00
netns_other.go Add netns support 2026-07-27 23:11:48 +08:00
nfqueue_linux.go Add flow tracking 2026-07-27 23:11:48 +08:00
packages.go Add PackagesByID for android package manager 2026-03-23 18:25:08 +08:00
packages_android.go Add PackagesByID for android package manager 2026-03-23 18:25:08 +08:00
packages_stub.go Use new fswatcher to udpate android packages 2024-06-26 11:02:47 +08:00
README.md Fix system stack for ios 2023-04-17 20:02:10 +08:00
redirect.go Add pre-matching support for auto redirect 2025-12-26 14:44:55 +08:00
redirect_iptables.go Reject connections to redirect listener 2026-07-27 23:11:22 +08:00
redirect_linux.go Add netns support 2026-07-27 23:11:48 +08:00
redirect_nftables.go Add netns support 2026-07-27 23:11:48 +08:00
redirect_nftables_docker.go Add compatibility with docker bridge 2026-07-27 23:11:48 +08:00
redirect_nftables_exprs.go Fix nftables interval end when range hits max address 2026-07-27 10:25:59 +08:00
redirect_nftables_rules.go Add DNS mode 2026-07-27 23:11:48 +08:00
redirect_nftables_rules_openwrt.go test: Add log for fw4 reload error 2025-08-03 00:12:24 +08:00
redirect_route_linux.go Fix redirect routes 2026-07-27 23:11:22 +08:00
redirect_server.go Reject connections to redirect listener 2026-07-27 23:11:22 +08:00
redirect_stub.go Add auto-redirect 2024-06-07 15:48:43 +08:00
stack.go Add Stack.ResetNetwork 2026-07-27 23:11:49 +08:00
stack_gvisor.go Add Stack.ResetNetwork 2026-07-27 23:11:49 +08:00
stack_gvisor_filter.go Add flow dispatcher 2026-07-27 23:11:48 +08:00
stack_gvisor_icmp.go Update gvisor to 20260727.0 2026-08-05 08:12:00 +08:00
stack_gvisor_lazy.go Minor fixes 2026-07-27 23:11:48 +08:00
stack_gvisor_log.go Add handshake interface support for gVisor UDP 2023-08-07 20:32:32 +08:00
stack_gvisor_stub.go Add mixed stack 2023-08-12 19:38:06 +08:00
stack_gvisor_tcp.go Add flow tracking 2026-07-27 23:11:48 +08:00
stack_gvisor_tcp_conn.go Add read waiter support for gVisor conn 2026-07-27 23:11:48 +08:00
stack_gvisor_tcpbuf_default.go Minor fixes 2026-07-27 23:11:48 +08:00
stack_gvisor_tcpbuf_ios.go Minor fixes 2026-07-27 23:11:48 +08:00
stack_gvisor_udp.go Add stateless DNS hijack 2026-07-27 23:11:49 +08:00
stack_mixed.go Add Stack.ResetNetwork 2026-07-27 23:11:49 +08:00
stack_system.go system stack: self-heal the TCP forwarder accept loop (sing-box-lx SPEC 040) 2026-08-05 16:57:11 +03:00
stack_system_nat.go Add Stack.ResetNetwork 2026-07-27 23:11:49 +08:00
stack_system_nonwindows.go Retry system listen 2024-10-14 22:10:23 +08:00
stack_system_packet.go refactor: New udpnat 2026-07-27 23:11:49 +08:00
stack_system_selfheal_test.go system stack: self-heal the TCP forwarder accept loop (sing-box-lx SPEC 040) 2026-08-05 16:57:11 +03:00
stack_system_windows.go Fix system stack 2025-07-21 09:44:17 +08:00
tun.go Add stateless DNS hijack 2026-07-27 23:11:49 +08:00
tun_darwin.go Improve darwin forwarding 2026-07-27 23:11:48 +08:00
tun_darwin_gvisor.go Fix gVisor process 2026-07-27 10:25:59 +08:00
tun_linux.go Add netns support 2026-07-27 23:11:48 +08:00
tun_linux_flags.go Fix android GSO 2026-07-27 23:11:22 +08:00
tun_linux_gvisor.go Fix gVisor process 2026-07-27 10:25:59 +08:00
tun_nondarwin.go Add system stack 2022-09-08 18:11:26 +08:00
tun_nonlinux.go Add GSO support 2023-12-21 16:51:06 +08:00
tun_offload.go Minor fixes 2026-07-27 23:11:48 +08:00
tun_offload_errors.go Copy UDP GSO support from tailscale 2024-11-23 12:58:52 +08:00
tun_offload_linux.go Minor fixes 2026-07-27 23:11:48 +08:00
tun_other.go Add create tun from file descriptor 2023-02-26 17:11:24 +08:00
tun_rules.go Fix generate darwin rules 2025-02-17 21:56:54 +08:00
tun_windows.go Add DNS mode 2026-07-27 23:11:48 +08:00
tun_windows_gvisor.go Fix dispatcher race operation in WintunEndpoint 2026-06-01 17:48:51 +08:00
udp_egress.go Add UDPEgressPool 2026-07-27 23:11:49 +08:00
udp_egress_conn.go Add UDPEgressPool 2026-07-27 23:11:49 +08:00
udp_nat.go refactor: New udpnat 2026-07-27 23:11:49 +08:00
udp_nat_cleanup.go refactor: New udpnat 2026-07-27 23:11:49 +08:00

sing-tun

Simple transparent proxy library.

For Linux, Windows, macOS and iOS.

License

Copyright (C) 2022 by nekohasekai <contact-sagernet@sekai.icu>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.