Skip to content

Commit 9b7acf8

Browse files
author
Jon Chiappetta
committed
mtio mode
1 parent 7aa27a7 commit 9b7acf8

File tree

16 files changed

+451
-32
lines changed

16 files changed

+451
-32
lines changed

src/openvpn/forward.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
#include "mstats.h"
4848

4949
#include <sys/select.h>
50+
#include <sys/socket.h>
5051
#include <sys/time.h>
52+
#include <pthread.h>
5153

5254
counter_type link_read_bytes_global; /* GLOBAL */
5355
counter_type link_write_bytes_global; /* GLOBAL */
@@ -2570,3 +2572,67 @@ process_io(struct context *c, struct link_socket *sock)
25702572
}
25712573
}
25722574
}
2575+
2576+
void threaded_read_tun(struct context *c, struct link_socket *sock, struct thread_pointer *b)
2577+
{
2578+
if (b->i != b->p->i)
2579+
{
2580+
if (pthread_mutex_trylock(&(b->p->l)) == 0)
2581+
{
2582+
read_incoming_tun(c);
2583+
b->p->i = ((b->p->i % b->p->n) + 1);
2584+
pthread_mutex_unlock(&(b->p->l));
2585+
if (!IS_SIG(c))
2586+
{
2587+
process_incoming_tun(c, sock);
2588+
}
2589+
}
2590+
}
2591+
}
2592+
2593+
void threaded_io(struct context *c, struct link_socket *sock, struct thread_pointer *b)
2594+
{
2595+
const unsigned int status = c->c2.event_set_status;
2596+
2597+
#ifdef ENABLE_MANAGEMENT
2598+
if (status & (MANAGEMENT_READ | MANAGEMENT_WRITE))
2599+
{
2600+
ASSERT(management);
2601+
management_io(management);
2602+
}
2603+
#endif
2604+
2605+
//msg(M_INFO, "MTIO MODE DEBUG PROC [%d] [%d][%d][%d][%d] [%d] [%d][%d][%p]",status,SOCKET_READ,SOCKET_WRITE,TUN_READ,TUN_WRITE,sock->sd,b->n,b->l,c->c2.buffers);
2606+
2607+
/* TCP/UDP port ready to accept write */
2608+
if (status & SOCKET_WRITE)
2609+
{
2610+
process_outgoing_link(c, sock);
2611+
}
2612+
/* TUN device ready to accept write */
2613+
else if (status & TUN_WRITE)
2614+
{
2615+
process_outgoing_tun(c, sock);
2616+
}
2617+
/* Incoming data on TCP/UDP port */
2618+
else if (status & SOCKET_READ)
2619+
{
2620+
read_incoming_link(c, sock);
2621+
if (!IS_SIG(c))
2622+
{
2623+
process_incoming_link(c, sock);
2624+
}
2625+
}
2626+
/* Incoming data on TUN device */
2627+
else if (status & TUN_READ)
2628+
{
2629+
threaded_read_tun(c, sock, b);
2630+
}
2631+
else if (status & DCO_READ)
2632+
{
2633+
if (!IS_SIG(c))
2634+
{
2635+
process_incoming_dco(c);
2636+
}
2637+
}
2638+
}

src/openvpn/forward.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ void process_ip_header(struct context *c, unsigned int flags, struct buffer *buf
330330

331331
bool schedule_exit(struct context *c);
332332

333+
void threaded_io(struct context *c, struct link_socket *sock, struct thread_pointer *p);
334+
335+
333336
static inline struct link_socket_info *
334337
get_link_socket_info(struct context *c)
335338
{

src/openvpn/mtcp.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,18 @@ struct ta_iow_flags
4646
};
4747

4848
struct multi_instance *
49-
multi_create_instance_tcp(struct multi_context *m, struct link_socket *sock)
49+
multi_create_instance_tcp(struct multi_args *a, struct link_socket *sock)
5050
{
5151
struct gc_arena gc = gc_new();
52+
struct multi_context *m = a->p->m[a->i-1];
5253
struct multi_instance *mi = NULL;
5354
struct hash *hash = m->hash;
5455

55-
mi = multi_create_instance(m, NULL, sock);
56+
mi = multi_create_instance(a, NULL, sock);
5657
if (mi)
5758
{
59+
m = a->p->p;
60+
hash = m->hash;
5861
mi->real.proto = sock->info.proto;
5962
struct hash_element *he;
6063
const uint32_t hv = hash_value(hash, &mi->real);

src/openvpn/mtcp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer,
4545
bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi,
4646
const unsigned int mpp_flags);
4747

48-
struct multi_instance *multi_create_instance_tcp(struct multi_context *m, struct link_socket *sock);
48+
struct multi_instance *multi_create_instance_tcp(struct multi_args *a, struct link_socket *sock);
4949

5050
void multi_tcp_link_out_deferred(struct multi_context *m, struct multi_instance *mi);
5151

src/openvpn/mudp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ multi_get_create_instance_udp(struct multi_context *m, bool *floated, struct lin
191191
struct mroute_addr real = { 0 };
192192
struct multi_instance *mi = NULL;
193193
struct hash *hash = m->hash;
194+
struct multi_pointer p = { 0 };
195+
struct multi_args a = { 0 };
194196
real.proto = sock->info.proto;
195197
m->hmac_reply_ls = sock;
196198

@@ -264,7 +266,8 @@ multi_get_create_instance_udp(struct multi_context *m, bool *floated, struct lin
264266
* connect-freq but not against connect-freq-initial */
265267
reflect_filter_rate_limit_decrease(m->initial_rate_limiter);
266268

267-
mi = multi_create_instance(m, &real, sock);
269+
p.p = m; a.p = &p; a.i = -1;
270+
mi = multi_create_instance(&a, &real, sock);
268271
if (mi)
269272
{
270273
hash_add_fast(hash, bucket, &mi->real, hv, mi);

0 commit comments

Comments
 (0)