From c86784ed70f158f310480eb1b1a71c0a09ab8d5d Mon Sep 17 00:00:00 2001 From: Aram Peres <6775216+aramperes@users.noreply.github.com> Date: Sun, 1 Dec 2024 11:33:53 -0500 Subject: [PATCH 1/3] log a better error regarding smoltcp max interface limit --- src/virtual_iface/tcp.rs | 4 +++- src/virtual_iface/udp.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/virtual_iface/tcp.rs b/src/virtual_iface/tcp.rs index 7522d7e..39d45ac 100644 --- a/src/virtual_iface/tcp.rs +++ b/src/virtual_iface/tcp.rs @@ -94,7 +94,9 @@ impl VirtualInterfacePoll for TcpVirtualInterface { let mut iface = Interface::new(config, &mut device, Instant::now()); iface.update_ip_addrs(|ip_addrs| { addresses.into_iter().for_each(|addr| { - ip_addrs.push(addr).unwrap(); + ip_addrs + .push(addr) + .expect("maximum number of IPs in TCP interface reached"); }); }); diff --git a/src/virtual_iface/udp.rs b/src/virtual_iface/udp.rs index 3ca4c2d..c72c51c 100644 --- a/src/virtual_iface/udp.rs +++ b/src/virtual_iface/udp.rs @@ -106,7 +106,9 @@ impl VirtualInterfacePoll for UdpVirtualInterface { let mut iface = Interface::new(config, &mut device, Instant::now()); iface.update_ip_addrs(|ip_addrs| { addresses.into_iter().for_each(|addr| { - ip_addrs.push(addr).unwrap(); + ip_addrs + .push(addr) + .expect("maximum number of IPs in UDP interface reached"); }); }); From 9ccd2e19f6f680a77de3e56a3e4549bf8cdc820f Mon Sep 17 00:00:00 2001 From: Aram Peres <6775216+aramperes@users.noreply.github.com> Date: Sun, 1 Dec 2024 12:03:41 -0500 Subject: [PATCH 2/3] increase default smoltcp interface limit and add to README --- .cargo/config.toml | 4 ++++ README.md | 8 ++++++++ 2 files changed, 12 insertions(+) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..408c0f3 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,4 @@ +[env] +# Each interface needs 1 IP allocated to the WireGuard peer IP. +# "8" = 7 tunnels per protocol. +SMOLTCP_IFACE_MAX_ADDR_COUNT = "8" diff --git a/README.md b/README.md index 60b4c15..413e6d0 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,14 @@ INFO onetun::tunnel > Tunneling TCP [127.0.0.1:8081]->[192.168.4.4:8081] (via [ ... would open TCP ports 8080 and 8081 locally, which forward to their respective ports on the different peers. +#### Maximum number of tunnels + +`smoltcp` imposes a compile-time limit on the number of IP addresses assigned to an interface. **onetun** increases +the default value to support most use-cases. In effect, the default limit on the number of **onetun** peers +is **7 per protocol** (TCP and UDP). + +Should you need more unique IP addresses to forward ports to, you can increase the limit in `.cargo/config.toml` and recompile **onetun**. + ### UDP Support **onetun** supports UDP forwarding. You can add `:UDP` at the end of the port-forward configuration, or `UDP,TCP` to support From 88ce1245444334898f8351e7c9e710308a0be803 Mon Sep 17 00:00:00 2001 From: Aram Peres <6775216+aramperes@users.noreply.github.com> Date: Sun, 1 Dec 2024 12:03:51 -0500 Subject: [PATCH 3/3] formatting --- src/virtual_device.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/virtual_device.rs b/src/virtual_device.rs index 7af4d27..febe2ac 100644 --- a/src/virtual_device.rs +++ b/src/virtual_device.rs @@ -55,8 +55,14 @@ impl VirtualIpDevice { } impl smoltcp::phy::Device for VirtualIpDevice { - type RxToken<'a> = RxToken where Self: 'a; - type TxToken<'a> = TxToken where Self: 'a; + type RxToken<'a> + = RxToken + where + Self: 'a; + type TxToken<'a> + = TxToken + where + Self: 'a; fn receive(&mut self, _timestamp: Instant) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { let next = {