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

Fix mismatching src ip address in TCP socket transmissions #970

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
19 changes: 17 additions & 2 deletions src/iface/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ impl Interface {

enum EgressError {
Exhausted,
MismatchedSrcIp,
Dispatch,
}

Expand All @@ -589,6 +590,12 @@ impl Interface {
let mut neighbor_addr = None;
let mut respond = |inner: &mut InterfaceInner, meta: PacketMeta, response: Packet| {
neighbor_addr = Some(response.ip_repr().dst_addr());

if !inner.has_ip_addr(response.ip_repr().src_addr()) {
net_debug!("failed to transmit IP: mismatched src addr");
return Err(EgressError::MismatchedSrcIp);
}

let t = device.transmit(inner.now).ok_or_else(|| {
net_debug!("failed to transmit IP: device exhausted");
EgressError::Exhausted
Expand Down Expand Up @@ -638,13 +645,20 @@ impl Interface {
})
}
#[cfg(feature = "socket-tcp")]
Socket::Tcp(socket) => socket.dispatch(&mut self.inner, |inner, (ip, tcp)| {
Socket::Tcp(socket) => match socket.dispatch(&mut self.inner, |inner, (ip, tcp)| {
respond(
inner,
PacketMeta::default(),
Packet::new(ip, IpPayload::Tcp(tcp)),
)
}),
}) {
Err(EgressError::MismatchedSrcIp) => {
// FIXME: Should this be `close()` or `abort()`?
socket.reset();
Err(EgressError::MismatchedSrcIp)
}
r => r,
},
#[cfg(feature = "socket-dhcpv4")]
Socket::Dhcpv4(socket) => {
socket.dispatch(&mut self.inner, |inner, (ip, udp, dhcp)| {
Expand Down Expand Up @@ -677,6 +691,7 @@ impl Interface {
neighbor_addr.expect("non-IP response packet"),
);
}
Err(EgressError::MismatchedSrcIp) => {},
Ok(()) => {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ impl<'a> Socket<'a> {
self.state
}

fn reset(&mut self) {
pub fn reset(&mut self) {
let rx_cap_log2 =
mem::size_of::<usize>() * 8 - self.rx_buffer.capacity().leading_zeros() as usize;

Expand Down
Loading