From: VittGam Date: Sun, 21 Dec 2014 13:29:40 +0000 (+0100) Subject: Support ToS/DiffServ priority handling for IPv6 meta and UDP connections. X-Git-Tag: release-1.0.25~6 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=c72e237;p=tinc Support ToS/DiffServ priority handling for IPv6 meta and UDP connections. --- diff --git a/src/net_packet.c b/src/net_packet.c index d11d58ad..dbf65463 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -415,7 +415,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) { vpn_packet_t *outpkt; int origlen; int outlen, outpad; -#if defined(SOL_IP) && defined(IP_TOS) +#if (defined(SOL_IP) && defined(IP_TOS)) || (defined(IPPROTO_IPV6) && defined(IPV6_TCLASS)) static int priority = 0; #endif int origpriority; @@ -550,15 +550,23 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) { } #if defined(SOL_IP) && defined(IP_TOS) - if(priorityinheritance && origpriority != priority - && listen_socket[n->sock].sa.sa.sa_family == AF_INET) { + if(priorityinheritance && origpriority != priority && listen_socket[n->sock].sa.sa.sa_family == AF_INET) { priority = origpriority; - ifdebug(TRAFFIC) logger(LOG_DEBUG, "Setting outgoing packet priority to %d", priority); + ifdebug(TRAFFIC) logger(LOG_DEBUG, "Setting IPv4 outgoing packet priority to %d", priority); if(setsockopt(listen_socket[n->sock].udp, SOL_IP, IP_TOS, &priority, sizeof(priority))) /* SO_PRIORITY doesn't seem to work */ logger(LOG_ERR, "System call `%s' failed: %s", "setsockopt", strerror(errno)); } #endif +#if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS) + if(priorityinheritance && origpriority != priority && listen_socket[n->sock].sa.sa.sa_family == AF_INET6) { + priority = origpriority; + ifdebug(TRAFFIC) logger(LOG_DEBUG, "Setting IPv6 outgoing packet priority to %d", priority); + if(setsockopt(listen_socket[n->sock].udp, IPPROTO_IPV6, IPV6_TCLASS, &priority, sizeof(priority))) /* SO_PRIORITY doesn't seem to work */ + logger(LOG_ERR, "System call `%s' failed: %s", "setsockopt", strerror(errno)); + } +#endif + if(sendto(listen_socket[sock].udp, (char *) &inpkt->seqno, inpkt->len, 0, sa, sl) < 0 && !sockwouldblock(sockerrno)) { if(sockmsgsize(sockerrno)) { if(n->maxmtu >= origlen) diff --git a/src/net_setup.c b/src/net_setup.c index a00a3210..765a9ebf 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -539,7 +539,12 @@ static bool setup_myself(void) { #if !defined(SOL_IP) || !defined(IP_TOS) if(priorityinheritance) - logger(LOG_WARNING, "%s not supported on this platform", "PriorityInheritance"); + logger(LOG_WARNING, "%s not supported on this platform for IPv4 connection", "PriorityInheritance"); +#endif + +#if !defined(IPPROTO_IPV6) || !defined(IPV6_TCLASS) + if(priorityinheritance) + logger(LOG_WARNING, "%s not supported on this platform for IPv6 connection", "PriorityInheritance"); #endif if(!get_config_int(lookup_config(config_tree, "MACExpire"), &macexpire)) diff --git a/src/net_socket.c b/src/net_socket.c index 948ce011..cb271063 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -78,6 +78,11 @@ static void configure_tcp(connection_t *c) { option = IPTOS_LOWDELAY; setsockopt(c->socket, SOL_IP, IP_TOS, (void *)&option, sizeof(option)); #endif + +#if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS) && defined(IPTOS_LOWDELAY) + option = IPTOS_LOWDELAY; + setsockopt(c->socket, IPPROTO_IPV6, IPV6_TCLASS, (void *)&option, sizeof(option)); +#endif } static bool bind_to_interface(int sd) {