Attention is currently required from: Arne Schwabe.
Hello Arne Schwabe,
I'd like you to do a code review.
Please visit
https://gerrit.openvpn.net/c/openvpn/+/2046?usp=email
to review the following change.
Change subject: multi_io: dispatch UDP events through
TA_SOCKET_READ/TA_SOCKET_WRITE
......................................................................
multi_io: dispatch UDP events through TA_SOCKET_READ/TA_SOCKET_WRITE
UDP socket events were handled by multi_process_io_udp() outside the
multi_io_action() state machine and re-entered it via TA_INITIAL,
running multi_process_post() twice.
Dispatch them as TA_SOCKET_READ, with mi == NULL and the socket passed
explicitly, and TA_SOCKET_WRITE, so that pending output is flushed
within the same event. Drop multi_process_io_udp(); multi_io_send_link()
has no caller left outside multi_io.c and becomes static.
Change-Id: Ia7a31ff1c3792104101cb2e828be3b7fd8f44156
Signed-off-by: Gianmarco De Gregori <[email protected]>
---
M src/openvpn/mudp.c
M src/openvpn/mudp.h
M src/openvpn/multi.c
M src/openvpn/multi_io.c
M src/openvpn/multi_io.h
5 files changed, 42 insertions(+), 70 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/46/2046/1
diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c
index 217b299..70ce458 100644
--- a/src/openvpn/mudp.c
+++ b/src/openvpn/mudp.c
@@ -29,7 +29,6 @@
#include "multi.h"
#include <inttypes.h>
#include "forward.h"
-#include "multi_io.h"
#include "memdbg.h"
#include "ssl_pkt.h"
@@ -462,39 +461,3 @@
ASSERT(!(mi && mi->halt));
return mi;
}
-
-/*
- * Send a packet to UDP socket.
- */
-static inline void
-multi_process_outgoing_link(struct multi_context *m, const unsigned int
mpp_flags)
-{
- if (m->pending)
- {
- multi_io_send_link(m, m->pending, mpp_flags);
- }
-}
-
-/*
- * Process a UDP socket event.
- */
-void
-multi_process_io_udp(struct multi_context *m, struct link_socket *sock,
unsigned int rwflags)
-{
- const unsigned int mpp_flags = (MPP_PRE_SELECT | MPP_CLOSE_ON_SIGNAL);
-
- /* UDP port ready to accept write */
- if (rwflags & SOCKET_WRITE)
- {
- multi_process_outgoing_link(m, mpp_flags);
- }
- /* Incoming data on UDP port */
- else if (rwflags & SOCKET_READ)
- {
- read_incoming_link(&m->top, sock);
- if (!IS_SIG(&m->top))
- {
- multi_process_incoming_link(m, NULL, mpp_flags, sock);
- }
- }
-}
diff --git a/src/openvpn/mudp.h b/src/openvpn/mudp.h
index 6567539..c38d9e5 100644
--- a/src/openvpn/mudp.h
+++ b/src/openvpn/mudp.h
@@ -30,7 +30,6 @@
struct context;
struct multi_context;
-void multi_process_io_udp(struct multi_context *m, struct link_socket *sock,
unsigned int rwflags);
/**************************************************************************/
/**
* Get, and if necessary create, the multi_instance associated with a
diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c
index 2e804ff..cf6a584 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c
@@ -4251,7 +4251,7 @@
}
else if (status == 0)
{
- multi_io_action(multi, NULL, TA_TIMEOUT, false);
+ multi_io_action(multi, NULL, NULL, TA_TIMEOUT, false);
}
MULTI_CHECK_SIG(multi);
diff --git a/src/openvpn/multi_io.c b/src/openvpn/multi_io.c
index fb4810b..d1b7bf4 100644
--- a/src/openvpn/multi_io.c
+++ b/src/openvpn/multi_io.c
@@ -345,7 +345,7 @@
return mi;
}
-bool
+static bool
multi_io_send_link(struct multi_context *m, struct multi_instance *mi, const
unsigned int mpp_flags)
{
bool ret = true;
@@ -423,7 +423,8 @@
}
static struct multi_instance *
-multi_io_dispatch(struct multi_context *m, struct multi_instance *mi, const
int action)
+multi_io_dispatch(struct multi_context *m, struct multi_instance *mi, struct
link_socket *sock,
+ const int action)
{
const unsigned int mpp_flags = MPP_PRE_SELECT | MPP_RECORD_TOUCH;
struct multi_instance *touched = mi;
@@ -445,21 +446,28 @@
case TA_SOCKET_READ:
case TA_SOCKET_READ_RESIDUAL:
- ASSERT(mi);
- ASSERT(mi->context.c2.link_sockets);
- ASSERT(mi->context.c2.link_sockets[0]);
- set_prefix(mi);
- read_incoming_link(&mi->context, mi->context.c2.link_sockets[0]);
- clear_prefix();
- if (!IS_SIG(&mi->context))
+ {
+ struct context *c = multi_get_context(m, mi);
+
+ if (mi)
{
- multi_process_incoming_link(m, mi, mpp_flags,
mi->context.c2.link_sockets[0]);
- if (!IS_SIG(&mi->context))
+ ASSERT(mi->context.c2.link_sockets);
+ sock = mi->context.c2.link_sockets[0];
+ set_prefix(mi);
+ }
+ ASSERT(sock);
+ read_incoming_link(c, sock);
+ clear_prefix();
+ if (!IS_SIG(c))
+ {
+ multi_process_incoming_link(m, mi, mpp_flags, sock);
+ if (!IS_SIG(c))
{
- stream_buf_read_setup(mi->context.c2.link_sockets[0]);
+ stream_buf_read_setup(sock);
}
}
break;
+ }
case TA_TIMEOUT:
multi_process_timeout(m, mpp_flags);
@@ -586,11 +594,11 @@
mi = ev_arg->u.mi;
if (e->rwflags & EVENT_WRITE)
{
- multi_io_action(m, mi, TA_SOCKET_WRITE_READY, false);
+ multi_io_action(m, mi, NULL, TA_SOCKET_WRITE_READY,
false);
}
else if (e->rwflags & EVENT_READ)
{
- multi_io_action(m, mi, TA_SOCKET_READ, false);
+ multi_io_action(m, mi, NULL, TA_SOCKET_READ, false);
}
break;
@@ -605,18 +613,21 @@
{
socket_reset_listen_persistent(ev_arg->u.sock);
mi = multi_create_instance_tcp(m, ev_arg->u.sock);
+ /* monitor and/or handle events that are
+ * triggered in succession by the first one
+ * before returning to the main loop. */
+ if (mi)
+ {
+ multi_io_action(m, mi, NULL, TA_INITIAL, false);
+ }
}
- else
+ else if (e->rwflags & EVENT_WRITE)
{
- multi_process_io_udp(m, ev_arg->u.sock, e->rwflags);
- mi = m->pending;
+ multi_io_action(m, NULL, NULL, TA_SOCKET_WRITE, false);
}
- /* monitor and/or handle events that are
- * triggered in succession by the first one
- * before returning to the main loop. */
- if (mi)
+ else if (e->rwflags & EVENT_READ)
{
- multi_io_action(m, mi, TA_INITIAL, false);
+ multi_io_action(m, NULL, ev_arg->u.sock,
TA_SOCKET_READ, false);
}
break;
}
@@ -636,11 +647,11 @@
{
if (e->rwflags & EVENT_WRITE)
{
- multi_io_action(m, NULL, TA_TUN_WRITE, false);
+ multi_io_action(m, NULL, NULL, TA_TUN_WRITE, false);
}
else if (e->rwflags & EVENT_READ)
{
- multi_io_action(m, NULL, TA_TUN_READ, false);
+ multi_io_action(m, NULL, NULL, TA_TUN_READ, false);
}
}
@@ -677,13 +688,14 @@
struct multi_instance *mi;
while (!IS_SIG(&m->top) && (mi = mbuf_peek(m->mbuf)) != NULL)
{
- multi_io_action(m, mi, TA_SOCKET_WRITE, true);
+ multi_io_action(m, mi, NULL, TA_SOCKET_WRITE, true);
}
}
}
void
-multi_io_action(struct multi_context *m, struct multi_instance *mi, int
action, bool poll)
+multi_io_action(struct multi_context *m, struct multi_instance *mi, struct
link_socket *sock,
+ int action, bool poll)
{
bool tun_input_pending = false;
@@ -716,7 +728,7 @@
/*
* Dispatch the action
*/
- struct multi_instance *touched = multi_io_dispatch(m, mi, action);
+ struct multi_instance *touched = multi_io_dispatch(m, mi, sock,
action);
/*
* Signal received or connection
diff --git a/src/openvpn/multi_io.h b/src/openvpn/multi_io.h
index c7f8f89..7ae25c6 100644
--- a/src/openvpn/multi_io.h
+++ b/src/openvpn/multi_io.h
@@ -68,11 +68,9 @@
void multi_io_process_io(struct multi_context *m);
-void multi_io_action(struct multi_context *m, struct multi_instance *mi, int
action, bool poll);
+void multi_io_action(struct multi_context *m, struct multi_instance *mi,
struct link_socket *sock,
+ int action, bool poll);
void multi_io_delete_event(struct multi_io *multi_io, event_t event);
-bool multi_io_send_link(struct multi_context *m, struct multi_instance *mi,
- const unsigned int mpp_flags);
-
#endif /* ifndef MULTI_IO_H */
--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2046?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia7a31ff1c3792104101cb2e828be3b7fd8f44156
Gerrit-Change-Number: 2046
Gerrit-PatchSet: 1
Gerrit-Owner: Gianmarco De Gregori <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel