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

laforge gerrit-no-reply at lists.osmocom.org
Wed Apr 28 06:51:53 UTC 2021


laforge has submitted this change. ( 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(-)

Approvals:
  Jenkins Builder: Verified
  lynxis lazus: Looks good to me, approved



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-Reviewer: Jenkins Builder
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/20210428/0bfd968a/attachment.htm>


More information about the gerrit-log mailing list