Skip to content

Commit 62478de

Browse files
author
Jon Chiappetta
committed
mtio mode
1 parent f5b1370 commit 62478de

File tree

18 files changed

+979
-68
lines changed

18 files changed

+979
-68
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 */
@@ -2502,8 +2504,24 @@ io_wait_dowork(struct context *c, const unsigned int flags)
25022504
dmsg(D_EVENT_WAIT, "I/O WAIT status=0x%04x", c->c2.event_set_status);
25032505
}
25042506

2507+
void threaded_fwd_inp_intf(struct context *c, struct link_socket *sock, struct thread_pointer *b)
2508+
{
2509+
if (b->p->h == b->p->n)
2510+
{
2511+
ssize_t size;
2512+
uint8_t temp[1];
2513+
size = read(c->c1.tuntap->fd, temp, 1);
2514+
if (size < 1) { /* no-op */ }
2515+
if (!IS_SIG(c))
2516+
{
2517+
process_incoming_tun(c, sock);
2518+
}
2519+
size = write(c->c1.tuntap->fz, temp, 1);
2520+
}
2521+
}
2522+
25052523
void
2506-
process_io(struct context *c, struct link_socket *sock)
2524+
process_io(struct context *c, struct link_socket *sock, struct thread_pointer *b)
25072525
{
25082526
const unsigned int status = c->c2.event_set_status;
25092527

@@ -2537,11 +2555,7 @@ process_io(struct context *c, struct link_socket *sock)
25372555
/* Incoming data on TUN device */
25382556
else if (status & TUN_READ)
25392557
{
2540-
read_incoming_tun(c);
2541-
if (!IS_SIG(c))
2542-
{
2543-
process_incoming_tun(c, sock);
2544-
}
2558+
threaded_fwd_inp_intf(c, sock, b);
25452559
}
25462560
else if (status & DCO_READ)
25472561
{

src/openvpn/forward.h

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

8282
void pre_select(struct context *c);
8383

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

8686

8787
/**********************************************************************/

src/openvpn/init.c

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

19221922
/* do ifconfig */
1923+
c->c1.tuntap->skip_bind = c->skip_bind;
19231924
if (!ifconfig_noexec_enabled(c) && ifconfig_order(c->c1.tuntap) == IFCONFIG_BEFORE_TUN_OPEN)
19241925
{
19251926
/* guess actual tun/tap unit number that will be returned
@@ -2013,6 +2014,10 @@ do_open_tun(struct context *c, int *error_flags)
20132014

20142015
add_wfp_block(c);
20152016
}
2017+
if (c->c1.tuntap)
2018+
{
2019+
c->c1.tuntap->fe = c->c1.tuntap->fd;
2020+
}
20162021
gc_free(&gc);
20172022
return ret;
20182023
}

src/openvpn/mtcp.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,18 @@ struct ta_iow_flags
5151
#endif
5252

5353
struct multi_instance *
54-
multi_create_instance_tcp(struct multi_context *m, struct link_socket *sock)
54+
multi_create_instance_tcp(struct thread_pointer *b, struct link_socket *sock)
5555
{
5656
struct gc_arena gc = gc_new();
57+
struct multi_context *m = b->p->m[b->i-1];
5758
struct multi_instance *mi = NULL;
5859
struct hash *hash = m->hash;
5960

60-
mi = multi_create_instance(m, NULL, sock);
61+
mi = multi_create_instance(b, NULL, sock);
6162
if (mi)
6263
{
64+
m = b->p->p;
65+
hash = m->hash;
6366
mi->real.proto = sock->info.proto;
6467
struct hash_element *he;
6568
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 *b, 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
@@ -198,6 +198,8 @@ multi_get_create_instance_udp(struct multi_context *m, bool *floated, struct lin
198198
struct mroute_addr real = { 0 };
199199
struct multi_instance *mi = NULL;
200200
struct hash *hash = m->hash;
201+
struct context_pointer p = { 0 };
202+
struct thread_pointer b = { 0 };
201203
real.proto = sock->info.proto;
202204
m->hmac_reply_ls = sock;
203205

@@ -271,7 +273,8 @@ multi_get_create_instance_udp(struct multi_context *m, bool *floated, struct lin
271273
* connect-freq but not against connect-freq-initial */
272274
reflect_filter_rate_limit_decrease(m->initial_rate_limiter);
273275

274-
mi = multi_create_instance(m, &real, sock);
276+
p.p = m; b.p = &p; b.i = -1;
277+
mi = multi_create_instance(&b, &real, sock);
275278
if (mi)
276279
{
277280
hash_add_fast(hash, bucket, &mi->real, hv, mi);

0 commit comments

Comments
 (0)