From f7fe0c1441843b04fa17ba0fe94f8c8d4f851882 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 7 Dec 2022 00:28:38 +0100 Subject: [PATCH] net: update smoltcp --- embassy-net/Cargo.toml | 2 +- embassy-net/src/device.rs | 14 ++++++-------- embassy-net/src/stack.rs | 21 ++++++--------------- embassy-net/src/tcp.rs | 5 ++++- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index 86d4aa10..ac338843 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml @@ -57,7 +57,7 @@ embedded-nal-async = { version = "0.3.0", optional = true } [dependencies.smoltcp] version = "0.8.0" git = "https://github.com/smoltcp-rs/smoltcp" -rev = "ed0cf16750a42f30e31fcaf5347915592924b1e3" +rev = "b7a7c4b1c56e8d4c2524c1e3a056c745a13cc09f" default-features = false features = [ "proto-ipv4", diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index c183bd58..4bdfd772 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs @@ -12,8 +12,6 @@ pub enum LinkState { Up, } -// 'static required due to the "fake GAT" in smoltcp::phy::Device. -// https://github.com/smoltcp-rs/smoltcp/pull/572 pub trait Device { fn is_transmit_ready(&mut self) -> bool; fn transmit(&mut self, pkt: PacketBuf); @@ -25,7 +23,7 @@ pub trait Device { fn ethernet_address(&self) -> [u8; 6]; } -impl Device for &'static mut T { +impl Device for &mut T { fn is_transmit_ready(&mut self) -> bool { T::is_transmit_ready(self) } @@ -63,11 +61,11 @@ impl DeviceAdapter { } } -impl<'a, D: Device + 'static> SmolDevice<'a> for DeviceAdapter { - type RxToken = RxToken; - type TxToken = TxToken<'a, D>; +impl SmolDevice for DeviceAdapter { + type RxToken<'a> = RxToken where Self: 'a; + type TxToken<'a> = TxToken<'a, D> where Self: 'a; - fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> { + fn receive(&mut self) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { let tx_pkt = PacketBox::new(Packet::new())?; let rx_pkt = self.device.receive()?; let rx_token = RxToken { pkt: rx_pkt }; @@ -80,7 +78,7 @@ impl<'a, D: Device + 'static> SmolDevice<'a> for DeviceAdapter { } /// Construct a transmit token. - fn transmit(&'a mut self) -> Option { + fn transmit(&mut self) -> Option> { if !self.device.is_transmit_ready() { return None; } diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs index 63108740..5c4fb044 100644 --- a/embassy-net/src/stack.rs +++ b/embassy-net/src/stack.rs @@ -266,21 +266,12 @@ impl Inner { None => {} Some(dhcpv4::Event::Deconfigured) => self.unapply_config(s), Some(dhcpv4::Event::Configured(config)) => { - let mut dns_servers = Vec::new(); - for s in &config.dns_servers { - if let Some(addr) = s { - dns_servers.push(addr.clone()).unwrap(); - } - } - - self.apply_config( - s, - Config { - address: config.address, - gateway: config.router, - dns_servers, - }, - ) + let config = Config { + address: config.address, + gateway: config.router, + dns_servers: config.dns_servers, + }; + self.apply_config(s, config) } } } else if old_link_up { diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs index 60386535..73cf2d4e 100644 --- a/embassy-net/src/tcp.rs +++ b/embassy-net/src/tcp.rs @@ -94,7 +94,10 @@ impl<'a> TcpSocket<'a> { { let local_port = self.io.stack.borrow_mut().get_local_port(); - match { self.io.with_mut(|s, i| s.connect(i, remote_endpoint, local_port)) } { + match { + self.io + .with_mut(|s, i| s.connect(i.context(), remote_endpoint, local_port)) + } { Ok(()) => {} Err(tcp::ConnectError::InvalidState) => return Err(ConnectError::InvalidState), Err(tcp::ConnectError::Unaddressable) => return Err(ConnectError::NoRoute),