forked from cellular-infrastructure/osmo-bsc-nat
Support forwarding messages with multiple BSCs
Implement a proper subscriber connection mapping. Create a new subscr_conn when one of the stored BSCs sends a conn.ind and use that subscr_conn for all related connection-oriented messages with the same RAN-side conn_id to send messages back and forth between BSC and MSC. Add subscr_conn_get_next_id based on OsmoBSC's bsc_sccp_inst_next_conn_id. With this patch, it's possible to do a successful Location Updating procedure between MS2 and MSC in the following network: MS1 --- BTS1 --- BSC1 --. BSCNAT --- MSC MS2 --- BTS2 --- BSC2 --' Related: SYS#5560 Change-Id: I1556aa665fbb0a97507f98794e74820731fa6935
This commit is contained in:
parent
1968ca922b
commit
499e1117a6
|
@ -13,10 +13,6 @@ cs7 instance 1
|
|||
asp asp-clnt-OsmoBSCNAT-RAN 2905 0 m3ua
|
||||
remote-ip 127.0.0.2
|
||||
local-ip 127.0.0.4
|
||||
sccp-address bsc
|
||||
routing-indicator PC
|
||||
point-code 0.23.3
|
||||
subsystem-number 254
|
||||
|
||||
bsc-nat
|
||||
cs7-instance-cn 0
|
||||
|
|
|
@ -5,5 +5,6 @@ noinst_HEADERS = \
|
|||
bssap.h \
|
||||
logging.h \
|
||||
msc.h \
|
||||
subscr_conn.h \
|
||||
vty.h \
|
||||
$(NULL)
|
||||
|
|
|
@ -29,3 +29,4 @@ struct bsc {
|
|||
struct bsc *bsc_alloc(struct osmo_sccp_addr *addr);
|
||||
struct bsc *bsc_get_by_pc(uint32_t pointcode);
|
||||
void bsc_free(struct bsc *bsc);
|
||||
void bsc_free_subscr_conn_all(struct bsc *bsc);
|
||||
|
|
|
@ -37,14 +37,17 @@ struct bsc_nat_sccp_inst {
|
|||
|
||||
struct bsc_nat {
|
||||
struct osmo_fsm_inst *fi;
|
||||
struct llist_head subscr_conns; /* list of struct subscr_conn */
|
||||
|
||||
struct {
|
||||
struct bsc_nat_sccp_inst *sccp_inst;
|
||||
uint32_t subscr_conn_id_next;
|
||||
struct llist_head mscs; /* list of struct msc */
|
||||
} cn;
|
||||
|
||||
struct {
|
||||
struct bsc_nat_sccp_inst *sccp_inst;
|
||||
uint32_t subscr_conn_id_next;
|
||||
struct llist_head bscs; /* list of struct bsc */
|
||||
} ran;
|
||||
};
|
||||
|
|
|
@ -39,3 +39,4 @@ void msc_rx_reset_ack(struct msc *msc);
|
|||
bool msc_is_connected(struct msc *msc);
|
||||
|
||||
void msc_free(struct msc *msc);
|
||||
void msc_free_subscr_conn_all(struct msc *msc);
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/* (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
|
||||
|
||||
/* connection for one subscriber */
|
||||
struct subscr_conn {
|
||||
struct llist_head list;
|
||||
|
||||
struct {
|
||||
uint32_t id;
|
||||
struct msc *msc;
|
||||
} cn;
|
||||
|
||||
struct {
|
||||
uint32_t id;
|
||||
struct bsc *bsc;
|
||||
} ran;
|
||||
};
|
||||
|
||||
int subscr_conn_get_next_id(enum bsc_nat_net net);
|
||||
|
||||
struct subscr_conn *subscr_conn_alloc(struct msc *msc, struct bsc *bsc, uint32_t id_cn, uint32_t id_ran);
|
||||
|
||||
struct subscr_conn *subscr_conn_get_by_id(uint32_t id, enum bsc_nat_net net);
|
||||
|
||||
void subscr_conn_free(struct subscr_conn *subscr_conn);
|
|
@ -33,6 +33,7 @@ osmo_bsc_nat_SOURCES = \
|
|||
main.c \
|
||||
msc.c \
|
||||
msc_fsm.c \
|
||||
subscr_conn.c \
|
||||
vty.c \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <osmocom/bsc_nat/bsc.h>
|
||||
#include <osmocom/bsc_nat/bsc_nat.h>
|
||||
#include <osmocom/bsc_nat/logging.h>
|
||||
#include <osmocom/bsc_nat/subscr_conn.h>
|
||||
|
||||
struct bsc *bsc_alloc(struct osmo_sccp_addr *addr)
|
||||
{
|
||||
|
@ -51,9 +52,20 @@ struct bsc *bsc_get_by_pc(uint32_t pointcode)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void bsc_free_subscr_conn_all(struct bsc *bsc)
|
||||
{
|
||||
struct subscr_conn *subscr_conn;
|
||||
|
||||
llist_for_each_entry(subscr_conn, &g_bsc_nat->subscr_conns, list) {
|
||||
if (subscr_conn->ran.bsc == bsc)
|
||||
subscr_conn_free(subscr_conn);
|
||||
}
|
||||
}
|
||||
|
||||
void bsc_free(struct bsc *bsc)
|
||||
{
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Del %s\n", talloc_get_name(bsc));
|
||||
bsc_free_subscr_conn_all(bsc);
|
||||
llist_del(&bsc->list);
|
||||
talloc_free(bsc);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <inttypes.h>
|
||||
#include <osmocom/core/talloc.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/bsc_nat/bsc.h>
|
||||
|
@ -25,6 +26,7 @@
|
|||
#include <osmocom/bsc_nat/bsc_nat_fsm.h>
|
||||
#include <osmocom/bsc_nat/logging.h>
|
||||
#include <osmocom/bsc_nat/msc.h>
|
||||
#include <osmocom/bsc_nat/subscr_conn.h>
|
||||
|
||||
struct bsc_nat *bsc_nat_alloc(void *tall_ctx)
|
||||
{
|
||||
|
@ -41,6 +43,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->subscr_conns);
|
||||
INIT_LLIST_HEAD(&bsc_nat->cn.mscs);
|
||||
INIT_LLIST_HEAD(&bsc_nat->ran.bscs);
|
||||
|
||||
|
@ -51,6 +54,7 @@ struct bsc_nat *bsc_nat_alloc(void *tall_ctx)
|
|||
|
||||
void bsc_nat_free(struct bsc_nat *bsc_nat)
|
||||
{
|
||||
struct subscr_conn *subscr_conn, *s;
|
||||
struct msc *msc, *m;
|
||||
struct bsc *bsc, *b;
|
||||
|
||||
|
@ -59,6 +63,10 @@ void bsc_nat_free(struct bsc_nat *bsc_nat)
|
|||
bsc_nat->fi = NULL;
|
||||
}
|
||||
|
||||
llist_for_each_entry_safe(subscr_conn, s, &bsc_nat->subscr_conns, list) {
|
||||
subscr_conn_free(subscr_conn);
|
||||
}
|
||||
|
||||
llist_for_each_entry_safe(msc, m, &bsc_nat->cn.mscs, list) {
|
||||
msc_free(msc);
|
||||
}
|
||||
|
|
|
@ -19,17 +19,20 @@
|
|||
|
||||
#include "config.h"
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <osmocom/core/fsm.h>
|
||||
#include <osmocom/core/select.h>
|
||||
#include <osmocom/gsm/gsm0808.h>
|
||||
#include <osmocom/sigtran/osmo_ss7.h>
|
||||
#include <osmocom/sigtran/sccp_helpers.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/bssap.h>
|
||||
#include <osmocom/bsc_nat/logging.h>
|
||||
#include <osmocom/bsc_nat/msc.h>
|
||||
#include <osmocom/bsc_nat/subscr_conn.h>
|
||||
|
||||
#define DEFAULT_PC_RAN "0.23.1" /* same as default for OsmoMSC */
|
||||
#define DEFAULT_PC_CN "0.23.3" /* same as default for OsmoBSC */
|
||||
|
@ -47,13 +50,6 @@ enum bsc_nat_fsm_events {
|
|||
BSC_NAT_FSM_EV_STOP,
|
||||
};
|
||||
|
||||
static struct bsc_nat_sccp_inst *sccp_inst_dest(struct bsc_nat_sccp_inst *src)
|
||||
{
|
||||
if (src == g_bsc_nat->cn.sccp_inst)
|
||||
return g_bsc_nat->ran.sccp_inst;
|
||||
return g_bsc_nat->cn.sccp_inst;
|
||||
}
|
||||
|
||||
/* For connection-oriented messages, figure out which side is not the BSCNAT,
|
||||
* either the called_addr or calling_addr. */
|
||||
static int sccp_sap_get_peer_addr_in(struct bsc_nat_sccp_inst *src, struct osmo_sccp_addr **peer_addr_in,
|
||||
|
@ -79,37 +75,13 @@ static int sccp_sap_get_peer_addr_in(struct bsc_nat_sccp_inst *src, struct osmo_
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* Figure out who will receive the message.
|
||||
* For now this is simplified by assuming there is only one MSC, one BSC. */
|
||||
static int sccp_sap_get_peer_addr_out(struct bsc_nat_sccp_inst *src, struct osmo_sccp_addr *peer_addr_in,
|
||||
struct osmo_sccp_addr *peer_addr_out)
|
||||
{
|
||||
struct bsc_nat_sccp_inst *dest = sccp_inst_dest(src);
|
||||
|
||||
if (src == g_bsc_nat->ran.sccp_inst) {
|
||||
if (osmo_sccp_addr_by_name_local(peer_addr_out, "msc", dest->ss7_inst) < 0) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "Could not find MSC in address book\n");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (osmo_sccp_addr_by_name_local(peer_addr_out, "bsc", dest->ss7_inst) < 0) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "Could not find BSC in address book\n");
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Handle incoming messages from CN (MSC). For now this is simplified by
|
||||
* assuming there is only one MSC, one BSC (not yet translating connection ids
|
||||
* etc.). */
|
||||
/* Handle incoming messages from CN (MSC) */
|
||||
static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu)
|
||||
{
|
||||
struct bsc_nat_sccp_inst *sccp_inst = osmo_sccp_user_get_priv(scu);
|
||||
struct osmo_scu_prim *prim = (struct osmo_scu_prim *) oph;
|
||||
struct osmo_sccp_addr *addr; /* MSC's address */
|
||||
struct osmo_sccp_addr peer_addr_out;
|
||||
struct subscr_conn *subscr_conn;
|
||||
int rc = -1;
|
||||
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Rx %s from CN\n", osmo_scu_prim_name(oph));
|
||||
|
@ -117,23 +89,9 @@ static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu)
|
|||
switch (OSMO_PRIM_HDR(oph)) {
|
||||
case OSMO_PRIM(OSMO_SCU_PRIM_N_CONNECT, PRIM_OP_INDICATION):
|
||||
/* indication of new inbound connection request */
|
||||
if (sccp_sap_get_peer_addr_in(sccp_inst, &addr, &prim->u.connect.called_addr,
|
||||
&prim->u.connect.calling_addr) < 0)
|
||||
goto error;
|
||||
|
||||
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));
|
||||
|
||||
msgb_pull_to_l2(oph->msg);
|
||||
osmo_sccp_tx_conn_req(g_bsc_nat->ran.sccp_inst->scu,
|
||||
prim->u.connect.conn_id,
|
||||
&g_bsc_nat->ran.sccp_inst->addr,
|
||||
&peer_addr_out,
|
||||
oph->msg->data,
|
||||
msgb_length(oph->msg));
|
||||
rc = 0;
|
||||
/* FIXME: MSC has sent a message without conn_id, figure out to
|
||||
* which BSC to forward this. */
|
||||
LOGP(DMAIN, LOGL_ERROR, "%s(%s) is not implemented!\n", __func__, osmo_scu_prim_name(oph));
|
||||
break;
|
||||
|
||||
case OSMO_PRIM(OSMO_SCU_PRIM_N_CONNECT, PRIM_OP_CONFIRM):
|
||||
|
@ -142,15 +100,19 @@ static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu)
|
|||
&prim->u.connect.calling_addr) < 0)
|
||||
goto error;
|
||||
|
||||
if (sccp_sap_get_peer_addr_out(sccp_inst, addr, &peer_addr_out) < 0)
|
||||
subscr_conn = subscr_conn_get_by_id(prim->u.connect.conn_id, BSC_NAT_NET_CN);
|
||||
if (!subscr_conn) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "Unknown conn_id=%" PRIu32 " from %s\n", prim->u.connect.conn_id,
|
||||
bsc_nat_print_addr_cn(addr));
|
||||
goto error;
|
||||
}
|
||||
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_ran(&peer_addr_out));
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Fwd via %s\n", talloc_get_name(subscr_conn));
|
||||
|
||||
msgb_pull_to_l2(oph->msg);
|
||||
osmo_sccp_tx_conn_resp(g_bsc_nat->ran.sccp_inst->scu,
|
||||
prim->u.connect.conn_id,
|
||||
&peer_addr_out,
|
||||
subscr_conn->ran.id,
|
||||
&subscr_conn->ran.bsc->addr,
|
||||
oph->msg->data,
|
||||
msgb_length(oph->msg));
|
||||
rc = 0;
|
||||
|
@ -158,14 +120,18 @@ static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu)
|
|||
|
||||
case OSMO_PRIM(OSMO_SCU_PRIM_N_DATA, PRIM_OP_INDICATION):
|
||||
/* connection-oriented data received */
|
||||
if (sccp_sap_get_peer_addr_out(sccp_inst, NULL, &peer_addr_out) < 0)
|
||||
subscr_conn = subscr_conn_get_by_id(prim->u.data.conn_id, BSC_NAT_NET_CN);
|
||||
if (!subscr_conn) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "Unknown conn_id=%" PRIu32 " from %s\n", prim->u.data.conn_id,
|
||||
bsc_nat_print_addr_cn(addr));
|
||||
goto error;
|
||||
}
|
||||
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_ran(&peer_addr_out));
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Fwd via %s\n", talloc_get_name(subscr_conn));
|
||||
|
||||
msgb_pull_to_l2(oph->msg);
|
||||
osmo_sccp_tx_data(g_bsc_nat->ran.sccp_inst->scu,
|
||||
prim->u.data.conn_id,
|
||||
subscr_conn->ran.id,
|
||||
oph->msg->data,
|
||||
msgb_length(oph->msg));
|
||||
rc = 0;
|
||||
|
@ -173,15 +139,22 @@ static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu)
|
|||
|
||||
case OSMO_PRIM(OSMO_SCU_PRIM_N_DISCONNECT, PRIM_OP_INDICATION):
|
||||
/* indication of disconnect */
|
||||
if (sccp_sap_get_peer_addr_out(sccp_inst, NULL, &peer_addr_out) < 0)
|
||||
subscr_conn = subscr_conn_get_by_id(prim->u.disconnect.conn_id, BSC_NAT_NET_CN);
|
||||
if (!subscr_conn) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "Unknown conn_id=%" PRIu32 " from %s\n", prim->u.disconnect.conn_id,
|
||||
bsc_nat_print_addr_cn(addr));
|
||||
goto error;
|
||||
}
|
||||
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_ran(&peer_addr_out));
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Fwd via %s\n", talloc_get_name(subscr_conn));
|
||||
|
||||
osmo_sccp_tx_disconn(g_bsc_nat->ran.sccp_inst->scu,
|
||||
prim->u.disconnect.conn_id,
|
||||
&prim->u.disconnect.responding_addr,
|
||||
subscr_conn->ran.id,
|
||||
&g_bsc_nat->ran.sccp_inst->addr,
|
||||
prim->u.disconnect.cause);
|
||||
|
||||
subscr_conn_free(subscr_conn);
|
||||
|
||||
rc = 0;
|
||||
break;
|
||||
|
||||
|
@ -200,16 +173,15 @@ error:
|
|||
return rc;
|
||||
}
|
||||
|
||||
/* Handle incoming messages from RAN (BSC). For now this is simplified by
|
||||
* assuming there is only one MSC, one BSC (not yet translating connection ids
|
||||
* etc.). */
|
||||
/* Handle incoming messages from RAN (BSC) */
|
||||
static int sccp_sap_up_ran(struct osmo_prim_hdr *oph, void *scu)
|
||||
{
|
||||
struct bsc_nat_sccp_inst *sccp_inst = osmo_sccp_user_get_priv(scu);
|
||||
struct osmo_scu_prim *prim = (struct osmo_scu_prim *) oph;
|
||||
struct osmo_sccp_addr *addr; /* BSC's address */
|
||||
struct osmo_sccp_addr peer_addr_out;
|
||||
struct subscr_conn *subscr_conn;
|
||||
struct msc *msc;
|
||||
struct bsc *bsc;
|
||||
int rc = -1;
|
||||
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Rx %s from RAN\n", osmo_scu_prim_name(oph));
|
||||
|
@ -227,16 +199,25 @@ static int sccp_sap_up_ran(struct osmo_prim_hdr *oph, void *scu)
|
|||
&prim->u.connect.calling_addr) < 0)
|
||||
goto error;
|
||||
|
||||
if (sccp_sap_get_peer_addr_out(sccp_inst, addr, &peer_addr_out) < 0)
|
||||
goto error;
|
||||
bsc = bsc_get_by_pc(addr->pc);
|
||||
if (!bsc)
|
||||
bsc = bsc_alloc(addr);
|
||||
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_cn(&peer_addr_out));
|
||||
if (subscr_conn_get_by_id(prim->u.connect.conn_id, BSC_NAT_NET_RAN)) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "%s attempted to create new connection with already used"
|
||||
" conn_id=%" PRIu32 ", ignoring\n", talloc_get_name(bsc), prim->u.connect.conn_id);
|
||||
goto error;
|
||||
}
|
||||
|
||||
subscr_conn = subscr_conn_alloc(msc, bsc, subscr_conn_get_next_id(BSC_NAT_NET_CN), prim->u.connect.conn_id);
|
||||
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Fwd via %s\n", talloc_get_name(subscr_conn));
|
||||
|
||||
msgb_pull_to_l2(oph->msg);
|
||||
osmo_sccp_tx_conn_req(g_bsc_nat->cn.sccp_inst->scu,
|
||||
prim->u.connect.conn_id,
|
||||
subscr_conn->cn.id,
|
||||
&g_bsc_nat->cn.sccp_inst->addr,
|
||||
&peer_addr_out,
|
||||
&subscr_conn->cn.msc->addr,
|
||||
oph->msg->data,
|
||||
msgb_length(oph->msg));
|
||||
rc = 0;
|
||||
|
@ -248,15 +229,19 @@ static int sccp_sap_up_ran(struct osmo_prim_hdr *oph, void *scu)
|
|||
&prim->u.connect.calling_addr) < 0)
|
||||
goto error;
|
||||
|
||||
if (sccp_sap_get_peer_addr_out(sccp_inst, addr, &peer_addr_out) < 0)
|
||||
subscr_conn = subscr_conn_get_by_id(prim->u.connect.conn_id, BSC_NAT_NET_RAN);
|
||||
if (!subscr_conn) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "Unknown conn_id=%" PRIu32 " from %s\n", prim->u.connect.conn_id,
|
||||
bsc_nat_print_addr_ran(addr));
|
||||
goto error;
|
||||
}
|
||||
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_cn(&peer_addr_out));
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Fwd via %s\n", talloc_get_name(subscr_conn));
|
||||
|
||||
msgb_pull_to_l2(oph->msg);
|
||||
osmo_sccp_tx_conn_resp(g_bsc_nat->cn.sccp_inst->scu,
|
||||
prim->u.connect.conn_id,
|
||||
&peer_addr_out,
|
||||
subscr_conn->cn.id,
|
||||
&subscr_conn->cn.msc->addr,
|
||||
oph->msg->data,
|
||||
msgb_length(oph->msg));
|
||||
rc = 0;
|
||||
|
@ -264,14 +249,18 @@ static int sccp_sap_up_ran(struct osmo_prim_hdr *oph, void *scu)
|
|||
|
||||
case OSMO_PRIM(OSMO_SCU_PRIM_N_DATA, PRIM_OP_INDICATION):
|
||||
/* connection-oriented data received */
|
||||
if (sccp_sap_get_peer_addr_out(sccp_inst, NULL, &peer_addr_out) < 0)
|
||||
subscr_conn = subscr_conn_get_by_id(prim->u.data.conn_id, BSC_NAT_NET_RAN);
|
||||
if (!subscr_conn) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "Unknown conn_id=%" PRIu32 " from %s\n", prim->u.data.conn_id,
|
||||
bsc_nat_print_addr_ran(addr));
|
||||
goto error;
|
||||
}
|
||||
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_cn(&peer_addr_out));
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Fwd via %s\n", talloc_get_name(subscr_conn));
|
||||
|
||||
msgb_pull_to_l2(oph->msg);
|
||||
osmo_sccp_tx_data(g_bsc_nat->cn.sccp_inst->scu,
|
||||
prim->u.data.conn_id,
|
||||
subscr_conn->cn.id,
|
||||
oph->msg->data,
|
||||
msgb_length(oph->msg));
|
||||
rc = 0;
|
||||
|
@ -279,15 +268,22 @@ static int sccp_sap_up_ran(struct osmo_prim_hdr *oph, void *scu)
|
|||
|
||||
case OSMO_PRIM(OSMO_SCU_PRIM_N_DISCONNECT, PRIM_OP_INDICATION):
|
||||
/* indication of disconnect */
|
||||
if (sccp_sap_get_peer_addr_out(sccp_inst, NULL, &peer_addr_out) < 0)
|
||||
subscr_conn = subscr_conn_get_by_id(prim->u.disconnect.conn_id, BSC_NAT_NET_RAN);
|
||||
if (!subscr_conn) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "Unknown conn_id=%" PRIu32 " from %s\n", prim->u.disconnect.conn_id,
|
||||
bsc_nat_print_addr_ran(addr));
|
||||
goto error;
|
||||
}
|
||||
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_cn(&peer_addr_out));
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Fwd via %s\n", talloc_get_name(subscr_conn));
|
||||
|
||||
osmo_sccp_tx_disconn(g_bsc_nat->cn.sccp_inst->scu,
|
||||
prim->u.disconnect.conn_id,
|
||||
&prim->u.disconnect.responding_addr,
|
||||
subscr_conn->cn.id,
|
||||
&g_bsc_nat->cn.sccp_inst->addr,
|
||||
prim->u.disconnect.cause);
|
||||
|
||||
subscr_conn_free(subscr_conn);
|
||||
|
||||
rc = 0;
|
||||
break;
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <osmocom/bsc_nat/msc.h>
|
||||
#include <osmocom/bsc_nat/bsc_nat.h>
|
||||
#include <osmocom/bsc_nat/logging.h>
|
||||
#include <osmocom/bsc_nat/subscr_conn.h>
|
||||
|
||||
extern struct osmo_fsm msc_fsm;
|
||||
|
||||
|
@ -70,9 +71,20 @@ struct msc *msc_get(void)
|
|||
return llist_first_entry(&g_bsc_nat->cn.mscs, struct msc, list);
|
||||
}
|
||||
|
||||
void msc_free_subscr_conn_all(struct msc *msc)
|
||||
{
|
||||
struct subscr_conn *subscr_conn;
|
||||
|
||||
llist_for_each_entry(subscr_conn, &g_bsc_nat->subscr_conns, list) {
|
||||
if (subscr_conn->cn.msc == msc)
|
||||
subscr_conn_free(subscr_conn);
|
||||
}
|
||||
}
|
||||
|
||||
void msc_free(struct msc *msc)
|
||||
{
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Del %s\n", talloc_get_name(msc));
|
||||
msc_free_subscr_conn_all(msc);
|
||||
llist_del(&msc->list);
|
||||
osmo_fsm_inst_free(msc->fi);
|
||||
talloc_free(msc);
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/* (C) 2022 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 <inttypes.h>
|
||||
#include <osmocom/core/talloc.h>
|
||||
#include <osmocom/bsc_nat/bsc.h>
|
||||
#include <osmocom/bsc_nat/bsc_nat.h>
|
||||
#include <osmocom/bsc_nat/msc.h>
|
||||
#include <osmocom/bsc_nat/subscr_conn.h>
|
||||
#include <osmocom/bsc_nat/logging.h>
|
||||
|
||||
/* Get the next available id in either CN or RAN. */
|
||||
int subscr_conn_get_next_id(enum bsc_nat_net net)
|
||||
{
|
||||
uint32_t *id;
|
||||
|
||||
if (net == BSC_NAT_NET_RAN)
|
||||
id = &g_bsc_nat->ran.subscr_conn_id_next;
|
||||
else
|
||||
id = &g_bsc_nat->cn.subscr_conn_id_next;
|
||||
|
||||
for (int i = 0; i < 0xFFFFFF; i++) {
|
||||
struct subscr_conn *subscr_conn;
|
||||
bool already_used = false;
|
||||
|
||||
*id = (*id + 1) & 0xffffff;
|
||||
|
||||
llist_for_each_entry(subscr_conn, &g_bsc_nat->subscr_conns, list) {
|
||||
if ((net == BSC_NAT_NET_RAN && subscr_conn->ran.id == *id)
|
||||
|| (net == BSC_NAT_NET_CN && subscr_conn->cn.id == *id)) {
|
||||
already_used = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!already_used)
|
||||
return *id;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct subscr_conn *subscr_conn_alloc(struct msc *msc, struct bsc *bsc, uint32_t id_cn, uint32_t id_ran)
|
||||
{
|
||||
struct subscr_conn *subscr_conn = talloc_zero(g_bsc_nat, struct subscr_conn);
|
||||
|
||||
OSMO_ASSERT(subscr_conn);
|
||||
talloc_set_name(subscr_conn, "SUBSCR-CONN %s:%" PRIu32 " <=> %s:%" PRIu32,
|
||||
talloc_get_name(msc), id_cn,
|
||||
talloc_get_name(bsc), id_ran);
|
||||
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Add %s\n", talloc_get_name(subscr_conn));
|
||||
|
||||
subscr_conn->cn.id = id_cn;
|
||||
subscr_conn->cn.msc = msc;
|
||||
subscr_conn->ran.id = id_ran;
|
||||
subscr_conn->ran.bsc = bsc;
|
||||
|
||||
INIT_LLIST_HEAD(&subscr_conn->list);
|
||||
llist_add(&subscr_conn->list, &g_bsc_nat->subscr_conns);
|
||||
|
||||
return subscr_conn;
|
||||
}
|
||||
|
||||
struct subscr_conn *subscr_conn_get_by_id(uint32_t id, enum bsc_nat_net net)
|
||||
{
|
||||
struct subscr_conn *subscr_conn;
|
||||
|
||||
llist_for_each_entry(subscr_conn, &g_bsc_nat->subscr_conns, list) {
|
||||
if ((net == BSC_NAT_NET_RAN && subscr_conn->ran.id == id)
|
||||
|| (net == BSC_NAT_NET_CN && subscr_conn->cn.id == id))
|
||||
return subscr_conn;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void subscr_conn_free(struct subscr_conn *subscr_conn)
|
||||
{
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Del %s\n", talloc_get_name(subscr_conn));
|
||||
llist_del(&subscr_conn->list);
|
||||
talloc_free(subscr_conn);
|
||||
}
|
Loading…
Reference in New Issue