Browse Source

core: setting the equivalent of IP_TOS socket option for IPv6

- reported in GH #598

(cherry picked from commit ff63e5c79592a37012018660552950a40a1a1581)
(cherry picked from commit 995d4084ebe192a51b89bd6b901e4d4b6ddd9fd7)
(cherry picked from commit bf5df06a84ba76e90c69253e93003ee44f8ebc8e)
Daniel-Constantin Mierla 9 years ago
parent
commit
bdb1f76ce8
1 changed files with 13 additions and 5 deletions
  1. 13 5
      tcp_main.c

+ 13 - 5
tcp_main.c

@@ -2795,7 +2795,7 @@ int tcp_init(struct socket_info* sock_info)
 		}
 	}
 #endif
-	
+
 	addr=&sock_info->su;
 	/* sock_info->proto=PROTO_TCP; */
 	if (init_su(addr, &sock_info->address, sock_info->port_no)<0){
@@ -2837,10 +2837,18 @@ int tcp_init(struct socket_info* sock_info)
 #endif
 	/* tos */
 	optval = tos;
-	if (setsockopt(sock_info->socket, IPPROTO_IP, IP_TOS, (void*)&optval, 
-				sizeof(optval)) ==-1){
-		LM_WARN("setsockopt tos: %s (%d)\n", strerror(errno), tos);
-		/* continue since this is not critical */
+	if(sock_info->address.af==AF_INET){
+		if (setsockopt(sock_info->socket, IPPROTO_IP, IP_TOS, (void*)&optval,
+					sizeof(optval)) ==-1){
+			LM_WARN("setsockopt tos: %s (%d)\n", strerror(errno), tos);
+			/* continue since this is not critical */
+		}
+	} else if(sock_info->address.af==AF_INET6){
+		if (setsockopt(sock_info->socket, IPPROTO_IPV6, IPV6_TCLASS,
+					(void*)&optval, sizeof(optval)) ==-1) {
+			LM_WARN("setsockopt v6 tos: %s (%d)\n", strerror(errno), tos);
+			/* continue since this is not critical */
+		}
 	}
 #ifdef HAVE_TCP_DEFER_ACCEPT
 	/* linux only */