Make sure packet header structures are correctly packed on Windows.
authorEtienne Dechamps <etienne@edechamps.fr>
Sun, 15 Mar 2015 10:00:56 +0000 (10:00 +0000)
committerEtienne Dechamps <etienne@edechamps.fr>
Sun, 15 Mar 2015 10:12:18 +0000 (10:12 +0000)
Modern versions of GCC handle structure packing differently when
compiling for Windows, as reported in the following GCC bug report:

  http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991

In practice, this affects tinc because it uses packed structs as a
convenient way to populate packet headers. "struct ip" is especially
affected - on Linux, sizeof(struct ip) returns 20 as expected, while on
Windows, it returns 24 because of the broken alignment.

This in turn completely breaks code that has to populate an IP header.
Specifically, this breaks route_ipv4_unreachable() which is responsible,
among other things, for the generation of ICMP Fragmentation Needed
messages. On Windows, these messages are corrupted beyond hope because
of this alignment issue. For TCP connections that are established
before tinc obtains a fix on the MTU (and thus are not MSS clamped),
this can result in massive disruption.

This commit fixes the issue by forcing GCC to use standard alignment
for all packed structures in the tinc codebase instead of the MSVC
alignment.


No differences found