Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SO_REUSEADDR support #1

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/iface/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 10 additions & 4 deletions src/iface/interface/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/phy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ impl<'a> phy::TxToken for StmPhyTxToken<'a> {
"##
)]

use crate::iface::SocketSet;
use crate::time::Instant;

#[cfg(all(
Expand Down Expand Up @@ -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.
Expand Down