From: "flichtenheld (Code Review)" Date: Tue, 9 Dec 2025 11:19:33 +0000 In-Reply-To: References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, gert@...1296... Message-ID: <23c5394d1b622c520c026abe85a6c760080ba051-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="X4/BiEDgyEI="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: tun: Change return type of write_tun/read_tun to ssize_t List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --X4/BiEDgyEI= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, flichtenheld, plaisthos. Hello cron2, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1376?usp=3Demail to look at the new patch set (#10). The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: tun: Change return type of write_tun/read_tun to ssize_t ...................................................................... tun: Change return type of write_tun/read_tun to ssize_t So we can directly give back the actual return type from write/read. Even if we then cast it back to int. The cast should be safe since we also specify an int as we also put an int in as length. Change-Id: I67f5bf53b80f53fd2e349f844479ed172a7b3aa1 Signed-off-by: Frank Lichtenheld --- M src/openvpn/forward.c M src/openvpn/tun.c M src/openvpn/tun.h 3 files changed, 28 insertions(+), 56 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/76/1376/10 diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 6f1bc0c..913fb92 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -1292,11 +1292,6 @@ #endif /* if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARG= ET_FREEBSD)) */ } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - /* * Output: c->c2.buf */ @@ -1323,11 +1318,11 @@ if (c->c1.tuntap->backend_driver =3D=3D DRIVER_AFUNIX) { c->c2.buf.len =3D - read_tun_afunix(c->c1.tuntap, BPTR(&c->c2.buf), c->c2.frame.bu= f.payload_size); + (int)read_tun_afunix(c->c1.tuntap, BPTR(&c->c2.buf), c->c2.fra= me.buf.payload_size); } else { - c->c2.buf.len =3D read_tun(c->c1.tuntap, BPTR(&c->c2.buf), c->c2.f= rame.buf.payload_size); + c->c2.buf.len =3D (int)read_tun(c->c1.tuntap, BPTR(&c->c2.buf), c-= >c2.frame.buf.payload_size); } #endif /* ifdef _WIN32 */ @@ -1357,6 +1352,11 @@ check_status(c->c2.buf.len, "read from TUN/TAP", NULL, c->c1.tuntap); } +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + /** * Drops UDP packets which OS decided to route via tun. * diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index b4e3cb4..0299285 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -1706,8 +1706,8 @@ #include #include -static inline int -header_modify_read_write_return(int len) +static inline ssize_t +header_modify_read_write_return(ssize_t len) { if (len > 0) { @@ -1719,12 +1719,7 @@ } } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - -static int +static ssize_t write_tun_header(struct tuntap *tt, uint8_t *buf, int len) { if (tt->type =3D=3D DEV_TYPE_TUN) @@ -1755,7 +1750,7 @@ } } -static int +static ssize_t read_tun_header(struct tuntap *tt, uint8_t *buf, int len) { if (tt->type =3D=3D DEV_TYPE_TUN) @@ -1776,30 +1771,25 @@ } } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - /* For MacOS this extra handling is conditional on the UTUN driver. * So it needs its own read_tun()/write_tun() with the necessary * checks. They are located in the macOS-specific section below. */ #if !defined(TARGET_DARWIN) -int +ssize_t write_tun(struct tuntap *tt, uint8_t *buf, int len) { return write_tun_header(tt, buf, len); } -int +ssize_t read_tun(struct tuntap *tt, uint8_t *buf, int len) { return read_tun_header(tt, buf, len); } #endif - -#endif /* defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) || defined(= TARGET_NETBSD) || if defined (TARGET_OPENBSD) || defined(TARGET_DARWIN) */ +#endif /* if defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) || defin= ed(TARGET_NETBSD) || defined (TARGET_OPENBSD) || defined(TARGET_DARWIN) */ bool tun_name_is_fixed(const char *dev) @@ -2056,13 +2046,13 @@ free(tt); } -int +ssize_t write_tun(struct tuntap *tt, uint8_t *buf, int len) { return write(tt->fd, buf, len); } -int +ssize_t read_tun(struct tuntap *tt, uint8_t *buf, int len) { return read(tt->fd, buf, len); @@ -2261,27 +2251,18 @@ free(tt); } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - -int +ssize_t write_tun(struct tuntap *tt, uint8_t *buf, int len) { return write(tt->fd, buf, len); } -int +ssize_t read_tun(struct tuntap *tt, uint8_t *buf, int len) { return read(tt->fd, buf, len); } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - #elif defined(TARGET_SOLARIS) #ifndef TUNNEWPPA @@ -2606,7 +2587,7 @@ argv_free(&argv); } -int +ssize_t write_tun(struct tuntap *tt, uint8_t *buf, int len) { struct strbuf sbuf; @@ -2615,7 +2596,7 @@ return putmsg(tt->fd, NULL, &sbuf, 0) >=3D 0 ? sbuf.len : -1; } -int +ssize_t read_tun(struct tuntap *tt, uint8_t *buf, int len) { struct strbuf sbuf; @@ -3090,11 +3071,6 @@ } } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - void close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) { @@ -3118,7 +3094,7 @@ gc_free(&gc); } -int +ssize_t write_tun(struct tuntap *tt, uint8_t *buf, int len) { if (tt->backend_driver =3D=3D DRIVER_UTUN) @@ -3131,7 +3107,7 @@ } } -int +ssize_t read_tun(struct tuntap *tt, uint8_t *buf, int len) { if (tt->backend_driver =3D=3D DRIVER_UTUN) @@ -3144,10 +3120,6 @@ } } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - #elif defined(TARGET_AIX) void @@ -3270,13 +3242,13 @@ argv_free(&argv); } -int +ssize_t write_tun(struct tuntap *tt, uint8_t *buf, int len) { return write(tt->fd, buf, len); } -int +ssize_t read_tun(struct tuntap *tt, uint8_t *buf, int len) { return read(tt->fd, buf, len); @@ -6322,13 +6294,13 @@ free(tt); } -int +ssize_t write_tun(struct tuntap *tt, uint8_t *buf, int len) { return write(tt->fd, buf, len); } -int +ssize_t read_tun(struct tuntap *tt, uint8_t *buf, int len) { return read(tt->fd, buf, len); diff --git a/src/openvpn/tun.h b/src/openvpn/tun.h index 876f147..8bc876e 100644 --- a/src/openvpn/tun.h +++ b/src/openvpn/tun.h @@ -274,9 +274,9 @@ void close_tun_handle(struct tuntap *tt); -int write_tun(struct tuntap *tt, uint8_t *buf, int len); +ssize_t write_tun(struct tuntap *tt, uint8_t *buf, int len); -int read_tun(struct tuntap *tt, uint8_t *buf, int len); +ssize_t read_tun(struct tuntap *tt, uint8_t *buf, int len); #ifdef ENABLE_FEATURE_TUN_PERSIST void tuncfg(const char *dev, const char *dev_type, const char *dev_node, i= nt persist_mode, -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1376?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I67f5bf53b80f53fd2e349f844479ed172a7b3aa1 Gerrit-Change-Number: 1376 Gerrit-PatchSet: 10 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-Attention: flichtenheld --X4/BiEDgyEI= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: cron2, flichtenheld, plaisthos.

flichtenheld uploaded patch set #10 to this change.

=

View = Change

The following approvals got outdated and were removed: Code-Review+2 by cron2

tun: Change return type of write_tu=
n/read_tun to ssize_t

So we can directly give back the actual return=
type from write/read. Even if we then cast it
back to int. The cast = should be safe since we
also specify an int as we also put an int in
= as length.

Change-Id: I67f5bf53b80f53fd2e349f844479ed172a7b3aa1
S= igned-off-by: Frank Lichtenheld <frank@...2641...>
---
M src/op= envpn/forward.c
M src/openvpn/tun.c
M src/openvpn/tun.h
3 files ch= anged, 28 insertions(+), 56 deletions(-)

git pul=
l ssh://gerrit.openvpn.net:29418/openvpn refs/changes/76/1376/10
di=
ff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
in= dex 6f1bc0c..913fb92 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -1292,11 +1292,= 6 @@
#endif /* if defined(ENABLE_DCO) && (defined(= TARGET_LINUX) || defined(TARGET_FREEBSD)) */
}
<= span>

-#if defined(__G= NUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"=
-#endif
-
/*
* Ou= tput: c->c2.buf
*/
@@ -1323,11 +1318,1= 1 @@
if (c->c1.tuntap->backend_driver =3D=3D DRI= VER_AFUNIX)
{
c->c2.buf.le= n =3D
- read= _tun_afunix(c->c1.tuntap, BPTR(&c->c2.buf), c->c2.frame.buf.pa= yload_size);
+ = (int)read_tun_afunix(c->c1.tuntap, BPTR(&c->c2.buf), c->c= 2.frame.buf.payload_size);
}
else=
{
- c->c2.buf.len =3D read_tun(c->c1.tuntap, BPTR(&c->c2= .buf), c->c2.frame.buf.payload_size);
+ c->c2.buf.len =3D (int)read_tun(c->c1.tu= ntap, BPTR(&c->c2.buf), c->c2.frame.buf.payload_size);
= }
#endif /* ifdef _WIN32 */

@@ -1357,6 +1352,11 @@
check_status(c-&= gt;c2.buf.len, "read from TUN/TAP", NULL, c->c1.tuntap);
}

+#if defined(__GNUC__) || defined(__clang__)
+#pragma GCC diagnostic push
<= span style=3D"color: hsl(120, 100%, 40%);">+#pragma GCC diagnostic ignored = "-Wconversion"

+#endif
+<= br> /**
* Drops UDP packets which OS decided to rou= te via tun.
*
diff --git a/src/openvpn/tu= n.c b/src/openvpn/tun.c
index b4e3cb4..0299285 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c<= /span>
@@ -1706,8 +1706,8 @@
#include <netinet= /ip.h>
#include <sys/uio.h>

-static inline int<= br>-header_modify_read_write_retu= rn(int len)
+static i= nline ssize_t
+header= _modify_read_write_return(ssize_t len)
{
= if (len > 0)
{
@@ -1719,12 +171= 9,7 @@
}
}
-#if defined(__GNUC__) || defin= ed(__clang__)
-#pragma = GCC diagnostic push
-#p= ragma GCC diagnostic ignored "-Wconversion"
-#endif
-
-stat= ic int
+static ssize_= t
write_tun_header(struct tuntap *tt, uint8_t *buf, int le= n)
{
if (tt->type =3D=3D DEV_TYPE_= TUN)
@@ -1755,7 +1750,7 @@
} }

-static int
+sta= tic ssize_t
read_tun_header(struct tuntap *tt, uint8_t *bu= f, int len)
{
if (tt->type =3D=3D = DEV_TYPE_TUN)
@@ -1776,30 +1771,25 @@
= }
}

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
/* For MacOS this extra hand= ling is conditional on the UTUN driver.
* So it needs its= own read_tun()/write_tun() with the necessary
* checks. = They are located in the macOS-specific section below.
*/<= /span>
#if !defined(TARGET_DARWIN)
-int
+ssize_t
write_tun(struct tuntap *tt, uint8_t *buf, = int len)
{
return write_tun_header(tt= , buf, len);
}

-int
+ssize_t
read_tun(struct tuntap *tt, uint8_t *b= uf, int len)
{
return read_tun_header= (tt, buf, len);
}
#endif
=
-
-#endif /* defined(TARGET_FREEBSD) || defi= ned(TARGET_DRAGONFLY) || defined(TARGET_NETBSD) || if defined (TARGET_OPENB= SD) || defined(TARGET_DARWIN) */
+#endif /* if defined(TARGET_FREEBSD) || defined(TARGET_DRAGONF= LY) || defined(TARGET_NETBSD) || defined (TARGET_OPENBSD) || defined(TARGET= _DARWIN) */

bool
tun_na= me_is_fixed(const char *dev)
@@ -2056,13 +2046,13 @@=
free(tt);
}

-int

+ssize_t
write_tun(struct tuntap *t= t, uint8_t *buf, int len)
{
return wr= ite(tt->fd, buf, len);
}

-int

+ssize_t
read_tun(struct tuntap *t= t, uint8_t *buf, int len)
{
return re= ad(tt->fd, buf, len);
@@ -2261,27 +2251,18 @@
= free(tt);
}

-#if defined(__GNUC__) || defined(__clan= g__)
-#pragma GCC diagn= ostic push
-#pragma GCC= diagnostic ignored "-Wconversion"
-#endif
-
-int+ssize_t
writ= e_tun(struct tuntap *tt, uint8_t *buf, int len)
{ return write(tt->fd, buf, len);
}
-int+ssize_t
rea= d_tun(struct tuntap *tt, uint8_t *buf, int len)
{ return read(tt->fd, buf, len);
}
-#if defined(_= _GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-<= /span>
#elif defined(TARGET_SOLARIS)

= #ifndef TUNNEWPPA
@@ -2606,7 +2587,7 @@
argv_free(&argv);

}
<= br>-int
+ssize_t
write_tun(struct tun= tap *tt, uint8_t *buf, int len)
{
str= uct strbuf sbuf;
@@ -2615,7 +2596,7 @@
= return putmsg(tt->fd, NULL, &sbuf, 0) >=3D 0 ? sbuf.len : -1;
}

-int
+ssi= ze_t
read_tun(struct tuntap *tt, uint8_t *buf, int len)
{
struct strbuf sbuf;
@= @ -3090,11 +3071,6 @@
}
}
<= span>

-#if defined(__G= NUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"=
-#endif
-
void
clo= se_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
{=
@@ -3118,7 +3094,7 @@
gc_free(&gc);
}

-int
+ssize= _t
write_tun(struct tuntap *tt, uint8_t *buf, int len)
{
if (tt->backend_driver =3D=3D DRIVE= R_UTUN)
@@ -3131,7 +3107,7 @@
}=
}

-int
+ssize_t=
read_tun(struct tuntap *tt, uint8_t *buf, int len)=
{
if (tt->backend_driver =3D=3D DRIVER_U= TUN)
@@ -3144,10 +3120,6 @@
} }

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
#elif defined(TARGET_AIX)

void
@@ -3270,13 +3242,13 @@<= br> argv_free(&argv);
}

-int
+ssize_t
write_tun(struc= t tuntap *tt, uint8_t *buf, int len)
{
= return write(tt->fd, buf, len);
}

-int
+ssize_t
read_tun(struc= t tuntap *tt, uint8_t *buf, int len)
{
= return read(tt->fd, buf, len);
@@ -6322,13 +6294,13 @@=
free(tt);
}
=
-int
+ssize_t
write_tun(struct tu= ntap *tt, uint8_t *buf, int len)
{
re= turn write(tt->fd, buf, len);
}

-int
+ssize_t
read_tun(struct = tuntap *tt, uint8_t *buf, int len)
{
= return read(tt->fd, buf, len);
diff --git a/src/openvpn/= tun.h b/src/openvpn/tun.h
index 876f147..8bc876e 100644
--- a/src/openvpn/tun.h
+++ b/src/openvpn/tun.= h
@@ -274,9 +274,9 @@

vo= id close_tun_handle(struct tuntap *tt);

-int write_tun(struct tuntap *tt, uint8_= t *buf, int len);
+ss= ize_t write_tun(struct tuntap *tt, uint8_t *buf, int len);
=
-int read_tun(struct = tuntap *tt, uint8_t *buf, int len);
+ssize_t read_tun(struct tuntap *tt, uint8_t *buf, int len);=

#ifdef ENABLE_FEATURE_TUN_PERSIST
void tuncfg(const char *dev, const char *dev_type, const char *= dev_node, int persist_mode,

To view, vi= sit chan= ge 1376. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I67f5bf53b80f53fd2e349f84447= 9ed172a7b3aa1
Gerrit-Change-Number: 1376
Gerrit-PatchSet: 10
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
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-Attention: cron2 <gert@...1296...>= ;
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
= --X4/BiEDgyEI=--