pespin has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmo-sigtran/+/38640?usp=email )

Change subject: sigtran: Make osmo_ss7_user struct private
......................................................................

sigtran: Make osmo_ss7_user struct private

ss7_user objects are managed so far exclusively through libosmo-sigtran
internal upper layers (SCCP), hence make the struct as well as all its
APIs private.

API ss7_mtp_to_user() is also made private since that's only meant for
internal use from lower layers in the library.

Change-Id: I59d8f70aa81ba396159af40ffd7e8cc6c27cb864
---
M include/osmocom/sigtran/osmo_ss7.h
M src/Makefile.am
M src/osmo_ss7.c
M src/osmo_ss7_hmrt.c
M src/osmo_ss7_user.c
M src/sccp_internal.h
A src/ss7_user.h
M tests/ss7/ss7_test.c
8 files changed, 109 insertions(+), 93 deletions(-)

Approvals:
  Jenkins Builder: Verified
  fixeria: Looks good to me, but someone else must approve
  osmith: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved




diff --git a/include/osmocom/sigtran/osmo_ss7.h 
b/include/osmocom/sigtran/osmo_ss7.h
index ccf2247..47e25d2 100644
--- a/include/osmocom/sigtran/osmo_ss7.h
+++ b/include/osmocom/sigtran/osmo_ss7.h
@@ -117,16 +117,8 @@
  * MTP Users (Users of MTP, such as SCCP or ISUP)
  ***********************************************************************/

-struct osmo_ss7_user {
-       /* pointer back to SS7 instance */
-       struct osmo_ss7_instance *inst;
-       /* name of the user */
-       const char *name;
-       /* primitive call-back for incoming MTP primitives */
-       osmo_prim_cb prim_cb;
-       /* private data */
-       void *priv;
-};
+struct osmo_ss7_user;
+

 struct osmo_ss7_user *osmo_ss7_user_create(struct osmo_ss7_instance *inst, 
const char *name);
 void osmo_ss7_user_destroy(struct osmo_ss7_user *user);
@@ -141,8 +133,6 @@
 int osmo_ss7_user_unregister(struct osmo_ss7_instance *inst, uint8_t 
service_ind,
                             struct osmo_ss7_user *user);

-int osmo_ss7_mtp_to_user(struct osmo_ss7_instance *inst, struct osmo_mtp_prim 
*omp);
-
 /* SS7 User wants to issue MTP-TRANSFER.req */
 int osmo_ss7_user_mtp_xfer_req(struct osmo_ss7_instance *inst,
                                struct osmo_mtp_prim *omp);
diff --git a/src/Makefile.am b/src/Makefile.am
index 44e6c34..8f848de 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,6 +9,7 @@
        ss7_linkset.h \
        ss7_route.h \
        ss7_route_table.h \
+       ss7_user.h \
        ss7_xua_srv.h \
        xua_asp_fsm.h \
        xua_as_fsm.h \
diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c
index 3659516..63456a0 100644
--- a/src/osmo_ss7.c
+++ b/src/osmo_ss7.c
@@ -462,84 +462,6 @@
 }

 /***********************************************************************
- * MTP Users (Users of MTP, such as SCCP or ISUP)
- ***********************************************************************/
-
-/*! \brief Register a MTP user for a given service indicator
- *  \param[in] inst SS7 instance for which we register the user
- *  \param[in] service_ind Service (ISUP, SCCP, ...)
- *  \param[in] user SS7 user (including primitive call-back)
- *  \returns 0 on success; negative on error */
-int osmo_ss7_user_register(struct osmo_ss7_instance *inst, uint8_t service_ind,
-                          struct osmo_ss7_user *user)
-{
-       if (service_ind >= ARRAY_SIZE(inst->user))
-               return -EINVAL;
-
-       if (inst->user[service_ind])
-               return -EBUSY;
-
-       DEBUGP(DLSS7, "registering user=%s for SI %u with priv %p\n",
-               user->name, service_ind, user->priv);
-
-       user->inst = inst;
-       inst->user[service_ind] = user;
-
-       return 0;
-}
-
-/*! \brief Unregister a MTP user for a given service indicator
- *  \param[in] inst SS7 instance for which we register the user
- *  \param[in] service_ind Service (ISUP, SCCP, ...)
- *  \param[in] user (optional) SS7 user. If present, we will not
- *             unregister other users
- *  \returns 0 on success; negative on error */
-int osmo_ss7_user_unregister(struct osmo_ss7_instance *inst, uint8_t 
service_ind,
-                            struct osmo_ss7_user *user)
-{
-       if (service_ind >= ARRAY_SIZE(inst->user))
-               return -EINVAL;
-
-       if (!inst->user[service_ind])
-               return -ENODEV;
-
-       if (user && (inst->user[service_ind] != user))
-               return -EINVAL;
-
-       if (user)
-               user->inst = NULL;
-       inst->user[service_ind] = NULL;
-
-       return 0;
-}
-
-/* deliver to a local MTP user */
-int osmo_ss7_mtp_to_user(struct osmo_ss7_instance *inst, struct osmo_mtp_prim 
*omp)
-{
-       uint32_t service_ind;
-       const struct osmo_ss7_user *osu;
-
-       if (omp->oph.sap != MTP_SAP_USER ||
-           omp->oph.primitive != OSMO_MTP_PRIM_TRANSFER ||
-           omp->oph.operation != PRIM_OP_INDICATION) {
-               LOGP(DLSS7, LOGL_ERROR, "Unsupported Primitive\n");
-               return -EINVAL;
-       }
-
-       service_ind = omp->u.transfer.sio & 0xF;
-       osu = inst->user[service_ind];
-
-       if (!osu) {
-               LOGP(DLSS7, LOGL_NOTICE, "No MTP-User for SI %u\n", 
service_ind);
-               return -ENODEV;
-       }
-
-       DEBUGP(DLSS7, "delivering MTP-TRANSFER.ind to user %s, priv=%p\n",
-               osu->name, osu->priv);
-       return osu->prim_cb(&omp->oph, (void *) osu->priv);
-}
-
-/***********************************************************************
  * SS7 Application Server
  ***********************************************************************/

diff --git a/src/osmo_ss7_hmrt.c b/src/osmo_ss7_hmrt.c
index b0208b0..e504cb1 100644
--- a/src/osmo_ss7_hmrt.c
+++ b/src/osmo_ss7_hmrt.c
@@ -39,6 +39,7 @@
 #include "ss7_route.h"
 #include "ss7_route_table.h"
 #include "ss7_internal.h"
+#include "ss7_user.h"

 /* convert from M3UA message to MTP-TRANSFER.ind osmo_mtp_prim */
 struct osmo_mtp_prim *m3ua_to_xfer_ind(struct xua_msg *xua)
diff --git a/src/osmo_ss7_user.c b/src/osmo_ss7_user.c
index 3aea3a9..e7d0483 100644
--- a/src/osmo_ss7_user.c
+++ b/src/osmo_ss7_user.c
@@ -27,6 +27,7 @@
 #include <osmocom/core/prim.h>
 #include <osmocom/sigtran/osmo_ss7.h>

+#include "ss7_user.h"
 #include "ss7_internal.h"

 /***********************************************************************
@@ -69,3 +70,77 @@
 {
        return user->priv;
 }
+
+/*! \brief Register a MTP user for a given service indicator
+ *  \param[in] inst SS7 instance for which we register the user
+ *  \param[in] service_ind Service (ISUP, SCCP, ...)
+ *  \param[in] user SS7 user (including primitive call-back)
+ *  \returns 0 on success; negative on error */
+int osmo_ss7_user_register(struct osmo_ss7_instance *inst, uint8_t service_ind,
+                          struct osmo_ss7_user *user)
+{
+       if (service_ind >= ARRAY_SIZE(inst->user))
+               return -EINVAL;
+
+       if (inst->user[service_ind])
+               return -EBUSY;
+
+       DEBUGP(DLSS7, "registering user=%s for SI %u with priv %p\n",
+               user->name, service_ind, user->priv);
+
+       user->inst = inst;
+       inst->user[service_ind] = user;
+
+       return 0;
+}
+
+/*! \brief Unregister a MTP user for a given service indicator
+ *  \param[in] inst SS7 instance for which we register the user
+ *  \param[in] service_ind Service (ISUP, SCCP, ...)
+ *  \param[in] user (optional) SS7 user. If present, we will not
+ *             unregister other users
+ *  \returns 0 on success; negative on error */
+int osmo_ss7_user_unregister(struct osmo_ss7_instance *inst, uint8_t 
service_ind,
+                            struct osmo_ss7_user *user)
+{
+       if (service_ind >= ARRAY_SIZE(inst->user))
+               return -EINVAL;
+
+       if (!inst->user[service_ind])
+               return -ENODEV;
+
+       if (user && (inst->user[service_ind] != user))
+               return -EINVAL;
+
+       if (user)
+               user->inst = NULL;
+       inst->user[service_ind] = NULL;
+
+       return 0;
+}
+
+/* deliver to a local MTP user */
+int ss7_mtp_to_user(struct osmo_ss7_instance *inst, struct osmo_mtp_prim *omp)
+{
+       uint32_t service_ind;
+       const struct osmo_ss7_user *osu;
+
+       if (omp->oph.sap != MTP_SAP_USER ||
+           omp->oph.primitive != OSMO_MTP_PRIM_TRANSFER ||
+           omp->oph.operation != PRIM_OP_INDICATION) {
+               LOGP(DLSS7, LOGL_ERROR, "Unsupported Primitive\n");
+               return -EINVAL;
+       }
+
+       service_ind = omp->u.transfer.sio & 0xF;
+       osu = inst->user[service_ind];
+
+       if (!osu) {
+               LOGP(DLSS7, LOGL_NOTICE, "No MTP-User for SI %u\n", 
service_ind);
+               return -ENODEV;
+       }
+
+       DEBUGP(DLSS7, "delivering MTP-TRANSFER.ind to user %s, priv=%p\n",
+               osu->name, osu->priv);
+       return osu->prim_cb(&omp->oph, (void *) osu->priv);
+}
diff --git a/src/sccp_internal.h b/src/sccp_internal.h
index dedcdcd..45df22d 100644
--- a/src/sccp_internal.h
+++ b/src/sccp_internal.h
@@ -11,6 +11,8 @@

 #define SCCP_STR "Signalling Connection Control Part\n"

+#include "ss7_user.h"
+
 /* Appendix C.4 of Q.714 */
 enum osmo_sccp_timer {
        /* 0 kept unused on purpose since it's handled specially by osmo_fsm */
diff --git a/src/ss7_user.h b/src/ss7_user.h
new file mode 100644
index 0000000..6021330
--- /dev/null
+++ b/src/ss7_user.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <stdint.h>
+#include <osmocom/core/prim.h>
+#include <osmocom/sigtran/mtp_sap.h>
+
+/***********************************************************************
+ * SS7 Linksets
+ ***********************************************************************/
+
+struct osmo_ss7_instance;
+
+struct osmo_ss7_user {
+       /* pointer back to SS7 instance */
+       struct osmo_ss7_instance *inst;
+       /* name of the user */
+       const char *name;
+       /* primitive call-back for incoming MTP primitives */
+       osmo_prim_cb prim_cb;
+       /* private data */
+       void *priv;
+};
+
+int ss7_mtp_to_user(struct osmo_ss7_instance *inst, struct osmo_mtp_prim *omp);
diff --git a/tests/ss7/ss7_test.c b/tests/ss7/ss7_test.c
index 5211fe6..9be7434 100644
--- a/tests/ss7/ss7_test.c
+++ b/tests/ss7/ss7_test.c
@@ -2,6 +2,7 @@
 #include "../src/ss7_linkset.h"
 #include "../src/ss7_route.h"
 #include "../src/ss7_route_table.h"
+#include "../src/ss7_user.h"
 #include "../src/xua_internal.h"
 #include "../src/xua_asp_fsm.h"

@@ -125,7 +126,7 @@
        OSMO_ASSERT(osmo_ss7_user_register(s7i, 255, NULL) == -EINVAL);

        /* primitive delivery */
-       OSMO_ASSERT(osmo_ss7_mtp_to_user(s7i, &omp) == 23);
+       OSMO_ASSERT(ss7_mtp_to_user(s7i, &omp) == 23);

        /* cleanup */
        OSMO_ASSERT(osmo_ss7_user_unregister(s7i, 255, NULL) == -EINVAL);
@@ -134,11 +135,11 @@
        OSMO_ASSERT(osmo_ss7_user_unregister(s7i, 1, user) == 0);

        /* primitive delivery should fail now */
-       OSMO_ASSERT(osmo_ss7_mtp_to_user(s7i, &omp) == -ENODEV);
+       OSMO_ASSERT(ss7_mtp_to_user(s7i, &omp) == -ENODEV);

        /* wrong primitive delivery should also fail */
        omp.oph.primitive = OSMO_MTP_PRIM_PAUSE;
-       OSMO_ASSERT(osmo_ss7_mtp_to_user(s7i, &omp) == -EINVAL);
+       OSMO_ASSERT(ss7_mtp_to_user(s7i, &omp) == -EINVAL);

        osmo_ss7_user_destroy(user);
        osmo_ss7_user_destroy(user2);

--
To view, visit https://gerrit.osmocom.org/c/libosmo-sigtran/+/38640?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: libosmo-sigtran
Gerrit-Branch: master
Gerrit-Change-Id: I59d8f70aa81ba396159af40ffd7e8cc6c27cb864
Gerrit-Change-Number: 38640
Gerrit-PatchSet: 10
Gerrit-Owner: pespin <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>

Reply via email to