<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/libosmo-sccp/+/22775">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">m3ua: Move find_as_for_asp() to shared xua_find_as_for_asp()<br><br>This way the function can be re-used by SUA.<br><br>Change-Id: I0dfc5a7a24dd068002e837dc47eb0778c503cac5<br>---<br>M src/Makefile.am<br>M src/m3ua.c<br>M src/xua_internal.h<br>A src/xua_shared.c<br>4 files changed, 108 insertions(+), 56 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/Makefile.am b/src/Makefile.am</span><br><span>index 484886c..91084de 100644</span><br><span>--- a/src/Makefile.am</span><br><span>+++ b/src/Makefile.am</span><br><span>@@ -29,7 +29,7 @@</span><br><span> </span><br><span> libosmo_sigtran_la_SOURCES = sccp_sap.c sua.c m3ua.c xua_msg.c sccp_helpers.c \</span><br><span>                            sccp2sua.c sccp_scrc.c sccp_sclc.c sccp_scoc.c \</span><br><span style="color: hsl(0, 100%, 40%);">-                        sccp_user.c sccp_types.c xua_rkm.c xua_default_lm_fsm.c \</span><br><span style="color: hsl(120, 100%, 40%);">+                             sccp_user.c sccp_types.c xua_rkm.c xua_shared.c xua_default_lm_fsm.c \</span><br><span>                       osmo_ss7.c osmo_ss7_hmrt.c xua_asp_fsm.c xua_as_fsm.c \</span><br><span>                              osmo_ss7_vty.c sccp_vty.c ipa.c</span><br><span> libosmo_sigtran_la_LDFLAGS = -version-info $(LIBVERSION) -no-undefined -export-symbols-regex '^osmo_'</span><br><span>diff --git a/src/m3ua.c b/src/m3ua.c</span><br><span>index 542777e..bfb0c23 100644</span><br><span>--- a/src/m3ua.c</span><br><span>+++ b/src/m3ua.c</span><br><span>@@ -532,60 +532,6 @@</span><br><span>    return data_hdr;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/* if given ASP only has one AS, return that AS */</span><br><span style="color: hsl(0, 100%, 40%);">-static struct osmo_ss7_as *find_single_as_for_asp(const struct osmo_ss7_asp *asp)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-   struct osmo_ss7_as *as, *as_found = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-       llist_for_each_entry(as, &asp->inst->as_list, list) {</span><br><span style="color: hsl(0, 100%, 40%);">-         if (!osmo_ss7_as_has_asp(as, asp))</span><br><span style="color: hsl(0, 100%, 40%);">-                      continue;</span><br><span style="color: hsl(0, 100%, 40%);">-               /* check if we already had found another AS within this ASP -> not unique */</span><br><span style="color: hsl(0, 100%, 40%);">-         if (as_found)</span><br><span style="color: hsl(0, 100%, 40%);">-                   return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-            as_found = as;</span><br><span style="color: hsl(0, 100%, 40%);">-  }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-       return as_found;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int find_as_for_asp(struct osmo_ss7_as **as, const struct osmo_ss7_asp *asp,</span><br><span style="color: hsl(0, 100%, 40%);">-                       const struct xua_msg_part *rctx_ie)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- *as = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-     if (rctx_ie) {</span><br><span style="color: hsl(0, 100%, 40%);">-          uint32_t rctx = xua_msg_part_get_u32(rctx_ie);</span><br><span style="color: hsl(0, 100%, 40%);">-          /* Use routing context IE to look up the AS for which the</span><br><span style="color: hsl(0, 100%, 40%);">-                * message was received. */</span><br><span style="color: hsl(0, 100%, 40%);">-             *as = osmo_ss7_as_find_by_rctx(asp->inst, rctx);</span><br><span style="color: hsl(0, 100%, 40%);">-             if (!*as) {</span><br><span style="color: hsl(0, 100%, 40%);">-                     LOGPASP(asp, DLM3UA, LOGL_ERROR, "%s(): invalid routing context: %u\n",</span><br><span style="color: hsl(0, 100%, 40%);">-                               __func__, rctx);</span><br><span style="color: hsl(0, 100%, 40%);">-                        return M3UA_ERR_INVAL_ROUT_CTX;</span><br><span style="color: hsl(0, 100%, 40%);">-         }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-               /* Verify that this ASP is part of the AS. */</span><br><span style="color: hsl(0, 100%, 40%);">-           if (!osmo_ss7_as_has_asp(*as, asp)) {</span><br><span style="color: hsl(0, 100%, 40%);">-                   LOGPASP(asp, DLM3UA, LOGL_ERROR,</span><br><span style="color: hsl(0, 100%, 40%);">-                                "%s(): This Application Server Process is not part of the AS %s "</span><br><span style="color: hsl(0, 100%, 40%);">-                             "resolved by routing context %u\n", __func__, (*as)->cfg.name, rctx);</span><br><span style="color: hsl(0, 100%, 40%);">-                      return M3UA_ERR_NO_CONFGD_AS_FOR_ASP;</span><br><span style="color: hsl(0, 100%, 40%);">-           }</span><br><span style="color: hsl(0, 100%, 40%);">-       } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                /* no explicit routing context; this only works if there is only one AS in the ASP */</span><br><span style="color: hsl(0, 100%, 40%);">-           *as = find_single_as_for_asp(asp);</span><br><span style="color: hsl(0, 100%, 40%);">-              if (!*as) {</span><br><span style="color: hsl(0, 100%, 40%);">-                     LOGPASP(asp, DLM3UA, LOGL_ERROR,</span><br><span style="color: hsl(0, 100%, 40%);">-                                "%s(): ASP sent M3UA without Routing Context IE but unable to uniquely "</span><br><span style="color: hsl(0, 100%, 40%);">-                              "identify the AS for this message\n", __func__);</span><br><span style="color: hsl(0, 100%, 40%);">-                      return M3UA_ERR_INVAL_ROUT_CTX;</span><br><span style="color: hsl(0, 100%, 40%);">-         }</span><br><span style="color: hsl(0, 100%, 40%);">-       }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-       return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> static int m3ua_rx_xfer(struct osmo_ss7_asp *asp, struct xua_msg *xua)</span><br><span> {</span><br><span>    struct xua_msg_part *rctx_ie = xua_msg_find_tag(xua, M3UA_IEI_ROUTE_CTX);</span><br><span>@@ -603,7 +549,7 @@</span><br><span>              return M3UA_ERR_UNSUPP_MSG_TYPE;</span><br><span>     }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   rc = find_as_for_asp(&as, asp, rctx_ie);</span><br><span style="color: hsl(120, 100%, 40%);">+  rc = xua_find_as_for_asp(&as, asp, rctx_ie);</span><br><span>     if (rc)</span><br><span>              return rc;</span><br><span> </span><br><span>diff --git a/src/xua_internal.h b/src/xua_internal.h</span><br><span>index d836fae..65adfb6 100644</span><br><span>--- a/src/xua_internal.h</span><br><span>+++ b/src/xua_internal.h</span><br><span>@@ -69,6 +69,8 @@</span><br><span> </span><br><span> int xua_as_transmit_msg(struct osmo_ss7_as *as, struct msgb *msg);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+int xua_find_as_for_asp(struct osmo_ss7_as **as, const struct osmo_ss7_asp *asp,</span><br><span style="color: hsl(120, 100%, 40%);">+                       const struct xua_msg_part *rctx_ie);</span><br><span> </span><br><span> int ipa_tx_xua_as(struct osmo_ss7_as *as, struct xua_msg *xua);</span><br><span> int ipa_rx_msg(struct osmo_ss7_asp *asp, struct msgb *msg);</span><br><span>diff --git a/src/xua_shared.c b/src/xua_shared.c</span><br><span>new file mode 100644</span><br><span>index 0000000..cdd6f7f</span><br><span>--- /dev/null</span><br><span>+++ b/src/xua_shared.c</span><br><span>@@ -0,0 +1,104 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/* Shared code between M3UA and SUA implementation */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* (C) 2015-2021 by Harald Welte <laforge@gnumonks.org></span><br><span style="color: hsl(120, 100%, 40%);">+ * All Rights Reserved</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * SPDX-License-Identifier: GPL-2.0+</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; either version 2 of the License, or</span><br><span style="color: hsl(120, 100%, 40%);">+ * (at your option) any later version.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * You should have received a copy of the GNU General Public License</span><br><span style="color: hsl(120, 100%, 40%);">+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdint.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <unistd.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <string.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/utils.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/linuxlist.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/logging.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/sigtran/xua_msg.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/sigtran/osmo_ss7.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/sigtran/protocol/m3ua.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/sigtran/protocol/sua.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include "xua_internal.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* if given ASP only has one AS, return that AS */</span><br><span style="color: hsl(120, 100%, 40%);">+static struct osmo_ss7_as *find_single_as_for_asp(const struct osmo_ss7_asp *asp)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  struct osmo_ss7_as *as, *as_found = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   llist_for_each_entry(as, &asp->inst->as_list, list) {</span><br><span style="color: hsl(120, 100%, 40%);">+               if (!osmo_ss7_as_has_asp(as, asp))</span><br><span style="color: hsl(120, 100%, 40%);">+                    continue;</span><br><span style="color: hsl(120, 100%, 40%);">+             /* check if we already had found another AS within this ASP -> not unique */</span><br><span style="color: hsl(120, 100%, 40%);">+               if (as_found)</span><br><span style="color: hsl(120, 100%, 40%);">+                 return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+          as_found = as;</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%);">+   return as_found;</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%);">+/* this is why we can use the M3UA constants below in a function shared between M3UA + SUA */</span><br><span style="color: hsl(120, 100%, 40%);">+osmo_static_assert(M3UA_ERR_INVAL_ROUT_CTX == SUA_ERR_INVAL_ROUT_CTX, _err_rctx);</span><br><span style="color: hsl(120, 100%, 40%);">+osmo_static_assert(M3UA_ERR_NO_CONFGD_AS_FOR_ASP == SUA_ERR_NO_CONFGD_AS_FOR_ASP, _err_as_for_asp);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! Find the AS for given ASP + optional routing context IE.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  if rctx_ie == NULL, we assume that this ASP is only part of a single AS;</span><br><span style="color: hsl(120, 100%, 40%);">+ *  if rctx_ie is given, then we look-up the ASP based on the routing context,</span><br><span style="color: hsl(120, 100%, 40%);">+ *  and verify that this ASP is part of it.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[out] as caller-provided address-of-pointer to store the found AS</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] asp ASP for which we want to look-up the AS</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] rctx_ie routing context IE (may be NULL) to use for look-up</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \returns 0 in case of success; {M3UA,SUA}_ERR_* code in case of error. */</span><br><span style="color: hsl(120, 100%, 40%);">+int xua_find_as_for_asp(struct osmo_ss7_as **as, const struct osmo_ss7_asp *asp,</span><br><span style="color: hsl(120, 100%, 40%);">+                 const struct xua_msg_part *rctx_ie)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        int log_ss = osmo_ss7_asp_get_log_subsys(asp);</span><br><span style="color: hsl(120, 100%, 40%);">+        *as = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rctx_ie) {</span><br><span style="color: hsl(120, 100%, 40%);">+                uint32_t rctx = xua_msg_part_get_u32(rctx_ie);</span><br><span style="color: hsl(120, 100%, 40%);">+                /* Use routing context IE to look up the AS for which the</span><br><span style="color: hsl(120, 100%, 40%);">+              * message was received. */</span><br><span style="color: hsl(120, 100%, 40%);">+           *as = osmo_ss7_as_find_by_rctx(asp->inst, rctx);</span><br><span style="color: hsl(120, 100%, 40%);">+           if (!*as) {</span><br><span style="color: hsl(120, 100%, 40%);">+                   LOGPASP(asp, log_ss, LOGL_ERROR, "%s(): invalid routing context: %u\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                             __func__, rctx);</span><br><span style="color: hsl(120, 100%, 40%);">+                      return M3UA_ERR_INVAL_ROUT_CTX;</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%);">+           /* Verify that this ASP is part of the AS. */</span><br><span style="color: hsl(120, 100%, 40%);">+         if (!osmo_ss7_as_has_asp(*as, asp)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                 LOGPASP(asp, log_ss, LOGL_ERROR,</span><br><span style="color: hsl(120, 100%, 40%);">+                              "%s(): This Application Server Process is not part of the AS %s "</span><br><span style="color: hsl(120, 100%, 40%);">+                           "resolved by routing context %u\n", __func__, (*as)->cfg.name, rctx);</span><br><span style="color: hsl(120, 100%, 40%);">+                    return M3UA_ERR_NO_CONFGD_AS_FOR_ASP;</span><br><span style="color: hsl(120, 100%, 40%);">+         }</span><br><span style="color: hsl(120, 100%, 40%);">+     } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              /* no explicit routing context; this only works if there is only one AS in the ASP */</span><br><span style="color: hsl(120, 100%, 40%);">+         *as = find_single_as_for_asp(asp);</span><br><span style="color: hsl(120, 100%, 40%);">+            if (!*as) {</span><br><span style="color: hsl(120, 100%, 40%);">+                   LOGPASP(asp, log_ss, LOGL_ERROR,</span><br><span style="color: hsl(120, 100%, 40%);">+                              "%s(): ASP sent M3UA without Routing Context IE but unable to uniquely "</span><br><span style="color: hsl(120, 100%, 40%);">+                            "identify the AS for this message\n", __func__);</span><br><span style="color: hsl(120, 100%, 40%);">+                    return M3UA_ERR_INVAL_ROUT_CTX;</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmo-sccp/+/22775">change 22775</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-sccp/+/22775"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmo-sccp </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I0dfc5a7a24dd068002e837dc47eb0778c503cac5 </div>
<div style="display:none"> Gerrit-Change-Number: 22775 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </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-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>