This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-sccp/+/22775 ) Change subject: m3ua: Move find_as_for_asp() to shared xua_find_as_for_asp() ...................................................................... m3ua: Move find_as_for_asp() to shared xua_find_as_for_asp() This way the function can be re-used by SUA. Change-Id: I0dfc5a7a24dd068002e837dc47eb0778c503cac5 --- M src/Makefile.am M src/m3ua.c M src/xua_internal.h A src/xua_shared.c 4 files changed, 108 insertions(+), 56 deletions(-) Approvals: Jenkins Builder: Verified pespin: Looks good to me, but someone else must approve laforge: Looks good to me, approved diff --git a/src/Makefile.am b/src/Makefile.am index 484886c..91084de 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,7 +29,7 @@ libosmo_sigtran_la_SOURCES = sccp_sap.c sua.c m3ua.c xua_msg.c sccp_helpers.c \ sccp2sua.c sccp_scrc.c sccp_sclc.c sccp_scoc.c \ - sccp_user.c sccp_types.c xua_rkm.c xua_default_lm_fsm.c \ + sccp_user.c sccp_types.c xua_rkm.c xua_shared.c xua_default_lm_fsm.c \ osmo_ss7.c osmo_ss7_hmrt.c xua_asp_fsm.c xua_as_fsm.c \ osmo_ss7_vty.c sccp_vty.c ipa.c libosmo_sigtran_la_LDFLAGS = -version-info $(LIBVERSION) -no-undefined -export-symbols-regex '^osmo_' diff --git a/src/m3ua.c b/src/m3ua.c index 542777e..bfb0c23 100644 --- a/src/m3ua.c +++ b/src/m3ua.c @@ -532,60 +532,6 @@ return data_hdr; } -/* if given ASP only has one AS, return that AS */ -static struct osmo_ss7_as *find_single_as_for_asp(const struct osmo_ss7_asp *asp) -{ - struct osmo_ss7_as *as, *as_found = NULL; - - llist_for_each_entry(as, &asp->inst->as_list, list) { - if (!osmo_ss7_as_has_asp(as, asp)) - continue; - /* check if we already had found another AS within this ASP -> not unique */ - if (as_found) - return NULL; - as_found = as; - } - - return as_found; -} - -static int find_as_for_asp(struct osmo_ss7_as **as, const struct osmo_ss7_asp *asp, - const struct xua_msg_part *rctx_ie) -{ - *as = NULL; - - if (rctx_ie) { - uint32_t rctx = xua_msg_part_get_u32(rctx_ie); - /* Use routing context IE to look up the AS for which the - * message was received. */ - *as = osmo_ss7_as_find_by_rctx(asp->inst, rctx); - if (!*as) { - LOGPASP(asp, DLM3UA, LOGL_ERROR, "%s(): invalid routing context: %u\n", - __func__, rctx); - return M3UA_ERR_INVAL_ROUT_CTX; - } - - /* Verify that this ASP is part of the AS. */ - if (!osmo_ss7_as_has_asp(*as, asp)) { - LOGPASP(asp, DLM3UA, LOGL_ERROR, - "%s(): This Application Server Process is not part of the AS %s " - "resolved by routing context %u\n", __func__, (*as)->cfg.name, rctx); - return M3UA_ERR_NO_CONFGD_AS_FOR_ASP; - } - } else { - /* no explicit routing context; this only works if there is only one AS in the ASP */ - *as = find_single_as_for_asp(asp); - if (!*as) { - LOGPASP(asp, DLM3UA, LOGL_ERROR, - "%s(): ASP sent M3UA without Routing Context IE but unable to uniquely " - "identify the AS for this message\n", __func__); - return M3UA_ERR_INVAL_ROUT_CTX; - } - } - - return 0; -} - static int m3ua_rx_xfer(struct osmo_ss7_asp *asp, struct xua_msg *xua) { struct xua_msg_part *rctx_ie = xua_msg_find_tag(xua, M3UA_IEI_ROUTE_CTX); @@ -603,7 +549,7 @@ return M3UA_ERR_UNSUPP_MSG_TYPE; } - rc = find_as_for_asp(&as, asp, rctx_ie); + rc = xua_find_as_for_asp(&as, asp, rctx_ie); if (rc) return rc; diff --git a/src/xua_internal.h b/src/xua_internal.h index d836fae..65adfb6 100644 --- a/src/xua_internal.h +++ b/src/xua_internal.h @@ -69,6 +69,8 @@ int xua_as_transmit_msg(struct osmo_ss7_as *as, struct msgb *msg); +int xua_find_as_for_asp(struct osmo_ss7_as **as, const struct osmo_ss7_asp *asp, + const struct xua_msg_part *rctx_ie); int ipa_tx_xua_as(struct osmo_ss7_as *as, struct xua_msg *xua); int ipa_rx_msg(struct osmo_ss7_asp *asp, struct msgb *msg); diff --git a/src/xua_shared.c b/src/xua_shared.c new file mode 100644 index 0000000..cdd6f7f --- /dev/null +++ b/src/xua_shared.c @@ -0,0 +1,104 @@ +/* Shared code between M3UA and SUA implementation */ + +/* (C) 2015-2021 by Harald Welte <laforge at gnumonks.org> + * All Rights Reserved + * + * SPDX-License-Identifier: GPL-2.0+ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <stdint.h> +#include <unistd.h> +#include <string.h> + +#include <osmocom/core/utils.h> +#include <osmocom/core/linuxlist.h> +#include <osmocom/core/logging.h> + +#include <osmocom/sigtran/xua_msg.h> + +#include <osmocom/sigtran/osmo_ss7.h> +#include <osmocom/sigtran/protocol/m3ua.h> +#include <osmocom/sigtran/protocol/sua.h> + +#include "xua_internal.h" + +/* if given ASP only has one AS, return that AS */ +static struct osmo_ss7_as *find_single_as_for_asp(const struct osmo_ss7_asp *asp) +{ + struct osmo_ss7_as *as, *as_found = NULL; + + llist_for_each_entry(as, &asp->inst->as_list, list) { + if (!osmo_ss7_as_has_asp(as, asp)) + continue; + /* check if we already had found another AS within this ASP -> not unique */ + if (as_found) + return NULL; + as_found = as; + } + + return as_found; +} + +/* this is why we can use the M3UA constants below in a function shared between M3UA + SUA */ +osmo_static_assert(M3UA_ERR_INVAL_ROUT_CTX == SUA_ERR_INVAL_ROUT_CTX, _err_rctx); +osmo_static_assert(M3UA_ERR_NO_CONFGD_AS_FOR_ASP == SUA_ERR_NO_CONFGD_AS_FOR_ASP, _err_as_for_asp); + +/*! Find the AS for given ASP + optional routing context IE. + * if rctx_ie == NULL, we assume that this ASP is only part of a single AS; + * if rctx_ie is given, then we look-up the ASP based on the routing context, + * and verify that this ASP is part of it. + * \param[out] as caller-provided address-of-pointer to store the found AS + * \param[in] asp ASP for which we want to look-up the AS + * \param[in] rctx_ie routing context IE (may be NULL) to use for look-up + * \returns 0 in case of success; {M3UA,SUA}_ERR_* code in case of error. */ +int xua_find_as_for_asp(struct osmo_ss7_as **as, const struct osmo_ss7_asp *asp, + const struct xua_msg_part *rctx_ie) +{ + int log_ss = osmo_ss7_asp_get_log_subsys(asp); + *as = NULL; + + if (rctx_ie) { + uint32_t rctx = xua_msg_part_get_u32(rctx_ie); + /* Use routing context IE to look up the AS for which the + * message was received. */ + *as = osmo_ss7_as_find_by_rctx(asp->inst, rctx); + if (!*as) { + LOGPASP(asp, log_ss, LOGL_ERROR, "%s(): invalid routing context: %u\n", + __func__, rctx); + return M3UA_ERR_INVAL_ROUT_CTX; + } + + /* Verify that this ASP is part of the AS. */ + if (!osmo_ss7_as_has_asp(*as, asp)) { + LOGPASP(asp, log_ss, LOGL_ERROR, + "%s(): This Application Server Process is not part of the AS %s " + "resolved by routing context %u\n", __func__, (*as)->cfg.name, rctx); + return M3UA_ERR_NO_CONFGD_AS_FOR_ASP; + } + } else { + /* no explicit routing context; this only works if there is only one AS in the ASP */ + *as = find_single_as_for_asp(asp); + if (!*as) { + LOGPASP(asp, log_ss, LOGL_ERROR, + "%s(): ASP sent M3UA without Routing Context IE but unable to uniquely " + "identify the AS for this message\n", __func__); + return M3UA_ERR_INVAL_ROUT_CTX; + } + } + + return 0; +} -- To view, visit https://gerrit.osmocom.org/c/libosmo-sccp/+/22775 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-sccp Gerrit-Branch: master Gerrit-Change-Id: I0dfc5a7a24dd068002e837dc47eb0778c503cac5 Gerrit-Change-Number: 22775 Gerrit-PatchSet: 2 Gerrit-Owner: laforge <laforge at osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge at osmocom.org> Gerrit-Reviewer: pespin <pespin at sysmocom.de> Gerrit-MessageType: merged -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210208/8154467a/attachment.htm>