pespin has uploaded this change for review. (
https://gerrit.osmocom.org/c/libosmo-sigtran/+/38638?usp=email )
Change subject: sigtran: Make osmo_ss7_linkset APIs private
......................................................................
sigtran: Make osmo_ss7_linkset APIs private
linkset objects are managed so far exclusively through libosmo-sigtran
VTY interface, hence make the struct as well as all its APIs private.
Change-Id: I3b16f858d890b0a31780a2b85a609eae6374665a
---
M include/osmocom/sigtran/osmo_ss7.h
M src/Makefile.am
M src/osmo_ss7.c
M src/osmo_ss7_hmrt.c
A src/osmo_ss7_linkset.c
M src/osmo_ss7_route.c
M src/sccp_scrc.c
A src/ss7_linkset.h
M tests/ss7/ss7_test.c
9 files changed, 159 insertions(+), 109 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran refs/changes/38/38638/1
diff --git a/include/osmocom/sigtran/osmo_ss7.h b/include/osmocom/sigtran/osmo_ss7.h
index 002117a..e91d354 100644
--- a/include/osmocom/sigtran/osmo_ss7.h
+++ b/include/osmocom/sigtran/osmo_ss7.h
@@ -155,27 +155,7 @@
* SS7 Linksets
***********************************************************************/
-struct osmo_ss7_linkset {
- struct llist_head list;
- /*! \ref osmo_ss7_instance to which we belong */
- struct osmo_ss7_instance *inst;
- /*! array of \ref osmo_ss7_link */
- struct osmo_ss7_link *links[16];
-
- struct {
- char *name;
- char *description;
- uint32_t adjacent_pc;
- uint32_t local_pc;
- } cfg;
-};
-
-void osmo_ss7_linkset_destroy(struct osmo_ss7_linkset *lset);
-struct osmo_ss7_linkset *
-osmo_ss7_linkset_find_by_name(struct osmo_ss7_instance *inst, const char *name);
-struct osmo_ss7_linkset *
-osmo_ss7_linkset_find_or_create(struct osmo_ss7_instance *inst, const char *name,
uint32_t pc);
-
+struct osmo_ss7_linkset;
/***********************************************************************
* SS7 Routes
diff --git a/src/Makefile.am b/src/Makefile.am
index af6bae8..f92f353 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,6 +5,7 @@
noinst_HEADERS = \
sccp_internal.h \
ss7_internal.h \
+ ss7_linkset.h \
ss7_route.h \
ss7_route_table.h \
xua_asp_fsm.h \
@@ -37,6 +38,7 @@
osmo_ss7_asp.c \
osmo_ss7_asp_peer.c \
osmo_ss7_hmrt.c \
+ osmo_ss7_linkset.c \
osmo_ss7_vty.c \
osmo_ss7_xua_srv.c \
osmo_ss7_route.c \
diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c
index 37b50da..b8d8141 100644
--- a/src/osmo_ss7.c
+++ b/src/osmo_ss7.c
@@ -51,6 +51,7 @@
#include "sccp_internal.h"
#include "xua_internal.h"
#include "ss7_internal.h"
+#include "ss7_linkset.h"
#include "ss7_route.h"
#include "ss7_route_table.h"
#include "xua_asp_fsm.h"
@@ -377,7 +378,7 @@
osmo_ss7_as_destroy(as);
llist_for_each_entry_safe(lset, lset2, &inst->linksets, list)
- osmo_ss7_linkset_destroy(lset);
+ ss7_linkset_destroy(lset);
llist_del(&inst->list);
talloc_free(inst);
@@ -492,80 +493,6 @@
}
/***********************************************************************
- * SS7 Linkset
- ***********************************************************************/
-
-/*! \brief Destroy a SS7 Linkset
- * \param[in] lset Linkset to be destroyed */
-void osmo_ss7_linkset_destroy(struct osmo_ss7_linkset *lset)
-{
- struct osmo_ss7_route *rt, *rt2;
- unsigned int i;
-
- OSMO_ASSERT(ss7_initialized);
- LOGSS7(lset->inst, LOGL_INFO, "Destroying Linkset %s\n",
- lset->cfg.name);
-
- /* find any routes pointing to this AS and remove them */
- llist_for_each_entry_safe(rt, rt2, &lset->inst->rtable_system->routes,
list) {
- if (rt->dest.linkset == lset)
- ss7_route_destroy(rt);
- }
-
- for (i = 0; i < ARRAY_SIZE(lset->links); i++) {
- struct osmo_ss7_link *link = lset->links[i];
- if (!link)
- continue;
- osmo_ss7_link_destroy(link);
- }
- llist_del(&lset->list);
- talloc_free(lset);
-}
-
-/*! \brief Find SS7 Linkset by given name
- * \param[in] inst SS7 Instance in which to look
- * \param[in] name Name of SS7 Linkset
- * \returns pointer to linkset on success; NULL on error */
-struct osmo_ss7_linkset *
-osmo_ss7_linkset_find_by_name(struct osmo_ss7_instance *inst, const char *name)
-{
- struct osmo_ss7_linkset *lset;
- OSMO_ASSERT(ss7_initialized);
- llist_for_each_entry(lset, &inst->linksets, list) {
- if (!strcmp(name, lset->cfg.name))
- return lset;
- }
- return NULL;
-}
-
-/*! \brief Find or allocate SS7 Linkset
- * \param[in] inst SS7 Instance in which we operate
- * \param[in] name Name of SS7 Linkset
- * \param[in] pc Adjacent Pointcode
- * \returns pointer to Linkset on success; NULL on error */
-struct osmo_ss7_linkset *
-osmo_ss7_linkset_find_or_create(struct osmo_ss7_instance *inst, const char *name,
uint32_t pc)
-{
- struct osmo_ss7_linkset *lset;
-
- OSMO_ASSERT(ss7_initialized);
- lset = osmo_ss7_linkset_find_by_name(inst, name);
- if (lset && lset->cfg.adjacent_pc != pc)
- return NULL;
-
- if (!lset) {
- LOGSS7(inst, LOGL_INFO, "Creating Linkset %s\n", name);
- lset = talloc_zero(inst, struct osmo_ss7_linkset);
- lset->inst = inst;
- lset->cfg.adjacent_pc = pc;
- lset->cfg.name = talloc_strdup(lset, name);
- llist_add_tail(&lset->list, &inst->linksets);
- }
-
- return lset;
-}
-
-/***********************************************************************
* SS7 Link
***********************************************************************/
diff --git a/src/osmo_ss7_hmrt.c b/src/osmo_ss7_hmrt.c
index 55e5776..b0208b0 100644
--- a/src/osmo_ss7_hmrt.c
+++ b/src/osmo_ss7_hmrt.c
@@ -35,6 +35,7 @@
#include <osmocom/sigtran/protocol/m3ua.h>
#include "xua_internal.h"
+#include "ss7_linkset.h"
#include "ss7_route.h"
#include "ss7_route_table.h"
#include "ss7_internal.h"
diff --git a/src/osmo_ss7_linkset.c b/src/osmo_ss7_linkset.c
new file mode 100644
index 0000000..18af7b6
--- /dev/null
+++ b/src/osmo_ss7_linkset.c
@@ -0,0 +1,105 @@
+/* (C) 2015-2017 by Harald Welte <laforge(a)gnumonks.org>
+ * (C) 2023-2024 by sysmocom s.f.m.c. GmbH <info(a)sysmocom.de>
+ * 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_linkset.h"
+#include "ss7_route.h"
+#include "ss7_route_table.h"
+#include "ss7_internal.h"
+
+/***********************************************************************
+ * SS7 Linkset
+ ***********************************************************************/
+
+/*! \brief Destroy a SS7 Linkset
+ * \param[in] lset Linkset to be destroyed */
+void ss7_linkset_destroy(struct osmo_ss7_linkset *lset)
+{
+ struct osmo_ss7_route *rt, *rt2;
+ unsigned int i;
+
+ OSMO_ASSERT(ss7_initialized);
+ LOGSS7(lset->inst, LOGL_INFO, "Destroying Linkset %s\n",
+ lset->cfg.name);
+
+ /* find any routes pointing to this AS and remove them */
+ llist_for_each_entry_safe(rt, rt2, &lset->inst->rtable_system->routes,
list) {
+ if (rt->dest.linkset == lset)
+ ss7_route_destroy(rt);
+ }
+
+ for (i = 0; i < ARRAY_SIZE(lset->links); i++) {
+ struct osmo_ss7_link *link = lset->links[i];
+ if (!link)
+ continue;
+ osmo_ss7_link_destroy(link);
+ }
+ llist_del(&lset->list);
+ talloc_free(lset);
+}
+
+/*! \brief Find SS7 Linkset by given name
+ * \param[in] inst SS7 Instance in which to look
+ * \param[in] name Name of SS7 Linkset
+ * \returns pointer to linkset on success; NULL on error */
+struct osmo_ss7_linkset *
+ss7_linkset_find_by_name(struct osmo_ss7_instance *inst, const char *name)
+{
+ struct osmo_ss7_linkset *lset;
+ OSMO_ASSERT(ss7_initialized);
+ llist_for_each_entry(lset, &inst->linksets, list) {
+ if (!strcmp(name, lset->cfg.name))
+ return lset;
+ }
+ return NULL;
+}
+
+/*! \brief Find or allocate SS7 Linkset
+ * \param[in] inst SS7 Instance in which we operate
+ * \param[in] name Name of SS7 Linkset
+ * \param[in] pc Adjacent Pointcode
+ * \returns pointer to Linkset on success; NULL on error */
+struct osmo_ss7_linkset *
+ss7_linkset_find_or_create(struct osmo_ss7_instance *inst, const char *name, uint32_t
pc)
+{
+ struct osmo_ss7_linkset *lset;
+
+ OSMO_ASSERT(ss7_initialized);
+ lset = ss7_linkset_find_by_name(inst, name);
+ if (lset && lset->cfg.adjacent_pc != pc)
+ return NULL;
+
+ if (!lset) {
+ LOGSS7(inst, LOGL_INFO, "Creating Linkset %s\n", name);
+ lset = talloc_zero(inst, struct osmo_ss7_linkset);
+ lset->inst = inst;
+ lset->cfg.adjacent_pc = pc;
+ lset->cfg.name = talloc_strdup(lset, name);
+ llist_add_tail(&lset->list, &inst->linksets);
+ }
+
+ return lset;
+}
diff --git a/src/osmo_ss7_route.c b/src/osmo_ss7_route.c
index b5b2d93..32e3eb7 100644
--- a/src/osmo_ss7_route.c
+++ b/src/osmo_ss7_route.c
@@ -26,6 +26,7 @@
#include <osmocom/sigtran/mtp_sap.h>
#include <osmocom/sigtran/osmo_ss7.h>
+#include "ss7_linkset.h"
#include "ss7_route.h"
#include "ss7_route_table.h"
#include "ss7_internal.h"
@@ -107,7 +108,7 @@
return -EALREADY;
}
- lset = osmo_ss7_linkset_find_by_name(rtbl->inst, linkset_name);
+ lset = ss7_linkset_find_by_name(rtbl->inst, linkset_name);
if (!lset) {
as = osmo_ss7_as_find_by_name(rtbl->inst, linkset_name);
if (!as)
diff --git a/src/sccp_scrc.c b/src/sccp_scrc.c
index 5b541d3..d9eb6df 100644
--- a/src/sccp_scrc.c
+++ b/src/sccp_scrc.c
@@ -33,6 +33,7 @@
#include <osmocom/sigtran/protocol/mtp.h>
#include "sccp_internal.h"
+#include "ss7_linkset.h"
#include "ss7_route.h"
#include "xua_internal.h"
diff --git a/src/ss7_linkset.h b/src/ss7_linkset.h
new file mode 100644
index 0000000..daa442f
--- /dev/null
+++ b/src/ss7_linkset.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <stdint.h>
+#include <osmocom/core/linuxlist.h>
+
+/***********************************************************************
+ * SS7 Linksets
+ ***********************************************************************/
+
+struct osmo_ss7_instance;
+struct osmo_ss7_link;
+
+struct osmo_ss7_linkset {
+ struct llist_head list;
+ /*! \ref osmo_ss7_instance to which we belong */
+ struct osmo_ss7_instance *inst;
+ /*! array of \ref osmo_ss7_link */
+ struct osmo_ss7_link *links[16];
+
+ struct {
+ char *name;
+ char *description;
+ uint32_t adjacent_pc;
+ uint32_t local_pc;
+ } cfg;
+};
+
+void ss7_linkset_destroy(struct osmo_ss7_linkset *lset);
+struct osmo_ss7_linkset *
+ss7_linkset_find_by_name(struct osmo_ss7_instance *inst, const char *name);
+struct osmo_ss7_linkset *
+ss7_linkset_find_or_create(struct osmo_ss7_instance *inst, const char *name, uint32_t
pc);
diff --git a/tests/ss7/ss7_test.c b/tests/ss7/ss7_test.c
index 79f6912..3b6a4b3 100644
--- a/tests/ss7/ss7_test.c
+++ b/tests/ss7/ss7_test.c
@@ -1,3 +1,4 @@
+#include "../src/ss7_linkset.h"
#include "../src/ss7_route.h"
#include "../src/ss7_route_table.h"
#include "../src/xua_internal.h"
@@ -156,9 +157,9 @@
rtbl = ss7_route_table_find(s7i, "system");
OSMO_ASSERT(rtbl && rtbl == s7i->rtable_system);
- lset_a = osmo_ss7_linkset_find_or_create(s7i, "a", 100);
+ lset_a = ss7_linkset_find_or_create(s7i, "a", 100);
OSMO_ASSERT(lset_a);
- lset_b = osmo_ss7_linkset_find_or_create(s7i, "b", 200);
+ lset_b = ss7_linkset_find_or_create(s7i, "b", 200);
OSMO_ASSERT(lset_b);
/* route with full mask */
@@ -197,8 +198,8 @@
printf("route with non-consecutive mask: %s\n", osmo_ss7_route_print(rt));
ss7_route_destroy(rt);
- osmo_ss7_linkset_destroy(lset_a);
- osmo_ss7_linkset_destroy(lset_b);
+ ss7_linkset_destroy(lset_a);
+ ss7_linkset_destroy(lset_b);
}
static void test_linkset(void)
@@ -208,16 +209,16 @@
printf("Testing SS7 linkset/link\n");
- OSMO_ASSERT(osmo_ss7_linkset_find_by_name(s7i, "a") == NULL);
- OSMO_ASSERT(osmo_ss7_linkset_find_by_name(s7i, "b") == NULL);
+ OSMO_ASSERT(ss7_linkset_find_by_name(s7i, "a") == NULL);
+ OSMO_ASSERT(ss7_linkset_find_by_name(s7i, "b") == NULL);
- lset_a = osmo_ss7_linkset_find_or_create(s7i, "a", 100);
+ lset_a = ss7_linkset_find_or_create(s7i, "a", 100);
OSMO_ASSERT(lset_a);
- OSMO_ASSERT(osmo_ss7_linkset_find_by_name(s7i, "a") == lset_a);
+ OSMO_ASSERT(ss7_linkset_find_by_name(s7i, "a") == lset_a);
- lset_b = osmo_ss7_linkset_find_or_create(s7i, "b", 200);
+ lset_b = ss7_linkset_find_or_create(s7i, "b", 200);
OSMO_ASSERT(lset_b);
- OSMO_ASSERT(osmo_ss7_linkset_find_by_name(s7i, "b") == lset_b);
+ OSMO_ASSERT(ss7_linkset_find_by_name(s7i, "b") == lset_b);
l_a1 = osmo_ss7_link_find_or_create(lset_a, 1);
OSMO_ASSERT(l_a1);
@@ -232,8 +233,8 @@
osmo_ss7_link_destroy(l_a1);
osmo_ss7_link_destroy(l_a2);
- osmo_ss7_linkset_destroy(lset_a);
- osmo_ss7_linkset_destroy(lset_b);
+ ss7_linkset_destroy(lset_a);
+ ss7_linkset_destroy(lset_b);
}
static void test_as(void)
--
To view, visit
https://gerrit.osmocom.org/c/libosmo-sigtran/+/38638?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: I3b16f858d890b0a31780a2b85a609eae6374665a
Gerrit-Change-Number: 38638
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>