<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/osmo-remsim/+/16591">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">rspro_client_fsm: Fix handling of IPA keepalive<br><br>We cannot rely on the implicit IPA keepalive FSM termination, as that<br>somehow gets the termination order wrong and we end up accessing free'd<br>memory.<br><br>Let's handle the termination explicitly:  We register a callback with<br>the IPA keepalive FSM, and once that callback gets hit, we ask the<br>core to *not* terminate the FSM implicitly.  We are anyway terminating<br>it explicitly in st_reestablish_onenter().<br><br>Change-Id: Ia745ccb44c0d0224d1e7ab6b6da3713474111d41<br>---<br>M src/rspro_client_fsm.c<br>M src/rspro_client_fsm.h<br>2 files changed, 11 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/rspro_client_fsm.c b/src/rspro_client_fsm.c</span><br><span>index eea8471..758bde7 100644</span><br><span>--- a/src/rspro_client_fsm.c</span><br><span>+++ b/src/rspro_client_fsm.c</span><br><span>@@ -113,6 +113,7 @@</span><br><span>   OSMO_VALUE_STRING(SRVC_E_TCP_UP),</span><br><span>    OSMO_VALUE_STRING(SRVC_E_TCP_DOWN),</span><br><span>  OSMO_VALUE_STRING(SRVC_E_KA_TIMEOUT),</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_VALUE_STRING(SRVC_E_KA_TERMINATED),</span><br><span>     OSMO_VALUE_STRING(SRVC_E_CLIENT_CONN_RES),</span><br><span>   OSMO_VALUE_STRING(SRVC_E_RSPRO_TX),</span><br><span>  { 0, NULL }</span><br><span>@@ -261,6 +262,13 @@</span><br><span>   }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static int ipa_kaepalive_timeout_cb(struct osmo_fsm_inst *ka_fi, void *conn)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   struct osmo_fsm_inst *fi = ka_fi->proc.parent;</span><br><span style="color: hsl(120, 100%, 40%);">+     osmo_fsm_inst_dispatch(fi, SRVC_E_KA_TIMEOUT, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+  return 0; /* we will explicitly terminate it */</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void srvc_st_reestablish_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)</span><br><span> {</span><br><span>  struct rspro_server_conn *srvc = (struct rspro_server_conn *) fi->priv;</span><br><span>@@ -292,8 +300,9 @@</span><br><span>             LOGPFSM(fi, "Unable to create keepalive FSM\n");</span><br><span>           exit(1);</span><br><span>     }</span><br><span style="color: hsl(120, 100%, 40%);">+     ipa_keepalive_fsm_set_timeout_cb(srvc->keepalive_fi, ipa_kaepalive_timeout_cb);</span><br><span>   /* ensure parent is notified once keepalive FSM instance is dying */</span><br><span style="color: hsl(0, 100%, 40%);">-    osmo_fsm_inst_change_parent(srvc->keepalive_fi, srvc->fi, SRVC_E_KA_TIMEOUT);</span><br><span style="color: hsl(120, 100%, 40%);">+   osmo_fsm_inst_change_parent(srvc->keepalive_fi, srvc->fi, SRVC_E_KA_TERMINATED);</span><br><span> </span><br><span>   /* Attempt to connect TCP socket */</span><br><span>  rc = ipa_client_conn_open(srvc->conn);</span><br><span>diff --git a/src/rspro_client_fsm.h b/src/rspro_client_fsm.h</span><br><span>index b1c14f8..ca59c77 100644</span><br><span>--- a/src/rspro_client_fsm.h</span><br><span>+++ b/src/rspro_client_fsm.h</span><br><span>@@ -9,6 +9,7 @@</span><br><span>     SRVC_E_TCP_UP,</span><br><span>       SRVC_E_TCP_DOWN,</span><br><span>     SRVC_E_KA_TIMEOUT,</span><br><span style="color: hsl(120, 100%, 40%);">+    SRVC_E_KA_TERMINATED,</span><br><span>        SRVC_E_CLIENT_CONN_RES,</span><br><span>      SRVC_E_RSPRO_TX         /* transmit a RSPRO PDU to the peer */</span><br><span> };</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-remsim/+/16591">change 16591</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.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.osmocom.org/c/osmo-remsim/+/16591"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-remsim </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ia745ccb44c0d0224d1e7ab6b6da3713474111d41 </div>
<div style="display:none"> Gerrit-Change-Number: 16591 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>