pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/38894?usp=email )
Change subject: stream_srv: Add osmo_stream_srv_link_set_{ip_dscp,priority}() APIs ......................................................................
stream_srv: Add osmo_stream_srv_link_set_{ip_dscp,priority}() APIs
Change-Id: Iacb6b72a05055820253eaaa04850637dd2fc20e9 --- M TODO-RELEASE M include/osmocom/netif/stream.h M src/stream_srv.c 3 files changed, 50 insertions(+), 1 deletion(-)
Approvals: pespin: Looks good to me, approved Jenkins Builder: Verified
diff --git a/TODO-RELEASE b/TODO-RELEASE index 15f995e..4f59788 100644 --- a/TODO-RELEASE +++ b/TODO-RELEASE @@ -7,4 +7,4 @@ # If any interfaces have been added since the last public release: c:r:a + 1. # If any interfaces have been removed or changed since the last public release: c:r:0. #library what description / commit summary line -libosmo-netif add API osmo_stream_cli_set_{ip_dscp,priority}() +libosmo-netif add API osmo_stream_cli_set_{ip_dscp,priority}(), osmo_stream_srv_link_set_{ip_dscp,priority}() diff --git a/include/osmocom/netif/stream.h b/include/osmocom/netif/stream.h index 96d8bbf..6edf915 100644 --- a/include/osmocom/netif/stream.h +++ b/include/osmocom/netif/stream.h @@ -70,6 +70,8 @@ void osmo_stream_srv_link_set_name(struct osmo_stream_srv_link *link, const char *name); const char *osmo_stream_srv_link_get_name(const struct osmo_stream_srv_link *link); void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay); +int osmo_stream_srv_link_set_priority(struct osmo_stream_srv_link *link, int sk_prio); +int osmo_stream_srv_link_set_ip_dscp(struct osmo_stream_srv_link *link, uint8_t ip_dscp); void osmo_stream_srv_link_set_addr(struct osmo_stream_srv_link *link, const char *addr); int osmo_stream_srv_link_set_addrs(struct osmo_stream_srv_link *link, const char **addr, size_t addrcnt); void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port); diff --git a/src/stream_srv.c b/src/stream_srv.c index a600ad9..aa7edbf 100644 --- a/src/stream_srv.c +++ b/src/stream_srv.c @@ -81,7 +81,9 @@ uint16_t port; int sk_domain; int sk_type; + int sk_prio; /* socket priority, SO_PRIORITY, default=0=unset */ uint16_t proto; + uint8_t ip_dscp; /* IP Differentiated services, 0..63, default=0=unset */ osmo_stream_srv_link_accept_cb_t accept_cb; void *data; int flags; @@ -148,6 +150,24 @@ goto error_close_socket; }
+ if (link->ip_dscp > 0) { + ret = osmo_sock_set_dscp(sock_fd, link->ip_dscp); + if (ret < 0) { + LOGSLNK(link, LOGL_ERROR, "set_ip_dscp(%u): failed setsockopt err=%d\n", + link->ip_dscp, errno); + goto error_close_socket; + } + } + + if (link->sk_prio > 0) { + ret = osmo_sock_set_priority(sock_fd, link->sk_prio); + if (ret < 0) { + LOGSLNK(link, LOGL_ERROR, "set_priority(%d): failed setsockopt err=%d\n", + link->sk_prio, errno); + goto error_close_socket; + } + } + if (!link->accept_cb) { ret = -ENOTSUP; goto error_close_socket; @@ -224,6 +244,33 @@ link->flags &= ~OSMO_STREAM_SRV_F_NODELAY; }
+/*! Set the priority value of the stream socket. + * Setting this will automatically set the socket priority + * option on any socket established via this server link, before + * calling the accept_cb(). + * \param[in] link server link whose sockets are to be configured + * \param[in] sk_prio priority value. Values outside 0..6 require CAP_NET_ADMIN. + * \return negative on error, 0 on success + */ +int osmo_stream_srv_link_set_priority(struct osmo_stream_srv_link *link, int sk_prio) +{ + link->sk_prio = sk_prio; + return 0; +} + +/*! Set the DSCP (differentiated services code point) of the stream socket. + * Setting this will automatically set the IP DSCP option on any socket on any + * socket established via this server link, before calling the accept_cb(). + * \param[in] link server link whose sockets are to be configured + * \param[in] ip_dscp DSCP value. Value range 0..63. + * \return negative on error, 0 on success + */ +int osmo_stream_srv_link_set_ip_dscp(struct osmo_stream_srv_link *link, uint8_t ip_dscp) +{ + link->ip_dscp = ip_dscp; + return 0; +} + /*! Set the local address to which we bind. * Any changes to this setting will only become active upon next (re)connect. * \param[in] link Stream Server Link to modify