@@ -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 ;
@@ -3455,6 +3460,10 @@ do_init_frame_tls(struct context *c)
34553460 if (c -> c2 .tls_multi )
34563461 {
34573462 tls_multi_init_finalize (c -> c2 .tls_multi , c -> options .ce .tls_mtu );
3463+ if (c -> c2 .frame .bulk_size > 0 )
3464+ {
3465+ c -> c2 .tls_multi -> opt .frame .buf .payload_size = c -> c2 .frame .tun_mtu ;
3466+ }
34583467 ASSERT (c -> c2 .tls_multi -> opt .frame .buf .payload_size <= c -> c2 .frame .buf .payload_size );
34593468 frame_print (& c -> c2 .tls_multi -> opt .frame , D_MTU_INFO , "Control Channel MTU parms" );
34603469
@@ -3522,6 +3531,14 @@ do_init_frame(struct context *c)
35223531 c -> c2 .frame .extra_tun += c -> options .ce .tun_mtu_extra ;
35233532 }
35243533
3534+ /*
3535+ * Adjust bulk size based on the --bulk-mode parameter.
3536+ */
3537+ if (c -> options .ce .bulk_mode )
3538+ {
3539+ c -> c2 .frame .bulk_size = c -> options .ce .tun_mtu ;
3540+ }
3541+
35253542 /*
35263543 * Fill in the blanks in the frame parameters structure,
35273544 * make sure values are rational, etc.
@@ -3662,9 +3679,45 @@ init_context_buffers(const struct frame *frame)
36623679
36633680 size_t buf_size = BUF_SIZE (frame );
36643681
3682+ if (frame -> bulk_size > 0 )
3683+ {
3684+ size_t off_size = (frame -> buf .headroom + TUN_BAT_OFF + frame -> buf .tailroom );
3685+ buf_size = BAT_SIZE (TUN_BAT_MAX , frame -> tun_mtu , off_size );
3686+ }
3687+
3688+ dmsg (M_INFO , "BULK bufs [%ld] [%d+%d+%d]" , buf_size , frame -> buf .headroom , frame -> buf .payload_size , frame -> buf .tailroom );
3689+
36653690 b -> read_link_buf = alloc_buf (buf_size );
36663691 b -> read_tun_buf = alloc_buf (buf_size );
36673692
3693+ if (frame -> bulk_size > 0 )
3694+ {
3695+ size_t off_size = (frame -> buf .headroom + TUN_BAT_OFF + frame -> buf .tailroom );
3696+ size_t one_size = BAT_SIZE (TUN_BAT_ONE , frame -> tun_mtu , off_size );
3697+
3698+ for (int x = 0 ; x < TUN_BAT_MAX ; ++ x )
3699+ {
3700+ b -> read_tun_bufs [x ] = alloc_buf (one_size );
3701+ b -> read_tun_bufs [x ].offset = TUN_BAT_OFF ;
3702+ b -> read_tun_bufs [x ].len = 0 ;
3703+ }
3704+
3705+ b -> read_tun_max = alloc_buf (buf_size );
3706+ b -> read_tun_max .offset = TUN_BAT_OFF ;
3707+ b -> read_tun_max .len = 0 ;
3708+
3709+ b -> send_tun_max = alloc_buf (buf_size );
3710+ b -> send_tun_max .offset = TUN_BAT_OFF ;
3711+ b -> send_tun_max .len = 0 ;
3712+
3713+ b -> to_tun_max = alloc_buf (buf_size );
3714+ b -> to_tun_max .offset = TUN_BAT_OFF ;
3715+ b -> to_tun_max .len = 0 ;
3716+ }
3717+
3718+ b -> bulk_indx = -1 ;
3719+ b -> bulk_leng = -1 ;
3720+
36683721 b -> aux_buf = alloc_buf (buf_size );
36693722
36703723 b -> encrypt_buf = alloc_buf (buf_size );
@@ -3687,6 +3740,17 @@ free_context_buffers(struct context_buffers *b)
36873740 free_buf (& b -> read_tun_buf );
36883741 free_buf (& b -> aux_buf );
36893742
3743+ if (b -> to_tun_max .data )
3744+ {
3745+ free_buf (& b -> to_tun_max );
3746+ free_buf (& b -> send_tun_max );
3747+ free_buf (& b -> read_tun_max );
3748+ for (int x = 0 ; x < TUN_BAT_MAX ; ++ x )
3749+ {
3750+ free_buf (& b -> read_tun_bufs [x ]);
3751+ }
3752+ }
3753+
36903754#ifdef USE_COMP
36913755 free_buf (& b -> compress_buf );
36923756 free_buf (& b -> decompress_buf );
0 commit comments