14 Commits

Author SHA1 Message Date
Datong Sun
726ecac9cf chore(phantun) bump phantun to v0.2.5 2022-01-03 07:47:48 -08:00
dependabot[bot]
2ef0a056be chore(deps): update clap requirement from 2.34 to 3.0
Updates the requirements on [clap](https://github.com/clap-rs/clap) to permit the latest version.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_generate-v3.0.0-rc.0...clap_complete-v3.0.0)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-03 23:45:13 +08:00
Datong Sun
cb9dd3e931 fix(client) disable AAAA resolve, since tokio-tun does not yet have IPv6
support. See: https://github.com/yaa110/tokio-tun/pull/8
2022-01-03 23:37:31 +08:00
Datong Sun
7db7164193 chore(*) use tokio-tun v0.5 instead of forked version. Bumped
`fake-tcp` to `v0.2.3`
2021-12-07 17:07:54 +08:00
Datong Sun
def134d73b docs(readme) bump latest version to v0.2.4 2021-12-05 07:13:01 -08:00
Datong Sun
b3c781cdc5 chore(phantun) bump phantun to v0.2.4 2021-12-05 07:10:42 -08:00
Datong Sun
d5e30c113f chore(phantun) bump clap and tokio dependencies to latest 2021-12-05 07:01:58 -08:00
Datong Sun
e2a9194f6f chore(fake-tcp) bump to v0.2.2 2021-12-05 06:57:23 -08:00
Datong Sun
d0eaefe5d0 chore(phantun) specify exact version for fake-tcp dependency 2021-12-05 06:49:35 -08:00
Datong Sun
299646a54f chore(fake-tcp) bump to v0.2.1 2021-12-05 06:43:18 -08:00
Datong Sun
8b28cdc6c2 chore(crates) do not include bugfix version in dependency as it prevents
auto update from Dependabot
2021-12-05 22:41:05 +08:00
Datong Sun
a8ad203754 docs(readme) fixed some typos 2021-12-01 15:10:52 +08:00
Datong Sun
33e510e7ba fix(fake-tcp) remove unneeded State::Closed as it is not in a
reachable code path
2021-11-19 10:45:13 -08:00
Datong Sun
521a3f1a01 docs(readme) bump release version and add host name support info for
`--remote`
2021-11-18 20:48:53 -08:00
6 changed files with 49 additions and 48 deletions

View File

@@ -31,16 +31,16 @@ Table of Contents
# Latest release
[v0.2.2](https://github.com/dndx/phantun/releases/tag/v0.2.2)
[v0.2.4](https://github.com/dndx/phantun/releases/tag/v0.2.4)
# Overview
Phanton is a project that obfuscated UDP packets into TCP connections. It aims to
Phantun is a project that obfuscated UDP packets into TCP connections. It aims to
achieve maximum performance with minimum processing and encapsulation overhead.
It is commonly used in environments where UDP is blocked/throttled but TCP is allowed through.
Phanton simply converts a stream of UDP packets into obfuscated TCP stream packets. The TCP stack
Phantun simply converts a stream of UDP packets into obfuscated TCP stream packets. The TCP stack
used by Phantun is designed to pass through most L3/L4 stateful/stateless firewalls/NAT
devices. It will **not** be able to pass through L7 proxies.
However, the advantage of this approach is that none of the common UDP over TCP performance killer
@@ -134,7 +134,7 @@ iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Server needs to DNAT the TCP listening port to Phantun's TUN interface address.
Note: change `eth0` to whatever actual physical interface name is and `4567` to
actual TCP port number used by Phanton server
actual TCP port number used by Phantun server
[Back to TOC](#table-of-contents)
@@ -185,6 +185,12 @@ rule specified above. `127.0.0.1:1234` is the UDP Server to connect to for new c
RUST_LOG=info /usr/local/bin/phantun_server --local 4567 --remote 127.0.0.1:1234
```
Or use host name with `--remote`:
```
RUST_LOG=info /usr/local/bin/phantun_server --local 4567 --remote example.com:1234
```
[Back to TOC](#table-of-contents)
### Client
@@ -196,6 +202,12 @@ the Phantun Server to connect.
RUST_LOG=info /usr/local/bin/phantun_client --local 127.0.0.1:1234 --remote 10.0.0.1:4567
```
Or use host name with `--remote`:
```
RUST_LOG=info /usr/local/bin/phantun_client --local 127.0.0.1:1234 --remote example.com:4567
```
[Back to TOC](#table-of-contents)
# MTU overhead
@@ -264,7 +276,7 @@ for tunneling TCP/UDP traffic between two test instances and MTU has been tuned
# Compariation to udp2raw
[udp2raw](https://github.com/wangyu-/udp2raw-tunnel) is another popular project by [@wangyu-](https://github.com/wangyu-)
that is very similar to what Phantun can do. In fact I took inspirations of Phantun from udp2raw. The biggest reason for
developing Phanton is because of lack of performance when running udp2raw (especially on multi-core systems such as Raspberry Pi).
developing Phantun is because of lack of performance when running udp2raw (especially on multi-core systems such as Raspberry Pi).
However, the goal is never to be as feature complete as udp2raw and only support the most common use cases. Most notably, UDP over ICMP
and UDP over UDP mode are not supported and there is no anti-replay nor encryption support. The benefit of this is much better
performance overall and less MTU overhead because lack of additional headers inside the TCP payload.

View File

@@ -1,6 +1,6 @@
[package]
name = "fake-tcp"
version = "0.2.0"
version = "0.2.3"
edition = "2021"
authors = ["Datong Sun <dndx@idndx.com>"]
license = "MIT OR Apache-2.0"
@@ -16,9 +16,9 @@ benchmark = []
[dependencies]
bytes = "1"
pnet = "0.28.0"
tokio = { version = "1.12.0", features = ["full"] }
rand = { version = "0.8.4", features = ["small_rng"] }
pnet = "0.28"
tokio = { version = "1.14", features = ["full"] }
rand = { version = "0.8", features = ["small_rng"] }
log = "0.4"
internet-checksum = "0.2.0"
dndx-fork-tokio-tun = "0.4.0"
internet-checksum = "0.2"
tokio-tun = "0.5"

View File

@@ -1,7 +1,6 @@
#![cfg_attr(feature = "benchmark", feature(test))]
pub mod packet;
extern crate dndx_fork_tokio_tun as tokio_tun;
use bytes::{Bytes, BytesMut};
use log::{error, info, trace, warn};
@@ -57,7 +56,6 @@ pub enum State {
SynSent,
SynReceived,
Established,
Closed,
}
pub struct Socket {
@@ -116,12 +114,10 @@ impl Socket {
tokio::select! {
res = self.tun.send(&buf) => {
res.unwrap();
Some(())
res.ok().and(Some(()))
},
}
}
State::Closed => None,
_ => unreachable!(),
}
}
@@ -148,7 +144,6 @@ impl Socket {
Some(payload.len())
})
}
State::Closed => None,
_ => unreachable!(),
}
}
@@ -252,8 +247,6 @@ impl Socket {
impl Drop for Socket {
fn drop(&mut self) {
self.state = State::Closed;
let tuple = AddrTuple::new(self.local_addr, self.remote_addr);
// dissociates ourself from the dispatch map
assert!(self.shared.tuples.write().unwrap().remove(&tuple).is_some());

View File

@@ -1,6 +1,6 @@
[package]
name = "phantun"
version = "0.2.3"
version = "0.2.5"
edition = "2021"
authors = ["Datong Sun <dndx@idndx.com>"]
license = "MIT OR Apache-2.0"
@@ -11,11 +11,11 @@ Transforms UDP stream into (fake) TCP streams that can go through
Layer 3 & Layer 4 (NAPT) firewalls/NATs.
"""
[dependencies]
clap = "2.33.3"
socket2 = { version = "0.4.2", features = ["all"] }
fake-tcp = "0.2.0"
tokio = { version = "1.12.0", features = ["full"] }
clap = { version = "3.0", features = ["cargo"] }
socket2 = { version = "0.4", features = ["all"] }
fake-tcp = "0.2"
tokio = { version = "1.14", features = ["full"] }
log = "0.4"
pretty_env_logger = "0.4.0"
dndx-fork-tokio-tun = "0.4.0"
num_cpus = "1.13.0"
pretty_env_logger = "0.4"
tokio-tun = "0.5"
num_cpus = "1.13"

View File

@@ -1,5 +1,3 @@
extern crate dndx_fork_tokio_tun as tokio_tun;
use clap::{crate_version, App, Arg};
use fake_tcp::packet::MAX_PACKET_LEN;
use fake_tcp::{Socket, Stack};
@@ -44,8 +42,8 @@ async fn main() {
.version(crate_version!())
.author("Datong Sun (github.com/dndx)")
.arg(
Arg::with_name("local")
.short("l")
Arg::new("local")
.short('l')
.long("local")
.required(true)
.value_name("IP:PORT")
@@ -53,8 +51,8 @@ async fn main() {
.takes_value(true),
)
.arg(
Arg::with_name("remote")
.short("r")
Arg::new("remote")
.short('r')
.long("remote")
.required(true)
.value_name("IP or HOST NAME:PORT")
@@ -62,7 +60,7 @@ async fn main() {
.takes_value(true),
)
.arg(
Arg::with_name("tun")
Arg::new("tun")
.long("tun")
.required(false)
.value_name("tunX")
@@ -71,7 +69,7 @@ async fn main() {
.takes_value(true),
)
.arg(
Arg::with_name("tun_local")
Arg::new("tun_local")
.long("tun-local")
.required(false)
.value_name("IP")
@@ -80,7 +78,7 @@ async fn main() {
.takes_value(true),
)
.arg(
Arg::with_name("tun_peer")
Arg::new("tun_peer")
.long("tun-peer")
.required(false)
.value_name("IP")
@@ -101,12 +99,12 @@ async fn main() {
let remote_addr = tokio::net::lookup_host(matches.value_of("remote").unwrap())
.await
.expect("bad remote address or host")
.next()
.expect("unable to resolve remote host name");
.find(|addr| addr.is_ipv4())
.expect("unable to resolve remote host name or no valid A record was returned");
let remote_addr = if let SocketAddr::V4(addr) = remote_addr {
addr
} else {
panic!("only IPv4 remote address is supported");
unreachable!();
};
info!("Remote address is: {}", remote_addr);

View File

@@ -1,5 +1,3 @@
extern crate dndx_fork_tokio_tun as tokio_tun;
use clap::{crate_version, App, Arg};
use fake_tcp::packet::MAX_PACKET_LEN;
use fake_tcp::Stack;
@@ -18,8 +16,8 @@ async fn main() {
.version(crate_version!())
.author("Datong Sun (github.com/dndx)")
.arg(
Arg::with_name("local")
.short("l")
Arg::new("local")
.short('l')
.long("local")
.required(true)
.value_name("PORT")
@@ -27,8 +25,8 @@ async fn main() {
.takes_value(true),
)
.arg(
Arg::with_name("remote")
.short("r")
Arg::new("remote")
.short('r')
.long("remote")
.required(true)
.value_name("IP or HOST NAME:PORT")
@@ -36,7 +34,7 @@ async fn main() {
.takes_value(true),
)
.arg(
Arg::with_name("tun")
Arg::new("tun")
.long("tun")
.required(false)
.value_name("tunX")
@@ -45,7 +43,7 @@ async fn main() {
.takes_value(true),
)
.arg(
Arg::with_name("tun_local")
Arg::new("tun_local")
.long("tun-local")
.required(false)
.value_name("IP")
@@ -54,7 +52,7 @@ async fn main() {
.takes_value(true),
)
.arg(
Arg::with_name("tun_peer")
Arg::new("tun_peer")
.long("tun-peer")
.required(false)
.value_name("IP")