From: "flichtenheld (Code Review)" Date: Tue, 2 Sep 2025 12:05:19 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <3cd7e230c1cd13c8add8dfef0c775bda270e5924-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Te3Xboapr/Q="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: proto: Clean up conversion warnings related to checksum macros List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --Te3Xboapr/Q= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1164?usp=3Demail to review the following change. Change subject: proto: Clean up conversion warnings related to checksum mac= ros ...................................................................... proto: Clean up conversion warnings related to checksum macros These should not change any behavior, they mostly clarify the used types and silence warnings, since these casts are deliberate. Change-Id: Ica721a51b00d5314125bcaf5a586e718c5982aef Signed-off-by: Frank Lichtenheld --- M src/openvpn/clinat.c M src/openvpn/mss.c M src/openvpn/proto.h 3 files changed, 37 insertions(+), 42 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/1164/1 diff --git a/src/openvpn/clinat.c b/src/openvpn/clinat.c index 48a2057..69471ae 100644 --- a/src/openvpn/clinat.c +++ b/src/openvpn/clinat.c @@ -185,11 +185,7 @@ const int direction) { struct ip_tcp_udp_hdr *h =3D (struct ip_tcp_udp_hdr *)BPTR(ipbuf); - int i; - uint32_t addr, *addr_ptr; - const uint32_t *from, *to; - int accumulate =3D 0; - unsigned int amask; + int32_t accumulate =3D 0; unsigned int alog =3D 0; if (check_debug_level(D_CLIENT_NAT)) @@ -197,8 +193,11 @@ print_pkt(&h->ip, "BEFORE", direction, D_CLIENT_NAT); } - for (i =3D 0; i < list->n; ++i) + for (int i =3D 0; i < list->n; ++i) { + uint32_t addr, *addr_ptr; + const uint32_t *from, *to; + unsigned int amask; const struct client_nat_entry *e =3D &list->entries[i]; /* current= NAT rule */ if (e->type ^ direction) { diff --git a/src/openvpn/mss.c b/src/openvpn/mss.c index 32cd3f8..f2b314f 100644 --- a/src/openvpn/mss.c +++ b/src/openvpn/mss.c @@ -138,11 +138,8 @@ void mss_fixup_dowork(struct buffer *buf, uint16_t maxmss) { - int hlen, olen, optlen; + int olen, optlen; uint8_t *opt; - uint16_t mssval; - int accumulate; - struct openvpn_tcphdr *tc; if (BLEN(buf) < (int)sizeof(struct openvpn_tcphdr)) { @@ -150,8 +147,8 @@ } verify_align_4(buf); - tc =3D (struct openvpn_tcphdr *)BPTR(buf); - hlen =3D OPENVPN_TCPH_GET_DOFF(tc->doff_res); + struct openvpn_tcphdr *tc =3D (struct openvpn_tcphdr *)BPTR(buf); + int hlen =3D OPENVPN_TCPH_GET_DOFF(tc->doff_res); /* Invalid header length or header without options. */ if (hlen <=3D (int)sizeof(struct openvpn_tcphdr) || hlen > BLEN(buf)) @@ -166,34 +163,33 @@ { break; } - else if (*opt =3D=3D OPENVPN_TCPOPT_NOP) + if (*opt =3D=3D OPENVPN_TCPOPT_NOP) { optlen =3D 1; + continue; } - else + + optlen =3D *(opt + 1); + if (optlen <=3D 0 || optlen > olen) { - optlen =3D *(opt + 1); - if (optlen <=3D 0 || optlen > olen) + break; + } + if (*opt =3D=3D OPENVPN_TCPOPT_MAXSEG) + { + if (optlen !=3D OPENVPN_TCPOLEN_MAXSEG) { - break; + continue; } - if (*opt =3D=3D OPENVPN_TCPOPT_MAXSEG) + uint16_t mssval =3D opt[2] << 8; + mssval +=3D opt[3]; + if (mssval > maxmss) { - if (optlen !=3D OPENVPN_TCPOLEN_MAXSEG) - { - continue; - } - mssval =3D opt[2] << 8; - mssval +=3D opt[3]; - if (mssval > maxmss) - { - dmsg(D_MSS, "MSS: %" PRIu16 " -> %" PRIu16, mssval, ma= xmss); - accumulate =3D htons(mssval); - opt[2] =3D (uint8_t)((maxmss >> 8) & 0xff); - opt[3] =3D (uint8_t)(maxmss & 0xff); - accumulate -=3D htons(maxmss); - ADJUST_CHECKSUM(accumulate, tc->check); - } + dmsg(D_MSS, "MSS: %" PRIu16 " -> %" PRIu16, mssval, maxmss= ); + opt[2] =3D (uint8_t)((maxmss >> 8) & 0xff); + opt[3] =3D (uint8_t)(maxmss & 0xff); + int32_t accumulate =3D htons(mssval); + accumulate -=3D htons(maxmss); + ADJUST_CHECKSUM(accumulate, tc->check); } } } diff --git a/src/openvpn/proto.h b/src/openvpn/proto.h index 62157fa..94952bd 100644 --- a/src/openvpn/proto.h +++ b/src/openvpn/proto.h @@ -214,7 +214,7 @@ */ #define ADJUST_CHECKSUM(acc, cksum) \ { \ - int _acc =3D acc; \ + int32_t _acc =3D acc; \ _acc +=3D (cksum); \ if (_acc < 0) \ { \ @@ -231,16 +231,16 @@ } \ } -#define ADD_CHECKSUM_32(acc, u32) \ - { \ - acc +=3D (u32) & 0xffff; \ - acc +=3D (u32) >> 16; \ +#define ADD_CHECKSUM_32(acc, u32) \ + { \ + acc +=3D (int32_t)((u32) & 0xffff); \ + acc +=3D (int32_t)((u32) >> 16); \ } -#define SUB_CHECKSUM_32(acc, u32) \ - { \ - acc -=3D (u32) & 0xffff; \ - acc -=3D (u32) >> 16; \ +#define SUB_CHECKSUM_32(acc, u32) \ + { \ + acc -=3D (int32_t)((u32) & 0xffff); \ + acc -=3D (int32_t)((u32) >> 16); \ } /* -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1164?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ica721a51b00d5314125bcaf5a586e718c5982aef Gerrit-Change-Number: 1164 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-MessageType: newchange --Te3Xboapr/Q= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

V= iew Change

proto: Clean up conversion warnings related to checksum macr=
os

These should not change any behavior, they mostly clarify
the = used types and silence warnings, since these casts are
deliberate.
Change-Id: Ica721a51b00d5314125bcaf5a586e718c5982aef
Signed-off-by: Fr= ank Lichtenheld <frank@...2641...>
---
M src/openvpn/clinat.cM src/openvpn/mss.c
M src/openvpn/proto.h
3 files changed, 37 inser= tions(+), 42 deletions(-)

git pull ssh://gerrit.openvpn.net:29418=
/openvpn refs/changes/64/1164/1
diff --git a/src/openvpn/clinat.c b=
/src/openvpn/clinat.c
index 48a2057..69471ae 100644<= br>--- a/src/openvpn/clinat.c
+++ b/src/openvpn/clina= t.c
@@ -185,11 +185,7 @@
= const int direction)
{
struct ip_= tcp_udp_hdr *h =3D (struct ip_tcp_udp_hdr *)BPTR(ipbuf);
- int i;
- uint32_t addr, *addr_ptr;
- const uint32_t *from, *to;
- int accumulate =3D 0;- unsigned int amask;=
+ int32_t accumulate =3D= 0;
unsigned int alog =3D 0;
<= br> if (check_debug_level(D_CLIENT_NAT))
@@ -197,= 8 +193,11 @@
print_pkt(&h->ip, "BEFORE= ", direction, D_CLIENT_NAT);
}
<= /span>
- for (i =3D 0; i &l= t; list->n; ++i)
+= for (int i =3D 0; i < list->n; ++i)
{=
+ uint32_t addr, *ad= dr_ptr;
+ cons= t uint32_t *from, *to;
- int hlen, olen, optlen;
+ int olen, optlen;
uint8_t= *opt;
- uint16_t ms= sval;
- int accumula= te;
- struct openvpn= _tcphdr *tc;

if (BLEN(buf) < (int= )sizeof(struct openvpn_tcphdr))
{
@@ -= 150,8 +147,8 @@
}

= verify_align_4(buf);
- tc =3D (struct openvpn_tcphdr *)BPTR(buf);
- hlen =3D OPENVPN_TCPH_GET_DOFF(tc->doff_r= es);
+ struct open= vpn_tcphdr *tc =3D (struct openvpn_tcphdr *)BPTR(buf);
+ int hlen =3D OPENVPN_TCPH_GET_DOFF(t= c->doff_res);

/* Invalid header l= ength or header without options. */
if (hlen <=3D (= int)sizeof(struct openvpn_tcphdr) || hlen > BLEN(buf))
@= @ -166,34 +163,33 @@
{
= break;
}
- else if (*opt =3D=3D OPENVPN_TCPOPT_NOP)
+ if (*opt =3D=3D OPENVPN_= TCPOPT_NOP)

{
optlen = =3D 1;
+ c= ontinue;
}
- else
+
+ optl= en =3D *(opt + 1);
+ = if (optlen <=3D 0 || optlen > olen)
{=
- optlen = =3D *(opt + 1);
- = if (optlen <=3D 0 || optlen > olen)
+ break;
+ }
+ if (*opt =3D=3D OPENVPN_TCPOPT_MAXSEG)
<= span style=3D"color: hsl(120, 100%, 40%);">+ {
+ if (optlen !=3D OPENVPN_TCPOL= EN_MAXSEG)
{
- break;
+ continue;
= }
- if (*= opt =3D=3D OPENVPN_TCPOPT_MAXSEG)
+ uint16_t mssval =3D opt[2] << 8;
= + mssval +=3D opt[3]= ;
+ if (ms= sval > maxmss)
{
- if (optlen !=3D OPENVPN_TCPOLEN_= MAXSEG)
- = {
- = continue;
- = }
- = mssval =3D opt[2] << 8;
- mssval +=3D opt[3];
- if (mssval > maxmss)
<= span style=3D"color: hsl(0, 100%, 40%);">- {
- dmsg(D_MSS, "= ;MSS: %" PRIu16 " -> %" PRIu16, mssval, maxmss);- accumulate= =3D htons(mssval);
- = opt[2] =3D (uint8_t)((maxmss >> 8) & 0xff);
- opt[3= ] =3D (uint8_t)(maxmss & 0xff);
- accumulate -=3D htons(maxmss);
= - ADJUST_CHECK= SUM(accumulate, tc->check);
- }
+ dmsg(D_MSS, "MSS: %" PRIu16 " -> %= " PRIu16, mssval, maxmss);
+ opt[2] =3D (uint8_t)((maxmss >> 8) & = 0xff);
+ = opt[3] =3D (uint8_t)(maxmss & 0xff);
+ int32_t accumulate =3D htons(mssval= );
+ a= ccumulate -=3D htons(maxmss);
+ ADJUST_CHECKSUM(accumulate, tc->check);=
}
}
}<= /span>
diff --git a/src/openvpn/proto.h b/src/openvpn/proto.h
index 62157fa..94952bd 100644
--- a/src/openvpn= /proto.h
+++ b/src/openvpn/proto.h
@@ -214,= 7 +214,7 @@
*/
#define ADJUST_CHECKSUM(a= cc, cksum) \
{ = \
= - int _acc =3D acc; \
+ int32_t _acc =3D acc; = \
_acc +=3D (cksum); = \
if (_acc < 0) = \
{ = \
@@ -231,16 +231,16 @@
} = \
}

-#define ADD_CHECK= SUM_32(acc, u32) \
- = { \
- acc +=3D (u32) & 0xffff; \
- acc +=3D (u32) >> 16; \=
+#define ADD_CHECKSU= M_32(acc, u32) \
+ { \
+ acc +=3D (int32_t)((u32) & 0xffff)= ; \
+ acc +=3D= (int32_t)((u32) >> 16); \
}
=
-#define SUB_CHECKSUM= _32(acc, u32) \
- { = \
- acc -=3D (u32) & 0xffff; \
- acc -=3D (u32) >> 16; \
+#define SUB_CHECKSUM_32= (acc, u32) \
= + { \
+ acc -=3D (int32_t)((u32) & 0xffff); \<= /span>
+ acc -=3D (in= t32_t)((u32) >> 16); \
}

/*

To view, visit change 1164. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ica721a51b00d5314125bcaf5a58= 6e718c5982aef
Gerrit-Change-Number: 1164
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-MessageType: newchange
--Te3Xboapr/Q=--