From aeeca0d7d100436272bb578d693a10cd4064fce2 Mon Sep 17 00:00:00 2001 From: nsgundy Date: Fri, 19 May 2023 15:21:20 +0000 Subject: Fix ip4 mapped ip6 addresses not considered to be part of network --- src/rendezvous_server.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/rendezvous_server.rs b/src/rendezvous_server.rs index 88cd6cb..5aba4d4 100644 --- a/src/rendezvous_server.rs +++ b/src/rendezvous_server.rs @@ -1188,8 +1188,16 @@ impl RendezvousServer { #[inline] fn is_lan(&self, addr: SocketAddr) -> bool { if let Some(network) = &self.inner.mask { - if let SocketAddr::V4(addr) = addr { - return network.contains(*addr.ip()); + match addr { + SocketAddr::V4(v4_socket_addr) => { + return network.contains(*v4_socket_addr.ip()); + } + + SocketAddr::V6(v6_socket_addr) => { + if let Some(v4_addr) = v6_socket_addr.ip().to_ipv4_mapped() { + return network.contains(v4_addr); + } + } } } false -- cgit v1.2.3 From 85a20769fb9754edeeb440191f129b860add5539 Mon Sep 17 00:00:00 2001 From: nsgundy Date: Fri, 19 May 2023 15:21:59 +0000 Subject: Consider peers to be on same intranet if is_lan() returns true for both --- src/rendezvous_server.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/rendezvous_server.rs b/src/rendezvous_server.rs index 5aba4d4..931b1df 100644 --- a/src/rendezvous_server.rs +++ b/src/rendezvous_server.rs @@ -706,17 +706,14 @@ impl RendezvousServer { } ph.nat_type = NatType::SYMMETRIC.into(); // will force relay } - let same_intranet = !ws - && match peer_addr { - SocketAddr::V4(a) => match addr { - SocketAddr::V4(b) => a.ip() == b.ip(), + let same_intranet: bool = !ws + && (peer_is_lan && is_lan || { + match (peer_addr, addr) { + (SocketAddr::V4(a), SocketAddr::V4(b)) => a.ip() == b.ip(), + (SocketAddr::V6(a), SocketAddr::V6(b)) => a.ip() == b.ip(), _ => false, - }, - SocketAddr::V6(a) => match addr { - SocketAddr::V6(b) => a.ip() == b.ip(), - _ => false, - }, - }; + } + }); let socket_addr = AddrMangle::encode(addr).into(); if same_intranet { log::debug!( -- cgit v1.2.3