From 4e2863294d2a994d34eb03fde5ec9a62f8a567fd Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 2 Mar 2018 22:38:04 +0800 Subject: [PATCH] Use stun servers that return XOR mapped address --- src/config/user_config.hpp | 26 ++++++-------------------- src/network/stk_host.cpp | 31 ++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index 1b5bbbb7e..cb51eadcf 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -719,31 +719,17 @@ namespace UserConfigParams PARAM_PREFIX StringListUserConfigParam m_stun_servers PARAM_DEFAULT( StringListUserConfigParam("Stun_servers", "The stun servers" " that will be used to know the public address.", - 24, - "provserver.televolution.net", - "sip1.lakedestiny.cordiaip.com", - "stun1.voiceeclipse.net", - "stun01.sipphone.com", + 10, + "stun.cope.es", + "stun.12connect.com", "stun.callwithus.com", "stun.counterpath.net", - "stun.endigovoip.com", "stun.ekiga.net", - "stun.ideasip.com", - "stun.internetcalls.com", - "stun.ipns.com", - "stun.noc.ams-ix.net", - "stun.phonepower.com", - "stun.phoneserve.com", - "stun.rnktel.com", - "stun.softjoys.com", - "stunserver.org", - "stun.sipgate.net", + "stun.schlund.de", "stun.stunprotocol.org", "stun.voip.aebc.com", - "stun.voipbuster.com", - "stun.voxalot.com", - "stun.voxgratia.org", - "stun.xten.com") ); + "numb.viagenie.ca", + "stun.ivao.aero") ); // ---- Gamemode setup PARAM_PREFIX IntToIntUserConfigParam m_num_karts_per_gamemode diff --git a/src/network/stk_host.cpp b/src/network/stk_host.cpp index 44de7cab8..4fe1e25cb 100644 --- a/src/network/stk_host.cpp +++ b/src/network/stk_host.cpp @@ -506,12 +506,11 @@ void STKHost::setPublicAddress() // The stun message is valid, so we parse it now: // Those are the port and the address to be detected - bool found = false; + TransportAddress non_xor_addr, xor_addr; while (true) { if (response.size() < 4) { - Log::error("STKHost", "STUN response is invalid."); break; } unsigned type = response.getUInt16(); @@ -558,11 +557,14 @@ void STKHost::setPublicAddress() // Obfuscation is described in Section 15.2 of RFC 5389. port ^= magic_cookie >> 16; ip ^= magic_cookie; + xor_addr.setPort(port); + xor_addr.setIP(ip); + } + else + { + non_xor_addr.setPort(port); + non_xor_addr.setIP(ip); } - m_public_address.setPort(port); - m_public_address.setIP(ip); - found = true; - break; } // type == mapped_address || type == xor_mapped_address else { @@ -573,8 +575,23 @@ void STKHost::setPublicAddress() } } // while true // Found public address and port - if (found) + if (!xor_addr.isUnset() || !non_xor_addr.isUnset()) + { + // Use XOR mapped address when possible to avoid translation of + // the packet content by application layer gateways (ALGs) that + // perform deep packet inspection in an attempt to perform + // alternate NAT traversal methods. + if (!xor_addr.isUnset()) + { + m_public_address.copy(xor_addr); + } + else + { + Log::warn("STKHost", "Only non xor-mapped address returned."); + m_public_address.copy(non_xor_addr); + } untried_server.clear(); + } } } // setPublicAddress