From 219c416a1ee926278770330846f76e5cc91dd5d3 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Tue, 11 Jan 2022 20:10:42 +0100
Subject: [PATCH] event/ServerSocket: rename ip_tos to dscp_class and support
 IPv6

---
 src/event/ServerSocket.cxx | 18 ++++++++++++------
 src/event/ServerSocket.hxx | 10 +++++-----
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/event/ServerSocket.cxx b/src/event/ServerSocket.cxx
index 77557db1d..e75d13560 100644
--- a/src/event/ServerSocket.cxx
+++ b/src/event/ServerSocket.cxx
@@ -182,12 +182,18 @@ ServerSocket::OneServerSocket::Open()
 				      address, 5);
 
 #ifdef HAVE_TCP
-	if (parent.ip_tos >= 0 && address.GetFamily() == AF_INET &&
-	    !_fd.SetIntOption(IPPROTO_IP, IP_TOS, parent.ip_tos)) {
-		const SocketErrorMessage msg;
-		FmtError(server_socket_domain,
-			 "Could not set TOS option: {}",
-			 (const char *)msg);
+	if (parent.dscp_class >= 0) {
+		const int family = address.GetFamily();
+		if ((family == AF_INET &&
+		     !_fd.SetIntOption(IPPROTO_IP, IP_TOS, parent.dscp_class)) ||
+		    (family == AF_INET6 &&
+		     !_fd.SetIntOption(IPPROTO_IPV6, IPV6_TCLASS,
+				       parent.dscp_class))) {
+			const SocketErrorMessage msg;
+			FmtError(server_socket_domain,
+				 "Could not set DSCP class: {}",
+				 (const char *)msg);
+		}
 	}
 #endif
 
diff --git a/src/event/ServerSocket.hxx b/src/event/ServerSocket.hxx
index 56bdf40d7..6af6261a4 100644
--- a/src/event/ServerSocket.hxx
+++ b/src/event/ServerSocket.hxx
@@ -43,10 +43,10 @@ class ServerSocket {
 
 #ifdef HAVE_TCP
 	/**
-	 * A non-negative value sets the IPPROTO_IP/IP_TOS socket
-	 * option.
+	 * A non-negative value sets the IPPROTO_IP/IP_TOS or
+	 * IPPROTO_IPV6/IPV6_TCLASS socket option.
 	 */
-	int ip_tos = -1;
+	int dscp_class = -1;
 #endif
 
 	unsigned next_serial = 1;
@@ -60,10 +60,10 @@ public:
 	}
 
 #ifdef HAVE_TCP
-	void SetIpTos(int _ip_tos) noexcept {
+	void SetDscpClass(int _dscp_class) noexcept {
 		assert(sockets.empty());
 
-		ip_tos = _ip_tos;
+		dscp_class = _dscp_class;
 	}
 #endif