aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;
}