From: "flichtenheld (Code Review)"
Date: Fri, 28 Nov 2025 16:21:45 +0000
In-Reply-To:
References:
Reply-To: frank@...2641..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net, gert@...1296...
Message-ID:
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="s/XKuTGK+OE="; 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
--s/XKuTGK+OE=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is currently required from: 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 (#9).
The change is no longer submittable: checks~ChecksSubmitRule is unsatisfied=
now.
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/9
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 9c04b6b..d2274e0 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ -1708,8 +1708,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)
{
@@ -1721,12 +1721,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)
@@ -1757,7 +1752,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)
@@ -1778,26 +1773,21 @@
}
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
#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)
@@ -2054,13 +2044,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);
@@ -2259,27 +2249,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
@@ -2604,7 +2585,7 @@
argv_free(&argv);
}
-int
+ssize_t
write_tun(struct tuntap *tt, uint8_t *buf, int len)
{
struct strbuf sbuf;
@@ -2613,7 +2594,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;
@@ -3088,11 +3069,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)
{
@@ -3116,7 +3092,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)
@@ -3129,7 +3105,7 @@
}
}
-int
+ssize_t
read_tun(struct tuntap *tt, uint8_t *buf, int len)
{
if (tt->backend_driver =3D=3D DRIVER_UTUN)
@@ -3142,10 +3118,6 @@
}
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
#elif defined(TARGET_AIX)
void
@@ -3268,13 +3240,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);
@@ -6320,13 +6292,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: 9
Gerrit-Owner: flichtenheld
Gerrit-Reviewer: cron2
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-Attention: plaisthos
Gerrit-Attention: flichtenheld
--s/XKuTGK+OE=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is cur=
rently required from: flichtenheld, plaisthos.
flichtenheld uploaded patch set #9 to this change.
<=
p>View C=
hange
The change is no longer submittable: checks~ChecksSubmitRul=
e is unsatisfied now.
tun: Change return type of write_tun=
/read_tun to ssize_t So we can directly give back the actual return<=
br>type from write/read. Even if we then cast it back to int. The cast s=
hould be safe since we also specify an int as we also put an int in a=
s length. Change-Id: I67f5bf53b80f53fd2e349f844479ed172a7b3aa1 Si=
gned-off-by: Frank Lichtenheld <frank@...2641...> --- M src/ope=
nvpn/forward.c M src/openvpn/tun.c M src/openvpn/tun.h 3 files cha=
nged, 28 insertions(+), 56 deletions(-) git pull=
ssh://gerrit.openvpn.net:29418/openvpn refs/changes/76/1376/9 diff=
--git a/src/openvpn/forward.c b/src/openvpn/forward.c inde=
x 6f1bc0c..913fb92 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -1292,11 +1292,6 =
@@ #endif /* if defined(ENABLE_DCO) && (defined(TA=
RGET_LINUX) || defined(TARGET_FREEBSD)) */ } -#if defined(__GNU=
C__) || 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 */ =
span>@@ -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 9c04b6b..d2274e0 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c<=
/span>@@ -1708,8 +1708,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) { @@ -1721,12 +172=
1,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) @@ -1757,7 +1752,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) @@ -1778,26 +1773,21 @@ =
} } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop-#endif - #if !defined(TARGET_DARWIN)<=
/span>-int +ssize_t write_tun(str=
uct 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 /* d=
efined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) || defined(TARGET_NETBS=
D) || if defined (TARGET_OPENBSD) || defined(TARGET_DARWIN) */ +#endif /* if defined(TARGET_FREE=
BSD) || defined(TARGET_DRAGONFLY) || defined(TARGET_NETBSD) || defined (TAR=
GET_OPENBSD) || defined(TARGET_DARWIN) */ bool tun_name_is_fixed(const char *dev) =
@@ -2054,13 +2044,13 @@ free(tt); }=
span> -int=
span>+ssize_t write_tun(struct tuntap *tt, uint8_t *buf, int len) {<=
/span> return write(tt->fd, buf, len); }<=
/span> -int<=
/span>+ssize_t read_tun(struct tuntap *tt, uint8_t *buf, int len) {<=
/span> return read(tt->fd, buf, len); @@ -=
2259,27 +2249,18 @@ free(tt); } -#if defin=
ed(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion"<=
/span>-#endif - -int =
+ssize_t write_tun(struct tuntap *tt, uint8_t *buf, int le=
n) { return write(tt->fd, buf, len=
); } -int +ssize_t read_tun(struct tuntap *tt, uint8_t *buf, int le=
n) { return read(tt->fd, buf, len)=
; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - #elif defined(TARGET_SOLARIS=
) #ifndef TUNNEWPPA @@ -=
2604,7 +2585,7 @@ argv_free(&argv); } =
-int +ssize_t <=
br> write_tun(struct tuntap *tt, uint8_t *buf, int len) { struct strbuf sbuf; @@ -2613,7 +=
2594,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; @@ -3088,11 +3069,6 @@ }<=
/span> } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push =
-#pragma GCC diagnostic ignored &=
quot;-Wconversion" -#endif - void close_tun(struct tuntap *tt, openvpn_net_ctx_t *=
ctx) { @@ -3116,7 +3092,7 @@ gc_free(&gc); } -int +ssize_t write_tun(struct tuntap *=
tt, uint8_t *buf, int len) { if (tt-&=
gt;backend_driver =3D=3D DRIVER_UTUN) @@ -3129,7 +3105,7 @@=
} } -int+ssize_t read_tun(struct tuntap *tt,=
uint8_t *buf, int len) { if (tt->=
backend_driver =3D=3D DRIVER_UTUN) @@ -3142,10 +3118,6 @@=
span> } } -#if defined(__GNUC__) || defined(__cla=
ng__) -#pragma GCC diag=
nostic pop -#endif - #elif de=
fined(TARGET_AIX) void @=
@ -3268,13 +3240,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=
span> read_tun(struct tuntap *tt, uint8_t *buf, int len) { return read(tt->fd, buf, len); @@ -6320,13 +6292,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.hindex=
876f147..8bc876e 100644 --- a/src/openvpn/tun.h =
+++ b/src/openvpn/tun.h @@ -274,9 +274,9 @@ void close_tun_handle(struct tuntap *tt); <=
br> -int write_t=
un(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); <=
span style=3D"color: hsl(120, 100%, 40%);">+ssize_t read_tun(struct tuntap =
*tt, uint8_t *buf, int len); #ifdef ENAB=
LE_FEATURE_TUN_PERSIST void tuncfg(const char *dev, const =
char *dev_type, const char *dev_node, int persist_mode, To view, visit change 1376 . To unsubscribe, or for help writin=
g mail filters, visit settings .
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I67f5bf53b80f53fd2e349f84447=
9ed172a7b3aa1
Gerrit-Change-Number: 1376
Gerrit-PatchSet: 9
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: flichtenheld <frank@...2375...=
41...>
=
--s/XKuTGK+OE=--