diff options
author | Harald Welte <laforge@osmocom.org> | 2021-04-28 19:57:12 +0200 |
---|---|---|
committer | Harald Welte <laforge@osmocom.org> | 2021-04-29 19:55:34 +0200 |
commit | d99e4eee2b602e3b878398e2fffafc2b7c97081b (patch) | |
tree | a15d4ace0897c6f283864728af62fd866862b591 | |
parent | 915caf75e24632084b16ff5e45d247da1b6f169e (diff) |
ns2: Allow setting the socket priority for a UDP bind
Change-Id: Ifdfa086ce1c8d62b256abb3454b70cf53da9dcdb
-rw-r--r-- | include/osmocom/gprs/gprs_ns2.h | 1 | ||||
-rw-r--r-- | src/gb/gprs_ns2_udp.c | 27 | ||||
-rw-r--r-- | src/gb/gprs_ns2_vty.c | 26 | ||||
-rw-r--r-- | src/gb/libosmogb.map | 1 | ||||
-rw-r--r-- | tests/gb/gprs_ns2_vty.vty | 6 |
5 files changed, 57 insertions, 4 deletions
diff --git a/include/osmocom/gprs/gprs_ns2.h b/include/osmocom/gprs/gprs_ns2.h index be59a679..a9c144cc 100644 --- a/include/osmocom/gprs/gprs_ns2.h +++ b/include/osmocom/gprs/gprs_ns2.h @@ -246,6 +246,7 @@ bool gprs_ns2_ip_vc_equal(const struct gprs_ns2_vc *nsvc, const struct osmo_sockaddr *gprs_ns2_ip_bind_sockaddr(struct gprs_ns2_vc_bind *bind); int gprs_ns2_is_ip_bind(struct gprs_ns2_vc_bind *bind); int gprs_ns2_ip_bind_set_dscp(struct gprs_ns2_vc_bind *bind, int dscp); +int gprs_ns2_ip_bind_set_priority(struct gprs_ns2_vc_bind *bind, uint8_t priority); struct gprs_ns2_vc *gprs_ns2_nsvc_by_sockaddr_bind( struct gprs_ns2_vc_bind *bind, const struct osmo_sockaddr *saddr); diff --git a/src/gb/gprs_ns2_udp.c b/src/gb/gprs_ns2_udp.c index 0de207c7..7980df59 100644 --- a/src/gb/gprs_ns2_udp.c +++ b/src/gb/gprs_ns2_udp.c @@ -49,6 +49,7 @@ struct priv_bind { struct osmo_fd fd; struct osmo_sockaddr addr; int dscp; + uint8_t priority; }; struct priv_vc { @@ -103,7 +104,8 @@ static void dump_vty(const struct gprs_ns2_vc_bind *bind, nsvcs++; } - vty_out(vty, "UDP bind: %s:%d DSCP: %d%s", sockstr.ip, sockstr.port, priv->dscp, VTY_NEWLINE); + vty_out(vty, "UDP bind: %s:%d DSCP: %d Priority: %u%s", sockstr.ip, sockstr.port, + priv->dscp, priv->priority, VTY_NEWLINE); vty_out(vty, " IP-SNS signalling weight: %u data weight: %u%s", bind->sns_sig_weight, bind->sns_data_weight, VTY_NEWLINE); vty_out(vty, " %lu NS-VC:%s", nsvcs, VTY_NEWLINE); @@ -525,6 +527,29 @@ int gprs_ns2_ip_bind_set_dscp(struct gprs_ns2_vc_bind *bind, int dscp) return rc; } +/*! Set the socket priority of the given bind. */ +int gprs_ns2_ip_bind_set_priority(struct gprs_ns2_vc_bind *bind, uint8_t priority) +{ + struct priv_bind *priv; + int rc = 0; + + OSMO_ASSERT(gprs_ns2_is_ip_bind(bind)); + priv = bind->priv; + + if (priority != priv->priority) { + priv->priority = priority; + + rc = osmo_sock_set_priority(priv->fd.fd, priority); + if (rc < 0) { + LOGBIND(bind, LOGL_ERROR, "Failed to set the priority to %u with ret(%d) errno(%d)\n", + priority, rc, errno); + } + } + + return rc; +} + + /*! Count UDP binds compatible with remote */ int ns2_ip_count_bind(struct gprs_ns2_inst *nsi, struct osmo_sockaddr *remote) { diff --git a/src/gb/gprs_ns2_vty.c b/src/gb/gprs_ns2_vty.c index c390423e..0fd7c17c 100644 --- a/src/gb/gprs_ns2_vty.c +++ b/src/gb/gprs_ns2_vty.c @@ -67,6 +67,7 @@ struct vty_bind { 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 @@ static void config_write_vbind(struct vty *vty, struct vty_bind *vbind) 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 @@ DEFUN(cfg_no_ns_bind_dscp, cfg_no_ns_bind_dscp_cmd, 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 @@ int gprs_ns2_vty_init(struct gprs_ns2_inst *nsi) 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); diff --git a/src/gb/libosmogb.map b/src/gb/libosmogb.map index ed9b8229..db638f9b 100644 --- a/src/gb/libosmogb.map +++ b/src/gb/libosmogb.map @@ -162,6 +162,7 @@ gprs_ns2_instantiate; gprs_ns2_ip_bind; gprs_ns2_ip_bind_by_sockaddr; gprs_ns2_ip_bind_set_dscp; +gprs_ns2_ip_bind_set_priority; gprs_ns2_ip_bind_set_sns_weight; gprs_ns2_ip_bind_sockaddr; gprs_ns2_ip_connect; diff --git a/tests/gb/gprs_ns2_vty.vty b/tests/gb/gprs_ns2_vty.vty index 78c7e78e..891bde59 100644 --- a/tests/gb/gprs_ns2_vty.vty +++ b/tests/gb/gprs_ns2_vty.vty @@ -29,7 +29,7 @@ fr can be only used with frame relay bind OsmoNSdummy(config-ns-bind)# listen 127.0.0.14 42999 OsmoNSdummy(config-ns-bind)# end OsmoNSdummy# show ns -UDP bind: 127.0.0.14:42999 DSCP: 0 +UDP bind: 127.0.0.14:42999 DSCP: 0 Priority: 0 IP-SNS signalling weight: 1 data weight: 1 0 NS-VC: OsmoNSdummy# configure terminal @@ -41,7 +41,7 @@ OsmoNSdummy# show ns NSEI 01234: UDP, DEAD 1 NS-VC: NSVCI none: RECOVERING PERSIST data_weight=1 sig_weight=1 udp)[127.0.0.14]:42999<>[127.0.0.15]:9496 -UDP bind: 127.0.0.14:42999 DSCP: 0 +UDP bind: 127.0.0.14:42999 DSCP: 0 Priority: 0 IP-SNS signalling weight: 1 data weight: 1 1 NS-VC: NSVCI none: RECOVERING PERSIST data_weight=1 sig_weight=1 udp)[127.0.0.14]:42999<>[127.0.0.15]:9496 @@ -57,7 +57,7 @@ NSEI 01234: UDP, DEAD NSVCI none: RECOVERING PERSIST data_weight=0 sig_weight=0 udp)[127.0.0.14]:42999<>[127.0.0.17]:9496 NSVCI none: RECOVERING PERSIST data_weight=9 sig_weight=0 udp)[127.0.0.14]:42999<>[127.0.0.16]:9496 NSVCI none: RECOVERING PERSIST data_weight=1 sig_weight=1 udp)[127.0.0.14]:42999<>[127.0.0.15]:9496 -UDP bind: 127.0.0.14:42999 DSCP: 0 +UDP bind: 127.0.0.14:42999 DSCP: 0 Priority: 0 IP-SNS signalling weight: 1 data weight: 1 3 NS-VC: NSVCI none: RECOVERING PERSIST data_weight=0 sig_weight=0 udp)[127.0.0.14]:42999<>[127.0.0.17]:9496 |