Change in libosmocore[master]: gprs_ns2: dynamic NS-VC + NSE creation for IP-SNS in SGSN role

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.org
Tue Mar 23 23:53:32 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/23414 )

Change subject: gprs_ns2: dynamic NS-VC + NSE creation for IP-SNS in SGSN role
......................................................................

gprs_ns2: dynamic NS-VC + NSE creation for IP-SNS in SGSN role

Related: OS#3373
Change-Id: Ie10bb3531fae2e651da04f965d964de6eb1e7a97
---
M src/gb/gprs_ns2.c
1 file changed, 62 insertions(+), 0 deletions(-)

Approvals:
  Jenkins Builder: Verified
  daniel: Looks good to me, but someone else must approve
  lynxis lazus: Looks good to me, approved



diff --git a/src/gb/gprs_ns2.c b/src/gb/gprs_ns2.c
index f2e6435..21a2d22 100644
--- a/src/gb/gprs_ns2.c
+++ b/src/gb/gprs_ns2.c
@@ -907,6 +907,54 @@
 	return rc;
 }
 
+static enum ns2_cs ns2_create_vc_sns(struct gprs_ns2_vc_bind *bind,
+			  const struct osmo_sockaddr *remote,
+			  struct gprs_ns2_vc **success, uint16_t nsei)
+{
+	struct gprs_ns2_vc *nsvc;
+	struct gprs_ns2_nse *nse;
+
+	nsvc = gprs_ns2_nsvc_by_sockaddr_bind(bind, remote);
+	/* ns2_create_vc() is only called if no NS-VC could be found */
+	OSMO_ASSERT(!nsvc);
+
+	nse = gprs_ns2_nse_by_nsei(bind->nsi, nsei);
+	if (!nse) {
+		if (!bind->accept_sns) {
+			struct osmo_sockaddr_str remote_str;
+			osmo_sockaddr_str_from_sockaddr(&remote_str, &remote->u.sas);
+			/* no dynamic creation of IP-SNS NSE permitted */
+			LOGP(DLNS, LOGL_ERROR, "[%s]:%u: Dynamic creation of NSE(%05u) via IP-SNS not "
+			     "permitted. Check your config.\n", remote_str.ip, remote_str.port, nsei);
+			return NS2_CS_ERROR;
+		}
+		nse = gprs_ns2_create_nse2(bind->nsi, nsei, bind->ll, GPRS_NS2_DIALECT_SNS, true);
+		if (!nse) {
+			LOGP(DLNS, LOGL_ERROR, "Failed to create NSE(%05u)\n", nsei);
+			return NS2_CS_ERROR;
+		}
+		gprs_ns2_sns_add_bind(nse, bind);
+		/* TODO: add (configured) list of other binds */
+	} else {
+		/* nsei already known */
+		if (nse->ll != bind->ll) {
+			LOGNSE(nse, LOGL_ERROR, "Received NS-RESET with wrong linklayer(%s)"
+				" for already known NSE(%s)\n", gprs_ns2_lltype_str(bind->ll),
+				gprs_ns2_lltype_str(nse->ll));
+			return NS2_CS_SKIPPED;
+		}
+	}
+
+	nsvc = ns2_ip_bind_connect(bind, nse, remote);
+	if (!nsvc)
+		return NS2_CS_SKIPPED;
+
+	nsvc->nsvci_is_valid = false;
+
+	*success = nsvc;
+
+	return NS2_CS_CREATED;
+}
 
 /*! Create a new NS-VC based on a [received] message. Depending on the bind it might create a NSE.
  *  \param[in] bind the bind through which msg was received
@@ -945,6 +993,20 @@
 	tlv = ns2_tlv_parse(&tp, nsh->data,
 			   msgb_l2len(msg) - sizeof(*nsh), 0, 0);
 
+	if (bind->ll == GPRS_NS2_LL_UDP && nsh->pdu_type == SNS_PDUT_SIZE && tlv >= 0) {
+		uint16_t nsei;
+
+		if (!TLVP_PRES_LEN(&tp, NS_IE_NSEI, 2)) {
+			rc = reject_status_msg(msg, &tp, reject, NS_CAUSE_MISSING_ESSENT_IE);
+			if (rc < 0)
+				LOGP(DLNS, LOGL_ERROR, "Failed to generate reject message (%d)\n", rc);
+			return NS2_CS_REJECTED;
+		}
+		nsei = tlvp_val16be(&tp, NS_IE_NSEI);
+		/* Create NS-VC, and if required, even NSE dynamically */
+		return ns2_create_vc_sns(bind, remote, success, nsei);
+	}
+
 	switch (nsh->pdu_type) {
 	case NS_PDUT_STATUS:
 		/* Do not respond, see 3GPP TS 08.16, 7.5.1 */

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/23414
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ie10bb3531fae2e651da04f965d964de6eb1e7a97
Gerrit-Change-Number: 23414
Gerrit-PatchSet: 6
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: lynxis lazus <lynxis at fe80.eu>
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/20210323/d8196aaf/attachment.htm>


More information about the gerrit-log mailing list