@@ -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 = BAT_SIZE (TUN_BAT_ONE , frame -> tun_mtu , TUN_BAT_OFF );
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,45 @@ 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+ size_t off_size = (frame -> buf .headroom + TUN_BAT_OFF + frame -> buf .tailroom );
3719+ size_t one_size = BAT_SIZE (TUN_BAT_ONE , frame -> tun_mtu , off_size );
3720+
3721+ for (int x = 0 ; x < TUN_BAT_MAX ; ++ x )
3722+ {
3723+ b -> read_tun_bufs [x ] = alloc_buf (one_size );
3724+ b -> read_tun_bufs [x ].offset = TUN_BAT_OFF ;
3725+ b -> read_tun_bufs [x ].len = 0 ;
3726+ }
3727+
3728+ b -> read_tun_max = alloc_buf (buf_size );
3729+ b -> read_tun_max .offset = TUN_BAT_OFF ;
3730+ b -> read_tun_max .len = 0 ;
3731+
3732+ b -> send_tun_max = alloc_buf (buf_size );
3733+ b -> send_tun_max .offset = TUN_BAT_OFF ;
3734+ b -> send_tun_max .len = 0 ;
3735+
3736+ b -> to_tun_max = alloc_buf (buf_size );
3737+ b -> to_tun_max .offset = TUN_BAT_OFF ;
3738+ b -> to_tun_max .len = 0 ;
3739+ }
3740+
3741+ b -> bulk_indx = -1 ;
3742+ b -> bulk_leng = -1 ;
3743+
36913744 b -> aux_buf = alloc_buf (buf_size );
36923745
36933746 b -> encrypt_buf = alloc_buf (buf_size );
@@ -3710,6 +3763,17 @@ free_context_buffers(struct context_buffers *b)
37103763 free_buf (& b -> read_tun_buf );
37113764 free_buf (& b -> aux_buf );
37123765
3766+ if (b -> to_tun_max .data )
3767+ {
3768+ free_buf (& b -> to_tun_max );
3769+ free_buf (& b -> send_tun_max );
3770+ free_buf (& b -> read_tun_max );
3771+ for (int x = 0 ; x < TUN_BAT_MAX ; ++ x )
3772+ {
3773+ free_buf (& b -> read_tun_bufs [x ]);
3774+ }
3775+ }
3776+
37133777#ifdef USE_COMP
37143778 free_buf (& b -> compress_buf );
37153779 free_buf (& b -> decompress_buf );
0 commit comments