#include "asterisk/translate.h"
#include "asterisk/ast_version.h"
#include "asterisk/event.h"
-#include "asterisk/stun.h"
#include "asterisk/cel.h"
#include "asterisk/data.h"
#include "asterisk/aoc.h"
* hostname is stored in externhost, and the hostname->IP mapping
* is refreshed every 'externrefresh' seconds;
*
- * + with "stunaddr = host[:port]" we run queries every externrefresh seconds
- * to the specified server, and store the result in externaddr.
- *
* Other variables (externhost, externexpire, externrefresh) are used
* to support the above functions.
*/
static char externhost[MAXHOSTNAMELEN]; /*!< External host name */
static time_t externexpire; /*!< Expiration counter for re-resolving external host name in dynamic DNS */
static int externrefresh = 10; /*!< Refresh timer for DNS-based external address (dyndns) */
-static struct sockaddr_in stunaddr; /*!< stun server address */
static uint16_t externtcpport; /*!< external tcp port */
static uint16_t externtlsport; /*!< external tls port */
static void ast_sip_ouraddrfor(const struct ast_sockaddr *them, struct ast_sockaddr *us, struct sip_pvt *p)
{
struct ast_sockaddr theirs;
- struct sockaddr_in externaddr_sin;
/* Set want_remap to non-zero if we want to remap 'us' to an externally
* reachable IP address and port. This is done if:
* 1. we have a localaddr list (containing 'internal' addresses marked
* as 'deny', so ast_apply_ha() will return AST_SENSE_DENY on them,
* and AST_SENSE_ALLOW on 'external' ones);
- * 2. either stunaddr or externaddr is set, so we know what to use as the
+ * 2. externaddr is set, so we know what to use as the
* externally visible address;
* 3. the remote address, 'them', is external;
* 4. the address returned by ast_ouraddrfor() is 'internal' (AST_SENSE_DENY
}
} else {
want_remap = localaddr &&
- !(ast_sockaddr_isnull(&externaddr) && stunaddr.sin_addr.s_addr) &&
+ !ast_sockaddr_isnull(&externaddr) &&
ast_apply_ha(localaddr, &theirs) == AST_SENSE_ALLOW ;
}
if (want_remap &&
(!sip_cfg.matchexternaddrlocally || !ast_apply_ha(localaddr, us)) ) {
- /* if we used externhost or stun, see if it is time to refresh the info */
+ /* if we used externhost, see if it is time to refresh the info */
if (externexpire && time(NULL) >= externexpire) {
- if (stunaddr.sin_addr.s_addr) {
- ast_sockaddr_to_sin(&externaddr, &externaddr_sin);
- ast_stun_request(sipsock, &stunaddr, NULL, &externaddr_sin);
- } else {
- if (ast_sockaddr_resolve_first(&externaddr, externhost, 0)) {
- ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost);
- }
- externexpire = time(NULL);
+ if (ast_sockaddr_resolve_first(&externaddr, externhost, 0)) {
+ ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost);
}
externexpire = time(NULL) + externrefresh;
}
break;
}
}
- else {
- ast_log(LOG_WARNING, "stun failed\n");
- }
ast_debug(1, "Target address %s is not local, substituting externaddr\n",
ast_sockaddr_stringify(them));
} else if (p) {
* address and port in the SIP headers without the need for STUN.
* The address part is also reused for the media sessions.
* Note that ast_sip_ouraddrfor() still rewrites p->ourip
- * if you specify externaddr/seternaddr/stunaddr.
+ * if you specify externaddr/seternaddr/.
*/
static attribute_unused void check_via_response(struct sip_pvt *p, struct sip_request *req)
{
msg = "Disabled, no localnet list";
else if (ast_sockaddr_isnull(&externaddr))
msg = "Disabled";
- else if (stunaddr.sin_addr.s_addr != 0)
- msg = "Enabled using STUN";
else if (!ast_strlen_zero(externhost))
msg = "Enabled using externhost";
else
ast_strdupa(ast_sockaddr_stringify_addr(&d->netmask)));
}
}
- ast_cli(a->fd, " STUN server: %s:%d\n", ast_inet_ntoa(stunaddr.sin_addr), ntohs(stunaddr.sin_port));
-
ast_cli(a->fd, "\nGlobal Signalling Settings:\n");
ast_cli(a->fd, "---------------------------\n");
ast_cli(a->fd, " Codecs: ");
int registry_count = 0, peer_count = 0, timerb_set = 0, timert1_set = 0;
int subscribe_network_change = 1;
time_t run_start, run_end;
- struct sockaddr_in externaddr_sin;
int bindport = 0;
run_start = time(0);
/* Reset IP addresses */
ast_sockaddr_parse(&bindaddr, "0.0.0.0:0", 0);
- memset(&stunaddr, 0, sizeof(stunaddr));
memset(&internip, 0, sizeof(internip));
/* Free memory for local network address mask */
}
} else if (!strcasecmp(v->name, "registerattempts")) {
global_regattempts_max = atoi(v->value);
- } else if (!strcasecmp(v->name, "stunaddr")) {
- stunaddr.sin_port = htons(3478);
- if (ast_parse_arg(v->value, PARSE_INADDR, &stunaddr)) {
- ast_log(LOG_WARNING, "Invalid STUN server address: %s\n", v->value);
- }
- externexpire = time(NULL);
} else if (!strcasecmp(v->name, "bindaddr") || !strcasecmp(v->name, "udpbindaddr")) {
if (ast_parse_arg(v->value, PARSE_ADDR, &bindaddr)) {
ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);
}
}
}
- if (stunaddr.sin_addr.s_addr != 0) {
- ast_debug(1, "stun to %s:%d\n",
- ast_inet_ntoa(stunaddr.sin_addr) , ntohs(stunaddr.sin_port));
- ast_sockaddr_to_sin(&externaddr, &externaddr_sin);
- ast_stun_request(sipsock, &stunaddr,
- NULL, &externaddr_sin);
- ast_debug(1, "STUN sees us at %s\n",
- ast_sockaddr_stringify(&externaddr));
- }
ast_mutex_unlock(&netlock);
/* Start TCP server */
; externhost=foo.dyndns.net ; refreshed periodically
; externrefresh=180 ; change the refresh interval
;
-; c. "stunaddr = stun.server[:port]" queries the STUN server specified
-; as an argument to obtain the external address/port.
-; Queries are also sent periodically every "externrefresh" seconds
-; (as a side effect, sending the query also acts as a keepalive for
-; the state entry on the nat box):
-;
-; stunaddr = foo.stun.com:3478
-; externrefresh = 15
-;
-; NOTE: STUN is only implemented for IPv4.
-;
; Note that at the moment all these mechanism work only for the SIP socket.
-; The IP address discovered with externaddr/externhost/STUN is reused for
+; The IP address discovered with externaddr/externhost is reused for
; media sessions as well, but the port numbers are not remapped so you
; may still experience problems.
;
; NOTE 1: in some cases, NAT boxes will use different port numbers in
; the internal<->external mapping. In these cases, the "externaddr" and
-; "externhost" might not help you configure addresses properly, and you
-; really need to use STUN.
+; "externhost" might not help you configure addresses properly.
;
; NOTE 2: when using "externaddr" or "externhost", the address part is
-; also used as the external address for media sessions. Even if you
-; use "stunaddr", STUN queries will be sent only from the SIP port,
-; not from media sockets. Thus, the port information in the SDP may be wrong!
+; also used as the external address for media sessions. Thus, the port
+; information in the SDP may be wrong!
;
; In addition to the above, Asterisk has an additional "nat" parameter to
; address NAT-related issues in incoming SIP or media sessions.