Fix spelling errors.
[tinc] / src / route.c
index a130e69..dcc6f3c 100644 (file)
@@ -59,6 +59,7 @@ static const size_t opt_size = sizeof(struct nd_opt_hdr);
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
 #endif
 
+volatile int dummy;
 static timeout_t age_subnets_timeout;
 
 /* RFC 1071 */
@@ -80,6 +81,11 @@ static uint16_t inet_checksum(void *data, int len, uint16_t prevsum) {
                checksum = (checksum & 0xFFFF) + (checksum >> 16);
        }
 
+       // Work around a compiler optimization bug.
+       if(checksum) {
+               dummy = 1;
+       }
+
        return ~checksum;
 }
 
@@ -406,6 +412,15 @@ static void clamp_mss(const node_t *source, const node_t *via, vpn_packet_t *pac
                type = DATA(packet)[16] << 8 | DATA(packet)[17];
        }
 
+       /* IP in IP (RFC 2003) packet */
+       if(type == ETH_P_IP && DATA(packet)[start + 9] == 4) {
+               start += 20;
+       }
+
+       if(packet->len <= start + 20) {
+               return;
+       }
+
        if(type == ETH_P_IP && DATA(packet)[start + 9] == 6) {
                start += (DATA(packet)[start] & 0xf) * 4;
        } else if(type == ETH_P_IPV6 && DATA(packet)[start + 6] == 6) {
@@ -480,6 +495,7 @@ static void clamp_mss(const node_t *source, const node_t *via, vpn_packet_t *pac
 }
 
 static void age_subnets(void *data) {
+       (void)data;
        bool left = false;
 
        for splay_each(subnet_t, s, myself->subnet_tree) {
@@ -642,11 +658,13 @@ static void route_ipv4(node_t *source, vpn_packet_t *packet) {
        }
 
        if(!subnet->owner->status.reachable) {
-               return route_ipv4_unreachable(source, packet, ether_size, ICMP_DEST_UNREACH, ICMP_NET_UNREACH);
+               route_ipv4_unreachable(source, packet, ether_size, ICMP_DEST_UNREACH, ICMP_NET_UNREACH);
+               return;
        }
 
        if(forwarding_mode == FMODE_OFF && source != myself && subnet->owner != myself) {
-               return route_ipv4_unreachable(source, packet, ether_size, ICMP_DEST_UNREACH, ICMP_NET_ANO);
+               route_ipv4_unreachable(source, packet, ether_size, ICMP_DEST_UNREACH, ICMP_NET_ANO);
+               return;
        }
 
        if(decrement_ttl && source != myself && subnet->owner != myself)
@@ -666,7 +684,8 @@ static void route_ipv4(node_t *source, vpn_packet_t *packet) {
        }
 
        if(directonly && subnet->owner != via) {
-               return route_ipv4_unreachable(source, packet, ether_size, ICMP_DEST_UNREACH, ICMP_NET_ANO);
+               route_ipv4_unreachable(source, packet, ether_size, ICMP_DEST_UNREACH, ICMP_NET_ANO);
+               return;
        }
 
        if(via && packet->len > MAX(via->mtu, 590) && via != myself) {
@@ -733,11 +752,13 @@ static void route_ipv6(node_t *source, vpn_packet_t *packet) {
        }
 
        if(!subnet->owner->status.reachable) {
-               return route_ipv6_unreachable(source, packet, ether_size, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOROUTE);
+               route_ipv6_unreachable(source, packet, ether_size, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOROUTE);
+               return;
        }
 
        if(forwarding_mode == FMODE_OFF && source != myself && subnet->owner != myself) {
-               return route_ipv6_unreachable(source, packet, ether_size, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADMIN);
+               route_ipv6_unreachable(source, packet, ether_size, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADMIN);
+               return;
        }
 
        if(decrement_ttl && source != myself && subnet->owner != myself)
@@ -757,7 +778,8 @@ static void route_ipv6(node_t *source, vpn_packet_t *packet) {
        }
 
        if(directonly && subnet->owner != via) {
-               return route_ipv6_unreachable(source, packet, ether_size, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADMIN);
+               route_ipv6_unreachable(source, packet, ether_size, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADMIN);
+               return;
        }
 
        if(via && packet->len > MAX(via->mtu, 1294) && via != myself) {
@@ -885,7 +907,7 @@ static void route_neighborsol(node_t *source, vpn_packet_t *packet) {
        memcpy(DATA(packet), DATA(packet) + ETH_ALEN, ETH_ALEN); /* copy destination address */
        DATA(packet)[ETH_ALEN * 2 - 1] ^= 0xFF;                  /* mangle source address so it looks like it's not from us */
 
-       ip6.ip6_dst = ip6.ip6_src;                               /* swap destination and source protocoll address */
+       ip6.ip6_dst = ip6.ip6_src;                               /* swap destination and source protocol address */
        ip6.ip6_src = ns.nd_ns_target;
 
        if(has_opt) {