Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
inetic committed Oct 21, 2024
2 parents b38d8e5 + 06324c9 commit 84d31a7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion net/src/stun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,22 @@ impl<T: DatagramSocket> StunClient<T> {
let mapped_addr_1 = get_xor_mapped_address(&response)?;
let other_addr = get_other_address(&response)?;

if other_addr == local_addr {
if mapped_addr_1 == local_addr {
Ok(NatBehavior::EndpointIndependent)
} else {
// RFC 5780, section 7.4, https://datatracker.ietf.org/doc/html/rfc5780#section-7.4
// OTHER-ADDRESS MUST NOT be inserted into a Binding Response unless the
// server has a second IP address.
//
// But some servers do respond with the alternate IP address same as their own. In
// those cases the below mapped_addr_2 would always be equal to mapped_addr_1 and we'd
// return Ok(NatBehavior::EndpointIndependent) regardless of what the actual NAT
// mapping is.

if other_addr.ip() == server_addr.ip() {
return Err(io::Error::new(io::ErrorKind::Other, "Faulty STUN server"));
}

// test II
let request = make_request(BINDING);
let dst_addr = SocketAddr::new(other_addr.ip(), server_addr.port());
Expand Down

0 comments on commit 84d31a7

Please sign in to comment.