pespin submitted this change.
Avoid allocating conn_id 0x00FFFFFF
The 0x00FFFFFF source local reference is reserved in M3UA/SCCP, hence
avoid allocating a conn_id with that value since later on when reused as
a source local reference it would fail to be encoded.
Change-Id: Ifcf710ef6024286a1cc3473d6ea3f858552b9926
---
M src/sccp_scoc.c
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/src/sccp_scoc.c b/src/sccp_scoc.c
index 00e677c..2430462 100644
--- a/src/sccp_scoc.c
+++ b/src/sccp_scoc.c
@@ -507,10 +507,22 @@
{
uint32_t conn_id;
+ /* SUA: RFC3868 sec 3.10.4:
+ * The source reference number is a 4 octet long integer.
+ * This is allocated by the source SUA instance.
+ * M3UA/SCCP: ITU-T Q.713 sec 3.3:
+ * The "source local reference" parameter field is a three-octet field containing a
+ * reference number which is generated and used by the local node to identify the
+ * connection section after the connection section is set up.
+ * The coding "all ones" is reserved for future use.
+ * Hence, as we currently use the connection ID also as local reference,
+ * let's simply use 24 bit ids to fit all link types (excluding 0x00ffffff).
+ */
do {
- /* modulo 2^24 as we currently use the connection ID also as local
- * reference, and that is limited to 24 bits */
- user->inst->next_id = (user->inst->next_id + 1) % (1 << 24);
+ /* Optimized modulo operation (% 0x00FFFFFE) using bitwise AND plus CMP: */
+ user->inst->next_id = (user->inst->next_id + 1) & 0x00FFFFFF;
+ if (OSMO_UNLIKELY(user->inst->next_id == 0x00FFFFFF))
+ user->inst->next_id = 0;
conn_id = user->inst->next_id;
} while (conn_find_by_id(user->inst, conn_id));
To view, visit change 31825. To unsubscribe, or for help writing mail filters, visit settings.