pespin has uploaded this change for review. (
https://gerrit.osmocom.org/c/libosmo-sigtran/+/40003?usp=email )
Change subject: ipa: Try picking unused asp_id in AS to use as SLS
......................................................................
ipa: Try picking unused asp_id in AS to use as SLS
Initially (b93e1d01205cdd7bd7a65e15945f664f31fb4bcb), incoming traffic
from IPA sockets was tagged with SLS using the LSB of the socket file
descriptor. that did however not achieve sufficient entropy in real
world use cases.
Later on (2c9ba16c2c0210a189c72064eafad5ef336254cd), SLS tagging was
changed to pseudo-random generation.
Still it has been found too that it may create bad entropy under certain
condtions, with eg. havig only 2 incoming ASPs and both ending up with
the same asp_id/SLS, which won't allow for proper load sharing towards
other peers.
This commit changes the previous method by delaying SLS assignment
decision of the socket until the ASP becomes assigned to an AS
(basically during IPA handshake, when we receive IPA IDENTITY RESPONSE
with the Unit-Name, or when we receive the IPA IDENTITY ACK for it).
It is fine delaying SLS assignment to that point, since it's impossible
to receive any userplane data before that handhsake ocurrs.
Once the ASP is assigned to the AS (IPA ASPs can only be part of one
AS), we lookup the other ASPs in the AS to try to allocate an unused
4-bit asp_id which will end up being used as SLS.
Related: SYS#6543
Related: SYS#6802
Change-Id: I723eac25e59002630dca87a738c8eb7c62edec75
---
M src/osmo_ss7_asp.c
M src/osmo_ss7_xua_srv.c
M src/xua_asp_fsm.c
3 files changed, 41 insertions(+), 12 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran refs/changes/03/40003/1
diff --git a/src/osmo_ss7_asp.c b/src/osmo_ss7_asp.c
index f785264..7e444b4 100644
--- a/src/osmo_ss7_asp.c
+++ b/src/osmo_ss7_asp.c
@@ -979,12 +979,6 @@
if (asp->cfg.trans_proto == IPPROTO_SCTP) {
rc = ss7_asp_apply_peer_primary_address(asp);
rc = ss7_asp_apply_primary_address(asp);
- } else {
- if (asp->cfg.proto == OSMO_SS7_ASP_PROT_IPA) {
- /* we use the lower 4 bits of the asp_id field as SLS;
- * let's initialize it here from a pseudo-random value */
- asp->asp_id = rand() & 0xf;
- }
}
if (asp->lm && asp->lm->prim_cb) {
diff --git a/src/osmo_ss7_xua_srv.c b/src/osmo_ss7_xua_srv.c
index 35e360f..52a3508 100644
--- a/src/osmo_ss7_xua_srv.c
+++ b/src/osmo_ss7_xua_srv.c
@@ -180,12 +180,6 @@
if (asp->cfg.trans_proto == IPPROTO_SCTP) {
rc = ss7_asp_apply_peer_primary_address(asp);
rc = ss7_asp_apply_primary_address(asp);
- } else {
- if (asp->cfg.proto == OSMO_SS7_ASP_PROT_IPA) {
- /* we use the lower 4 bits of the asp_id field as SLS;
- * let's initialize it here from a pseudo-random value */
- asp->asp_id = rand() & 0xf;
- }
}
/* send M-SCTP_ESTABLISH.ind to Layer Manager */
diff --git a/src/xua_asp_fsm.c b/src/xua_asp_fsm.c
index ec149d1..0c5159f 100644
--- a/src/xua_asp_fsm.c
+++ b/src/xua_asp_fsm.c
@@ -1104,6 +1104,41 @@
}
}
+static bool _ipa_asp_fsm_handshake_done(struct osmo_ss7_asp *asp)
+{
+ if (!asp->fi)
+ return false;
+ return asp->fi->state == XUA_ASP_S_INACTIVE || asp->fi->state ==
XUA_ASP_S_ACTIVE;
+}
+
+/* Assign a 4 bit asp_id (as unqiue as possible) which will be used as SLS for incoming
IPA PDUs.*/
+static void _ss7_asp_pick_unused_asp_id_as_sls(struct osmo_ss7_asp *asp, const struct
osmo_ss7_as *as)
+{
+ for (unsigned int asp_id = 0; asp_id <= 0x0f; asp_id++) {
+ bool used = false;
+ for (unsigned i = 0; i < ARRAY_SIZE(as->cfg.asps); i++) {
+ if (!as->cfg.asps[i])
+ continue;
+ if (as->cfg.asps[i] == asp)
+ continue;
+ if (!_ipa_asp_fsm_handshake_done(as->cfg.asps[i]))
+ continue;
+ if (as->cfg.asps[i]->asp_id == asp_id) {
+ used = true;
+ break;
+ }
+ }
+ if (used)
+ continue;
+ /* Found an unused asp_id, use it: */
+ asp->asp_id = asp_id;
+ LOGPASP(asp, DLSS7, LOGL_DEBUG, "Assigned unsued asp_id = %u to be used as
SLS\n", asp_id);
+ return;
+ }
+ LOGPASP(asp, DLSS7, LOGL_INFO, "All asp_ids in IPA AS picked, unique SLS not
possible, picking random one\n");
+ asp->asp_id = rand() & 0x0f;
+}
+
static void ipa_asp_allstate(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct ipa_asp_fsm_priv *iafp = fi->priv;
@@ -1130,6 +1165,12 @@
case XUA_ASP_E_AS_ASSIGNED:
as = data;
osmo_talloc_replace_string(iafp->ipa_unit, &iafp->ipa_unit->unit_name,
as->cfg.name);
+ /* In IPA, asp_id is not really used on the wire, and we
+ * actually use it internally the lower 4 bits of the field to
+ * fill in a potentailly unique SLS to apply to PDUs received from the IPA socket.
+ * Now that AS is known, try picking an unused asp_id inside the AS.
+ * we use the lower 4 bits of the asp_id field as SLS; */
+ _ss7_asp_pick_unused_asp_id_as_sls(iafp->asp, as);
/* Now that the AS is known, start the client side: */
if (iafp->role == OSMO_SS7_ASP_ROLE_ASP && fi->state == IPA_ASP_S_DOWN)
{
LOGPFSML(fi, LOGL_NOTICE, "Bringing up ASP now once it has been assigned to an
AS\n");
--
To view, visit
https://gerrit.osmocom.org/c/libosmo-sigtran/+/40003?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: libosmo-sigtran
Gerrit-Branch: master
Gerrit-Change-Id: I723eac25e59002630dca87a738c8eb7c62edec75
Gerrit-Change-Number: 40003
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>