Big buffer/frame refactoring patch set v3
v3 cover Big buffer/frame refactoring patch set v3
This version of the patchset adds the CBC fix to correct the CBC calculation. This patch introduces a lot of rebase conflicts and therefore the whole patchset is resent as v3.
Arne Schwabe (14):
Deprecate link-mtu
Fix mssfix and frame calculation in CBC mode
Change buffer allocation calculation and checks to be more static Fix datagram_overhead and assorted functions
Implement optional mtu parameter for mssfix
Update fragment and mssfix related warnings
Change the default for mssfix to mssfix 1492 mtu
Remove link_mtu parameter when running up/down scripts Add mtu paramter to --fragment and change fragment calculation Use new frame header methods to calculate OCC_MTU_LOAD payload size Remove extra_link from frame
Replace TUN_MTU_SIZE with frame->tun_mtu
Remove frame->link_mtu
Remove frame.extra_frame and frame.extra_buffer
Changes.rst | 9 + doc/man-sections/link-options.rst | 65 ++++-- src/openvpn/comp-lz4.c | 4 +- src/openvpn/comp.c | 15 -- src/openvpn/comp.h | 4 - src/openvpn/crypto.c | 59 +----- src/openvpn/crypto.h | 14 +- src/openvpn/forward.c | 25 +-- src/openvpn/fragment.c | 7 +- src/openvpn/init.c | 274 ++++++++++++------------- src/openvpn/integer.h | 9 + src/openvpn/lzo.c | 2 +- src/openvpn/mss.c | 159 ++++++++++++-- src/openvpn/mss.h | 12 +- src/openvpn/mtu.c | 143 +++++-------- src/openvpn/mtu.h | 204 +++++++----------- src/openvpn/multi.c | 7 +- src/openvpn/multi.h | 2 +- src/openvpn/occ.c | 33 ++- src/openvpn/options.c | 85 +++++--- src/openvpn/options.h | 6 +- src/openvpn/ping.c | 2 +- src/openvpn/reliable.c | 7 - src/openvpn/reliable.h | 3 - src/openvpn/socket.c | 31 --- src/openvpn/socket.h | 19 +- src/openvpn/socks.c | 11 +- src/openvpn/socks.h | 2 - src/openvpn/ssl.c | 89 +++----- src/openvpn/ssl.h | 10 +- src/openvpn/ssl_common.h | 3 +- src/openvpn/tls_crypt.c | 10 - src/openvpn/tls_crypt.h | 5 - tests/unit_tests/openvpn/test_crypto.c | 86 +++++++- 34 files changed, 733 insertions(+), 683 deletions(-)
Signature · 1 line
2.33.0
PATCH v3 1/14 Deprecate link-mtu
This options might have been useful in the past but nowadays it has a very unclear semantics, so better remove/deprecate it.
--- doc/man-sections/link-options.rst | 7 ++++++- src/openvpn/options.c | 4 +--- 2 files changed, 7 insertions(+), 4 deletions(-)
doc/man-sections/link-options.rst +6 -1
@@ -82,10 +82,15 @@ the local and the remote host. ping-restart 60 # Argument: timeout --link-mtu n - Sets an upper bound on the size of UDP packets which are sent between + **DEPRECATED** Sets an upper bound on the size of UDP packets which are sent between OpenVPN peers. *It's best not to set this parameter unless you know what you're doing.* + Due to variable header size of IP header (20 bytes for IPv4 and 40 bytes + for IPv6) and dynamically negotiated data channel cipher, this option + is not reliable. It is recommended to set tun-mtu with enough headroom + instead. + --local host Local host name or IP address for bind. If specified, OpenVPN will bind to this address only. If unspecified, OpenVPN will bind to all
src/openvpn/options.c +1 -3
@@ -2111,9 +2111,7 @@ options_postprocess_verify_ce(const struct options *options,*/ if (options->ce.tun_mtu_defined && options->ce.link_mtu_defined) { -msg (M_USAGE , -"only one of --tun-mtu or --link-mtu may be defined (note that " -"--ifconfig implies --link-mtu %d)" ,LINK_MTU_DEFAULT ); +msg (M_USAGE ,"only one of --tun-mtu or --link-mtu may be defined" ); }if (!proto_is_udp (ce->proto) && options->mtu_test)
Signature · 1 line
2.33.0
PATCH v3 2/14 Fix mssfix and frame calculation in CBC mode
In reply to Arne SchwabeThis commit fixes the MSS calculation in CBC mode. This fix has two parts:
- Added rounding to a multiple of block size during calculation of overhead
- In CBC mode the packet ID is part of the plaintext (or payload) rather than part of the header (like for AEAD), adjust the functions to correctly reflect this.
OCC link calculation is not affected since it ignores rounding of CBC block size completely.
--- src/openvpn/crypto.c | 18 ++---- src/openvpn/crypto.h | 14 ++--- src/openvpn/integer.h | 9 +++ src/openvpn/mss.c | 40 +++++++++--- src/openvpn/mtu.c | 59 +++++++++++++----- src/openvpn/mtu.h | 39 +++++++----- tests/unit_tests/openvpn/test_crypto.c | 86 +++++++++++++++++++++++++- 7 files changed, 203 insertions(+), 62 deletions(-)
src/openvpn/crypto.c +6 -12
@@ -209,7 +209,7 @@ openvpn_encrypt_v1(struct buffer *buf, struct buffer work,ASSERT (0 ); } -/* set the IV pseudo-randomly */ +/* write the pseudo-randomly IV (CBC)/packet ID (OFB/CFB) */ ASSERT (buf_write (&work, iv_buf, iv_size));dmsg (D_PACKET_CONTENT ,"ENCRYPT IV: %s" ,format_hex (iv_buf, iv_size,0 , &gc));
@@ -669,17 +669,15 @@ openvpn_decrypt(struct buffer *buf, struct buffer work,unsigned int calculate_crypto_overhead (const struct key_type *kt, -bool packet_id, -bool packet_id_long_form, -unsigned int payload_size, +unsigned int pkt_id_size,bool occ) {unsigned int crypto_overhead =0 ; -/* We always have a packet id, no matter if encrypted or unencrypted */ -if (packet_id) +if (!cipher_kt_mode_cbc (kt->cipher)) { - crypto_overhead +=packet_id_size (packet_id_long_form); +/* In CBC mode, the packet id is part of the payload size/overhead */ + crypto_overhead += pkt_id_size; }if (cipher_kt_mode_aead (kt->cipher))
@@ -702,11 +700,7 @@ calculate_crypto_overhead(const struct key_type *kt,if (cipher_defined (kt->cipher)) {/* CBC, OFB or CFB mode */ -/* This is a worst case upper bound of needing to add -* a full extra block for padding when the payload -* is exactly a multiple of the block size */ -if (occ || (cipher_kt_mode_cbc (kt->cipher) && - (payload_size %cipher_kt_block_size (kt->cipher) ==0 ))) +if (occ) { crypto_overhead +=cipher_kt_block_size (kt->cipher); }
src/openvpn/crypto.h +7 -7
@@ -418,20 +418,20 @@ void crypto_adjust_frame_parameters(struct frame *frame,/** Calculate the maximum overhead that our encryption has * on a packet. This does not include needed additional buffer size * +* This does NOT include the padding and rounding of CBC size +* as the users (mssfix/fragment) of this function need to adjust for +* this and add it themselves. +* * @param kt Struct with the crypto algorithm to use -* @param packet_id Whether packet_id is used -* @param packet_id_long_form Whether the packet id has the long form -* @param payload_size payload size, only used if occ is false +* @param packet_id_size Size of the packet id, can be 0 if no-replay is used * @param occ if true calculates the overhead for crypto in the same * incorrect way as all previous OpenVPN versions did, to * end up with identical numbers for OCC compatibility */ unsigned int calculate_crypto_overhead (const struct key_type *kt, -bool packet_id, -bool packet_id_long_form, -unsigned int payload_size, -bool occ); +unsigned int pkt_id_size, +bool occ);/** Return the worst-case OpenVPN crypto overhead (in bytes) */ unsigned int crypto_max_overhead (void );
src/openvpn/integer.h +9 -0
@@ -185,4 +185,13 @@ index_verify(int index, int size, const char *file, int line) return index; } +/** +* Rounds down num to the nearest multiple of multiple +*/ +static inline unsigned int +round_down_uint (unsigned int num,unsigned int multiple) +{ +return (num / multiple) * multiple; +} +#endif /* ifndef INTEGER_H */
src/openvpn/mss.c +30 -10
@@ -207,6 +207,26 @@ mss_fixup_dowork(struct buffer *buf, uint16_t maxmss) } } +static inline unsigned int +adjust_payload_max_cbc (const struct key_type *kt,unsigned int target) +{ +if (!cipher_kt_mode_cbc (kt->cipher)) + { +/* With stream ciphers (or block cipher in stream modes like CFB, AEAD) +* we can just subtract use the target as is */ +return target; + } +else + { +/* With CBC we need at least one extra byte for padding and then need +* to ensure that the resulting CBC ciphertext length, which is always +* a multiple of the block size, is not larger than the target value */ +unsigned int block_size =cipher_kt_block_size (kt->cipher); + target =round_down_uint (target, block_size); +return target -1 ; + } +} +void frame_calculate_mssfix (struct frame *frame,struct key_type *kt,const struct options *options)
@@ -216,18 +236,13 @@ frame_calculate_mssfix(struct frame *frame, struct key_type *kt,return ; } -unsigned int payload_size; -unsigned int overhead; - - - payload_size =frame_calculate_payload_size (frame, options); +unsigned int overhead, payload_overhead; - overhead =frame_calculate_protocol_header_size (kt, options, - payload_size, false); + overhead =frame_calculate_protocol_header_size (kt, options, false);/* Calculate the number of bytes that the payload differs from the payload * MTU. This are fragment/compression/ethernet headers */ -unsigned payload_overhead =frame_calculate_payload_overhead (frame, options, true); + payload_overhead =frame_calculate_payload_overhead (frame, options, kt, true);/* We are in a "liberal" position with respect to MSS, * i.e. we assume that MSS can be calculated from MTU
@@ -238,9 +253,14 @@ frame_calculate_mssfix(struct frame *frame, struct key_type *kt,/* Add 20 bytes for the IPv4 header and 20 byte for the TCP header of the * payload, the mssfix method will add 20 extra if payload is IPv6 */ - overhead +=20 +20 ; + payload_overhead +=20 +20 ;/* Calculate the maximum MSS value from the max link layer size specified * by ce.mssfix */ - frame->mss_fix = options->ce.mssfix - overhead - payload_overhead; + +/* This is the target value our payload needs to be smaller */ +unsigned int target = options->ce.mssfix - overhead; + frame->mss_fix =adjust_payload_max_cbc (kt, target) - payload_overhead; + + }
src/openvpn/mtu.c +44 -15
119 lines not on this page · raw message
src/openvpn/mtu.h +22 -17
@@ -226,19 +226,22 @@ void set_mtu_discover_type(socket_descriptor_t sd, int mtu_type, sa_family_t proint translate_mtu_discover_type_name (const char *name); +/* forward declaration of key_type */ +struct key_type ; +/** -* Calculates the size of the payload according to tun-mtu and tap overhead. -* This also includes compression and fragmentation overhead if they are -* enabled. +* Calculates the size of the payload according to tun-mtu and tap overhead. In +* this context payload is identical to the size of the plaintext. +* This also includes compression, fragmentation overhead, and packet id in CBC +* mode if these options are used. +* * * * [IP][UDP][OPENVPN PROTOCOL HEADER][ **PAYLOAD incl compression header** ] -* @param frame -* @param options -* @return */ size_t frame_calculate_payload_size (const struct frame *frame, -const struct options *options); +const struct options *options, +const struct key_type *kt);/** * Calculates the size of the payload overhead according to tun-mtu and
@@ -247,37 +250,39 @@ frame_calculate_payload_size(const struct frame *frame,* are considered part of this overhead that increases the payload larger than * tun-mtu. * +* In CBC mode, the IV is part of the payload instead of part of the OpenVPN +* protocol header and is included in the returned value. +* +* In this context payload is identical to the size of the plaintext and this +* method can be also understand as number of bytes that are added to the +* plaintext before encryption. +* * * [IP][UDP][OPENVPN PROTOCOL HEADER][ **PAYLOAD incl compression header** ] -* @param frame -* @param options -* @param extra_tun -* @return */ size_t frame_calculate_payload_overhead (const struct frame *frame,const struct options *options, +const struct key_type *kt,bool extra_tun); -/* forward declaration of key_type */ -struct key_type ; -/** * Calculates the size of the OpenVPN protocol header. This includes * the crypto IV/tag/HMAC but does not include the IP encapsulation * +* This does NOT include the padding and rounding of CBC size +* as the users (mssfix/fragment) of this function need to adjust for +* this and add it themselves. * * [IP][UDP][ **OPENVPN PROTOCOL HEADER**][PAYLOAD incl compression header] * * @param kt the key_type to use to calculate the crypto overhead * @param options the options struct to be used to calculate -* @param payload_size the payload size, ignored if occ is true -* @param occ if the calculation should be done for occ compatibility +* @param occ Use the calculation for the OCC link-mtu * @return size of the overhead in bytes */ size_t frame_calculate_protocol_header_size (const struct key_type *kt,const struct options *options, -unsigned int payload_size,bool occ);/**
tests/unit_tests/openvpn/test_crypto.c +85 -1
104 lines not on this page · raw message
Signature · 1 line
2.33.0
PATCH v3 3/14 Change buffer allocation calculation and checks to be more static
In reply to Arne SchwabeCurrently we use half dynamic buffer sizes where we use have a fixed overhead for crypto (crypto_max_overhead) but use a dynamic overhead for the the other small header sizes.
--- src/openvpn/comp-lz4.c | 4 +- src/openvpn/crypto.c | 4 +- src/openvpn/forward.c | 8 +-- src/openvpn/init.c | 107 +++++++++++++++++++++++++++++++++++---- src/openvpn/lzo.c | 2 +- src/openvpn/mtu.c | 7 ++- src/openvpn/mtu.h | 74 ++++++++++++++------------- src/openvpn/multi.c | 4 +- src/openvpn/multi.h | 2 +- src/openvpn/occ.c | 4 +- src/openvpn/options.c | 2 +- src/openvpn/ping.c | 2 +- src/openvpn/ssl.c | 35 ++++++++++--- src/openvpn/ssl_common.h | 3 +- 14 files changed, 187 insertions(+), 71 deletions(-)
src/openvpn/comp-lz4.c +2 -2
@@ -213,7 +213,7 @@ lz4_decompress(struct buffer *buf, struct buffer work,struct compress_context *compctx, const struct frame *frame) { - size_t zlen_max = EXPANDED_SIZE(frame); + size_t zlen_max = frame->buf.payload_size;uint8_t c;/* flag indicating whether or not our peer compressed */ if (buf->len <=0 )
@@ -250,7 +250,7 @@ lz4v2_decompress(struct buffer *buf, struct buffer work,struct compress_context *compctx, const struct frame *frame) { - size_t zlen_max = EXPANDED_SIZE(frame); + size_t zlen_max = frame->buf.payload_size;uint8_t c;/* flag indicating whether or not our peer compressed */ if (buf->len <=0 )
src/openvpn/crypto.c +2 -2
@@ -1064,7 +1064,7 @@ test_crypto(struct crypto_options *co, struct frame *frame) {int i, j;struct gc_arena gc =gc_new (); -struct buffer src =alloc_buf_gc (TUN_MTU_SIZE (frame), &gc); +struct buffer src =alloc_buf_gc (frame->buf.payload_size, &gc);struct buffer work =alloc_buf_gc (BUF_SIZE (frame), &gc);struct buffer encrypt_workspace =alloc_buf_gc (BUF_SIZE (frame), &gc);struct buffer decrypt_workspace =alloc_buf_gc (BUF_SIZE (frame), &gc);
@@ -1095,7 +1095,7 @@ test_crypto(struct crypto_options *co, struct frame *frame) }msg (M_INFO ,"Entering " PACKAGE_NAME " crypto self-test mode." ); -for (i =1 ; i <=TUN_MTU_SIZE (frame); ++i) +for (i =1 ; i <= frame->buf.payload_size; ++i) {update_time ();
src/openvpn/forward.c +4 -4
@@ -1119,8 +1119,8 @@ read_incoming_tun(struct context *c) }#else /* ifdef _WIN32 */ ASSERT (buf_init (&c->c2.buf,FRAME_HEADROOM (&c->c2.frame))); -ASSERT (buf_safe (&c->c2.buf,MAX_RW_SIZE_TUN (&c->c2.frame))); - c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf),MAX_RW_SIZE_TUN (&c->c2.frame)); +ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size)); + c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size);#endif /* ifdef _WIN32 */ #ifdef PACKET_TRUNCATION_CHECK
@@ -1709,7 +1709,7 @@ process_outgoing_tun(struct context *c)PIP_MSSFIX |PIPV4_EXTRACT_DHCP_ROUTER |PIPV4_CLIENT_NAT |PIP_OUTGOING , &c->c2.to_tun); -if (c->c2.to_tun.len <=MAX_RW_SIZE_TUN (&c->c2.frame)) +if (c->c2.to_tun.len <= c->c2.frame.buf.payload_size) {/* * Write to TUN/TAP device.
@@ -1769,7 +1769,7 @@ process_outgoing_tun(struct context *c)*/ msg (D_LINK_ERRORS ,"tun packet too large on write (tried=%d,max=%d)" , c->c2.to_tun.len, -MAX_RW_SIZE_TUN (&c->c2.frame)); + c->c2.frame.buf.payload_size); }buf_reset (&c->c2.to_tun);
src/openvpn/init.c +97 -10
139 lines not on this page · raw message
src/openvpn/lzo.c +1 -1
@@ -213,7 +213,7 @@ lzo_decompress(struct buffer *buf, struct buffer work,struct compress_context *compctx, const struct frame *frame) { - lzo_uint zlen = EXPANDED_SIZE(frame); + lzo_uint zlen = frame->buf.payload_size;int err;uint8_t c;/* flag indicating whether or not our peer compressed */
src/openvpn/mtu.c +6 -1
@@ -48,7 +48,7 @@ alloc_buf_sock_tun(struct buffer *buf,/* allocate buffer for overlapped I/O */ *buf =alloc_buf (BUF_SIZE (frame));ASSERT (buf_init (buf,FRAME_HEADROOM (frame))); - buf->len = tuntap_buffer ?MAX_RW_SIZE_TUN (frame) :MAX_RW_SIZE_LINK (frame); + buf->len = frame->buf.payload_size;ASSERT (buf_safe (buf,0 )); }
@@ -296,6 +296,11 @@ frame_print(const struct frame *frame,buf_printf (&out,"%s " , prefix); }buf_printf (&out,"[" ); +buf_printf (&out," mss_fix:%d" , frame->mss_fix); +buf_printf (&out," tun_mtu:%d" , frame->tun_mtu); +buf_printf (&out," headroom:%d" , frame->buf.headroom); +buf_printf (&out," payload:%d" , frame->buf.payload_size); +buf_printf (&out," tailroom:%d" , frame->buf.tailroom);buf_printf (&out," L:%d" , frame->link_mtu);buf_printf (&out," D:%d" , frame->link_mtu_dynamic);buf_printf (&out," EF:%d" , frame->extra_frame);
src/openvpn/mtu.h +39 -35
121 lines not on this page · raw message
src/openvpn/multi.c +2 -2
@@ -3495,7 +3495,7 @@ gremlin_flood_clients(struct multi_context *m)int i;ASSERT (buf_init (&buf,FRAME_HEADROOM (&m->top.c2.frame))); - parm.packet_size =min_int (parm.packet_size,MAX_RW_SIZE_TUN (&m->top.c2.frame)); + parm.packet_size =min_int (parm.packet_size, m->top.c2.frame.buf.payload_size); msg(D_GREMLIN, "GREMLIN_FLOOD_CLIENTS: flooding clients with %d packets of size %d", parm.n_packets,
@@ -3557,7 +3557,7 @@ multi_process_per_second_timers_dowork(struct multi_context *m) }void -multi_top_init (struct multi_context *m,const struct context *top) +multi_top_init (struct multi_context *m,struct context *top) {inherit_context_top (&m->top, top); m->top.c2.buffers =init_context_buffers (&top->c2.frame);
src/openvpn/multi.h +1 -1
@@ -257,7 +257,7 @@ void multi_init(struct multi_context *m, struct context *t, bool tcp_mode);void multi_uninit (struct multi_context *m); -void multi_top_init (struct multi_context *m,const struct context *top); +void multi_top_init (struct multi_context *m,struct context *top);void multi_top_free (struct multi_context *m);
src/openvpn/occ.c +2 -2
@@ -219,7 +219,7 @@ check_send_occ_msg_dowork(struct context *c) c->c2.buf = c->c2.buffers->aux_buf;ASSERT (buf_init (&c->c2.buf,FRAME_HEADROOM (&c->c2.frame))); -ASSERT (buf_safe (&c->c2.buf,MAX_RW_SIZE_TUN (&c->c2.frame))); +ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size));ASSERT (buf_write (&c->c2.buf, occ_magic,OCC_STRING_SIZE )); switch (c->c2.occ_op)
@@ -319,7 +319,7 @@ check_send_occ_msg_dowork(struct context *c)OCC_STRING_SIZE , (int )sizeof (uint8_t ),EXTRA_FRAME (&c->c2.frame), -MAX_RW_SIZE_TUN (&c->c2.frame), + c->c2.frame.buf.payload_size, BLEN(&c->c2.buf)); doit = true; }
src/openvpn/options.c +1 -1
@@ -3832,7 +3832,7 @@ options_string(const struct options *o,buf_printf (&out,",link-mtu %u" , (unsigned int )calc_options_string_link_mtu (o, frame)); -buf_printf (&out,",tun-mtu %d" ,PAYLOAD_SIZE (frame)); +buf_printf (&out,",tun-mtu %d" , frame->tun_mtu);buf_printf (&out,",proto %s" ,proto_remote (o->ce.proto, remote));bool p2p_nopull = o->mode ==MODE_POINT_TO_POINT && !PULL_DEFINED (o);
src/openvpn/ping.c +1 -1
@@ -80,7 +80,7 @@ check_ping_send_dowork(struct context *c) { c->c2.buf = c->c2.buffers->aux_buf;ASSERT (buf_init (&c->c2.buf,FRAME_HEADROOM (&c->c2.frame))); -ASSERT (buf_safe (&c->c2.buf,MAX_RW_SIZE_TUN (&c->c2.frame))); +ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size));ASSERT (buf_write (&c->c2.buf, ping_string,sizeof (ping_string)));/*
src/openvpn/ssl.c +27 -8
@@ -332,6 +332,32 @@ tls_init_control_channel_frame_parameters(const struct frame *data_channel_frame/* set dynamic link MTU to cap control channel packets at 1250 bytes */ ASSERT (TUN_LINK_DELTA (frame) <min_int (frame->link_mtu,1250 )); frame->link_mtu_dynamic =min_int (frame->link_mtu,1250 ) -TUN_LINK_DELTA (frame); + +/* calculate the maximum overhead that control channel frames may have */ +int overhead =0 ; + +/* Socks */ + overhead +=10 ; + +/* tls-auth and tls-crypt */ + overhead +=max_int (tls_crypt_buf_overhead (), +packet_id_size (true) +OPENVPN_MAX_HMAC_SIZE ); + +/* TCP length field and opcode */ + overhead+=3 ; + +/* Previous OpenVPN version calculated the maximum size and buffer of a +* control frame depending on the overhead of the data channel frame +* overhead and limited its maximum size to 1250. We always allocate the +* 1250 buffer size since a lot of code blindly assumes a large buffer +* (e.g. PUSH_BUNDLE_SIZE) and set frame->mtu_mtu as suggestion for the +* size */ + frame->buf.payload_size =1250 + overhead; + + frame->buf.headroom = overhead; + frame->buf.tailroom = overhead; + + frame->tun_mtu =min_int (data_channel_frame->tun_mtu,1250 ); }void
@@ -1870,13 +1896,6 @@ tls_session_update_crypto_params_do_work(struct tls_session *session,msg (D_HANDSHAKE ,"Data Channel: using negotiated cipher '%s'" , options->ciphername); } -else - { -/* Very hacky workaround and quick fix for frame calculation -* different when adjusting frame size when the original and new cipher -* are identical to avoid a regression with client without NCP */ -return tls_session_generate_data_channel_keys (session); - }init_key_type (&session->opt->key_type, options->ciphername, options->authname, true, true);
@@ -2959,7 +2978,7 @@ tls_process(struct tls_multi *multi, buf =reliable_get_buf_output_sequenced (ks->send_reliable);if (buf) { -int status =key_state_read_ciphertext (&ks->ks_ssl, buf,PAYLOAD_SIZE_DYNAMIC (&multi->opt.frame)); +int status =key_state_read_ciphertext (&ks->ks_ssl, buf, multi->opt.frame.tun_mtu);if (status ==-1 ) { msg(D_TLS_ERRORS,
src/openvpn/ssl_common.h +2 -1
@@ -221,8 +221,9 @@ struct key_statestruct reliable *rec_reliable;/* order incoming ciphertext packets before we pass to TLS */ struct reliable_ack *rec_ack;/* buffers all packet IDs we want to ACK back to sender */ +/** Holds outgoing message for the control channel until ks->state reaches +* S_ACTIVE */ struct buffer_list *paybuf; -counter_type n_bytes;/* how many bytes sent/recvd since last key exchange */ counter_type n_packets;/* how many packets sent/recvd since last key exchange */
Signature · 1 line
2.33.0
PATCH v3 4/14 Fix datagram_overhead and assorted functions
In reply to Arne SchwabeThis function is supposed to calculate the overhead of the protocol header (IP/IPv6 + TCP/UDP). But at some point the index that used to index the array proto_overhead and the associated PROTO_N went completely out of sync. This fixed the function and related caller to again calculate the overhead as intended.
Note that IPv6 mapped IPv4 addresses still have the wrong overhead calculated as they treated as IPv6 addresses (0:0:0:0:0:ffff::/96)
--- src/openvpn/forward.c | 10 ++++++---- src/openvpn/socket.c | 16 +++------------- src/openvpn/socket.h | 17 ++++++----------- 3 files changed, 15 insertions(+), 28 deletions(-)
src/openvpn/forward.c +6 -4
@@ -480,10 +480,10 @@ check_fragment(struct context *c)struct link_socket_info *lsi =get_link_socket_info (c);/* OS MTU Hint? */ -if (lsi->mtu_changed) +if (lsi->mtu_changed && lsi->lsa) {frame_adjust_path_mtu (&c->c2.frame_fragment, c->c2.link_socket->mtu, - c->options.ce.proto); + lsi->lsa->actual.dest.addr.sa.sa_family, lsi->proto); lsi->mtu_changed = false; }
@@ -1565,8 +1565,10 @@ process_outgoing_link(struct context *c)*/ if (c->options.shaper) { -shaper_wrote_bytes (&c->c2.shaper,BLEN (&c->c2.to_link) - +datagram_overhead (c->options.ce.proto)); +int overhead =datagram_overhead (c->c2.to_link_addr->dest.addr.sa.sa_family, + c->options.ce.proto); +shaper_wrote_bytes (&c->c2.shaper, +BLEN (&c->c2.to_link) + overhead); }/*
src/openvpn/socket.c +3 -13
@@ -44,17 +44,6 @@#include "memdbg.h" -const int proto_overhead[] = {/* indexed by PROTO_x */ -0 , - IPv4_UDP_HEADER_SIZE,/* IPv4 */ - IPv4_TCP_HEADER_SIZE, - IPv4_TCP_HEADER_SIZE, - IPv6_UDP_HEADER_SIZE,/* IPv6 */ - IPv6_TCP_HEADER_SIZE, - IPv6_TCP_HEADER_SIZE, - IPv6_TCP_HEADER_SIZE, -}; -/* * Convert sockflags/getaddr_flags into getaddr_flags */
@@ -1660,9 +1649,10 @@ socket_frame_init(const struct frame *frame, struct link_socket *sock)* to us by the OS. */ void -frame_adjust_path_mtu (struct frame *frame,int pmtu,int proto) +frame_adjust_path_mtu (struct frame *frame,int pmtu,sa_family_t af,int proto) { -frame_set_mtu_dynamic (frame, pmtu -datagram_overhead (proto),SET_MTU_UPPER_BOUND ); +frame_set_mtu_dynamic (frame, pmtu -datagram_overhead (af, proto), +SET_MTU_UPPER_BOUND ); } static void
src/openvpn/socket.h +6 -11
@@ -300,7 +300,7 @@ void do_preresolve(struct context *c);void socket_adjust_frame_parameters (struct frame *frame,int proto); -void frame_adjust_path_mtu (struct frame *frame,int pmtu,int proto); +void frame_adjust_path_mtu (struct frame *frame,int pmtu,sa_family_t af,int proto);void link_socket_close (struct link_socket *sock);
@@ -579,18 +579,13 @@ const char *addr_family_name(int af);/* * Overhead added to packets by various protocols. */ -#define IPv4_UDP_HEADER_SIZE 28 -#define IPv4_TCP_HEADER_SIZE 40 -#define IPv6_UDP_HEADER_SIZE 48 -#define IPv6_TCP_HEADER_SIZE 60 - -extern const int proto_overhead[]; -static inline int -datagram_overhead (int proto) +datagram_overhead (sa_family_t af,int proto) { -ASSERT (proto >=0 && proto <PROTO_N ); -return proto_overhead [proto]; +int overhead =0 ; + overhead += (proto ==PROTO_UDP ) ?8 :20 ; + overhead += (af ==AF_INET ) ?20 :40 ; +return overhead; }/*
Signature · 1 line
2.33.0
PATCH v3 5/14 Implement optional mtu parameter for mssfix
In reply to Arne SchwabeThe current mssfix parameter is a bit as it needs manual calculation of the allowable packet size and also the resulting MSS value does not take into account if IPv4 or IPv6 is used on the outer tunnel. The mtu parameter fixes both of these problem by dynamically including the real overhead.
The syntax and naming of the parater is chosen for compatiblity with OpenVPN3.
Patch V2: document mssfix 0 disabling mssfix, fix rst syntax
--- Changes.rst | 6 ++++ doc/man-sections/link-options.rst | 38 +++++++++++++++++++------- src/openvpn/init.c | 7 +++-- src/openvpn/mss.c | 29 +++++++++++++++++++- src/openvpn/mss.h | 3 +- src/openvpn/multi.c | 3 +- src/openvpn/options.c | 13 +++++++-- src/openvpn/options.h | 2 ++ src/openvpn/ssl.c | 11 +++++--- src/openvpn/ssl.h | 5 +++- tests/unit_tests/openvpn/test_crypto.c | 8 +++--- 11 files changed, 98 insertions(+), 27 deletions(-)
Changes.rst +6 -0
@@ -62,6 +62,12 @@ Optional ciphers in ``--data-ciphers`` Ciphers in ``--data-ciphers`` can now be prefixed with a ``?`` to mark those as optional and only use them if the SSL library supports them. + +Improved ``--mssfix`` calculation + The ``--mssfix`` option now allows an optional :code:`mtu` parameter to specify + that different overhead for IPv4/IPv6 should taken into account and the resulting + size is specified as the total size of the VPN packets including IP and UDP headers. + Deprecated features ------------------- ``inetd`` has been removed
doc/man-sections/link-options.rst +28 -10
@@ -110,19 +110,37 @@ the local and the remote host. (:code:`p2p`). OpenVPN 2.0 introduces a new mode (:code:`server`) which implements a multi-client server capability. ---mssfix max +--mssfix args + + Valid syntax: + :: + + mssfix max [mtu] + + mssfix + Announce to TCP sessions running over the tunnel that they should limit their send packet sizes such that after OpenVPN has encapsulated them, the resulting UDP packet size that OpenVPN sends to its peer will not - exceed ``max`` bytes. The default value is :code:`1450`. - - The ``max`` parameter is interpreted in the same way as the - ``--link-mtu`` parameter, i.e. the UDP packet size after encapsulation - overhead has been added in, but not including the UDP header itself. - Resulting packet would be at most 28 bytes larger for IPv4 and 48 bytes - for IPv6 (20/40 bytes for IP header and 8 bytes for UDP header). Default - value of 1450 allows IPv4 packets to be transmitted over a link with MTU - 1473 or higher without IP level fragmentation. + exceed ``max`` bytes. The default value is :code:`1450`. Use :code:`0` + as max to disable mssfix. + + If the :code:`mtu` parameter is specified the ``max`` value is interpreted + as the resulting packet size of VPN packets including the IP and UDP header. + Support for the :code:`mtu` parameter was added with OpenVPN version 2.6.0. + + If the :code:`mtu` parameter is not specified, the ``max`` parameter + is interpreted in the same way as the ``--link-mtu`` parameter, i.e. + the UDP packet size after encapsulation overhead has been added in, but + not including the UDP header itself. Resulting packet would be at most 28 + bytes larger for IPv4 and 48 bytes for IPv6 (20/40 bytes for IP header and + 8 bytes for UDP header). Default value of 1450 allows IPv4 packets to be + transmitted over a link with MTU 1473 or higher without IP level + fragmentation. + + if ``--mssfix`` is specified is specified without any parameter it + inherits the parameters of ``--fragment`` if specified or uses the + default for ``--mssfix`` otherwise. The ``--mssfix`` option only makes sense when you are using the UDP protocol for OpenVPN peer-to-peer communication, i.e. ``--proto udp``.
src/openvpn/init.c +4 -3
@@ -2271,7 +2271,7 @@ do_deferred_p2p_ncp(struct context *c)#endif if (!tls_session_update_crypto_params (session, &c->options, &c->c2.frame, - frame_fragment)) + frame_fragment,get_link_socket_info (c))) {msg (D_TLS_ERRORS ,"ERROR: failed to set crypto cipher" );return false;
@@ -2386,7 +2386,7 @@ do_deferred_options(struct context *c, const unsigned int found)struct tls_session *session = &c->c2.tls_multi->session[TM_ACTIVE ];if (!tls_session_update_crypto_params (session, &c->options, &c->c2.frame, - frame_fragment)) + frame_fragment,get_link_socket_info (c))) {msg (D_TLS_ERRORS ,"OPTIONS ERROR: failed to import crypto options" );return false;
@@ -4302,7 +4302,8 @@ init_instance(struct context *c, const struct env_set *env, const unsigned int f#endif /* initialize dynamic MTU variable */ -frame_calculate_mssfix (&c->c2.frame, &c->c1.ks.key_type, &c->options); +frame_calculate_mssfix (&c->c2.frame, &c->c1.ks.key_type, &c->options, +get_link_socket_info (c));/* bind the TCP/UDP socket */ if (c->mode ==CM_P2P || c->mode ==CM_TOP || c->mode ==CM_CHILD_TCP )
src/openvpn/mss.c +28 -1
@@ -227,9 +227,30 @@ adjust_payload_max_cbc(const struct key_type *kt, unsigned int target) } } +static unsigned int +get_ip_encap_overhead (const struct options *options, +const struct link_socket_info *lsi) +{ +/* Add the overhead of the encapsulating IP packets */ +sa_family_t af; +if (lsi->lsa) + { + af = lsi->lsa->actual.dest.addr.sa.sa_family; + } +else + { +/* In the early init before the connection is established or we +* are in listen mode we can only make an educated guess +* from the af of the connection entry */ + af = options->ce.af; + } +return datagram_overhead (af, lsi->proto); +} +void frame_calculate_mssfix (struct frame *frame,struct key_type *kt, -const struct options *options) +const struct options *options, +struct link_socket_info *lsi) {if (options->ce.mssfix ==0 ) {
@@ -251,6 +272,12 @@ frame_calculate_mssfix(struct frame *frame, struct key_type *kt,* * (RFC 879, section 7). */ +if (options->ce.mssfix_encap) + { +/* Add the overhead of the encapsulating IP packets */ + overhead +=get_ip_encap_overhead (options, lsi); + } +/* Add 20 bytes for the IPv4 header and 20 byte for the TCP header of the * payload, the mssfix method will add 20 extra if payload is IPv6 */ payload_overhead +=20 +20 ;
src/openvpn/mss.h +2 -1
@@ -37,6 +37,7 @@ void mss_fixup_dowork(struct buffer *buf, uint16_t maxmss);/** Set the --mssfix option. */ void frame_calculate_mssfix (struct frame *frame,struct key_type *kt, -const struct options *options); +const struct options *options, +struct link_socket_info *lsi);#endif
src/openvpn/multi.c +2 -1
@@ -2286,7 +2286,8 @@ multi_client_generate_tls_keys(struct context *c)#endif struct tls_session *session = &c->c2.tls_multi->session[TM_ACTIVE ];if (!tls_session_update_crypto_params (session, &c->options, - &c->c2.frame, frame_fragment)) + &c->c2.frame, frame_fragment, +get_link_socket_info (c))) {msg (D_TLS_ERRORS ,"TLS Error: initializing data channel failed" );register_signal (c,SIGUSR1 ,"process-push-msg-failed" );
src/openvpn/options.c +11 -2
@@ -6771,18 +6771,27 @@ add_option(struct options *options,VERIFY_PERMISSION (OPT_P_GENERAL );script_security_set (atoi (p[1 ])); } -else if (streq (p[0 ],"mssfix" ) && !p[2 ]) +else if (streq (p[0 ],"mssfix" ) && !p[3 ]) {VERIFY_PERMISSION (OPT_P_GENERAL |OPT_P_CONNECTION );if (p[1 ]) { options->ce.mssfix =positive_atoi (p[1 ]); } -else + +if (!p[1 ]) { options->ce.mssfix_default = true; } +if (p[2 ] &&streq (p[2 ],"mtu" )) + { + options->ce.mssfix_encap = true; + } +else if (p[2 ]) + { +msg (msglevel,"Unknown parameter to --mssfix: %s" , p[2 ]); + } }else if (streq (p[0 ],"disable-occ" ) && !p[1 ]) {
src/openvpn/options.h +2 -0
@@ -127,6 +127,8 @@ struct connection_entryint fragment;/* internal fragmentation size */ int mssfix;/* Upper bound on TCP MSS */ bool mssfix_default;/* true if --mssfix was supplied without a parameter */ +bool mssfix_encap;/* true if --mssfix had the "mtu" parameter to include +* overhead from IP and TCP/UDP encapsulation */ int explicit_exit_notification;/* Explicitly tell peer when we are exiting via OCC_EXIT or [RESTART] message */
src/openvpn/ssl.c +7 -4
@@ -1883,7 +1883,8 @@ cleanup:bool tls_session_update_crypto_params_do_work (struct tls_session *session,struct options * options,struct frame *frame, -struct frame *frame_fragment) +struct frame *frame_fragment, +struct link_socket_info *lsi) {if (session->key[KS_PRIMARY ].crypto_options.key_ctx_bi.initialized) {
@@ -1913,7 +1914,7 @@ tls_session_update_crypto_params_do_work(struct tls_session *session, options->replay, packet_id_long_form);frame_finalize (frame, options->ce.link_mtu_defined, options->ce.link_mtu, options->ce.tun_mtu_defined, options->ce.tun_mtu); -frame_calculate_mssfix (frame, &session->opt->key_type, options); +frame_calculate_mssfix (frame, &session->opt->key_type, options, lsi);frame_print (frame,D_MTU_INFO ,"Data Channel MTU parms" );/*
@@ -1938,7 +1939,8 @@ tls_session_update_crypto_params_do_work(struct tls_session *session,bool tls_session_update_crypto_params (struct tls_session *session,struct options *options,struct frame *frame, -struct frame *frame_fragment) +struct frame *frame_fragment, +struct link_socket_info *lsi) {bool cipher_allowed_as_fallback = options->enable_ncp_fallback
@@ -1957,7 +1959,8 @@ tls_session_update_crypto_params(struct tls_session *session,/* Import crypto settings that might be set by pull/push */ session->opt->crypto_flags |= options->data_channel_crypto_flags; -return tls_session_update_crypto_params_do_work (session, options, frame, frame_fragment); +return tls_session_update_crypto_params_do_work (session, options, frame, + frame_fragment, lsi); }
src/openvpn/ssl.h +4 -1
@@ -508,13 +508,16 @@ void tls_update_remote_addr(struct tls_multi *multi,* @param frame The frame options for this session (frame overhead is * adjusted based on the selected cipher/auth). * @param frame_fragment The fragment frame options. +* @param lsi link socket info to adjust MTU related options +* depending on the current protocol * * @return true if updating succeeded or keys are already generated, false otherwise. */ bool tls_session_update_crypto_params (struct tls_session *session,struct options *options,struct frame *frame, -struct frame *frame_fragment); +struct frame *frame_fragment, +struct link_socket_info *lsi);/* * inline functions
tests/unit_tests/openvpn/test_crypto.c +4 -4
@@ -382,7 +382,7 @@ test_mssfix_mtu_calculation(void **state)init_key_type (&kt, o.ciphername, o.authname, false, false);/* No encryption, just packet id (8) + TCP payload(20) + IP payload(20) */ -frame_calculate_mssfix (&f, &kt, &o); +frame_calculate_mssfix (&f, &kt, &o,NULL );assert_int_equal (f.mss_fix,952 );/* Static key OCC examples */
@@ -392,7 +392,7 @@ test_mssfix_mtu_calculation(void **state) o.ciphername ="none" ; o.authname ="none" ;init_key_type (&kt, o.ciphername, o.authname, false, false); -frame_calculate_mssfix (&f, &kt, &o); +frame_calculate_mssfix (&f, &kt, &o,NULL );assert_int_equal (f.mss_fix,952 );/* secret, cipher AES-128-CBC, auth none */
@@ -406,7 +406,7 @@ test_mssfix_mtu_calculation(void **state)* all result in the same CBC block size/padding and <= 991 and >=1008 * should be one block less and more respectively */ o.ce.mssfix = i; -frame_calculate_mssfix (&f, &kt, &o); +frame_calculate_mssfix (&f, &kt, &o,NULL );if (i <=991 ) {assert_int_equal (f.mss_fix,911 );
@@ -434,7 +434,7 @@ test_mssfix_mtu_calculation(void **state)/* For stream ciphers, the value should not be influenced by block * sizes or similar but always have the same difference */ o.ce.mssfix = i; -frame_calculate_mssfix (&f, &kt, &o); +frame_calculate_mssfix (&f, &kt, &o,NULL );/* 4 byte opcode/peerid, 4 byte pkt ID, 16 byte tag, 40 TCP+IP */ assert_int_equal (f.mss_fix, i -4 -4 -16 -40 );
Signature · 1 line
2.33.0
PATCH v3 6/14 Update fragment and mssfix related warnings
In reply to Arne SchwabeThe warning that fragment/mssfix needs also tun-mtu set to 1500 makes little sense. Remove it completely. Instead warn if there are incosistencies between --fragment and mssfix.
Patch v2: clarify the mssfix and fragment mtu warning message
--- src/openvpn/init.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
src/openvpn/init.c +10 -5
@@ -3255,12 +3255,17 @@ do_init_frame(struct context *c)#endif #ifdef ENABLE_FRAGMENT -if ((c->options.ce.mssfix || c->options.ce.fragment) - &&TUN_MTU_SIZE (&c->c2.frame_fragment) !=ETHERNET_MTU ) +if (c->options.ce.fragment >0 && c->options.ce.mssfix > c->options.ce.fragment) { -msg (M_WARN , -"WARNING: normally if you use --mssfix and/or --fragment, you should also set --tun-mtu %d (currently it is %d)" , -ETHERNET_MTU ,TUN_MTU_SIZE (&c->c2.frame_fragment)); +msg (M_WARN ,"WARNING: if you use --mssfix and --fragment, you should " +"set --fragment (%d) larger or equal than --mssfix (%d)" , + c->options.ce.fragment, c->options.ce.mssfix); + } +if (c->options.ce.fragment >0 && c->options.ce.mssfix >0 + && c->options.ce.fragment_encap != c->options.ce.mssfix_encap) + { +msg (M_WARN ,"WARNING: if you use --mssfix and --fragment, you should " +"use the \"mtu\" flag for both or none of of them." ); }#endif }
Signature · 1 line
2.33.0
PATCH v3 7/14 Change the default for mssfix to mssfix 1492 mtu
In reply to Arne SchwabeThe current default is 1450, which translates to 1478 byte packets for udp4 and 1498 byte packets for udp6. This commit changes the mssfix default to take the outer IP overhead into account as well and changes the target to 1492. 1492 was picked in our community meeting for being a very common encapsulation upper bound.
The change also disables an mssfix default if tun-mtu is set to a value different than 1500.
--- src/openvpn/mtu.h | 2 +- src/openvpn/options.c | 60 +++++++++++++++++++++++++++++-------------- src/openvpn/options.h | 2 +- 3 files changed, 43 insertions(+), 21 deletions(-)
src/openvpn/mtu.h +1 -1
@@ -77,7 +77,7 @@/* * Default MSSFIX value, used for reducing TCP MTU size */ -#define MSSFIX_DEFAULT 1450 +#define MSSFIX_DEFAULT 1492/* * Alignment of payload data such as IP packet or
src/openvpn/options.c +41 -19
94 lines not on this page · raw message
src/openvpn/options.h +1 -1
@@ -126,7 +126,7 @@ struct connection_entryint fragment;/* internal fragmentation size */ int mssfix;/* Upper bound on TCP MSS */ -bool mssfix_default;/* true if --mssfix was supplied without a parameter */ +bool mssfix_default;/* true if --mssfix should use the default parameters */ bool mssfix_encap;/* true if --mssfix had the "mtu" parameter to include * overhead from IP and TCP/UDP encapsulation */
Signature · 1 line
2.33.0
PATCH v3 8/14 Remove link_mtu parameter when running up/down scripts
In reply to Arne SchwabeThe link mtu is no longer used and calculating a compatibility link MTU just for scripts makes little sense as well. Replace the parameter instead with a fixed paramter 0.
--- Changes.rst | 2 ++ src/openvpn/init.c | 16 +++------------- 2 files changed, 5 insertions(+), 13 deletions(-)
Changes.rst +2 -0
@@ -128,6 +128,8 @@ User-visible Changes - CHACHA20-POLY1305 is included in the default of ``--data-ciphers`` when available. - Option ``--prng`` is ignored as we rely on the SSL library random number generator. - Option ``--nobind`` is default when ``--client`` or ``--pull`` is used in the configuration +- :code:`link_mtu` parameter is removed from environment or replaced with 0 when scripts are + called with parameters. This parameter is unreliable and no longer internally calculated. Overview of changes in 2.5 ==========================
src/openvpn/init.c +3 -13
@@ -113,7 +113,6 @@ run_up_down(const char *command,#endif const char *dev_type, int tun_mtu, - int link_mtu, const char *ifconfig_local, const char *ifconfig_remote, const char *context,
@@ -129,7 +128,6 @@ run_up_down(const char *command, }setenv_str (es,"script_context" , context);setenv_int (es,"tun_mtu" , tun_mtu); -setenv_int (es,"link_mtu" , link_mtu);setenv_str (es,"dev" , arg);if (dev_type) {
@@ -157,11 +155,8 @@ run_up_down(const char *command,struct argv argv =argv_new ();ASSERT (arg);argv_printf (&argv, -"%s %d %d %s %s %s" , - arg, - tun_mtu, link_mtu, - ifconfig_local, ifconfig_remote, - context); +"%s %d 0 %s %s %s" , + arg, tun_mtu, ifconfig_local, ifconfig_remote, context);if (plugin_call (plugins, plugin_type, &argv,NULL , es) !=OPENVPN_PLUGIN_FUNC_SUCCESS ) {
@@ -177,7 +172,7 @@ run_up_down(const char *command,ASSERT (arg);setenv_str (es,"script_type" , script_type);argv_parse_cmd (&argv, command); -argv_printf_cat (&argv,"%s %d %d %s %s %s" , arg, tun_mtu, link_mtu, +argv_printf_cat (&argv,"%s %d 0 %s %s %s" , arg, tun_mtu, ifconfig_local, ifconfig_remote, context);argv_msg (M_INFO , &argv);openvpn_run_script (&argv, es,S_FATAL ,"--up/--down" );
@@ -1848,7 +1843,6 @@ do_open_tun(struct context *c)#endif dev_type_string (c->options.dev, c->options.dev_type),TUN_MTU_SIZE (&c->c2.frame), -EXPANDED_SIZE (&c->c2.frame),print_in_addr_t (c->c1.tuntap->local,IA_EMPTY_IF_UNDEF , &gc),print_in_addr_t (c->c1.tuntap->remote_netmask,IA_EMPTY_IF_UNDEF , &gc), "init",
@@ -1898,7 +1892,6 @@ else#endif dev_type_string (c->options.dev, c->options.dev_type),TUN_MTU_SIZE (&c->c2.frame), -EXPANDED_SIZE (&c->c2.frame),print_in_addr_t (c->c1.tuntap->local,IA_EMPTY_IF_UNDEF , &gc),print_in_addr_t (c->c1.tuntap->remote_netmask,IA_EMPTY_IF_UNDEF , &gc), "restart",
@@ -1978,7 +1971,6 @@ do_close_tun(struct context *c, bool force)#endif NULL ,TUN_MTU_SIZE (&c->c2.frame), -EXPANDED_SIZE (&c->c2.frame),print_in_addr_t (local,IA_EMPTY_IF_UNDEF , &gc),print_in_addr_t (remote_netmask,IA_EMPTY_IF_UNDEF , &gc), "init",
@@ -2009,7 +2001,6 @@ do_close_tun(struct context *c, bool force)#endif NULL ,TUN_MTU_SIZE (&c->c2.frame), -EXPANDED_SIZE (&c->c2.frame),print_in_addr_t (local,IA_EMPTY_IF_UNDEF , &gc),print_in_addr_t (remote_netmask,IA_EMPTY_IF_UNDEF , &gc), "init",
@@ -2048,7 +2039,6 @@ do_close_tun(struct context *c, bool force)#endif NULL ,TUN_MTU_SIZE (&c->c2.frame), -EXPANDED_SIZE (&c->c2.frame),print_in_addr_t (local,IA_EMPTY_IF_UNDEF , &gc),print_in_addr_t (remote_netmask,IA_EMPTY_IF_UNDEF , &gc), "restart",
Signature · 1 line
2.33.0
PATCH v3 9/14 Add mtu paramter to --fragment and change fragment calculation
In reply to Arne SchwabeInstead relying on the link_mtu_dynamic field and its calculation in the frame struct, add a new field max_fragment_size and add a calculation of it similar to mssfix.
Also whenever mssfix value is calculated, we also want to calculate the values for fragment as both options need to be calculated from the real overhead.
Patch v2: Fix syntax in rst man page
--- Changes.rst | 9 ++- doc/man-sections/link-options.rst | 20 ++++- src/openvpn/forward.c | 3 +- src/openvpn/fragment.c | 4 +- src/openvpn/init.c | 15 ++-- src/openvpn/mss.c | 100 +++++++++++++++++++++++-- src/openvpn/mss.h | 13 +++- src/openvpn/mtu.c | 48 +----------- src/openvpn/mtu.h | 21 ++++-- src/openvpn/options.c | 12 ++- src/openvpn/options.h | 2 + src/openvpn/socket.c | 11 --- src/openvpn/socket.h | 2 - src/openvpn/ssl.c | 20 +---- tests/unit_tests/openvpn/test_crypto.c | 8 +- 15 files changed, 178 insertions(+), 110 deletions(-)
Changes.rst +5 -4
@@ -63,10 +63,11 @@ Optional ciphers in ``--data-ciphers`` those as optional and only use them if the SSL library supports them. -Improved ``--mssfix`` calculation - The ``--mssfix`` option now allows an optional :code:`mtu` parameter to specify - that different overhead for IPv4/IPv6 should taken into account and the resulting - size is specified as the total size of the VPN packets including IP and UDP headers. +Improved ``--mssfix`` and ``--fragment`` calculation + The ``--mssfix`` and ``--fragment`` options now allow an optional :code:`mtu` + parameter to specify that different overhead for IPv4/IPv6 should taken into + account and the resulting size is specified as the total size of the VPN packets + including IP and UDP headers. Deprecated features -------------------
doc/man-sections/link-options.rst +16 -4
@@ -24,13 +24,25 @@ the local and the remote host. from any address, not only the address which was specified in the ``--remote`` option. ---fragment max +--fragment args + + Valid syntax: + :: + + fragment max + fragment max mtu + Enable internal datagram fragmentation so that no UDP datagrams are sent which are larger than ``max`` bytes. - The ``max`` parameter is interpreted in the same way as the - ``--link-mtu`` parameter, i.e. the UDP packet size after encapsulation - overhead has been added in, but not including the UDP header itself. + If the :code:`mtu` parameter is present the ``max`` parameter is + interpreted to include IP and UDP encapsulation overhead. The + :code:`mtu` parameter is introduced in OpenVPN version 2.6.0. + + If the :code:`mtu` parameter is absent, the ``max`` parameter is + interpreted in the same way as the ``--link-mtu`` parameter, i.e. + the UDP packet size after encapsulation overhead has been added in, + but not including the UDP header itself. The ``--fragment`` option only makes sense when you are using the UDP protocol (``--proto udp``).
src/openvpn/forward.c +1 -2
@@ -482,8 +482,7 @@ check_fragment(struct context *c)/* OS MTU Hint? */ if (lsi->mtu_changed && lsi->lsa) { -frame_adjust_path_mtu (&c->c2.frame_fragment, c->c2.link_socket->mtu, - lsi->lsa->actual.dest.addr.sa.sa_family, lsi->proto); +frame_adjust_path_mtu (c); lsi->mtu_changed = false; }
src/openvpn/fragment.c +2 -2
@@ -335,12 +335,12 @@ fragment_outgoing(struct fragment_master *f, struct buffer *buf,msg (D_FRAG_ERRORS ,"FRAG: outgoing buffer is not empty, len=[%d,%d]" , buf->len, f->outgoing.len); } -if (buf->len >PAYLOAD_SIZE_DYNAMIC (frame))/* should we fragment? */ +if (buf->len > frame->max_fragment_size)/* should we fragment? */ {/* * Send the datagram as a series of 2 or more fragments. */ - f->outgoing_frag_size =optimal_fragment_size (buf->len,PAYLOAD_SIZE_DYNAMIC (frame)); + f->outgoing_frag_size =optimal_fragment_size (buf->len, frame->max_fragment_size);if (buf->len > f->outgoing_frag_size *MAX_FRAGS ) {FRAG_ERR ("too many fragments would be required to send datagram" );
src/openvpn/init.c +10 -5
@@ -3427,8 +3427,8 @@ static void do_init_fragment(struct context *c) {ASSERT (c->options.ce.fragment); -frame_set_mtu_dynamic (&c->c2.frame_fragment, - c->options.ce.fragment,SET_MTU_UPPER_BOUND ); +frame_calculate_dynamic (&c->c2.frame_fragment, &c->c1.ks.key_type, + &c->options,get_link_socket_info (c));fragment_frame_init (c->c2.fragment, &c->c2.frame_fragment); }#endif
@@ -4296,9 +4296,9 @@ init_instance(struct context *c, const struct env_set *env, const unsigned int f }#endif -/* initialize dynamic MTU variable */ -frame_calculate_mssfix (&c->c2.frame, &c->c1.ks.key_type, &c->options, -get_link_socket_info (c)); +/* initialize dynamic MTU based options (fragment/mssfix) */ +frame_calculate_dynamic (&c->c2.frame, &c->c1.ks.key_type, &c->options, +get_link_socket_info (c));/* bind the TCP/UDP socket */ if (c->mode ==CM_P2P || c->mode ==CM_TOP || c->mode ==CM_CHILD_TCP )
@@ -4350,6 +4350,11 @@ init_instance(struct context *c, const struct env_set *env, const unsigned int flink_socket_init_phase2 (c); } +/* Update dynamic frame calculation as exact transport socket information +* (IP vs IPv6) may be only available after socket phase2 has finished */ +frame_calculate_dynamic (&c->c2.frame, &c->c1.ks.key_type, &c->options, +get_link_socket_info (c)); +/* * Actually do UID/GID downgrade, and chroot, if requested. * May be delayed by --client, --pull, or --up-delay.
src/openvpn/mss.c +94 -6
119 lines not on this page · raw message
src/openvpn/mss.h +10 -3
@@ -36,8 +36,15 @@ void mss_fixup_ipv6(struct buffer *buf, int maxmss);void mss_fixup_dowork (struct buffer *buf,uint16_t maxmss);/** Set the --mssfix option. */ -void frame_calculate_mssfix (struct frame *frame,struct key_type *kt, -const struct options *options, -struct link_socket_info *lsi); +void frame_calculate_dynamic (struct frame *frame,struct key_type *kt, +const struct options *options, +struct link_socket_info *lsi); + +/** +* Checks and adjusts the fragment and mssfix value according to the +* discovered path mtu value +* @param c context to adjust +*/ +void frame_adjust_path_mtu (struct context *c);#endif
src/openvpn/mtu.c +4 -44
72 lines not on this page · raw message
src/openvpn/mtu.h +16 -5
@@ -113,14 +113,18 @@ struct frame {int link_mtu;/**< Maximum packet size to be sent over * the external network interface. */ -unsigned int mss_fix;/**< The actual MSS value that should be +unsigned int mss_fix;/**< The actual MSS value that should be * written to the payload packets. This * is the value for IPv4 TCP packets. For * IPv6 packets another 20 bytes must * be subtracted */ -int link_mtu_dynamic;/**< Dynamic MTU value for the external -* network interface. */ +int max_fragment_size;/**< The maximum size of a fragment. +* Fragmentation is done on the unencrypted +* payload after (potential) compression. So +* this value specifies the maximum payload +* size that can be send in a single fragment +*/ int extra_frame;/**< Maximum number of bytes that all * processing steps together could add.
@@ -195,7 +199,6 @@ struct options;* a tap device ifconfiged to an MTU of 1200 might actually want * to return a packet size of 1214 on a read(). */ -#define PAYLOAD_SIZE_DYNAMIC (f) ((f)->link_mtu_dynamic - (f)->extra_frame)#define PAYLOAD_SIZE (f) ((f)->buf.payload_size)/*
@@ -203,7 +206,6 @@ struct options;* overhead is added. */ #define EXPANDED_SIZE (f) ((f)->link_mtu) -#define EXPANDED_SIZE_DYNAMIC (f) ((f)->link_mtu_dynamic)#define EXPANDED_SIZE_MIN (f) (TUN_MTU_MIN + TUN_LINK_DELTA(f))/*
@@ -314,6 +316,15 @@ size_t calc_options_string_link_mtu(const struct options *options, const struct frame *frame); +/** +* Return the size of the packet ID size that is currently in use by cipher and +* options for the data channel. +*/ +unsigned int +calc_packet_id_size_dc (const struct options *options, +const struct key_type *kt); + +/* * frame_set_mtu_dynamic and flags */
src/openvpn/options.c +10 -2
@@ -6132,11 +6132,19 @@ add_option(struct options *options,msg (msglevel,"--mtu-dynamic has been replaced by --fragment" ); goto err; } -else if (streq (p[0 ],"fragment" ) && p[1 ] && !p[2 ]) +else if (streq (p[0 ],"fragment" ) && p[1 ] && !p[3 ]) { -/* VERIFY_PERMISSION (OPT_P_MTU); */ VERIFY_PERMISSION (OPT_P_MTU |OPT_P_CONNECTION ); options->ce.fragment =positive_atoi (p[1 ]); + +if (p[2 ] &&streq (p[2 ],"mtu" )) + { + options->ce.fragment_encap = true; + } +else if (p[2 ]) + { +msg (msglevel,"Unknown parameter to --fragment: %s" , p[2 ]); + } }#endif else if (streq(p[0], "mtu-disc") && p[1] && !p[2])
src/openvpn/options.h +2 -0
@@ -125,6 +125,8 @@ struct connection_entryint mtu_discover_type;/* used if OS supports setting Path MTU discovery options on socket */ int fragment;/* internal fragmentation size */ +bool fragment_encap;/* true if --fragment had the "mtu" parameter to +* include overhead from IP and TCP/UDP encapsulation */ int mssfix;/* Upper bound on TCP MSS */ bool mssfix_default;/* true if --mssfix should use the default parameters */ bool mssfix_encap;/* true if --mssfix had the "mtu" parameter to include
src/openvpn/socket.c +0 -11
@@ -1644,17 +1644,6 @@ socket_frame_init(const struct frame *frame, struct link_socket *sock) } } -/* -* Adjust frame structure based on a Path MTU value given -* to us by the OS. -*/ -void -frame_adjust_path_mtu (struct frame *frame,int pmtu,sa_family_t af,int proto) -{ -frame_set_mtu_dynamic (frame, pmtu -datagram_overhead (af, proto), -SET_MTU_UPPER_BOUND ); -} -static void resolve_bind_local (struct link_socket *sock,const sa_family_t af) {
src/openvpn/socket.h +0 -2
@@ -300,8 +300,6 @@ void do_preresolve(struct context *c);void socket_adjust_frame_parameters (struct frame *frame,int proto); -void frame_adjust_path_mtu (struct frame *frame,int pmtu,sa_family_t af,int proto); -void link_socket_close (struct link_socket *sock);void sd_close (socket_descriptor_t *sd);
src/openvpn/ssl.c +4 -16
@@ -331,7 +331,6 @@ tls_init_control_channel_frame_parameters(const struct frame *data_channel_frame/* set dynamic link MTU to cap control channel packets at 1250 bytes */ ASSERT (TUN_LINK_DELTA (frame) <min_int (frame->link_mtu,1250 )); - frame->link_mtu_dynamic =min_int (frame->link_mtu,1250 ) -TUN_LINK_DELTA (frame);/* calculate the maximum overhead that control channel frames may have */ int overhead =0 ;
@@ -1912,9 +1911,8 @@ tls_session_update_crypto_params_do_work(struct tls_session *session,frame_remove_from_extra_frame (frame,crypto_max_overhead ());crypto_adjust_frame_parameters (frame, &session->opt->key_type, options->replay, packet_id_long_form); -frame_finalize (frame, options->ce.link_mtu_defined, options->ce.link_mtu, - options->ce.tun_mtu_defined, options->ce.tun_mtu); -frame_calculate_mssfix (frame, &session->opt->key_type, options, lsi); +frame_calculate_dynamic (frame, &session->opt->key_type, options, lsi); +frame_print (frame,D_MTU_INFO ,"Data Channel MTU parms" );/*
@@ -1929,7 +1927,7 @@ tls_session_update_crypto_params_do_work(struct tls_session *session,frame_remove_from_extra_frame (frame_fragment,crypto_max_overhead ());crypto_adjust_frame_parameters (frame_fragment, &session->opt->key_type, options->replay, packet_id_long_form); -frame_set_mtu_dynamic (frame_fragment, options->ce.fragment,SET_MTU_UPPER_BOUND ); +frame_calculate_dynamic (frame_fragment, &session->opt->key_type, options, lsi);frame_print (frame_fragment,D_MTU_INFO ,"Fragmentation MTU parms" ); }
@@ -2982,6 +2980,7 @@ tls_process(struct tls_multi *multi,if (buf) {int status =key_state_read_ciphertext (&ks->ks_ssl, buf, multi->opt.frame.tun_mtu); +if (status ==-1 ) { msg(D_TLS_ERRORS,
@@ -3827,17 +3826,6 @@ tls_pre_decrypt_lite(const struct tls_auth_standalone *tas, goto error; } -if (buf->len >EXPANDED_SIZE_DYNAMIC (&tas->frame)) - { -dmsg (D_TLS_STATE_ERRORS , -"TLS State Error: Large packet (size %d) received from %s -- a packet no larger than %d bytes was expected" , - buf->len, -print_link_socket_actual (from, &gc), -EXPANDED_SIZE_DYNAMIC (&tas->frame)); - goto error; - } - -struct buffer newbuf =clone_buf (buf);struct tls_wrap_ctx tls_wrap_tmp = tas->tls_wrap;
tests/unit_tests/openvpn/test_crypto.c +4 -4
@@ -382,7 +382,7 @@ test_mssfix_mtu_calculation(void **state)init_key_type (&kt, o.ciphername, o.authname, false, false);/* No encryption, just packet id (8) + TCP payload(20) + IP payload(20) */ -frame_calculate_mssfix (&f, &kt, &o,NULL ); +frame_calculate_dynamic (&f, &kt, &o,NULL );assert_int_equal (f.mss_fix,952 );/* Static key OCC examples */
@@ -392,7 +392,7 @@ test_mssfix_mtu_calculation(void **state) o.ciphername ="none" ; o.authname ="none" ;init_key_type (&kt, o.ciphername, o.authname, false, false); -frame_calculate_mssfix (&f, &kt, &o,NULL ); +frame_calculate_dynamic (&f, &kt, &o,NULL );assert_int_equal (f.mss_fix,952 );/* secret, cipher AES-128-CBC, auth none */
@@ -406,7 +406,7 @@ test_mssfix_mtu_calculation(void **state)* all result in the same CBC block size/padding and <= 991 and >=1008 * should be one block less and more respectively */ o.ce.mssfix = i; -frame_calculate_mssfix (&f, &kt, &o,NULL ); +frame_calculate_dynamic (&f, &kt, &o,NULL );if (i <=991 ) {assert_int_equal (f.mss_fix,911 );
@@ -434,7 +434,7 @@ test_mssfix_mtu_calculation(void **state)/* For stream ciphers, the value should not be influenced by block * sizes or similar but always have the same difference */ o.ce.mssfix = i; -frame_calculate_mssfix (&f, &kt, &o,NULL ); +frame_calculate_dynamic (&f, &kt, &o,NULL );/* 4 byte opcode/peerid, 4 byte pkt ID, 16 byte tag, 40 TCP+IP */ assert_int_equal (f.mss_fix, i -4 -4 -16 -40 );
Signature · 1 line
2.33.0
PATCH v3 10/14 Use new frame header methods to calculate OCC_MTU_LOAD payload size
In reply to Arne Schwabe--- src/openvpn/occ.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)
src/openvpn/occ.c +23 -8
@@ -199,8 +199,11 @@ check_send_occ_load_test_dowork(struct context *c)if (entry->op >=0 ) { c->c2.occ_op = entry->op; - c->c2.occ_mtu_load_size = -EXPANDED_SIZE (&c->c2.frame) + entry->delta; +size_t payload_size =frame_calculate_payload_size (&c->c2.frame, + &c->options, &c->c1.ks.key_type); +size_t header_size =frame_calculate_protocol_header_size (&c->c1.ks.key_type, &c->options, false); + + c->c2.occ_mtu_load_size = payload_size + header_size; }else {
@@ -298,10 +301,21 @@ check_send_occ_msg_dowork(struct context *c) {break ; } - need_to_add =min_int (c->c2.occ_mtu_load_size,EXPANDED_SIZE (&c->c2.frame)) +size_t proto_hdr, payload_hdr; +const struct key_type *kt = &c->c1.ks.key_type; + +/* OCC message have comp/fragment headers but not ethernet headers */ + payload_hdr =frame_calculate_payload_overhead (&c->c2.frame, &c->options, + kt, false); + +/* Since we do not know the payload size we just pass 0 as size here */ + proto_hdr =frame_calculate_protocol_header_size (kt, &c->options, false); + + need_to_add =min_int (c->c2.occ_mtu_load_size, c->c2.frame.buf.payload_size) -OCC_STRING_SIZE - -sizeof (uint8_t ) - -EXTRA_FRAME (&c->c2.frame); + -sizeof (uint8_t )/* occ opcode */ + - payload_hdr + - proto_hdr;while (need_to_add >0 ) {
@@ -314,12 +328,13 @@ check_send_occ_msg_dowork(struct context *c) } --need_to_add; } -dmsg (D_PACKET_CONTENT ,"SENT OCC_MTU_LOAD min_int(%d-%d-%d-%d,%d) size=%d" , +dmsg (D_PACKET_CONTENT ,"SENT OCC_MTU_LOAD min_int(%d,%d)-%d-%d-%d-%d) size=%d" , c->c2.occ_mtu_load_size, + c->c2.frame.buf.payload_size,OCC_STRING_SIZE , (int )sizeof (uint8_t ), -EXTRA_FRAME (&c->c2.frame), - c->c2.frame.buf.payload_size, + (int ) payload_hdr, + (int ) proto_hdr,BLEN (&c->c2.buf)); doit = true; }
Signature · 1 line
2.33.0
PATCH v3 11/14 Remove extra_link from frame
In reply to Arne SchwabeThe previous commits removed any reads from this variable. So we can now safely remove it.
--- src/openvpn/init.c | 19 ------------------- src/openvpn/mtu.c | 1 - src/openvpn/mtu.h | 13 ------------- src/openvpn/socks.c | 11 +---------- src/openvpn/socks.h | 2 -- src/openvpn/ssl.c | 1 - 6 files changed, 1 insertion(+), 46 deletions(-)
src/openvpn/init.c +0 -19
@@ -3171,14 +3171,6 @@ do_init_frame(struct context *c) }#endif /* USE_COMP */ -/* -* Adjust frame size for UDP Socks support. -*/ -if (c->options.ce.socks_proxy_server) - { -socks_adjust_frame_parameters (&c->c2.frame, c->options.ce.proto); - } -/* * Adjust frame size based on the --tun-mtu-extra parameter. */
@@ -3211,17 +3203,6 @@ do_init_frame(struct context *c)#endif #endif /* USE_COMP */ -/* packets with peer-id (P_DATA_V2) need 3 extra bytes in frame (on client) -* and need link_mtu+3 bytes on socket reception (on server). -* -* accommodate receive path in f->extra_link, which has the side effect of -* also increasing send buffers (BUF_SIZE() macro), which need to be -* allocated big enough before receiving peer-id option from server. -* -* f->extra_frame is adjusted when peer-id option is push-received -*/ -frame_add_to_extra_link (&c->c2.frame,3 ); -#ifdef ENABLE_FRAGMENT /* * Set frame parameter for fragment code. This is necessary because
src/openvpn/mtu.c +0 -1
@@ -266,7 +266,6 @@ frame_print(const struct frame *frame,buf_printf (&out," EF:%d" , frame->extra_frame);buf_printf (&out," EB:%d" , frame->extra_buffer);buf_printf (&out," ET:%d" , frame->extra_tun); -buf_printf (&out," EL:%d" , frame->extra_link);buf_printf (&out," ]" );msg (level,"%s" , out.data);
src/openvpn/mtu.h +0 -13
@@ -163,13 +163,6 @@ struct frame {* which defaults to 0 for tun and 32 * (\c TAP_MTU_EXTRA_DEFAULT) for tap. * */ - -int extra_link;/**< Maximum number of bytes in excess of -* external network interface's MTU that -* might be read from or written to it. -* -* Used by peer-id (3) and -* socks UDP (10) */ };/* Forward declarations, to prevent includes */
@@ -383,12 +376,6 @@ frame_add_to_extra_tun(struct frame *frame, const int increment) frame->extra_tun += increment; } -static inline void -frame_add_to_extra_link (struct frame *frame,const int increment) -{ - frame->extra_link += increment; -} -static inline void frame_add_to_extra_buffer (struct frame *frame,const int increment) {
src/openvpn/socks.c +1 -10
@@ -49,15 +49,6 @@#define UP_TYPE_SOCKS "SOCKS Proxy" -void -socks_adjust_frame_parameters (struct frame *frame,int proto) -{ -if (proto ==PROTO_UDP ) - { -frame_add_to_extra_link (frame,10 ); - } -} -struct socks_proxy_info * socks_proxy_new(const char *server, const char *port,
@@ -610,7 +601,7 @@ socks_process_outgoing_udp(struct buffer *buf,/* * Get a 10 byte subset buffer prepended to buf -- * we expect these bytes will be here because -* we allocated frame space in socks_adjust_frame_parameters. +* we always allocate space for these bytes */ struct buffer head =buf_sub (buf,10 , true);
src/openvpn/socks.h +0 -2
@@ -42,8 +42,6 @@ struct socks_proxy_info {char authfile[256 ]; }; -void socks_adjust_frame_parameters (struct frame *frame,int proto); -struct socks_proxy_info *socks_proxy_new (const char *server,const char *port,const char *authfile);
src/openvpn/ssl.c +0 -1
@@ -322,7 +322,6 @@ tls_init_control_channel_frame_parameters(const struct frame *data_channel_frame/* inherit link MTU and extra_link from data channel */ frame->link_mtu = data_channel_frame->link_mtu; - frame->extra_link = data_channel_frame->extra_link;/* set extra_frame */ tls_adjust_frame_parameters (frame);
Signature · 1 line
2.33.0
PATCH v3 12/14 Replace TUN_MTU_SIZE with frame->tun_mtu
In reply to Arne SchwabeThis always uses the configured MTU size instead relying on the calculated MTU size.
--- src/openvpn/forward.c | 2 +- src/openvpn/init.c | 16 ++++++++-------- src/openvpn/mtu.h | 5 ----- 3 files changed, 9 insertions(+), 14 deletions(-)
src/openvpn/forward.c +1 -1
@@ -1379,7 +1379,7 @@ ipv6_send_icmp_unreachable(struct context *c, struct buffer *buf, bool client)* packet */ int max_payload_size =min_int (MAX_ICMPV6LEN , -TUN_MTU_SIZE (&c->c2.frame) - icmpheader_len); + c->c2.frame.tun_mtu - icmpheader_len);int payload_len =min_int (max_payload_size,BLEN (&inputipbuf)); pip6out.payload_len =htons (sizeof (struct openvpn_icmp6hdr ) + payload_len);
src/openvpn/init.c +8 -8
@@ -1799,7 +1799,7 @@ do_open_tun(struct context *c) c->options.dev_type, c->options.dev_node, &gc); -do_ifconfig (c->c1.tuntap, guess,TUN_MTU_SIZE (&c->c2.frame), c->c2.es, +do_ifconfig (c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); }
@@ -1830,7 +1830,7 @@ do_open_tun(struct context *c) && ifconfig_order() == IFCONFIG_AFTER_TUN_OPEN) {do_ifconfig (c->c1.tuntap, c->c1.tuntap->actual_name, -TUN_MTU_SIZE (&c->c2.frame), c->c2.es, &c->net_ctx); + c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx); }/* run the up script */
@@ -1842,7 +1842,7 @@ do_open_tun(struct context *c) c->c1.tuntap->adapter_index, #endifdev_type_string (c->options.dev, c->options.dev_type), -TUN_MTU_SIZE (&c->c2.frame), + c->c2.frame.tun_mtu,print_in_addr_t (c->c1.tuntap->local,IA_EMPTY_IF_UNDEF , &gc),print_in_addr_t (c->c1.tuntap->remote_netmask,IA_EMPTY_IF_UNDEF , &gc), "init",
@@ -1891,7 +1891,7 @@ else c->c1.tuntap->adapter_index, #endifdev_type_string (c->options.dev, c->options.dev_type), -TUN_MTU_SIZE (&c->c2.frame), + c->c2.frame.tun_mtu,print_in_addr_t (c->c1.tuntap->local,IA_EMPTY_IF_UNDEF , &gc),print_in_addr_t (c->c1.tuntap->remote_netmask,IA_EMPTY_IF_UNDEF , &gc), "restart",
@@ -1970,7 +1970,7 @@ do_close_tun(struct context *c, bool force) adapter_index, #endifNULL , -TUN_MTU_SIZE (&c->c2.frame), + c->c2.frame.tun_mtu,print_in_addr_t (local,IA_EMPTY_IF_UNDEF , &gc),print_in_addr_t (remote_netmask,IA_EMPTY_IF_UNDEF , &gc), "init",
@@ -2000,7 +2000,7 @@ do_close_tun(struct context *c, bool force) adapter_index, #endifNULL , -TUN_MTU_SIZE (&c->c2.frame), + c->c2.frame.tun_mtu,print_in_addr_t (local,IA_EMPTY_IF_UNDEF , &gc),print_in_addr_t (remote_netmask,IA_EMPTY_IF_UNDEF , &gc), "init",
@@ -2038,7 +2038,7 @@ do_close_tun(struct context *c, bool force) adapter_index, #endifNULL , -TUN_MTU_SIZE (&c->c2.frame), + c->c2.frame.tun_mtu,print_in_addr_t (local,IA_EMPTY_IF_UNDEF , &gc),print_in_addr_t (remote_netmask,IA_EMPTY_IF_UNDEF , &gc), "restart",
@@ -2218,7 +2218,7 @@ void adjust_mtu_peerid(struct context *c) {msg (M_WARN ,"OPTIONS IMPORT: WARNING: peer-id set, but link-mtu" " fixed by config - reducing tun-mtu to %d, expect" -" MTU problems" ,TUN_MTU_SIZE (&c->c2.frame)); +" MTU problems" , c->c2.frame.tun_mtu); } }
src/openvpn/mtu.h +0 -5
@@ -181,11 +181,6 @@ struct options;*/ #define TUN_LINK_DELTA (f) ((f)->extra_frame + (f)->extra_tun) -/* -* This is the size to "ifconfig" the tun or tap device. -*/ -#define TUN_MTU_SIZE (f) ((f)->link_mtu - TUN_LINK_DELTA(f)) -/* * This is the maximum packet size that we need to be able to * read from or write to a tun or tap device. For example,
Signature · 1 line
2.33.0
PATCH v3 13/14 Remove frame->link_mtu
In reply to Arne Schwabe--- src/openvpn/comp.c | 8 -------- src/openvpn/comp.h | 2 -- src/openvpn/forward.c | 4 ++-- src/openvpn/init.c | 39 +++------------------------------------ src/openvpn/mtu.c | 26 -------------------------- src/openvpn/mtu.h | 22 ---------------------- src/openvpn/ssl.c | 9 --------- 7 files changed, 5 insertions(+), 105 deletions(-)
src/openvpn/comp.c +0 -8
@@ -123,14 +123,6 @@ comp_add_to_extra_frame(struct frame *frame)frame_add_to_extra_frame (frame,COMP_PREFIX_LEN ); } -void -comp_add_to_extra_buffer (struct frame *frame) -{ -/* Leave room for compression buffer to expand in worst case scenario -* where data is totally incompressible */ -frame_add_to_extra_buffer (frame,COMP_EXTRA_BUFFER (EXPANDED_SIZE (frame))); -} -void comp_print_stats (const struct compress_context *compctx,struct status_output *so) {
src/openvpn/comp.h +0 -2
@@ -178,8 +178,6 @@ void comp_uninit(struct compress_context *compctx);void comp_add_to_extra_frame (struct frame *frame); -void comp_add_to_extra_buffer (struct frame *frame); -void comp_print_stats (const struct compress_context *compctx,struct status_output *so);void comp_generate_peer_info_string (const struct compress_options *opt,struct buffer *out);
src/openvpn/forward.c +2 -2
@@ -1544,7 +1544,7 @@ process_outgoing_link(struct context *c)perf_push (PERF_PROC_OUT_LINK ); -if (c->c2.to_link.len >0 && c->c2.to_link.len <=EXPANDED_SIZE (&c->c2.frame)) +if (c->c2.to_link.len >0 && c->c2.to_link.len <= c->c2.frame.buf.payload_size) {/* * Setup for call to send/sendto which will send
@@ -1672,7 +1672,7 @@ process_outgoing_link(struct context *c)msg (D_LINK_ERRORS ,"TCP/UDP packet too large on write to %s (tried=%d,max=%d)" ,print_link_socket_actual (c->c2.to_link_addr, &gc), c->c2.to_link.len, -EXPANDED_SIZE (&c->c2.frame)); + c->c2.frame.buf.payload_size); } }
src/openvpn/init.c +3 -36
@@ -2204,24 +2204,6 @@ pull_permission_mask(const struct context *c)return flags; } -static -void adjust_mtu_peerid (struct context *c) -{ -frame_add_to_extra_frame (&c->c2.frame,3 );/* peer-id overhead */ -if (!c->options.ce.link_mtu_defined) - { -frame_add_to_link_mtu (&c->c2.frame,3 ); -msg (D_PUSH ,"OPTIONS IMPORT: adjusting link_mtu to %d" , -EXPANDED_SIZE (&c->c2.frame)); - } -else - { -msg (M_WARN ,"OPTIONS IMPORT: WARNING: peer-id set, but link-mtu" -" fixed by config - reducing tun-mtu to %d, expect" -" MTU problems" , c->c2.frame.tun_mtu); - } -} -static bool do_deferred_p2p_ncp (struct context *c) {
@@ -2230,11 +2212,6 @@ do_deferred_p2p_ncp(struct context *c)return true; } -if (c->c2.tls_multi->use_peer_id) - { -adjust_mtu_peerid (c); - } -struct tls_session *session = &c->c2.tls_multi->session[TM_ACTIVE ]; const char *ncp_cipher = get_p2p_ncp_cipher(session, c->c2.tls_multi->peer_info,
@@ -2356,7 +2333,6 @@ do_deferred_options(struct context *c, const unsigned int found)msg (D_PUSH ,"OPTIONS IMPORT: peer-id set" ); c->c2.tls_multi->use_peer_id = true; c->c2.tls_multi->peer_id = c->options.peer_id; -adjust_mtu_peerid (c); }/* process (potentially pushed) crypto options */
@@ -2589,14 +2565,6 @@ frame_finalize_options(struct context *c, const struct options *o) frame->buf.payload_size = payload_size; frame->buf.headroom = headroom; frame->buf.tailroom = tailroom; - -/* Kept to still update/calculate the other fields for now */ -frame_finalize (frame, - o->ce.link_mtu_defined, - o->ce.link_mtu, - o->ce.tun_mtu_defined, - o->ce.tun_mtu); - }/*
@@ -3104,8 +3072,8 @@ do_init_frame_tls(struct context *c)if (c->c2.tls_multi) {tls_multi_init_finalize (c->c2.tls_multi, &c->c2.frame); -ASSERT (EXPANDED_SIZE (&c->c2.tls_multi->opt.frame) <= -EXPANDED_SIZE (&c->c2.frame)); +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" ); }
@@ -3197,9 +3165,8 @@ do_init_frame(struct context *c)* Modify frame parameters if compression is compiled in. * Should be called after frame_finalize_options. */ -comp_add_to_extra_buffer (&c->c2.frame);#ifdef ENABLE_FRAGMENT -comp_add_to_extra_buffer (&c->c2.frame_fragment_omit);/* omit compression frame delta from final frame_fragment */ +/*TODO:frame comp_add_to_extra_buffer(&c->c2.frame_fragment_omit); omit compression frame delta from final frame_fragment */ #endif #endif /* USE_COMP */
src/openvpn/mtu.c +0 -26
@@ -205,31 +205,6 @@ calc_options_string_link_mtu(const struct options *o, const struct frame *frame)return payload + overhead; } -void -frame_finalize (struct frame *frame, -bool link_mtu_defined, -int link_mtu, -bool tun_mtu_defined, -int tun_mtu) -{ -/* Set link_mtu based on command line options */ -if (tun_mtu_defined) - { -ASSERT (!link_mtu_defined); - frame->link_mtu = tun_mtu +TUN_LINK_DELTA (frame); - } -else - { -ASSERT (link_mtu_defined); - frame->link_mtu = link_mtu; - } - -if (TUN_MTU_SIZE (frame) <TUN_MTU_MIN ) - { -msg (M_WARN ,"TUN MTU value (%d) must be at least %d" ,TUN_MTU_SIZE (frame),TUN_MTU_MIN ); -frame_print (frame,M_FATAL ,"MTU is too small" ); - } -}/* * Move extra_frame octets into extra_tun. Used by fragmenting code * to adjust frame relative to its position in the buffer processing
@@ -262,7 +237,6 @@ frame_print(const struct frame *frame,buf_printf (&out," headroom:%d" , frame->buf.headroom);buf_printf (&out," payload:%d" , frame->buf.payload_size);buf_printf (&out," tailroom:%d" , frame->buf.tailroom); -buf_printf (&out," L:%d" , frame->link_mtu);buf_printf (&out," EF:%d" , frame->extra_frame);buf_printf (&out," EB:%d" , frame->extra_buffer);buf_printf (&out," ET:%d" , frame->extra_tun);
src/openvpn/mtu.h +0 -22
@@ -110,9 +110,6 @@ struct frame {* decryption/encryption or compression. */ } buf; -int link_mtu;/**< Maximum packet size to be sent over -* the external network interface. */ -unsigned int mss_fix;/**< The actual MSS value that should be * written to the payload packets. This * is the value for IPv4 TCP packets. For
@@ -189,13 +186,6 @@ struct options;*/ #define PAYLOAD_SIZE (f) ((f)->buf.payload_size) -/* -* Max size of a payload packet after encryption, compression, etc. -* overhead is added. -*/ -#define EXPANDED_SIZE (f) ((f)->link_mtu) -#define EXPANDED_SIZE_MIN (f) (TUN_MTU_MIN + TUN_LINK_DELTA(f)) -/* * Control buffer headroom allocations to allow for efficient prepending. */
@@ -218,12 +208,6 @@ struct options;* Function prototypes. */ -void frame_finalize (struct frame *frame, -bool link_mtu_defined, -int link_mtu, -bool tun_mtu_defined, -int tun_mtu); -void frame_subtract_extra (struct frame *frame,const struct frame *src); void frame_print(const struct frame *frame,
@@ -347,12 +331,6 @@ const char *format_extended_socket_error(int fd, int *mtu, struct gc_arena *gc);* frame member adjustment functions */ -static inline void -frame_add_to_link_mtu (struct frame *frame,const int increment) -{ - frame->link_mtu += increment; -} -static inline void frame_add_to_extra_frame (struct frame *frame,const unsigned int increment) {
src/openvpn/ssl.c +0 -9
@@ -320,17 +320,11 @@ tls_init_control_channel_frame_parameters(const struct frame *data_channel_frame* if --tls-auth is enabled. */ -/* inherit link MTU and extra_link from data channel */ - frame->link_mtu = data_channel_frame->link_mtu; -/* set extra_frame */ tls_adjust_frame_parameters (frame);reliable_ack_adjust_frame_parameters (frame,CONTROL_SEND_ACK_MAX );frame_add_to_extra_frame (frame,SID_SIZE +sizeof (packet_id_type)); -/* set dynamic link MTU to cap control channel packets at 1250 bytes */ -ASSERT (TUN_LINK_DELTA (frame) <min_int (frame->link_mtu,1250 )); -/* calculate the maximum overhead that control channel frames may have */ int overhead =0 ;
@@ -1923,9 +1917,6 @@ tls_session_update_crypto_params_do_work(struct tls_session *session,if (frame_fragment) { -frame_remove_from_extra_frame (frame_fragment,crypto_max_overhead ()); -crypto_adjust_frame_parameters (frame_fragment, &session->opt->key_type, - options->replay, packet_id_long_form);frame_calculate_dynamic (frame_fragment, &session->opt->key_type, options, lsi);frame_print (frame_fragment,D_MTU_INFO ,"Fragmentation MTU parms" ); }
Signature · 1 line
2.33.0
PATCH v3 14/14 Remove frame.extra_frame and frame.extra_buffer
In reply to Arne Schwabe--- src/openvpn/comp.c | 7 ------ src/openvpn/comp.h | 2 -- src/openvpn/crypto.c | 37 --------------------------- src/openvpn/fragment.c | 3 --- src/openvpn/init.c | 56 ----------------------------------------- src/openvpn/mtu.c | 14 ----------- src/openvpn/mtu.h | 42 ++----------------------------- src/openvpn/reliable.c | 7 ------ src/openvpn/reliable.h | 3 --- src/openvpn/socket.c | 10 -------- src/openvpn/socket.h | 2 -- src/openvpn/ssl.c | 21 ---------------- src/openvpn/ssl.h | 5 ---- src/openvpn/tls_crypt.c | 10 -------- src/openvpn/tls_crypt.h | 5 ---- 15 files changed, 2 insertions(+), 222 deletions(-)
src/openvpn/comp.c +0 -7
@@ -116,13 +116,6 @@ comp_uninit(struct compress_context *compctx) } } -void -comp_add_to_extra_frame (struct frame *frame) -{ -/* Leave room for our one-byte compressed/didn't-compress prefix byte. */ -frame_add_to_extra_frame (frame,COMP_PREFIX_LEN ); -} -void comp_print_stats (const struct compress_context *compctx,struct status_output *so) {
src/openvpn/comp.h +0 -2
@@ -176,8 +176,6 @@ struct compress_context *comp_init(const struct compress_options *opt);void comp_uninit (struct compress_context *compctx); -void comp_add_to_extra_frame (struct frame *frame); -void comp_print_stats (const struct compress_context *compctx,struct status_output *so);void comp_generate_peer_info_string (const struct compress_options *opt,struct buffer *out);
src/openvpn/crypto.c +0 -37
@@ -716,43 +716,6 @@ calculate_crypto_overhead(const struct key_type *kt,return crypto_overhead; } -void -crypto_adjust_frame_parameters (struct frame *frame, -const struct key_type *kt, -bool packet_id, -bool packet_id_long_form) -{ -unsigned int crypto_overhead =0 ; - -if (packet_id) - { - crypto_overhead +=packet_id_size (packet_id_long_form); - } - -if (cipher_defined (kt->cipher)) - { - crypto_overhead +=cipher_kt_iv_size (kt->cipher); - -if (cipher_kt_mode_aead (kt->cipher)) - { - crypto_overhead +=cipher_kt_tag_size (kt->cipher); - } - -/* extra block required by cipher_ctx_update() */ - crypto_overhead +=cipher_kt_block_size (kt->cipher); - } - -if (md_defined (kt->digest)) - { - crypto_overhead +=md_kt_size (kt->digest); - } - -frame_add_to_extra_frame (frame, crypto_overhead); - -msg (D_MTU_DEBUG ,"%s: Adjusting frame parameters for crypto by %u bytes" , - __func__, crypto_overhead); -} -unsigned int crypto_max_overhead (void ) {
src/openvpn/fragment.c +0 -3
@@ -96,9 +96,6 @@ fragment_init(struct frame *frame)* fragment_master assume an initial CLEAR */ ALLOC_OBJ_CLEAR(ret, struct fragment_master); -/* add in the size of our contribution to the expanded frame size */ -frame_add_to_extra_frame (frame,sizeof (fragment_header_type)); -/* * Outgoing sequence ID is randomized to reduce * the probability of sequence number collisions
src/openvpn/init.c +0 -56
110 lines not on this page · raw message
src/openvpn/mtu.c +0 -14
@@ -205,18 +205,6 @@ calc_options_string_link_mtu(const struct options *o, const struct frame *frame)return payload + overhead; } -/* -* Move extra_frame octets into extra_tun. Used by fragmenting code -* to adjust frame relative to its position in the buffer processing -* queue. -*/ -void -frame_subtract_extra (struct frame *frame,const struct frame *src) -{ - frame->extra_frame -= src->extra_frame; - frame->extra_tun += src->extra_frame; -} - void frame_print(const struct frame *frame, int level,
@@ -237,8 +225,6 @@ frame_print(const struct frame *frame,buf_printf (&out," headroom:%d" , frame->buf.headroom);buf_printf (&out," payload:%d" , frame->buf.payload_size);buf_printf (&out," tailroom:%d" , frame->buf.tailroom); -buf_printf (&out," EF:%d" , frame->extra_frame); -buf_printf (&out," EB:%d" , frame->extra_buffer);buf_printf (&out," ET:%d" , frame->extra_tun);buf_printf (&out," ]" );
src/openvpn/mtu.h +2 -40
78 lines not on this page · raw message
src/openvpn/reliable.c +0 -7
@@ -253,13 +253,6 @@ error:return false; } -/* add to extra_frame the maximum number of bytes we will need for reliable_ack_write */ -void -reliable_ack_adjust_frame_parameters (struct frame *frame,int max) -{ -frame_add_to_extra_frame (frame,ACK_SIZE (max)); -} -/* print a reliable ACK record coming off the wire */ const char *reliable_ack_print (struct buffer *buf,bool verbose,struct gc_arena *gc)
src/openvpn/reliable.h +0 -3
@@ -207,9 +207,6 @@ void reliable_init(struct reliable *rel, int buf_size, int offset, int array_siz*/ void reliable_free (struct reliable *rel); -/* add to extra_frame the maximum number of bytes we will need for reliable_ack_write */ -void reliable_ack_adjust_frame_parameters (struct frame *frame,int max); -/** @} name Functions for initialization and cleanup */
src/openvpn/socket.c +0 -10
@@ -2285,16 +2285,6 @@ link_socket_close(struct link_socket *sock) } } -/* for stream protocols, allow for packet length prefix */ -void -socket_adjust_frame_parameters (struct frame *frame,int proto) -{ -if (link_socket_proto_connection_oriented (proto)) - { -frame_add_to_extra_frame (frame,sizeof (packet_size_type)); - } -} -void setenv_trusted (struct env_set *es,const struct link_socket_info *info) {
src/openvpn/socket.h +0 -2
@@ -298,8 +298,6 @@ void link_socket_init_phase2(struct context *c);void do_preresolve (struct context *c); -void socket_adjust_frame_parameters (struct frame *frame,int proto); -void link_socket_close (struct link_socket *sock);void sd_close (socket_descriptor_t *sd);
src/openvpn/ssl.c +0 -21
@@ -295,18 +295,6 @@ tls_limit_reneg_bytes(const char *ciphername, int *reneg_bytes) } } -/* -* Max number of bytes we will add -* for data structures common to both -* data and control channel packets. -* (opcode only). -*/ -void -tls_adjust_frame_parameters (struct frame *frame) -{ -frame_add_to_extra_frame (frame,1 );/* space for opcode */ -} -/* * Max number of bytes we will add * to control channel packet.
@@ -320,11 +308,6 @@ tls_init_control_channel_frame_parameters(const struct frame *data_channel_frame* if --tls-auth is enabled. */ -/* set extra_frame */ -tls_adjust_frame_parameters (frame); -reliable_ack_adjust_frame_parameters (frame,CONTROL_SEND_ACK_MAX ); -frame_add_to_extra_frame (frame,SID_SIZE +sizeof (packet_id_type)); -/* calculate the maximum overhead that control channel frames may have */ int overhead =0 ;
@@ -1900,10 +1883,6 @@ tls_session_update_crypto_params_do_work(struct tls_session *session, session->opt->crypto_flags |=CO_PACKET_ID_LONG_FORM ; } -/* Update frame parameters: undo worst-case overhead, add actual overhead */ -frame_remove_from_extra_frame (frame,crypto_max_overhead ()); -crypto_adjust_frame_parameters (frame, &session->opt->key_type, - options->replay, packet_id_long_form);frame_calculate_dynamic (frame, &session->opt->key_type, options, lsi);frame_print (frame,D_MTU_INFO ,"Data Channel MTU parms" );
src/openvpn/ssl.h +0 -5
@@ -471,11 +471,6 @@ void ssl_put_auth_challenge(const char *cr_str);#endif -/* -* Reserve any extra space required on frames. -*/ -void tls_adjust_frame_parameters (struct frame *frame); -/* * Send a payload over the TLS control channel */
src/openvpn/tls_crypt.c +0 -10
@@ -89,16 +89,6 @@ tls_crypt_init_key(struct key_ctx_bi *key, const char *key_file, "Control Channel Encryption", "tls-crypt"); } -void -tls_crypt_adjust_frame_parameters (struct frame *frame) -{ -frame_add_to_extra_frame (frame,tls_crypt_buf_overhead ()); - -msg (D_MTU_DEBUG ,"%s: Adjusting frame parameters for tls-crypt by %i bytes" , - __func__,tls_crypt_buf_overhead ()); -} - -bool tls_crypt_wrap (const struct buffer *src,struct buffer *dst,struct crypto_options *opt)
src/openvpn/tls_crypt.h +0 -5
@@ -123,11 +123,6 @@ void tls_crypt_init_key(struct key_ctx_bi *key, const char *key_file,*/ int tls_crypt_buf_overhead (void ); -/** -* Adjust frame parameters for --tls-crypt overhead. -*/ -void tls_crypt_adjust_frame_parameters (struct frame *frame); -/** * Wrap a control channel packet (both authenticates and encrypts the data). *
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 03/14] Change buffer allocation calculation and checks to be more static
In reply to Arne SchwabeGet Outlook for iOS<https://aka.ms/o0ukef>
________________________________
From: Arne Schwabe <[email protected]...>
Sent: Saturday, January 1, 2022 5:26 PM
To: [email protected]
Subject: [Openvpn-devel] [PATCH v3 03/14] Change buffer allocation calculation and checks to be more static
Currently we use half dynamic buffer sizes where we use have a fixed overhead for crypto (crypto_max_overhead) but use a dynamic overhead for the the other small header sizes.
--- src/openvpn/comp-lz4.c | 4 +- src/openvpn/crypto.c | 4 +- src/openvpn/forward.c | 8 +-- src/openvpn/init.c | 107 +++++++++++++++++++++++++++++++++++---- src/openvpn/lzo.c | 2 +- src/openvpn/mtu.c | 7 ++- src/openvpn/mtu.h | 74 ++++++++++++++------------- src/openvpn/multi.c | 4 +- src/openvpn/multi.h | 2 +- src/openvpn/occ.c | 4 +- src/openvpn/options.c | 2 +- src/openvpn/ping.c | 2 +- src/openvpn/ssl.c | 35 ++++++++++--- src/openvpn/ssl_common.h | 3 +- 14 files changed, 187 insertions(+), 71 deletions(-)
src/openvpn/comp-lz4.c +2 -2
@@ -213,7 +213,7 @@ lz4_decompress(struct buffer *buf, struct buffer work,struct compress_context *compctx, const struct frame *frame) { - size_t zlen_max = EXPANDED_SIZE(frame); + size_t zlen_max = frame->buf.payload_size;uint8_t c;/* flag indicating whether or not our peer compressed */ if (buf->len <=0 )
@@ -250,7 +250,7 @@ lz4v2_decompress(struct buffer *buf, struct buffer work,struct compress_context *compctx, const struct frame *frame) { - size_t zlen_max = EXPANDED_SIZE(frame); + size_t zlen_max = frame->buf.payload_size;uint8_t c;/* flag indicating whether or not our peer compressed */ if (buf->len <=0 )
src/openvpn/crypto.c +2 -2
@@ -1064,7 +1064,7 @@ test_crypto(struct crypto_options *co, struct frame *frame) {int i, j;struct gc_arena gc =gc_new (); -struct buffer src =alloc_buf_gc (TUN_MTU_SIZE (frame), &gc); +struct buffer src =alloc_buf_gc (frame->buf.payload_size, &gc);struct buffer work =alloc_buf_gc (BUF_SIZE (frame), &gc);struct buffer encrypt_workspace =alloc_buf_gc (BUF_SIZE (frame), &gc);struct buffer decrypt_workspace =alloc_buf_gc (BUF_SIZE (frame), &gc);
@@ -1095,7 +1095,7 @@ test_crypto(struct crypto_options *co, struct frame *frame) }msg (M_INFO ,"Entering " PACKAGE_NAME " crypto self-test mode." ); -for (i =1 ; i <=TUN_MTU_SIZE (frame); ++i) +for (i =1 ; i <= frame->buf.payload_size; ++i) {update_time ();
src/openvpn/forward.c +4 -4
@@ -1119,8 +1119,8 @@ read_incoming_tun(struct context *c) }#else /* ifdef _WIN32 */ ASSERT (buf_init (&c->c2.buf,FRAME_HEADROOM (&c->c2.frame))); -ASSERT (buf_safe (&c->c2.buf,MAX_RW_SIZE_TUN (&c->c2.frame))); - c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf),MAX_RW_SIZE_TUN (&c->c2.frame)); +ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size)); + c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size);#endif /* ifdef _WIN32 */ #ifdef PACKET_TRUNCATION_CHECK
@@ -1709,7 +1709,7 @@ process_outgoing_tun(struct context *c)PIP_MSSFIX |PIPV4_EXTRACT_DHCP_ROUTER |PIPV4_CLIENT_NAT |PIP_OUTGOING , &c->c2.to_tun); -if (c->c2.to_tun.len <=MAX_RW_SIZE_TUN (&c->c2.frame)) +if (c->c2.to_tun.len <= c->c2.frame.buf.payload_size) {/* * Write to TUN/TAP device.
@@ -1769,7 +1769,7 @@ process_outgoing_tun(struct context *c)*/ msg (D_LINK_ERRORS ,"tun packet too large on write (tried=%d,max=%d)" , c->c2.to_tun.len, -MAX_RW_SIZE_TUN (&c->c2.frame)); + c->c2.frame.buf.payload_size); }buf_reset (&c->c2.to_tun);
src/openvpn/init.c +97 -10
139 lines not on this page · raw message
src/openvpn/lzo.c +1 -1
@@ -213,7 +213,7 @@ lzo_decompress(struct buffer *buf, struct buffer work,struct compress_context *compctx, const struct frame *frame) { - lzo_uint zlen = EXPANDED_SIZE(frame); + lzo_uint zlen = frame->buf.payload_size;int err;uint8_t c;/* flag indicating whether or not our peer compressed */
src/openvpn/mtu.c +6 -1
@@ -48,7 +48,7 @@ alloc_buf_sock_tun(struct buffer *buf,/* allocate buffer for overlapped I/O */ *buf =alloc_buf (BUF_SIZE (frame));ASSERT (buf_init (buf,FRAME_HEADROOM (frame))); - buf->len = tuntap_buffer ?MAX_RW_SIZE_TUN (frame) :MAX_RW_SIZE_LINK (frame); + buf->len = frame->buf.payload_size;ASSERT (buf_safe (buf,0 )); }
@@ -296,6 +296,11 @@ frame_print(const struct frame *frame,buf_printf (&out,"%s " , prefix); }buf_printf (&out,"[" ); +buf_printf (&out," mss_fix:%d" , frame->mss_fix); +buf_printf (&out," tun_mtu:%d" , frame->tun_mtu); +buf_printf (&out," headroom:%d" , frame->buf.headroom); +buf_printf (&out," payload:%d" , frame->buf.payload_size); +buf_printf (&out," tailroom:%d" , frame->buf.tailroom);buf_printf (&out," L:%d" , frame->link_mtu);buf_printf (&out," D:%d" , frame->link_mtu_dynamic);buf_printf (&out," EF:%d" , frame->extra_frame);
src/openvpn/mtu.h +39 -35
121 lines not on this page · raw message
src/openvpn/multi.c +2 -2
@@ -3495,7 +3495,7 @@ gremlin_flood_clients(struct multi_context *m)int i;ASSERT (buf_init (&buf,FRAME_HEADROOM (&m->top.c2.frame))); - parm.packet_size =min_int (parm.packet_size,MAX_RW_SIZE_TUN (&m->top.c2.frame)); + parm.packet_size =min_int (parm.packet_size, m->top.c2.frame.buf.payload_size); msg(D_GREMLIN, "GREMLIN_FLOOD_CLIENTS: flooding clients with %d packets of size %d", parm.n_packets,
@@ -3557,7 +3557,7 @@ multi_process_per_second_timers_dowork(struct multi_context *m) }void -multi_top_init (struct multi_context *m,const struct context *top) +multi_top_init (struct multi_context *m,struct context *top) {inherit_context_top (&m->top, top); m->top.c2.buffers =init_context_buffers (&top->c2.frame);
src/openvpn/multi.h +1 -1
@@ -257,7 +257,7 @@ void multi_init(struct multi_context *m, struct context *t, bool tcp_mode);void multi_uninit (struct multi_context *m); -void multi_top_init (struct multi_context *m,const struct context *top); +void multi_top_init (struct multi_context *m,struct context *top);void multi_top_free (struct multi_context *m);
src/openvpn/occ.c +2 -2
@@ -219,7 +219,7 @@ check_send_occ_msg_dowork(struct context *c) c->c2.buf = c->c2.buffers->aux_buf;ASSERT (buf_init (&c->c2.buf,FRAME_HEADROOM (&c->c2.frame))); -ASSERT (buf_safe (&c->c2.buf,MAX_RW_SIZE_TUN (&c->c2.frame))); +ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size));ASSERT (buf_write (&c->c2.buf, occ_magic,OCC_STRING_SIZE )); switch (c->c2.occ_op)
@@ -319,7 +319,7 @@ check_send_occ_msg_dowork(struct context *c)OCC_STRING_SIZE , (int )sizeof (uint8_t ),EXTRA_FRAME (&c->c2.frame), -MAX_RW_SIZE_TUN (&c->c2.frame), + c->c2.frame.buf.payload_size, BLEN(&c->c2.buf)); doit = true; }
src/openvpn/options.c +1 -1
@@ -3832,7 +3832,7 @@ options_string(const struct options *o,buf_printf (&out,",link-mtu %u" , (unsigned int )calc_options_string_link_mtu (o, frame)); -buf_printf (&out,",tun-mtu %d" ,PAYLOAD_SIZE (frame)); +buf_printf (&out,",tun-mtu %d" , frame->tun_mtu);buf_printf (&out,",proto %s" ,proto_remote (o->ce.proto, remote));bool p2p_nopull = o->mode ==MODE_POINT_TO_POINT && !PULL_DEFINED (o);
src/openvpn/ping.c +1 -1
@@ -80,7 +80,7 @@ check_ping_send_dowork(struct context *c) { c->c2.buf = c->c2.buffers->aux_buf;ASSERT (buf_init (&c->c2.buf,FRAME_HEADROOM (&c->c2.frame))); -ASSERT (buf_safe (&c->c2.buf,MAX_RW_SIZE_TUN (&c->c2.frame))); +ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size));ASSERT (buf_write (&c->c2.buf, ping_string,sizeof (ping_string)));/*
src/openvpn/ssl.c +27 -8
@@ -332,6 +332,32 @@ tls_init_control_channel_frame_parameters(const struct frame *data_channel_frame/* set dynamic link MTU to cap control channel packets at 1250 bytes */ ASSERT (TUN_LINK_DELTA (frame) <min_int (frame->link_mtu,1250 )); frame->link_mtu_dynamic =min_int (frame->link_mtu,1250 ) -TUN_LINK_DELTA (frame); + +/* calculate the maximum overhead that control channel frames may have */ +int overhead =0 ; + +/* Socks */ + overhead +=10 ; + +/* tls-auth and tls-crypt */ + overhead +=max_int (tls_crypt_buf_overhead (), +packet_id_size (true) +OPENVPN_MAX_HMAC_SIZE ); + +/* TCP length field and opcode */ + overhead+=3 ; + +/* Previous OpenVPN version calculated the maximum size and buffer of a +* control frame depending on the overhead of the data channel frame +* overhead and limited its maximum size to 1250. We always allocate the +* 1250 buffer size since a lot of code blindly assumes a large buffer +* (e.g. PUSH_BUNDLE_SIZE) and set frame->mtu_mtu as suggestion for the +* size */ + frame->buf.payload_size =1250 + overhead; + + frame->buf.headroom = overhead; + frame->buf.tailroom = overhead; + + frame->tun_mtu =min_int (data_channel_frame->tun_mtu,1250 ); }void
@@ -1870,13 +1896,6 @@ tls_session_update_crypto_params_do_work(struct tls_session *session,msg (D_HANDSHAKE ,"Data Channel: using negotiated cipher '%s'" , options->ciphername); } -else - { -/* Very hacky workaround and quick fix for frame calculation -* different when adjusting frame size when the original and new cipher -* are identical to avoid a regression with client without NCP */ -return tls_session_generate_data_channel_keys (session); - }init_key_type (&session->opt->key_type, options->ciphername, options->authname, true, true);
@@ -2959,7 +2978,7 @@ tls_process(struct tls_multi *multi, buf =reliable_get_buf_output_sequenced (ks->send_reliable);if (buf) { -int status =key_state_read_ciphertext (&ks->ks_ssl, buf,PAYLOAD_SIZE_DYNAMIC (&multi->opt.frame)); +int status =key_state_read_ciphertext (&ks->ks_ssl, buf, multi->opt.frame.tun_mtu);if (status ==-1 ) { msg(D_TLS_ERRORS,
src/openvpn/ssl_common.h +2 -1
@@ -221,8 +221,9 @@ struct key_statestruct reliable *rec_reliable;/* order incoming ciphertext packets before we pass to TLS */ struct reliable_ack *rec_ack;/* buffers all packet IDs we want to ACK back to sender */ +/** Holds outgoing message for the control channel until ks->state reaches +* S_ACTIVE */ struct buffer_list *paybuf; -counter_type n_bytes;/* how many bytes sent/recvd since last key exchange */ counter_type n_packets;/* how many packets sent/recvd since last key exchange */
--
2.33.0
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Fopenvpn-devel&data=04%7C01%7C%7Cc6b0d28a607f43d51a2008d9cd437553%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637766511911959351%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=7JCqlDEY7ZQhaObeHQ%2FaEL77ZhIgLdjhR5G7HVnkquA%3D&reserved=0
PATCH v4 1/1 Change buffer allocation calculation and checks to be more static
In reply to Arne SchwabeCurrently we use half dynamic buffer sizes where we use have a fixed overhead for crypto (crypto_max_overhead) but use a dynamic overhead for the the other small header sizes.
Patch v3: rebase
Patch v4: add size of ack array to control channel frame size
--- src/openvpn/comp-lz4.c | 4 +- src/openvpn/crypto.c | 4 +- src/openvpn/forward.c | 8 +-- src/openvpn/init.c | 107 +++++++++++++++++++++++++++++++++++---- src/openvpn/lzo.c | 2 +- src/openvpn/mtu.c | 7 ++- src/openvpn/mtu.h | 74 ++++++++++++++------------- src/openvpn/multi.c | 4 +- src/openvpn/multi.h | 2 +- src/openvpn/occ.c | 4 +- src/openvpn/options.c | 2 +- src/openvpn/ping.c | 2 +- src/openvpn/reliable.c | 2 - src/openvpn/reliable.h | 3 ++ src/openvpn/ssl.c | 38 +++++++++++--- src/openvpn/ssl_common.h | 3 +- 16 files changed, 193 insertions(+), 73 deletions(-)
src/openvpn/comp-lz4.c +2 -2
@@ -213,7 +213,7 @@ lz4_decompress(struct buffer *buf, struct buffer work,struct compress_context *compctx, const struct frame *frame) { - size_t zlen_max = EXPANDED_SIZE(frame); + size_t zlen_max = frame->buf.payload_size;uint8_t c;/* flag indicating whether or not our peer compressed */ if (buf->len <=0 )
@@ -250,7 +250,7 @@ lz4v2_decompress(struct buffer *buf, struct buffer work,struct compress_context *compctx, const struct frame *frame) { - size_t zlen_max = EXPANDED_SIZE(frame); + size_t zlen_max = frame->buf.payload_size;uint8_t c;/* flag indicating whether or not our peer compressed */ if (buf->len <=0 )
src/openvpn/crypto.c +2 -2
@@ -1064,7 +1064,7 @@ test_crypto(struct crypto_options *co, struct frame *frame) {int i, j;struct gc_arena gc =gc_new (); -struct buffer src =alloc_buf_gc (TUN_MTU_SIZE (frame), &gc); +struct buffer src =alloc_buf_gc (frame->buf.payload_size, &gc);struct buffer work =alloc_buf_gc (BUF_SIZE (frame), &gc);struct buffer encrypt_workspace =alloc_buf_gc (BUF_SIZE (frame), &gc);struct buffer decrypt_workspace =alloc_buf_gc (BUF_SIZE (frame), &gc);
@@ -1095,7 +1095,7 @@ test_crypto(struct crypto_options *co, struct frame *frame) }msg (M_INFO ,"Entering " PACKAGE_NAME " crypto self-test mode." ); -for (i =1 ; i <=TUN_MTU_SIZE (frame); ++i) +for (i =1 ; i <= frame->buf.payload_size; ++i) {update_time ();
src/openvpn/forward.c +4 -4
@@ -1119,8 +1119,8 @@ read_incoming_tun(struct context *c) }#else /* ifdef _WIN32 */ ASSERT (buf_init (&c->c2.buf,FRAME_HEADROOM (&c->c2.frame))); -ASSERT (buf_safe (&c->c2.buf,MAX_RW_SIZE_TUN (&c->c2.frame))); - c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf),MAX_RW_SIZE_TUN (&c->c2.frame)); +ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size)); + c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size);#endif /* ifdef _WIN32 */ #ifdef PACKET_TRUNCATION_CHECK
@@ -1709,7 +1709,7 @@ process_outgoing_tun(struct context *c)PIP_MSSFIX |PIPV4_EXTRACT_DHCP_ROUTER |PIPV4_CLIENT_NAT |PIP_OUTGOING , &c->c2.to_tun); -if (c->c2.to_tun.len <=MAX_RW_SIZE_TUN (&c->c2.frame)) +if (c->c2.to_tun.len <= c->c2.frame.buf.payload_size) {/* * Write to TUN/TAP device.
@@ -1769,7 +1769,7 @@ process_outgoing_tun(struct context *c)*/ msg (D_LINK_ERRORS ,"tun packet too large on write (tried=%d,max=%d)" , c->c2.to_tun.len, -MAX_RW_SIZE_TUN (&c->c2.frame)); + c->c2.frame.buf.payload_size); }buf_reset (&c->c2.to_tun);
src/openvpn/init.c +97 -10
139 lines not on this page · raw message
src/openvpn/lzo.c +1 -1
@@ -213,7 +213,7 @@ lzo_decompress(struct buffer *buf, struct buffer work,struct compress_context *compctx, const struct frame *frame) { - lzo_uint zlen = EXPANDED_SIZE(frame); + lzo_uint zlen = frame->buf.payload_size;int err;uint8_t c;/* flag indicating whether or not our peer compressed */
src/openvpn/mtu.c +6 -1
@@ -48,7 +48,7 @@ alloc_buf_sock_tun(struct buffer *buf,/* allocate buffer for overlapped I/O */ *buf =alloc_buf (BUF_SIZE (frame));ASSERT (buf_init (buf,FRAME_HEADROOM (frame))); - buf->len = tuntap_buffer ?MAX_RW_SIZE_TUN (frame) :MAX_RW_SIZE_LINK (frame); + buf->len = frame->buf.payload_size;ASSERT (buf_safe (buf,0 )); }
@@ -296,6 +296,11 @@ frame_print(const struct frame *frame,buf_printf (&out,"%s " , prefix); }buf_printf (&out,"[" ); +buf_printf (&out," mss_fix:%d" , frame->mss_fix); +buf_printf (&out," tun_mtu:%d" , frame->tun_mtu); +buf_printf (&out," headroom:%d" , frame->buf.headroom); +buf_printf (&out," payload:%d" , frame->buf.payload_size); +buf_printf (&out," tailroom:%d" , frame->buf.tailroom);buf_printf (&out," L:%d" , frame->link_mtu);buf_printf (&out," D:%d" , frame->link_mtu_dynamic);buf_printf (&out," EF:%d" , frame->extra_frame);
src/openvpn/mtu.h +39 -35
121 lines not on this page · raw message
src/openvpn/multi.c +2 -2
@@ -3495,7 +3495,7 @@ gremlin_flood_clients(struct multi_context *m)int i;ASSERT (buf_init (&buf,FRAME_HEADROOM (&m->top.c2.frame))); - parm.packet_size =min_int (parm.packet_size,MAX_RW_SIZE_TUN (&m->top.c2.frame)); + parm.packet_size =min_int (parm.packet_size, m->top.c2.frame.buf.payload_size); msg(D_GREMLIN, "GREMLIN_FLOOD_CLIENTS: flooding clients with %d packets of size %d", parm.n_packets,
@@ -3557,7 +3557,7 @@ multi_process_per_second_timers_dowork(struct multi_context *m) }void -multi_top_init (struct multi_context *m,const struct context *top) +multi_top_init (struct multi_context *m,struct context *top) {inherit_context_top (&m->top, top); m->top.c2.buffers =init_context_buffers (&top->c2.frame);
src/openvpn/multi.h +1 -1
@@ -257,7 +257,7 @@ void multi_init(struct multi_context *m, struct context *t, bool tcp_mode);void multi_uninit (struct multi_context *m); -void multi_top_init (struct multi_context *m,const struct context *top); +void multi_top_init (struct multi_context *m,struct context *top);void multi_top_free (struct multi_context *m);
src/openvpn/occ.c +2 -2
@@ -219,7 +219,7 @@ check_send_occ_msg_dowork(struct context *c) c->c2.buf = c->c2.buffers->aux_buf;ASSERT (buf_init (&c->c2.buf,FRAME_HEADROOM (&c->c2.frame))); -ASSERT (buf_safe (&c->c2.buf,MAX_RW_SIZE_TUN (&c->c2.frame))); +ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size));ASSERT (buf_write (&c->c2.buf, occ_magic,OCC_STRING_SIZE )); switch (c->c2.occ_op)
@@ -319,7 +319,7 @@ check_send_occ_msg_dowork(struct context *c)OCC_STRING_SIZE , (int )sizeof (uint8_t ),EXTRA_FRAME (&c->c2.frame), -MAX_RW_SIZE_TUN (&c->c2.frame), + c->c2.frame.buf.payload_size, BLEN(&c->c2.buf)); doit = true; }
src/openvpn/options.c +1 -1
@@ -3832,7 +3832,7 @@ options_string(const struct options *o,buf_printf (&out,",link-mtu %u" , (unsigned int )calc_options_string_link_mtu (o, frame)); -buf_printf (&out,",tun-mtu %d" ,PAYLOAD_SIZE (frame)); +buf_printf (&out,",tun-mtu %d" , frame->tun_mtu);buf_printf (&out,",proto %s" ,proto_remote (o->ce.proto, remote));bool p2p_nopull = o->mode ==MODE_POINT_TO_POINT && !PULL_DEFINED (o);
src/openvpn/ping.c +1 -1
@@ -80,7 +80,7 @@ check_ping_send_dowork(struct context *c) { c->c2.buf = c->c2.buffers->aux_buf;ASSERT (buf_init (&c->c2.buf,FRAME_HEADROOM (&c->c2.frame))); -ASSERT (buf_safe (&c->c2.buf,MAX_RW_SIZE_TUN (&c->c2.frame))); +ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size));ASSERT (buf_write (&c->c2.buf, ping_string,sizeof (ping_string)));/*
src/openvpn/reliable.c +0 -2
@@ -205,8 +205,6 @@ error:return false; } -#define ACK_SIZE (n) (sizeof(uint8_t) + ((n) ? SID_SIZE : 0) + sizeof(packet_id_type) * (n)) -/* write a packet ID acknowledgement record to buf, */ /* removing all acknowledged entries from ack */ bool
src/openvpn/reliable.h +3 -0
@@ -66,6 +66,9 @@ struct reliable_ackpacket_id_type packet_id[RELIABLE_ACK_SIZE ]; }; +/* The size of the ACK header */ +#define ACK_SIZE (n) (sizeof(uint8_t) + ((n) ? SID_SIZE : 0) + sizeof(packet_id_type) * (n)) +/** * The structure in which the reliability layer stores a single incoming * or outgoing packet.
src/openvpn/ssl.c +30 -8
@@ -332,6 +332,35 @@ tls_init_control_channel_frame_parameters(const struct frame *data_channel_frame/* set dynamic link MTU to cap control channel packets at 1250 bytes */ ASSERT (TUN_LINK_DELTA (frame) <min_int (frame->link_mtu,1250 )); frame->link_mtu_dynamic =min_int (frame->link_mtu,1250 ) -TUN_LINK_DELTA (frame); + +/* calculate the maximum overhead that control channel frames may have */ +int overhead =0 ; + +/* Socks */ + overhead +=10 ; + +/* tls-auth and tls-crypt */ + overhead +=max_int (tls_crypt_buf_overhead (), +packet_id_size (true) +OPENVPN_MAX_HMAC_SIZE ); + +/* TCP length field and opcode */ + overhead+=3 ; + +/* ACK array and remote SESSION ID (part of the ACK array) */ + overhead +=ACK_SIZE (RELIABLE_ACK_SIZE ); + +/* Previous OpenVPN version calculated the maximum size and buffer of a +* control frame depending on the overhead of the data channel frame +* overhead and limited its maximum size to 1250. We always allocate the +* 1250 buffer size since a lot of code blindly assumes a large buffer +* (e.g. PUSH_BUNDLE_SIZE) and set frame->mtu_mtu as suggestion for the +* size */ + frame->buf.payload_size =1250 + overhead; + + frame->buf.headroom = overhead; + frame->buf.tailroom = overhead; + + frame->tun_mtu =min_int (data_channel_frame->tun_mtu,1250 ); }void
@@ -1870,13 +1899,6 @@ tls_session_update_crypto_params_do_work(struct tls_session *session,msg (D_HANDSHAKE ,"Data Channel: using negotiated cipher '%s'" , options->ciphername); } -else - { -/* Very hacky workaround and quick fix for frame calculation -* different when adjusting frame size when the original and new cipher -* are identical to avoid a regression with client without NCP */ -return tls_session_generate_data_channel_keys (session); - }init_key_type (&session->opt->key_type, options->ciphername, options->authname, true, true);
@@ -2959,7 +2981,7 @@ tls_process(struct tls_multi *multi, buf =reliable_get_buf_output_sequenced (ks->send_reliable);if (buf) { -int status =key_state_read_ciphertext (&ks->ks_ssl, buf,PAYLOAD_SIZE_DYNAMIC (&multi->opt.frame)); +int status =key_state_read_ciphertext (&ks->ks_ssl, buf, multi->opt.frame.tun_mtu);if (status ==-1 ) { msg(D_TLS_ERRORS,
src/openvpn/ssl_common.h +2 -1
@@ -221,8 +221,9 @@ struct key_statestruct reliable *rec_reliable;/* order incoming ciphertext packets before we pass to TLS */ struct reliable_ack *rec_ack;/* buffers all packet IDs we want to ACK back to sender */ +/** Holds outgoing message for the control channel until ks->state reaches +* S_ACTIVE */ struct buffer_list *paybuf; -counter_type n_bytes;/* how many bytes sent/recvd since last key exchange */ counter_type n_packets;/* how many packets sent/recvd since last key exchange */
Signature · 1 line
2.33.0
PATCH v5 1/1 Change buffer allocation calculation and checks to be more static
In reply to Arne SchwabeCurrently we use half dynamic buffer sizes where we use have a fixed overhead for crypto (crypto_max_overhead) but use a dynamic overhead for the the other small header sizes.
Patch v3: rebase
Patch v4: add size of ack array to control channel frame size Patch v5: fix calculation of compression overhead calculated over 0 instead
of payload size
--- src/openvpn/comp-lz4.c | 4 +- src/openvpn/crypto.c | 4 +- src/openvpn/forward.c | 8 +-- src/openvpn/init.c | 110 +++++++++++++++++++++++++++++++++++---- src/openvpn/lzo.c | 2 +- src/openvpn/mtu.c | 7 ++- src/openvpn/mtu.h | 74 +++++++++++++------------- src/openvpn/multi.c | 4 +- src/openvpn/multi.h | 2 +- src/openvpn/occ.c | 4 +- src/openvpn/options.c | 2 +- src/openvpn/ping.c | 2 +- src/openvpn/reliable.c | 2 - src/openvpn/reliable.h | 3 ++ src/openvpn/ssl.c | 38 +++++++++++--- src/openvpn/ssl_common.h | 3 +- 16 files changed, 196 insertions(+), 73 deletions(-)
src/openvpn/comp-lz4.c +2 -2
@@ -213,7 +213,7 @@ lz4_decompress(struct buffer *buf, struct buffer work,struct compress_context *compctx, const struct frame *frame) { - size_t zlen_max = EXPANDED_SIZE(frame); + size_t zlen_max = frame->buf.payload_size;uint8_t c;/* flag indicating whether or not our peer compressed */ if (buf->len <=0 )
@@ -250,7 +250,7 @@ lz4v2_decompress(struct buffer *buf, struct buffer work,struct compress_context *compctx, const struct frame *frame) { - size_t zlen_max = EXPANDED_SIZE(frame); + size_t zlen_max = frame->buf.payload_size;uint8_t c;/* flag indicating whether or not our peer compressed */ if (buf->len <=0 )
src/openvpn/crypto.c +2 -2
@@ -1065,7 +1065,7 @@ test_crypto(struct crypto_options *co, struct frame *frame) {int i, j;struct gc_arena gc =gc_new (); -struct buffer src =alloc_buf_gc (TUN_MTU_SIZE (frame), &gc); +struct buffer src =alloc_buf_gc (frame->buf.payload_size, &gc);struct buffer work =alloc_buf_gc (BUF_SIZE (frame), &gc);struct buffer encrypt_workspace =alloc_buf_gc (BUF_SIZE (frame), &gc);struct buffer decrypt_workspace =alloc_buf_gc (BUF_SIZE (frame), &gc);
@@ -1096,7 +1096,7 @@ test_crypto(struct crypto_options *co, struct frame *frame) }msg (M_INFO ,"Entering " PACKAGE_NAME " crypto self-test mode." ); -for (i =1 ; i <=TUN_MTU_SIZE (frame); ++i) +for (i =1 ; i <= frame->buf.payload_size; ++i) {update_time ();
src/openvpn/forward.c +4 -4
@@ -1120,8 +1120,8 @@ read_incoming_tun(struct context *c) }#else /* ifdef _WIN32 */ ASSERT (buf_init (&c->c2.buf,FRAME_HEADROOM (&c->c2.frame))); -ASSERT (buf_safe (&c->c2.buf,MAX_RW_SIZE_TUN (&c->c2.frame))); - c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf),MAX_RW_SIZE_TUN (&c->c2.frame)); +ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size)); + c->c2.buf.len =read_tun (c->c1.tuntap,BPTR (&c->c2.buf), c->c2.frame.buf.payload_size);#endif /* ifdef _WIN32 */ #ifdef PACKET_TRUNCATION_CHECK
@@ -1710,7 +1710,7 @@ process_outgoing_tun(struct context *c)PIP_MSSFIX |PIPV4_EXTRACT_DHCP_ROUTER |PIPV4_CLIENT_NAT |PIP_OUTGOING , &c->c2.to_tun); -if (c->c2.to_tun.len <=MAX_RW_SIZE_TUN (&c->c2.frame)) +if (c->c2.to_tun.len <= c->c2.frame.buf.payload_size) {/* * Write to TUN/TAP device.
@@ -1770,7 +1770,7 @@ process_outgoing_tun(struct context *c)*/ msg (D_LINK_ERRORS ,"tun packet too large on write (tried=%d,max=%d)" , c->c2.to_tun.len, -MAX_RW_SIZE_TUN (&c->c2.frame)); + c->c2.frame.buf.payload_size); }buf_reset (&c->c2.to_tun);
src/openvpn/init.c +100 -10
142 lines not on this page · raw message
src/openvpn/lzo.c +1 -1
@@ -213,7 +213,7 @@ lzo_decompress(struct buffer *buf, struct buffer work,struct compress_context *compctx, const struct frame *frame) { - lzo_uint zlen = EXPANDED_SIZE(frame); + lzo_uint zlen = frame->buf.payload_size;int err;uint8_t c;/* flag indicating whether or not our peer compressed */
src/openvpn/mtu.c +6 -1
@@ -48,7 +48,7 @@ alloc_buf_sock_tun(struct buffer *buf,/* allocate buffer for overlapped I/O */ *buf =alloc_buf (BUF_SIZE (frame));ASSERT (buf_init (buf,FRAME_HEADROOM (frame))); - buf->len = tuntap_buffer ?MAX_RW_SIZE_TUN (frame) :MAX_RW_SIZE_LINK (frame); + buf->len = frame->buf.payload_size;ASSERT (buf_safe (buf,0 )); }
@@ -296,6 +296,11 @@ frame_print(const struct frame *frame,buf_printf (&out,"%s " , prefix); }buf_printf (&out,"[" ); +buf_printf (&out," mss_fix:%d" , frame->mss_fix); +buf_printf (&out," tun_mtu:%d" , frame->tun_mtu); +buf_printf (&out," headroom:%d" , frame->buf.headroom); +buf_printf (&out," payload:%d" , frame->buf.payload_size); +buf_printf (&out," tailroom:%d" , frame->buf.tailroom);buf_printf (&out," L:%d" , frame->link_mtu);buf_printf (&out," D:%d" , frame->link_mtu_dynamic);buf_printf (&out," EF:%d" , frame->extra_frame);
src/openvpn/mtu.h +39 -35
121 lines not on this page · raw message
src/openvpn/multi.c +2 -2
@@ -3495,7 +3495,7 @@ gremlin_flood_clients(struct multi_context *m)int i;ASSERT (buf_init (&buf,FRAME_HEADROOM (&m->top.c2.frame))); - parm.packet_size =min_int (parm.packet_size,MAX_RW_SIZE_TUN (&m->top.c2.frame)); + parm.packet_size =min_int (parm.packet_size, m->top.c2.frame.buf.payload_size); msg(D_GREMLIN, "GREMLIN_FLOOD_CLIENTS: flooding clients with %d packets of size %d", parm.n_packets,
@@ -3557,7 +3557,7 @@ multi_process_per_second_timers_dowork(struct multi_context *m) }void -multi_top_init (struct multi_context *m,const struct context *top) +multi_top_init (struct multi_context *m,struct context *top) {inherit_context_top (&m->top, top); m->top.c2.buffers =init_context_buffers (&top->c2.frame);
src/openvpn/multi.h +1 -1
@@ -257,7 +257,7 @@ void multi_init(struct multi_context *m, struct context *t, bool tcp_mode);void multi_uninit (struct multi_context *m); -void multi_top_init (struct multi_context *m,const struct context *top); +void multi_top_init (struct multi_context *m,struct context *top);void multi_top_free (struct multi_context *m);
src/openvpn/occ.c +2 -2
@@ -219,7 +219,7 @@ check_send_occ_msg_dowork(struct context *c) c->c2.buf = c->c2.buffers->aux_buf;ASSERT (buf_init (&c->c2.buf,FRAME_HEADROOM (&c->c2.frame))); -ASSERT (buf_safe (&c->c2.buf,MAX_RW_SIZE_TUN (&c->c2.frame))); +ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size));ASSERT (buf_write (&c->c2.buf, occ_magic,OCC_STRING_SIZE )); switch (c->c2.occ_op)
@@ -319,7 +319,7 @@ check_send_occ_msg_dowork(struct context *c)OCC_STRING_SIZE , (int )sizeof (uint8_t ),EXTRA_FRAME (&c->c2.frame), -MAX_RW_SIZE_TUN (&c->c2.frame), + c->c2.frame.buf.payload_size, BLEN(&c->c2.buf)); doit = true; }
src/openvpn/options.c +1 -1
@@ -3833,7 +3833,7 @@ options_string(const struct options *o,buf_printf (&out,",link-mtu %u" , (unsigned int )calc_options_string_link_mtu (o, frame)); -buf_printf (&out,",tun-mtu %d" ,PAYLOAD_SIZE (frame)); +buf_printf (&out,",tun-mtu %d" , frame->tun_mtu);buf_printf (&out,",proto %s" ,proto_remote (o->ce.proto, remote));bool p2p_nopull = o->mode ==MODE_POINT_TO_POINT && !PULL_DEFINED (o);
src/openvpn/ping.c +1 -1
@@ -80,7 +80,7 @@ check_ping_send_dowork(struct context *c) { c->c2.buf = c->c2.buffers->aux_buf;ASSERT (buf_init (&c->c2.buf,FRAME_HEADROOM (&c->c2.frame))); -ASSERT (buf_safe (&c->c2.buf,MAX_RW_SIZE_TUN (&c->c2.frame))); +ASSERT (buf_safe (&c->c2.buf, c->c2.frame.buf.payload_size));ASSERT (buf_write (&c->c2.buf, ping_string,sizeof (ping_string)));/*
src/openvpn/reliable.c +0 -2
@@ -205,8 +205,6 @@ error:return false; } -#define ACK_SIZE (n) (sizeof(uint8_t) + ((n) ? SID_SIZE : 0) + sizeof(packet_id_type) * (n)) -/* write a packet ID acknowledgement record to buf, */ /* removing all acknowledged entries from ack */ bool
src/openvpn/reliable.h +3 -0
@@ -66,6 +66,9 @@ struct reliable_ackpacket_id_type packet_id[RELIABLE_ACK_SIZE ]; }; +/* The size of the ACK header */ +#define ACK_SIZE (n) (sizeof(uint8_t) + ((n) ? SID_SIZE : 0) + sizeof(packet_id_type) * (n)) +/** * The structure in which the reliability layer stores a single incoming * or outgoing packet.
src/openvpn/ssl.c +30 -8
@@ -332,6 +332,35 @@ tls_init_control_channel_frame_parameters(const struct frame *data_channel_frame/* set dynamic link MTU to cap control channel packets at 1250 bytes */ ASSERT (TUN_LINK_DELTA (frame) <min_int (frame->link_mtu,1250 )); frame->link_mtu_dynamic =min_int (frame->link_mtu,1250 ) -TUN_LINK_DELTA (frame); + +/* calculate the maximum overhead that control channel frames may have */ +int overhead =0 ; + +/* Socks */ + overhead +=10 ; + +/* tls-auth and tls-crypt */ + overhead +=max_int (tls_crypt_buf_overhead (), +packet_id_size (true) +OPENVPN_MAX_HMAC_SIZE ); + +/* TCP length field and opcode */ + overhead+=3 ; + +/* ACK array and remote SESSION ID (part of the ACK array) */ + overhead +=ACK_SIZE (RELIABLE_ACK_SIZE ); + +/* Previous OpenVPN version calculated the maximum size and buffer of a +* control frame depending on the overhead of the data channel frame +* overhead and limited its maximum size to 1250. We always allocate the +* 1250 buffer size since a lot of code blindly assumes a large buffer +* (e.g. PUSH_BUNDLE_SIZE) and set frame->mtu_mtu as suggestion for the +* size */ + frame->buf.payload_size =1250 + overhead; + + frame->buf.headroom = overhead; + frame->buf.tailroom = overhead; + + frame->tun_mtu =min_int (data_channel_frame->tun_mtu,1250 ); }void
@@ -1875,13 +1904,6 @@ tls_session_update_crypto_params_do_work(struct tls_session *session,msg (D_HANDSHAKE ,"Data Channel: using negotiated cipher '%s'" , options->ciphername); } -else - { -/* Very hacky workaround and quick fix for frame calculation -* different when adjusting frame size when the original and new cipher -* are identical to avoid a regression with client without NCP */ -return tls_session_generate_data_channel_keys (session); - }init_key_type (&session->opt->key_type, options->ciphername, options->authname, true, true);
@@ -2964,7 +2986,7 @@ tls_process(struct tls_multi *multi, buf =reliable_get_buf_output_sequenced (ks->send_reliable);if (buf) { -int status =key_state_read_ciphertext (&ks->ks_ssl, buf,PAYLOAD_SIZE_DYNAMIC (&multi->opt.frame)); +int status =key_state_read_ciphertext (&ks->ks_ssl, buf, multi->opt.frame.tun_mtu);if (status ==-1 ) { msg(D_TLS_ERRORS,
src/openvpn/ssl_common.h +2 -1
@@ -221,8 +221,9 @@ struct key_statestruct reliable *rec_reliable;/* order incoming ciphertext packets before we pass to TLS */ struct reliable_ack *rec_ack;/* buffers all packet IDs we want to ACK back to sender */ +/** Holds outgoing message for the control channel until ks->state reaches +* S_ACTIVE */ struct buffer_list *paybuf; -counter_type n_bytes;/* how many bytes sent/recvd since last key exchange */ counter_type n_packets;/* how many packets sent/recvd since last key exchange */
Signature · 1 line
2.33.0
[Openvpn-devel] [PATCH applied] Re: Deprecate link-mtu
In reply to Arne SchwabeThe change is mostly documentation, and it makes sense, for the reasons given. The actual code change just reduces the connection between --ifconfig and --link-mtu, which is confusing at best.
Have not tested beyond a simple compile check.
(For reference: this was 02/21 in v2 of the patchset, and did not see an ACK there)
Your patch has been applied to the master branch.
commit 29453c37c1f3aa420a894996dd7be4a4f8393c5a
Author: Arne Schwabe Date: Sat Jan 1 17:25:19 2022 +0100
Deprecate link-mtu
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23496.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v3 02/14] Fix mssfix and frame calculation in CBC mode
In reply to Arne SchwabeHi,
Quoted 9 lines · Arne Schwabe
This commit fixes the MSS calculation in CBC mode. This fix has two parts:
- Added rounding to a multiple of block size during calculation of overhead
- In CBC mode the packet ID is part of the plaintext (or payload) rather than part of the header (like for AEAD), adjust the functions to correctly reflect this.OCC link calculation is not affected since it ignores rounding of CBC block size completely.
I've done a bit of whacking of this, and it is still not fully right, unfortunately.
The short form is
- BF-CBC, LZ4, --mssfix 1000, over IPv4
v4 TCP -> MSS 923, resulting UDP payload <= 1008 bytes
v6 TCP -> MSS 903, resulting UDP payload <= 1008 bytes
- BF-CBC, LZ4, --mssfix 1000, over IPv6
v4 TCP -> MSS 923, resulting UDP payload <= 1008 bytes
v6 TCP -> MSS 903, resulting UDP payload <= 1008 bytes
[so this is clearly wrong!] - BF-CBC, comp no, --mssfix 1000, over IPv4
v4 TCP -> MSS 923, resulting UDP payload <= 1000 bytes [can't test v6 inside in this particular server instance]
so, something is wrong with the rounding and the compression opcode in CBC mode. With "comp no" the resulting packets are correct (UDP payload <= 1000 bytes), with "comp lz4" - doing the framing, but not doing actual compression - UDP payload exceeds --mssfix config.
So, not merging this, until we've decided how to proceed (fixup patch, or new version of this one).
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Re: [Openvpn-devel] [PATCH v3 06/14] Update fragment and mssfix related warnings
In reply to Arne Schwabec->options.ce.fragment, c->options.ce.mssfix);
src/openvpn/init.c do_init_frame(struct context *c) · line 3265
Quoted 3 lines
src/openvpn/init.c +3
-0+ } +if (c->options.ce.fragment >0 && c->options.ce.mssfix >0 + && c->options.ce.fragment_encap != c->options.ce.mssfix_encap)
Note that fragment_encap is added in
[Openvpn-devel] [PATCH v3 09/14] Add mtu paramter to --fragment and change fragment calculation
and this patch needs to added after that patch to avoid an compile error.
Arne
Re: [Openvpn-devel] [PATCH v3 02/14] Fix mssfix and frame calculation in CBC mode
In reply to Gert DoeringAm 28.01.22 um 12:15 schrieb Gert Doering:
Quoted 26 lines
Hi,
Quoted 9 lines · Arne Schwabe
This commit fixes the MSS calculation in CBC mode. This fix has two parts:
- Added rounding to a multiple of block size during calculation of overhead
- In CBC mode the packet ID is part of the plaintext (or payload) rather than part of the header (like for AEAD), adjust the functions to correctly reflect this.OCC link calculation is not affected since it ignores rounding of CBC block size completely.
I've done a bit of whacking of this, and it is still not fully right, unfortunately.
The short form is
- BF-CBC, LZ4, --mssfix 1000, over IPv4 v4 TCP -> MSS 923, resulting UDP payload <= 1008 bytes v6 TCP -> MSS 903, resulting UDP payload <= 1008 bytes - BF-CBC, LZ4, --mssfix 1000, over IPv6 v4 TCP -> MSS 923, resulting UDP payload <= 1008 bytes v6 TCP -> MSS 903, resulting UDP payload <= 1008 bytes [so this is clearly wrong!]
Quoted 8 lines
- BF-CBC, comp no, --mssfix 1000, over IPv4
v4 TCP -> MSS 923, resulting UDP payload <= 1000 bytes [can't test v6 inside in this particular server instance]so, something is wrong with the rounding and the compression opcode in CBC mode. With "comp no" the resulting packets are correct (UDP payload <= 1000 bytes), with "comp lz4" - doing the framing, but not doing actual compression - UDP payload exceeds --mssfix config.
I looked into this. This is still an artefact from our workaround that we do not recalculate frame parameter if the cipehr does not change after push. So if something else is pushed that changes the frame parameter like compression, we continue to use the old parameter and this the behaviour we are seeing.
The workaround is eventually removed in the patch set but not in this patch. To test here either already put the compress option in the config before or artificially use a different cipher to force teh recalculation.
Arne
[Openvpn-devel] [PATCH applied] Re: Fix mssfix and frame calculation in CBC mode
In reply to Arne SchwabeThis came out of discussions on the "last" mssfix patch (d4458eed0c3, "Decouple MSS fix calculation") where I discovered that sometimes we'd still see too-big payloads for BF-CBC - this was a rounding issue, and also an interpretation issue on "which parts of the frame are considered 'plaintext' or 'header', depending on CBC vs. AEAD mode". See this:
https://www.mail-archive.com/[email protected]/msg23481.html
Stared at code, scratched my head, tested client and server side ("normal packet tests" - everything passes) and explicitly tested combinations for resulting packet size.
Thus, tested:
- BF-CBC, LZ4 (pushed), --mssfix 1000, over IPv4
v4 TCP -> MSS 923, resulting UDP payload <= 1008 bytes
v6 TCP -> MSS 903, resulting UDP payload <= 1008 bytes
- BF-CBC, LZ4 (pushed), --mssfix 1000, over IPv6
v4 TCP -> MSS 923, resulting UDP payload <= 1008 bytes
v6 TCP -> MSS 903, resulting UDP payload <= 1008 bytes
[so this is clearly wrong, but see below]- BF-CBC, comp no, --mssfix 1000, over IPv4
v4 TCP -> MSS 923, resulting UDP payload <= 1000 bytes
[OK]- AES256GCM, LZ4, --mssfix 1000, over IPv4
v4 TCP -> MSS 935, resulting UDP payload <= 1000 bytes
v6 TCP -> MSS 915, resulting UDP payload <= 1000 bytes
- AES256GCM, LZ4, --mssfix 1000, over IPv6
v4 TCP -> MSS 935, resulting UDP payload <= 1000 bytes
v6 TCP -> MSS 915, resulting UDP payload <= 1000 bytes- AES256GCM, comp no, --mssfix 1000, over IPv4
v4 TCP -> MSS 936, resulting UDP payload <= 1000 bytes
--> so it looks as if the CBC code is not handling the compression framing and then rounding up and down and sideways correctly...
I've discussed this with Arne, and the result of that was "it's due to option recalculation wackiness if cipher does not change, but other options do".
So, the failing test above has no compression setting in the client config *but* permits pushed LZ4. If I change that towards "client has compress lz4", the result changes:
- BF-CBC, LZ4 (config), --mssfix 1000, over IPv4
v4 TCP -> MSS 922 (from 923), resulting UDP payload <= 1000 bytes
v6 TCP -> MSS 902 (from 903), resulting UDP payload <= 1000 bytesso the resulting packets are correct. The fix for the underlying issue comes later in the patch series.
Given that these corner cases have been wrong all the time, it makes sense to merge this patch as it is (nothing is getting worse), and re-test when the dewackyfying patch is in.
I have fixed one comment in mss.c
Your patch has been applied to the master branch.
commit 5b3c8ca869766de2c94eb7dd4450b0d9ab1c75fc
Author: Arne Schwabe Date: Sat Jan 1 17:25:20 2022 +0100
Fix mssfix and frame calculation in CBC mode
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23494.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v5] Change buffer allocation calculation and checks to be more static
In reply to Arne SchwabeHi,
Quoted 8 lines · Arne Schwabe
Currently we use half dynamic buffer sizes where we use have a fixed overhead for crypto (
crypto_max_overhead) but use a dynamic overhead for the the other small header sizes.Patch v3: rebase
Patch v4: add size of ack array to control channel frame size Patch v5: fix calculation of compression overhead calculated over 0 instead
of payload size
Generally this looks okayish, and *most* t_client / t_server tests work beautifully.
It does break --tls-client --proto tcp for me, for big packets, though...
The client is called like this:
openvpn --ca ... --cert ... --key ... --comp-lzo --verb 3 --tls-client --dev tap --proto tcp-client --remote gentoo.ov.greenie.net 51204 --ifconfig 10.204.9.2 255.255.255.0 --comp-lzo --tun-ipv6 --ifconfig-ipv6 fd00:abcd:204:9::2/64 fd00:abcd:204:9::1 --route 10.204.0.0 255.255.0.0 10.204.9.1 --route-ipv6 fd00:abcd:204::/48 --data-ciphers BF-CBC
and will do
2022-02-02 12:56:52 peer info: IV_CIPHERS=BF-CBC:AES-256-GCM:AES-128-GCM 2022-02-02 12:56:52 peer info: IV_PROTO=42 2022-02-02 12:56:52 WARNING: 'tun-mtu' is used inconsistently, local='tun-mtu 1500', remote='tun-mtu 1532' 2022-02-02 12:56:52 P2P mode NCP negotiation result: TLS_export=1, DATA_v2=1, peer-id 897556, cipher=BF-CBC 2022-02-02 12:56:52 Control Channel: TLSv1.3, cipher TLSv1.3 TLS_AES_256_GCM_SHA384, peer certificate: 2048 bit RSA, signature: RSA-SHA1 2022-02-02 12:56:52 [server] Peer Connection Initiated with [AF_INET6]2001:608:0:814::f000:11:51204 2022-02-02 12:56:53 OPTIONS IMPORT: adjusting link_mtu to 1579 2022-02-02 12:56:53 Outgoing Data Channel: Cipher 'BF-CBC' initialized with 128 bit key 2022-02-02 12:56:53 Outgoing Data Channel: Using 160 bit message hash 'SHA1' for HMAC authentication
when sending 1440 byte pings (t_client test) it will complain
2022-02-02 12:56:15 TCP/UDP packet too large on write to [AF_INET6]2001:608:0:814::f000:11:51204 (tried=1520,max=1499) 2022-02-02 12:56:15 TCP/UDP packet too large on write to [AF_INET6]2001:608:0:814::f000:11:51204 (tried=1520,max=1499) 2022-02-02 12:56:15 TCP/UDP packet too large on write to [AF_INET6]2001:608:0:814::f000:11:51204 (tried=1520,max=1499)
soo... is this something that "should be fixed" by a later patch in the series, or do we need a v6 of this one?
The same test works correctly with master as of right now (5b3c8ca86976).
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...[Openvpn-devel] [PATCH applied] Re: Change buffer allocation calculation and checks to be more static
In reply to Arne SchwabeTested on client and server side, all "regular" stuff works, but it breaks my TCP/P2P/P2P-NCP test case for big packets, namely...
2022-02-02 12:57:19 TCP/UDP packet too large on write to [AF_INET6]2001:608:0:814::f000:11:51204 (tried=1520,max=1499)
(expected result: oversized packet, fragment/segment on outer layer)
After discussion on IRC, decided to go forward anyway, as this is only one specific corner case (P2P NCP), and it gets fixed for good in 13/14
- removing EXPANDED_SIZE() in forward.c, replacing it with just "buf.payload_size", which always has "sufficient headroom" - tested, fixes this corner case, doesn't break anything else.
(For reference, this was 10/21 in v1 of the patchset, 03/14 in v3, and standalone patches v4+v5 - but neither of the previous ones got an ACK or NAK, just MaxF finding ways to crash v3 and v4 ;-) )
Your patch has been applied to the master branch.
commit 65a21eb14f4afd80864e88ff425f5d9ef8d8fdec
Author: Arne Schwabe Date: Mon Jan 24 03:54:59 2022 +0100
Change buffer allocation calculation and checks to be more static
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23638.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: Change buffer allocation calculation and checks to be more static
In reply to Arne SchwabeTested on client and server side, all "regular" stuff works, but it breaks my TCP/P2P/P2P-NCP test case for big packets, namely...
2022-02-02 12:57:19 TCP/UDP packet too large on write to [AF_INET6]2001:608:0:814::f000:11:51204 (tried=1520,max=1499)
(expected result: oversized packet, fragment/segment on outer layer)
After discussion on IRC, decided to go forward anyway, as this is only one specific corner case (P2P NCP), and it gets fixed for good in 13/14
- removing EXPANDED_SIZE() in forward.c, replacing it with just "buf.payload_size", which always has "sufficient headroom" - tested, fixes this corner case, doesn't break anything else.
(For reference, this was 10/21 in v1 of the patchset, 03/14 in v3, and standalone patches v4+v5 - but neither of the previous ones got an ACK or NAK, just MaxF finding ways to crash v3 and v4 ;-) )
Your patch has been applied to the master branch.
commit 65a21eb14f4afd80864e88ff425f5d9ef8d8fdec
Author: Arne Schwabe Date: Mon Jan 24 03:54:59 2022 +0100
Change buffer allocation calculation and checks to be more static
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23638.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: Fix datagram_overhead and assorted functions
In reply to Arne SchwabeFor reference, this was 12/21 in the first patch series, and got an ACK from Frank Lichtenheld there.
Stared at the code. Looks bigger than it really is :-) - what it really does is pass on the socket address family down the call chain to the "datagram_overhead()" function, which will then know if it's v4 or v6.
Should we ever support SCTP, we'll only have to adjust a single function here, no mixture of functions and tables... :-)
Tested client and server side. P2P NCP is still broken (waiting for 13/14), Rest works.
Your patch has been applied to the master branch.
commit a63a727b020ef42c475bd861b960200686359b2d
Author: Arne Schwabe Date: Sat Jan 1 17:25:22 2022 +0100
Fix datagram_overhead and assorted functions
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Frank Lichtenheld <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23504.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: Implement optional mtu parameter for mssfix
In reply to Arne SchwabeChange makes sense, to take IPv4/IPv6 encap into account.
Code looks reasonable.
Tested with my previous mssfix test setup (and looking very carefully at tcpdump-reported "length" values, which one is "packet" and which one is "UDP encap" length :-) - that got me confused last time...).
- BF-CBC, LZ4 (conf), --mssfix 1000 mtu, over IPv4
v4 TCP -> MSS 890, resulting UDP payload 968, IP size 996 bytes
v6 TCP -> MSS 870, resulting UDP payload 968, IP size 996 bytes
(= OK, CBC rounding on 8 byte boundaries)
- BF-CBC, LZ4 (conf), --mssfix 1000 mtu, over IPv6
v4 TCP -> MSS 874, resulting UDP payload 952, IP size 1000 bytes
v6 TCP -> MSS 854, resulting UDP payload 952, IP size 1000 bytes- AES256GCM, LZ4, --mssfix 1000 mtu, over IPv4
v4 TCP -> MSS 907, resulting UDP payload 972, IP size 1000 bytes
v6 TCP -> MSS 887, resulting UDP payload 972, IP size 1000 bytes
- AES256GCM, LZ4, --mssfix 1000 mtu, over IPv6
v4 TCP -> MSS 887, resulting UDP payload 952, IP size 1000 bytes
v6 TCP -> MSS 867, resulting UDP payload 952, IP size 1000 bytes"just for completeness" I've re-tested "without 'mtu'" for a few cases
- BF-CBC, LZ4 (conf), --mssfix 1000 mtu, over IPv4
v4 TCP -> MSS 922, resulting UDP payload 1000, IP size 1028 bytes
v6 TCP -> MSS 902, resulting UDP payload 1000, IP size 1028 bytes- AES256GCM, LZ4, --mssfix 1000, over IPv4
v4 TCP -> MSS 935, resulting UDP payload 1000, IP size 1028 bytes
v6 TCP -> MSS 915, resulting UDP payload 1000, IP size 1028 bytes
- AES256GCM, LZ4, --mssfix 1000, over IPv6
v4 TCP -> MSS 935, resulting UDP payload 1000, IP size 1048 bytes
v6 TCP -> MSS 915, resulting UDP payload 1000, IP size 1048 bytes (this is "as before", so the previously documented behaviour is not
broken)
The "if (p[2]..." part of options.c is not perfect (it will check this even if p[1] was already found to be NULL) but given the calling environment, it's well defined as all of p[] is CLEAR()ed on every line.
As discussed on IRC, I have adjusted the man page entry somewhat (1473 was just plain wrong, 1478 is correct math, but I found the "pass IPv4 packets" text still misleading wrt inside/outside IPv4)
For reference, this was 13/21 in the v1 and v2 series, got feedback from Frank Lichtenheld. I have adjusted the commit message according to this (make the sentence a bit clearer). The RST formatting comments have been addressed in v2.
Your patch has been applied to the master branch.
commit 0fcb7cadb225d7f43e29c3ad6a1e9c34abbb8a63
Author: Arne Schwabe Date: Sat Jan 1 17:25:23 2022 +0100
Implement optional mtu parameter for mssfix
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23495.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: Remove link_mtu parameter when running up/down scripts
In reply to Arne Schwabe"Because it makes sense". Client-side and server-side tested (I do not have any scripts that look at link_mtu, I have other scripts that might be upset). Code change is simple enough.
For reference, this was 16/21 in v1 of the series, and got a NAK for "missing update to script-options.rst". This is still not in, so we agreed on IRC this morning that I'll do the missing text adjustments, which I have done.
Your patch has been applied to the master branch.
commit 3780ce0e16c2cd06e77357a30df3c43595c98cab (master)
Author: Arne Schwabe Date: Sat Jan 1 17:25:26 2022 +0100
Remove link_mtu parameter when running up/down scripts
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23493.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Gert Doering
NAKRe: [Openvpn-devel] [PATCH v3 09/14] Add mtu paramter to --fragment and change fragment calculation
In reply to Arne SchwabeHi,
Quoted 9 lines · Arne Schwabe
Instead relying on the
link_mtu_dynamicfield and its calculation in the frame struct, add a new fieldmax_fragment_sizeand add a calculation of it similar to mssfix.Also whenever mssfix value is calculated, we also want to calculate the values for fragment as both options need to be calculated from the real overhead.
Patch v2: Fix syntax in rst man page
NAK, as this breaks about everything :-o - I tried applying this on top of "master as of today" (3780ce0e1). It goes in with a little bit of help in options.h and compiles fine, but almost all t_client "--client" tests break with
run IPv4 ping tests (want_ok), 64 byte packets... run IPv4 ping tests (want_ok), 1440 byte packets... run IPv4 ping tests (want_ok), 3000 byte packets...
FAIL: IPv4 ping test (3000 bytes) failed, but should succeed. run IPv6 ping tests (want_ok), 64 byte packets... run IPv6 ping tests (want_ok), 1440 byte packets... run IPv6 ping tests (want_ok), 3000 byte packets...
FAIL: IPv6 ping test (3000 bytes) failed, but should succeed.
Test sets succeeded: 8 8a 9 9a 9b 9x.
Test sets failed: 1 1a 1b 1c 1d 1e 2 2a 2b 2c 2d 2e 2f 3 4 4a 4b 5 6.
(8+9 are p2p tests, with or without --client, which makes this a bit more puzzling)
Looking more closely, I see this in the log now:
2022-02-03 14:24:04 /sbin/ifconfig tun0 10.194.2.54 10.194.2.53 mtu 1572 netmask 255.255.255.255 up
"mtu 1572" while 3780ce0e16c configures
2022-02-03 14:28:24 /sbin/ifconfig tun0 10.194.2.54 10.194.2.53 mtu 1500 netmask 255.255.255.255 up
- so, the ping fails are explained (client OS fragments to 1572 MTU, which the client OS on the receiving end rejects). I couldn't easily see why this happens, though...
Client config is:
src/openvpn/openvpn --client --ca ... --cert ... --key ... --comp-lzo --verb 3 --dev tun --proto udp4 --remote conn-test-server.openvpn.org --port 51194
and server pushes this:
2022-02-03 14:28:24 PUSH: Received control message: 'PUSH_REPLY,route 10.194.0.0 255.255.0.0,route-ipv6 fd00:abcd:194::/48,tun-ipv6,route 10.194.2.1,topology net30,ping 10,ping-restart 30,compress lz4,ifconfig-ipv6 fd00:abcd:194:2::100c/64 fd00:abcd:194:2::1,ifconfig 10.194.2.54 10.194.2.53,peer-id 0,cipher AES-256-GCM,key-derivation tls-ekm'
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Re: [Openvpn-devel] [PATCH v3 09/14] Add mtu paramter to --fragment and change fragment calculation
Hi,
Quoted 3 lines · Gert Doering
and server pushes this:
2022-02-03 14:28:24 PUSH: Received control message: 'PUSH_REPLY,route 10.194.0.0 255.255.0.0,route-ipv6 fd00:abcd:194::/48,tun-ipv6,route 10.194.2.1,topology net30,ping 10,ping-restart 30,compress lz4,ifconfig-ipv6 fd00:abcd:194:2::100c/64 fd00:abcd:194:2::1,ifconfig 10.194.2.54 10.194.2.53,peer-id 0,cipher AES-256-GCM,key-derivation tls-ekm'
Looking more closely, this is followed by...
2022-02-03 17:34:29 PUSH: Received control message: 'PUSH_REPLY,route 10.194.0.0 255.255.0.0,route-ipv6 fd00:abcd:194::/48,tun-ipv6,route 10.194.2.1,topology net30,ping 10,ping-restart 30,compress lz4,ifconfig-ipv6 fd00:abcd:194:2::100c/64 fd00:abcd:194:2::1,ifconfig 10.194.2.54 10.194.2.53,peer-id 1,cipher AES-256-GCM,key-derivation tls-ekm' 2022-02-03 17:34:29 WARNING: Compression for receiving enabled. Compression has been used in the past to break encryption. Sent packets are not compressed unless "allow-compression yes" is also set. 2022-02-03 17:34:29 OPTIONS IMPORT: timers and/or timeouts modified 2022-02-03 17:34:29 OPTIONS IMPORT: compression parms modified 2022-02-03 17:34:29 OPTIONS IMPORT: --ifconfig/up options modified 2022-02-03 17:34:29 OPTIONS IMPORT: route options modified 2022-02-03 17:34:29 OPTIONS IMPORT: peer-id set 2022-02-03 17:34:29 OPTIONS IMPORT: adjusting link_mtu to 1625 2022-02-03 17:34:29 OPTIONS IMPORT: data channel crypto options modified
"adjusting link_mtu to 1625" which then maps to a tun_mtu of 1572, and
2022-02-03 17:34:29 /sbin/ifconfig tun0 10.194.2.54 10.194.2.53 mtu 1572 netmask 255.255.255.255 up
Which happens in adjust_mtu_peerid() iff there is no --link-mtu in the config (which it isn't)...
This binary is extremely stubborn about it, as in "even if I configure --tun-mtu 1490, I get a larger mtu configured afterwards".
Maybe this is a transient effect which will disappear when all of the patchset is in... trying this next.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Re: [Openvpn-devel] [PATCH v3 12/14] Replace TUN_MTU_SIZE with frame->tun_mtu
In reply to Arne SchwabeHi,
Quoted 2 lines · Arne Schwabe
This always uses the configured MTU size instead relying on the calculated MTU size.
This one, applied on top of "everything up to 11/14 v3" does not compile. It removes the TUN_MTU_SIZE() macro, but there is still "frame_finalize()", which uses it.
frame_finalize() goes away in 13/14.
So maybe I'll squash these two together... discuss tomorrow.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Re: [Openvpn-devel] [PATCH v3 09/14] Add mtu paramter to --fragment and change fragment calculation
In reply to Gert DoeringHi,
Quoted 2 lines · Gert Doering
Maybe this is a transient effect which will disappear when all of the patchset is in... trying this next.
This is transient.
12/14 ("Replace TUN_MTU_SIZE with frame->tun_mtu") makes the code return to "the ifconfig mtu is 1500 unless --tun-mtu is used, in which case it uses exactly what is configured". It needs 13/14 ("Remove frame->link_mtu") to compile, though.
So we have a patchset that introduces subtle brokenness for 06+07+09+10+11 (breaks t_client, so might get in the way of bisecting), compile-time brokenness for 12, and back to "everything works" in 13.
How shall we handle this? (Discuss on IRC tomorrow)
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...