Change in libosmocore[master]: ns2: Fix setting the DSCP value.

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 Apr 27 19:58:02 UTC 2021


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


Change subject: ns2: Fix setting the DSCP value.
......................................................................

ns2: Fix setting the DSCP value.

DSCP is a 6-bit value (0..63) stored in the upper 6 bits of what was
formerly known as TOS bits.  We must
* make sure the user can only specify 0..63
* shift the value by two bits when using the IP_TOS socket option

We achieve the latter by using the recently-added osmo_sock_set_dscp()
helper.

Change-Id: I64fee56b04d0ecd128bf661699d5071817ea96ec
Closes: OS#5136
---
M src/gb/gprs_ns2_udp.c
M src/gb/gprs_ns2_vty.c
2 files changed, 5 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/21/23921/1

diff --git a/src/gb/gprs_ns2_udp.c b/src/gb/gprs_ns2_udp.c
index 8350ad8..eb7d37b 100644
--- a/src/gb/gprs_ns2_udp.c
+++ b/src/gb/gprs_ns2_udp.c
@@ -320,6 +320,9 @@
 	if (local->u.sa.sa_family != AF_INET && local->u.sa.sa_family != AF_INET6)
 		return -EINVAL;
 
+	if (dscp < 0 || dscp > 63)
+		return -EINVAL;
+
 	bind = gprs_ns2_ip_bind_by_sockaddr(nsi, local);
 	if (bind) {
 		if (result)
@@ -361,8 +364,7 @@
 	if (dscp > 0) {
 		priv->dscp = dscp;
 
-		rc = setsockopt(priv->fd.fd, IPPROTO_IP, IP_TOS,
-				&dscp, sizeof(dscp));
+		rc = osmo_sock_set_dscp(priv->fd.fd, dscp);
 		if (rc < 0)
 			LOGBIND(bind, LOGL_ERROR, "Failed to set the DSCP to %d with ret(%d) errno(%d)\n",
 				dscp, rc, errno);
diff --git a/src/gb/gprs_ns2_vty.c b/src/gb/gprs_ns2_vty.c
index 1ef22f5..c390423 100644
--- a/src/gb/gprs_ns2_vty.c
+++ b/src/gb/gprs_ns2_vty.c
@@ -679,7 +679,7 @@
 }
 
 DEFUN(cfg_ns_bind_dscp, cfg_ns_bind_dscp_cmd,
-      "dscp <0-255>",
+      "dscp <0-63>",
       "Set DSCP/TOS on the UDP socket\n" "DSCP Value\n")
 {
 	struct vty_bind *vbind = vty->index;

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I64fee56b04d0ecd128bf661699d5071817ea96ec
Gerrit-Change-Number: 23921
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/20210427/648e7a37/attachment.htm>


More information about the gerrit-log mailing list