Skip to content

Commit bdc1cbc

Browse files
author
Jon Chiappetta
committed
mtio mode
1 parent c3db7c0 commit bdc1cbc

File tree

18 files changed

+750
-61
lines changed

18 files changed

+750
-61
lines changed

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 */
@@ -2513,8 +2515,24 @@ io_wait_dowork(struct context *c, const unsigned int flags)
25132515
dmsg(D_EVENT_WAIT, "I/O WAIT status=0x%04x", c->c2.event_set_status);
25142516
}
25152517

2518+
void threaded_fwd_in_tun(struct context *c, struct link_socket *sock, struct thread_pointer *b)
2519+
{
2520+
if (b->p->h == b->p->n)
2521+
{
2522+
int size;
2523+
uint8_t temp[1];
2524+
size = read(c->c1.tuntap->fd, temp, 1);
2525+
if (size < 1) { /* no-op */ }
2526+
if (!IS_SIG(c))
2527+
{
2528+
process_incoming_tun(c, sock);
2529+
}
2530+
size = write(c->c1.tuntap->fz, temp, 1);
2531+
}
2532+
}
2533+
25162534
void
2517-
process_io(struct context *c, struct link_socket *sock)
2535+
process_io(struct context *c, struct link_socket *sock, struct thread_pointer *b)
25182536
{
25192537
const unsigned int status = c->c2.event_set_status;
25202538

@@ -2548,11 +2566,7 @@ process_io(struct context *c, struct link_socket *sock)
25482566
/* Incoming data on TUN device */
25492567
else if (status & TUN_READ)
25502568
{
2551-
read_incoming_tun(c);
2552-
if (!IS_SIG(c))
2553-
{
2554-
process_incoming_tun(c, sock);
2555-
}
2569+
threaded_fwd_in_tun(c, sock, b);
25562570
}
25572571
else if (status & DCO_READ)
25582572
{

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)