bsc_nat: use sub-structs for cn, ran
As suggested in code review, create sub-structs for cn and ran. The following patches will fill them up with mscs, bscs etc. Related: SYS#5560 Change-Id: I6a3cc0d837a3d89e7153c2296812df0863f3471f
This commit is contained in:
parent
0aa4cb372b
commit
318b4820fc
|
@ -38,8 +38,13 @@ struct bsc_nat_sccp_inst {
|
|||
struct bsc_nat {
|
||||
struct osmo_fsm_inst *fi;
|
||||
|
||||
struct bsc_nat_sccp_inst *cn;
|
||||
struct bsc_nat_sccp_inst *ran;
|
||||
struct {
|
||||
struct bsc_nat_sccp_inst *sccp_inst;
|
||||
} cn;
|
||||
|
||||
struct {
|
||||
struct bsc_nat_sccp_inst *sccp_inst;
|
||||
} ran;
|
||||
};
|
||||
|
||||
struct bsc_nat *bsc_nat_alloc(void *tall_ctx);
|
||||
|
|
|
@ -30,13 +30,13 @@ struct bsc_nat *bsc_nat_alloc(void *tall_ctx)
|
|||
bsc_nat = talloc_zero(tall_ctx, struct bsc_nat);
|
||||
OSMO_ASSERT(bsc_nat);
|
||||
|
||||
bsc_nat->cn = talloc_zero(bsc_nat, struct bsc_nat_sccp_inst);
|
||||
OSMO_ASSERT(bsc_nat->cn);
|
||||
talloc_set_name_const(bsc_nat->cn, "struct bsc_nat_sccp_inst (CN)");
|
||||
bsc_nat->cn.sccp_inst = talloc_zero(bsc_nat, struct bsc_nat_sccp_inst);
|
||||
OSMO_ASSERT(bsc_nat->cn.sccp_inst);
|
||||
talloc_set_name_const(bsc_nat->cn.sccp_inst, "struct bsc_nat_sccp_inst (CN)");
|
||||
|
||||
bsc_nat->ran = talloc_zero(bsc_nat, struct bsc_nat_sccp_inst);
|
||||
OSMO_ASSERT(bsc_nat->ran);
|
||||
talloc_set_name_const(bsc_nat->ran, "struct bsc_nat_sccp_inst (RAN)");
|
||||
bsc_nat->ran.sccp_inst = talloc_zero(bsc_nat, struct bsc_nat_sccp_inst);
|
||||
OSMO_ASSERT(bsc_nat->ran.sccp_inst);
|
||||
talloc_set_name_const(bsc_nat->ran.sccp_inst, "struct bsc_nat_sccp_inst (RAN)");
|
||||
|
||||
bsc_nat_fsm_alloc(bsc_nat);
|
||||
|
||||
|
|
|
@ -48,9 +48,9 @@ enum bsc_nat_fsm_events {
|
|||
|
||||
static struct bsc_nat_sccp_inst *sccp_inst_dest(struct bsc_nat_sccp_inst *src)
|
||||
{
|
||||
if (src == g_bsc_nat->cn)
|
||||
return g_bsc_nat->ran;
|
||||
return g_bsc_nat->cn;
|
||||
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,
|
||||
|
@ -85,7 +85,7 @@ static int sccp_sap_get_peer_addr_out(struct bsc_nat_sccp_inst *src, struct osmo
|
|||
{
|
||||
struct bsc_nat_sccp_inst *dest = sccp_inst_dest(src);
|
||||
|
||||
if (src == g_bsc_nat->ran) {
|
||||
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;
|
||||
|
@ -126,9 +126,9 @@ static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu)
|
|||
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->scu,
|
||||
osmo_sccp_tx_conn_req(g_bsc_nat->ran.sccp_inst->scu,
|
||||
prim->u.connect.conn_id,
|
||||
&g_bsc_nat->ran->addr,
|
||||
&g_bsc_nat->ran.sccp_inst->addr,
|
||||
&peer_addr_out,
|
||||
oph->msg->data,
|
||||
msgb_length(oph->msg));
|
||||
|
@ -147,7 +147,7 @@ static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu)
|
|||
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_resp(g_bsc_nat->ran->scu,
|
||||
osmo_sccp_tx_conn_resp(g_bsc_nat->ran.sccp_inst->scu,
|
||||
prim->u.connect.conn_id,
|
||||
&peer_addr_out,
|
||||
oph->msg->data,
|
||||
|
@ -163,7 +163,7 @@ static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu)
|
|||
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_data(g_bsc_nat->ran->scu,
|
||||
osmo_sccp_tx_data(g_bsc_nat->ran.sccp_inst->scu,
|
||||
prim->u.data.conn_id,
|
||||
oph->msg->data,
|
||||
msgb_length(oph->msg));
|
||||
|
@ -177,7 +177,7 @@ static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu)
|
|||
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_ran(&peer_addr_out));
|
||||
|
||||
osmo_sccp_tx_disconn(g_bsc_nat->ran->scu,
|
||||
osmo_sccp_tx_disconn(g_bsc_nat->ran.sccp_inst->scu,
|
||||
prim->u.disconnect.conn_id,
|
||||
&prim->u.disconnect.responding_addr,
|
||||
prim->u.disconnect.cause);
|
||||
|
@ -196,8 +196,8 @@ static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu)
|
|||
/* 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->scu,
|
||||
&g_bsc_nat->ran->addr,
|
||||
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));
|
||||
|
@ -240,9 +240,9 @@ static int sccp_sap_up_ran(struct osmo_prim_hdr *oph, void *scu)
|
|||
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_cn(&peer_addr_out));
|
||||
|
||||
msgb_pull_to_l2(oph->msg);
|
||||
osmo_sccp_tx_conn_req(g_bsc_nat->cn->scu,
|
||||
osmo_sccp_tx_conn_req(g_bsc_nat->cn.sccp_inst->scu,
|
||||
prim->u.connect.conn_id,
|
||||
&g_bsc_nat->cn->addr,
|
||||
&g_bsc_nat->cn.sccp_inst->addr,
|
||||
&peer_addr_out,
|
||||
oph->msg->data,
|
||||
msgb_length(oph->msg));
|
||||
|
@ -261,7 +261,7 @@ static int sccp_sap_up_ran(struct osmo_prim_hdr *oph, void *scu)
|
|||
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_cn(&peer_addr_out));
|
||||
|
||||
msgb_pull_to_l2(oph->msg);
|
||||
osmo_sccp_tx_conn_resp(g_bsc_nat->cn->scu,
|
||||
osmo_sccp_tx_conn_resp(g_bsc_nat->cn.sccp_inst->scu,
|
||||
prim->u.connect.conn_id,
|
||||
&peer_addr_out,
|
||||
oph->msg->data,
|
||||
|
@ -277,7 +277,7 @@ static int sccp_sap_up_ran(struct osmo_prim_hdr *oph, void *scu)
|
|||
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_cn(&peer_addr_out));
|
||||
|
||||
msgb_pull_to_l2(oph->msg);
|
||||
osmo_sccp_tx_data(g_bsc_nat->cn->scu,
|
||||
osmo_sccp_tx_data(g_bsc_nat->cn.sccp_inst->scu,
|
||||
prim->u.data.conn_id,
|
||||
oph->msg->data,
|
||||
msgb_length(oph->msg));
|
||||
|
@ -291,7 +291,7 @@ static int sccp_sap_up_ran(struct osmo_prim_hdr *oph, void *scu)
|
|||
|
||||
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_cn(&peer_addr_out));
|
||||
|
||||
osmo_sccp_tx_disconn(g_bsc_nat->cn->scu,
|
||||
osmo_sccp_tx_disconn(g_bsc_nat->cn.sccp_inst->scu,
|
||||
prim->u.disconnect.conn_id,
|
||||
&prim->u.disconnect.responding_addr,
|
||||
prim->u.disconnect.cause);
|
||||
|
@ -314,8 +314,8 @@ static int sccp_sap_up_ran(struct osmo_prim_hdr *oph, void *scu)
|
|||
/* 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->cn->scu,
|
||||
&g_bsc_nat->cn->addr,
|
||||
osmo_sccp_tx_unitdata(g_bsc_nat->cn.sccp_inst->scu,
|
||||
&g_bsc_nat->cn.sccp_inst->addr,
|
||||
&peer_addr_out,
|
||||
oph->msg->data,
|
||||
msgb_length(oph->msg));
|
||||
|
@ -380,12 +380,12 @@ static void st_starting_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state)
|
|||
{
|
||||
struct bsc_nat *bsc_nat = (struct bsc_nat *)fi->priv;
|
||||
|
||||
if (sccp_inst_init(bsc_nat->cn, "OsmoBSCNAT-CN", DEFAULT_PC_CN, sccp_sap_up_cn, OSMO_SCCP_SSN_BSSAP) < 0) {
|
||||
if (sccp_inst_init(bsc_nat->cn.sccp_inst, "OsmoBSCNAT-CN", DEFAULT_PC_CN, sccp_sap_up_cn, OSMO_SCCP_SSN_BSSAP) < 0) {
|
||||
osmo_fsm_inst_state_chg(fi, BSC_NAT_FSM_ST_STOPPED, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sccp_inst_init(bsc_nat->ran, "OsmoBSCNAT-RAN", DEFAULT_PC_RAN, sccp_sap_up_ran, OSMO_SCCP_SSN_BSSAP) < 0) {
|
||||
if (sccp_inst_init(bsc_nat->ran.sccp_inst, "OsmoBSCNAT-RAN", DEFAULT_PC_RAN, sccp_sap_up_ran, OSMO_SCCP_SSN_BSSAP) < 0) {
|
||||
osmo_fsm_inst_state_chg(fi, BSC_NAT_FSM_ST_STOPPED, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
@ -408,11 +408,11 @@ static void st_stopped_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state)
|
|||
{
|
||||
struct bsc_nat *bsc_nat = (struct bsc_nat *)fi->priv;
|
||||
|
||||
sccp_inst_free(bsc_nat->cn);
|
||||
bsc_nat->cn = NULL;
|
||||
sccp_inst_free(bsc_nat->cn.sccp_inst);
|
||||
bsc_nat->cn.sccp_inst = NULL;
|
||||
|
||||
sccp_inst_free(bsc_nat->ran);
|
||||
bsc_nat->ran = NULL;
|
||||
sccp_inst_free(bsc_nat->ran.sccp_inst);
|
||||
bsc_nat->ran.sccp_inst = NULL;
|
||||
}
|
||||
|
||||
static void st_stopped(struct osmo_fsm_inst *fi, uint32_t event, void *data)
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
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;
|
||||
struct bsc_nat_sccp_inst *sccp_inst = g_bsc_nat->ran.sccp_inst;
|
||||
|
||||
LOGP(DMAIN, LOGL_NOTICE, "Rx RESET from %s\n", bsc_nat_print_addr_ran(addr));
|
||||
|
||||
|
|
|
@ -45,8 +45,8 @@ DEFUN(cfg_bsc_nat,
|
|||
static int config_write_bsc_nat(struct vty *vty)
|
||||
{
|
||||
vty_out(vty, "bsc-nat%s", VTY_NEWLINE);
|
||||
vty_out(vty, " cs7-instance-cn %u%s", g_bsc_nat->cn->ss7_id, VTY_NEWLINE);
|
||||
vty_out(vty, " cs7-instance-ran %u%s", g_bsc_nat->ran->ss7_id, VTY_NEWLINE);
|
||||
vty_out(vty, " cs7-instance-cn %u%s", g_bsc_nat->cn.sccp_inst->ss7_id, VTY_NEWLINE);
|
||||
vty_out(vty, " cs7-instance-ran %u%s", g_bsc_nat->ran.sccp_inst->ss7_id, VTY_NEWLINE);
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ DEFUN(cfg_cs7_instance_cn,
|
|||
"cs7-instance-cn <0-15>",
|
||||
"Set SS7 to be used to connect to CN-side\n" SS7_REF_STR)
|
||||
{
|
||||
g_bsc_nat->cn->ss7_id = atoi(argv[0]);
|
||||
g_bsc_nat->cn.sccp_inst->ss7_id = atoi(argv[0]);
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ DEFUN(cfg_cs7_instance_ran,
|
|||
"cs7-instance-ran <0-15>",
|
||||
"Set SS7 to be used to connect to RAN-side\n" SS7_REF_STR)
|
||||
{
|
||||
g_bsc_nat->ran->ss7_id = atoi(argv[0]);
|
||||
g_bsc_nat->ran.sccp_inst->ss7_id = atoi(argv[0]);
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue