Skip to content

Commit c97aa55

Browse files
flichtenheldcron2
authored andcommitted
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 <[email protected]> Acked-by: Gert Doering <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1376 Message-Id: <[email protected]> URL: https://www.mail-archive.com/[email protected]/msg34961.html Signed-off-by: Gert Doering <[email protected]>
1 parent 6c7489e commit c97aa55

File tree

3 files changed

+28
-56
lines changed

3 files changed

+28
-56
lines changed

src/openvpn/forward.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,11 +1292,6 @@ process_incoming_dco(dco_context_t *dco)
12921292
#endif /* if defined(ENABLE_DCO) && (defined(TARGET_LINUX) || defined(TARGET_FREEBSD)) */
12931293
}
12941294

1295-
#if defined(__GNUC__) || defined(__clang__)
1296-
#pragma GCC diagnostic push
1297-
#pragma GCC diagnostic ignored "-Wconversion"
1298-
#endif
1299-
13001295
/*
13011296
* Output: c->c2.buf
13021297
*/
@@ -1323,11 +1318,11 @@ read_incoming_tun(struct context *c)
13231318
if (c->c1.tuntap->backend_driver == DRIVER_AFUNIX)
13241319
{
13251320
c->c2.buf.len =
1326-
read_tun_afunix(c->c1.tuntap, BPTR(&c->c2.buf), c->c2.frame.buf.payload_size);
1321+
(int)read_tun_afunix(c->c1.tuntap, BPTR(&c->c2.buf), c->c2.frame.buf.payload_size);
13271322
}
13281323
else
13291324
{
1330-
c->c2.buf.len = read_tun(c->c1.tuntap, BPTR(&c->c2.buf), c->c2.frame.buf.payload_size);
1325+
c->c2.buf.len = (int)read_tun(c->c1.tuntap, BPTR(&c->c2.buf), c->c2.frame.buf.payload_size);
13311326
}
13321327
#endif /* ifdef _WIN32 */
13331328

@@ -1357,6 +1352,11 @@ read_incoming_tun(struct context *c)
13571352
check_status(c->c2.buf.len, "read from TUN/TAP", NULL, c->c1.tuntap);
13581353
}
13591354

1355+
#if defined(__GNUC__) || defined(__clang__)
1356+
#pragma GCC diagnostic push
1357+
#pragma GCC diagnostic ignored "-Wconversion"
1358+
#endif
1359+
13601360
/**
13611361
* Drops UDP packets which OS decided to route via tun.
13621362
*

src/openvpn/tun.c

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,8 +1706,8 @@ clear_tuntap(struct tuntap *tuntap)
17061706
#include <netinet/ip.h>
17071707
#include <sys/uio.h>
17081708

1709-
static inline int
1710-
header_modify_read_write_return(int len)
1709+
static inline ssize_t
1710+
header_modify_read_write_return(ssize_t len)
17111711
{
17121712
if (len > 0)
17131713
{
@@ -1719,12 +1719,7 @@ header_modify_read_write_return(int len)
17191719
}
17201720
}
17211721

1722-
#if defined(__GNUC__) || defined(__clang__)
1723-
#pragma GCC diagnostic push
1724-
#pragma GCC diagnostic ignored "-Wconversion"
1725-
#endif
1726-
1727-
static int
1722+
static ssize_t
17281723
write_tun_header(struct tuntap *tt, uint8_t *buf, int len)
17291724
{
17301725
if (tt->type == DEV_TYPE_TUN)
@@ -1755,7 +1750,7 @@ write_tun_header(struct tuntap *tt, uint8_t *buf, int len)
17551750
}
17561751
}
17571752

1758-
static int
1753+
static ssize_t
17591754
read_tun_header(struct tuntap *tt, uint8_t *buf, int len)
17601755
{
17611756
if (tt->type == DEV_TYPE_TUN)
@@ -1776,30 +1771,25 @@ read_tun_header(struct tuntap *tt, uint8_t *buf, int len)
17761771
}
17771772
}
17781773

1779-
#if defined(__GNUC__) || defined(__clang__)
1780-
#pragma GCC diagnostic pop
1781-
#endif
1782-
17831774
/* For MacOS this extra handling is conditional on the UTUN driver.
17841775
* So it needs its own read_tun()/write_tun() with the necessary
17851776
* checks. They are located in the macOS-specific section below.
17861777
*/
17871778
#if !defined(TARGET_DARWIN)
1788-
int
1779+
ssize_t
17891780
write_tun(struct tuntap *tt, uint8_t *buf, int len)
17901781
{
17911782
return write_tun_header(tt, buf, len);
17921783
}
17931784

1794-
int
1785+
ssize_t
17951786
read_tun(struct tuntap *tt, uint8_t *buf, int len)
17961787
{
17971788
return read_tun_header(tt, buf, len);
17981789
}
17991790
#endif
18001791

1801-
1802-
#endif /* defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) || defined(TARGET_NETBSD) || if defined (TARGET_OPENBSD) || defined(TARGET_DARWIN) */
1792+
#endif /* if defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) || defined(TARGET_NETBSD) || defined (TARGET_OPENBSD) || defined(TARGET_DARWIN) */
18031793

18041794
bool
18051795
tun_name_is_fixed(const char *dev)
@@ -2056,13 +2046,13 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
20562046
free(tt);
20572047
}
20582048

2059-
int
2049+
ssize_t
20602050
write_tun(struct tuntap *tt, uint8_t *buf, int len)
20612051
{
20622052
return write(tt->fd, buf, len);
20632053
}
20642054

2065-
int
2055+
ssize_t
20662056
read_tun(struct tuntap *tt, uint8_t *buf, int len)
20672057
{
20682058
return read(tt->fd, buf, len);
@@ -2261,27 +2251,18 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
22612251
free(tt);
22622252
}
22632253

2264-
#if defined(__GNUC__) || defined(__clang__)
2265-
#pragma GCC diagnostic push
2266-
#pragma GCC diagnostic ignored "-Wconversion"
2267-
#endif
2268-
2269-
int
2254+
ssize_t
22702255
write_tun(struct tuntap *tt, uint8_t *buf, int len)
22712256
{
22722257
return write(tt->fd, buf, len);
22732258
}
22742259

2275-
int
2260+
ssize_t
22762261
read_tun(struct tuntap *tt, uint8_t *buf, int len)
22772262
{
22782263
return read(tt->fd, buf, len);
22792264
}
22802265

2281-
#if defined(__GNUC__) || defined(__clang__)
2282-
#pragma GCC diagnostic pop
2283-
#endif
2284-
22852266
#elif defined(TARGET_SOLARIS)
22862267

22872268
#ifndef TUNNEWPPA
@@ -2606,7 +2587,7 @@ solaris_error_close(struct tuntap *tt, const struct env_set *es, const char *act
26062587
argv_free(&argv);
26072588
}
26082589

2609-
int
2590+
ssize_t
26102591
write_tun(struct tuntap *tt, uint8_t *buf, int len)
26112592
{
26122593
struct strbuf sbuf;
@@ -2615,7 +2596,7 @@ write_tun(struct tuntap *tt, uint8_t *buf, int len)
26152596
return putmsg(tt->fd, NULL, &sbuf, 0) >= 0 ? sbuf.len : -1;
26162597
}
26172598

2618-
int
2599+
ssize_t
26192600
read_tun(struct tuntap *tt, uint8_t *buf, int len)
26202601
{
26212602
struct strbuf sbuf;
@@ -3090,11 +3071,6 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
30903071
}
30913072
}
30923073

3093-
#if defined(__GNUC__) || defined(__clang__)
3094-
#pragma GCC diagnostic push
3095-
#pragma GCC diagnostic ignored "-Wconversion"
3096-
#endif
3097-
30983074
void
30993075
close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
31003076
{
@@ -3118,7 +3094,7 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
31183094
gc_free(&gc);
31193095
}
31203096

3121-
int
3097+
ssize_t
31223098
write_tun(struct tuntap *tt, uint8_t *buf, int len)
31233099
{
31243100
if (tt->backend_driver == DRIVER_UTUN)
@@ -3131,7 +3107,7 @@ write_tun(struct tuntap *tt, uint8_t *buf, int len)
31313107
}
31323108
}
31333109

3134-
int
3110+
ssize_t
31353111
read_tun(struct tuntap *tt, uint8_t *buf, int len)
31363112
{
31373113
if (tt->backend_driver == DRIVER_UTUN)
@@ -3144,10 +3120,6 @@ read_tun(struct tuntap *tt, uint8_t *buf, int len)
31443120
}
31453121
}
31463122

3147-
#if defined(__GNUC__) || defined(__clang__)
3148-
#pragma GCC diagnostic pop
3149-
#endif
3150-
31513123
#elif defined(TARGET_AIX)
31523124

31533125
void
@@ -3270,13 +3242,13 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
32703242
argv_free(&argv);
32713243
}
32723244

3273-
int
3245+
ssize_t
32743246
write_tun(struct tuntap *tt, uint8_t *buf, int len)
32753247
{
32763248
return write(tt->fd, buf, len);
32773249
}
32783250

3279-
int
3251+
ssize_t
32803252
read_tun(struct tuntap *tt, uint8_t *buf, int len)
32813253
{
32823254
return read(tt->fd, buf, len);
@@ -6322,13 +6294,13 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
63226294
free(tt);
63236295
}
63246296

6325-
int
6297+
ssize_t
63266298
write_tun(struct tuntap *tt, uint8_t *buf, int len)
63276299
{
63286300
return write(tt->fd, buf, len);
63296301
}
63306302

6331-
int
6303+
ssize_t
63326304
read_tun(struct tuntap *tt, uint8_t *buf, int len)
63336305
{
63346306
return read(tt->fd, buf, len);

src/openvpn/tun.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ void tun_open_device(struct tuntap *tt, const char *dev_node, const char **devic
274274

275275
void close_tun_handle(struct tuntap *tt);
276276

277-
int write_tun(struct tuntap *tt, uint8_t *buf, int len);
277+
ssize_t write_tun(struct tuntap *tt, uint8_t *buf, int len);
278278

279-
int read_tun(struct tuntap *tt, uint8_t *buf, int len);
279+
ssize_t read_tun(struct tuntap *tt, uint8_t *buf, int len);
280280

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

0 commit comments

Comments
 (0)