diff --git a/src/iface/interface/mod.rs b/src/iface/interface/mod.rs index 00f46d07d..59c06c72e 100644 --- a/src/iface/interface/mod.rs +++ b/src/iface/interface/mod.rs @@ -513,6 +513,7 @@ impl Interface { let mut processed_any = false; while let Some((rx_token, tx_token)) = device.receive(self.inner.now) { + rx_token.preprocess(sockets); let rx_meta = rx_token.meta(); rx_token.consume(|frame| { if frame.is_empty() { diff --git a/src/iface/interface/udp.rs b/src/iface/interface/udp.rs index 3c9b0949d..aed2a7786 100644 --- a/src/iface/interface/udp.rs +++ b/src/iface/interface/udp.rs @@ -25,12 +25,18 @@ impl InterfaceInner { )); #[cfg(feature = "socket-udp")] - for udp_socket in sockets + { + let mut is_received = false; + for udp_socket in sockets .items_mut() .filter_map(|i| UdpSocket::downcast_mut(&mut i.socket)) - { - if udp_socket.accepts(self, &ip_repr, &udp_repr) { - udp_socket.process(self, meta, &ip_repr, &udp_repr, udp_packet.payload()); + { + if udp_socket.accepts(self, &ip_repr, &udp_repr) { + udp_socket.process(self, meta, &ip_repr, &udp_repr, udp_packet.payload()); + is_received = true; + } + } + if is_received { return None; } } diff --git a/src/phy/mod.rs b/src/phy/mod.rs index c3845d980..6a41ea073 100644 --- a/src/phy/mod.rs +++ b/src/phy/mod.rs @@ -88,6 +88,7 @@ impl<'a> phy::TxToken for StmPhyTxToken<'a> { "## )] +use crate::iface::SocketSet; use crate::time::Instant; #[cfg(all( @@ -378,6 +379,11 @@ pub trait RxToken { fn meta(&self) -> PacketMeta { PacketMeta::default() } + + /// Preprocess the incomming packet before it is passed to the stack. + /// + /// e.g., prepare TCP sockets when received a SYN packet. + fn preprocess(&self, _sockets: &mut SocketSet<'_>) {} } /// A token to transmit a single network packet.