socket: Introduce osmo_sock_set_priority() helper function

In some situations we want to set the SO_PRIORITY socket option
to determine the in-kernel priority of packets generated by this
socket.

Change-Id: I89abffcd125e6d073338a5c6437b9433220e1823
Related: SYS#5427
This commit is contained in:
Harald Welte 2021-04-27 22:24:08 +02:00
parent c96d716606
commit ecc0bd8d42
2 changed files with 9 additions and 0 deletions

View File

@ -123,6 +123,7 @@ char *osmo_sockaddr_to_str_buf(char *buf, size_t buf_len,
const struct osmo_sockaddr *sockaddr);
int osmo_sock_set_dscp(int fd, uint8_t dscp);
int osmo_sock_set_priority(int fd, int prio);
#endif /* (!EMBEDDED) */
/*! @} */

View File

@ -1802,6 +1802,14 @@ int osmo_sock_set_dscp(int fd, uint8_t dscp)
return setsockopt(fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos));
}
/*! Set the priority value of a socket.
* \param[in] prio priority value. Values outside 0..6 require CAP_NET_ADMIN.
* \returns 0 on success; negative on error. */
int osmo_sock_set_priority(int fd, int prio)
{
/* and write it back to the kernel */
return setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio));
}
#endif /* HAVE_SYS_SOCKET_H */