osmith has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-bsc-nat/+/27473 )

Change subject: Store MSC
......................................................................

Store MSC

Expect one MSC to be configured in the address book (part of the cs7
section in the config, see doc/examples/osmo-bsc-nat/osmo-bsc-nat.cfg)
and store it on start up.

Store the MSC in a list, as we may potentially support multiple MSCs in
the future. Also that makes it symmetric to the BSC list.

Don't use the stored MSCs in the forwarding logic just yet, a future
commit will replace the current forwarding code with proper connection
mappings.

Related: SYS#5560
Change-Id: I711df0c649728f1007857fbfda500ed5ef69287b
---
M include/osmocom/bsc_nat/Makefile.am
M include/osmocom/bsc_nat/bsc_nat.h
A include/osmocom/bsc_nat/msc.h
M src/osmo-bsc-nat/Makefile.am
M src/osmo-bsc-nat/bsc_nat.c
M src/osmo-bsc-nat/bsc_nat_fsm.c
M src/osmo-bsc-nat/main.c
A src/osmo-bsc-nat/msc.c
8 files changed, 120 insertions(+), 16 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 398b0aa..1c675f7 100644
--- a/include/osmocom/bsc_nat/Makefile.am
+++ b/include/osmocom/bsc_nat/Makefile.am
@@ -4,5 +4,6 @@
        bsc_nat_fsm.h \
        bssap.h \
        logging.h \
+       msc.h \
        vty.h \
        $(NULL)
diff --git a/include/osmocom/bsc_nat/bsc_nat.h 
b/include/osmocom/bsc_nat/bsc_nat.h
index aac06ab..9e58a79 100644
--- a/include/osmocom/bsc_nat/bsc_nat.h
+++ b/include/osmocom/bsc_nat/bsc_nat.h
@@ -40,6 +40,7 @@

        struct {
                struct bsc_nat_sccp_inst *sccp_inst;
+               struct llist_head mscs; /* list of struct msc */
        } cn;

        struct {
diff --git a/include/osmocom/bsc_nat/msc.h b/include/osmocom/bsc_nat/msc.h
new file mode 100644
index 0000000..1f91de0
--- /dev/null
+++ b/include/osmocom/bsc_nat/msc.h
@@ -0,0 +1,34 @@
+/* (C) 2021 by sysmocom - s.f.m.c. GmbH <[email protected]>
+ * Author: Oliver Smith <[email protected]>
+ * 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 msc {
+       struct llist_head list;
+       struct osmo_sccp_addr addr;
+};
+
+struct msc *msc_alloc(struct osmo_sccp_addr *addr);
+int msc_alloc_from_addr_book(void);
+
+struct msc *msc_get(void);
+
+void msc_free(struct msc *msc);
diff --git a/src/osmo-bsc-nat/Makefile.am b/src/osmo-bsc-nat/Makefile.am
index bb8e990..1dd82fd 100644
--- a/src/osmo-bsc-nat/Makefile.am
+++ b/src/osmo-bsc-nat/Makefile.am
@@ -31,6 +31,7 @@
        bssap.c \
        logging.c \
        main.c \
+       msc.c \
        vty.c \
        $(NULL)

diff --git a/src/osmo-bsc-nat/bsc_nat.c b/src/osmo-bsc-nat/bsc_nat.c
index 8baa096..23d7498 100644
--- a/src/osmo-bsc-nat/bsc_nat.c
+++ b/src/osmo-bsc-nat/bsc_nat.c
@@ -24,6 +24,7 @@
 #include <osmocom/bsc_nat/bsc_nat.h>
 #include <osmocom/bsc_nat/bsc_nat_fsm.h>
 #include <osmocom/bsc_nat/logging.h>
+#include <osmocom/bsc_nat/msc.h>
 
 struct bsc_nat *bsc_nat_alloc(void *tall_ctx)
 {
@@ -40,6 +41,7 @@
        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->cn.mscs);
        INIT_LLIST_HEAD(&bsc_nat->ran.bscs);

        bsc_nat_fsm_alloc(bsc_nat);
@@ -49,6 +51,7 @@

 void bsc_nat_free(struct bsc_nat *bsc_nat)
 {
+       struct msc *msc, *m;
        struct bsc *bsc, *b;

        if (bsc_nat->fi) {
@@ -56,6 +59,10 @@
                bsc_nat->fi = NULL;
        }

+       llist_for_each_entry_safe(msc, m, &bsc_nat->cn.mscs, list) {
+               msc_free(msc);
+       }
+
        llist_for_each_entry_safe(bsc, b, &bsc_nat->ran.bscs, list) {
                bsc_free(bsc);
        }
diff --git a/src/osmo-bsc-nat/bsc_nat_fsm.c b/src/osmo-bsc-nat/bsc_nat_fsm.c
index 07b9eb5..4193ae9 100644
--- a/src/osmo-bsc-nat/bsc_nat_fsm.c
+++ b/src/osmo-bsc-nat/bsc_nat_fsm.c
@@ -186,22 +186,7 @@

        case OSMO_PRIM(OSMO_SCU_PRIM_N_UNITDATA, PRIM_OP_INDICATION):
                /* connection-less data received */
-               addr = &prim->u.unitdata.calling_addr;
-
-               if (sccp_sap_get_peer_addr_out(sccp_inst, addr, &peer_addr_out) 
< 0)
-                       goto error;
-
-               LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", 
bsc_nat_print_addr_ran(&peer_addr_out));
-
-               /* oph->msg stores oph and unitdata msg. Move oph->msg->data to
-                * unitdata msg and send it again. */
-               msgb_pull_to_l2(oph->msg);
-               osmo_sccp_tx_unitdata(g_bsc_nat->ran.sccp_inst->scu,
-                                     &g_bsc_nat->ran.sccp_inst->addr,
-                                     &peer_addr_out,
-                                     oph->msg->data,
-                                     msgb_length(oph->msg));
-               rc = 0;
+               rc = bssap_handle_udt(sccp_inst, 
&prim->u.unitdata.calling_addr, oph->msg, msgb_l2len(oph->msg));
                break;

        default:
diff --git a/src/osmo-bsc-nat/main.c b/src/osmo-bsc-nat/main.c
index c0b65ea..6cb1e0f 100644
--- a/src/osmo-bsc-nat/main.c
+++ b/src/osmo-bsc-nat/main.c
@@ -30,6 +30,7 @@
 #include <osmocom/bsc_nat/bsc_nat.h>
 #include <osmocom/bsc_nat/bsc_nat_fsm.h>
 #include <osmocom/bsc_nat/logging.h>
+#include <osmocom/bsc_nat/msc.h>
 #include <osmocom/bsc_nat/vty.h>

 static const char *const copyright =
@@ -199,6 +200,9 @@

        bsc_nat_fsm_start(g_bsc_nat);
 
+       if (msc_alloc_from_addr_book() < 0)
+               exit(1);
+
        while (!osmo_select_shutdown_done())
                osmo_select_main_ctx(0);

diff --git a/src/osmo-bsc-nat/msc.c b/src/osmo-bsc-nat/msc.c
new file mode 100644
index 0000000..70f9d76
--- /dev/null
+++ b/src/osmo-bsc-nat/msc.c
@@ -0,0 +1,71 @@
+/* (C) 2021 by sysmocom - s.f.m.c. GmbH <[email protected]>
+ * Author: Oliver Smith <[email protected]>
+ * 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 <errno.h>
+#include <osmocom/bsc_nat/msc.h>
+#include <osmocom/bsc_nat/bsc_nat.h>
+#include <osmocom/bsc_nat/logging.h>
+
+struct msc *msc_alloc(struct osmo_sccp_addr *addr)
+{
+       struct msc *msc = talloc_zero(g_bsc_nat, struct msc);
+
+       OSMO_ASSERT(msc);
+       talloc_set_name(msc, "MSC(PC=%s)", osmo_ss7_pointcode_print(NULL, 
addr->pc));
+
+       LOGP(DMAIN, LOGL_DEBUG, "Add %s\n", talloc_get_name(msc));
+
+       msc->addr = *addr;
+
+       INIT_LLIST_HEAD(&msc->list);
+       llist_add(&msc->list, &g_bsc_nat->cn.mscs);
+
+       return msc;
+}
+
+int msc_alloc_from_addr_book(void)
+{
+       struct osmo_sccp_addr addr;
+
+       /* For now only one MSC is supported */
+       if (osmo_sccp_addr_by_name_local(&addr, "msc", 
g_bsc_nat->cn.sccp_inst->ss7_inst) < 0) {
+               LOGP(DMAIN, LOGL_ERROR, "Configuration error, MSC not found in 
address book\n");
+               return -ENOENT;
+       }
+
+       msc_alloc(&addr);
+       return 0;
+}
+
+struct msc *msc_get(void)
+{
+       /* For now only one MSC is supported */
+
+       OSMO_ASSERT(!llist_empty(&g_bsc_nat->cn.mscs));
+
+       return llist_first_entry(&g_bsc_nat->cn.mscs, struct msc, list);
+}
+
+void msc_free(struct msc *msc)
+{
+       LOGP(DMAIN, LOGL_DEBUG, "Del %s\n", talloc_get_name(msc));
+       llist_del(&msc->list);
+       talloc_free(msc);
+}

--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc-nat/+/27473
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: I711df0c649728f1007857fbfda500ed5ef69287b
Gerrit-Change-Number: 27473
Gerrit-PatchSet: 4
Gerrit-Owner: osmith <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to