Skip to content

Commit 52c565f

Browse files
author
Jon Chiappetta
committed
mtio mode
1 parent b82ba4f commit 52c565f

18 files changed

Lines changed: 731 additions & 58 deletions

src/openvpn/forward.c

Lines changed: 20 additions & 6 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 */
@@ -2508,8 +2510,24 @@ io_wait_dowork(struct context *c, const unsigned int flags)
25082510
dmsg(D_EVENT_WAIT, "I/O WAIT status=0x%04x", c->c2.event_set_status);
25092511
}
25102512

2513+
void threaded_read_tun(struct context *c, struct link_socket *sock, struct thread_pointer *b)
2514+
{
2515+
if (b->p->h == b->p->n)
2516+
{
2517+
int size;
2518+
uint8_t temp[1];
2519+
size = read(c->c1.tuntap->fd, temp, 1);
2520+
if (size < 1) { /* no-op */ }
2521+
if (!IS_SIG(c))
2522+
{
2523+
process_incoming_tun(c, sock);
2524+
}
2525+
size = write(c->c1.tuntap->fz, temp, 1);
2526+
}
2527+
}
2528+
25112529
void
2512-
process_io(struct context *c, struct link_socket *sock)
2530+
process_io(struct context *c, struct link_socket *sock, struct thread_pointer *b)
25132531
{
25142532
const unsigned int status = c->c2.event_set_status;
25152533

@@ -2543,11 +2561,7 @@ process_io(struct context *c, struct link_socket *sock)
25432561
/* Incoming data on TUN device */
25442562
else if (status & TUN_READ)
25452563
{
2546-
read_incoming_tun(c);
2547-
if (!IS_SIG(c))
2548-
{
2549-
process_incoming_tun(c, sock);
2550-
}
2564+
threaded_read_tun(c, sock, b);
25512565
}
25522566
else if (status & DCO_READ)
25532567
{

src/openvpn/forward.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void io_wait_dowork(struct context *c, const unsigned int flags);
7777

7878
void pre_select(struct context *c);
7979

80-
void process_io(struct context *c, struct link_socket *sock);
80+
void process_io(struct context *c, struct link_socket *sock, struct thread_pointer *b);
8181

8282
bool check_bulk_mode(struct context *c);
8383

src/openvpn/init.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,7 @@ do_open_tun(struct context *c, int *error_flags)
19151915
}
19161916

19171917
/* do ifconfig */
1918+
c->c1.tuntap->skip_bind = c->skip_bind;
19181919
if (!ifconfig_noexec_enabled(c) && ifconfig_order(c->c1.tuntap) == IFCONFIG_BEFORE_TUN_OPEN)
19191920
{
19201921
/* guess actual tun/tap unit number that will be returned
@@ -2008,6 +2009,10 @@ do_open_tun(struct context *c, int *error_flags)
20082009

20092010
add_wfp_block(c);
20102011
}
2012+
if (c->c1.tuntap)
2013+
{
2014+
c->c1.tuntap->fe = c->c1.tuntap->fd;
2015+
}
20112016
gc_free(&gc);
20122017
return ret;
20132018
}

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 thread_pointer *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 thread_pointer *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
@@ -193,6 +193,8 @@ multi_get_create_instance_udp(struct multi_context *m, bool *floated, struct lin
193193
struct mroute_addr real = { 0 };
194194
struct multi_instance *mi = NULL;
195195
struct hash *hash = m->hash;
196+
struct context_pointer p = { 0 };
197+
struct thread_pointer a = { 0 };
196198
real.proto = sock->info.proto;
197199
m->hmac_reply_ls = sock;
198200

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

269-
mi = multi_create_instance(m, &real, sock);
271+
p.p = m; a.p = &p; a.i = -1;
272+
mi = multi_create_instance(&a, &real, sock);
270273
if (mi)
271274
{
272275
hash_add_fast(hash, bucket, &mi->real, hv, mi);

0 commit comments

Comments
 (0)