Neels Hofmeyr has uploaded this change for review. ( 
https://gerrit.osmocom.org/13278


Change subject: add osmo_sccp_inst_unused_conn_id()
......................................................................

add osmo_sccp_inst_unused_conn_id()

On incoming connections, sccp_scoc.c assigns a new local reference
(osmo_scu_prim conn_id) to a conn. When creating a new outgoing connection, the
caller needs to provide that.

Allow callers to use the same local reference creation code that is used on
incoming connections.

Change-Id: I6e1b4897f4143b97bf90bfd8d0ae5d50bbd2e1dd
---
M include/osmocom/sigtran/sccp_sap.h
M src/sccp_scoc.c
2 files changed, 25 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/78/13278/1

diff --git a/include/osmocom/sigtran/sccp_sap.h 
b/include/osmocom/sigtran/sccp_sap.h
index f1fdd98..def8459 100644
--- a/include/osmocom/sigtran/sccp_sap.h
+++ b/include/osmocom/sigtran/sccp_sap.h
@@ -250,6 +250,8 @@
 struct osmo_ss7_instance *osmo_sccp_get_ss7(const struct osmo_sccp_instance 
*sccp);
 struct osmo_sccp_instance *osmo_sccp_get_sccp(const struct osmo_sccp_user 
*scu);

+int osmo_sccp_instance_unused_conn_id(struct osmo_sccp_instance *inst, 
uint32_t *conn_id);
+
 void osmo_sccp_user_unbind(struct osmo_sccp_user *scu);
 void osmo_sccp_user_set_priv(struct osmo_sccp_user *scu, void *priv);
 void *osmo_sccp_user_get_priv(struct osmo_sccp_user *scu);
diff --git a/src/sccp_scoc.c b/src/sccp_scoc.c
index 6a56692..db3ded7 100644
--- a/src/sccp_scoc.c
+++ b/src/sccp_scoc.c
@@ -47,6 +47,7 @@
  */

 #include <string.h>
+#include <errno.h>

 #include <osmocom/core/utils.h>
 #include <osmocom/core/linuxlist.h>
@@ -485,14 +486,30 @@
        return conn;
 }

+/* Return a free connection ID (local reference) */
+int osmo_sccp_instance_unused_conn_id(struct osmo_sccp_instance *inst, 
uint32_t *conn_id)
+{
+       uint32_t id;
+       uint32_t started_at = inst->next_id;
+
+       do {
+               id = inst->next_id++;
+               if (inst->next_id == started_at) {
+                       LOGP(DLSCCP, LOGL_ERROR, "No unused local reference 
available\n");
+                       return -ENOSPC;
+               }
+       } while (conn_find_by_id(inst, id));
+
+       *conn_id = id;
+       return 0;
+}
+
 /* Search for next free connection ID (local reference) and allocate conn */
 static struct sccp_connection *conn_create(struct osmo_sccp_instance *inst)
 {
        uint32_t conn_id;
-
-       do {
-               conn_id = inst->next_id++;
-       } while (conn_find_by_id(inst, conn_id));
+       if (osmo_sccp_instance_unused_conn_id(inst, &conn_id))
+               return NULL;

        return conn_create_id(inst, conn_id);
 }
@@ -1616,6 +1633,8 @@
                }
                /* Allocate new connection */
                conn = conn_create(inst);
+               if (!conn)
+                       return;
                conn->user = scu;
                conn->incoming = true;
        } else {

--
To view, visit https://gerrit.osmocom.org/13278
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6e1b4897f4143b97bf90bfd8d0ae5d50bbd2e1dd
Gerrit-Change-Number: 13278
Gerrit-PatchSet: 1
Gerrit-Owner: Neels Hofmeyr <[email protected]>

Reply via email to