chan_sip: Resolve externhost not to IPv6; instead go for IPv4.

For the channel driver chan_sip, you specify externhost=example.com in sip.conf
when your Asterisk is behind a NAT and your IP address is assigned dynamically.
Or stated differently: You do not have a static IP address to use "externaddr"
directly. This NAT support is quite handy but just about IPv4. Previously,
Asterisk resolved "externhost" to any IP version. When the first DNS answer
resolved to an IPv6, Asterisk sent an IPv6 in SIP/SDP for origin (o=) and
connection (c=). This happened in outgoing SIP-REGISTER and while answering
SIP-INVITE. If the remote peer is IPv4-only, it might not handle o=/c= with an
IPv6. This change makes sure, no IPv6 is resolved anymore for "externhost".

ASTERISK-18232 #close
Reported by: Jacek Kowalski
Tested by: Alexander Traud
patches:
 changes.patch submitted by Alessandro Crespi

Change-Id: If68eedbeff65bd1c1d8a9ed921c02ba464b32dac
changes/67/3967/1
Alexander Traud 9 years ago
parent d4422a2253
commit 175975e994

@ -3843,7 +3843,7 @@ static void ast_sip_ouraddrfor(const struct ast_sockaddr *them, struct ast_socka
(!sip_cfg.matchexternaddrlocally || !ast_apply_ha(localaddr, us)) ) { (!sip_cfg.matchexternaddrlocally || !ast_apply_ha(localaddr, us)) ) {
/* if we used externhost, 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 (externexpire && time(NULL) >= externexpire) {
if (ast_sockaddr_resolve_first(&externaddr, externhost, 0)) { if (ast_sockaddr_resolve_first_af(&externaddr, externhost, 0, AST_AF_INET)) {
ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost); ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost);
} }
externexpire = time(NULL) + externrefresh; externexpire = time(NULL) + externrefresh;
@ -32565,7 +32565,7 @@ static int reload_config(enum channelreloadreason reason)
externexpire = 0; externexpire = 0;
} else if (!strcasecmp(v->name, "externhost")) { } else if (!strcasecmp(v->name, "externhost")) {
ast_copy_string(externhost, v->value, sizeof(externhost)); ast_copy_string(externhost, v->value, sizeof(externhost));
if (ast_sockaddr_resolve_first(&externaddr, externhost, 0)) { if (ast_sockaddr_resolve_first_af(&externaddr, externhost, 0, AST_AF_INET)) {
ast_log(LOG_WARNING, "Invalid address for externhost keyword: %s\n", externhost); ast_log(LOG_WARNING, "Invalid address for externhost keyword: %s\n", externhost);
} }
externexpire = time(NULL); externexpire = time(NULL);

Loading…
Cancel
Save