Convert sizeof foo to sizeof(foo).
[tinc] / src / route.c
index 907197b..ef68759 100644 (file)
@@ -1,7 +1,8 @@
 /*
     route.c -- routing
     Copyright (C) 2000-2005 Ivo Timmermans,
-                  2000-2014 Guus Sliepen <guus@tinc-vpn.org>
+                  2000-2017 Guus Sliepen <guus@tinc-vpn.org>
+                 2015-2016 Vittorio Gambaletta
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -103,9 +104,9 @@ static bool checklength(node_t *source, vpn_packet_t *packet, length_t length) {
 
 static void swap_mac_addresses(vpn_packet_t *packet) {
        mac_t tmp;
-       memcpy(&tmp, &packet->data[0], sizeof tmp);
-       memcpy(&packet->data[0], &packet->data[6], sizeof tmp);
-       memcpy(&packet->data[6], &tmp, sizeof tmp);
+       memcpy(&tmp, &packet->data[0], sizeof(tmp));
+       memcpy(&packet->data[0], &packet->data[6], sizeof(tmp));
+       memcpy(&packet->data[6], &tmp, sizeof(tmp));
 }
 
 /* RFC 792 */
@@ -482,7 +483,7 @@ void age_subnets(void) {
                if(s->expires && s->expires <= now) {
                        ifdebug(TRAFFIC) {
                                char netstr[MAXNETSTR];
-                               if(net2str(netstr, sizeof netstr, s))
+                               if(net2str(netstr, sizeof(netstr), s))
                                        logger(LOG_INFO, "Subnet %s expired", netstr);
                        }
 
@@ -561,7 +562,7 @@ static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet) {
        node_t *via;
        ipv4_t dest;
 
-       memcpy(&dest, &packet->data[30], sizeof dest);
+       memcpy(&dest, &packet->data[30], sizeof(dest));
        subnet = lookup_subnet_ipv4(&dest);
 
        if(!subnet) {
@@ -640,7 +641,7 @@ static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet) {
        node_t *via;
        ipv6_t dest;
 
-       memcpy(&dest, &packet->data[38], sizeof dest);
+       memcpy(&dest, &packet->data[38], sizeof(dest));
        subnet = lookup_subnet_ipv6(&dest);
 
        if(!subnet) {
@@ -674,6 +675,9 @@ static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet) {
                if(!do_decrement_ttl(source, packet))
                        return;
 
+       if(priorityinheritance)
+               packet->priority = ((packet->data[14] & 0x0f) << 4) | (packet->data[15] >> 4);
+
        via = (subnet->owner->via == myself) ? subnet->owner->nexthop : subnet->owner->via;
        
        if(via == source) {
@@ -934,13 +938,13 @@ static void route_mac(node_t *source, vpn_packet_t *packet) {
 
        if(source == myself) {
                mac_t src;
-               memcpy(&src, &packet->data[6], sizeof src);
+               memcpy(&src, &packet->data[6], sizeof(src));
                learn_mac(&src);
        }
 
        /* Lookup destination address */
 
-       memcpy(&dest, &packet->data[0], sizeof dest);
+       memcpy(&dest, &packet->data[0], sizeof(dest));
        subnet = lookup_subnet_mac(NULL, &dest);
 
        if(!subnet) {
@@ -962,8 +966,12 @@ static void route_mac(node_t *source, vpn_packet_t *packet) {
 
        uint16_t type = packet->data[12] << 8 | packet->data[13];
 
-       if(priorityinheritance && type == ETH_P_IP && packet->len >= ether_size + ip_size)
-               packet->priority = packet->data[15];
+       if(priorityinheritance) {
+               if(type == ETH_P_IP && packet->len >= ether_size + ip_size)
+                       packet->priority = packet->data[15];
+               else if(type == ETH_P_IPV6 && packet->len >= ether_size + ip6_size)
+                       packet->priority = ((packet->data[14] & 0x0f) << 4) | (packet->data[15] >> 4);
+       }
 
        // Handle packets larger than PMTU