Attention is currently required from: Arne Schwabe.

Hello Arne Schwabe,

I'd like you to do a code review.
Please visit

    https://gerrit.openvpn.net/c/openvpn/+/2208?usp=email

to review the following change.


Change subject: clinat: locate the TCP/UDP header via the IP header length
......................................................................

clinat: locate the TCP/UDP header via the IP header length

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]>
---
M src/openvpn/clinat.c
1 file changed, 20 insertions(+), 7 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/2208/1

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;
                     }
                 }
             }

--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2208?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ibd316e5c3e6a0fb600ec4817aa079554464fd942
Gerrit-Change-Number: 2208
Gerrit-PatchSet: 1
Gerrit-Owner: Răzvan Cojocaru <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
  • [Openvpn-devel] [S] Chan... Code Review

Reply via email to