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
288 changes: 239 additions & 49 deletions src/openvpn/forward.c

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/openvpn/forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
* file
*/

#define BULK_MODE(c) (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))
#define LINK_LEFT(i) (i && sockets_read_residual(i))

#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 @@ -193,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
64 changes: 64 additions & 0 deletions src/openvpn/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -2952,6 +2952,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 @@ -3457,6 +3462,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 @@ -3524,6 +3533,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 @@ -3664,9 +3681,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, "BULK bufs [%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 @@ -3689,6 +3742,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
11 changes: 9 additions & 2 deletions src/openvpn/mtu.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ 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; /**< Configure and setup in the init library
* frame function to signal and inform the various
* related function calls 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
10 changes: 5 additions & 5 deletions src/openvpn/mudp.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,15 @@ unsigned int
p2mp_iow_flags(const struct multi_context *m)
{
unsigned int flags = IOW_WAIT_SIGNAL;
if (m->pending)
if (m->pending || m->pending2)
{
if (TUN_OUT(&m->pending->context))
if (m->pending && LINK_OUT(&m->pending->context))
{
flags |= IOW_TO_TUN;
flags |= IOW_TO_LINK;
}
if (LINK_OUT(&m->pending->context))
if (m->pending2 && TUN_OUT(&m->pending2->context))
{
flags |= IOW_TO_LINK;
flags |= IOW_TO_TUN;
}
}
else if (mbuf_defined(m->mbuf))
Expand Down
Loading