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


Change subject: Refactor subscr_conn_get_next_id
......................................................................

Refactor subscr_conn_get_next_id

Prepare to use this function for generating MGW call IDs too, by
replacing the net argument with a new id_type enum that will get a
SUBSCR_CONN_ID_TYPE_CALL_ID_MGW in a future patch.

Related: SYS#5560
Change-Id: I77b0ef33f94c401d24f38eb8d79e1007234e0ab4
---
M include/osmocom/bsc_nat/subscr_conn.h
M src/osmo-bsc-nat/bsc_nat_fsm.c
M src/osmo-bsc-nat/subscr_conn.c
3 files changed, 32 insertions(+), 8 deletions(-)



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

diff --git a/include/osmocom/bsc_nat/subscr_conn.h 
b/include/osmocom/bsc_nat/subscr_conn.h
index 7de3f0f..7a0dc44 100644
--- a/include/osmocom/bsc_nat/subscr_conn.h
+++ b/include/osmocom/bsc_nat/subscr_conn.h
@@ -21,6 +21,12 @@

 #include <osmocom/bsc_nat/bsc_nat.h>

+enum subscr_conn_id_type {
+       SUBSCR_CONN_ID_TYPE_CONN_ID_CN = 0,
+       SUBSCR_CONN_ID_TYPE_CONN_ID_RAN,
+       /* SUBSCR_CONN_ID_TYPE_CALL_ID_MGW will be added in future patch */
+};
+
 /* connection for one subscriber */
 struct subscr_conn {
        struct llist_head list;
@@ -36,7 +42,7 @@
        } ran;
 };

-int subscr_conn_get_next_id(enum bsc_nat_net net);
+int subscr_conn_get_next_id(enum subscr_conn_id_type id_type);

 struct subscr_conn *subscr_conn_alloc(struct msc *msc, struct bsc *bsc, 
uint32_t id_cn, uint32_t id_ran);

diff --git a/src/osmo-bsc-nat/bsc_nat_fsm.c b/src/osmo-bsc-nat/bsc_nat_fsm.c
index ce3beed..4d36fb1 100644
--- a/src/osmo-bsc-nat/bsc_nat_fsm.c
+++ b/src/osmo-bsc-nat/bsc_nat_fsm.c
@@ -200,7 +200,8 @@
                        goto error;
                }

-               subscr_conn = subscr_conn_alloc(msc, bsc, 
subscr_conn_get_next_id(BSC_NAT_NET_CN), prim->u.connect.conn_id);
+               subscr_conn = subscr_conn_alloc(msc, bsc, 
subscr_conn_get_next_id(SUBSCR_CONN_ID_TYPE_CONN_ID_RAN),
+                                               prim->u.connect.conn_id);

                LOGP(DMAIN, LOGL_DEBUG, "Fwd via %s\n", 
talloc_get_name(subscr_conn));

diff --git a/src/osmo-bsc-nat/subscr_conn.c b/src/osmo-bsc-nat/subscr_conn.c
index 02afb7d..5a918ba 100644
--- a/src/osmo-bsc-nat/subscr_conn.c
+++ b/src/osmo-bsc-nat/subscr_conn.c
@@ -27,14 +27,20 @@
 #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)
+int subscr_conn_get_next_id(enum subscr_conn_id_type id_type)
 {
        uint32_t *id;

-       if (net == BSC_NAT_NET_RAN)
-               id = &g_bsc_nat->ran.subscr_conn_id_next;
-       else
+       switch (id_type) {
+       case SUBSCR_CONN_ID_TYPE_CONN_ID_CN:
                id = &g_bsc_nat->cn.subscr_conn_id_next;
+               break;
+       case SUBSCR_CONN_ID_TYPE_CONN_ID_RAN:
+               id = &g_bsc_nat->ran.subscr_conn_id_next;
+               break;
+       default:
+               OSMO_ASSERT(false);
+       }

        for (int i = 0; i < 0xFFFFFF; i++) {
                struct subscr_conn *subscr_conn;
@@ -43,8 +49,19 @@
                *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)) {
+                       uint32_t subscr_id;
+
+                       switch (id_type) {
+                       case SUBSCR_CONN_ID_TYPE_CONN_ID_CN:
+                               subscr_id = subscr_conn->cn.id;
+                               break;
+                       case SUBSCR_CONN_ID_TYPE_CONN_ID_RAN:
+                               subscr_id = subscr_conn->ran.id;
+                               break;
+                       default:
+                               OSMO_ASSERT(false);
+                       }
+                       if (*id == subscr_id) {
                                already_used = true;
                                break;
                        }

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

Reply via email to