From 987635d3dc201d9b2a279cde710e5dc6558a1b87 Mon Sep 17 00:00:00 2001
From: ssrlive <30760636+ssrlive@users.noreply.github.com>
Date: Sat, 23 Nov 2024 22:10:53 +0800
Subject: [PATCH 01/59] Contributors in README
---
README.md | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 06f0601..f737745 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,10 @@
+[](https://github.com/tun2proxy/tun2proxy)
+
# tun2proxy
A tunnel interface for HTTP and SOCKS proxies on Linux, Android, macOS, iOS and Windows.
[](https://crates.io/crates/tun2proxy)
-
+[](https://docs.rs/tun2proxy)
[](https://docs.rs/tun2proxy)
[](https://crates.io/crates/tun2proxy)
[](https://github.com/tun2proxy/tun2proxy/blob/master/LICENSE)
@@ -216,3 +218,10 @@ asked to open connections to IPv6 destinations. In such a case, you can disable
either through `sysctl -w net.ipv6.conf.all.disable_ipv6=1` and `sysctl -w net.ipv6.conf.default.disable_ipv6=1`
or through `ip -6 route del default`, which causes the `libc` resolver (and other software) to not issue DNS AAAA
requests for IPv6 addresses.
+
+## Contributors ✨
+Thanks goes to these wonderful people:
+
+
+
+
From d37cb44b6221c0b1b5e3841ead6eb98c4a8d920f Mon Sep 17 00:00:00 2001
From: ssrlive <30760636+ssrlive@users.noreply.github.com>
Date: Tue, 26 Nov 2024 12:17:16 +0800
Subject: [PATCH 02/59] Fix #165
---
src/args.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/args.rs b/src/args.rs
index 85904db..33f160c 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -397,7 +397,7 @@ impl TryFrom<&str> for ArgProxy {
let mut url_host = String::from(host);
let e = format!("`{s}` does not contain a port");
- let port = url.port().ok_or(Error::from(&e))?;
+ let port = url.port_or_known_default().ok_or(Error::from(&e))?;
url_host.push(':');
url_host.push_str(port.to_string().as_str());
From 46bf4434ef4dc6eb29950aacbdeff0c16bc733c2 Mon Sep 17 00:00:00 2001
From: ssrlive <30760636+ssrlive@users.noreply.github.com>
Date: Tue, 26 Nov 2024 12:28:03 +0800
Subject: [PATCH 03/59] Bump version 0.6.6
---
Cargo.toml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Cargo.toml b/Cargo.toml
index c426865..a2285cb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "tun2proxy"
-version = "0.6.5"
+version = "0.6.6"
edition = "2021"
license = "MIT"
repository = "https://github.com/tun2proxy/tun2proxy"
From 7a7293effd893dcf9e94eeb1e10bdede4a499000 Mon Sep 17 00:00:00 2001
From: ssrlive <30760636+ssrlive@users.noreply.github.com>
Date: Tue, 26 Nov 2024 12:50:07 +0800
Subject: [PATCH 04/59] Refine code
---
src/args.rs | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/src/args.rs b/src/args.rs
index 33f160c..38c2a09 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -395,17 +395,11 @@ impl TryFrom<&str> for ArgProxy {
let e = format!("`{s}` does not contain a host");
let host = url.host_str().ok_or(Error::from(e))?;
- let mut url_host = String::from(host);
let e = format!("`{s}` does not contain a port");
let port = url.port_or_known_default().ok_or(Error::from(&e))?;
- url_host.push(':');
- url_host.push_str(port.to_string().as_str());
- let e = format!("`{host}` could not be resolved");
- let mut addr_iter = url_host.to_socket_addrs().map_err(|_| Error::from(&e))?;
-
- let e = format!("`{host}` does not resolve to a usable IP address");
- let addr = addr_iter.next().ok_or(Error::from(&e))?;
+ let e2 = format!("`{host}` does not resolve to a usable IP address");
+ let addr = (host, port).to_socket_addrs()?.next().ok_or(Error::from(&e2))?;
let credentials = if url.username() == "" && url.password().is_none() {
None
From 724557b30e5199febf3ff96f667836856da6d726 Mon Sep 17 00:00:00 2001
From: Paper-Dragon <2678885646@qq.com>
Date: Tue, 26 Nov 2024 13:12:04 +0800
Subject: [PATCH 05/59] docker-compose.yaml support (#166)
---
README.md | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index f737745..3f320e2 100644
--- a/README.md
+++ b/README.md
@@ -172,7 +172,8 @@ Currently, tun2proxy supports HTTP, SOCKS4/SOCKS4a and SOCKS5. A proxy is suppli
URL format. For example, an HTTP proxy at `1.2.3.4:3128` with a username of `john.doe` and a password of `secret` is
supplied as `--proxy http://john.doe:secret@1.2.3.4:3128`. This works analogously to curl's `--proxy` argument.
-## Docker Support
+## Container Support
+### Docker
Tun2proxy can serve as a proxy for other Docker containers. To make use of that feature, first build the image:
```bash
@@ -197,6 +198,36 @@ docker run -it \
--network "container:tun2proxy" \
ubuntu:latest
```
+### Docker Compose
+
+The above docker command is written into a `docker-compose.yaml` file.
+
+```yaml
+services:
+ tun2proxy:
+ volumes:
+ - /dev/net/tun:/dev/net/tun
+ sysctls:
+ - net.ipv6.conf.default.disable_ipv6=0
+ cap_add:
+ - NET_ADMIN
+ container_name: tun2proxy
+ image: ghcr.io/tun2proxy/tun2proxy:latest
+ command: --proxy proto://[username[:password]@]host:port
+ alpine:
+ stdin_open: true
+ tty: true
+ network_mode: container:tun2proxy
+ image: alpine:latest
+ command: apk add curl && curl ifconfig.icu && sleep 10
+```
+
+run compose file
+
+```bash
+docker compose up -d tun2proxy
+docker compose up alpine
+```
## Configuration Tips
### DNS
From a01de17b365bc6343dbff4051490f0b3b974e463 Mon Sep 17 00:00:00 2001
From: ssrlive <30760636+ssrlive@users.noreply.github.com>
Date: Tue, 26 Nov 2024 13:32:39 +0800
Subject: [PATCH 06/59] minor changes
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 3f320e2..5c9b591 100644
--- a/README.md
+++ b/README.md
@@ -200,7 +200,7 @@ docker run -it \
```
### Docker Compose
-The above docker command is written into a `docker-compose.yaml` file.
+Write a `docker-compose.yaml` file with the following content:
```yaml
services:
@@ -222,7 +222,7 @@ services:
command: apk add curl && curl ifconfig.icu && sleep 10
```
-run compose file
+Then run the compose file
```bash
docker compose up -d tun2proxy
From 258637a52ea663e832a8cb380a78d5774140c8ab Mon Sep 17 00:00:00 2001
From: ssrlive <30760636+ssrlive@users.noreply.github.com>
Date: Tue, 10 Dec 2024 11:17:51 +0800
Subject: [PATCH 07/59] upgrade dependencies
---
Cargo.toml | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index a2285cb..1f46a49 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -26,14 +26,16 @@ ctrlc2 = { version = "3", features = ["tokio", "termination"] }
digest_auth = "0.3"
dotenvy = "0.15"
env_logger = "0.11"
-hashlink = "0.9"
+hashlink = "0.10"
hickory-proto = "0.24"
httparse = "1"
ipstack = { version = "0.1" }
log = { version = "0.4", features = ["std"] }
mimalloc = { version = "0.1", default-features = false, optional = true }
percent-encoding = "2"
-socks5-impl = { version = "0.5" }
+socks5-impl = { version = "0.6", default-features = false, features = [
+ "tokio",
+] }
thiserror = "2"
tokio = { version = "1", features = ["full"] }
tokio-util = "0.7"
@@ -43,6 +45,9 @@ udp-stream = { version = "0.0.12", default-features = false }
unicase = "2"
url = "2"
+[build-dependencies]
+serde_json = "1"
+
[target.'cfg(target_os="linux")'.dependencies]
serde = { version = "1", features = ["derive"] }
bincode = "1"
@@ -62,9 +67,6 @@ nix = { version = "0.29", default-features = false, features = [
[target.'cfg(target_os = "windows")'.dependencies]
windows-service = "0.7"
-[build-dependencies]
-serde_json = "1"
-
[[bin]]
name = "tun2proxy-bin"
path = "src/bin/main.rs"
From 4d4a0ce85cc3222d34f9dd7cf38ec05548cb189b Mon Sep 17 00:00:00 2001
From: ssrlive <30760636+ssrlive@users.noreply.github.com>
Date: Thu, 26 Dec 2024 20:38:13 +0800
Subject: [PATCH 08/59] minor changes
---
Cargo.toml | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index 1f46a49..f203a2e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,6 +13,15 @@ rust-version = "1.80"
[lib]
crate-type = ["staticlib", "cdylib", "lib"]
+[[bin]]
+name = "tun2proxy-bin"
+path = "src/bin/main.rs"
+
+[[bin]]
+name = "udpgw-server"
+path = "src/bin/udpgw_server.rs"
+required-features = ["udpgw"]
+
[features]
default = ["udpgw"]
udpgw = []
@@ -67,14 +76,5 @@ nix = { version = "0.29", default-features = false, features = [
[target.'cfg(target_os = "windows")'.dependencies]
windows-service = "0.7"
-[[bin]]
-name = "tun2proxy-bin"
-path = "src/bin/main.rs"
-
-[[bin]]
-name = "udpgw-server"
-path = "src/bin/udpgw_server.rs"
-required-features = ["udpgw"]
-
[profile.release]
strip = "symbols"
From ea5ee834dbbfa6cf373b14fd77caee9946e22403 Mon Sep 17 00:00:00 2001
From: ssrlive <30760636+ssrlive@users.noreply.github.com>
Date: Fri, 27 Dec 2024 16:59:11 +0800
Subject: [PATCH 09/59] Bump version 0.6.7
---
.github/workflows/publish-exe.yml | 8 ++++++++
Cargo.toml | 2 +-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/publish-exe.yml b/.github/workflows/publish-exe.yml
index 628baf3..c9730b9 100644
--- a/.github/workflows/publish-exe.yml
+++ b/.github/workflows/publish-exe.yml
@@ -15,6 +15,7 @@ jobs:
attestations: write
strategy:
+ fail-fast: false
matrix:
target:
- x86_64-unknown-linux-gnu
@@ -77,6 +78,7 @@ jobs:
fi
- name: Build
+ if: ${{ !cancelled() }}
shell: bash
run: |
if [[ "${{ matrix.host_os }}" == "ubuntu-latest" ]]; then
@@ -112,20 +114,26 @@ jobs:
fi
- name: Upload artifacts
+ if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: bin-${{ matrix.target }}
path: mypubdir4/*
- name: Generate artifact attestation
+ if: ${{ !cancelled() }}
uses: actions/attest-build-provenance@v1
with:
subject-path: mypubdir4/*
- name: Publish
+ if: ${{ !cancelled() }}
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: mypubdir4/*
+ - name: Abort on error
+ if: ${{ failure() }}
+ run: echo "Some of jobs failed" && false
diff --git a/Cargo.toml b/Cargo.toml
index f203a2e..171b742 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "tun2proxy"
-version = "0.6.6"
+version = "0.6.7"
edition = "2021"
license = "MIT"
repository = "https://github.com/tun2proxy/tun2proxy"
From 2a8e31225c8369b4a0ccd346c45288c04fb0019d Mon Sep 17 00:00:00 2001
From: ssrlive <30760636+ssrlive@users.noreply.github.com>
Date: Thu, 2 Jan 2025 17:05:32 +0800
Subject: [PATCH 10/59] refine clap::Parser
---
src/args.rs | 3 +--
src/bin/udpgw_server.rs | 4 +---
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/src/args.rs b/src/args.rs
index 38c2a09..71a85f2 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -181,8 +181,7 @@ impl Default for Args {
impl Args {
#[allow(clippy::let_and_return)]
pub fn parse_args() -> Self {
- use clap::Parser;
- let args = Self::parse();
+ let args = ::parse();
#[cfg(target_os = "linux")]
if !args.setup && args.tun.is_none() {
eprintln!("Missing required argument, '--tun' must present when '--setup' is not used.");
diff --git a/src/bin/udpgw_server.rs b/src/bin/udpgw_server.rs
index e78fbb9..9cf144a 100644
--- a/src/bin/udpgw_server.rs
+++ b/src/bin/udpgw_server.rs
@@ -54,10 +54,8 @@ pub struct UdpGwArgs {
}
impl UdpGwArgs {
- #[allow(clippy::let_and_return)]
pub fn parse_args() -> Self {
- use clap::Parser;
- Self::parse()
+ ::parse()
}
}
From 7136e2a20c63526f217c1ce9ca05f4ced26b0bba Mon Sep 17 00:00:00 2001
From: ssrlive <30760636+ssrlive@users.noreply.github.com>
Date: Thu, 2 Jan 2025 23:18:40 +0800
Subject: [PATCH 11/59] refactor desktop_run_async
---
Cargo.toml | 2 +-
cbindgen.toml | 1 +
src/bin/main.rs | 3 +-
src/desktop_api.rs | 116 ++++++++++++++++++++++++++++-----------------
src/mobile_api.rs | 101 +++++++++++++++++++--------------------
src/win_svc.rs | 2 +-
6 files changed, 127 insertions(+), 98 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index 171b742..e93e99b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "tun2proxy"
-version = "0.6.7"
+version = "0.7.0"
edition = "2021"
license = "MIT"
repository = "https://github.com/tun2proxy/tun2proxy"
diff --git a/cbindgen.toml b/cbindgen.toml
index 8354c6c..10e4235 100644
--- a/cbindgen.toml
+++ b/cbindgen.toml
@@ -3,6 +3,7 @@ cpp_compat = true
[export]
include = [
+ "tun2proxy_run_with_cli",
"tun2proxy_with_fd_run",
"tun2proxy_with_name_run",
"tun2proxy_with_name_stop",
diff --git a/src/bin/main.rs b/src/bin/main.rs
index e39b7b4..d5b1ebe 100644
--- a/src/bin/main.rs
+++ b/src/bin/main.rs
@@ -1,3 +1,4 @@
+use tun::DEFAULT_MTU as MTU;
use tun2proxy::{Args, BoxError};
fn main() -> Result<(), BoxError> {
@@ -49,7 +50,7 @@ async fn main_async(args: Args) -> Result<(), BoxError> {
}
unsafe { tun2proxy::tun2proxy_set_traffic_status_callback(1, Some(traffic_cb), std::ptr::null_mut()) };
- if let Err(err) = tun2proxy::desktop_run_async(args, shutdown_token).await {
+ if let Err(err) = tun2proxy::desktop_run_async(args, MTU, false, shutdown_token).await {
log::error!("main loop error: {}", err);
}
}
diff --git a/src/desktop_api.rs b/src/desktop_api.rs
index 17428fb..ed8dbb5 100644
--- a/src/desktop_api.rs
+++ b/src/desktop_api.rs
@@ -5,7 +5,6 @@ use crate::{
ArgVerbosity, Args,
};
use std::os::raw::{c_char, c_int};
-use tproxy_config::{TproxyArgs, TUN_GATEWAY, TUN_IPV4, TUN_NETMASK};
use tun::{AbstractDevice, DEFAULT_MTU as MTU};
static TUN_QUIT: std::sync::Mutex