gprs_ns: Allow to set the DSCP for the UDP socket.

Allow to tag the NS service with a custom DSCP.
diff --git a/include/osmocom/gprs/gprs_ns.h b/include/osmocom/gprs/gprs_ns.h
index a7f32b2..8fca70c 100644
--- a/include/osmocom/gprs/gprs_ns.h
+++ b/include/osmocom/gprs/gprs_ns.h
@@ -73,6 +73,7 @@
 		struct osmo_fd fd;
 		uint32_t local_ip;
 		uint16_t local_port;
+		int dscp;
 	} nsip;
 	/*! \brief NS-over-FR-over-GRE-over-IP specific bits */
 	struct {
diff --git a/src/gb/Makefile.am b/src/gb/Makefile.am
index 8b7473d..af45720 100644
--- a/src/gb/Makefile.am
+++ b/src/gb/Makefile.am
@@ -1,3 +1,6 @@
+# FIXME: LIBVERSION adjustments required for next version
+#  ABI of gprs_ns structure changed by adding DSCP.
+#
 # This is _NOT_ the library release version, it's an API version.
 # Please read Chapter 6 "Library interface versions" of the libtool documentation before making any modification
 LIBVERSION=2:0:0
diff --git a/src/gb/gprs_ns.c b/src/gb/gprs_ns.c
index cdcf36e..ef937d9 100644
--- a/src/gb/gprs_ns.c
+++ b/src/gb/gprs_ns.c
@@ -1051,6 +1051,13 @@
 	if (ret < 0)
 		return ret;
 
+	ret = setsockopt(nsi->nsip.fd.fd, IPPROTO_IP, IP_TOS,
+				&nsi->nsip.dscp, sizeof(nsi->nsip.dscp));
+	if (ret < 0)
+		LOGP(DNS, LOGL_ERROR,
+			"Failed to set the DSCP to %d with ret(%d) errno(%d)\n",
+			nsi->nsip.dscp, ret, errno);
+
 
 	return ret;
 }
diff --git a/src/gb/gprs_ns_vty.c b/src/gb/gprs_ns_vty.c
index fac431c..a2e7beb 100644
--- a/src/gb/gprs_ns_vty.c
+++ b/src/gb/gprs_ns_vty.c
@@ -131,6 +131,9 @@
 	if (vty_nsi->nsip.local_port)
 		vty_out(vty, " encapsulation udp local-port %u%s",
 			vty_nsi->nsip.local_port, VTY_NEWLINE);
+	if (vty_nsi->nsip.dscp)
+		vty_out(vty, " encapsulation udp dscp %d%s",
+			vty_nsi->nsip.dscp, VTY_NEWLINE);
 
 	vty_out(vty, " encapsulation framerelay-gre enabled %u%s",
 		vty_nsi->frgre.enabled ? 1 : 0, VTY_NEWLINE);
@@ -454,6 +457,16 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(cfg_nsip_dscp, cfg_nsip_dscp_cmd,
+      "encapsulation udp dscp <0-255>",
+	ENCAPS_STR "NS over UDP Encapsulation\n"
+	"Set DSCP/TOS on the UDP socket\n" "DSCP Value\n")
+{
+	int dscp = atoi(argv[0]);
+	vty_nsi->nsip.dscp = dscp;
+	return CMD_SUCCESS;
+}
+
 DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd,
       "encapsulation framerelay-gre local-ip A.B.C.D",
 	ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
@@ -572,6 +585,7 @@
 	install_element(L_NS_NODE, &cfg_ns_timer_cmd);
 	install_element(L_NS_NODE, &cfg_nsip_local_ip_cmd);
 	install_element(L_NS_NODE, &cfg_nsip_local_port_cmd);
+	install_element(L_NS_NODE, &cfg_nsip_dscp_cmd);
 	install_element(L_NS_NODE, &cfg_frgre_enable_cmd);
 	install_element(L_NS_NODE, &cfg_frgre_local_ip_cmd);