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
315 changes: 267 additions & 48 deletions src/openvpn/forward.c

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/openvpn/forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ 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);

bool check_for_bulk_mode(struct context *c);
bool check_for_bulk_data(struct context *c);

/**********************************************************************/
/**
Expand Down Expand Up @@ -196,6 +198,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
62 changes: 62 additions & 0 deletions src/openvpn/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,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 @@ -2008,6 +2009,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 @@ -2971,6 +2976,10 @@ frame_finalize_options(struct context *c, const struct options *o)
tailroom += COMP_EXTRA_BUFFER(payload_size);
#endif

if (frame->bulk_size > 0) {
payload_size = frame->tun_mtu;
}

frame->buf.payload_size = payload_size;
frame->buf.headroom = headroom;
frame->buf.tailroom = tailroom;
Expand Down Expand Up @@ -3473,6 +3482,9 @@ 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 @@ -3536,6 +3548,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 @@ -3676,9 +3696,41 @@ 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) {
for (int x = 0; x < TUN_BAT_MAX; ++x)
{
size_t part_size = BUF_SIZE(frame);
b->read_tun_bufs[x] = alloc_buf(part_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_flag = -1;

b->aux_buf = alloc_buf(buf_size);

b->encrypt_buf = alloc_buf(buf_size);
Expand All @@ -3701,6 +3753,16 @@ 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 @@ -46,15 +46,18 @@ struct ta_iow_flags
};

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));
size_t alen = BUF_SIZE(frame);
size_t 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
13 changes: 13 additions & 0 deletions src/openvpn/mtu.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
*/
#define TUN_MTU_MIN 100

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

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

int bulk_size; /**< Signal to the init frame function
* to allow for bulk mode TCP transfers.
* */
};

/* Forward declarations, to prevent includes */
Expand All @@ -176,6 +188,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 @@ -193,6 +193,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 @@ -266,7 +268,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