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
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;