Skip to content

Commit

Permalink
auto-detect public IP with ExternalIP=STUN and STUNServer=stun.exampl…
Browse files Browse the repository at this point in the history
…e.com
  • Loading branch information
willamowius committed Dec 26, 2023
1 parent 3af9b5c commit e0ced3d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Toolkit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <ptclib/pdns.h>
#include <ptclib/cypher.h>
#include <ptclib/http.h>
#include <ptclib/pstun.h>
#include <h323pdu.h>
#include <map>
#include <vector>
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions docs/manual/mainconfig.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<item><tt/ExternalIsDynamic=1/<newline>
Default: <tt/0/<newline>
<p>
Expand All @@ -560,6 +564,11 @@ messages to maintain your DDNS name lease. You must also configure the
<tt>ExternalIP</tt> setting with a DNS address maintained by a DDNS service
such as www.dyndns.com or www.no-ip.com.

<item><tt/STUNServer=stun.example.com/<newline>
Default: <tt>stun.ekiga.net</tt><newline>
<p>
Configures the STUN server to be used when setting ExternalIP=STUN.

<item><tt/DefaultDomain=gnugk.org,gnugk.de/<newline>
Default: <tt>N/A</tt><newline>
<p>
Expand Down
1 change: 1 addition & 0 deletions gk.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down

0 comments on commit e0ced3d

Please sign in to comment.