<p>Joshua Colp <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15634">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Kevin Harwell: Looks good to me, approved
George Joseph: Looks good to me, but someone else must approve
Joshua Colp: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip: Add support for partial transport reload.<br><br>Some configuration items for a transport do not result in<br>the underlying transport changing, but instead are just<br>state we keep ourselves and use. It is perfectly reasonable<br>to change these items.<br><br>These include local_net and external_* information.<br><br>ASTERISK-29354<br><br>Change-Id: I027857ccfe4419f460243e562b5f098434b3d43a<br>---<br>A doc/CHANGES-staging/pjsip_transport_partial_reload.txt<br>M res/res_pjsip/config_transport.c<br>2 files changed, 24 insertions(+), 19 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/pjsip_transport_partial_reload.txt b/doc/CHANGES-staging/pjsip_transport_partial_reload.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..1d1b0b6</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/pjsip_transport_partial_reload.txt</span><br><span>@@ -0,0 +1,4 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: res_pjsip</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+PJSIP transports can now be partially reloaded safely. This allows the</span><br><span style="color: hsl(120, 100%, 40%);">+local_net and external_* options to be updated without restarting Asterisk.</span><br><span>diff --git a/res/res_pjsip/config_transport.c b/res/res_pjsip/config_transport.c</span><br><span>index f3a8d97..c1001f4 100644</span><br><span>--- a/res/res_pjsip/config_transport.c</span><br><span>+++ b/res/res_pjsip/config_transport.c</span><br><span>@@ -499,28 +499,24 @@</span><br><span> ao2_replace(perm_state->transport, transport);</span><br><span> return 0;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+ /* If we aren't allowed to reload then we copy values that can't be changed from perm_state */</span><br><span> if (!transport->allow_reload) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!perm_state->change_detected) {</span><br><span style="color: hsl(0, 100%, 40%);">- perm_state->change_detected = 1;</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Transport '%s' is not reloadable, maintaining previous values\n", transport_id);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- /* In case someone is using the deprecated fields, reset them */</span><br><span style="color: hsl(0, 100%, 40%);">- transport->state = perm_state->state;</span><br><span style="color: hsl(0, 100%, 40%);">- copy_state_to_transport(transport);</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_replace(perm_state->transport, transport);</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ memcpy(&temp_state->state->host, &perm_state->state->host, sizeof(temp_state->state->host));</span><br><span style="color: hsl(120, 100%, 40%);">+ memcpy(&temp_state->state->tls, &perm_state->state->tls, sizeof(temp_state->state->tls));</span><br><span style="color: hsl(120, 100%, 40%);">+ memcpy(&temp_state->state->ciphers, &perm_state->state->ciphers, sizeof(temp_state->state->ciphers));</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (temp_state->state->host.addr.sa_family != PJ_AF_INET && temp_state->state->host.addr.sa_family != PJ_AF_INET6) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_ERROR, "Transport '%s' could not be started as binding not specified\n", transport_id);</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!perm_state || transport->allow_reload) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (temp_state->state->host.addr.sa_family != PJ_AF_INET && temp_state->state->host.addr.sa_family != PJ_AF_INET6) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Transport '%s' could not be started as binding not specified\n", transport_id);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- /* Set default port if not present */</span><br><span style="color: hsl(0, 100%, 40%);">- if (!pj_sockaddr_get_port(&temp_state->state->host)) {</span><br><span style="color: hsl(0, 100%, 40%);">- pj_sockaddr_set_port(&temp_state->state->host, (transport->type == AST_TRANSPORT_TLS) ? 5061 : 5060);</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Set default port if not present */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!pj_sockaddr_get_port(&temp_state->state->host)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_sockaddr_set_port(&temp_state->state->host, (transport->type == AST_TRANSPORT_TLS) ? 5061 : 5060);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span> /* Now that we know what address family we can set up a dnsmgr refresh for the external addresses if present */</span><br><span>@@ -558,8 +554,13 @@</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (transport->type == AST_TRANSPORT_UDP) {</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!transport->allow_reload && perm_state) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* We inherit the transport from perm state, untouched */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Transport '%s' is not fully reloadable, not reloading: protocol, bind, TLS, TCP, ToS, or CoS options.\n", transport_id);</span><br><span style="color: hsl(120, 100%, 40%);">+ temp_state->state->transport = perm_state->state->transport;</span><br><span style="color: hsl(120, 100%, 40%);">+ perm_state->state->transport = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ res = PJ_SUCCESS;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (transport->type == AST_TRANSPORT_UDP) {</span><br><span> for (i = 0; i < BIND_TRIES && res != PJ_SUCCESS; i++) {</span><br><span> if (perm_state && perm_state->state && perm_state->state->transport) {</span><br><span> pjsip_udp_transport_pause(perm_state->state->transport,</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15634">change 15634</a>. To unsubscribe, or for help writing mail filters, 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/c/asterisk/+/15634"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I027857ccfe4419f460243e562b5f098434b3d43a </div>
<div style="display:none"> Gerrit-Change-Number: 15634 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>