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 d11d58a..dbf6546 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 a00a321..765a9eb 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 948ce01..cb27106 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) {