From 246d6a5f8f2d974796230dcf7638bdc271c0129d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sun, 3 May 2026 21:54:38 +0800 Subject: [PATCH 1/3] Fix cronet close --- .github/CRONET_GO_VERSION | 2 +- go.mod | 64 +++++++++---------- go.sum | 128 +++++++++++++++++++------------------- 3 files changed, 97 insertions(+), 97 deletions(-) diff --git a/.github/CRONET_GO_VERSION b/.github/CRONET_GO_VERSION index 80c50a89d0..2a67ecab4f 100644 --- a/.github/CRONET_GO_VERSION +++ b/.github/CRONET_GO_VERSION @@ -1 +1 @@ -cd9fcba9981bf69c1aab541887d2758d84dc31f3 +359394912c9e1c1ec528fccb6ee05ce05fe9a17f diff --git a/go.mod b/go.mod index 66a735909a..c7b89e91d2 100644 --- a/go.mod +++ b/go.mod @@ -31,8 +31,8 @@ require ( github.com/sagernet/asc-go v0.0.0-20241217030726-d563060fe4e1 github.com/sagernet/bbolt v0.0.0-20231014093535-ea5cb2fe9f0a github.com/sagernet/cors v1.2.1 - github.com/sagernet/cronet-go v0.0.0-20260502110630-bdcbb26bce76 - github.com/sagernet/cronet-go/all v0.0.0-20260502110630-bdcbb26bce76 + github.com/sagernet/cronet-go v0.0.0-20260503134420-c7a929f9ecc7 + github.com/sagernet/cronet-go/all v0.0.0-20260503134420-c7a929f9ecc7 github.com/sagernet/fswatch v0.1.2 github.com/sagernet/gomobile v0.1.12 github.com/sagernet/gvisor v0.0.0-20250811.0-sing-box-mod.1 @@ -79,7 +79,7 @@ require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/dblohm7/wingoes v0.0.0-20240119213807-a09d6be7affa // indirect github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 // indirect - github.com/ebitengine/purego v0.9.1 // indirect + github.com/ebitengine/purego v0.10.0 // indirect github.com/florianl/go-nfqueue/v2 v2.0.2 // indirect github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/fxamacker/cbor/v2 v2.7.0 // indirect @@ -109,35 +109,35 @@ require ( github.com/prometheus-community/pro-bing v0.4.0 // indirect github.com/quic-go/qpack v0.6.0 // indirect github.com/safchain/ethtool v0.3.0 // indirect - github.com/sagernet/cronet-go/lib/android_386 v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/android_amd64 v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/android_arm v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/android_arm64 v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/darwin_amd64 v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/darwin_arm64 v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/ios_amd64_simulator v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/ios_arm64 v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/ios_arm64_simulator v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/linux_386 v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/linux_386_musl v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/linux_amd64 v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/linux_amd64_musl v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/linux_arm v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/linux_arm64 v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/linux_arm64_musl v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/linux_arm_musl v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/linux_loong64 v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/linux_loong64_musl v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/linux_mips64le v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/linux_mipsle v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/linux_mipsle_musl v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/linux_riscv64 v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/linux_riscv64_musl v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/tvos_amd64_simulator v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/tvos_arm64 v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/tvos_arm64_simulator v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/windows_amd64 v0.0.0-20260502110005-e9754926ef93 // indirect - github.com/sagernet/cronet-go/lib/windows_arm64 v0.0.0-20260502110005-e9754926ef93 // indirect + github.com/sagernet/cronet-go/lib/android_386 v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/android_amd64 v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/android_arm v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/android_arm64 v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/darwin_amd64 v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/darwin_arm64 v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/ios_amd64_simulator v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/ios_arm64 v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/ios_arm64_simulator v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/linux_386 v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/linux_386_musl v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/linux_amd64 v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/linux_amd64_musl v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/linux_arm v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/linux_arm64 v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/linux_arm64_musl v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/linux_arm_musl v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/linux_loong64 v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/linux_loong64_musl v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/linux_mips64le v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/linux_mipsle v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/linux_mipsle_musl v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/linux_riscv64 v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/linux_riscv64_musl v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/tvos_amd64_simulator v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/tvos_arm64 v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/tvos_arm64_simulator v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/windows_amd64 v0.0.0-20260503133750-4cc3f271bbae // indirect + github.com/sagernet/cronet-go/lib/windows_arm64 v0.0.0-20260503133750-4cc3f271bbae // indirect github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a // indirect github.com/sagernet/nftables v0.3.0-mod.2 // indirect github.com/spf13/pflag v1.0.9 // indirect diff --git a/go.sum b/go.sum index 8496ea5f16..4a882cc19a 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,8 @@ github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 h1:CaO/zOnF8VvUfEbhRatPcwKVWamvbY github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1/go.mod h1:+hnT3ywWDTAFrW5aE+u2Sa/wT555ZqwoCS+pk3p6ry4= github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= -github.com/ebitengine/purego v0.9.1 h1:a/k2f2HQU3Pi399RPW1MOaZyhKJL9w/xFpKAg4q1s0A= -github.com/ebitengine/purego v0.9.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= +github.com/ebitengine/purego v0.10.0 h1:QIw4xfpWT6GWTzaW5XEKy3HXoqrJGx1ijYHzTF0/ISU= +github.com/ebitengine/purego v0.10.0/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= github.com/florianl/go-nfqueue/v2 v2.0.2 h1:FL5lQTeetgpCvac1TRwSfgaXUn0YSO7WzGvWNIp3JPE= github.com/florianl/go-nfqueue/v2 v2.0.2/go.mod h1:VA09+iPOT43OMoCKNfXHyzujQUty2xmzyCRkBOlmabc= github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= @@ -168,68 +168,68 @@ github.com/sagernet/bbolt v0.0.0-20231014093535-ea5cb2fe9f0a h1:+NkI2670SQpQWvkk github.com/sagernet/bbolt v0.0.0-20231014093535-ea5cb2fe9f0a/go.mod h1:63s7jpZqcDAIpj8oI/1v4Izok+npJOHACFCU6+huCkM= github.com/sagernet/cors v1.2.1 h1:Cv5Z8y9YSD6Gm+qSpNrL3LO4lD3eQVvbFYJSG7JCMHQ= github.com/sagernet/cors v1.2.1/go.mod h1:O64VyOjjhrkLmQIjF4KGRrJO/5dVXFdpEmCW/eISRAI= -github.com/sagernet/cronet-go v0.0.0-20260502110630-bdcbb26bce76 h1:gEHy7Tr07rlXcw26YrO99nNrbyZxZM3XiEWchQN2+JA= -github.com/sagernet/cronet-go v0.0.0-20260502110630-bdcbb26bce76/go.mod h1:hwFHBEjjthyEquDULbr4c4ucMedp8Drb6Jvm2kt/0Bw= -github.com/sagernet/cronet-go/all v0.0.0-20260502110630-bdcbb26bce76 h1:HIWLA9kqPeWdZJVVALeI8+zlmMrJ8Sgx+4WpDiFcYn4= -github.com/sagernet/cronet-go/all v0.0.0-20260502110630-bdcbb26bce76/go.mod h1:Ws1+lX4ozLw1kjMhNP6jMMMYzDQ+xj37JowIzsKjAQg= -github.com/sagernet/cronet-go/lib/android_386 v0.0.0-20260502110005-e9754926ef93 h1:Ai6n4KUL8xL5+sPPGLMA6gR6pdGE+YfyumEHmu0WOz8= -github.com/sagernet/cronet-go/lib/android_386 v0.0.0-20260502110005-e9754926ef93/go.mod h1:XXDwdjX/T8xftoeJxQmbBoYXZp8MAPFR2CwbFuTpEtw= -github.com/sagernet/cronet-go/lib/android_amd64 v0.0.0-20260502110005-e9754926ef93 h1:YCsJA84Kqn+M79nugJBvLe32g7NPROwIHrCQcUeg8z0= -github.com/sagernet/cronet-go/lib/android_amd64 v0.0.0-20260502110005-e9754926ef93/go.mod h1:iNiUGoLtnr8/JTuVNj7XJbmpOAp2C6+B81KDrPxwaZM= -github.com/sagernet/cronet-go/lib/android_arm v0.0.0-20260502110005-e9754926ef93 h1:iZIW+x0tyAriSheonyexh/EXgY1Yf3clZ3ZXXQlUrqI= -github.com/sagernet/cronet-go/lib/android_arm v0.0.0-20260502110005-e9754926ef93/go.mod h1:19ILNUOGIzRdOqa2mq+iY0JoHxuieB7/lnjYeaA2vEc= -github.com/sagernet/cronet-go/lib/android_arm64 v0.0.0-20260502110005-e9754926ef93 h1:5fFO+M2tKzvuqrlLA7dpYb3D+s1FYUjvZRfhGPzaxyQ= -github.com/sagernet/cronet-go/lib/android_arm64 v0.0.0-20260502110005-e9754926ef93/go.mod h1:JxzGyQf94Cr6sBShKqODGDyRUlESfJK/Njcz9Lz6qMQ= -github.com/sagernet/cronet-go/lib/darwin_amd64 v0.0.0-20260502110005-e9754926ef93 h1:22KfcLvNGCB41xAEWou7NgIFUja6mxUgUWpLEO4Z3PE= -github.com/sagernet/cronet-go/lib/darwin_amd64 v0.0.0-20260502110005-e9754926ef93/go.mod h1:KN+9T9TBycGOLzmKU4QdcHAJEj6Nlx48ifnlTvvHMvs= -github.com/sagernet/cronet-go/lib/darwin_arm64 v0.0.0-20260502110005-e9754926ef93 h1:38qlpF10SZ5ZQkHAFq+Itg6aDqi65d60U7GWeoae6Qg= -github.com/sagernet/cronet-go/lib/darwin_arm64 v0.0.0-20260502110005-e9754926ef93/go.mod h1:kojvtUc29KKnk8hs2QIANynVR59921SnGWA9kXohHc0= -github.com/sagernet/cronet-go/lib/ios_amd64_simulator v0.0.0-20260502110005-e9754926ef93 h1:NtZYaRFqlrQSFQpA+VhaIlwL1VMSeI5N8zEuJT+D5Mc= -github.com/sagernet/cronet-go/lib/ios_amd64_simulator v0.0.0-20260502110005-e9754926ef93/go.mod h1:hkQzRE5GDbaH1/ioqYh0Taho4L6i0yLRCVEZ5xHz5M0= -github.com/sagernet/cronet-go/lib/ios_arm64 v0.0.0-20260502110005-e9754926ef93 h1:qgBCWWszFCUJDwJbUx4E7iLlyvZRgH4J+wWJWw7zz58= -github.com/sagernet/cronet-go/lib/ios_arm64 v0.0.0-20260502110005-e9754926ef93/go.mod h1:tzVJFTOm66UxLxy6K0ZN5Ic2PC79e+sKKnt+V9puEa4= -github.com/sagernet/cronet-go/lib/ios_arm64_simulator v0.0.0-20260502110005-e9754926ef93 h1:5pGx9W7N1DIONRxX0gFDcDLOsC+A2jVlbIeabdJl1l4= -github.com/sagernet/cronet-go/lib/ios_arm64_simulator v0.0.0-20260502110005-e9754926ef93/go.mod h1:M/pN6m3j0HFU6/y83n0HU6GLYys3tYdr/xTE8hVEGMo= -github.com/sagernet/cronet-go/lib/linux_386 v0.0.0-20260502110005-e9754926ef93 h1:BaTS59k8zsnM8wb0Fahe3828oJtEUP6uVt5DOut1k/o= -github.com/sagernet/cronet-go/lib/linux_386 v0.0.0-20260502110005-e9754926ef93/go.mod h1:cGh5hO6eljCo6KMQ/Cel8Xgq4+etL0awZLRBDVG1EZQ= -github.com/sagernet/cronet-go/lib/linux_386_musl v0.0.0-20260502110005-e9754926ef93 h1:ZvOfpob2GE3MwT/DujqOsBo+YyuTbN5CXvhahh88DTM= -github.com/sagernet/cronet-go/lib/linux_386_musl v0.0.0-20260502110005-e9754926ef93/go.mod h1:JFE0/cxaKkx0wqPMZU7MgaplQlU0zudv82dROJjClKU= -github.com/sagernet/cronet-go/lib/linux_amd64 v0.0.0-20260502110005-e9754926ef93 h1:AugS8654l2PdCSZEo1Hl//+WzkHKE7jnIu09XWpnjLE= -github.com/sagernet/cronet-go/lib/linux_amd64 v0.0.0-20260502110005-e9754926ef93/go.mod h1:vU8VftFeSt7fURCa3JXD6+k6ss1YAX+idQjPvHmJ2tI= -github.com/sagernet/cronet-go/lib/linux_amd64_musl v0.0.0-20260502110005-e9754926ef93 h1:+zmnmfrEKZbvzmRbKw4dDp4vlLzvto9LBQmGNx+5prk= -github.com/sagernet/cronet-go/lib/linux_amd64_musl v0.0.0-20260502110005-e9754926ef93/go.mod h1:vCe4OUuL+XOUge9v3MyTD45BnuAXiH+DkjN9quDXJzQ= -github.com/sagernet/cronet-go/lib/linux_arm v0.0.0-20260502110005-e9754926ef93 h1:sOf3QZxokQLMXEAYK2Ev1UBKw7T4dCScpejK5Sg40Fo= -github.com/sagernet/cronet-go/lib/linux_arm v0.0.0-20260502110005-e9754926ef93/go.mod h1:w9amBWrvjtohQzBGCKJ7LCh22LhTIJs4sE7cYaKQzM0= -github.com/sagernet/cronet-go/lib/linux_arm64 v0.0.0-20260502110005-e9754926ef93 h1:jyK14VGV4ZK+5SAITLWuwHlA+UTV6yKfnpFaEM1FaCE= -github.com/sagernet/cronet-go/lib/linux_arm64 v0.0.0-20260502110005-e9754926ef93/go.mod h1:TqlsFtcYS/etTeck46kHBeT8Le0Igw1Q/AV88UnMS3s= -github.com/sagernet/cronet-go/lib/linux_arm64_musl v0.0.0-20260502110005-e9754926ef93 h1:na2c0wGTPMhFS7rSJNhokYIUq10y7q00KyEXhXsI3fc= -github.com/sagernet/cronet-go/lib/linux_arm64_musl v0.0.0-20260502110005-e9754926ef93/go.mod h1:B6Qd0vys8sv9OKVRN6J9RqDzYRGE938Fb2zrYdBDyTQ= -github.com/sagernet/cronet-go/lib/linux_arm_musl v0.0.0-20260502110005-e9754926ef93 h1:+vmvZIGIaUXOyF/tFo9JGEbU7IfVENjlQduc1mYP6l8= -github.com/sagernet/cronet-go/lib/linux_arm_musl v0.0.0-20260502110005-e9754926ef93/go.mod h1:3tXMMFY7AHugOVBZ5Al7cL7JKsnFOe5bMVr0hZPk3ow= -github.com/sagernet/cronet-go/lib/linux_loong64 v0.0.0-20260502110005-e9754926ef93 h1:/RKvCIdn3kQwojdPU8p3wslQiby0cZ2n7HnQPW8hGeo= -github.com/sagernet/cronet-go/lib/linux_loong64 v0.0.0-20260502110005-e9754926ef93/go.mod h1:Wt5uFdU3tnmm8YzobYewwdF7Mt6SucRQg6xeTNWC3Tk= -github.com/sagernet/cronet-go/lib/linux_loong64_musl v0.0.0-20260502110005-e9754926ef93 h1:76aHGGm4mJNUqJQRgYKw4Y/FMgbRr3EMaaGaAGcr5qE= -github.com/sagernet/cronet-go/lib/linux_loong64_musl v0.0.0-20260502110005-e9754926ef93/go.mod h1:lyIF6wKBLwWa5ZXaAKbAoewewl+yCHo2iYev39Mbj4E= -github.com/sagernet/cronet-go/lib/linux_mips64le v0.0.0-20260502110005-e9754926ef93 h1:O7MaOwIuwiqrC9uR4W+dewvkCAFa4Uh9o2Y2G5IO8Z0= -github.com/sagernet/cronet-go/lib/linux_mips64le v0.0.0-20260502110005-e9754926ef93/go.mod h1:H46PnSTTZNcZokLLiDeMDaHiS1l14PH3tzWi0eykjD8= -github.com/sagernet/cronet-go/lib/linux_mipsle v0.0.0-20260502110005-e9754926ef93 h1:tK68PKvoy6CRJHyunQeImVPriYsPxXdRG9RtcQRCWb8= -github.com/sagernet/cronet-go/lib/linux_mipsle v0.0.0-20260502110005-e9754926ef93/go.mod h1:RBhSUDAKWq7fswtV4nQUQhuaTLcX3ettR7teA7/yf2w= -github.com/sagernet/cronet-go/lib/linux_mipsle_musl v0.0.0-20260502110005-e9754926ef93 h1:tspbl1GfyatQaGpvjkowtHR/HjbEakDyTR15cNC2wmo= -github.com/sagernet/cronet-go/lib/linux_mipsle_musl v0.0.0-20260502110005-e9754926ef93/go.mod h1:wRzoIOGG4xbpp3Gh3triLKwMwYriScXzFtunLYhY4w0= -github.com/sagernet/cronet-go/lib/linux_riscv64 v0.0.0-20260502110005-e9754926ef93 h1:MFtSQBsTOxAkLYSA7+VNUR2VTBLxLXi15Vw9tYKiqH0= -github.com/sagernet/cronet-go/lib/linux_riscv64 v0.0.0-20260502110005-e9754926ef93/go.mod h1:LNiZXmWil1OPwKCheqQjtakZlJuKGFz+iv2eGF76Hhs= -github.com/sagernet/cronet-go/lib/linux_riscv64_musl v0.0.0-20260502110005-e9754926ef93 h1:4i9OVY94DMslpvZP38tPSN7iZVa4iRE2wqVWPgGUJR0= -github.com/sagernet/cronet-go/lib/linux_riscv64_musl v0.0.0-20260502110005-e9754926ef93/go.mod h1:YFDGKTkpkJGc5+hnX/RYosZyTWg9h+68VB55fYRRLYc= -github.com/sagernet/cronet-go/lib/tvos_amd64_simulator v0.0.0-20260502110005-e9754926ef93 h1:/P/+rX2PTFI5HlIbq8kxB+HA+tqpNIx/okv4/cDZkJo= -github.com/sagernet/cronet-go/lib/tvos_amd64_simulator v0.0.0-20260502110005-e9754926ef93/go.mod h1:aaX0YGl8nhGmfRWI8bc3BtDjY8Vzx6O0cS/e1uqxDq4= -github.com/sagernet/cronet-go/lib/tvos_arm64 v0.0.0-20260502110005-e9754926ef93 h1:Szdw25xT4Wz+Xt7ZuJ1g6M4GlUpovAzSlTLEKxitoEs= -github.com/sagernet/cronet-go/lib/tvos_arm64 v0.0.0-20260502110005-e9754926ef93/go.mod h1:EdzMKA96xITc42QEI+ct4SwqX8Dn3ltKK8wzdkLWpSc= -github.com/sagernet/cronet-go/lib/tvos_arm64_simulator v0.0.0-20260502110005-e9754926ef93 h1:yp3eCuMi/y5Ql4d3usN8EJJ6eU3qxQ7dqe79ExZA/j8= -github.com/sagernet/cronet-go/lib/tvos_arm64_simulator v0.0.0-20260502110005-e9754926ef93/go.mod h1:qix4kv1TTAJ5tY4lJ9vjhe9EY4mM+B7H5giOhbxDVcc= -github.com/sagernet/cronet-go/lib/windows_amd64 v0.0.0-20260502110005-e9754926ef93 h1:VFA4sS7Sdi8Zzk6FlT0MKcmBgI+mMo0ERBZHE9xdckM= -github.com/sagernet/cronet-go/lib/windows_amd64 v0.0.0-20260502110005-e9754926ef93/go.mod h1:lm9w/oCCRyBiUa3G8lDQTT8x/ONUvgVR2iV9fVzUZB8= -github.com/sagernet/cronet-go/lib/windows_arm64 v0.0.0-20260502110005-e9754926ef93 h1:r2ACrUknRLL0Ysb3BbidkmQ1ZNtidBqX0N0OHqL1g6M= -github.com/sagernet/cronet-go/lib/windows_arm64 v0.0.0-20260502110005-e9754926ef93/go.mod h1:n34YyLgapgjWdKa0IoeczjAFCwD3/dxbsH5sucKw0bw= +github.com/sagernet/cronet-go v0.0.0-20260503134420-c7a929f9ecc7 h1:YnDDuoloCMkIgAEyx18eGoPMFpzQGDimnS2pbHLMs0k= +github.com/sagernet/cronet-go v0.0.0-20260503134420-c7a929f9ecc7/go.mod h1:T/mwtrpC4JlWfScw73CmSBvHzIvc7BatQ1MhRr+cYNw= +github.com/sagernet/cronet-go/all v0.0.0-20260503134420-c7a929f9ecc7 h1:ggD607yCvSuQUNCTg+z3osNAy1U0uZqZQosYvXPUGV0= +github.com/sagernet/cronet-go/all v0.0.0-20260503134420-c7a929f9ecc7/go.mod h1:AOSVRFLlq6Ipp7mMT9dMxI82XTORttYZ1jvtcHrZbK8= +github.com/sagernet/cronet-go/lib/android_386 v0.0.0-20260503133750-4cc3f271bbae h1:8dyLAZ/aJEaEDJQAuGAiJcYNe/N6fqLo2G3Ixr/axHM= +github.com/sagernet/cronet-go/lib/android_386 v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:XXDwdjX/T8xftoeJxQmbBoYXZp8MAPFR2CwbFuTpEtw= +github.com/sagernet/cronet-go/lib/android_amd64 v0.0.0-20260503133750-4cc3f271bbae h1:gXaWxEsoUL5udSM/6lChqLJtw1PbSG7QrOzwlTzs0ok= +github.com/sagernet/cronet-go/lib/android_amd64 v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:iNiUGoLtnr8/JTuVNj7XJbmpOAp2C6+B81KDrPxwaZM= +github.com/sagernet/cronet-go/lib/android_arm v0.0.0-20260503133750-4cc3f271bbae h1:hCNpoofwT3S7w4K6U9ZBPy10YiarlocMgdMtUPAsBEc= +github.com/sagernet/cronet-go/lib/android_arm v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:19ILNUOGIzRdOqa2mq+iY0JoHxuieB7/lnjYeaA2vEc= +github.com/sagernet/cronet-go/lib/android_arm64 v0.0.0-20260503133750-4cc3f271bbae h1:2yuutIf3GkCwZu1oSMGQQwEoRSInyzwaOpQtfEWPgp0= +github.com/sagernet/cronet-go/lib/android_arm64 v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:JxzGyQf94Cr6sBShKqODGDyRUlESfJK/Njcz9Lz6qMQ= +github.com/sagernet/cronet-go/lib/darwin_amd64 v0.0.0-20260503133750-4cc3f271bbae h1:6bdQLLeONs/vP4T1kJW8JyMF55Xk0Zd1KQl3qq83lX4= +github.com/sagernet/cronet-go/lib/darwin_amd64 v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:KN+9T9TBycGOLzmKU4QdcHAJEj6Nlx48ifnlTvvHMvs= +github.com/sagernet/cronet-go/lib/darwin_arm64 v0.0.0-20260503133750-4cc3f271bbae h1:85yQqtxGp0a10TxvUMrMZUoP7YrFbAqifM2ImIwtp8k= +github.com/sagernet/cronet-go/lib/darwin_arm64 v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:kojvtUc29KKnk8hs2QIANynVR59921SnGWA9kXohHc0= +github.com/sagernet/cronet-go/lib/ios_amd64_simulator v0.0.0-20260503133750-4cc3f271bbae h1:PAeMpntLZYGp+vPbXum0uwRzd8UHp9gQ2hhaTdIGAUg= +github.com/sagernet/cronet-go/lib/ios_amd64_simulator v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:hkQzRE5GDbaH1/ioqYh0Taho4L6i0yLRCVEZ5xHz5M0= +github.com/sagernet/cronet-go/lib/ios_arm64 v0.0.0-20260503133750-4cc3f271bbae h1:Et/nfB4jaEUuzqdU3rDBj3ohFs2qRRk9ipDpiaqJKng= +github.com/sagernet/cronet-go/lib/ios_arm64 v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:tzVJFTOm66UxLxy6K0ZN5Ic2PC79e+sKKnt+V9puEa4= +github.com/sagernet/cronet-go/lib/ios_arm64_simulator v0.0.0-20260503133750-4cc3f271bbae h1:ofHyNQOQh0qkPb1wMlINUYYjANcVALx3li8tuoRPrbY= +github.com/sagernet/cronet-go/lib/ios_arm64_simulator v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:M/pN6m3j0HFU6/y83n0HU6GLYys3tYdr/xTE8hVEGMo= +github.com/sagernet/cronet-go/lib/linux_386 v0.0.0-20260503133750-4cc3f271bbae h1:A4XBM4now2jUMrkmki51OOwhUS1WGpVbhGZXS5T55AM= +github.com/sagernet/cronet-go/lib/linux_386 v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:cGh5hO6eljCo6KMQ/Cel8Xgq4+etL0awZLRBDVG1EZQ= +github.com/sagernet/cronet-go/lib/linux_386_musl v0.0.0-20260503133750-4cc3f271bbae h1:iW+YBmCSGGlg0epxFZ2rcKlbgHo4wlcmpqyCEu8eVLs= +github.com/sagernet/cronet-go/lib/linux_386_musl v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:JFE0/cxaKkx0wqPMZU7MgaplQlU0zudv82dROJjClKU= +github.com/sagernet/cronet-go/lib/linux_amd64 v0.0.0-20260503133750-4cc3f271bbae h1:/EWXuwcbXYeWiMYk8/d8BCPVWYJZDCpdXBhDLls1xkw= +github.com/sagernet/cronet-go/lib/linux_amd64 v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:vU8VftFeSt7fURCa3JXD6+k6ss1YAX+idQjPvHmJ2tI= +github.com/sagernet/cronet-go/lib/linux_amd64_musl v0.0.0-20260503133750-4cc3f271bbae h1:tcfGd5Fe/k3EqWXAqoThlORiAYHUcAPFk3Wun+o1dwM= +github.com/sagernet/cronet-go/lib/linux_amd64_musl v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:vCe4OUuL+XOUge9v3MyTD45BnuAXiH+DkjN9quDXJzQ= +github.com/sagernet/cronet-go/lib/linux_arm v0.0.0-20260503133750-4cc3f271bbae h1:NPpOOQXr6DgrBw6L2BrIm+cWp364tgO/EurfxybIcDk= +github.com/sagernet/cronet-go/lib/linux_arm v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:w9amBWrvjtohQzBGCKJ7LCh22LhTIJs4sE7cYaKQzM0= +github.com/sagernet/cronet-go/lib/linux_arm64 v0.0.0-20260503133750-4cc3f271bbae h1:0rQCKmdDRB4WNnvj4nuVjLFtFw40zSi+u8sxV/VXXA4= +github.com/sagernet/cronet-go/lib/linux_arm64 v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:TqlsFtcYS/etTeck46kHBeT8Le0Igw1Q/AV88UnMS3s= +github.com/sagernet/cronet-go/lib/linux_arm64_musl v0.0.0-20260503133750-4cc3f271bbae h1:qbsxqMEkeP2fmIP+kZjl82qIKSZOcIr8pcvGkdc14tU= +github.com/sagernet/cronet-go/lib/linux_arm64_musl v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:B6Qd0vys8sv9OKVRN6J9RqDzYRGE938Fb2zrYdBDyTQ= +github.com/sagernet/cronet-go/lib/linux_arm_musl v0.0.0-20260503133750-4cc3f271bbae h1:6JOR91cQtwpmTIwF03KFwc1x69lHhcfd50sNriEDpOY= +github.com/sagernet/cronet-go/lib/linux_arm_musl v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:3tXMMFY7AHugOVBZ5Al7cL7JKsnFOe5bMVr0hZPk3ow= +github.com/sagernet/cronet-go/lib/linux_loong64 v0.0.0-20260503133750-4cc3f271bbae h1:abvmwXBqgEbX/lfysxrmdiIyZw81nJE/4ZTed/9bmMQ= +github.com/sagernet/cronet-go/lib/linux_loong64 v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:Wt5uFdU3tnmm8YzobYewwdF7Mt6SucRQg6xeTNWC3Tk= +github.com/sagernet/cronet-go/lib/linux_loong64_musl v0.0.0-20260503133750-4cc3f271bbae h1:/Dnd8wbubyvScpFDS7ra3avQ0yiFe9IOH7xJ21uHS5U= +github.com/sagernet/cronet-go/lib/linux_loong64_musl v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:lyIF6wKBLwWa5ZXaAKbAoewewl+yCHo2iYev39Mbj4E= +github.com/sagernet/cronet-go/lib/linux_mips64le v0.0.0-20260503133750-4cc3f271bbae h1:sztI0M8JbBrAnwYbFCW7OLo/W10Gt/TDdc+/Cj1OWRs= +github.com/sagernet/cronet-go/lib/linux_mips64le v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:H46PnSTTZNcZokLLiDeMDaHiS1l14PH3tzWi0eykjD8= +github.com/sagernet/cronet-go/lib/linux_mipsle v0.0.0-20260503133750-4cc3f271bbae h1:PX9CXB8QXnezL+DfCcDZg5Pc6L2hgKkaFto6DV0iAs0= +github.com/sagernet/cronet-go/lib/linux_mipsle v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:RBhSUDAKWq7fswtV4nQUQhuaTLcX3ettR7teA7/yf2w= +github.com/sagernet/cronet-go/lib/linux_mipsle_musl v0.0.0-20260503133750-4cc3f271bbae h1:J8+5peZWaVnCI+S7arKcgx5mQ/MjTJNSbEap3L66f2Q= +github.com/sagernet/cronet-go/lib/linux_mipsle_musl v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:wRzoIOGG4xbpp3Gh3triLKwMwYriScXzFtunLYhY4w0= +github.com/sagernet/cronet-go/lib/linux_riscv64 v0.0.0-20260503133750-4cc3f271bbae h1:nRU2Dcaai3o99ZCtfSUAu3bmcbh3D0bVydVod8lkwLA= +github.com/sagernet/cronet-go/lib/linux_riscv64 v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:LNiZXmWil1OPwKCheqQjtakZlJuKGFz+iv2eGF76Hhs= +github.com/sagernet/cronet-go/lib/linux_riscv64_musl v0.0.0-20260503133750-4cc3f271bbae h1:6ALDNIh0IhIzbkMNO8YohMVBs4WYZEq+457qJPuuWC8= +github.com/sagernet/cronet-go/lib/linux_riscv64_musl v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:YFDGKTkpkJGc5+hnX/RYosZyTWg9h+68VB55fYRRLYc= +github.com/sagernet/cronet-go/lib/tvos_amd64_simulator v0.0.0-20260503133750-4cc3f271bbae h1:uWCLHEQrnJQNy1EMEAkezTd9IuhHJT6OG/xeL0+Ut/Y= +github.com/sagernet/cronet-go/lib/tvos_amd64_simulator v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:aaX0YGl8nhGmfRWI8bc3BtDjY8Vzx6O0cS/e1uqxDq4= +github.com/sagernet/cronet-go/lib/tvos_arm64 v0.0.0-20260503133750-4cc3f271bbae h1:0TLlyiqv4OvJ6vjR20caLWjwaDtED6Ti8pTjDIqSIQY= +github.com/sagernet/cronet-go/lib/tvos_arm64 v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:EdzMKA96xITc42QEI+ct4SwqX8Dn3ltKK8wzdkLWpSc= +github.com/sagernet/cronet-go/lib/tvos_arm64_simulator v0.0.0-20260503133750-4cc3f271bbae h1:qajv+maCrVa8+liFV4DcbsyEvS0CzzyKSmknFEdLrzY= +github.com/sagernet/cronet-go/lib/tvos_arm64_simulator v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:qix4kv1TTAJ5tY4lJ9vjhe9EY4mM+B7H5giOhbxDVcc= +github.com/sagernet/cronet-go/lib/windows_amd64 v0.0.0-20260503133750-4cc3f271bbae h1:TylGkMbdToZnbV9EaiuUgKT8mDLI85prC7NbLLep6Rc= +github.com/sagernet/cronet-go/lib/windows_amd64 v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:lm9w/oCCRyBiUa3G8lDQTT8x/ONUvgVR2iV9fVzUZB8= +github.com/sagernet/cronet-go/lib/windows_arm64 v0.0.0-20260503133750-4cc3f271bbae h1:sSpHLo33I6d/z7WT2l4ayylO/vwaTLq45ykamHjx5M4= +github.com/sagernet/cronet-go/lib/windows_arm64 v0.0.0-20260503133750-4cc3f271bbae/go.mod h1:n34YyLgapgjWdKa0IoeczjAFCwD3/dxbsH5sucKw0bw= github.com/sagernet/fswatch v0.1.2 h1:/TT7k4mkce1qFPxamLO842WjqBgbTBiXP2mlUjp9PFk= github.com/sagernet/fswatch v0.1.2/go.mod h1:5BpGmpUQVd3Mc5r313HRpvADHRg3/rKn5QbwFteB880= github.com/sagernet/gomobile v0.1.12 h1:XwzjZaclFF96deLqwAgK8gU3w0M2A8qxgDmhV+A0wjg= From 793b81c190170e424da1fbf3ae9eeb457312510b Mon Sep 17 00:00:00 2001 From: Sheldon Qi <3365420+xdqi@users.noreply.github.com> Date: Mon, 4 May 2026 12:29:22 +0800 Subject: [PATCH 2/3] feat: DirectRoute support for UDP/TCP traceroute Add UDP and TCP DirectRoute handling to enable mtr --udp and mtr --tcp through WireGuard and other tunnels. - Add UDP DirectRoute with ICMPForwarder integration in direct outbound - Add TCP DirectRoute for traceroute in route matching - Pass ICMPForwarder to UDP/TCP forwarders in WireGuard stack - Fix safe type assertion for DirectRouteOutbound in PreMatch - Intercept ICMP errors in stackDevice before gVisor delivery - Use import aliases for sing-tun packages --- protocol/direct/outbound.go | 16 +++++++- protocol/group/selector.go | 6 ++- protocol/group/urltest.go | 6 ++- route/route.go | 26 +++++++++---- transport/wireguard/device_nat.go | 2 +- transport/wireguard/device_stack.go | 57 ++++++++++++++++++++++------- 6 files changed, 87 insertions(+), 26 deletions(-) diff --git a/protocol/direct/outbound.go b/protocol/direct/outbound.go index 9d24f31aff..5cb51e0176 100644 --- a/protocol/direct/outbound.go +++ b/protocol/direct/outbound.go @@ -13,7 +13,7 @@ import ( C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/log" "github.com/sagernet/sing-box/option" - "github.com/sagernet/sing-tun" + tun "github.com/sagernet/sing-tun" "github.com/sagernet/sing-tun/ping" "github.com/sagernet/sing/common" E "github.com/sagernet/sing/common/exceptions" @@ -110,7 +110,19 @@ func (h *Outbound) ListenPacket(ctx context.Context, destination M.Socksaddr) (n func (h *Outbound) NewDirectRouteConnection(metadata adapter.InboundContext, routeContext tun.DirectRouteContext, timeout time.Duration) (tun.DirectRouteDestination, error) { ctx := log.ContextWithNewID(h.ctx) - destination, err := ping.ConnectDestination(ctx, h.logger, common.MustCast[*dialer.DefaultDialer](h.dialer).DialerForICMPDestination(metadata.Destination.Addr).Control, metadata.Destination.Addr, routeContext, timeout) + controlFunc := common.MustCast[*dialer.DefaultDialer](h.dialer).DialerForICMPDestination(metadata.Destination.Addr).Control + var ( + destination tun.DirectRouteDestination + err error + ) + switch metadata.Network { + case N.NetworkUDP: + destination, err = ping.ConnectUDPDestination(ctx, h.logger, controlFunc, metadata.Destination.Addr, routeContext, timeout) + case N.NetworkTCP: + destination, err = ping.ConnectTCPDestination(ctx, h.logger, controlFunc, metadata.Destination.Addr, routeContext, timeout) + default: + destination, err = ping.ConnectDestination(ctx, h.logger, controlFunc, metadata.Destination.Addr, routeContext, timeout) + } if err != nil { return nil, err } diff --git a/protocol/group/selector.go b/protocol/group/selector.go index 85bea2b964..7210f0fce7 100644 --- a/protocol/group/selector.go +++ b/protocol/group/selector.go @@ -181,7 +181,11 @@ func (s *Selector) NewDirectRouteConnection(metadata adapter.InboundContext, rou if !common.Contains(selected.Network(), metadata.Network) { return nil, E.New(metadata.Network, " is not supported by outbound: ", selected.Tag()) } - return selected.(adapter.DirectRouteOutbound).NewDirectRouteConnection(metadata, routeContext, timeout) + directRoute, ok := selected.(adapter.DirectRouteOutbound) + if !ok { + return nil, nil + } + return directRoute.NewDirectRouteConnection(metadata, routeContext, timeout) } func RealTag(detour adapter.Outbound) string { diff --git a/protocol/group/urltest.go b/protocol/group/urltest.go index 03d2e8afbb..19b5c5cbe6 100644 --- a/protocol/group/urltest.go +++ b/protocol/group/urltest.go @@ -183,7 +183,11 @@ func (s *URLTest) NewDirectRouteConnection(metadata adapter.InboundContext, rout if !common.Contains(selected.Network(), metadata.Network) { return nil, E.New(metadata.Network, " is not supported by outbound: ", selected.Tag()) } - return selected.(adapter.DirectRouteOutbound).NewDirectRouteConnection(metadata, routeContext, timeout) + directRoute, ok := selected.(adapter.DirectRouteOutbound) + if !ok { + return nil, nil + } + return directRoute.NewDirectRouteConnection(metadata, routeContext, timeout) } type URLTestGroup struct { diff --git a/route/route.go b/route/route.go index 924b6cc47d..c8450c66f7 100644 --- a/route/route.go +++ b/route/route.go @@ -12,10 +12,10 @@ import ( "github.com/sagernet/sing-box/common/sniff" C "github.com/sagernet/sing-box/constant" R "github.com/sagernet/sing-box/route/rule" - "github.com/sagernet/sing-mux" - "github.com/sagernet/sing-tun" + mux "github.com/sagernet/sing-mux" + tun "github.com/sagernet/sing-tun" "github.com/sagernet/sing-tun/ping" - "github.com/sagernet/sing-vmess" + vmess "github.com/sagernet/sing-vmess" "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/buf" "github.com/sagernet/sing/common/bufio" @@ -329,7 +329,11 @@ func (r *Router) PreMatch(metadata adapter.InboundContext, routeContext tun.Dire if !common.Contains(outbound.Network(), metadata.Network) { return nil, E.New(metadata.Network, " is not supported by outbound: ", action.Outbound) } - directRouteOutbound = outbound.(adapter.DirectRouteOutbound) + var ok bool + directRouteOutbound, ok = outbound.(adapter.DirectRouteOutbound) + if !ok { + return nil, nil + } case *R.RuleActionRoute: if routeContext == nil { return nil, nil @@ -341,18 +345,26 @@ func (r *Router) PreMatch(metadata adapter.InboundContext, routeContext tun.Dire if !common.Contains(outbound.Network(), metadata.Network) { return nil, E.New(metadata.Network, " is not supported by outbound: ", action.Outbound) } - directRouteOutbound = outbound.(adapter.DirectRouteOutbound) + var ok bool + directRouteOutbound, ok = outbound.(adapter.DirectRouteOutbound) + if !ok { + return nil, nil + } } } if directRouteOutbound == nil { - if selectedRule != nil || metadata.Network != N.NetworkICMP { + if selectedRule != nil || (metadata.Network != N.NetworkICMP && metadata.Network != N.NetworkUDP && metadata.Network != N.NetworkTCP) { return nil, nil } defaultOutbound := r.outbound.Default() if !common.Contains(defaultOutbound.Network(), metadata.Network) { return nil, E.New(metadata.Network, " is not supported by default outbound: ", defaultOutbound.Tag()) } - directRouteOutbound = defaultOutbound.(adapter.DirectRouteOutbound) + var ok bool + directRouteOutbound, ok = defaultOutbound.(adapter.DirectRouteOutbound) + if !ok { + return nil, nil + } } if metadata.Destination.IsDomain() { if len(metadata.DestinationAddresses) == 0 { diff --git a/transport/wireguard/device_nat.go b/transport/wireguard/device_nat.go index d214b737b0..495fb8a2c8 100644 --- a/transport/wireguard/device_nat.go +++ b/transport/wireguard/device_nat.go @@ -7,7 +7,7 @@ import ( "github.com/sagernet/sing-box/adapter" "github.com/sagernet/sing-box/log" - "github.com/sagernet/sing-tun" + tun "github.com/sagernet/sing-tun" "github.com/sagernet/sing-tun/ping" "github.com/sagernet/sing/common/buf" "github.com/sagernet/sing/common/logger" diff --git a/transport/wireguard/device_stack.go b/transport/wireguard/device_stack.go index a190baba4f..220db8d2fd 100644 --- a/transport/wireguard/device_stack.go +++ b/transport/wireguard/device_stack.go @@ -7,6 +7,7 @@ import ( "net" "net/netip" "os" + "sync/atomic" "time" "github.com/sagernet/gvisor/pkg/buffer" @@ -21,7 +22,7 @@ import ( "github.com/sagernet/gvisor/pkg/tcpip/transport/udp" "github.com/sagernet/sing-box/adapter" "github.com/sagernet/sing-box/log" - "github.com/sagernet/sing-tun" + tun "github.com/sagernet/sing-tun" "github.com/sagernet/sing-tun/ping" "github.com/sagernet/sing/common/buf" E "github.com/sagernet/sing/common/exceptions" @@ -45,6 +46,7 @@ type stackDevice struct { dispatcher stack.NetworkDispatcher inet4Address netip.Addr inet6Address netip.Addr + rewriter *ping.SourceRewriter } func newStackDevice(options DeviceOptions) (*stackDevice, error) { @@ -88,11 +90,15 @@ func newStackDevice(options DeviceOptions) (*stackDevice, error) { } } tunDevice.stack = ipStack + tunDevice.rewriter = ping.NewSourceRewriter(options.Context, options.Logger, inet4Address, inet6Address) if options.Handler != nil { - ipStack.SetTransportProtocolHandler(tcp.ProtocolNumber, tun.NewTCPForwarder(options.Context, ipStack, options.Handler).HandlePacket) - ipStack.SetTransportProtocolHandler(udp.ProtocolNumber, tun.NewUDPForwarder(options.Context, ipStack, options.Handler, options.UDPTimeout).HandlePacket) icmpForwarder := tun.NewICMPForwarder(options.Context, ipStack, options.Handler, options.UDPTimeout) icmpForwarder.SetLocalAddresses(inet4Address, inet6Address) + icmpForwarder.SetTTLDecrement(inet4Address, inet6Address, 0) + tcpHandler := tun.NewTCPForwarder(options.Context, ipStack, options.Handler).HandlePacket + udpHandler := tun.NewUDPForwarder(options.Context, ipStack, options.Handler, options.UDPTimeout).HandlePacket + ipStack.SetTransportProtocolHandler(tcp.ProtocolNumber, tun.WrapTCPHandlerWithDirectRoute(ipStack, options.Handler, icmpForwarder, options.UDPTimeout, 0, inet4Address, inet6Address, tcpHandler)) + ipStack.SetTransportProtocolHandler(udp.ProtocolNumber, tun.WrapUDPHandlerWithDirectRoute(ipStack, options.Handler, icmpForwarder, options.UDPTimeout, 0, inet4Address, inet6Address, udpHandler)) ipStack.SetTransportProtocolHandler(icmp.ProtocolNumber4, icmpForwarder.HandlePacket) ipStack.SetTransportProtocolHandler(icmp.ProtocolNumber6, icmpForwarder.HandlePacket) } @@ -210,6 +216,11 @@ func (w *stackDevice) Write(bufs [][]byte, offset int) (count int, err error) { if len(b) == 0 { continue } + handled, _ := w.rewriter.WriteBack(b) + if handled { + count++ + continue + } var networkProtocol tcpip.NetworkProtocolNumber switch header.IPVersion(b) { case header.IPv4Version: @@ -260,19 +271,37 @@ func (w *stackDevice) BatchSize() int { func (w *stackDevice) CreateDestination(metadata adapter.InboundContext, routeContext tun.DirectRouteContext, timeout time.Duration) (tun.DirectRouteDestination, error) { ctx := log.ContextWithNewID(w.ctx) - destination, err := ping.ConnectGVisor( - ctx, w.logger, - metadata.Source.Addr, metadata.Destination.Addr, - routeContext, - w.stack, - w.inet4Address, w.inet6Address, - timeout, - ) - if err != nil { - return nil, err + session := tun.DirectRouteSession{ + Source: metadata.Source.Addr, + Destination: metadata.Destination.Addr, } + w.rewriter.CreateSession(session, routeContext) w.logger.InfoContext(ctx, "linked ", metadata.Network, " connection from ", metadata.Source.AddrString(), " to ", metadata.Destination.AddrString()) - return destination, nil + return &stackNatDestination{device: w, session: session}, nil +} + +var _ tun.DirectRouteDestination = (*stackNatDestination)(nil) + +type stackNatDestination struct { + device *stackDevice + session tun.DirectRouteSession + closed atomic.Bool +} + +func (d *stackNatDestination) WritePacket(buffer *buf.Buffer) error { + d.device.rewriter.RewritePacket(buffer.Bytes()) + d.device.packetOutbound <- buffer + return nil +} + +func (d *stackNatDestination) Close() error { + d.closed.Store(true) + d.device.rewriter.DeleteSession(d.session) + return nil +} + +func (d *stackNatDestination) IsClosed() bool { + return d.closed.Load() } var _ stack.LinkEndpoint = (*wireEndpoint)(nil) From d914eeac83fad21384bed43f7fa56d0f5e92d70d Mon Sep 17 00:00:00 2001 From: Sheldon Qi <3365420+xdqi@users.noreply.github.com> Date: Mon, 4 May 2026 12:29:32 +0800 Subject: [PATCH 3/3] feat: configurable traceroute hop limit and TTL decrement Add max_traceroute_hop_limit configuration for TUN inbound and enable ICMP TTL decrement on WireGuard and Tailscale endpoints for VPN server mode. - Add MaxTracerouteHopLimit option to TUN inbound configuration - Pass local addresses to DirectRoute wrapper for TTL decrement - Use DirectRoute wrapper for WireGuard and Tailscale stacks - Enable ICMP TTL decrement on WG and Tailscale servers --- option/tun.go | 1 + protocol/tailscale/endpoint.go | 19 ++++++++++++++++++- protocol/tun/inbound.go | 13 ++++++++----- transport/wireguard/device_system_stack.go | 9 ++++++--- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/option/tun.go b/option/tun.go index 379aa7c330..a1a4afeadc 100644 --- a/option/tun.go +++ b/option/tun.go @@ -44,6 +44,7 @@ type TunInboundOptions struct { IncludeMACAddress badoption.Listable[string] `json:"include_mac_address,omitempty"` ExcludeMACAddress badoption.Listable[string] `json:"exclude_mac_address,omitempty"` UDPTimeout UDPTimeoutCompat `json:"udp_timeout,omitempty"` + MaxTracerouteHopLimit uint8 `json:"max_traceroute_hop_limit,omitempty"` Stack string `json:"stack,omitempty"` Platform *TunPlatformOptions `json:"platform,omitempty"` InboundOptions diff --git a/protocol/tailscale/endpoint.go b/protocol/tailscale/endpoint.go index f265a470d1..e2079515e3 100644 --- a/protocol/tailscale/endpoint.go +++ b/protocol/tailscale/endpoint.go @@ -23,6 +23,8 @@ import ( "github.com/sagernet/gvisor/pkg/tcpip/header" "github.com/sagernet/gvisor/pkg/tcpip/stack" "github.com/sagernet/gvisor/pkg/tcpip/transport/icmp" + "github.com/sagernet/gvisor/pkg/tcpip/transport/tcp" + "github.com/sagernet/gvisor/pkg/tcpip/transport/udp" "github.com/sagernet/sing-box/adapter" "github.com/sagernet/sing-box/adapter/endpoint" "github.com/sagernet/sing-box/common/dialer" @@ -31,7 +33,7 @@ import ( "github.com/sagernet/sing-box/log" "github.com/sagernet/sing-box/option" "github.com/sagernet/sing-box/route/rule" - "github.com/sagernet/sing-tun" + tun "github.com/sagernet/sing-tun" "github.com/sagernet/sing-tun/ping" "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/bufio" @@ -398,6 +400,20 @@ func (t *Endpoint) postStart() error { icmpForwarder := tun.NewICMPForwarder(t.ctx, ipStack, t, t.udpTimeout) ipStack.SetTransportProtocolHandler(icmp.ProtocolNumber4, icmpForwarder.HandlePacket) ipStack.SetTransportProtocolHandler(icmp.ProtocolNumber6, icmpForwarder.HandlePacket) + + // Wrap Tailscale's existing TCP/UDP handlers with DirectRoute for traceroute support. + // Low-TTL packets are handled via DirectRoute (ICMP Time Exceeded), while + // normal packets are passed to Tailscale's original netstack handlers. + tsAddr4, tsAddr6 := t.server.TailscaleIPs() + if prevTCP := ipStack.GetTransportProtocolHandler(tcp.ProtocolNumber); prevTCP != nil { + ipStack.SetTransportProtocolHandler(tcp.ProtocolNumber, + tun.WrapTCPHandlerWithDirectRoute(ipStack, t, icmpForwarder, t.udpTimeout, 0, tsAddr4, tsAddr6, prevTCP)) + } + if prevUDP := ipStack.GetTransportProtocolHandler(udp.ProtocolNumber); prevUDP != nil { + ipStack.SetTransportProtocolHandler(udp.ProtocolNumber, + tun.WrapUDPHandlerWithDirectRoute(ipStack, t, icmpForwarder, t.udpTimeout, 0, tsAddr4, tsAddr6, prevUDP)) + } + t.stack = ipStack t.icmpForwarder = icmpForwarder t.registerNetstackHandlers() @@ -798,6 +814,7 @@ func (t *Endpoint) onReconfig(cfg *wgcfg.Config, routerCfg *router.Config, dnsCf } } t.icmpForwarder.SetLocalAddresses(inet4Address, inet6Address) + t.icmpForwarder.SetTTLDecrement(inet4Address, inet6Address, 0) t.cfg = cfg t.dnsCfg = dnsCfg diff --git a/protocol/tun/inbound.go b/protocol/tun/inbound.go index 65e87bfdc5..bc442f3066 100644 --- a/protocol/tun/inbound.go +++ b/protocol/tun/inbound.go @@ -17,7 +17,7 @@ import ( "github.com/sagernet/sing-box/log" "github.com/sagernet/sing-box/option" "github.com/sagernet/sing-box/route/rule" - "github.com/sagernet/sing-tun" + tun "github.com/sagernet/sing-tun" "github.com/sagernet/sing/common" E "github.com/sagernet/sing/common/exceptions" "github.com/sagernet/sing/common/json/badoption" @@ -43,6 +43,7 @@ type Inbound struct { tunOptions tun.Options udpTimeout time.Duration dnsHijackAddress []netip.Addr + maxTracerouteHopLimit uint8 stack string tunIf tun.Tun tunStack tun.Stack @@ -221,10 +222,11 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo InterfaceMonitor: networkManager.InterfaceMonitor(), EXP_MultiPendingPackets: multiPendingPackets, }, - udpTimeout: udpTimeout, - stack: options.Stack, - platformInterface: platformInterface, - platformOptions: common.PtrValueOrDefault(options.Platform), + udpTimeout: udpTimeout, + maxTracerouteHopLimit: options.MaxTracerouteHopLimit, + stack: options.Stack, + platformInterface: platformInterface, + platformOptions: common.PtrValueOrDefault(options.Platform), } for _, routeAddressSet := range options.RouteAddressSet { ruleSet, loaded := router.RuleSet(routeAddressSet) @@ -409,6 +411,7 @@ func (t *Inbound) Start(stage adapter.StartStage) error { ForwarderBindInterface: forwarderBindInterface, InterfaceFinder: t.networkManager.InterfaceFinder(), IncludeAllNetworks: includeAllNetworks, + MaxTracerouteHopLimit: t.maxTracerouteHopLimit, }) if err != nil { return err diff --git a/transport/wireguard/device_system_stack.go b/transport/wireguard/device_system_stack.go index d3b47222aa..0d52761f54 100644 --- a/transport/wireguard/device_system_stack.go +++ b/transport/wireguard/device_system_stack.go @@ -18,7 +18,7 @@ import ( "github.com/sagernet/gvisor/pkg/tcpip/transport/udp" "github.com/sagernet/sing-box/adapter" "github.com/sagernet/sing-box/log" - "github.com/sagernet/sing-tun" + tun "github.com/sagernet/sing-tun" "github.com/sagernet/sing-tun/ping" E "github.com/sagernet/sing/common/exceptions" "github.com/sagernet/sing/common/logger" @@ -74,10 +74,13 @@ func newSystemStackDevice(options DeviceOptions) (*systemStackDevice, error) { } } if options.Handler != nil { - ipStack.SetTransportProtocolHandler(tcp.ProtocolNumber, tun.NewTCPForwarder(options.Context, ipStack, options.Handler).HandlePacket) - ipStack.SetTransportProtocolHandler(udp.ProtocolNumber, tun.NewUDPForwarder(options.Context, ipStack, options.Handler, options.UDPTimeout).HandlePacket) icmpForwarder := tun.NewICMPForwarder(options.Context, ipStack, options.Handler, options.UDPTimeout) icmpForwarder.SetLocalAddresses(inet4Address, inet6Address) + icmpForwarder.SetTTLDecrement(inet4Address, inet6Address, 0) + tcpHandler := tun.NewTCPForwarder(options.Context, ipStack, options.Handler).HandlePacket + udpHandler := tun.NewUDPForwarder(options.Context, ipStack, options.Handler, options.UDPTimeout).HandlePacket + ipStack.SetTransportProtocolHandler(tcp.ProtocolNumber, tun.WrapTCPHandlerWithDirectRoute(ipStack, options.Handler, icmpForwarder, options.UDPTimeout, 0, inet4Address, inet6Address, tcpHandler)) + ipStack.SetTransportProtocolHandler(udp.ProtocolNumber, tun.WrapUDPHandlerWithDirectRoute(ipStack, options.Handler, icmpForwarder, options.UDPTimeout, 0, inet4Address, inet6Address, udpHandler)) ipStack.SetTransportProtocolHandler(icmp.ProtocolNumber4, icmpForwarder.HandlePacket) ipStack.SetTransportProtocolHandler(icmp.ProtocolNumber6, icmpForwarder.HandlePacket) }