[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#498297: openssh: Please set traffic class on IPv6 packets



Package: openssh
Version: 1:5.1p1
Severity: wishlist
Tags: patch

OpenSSH sets the IPv4 ToS (Type of Service) byte to "low delay" or
"max throughput" depending on the situation, but does not set the
equivalent IPv6 Traffic Class byte. As far as I understand, these two
bytes are supposed to be used the same way, so here's a patch to set
the said traffic class byte on IPv6 packets.

-- 
Lionel
--- openssh-5.1p1.orig/packet.c
+++ openssh-5.1p1/packet.c
@@ -363,6 +363,27 @@
 	return 0;
 }
 
+/* returns 1 if connection is via ipv6 */
+
+int
+packet_connection_is_ipv6(void)
+{
+	struct sockaddr_storage to;
+	socklen_t tolen = sizeof(to);
+
+	memset(&to, 0, sizeof(to));
+	if (getsockname(connection_out, (struct sockaddr *)&to, &tolen) < 0)
+		return 0;
+#ifdef IPV4_IN_IPV6
+	if (to.ss_family == AF_INET6 &&
+	    IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)&to)->sin6_addr))
+		return 0;
+#endif
+	if (to.ss_family == AF_INET6)
+		return 1;
+	return 0;
+}
+
 /* Sets the connection into non-blocking mode. */
 
 void
@@ -1582,13 +1603,19 @@
 #if defined(IP_TOS) && !defined(IP_TOS_IS_BROKEN)
 	int tos = interactive ? IPTOS_LOWDELAY : IPTOS_THROUGHPUT;
 
-	if (!packet_connection_is_on_socket() ||
-	    !packet_connection_is_ipv4())
+	if (!packet_connection_is_on_socket())
 		return;
-	if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, &tos,
-	    sizeof(tos)) < 0)
-		error("setsockopt IP_TOS %d: %.100s:",
-		    tos, strerror(errno));
+	if (packet_connection_is_ipv4()) {
+		if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, &tos,
+		    sizeof(tos)) < 0)
+			error("setsockopt IP_TOS %d: %.100s:",
+			      tos, strerror(errno));
+	} else if (packet_connection_is_ipv6()) {
+		if (setsockopt(connection_in, IPPROTO_IPV6, IPV6_TCLASS, &tos,
+		    sizeof(tos)) < 0)
+			error("setsockopt IPV6_TCLASS %d: %.100s:",
+			      tos, strerror(errno));
+	}
 #endif
 }
 

Reply to: