From: "cron2 (Code Review)" Date: Tue, 9 Dec 2025 18:12:06 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <1310b2a94c9b44296c8bbdb22ff58becd3bac006-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="mxI73+5n8bI="; 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: flichtenheld , plaisthos Cc: openvpn-devel --mxI73+5n8bI= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#11) to the change originally created b= y flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1376?usp=3Demail ) 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 Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1376 Message-Id: <20251209153715.15832-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34= 961.html Signed-off-by: Gert Doering --- 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/11 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: 11 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --mxI73+5n8bI= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #11 to the change originally created by flichtenhe= ld.

View Change

The following approvals got outdated and were remov= ed: 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...>
Acked-by: Gert = Doering <gert@...1296...>
Gerrit URL: https://gerrit.openvpn.net/c= /openvpn/+/1376
Message-Id: <20251209153715.15832-1-gert@...1296...&g= t;
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net= /msg34961.html
Signed-off-by: Gert Doering <gert@...1296...>
--= -
M src/openvpn/forward.c
M src/openvpn/tun.c
M src/openvpn/tun.h<= br>3 files changed, 28 insertions(+), 56 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/76/1376/=
11
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
@@ -1= 292,11 +1292,6 @@
#endif /* if defined(ENABLE_DCO) &&a= mp; (defined(TARGET_LINUX) || defined(TARGET_FREEBSD)) */
= }

-#i= f defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion= "
-#endif-
/* * Output: c->c2.buf
*/
@@ -13= 23,11 +1318,11 @@
if (c->c1.tuntap->backend_driv= er =3D=3D DRIVER_AFUNIX)
{
c-= >c2.buf.len =3D
- = read_tun_afunix(c->c1.tuntap, BPTR(&c->c2.buf), c->c2= .frame.buf.payload_size);
+ (int)read_tun_afunix(c->c1.tuntap, BPTR(&c->c2.= buf), c->c2.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_tu= n(c->c1.tuntap, BPTR(&c->c2.buf), c->c2.frame.buf.payload_size= );
}
#endif /* ifdef _WIN32 */=

@@ -1357,6 +1352,11 @@
che= ck_status(c->c2.buf.len, "read from TUN/TAP", NULL, c->c1.t= untap);
}

+#if defined(__GNUC__) || defined(__clang__)=
+#pragma GCC diagnostic pus= h
+#pragma GCC diagno= stic ignored "-Wconversion"
+#endif
+
/**
* Drops UDP packets which OS d= ecided to route via tun.
*
diff --git a/s= rc/openvpn/tun.c b/src/openvpn/tun.c
index b4e3cb4..0299285= 100644
--- a/src/openvpn/tun.c
+++ b/src/o= penvpn/tun.c
@@ -1706,8 +1706,8 @@
#includ= e <netinet/ip.h>
#include <sys/uio.h>
-static inlin= e int
-header_modify_re= ad_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(__GNU= C__) || 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 diagnost= ic 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 wri= te_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<= /span>

-
-#endif /* defined(TARGET_= FREEBSD) || defined(TARGET_DRAGONFLY) || defined(TARGET_NETBSD) || if defin= ed (TARGET_OPENBSD) || defined(TARGET_DARWIN) */
+#endif /* if defined(TARGET_FREEBSD) || define= d(TARGET_DRAGONFLY) || defined(TARGET_NETBSD) || defined (TARGET_OPENBSD) |= | defined(TARGET_DARWIN) */

bool<= br> tun_name_is_fixed(const char *dev)
@@ -2056,13 +2= 046,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

-
+ssize_t
write_tun(struct tuntap *tt, uint8_t *buf, int len)
<= span> {

return write(tt->fd, buf, len);
<= span> }

-int
+ssize_t

read_tun(struct tuntap *tt, uint8_t *buf, int len)
<= span> {
return read(tt->fd, buf, len);
}

-#pragma GCC diagnostic pop
-#endif
-
#elif defined(TARGET_SOLARIS)
=
#ifndef TUNNEWPPA
@@ -2606,7 +2587= ,7 @@
argv_free(&argv);
}<= br>
-int<= br>+ssize_t
wr= ite_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 @@
}
<= span> }

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconv= ersion"
-#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->backen= d_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 diagnosti= c pop
-#endif-
#elif defined= (TARGET_AIX)

void
@@ -32= 70,13 +3242,13 @@
argv_free(&argv);
}


= -int
+ssize_t<= br> 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
<= span> write_tun(struct tuntap *tt, uint8_t *buf, int len)
= {
return write(tt->fd, buf, len);
= }

-in= t
+ssize_t
= read_tun(struct tuntap *tt, uint8_t *buf, int len)
= {
return read(tt->fd, buf, len);
di= ff --git a/src/openvpn/tun.h b/src/openvpn/tun.h
index 876f= 147..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(st= ruct tuntap *tt, uint8_t *buf, int len);
+ssize_t write_tun(struct tuntap *tt, uint8_t *buf, int= len);

+ssize_t read_tun(struct tuntap *tt, = uint8_t *buf, int len);

#ifdef ENABLE_FE= ATURE_TUN_PERSIST
void tuncfg(const char *dev, const char = *dev_type, const char *dev_node, int persist_mode,
<= br>

To view, visit change 1376. To unsubscribe, or for help writing mai= l filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I67f5bf53b80f53fd2e349f84447= 9ed172a7b3aa1
Gerrit-Change-Number: 1376
Gerrit-PatchSet: 11
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>
= --mxI73+5n8bI=--