Browse code

core: set TOS for tcp IPv6 sockets

Daniel-Constantin Mierla authored on 30/03/2013 08:24:19
Showing 1 changed files
... ...
@@ -373,7 +373,7 @@ static inline int init_sock_keepalive(int s)
373 373
  *  disable nagle, tos lowdelay, reuseaddr, non-blocking
374 374
  *
375 375
  * return -1 on error */
376
-static int init_sock_opt(int s)
376
+static int init_sock_opt(int s, int af)
377 377
 {
378 378
 	int flags;
379 379
 	int optval;
... ...
@@ -388,11 +388,24 @@ static int init_sock_opt(int s)
388 388
 #endif
389 389
 	/* tos*/
390 390
 	optval = tos;
391
-	if (setsockopt(s, IPPROTO_IP, IP_TOS, (void*)&optval,sizeof(optval)) ==-1){
392
-		LOG(L_WARN, "WARNING: init_sock_opt: setsockopt tos: %s\n",
393
-				strerror(errno));
394
-		/* continue since this is not critical */
391
+	if(af==AF_INET){
392
+		if (setsockopt(s, IPPROTO_IP, IP_TOS, (void*)&optval,
393
+					sizeof(optval)) ==-1){
394
+			LOG(L_WARN, "WARNING: init_sock_opt: setsockopt tos: %s\n",
395
+					strerror(errno));
396
+			/* continue since this is not critical */
397
+		}
398
+#ifdef USE_IPV6
399
+	} else if(af==AF_INET6){
400
+		if (setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS,
401
+					(void*)&optval, sizeof(optval)) ==-1) {
402
+			LOG(L_WARN, "WARNING: init_sock_opt: setsockopt v6 tos: %s\n",
403
+					strerror(errno));
404
+			/* continue since this is not critical */
405
+		}
406
+#endif
395 407
 	}
408
+
396 409
 #if  !defined(TCP_DONT_REUSEADDR) 
397 410
 	optval=1;
398 411
 	if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
... ...
@@ -1140,7 +1153,7 @@ inline static int tcp_do_connect(	union sockaddr_union* server,
1140 1140
 				su2a(server, sizeof(*server)), errno, strerror(errno));
1141 1141
 		goto error;
1142 1142
 	}
1143
-	if (init_sock_opt(s)<0){
1143
+	if (init_sock_opt(s, server->s.sa_family)<0){
1144 1144
 		LOG(L_ERR, "ERROR: tcp_do_connect %s: init_sock_opt failed\n",
1145 1145
 					su2a(server, sizeof(*server)));
1146 1146
 		goto error;