Skip to content

Commit b623e46

Browse files
author
Jon Chiappetta
committed
mtio mode
1 parent 1b090dd commit b623e46

18 files changed

Lines changed: 691 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 */
@@ -2524,8 +2526,24 @@ io_wait_dowork(struct context *c, const unsigned int flags)
25242526
dmsg(D_EVENT_WAIT, "I/O WAIT status=0x%04x", c->c2.event_set_status);
25252527
}
25262528

2529+
void threaded_read_tun(struct context *c, struct link_socket *sock, struct thread_pointer *b)
2530+
{
2531+
if (b->p->h == b->p->n)
2532+
{
2533+
int size;
2534+
uint8_t temp[1];
2535+
size = read(c->c1.tuntap->fd, temp, 1);
2536+
if (size < 1) { /* no-op */ }
2537+
if (!IS_SIG(c))
2538+
{
2539+
process_incoming_tun(c, sock);
2540+
}
2541+
size = write(c->c1.tuntap->fz, temp, 1);
2542+
}
2543+
}
2544+
25272545
void
2528-
process_io(struct context *c, struct link_socket *sock)
2546+
process_io(struct context *c, struct link_socket *sock, struct thread_pointer *b)
25292547
{
25302548
const unsigned int status = c->c2.event_set_status;
25312549

@@ -2559,11 +2577,7 @@ process_io(struct context *c, struct link_socket *sock)
25592577
/* Incoming data on TUN device */
25602578
else if (status & TUN_READ)
25612579
{
2562-
read_incoming_tun(c);
2563-
if (!IS_SIG(c))
2564-
{
2565-
process_incoming_tun(c, sock);
2566-
}
2580+
threaded_read_tun(c, sock, b);
25672581
}
25682582
else if (status & DCO_READ)
25692583
{

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)