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: construct underlay for hosts in same IA #85

Merged
merged 1 commit into from
Dec 6, 2023
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
3 changes: 3 additions & 0 deletions crates/scion/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ use tokio::{
net::UnixStream,
};

/// Underlay port on which the dispatcher receives packets from the network.
pub const UNDERLAY_PORT: u16 = 30041;

// Recv buffer to 1 MiB
// TODO(jsmith): Allow the user to set this
const RECV_BUFFER_LEN: usize = 1024 * 1024; // 1 MiB;
Expand Down
16 changes: 14 additions & 2 deletions crates/scion/src/udp_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub enum SendError {
NoRemoteAddress,
#[error("path is not set")]
NoPath,
#[error("no underlay next hop provided by path")]
NoUnderlayNextHop,
}

impl From<dispatcher::SendError> for SendError {
Expand Down Expand Up @@ -225,7 +227,17 @@ impl UdpSocketInner {
}
}

let relay = path.underlay_next_hop;
let relay = if path.underlay_next_hop.is_some() {
path.underlay_next_hop
} else if endhosts.source.isd_asn() == endhosts.destination.isd_asn() {
endhosts.destination.local_address().map(|mut socket_addr| {
socket_addr.set_port(dispatcher::UNDERLAY_PORT);
socket_addr
})
} else {
return Err(SendError::NoUnderlayNextHop);
};

let packet = ScionPacketUdp::new(endhosts, path, payload)?;

self.state
Expand Down Expand Up @@ -297,7 +309,7 @@ impl UdpSocketInner {

let payload_len = udp_datagram.payload.len();
let copy_length = cmp::min(payload_len, buf.len());
buf.copy_from_slice(&udp_datagram.payload[..copy_length]);
buf[..copy_length].copy_from_slice(&udp_datagram.payload[..copy_length]);

Some((payload_len, source, path))
}
Expand Down