pespin has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-bsc/+/31796 )

Change subject: Clarify type and values of sccp.conn_id
......................................................................

Clarify type and values of sccp.conn_id

Currently, the conn_id is allocated in a range 0..0xffffff by
bsc_sccp_inst_next_conn_id(), and -1 means it is unset.

This means allocation expects "int" to be at least 32 bits integer,
in order to fit 24 bits for 0..0xffffff plus the -1.
Hence, let's define the variable as uint32_t, as already done in
libosmo-sccp. Use last value 0xFFFFFFFF ((uint32_t)-1) and avoid playing
with the value being unsigned sometimes and signed only for "unset"
value.

The value is actually already handled as unsigned (printed with %u) in
most places.

Change-Id: If019bcbc1e28929fe8d981fef9103835fc6ead2e
---
M include/osmocom/bsc/gsm_data.h
M src/osmo-bsc/bsc_sccp.c
M src/osmo-bsc/bsc_subscr_conn_fsm.c
M src/osmo-bsc/lb.c
M src/osmo-bsc/osmo_bsc_sigtran.c
5 files changed, 52 insertions(+), 21 deletions(-)

Approvals:
  fixeria: Looks good to me, but someone else must approve
  daniel: Looks good to me, but someone else must approve
  Jenkins Builder: Verified
  pespin: Looks good to me, approved




diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index 533be93..268aa0c 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -51,6 +51,9 @@
  * with delta = time between expiration of T3124 and receiving HANDOVER 
FAILURE by the serving BSC. */
 #define GSM_NY1_DEFAULT ((unsigned long)((GSM_T3124_MAX + 
GSM_NY1_REQ_DELTA)/GSM_T3105_DEFAULT + 1))

+#define SCCP_CONN_ID_UNSET     0xFFFFFFFF
+#define SCCP_CONN_ID_MAX       0x00FFFFFF
+
 struct mgcp_client_conf;
 struct mgcp_client;
 struct gsm0808_cell_id;
@@ -328,8 +331,10 @@
                /* SCCP connection related */
                struct bsc_msc_data *msc;

-               /* Sigtran connection ID */
-               int conn_id;
+               /* Sigtran connection ID:
+               *  if set: Range (0..SCCP_CONN_ID_MAX) (24 bit)
+               *  if unset: SCCP_CONN_ID_UNSET (-1) if unset */
+               uint32_t conn_id;
                enum subscr_sccp_state state;
        } sccp;

@@ -379,7 +384,10 @@

                /* Lb interface to the SMLC: BSSMAP-LE/SCCP connection 
associated with this subscriber */
                struct {
-                       int conn_id;
+                       /* Sigtran connection ID:
+                       *  if set: Range (0..SCCP_CONN_ID_MAX) (24 bit)
+                       *  if unset: SCCP_CONN_ID_UNSET (-1) if unset */
+                       uint32_t conn_id;
                        enum subscr_sccp_state state;
                } lb;
        } lcs;
@@ -1022,7 +1030,7 @@
 enum gsm48_rr_cause bsc_gsm48_rr_cause_from_gsm0808_cause(enum gsm0808_cause 
c);
 enum gsm48_rr_cause bsc_gsm48_rr_cause_from_rsl_cause(uint8_t c);

-int bsc_sccp_inst_next_conn_id(struct osmo_sccp_instance *sccp);
+uint32_t bsc_sccp_inst_next_conn_id(struct osmo_sccp_instance *sccp);

 /* Interference Measurement Parameters */
 struct gsm_interf_meas_params {
diff --git a/src/osmo-bsc/bsc_sccp.c b/src/osmo-bsc/bsc_sccp.c
index 0cd1dc9..30d4c4c 100644
--- a/src/osmo-bsc/bsc_sccp.c
+++ b/src/osmo-bsc/bsc_sccp.c
@@ -26,7 +26,7 @@
 #include <osmocom/bsc/lb.h>

 /* We need an unused SCCP conn_id across all SCCP users. */
-int bsc_sccp_inst_next_conn_id(struct osmo_sccp_instance *sccp)
+uint32_t bsc_sccp_inst_next_conn_id(struct osmo_sccp_instance *sccp)
 {
        static uint32_t next_id = 1;
        int i;
@@ -34,11 +34,13 @@
        /* This looks really suboptimal, but in most cases the static next_id 
should indicate exactly the next unused
         * conn_id, and we only iterate all conns once to make super sure that 
it is not already in use. */

-       for (i = 0; i < 0xFFFFFF; i++) {
+       for (i = 0; i < SCCP_CONN_ID_MAX; i++) {
                struct gsm_subscriber_connection *conn;
                uint32_t conn_id = next_id;
                bool conn_id_already_used = false;
-               next_id = (next_id + 1) & 0xffffff;
+
+               /* Optimized modulo operation using bitwise AND: */
+               next_id = (next_id + 1) & SCCP_CONN_ID_MAX;
 
                llist_for_each_entry(conn, &bsc_gsmnet->subscr_conns, entry) {
                        if (conn->sccp.msc && conn->sccp.msc->a.sccp == sccp) {
@@ -60,5 +62,5 @@
                if (!conn_id_already_used)
                        return conn_id;
        }
-       return -1;
+       return SCCP_CONN_ID_UNSET;
 }
diff --git a/src/osmo-bsc/bsc_subscr_conn_fsm.c 
b/src/osmo-bsc/bsc_subscr_conn_fsm.c
index ebfbe82..e37f030 100644
--- a/src/osmo-bsc/bsc_subscr_conn_fsm.c
+++ b/src/osmo-bsc/bsc_subscr_conn_fsm.c
@@ -1226,8 +1226,7 @@
        conn->network = net;
        INIT_LLIST_HEAD(&conn->dtap_queue);
        INIT_LLIST_HEAD(&conn->hodec2.penalty_timers);
-       conn->sccp.conn_id = -1;
-
+       conn->sccp.conn_id = SCCP_CONN_ID_UNSET;
        /* Default clear cause (on RR translates to 
GSM48_RR_CAUSE_ABNORMAL_UNSPEC) */
        conn->clear_cause = GSM0808_CAUSE_EQUIPMENT_FAILURE;

diff --git a/src/osmo-bsc/lb.c b/src/osmo-bsc/lb.c
index 6f3cfac..c34d88e 100644
--- a/src/osmo-bsc/lb.c
+++ b/src/osmo-bsc/lb.c
@@ -32,7 +32,7 @@
 #include <osmocom/bsc/lcs_loc_req.h>
 #include <osmocom/bsc/bssmap_reset.h>

-static struct gsm_subscriber_connection *get_bsc_conn_by_lb_conn_id(int 
conn_id)
+static struct gsm_subscriber_connection *get_bsc_conn_by_lb_conn_id(uint32_t 
conn_id)
 {
        struct gsm_subscriber_connection *conn;

@@ -229,7 +229,7 @@
 static int lb_open_conn(struct gsm_subscriber_connection *conn, struct msgb 
*msg)
 {
        struct osmo_ss7_instance *ss7;
-       int conn_id;
+       uint32_t conn_id;
        int rc;

        OSMO_ASSERT(conn);
@@ -242,14 +242,14 @@
        }

        conn_id = bsc_sccp_inst_next_conn_id(bsc_gsmnet->smlc->sccp);
-       if (conn_id < 0) {
+       if (conn_id == SCCP_CONN_ID_UNSET) {
                LOGPFSMSL(conn->fi, DLCS, LOGL_ERROR, "Unable to allocate SCCP 
Connection ID for BSSMAP-LE to SMLC\n");
                return -ENOSPC;
        }
        conn->lcs.lb.conn_id = conn_id;
        ss7 = osmo_ss7_instance_find(bsc_gsmnet->smlc->cs7_instance);
        OSMO_ASSERT(ss7);
-       LOGPFSMSL(conn->fi, DLCS, LOGL_INFO, "Opening new SCCP connection 
(id=%i) to SMLC: %s\n", conn_id,
+       LOGPFSMSL(conn->fi, DLCS, LOGL_INFO, "Opening new SCCP connection 
(id=%u) to SMLC: %s\n", conn_id,
                  osmo_sccp_addr_name(ss7, &bsc_gsmnet->smlc->smlc_addr));

        rc = osmo_sccp_tx_conn_req_msg(bsc_gsmnet->smlc->sccp_user, conn_id, 
&bsc_gsmnet->smlc->bsc_addr,
diff --git a/src/osmo-bsc/osmo_bsc_sigtran.c b/src/osmo-bsc/osmo_bsc_sigtran.c
index 88ee01c..748b3f0 100644
--- a/src/osmo-bsc/osmo_bsc_sigtran.c
+++ b/src/osmo-bsc/osmo_bsc_sigtran.c
@@ -46,9 +46,9 @@
 #define DEFAULT_ASP_REMOTE_IP "localhost"

 /* Helper function to Check if the given connection id is already assigned */
-static struct gsm_subscriber_connection *get_bsc_conn_by_conn_id(int conn_id)
+static struct gsm_subscriber_connection *get_bsc_conn_by_conn_id(uint32_t 
conn_id)
 {
-       conn_id &= 0xFFFFFF;
+       conn_id &= SCCP_CONN_ID_MAX;
        struct gsm_subscriber_connection *conn;

        llist_for_each_entry(conn, &bsc_gsmnet->subscr_conns, entry) {
@@ -317,13 +317,13 @@
 {
        struct osmo_ss7_instance *ss7;
        struct bsc_msc_data *msc;
-       int conn_id;
+       uint32_t conn_id;
        int rc;

        OSMO_ASSERT(conn);
        OSMO_ASSERT(msg);
        OSMO_ASSERT(conn->sccp.msc);
-       OSMO_ASSERT(conn->sccp.conn_id == -1);
+       OSMO_ASSERT(conn->sccp.conn_id == SCCP_CONN_ID_UNSET);

        msc = conn->sccp.msc;

@@ -333,14 +333,14 @@
        }

        conn->sccp.conn_id = conn_id = 
bsc_sccp_inst_next_conn_id(conn->sccp.msc->a.sccp);
-       if (conn->sccp.conn_id < 0) {
+       if (conn->sccp.conn_id == SCCP_CONN_ID_UNSET) {
                LOGP(DMSC, LOGL_ERROR, "Unable to allocate SCCP Connection 
ID\n");
                return -1;
        }
-       LOGP(DMSC, LOGL_DEBUG, "Allocated new connection id: %d\n", 
conn->sccp.conn_id);
+       LOGP(DMSC, LOGL_DEBUG, "Allocated new connection id: %u\n", 
conn->sccp.conn_id);
        ss7 = osmo_ss7_instance_find(msc->a.cs7_instance);
        OSMO_ASSERT(ss7);
-       LOGP(DMSC, LOGL_INFO, "Opening new SCCP connection (id=%i) to MSC %d: 
%s\n", conn_id,
+       LOGP(DMSC, LOGL_INFO, "Opening new SCCP connection (id=%u) to MSC %d: 
%s\n", conn_id,
             msc->nr, osmo_sccp_addr_name(ss7, &msc->a.msc_addr));

        rc = osmo_sccp_tx_conn_req_msg(msc->a.sccp_user, conn_id, 
&msc->a.bsc_addr,

--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/31796
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: If019bcbc1e28929fe8d981fef9103835fc6ead2e
Gerrit-Change-Number: 31796
Gerrit-PatchSet: 4
Gerrit-Owner: pespin <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <[email protected]>
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to