mirror of
https://github.com/dndx/phantun.git
synced 2025-09-16 04:04:29 +08:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
494abf37c5 | ||
|
cab87bd75b | ||
|
042f5af49f | ||
|
f667f56747 | ||
|
49665b906f | ||
|
e9cde27923 |
12
.github/dependabot.yml
vendored
Normal file
12
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
||||||
|
|
||||||
|
- package-ecosystem: "cargo"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
3
.github/workflows/rust.yml
vendored
3
.github/workflows/rust.yml
vendored
@@ -12,6 +12,9 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
- name: Run lint
|
- name: Run lint
|
||||||
run: cargo clippy --verbose
|
run: cargo clippy --verbose
|
||||||
- name: Build
|
- name: Build
|
||||||
|
@@ -84,6 +84,10 @@ and change the destination IP address to where the server is listening for incom
|
|||||||
In those cases, the machine/iptables running Phantun acts as the "router" that allows Phantun
|
In those cases, the machine/iptables running Phantun acts as the "router" that allows Phantun
|
||||||
to communicate with outside using it's private IP addresses.
|
to communicate with outside using it's private IP addresses.
|
||||||
|
|
||||||
|
As of Phantun v0.2.2, IPv6 support for UDP endpoints has been added, however Fake TCP IPv6 support
|
||||||
|
has not been finished yet. To specify an IPv6 address, use the following format: `[::1]:1234` with
|
||||||
|
the command line options.
|
||||||
|
|
||||||
[Back to TOC](#table-of-contents)
|
[Back to TOC](#table-of-contents)
|
||||||
|
|
||||||
## 1. Enable Kernel IP forwarding
|
## 1. Enable Kernel IP forwarding
|
||||||
@@ -250,7 +254,7 @@ for tunneling TCP/UDP traffic between two test instances and MTU has been tuned
|
|||||||
|
|
||||||
# Future plans
|
# Future plans
|
||||||
|
|
||||||
* IPv6 support
|
* IPv6 support for fake-tcp
|
||||||
* Load balancing a single UDP stream into multiple TCP streams
|
* Load balancing a single UDP stream into multiple TCP streams
|
||||||
* Integration tests
|
* Integration tests
|
||||||
* Auto insertion/removal of required firewall rules
|
* Auto insertion/removal of required firewall rules
|
||||||
@@ -278,7 +282,7 @@ Here is a quick overview of comparison between those two to help you choose:
|
|||||||
| Tunneling MTU overhead | 12 bytes | 44 bytes |
|
| Tunneling MTU overhead | 12 bytes | 44 bytes |
|
||||||
| Seprate TCP connections for each UDP connection | Client/Server | Server only |
|
| Seprate TCP connections for each UDP connection | Client/Server | Server only |
|
||||||
| Anti-replay, encryption | ❌ | ✅ |
|
| Anti-replay, encryption | ❌ | ✅ |
|
||||||
| IPv6 | Planned | ✅ |
|
| IPv6 | UDP only | ✅ |
|
||||||
|
|
||||||
[Back to TOC](#table-of-contents)
|
[Back to TOC](#table-of-contents)
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "fake-tcp"
|
name = "fake-tcp"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
authors = ["Datong Sun <dndx@idndx.com>"]
|
authors = ["Datong Sun <dndx@idndx.com>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
repository = "https://github.com/dndx/phantun"
|
repository = "https://github.com/dndx/phantun"
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "phantun"
|
name = "phantun"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
authors = ["Datong Sun <dndx@idndx.com>"]
|
authors = ["Datong Sun <dndx@idndx.com>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
repository = "https://github.com/dndx/phantun"
|
repository = "https://github.com/dndx/phantun"
|
||||||
|
@@ -16,8 +16,17 @@ use tokio_tun::TunBuilder;
|
|||||||
|
|
||||||
const UDP_TTL: Duration = Duration::from_secs(180);
|
const UDP_TTL: Duration = Duration::from_secs(180);
|
||||||
|
|
||||||
fn new_udp_reuseport(addr: SocketAddrV4) -> UdpSocket {
|
fn new_udp_reuseport(addr: SocketAddr) -> UdpSocket {
|
||||||
let udp_sock = socket2::Socket::new(socket2::Domain::IPV4, socket2::Type::DGRAM, None).unwrap();
|
let udp_sock = socket2::Socket::new(
|
||||||
|
if addr.is_ipv4() {
|
||||||
|
socket2::Domain::IPV4
|
||||||
|
} else {
|
||||||
|
socket2::Domain::IPV6
|
||||||
|
},
|
||||||
|
socket2::Type::DGRAM,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
udp_sock.set_reuse_port(true).unwrap();
|
udp_sock.set_reuse_port(true).unwrap();
|
||||||
// from tokio-rs/mio/blob/master/src/sys/unix/net.rs
|
// from tokio-rs/mio/blob/master/src/sys/unix/net.rs
|
||||||
udp_sock.set_cloexec(true).unwrap();
|
udp_sock.set_cloexec(true).unwrap();
|
||||||
@@ -40,7 +49,7 @@ async fn main() {
|
|||||||
.long("local")
|
.long("local")
|
||||||
.required(true)
|
.required(true)
|
||||||
.value_name("IP:PORT")
|
.value_name("IP:PORT")
|
||||||
.help("Sets the IP and port where Phantun Client listens for incoming UDP datagrams")
|
.help("Sets the IP and port where Phantun Client listens for incoming UDP datagrams, IPv6 address need to be specified as: \"[IPv6]:PORT\"")
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
@@ -83,7 +92,7 @@ async fn main() {
|
|||||||
)
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let local_addr: SocketAddrV4 = matches
|
let local_addr: SocketAddr = matches
|
||||||
.value_of("local")
|
.value_of("local")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.parse()
|
.parse()
|
||||||
@@ -117,7 +126,7 @@ async fn main() {
|
|||||||
info!("Created TUN device {}", tun[0].name());
|
info!("Created TUN device {}", tun[0].name());
|
||||||
|
|
||||||
let udp_sock = Arc::new(new_udp_reuseport(local_addr));
|
let udp_sock = Arc::new(new_udp_reuseport(local_addr));
|
||||||
let connections = Arc::new(RwLock::new(HashMap::<SocketAddrV4, Arc<Socket>>::new()));
|
let connections = Arc::new(RwLock::new(HashMap::<SocketAddr, Arc<Socket>>::new()));
|
||||||
|
|
||||||
let mut stack = Stack::new(tun);
|
let mut stack = Stack::new(tun);
|
||||||
|
|
||||||
@@ -126,7 +135,7 @@ async fn main() {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
Ok((size, SocketAddr::V4(addr))) = udp_sock.recv_from(&mut buf_r) => {
|
Ok((size, addr)) = udp_sock.recv_from(&mut buf_r) => {
|
||||||
// seen UDP packet to listening socket, this means:
|
// seen UDP packet to listening socket, this means:
|
||||||
// 1. It is a new UDP connection, or
|
// 1. It is a new UDP connection, or
|
||||||
// 2. It is some extra packets not filtered by more specific
|
// 2. It is some extra packets not filtered by more specific
|
||||||
|
@@ -4,7 +4,7 @@ use clap::{crate_version, App, Arg};
|
|||||||
use fake_tcp::packet::MAX_PACKET_LEN;
|
use fake_tcp::packet::MAX_PACKET_LEN;
|
||||||
use fake_tcp::Stack;
|
use fake_tcp::Stack;
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use std::net::{Ipv4Addr, SocketAddrV4};
|
use std::net::{Ipv4Addr, SocketAddr};
|
||||||
use tokio::net::UdpSocket;
|
use tokio::net::UdpSocket;
|
||||||
use tokio::time::{self, Duration};
|
use tokio::time::{self, Duration};
|
||||||
use tokio_tun::TunBuilder;
|
use tokio_tun::TunBuilder;
|
||||||
@@ -32,7 +32,7 @@ async fn main() {
|
|||||||
.long("remote")
|
.long("remote")
|
||||||
.required(true)
|
.required(true)
|
||||||
.value_name("IP:PORT")
|
.value_name("IP:PORT")
|
||||||
.help("Sets the address and port where Phantun Server forwards UDP packets to")
|
.help("Sets the address and port where Phantun Server forwards UDP packets to, IPv6 address need to be specified as: \"[IPv6]:PORT\"")
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
@@ -71,7 +71,7 @@ async fn main() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.parse()
|
.parse()
|
||||||
.expect("bad local port");
|
.expect("bad local port");
|
||||||
let remote_addr: SocketAddrV4 = matches
|
let remote_addr: SocketAddr = matches
|
||||||
.value_of("remote")
|
.value_of("remote")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.parse()
|
.parse()
|
||||||
@@ -113,7 +113,13 @@ async fn main() {
|
|||||||
info!("New connection: {}", sock);
|
info!("New connection: {}", sock);
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let udp_sock = UdpSocket::bind("0.0.0.0:0").await.unwrap();
|
let udp_sock = UdpSocket::bind(if remote_addr.is_ipv4() {
|
||||||
|
"0.0.0.0:0"
|
||||||
|
} else {
|
||||||
|
"[::]:0"
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
udp_sock.connect(remote_addr).await.unwrap();
|
udp_sock.connect(remote_addr).await.unwrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
Reference in New Issue
Block a user