<p>Hoernchen has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/libosmo-abis/+/14742">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">extend the ipa keepalive fsm<br><br>The new and improved fsm supports multipe use cases:<br>1) plain old ipa server/client operation<br>2) ipa client/server operation with custom send callback (i.e. to bypass<br>the tx queue)<br>3) all of the above + custom timeout callback<br>4) fully generic operation that will pass opaque data to the callbacks<br><br>The current code will always kill the fsm and deallocate it upon<br>timeout, so the timeout callback will now return a value: 1 means the<br>fsm will be automatically terminated, 0 means no action, which allows<br>manually stopping/starting the fsm to reuse it.<br><br>Change-Id: Ie453fdee8bfd7fc1a3f1ed67ef0331f0abb1d59b<br>---<br>M include/osmocom/abis/ipa.h<br>M src/input/ipa_keepalive.c<br>2 files changed, 58 insertions(+), 9 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmo-abis refs/changes/42/14742/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/abis/ipa.h b/include/osmocom/abis/ipa.h</span><br><span>index 4f6081f..71441aa 100644</span><br><span>--- a/include/osmocom/abis/ipa.h</span><br><span>+++ b/include/osmocom/abis/ipa.h</span><br><span>@@ -113,7 +113,9 @@</span><br><span>         unsigned int wait_for_resp;</span><br><span> };</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-typedef void ipa_keepalive_timeout_cb_t(struct osmo_fsm_inst *fi, void *conn);</span><br><span style="color: hsl(120, 100%, 40%);">+typedef int ipa_keepalive_timeout_cb_t(struct osmo_fsm_inst *fi, void *conn);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+typedef void ipa_keepalive_send_cb_t(struct osmo_fsm_inst *fi, void *conn, struct msgb *msg);</span><br><span> </span><br><span> struct osmo_fsm_inst *ipa_client_conn_alloc_keepalive_fsm(struct ipa_client_conn *client,</span><br><span>                                                           const struct ipa_keepalive_params *params,</span><br><span>@@ -123,12 +125,14 @@</span><br><span>                                                           const struct ipa_keepalive_params *params,</span><br><span>                                                           const char *id);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-struct osmo_fsm_inst *ipa_keepalive_alloc_server(struct ipa_server_conn *server,</span><br><span style="color: hsl(0, 100%, 40%);">-                                           const struct ipa_keepalive_params *params,</span><br><span style="color: hsl(0, 100%, 40%);">-                                              const char *id);</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fsm_inst *ipa_generic_conn_alloc_keepalive_fsm(void *ctx, void* data,</span><br><span style="color: hsl(120, 100%, 40%);">+                                                           const struct ipa_keepalive_params *params,</span><br><span style="color: hsl(120, 100%, 40%);">+                                                           const char *id);</span><br><span> </span><br><span> void ipa_keepalive_fsm_set_timeout_cb(struct osmo_fsm_inst *fi, ipa_keepalive_timeout_cb_t *cb);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+void ipa_keepalive_fsm_set_send_cb(struct osmo_fsm_inst *fi, ipa_keepalive_send_cb_t *fn);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> void ipa_keepalive_fsm_start(struct osmo_fsm_inst *fi);</span><br><span> </span><br><span> void ipa_keepalive_fsm_stop(struct osmo_fsm_inst *fi);</span><br><span>diff --git a/src/input/ipa_keepalive.c b/src/input/ipa_keepalive.c</span><br><span>index 81b5a26..7207be5 100644</span><br><span>--- a/src/input/ipa_keepalive.c</span><br><span>+++ b/src/input/ipa_keepalive.c</span><br><span>@@ -76,7 +76,9 @@</span><br><span> </span><br><span>         struct ipa_server_conn *srv_conn;</span><br><span>    struct ipa_client_conn *client_conn;</span><br><span style="color: hsl(120, 100%, 40%);">+  void* generic;</span><br><span>       ipa_keepalive_timeout_cb_t *timeout_cb;</span><br><span style="color: hsl(120, 100%, 40%);">+       ipa_keepalive_send_cb_t *send_fn;</span><br><span> };</span><br><span> </span><br><span> static void ipa_ka_init(struct osmo_fsm_inst *fi, uint32_t event, void *data)</span><br><span>@@ -103,11 +105,23 @@</span><br><span>         msg = gen_ipa_ping();</span><br><span>        OSMO_ASSERT(msg);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   if (ifp->srv_conn)</span><br><span style="color: hsl(0, 100%, 40%);">-           ipa_server_conn_send(ifp->srv_conn, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+  if(ifp->send_fn && ifp->generic){</span><br><span style="color: hsl(120, 100%, 40%);">+               ifp->send_fn(fi, ifp->generic, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+            return;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   if (ifp->srv_conn){</span><br><span style="color: hsl(120, 100%, 40%);">+                if(ifp->send_fn)</span><br><span style="color: hsl(120, 100%, 40%);">+                   ifp->send_fn(fi, ifp->srv_conn, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+           else</span><br><span style="color: hsl(120, 100%, 40%);">+                  ipa_server_conn_send(ifp->srv_conn, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span>    else {</span><br><span>               OSMO_ASSERT(ifp->client_conn);</span><br><span style="color: hsl(0, 100%, 40%);">-               ipa_client_conn_send(ifp->client_conn, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+               if(ifp->send_fn)</span><br><span style="color: hsl(120, 100%, 40%);">+                   ifp->send_fn(fi, ifp->client_conn, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+                else</span><br><span style="color: hsl(120, 100%, 40%);">+                  ipa_client_conn_send(ifp->client_conn, msg);</span><br><span>      }</span><br><span> }</span><br><span> </span><br><span>@@ -140,10 +154,12 @@</span><br><span>           /* PONG not received within time */</span><br><span>          if (ifp->srv_conn)</span><br><span>                        conn = ifp->srv_conn;</span><br><span style="color: hsl(0, 100%, 40%);">-                else</span><br><span style="color: hsl(120, 100%, 40%);">+          else if (ifp->client_conn)</span><br><span>                        conn = ifp->client_conn;</span><br><span style="color: hsl(120, 100%, 40%);">+           else</span><br><span style="color: hsl(120, 100%, 40%);">+                  conn = ifp->generic;</span><br><span>              if (ifp->timeout_cb)</span><br><span style="color: hsl(0, 100%, 40%);">-                 ifp->timeout_cb(fi, conn);</span><br><span style="color: hsl(120, 100%, 40%);">+                 return ifp->timeout_cb(fi, conn);</span><br><span>                 /* ask fsm core to terminate us */</span><br><span>           return 1;</span><br><span>    default:</span><br><span>@@ -261,6 +277,27 @@</span><br><span>      return fi;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! Create a new instance of an IPA keepalive FSM: Periodically transmit PING and expect PONG.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] ctx Talloc context.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] data Data to pass to write/timeout cb.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] params Parameters describing the keepalive FSM time-outs.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] id String used as identifier for the FSM.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \returns pointer to the newly-created FSM instance; NULL in case of error. */</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_fsm_inst *ipa_generic_conn_alloc_keepalive_fsm(void *ctx, void* data,</span><br><span style="color: hsl(120, 100%, 40%);">+                                                          const struct ipa_keepalive_params *params,</span><br><span style="color: hsl(120, 100%, 40%);">+                                                          const char *id)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    struct osmo_fsm_inst *fi;</span><br><span style="color: hsl(120, 100%, 40%);">+    struct ipa_fsm_priv *ifp;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    fi = __ipa_conn_alloc_keepalive_fsm(ctx, params, id);</span><br><span style="color: hsl(120, 100%, 40%);">+    if (!fi)</span><br><span style="color: hsl(120, 100%, 40%);">+        return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+    ifp = fi->priv;</span><br><span style="color: hsl(120, 100%, 40%);">+    ifp->generic = data;</span><br><span style="color: hsl(120, 100%, 40%);">+    return fi;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! Set a timeout call-back which is to be called once the peer doesn't respond anymore */</span><br><span> void ipa_keepalive_fsm_set_timeout_cb(struct osmo_fsm_inst *fi, ipa_keepalive_timeout_cb_t *cb)</span><br><span> {</span><br><span>@@ -269,6 +306,14 @@</span><br><span>       ifp->timeout_cb = cb;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! Set a custom send callback for sending pings */</span><br><span style="color: hsl(120, 100%, 40%);">+void ipa_keepalive_fsm_set_send_cb(struct osmo_fsm_inst *fi, ipa_keepalive_send_cb_t *fn)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    struct ipa_fsm_priv *ifp = fi->priv;</span><br><span style="color: hsl(120, 100%, 40%);">+    OSMO_ASSERT(fi->fsm == &ipa_keepalive_fsm);</span><br><span style="color: hsl(120, 100%, 40%);">+    ifp->send_fn = fn;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! Inform IPA Keepalive FSM that a PONG has been received. */</span><br><span> void ipa_keepalive_fsm_pong_received(struct osmo_fsm_inst *fi)</span><br><span> {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmo-abis/+/14742">change 14742</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/libosmo-abis/+/14742"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmo-abis </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ie453fdee8bfd7fc1a3f1ed67ef0331f0abb1d59b </div>
<div style="display:none"> Gerrit-Change-Number: 14742 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Hoernchen <ewild@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>