Make sure packet header structures are correctly packed on Windows.
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.
This commit is contained in:
parent
6568cffd52
commit
176ee01526
3 changed files with 11 additions and 11 deletions
|
@ -81,7 +81,7 @@ struct ip {
|
|||
uint8_t ip_p;
|
||||
uint16_t ip_sum;
|
||||
struct in_addr ip_src, ip_dst;
|
||||
} __attribute__ ((__packed__));
|
||||
} __attribute__ ((__gcc_struct__, __packed__));
|
||||
#endif
|
||||
|
||||
#ifndef IP_OFFMASK
|
||||
|
@ -143,7 +143,7 @@ struct icmp {
|
|||
#define icmp_radv icmp_dun.id_radv
|
||||
#define icmp_mask icmp_dun.id_mask
|
||||
#define icmp_data icmp_dun.id_data
|
||||
} __attribute__ ((__packed__));
|
||||
} __attribute__ ((__gcc_struct__, __packed__));
|
||||
#endif
|
||||
|
||||
#endif /* __TINC_IPV4_H__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue