Author: rizzo
Date: Fri Jul 20 20:09:26 2007
New Revision: 76223

URL: http://svn.digium.com/view/asterisk?view=rev&rev=76223
Log:
sync externip/stun support with the code in trunk

Modified:
    team/rizzo/astobj2/channels/chan_sip.c

Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: 
http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?view=diff&rev=76223&r1=76222&r2=76223
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Fri Jul 20 20:09:26 2007
@@ -1420,6 +1420,9 @@
  *
  * + with "stunaddr = host[:port]" we run queries every externrefresh seconds
  *   to the specified server, and store the result in externip.
+ *
+ * Other variables (externhost, externexpire, externrefresh) are used
+ * to support the above functions.
  */
 static struct sockaddr_in externip;            /*!< External IP address if we 
are behind NAT */
 
@@ -11430,6 +11433,7 @@
        int realtimeusers;
        int realtimeregs;
        char codec_buf[BUFSIZ];
+       const char *msg;        /* temporary msg pointer */
 
        realtimepeers = ast_check_realtime("sippeers");
        realtimeusers = ast_check_realtime("sipusers");
@@ -11491,23 +11495,32 @@
 
        ast_cli(fd, "\nNetwork Settings:\n");
        ast_cli(fd, "---------------------------\n");
-       ast_cli(fd, "  Externhost:             %s\n", externhost);
+       /* determine if/how SIP address can be remapped */
+       if (localaddr == NULL)
+               msg = "Disabled, no localnet list";
+       else if (externip.sin_addr.s_addr == 0)
+               msg = "Disabled, externip is 0.0.0.0";
+       else if (!ast_strlen_zero(externhost))
+               msg = "Enabled using externhost";
+       else
+               msg = "Enabled using externip";
+       ast_cli(fd, "  SIP address remapping:  %s\n", msg);
+       ast_cli(fd, "  Externhost:             %s\n", S_OR(externhost, 
"<none>"));
        ast_cli(fd, "  Externip:               %s:%d\n", 
ast_inet_ntoa(externip.sin_addr), ntohs(externip.sin_port));
        ast_cli(fd, "  Externrefresh:          %d\n", externrefresh);
        ast_cli(fd, "  Internal IP:            %s:%d\n", 
ast_inet_ntoa(internip.sin_addr), ntohs(internip.sin_port));
-       { struct ast_ha *a;
-         const char *prefix = "Localnet:";
-         char buf[INET_ADDRSTRLEN]; /* need to print two addresses */
-
-         for (a = localaddr; a ; a = a->next) {
-               ast_cli(fd, "  %-24s%s/%s\n",
-                       prefix,
-                       ast_inet_ntoa(a->netaddr),
-                       inet_ntop(AF_INET, &a->netmask, buf, sizeof(buf)) );
-               prefix = "";
-         }
-       }
-       ast_cli(fd, "  Stun server:            %s:%d\n", 
ast_inet_ntoa(stunaddr.sin_addr), ntohs(stunaddr.sin_port));
+       {
+               struct ast_ha *a;
+               const char *prefix = "Localnet:";
+               char buf[INET_ADDRSTRLEN]; /* need to print two addresses */
+
+               for (a = localaddr; a ; prefix = "", a = a->next) {
+                       ast_cli(fd, "  %-24s%s/%s\n",
+                               prefix, ast_inet_ntoa(a->netaddr),
+                               inet_ntop(AF_INET, &a->netmask, buf, 
sizeof(buf)) );
+               }
+       }
+       ast_cli(fd, "  STUN server:            %s:%d\n", 
ast_inet_ntoa(stunaddr.sin_addr), ntohs(stunaddr.sin_port));
 
        ast_cli(fd, "\nGlobal Signalling Settings:\n");
        ast_cli(fd, "---------------------------\n");
@@ -11538,6 +11551,7 @@
        ast_cli(fd, "  Auto-Framing:           %s\n", global_autoframing ? 
"Yes" : "No");
        ast_cli(fd, "  Outb. proxy:            %s %s\n", 
ast_strlen_zero(global_outboundproxy.name) ? "<not set>" : 
global_outboundproxy.name,
                                                                 
global_outboundproxy.force ? "(forced)" : "");
+
        ast_cli(fd, "\nDefault Settings:\n");
        ast_cli(fd, "-----------------\n");
        ast_cli(fd, "  Context:                %s\n", default_context);
@@ -17607,7 +17621,10 @@
 
        /* Reset IP addresses  */
        memset(&bindaddr, 0, sizeof(bindaddr));
+       memset(&stunaddr, 0, sizeof(stunaddr));
        memset(&internip, 0, sizeof(internip));
+       /* Free memory for local network address mask */
+       ast_free_ha(localaddr);
        memset(&localaddr, 0, sizeof(localaddr));
        memset(&externip, 0, sizeof(externip));
        memset(&default_prefs, 0 , sizeof(default_prefs));
@@ -17781,7 +17798,7 @@
                M_F("stunaddr", {
                        stunaddr.sin_port = htons(3478); /* default */
                        if (ast_parse_arg(v->value, PARSE_INADDR, &stunaddr))
-                               ast_log(LOG_WARNING, "Invalid stun address: 
%s\n", v->value);
+                               ast_log(LOG_WARNING, "Invalid STUN server 
address: %s\n", v->value);
                        } )
                M_F("bindaddr", {
                        if (ast_parse_arg(v->value, PARSE_INADDR, &bindaddr))
@@ -18019,11 +18036,11 @@
                                ast_netsock_set_qos(my_socket, global_tos_sip, 
global_tos_sip);
                                sipsock = my_socket;
                                if (stunaddr.sin_addr.s_addr != 0) {
-                                       ast_log(LOG_WARNING, "stun to %s:%d\n",
+                                       ast_debug(1, "stun to %s:%d\n",
                                                
ast_inet_ntoa(stunaddr.sin_addr) , ntohs(stunaddr.sin_port));
                                        ast_stun_request(sipsock, &stunaddr,
                                                NULL, &externip);
-                                       ast_log(LOG_WARNING, "stun sees us at 
%s:%d\n",
+                                       ast_debug(1, "stun sees us at %s:%d\n",
                                                
ast_inet_ntoa(externip.sin_addr) , ntohs(externip.sin_port));
                                }
                                sipsock_read_id = ast_io_add(io, sipsock, 
sipsock_read, AST_IO_IN, NULL);


_______________________________________________
--Bandwidth and Colocation Provided by http://www.api-digital.com--

svn-commits mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/svn-commits

Reply via email to