osmith has submitted this change. (
https://gerrit.osmocom.org/c/osmo-bsc-nat/+/27472 )
Change subject: Store BSCs
......................................................................
Store BSCs
Once a BSC has sent a RESET to BSCNAT, store it. This will be used in
future patches to build connection mappings between MSC and BSCs, and to
block messages from BSCs that did not send a RESET.
I've considered using a FSM, but at least right now there doesn't seem
to be multiple states worth storing. We only have the BSC before it has
done the RESET (and then it's simply not in our list) and after it did
the RESET (in the list).
Don't use the stored BSCs in the forwarding logic just yet, a future
commit will replace the current forwarding code with proper connection
mappings.
Related: SYS#5560
Change-Id: Icd7316c49ef26fb45ad45a2ccc1a7916bfb0a387
---
M include/osmocom/bsc_nat/Makefile.am
A include/osmocom/bsc_nat/bsc.h
M include/osmocom/bsc_nat/bsc_nat.h
M src/osmo-bsc-nat/Makefile.am
A src/osmo-bsc-nat/bsc.c
M src/osmo-bsc-nat/bsc_nat.c
M src/osmo-bsc-nat/bssap.c
7 files changed, 110 insertions(+), 0 deletions(-)
Approvals:
Jenkins Builder: Verified
pespin: Looks good to me, but someone else must approve
laforge: Looks good to me, approved
diff --git a/include/osmocom/bsc_nat/Makefile.am b/include/osmocom/bsc_nat/Makefile.am
index 76aada0..398b0aa 100644
--- a/include/osmocom/bsc_nat/Makefile.am
+++ b/include/osmocom/bsc_nat/Makefile.am
@@ -1,4 +1,5 @@
noinst_HEADERS = \
+ bsc.h \
bsc_nat.h \
bsc_nat_fsm.h \
bssap.h \
diff --git a/include/osmocom/bsc_nat/bsc.h b/include/osmocom/bsc_nat/bsc.h
new file mode 100644
index 0000000..34590b9
--- /dev/null
+++ b/include/osmocom/bsc_nat/bsc.h
@@ -0,0 +1,31 @@
+/* (C) 2021 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+ * Author: Oliver Smith <osmith(a)sysmocom.de>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/lienses/>.
+ *
+ */
+
+#pragma once
+
+#include <osmocom/sigtran/sccp_sap.h>
+
+struct bsc {
+ struct llist_head list;
+ struct osmo_sccp_addr addr;
+};
+
+struct bsc *bsc_alloc(struct osmo_sccp_addr *addr);
+struct bsc *bsc_get_by_pc(uint32_t pointcode);
+void bsc_free(struct bsc *bsc);
diff --git a/include/osmocom/bsc_nat/bsc_nat.h b/include/osmocom/bsc_nat/bsc_nat.h
index 3d863f1..aac06ab 100644
--- a/include/osmocom/bsc_nat/bsc_nat.h
+++ b/include/osmocom/bsc_nat/bsc_nat.h
@@ -44,6 +44,7 @@
struct {
struct bsc_nat_sccp_inst *sccp_inst;
+ struct llist_head bscs; /* list of struct bsc */
} ran;
};
diff --git a/src/osmo-bsc-nat/Makefile.am b/src/osmo-bsc-nat/Makefile.am
index 445c098..bb8e990 100644
--- a/src/osmo-bsc-nat/Makefile.am
+++ b/src/osmo-bsc-nat/Makefile.am
@@ -25,6 +25,7 @@
$(NULL)
osmo_bsc_nat_SOURCES = \
+ bsc.c \
bsc_nat.c \
bsc_nat_fsm.c \
bssap.c \
diff --git a/src/osmo-bsc-nat/bsc.c b/src/osmo-bsc-nat/bsc.c
new file mode 100644
index 0000000..2ad6e0e
--- /dev/null
+++ b/src/osmo-bsc-nat/bsc.c
@@ -0,0 +1,59 @@
+/* (C) 2021 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+ * Author: Oliver Smith <osmith(a)sysmocom.de>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/lienses/>.
+ *
+ */
+
+#include "config.h"
+#include <osmocom/bsc_nat/bsc.h>
+#include <osmocom/bsc_nat/bsc_nat.h>
+#include <osmocom/bsc_nat/logging.h>
+
+struct bsc *bsc_alloc(struct osmo_sccp_addr *addr)
+{
+ struct bsc *bsc = talloc_zero(g_bsc_nat, struct bsc);
+
+ OSMO_ASSERT(bsc);
+ talloc_set_name(bsc, "BSC(PC=%s)", osmo_ss7_pointcode_print(NULL,
addr->pc));
+
+ LOGP(DMAIN, LOGL_DEBUG, "Add %s\n", talloc_get_name(bsc));
+
+ bsc->addr = *addr;
+
+ INIT_LLIST_HEAD(&bsc->list);
+ llist_add(&bsc->list, &g_bsc_nat->ran.bscs);
+
+ return bsc;
+}
+
+struct bsc *bsc_get_by_pc(uint32_t pointcode)
+{
+ struct bsc *bsc;
+
+ llist_for_each_entry(bsc, &g_bsc_nat->ran.bscs, list) {
+ if (bsc->addr.pc == pointcode)
+ return bsc;
+ }
+
+ return NULL;
+}
+
+void bsc_free(struct bsc *bsc)
+{
+ LOGP(DMAIN, LOGL_DEBUG, "Del %s\n", talloc_get_name(bsc));
+ llist_del(&bsc->list);
+ talloc_free(bsc);
+}
diff --git a/src/osmo-bsc-nat/bsc_nat.c b/src/osmo-bsc-nat/bsc_nat.c
index 409bf74..8baa096 100644
--- a/src/osmo-bsc-nat/bsc_nat.c
+++ b/src/osmo-bsc-nat/bsc_nat.c
@@ -20,8 +20,10 @@
#include "config.h"
#include <osmocom/core/talloc.h>
#include <osmocom/core/utils.h>
+#include <osmocom/bsc_nat/bsc.h>
#include <osmocom/bsc_nat/bsc_nat.h>
#include <osmocom/bsc_nat/bsc_nat_fsm.h>
+#include <osmocom/bsc_nat/logging.h>
struct bsc_nat *bsc_nat_alloc(void *tall_ctx)
{
@@ -38,6 +40,8 @@
OSMO_ASSERT(bsc_nat->ran.sccp_inst);
talloc_set_name_const(bsc_nat->ran.sccp_inst, "struct bsc_nat_sccp_inst
(RAN)");
+ INIT_LLIST_HEAD(&bsc_nat->ran.bscs);
+
bsc_nat_fsm_alloc(bsc_nat);
return bsc_nat;
@@ -45,11 +49,17 @@
void bsc_nat_free(struct bsc_nat *bsc_nat)
{
+ struct bsc *bsc, *b;
+
if (bsc_nat->fi) {
osmo_fsm_inst_free(bsc_nat->fi);
bsc_nat->fi = NULL;
}
+ llist_for_each_entry_safe(bsc, b, &bsc_nat->ran.bscs, list) {
+ bsc_free(bsc);
+ }
+
talloc_free(bsc_nat);
}
diff --git a/src/osmo-bsc-nat/bssap.c b/src/osmo-bsc-nat/bssap.c
index e5c8ca2..83eec99 100644
--- a/src/osmo-bsc-nat/bssap.c
+++ b/src/osmo-bsc-nat/bssap.c
@@ -22,12 +22,19 @@
#include <osmocom/gsm/gsm0808.h>
#include <osmocom/sigtran/sccp_helpers.h>
#include <osmocom/sigtran/sccp_sap.h>
+#include <osmocom/bsc_nat/bsc.h>
#include <osmocom/bsc_nat/bsc_nat.h>
#include <osmocom/bsc_nat/logging.h>
static int bssap_ran_handle_reset(struct osmo_sccp_addr *addr, struct msgb *msg, unsigned
int length)
{
struct bsc_nat_sccp_inst *sccp_inst = g_bsc_nat->ran.sccp_inst;
+ struct bsc *bsc;
+
+ /* Store the BSC, since RESET was done the BSCNAT should accept its messages */
+ bsc = bsc_get_by_pc(addr->pc);
+ if (!bsc)
+ bsc = bsc_alloc(addr);
LOGP(DMAIN, LOGL_NOTICE, "Rx RESET from %s\n", bsc_nat_print_addr_ran(addr));
--
To view, visit
https://gerrit.osmocom.org/c/osmo-bsc-nat/+/27472
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-bsc-nat
Gerrit-Branch: master
Gerrit-Change-Id: Icd7316c49ef26fb45ad45a2ccc1a7916bfb0a387
Gerrit-Change-Number: 27472
Gerrit-PatchSet: 4
Gerrit-Owner: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged