Skip to content

Commit 8f28dc6

Browse files
author
Jon Chiappetta
committed
mtio mode
1 parent c24c20e commit 8f28dc6

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
@@ -45,7 +45,9 @@
4545
#include "memdbg.h"
4646

4747
#include <sys/select.h>
48+
#include <sys/socket.h>
4849
#include <sys/time.h>
50+
#include <pthread.h>
4951

5052
counter_type link_read_bytes_global; /* GLOBAL */
5153
counter_type link_write_bytes_global; /* GLOBAL */
@@ -2488,8 +2490,24 @@ io_wait_dowork(struct context *c, const unsigned int flags)
24882490
dmsg(D_EVENT_WAIT, "I/O WAIT status=0x%04x", c->c2.event_set_status);
24892491
}
24902492

2493+
void threaded_fwd_inp_intf(struct context *c, struct link_socket *sock, struct thread_pointer *b)
2494+
{
2495+
if (b->p->h == b->p->n)
2496+
{
2497+
ssize_t size;
2498+
uint8_t temp[1];
2499+
size = read(c->c1.tuntap->fd, temp, 1);
2500+
if (size < 1) { /* no-op */ }
2501+
if (!IS_SIG(c))
2502+
{
2503+
process_incoming_tun(c, sock);
2504+
}
2505+
size = write(c->c1.tuntap->fz, temp, 1);
2506+
}
2507+
}
2508+
24912509
void
2492-
process_io(struct context *c, struct link_socket *sock)
2510+
process_io(struct context *c, struct link_socket *sock, struct thread_pointer *b)
24932511
{
24942512
const unsigned int status = c->c2.event_set_status;
24952513

@@ -2523,11 +2541,7 @@ process_io(struct context *c, struct link_socket *sock)
25232541
/* Incoming data on TUN device */
25242542
else if (status & TUN_READ)
25252543
{
2526-
read_incoming_tun(c);
2527-
if (!IS_SIG(c))
2528-
{
2529-
process_incoming_tun(c, sock);
2530-
}
2544+
threaded_fwd_inp_intf(c, sock, b);
25312545
}
25322546
else if (status & DCO_READ)
25332547
{

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
@@ -1896,6 +1896,7 @@ do_open_tun(struct context *c, int *error_flags)
18961896
}
18971897

18981898
/* do ifconfig */
1899+
c->c1.tuntap->skip_bind = c->skip_bind;
18991900
if (!ifconfig_noexec_enabled(c) && ifconfig_order(c->c1.tuntap) == IFCONFIG_BEFORE_TUN_OPEN)
19001901
{
19011902
/* guess actual tun/tap unit number that will be returned
@@ -1989,6 +1990,10 @@ do_open_tun(struct context *c, int *error_flags)
19891990

19901991
add_wfp_block(c);
19911992
}
1993+
if (c->c1.tuntap)
1994+
{
1995+
c->c1.tuntap->fe = c->c1.tuntap->fd;
1996+
}
19921997
gc_free(&gc);
19931998
return ret;
19941999
}

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)