Skip to content

Commit

Permalink
chore: udpate to smoltcp 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
aramperes committed Dec 1, 2024
1 parent ca3590a commit 0e93a64
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/virtual_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/virtual_iface/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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");
}

Expand Down
3 changes: 2 additions & 1 deletion src/virtual_iface/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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");
}

Expand Down
6 changes: 3 additions & 3 deletions src/wg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
use std::net::{IpAddr, SocketAddr};
use std::time::Duration;

use crate::Bus;
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down

0 comments on commit 0e93a64

Please sign in to comment.