ns2: Allow setting the socket priority for a UDP bind

Change-Id: Ifdfa086ce1c8d62b256abb3454b70cf53da9dcdb
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);