aboutsummaryrefslogtreecommitdiffstats
path: root/src/socket.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2021-04-28 13:09:49 +0200
committerHarald Welte <laforge@osmocom.org>2021-04-28 13:15:20 +0200
commitc545ff6f3eec08730a87cf0e469c904180a16ff6 (patch)
treea631d0c8e071bfabdd2f9ae4e6ae286feabd168a /src/socket.c
parentfaf6b70b0ed5d62854c1ec542cb448c055c961be (diff)
socket: QoS support for all our socket init functions
Every socket function that can be passed a 'flags' argument now supports the following two additional macros that can be or-ed in with the flags: * OSMO_SOCK_F_DSCP(x) -- specify the IP DSCP of the socket * OSMO_SOCK_F_PRIO(x) -- specify the priority of the socket The existing osmo_sock_set_{dscp,priority}() functions are useful, but you cannot call them in between the socket creation and the connect() operation when using our socket helpers. This means that the first packet sent will have the default DSCP/priority, and only later packets would have the desired values. When using the functionality introduced by this patch, we can ensure that even the very first packet of e.g. a TCP or SCTP connect() will have the correct DSCP/priority applied. Change-Id: If22988735fe05e51226c6b091a5348dcf1208cdf Related: SYS#5427
Diffstat (limited to 'src/socket.c')
-rw-r--r--src/socket.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/socket.c b/src/socket.c
index b44bbc6d..6afe9865 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -134,7 +134,9 @@ static int addrinfo_helper_multi(struct addrinfo **addrinfo, uint16_t family, ui
static int socket_helper_tail(int sfd, unsigned int flags)
{
- int on = 1;
+ int rc, on = 1;
+ uint8_t dscp = GET_OSMO_SOCK_F_DSCP(flags);
+ uint8_t prio = GET_OSMO_SOCK_F_PRIO(flags);
if (flags & OSMO_SOCK_F_NONBLOCK) {
if (ioctl(sfd, FIONBIO, (unsigned char *)&on) < 0) {
@@ -146,6 +148,24 @@ static int socket_helper_tail(int sfd, unsigned int flags)
}
}
+ if (dscp) {
+ rc = osmo_sock_set_dscp(sfd, dscp);
+ if (rc) {
+ LOGP(DLGLOBAL, LOGL_ERROR, "cannot set IP DSCP of socket to %u: %s\n",
+ dscp, strerror(errno));
+ /* we consider this a non-fatal error */
+ }
+ }
+
+ if (prio) {
+ rc = osmo_sock_set_priority(sfd, prio);
+ if (rc) {
+ LOGP(DLGLOBAL, LOGL_ERROR, "cannot set priority of socket to %u: %s\n",
+ prio, strerror(errno));
+ /* we consider this a non-fatal error */
+ }
+ }
+
return 0;
}