Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
283 changes: 235 additions & 48 deletions src/openvpn/forward.c

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/openvpn/forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
* file
*/

#define BULK_MODE(c) (c->c2.frame.bulk_size > 0)
#define BULK_DATA(b) (b && (b->bulk_leng > 0) && (b->bulk_indx < b->bulk_leng))
#define INST_LENG(a) (a && (a->inst_leng > 0) && (a->inst_indx < a->inst_leng) && (a->pending == NULL))

#define TUN_OUT(c) (BLEN(&(c)->c2.to_tun) > 0)
#define LINK_OUT(c) (BLEN(&(c)->c2.to_link) > 0)
#define ANY_OUT(c) (TUN_OUT(c) || LINK_OUT(c))
Expand Down Expand Up @@ -77,7 +81,7 @@ void io_wait_dowork(struct context *c, const unsigned int flags);

void pre_select(struct context *c);

void process_io(struct context *c, struct link_socket *sock);
void process_io(struct context *c, struct link_socket *sock, struct thread_pointer *b);


/**********************************************************************/
Expand Down Expand Up @@ -196,6 +200,8 @@ bool process_incoming_link_part1(struct context *c, struct link_socket_info *lsi
void process_incoming_link_part2(struct context *c, struct link_socket_info *lsi,
const uint8_t *orig_buf);

void process_incoming_link_part3(struct context *c);

/**
* Transfers \c float_sa data extracted from an incoming DCO
* PEER_FLOAT_NTF to \c out_osaddr for later processing.
Expand Down
69 changes: 69 additions & 0 deletions src/openvpn/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,7 @@ do_open_tun(struct context *c, int *error_flags)
}

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

add_wfp_block(c);
}
if (c->c1.tuntap)
{
c->c1.tuntap->fe = c->c1.tuntap->fd;
}
gc_free(&gc);
return ret;
}
Expand Down Expand Up @@ -2976,6 +2981,11 @@ frame_finalize_options(struct context *c, const struct options *o)
tailroom += COMP_EXTRA_BUFFER(payload_size);
#endif

if (frame->bulk_size > 0)
{
payload_size = BAT_SIZE(TUN_BAT_ONE, frame->tun_mtu, TUN_BAT_OFF);
}

frame->buf.payload_size = payload_size;
frame->buf.headroom = headroom;
frame->buf.tailroom = tailroom;
Expand Down Expand Up @@ -3478,6 +3488,10 @@ do_init_frame_tls(struct context *c)
if (c->c2.tls_multi)
{
tls_multi_init_finalize(c->c2.tls_multi, c->options.ce.tls_mtu);
if (c->c2.frame.bulk_size > 0)
{
c->c2.tls_multi->opt.frame.buf.payload_size = c->c2.frame.tun_mtu;
}
ASSERT(c->c2.tls_multi->opt.frame.buf.payload_size <= c->c2.frame.buf.payload_size);
frame_print(&c->c2.tls_multi->opt.frame, D_MTU_INFO, "Control Channel MTU parms");

Expand Down Expand Up @@ -3545,6 +3559,14 @@ do_init_frame(struct context *c)
c->c2.frame.extra_tun += c->options.ce.tun_mtu_extra;
}

/*
* Adjust bulk size based on the --bulk-mode parameter.
*/
if (c->options.ce.bulk_mode)
{
c->c2.frame.bulk_size = c->options.ce.tun_mtu;
}

/*
* Fill in the blanks in the frame parameters structure,
* make sure values are rational, etc.
Expand Down Expand Up @@ -3685,9 +3707,45 @@ init_context_buffers(const struct frame *frame)

size_t buf_size = BUF_SIZE(frame);

if (frame->bulk_size > 0)
{
size_t off_size = (frame->buf.headroom + TUN_BAT_OFF + frame->buf.tailroom);
buf_size = BAT_SIZE(TUN_BAT_MAX, frame->tun_mtu, off_size);
}

dmsg(M_INFO, "MEM NEW [%ld] [%d+%d+%d]", buf_size, frame->buf.headroom, frame->buf.payload_size, frame->buf.tailroom);

b->read_link_buf = alloc_buf(buf_size);
b->read_tun_buf = alloc_buf(buf_size);

if (frame->bulk_size > 0)
{
size_t off_size = (frame->buf.headroom + TUN_BAT_OFF + frame->buf.tailroom);
size_t one_size = BAT_SIZE(TUN_BAT_ONE, frame->tun_mtu, off_size);

for (int x = 0; x < TUN_BAT_MAX; ++x)
{
b->read_tun_bufs[x] = alloc_buf(one_size);
b->read_tun_bufs[x].offset = TUN_BAT_OFF;
b->read_tun_bufs[x].len = 0;
}

b->read_tun_max = alloc_buf(buf_size);
b->read_tun_max.offset = TUN_BAT_OFF;
b->read_tun_max.len = 0;

b->send_tun_max = alloc_buf(buf_size);
b->send_tun_max.offset = TUN_BAT_OFF;
b->send_tun_max.len = 0;

b->to_tun_max = alloc_buf(buf_size);
b->to_tun_max.offset = TUN_BAT_OFF;
b->to_tun_max.len = 0;
}

b->bulk_indx = -1;
b->bulk_leng = -1;

b->aux_buf = alloc_buf(buf_size);

b->encrypt_buf = alloc_buf(buf_size);
Expand All @@ -3710,6 +3768,17 @@ free_context_buffers(struct context_buffers *b)
free_buf(&b->read_tun_buf);
free_buf(&b->aux_buf);

if (b->to_tun_max.data)
{
free_buf(&b->to_tun_max);
free_buf(&b->send_tun_max);
free_buf(&b->read_tun_max);
for (int x = 0; x < TUN_BAT_MAX; ++x)
{
free_buf(&b->read_tun_bufs[x]);
}
}

#ifdef USE_COMP
free_buf(&b->compress_buf);
free_buf(&b->decompress_buf);
Expand Down
7 changes: 5 additions & 2 deletions src/openvpn/mtcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,18 @@ struct ta_iow_flags
#endif

struct multi_instance *
multi_create_instance_tcp(struct multi_context *m, struct link_socket *sock)
multi_create_instance_tcp(struct thread_pointer *a, struct link_socket *sock)
{
struct gc_arena gc = gc_new();
struct multi_context *m = a->p->m[a->i-1];
struct multi_instance *mi = NULL;
struct hash *hash = m->hash;

mi = multi_create_instance(m, NULL, sock);
mi = multi_create_instance(a, NULL, sock);
if (mi)
{
m = a->p->p;
hash = m->hash;
mi->real.proto = sock->info.proto;
struct hash_element *he;
const uint32_t hv = hash_value(hash, &mi->real);
Expand Down
2 changes: 1 addition & 1 deletion src/openvpn/mtcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer,
bool multi_tcp_process_outgoing_link_ready(struct multi_context *m, struct multi_instance *mi,
const unsigned int mpp_flags);

struct multi_instance *multi_create_instance_tcp(struct multi_context *m, struct link_socket *sock);
struct multi_instance *multi_create_instance_tcp(struct thread_pointer *a, struct link_socket *sock);

void multi_tcp_link_out_deferred(struct multi_context *m, struct multi_instance *mi);

Expand Down
10 changes: 8 additions & 2 deletions src/openvpn/mtu.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ void
alloc_buf_sock_tun(struct buffer *buf, const struct frame *frame)
{
/* allocate buffer for overlapped I/O */
*buf = alloc_buf(BUF_SIZE(frame));
int alen = BUF_SIZE(frame);
int blen = frame->buf.payload_size;
if (frame->bulk_size > 0) {
alen = BAT_SIZE(TUN_BAT_MAX, frame->tun_mtu, TUN_BAT_OFF);
blen = BAT_SIZE(TUN_BAT_MAX, frame->tun_mtu, TUN_BAT_NOP);
}
*buf = alloc_buf(alen);
ASSERT(buf_init(buf, frame->buf.headroom));
buf->len = frame->buf.payload_size;
buf->len = blen;
ASSERT(buf_safe(buf, 0));
}

Expand Down
15 changes: 15 additions & 0 deletions src/openvpn/mtu.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@
*/
#define TUN_MTU_MIN 100

/*
* Bulk mode static define values.
*/
#define TUN_BAT_MIN 6
#define TUN_BAT_MAX 9
#define TUN_BAT_OFF 250
#define TUN_BAT_NOP 0
#define TUN_BAT_ONE 1

/*
* Default MTU of network over which tunnel data will pass by TCP/UDP.
*/
Expand Down Expand Up @@ -157,6 +166,11 @@ struct frame
* which defaults to 0 for tun and 32
* (\c TAP_MTU_EXTRA_DEFAULT) for tap.
* */

int bulk_size; /**< Set in the init frame function to
* signal to related functions to
* process bulk mode data transfers.
* */
};

/* Forward declarations, to prevent includes */
Expand All @@ -176,6 +190,7 @@ struct options;
* larger than the headroom.
*/
#define BUF_SIZE(f) ((f)->buf.headroom + (f)->buf.payload_size + (f)->buf.tailroom)
#define BAT_SIZE(a, b, c) ((a * b) + c)

/*
* Function prototypes.
Expand Down
5 changes: 4 additions & 1 deletion src/openvpn/mudp.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ multi_get_create_instance_udp(struct multi_context *m, bool *floated, struct lin
struct mroute_addr real = { 0 };
struct multi_instance *mi = NULL;
struct hash *hash = m->hash;
struct context_pointer p = { 0 };
struct thread_pointer a = { 0 };
real.proto = sock->info.proto;
m->hmac_reply_ls = sock;

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

mi = multi_create_instance(m, &real, sock);
p.p = m; a.p = &p; a.i = -1;
mi = multi_create_instance(&a, &real, sock);
if (mi)
{
hash_add_fast(hash, bucket, &mi->real, hv, mi);
Expand Down
Loading