aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--include/osmocom/core/socket.h9
-rw-r--r--src/socket.c22
2 files changed, 30 insertions, 1 deletions
diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h
index 10e17663..a053391d 100644
--- a/include/osmocom/core/socket.h
+++ b/include/osmocom/core/socket.h
@@ -44,6 +44,15 @@ struct osmo_sockaddr {
/*! use SO_REUSEADDR on UDP ports (required for multicast) */
#define OSMO_SOCK_F_UDP_REUSEADDR (1 << 5)
+/*! use OSMO_SOCK_F_DSCP(x) to set IP DSCP 'x' for packets transmitted on the socket */
+#define OSMO_SOCK_F_DSCP(x) (((x)&0x3f) << 24)
+#define GET_OSMO_SOCK_F_DSCP(f) (((f) >> 24) & 0x3f)
+
+/*! use OSMO_SOCK_F_PRIO(x) to set priority 'x' for packets transmitted on the socket */
+#define OSMO_SOCK_F_PRIO(x) (((x)&0xff) << 16)
+#define GET_OSMO_SOCK_F_PRIO(f) (((f) >> 16) & 0xff)
+
+
/*! maximum number of local or remote addresses supported by an osmo_sock instance */
#define OSMO_SOCK_MAX_ADDRS 32
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;
}