Change in libosmocore[master]: gprs_ns2_sns: Allow VTY configuration of default binds for IP-SNS

laforge gerrit-no-reply at lists.osmocom.org
Fri Mar 19 12:38:56 UTC 2021


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


Change subject: gprs_ns2_sns: Allow VTY configuration of default binds for IP-SNS
......................................................................

gprs_ns2_sns: Allow VTY configuration of default binds for IP-SNS

In the IP-SNS SGSN role, we need to inform the BSS of our local
IP endpoints.  For statically configured NSEs, those are explicitly
stated on a per-NSE level.

For dynamically created IP-SNS NSEs, we are adding a new VTY
command, using which the administrator can configure which binds
should be advertised as IP endpoints to such BSS.

Change-Id: Id01c29b07e9203c9305f2129361a4f5aaefa2c52
Related: OS#3373
---
M src/gb/gprs_ns2.c
M src/gb/gprs_ns2_internal.h
M src/gb/gprs_ns2_vty.c
3 files changed, 106 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/15/23415/1

diff --git a/src/gb/gprs_ns2.c b/src/gb/gprs_ns2.c
index 91be542..7fe3956 100644
--- a/src/gb/gprs_ns2.c
+++ b/src/gb/gprs_ns2.c
@@ -934,8 +934,9 @@
 			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 */
+		/* add configured list of default binds; if that fails, use only current bind */
+		if (!ns2_sns_add_sns_default_binds(nse))
+			gprs_ns2_sns_add_bind(nse, bind);
 	} else {
 		/* nsei already known */
 		if (nse->ll != bind->ll) {
diff --git a/src/gb/gprs_ns2_internal.h b/src/gb/gprs_ns2_internal.h
index f0dd9bf..9788652 100644
--- a/src/gb/gprs_ns2_internal.h
+++ b/src/gb/gprs_ns2_internal.h
@@ -388,3 +388,6 @@
 enum gprs_ns2_vc_mode ns2_dialect_to_vc_mode(enum gprs_ns2_dialect dialect);
 int ns2_count_transfer_cap(struct gprs_ns2_nse *nse,
 			   uint16_t bvci);
+
+/* vty */
+int ns2_sns_add_sns_default_binds(struct gprs_ns2_nse *nse);
diff --git a/src/gb/gprs_ns2_vty.c b/src/gb/gprs_ns2_vty.c
index 47a888f..c910ea7 100644
--- a/src/gb/gprs_ns2_vty.c
+++ b/src/gb/gprs_ns2_vty.c
@@ -3,6 +3,7 @@
 
 /* (C) 2020 by sysmocom - s.f.m.c. GmbH <info at sysmocom.de>
  * Author: Alexander Couzens <lynxis at fe80.eu>
+ * (C) 2021 by Harald Welte <laforge at osmocom.org>
  *
  * All Rights Reserved
  *
@@ -59,6 +60,7 @@
 static struct osmo_fr_network *vty_fr_network = NULL;
 static struct llist_head binds;
 static struct llist_head nses;
+static struct llist_head ip_sns_default_binds;
 
 struct vty_bind {
 	struct llist_head list;
@@ -552,6 +554,7 @@
 static int config_write_ns_nse(struct vty *vty)
 {
 	struct gprs_ns2_nse *nse;
+	struct vty_nse_bind *vbind;
 
 	llist_for_each_entry(nse, &vty_nsi->nse, list) {
 		if (!nse->persistent)
@@ -560,6 +563,10 @@
 		_config_write_ns_nse(vty, nse);
 	}
 
+	llist_for_each_entry(vbind, &ip_sns_default_binds, list) {
+		vty_out(vty, " ip-sns-default bind %s%s", vbind->vbind->name, VTY_NEWLINE);
+	}
+
 	return 0;
 }
 
@@ -1583,6 +1590,95 @@
 	return CMD_SUCCESS;
 }
 
+/* add all IP-SNS default binds to the given NSE */
+int ns2_sns_add_sns_default_binds(struct gprs_ns2_nse *nse)
+{
+	struct vty_nse_bind *vnse_bind;
+	int count = 0;
+
+	OSMO_ASSERT(nse->ll == GPRS_NS2_LL_UDP);
+	OSMO_ASSERT(nse->dialect == GPRS_NS2_DIALECT_SNS);
+
+	llist_for_each_entry(vnse_bind, &ip_sns_default_binds, list) {
+		struct gprs_ns2_vc_bind *bind = gprs_ns2_bind_by_name(vty_nsi, vnse_bind->vbind->name);
+		/* the bind might not yet created because "listen" is missing. */
+		if (!bind)
+			continue;
+		gprs_ns2_sns_add_bind(nse, bind);
+		count++;
+	}
+	return count;
+}
+
+DEFUN(cfg_ns_ip_sns_default_bind, cfg_ns_ip_sns_default_bind_cmd,
+      "ip-sns-default bind ID",
+      "Defaults for dynamically created NSEs created by IP-SNS in SGSN role\n"
+      "IP SNS binds\n"
+      "Name of NS udp bind whose IP endpoint will be used as IP-SNS local endpoint. Can be given multiple times.\n")
+{
+	struct vty_bind *vbind;
+	struct vty_nse_bind *vnse_bind;
+	const char *name = argv[0];
+
+	vbind = vty_bind_by_name(name);
+	if (!vbind) {
+		vty_out(vty, "Can not find the given bind '%s'%s", name, VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	if (vbind->ll != GPRS_NS2_LL_UDP) {
+		vty_out(vty, "ip-sns-default bind can only be used with UDP bind%s", VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	llist_for_each_entry(vnse_bind, &ip_sns_default_binds, list) {
+		if (vnse_bind->vbind == vbind)
+			return CMD_SUCCESS;
+	}
+
+	vnse_bind = talloc(vty_nsi, struct vty_nse_bind);
+	if (!vnse_bind)
+		return CMD_WARNING;
+	vnse_bind->vbind = vbind;
+
+	llist_add_tail(&vnse_bind->list, &ip_sns_default_binds);
+
+	return CMD_SUCCESS;
+}
+
+DEFUN(cfg_no_ns_ip_sns_default_bind, cfg_no_ns_ip_sns_default_bind_cmd,
+      "no ip-sns-default bind ID",
+      NO_STR "Defaults for dynamically created NSEs created by IP-SNS in SGSN role\n"
+      "IP SNS binds\n"
+      "Name of NS udp bind whose IP endpoint will be removed as IP-SNS local endpoint.\n")
+{
+	struct vty_bind *vbind;
+	struct vty_nse_bind *vnse_bind;
+	const char *name = argv[0];
+
+	vbind = vty_bind_by_name(name);
+	if (!vbind) {
+		vty_out(vty, "Can not find the given bind '%s'%s", name, VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	if (vbind->ll != GPRS_NS2_LL_UDP) {
+		vty_out(vty, "ip-sns-default bind can only be used with UDP bind%s", VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	llist_for_each_entry(vnse_bind, &ip_sns_default_binds, list) {
+		if (vnse_bind->vbind == vbind) {
+			llist_del(&vnse_bind->list);
+			talloc_free(vnse_bind);
+			return CMD_SUCCESS;
+		}
+	}
+
+	vty_out(vty, "Bind '%s' was not an ip-sns-default bind%s", name, VTY_NEWLINE);
+	return CMD_WARNING;
+}
+
 DEFUN(cfg_ns_nse_ip_sns_bind, cfg_ns_nse_ip_sns_bind_cmd,
       "ip-sns-bind BINDID",
       "IP SNS binds\n"
@@ -2059,6 +2155,7 @@
 	vty_nsi = nsi;
 	INIT_LLIST_HEAD(&binds);
 	INIT_LLIST_HEAD(&nses);
+	INIT_LLIST_HEAD(&ip_sns_default_binds);
 
 	vty_fr_network = osmo_fr_network_alloc(nsi);
 	if (!vty_fr_network)
@@ -2098,6 +2195,9 @@
 	install_lib_element(L_NS_NODE, &cfg_ns_bind_cmd);
 	install_lib_element(L_NS_NODE, &cfg_no_ns_bind_cmd);
 
+	install_lib_element(L_NS_NODE, &cfg_ns_ip_sns_default_bind_cmd);
+	install_lib_element(L_NS_NODE, &cfg_no_ns_ip_sns_default_bind_cmd);
+
 	install_node(&ns_bind_node, NULL);
 	install_lib_element(L_NS_BIND_NODE, &cfg_ns_bind_listen_cmd);
 	install_lib_element(L_NS_BIND_NODE, &cfg_no_ns_bind_listen_cmd);

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Id01c29b07e9203c9305f2129361a4f5aaefa2c52
Gerrit-Change-Number: 23415
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/20210319/c1afc12a/attachment.htm>


More information about the gerrit-log mailing list