net: update smoltcp

This commit is contained in:
Dario Nieuwenhuis 2022-12-07 00:28:38 +01:00
parent 02abe00439
commit f7fe0c1441
4 changed files with 17 additions and 25 deletions

View File

@ -57,7 +57,7 @@ embedded-nal-async = { version = "0.3.0", optional = true }
[dependencies.smoltcp] [dependencies.smoltcp]
version = "0.8.0" version = "0.8.0"
git = "https://github.com/smoltcp-rs/smoltcp" git = "https://github.com/smoltcp-rs/smoltcp"
rev = "ed0cf16750a42f30e31fcaf5347915592924b1e3" rev = "b7a7c4b1c56e8d4c2524c1e3a056c745a13cc09f"
default-features = false default-features = false
features = [ features = [
"proto-ipv4", "proto-ipv4",

View File

@ -12,8 +12,6 @@ pub enum LinkState {
Up, Up,
} }
// 'static required due to the "fake GAT" in smoltcp::phy::Device.
// https://github.com/smoltcp-rs/smoltcp/pull/572
pub trait Device { pub trait Device {
fn is_transmit_ready(&mut self) -> bool; fn is_transmit_ready(&mut self) -> bool;
fn transmit(&mut self, pkt: PacketBuf); fn transmit(&mut self, pkt: PacketBuf);
@ -25,7 +23,7 @@ pub trait Device {
fn ethernet_address(&self) -> [u8; 6]; fn ethernet_address(&self) -> [u8; 6];
} }
impl<T: ?Sized + Device> Device for &'static mut T { impl<T: ?Sized + Device> Device for &mut T {
fn is_transmit_ready(&mut self) -> bool { fn is_transmit_ready(&mut self) -> bool {
T::is_transmit_ready(self) T::is_transmit_ready(self)
} }
@ -63,11 +61,11 @@ impl<D: Device> DeviceAdapter<D> {
} }
} }
impl<'a, D: Device + 'static> SmolDevice<'a> for DeviceAdapter<D> { impl<D: Device> SmolDevice for DeviceAdapter<D> {
type RxToken = RxToken; type RxToken<'a> = RxToken where Self: 'a;
type TxToken = TxToken<'a, D>; 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 tx_pkt = PacketBox::new(Packet::new())?;
let rx_pkt = self.device.receive()?; let rx_pkt = self.device.receive()?;
let rx_token = RxToken { pkt: rx_pkt }; let rx_token = RxToken { pkt: rx_pkt };
@ -80,7 +78,7 @@ impl<'a, D: Device + 'static> SmolDevice<'a> for DeviceAdapter<D> {
} }
/// Construct a transmit token. /// Construct a transmit token.
fn transmit(&'a mut self) -> Option<Self::TxToken> { fn transmit(&mut self) -> Option<Self::TxToken<'_>> {
if !self.device.is_transmit_ready() { if !self.device.is_transmit_ready() {
return None; return None;
} }

View File

@ -266,21 +266,12 @@ impl<D: Device + 'static> Inner<D> {
None => {} None => {}
Some(dhcpv4::Event::Deconfigured) => self.unapply_config(s), Some(dhcpv4::Event::Deconfigured) => self.unapply_config(s),
Some(dhcpv4::Event::Configured(config)) => { Some(dhcpv4::Event::Configured(config)) => {
let mut dns_servers = Vec::new(); let config = Config {
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, address: config.address,
gateway: config.router, gateway: config.router,
dns_servers, dns_servers: config.dns_servers,
}, };
) self.apply_config(s, config)
} }
} }
} else if old_link_up { } else if old_link_up {

View File

@ -94,7 +94,10 @@ impl<'a> TcpSocket<'a> {
{ {
let local_port = self.io.stack.borrow_mut().get_local_port(); 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(()) => {} Ok(()) => {}
Err(tcp::ConnectError::InvalidState) => return Err(ConnectError::InvalidState), Err(tcp::ConnectError::InvalidState) => return Err(ConnectError::InvalidState),
Err(tcp::ConnectError::Unaddressable) => return Err(ConnectError::NoRoute), Err(tcp::ConnectError::Unaddressable) => return Err(ConnectError::NoRoute),