Change in libosmocore[master]: ns2: Allow setting the socket priority for a UDP bind

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
Thu Apr 29 19:14:53 UTC 2021


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

Change subject: ns2: Allow setting the socket priority for a UDP bind
......................................................................

ns2: Allow setting the socket priority for a UDP bind

Change-Id: Ifdfa086ce1c8d62b256abb3454b70cf53da9dcdb
---
M include/osmocom/gprs/gprs_ns2.h
M src/gb/gprs_ns2_udp.c
M src/gb/gprs_ns2_vty.c
M src/gb/libosmogb.map
M tests/gb/gprs_ns2_vty.vty
5 files changed, 57 insertions(+), 4 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



diff --git a/include/osmocom/gprs/gprs_ns2.h b/include/osmocom/gprs/gprs_ns2.h
index be59a67..a9c144c 100644
--- a/include/osmocom/gprs/gprs_ns2.h
+++ b/include/osmocom/gprs/gprs_ns2.h
@@ -246,6 +246,7 @@
 const struct osmo_sockaddr *gprs_ns2_ip_bind_sockaddr(struct gprs_ns2_vc_bind *bind);
 int gprs_ns2_is_ip_bind(struct gprs_ns2_vc_bind *bind);
 int gprs_ns2_ip_bind_set_dscp(struct gprs_ns2_vc_bind *bind, int dscp);
+int gprs_ns2_ip_bind_set_priority(struct gprs_ns2_vc_bind *bind, uint8_t priority);
 struct gprs_ns2_vc *gprs_ns2_nsvc_by_sockaddr_bind(
 		struct gprs_ns2_vc_bind *bind,
 		const struct osmo_sockaddr *saddr);
diff --git a/src/gb/gprs_ns2_udp.c b/src/gb/gprs_ns2_udp.c
index 0de207c..7980df5 100644
--- a/src/gb/gprs_ns2_udp.c
+++ b/src/gb/gprs_ns2_udp.c
@@ -49,6 +49,7 @@
 	struct osmo_fd fd;
 	struct osmo_sockaddr addr;
 	int dscp;
+	uint8_t priority;
 };
 
 struct priv_vc {
@@ -103,7 +104,8 @@
 		nsvcs++;
 	}
 
-	vty_out(vty, "UDP bind: %s:%d DSCP: %d%s", sockstr.ip, sockstr.port, priv->dscp, VTY_NEWLINE);
+	vty_out(vty, "UDP bind: %s:%d DSCP: %d Priority: %u%s", sockstr.ip, sockstr.port,
+		priv->dscp, priv->priority, VTY_NEWLINE);
 	vty_out(vty, "  IP-SNS signalling weight: %u data weight: %u%s",
 		bind->sns_sig_weight, bind->sns_data_weight, VTY_NEWLINE);
 	vty_out(vty, "  %lu NS-VC:%s", nsvcs, VTY_NEWLINE);
@@ -525,6 +527,29 @@
 	return rc;
 }
 
+/*! Set the socket priority of the given bind. */
+int gprs_ns2_ip_bind_set_priority(struct gprs_ns2_vc_bind *bind, uint8_t priority)
+{
+	struct priv_bind *priv;
+	int rc = 0;
+
+	OSMO_ASSERT(gprs_ns2_is_ip_bind(bind));
+	priv = bind->priv;
+
+	if (priority != priv->priority) {
+		priv->priority = priority;
+
+		rc = osmo_sock_set_priority(priv->fd.fd, priority);
+		if (rc < 0) {
+			LOGBIND(bind, LOGL_ERROR, "Failed to set the priority to %u with ret(%d) errno(%d)\n",
+				priority, rc, errno);
+		}
+	}
+
+	return rc;
+}
+
+
 /*! Count UDP binds compatible with remote */
 int ns2_ip_count_bind(struct gprs_ns2_inst *nsi, struct osmo_sockaddr *remote)
 {
diff --git a/src/gb/gprs_ns2_vty.c b/src/gb/gprs_ns2_vty.c
index c390423..0fd7c17 100644
--- a/src/gb/gprs_ns2_vty.c
+++ b/src/gb/gprs_ns2_vty.c
@@ -67,6 +67,7 @@
 	const char *name;
 	enum gprs_ns2_ll ll;
 	int dscp;
+	uint8_t priority;
 	bool accept_ipaccess;
 	bool accept_sns;
 	uint8_t ip_sns_sig_weight;
@@ -468,6 +469,8 @@
 			vty_out(vty, "  accept-dynamic-ip-sns%s", VTY_NEWLINE);
 		if (vbind->dscp)
 			vty_out(vty, "  dscp %u%s", vbind->dscp, VTY_NEWLINE);
+		if (vbind->priority)
+			vty_out(vty, "  priority %u%s", vbind->priority, VTY_NEWLINE);
 		vty_out(vty, "  ip-sns signalling-weight %u data-weight %u%s",
 			vbind->ip_sns_sig_weight, vbind->ip_sns_data_weight, VTY_NEWLINE);
 		break;
@@ -722,6 +725,28 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(cfg_ns_bind_priority, cfg_ns_bind_priority_cmd,
+      "priority <0-255>",
+      "Set socket priority on the UDP socket\n" "Priority Value (>6 requires CAP_NET_ADMIN)\n")
+{
+	struct vty_bind *vbind = vty->index;
+	struct gprs_ns2_vc_bind *bind;
+	uint8_t prio = atoi(argv[0]);
+
+	if (vbind->ll != GPRS_NS2_LL_UDP) {
+		vty_out(vty, "dscp can be only used with UDP bind%s",
+			VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	vbind->priority = prio;
+	bind = gprs_ns2_bind_by_name(vty_nsi, vbind->name);
+	if (bind)
+		gprs_ns2_ip_bind_set_priority(bind, prio);
+
+	return CMD_SUCCESS;
+}
+
 DEFUN(cfg_ns_bind_ipaccess, cfg_ns_bind_ipaccess_cmd,
       "accept-ipaccess",
       "Allow to create dynamic NS Entity by NS Reset PDU on UDP (ip.access style)\n"
@@ -2235,6 +2260,7 @@
 	install_lib_element(L_NS_BIND_NODE, &cfg_no_ns_bind_listen_cmd);
 	install_lib_element(L_NS_BIND_NODE, &cfg_ns_bind_dscp_cmd);
 	install_lib_element(L_NS_BIND_NODE, &cfg_no_ns_bind_dscp_cmd);
+	install_lib_element(L_NS_BIND_NODE, &cfg_ns_bind_priority_cmd);
 	install_lib_element(L_NS_BIND_NODE, &cfg_ns_bind_ip_sns_weight_cmd);
 	install_lib_element(L_NS_BIND_NODE, &cfg_ns_bind_ipaccess_cmd);
 	install_lib_element(L_NS_BIND_NODE, &cfg_no_ns_bind_ipaccess_cmd);
diff --git a/src/gb/libosmogb.map b/src/gb/libosmogb.map
index ed9b822..db638f9 100644
--- a/src/gb/libosmogb.map
+++ b/src/gb/libosmogb.map
@@ -162,6 +162,7 @@
 gprs_ns2_ip_bind;
 gprs_ns2_ip_bind_by_sockaddr;
 gprs_ns2_ip_bind_set_dscp;
+gprs_ns2_ip_bind_set_priority;
 gprs_ns2_ip_bind_set_sns_weight;
 gprs_ns2_ip_bind_sockaddr;
 gprs_ns2_ip_connect;
diff --git a/tests/gb/gprs_ns2_vty.vty b/tests/gb/gprs_ns2_vty.vty
index 78c7e78..891bde5 100644
--- a/tests/gb/gprs_ns2_vty.vty
+++ b/tests/gb/gprs_ns2_vty.vty
@@ -29,7 +29,7 @@
 OsmoNSdummy(config-ns-bind)# listen 127.0.0.14 42999
 OsmoNSdummy(config-ns-bind)# end
 OsmoNSdummy# show ns
-UDP bind: 127.0.0.14:42999 DSCP: 0
+UDP bind: 127.0.0.14:42999 DSCP: 0 Priority: 0
   IP-SNS signalling weight: 1 data weight: 1
   0 NS-VC:
 OsmoNSdummy# configure terminal
@@ -41,7 +41,7 @@
 NSEI 01234: UDP, DEAD
   1 NS-VC:
    NSVCI none: RECOVERING PERSIST data_weight=1 sig_weight=1 udp)[127.0.0.14]:42999<>[127.0.0.15]:9496
-UDP bind: 127.0.0.14:42999 DSCP: 0
+UDP bind: 127.0.0.14:42999 DSCP: 0 Priority: 0
   IP-SNS signalling weight: 1 data weight: 1
   1 NS-VC:
    NSVCI none: RECOVERING PERSIST data_weight=1 sig_weight=1 udp)[127.0.0.14]:42999<>[127.0.0.15]:9496
@@ -57,7 +57,7 @@
    NSVCI none: RECOVERING PERSIST data_weight=0 sig_weight=0 udp)[127.0.0.14]:42999<>[127.0.0.17]:9496
    NSVCI none: RECOVERING PERSIST data_weight=9 sig_weight=0 udp)[127.0.0.14]:42999<>[127.0.0.16]:9496
    NSVCI none: RECOVERING PERSIST data_weight=1 sig_weight=1 udp)[127.0.0.14]:42999<>[127.0.0.15]:9496
-UDP bind: 127.0.0.14:42999 DSCP: 0
+UDP bind: 127.0.0.14:42999 DSCP: 0 Priority: 0
   IP-SNS signalling weight: 1 data weight: 1
   3 NS-VC:
    NSVCI none: RECOVERING PERSIST data_weight=0 sig_weight=0 udp)[127.0.0.14]:42999<>[127.0.0.17]:9496

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ifdfa086ce1c8d62b256abb3454b70cf53da9dcdb
Gerrit-Change-Number: 23976
Gerrit-PatchSet: 2
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-CC: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210429/77ef5a4d/attachment.htm>


More information about the gerrit-log mailing list