Merge pull request #65 from aramperes/smoltcp-0.12

This commit is contained in:
Aram 🍐 2024-12-01 15:31:03 -05:00 committed by GitHub
commit c4c52babae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 297 additions and 338 deletions

View file

@ -10,7 +10,7 @@ jobs:
matrix:
rust:
- stable
- 1.78.0
- 1.80.0
steps:
- name: Checkout sources
uses: actions/checkout@v2
@ -39,7 +39,7 @@ jobs:
matrix:
rust:
- stable
- 1.78.0
- 1.80.0
steps:
- name: Checkout sources
uses: actions/checkout@v2

View file

@ -75,12 +75,16 @@ jobs:
RUST_BACKTRACE: 1
strategy:
matrix:
build: [ linux-amd64, macos-aarch64, windows ]
build: [ linux-amd64, linux-aarch64, macos-aarch64, windows ]
include:
- build: linux-amd64
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-musl
- build: linux-aarch64
os: ubuntu-latest
rust: stable
target: aarch64-unknown-linux-musl
- build: macos-aarch64
os: macos-latest
rust: stable

601
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -20,7 +20,7 @@ rand = "0.8"
nom = "7"
async-trait = "0.1"
priority-queue = "1.3"
smoltcp = { version = "0.11", default-features = false, features = [
smoltcp = { version = "0.12", default-features = false, features = [
"std",
"log",
"medium-ip",

View file

@ -21,7 +21,7 @@ For example,
## Download
onetun is available to install from [crates.io](https://crates.io/crates/onetun) with Rust ≥1.78.0:
onetun is available to install from [crates.io](https://crates.io/crates/onetun) with Rust ≥1.80.0:
```shell
cargo install onetun
@ -37,7 +37,7 @@ docker run --rm --name onetun --user 1000 -p 8080:8080 aramperes/onetun \
0.0.0.0:8080:192.168.4.2:8080 [...options...]
```
You can also build onetun locally, using Rust ≥1.78.0:
You can also build onetun locally, using Rust ≥1.80.0:
```shell
git clone https://github.com/aramperes/onetun && cd onetun

View file

@ -109,11 +109,11 @@ pub struct RxToken {
}
impl smoltcp::phy::RxToken for RxToken {
fn consume<R, F>(mut self, f: F) -> R
fn consume<R, F>(self, f: F) -> R
where
F: FnOnce(&mut [u8]) -> R,
F: FnOnce(&[u8]) -> R,
{
f(&mut self.buffer)
f(&self.buffer)
}
}

View file

@ -6,6 +6,7 @@ use crate::Bus;
use anyhow::Context;
use async_trait::async_trait;
use bytes::Bytes;
use smoltcp::iface::PollResult;
use smoltcp::{
iface::{Config, Interface, SocketHandle, SocketSet},
socket::tcp,
@ -141,7 +142,7 @@ impl VirtualInterfacePoll for TcpVirtualInterface {
}
});
if iface.poll(loop_start, &mut device, &mut self.sockets) {
if iface.poll(loop_start, &mut device, &mut self.sockets) == PollResult::SocketStateChanged {
log::trace!("TCP virtual interface polled some packets to be processed");
}

View file

@ -6,6 +6,7 @@ use crate::{Bus, PortProtocol};
use anyhow::Context;
use async_trait::async_trait;
use bytes::Bytes;
use smoltcp::iface::PollResult;
use smoltcp::{
iface::{Config, Interface, SocketHandle, SocketSet},
socket::udp::{self, UdpMetadata},
@ -140,7 +141,7 @@ impl VirtualInterfacePoll for UdpVirtualInterface {
} => {
let loop_start = smoltcp::time::Instant::now();
if iface.poll(loop_start, &mut device, &mut self.sockets) {
if iface.poll(loop_start, &mut device, &mut self.sockets) == PollResult::SocketStateChanged {
log::trace!("UDP virtual interface polled some packets to be processed");
}

View file

@ -1,4 +1,4 @@
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
use std::net::{IpAddr, SocketAddr};
use std::time::Duration;
use crate::Bus;
@ -253,7 +253,7 @@ impl WireGuardTunnel {
Ok(IpVersion::Ipv4) => Ipv4Packet::new_checked(&packet)
.ok()
// Only care if the packet is destined for this tunnel
.filter(|packet| Ipv4Addr::from(packet.dst_addr()) == self.source_peer_ip)
.filter(|packet| packet.dst_addr() == self.source_peer_ip)
.and_then(|packet| match packet.next_header() {
IpProtocol::Tcp => Some(PortProtocol::Tcp),
IpProtocol::Udp => Some(PortProtocol::Udp),
@ -263,7 +263,7 @@ impl WireGuardTunnel {
Ok(IpVersion::Ipv6) => Ipv6Packet::new_checked(&packet)
.ok()
// Only care if the packet is destined for this tunnel
.filter(|packet| Ipv6Addr::from(packet.dst_addr()) == self.source_peer_ip)
.filter(|packet| packet.dst_addr() == self.source_peer_ip)
.and_then(|packet| match packet.next_header() {
IpProtocol::Tcp => Some(PortProtocol::Tcp),
IpProtocol::Udp => Some(PortProtocol::Udp),