Skip to content

Commit a93f07d

Browse files
author
Jon Chiappetta
committed
bulk mode
1 parent 0fb5a00 commit a93f07d

File tree

12 files changed

+533
-57
lines changed

12 files changed

+533
-57
lines changed

src/openvpn/forward.c

Lines changed: 247 additions & 42 deletions
Large diffs are not rendered by default.

src/openvpn/forward.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ void pre_select(struct context *c);
7979

8080
void process_io(struct context *c, struct link_socket *sock);
8181

82+
bool check_for_bulk_mode(struct context *c);
83+
bool check_for_bulk_data(struct context *c);
8284

8385
/**********************************************************************/
8486
/**
@@ -196,6 +198,8 @@ bool process_incoming_link_part1(struct context *c, struct link_socket_info *lsi
196198
void process_incoming_link_part2(struct context *c, struct link_socket_info *lsi,
197199
const uint8_t *orig_buf);
198200

201+
void process_incoming_link_part3(struct context *c);
202+
199203
/**
200204
* Transfers \c float_sa data extracted from an incoming DCO
201205
* PEER_FLOAT_NTF to \c out_osaddr for later processing.

src/openvpn/init.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2976,6 +2976,11 @@ frame_finalize_options(struct context *c, const struct options *o)
29762976
tailroom += COMP_EXTRA_BUFFER(payload_size);
29772977
#endif
29782978

2979+
if (frame->bulk_size > 0)
2980+
{
2981+
payload_size = frame->tun_mtu;
2982+
}
2983+
29792984
frame->buf.payload_size = payload_size;
29802985
frame->buf.headroom = headroom;
29812986
frame->buf.tailroom = tailroom;
@@ -3478,6 +3483,10 @@ do_init_frame_tls(struct context *c)
34783483
if (c->c2.tls_multi)
34793484
{
34803485
tls_multi_init_finalize(c->c2.tls_multi, c->options.ce.tls_mtu);
3486+
if (c->c2.frame.bulk_size > 0)
3487+
{
3488+
c->c2.tls_multi->opt.frame.buf.payload_size = c->c2.frame.tun_mtu;
3489+
}
34813490
ASSERT(c->c2.tls_multi->opt.frame.buf.payload_size <= c->c2.frame.buf.payload_size);
34823491
frame_print(&c->c2.tls_multi->opt.frame, D_MTU_INFO, "Control Channel MTU parms");
34833492

@@ -3545,6 +3554,14 @@ do_init_frame(struct context *c)
35453554
c->c2.frame.extra_tun += c->options.ce.tun_mtu_extra;
35463555
}
35473556

3557+
/*
3558+
* Adjust bulk size based on the --bulk-mode parameter.
3559+
*/
3560+
if (c->options.ce.bulk_mode)
3561+
{
3562+
c->c2.frame.bulk_size = c->options.ce.tun_mtu;
3563+
}
3564+
35483565
/*
35493566
* Fill in the blanks in the frame parameters structure,
35503567
* make sure values are rational, etc.
@@ -3685,9 +3702,43 @@ init_context_buffers(const struct frame *frame)
36853702

36863703
size_t buf_size = BUF_SIZE(frame);
36873704

3705+
if (frame->bulk_size > 0)
3706+
{
3707+
size_t off_size = (frame->buf.headroom + TUN_BAT_OFF + frame->buf.tailroom);
3708+
buf_size = BAT_SIZE(TUN_BAT_MAX, frame->tun_mtu, off_size);
3709+
}
3710+
3711+
dmsg(M_INFO, "MEM NEW [%ld] [%d+%d+%d]", buf_size, frame->buf.headroom, frame->buf.payload_size, frame->buf.tailroom);
3712+
36883713
b->read_link_buf = alloc_buf(buf_size);
36893714
b->read_tun_buf = alloc_buf(buf_size);
36903715

3716+
if (frame->bulk_size > 0)
3717+
{
3718+
for (int x = 0; x < TUN_BAT_MAX; ++x)
3719+
{
3720+
size_t part_size = BUF_SIZE(frame);
3721+
b->read_tun_bufs[x] = alloc_buf(part_size);
3722+
b->read_tun_bufs[x].offset = TUN_BAT_OFF;
3723+
b->read_tun_bufs[x].len = 0;
3724+
}
3725+
3726+
b->read_tun_max = alloc_buf(buf_size);
3727+
b->read_tun_max.offset = TUN_BAT_OFF;
3728+
b->read_tun_max.len = 0;
3729+
3730+
b->send_tun_max = alloc_buf(buf_size);
3731+
b->send_tun_max.offset = TUN_BAT_OFF;
3732+
b->send_tun_max.len = 0;
3733+
3734+
b->to_tun_max = alloc_buf(buf_size);
3735+
b->to_tun_max.offset = TUN_BAT_OFF;
3736+
b->to_tun_max.len = 0;
3737+
}
3738+
3739+
b->bulk_indx = -1;
3740+
b->bulk_flag = -1;
3741+
36913742
b->aux_buf = alloc_buf(buf_size);
36923743

36933744
b->encrypt_buf = alloc_buf(buf_size);
@@ -3710,6 +3761,17 @@ free_context_buffers(struct context_buffers *b)
37103761
free_buf(&b->read_tun_buf);
37113762
free_buf(&b->aux_buf);
37123763

3764+
if (b->to_tun_max.data)
3765+
{
3766+
free_buf(&b->to_tun_max);
3767+
free_buf(&b->send_tun_max);
3768+
free_buf(&b->read_tun_max);
3769+
for (int x = 0; x < TUN_BAT_MAX; ++x)
3770+
{
3771+
free_buf(&b->read_tun_bufs[x]);
3772+
}
3773+
}
3774+
37133775
#ifdef USE_COMP
37143776
free_buf(&b->compress_buf);
37153777
free_buf(&b->decompress_buf);

src/openvpn/mtu.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,15 @@ void
4141
alloc_buf_sock_tun(struct buffer *buf, const struct frame *frame)
4242
{
4343
/* allocate buffer for overlapped I/O */
44-
*buf = alloc_buf(BUF_SIZE(frame));
44+
int alen = BUF_SIZE(frame);
45+
int blen = frame->buf.payload_size;
46+
if (frame->bulk_size > 0) {
47+
alen = BAT_SIZE(TUN_BAT_MAX, frame->tun_mtu, TUN_BAT_OFF);
48+
blen = BAT_SIZE(TUN_BAT_MAX, frame->tun_mtu, TUN_BAT_NOP);
49+
}
50+
*buf = alloc_buf(alen);
4551
ASSERT(buf_init(buf, frame->buf.headroom));
46-
buf->len = frame->buf.payload_size;
52+
buf->len = blen;
4753
ASSERT(buf_safe(buf, 0));
4854
}
4955

src/openvpn/mtu.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@
5858
*/
5959
#define TUN_MTU_MIN 100
6060

61+
/*
62+
* Bulk mode static define values.
63+
*/
64+
#define TUN_BAT_MIN 6
65+
#define TUN_BAT_MAX 9
66+
#define TUN_BAT_OFF 256
67+
#define TUN_BAT_NOP 0
68+
6169
/*
6270
* Default MTU of network over which tunnel data will pass by TCP/UDP.
6371
*/
@@ -157,6 +165,11 @@ struct frame
157165
* which defaults to 0 for tun and 32
158166
* (\c TAP_MTU_EXTRA_DEFAULT) for tap.
159167
* */
168+
169+
int bulk_size; /**< Set in the init frame function to
170+
* signal to related functions to
171+
* process bulk mode data transfers.
172+
* */
160173
};
161174

162175
/* Forward declarations, to prevent includes */
@@ -176,6 +189,7 @@ struct options;
176189
* larger than the headroom.
177190
*/
178191
#define BUF_SIZE(f) ((f)->buf.headroom + (f)->buf.payload_size + (f)->buf.tailroom)
192+
#define BAT_SIZE(a, b, c) ((a * b) + c)
179193

180194
/*
181195
* Function prototypes.

0 commit comments

Comments
 (0)