aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjpeeler <jpeeler@f38db490-d61c-443f-a65b-d21fe96a405b>2010-07-15 20:21:03 +0000
committerjpeeler <jpeeler@f38db490-d61c-443f-a65b-d21fe96a405b>2010-07-15 20:21:03 +0000
commit9823a33ff4e1bed6e77b715ed10980d0a744f7d1 (patch)
tree2cdd96922db9dd3f3ef1cf66b9ca0ba2226574b5
parent6f7cb5d2e8fddcd324374e0de6f3c89b4d005482 (diff)
Correct not setting the bindport before attempting to open the socket.
Related to changes from 276571, I was accidentally testing with a port set in my configuration causing me to miss this. Also moved the TCP handling as well to occur before build_peer is called. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@276788 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--channels/chan_sip.c126
1 files changed, 62 insertions, 64 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 3e568ac58..7d87e24db 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -26719,6 +26719,26 @@ static int reload_config(enum channelreloadreason reason)
authl = add_realm_authentication(authl, v->value, v->lineno);
}
+ if (bindport) {
+ if (ast_sockaddr_port(&bindaddr)) {
+ ast_log(LOG_WARNING, "bindport is also specified in bindaddr. "
+ "Using %d.\n", bindport);
+ }
+ ast_sockaddr_set_port(&bindaddr, bindport);
+ }
+
+ if (!ast_sockaddr_port(&bindaddr)) {
+ ast_sockaddr_set_port(&bindaddr, STANDARD_SIP_PORT);
+ }
+
+ /* Set UDP address and open socket */
+ ast_sockaddr_copy(&internip, &bindaddr);
+ if (ast_find_ourip(&internip, &bindaddr)) {
+ ast_log(LOG_WARNING, "Unable to get own IP address, SIP disabled\n");
+ ast_config_destroy(cfg);
+ return 0;
+ }
+
ast_mutex_lock(&netlock);
if ((sipsock > -1) && (ast_sockaddr_cmp(&old_bindaddr, &bindaddr))) {
close(sipsock);
@@ -26763,6 +26783,48 @@ static int reload_config(enum channelreloadreason reason)
}
ast_mutex_unlock(&netlock);
+ /* Start TCP server */
+ if (sip_cfg.tcp_enabled) {
+ if (ast_sockaddr_isnull(&sip_tcp_desc.local_address)) {
+ ast_sockaddr_copy(&sip_tcp_desc.local_address, &bindaddr);
+ }
+ if (!ast_sockaddr_port(&sip_tcp_desc.local_address)) {
+ ast_sockaddr_set_port(&sip_tcp_desc.local_address, STANDARD_SIP_PORT);
+ }
+ } else {
+ ast_sockaddr_setnull(&sip_tcp_desc.local_address);
+ }
+ ast_tcptls_server_start(&sip_tcp_desc);
+ if (sip_cfg.tcp_enabled && sip_tcp_desc.accept_fd == -1) {
+ /* TCP server start failed. Tell the admin */
+ ast_log(LOG_ERROR, "SIP TCP Server start failed. Not listening on TCP socket.\n");
+ } else {
+ ast_debug(2, "SIP TCP server started\n");
+ }
+
+ /* Start TLS server if needed */
+ memcpy(sip_tls_desc.tls_cfg, &default_tls_cfg, sizeof(default_tls_cfg));
+
+ if (ast_ssl_setup(sip_tls_desc.tls_cfg)) {
+ if (ast_sockaddr_isnull(&sip_tls_desc.local_address)) {
+ ast_sockaddr_copy(&sip_tls_desc.local_address, &bindaddr);
+ ast_sockaddr_set_port(&sip_tls_desc.local_address,
+ STANDARD_TLS_PORT);
+ }
+ if (!ast_sockaddr_port(&sip_tls_desc.local_address)) {
+ ast_sockaddr_set_port(&sip_tls_desc.local_address,
+ STANDARD_TLS_PORT);
+ }
+ ast_tcptls_server_start(&sip_tls_desc);
+ if (default_tls_cfg.enabled && sip_tls_desc.accept_fd == -1) {
+ ast_log(LOG_ERROR, "TLS Server start failed. Not listening on TLS socket.\n");
+ sip_tls_desc.tls_cfg = NULL;
+ }
+ } else if (sip_tls_desc.tls_cfg->enabled) {
+ sip_tls_desc.tls_cfg = NULL;
+ ast_log(LOG_WARNING, "SIP TLS server did not load because of errors.\n");
+ }
+
if (ucfg) {
struct ast_variable *gen;
int genhassip, genregistersip;
@@ -26826,7 +26888,6 @@ static int reload_config(enum channelreloadreason reason)
}
ast_config_destroy(ucfg);
}
-
/* Load peers, users and friends */
cat = NULL;
@@ -26861,69 +26922,6 @@ static int reload_config(enum channelreloadreason reason)
}
}
- if (bindport) {
- if (ast_sockaddr_port(&bindaddr)) {
- ast_log(LOG_WARNING, "bindport is also specified in bindaddr. "
- "Using %d.\n", bindport);
- }
- ast_sockaddr_set_port(&bindaddr, bindport);
- }
-
- if (!ast_sockaddr_port(&bindaddr)) {
- ast_sockaddr_set_port(&bindaddr, STANDARD_SIP_PORT);
- }
-
- /* Set UDP address and open socket */
- ast_sockaddr_copy(&internip, &bindaddr);
- if (ast_find_ourip(&internip, &bindaddr)) {
- ast_log(LOG_WARNING, "Unable to get own IP address, SIP disabled\n");
- ast_config_destroy(cfg);
- return 0;
- }
-
- /* Start TCP server */
- if (sip_cfg.tcp_enabled) {
- if (ast_sockaddr_isnull(&sip_tcp_desc.local_address)) {
- ast_sockaddr_copy(&sip_tcp_desc.local_address, &bindaddr);
- }
- if (!ast_sockaddr_port(&sip_tcp_desc.local_address)) {
- ast_sockaddr_set_port(&sip_tcp_desc.local_address, STANDARD_SIP_PORT);
- }
- } else {
- ast_sockaddr_setnull(&sip_tcp_desc.local_address);
- }
- ast_tcptls_server_start(&sip_tcp_desc);
- if (sip_cfg.tcp_enabled && sip_tcp_desc.accept_fd == -1) {
- /* TCP server start failed. Tell the admin */
- ast_log(LOG_ERROR, "SIP TCP Server start failed. Not listening on TCP socket.\n");
- } else {
- ast_debug(2, "SIP TCP server started\n");
- }
-
- /* Start TLS server if needed */
- memcpy(sip_tls_desc.tls_cfg, &default_tls_cfg, sizeof(default_tls_cfg));
-
- if (ast_ssl_setup(sip_tls_desc.tls_cfg)) {
- if (ast_sockaddr_isnull(&sip_tls_desc.local_address)) {
- ast_sockaddr_copy(&sip_tls_desc.local_address, &bindaddr);
- ast_sockaddr_set_port(&sip_tls_desc.local_address,
- STANDARD_TLS_PORT);
- }
- if (!ast_sockaddr_port(&sip_tls_desc.local_address)) {
- ast_sockaddr_set_port(&sip_tls_desc.local_address,
- STANDARD_TLS_PORT);
- }
- ast_tcptls_server_start(&sip_tls_desc);
- if (default_tls_cfg.enabled && sip_tls_desc.accept_fd == -1) {
- ast_log(LOG_ERROR, "TLS Server start failed. Not listening on TLS socket.\n");
- sip_tls_desc.tls_cfg = NULL;
- }
- } else if (sip_tls_desc.tls_cfg->enabled) {
- sip_tls_desc.tls_cfg = NULL;
- ast_log(LOG_WARNING, "SIP TLS server did not load because of errors.\n");
- }
-
-
/* Add default domains - host name, IP address and IP:port
* Only do this if user added any sip domain with "localdomains"
* In order to *not* break backwards compatibility