From: "cron2 (Code Review)" Date: Wed, 25 Sep 2024 07:06:33 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="lcINSyMK47k="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Ensure that the AF_UNIX socket pair has at least 65k of buffer space List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: flichtenheld , openvpn-devel --lcINSyMK47k= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/75= 4?usp=3Demail ) Change subject: Ensure that the AF_UNIX socket pair has at least 65k of buf= fer space ...................................................................... Ensure that the AF_UNIX socket pair has at least 65k of buffer space Without this change, pinging a lwipovpn client with something like a 3000 byte payload on macOS often fails as the default buffer sizes on macOS are 2048 for send and 4096 for receive. Change-Id: Ice015df81543c01094479929f0cb3075ca4f3813 Signed-off-by: Arne Schwabe Acked-by: Gert Doering Message-Id: <20240925063016.22532-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg29= 413.html Signed-off-by: Gert Doering --- M src/openvpn/socket.c M src/openvpn/socket.h M src/openvpn/tun_afunix.c 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 6c790a0..7b1e603 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -890,20 +890,23 @@ #endif } -static void -socket_set_buffers(socket_descriptor_t fd, const struct socket_buffer_size= *sbs) +void +socket_set_buffers(socket_descriptor_t fd, const struct socket_buffer_size= *sbs, + bool reduce_size) { if (sbs) { const int sndbuf_old =3D socket_get_sndbuf(fd); const int rcvbuf_old =3D socket_get_rcvbuf(fd); - if (sbs->sndbuf) + if (sbs->sndbuf + && (reduce_size || sndbuf_old < sbs->sndbuf)) { socket_set_sndbuf(fd, sbs->sndbuf); } - if (sbs->rcvbuf) + if (sbs->rcvbuf + && (reduce_size || rcvbuf_old < sbs->rcvbuf)) { socket_set_rcvbuf(fd, sbs->rcvbuf); } @@ -986,7 +989,7 @@ { ls->socket_buffer_sizes.sndbuf =3D sndbuf; ls->socket_buffer_sizes.rcvbuf =3D rcvbuf; - socket_set_buffers(ls->sd, &ls->socket_buffer_sizes); + socket_set_buffers(ls->sd, &ls->socket_buffer_sizes, true); } } @@ -1136,7 +1139,7 @@ sock->info.af =3D addr->ai_family; /* set socket buffers based on --sndbuf and --rcvbuf options */ - socket_set_buffers(sock->sd, &sock->socket_buffer_sizes); + socket_set_buffers(sock->sd, &sock->socket_buffer_sizes, true); /* set socket to --mark packets with given value */ socket_set_mark(sock->sd, sock->mark); diff --git a/src/openvpn/socket.h b/src/openvpn/socket.h index bbdabfb..2e583af 100644 --- a/src/openvpn/socket.h +++ b/src/openvpn/socket.h @@ -157,6 +157,18 @@ int sndbuf; }; +/** + * Sets the receive and send buffer sizes of a socket descriptor. + * + * @param fd The socket to modify + * @param sbs new sizes. + * @param reduce_size apply the new size even if smaller than current one + */ +void +socket_set_buffers(socket_descriptor_t fd, + const struct socket_buffer_size *sbs, + bool reduce_size); + /* * This is the main socket structure used by OpenVPN. The SOCKET_ * defines try to abstract away our implementation differences between diff --git a/src/openvpn/tun_afunix.c b/src/openvpn/tun_afunix.c index f4ce4b7..6b6c159 100644 --- a/src/openvpn/tun_afunix.c +++ b/src/openvpn/tun_afunix.c @@ -35,6 +35,7 @@ #include "wfp_block.h" #include "argv.h" #include "options.h" +#include "socket.h" #ifndef WIN32 /* Windows does implement some AF_UNIX functionality but key features @@ -80,6 +81,13 @@ return; } + + /* Ensure that the buffer sizes are decently sized. Otherwise macOS wi= ll + * just have 2048 */ + struct socket_buffer_size newsizes =3D {65536, 65536 }; + socket_set_buffers(fds[0], &newsizes, false); + socket_set_buffers(fds[1], &newsizes, false); + /* Use the first file descriptor for our side and avoid passing it * to the child */ tt->fd =3D fds[1]; -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/754?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: Ice015df81543c01094479929f0cb3075ca4f3813 Gerrit-Change-Number: 754 Gerrit-PatchSet: 3 Gerrit-Owner: plaisthos Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-MessageType: merged --lcINSyMK47k= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

Ensure that the AF_UNIX socket pair has at lea=
st 65k of buffer space

Without this change, pinging a lwipovpn clien= t with something like a
3000 byte payload on macOS often fails as the de= fault buffer sizes on
macOS are 2048 for send and 4096 for receive.
<= br>Change-Id: Ice015df81543c01094479929f0cb3075ca4f3813
Signed-off-by: A= rne Schwabe <arne@...1227...>
Acked-by: Gert Doering <gert@...1386...= 296...>
Message-Id: <20240925063016.22532-1-gert@...1296...>URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg2= 9413.html
Signed-off-by: Gert Doering <gert@...1296...>
---
= M src/openvpn/socket.c
M src/openvpn/socket.h
M src/openvpn/tun_afuni= x.c
3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c
index 6c790a0..7b1e603 100644
--- a/src/openvpn/socket.c
+++ b/src/openvpn/socket.c
@@ -890,20 +890,2= 3 @@
#endif
}
-static void
-socket_set_buffers(socket_descriptor_t fd= , const struct socket_buffer_size *sbs)
+void
+socket_set_buffers(socket_descriptor_t fd, const struct socket_buffer_= size *sbs,
+ = bool reduce_size)
{
if (sbs= )
{
const int sndbuf_old =3D = socket_get_sndbuf(fd);
const int rcvbuf_old =3D so= cket_get_rcvbuf(fd);

- if (sbs->sndbuf)
+ if (sbs->sndbuf
+ && (reduce_size || sn= dbuf_old < sbs->sndbuf))
{
= socket_set_sndbuf(fd, sbs->sndbuf);
= }

- = if (sbs->rcvbuf)
+ if (sbs->rcvbuf
+ && (reduce_size || rcvbuf_old < sbs-&g= t;rcvbuf))
{
socket_s= et_rcvbuf(fd, sbs->rcvbuf);
}
@= @ -986,7 +989,7 @@
{
ls->s= ocket_buffer_sizes.sndbuf =3D sndbuf;
ls->socke= t_buffer_sizes.rcvbuf =3D rcvbuf;
- socket_set_buffers(ls->sd, &ls->socket_buffer= _sizes);
+ soc= ket_set_buffers(ls->sd, &ls->socket_buffer_sizes, true); }
}

@@ -113= 6,7 +1139,7 @@
sock->info.af =3D addr->ai_family= ;

/* set socket buffers based on --s= ndbuf and --rcvbuf options */
- socket_set_buffers(sock->sd, &sock->socket_buffer_siz= es);
+ socket_set_= buffers(sock->sd, &sock->socket_buffer_sizes, true);

/* set socket to --mark packets with given value= */
socket_set_mark(sock->sd, sock->mark);

diff --git a/src/openvpn/socket.h b/src/openvpn/socket.h<= br>index bbdabfb..2e583af 100644
--- a/src/openvpn/so= cket.h
+++ b/src/openvpn/socket.h
@@ -157,6= +157,18 @@
int sndbuf;
};
=
+/**+ * Sets the receive and send= buffer sizes of a socket descriptor.
+ *
= + * @param fd The socket to modify
+ * @param sbs new sizes.
+ * @param reduce_size apply the = new size even if smaller than current one
+ */
+void
+socket_se= t_buffers(socket_descriptor_t fd,
+ const struct socket_buffer_size *sbs,

+ bool = reduce_size);
+
/*
* This is the main socket structure used b= y OpenVPN. The SOCKET_
* defines try to abstract away ou= r implementation differences between
diff --git a/src/openv= pn/tun_afunix.c b/src/openvpn/tun_afunix.c
index f4ce4b7..6= b6c159 100644
--- a/src/openvpn/tun_afunix.c
+++ b/src/openvpn/tun_afunix.c

@@ -35,6 +35,7 @@ #include "wfp_block.h"
#include "a= rgv.h"
#include "options.h"
+#include "socket.h"

#ifndef WIN32
/* Windows doe= s implement some AF_UNIX functionality but key features
@@ = -80,6 +81,13 @@
return;
}


+
+ /* Ensure that the b= uffer sizes are decently sized. Otherwise macOS will
+ * just have 2048 */
+ struct socket_buffer_size newsiz= es =3D {65536, 65536 };
+ socket_set_buffers(fds[0], &newsizes, false);
+ socket_set_buffers(fds[1], &n= ewsizes, false);
+
/* Use the first file descriptor for our side and avoid = passing it
* to the child */
tt-= >fd =3D fds[1];

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

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ice015df81543c01094479929f0c= b3075ca4f3813
Gerrit-Change-Number: 754
Gerrit-PatchSet: 3
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: merged
--lcINSyMK47k=--