Extract update_session_cipher into standalone function
PATCH v3 1/5 Extract update_session_cipher into standalone function
This allow the code later to check if the cipher is okay to use and update it for the calculation for the max MTU size.
--- src/openvpn/ssl.c | 11 +---------- src/openvpn/ssl_ncp.c | 22 ++++++++++++++++++++++ src/openvpn/ssl_ncp.h | 8 ++++++++ 3 files changed, 31 insertions(+), 10 deletions(-)
src/openvpn/ssl.c +1 -10
@@ -1678,17 +1678,8 @@ tls_session_update_crypto_params(struct tls_session *session, struct frame *frame_fragment, struct link_socket_info *lsi) { - - bool cipher_allowed_as_fallback = options->enable_ncp_fallback - &&streq (options->ciphername, session->opt->config_ciphername); - -if (!session->opt->server && !cipher_allowed_as_fallback - && !tls_item_in_cipher_list (options->ciphername, options->ncp_ciphers)) +if (!update_session_cipher (session, options)) { -msg (D_TLS_ERRORS ,"Error: negotiated cipher not allowed - %s not in %s" , - options->ciphername, options->ncp_ciphers); -/* undo cipher push, abort connection setup */ - options->ciphername = session->opt->config_ciphername;return false; }
src/openvpn/ssl_ncp.c +22 -0
@@ -490,3 +490,25 @@ p2p_mode_ncp(struct tls_multi *multi, struct tls_session *session)gc_free (&gc); } + + +bool +update_session_cipher (struct tls_session *session,struct options *options) +{ +bool cipher_allowed_as_fallback = options->enable_ncp_fallback + &&streq (options->ciphername, session->opt->config_ciphername); + +if (!session->opt->server && !cipher_allowed_as_fallback + && !tls_item_in_cipher_list (options->ciphername, options->ncp_ciphers)) + { +msg (D_TLS_ERRORS ,"Error: negotiated cipher not allowed - %s not in %s" , + options->ciphername, options->ncp_ciphers); +/* undo cipher push, abort connection setup */ + options->ciphername = session->opt->config_ciphername; +return false; + } +else + { +return true; + } +}
src/openvpn/ssl_ncp.h +8 -0
@@ -148,4 +148,12 @@ const char * get_p2p_ncp_cipher(struct tls_session *session, const char *peer_info, struct gc_arena *gc); + +/** +* Checks if the cipher is allowed and updates the TLS session cipher with it, +* otherwise returns false +*/ +bool +update_session_cipher (struct tls_session *session,struct options *options); +#endif /* ifndef OPENVPN_SSL_NCP_H */
Signature · 1 line
2.32.1 (Apple Git-133)
PATCH v3 2/5 Allow tun-mtu to be pushed
This allows tun-mtu to pushed but only up to the size of the preallocated buffers. This is not a perfect solution but should allow most of the use cases where the mtu is close enough to 1500.
--- Changes.rst | 8 ++++ doc/man-sections/client-options.rst | 4 ++ doc/man-sections/vpn-network-options.rst | 5 +++ src/openvpn/init.c | 50 ++++++++++++++++++++---- src/openvpn/mtu.c | 1 + src/openvpn/mtu.h | 3 ++ src/openvpn/options.c | 15 ++++++- src/openvpn/options.h | 3 ++ src/openvpn/ssl.c | 3 ++ 9 files changed, 84 insertions(+), 8 deletions(-)
Changes.rst +8 -0
@@ -79,6 +79,14 @@ Cookie based handshake for UDP server shake. The tls-crypt-v2 option allows controlling if older clients are accepted. + +Tun MTU can be pushed + As part of changing the ``--tun-mtu`` default to 1420 (see below), the + client can now also dynamically configure its MTU and the server will + try to push the client MTU when the client supports it. The directive + ``--tun-mtu-max`` has been introduced to specify the maximum pushable + MTU size. + Deprecated features ------------------- ``inetd`` has been removed
doc/man-sections/client-options.rst +4 -0
@@ -358,6 +358,10 @@ configuration. The client announces the list of supported ciphers configured with the ``--data-ciphers`` option to the server. + :code:`IV_MTU=<max_mtu>` + The client announces the support of pushable MTU and the maximum MTU + it is willing to accept. + :code:`IV_GUI_VER=<gui_id> <version>` The UI version of a UI if one is running, for example :code:`de.blinkt.openvpn 0.5.47` for the Android app.
doc/man-sections/vpn-network-options.rst +5 -0
@@ -516,6 +516,11 @@ routing. It's best to use the ``--fragment`` and/or ``--mssfix`` options to deal with MTU sizing issues. +--tun-max-mtu maxmtu + This configures the maximum MTU size that a server can push to ``maxmtu``. + The default for ``maxmtu`` is 1600. This will increase internal buffers + allocation for larger packet sizes. + --tun-mtu-extra n Assume that the TUN/TAP device might return as many as ``n`` bytes more than the ``--tun-mtu`` size on read. This parameter defaults to 0, which
src/openvpn/init.c +43 -7
81 lines not on this page · raw message
src/openvpn/mtu.c +1 -0
@@ -222,6 +222,7 @@ frame_print(const struct frame *frame,buf_printf (&out," max_frag:%d" , frame->max_fragment_size);#endif buf_printf (&out," tun_mtu:%d" , frame->tun_mtu); +buf_printf (&out," tun_max_mtu:%d" , frame->tun_max_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);
src/openvpn/mtu.h +3 -0
@@ -133,6 +133,9 @@ struct frame {* control frame payload (although most of * code ignores it) */ +int tun_max_mtu;/**< the maximum tun-mtu size the buffers are +* are sized for. This is the upper bound that +* a server can push as MTU */ int extra_tun;/**< Maximum number of bytes in excess of * the tun/tap MTU that might be read
src/openvpn/options.c +14 -1
@@ -6264,10 +6264,23 @@ add_option(struct options *options, }else if (streq (p[0 ],"tun-mtu" ) && p[1 ] && !p[2 ]) { -VERIFY_PERMISSION (OPT_P_MTU |OPT_P_CONNECTION ); +VERIFY_PERMISSION (OPT_P_PUSH_MTU |OPT_P_CONNECTION ); options->ce.tun_mtu =positive_atoi (p[1 ]); options->ce.tun_mtu_defined = true; } +else if (streq (p[0 ],"tun-mtu-max" ) && p[1 ] && !p[3 ]) + { +VERIFY_PERMISSION (OPT_P_MTU |OPT_P_CONNECTION ); +int max_mtu =positive_atoi (p[1 ]); +if (max_mtu <68 || max_mtu >65536 ) + { +msg (msglevel,"--tun-mtu-max value '%s' is invalid" , p[1 ]); + } +else + { + options->ce.tun_mtu_max = max_mtu; + } + }else if (streq (p[0 ],"tun-mtu-extra" ) && p[1 ] && !p[2 ]) {VERIFY_PERMISSION (OPT_P_MTU |OPT_P_CONNECTION );
src/openvpn/options.h +3 -0
@@ -118,6 +118,8 @@ struct connection_entryconst char *socks_proxy_authfile;int tun_mtu;/* MTU of tun device */ +int tun_mtu_max;/* maximum MTU that can be pushed */ +bool tun_mtu_defined;/* true if user overriding parm with command line option */ int tun_mtu_extra;bool tun_mtu_extra_defined;
@@ -719,6 +721,7 @@ struct options#define OPT_P_CONNECTION (1<<27)#define OPT_P_PEER_ID (1<<28)#define OPT_P_INLINE (1<<29) +#define OPT_P_PUSH_MTU (1<<30)#define OPT_P_DEFAULT (~(OPT_P_INSTANCE|OPT_P_PULL_MODE))
src/openvpn/ssl.c +3 -0
@@ -1939,6 +1939,9 @@ push_peer_info(struct buffer *buf, struct tls_session *session) { iv_proto |=IV_PROTO_REQUEST_PUSH ; iv_proto |=IV_PROTO_AUTH_PENDING_KW ; + +/* support for tun-mtu as part of the push message */ +buf_printf (&out,"IV_MTU=%d\n" , session->opt->frame.tun_max_mtu); }/* support for Negotiable Crypto Parameters */
Signature · 1 line
2.32.1 (Apple Git-133)
PATCH v3 3/5 Push server mtu to client when support and support occ mtu
In reply to Arne SchwabeTo maximise compatibility allow to lie our MTU in the default OCC message.
Patch v2: improve documentation
Patch v3: split changing default MTU into its own patch
--- Changes.rst | 5 +++++ doc/man-sections/vpn-network-options.rst | 27 ++++++++++++++++++++---- src/openvpn/options.c | 21 ++++++++++++++++-- src/openvpn/options.h | 1 + src/openvpn/push.c | 16 ++++++++++++++ 5 files changed, 64 insertions(+), 6 deletions(-)
Changes.rst +5 -0
@@ -149,6 +149,11 @@ User-visible Changes - 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. +- the default of ``--tun-mtu`` has been changed to ``--tun-mtu 1420 1500`` when + running in server mode. This will create an MTU mismatch with older clients + (newer clients allow pushable mtu) but the most common server platforms + (Linux and FreeBSD) allow receiving 1500 byte packets even when tun-mtu is + set to 1420, still allowing larger packets from clients with 1500 byte MTU. Overview of changes in 2.5 ==========================
doc/man-sections/vpn-network-options.rst +23 -4
@@ -500,10 +500,25 @@ routing. arguments of ``--ifconfig`` to mean "address netmask", no longer "local remote". ---tun-mtu n - Take the TUN device MTU to be **n** and derive the link MTU from it - (default :code:`1500`). In most cases, you will probably want to leave - this parameter set to its default value. +--tun-mtu args + + Valid syntaxes: + :: + + tun-mtu tun-mtu + tun-mtu tun-mtu occ-mtu + + Take the TUN device MTU to be ``tun-mtu`` and derive the link MTU from it. + In most cases, you will probably want to leave this parameter set to + its default value. + + Starting with OpenVPN 2.6 when running server mode (``--mode server``, + ``--server``, or ``-server-ipv6`` options present in the configuration), + the default will be 1420 for the tun mtu size and 1500 for the ``occ-mtu``. + + The OCC MTU can be used to avoid warnings about mismatched MTU from + clients. If :code:`occ-mtu` is not specified, it will to default to the + tun-mtu. The MTU (Maximum Transmission Units) is the maximum datagram size in bytes that can be sent unfragmented over a particular network path.
@@ -516,6 +531,10 @@ routing. It's best to use the ``--fragment`` and/or ``--mssfix`` options to deal with MTU sizing issues. + Note: Depending on the platform, the operating system allows to receive + packets larger than ``tun-mtu`` (e.g. Linux and FreeBSD) but other platforms + (like macOS) limit received packets to the same size as the MTU. + --tun-max-mtu maxmtu This configures the maximum MTU size that a server can push to ``maxmtu``. The default for ``maxmtu`` is 1600. This will increase internal buffers
src/openvpn/options.c +19 -2
@@ -814,6 +814,7 @@ init_options(struct options *o, const bool init_gc) o->status_file_version =1 ; o->ce.bind_local = true; o->ce.tun_mtu =TUN_MTU_DEFAULT ; + o->ce.occ_mtu =0 ; o->ce.link_mtu =LINK_MTU_DEFAULT ; o->ce.mtu_discover_type =-1 ; o->ce.mssfix =0 ;
@@ -4018,7 +4019,15 @@ 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" , frame->tun_mtu); +if (o->ce.occ_mtu !=0 ) + { +buf_printf (&out,",tun-mtu %d" , o->ce.occ_mtu); + } +else + { +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);
@@ -6262,11 +6271,19 @@ add_option(struct options *options, options->ce.link_mtu =positive_atoi (p[1 ]); options->ce.link_mtu_defined = true; } -else if (streq (p[0 ],"tun-mtu" ) && p[1 ] && !p[2 ]) +else if (streq (p[0 ],"tun-mtu" ) && p[1 ] && !p[3 ]) {VERIFY_PERMISSION (OPT_P_PUSH_MTU |OPT_P_CONNECTION ); options->ce.tun_mtu =positive_atoi (p[1 ]); options->ce.tun_mtu_defined = true; +if (p[2 ]) + { + options->ce.occ_mtu =positive_atoi (p[2 ]); + } +else + { + options->ce.occ_mtu =0 ; + } }else if (streq (p[0 ],"tun-mtu-max" ) && p[1 ] && !p[3 ]) {
src/openvpn/options.h +1 -0
@@ -118,6 +118,7 @@ struct connection_entryconst char *socks_proxy_authfile;int tun_mtu;/* MTU of tun device */ +int occ_mtu;/* if non-null, this is the MTU we announce to peers in OCC */ int tun_mtu_max;/* maximum MTU that can be pushed */ bool tun_mtu_defined;/* true if user overriding parm with command line option */
src/openvpn/push.c +16 -0
@@ -603,6 +603,22 @@ prepare_push_reply(struct context *c, struct gc_arena *gc, {push_option_fmt (gc, push_list,M_USAGE ,"key-derivation tls-ekm" ); } + +/* Push our mtu to the peer if it supports pushable MTUs */ +int client_max_mtu =0 ; +const char *iv_mtu =extract_var_peer_info (tls_multi->peer_info,"IV_MTU=" , gc); + +if (iv_mtu &&sscanf (iv_mtu,"%d" , &client_max_mtu) ==1 ) + { +push_option_fmt (gc, push_list,M_USAGE ,"tun-mtu %d" , o->ce.tun_mtu); +if (client_max_mtu < o->ce.tun_mtu) + { +msg (M_WARN ,"Warning: reported maximum MTU from client (%d) is lower " +"than MTU used on the server (%d). Add tun-max-mtu %d " +"to client configuration." , client_max_mtu, + o->ce.tun_mtu, o->ce.tun_mtu); + } + }return true; }
Signature · 1 line
2.32.1 (Apple Git-133)
PATCH v3 4/5 Implement a function to calculate the default MTU
In reply to Arne SchwabeWe could also just hardcode this value to 1420 but this approach does not add much (complicated) code and it is a bit better than to have a magic number to just be there.
--- src/openvpn/mtu.c | 22 ++++++++++++++++++++++ src/openvpn/mtu.h | 14 ++++++++++++++ tests/unit_tests/openvpn/test_crypto.c | 19 ++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-)
src/openvpn/mtu.c +22 -0
@@ -205,6 +205,28 @@ calc_options_string_link_mtu(const struct options *o, const struct frame *frame)return payload + overhead; } +int +frame_calculate_default_mtu (struct options *o) +{ +struct options options = *o; + +/* assume we have peer_id enabled */ + options.use_peer_id = true; + +/* We use IPv6+UDP here to have a consistent size for tun MTU no matter +* the combination of udp/tcp and IPv4/IPv6 */ +int encap_overhead =datagram_overhead (AF_INET6 ,PROTO_UDP ); + +struct key_type kt; +init_key_type (&kt,"AES-256-GCM" ,"none" , true, false); + +size_t payload_overhead =frame_calculate_payload_overhead (0 , &options, &kt, false); +size_t protocol_overhead =frame_calculate_protocol_header_size (&kt, &options, false); + +return MTU_ENCAP_DEFAULT - encap_overhead - payload_overhead - protocol_overhead; + +} + void frame_print(const struct frame *frame, int level,
src/openvpn/mtu.h +14 -0
@@ -79,6 +79,10 @@*/ #define MSSFIX_DEFAULT 1492 +/* The default size we aim to reach to with our VPN packets by setting +* the MTU accordingly */ +#define MTU_ENCAP_DEFAULT 1492 +/* * Alignment of payload data such as IP packet or * ethernet frame.
@@ -263,6 +267,16 @@ void alloc_buf_sock_tun(struct buffer *buf,const struct frame *frame, const bool tuntap_buffer); + +/** +* Function to calculate the default MTU for Layer 3 VPNs. The function +* assumes that UDP packets should be a maximum of \c MTU_ENCAP_DEFAULT (1492) +* with a AEAD cipher. This default comes out to be 1420. +*/ +int +frame_calculate_default_mtu (struct options *o); + +/* * EXTENDED_SOCKET_ERROR_CAPABILITY functions -- print extra error info * on socket errors, such as PMTU size. As of 2003.05.11, only works
tests/unit_tests/openvpn/test_crypto.c +18 -1
@@ -477,6 +477,22 @@ test_mssfix_mtu_calculation(void **state)gc_free (&gc); } + +static void +test_mtu_default_calculation (void **state) +{ +struct options o = {0 }; + +/* common defaults */ + o.ce.tun_mtu =1400 ; + o.ce.mssfix =1000 ; + o.replay = true; + o.ce.proto =PROTO_UDP ; + +size_t mtu =frame_calculate_default_mtu (&o); +assert_int_equal (1420 , mtu); +} +int main (void ) {
@@ -487,7 +503,8 @@ main(void)cmocka_unit_test (crypto_test_hmac),cmocka_unit_test (test_des_encrypt),cmocka_unit_test (test_occ_mtu_calculation), - cmocka_unit_test(test_mssfix_mtu_calculation) +cmocka_unit_test (test_mssfix_mtu_calculation), + cmocka_unit_test(test_mtu_default_calculation) };#if defined(ENABLE_CRYPTO_OPENSSL )
Signature · 1 line
2.32.1 (Apple Git-133)
PATCH v3 5/5 Change default MTU in server mode to 1420
In reply to Arne SchwabeThis changes the default MTU of the tun-mtu to 1420 to avoid MTU related issues that are even more prominent when DCO server or clients are involved.
To maximise compatibility to lie our MTU in the default OCC message and keep it at 1500.
--- doc/man-sections/vpn-network-options.rst | 17 ++++++++++++----- src/openvpn/options.c | 10 ++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-)
doc/man-sections/vpn-network-options.rst +12 -5
@@ -525,11 +525,18 @@ routing. OpenVPN requires that packets on the control and data channels be sent unfragmented. - MTU problems often manifest themselves as connections which hang during - periods of active usage. - - It's best to use the ``--fragment`` and/or ``--mssfix`` options to deal - with MTU sizing issues. + A VPN protocol like OpenVPN adds encapsulation overhead in each packet. If a + VPN packet with the encapsulation becomes larger than the transport network + MTU (typically 1500 or 1492) the packet will become fragmented or completely + dropped. These problems can manifest themselves as connections which hang + during periods of active usage or slower performance. To avoid these problems + it is generally advisable to set the tun MTU small enough to avoid these + problems. The default of 1420 is chosen to be safe with default parameters + and a (transport) network MTU of 1492. + + If lowering the tun MTU to avoid MTU related problems (e.g. when tap is used + and an MTU of 1500 is required), the ``--fragment`` and/or ``--mssfix`` + options can be also used to deal with MTU sizing issues. Note: Depending on the platform, the operating system allows to receive packets larger than ``tun-mtu`` (e.g. Linux and FreeBSD) but other platforms
src/openvpn/options.c +10 -0
@@ -3032,6 +3032,16 @@ options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce)if (!ce->tun_mtu_defined && !ce->link_mtu_defined) { ce->tun_mtu_defined = true; +if (o->mode ==MODE_SERVER && dev !=DEV_TYPE_TAP ) + { +/* If we are running in P2MP mode we default to a MTU +* that is low enough by default to fit into a 1492 +* MTU UDP IPv6 packet: +* +*/ + ce->tun_mtu =frame_calculate_default_mtu (o); + ce->occ_mtu =TUN_MTU_DEFAULT ; + } }if ((dev ==DEV_TYPE_TAP ) && !ce->tun_mtu_extra_defined) {
Signature · 1 line
2.32.1 (Apple Git-133)
Re: [Openvpn-devel] [PATCH v3 4/5] Implement a function to calculate the default MTU
In reply to Arne SchwabeNACK. See below.
Quoted 12 lines · Arne Schwabe
tests/unit_tests/openvpn/test_crypto.c +4
-0@@ -477,6 +477,22 @@ test_mssfix_mtu_calculation(void **state)gc_free (&gc); } + +static void +test_mtu_default_calculation (void **state) +{
tests/unit_tests/openvpn/test_crypto.c test_mssfix_mtu_calculation(void **state) · line 493
Quoted 10 lines
tests/unit_tests/openvpn/test_crypto.c +10
-0+struct options o = {0 }; + +/* common defaults */ + o.ce.tun_mtu =1400 ; + o.ce.mssfix =1000 ; + o.replay = true; + o.ce.proto =PROTO_UDP ; + +size_t mtu =frame_calculate_default_mtu (&o); +assert_int_equal (1420 , mtu);
As mentioned this is true for the specific options configured above. But you can easily also get different values out of this function by changing the options because frame_calculate_payload overhead does not always return the same value.
There are various things you could do:
1) you could add a test here to show that this is expected behavior.
2) you could add a comment here to the same effect (although I would prefer an actual test)
3) you could change the function so that it actually always returns the same value (e.g. by overriding fragment and comp settings like you do for use_peer_id)
But doing nothing is not an option, IMHO. That will just confuse others in the future.
Regards,
Frank
Hi,
src/openvpn/ssl_ncp.h const char * · line 158
Quoted 8 lines · Arne Schwabe
src/openvpn/ssl_ncp.h +8
-0+ +/** +* Checks if the cipher is allowed and updates the TLS session cipher with it, +* otherwise returns false +*/ +bool +update_session_cipher (struct tls_session *session,struct options *options); +
Is that comment correct? I can't find any "updating" here, only "checking".
What am I overlooking?
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]...Am 27.07.22 um 20:58 schrieb Gert Doering:
Quoted 14 lines
Hi,
src/openvpn/ssl_ncp.h const char * · line 158
Quoted 8 lines · Arne Schwabe
src/openvpn/ssl_ncp.h +8
-0+ +/** +* Checks if the cipher is allowed and updates the TLS session cipher with it, +* otherwise returns false +*/ +bool +update_session_cipher (struct tls_session *session,struct options *options); +Is that comment correct? I can't find any "updating" here, only "checking".
Quoted 2 lines
What am I overlooking?
It sets options->cipher sometimes but the name is misleading. I will rename to check_session_cipher
Arne
Hi,
Quoted 6 lines · Arne Schwabe
Quoted 3 lines
Is that comment correct? I can't find any "updating" here, only "checking".
What am I overlooking?
It sets
options->ciphersometimes but the name is misleading. I will rename tocheck_session_cipher
The "options->cipher setting" part is more "restore to config if requested cipher is not allowed" - so that one I understood ;-)
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]...PATCH v4 1/5 Extract check_session_cipher into standalone function
In reply to Arne SchwabeThis allow the code later to check if the cipher is okay to use and update it for the calculation for the max MTU size.
Patch v2: Name function check_session_cipher to better reflect its
function
--- src/openvpn/ssl.c | 11 +---------- src/openvpn/ssl_ncp.c | 22 ++++++++++++++++++++++ src/openvpn/ssl_ncp.h | 8 ++++++++ 3 files changed, 31 insertions(+), 10 deletions(-)
src/openvpn/ssl.c +1 -10
@@ -1678,17 +1678,8 @@ tls_session_update_crypto_params(struct tls_session *session, struct frame *frame_fragment, struct link_socket_info *lsi) { - - bool cipher_allowed_as_fallback = options->enable_ncp_fallback - &&streq (options->ciphername, session->opt->config_ciphername); - -if (!session->opt->server && !cipher_allowed_as_fallback - && !tls_item_in_cipher_list (options->ciphername, options->ncp_ciphers)) +if (!check_session_cipher (session, options)) { -msg (D_TLS_ERRORS ,"Error: negotiated cipher not allowed - %s not in %s" , - options->ciphername, options->ncp_ciphers); -/* undo cipher push, abort connection setup */ - options->ciphername = session->opt->config_ciphername;return false; }
src/openvpn/ssl_ncp.c +22 -0
@@ -490,3 +490,25 @@ p2p_mode_ncp(struct tls_multi *multi, struct tls_session *session)gc_free (&gc); } + + +bool +check_session_cipher (struct tls_session *session,struct options *options) +{ +bool cipher_allowed_as_fallback = options->enable_ncp_fallback + &&streq (options->ciphername, session->opt->config_ciphername); + +if (!session->opt->server && !cipher_allowed_as_fallback + && !tls_item_in_cipher_list (options->ciphername, options->ncp_ciphers)) + { +msg (D_TLS_ERRORS ,"Error: negotiated cipher not allowed - %s not in %s" , + options->ciphername, options->ncp_ciphers); +/* undo cipher push, abort connection setup */ + options->ciphername = session->opt->config_ciphername; +return false; + } +else + { +return true; + } +}
src/openvpn/ssl_ncp.h +8 -0
@@ -148,4 +148,12 @@ const char * get_p2p_ncp_cipher(struct tls_session *session, const char *peer_info, struct gc_arena *gc); + +/** +* Checks if the cipher is allowed, otherwise returns false and reset the +* cipher to the config cipher. +*/ +bool +check_session_cipher (struct tls_session *session,struct options *options); +#endif /* ifndef OPENVPN_SSL_NCP_H */
Signature · 1 line
2.32.1 (Apple Git-133)
[Openvpn-devel] [PATCH applied] Re: Extract check_session_cipher into standalone function
This is technically the same as 1/5 in v3, except s/update/check/, and *that* one is is exactly the same patch as "3/6" in the earlier patch series ([email protected]...) which had an ACK from Frank -> applying that ACK here, adding my own.
Stare-at-code and --color-moved=zebra confirms "trivial code move"
Passes t_client tests.
Your patch has been applied to the master branch.
commit dd1837ca549e0494164fb4633d61a317529778b4
Author: Arne Schwabe Date: Fri Jul 29 14:37:48 2022 +0200
Extract check_session_cipher into standalone function
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]/msg24766.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v4 2/5 Allow tun-mtu to be pushed
In reply to Arne SchwabeThis allows tun-mtu to pushed but only up to the size of the preallocated buffers. This is not a perfect solution but should allow most of the use cases where the mtu is close enough to 1500.
Patch v4: rebase for check_session_cipher name change
--- Changes.rst | 8 ++++ doc/man-sections/client-options.rst | 4 ++ doc/man-sections/vpn-network-options.rst | 5 +++ src/openvpn/init.c | 50 ++++++++++++++++++++---- src/openvpn/mtu.c | 1 + src/openvpn/mtu.h | 3 ++ src/openvpn/options.c | 15 ++++++- src/openvpn/options.h | 3 ++ src/openvpn/ssl.c | 3 ++ 9 files changed, 84 insertions(+), 8 deletions(-)
Changes.rst +8 -0
@@ -79,6 +79,14 @@ Cookie based handshake for UDP server shake. The tls-crypt-v2 option allows controlling if older clients are accepted. + +Tun MTU can be pushed + As part of changing the ``--tun-mtu`` default to 1420 (see below), the + client can now also dynamically configure its MTU and the server will + try to push the client MTU when the client supports it. The directive + ``--tun-mtu-max`` has been introduced to specify the maximum pushable + MTU size. + Deprecated features ------------------- ``inetd`` has been removed
doc/man-sections/client-options.rst +4 -0
@@ -358,6 +358,10 @@ configuration. The client announces the list of supported ciphers configured with the ``--data-ciphers`` option to the server. + :code:`IV_MTU=<max_mtu>` + The client announces the support of pushable MTU and the maximum MTU + it is willing to accept. + :code:`IV_GUI_VER=<gui_id> <version>` The UI version of a UI if one is running, for example :code:`de.blinkt.openvpn 0.5.47` for the Android app.
doc/man-sections/vpn-network-options.rst +5 -0
@@ -516,6 +516,11 @@ routing. It's best to use the ``--fragment`` and/or ``--mssfix`` options to deal with MTU sizing issues. +--tun-max-mtu maxmtu + This configures the maximum MTU size that a server can push to ``maxmtu``. + The default for ``maxmtu`` is 1600. This will increase internal buffers + allocation for larger packet sizes. + --tun-mtu-extra n Assume that the TUN/TAP device might return as many as ``n`` bytes more than the ``--tun-mtu`` size on read. This parameter defaults to 0, which
src/openvpn/init.c +43 -7
81 lines not on this page · raw message
src/openvpn/mtu.c +1 -0
@@ -222,6 +222,7 @@ frame_print(const struct frame *frame,buf_printf (&out," max_frag:%d" , frame->max_fragment_size);#endif buf_printf (&out," tun_mtu:%d" , frame->tun_mtu); +buf_printf (&out," tun_max_mtu:%d" , frame->tun_max_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);
src/openvpn/mtu.h +3 -0
@@ -133,6 +133,9 @@ struct frame {* control frame payload (although most of * code ignores it) */ +int tun_max_mtu;/**< the maximum tun-mtu size the buffers are +* are sized for. This is the upper bound that +* a server can push as MTU */ int extra_tun;/**< Maximum number of bytes in excess of * the tun/tap MTU that might be read
src/openvpn/options.c +14 -1
@@ -6380,10 +6380,23 @@ add_option(struct options *options, }else if (streq (p[0 ],"tun-mtu" ) && p[1 ] && !p[2 ]) { -VERIFY_PERMISSION (OPT_P_MTU |OPT_P_CONNECTION ); +VERIFY_PERMISSION (OPT_P_PUSH_MTU |OPT_P_CONNECTION ); options->ce.tun_mtu =positive_atoi (p[1 ]); options->ce.tun_mtu_defined = true; } +else if (streq (p[0 ],"tun-mtu-max" ) && p[1 ] && !p[3 ]) + { +VERIFY_PERMISSION (OPT_P_MTU |OPT_P_CONNECTION ); +int max_mtu =positive_atoi (p[1 ]); +if (max_mtu <68 || max_mtu >65536 ) + { +msg (msglevel,"--tun-mtu-max value '%s' is invalid" , p[1 ]); + } +else + { + options->ce.tun_mtu_max = max_mtu; + } + }else if (streq (p[0 ],"tun-mtu-extra" ) && p[1 ] && !p[2 ]) {VERIFY_PERMISSION (OPT_P_MTU |OPT_P_CONNECTION );
src/openvpn/options.h +3 -0
@@ -118,6 +118,8 @@ struct connection_entryconst char *socks_proxy_authfile;int tun_mtu;/* MTU of tun device */ +int tun_mtu_max;/* maximum MTU that can be pushed */ +bool tun_mtu_defined;/* true if user overriding parm with command line option */ int tun_mtu_extra;bool tun_mtu_extra_defined;
@@ -718,6 +720,7 @@ struct options#define OPT_P_CONNECTION (1<<27)#define OPT_P_PEER_ID (1<<28)#define OPT_P_INLINE (1<<29) +#define OPT_P_PUSH_MTU (1<<30)#define OPT_P_DEFAULT (~(OPT_P_INSTANCE|OPT_P_PULL_MODE))
src/openvpn/ssl.c +3 -0
@@ -1942,6 +1942,9 @@ push_peer_info(struct buffer *buf, struct tls_session *session) { iv_proto |=IV_PROTO_REQUEST_PUSH ; iv_proto |=IV_PROTO_AUTH_PENDING_KW ; + +/* support for tun-mtu as part of the push message */ +buf_printf (&out,"IV_MTU=%d\n" , session->opt->frame.tun_max_mtu); }/* support for Negotiable Crypto Parameters */
Signature · 1 line
2.32.1 (Apple Git-133)
Re: [Openvpn-devel] [PATCH v3 3/5] Push server mtu to client when support and support occ mtu
In reply to Arne SchwabeQuoted 5 lines · On Sonntag, 26. Juni 2022 01:41:48 CEST Arne Schwabe wrote:
To maximise compatibility allow to lie our MTU in the default OCC message.
Patch v2: improve documentation
Patch v3: split changing default MTU into its own patch
Doesn't apply to master anymore. From what I have seen, besides the small typo below:
doc/man-sections/vpn-network-options.rst routing. · line 516
Quoted 2 lines
doc/man-sections/vpn-network-options.rst +2
-0+ Starting with OpenVPN 2.6 when running server mode (``--mode server``, + ``--server``, or ``-server-ipv6`` options present in the configuration),
Should be ``--server-ipv6``
Re: [Openvpn-devel] [PATCH v3 2/5] Allow tun-mtu to be pushed
In reply to Arne SchwabeDoesn't apply to master anymore, please rebase.
doc/man-sections/vpn-network-options.rst routing. · line 519
Quoted 7 lines · On Sonntag, 26. Juni 2022 01:41:47 CEST Arne Schwabe wrote:
doc/man-sections/vpn-network-options.rst +1
-0@@ -516,6 +516,11 @@ routing. It's best to use the ``--fragment`` and/or ``--mssfix`` options to deal with MTU sizing issues. +--tun-max-mtu maxmtu
--tun-mtu-max
doc/man-sections/vpn-network-options.rst routing. · line 523
Quoted 4 lines
doc/man-sections/vpn-network-options.rst +4
-0+ if (c->options.ce.tun_mtu > frame->tun_max_mtu) + { + msg(D_PUSH_ERRORS, "Server pushed a large mtu, please add " + "tun-mtu-max %d in the client configuration", +
"a too large MTU, to accept it add" would describe it better
doc/man-sections/vpn-network-options.rst frame_print(const struct frame *frame, · line 225
Quoted 5 lines
doc/man-sections/vpn-network-options.rst +1
-0@@ -222,6 +222,7 @@ frame_print(const struct frame *frame, buf_printf(&out, " max_frag:%d", frame->max_fragment_size); #endif buf_printf(&out, " tun_mtu:%d", frame->tun_mtu); + buf_printf(&out, " tun_max_mtu:%d", frame->tun_max_mtu);
should be printed as "tun_mtu_max" to be consistent with the option. Maybe it Should even make sense to rename the frame element to match the option name as they are closely related.
Re: [Openvpn-devel] [PATCH v3 4/5] Implement a function to calculate the default MTU
In reply to Frank LichtenheldQuoted 4 lines · On Montag, 27. Juni 2022 10:36:02 CEST Frank Lichtenheld wrote:
As mentioned this is true for the specific options configured above. But you can easily also get different values out of this function by changing the options because
frame_calculate_payloadoverhead does not always return the same value.
I don't get it. It produces the same output for the same input reliably. Do you want to see a test which forces something different to 1420 by modifying the inputs accordingly?
Heiko
Re: [Openvpn-devel] [PATCH v3 4/5] Implement a function to calculate the default MTU
Quoted 9 lines · Heiko Hund
Quoted 4 lines · On Montag, 27. Juni 2022 10:36:02 CEST Frank Lichtenheld wrote:
As mentioned this is true for the specific options configured above. But you can easily also get different values out of this function by changing the options because
frame_calculate_payloadoverhead does not always return the same value.I don't get it. It produces the same output for the same input reliably. Do you want to see a test which forces something different to 1420 by modifying the inputs accordingly?
Yes, I would like to know (i.e. having the correct behavior being documented by a test) what should happen if options->ce.fragment is set, or options->comp.alg.
Because in the code comments it sounds like this will *always* produce 1420, and I don't actually believed that that is true (although I do not remember whether I actually tested this or just read the code).
Regards,
Signature · 1 line
Frank Lichtenheld
Re: [Openvpn-devel] [PATCH v4 2/5] Allow tun-mtu to be pushed
In reply to Arne SchwabeHi,
Changes.rst Cookie based handshake for UDP server · line 88
Quoted 7 lines · Arne Schwabe
Changes.rst +7
-0+ +Tun MTU can be pushed + As part of changing the ``--tun-mtu`` default to 1420 (see below), the + client can now also dynamically configure its MTU and the server will + try to push the client MTU when the client supports it. The directive + ``--tun-mtu-max`` has been introduced to specify the maximum pushable + MTU size.
This text needs rewording, as the default isn't changed.
I can do this on the fly, but I'm not sure what to write here - maybe
Quoted 6 lines
src/openvpn/init.c +5
-0+Tun MTU can be pushed + Clients can now also dynamically configure their MTU and the server will + try to push the ``--tun-mtu`` the client should use when the client + supports it. The directive ``--tun-mtu-max`` has been introduced to + specify the maximum pushable MTU size.
src/openvpn/init.c do_deferred_options(struct context *c, const unsigned int found) · line 2351
Quoted 10 lines
src/openvpn/init.c +8
-0struct tls_session *session = &c->c2.tls_multi->session[TM_ACTIVE ]; +if (!check_session_cipher (session, &c->options)) + { +/* The update_session_cipher method will already print an error */ +return false; + } + +/* Cipher is considered safe, so we can use it to calculate the max +* MTU size */
I'm not sure I understand that comment, and the introducion of check_session_cipher() above... where's the cipher used for the MTU calculation below?
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]...