From: Razvan Cojocaru <[email protected]> client_nat_transform() adjusted the TCP/UDP checksum at a fixed offset of 20 bytes. With IP options this rewrote the UDP destination port or the TCP data offset and flags instead, and for non-first fragments it modified payload bytes. Use the header length from the IP header and skip the transport checksum for non-first fragments, as mss_fixup_ipv4() does.
Change-Id: Ibd316e5c3e6a0fb600ec4817aa079554464fd942 Signed-off-by: Razvan Cojocaru <[email protected]> Acked-by: Antonio Quartulli <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2208 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2208 This mail reflects revision 2 of this Change. Acked-by according to Gerrit (reflected above): Antonio Quartulli <[email protected]> diff --git a/src/openvpn/clinat.c b/src/openvpn/clinat.c index fc4acef..a046324 100644 --- a/src/openvpn/clinat.c +++ b/src/openvpn/clinat.c @@ -247,32 +247,45 @@ ADJUST_CHECKSUM(accumulate, h->ip.check); + /* The TCP/UDP header follows any IP options, and only the first + * fragment carries it. */ + const int hlen = OPENVPN_IPH_GET_LEN(h->ip.version_len); + struct buffer l4 = *ipbuf; + if ((ntohs(h->ip.frag_off) & OPENVPN_IP_OFFMASK) || hlen < (int)sizeof(struct openvpn_iphdr) + || !buf_advance(&l4, hlen)) + { + return; + } + if (h->ip.protocol == OPENVPN_IPPROTO_TCP) { - if (BLENZ(ipbuf) >= sizeof(struct openvpn_iphdr) + sizeof(struct openvpn_tcphdr)) + if (BLENZ(&l4) >= sizeof(struct openvpn_tcphdr)) { - ADJUST_CHECKSUM(accumulate, h->u.tcp.check); + struct openvpn_tcphdr *tcp = (struct openvpn_tcphdr *)BPTR(&l4); + ADJUST_CHECKSUM(accumulate, tcp->check); } } else if (h->ip.protocol == OPENVPN_IPPROTO_UDP) { - if (BLENZ(ipbuf) >= sizeof(struct openvpn_iphdr) + sizeof(struct openvpn_udphdr)) + if (BLENZ(&l4) >= sizeof(struct openvpn_udphdr)) { + struct openvpn_udphdr *udp = (struct openvpn_udphdr *)BPTR(&l4); + /* RFC 768: a UDP checksum of 0 means "no checksum computed". * Do not run the incremental adjustment over a non-checksum, * or we will write a bogus non-zero value into the field. */ - if (h->u.udp.check) + if (udp->check) { - ADJUST_CHECKSUM(accumulate, h->u.udp.check); + ADJUST_CHECKSUM(accumulate, udp->check); - if (!h->u.udp.check) + if (!udp->check) { /* RFC 768: a computed checksum of 0 must be transmitted * as 0xFFFF (one-complement), because 0 is reserved for * "no checksum computed" */ - h->u.udp.check = 0xFFFF; + udp->check = 0xFFFF; } } } _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
