Fix invalid checksum generation.
authorNathan Stratton Treadway <nathanst@ontko.com>
Sat, 12 Sep 2015 14:33:52 +0000 (16:33 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Sat, 12 Sep 2015 14:37:45 +0000 (16:37 +0200)
Use equation 3 given in RFC 1624 and the UpdateTTL() example function given
RFC 1141.

src/route.c

index 324212b7c0be585a13f549f4b0f9543dc295a456..c1be6cb0ae4a607ce54f1bb1cf0519c1ff49a484 100644 (file)
@@ -160,7 +160,7 @@ static void clamp_mss(const node_t *source, const node_t *via, vpn_packet_t *pac
                /* Found it */
                uint16_t oldmss = packet->data[start + 22 + i] << 8 | packet->data[start + 23 + i];
                uint16_t newmss = mtu - start - 20;
-               uint16_t csum = packet->data[start + 16] << 8 | packet->data[start + 17];
+               uint32_t csum = packet->data[start + 16] << 8 | packet->data[start + 17];
 
                if(oldmss <= newmss)
                        break;
@@ -171,11 +171,13 @@ static void clamp_mss(const node_t *source, const node_t *via, vpn_packet_t *pac
                packet->data[start + 22 + i] = newmss >> 8;
                packet->data[start + 23 + i] = newmss & 0xff;
                csum ^= 0xffff;
-               csum -= oldmss;
+               csum += oldmss ^ 0xffff;
                csum += newmss;
+               csum = (csum & 0xffff) + (csum >> 16);
+               csum += csum >> 16;
                csum ^= 0xffff;
                packet->data[start + 16] = csum >> 8;
-               packet->data[start + 17] = csum & 0xff;
+               packet->data[start + 17] = csum;
                break;
        }
 }