osmith has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-bsc-nat/+/27547 )


Change subject: bsc_nat: use sub-structs for cn, ran
......................................................................

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
---
M include/osmocom/bsc_nat/bsc_nat.h
M src/osmo-bsc-nat/bsc_nat.c
M src/osmo-bsc-nat/bsc_nat_fsm.c
M src/osmo-bsc-nat/bssap.c
M src/osmo-bsc-nat/vty.c
5 files changed, 42 insertions(+), 37 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc-nat refs/changes/47/27547/1

diff --git a/include/osmocom/bsc_nat/bsc_nat.h 
b/include/osmocom/bsc_nat/bsc_nat.h
index af4041b..3d863f1 100644
--- a/include/osmocom/bsc_nat/bsc_nat.h
+++ b/include/osmocom/bsc_nat/bsc_nat.h
@@ -38,8 +38,13 @@
 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);
diff --git a/src/osmo-bsc-nat/bsc_nat.c b/src/osmo-bsc-nat/bsc_nat.c
index cae65e5..409bf74 100644
--- a/src/osmo-bsc-nat/bsc_nat.c
+++ b/src/osmo-bsc-nat/bsc_nat.c
@@ -30,13 +30,13 @@
        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);
 
diff --git a/src/osmo-bsc-nat/bsc_nat_fsm.c b/src/osmo-bsc-nat/bsc_nat_fsm.c
index 1f4662f..07b9eb5 100644
--- a/src/osmo-bsc-nat/bsc_nat_fsm.c
+++ b/src/osmo-bsc-nat/bsc_nat_fsm.c
@@ -48,9 +48,9 @@

 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 @@
 {
        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 @@
                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 @@
                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 @@
                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 @@

                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 @@
                /* 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 @@
                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 @@
                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 @@
                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 @@

                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 @@
                /* 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 @@
 {
        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 @@
 {
        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)
diff --git a/src/osmo-bsc-nat/bssap.c b/src/osmo-bsc-nat/bssap.c
index 597c0e6..e5c8ca2 100644
--- a/src/osmo-bsc-nat/bssap.c
+++ b/src/osmo-bsc-nat/bssap.c
@@ -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));

diff --git a/src/osmo-bsc-nat/vty.c b/src/osmo-bsc-nat/vty.c
index 10c669a..bf86faa 100644
--- a/src/osmo-bsc-nat/vty.c
+++ b/src/osmo-bsc-nat/vty.c
@@ -45,8 +45,8 @@
 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 @@
       "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 @@
       "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;
 }


--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc-nat/+/27547
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: I6a3cc0d837a3d89e7153c2296812df0863f3471f
Gerrit-Change-Number: 27547
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <[email protected]>
Gerrit-MessageType: newchange

Reply via email to