pespin has uploaded this change for review. (
https://gerrit.osmocom.org/c/libosmo-sigtran/+/38626?usp=email )
Change subject: Make osmo_ss7_route_table APIs private
......................................................................
Make osmo_ss7_route_table APIs private
The routing table is actually handled internally through VTY and no user
is making use of it.
Make it private, to ease extension in the future (it will be extended
to eg. support combined link load sharing).
Change-Id: Ie7c709c9849ef3d50aef94f79751c9c4a010c92a
---
M include/osmocom/sigtran/osmo_ss7.h
M src/Makefile.am
M src/osmo_ss7.c
M src/osmo_ss7_as.c
M src/osmo_ss7_hmrt.c
A src/osmo_ss7_route_table.c
M src/osmo_ss7_vty.c
A src/ss7_route_table.h
M tests/ss7/ss7_test.c
9 files changed, 115 insertions(+), 74 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran refs/changes/26/38626/1
diff --git a/include/osmocom/sigtran/osmo_ss7.h b/include/osmocom/sigtran/osmo_ss7.h
index 049c7d8..1fb4cfc 100644
--- a/include/osmocom/sigtran/osmo_ss7.h
+++ b/include/osmocom/sigtran/osmo_ss7.h
@@ -18,6 +18,7 @@
struct osmo_sccp_instance;
struct osmo_mtp_prim;
struct osmo_xua_layer_manager;
+struct osmo_ss7_route_table;
int osmo_ss7_init(void);
int osmo_ss7_find_free_rctx(struct osmo_ss7_instance *inst);
@@ -38,30 +39,6 @@
}
/***********************************************************************
- * SS7 Routing Tables
- ***********************************************************************/
-
-struct osmo_ss7_route_table {
- /*! member in list of routing tables */
- struct llist_head list;
- /*! \ref osmo_ss7_instance to which we belong */
- struct osmo_ss7_instance *inst;
- /*! list of \ref osmo_ss7_route */
- struct llist_head routes;
-
- struct {
- char *name;
- char *description;
- } cfg;
-};
-
-struct osmo_ss7_route_table *
-osmo_ss7_route_table_find(struct osmo_ss7_instance *inst, const char *name);
-struct osmo_ss7_route_table *
-osmo_ss7_route_table_find_or_create(struct osmo_ss7_instance *inst, const char *name);
-void osmo_ss7_route_table_destroy(struct osmo_ss7_route_table *rtbl);
-
-/***********************************************************************
* SS7 Instances
***********************************************************************/
diff --git a/src/Makefile.am b/src/Makefile.am
index 2a257ae..5dddb05 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,6 +5,7 @@
noinst_HEADERS = \
sccp_internal.h \
ss7_internal.h \
+ ss7_route_table.h \
xua_asp_fsm.h \
xua_as_fsm.h \
xua_internal.h \
@@ -37,6 +38,7 @@
osmo_ss7_hmrt.c \
osmo_ss7_vty.c \
osmo_ss7_xua_srv.c \
+ osmo_ss7_route_table.c \
sccp2sua.c \
sccp_helpers.c \
sccp_lbcs.c \
diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c
index 93bcfc2..1a19e2a 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_route_table.h"
#include "xua_asp_fsm.h"
#include "xua_as_fsm.h"
@@ -342,7 +343,7 @@
INIT_LLIST_HEAD(&inst->asp_list);
INIT_LLIST_HEAD(&inst->rtable_list);
INIT_LLIST_HEAD(&inst->xua_servers);
- inst->rtable_system = osmo_ss7_route_table_find_or_create(inst, "system");
+ inst->rtable_system = ss7_route_table_find_or_create(inst, "system");
/* default point code structure + formatting */
inst->cfg.pc_fmt.delimiter = '.';
@@ -610,49 +611,6 @@
return link;
}
-
-/***********************************************************************
- * SS7 Route Tables
- ***********************************************************************/
-
-struct osmo_ss7_route_table *
-osmo_ss7_route_table_find(struct osmo_ss7_instance *inst, const char *name)
-{
- struct osmo_ss7_route_table *rtbl;
- OSMO_ASSERT(ss7_initialized);
- llist_for_each_entry(rtbl, &inst->rtable_list, list) {
- if (!strcmp(rtbl->cfg.name, name))
- return rtbl;
- }
- return NULL;
-}
-
-struct osmo_ss7_route_table *
-osmo_ss7_route_table_find_or_create(struct osmo_ss7_instance *inst, const char *name)
-{
- struct osmo_ss7_route_table *rtbl;
-
- OSMO_ASSERT(ss7_initialized);
- rtbl = osmo_ss7_route_table_find(inst, name);
- if (!rtbl) {
- LOGSS7(inst, LOGL_INFO, "Creating Route Table %s\n", name);
- rtbl = talloc_zero(inst, struct osmo_ss7_route_table);
- rtbl->inst = inst;
- rtbl->cfg.name = talloc_strdup(rtbl, name);
- INIT_LLIST_HEAD(&rtbl->routes);
- llist_add_tail(&rtbl->list, &inst->rtable_list);
- }
- return rtbl;
-}
-
-void osmo_ss7_route_table_destroy(struct osmo_ss7_route_table *rtbl)
-{
- llist_del(&rtbl->list);
- /* routes are allocated as children of route table, will be
- * automatically freed() */
- talloc_free(rtbl);
-}
-
/***********************************************************************
* SS7 Routes
***********************************************************************/
diff --git a/src/osmo_ss7_as.c b/src/osmo_ss7_as.c
index 9683e94..87e7e04 100644
--- a/src/osmo_ss7_as.c
+++ b/src/osmo_ss7_as.c
@@ -33,6 +33,7 @@
#include <osmocom/core/talloc.h>
#include <osmocom/core/logging.h>
+#include "ss7_route_table.h"
#include "ss7_internal.h"
#include "xua_as_fsm.h"
#include "xua_asp_fsm.h"
diff --git a/src/osmo_ss7_hmrt.c b/src/osmo_ss7_hmrt.c
index 3ac43b8..57d7388 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_route_table.h"
#include "ss7_internal.h"
/* convert from M3UA message to MTP-TRANSFER.ind osmo_mtp_prim */
diff --git a/src/osmo_ss7_route_table.c b/src/osmo_ss7_route_table.c
new file mode 100644
index 0000000..311f13f
--- /dev/null
+++ b/src/osmo_ss7_route_table.c
@@ -0,0 +1,71 @@
+/* (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 <osmocom/core/linuxlist.h>
+#include <osmocom/core/logging.h>
+#include <osmocom/sigtran/mtp_sap.h>
+#include <osmocom/sigtran/osmo_ss7.h>
+
+#include "ss7_route_table.h"
+#include "ss7_internal.h"
+
+/***********************************************************************
+ * SS7 Route Tables
+ ***********************************************************************/
+
+struct osmo_ss7_route_table *
+ss7_route_table_find(struct osmo_ss7_instance *inst, const char *name)
+{
+ struct osmo_ss7_route_table *rtbl;
+ OSMO_ASSERT(ss7_initialized);
+ llist_for_each_entry(rtbl, &inst->rtable_list, list) {
+ if (!strcmp(rtbl->cfg.name, name))
+ return rtbl;
+ }
+ return NULL;
+}
+
+struct osmo_ss7_route_table *
+ss7_route_table_find_or_create(struct osmo_ss7_instance *inst, const char *name)
+{
+ struct osmo_ss7_route_table *rtbl;
+
+ OSMO_ASSERT(ss7_initialized);
+ rtbl = ss7_route_table_find(inst, name);
+ if (!rtbl) {
+ LOGSS7(inst, LOGL_INFO, "Creating Route Table %s\n", name);
+ rtbl = talloc_zero(inst, struct osmo_ss7_route_table);
+ rtbl->inst = inst;
+ rtbl->cfg.name = talloc_strdup(rtbl, name);
+ INIT_LLIST_HEAD(&rtbl->routes);
+ llist_add_tail(&rtbl->list, &inst->rtable_list);
+ }
+ return rtbl;
+}
+
+void
+ss7_route_table_destroy(struct osmo_ss7_route_table *rtbl)
+{
+ llist_del(&rtbl->list);
+ /* routes are allocated as children of route table, will be
+ * automatically freed() */
+ talloc_free(rtbl);
+}
diff --git a/src/osmo_ss7_vty.c b/src/osmo_ss7_vty.c
index e3142c7..7c93039 100644
--- a/src/osmo_ss7_vty.c
+++ b/src/osmo_ss7_vty.c
@@ -46,6 +46,7 @@
#include "xua_internal.h"
#include <osmocom/sigtran/sccp_sap.h>
#include "sccp_internal.h"
+#include "ss7_route_table.h"
#include "ss7_internal.h"
#include <netinet/tcp.h>
diff --git a/src/ss7_route_table.h b/src/ss7_route_table.h
new file mode 100644
index 0000000..25f0266
--- /dev/null
+++ b/src/ss7_route_table.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <osmocom/core/linuxlist.h>
+
+/***********************************************************************
+ * SS7 Routing Tables
+ ***********************************************************************/
+
+struct osmo_ss7_instance;
+
+struct osmo_ss7_route_table {
+ /*! member in list of routing tables */
+ struct llist_head list;
+ /*! \ref osmo_ss7_instance to which we belong */
+ struct osmo_ss7_instance *inst;
+ /*! list of \ref osmo_ss7_route */
+ struct llist_head routes;
+
+ struct {
+ char *name;
+ char *description;
+ } cfg;
+};
+
+struct osmo_ss7_route_table *
+ss7_route_table_find(struct osmo_ss7_instance *inst, const char *name);
+struct osmo_ss7_route_table *
+ss7_route_table_find_or_create(struct osmo_ss7_instance *inst, const char *name);
+void ss7_route_table_destroy(struct osmo_ss7_route_table *rtbl);
diff --git a/tests/ss7/ss7_test.c b/tests/ss7/ss7_test.c
index ad8dc77..54a8e62 100644
--- a/tests/ss7/ss7_test.c
+++ b/tests/ss7/ss7_test.c
@@ -1,3 +1,4 @@
+#include "../src/ss7_route_table.h"
#include "../src/xua_internal.h"
#include "../src/xua_asp_fsm.h"
@@ -143,15 +144,15 @@
printf("Testing SS7 routing\n");
/* creation / destruction */
- OSMO_ASSERT(osmo_ss7_route_table_find(s7i, "foobar") == NULL);
- rtbl = osmo_ss7_route_table_find_or_create(s7i, "foobar");
+ OSMO_ASSERT(ss7_route_table_find(s7i, "foobar") == NULL);
+ rtbl = ss7_route_table_find_or_create(s7i, "foobar");
OSMO_ASSERT(rtbl);
- OSMO_ASSERT(osmo_ss7_route_table_find_or_create(s7i, "foobar") == rtbl);
- osmo_ss7_route_table_destroy(rtbl);
- OSMO_ASSERT(osmo_ss7_route_table_find(s7i, "foobar") == NULL);
+ OSMO_ASSERT(ss7_route_table_find_or_create(s7i, "foobar") == rtbl);
+ ss7_route_table_destroy(rtbl);
+ OSMO_ASSERT(ss7_route_table_find(s7i, "foobar") == NULL);
/* we now work with system route table */
- rtbl = osmo_ss7_route_table_find(s7i, "system");
+ 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);
--
To view, visit
https://gerrit.osmocom.org/c/libosmo-sigtran/+/38626?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: Ie7c709c9849ef3d50aef94f79751c9c4a010c92a
Gerrit-Change-Number: 38626
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>