<p>Joshua Colp has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/6068">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip: Add support for dnsmgr to external_media_address.<br><br>The "external_media_address" option on transports is now<br>resolved using dnsmgr. This allows it to be automatically<br>refreshed regularly if refreshes are enabled in dnsmgr.<br>If the system is using a dynamic IP address a dynamic DNS<br>hostname can be provided to keep the IP address up to<br>date.<br><br>Change-Id: Ia54771720dff0105bde55d5bbb81a3ba437e05b2<br>---<br>M CHANGES<br>M include/asterisk/res_pjsip.h<br>M res/res_pjsip/config_transport.c<br>M res/res_pjsip_nat.c<br>M res/res_pjsip_sdp_rtp.c<br>M res/res_pjsip_session.c<br>M res/res_pjsip_t38.c<br>7 files changed, 62 insertions(+), 22 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/68/6068/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/CHANGES b/CHANGES<br>index c7d801d..9e51134 100644<br>--- a/CHANGES<br>+++ b/CHANGES<br>@@ -12,6 +12,12 @@<br> --- Functionality changes from Asterisk 13.17.0 to Asterisk 13.18.0 ----------<br> ------------------------------------------------------------------------------<br> <br>+res_pjsip<br>+------------------<br>+ * The "external_media_address" on transports is now resolved using dnsmgr and<br>+   when dnsmgr refreshes are enabled will be automatically updated with the new<br>+   IP address of a given hostname.<br>+<br> res_musiconhold<br> ------------------<br>  * By default, when res_musiconhold reloads or unloads, it sends a HUP signal<br>diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h<br>index b5a0288..e56ece6 100644<br>--- a/include/asterisk/res_pjsip.h<br>+++ b/include/asterisk/res_pjsip.h<br>@@ -103,15 +103,25 @@<br>          */<br>   struct ast_ha *localnet;<br>      /*!<br>-   * DNS manager for refreshing the external address<br>+    * DNS manager for refreshing the external signaling address<br>   * \since 13.8.0<br>       */<br>-  struct ast_dnsmgr_entry *external_address_refresher;<br>+ struct ast_dnsmgr_entry *external_signaling_address_refresher;<br>        /*!<br>-   * Optional external address information<br>+      * Optional external signaling address information<br>     * \since 13.8.0<br>       */<br>-  struct ast_sockaddr external_address;<br>+        struct ast_sockaddr external_signaling_address;<br>+      /*!<br>+   * DNS manager for refreshing the external media address<br>+      * \since 13.18.0<br>+     */<br>+  struct ast_dnsmgr_entry *external_media_address_refresher;<br>+   /*!<br>+   * Optional external signaling address information<br>+    * \since 13.18.0<br>+     */<br>+  struct ast_sockaddr external_media_address;<br> };<br> <br> /*<br>diff --git a/res/res_pjsip/config_transport.c b/res/res_pjsip/config_transport.c<br>index 62bc9d6..5f7eafa 100644<br>--- a/res/res_pjsip/config_transport.c<br>+++ b/res/res_pjsip/config_transport.c<br>@@ -248,8 +248,11 @@<br>       ast_free(transport_state->id);<br>     ast_free_ha(transport_state->localnet);<br> <br>-        if (transport_state->external_address_refresher) {<br>-                ast_dnsmgr_release(transport_state->external_address_refresher);<br>+  if (transport_state->external_signaling_address_refresher) {<br>+              ast_dnsmgr_release(transport_state->external_signaling_address_refresher);<br>+        }<br>+    if (transport_state->external_media_address_refresher) {<br>+          ast_dnsmgr_release(transport_state->external_media_address_refresher);<br>     }<br>     if (transport_state->transport) {<br>          pjsip_transport_shutdown(transport_state->transport);<br>@@ -399,8 +402,8 @@<br>         memcpy(&transport->tls, &transport->state->tls, sizeof(transport->tls));<br>  memcpy(&transport->ciphers, &transport->state->ciphers, sizeof(transport->ciphers));<br>      transport->localnet = transport->state->localnet;<br>-   transport->external_address_refresher = transport->state->external_address_refresher;<br>-       memcpy(&transport->external_address, &transport->state->external_address, sizeof(transport->external_address));<br>+  transport->external_address_refresher = transport->state->external_signaling_address_refresher;<br>+     memcpy(&transport->external_address, &transport->state->external_signaling_address, sizeof(transport->external_signaling_address));<br> }<br> <br> static int has_state_changed(struct ast_sip_transport_state *a, struct ast_sip_transport_state *b)<br>@@ -421,7 +424,11 @@<br>             return -1;<br>    }<br> <br>- if (ast_sockaddr_cmp(&a->external_address, &b->external_address)) {<br>+    if (ast_sockaddr_cmp(&a->external_signaling_address, &b->external_signaling_address)) {<br>+                return -1;<br>+   }<br>+<br>+ if (ast_sockaddr_cmp(&a->external_media_address, &b->external_media_address)) {<br>                 return -1;<br>    }<br> <br>@@ -515,24 +522,41 @@<br>           pj_sockaddr_set_port(&temp_state->state->host, (transport->type == AST_TRANSPORT_TLS) ? 5061 : 5060);<br>    }<br> <br>- /* Now that we know what address family we can set up a dnsmgr refresh for the external media address if present */<br>+  /* Now that we know what address family we can set up a dnsmgr refresh for the external addresses if present */<br>       if (!ast_strlen_zero(transport->external_signaling_address)) {<br>             if (temp_state->state->host.addr.sa_family == pj_AF_INET()) {<br>-                  temp_state->state->external_address.ss.ss_family = AF_INET;<br>+                    temp_state->state->external_signaling_address.ss.ss_family = AF_INET;<br>           } else if (temp_state->state->host.addr.sa_family == pj_AF_INET6()) {<br>-                  temp_state->state->external_address.ss.ss_family = AF_INET6;<br>+                   temp_state->state->external_signaling_address.ss.ss_family = AF_INET6;<br>          } else {<br>                      ast_log(LOG_ERROR, "Unknown address family for transport '%s', could not get external signaling address\n",<br>                                         transport_id);<br>                        return -1;<br>            }<br> <br>-         if (ast_dnsmgr_lookup(transport->external_signaling_address, &temp_state->state->external_address, &temp_state->state->external_address_refresher, NULL) < 0) {<br>+            if (ast_dnsmgr_lookup(transport->external_signaling_address, &temp_state->state->external_signaling_address, &temp_state->state->external_signaling_address_refresher, NULL) < 0) {<br>                         ast_log(LOG_ERROR, "Could not create dnsmgr for external signaling address on '%s'\n", transport_id);<br>                       return -1;<br>            }<br>     }<br> <br>+ if (!ast_strlen_zero(transport->external_media_address)) {<br>+                if (temp_state->state->host.addr.sa_family == pj_AF_INET()) {<br>+                  temp_state->state->external_media_address.ss.ss_family = AF_INET;<br>+              } else if (temp_state->state->host.addr.sa_family == pj_AF_INET6()) {<br>+                  temp_state->state->external_media_address.ss.ss_family = AF_INET6;<br>+             } else {<br>+                     ast_log(LOG_ERROR, "Unknown address family for transport '%s', could not get external media address\n",<br>+                                    transport_id);<br>+                       return -1;<br>+           }<br>+<br>+         if (ast_dnsmgr_lookup(transport->external_media_address, &temp_state->state->external_media_address, &temp_state->state->external_media_address_refresher, NULL) < 0) {<br>+                    ast_log(LOG_ERROR, "Could not create dnsmgr for external media address on '%s'\n", transport_id);<br>+                  return -1;<br>+           }<br>+    }<br>+<br>  if (transport->type == AST_TRANSPORT_UDP) {<br> <br>             for (i = 0; i < BIND_TRIES && res != PJ_SUCCESS; i++) {<br>diff --git a/res/res_pjsip_nat.c b/res/res_pjsip_nat.c<br>index a0ce2a9..3847de7 100644<br>--- a/res/res_pjsip_nat.c<br>+++ b/res/res_pjsip_nat.c<br>@@ -273,10 +273,10 @@<br>                }<br>     }<br> <br>- if (!ast_sockaddr_isnull(&transport_state->external_address)) {<br>+       if (!ast_sockaddr_isnull(&transport_state->external_signaling_address)) {<br>              /* Update the contact header with the external address */<br>             if (uri || (uri = nat_get_contact_sip_uri(tdata))) {<br>-                 pj_strdup2(tdata->pool, &uri->host, ast_sockaddr_stringify_host(&transport_state->external_address));<br>+                       pj_strdup2(tdata->pool, &uri->host, ast_sockaddr_stringify_host(&transport_state->external_signaling_address));<br>                      if (transport->external_signaling_port) {<br>                          uri->port = transport->external_signaling_port;<br>                                 ast_debug(4, "Re-wrote Contact URI port to %d\n", uri->port);<br>@@ -285,7 +285,7 @@<br> <br>            /* Update the via header if relevant */<br>               if ((tdata->msg->type == PJSIP_REQUEST_MSG) && (via || (via = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL)))) {<br>-                        pj_strdup2(tdata->pool, &via->sent_by.host, ast_sockaddr_stringify_host(&transport_state->external_address));<br>+                       pj_strdup2(tdata->pool, &via->sent_by.host, ast_sockaddr_stringify_host(&transport_state->external_signaling_address));<br>                      if (transport->external_signaling_port) {<br>                          via->sent_by.port = transport->external_signaling_port;<br>                         }<br>diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c<br>index a6bd2d7..8dfcd8b 100644<br>--- a/res/res_pjsip_sdp_rtp.c<br>+++ b/res/res_pjsip_sdp_rtp.c<br>@@ -1520,8 +1520,8 @@<br>                 && ast_apply_ha(transport_state->localnet, &addr) == AST_SENSE_ALLOW) {<br>                return;<br>       }<br>-    ast_debug(5, "Setting media address to %s\n", transport->external_media_address);<br>-       pj_strdup2(tdata->pool, &stream->conn->addr, transport->external_media_address);<br>+     ast_debug(5, "Setting media address to %s\n", ast_sockaddr_stringify_host(&transport_state->external_media_address));<br>+       pj_strdup2(tdata->pool, &stream->conn->addr, ast_sockaddr_stringify_host(&transport_state->external_media_address));<br> }<br> <br> /*! \brief Function which stops the RTP instance */<br>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c<br>index d6c5fbc..bcf7447 100644<br>--- a/res/res_pjsip_session.c<br>+++ b/res/res_pjsip_session.c<br>@@ -3150,8 +3150,8 @@<br> <br>          if (!transport_state->localnet<br>                     || ast_apply_ha(transport_state->localnet, &addr) != AST_SENSE_ALLOW) {<br>-                       ast_debug(5, "Setting external media address to %s\n", transport->external_media_address);<br>-                      pj_strdup2(tdata->pool, &sdp->conn->addr, transport->external_media_address);<br>+                        ast_debug(5, "Setting external media address to %s\n", ast_sockaddr_stringify_host(&transport_state->external_media_address));<br>+                      pj_strdup2(tdata->pool, &sdp->conn->addr, ast_sockaddr_stringify_host(&transport_state->external_media_address));<br>                 }<br>     }<br> <br>diff --git a/res/res_pjsip_t38.c b/res/res_pjsip_t38.c<br>index 91af292..648c753 100644<br>--- a/res/res_pjsip_t38.c<br>+++ b/res/res_pjsip_t38.c<br>@@ -885,8 +885,8 @@<br>                && ast_apply_ha(transport_state->localnet, &addr) == AST_SENSE_ALLOW) {<br>                return;<br>       }<br>-    ast_debug(5, "Setting media address to %s\n", transport->external_media_address);<br>-       pj_strdup2(tdata->pool, &stream->conn->addr, transport->external_media_address);<br>+     ast_debug(5, "Setting media address to %s\n", ast_sockaddr_stringify_host(&transport_state->external_media_address));<br>+       pj_strdup2(tdata->pool, &stream->conn->addr, ast_sockaddr_stringify_host(&transport_state->external_media_address));<br> }<br> <br> /*! \brief Function which destroys the UDPTL instance when session ends */<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/6068">change 6068</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/6068"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ia54771720dff0105bde55d5bbb81a3ba437e05b2 </div>
<div style="display:none"> Gerrit-Change-Number: 6068 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@digium.com> </div>