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
This commit is contained in:
Oliver Smith 2022-03-10 11:09:44 +01:00
parent 793ca23f07
commit 49e50de426
8 changed files with 120 additions and 16 deletions

View File

@ -4,5 +4,6 @@ noinst_HEADERS = \
bsc_nat_fsm.h \
bssap.h \
logging.h \
msc.h \
vty.h \
$(NULL)

View File

@ -40,6 +40,7 @@ struct bsc_nat {
struct {
struct bsc_nat_sccp_inst *sccp_inst;
struct llist_head mscs; /* list of struct msc */
} cn;
struct {

View File

@ -0,0 +1,34 @@
/* (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
* Author: Oliver Smith <osmith@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 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);

View File

@ -31,6 +31,7 @@ osmo_bsc_nat_SOURCES = \
bssap.c \
logging.c \
main.c \
msc.c \
vty.c \
$(NULL)

View File

@ -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 @@ struct bsc_nat *bsc_nat_alloc(void *tall_ctx)
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 @@ struct bsc_nat *bsc_nat_alloc(void *tall_ctx)
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 @@ void bsc_nat_free(struct bsc_nat *bsc_nat)
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);
}

View File

@ -186,22 +186,7 @@ static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu)
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:

View File

@ -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 @@ int main(int argc, char **argv)
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);

71
src/osmo-bsc-nat/msc.c Normal file
View File

@ -0,0 +1,71 @@
/* (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
* Author: Oliver Smith <osmith@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 <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);
}