From d897e7daa6138f815f2de71630e2a0de5f32ff64 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Thu, 25 Jun 2020 19:37:44 +0200 Subject: osmo_sccp_simple_client_on_ss7_id(): do not care about ASP name Our manuals explain that the cs7 config automatically adds missing parts. However, previous code requires an ASP to exactly match the default name that the autoconfiguration would choose -- that is unintuitive. If a config included only an ASP, or both AS and ASP but omitting to add the ASP to the AS, auto configuration would pick it up iff it exactly had the name the application chose. For osmo-bsc, that was 'asp-clnt-msc-0', if 'msc 0' is the first MSC in the config file. For osmo-msc, it is 'asp-clnt-OsmoMSC-A' or 'asp-clnt-OsmoMSC-A-Iu' and so forth, so it is not always clear which name the user should pick to get the ASP used by auto config. Refactor so that any ASP with a matching protocol that is not associated with any AS yet is picked up by the auto configuration, i.e. associated with the AS etc., regardless of the name chosen in the config file. Related: OS#4635 Change-Id: I2954e0167729fd0b1a7d0144a5b5775fc1c44c35 --- src/sccp_user.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/sccp_user.c b/src/sccp_user.c index d8a7357..e1329ac 100644 --- a/src/sccp_user.c +++ b/src/sccp_user.c @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -574,13 +575,33 @@ osmo_sccp_simple_client_on_ss7_id(void *ctx, uint32_t ss7_id, const char *name, * we intend to use. */ asp = osmo_ss7_asp_find_by_proto(as, prot); if (!asp) { - /* Check if the user has already created an ASP elsewhere under - * the default asp name. */ - asp_name = talloc_asprintf(ctx, "asp-clnt-%s", name); - asp = osmo_ss7_asp_find_by_name(ss7, asp_name); + /* Check if the user has created an ASP for this proto that is not added on any AS yet. */ + struct osmo_ss7_asp *asp_i; + llist_for_each_entry(asp_i, &ss7->asp_list, list) { + struct osmo_ss7_as *as_i; + bool is_on_as = false; + if (asp_i->cfg.proto != prot) + continue; + llist_for_each_entry(as_i, &ss7->as_list, list) { + if (!osmo_ss7_as_has_asp(as_i, asp_i)) + continue; + is_on_as = true; + break; + } + if (is_on_as) { + /* This ASP is already on another AS. If it was on this AS, we'd have found it above. */ + continue; + } + /* This ASP matches the protocol and is not yet associated to any AS. Use it. */ + asp = asp_i; + LOGP(DLSCCP, LOGL_NOTICE, "%s: ASP %s for %s is not associated with any AS, using it\n", + name, asp->cfg.name, osmo_ss7_asp_protocol_name(prot)); + break; + } if (!asp) { - LOGP(DLSCCP, LOGL_NOTICE, "%s: Creating ASP instance\n", - name); + asp_name = talloc_asprintf(ctx, "asp-clnt-%s", name); + LOGP(DLSCCP, LOGL_NOTICE, "%s: No unassociated ASP for %s, creating new ASP %s\n", + name, osmo_ss7_asp_protocol_name(prot), asp_name); asp = osmo_ss7_asp_find_or_create(ss7, asp_name, default_remote_port, @@ -593,8 +614,7 @@ osmo_sccp_simple_client_on_ss7_id(void *ctx, uint32_t ss7_id, const char *name, osmo_ss7_asp_peer_set_hosts(&asp->cfg.local, asp, &default_local_ip, 1); osmo_ss7_asp_peer_set_hosts(&asp->cfg.remote, asp, &default_remote_ip, 1); asp->simple_client_allocated = true; - } else - talloc_free(asp_name); + } osmo_ss7_as_add_asp(as, asp->cfg.name); } -- cgit v1.2.3