Fix parsing of IPv6 address literals in outboundproxy

(closes issue #17757)
Reported by: oej
Patches:
      17757.diff uploaded by sperreault (license 252)
      sip.conf.diff uploaded by sperreault (license 252)
Tested by: oej


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@281687 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
2010-08-11 13:30:59 +00:00
parent 7011a94fc0
commit 5c1c1b35bd
4 changed files with 34 additions and 8 deletions

View File

@@ -661,16 +661,18 @@ int sip_parse_host(char *line, int lineno, char **hostname, int *portnum, enum s
else
line = *hostname;
if ((port = strrchr(line, ':'))) {
*port++ = '\0';
if (ast_sockaddr_split_hostport(line, hostname, &port, 0) == 0) {
ast_log(LOG_WARNING, "Cannot parse host '%s' on line %d of sip.conf.\n",
line, lineno);
return -1;
}
if (port) {
if (!sscanf(port, "%5u", portnum)) {
ast_log(LOG_NOTICE, "'%s' is not a valid port number on line %d of sip.conf. using default.\n", port, lineno);
port = NULL;
}
}
if (!port) {
} else {
if (*transport & SIP_TRANSPORT_TLS) {
*portnum = STANDARD_TLS_PORT;
} else {

View File

@@ -367,6 +367,10 @@ srvlookup=yes ; Enable DNS SRV lookups on outbound calls
;outboundproxy=proxy.provider.domain:8080 ; send outbound signaling to this proxy, not directly to the devices
;outboundproxy=proxy.provider.domain,force ; Send ALL outbound signalling to proxy, ignoring route: headers
;outboundproxy=tls://proxy.provider.domain ; same as '=proxy.provider.domain' except we try to connect with tls
;outboundproxy=192.0.2.1 ; IPv4 address literal (default port is 5060)
;outboundproxy=2001:db8::1 ; IPv6 address literal (default port is 5060)
;outboundproxy=192.168.0.2.1:5062 ; IPv4 address literal with explicit port
;outboundproxy=[2001:db8::1]:5062 ; IPv6 address literal with explicit port
; ; (could also be tcp,udp) - defining transports on the proxy line only
; ; applies for the global proxy, otherwise use the transport= option
;matchexternaddrlocally = yes ; Only substitute the externaddr or externhost setting if it matches

View File

@@ -229,6 +229,26 @@ static inline char *ast_sockaddr_stringify_port(const struct ast_sockaddr *addr)
return ast_sockaddr_stringify_fmt(addr, AST_SOCKADDR_STR_PORT);
}
/*!
* \since 1.8
*
* \brief
* Splits a string into its host and port components
*
* \param str[in] The string to parse. May be modified by writing a NUL at the end of
* the host part.
* \param host[out] Pointer to the host component within \a str.
* \param port[out] Pointer to the port component within \a str.
* \param flags If set to zero, a port MAY be present. If set to PARSE_PORT_IGNORE, a
* port MAY be present but will be ignored. If set to PARSE_PORT_REQUIRE,
* a port MUST be present. If set to PARSE_PORT_FORBID, a port MUST NOT
* be present.
*
* \retval 1 Success
* \retval 0 Failure
*/
int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags);
/*!
* \since 1.8
*

View File

@@ -118,7 +118,7 @@ char *ast_sockaddr_stringify_fmt(const struct ast_sockaddr *sa, int format)
return ast_str_buffer(str);
}
int static _ast_sockaddr_parse(char *str, char **host, char **port, int flags)
int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
{
char *s = str;
@@ -187,7 +187,7 @@ int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
int e;
s = ast_strdupa(str);
if (!_ast_sockaddr_parse(s, &host, &port, flags)) {
if (!ast_sockaddr_split_hostport(s, &host, &port, flags)) {
return 0;
}
@@ -233,7 +233,7 @@ int ast_sockaddr_resolve(struct ast_sockaddr **addrs, const char *str,
int e, i, res_cnt;
s = ast_strdupa(str);
if (!_ast_sockaddr_parse(s, &host, &port, flags)) {
if (!ast_sockaddr_split_hostport(s, &host, &port, flags)) {
return 0;
}