]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Make it possible to configure an externhost and not just an externip (bug #3069)
authorMark Spencer <markster@digium.com>
Tue, 28 Dec 2004 21:20:18 +0000 (21:20 +0000)
committerMark Spencer <markster@digium.com>
Tue, 28 Dec 2004 21:20:18 +0000 (21:20 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4573 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_sip.c
configs/sip.conf.sample

index 8c4365954b5de174c4ff71392dd71e6c3b015c74..7012a9f21059281e259177ea931474f20ad7df1b 100755 (executable)
@@ -564,6 +564,9 @@ static int global_canreinvite = REINVITE_INVITE;
 
 static struct sockaddr_in bindaddr;
 static struct sockaddr_in externip;
+static char externhost[256] = "";
+static time_t externexpire = 0;
+static int externrefresh = 10;
 static struct ast_ha *localaddr;
 
 static struct ast_frame  *sip_read(struct ast_channel *ast);
@@ -636,6 +639,16 @@ static int ast_sip_ouraddrfor(struct in_addr *them, struct in_addr *us)
         */
        struct sockaddr_in theirs;
        theirs.sin_addr = *them;
+       if (externexpire && (time(NULL) >= externexpire)) {
+               struct ast_hostent ahp;
+               struct hostent *hp;
+               time(&externexpire);
+               externexpire += externrefresh;
+               if ((hp = ast_gethostbyname(externhost, &ahp))) {
+                       memcpy(&externip, hp->h_addr, sizeof(externip));
+               } else
+                       ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost);
+       }
        if (localaddr && externip.sin_addr.s_addr &&
           ast_apply_ha(localaddr, &theirs)) {
                char iabuf[INET_ADDRSTRLEN];
@@ -8837,6 +8850,9 @@ static int reload_config(void)
        strncpy(default_context, DEFAULT_CONTEXT, sizeof(default_context) - 1);
        default_language[0] = '\0';
        default_fromdomain[0] = '\0';
+       externhost[0] = '\0';
+       externexpire = 0;
+       externrefresh = 10;
        strncpy(default_useragent, DEFAULT_USERAGENT, sizeof(default_useragent) - 1);
        strncpy(default_notifymime, DEFAULT_NOTIFYMIME, sizeof(default_notifymime) - 1);
        global_realm[sizeof(global_realm)-1] = '\0';
@@ -9008,6 +9024,19 @@ static int reload_config(void)
                                ast_log(LOG_WARNING, "Invalid address for externip keyword: %s\n", v->value);
                        else
                                memcpy(&externip.sin_addr, hp->h_addr, sizeof(externip.sin_addr));
+                       externexpire = 0;
+               } else if (!strcasecmp(v->name, "externhost")) {
+                       strncpy(externhost, v->value, sizeof(externhost) - 1);
+                       if (!(hp = ast_gethostbyname(externhost, &ahp))) 
+                               ast_log(LOG_WARNING, "Invalid address for externhost keyword: %s\n", externhost);
+                       else
+                               memcpy(&externip.sin_addr, hp->h_addr, sizeof(externip.sin_addr));
+                       time(&externexpire);
+               } else if (!strcasecmp(v->name, "externrefresh")) {
+                       if (sscanf(v->value, "%i", &externrefresh) != 1) {
+                               ast_log(LOG_WARNING, "Invalid externrefresh value '%s', must be an integer >0 at line %d\n", v->value, v->lineno);
+                               externrefresh = 10;
+                       }
                } else if (!strcasecmp(v->name, "allow")) {
                        ast_parse_allow_disallow(&prefs, &global_capability, v->value, 1);
                } else if (!strcasecmp(v->name, "disallow")) {
index 557d443e976cc977587ffa81bbec12f3c8311302..26b4e4a0edc498d7bc1e68024be804635daaf0f0 100755 (executable)
@@ -131,6 +131,13 @@ srvlookup=yes                      ; Enable DNS SRV lookups on outbound calls
                                ; that we're registered with
                                ; You may add multiple local networks.  A reasonable set of defaults
                                ; are:
+;externhost=foo.dyndns.net     ; Alternatively you can specify an 
+                               ; external host, and Asterisk will 
+                               ; perform DNS queries periodically.  Not
+                               ; recommended for production 
+                               ; environments!  Use externip instead
+;externrefresh=10              ; How often to refresh externhost if 
+                               ; usedl
 ;localnet=192.168.0.0/255.255.0.0; All RFC 1918 addresses are local networks
 ;localnet=10.0.0.0/255.0.0.0   ; Also RFC1918
 ;localnet=172.16.0.0/12                ; Another RFC1918 with CIDR notation