Skip to content

Commit

Permalink
try to make sure that quic ignores stun and callmemaybe packets
Browse files Browse the repository at this point in the history
  • Loading branch information
Frando committed Oct 6, 2023
1 parent d49c8f3 commit b506be1
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions iroh-net/src/magicsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,12 @@ impl Inner {

if !derp_sent && !udp_sent {
warn!(peer = %public_key.fmt_short(), "failed to send: no UDP or DERP addr");
let err = udp_error.unwrap_or_else(|| io::Error::new(io::ErrorKind::NotConnected, "no UDP or Derp address available for peer"));
let err = udp_error.unwrap_or_else(|| {
io::Error::new(
io::ErrorKind::NotConnected,
"no UDP or Derp address available for peer",
)
});
Poll::Ready(Err(err))
} else {
Poll::Ready(Ok(n))
Expand Down Expand Up @@ -474,8 +479,9 @@ impl Inner {

let mut num_msgs = 0;

for (meta, buf) in metas.into_iter().zip(bufs.iter()).take(msgs) {
for (meta, buf) in metas.into_iter().zip(bufs.iter_mut()).take(msgs) {
let mut start = 0;
let mut outer_is_quic = true;

// find disco and stun packets and forward them to the actor
loop {
Expand All @@ -484,30 +490,41 @@ impl Inner {
break;
}
let packet = &buf[start..end];
let mut is_quic = true;
if stun::is(&packet) {
trace!("UDP recv: stun packet");
let packet = Bytes::copy_from_slice(packet);
self.net_checker.receive_stun_packet(packet, meta.addr);
let packet2 = Bytes::copy_from_slice(packet);
self.net_checker.receive_stun_packet(packet2, meta.addr);
is_quic = false;
} else if let Some((sender, sealed_box)) = disco::source_and_box(&packet) {
// Disco?
trace!("UDP recv: disco packet: {:?}", meta);
self.handle_disco_message(sender, &sealed_box, SendAddr::Udp(meta.addr), None);
is_quic = false;
}
// make quinn ignore the packet
// todo: check with QUIC spec that this is enough
if !is_quic {
buf[start..(start + 8)].fill(0u8);
outer_is_quic = false;
}
start = end;
}

// remap addr
match self
.peer_map
.get_quic_mapped_addr_for_ip_port(&SendAddr::Udp(meta.addr))
{
None => {
warn!(peer=?meta.addr, "no peer_map state found for peer, skipping");
}
Some(quic_mapped_addr) => {
debug!("peer_map state found for {}", meta.addr);
num_msgs += meta.len / meta.stride;
meta.addr = quic_mapped_addr.0;
if outer_is_quic {
// remap addr
match self
.peer_map
.get_quic_mapped_addr_for_ip_port(&SendAddr::Udp(meta.addr))
{
None => {
warn!(peer=?meta.addr, "no peer_map state found for peer, skipping");
}
Some(quic_mapped_addr) => {
debug!("peer_map state found for {}", meta.addr);
num_msgs += meta.len / meta.stride;
meta.addr = quic_mapped_addr.0;
}
}
}
// Normalize local_ip
Expand Down

0 comments on commit b506be1

Please sign in to comment.