From: "its_Giaan (Code Review)"
Date: Fri, 11 Oct 2024 14:07:43 +0000
In-Reply-To:
References:
Reply-To: gianmarco@...2726..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net, frank@...2641..., a@...2181...
Message-ID: <288ef5df7171cbb6253c593b3c9fd204db5a32c1-EmailReplacePatchSet-HTML@...2715...>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="OsvnYWhz+4I="; charset=UTF-8
Subject: [Openvpn-devel] [S] Change in openvpn[master]: io_work: pass
event_arg object to event handler in case of socket event
List-Id:
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
To: plaisthos , flichtenheld
Cc: openvpn-devel
--OsvnYWhz+4I=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is currently required from: its_Giaan, plaisthos.
Hello flichtenheld, ordex, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/760?usp=3Demail
to look at the new patch set (#4).
The change is no longer submittable: checks~ChecksSubmitRule is unsatisfied=
now.
Change subject: io_work: pass event_arg object to event handler in case of =
socket event
......................................................................
io_work: pass event_arg object to event handler in case of socket event
In order to allow the code to work with multiple listening sockets
it is essential to allow the generic multi_io event handler
to distinguish between the various socket objects.
This can be achieved by passing an event_arg object that contains
a pointer to the link_socket.
This code path is used on clients as well as UDP servers.
Change-Id: I7ebf0d4fb2a23278e16003b2e35598178155d658
Signed-off-by: Antonio Quartulli
---
M src/openvpn/event.h
M src/openvpn/forward.c
M src/openvpn/mtcp.c
3 files changed, 30 insertions(+), 5 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/60/760/4
diff --git a/src/openvpn/event.h b/src/openvpn/event.h
index b3ba183..c212e07 100644
--- a/src/openvpn/event.h
+++ b/src/openvpn/event.h
@@ -82,6 +82,12 @@
#define EVENT_METHOD_US_TIMEOUT (1<<0)
#define EVENT_METHOD_FAST (1<<1)
+/*
+ * The following constant is used as boundary between integer value
+ * and real addresses when passing arguments to event handlers as (void *)
+ */
+#define MULTI_N ((void *)16) /* upper bound on MTCP_x */
+
#ifdef _WIN32
typedef const struct rw_handle *event_t;
diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
index 66e5be1..d50b24c 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -2183,7 +2183,8 @@
/*
* Configure event wait based on socket, tuntap flags.
*/
- socket_set(c->c2.link_socket, c->c2.event_set, socket, (void *)socket_=
shift, NULL);
+ socket_set(c->c2.link_socket, c->c2.event_set, socket,
+ &c->c2.link_socket->ev_arg, NULL);
tun_set(c->c1.tuntap, c->c2.event_set, tuntap, (void *)tun_shift, NULL=
);
#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
if (socket & EVENT_READ && c->c2.did_open_tun)
@@ -2246,7 +2247,27 @@
for (i =3D 0; i < status; ++i)
{
const struct event_set_return *e =3D &esr[i];
- c->c2.event_set_status |=3D ((e->rwflags & 3) << (uint=
ptr_t)e->arg);
+ uintptr_t shift;
+
+ if (e->arg >=3D MULTI_N)
+ {
+ struct event_arg *ev_arg =3D (struct event_arg *)e=
->arg;
+ if (ev_arg->type !=3D EVENT_ARG_LINK_SOCKET)
+ {
+ c->c2.event_set_status =3D ES_ERROR;
+ msg(D_LINK_ERRORS,
+ "io_work: non socket event delivered");
+ return;
+ }
+
+ shift =3D socket_shift;
+ }
+ else
+ {
+ shift =3D (uintptr_t)e->arg;
+ }
+
+ c->c2.event_set_status |=3D ((e->rwflags & 3) << shift=
);
}
}
else if (status =3D=3D 0)
diff --git a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c
index 1b956f4..e89ddba 100644
--- a/src/openvpn/mtcp.c
+++ b/src/openvpn/mtcp.c
@@ -60,8 +60,6 @@
#define MTCP_FILE_CLOSE_WRITE ((void *)5)
#define MTCP_DCO ((void *)6)
-#define MTCP_N ((void *)16) /* upper bound on MTCP_x */
-
struct ta_iow_flags
{
unsigned int flags;
@@ -693,7 +691,7 @@
struct event_set_return *e =3D &mtcp->esr[i];
/* incoming data for instance or listening socket? */
- if (e->arg >=3D MTCP_N)
+ if (e->arg >=3D MULTI_N)
{
struct event_arg *ev_arg =3D (struct event_arg *)e->arg;
switch (ev_arg->type)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/760?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: I7ebf0d4fb2a23278e16003b2e35598178155d658
Gerrit-Change-Number: 760
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan
Gerrit-Reviewer: flichtenheld
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-CC: ordex
Gerrit-Attention: plaisthos
Gerrit-Attention: its_Giaan
Gerrit-MessageType: newpatchset
--OsvnYWhz+4I=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is currently required from: its_Giaan, plaisthos.
its_Giaan uploaded patch set #4 to this change.
<=
a href=3D"http://gerrit.openvpn.net/c/openvpn/+/760?usp=3Demail">View Chang=
e
The change is no longer submittable: checks~ChecksSubmitRule is=
unsatisfied now.
io_work: pass event_arg object to event handler in case o=
f socket event
In order to allow the code to work with multiple list=
ening sockets
it is essential to allow the generic multi_io event handle=
r
to distinguish between the various socket objects.
This can be =
achieved by passing an event_arg object that contains
a pointer to the l=
ink_socket.
This code path is used on clients as well as UDP servers=
.
Change-Id: I7ebf0d4fb2a23278e16003b2e35598178155d658
Signed-off=
-by: Antonio Quartulli <a@...2181...>
---
M src/openvpn/event.h=
M src/openvpn/forward.c
M src/openvpn/mtcp.c
3 files changed, 30 =
insertions(+), 5 deletions(-)
git pull ssh://gerrit.openvpn.net:2=
9418/openvpn refs/changes/60/760/4
diff --git a/src/openvpn/event.h=
b/src/openvpn/event.h
index b3ba183..c212e07 100644=
--- a/src/openvpn/event.h
+++ b/src/openvpn/event=
.h
@@ -82,6 +82,12 @@
#define EVENT_METHOD=
_US_TIMEOUT (1<<0)
#define EVENT_METHOD_FAST =
(1<<1)
+/*
+ * =
The following constant is used as boundary between integer value
=
+ * and real addresses when pas=
sing arguments to event handlers as (void *)
+ */
+#define MULTI_N ((void *)16) /* upper bound on MTCP_x */=
+
#=
ifdef _WIN32
typedef const struct rw_han=
dle *event_t;
diff --git a/src/openvpn/forward.c b/src/open=
vpn/forward.c
index 66e5be1..d50b24c 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -2183,7 +2183,8 @@
/*
* Configure event wait based on socket, tuntap flags.
*/
- socket_=
set(c->c2.link_socket, c->c2.event_set, socket, (void *)socket_shift,=
NULL);
+ socket_s=
et(c->c2.link_socket, c->c2.event_set, socket,
+ &c->c2.link_socket-=
>ev_arg, NULL);
tun_set(c->c1.tuntap, c->c2.e=
vent_set, tuntap, (void *)tun_shift, NULL);
#if defined(TA=
RGET_LINUX) || defined(TARGET_FREEBSD)
if (socket &=
; EVENT_READ && c->c2.did_open_tun)
@@ -2246,7 +=
2247,27 @@
for (i =3D 0; i < status; ++=
i)
{
=
const struct event_set_return *e =3D &esr[i];
- c->c2.event_set_status |=
=3D ((e->rwflags & 3) << (uintptr_t)e->arg);
+ uintptr_t shif=
t;
+
+ if (e->arg &g=
t;=3D MULTI_N)
+ =
{
+ =
struct event_arg *ev_arg =3D (struct event_arg *)e->=
;arg;
+ =
if (ev_arg->type !=3D EVENT_ARG_LINK_SOCKET)
+ {
<=
span style=3D"color: hsl(120, 100%, 40%);">+ c-&=
gt;c2.event_set_status =3D ES_ERROR;
+ msg(D_LINK_ERRORS,
<=
span style=3D"color: hsl(120, 100%, 40%);">+ =
"io_work: non socket event delivered");
+ return;+ }
+
+ shift =3D socket_=
shift;
+ =
}
+ =
else
+ =
{
+ =
shift =3D (uintptr_t)e->arg;
+ }
+
+ c->c2.event_set_status |=3D ((e->=
;rwflags & 3) << shift);
}
}
else if (status =3D=
=3D 0)
diff --git a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c=
index 1b956f4..e89ddba 100644
--- a/src/op=
envpn/mtcp.c
+++ b/src/openvpn/mtcp.c
@@ -6=
0,8 +60,6 @@
#define MTCP_FILE_CLOSE_WRITE ((void *)5)
#define MTCP_DCO ((void *)6)
<=
br>-#define MTCP_N ((vo=
id *)16) /* upper bound on MTCP_x */
-
struct ta_iow_flags
{
unsigned int flags;
@@ -693,7 +691,7 @@=
span>
struct event_set_return *e =3D &mtcp->esr[i]=
;
/* incoming data for instance =
or listening socket? */
- if (e->arg >=3D MTCP_N)
+ if (e->arg >=3D MULTI_N)
=
{
struct event_arg *ev_arg =3D (struc=
t event_arg *)e->arg;
switch (ev_arg->ty=
pe)
To view, visit change 760. To unsubscrib=
e, or for help writing mail filters, visit settings.
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7ebf0d4fb2a23278e16003b2e35=
598178155d658
Gerrit-Change-Number: 760
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <gianmarco@...2786...=
..>
Gerrit-Reviewer: flichtenheld <frank@...2716...=
1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...=
.1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...=
ts.sourceforge.net>
Gerrit-CC: ordex <a@...2181...>
Gerrit-Attention: plaisthos <arne-openvpn@...220...=
..1227...>
Gerrit-Attention: its_Giaan <gianmarco@...1665...=
726...>
Gerrit-MessageType: newpatchset
--OsvnYWhz+4I=--