Skip to content

Commit 7a5bf01

Browse files
author
Jon Chiappetta
committed
bulk mode
1 parent 44dd39b commit 7a5bf01

File tree

13 files changed

+596
-133
lines changed

13 files changed

+596
-133
lines changed

src/openvpn/forward.c

Lines changed: 239 additions & 49 deletions
Large diffs are not rendered by default.

src/openvpn/forward.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
* file
3535
*/
3636

37+
#define BULK_MODE(c) (c && c->c2.frame.bulk_size > 0)
38+
#define BULK_DATA(b) (b && (b->bulk_leng > 0) && (b->bulk_indx < b->bulk_leng))
39+
#define INST_LENG(a) (a && (a->inst_leng > 0) && (a->inst_indx < a->inst_leng))
40+
#define LINK_LEFT(i) (i && sockets_read_residual(i))
41+
3742
#define TUN_OUT(c) (BLEN(&(c)->c2.to_tun) > 0)
3843
#define LINK_OUT(c) (BLEN(&(c)->c2.to_link) > 0)
3944
#define ANY_OUT(c) (TUN_OUT(c) || LINK_OUT(c))
@@ -193,6 +198,8 @@ bool process_incoming_link_part1(struct context *c, struct link_socket_info *lsi
193198
void process_incoming_link_part2(struct context *c, struct link_socket_info *lsi,
194199
const uint8_t *orig_buf);
195200

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

src/openvpn/init.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,6 +2952,11 @@ frame_finalize_options(struct context *c, const struct options *o)
29522952
tailroom += COMP_EXTRA_BUFFER(payload_size);
29532953
#endif
29542954

2955+
if (frame->bulk_size > 0)
2956+
{
2957+
payload_size = BAT_SIZE(TUN_BAT_ONE, frame->tun_mtu, TUN_BAT_OFF);
2958+
}
2959+
29552960
frame->buf.payload_size = payload_size;
29562961
frame->buf.headroom = headroom;
29572962
frame->buf.tailroom = tailroom;
@@ -3457,6 +3462,10 @@ do_init_frame_tls(struct context *c)
34573462
if (c->c2.tls_multi)
34583463
{
34593464
tls_multi_init_finalize(c->c2.tls_multi, c->options.ce.tls_mtu);
3465+
if (c->c2.frame.bulk_size > 0)
3466+
{
3467+
c->c2.tls_multi->opt.frame.buf.payload_size = c->c2.frame.tun_mtu;
3468+
}
34603469
ASSERT(c->c2.tls_multi->opt.frame.buf.payload_size <= c->c2.frame.buf.payload_size);
34613470
frame_print(&c->c2.tls_multi->opt.frame, D_MTU_INFO, "Control Channel MTU parms");
34623471

@@ -3524,6 +3533,14 @@ do_init_frame(struct context *c)
35243533
c->c2.frame.extra_tun += c->options.ce.tun_mtu_extra;
35253534
}
35263535

3536+
/*
3537+
* Adjust bulk size based on the --bulk-mode parameter.
3538+
*/
3539+
if (c->options.ce.bulk_mode)
3540+
{
3541+
c->c2.frame.bulk_size = c->options.ce.tun_mtu;
3542+
}
3543+
35273544
/*
35283545
* Fill in the blanks in the frame parameters structure,
35293546
* make sure values are rational, etc.
@@ -3664,9 +3681,45 @@ init_context_buffers(const struct frame *frame)
36643681

36653682
size_t buf_size = BUF_SIZE(frame);
36663683

3684+
if (frame->bulk_size > 0)
3685+
{
3686+
size_t off_size = (frame->buf.headroom + TUN_BAT_OFF + frame->buf.tailroom);
3687+
buf_size = BAT_SIZE(TUN_BAT_MAX, frame->tun_mtu, off_size);
3688+
}
3689+
3690+
dmsg(M_INFO, "BULK bufs [%ld] [%d+%d+%d]", buf_size, frame->buf.headroom, frame->buf.payload_size, frame->buf.tailroom);
3691+
36673692
b->read_link_buf = alloc_buf(buf_size);
36683693
b->read_tun_buf = alloc_buf(buf_size);
36693694

3695+
if (frame->bulk_size > 0)
3696+
{
3697+
size_t off_size = (frame->buf.headroom + TUN_BAT_OFF + frame->buf.tailroom);
3698+
size_t one_size = BAT_SIZE(TUN_BAT_ONE, frame->tun_mtu, off_size);
3699+
3700+
for (int x = 0; x < TUN_BAT_MAX; ++x)
3701+
{
3702+
b->read_tun_bufs[x] = alloc_buf(one_size);
3703+
b->read_tun_bufs[x].offset = TUN_BAT_OFF;
3704+
b->read_tun_bufs[x].len = 0;
3705+
}
3706+
3707+
b->read_tun_max = alloc_buf(buf_size);
3708+
b->read_tun_max.offset = TUN_BAT_OFF;
3709+
b->read_tun_max.len = 0;
3710+
3711+
b->send_tun_max = alloc_buf(buf_size);
3712+
b->send_tun_max.offset = TUN_BAT_OFF;
3713+
b->send_tun_max.len = 0;
3714+
3715+
b->to_tun_max = alloc_buf(buf_size);
3716+
b->to_tun_max.offset = TUN_BAT_OFF;
3717+
b->to_tun_max.len = 0;
3718+
}
3719+
3720+
b->bulk_indx = -1;
3721+
b->bulk_leng = -1;
3722+
36703723
b->aux_buf = alloc_buf(buf_size);
36713724

36723725
b->encrypt_buf = alloc_buf(buf_size);
@@ -3689,6 +3742,17 @@ free_context_buffers(struct context_buffers *b)
36893742
free_buf(&b->read_tun_buf);
36903743
free_buf(&b->aux_buf);
36913744

3745+
if (b->to_tun_max.data)
3746+
{
3747+
free_buf(&b->to_tun_max);
3748+
free_buf(&b->send_tun_max);
3749+
free_buf(&b->read_tun_max);
3750+
for (int x = 0; x < TUN_BAT_MAX; ++x)
3751+
{
3752+
free_buf(&b->read_tun_bufs[x]);
3753+
}
3754+
}
3755+
36923756
#ifdef USE_COMP
36933757
free_buf(&b->compress_buf);
36943758
free_buf(&b->decompress_buf);

src/openvpn/mtu.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,16 @@ 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+
{
48+
alen = BAT_SIZE(TUN_BAT_MAX, frame->tun_mtu, TUN_BAT_OFF);
49+
blen = BAT_SIZE(TUN_BAT_MAX, frame->tun_mtu, TUN_BAT_NOP);
50+
}
51+
*buf = alloc_buf(alen);
4552
ASSERT(buf_init(buf, frame->buf.headroom));
46-
buf->len = frame->buf.payload_size;
53+
buf->len = blen;
4754
ASSERT(buf_safe(buf, 0));
4855
}
4956

src/openvpn/mtu.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@
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 250
67+
#define TUN_BAT_NOP 0
68+
#define TUN_BAT_ONE 1
69+
6170
/*
6271
* Default MTU of network over which tunnel data will pass by TCP/UDP.
6372
*/
@@ -157,6 +166,11 @@ struct frame
157166
* which defaults to 0 for tun and 32
158167
* (\c TAP_MTU_EXTRA_DEFAULT) for tap.
159168
* */
169+
170+
int bulk_size; /**< Configure and setup in the init library
171+
* frame function to signal and inform the various
172+
* related function calls to process bulk mode data transfers.
173+
* */
160174
};
161175

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

180195
/*
181196
* Function prototypes.

src/openvpn/mudp.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,15 @@ unsigned int
367367
p2mp_iow_flags(const struct multi_context *m)
368368
{
369369
unsigned int flags = IOW_WAIT_SIGNAL;
370-
if (m->pending)
370+
if (m->pending || m->pending2)
371371
{
372-
if (TUN_OUT(&m->pending->context))
372+
if (m->pending && LINK_OUT(&m->pending->context))
373373
{
374-
flags |= IOW_TO_TUN;
374+
flags |= IOW_TO_LINK;
375375
}
376-
if (LINK_OUT(&m->pending->context))
376+
if (m->pending2 && TUN_OUT(&m->pending2->context))
377377
{
378-
flags |= IOW_TO_LINK;
378+
flags |= IOW_TO_TUN;
379379
}
380380
}
381381
else if (mbuf_defined(m->mbuf))

0 commit comments

Comments
 (0)