neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-sccp/+/32321 ) Change subject: add public API: osmo_sccp_instance_next_conn_id() ...................................................................... add public API: osmo_sccp_instance_next_conn_id() In struct osmo_sccp_instance, we have a next_id, to find an unused SCCP connection ID. This is used for inbound SCCP connections. At the same time, in each of our SCCP client programs, we have a separate mechanism to find a connection ID for outbound connections. See for example bsc_sccp.c: bsc_sccp_inst_next_conn_id() It makes much more sense for callers to use the same osmo_sccp_instance->next_id counter: - Currently the inbound and outbound counters go out of sync: For example, in osmo-bsc, if we have three MS doing a usual Complete Layer 3, osmo-bsc's counter increments by three. If we then have one Handover Required coming back from the MSC, i.e. inbound SCCP connection, the sccp_inst->next_id is behind by three, and will iterate SCCP connections three times before finding an unused id. - Each implementation has to take care to properly wrap the ID in its valid range, e.g. in osmo-bsc: test_id = (test_id + 1) & 0x00FFFFFF; if (OSMO_UNLIKELY(test_id == 0x00FFFFFF)) test_id = 0; Add public API so that callers can benefit from the internal osmo_sccp_instance->next_id and do not need to duplicate the code for staying within the proper range. Change-Id: If59d524fbe1088a59ae1b69908e2d4bf67113439 --- M include/osmocom/sigtran/sccp_sap.h M src/sccp_scoc.c 2 files changed, 41 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/21/32321/1 diff --git a/include/osmocom/sigtran/sccp_sap.h b/include/osmocom/sigtran/sccp_sap.h index 24d8832..403928f 100644 --- a/include/osmocom/sigtran/sccp_sap.h +++ b/include/osmocom/sigtran/sccp_sap.h @@ -339,3 +339,5 @@ int osmo_sccp_gt_cmp(const struct osmo_sccp_gt *a, const struct osmo_sccp_gt *b); const char *osmo_sccp_user_name(struct osmo_sccp_user *scu); + +int osmo_sccp_instance_next_conn_id(struct osmo_sccp_instance *sccp, uint32_t max_attempts); diff --git a/src/sccp_scoc.c b/src/sccp_scoc.c index 6d2499c..f42a88d 100644 --- a/src/sccp_scoc.c +++ b/src/sccp_scoc.c @@ -546,7 +546,7 @@ * \param[in] max_attempts Number of iterations to find an unused ID, or zero to iterate the entire ID number space. * \return unused ID on success (>=0) or negative on elapsed max_attempts without an unused id (<0). */ -static int osmo_sccp_instance_next_conn_id(struct osmo_sccp_instance *sccp, uint32_t max_attempts) +int osmo_sccp_instance_next_conn_id(struct osmo_sccp_instance *sccp, uint32_t max_attempts) { if (!max_attempts || max_attempts > 0x00FFFFFE) { /* Maximally iterate the entire conn id number space once. */ -- To view, visit https://gerrit.osmocom.org/c/libosmo-sccp/+/32321 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-sccp Gerrit-Branch: master Gerrit-Change-Id: If59d524fbe1088a59ae1b69908e2d4bf67113439 Gerrit-Change-Number: 32321 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr@sysmocom.de> Gerrit-MessageType: newchange