Browse code

core: set TOS for IPv6 UDP sockets

- reported by Klaus Feichtinger, FS#179

Daniel-Constantin Mierla authored on 27/03/2013 19:53:00
Showing 1 changed files
... ...
@@ -321,11 +321,24 @@ int udp_init(struct socket_info* sock_info)
321 321
 	}
322 322
 	/* tos */
323 323
 	optval = tos;
324
-	if (setsockopt(sock_info->socket, IPPROTO_IP, IP_TOS, (void*)&optval, 
325
-			sizeof(optval)) ==-1){
326
-		LOG(L_WARN, "WARNING: udp_init: setsockopt tos: %s\n", strerror(errno));
327
-		/* continue since this is not critical */
324
+	if (addr->s.sa_family==AF_INET){
325
+		if (setsockopt(sock_info->socket, IPPROTO_IP, IP_TOS, (void*)&optval, 
326
+				sizeof(optval)) ==-1){
327
+			LOG(L_WARN, "WARNING: udp_init: setsockopt tos: %s\n",
328
+					strerror(errno));
329
+			/* continue since this is not critical */
330
+		}
331
+#ifdef USE_IPV6
332
+	} else if (addr->s.sa_family==AF_INET6){
333
+		if (setsockopt(sock_info->socket, IPPROTO_IPV6, IPV6_TCLASS,
334
+					(void*)&optval, sizeof(optval)) ==-1) {
335
+			LOG(L_WARN, "WARNING: udp_init: setsockopt v6 tos: %s\n",
336
+					strerror(errno));
337
+			/* continue since this is not critical */
338
+		}
339
+#endif
328 340
 	}
341
+
329 342
 #if defined (__OS_linux) && defined(UDP_ERRORS)
330 343
 	optval=1;
331 344
 	/* enable error receiving on unconnected sockets */