From e0ced3d04e3356d5158473c80e5e5039b63e6702 Mon Sep 17 00:00:00 2001 From: Jan Willamowius Date: Tue, 26 Dec 2023 23:42:33 +0100 Subject: [PATCH] auto-detect public IP with ExternalIP=STUN and STUNServer=stun.example.com --- Toolkit.cxx | 18 ++++++++++++++++++ changes.txt | 1 + docs/manual/mainconfig.sgml | 9 +++++++++ gk.cxx | 1 + 4 files changed, 29 insertions(+) diff --git a/Toolkit.cxx b/Toolkit.cxx index 5778d52a..457f5b08 100644 --- a/Toolkit.cxx +++ b/Toolkit.cxx @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -3909,6 +3910,23 @@ PString Toolkit::GetExternalIP() const m_Config->SetString("ExternalIP", ext); } #endif // P_HTTP + if (ext == "STUN") { + PString m_stunConfig = m_Config->GetString("STUNServer", "stun.ekiga.net"); + PStringArray ip_parts = SplitIPAndPort(m_stunConfig, 3478); + PIPSocket::Address m_stunIP; + PIPSocket::GetHostAddress(ip_parts[0], m_stunIP); + WORD m_stunPort = (WORD)(ip_parts[1].AsUnsigned()); + PSTUNClient m_stunServer(m_stunIP, m_stunPort); + PIPSocket::Address extIP; + if (m_stunServer.GetExternalAddress(extIP)) { + ext = ::AsString(extIP); + } else { + ext = ""; + PTRACE(1, "STUN\tExternal IP can't be detected. Did you set STUNServer= correctly ?"); + } + PTRACE(2, "STUN\tSetting ExternalIP to " << ext); + m_Config->SetString("ExternalIP", ext); + } return ext; } diff --git a/changes.txt b/changes.txt index abafa3a7..cd63677c 100644 --- a/changes.txt +++ b/changes.txt @@ -1,5 +1,6 @@ Changes from 5.11 to 5.12 ========================= +- auto-detect public IP with ExternalIP=STUN and STUNServer=stun.example.com - compiler support for VS2022 - new database driver for Oracle and new timestamp format 'Oracle' - new switch [EP::xxx] ForceDirectMode=1 to handle all calls from this endpoint in direct mode diff --git a/docs/manual/mainconfig.sgml b/docs/manual/mainconfig.sgml index d9de61ee..aa32be2e 100644 --- a/docs/manual/mainconfig.sgml +++ b/docs/manual/mainconfig.sgml @@ -551,6 +551,10 @@ resolved when needed. If you set this switch to "AWSPublicIP", GnuGk will fetch the public / elastic IP from AWS meta data. Same with "GooglePublicIP", "AzurePublicIP" and "AlibabaPublicIP" for Google Cloud, Azure and Alibaba Cloud. +If you set this switch to "STUN", GnuGk will try to detect the public IP using a STUN server. +Use this for deployments in the Oracle Cloud or other cloud environments that don't provice +the external IP in the metadata. use the STUNServer= switch to set the STUN server to use. + Default:

@@ -560,6 +564,11 @@ messages to maintain your DDNS name lease. You must also configure the ExternalIP setting with a DNS address maintained by a DDNS service such as www.dyndns.com or www.no-ip.com. + +Default: stun.ekiga.net +

+Configures the STUN server to be used when setting ExternalIP=STUN. + Default: N/A

diff --git a/gk.cxx b/gk.cxx index 487bd3ac..56b5d50d 100644 --- a/gk.cxx +++ b/gk.cxx @@ -283,6 +283,7 @@ const char * KnownConfigEntries[][2] = { { "Gatekeeper::Main", "StatusEventBacklogRegex" }, { "Gatekeeper::Main", "StatusPort" }, { "Gatekeeper::Main", "StatusTraceLevel" }, + { "Gatekeeper::Main", "STUNServer" }, { "Gatekeeper::Main", "TimeToLive" }, { "Gatekeeper::Main", "TimestampFormat" }, { "Gatekeeper::Main", "TotalBandwidth" },