Change in libosmocore[master]: gprs_ns2_sns: refactor ns2_sns_st_size_onenter()

laforge gerrit-no-reply at lists.osmocom.org
Fri Mar 5 09:41:12 UTC 2021


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/23244 )


Change subject: gprs_ns2_sns: refactor ns2_sns_st_size_onenter()
......................................................................

gprs_ns2_sns: refactor ns2_sns_st_size_onenter()

Let's move computing of the local IP endpoints to a separate function,
so it can not only be used when entering the SNS_SIZE state. Preparation
for SGSN-side IP-SNS.

Change-Id: I5d7ce419135a8ef538cf9abcb76a49049ed7d5f9
Related: OS#3373
---
M src/gb/gprs_ns2_sns.c
1 file changed, 40 insertions(+), 31 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/44/23244/1

diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c
index 04cebf4..1d4d069 100644
--- a/src/gb/gprs_ns2_sns.c
+++ b/src/gb/gprs_ns2_sns.c
@@ -723,8 +723,7 @@
 	}
 }
 
-/* setup all dynamic SNS settings, create a new nsvc and send the SIZE */
-static void ns2_sns_st_size_onenter(struct osmo_fsm_inst *fi, uint32_t old_state)
+static void ns2_sns_compute_local_ep_from_binds(struct osmo_fsm_inst *fi)
 {
 	struct ns2_sns_state *gss = (struct ns2_sns_state *) fi->priv;
 	struct gprs_ns_ie_ip4_elem *ip4_elems;
@@ -736,14 +735,6 @@
 	struct osmo_sockaddr local;
 	int count;
 
-	/* on a generic failure, the timer callback will recover */
-	if (old_state != GPRS_SNS_ST_UNCONFIGURED)
-		ns2_prim_status_ind(gss->nse, NULL, 0, GPRS_NS2_AFF_CAUSE_SNS_FAILURE);
-	if (old_state != GPRS_SNS_ST_SIZE)
-		gss->N = 0;
-
-
-	gss->alive = false;
 	ns2_clear_ipv46_entries(gss);
 
 	/* no initial available */
@@ -759,27 +750,6 @@
 		return;
 	}
 
-	/* take the first bind or take the next bind */
-	if (!gss->initial_bind) {
-		gss->initial_bind = llist_first_entry(&gss->binds, struct ns2_sns_bind, list);
-	} else {
-		if (gss->initial_bind->list.next != &gss->binds) {
-			gss->initial_bind = llist_entry(gss->initial_bind->list.next, struct ns2_sns_bind, list);
-		} else {
-			gss->initial_bind = llist_first_entry(&gss->binds, struct ns2_sns_bind, list);
-		}
-	}
-
-	bind = gss->initial_bind->bind;
-
-	/* setup the NSVC */
-	if (!gss->sns_nsvc) {
-		gss->sns_nsvc = ns2_ip_bind_connect(bind, gss->nse, remote);
-		if (!gss->sns_nsvc)
-			return;
-		gss->sns_nsvc->sns_only = true;
-	}
-
 	switch (gss->ip) {
 	case IPv4:
 		ip4_elems = talloc_zero_size(fi, sizeof(struct gprs_ns_ie_ip4_elem) * count);
@@ -854,6 +824,45 @@
 		gss->num_max_nsvcs = OSMO_MAX(gss->num_max_ip6_remote * gss->num_ip6_local, 8);
 		break;
 	}
+}
+
+/* setup all dynamic SNS settings, create a new nsvc and send the SIZE */
+static void ns2_sns_st_size_onenter(struct osmo_fsm_inst *fi, uint32_t old_state)
+{
+	struct ns2_sns_state *gss = (struct ns2_sns_state *) fi->priv;
+
+	/* on a generic failure, the timer callback will recover */
+	if (old_state != GPRS_SNS_ST_UNCONFIGURED)
+		ns2_prim_status_ind(gss->nse, NULL, 0, GPRS_NS2_AFF_CAUSE_SNS_FAILURE);
+	if (old_state != GPRS_SNS_ST_SIZE)
+		gss->N = 0;
+
+	gss->alive = false;
+
+	ns2_sns_compute_local_ep_from_binds(fi);
+
+	/* take the first bind or take the next bind */
+	if (!gss->initial_bind) {
+		gss->initial_bind = llist_first_entry(&gss->binds, struct ns2_sns_bind, list);
+	} else {
+		if (gss->initial_bind->list.next != &gss->binds) {
+			gss->initial_bind = llist_entry(gss->initial_bind->list.next, struct ns2_sns_bind, list);
+		} else {
+			gss->initial_bind = llist_first_entry(&gss->binds, struct ns2_sns_bind, list);
+		}
+	}
+
+
+	/* setup the NSVC */
+	if (!gss->sns_nsvc) {
+		struct gprs_ns2_vc_bind *bind = gss->initial_bind->bind;
+		struct osmo_sockaddr *remote = &gss->initial->saddr;
+		gss->sns_nsvc = ns2_ip_bind_connect(bind, gss->nse, remote);
+		if (!gss->sns_nsvc)
+			return;
+		gss->sns_nsvc->sns_only = true;
+	}
+
 
 	if (gss->num_max_ip4_remote > 0)
 		ns2_tx_sns_size(gss->sns_nsvc, true, gss->num_max_nsvcs, gss->num_max_ip4_remote, -1);

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I5d7ce419135a8ef538cf9abcb76a49049ed7d5f9
Gerrit-Change-Number: 23244
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210305/5fe47f73/attachment.htm>


More information about the gerrit-log mailing list