Support ToS/DiffServ priority handling for IPv6 meta and UDP connections.
authorVittGam <github@vittgam.net>
Sun, 21 Dec 2014 13:29:40 +0000 (14:29 +0100)
committerVittGam <github@vittgam.net>
Sun, 21 Dec 2014 13:29:40 +0000 (14:29 +0100)
src/net_packet.c
src/net_setup.c
src/net_socket.c

index d11d58ad2b899ea4600c5df27a4e4fa4c371b3b6..dbf65463df9ad7624d4bc0723716d10a8c1f127f 100644 (file)
@@ -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)
index a00a32109d9a3080c0a8ae6b13f5fa9151315c2a..765a9ebf37a1ea0bd11b01c49b84247b6e76d87c 100644 (file)
@@ -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))
index 948ce0112e9953eeb20a9c4d6054a4bf64aed25f..cb271063b0bc5d25ad22d3d0cec65e66ad5052f8 100644 (file)
@@ -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) {