Skip to content

Commit 5941946

Browse files
author
Jon Chiappetta
committed
mtio mode
1 parent 0afd598 commit 5941946

File tree

15 files changed

+420
-34
lines changed

15 files changed

+420
-34
lines changed

src/openvpn/forward.c

Lines changed: 71 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,72 @@ process_io(struct context *c, struct link_socket *sock)
25702572
}
25712573
}
25722574
}
2575+
2576+
bool threaded_lock(struct thread_pointer *b)
2577+
{
2578+
if (pthread_mutex_trylock(&(b->p->m)) == 0)
2579+
{
2580+
if (b->p->f == 0)
2581+
{
2582+
b->p->f = b->n;
2583+
}
2584+
pthread_mutex_unlock(&(b->p->m));
2585+
}
2586+
if (b->p->f == b->n) { return true; }
2587+
return false;
2588+
}
2589+
2590+
void threaded_io(struct context *c, struct link_socket *sock, struct thread_pointer *b)
2591+
{
2592+
const unsigned int status = c->c2.event_set_status;
2593+
2594+
#ifdef ENABLE_MANAGEMENT
2595+
if (status & (MANAGEMENT_READ | MANAGEMENT_WRITE))
2596+
{
2597+
ASSERT(management);
2598+
management_io(management);
2599+
}
2600+
#endif
2601+
2602+
//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);
2603+
2604+
/* TCP/UDP port ready to accept write */
2605+
if (status & SOCKET_WRITE)
2606+
{
2607+
process_outgoing_link(c, sock);
2608+
}
2609+
/* TUN device ready to accept write */
2610+
else if (status & TUN_WRITE)
2611+
{
2612+
process_outgoing_tun(c, sock);
2613+
}
2614+
/* Incoming data on TCP/UDP port */
2615+
else if (status & SOCKET_READ)
2616+
{
2617+
read_incoming_link(c, sock);
2618+
if (!IS_SIG(c))
2619+
{
2620+
process_incoming_link(c, sock);
2621+
}
2622+
}
2623+
/* Incoming data on TUN device */
2624+
else if (status & TUN_READ)
2625+
{
2626+
if (threaded_lock(b))
2627+
{
2628+
read_incoming_tun(c);
2629+
b->p->f = 0;
2630+
if (!IS_SIG(c))
2631+
{
2632+
process_incoming_tun(c, sock);
2633+
}
2634+
}
2635+
}
2636+
else if (status & DCO_READ)
2637+
{
2638+
if (!IS_SIG(c))
2639+
{
2640+
process_incoming_dco(c);
2641+
}
2642+
}
2643+
}

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)