Skip to content

Commit c205e2b

Browse files
earthlingnormanmaurer
authored andcommitted
Set DSCP bits for IPv6 when setting traffic class.
Motivation: Linux uses different socket options to set the traffic class (DSCP) on IPv6 Modifications: Also set IPV6_TCLASS for IPv6 sockets Result: TrafficClass will work on IPv4 and IPv6 correctly
1 parent 4eaa59d commit c205e2b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

transport-native-epoll/src/main/c/io_netty_channel_epoll_Native.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ JNIEXPORT void JNICALL Java_io_netty_channel_epoll_Native_setTcpNotSentLowAt(JNI
405405

406406
JNIEXPORT void JNICALL Java_io_netty_channel_epoll_Native_setTrafficClass(JNIEnv* env, jclass clazz, jint fd, jint optval) {
407407
netty_unix_socket_setOption(env, fd, IPPROTO_IP, IP_TOS, &optval, sizeof(optval));
408+
409+
/* Try to set the ipv6 equivalent, but don't throw if this is an ipv4 only socket. */
410+
int rc = setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &optval, sizeof(optval));
411+
if (rc < 0 && errno != ENOPROTOOPT) {
412+
netty_unix_errors_throwChannelExceptionErrorNo(env, "setting ipv6 dscp failed: ", errno);
413+
}
408414
}
409415

410416
JNIEXPORT void JNICALL Java_io_netty_channel_epoll_Native_setBroadcast(JNIEnv* env, jclass clazz, jint fd, jint optval) {

0 commit comments

Comments
 (0)