pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmo-sigtran/+/38639?usp=email )


Change subject: sigtran: Make osmo_ss7_link APIs private
......................................................................

sigtran: Make osmo_ss7_link APIs private

link objects are managed so far exclusively through libosmo-sigtran
VTY interface, hence make the struct as well as all its APIs private.

Change-Id: Ia6fa48bdc23adb15579852cff4873f654b3bf029
---
M include/osmocom/sigtran/osmo_ss7.h
M src/Makefile.am
M src/osmo_ss7.c
A src/osmo_ss7_link.c
M src/osmo_ss7_linkset.c
A src/ss7_link.h
M tests/ss7/ss7_test.c
7 files changed, 121 insertions(+), 78 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran 
refs/changes/39/38639/1

diff --git a/include/osmocom/sigtran/osmo_ss7.h 
b/include/osmocom/sigtran/osmo_ss7.h
index e91d354..9a754cd 100644
--- a/include/osmocom/sigtran/osmo_ss7.h
+++ b/include/osmocom/sigtran/osmo_ss7.h
@@ -125,32 +125,8 @@
  * SS7 Links
  ***********************************************************************/

-enum osmo_ss7_link_adm_state {
-       OSMO_SS7_LS_SHUTDOWN,
-       OSMO_SS7_LS_INHIBITED,
-       OSMO_SS7_LS_ENABLED,
-       _NUM_OSMO_SS7_LS
-};
-
-struct osmo_ss7_linkset;
 struct osmo_ss7_link;

-struct osmo_ss7_link {
-       /*! \ref osmo_ss7_linkset to which we belong */
-       struct osmo_ss7_linkset *linkset;
-       struct {
-               char *name;
-               char *description;
-               uint32_t id;
-
-               enum osmo_ss7_link_adm_state adm_state;
-       } cfg;
-};
-
-void osmo_ss7_link_destroy(struct osmo_ss7_link *link);
-struct osmo_ss7_link *
-osmo_ss7_link_find_or_create(struct osmo_ss7_linkset *lset, uint32_t id);
-
 /***********************************************************************
  * SS7 Linksets
  ***********************************************************************/
diff --git a/src/Makefile.am b/src/Makefile.am
index f92f353..6dd338e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,6 +5,7 @@
 noinst_HEADERS = \
        sccp_internal.h \
        ss7_internal.h \
+       ss7_link.h \
        ss7_linkset.h \
        ss7_route.h \
        ss7_route_table.h \
@@ -38,6 +39,7 @@
        osmo_ss7_asp.c \
        osmo_ss7_asp_peer.c \
        osmo_ss7_hmrt.c \
+       osmo_ss7_link.c \
        osmo_ss7_linkset.c \
        osmo_ss7_vty.c \
        osmo_ss7_xua_srv.c \
diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c
index b8d8141..8f6d417 100644
--- a/src/osmo_ss7.c
+++ b/src/osmo_ss7.c
@@ -493,53 +493,6 @@
 }

 /***********************************************************************
- * SS7 Link
- ***********************************************************************/
-
-/*! \brief Destroy SS7 Link
- *  \param[in] link SS7 Link to be destroyed */
-void osmo_ss7_link_destroy(struct osmo_ss7_link *link)
-{
-       struct osmo_ss7_linkset *lset = link->linkset;
-
-       OSMO_ASSERT(ss7_initialized);
-       LOGSS7(lset->inst, LOGL_INFO, "Destroying Link %s:%u\n",
-               lset->cfg.name, link->cfg.id);
-       /* FIXME: do cleanup */
-       lset->links[link->cfg.id] = NULL;
-       talloc_free(link);
-}
-
-/*! \brief Find or create SS7 Link with given ID in given Linkset
- *  \param[in] lset SS7 Linkset on which we operate
- *  \param[in] id Link number within Linkset
- *  \returns pointer to SS7 Link on success; NULL on error */
-struct osmo_ss7_link *
-osmo_ss7_link_find_or_create(struct osmo_ss7_linkset *lset, uint32_t id)
-{
-       struct osmo_ss7_link *link;
-
-       OSMO_ASSERT(ss7_initialized);
-       if (id >= ARRAY_SIZE(lset->links))
-               return NULL;
-
-       if (lset->links[id]) {
-               link = lset->links[id];
-       } else {
-               LOGSS7(lset->inst, LOGL_INFO, "Creating Link %s:%u\n",
-                       lset->cfg.name, id);
-               link = talloc_zero(lset, struct osmo_ss7_link);
-               if (!link)
-                       return NULL;
-               link->linkset = lset;
-               lset->links[id] = link;
-               link->cfg.id = id;
-       }
-
-       return link;
-}
-
-/***********************************************************************
  * SS7 Application Server
  ***********************************************************************/

diff --git a/src/osmo_ss7_link.c b/src/osmo_ss7_link.c
new file mode 100644
index 0000000..321d72e
--- /dev/null
+++ b/src/osmo_ss7_link.c
@@ -0,0 +1,77 @@
+/* (C) 2015-2017 by Harald Welte <[email protected]>
+ * (C) 2023-2024 by sysmocom s.f.m.c. GmbH <[email protected]>
+ * All Rights Reserved
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <errno.h>
+
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/logging.h>
+#include <osmocom/sigtran/osmo_ss7.h>
+
+#include "ss7_link.h"
+#include "ss7_linkset.h"
+#include "ss7_internal.h"
+
+/***********************************************************************
+ * SS7 Link
+ ***********************************************************************/
+
+/*! \brief Destroy SS7 Link
+ *  \param[in] link SS7 Link to be destroyed */
+void ss7_link_destroy(struct osmo_ss7_link *link)
+{
+       struct osmo_ss7_linkset *lset = link->linkset;
+
+       OSMO_ASSERT(ss7_initialized);
+       LOGSS7(lset->inst, LOGL_INFO, "Destroying Link %s:%u\n",
+               lset->cfg.name, link->cfg.id);
+       /* FIXME: do cleanup */
+       lset->links[link->cfg.id] = NULL;
+       talloc_free(link);
+}
+
+/*! \brief Find or create SS7 Link with given ID in given Linkset
+ *  \param[in] lset SS7 Linkset on which we operate
+ *  \param[in] id Link number within Linkset
+ *  \returns pointer to SS7 Link on success; NULL on error */
+struct osmo_ss7_link *
+ss7_link_find_or_create(struct osmo_ss7_linkset *lset, uint32_t id)
+{
+       struct osmo_ss7_link *link;
+
+       OSMO_ASSERT(ss7_initialized);
+       if (id >= ARRAY_SIZE(lset->links))
+               return NULL;
+
+       if (lset->links[id]) {
+               link = lset->links[id];
+       } else {
+               LOGSS7(lset->inst, LOGL_INFO, "Creating Link %s:%u\n",
+                       lset->cfg.name, id);
+               link = talloc_zero(lset, struct osmo_ss7_link);
+               if (!link)
+                       return NULL;
+               link->linkset = lset;
+               lset->links[id] = link;
+               link->cfg.id = id;
+       }
+
+       return link;
+}
diff --git a/src/osmo_ss7_linkset.c b/src/osmo_ss7_linkset.c
index 18af7b6..9e0b17b 100644
--- a/src/osmo_ss7_linkset.c
+++ b/src/osmo_ss7_linkset.c
@@ -25,6 +25,7 @@
 #include <osmocom/core/logging.h>
 #include <osmocom/sigtran/osmo_ss7.h>

+#include "ss7_link.h"
 #include "ss7_linkset.h"
 #include "ss7_route.h"
 #include "ss7_route_table.h"
@@ -55,7 +56,7 @@
                struct osmo_ss7_link *link = lset->links[i];
                if (!link)
                        continue;
-               osmo_ss7_link_destroy(link);
+               ss7_link_destroy(link);
        }
        llist_del(&lset->list);
        talloc_free(lset);
diff --git a/src/ss7_link.h b/src/ss7_link.h
new file mode 100644
index 0000000..5ea6556
--- /dev/null
+++ b/src/ss7_link.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <stdint.h>
+#include <osmocom/core/linuxlist.h>
+
+/***********************************************************************
+ * SS7 Linksets
+ ***********************************************************************/
+
+struct osmo_ss7_linkset;
+
+enum osmo_ss7_link_adm_state {
+       OSMO_SS7_LS_SHUTDOWN,
+       OSMO_SS7_LS_INHIBITED,
+       OSMO_SS7_LS_ENABLED,
+       _NUM_OSMO_SS7_LS
+};
+
+struct osmo_ss7_link {
+       /*! \ref osmo_ss7_linkset to which we belong */
+       struct osmo_ss7_linkset *linkset;
+       struct {
+               char *name;
+               char *description;
+               uint32_t id;
+
+               enum osmo_ss7_link_adm_state adm_state;
+       } cfg;
+};
+
+void ss7_link_destroy(struct osmo_ss7_link *link);
+struct osmo_ss7_link *
+ss7_link_find_or_create(struct osmo_ss7_linkset *lset, uint32_t id);
diff --git a/tests/ss7/ss7_test.c b/tests/ss7/ss7_test.c
index 3b6a4b3..7d4ec5f 100644
--- a/tests/ss7/ss7_test.c
+++ b/tests/ss7/ss7_test.c
@@ -1,3 +1,4 @@
+#include "../src/ss7_link.h"
 #include "../src/ss7_linkset.h"
 #include "../src/ss7_route.h"
 #include "../src/ss7_route_table.h"
@@ -220,18 +221,18 @@
        OSMO_ASSERT(lset_b);
        OSMO_ASSERT(ss7_linkset_find_by_name(s7i, "b") == lset_b);

-       l_a1 = osmo_ss7_link_find_or_create(lset_a, 1);
+       l_a1 = ss7_link_find_or_create(lset_a, 1);
        OSMO_ASSERT(l_a1);
-       l_a2 = osmo_ss7_link_find_or_create(lset_a, 2);
+       l_a2 = ss7_link_find_or_create(lset_a, 2);
        OSMO_ASSERT(l_a2);

        /* ID too high */
-       OSMO_ASSERT(osmo_ss7_link_find_or_create(lset_a, 1000) == NULL);
+       OSMO_ASSERT(ss7_link_find_or_create(lset_a, 1000) == NULL);
        /* already exists */
-       OSMO_ASSERT(osmo_ss7_link_find_or_create(lset_a, 1) == l_a1);
+       OSMO_ASSERT(ss7_link_find_or_create(lset_a, 1) == l_a1);

-       osmo_ss7_link_destroy(l_a1);
-       osmo_ss7_link_destroy(l_a2);
+       ss7_link_destroy(l_a1);
+       ss7_link_destroy(l_a2);

        ss7_linkset_destroy(lset_a);
        ss7_linkset_destroy(lset_b);

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

Gerrit-MessageType: newchange
Gerrit-Project: libosmo-sigtran
Gerrit-Branch: master
Gerrit-Change-Id: Ia6fa48bdc23adb15579852cff4873f654b3bf029
Gerrit-Change-Number: 38639
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>

Reply via email to