Replace TUN_MTU_SIZE with frame->tun_mtu
PATCH v4 1/8 Replace TUN_MTU_SIZE with frame->tun_mtu
This always uses the configured MTU size instead relying on the calculated MTU size.
Patch v4: Fix a few overlooked TUN_MTU_SIZE.
--- src/openvpn/forward.c | 2 +- src/openvpn/init.c | 20 ++++++++++---------- src/openvpn/mtu.c | 4 ++-- src/openvpn/mtu.h | 5 ----- 4 files changed, 13 insertions(+), 18 deletions(-)
src/openvpn/forward.c +1 -1
@@ -1381,7 +1381,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 +10 -10
@@ -1735,7 +1735,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); }
@@ -1766,7 +1766,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 */
@@ -1778,7 +1778,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",
@@ -1827,7 +1827,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",
@@ -1906,7 +1906,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",
@@ -1936,7 +1936,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",
@@ -1974,7 +1974,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",
@@ -2154,7 +2154,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); } }
@@ -3185,11 +3185,11 @@ do_init_frame(struct context *c)#ifdef ENABLE_FRAGMENT if ((c->options.ce.mssfix || c->options.ce.fragment) - &&TUN_MTU_SIZE (&c->c2.frame_fragment) !=ETHERNET_MTU ) + && c->c2.frame.tun_mtu !=ETHERNET_MTU ) {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)); +ETHERNET_MTU , c->c2.frame.tun_mtu); }#endif }
src/openvpn/mtu.c +2 -2
@@ -229,9 +229,9 @@ frame_finalize(struct frame *frame, frame->link_mtu = link_mtu; } -if (TUN_MTU_SIZE (frame) <TUN_MTU_MIN ) +if (frame->tun_mtu <TUN_MTU_MIN ) { -msg (M_WARN ,"TUN MTU value (%d) must be at least %d" ,TUN_MTU_SIZE (frame),TUN_MTU_MIN ); +msg (M_WARN ,"TUN MTU value (%d) must be at least %d" , frame->tun_mtu,TUN_MTU_MIN );frame_print (frame,M_FATAL ,"MTU is too small" ); }
src/openvpn/mtu.h +0 -5
@@ -184,11 +184,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 v4 2/8 Change the default for mssfix to mssfix 1492 mtu
The 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
Re: [Openvpn-devel] [PATCH v4 2/8] Change the default for mssfix to mssfix 1492 mtu
Hi,
Quoted 8 lines · Arne Schwabe
The 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.
I think this needs a followup patch... I'll apply it (as it does what it says on the lid), but it needs further work, see below.
Feature-ACK on having "1492 mtu" by default, so that is good.
It should have a Changes.rst entry for "User-visible Changes" - I tried to draft something, but then decided to send it back via the list. Here's my draft text
- :code:--mssfix default has been changed from 1450 to ``1492 mtu`` to take IPv4 or IPv6 encap and today's typical SoHo internet links into account. If :code:--tun-mtu is changed from the default setting, the default for :code:--mssfix is now ``off``
Also, the patch needs to change the manpage from
"Default value of 1450 allows ..."
to
"Default value of ``1492 mtu`` allows packets to be transmitted
over a link with MTU 1492 or higher without IP level fragmentation. If :code:tun-mtu is used to set a value != 1500, mssfix needs to be configured with an explicit value, as no default applies."
(or such)
The code itself looks a bit fumbly with changing "o->ce.mssfix_encap = true" in the defaults section, just to change it back to "false" in the options.c handler - why not leave it at false, as it's set to "true" anyway at setting MSSFIX_DEFAULT?
But my main concern is this combination of options:
--tun_mtu 1400 --mssfix
what would the user expect OpenVPN to do here? I would expect "apply mssfix handling, in a reasonable fashion for the configured tun_mtu", but what OpenVPN does is "turn off mssfix, because, not 1500".
So the default "no mssfix in the config" and "mssfix without arguments" are handled the same way. If this is intentional ("mssfix without arguments does nothing if the tun_mtu is not 1500") it should be documented.
This said, the patch applies and works fine.
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 v4 2/8] Change the default for mssfix to mssfix 1492 mtu
Am 11.02.22 um 10:44 schrieb Gert Doering:
Quoted 18 lines
Hi,
Quoted 8 lines · Arne Schwabe
The 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.
I think this needs a followup patch... I'll apply it (as it does what it says on the lid), but it needs further work, see below.
Feature-ACK on having "1492 mtu" by default, so that is good.
Quoted 8 lines
It should have a
Changes.rstentry for "User-visible Changes" - I tried to draft something, but then decided to send it back via the list. Here's my draft text- :code:
--mssfixdefault has been changed from 1450 to ``1492 mtu`` to take IPv4 or IPv6 encap and today's typical SoHo internet links into account. If :code:--tun-mtuis changed from the default setting, the default for :code:--mssfixis now ``off``
Sounds good.
Quoted 12 lines
Also, the patch needs to change the manpage from
"Default value of 1450 allows ..."to
"Default value of ``1492 mtu`` allows packets to be transmitted
over a link with MTU 1492 or higher without IP level fragmentation. If :code:tun-mtuis used to set a value != 1500, mssfix needs to be configured with an explicit value, as no default applies."
(or such)
Quoted 4 lines
The code itself looks a bit fumbly with changing "
o->ce.mssfix_encap= true" in the defaults section, just to change it back to "false" in theoptions.chandler - why not leave it at false, as it's set to "true" anyway at settingMSSFIX_DEFAULT?
Yeah, it is all a bit finnicky and I am not super happy with it. I change the default of it to false if you prefer that.
Quoted 6 lines
But my main concern is this combination of options:
--tun_mtu 1400 --mssfix
Quoted 8 lines
what would the user expect OpenVPN to do here? I would expect "apply mssfix handling, in a reasonable fashion for the configured
tun_mtu", but what OpenVPN does is "turn off mssfix, because, not 1500".So the default "no mssfix in the config" and "mssfix without arguments" are handled the same way. If this is intentional ("mssfix without arguments does nothing if the
tun_mtuis not 1500") it should be documented.
So my reason is that if you have a tun-mtu > 1500, that you want to had a reason and want use larger packet and then a mssfix would break whatever you are trying to do.
And if you have a tun-tmu < 1500, then the smaller tun-mtu should already give you a MSS value that is small enough. If the MTU value is between something like 1450 and 1500, mssfix probably still does something but it felt to odd of a corner to still enable it.
Arne
[Openvpn-devel] [PATCH applied] Re: Change the default for mssfix to mssfix 1492 mtu
In reply to Arne SchwabeThe code does what it says on the lid, and the resulting program run confirms it:
2022-02-11 10:43:41 us=304654 mssfix = 1492 2022-02-11 10:43:41 us=304660 mssfix_encap = ENABLED
I have not actually tested the resulting SYN/SYN-ACK values for IPv4 transport, as the other end of my test setup is on an older code base and would interfere with the tests (both sides modify MSS by default, in both directions, and the one with the lower MSS value "wins"). I have tested "mssfix ... mtu" before, so I'm reasonably sure it will do the right thing for "1492 mtu" now.
It does the right thing, for IPv6, though :-)
- IPv4 over IPv6, BF-CBC -> mss 1362 -> UDP payload 1440, IPv6 len 1488
- IPv6 over IPv6, BF-CBC -> mss 1342 -> UDP payload 1440, IPv6 len 1488
- IPv6 over IPv4, AES-GCM -> mss 1379 -> UDP payload 1444, IPv6 len 1492
- IPv6 over IPv6, AES-GCM -> mss 1359 -> UDP payload 1444, IPv6 len 1492
For reference, this was 07/14 in v3 of the patchset, and was neither ACKed nor NAKed there (I had the same concerns as I voiced in my preceding e-mail here, but did only mention them on IRC).
Your patch has been applied to the master branch.
commit 0d86da32695539a96848b96149484af41bba83c5
Author: Arne Schwabe Date: Thu Feb 10 17:26:26 2022 +0100
Change the default for mssfix to mssfix 1492 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]/msg23754.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v4 3/8 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
@@ -3361,8 +3361,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
@@ -4230,9 +4230,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 )
@@ -4284,6 +4284,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.
@@ -190,7 +194,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)/*
@@ -198,7 +201,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))/*
@@ -309,6 +311,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
@@ -6159,11 +6159,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
@@ -333,8 +333,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 ;
@@ -1920,9 +1919,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" );/*
@@ -1937,7 +1935,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" ); }
@@ -2990,6 +2988,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,
@@ -3835,17 +3834,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
@@ -388,7 +388,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 */
@@ -398,7 +398,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 */
@@ -412,7 +412,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 );
@@ -440,7 +440,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
Re: [Openvpn-devel] [PATCH v4 3/8] Add mtu paramter to --fragment and change fragment calculation
Hi,
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
Not sure what exactly caused this (maybe the reordering), but applying 3/8 after 1+2 (in tree) leads to "UDP p2mp server crashing"
2022-02-11 12:24:07 us=152359 Initialization Sequence Completed 2022-02-11 12:24:18 us=290966 MULTI: multi_create_instance called 2022-02-11 12:24:18 us=291063 194.97.140.21:62328 Re-using SSL/TLS context 2022-02-11 12:24:18 us=291116 194.97.140.21:62328 LZO compression initializing 2022-02-11 12:24:18 us=291376 194.97.140.21:62328 Control Channel MTU parms [ mss_fix:0 max_frag:0 tun_mtu:1250 headroom:126 payload:1376 tailroom:126 L:1622 EF:38 EB:0 ET:0 EL:3 ]
Program received signal SIGSEGV, Segmentation fault.frame_calculate_mssfix (lsi=0x0, options=0x555555642280, kt=0x555555642b40, frame=0x555555642dd0) at mss.c:305
305 overhead += get_ip_encap_overhead(options, lsi);
(gdb) where
#0 frame_calculate_mssfix (lsi=0x0, options=0x555555642280, kt=0x555555642b40, frame=0x555555642dd0) at mss.c:305
#1 frame_calculate_dynamic ([email protected]...=0x555555642dd0, [email protected]...=0x555555642b40, [email protected]...=0x555555642280, lsi=0x0)
at mss.c:334 #2 0x000055555557b2bb in init_instance ([email protected]...=0x555555642280, env=<optimized out>, [email protected]...=10) at init.c:4234 #3 0x000055555557c4a6 in inherit_context_child ([email protected]...=0x555555642280, [email protected]...=0x7fffffffc4b0) at init.c:4459 #4 0x0000555555591af3 in multi_create_instance ([email protected]...=0x7fffffffc3f0, [email protected]...=0x7fffffffc2b0) at multi.c:759 #5 0x000055555558b89e in multi_get_create_instance_udp (m=0x7fffffffc3f0, [email protected]...=0x7fffffffc33f) at mudp.c:103 #6 0x0000555555591efa in multi_process_incoming_link ([email protected]...=0x7fffffffc3f0, [email protected]...=0x0, [email protected]...=5) at multi.c:3107
the crucial part is "lsi=0x0" here, I think, but I'm not sure why... we do have a socket, we know we bound it to IPv6 (+dual-stack)...
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 v4 3/8] Add mtu paramter to --fragment and change fragment calculation
Hi,
Quoted 2 lines · Gert Doering
the crucial part is "lsi=0x0" here, I think, but I'm not sure why... we do have a socket, we know we bound it to IPv6 (+dual-stack)...
Trying this trivial fix...
src/openvpn/mss.c +1 -1
@@ -234,7 +234,7 @@ get_ip_encap_overhead(const struct options *options, {/* Add the overhead of the encapsulating IP packets */ sa_family_t af; -if (lsi->lsa) +if (lsi && lsi->lsa) { af = lsi->lsa->actual.dest.addr.sa.sa_family; }
... moves the crash onward to
0x00005555555891b6 in datagram_overhead (proto=<error reading variable: Cannot access memory at address 0x24>, af=10) at socket.h:617
617 overhead += (proto == PROTO_UDP) ? 8 : 20;
(gdb) where
#0 0x00005555555891b6 in datagram_overhead (proto=<error reading variable: Cannot access memory at address 0x24>, af=10) at socket.h:617 #1 get_ip_encap_overhead (lsi=0x0, options=0x555555642280) at mss.c:248 #2 frame_calculate_mssfix (lsi=0x0, options=0x555555642280, kt=0x555555642b40, frame=0x555555642dd0) at mss.c:305 #3 frame_calculate_dynamic ([email protected]...=0x555555642dd0, [email protected]...=0x555555642b40, [email protected]...=0x555555642280, lsi=0x0) at mss.c:334
#4 0x000055555557b2bb in init_instance ([email protected]...=0x555555642280, env=<optimized out>, [email protected]...=10) at init.c:4234 #5 0x000055555557c4a6 in inherit_context_child ([email protected]...=0x555555642280, [email protected]...=0x7fffffffc4b0) at init.c:4459
which looks weird, but is likely due to inlining.
The culprit is this one:
return datagram_overhead(af, lsi->proto);
"lsi" is still NULL...
Not sure how to fix this in a good way.
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 v4 3/8] Add mtu paramter to --fragment and change fragment calculation
Quoted 17 lines
... moves the crash onward to
0x00005555555891b6indatagram_overhead(proto=<error reading variable: Cannot access memory at address0x24>, af=10) at socket.h:617
617 overhead += (proto ==PROTO_UDP) ? 8 : 20;
(gdb) where#0 0x00005555555891b6 in datagram_overhead (proto=<error reading variable: Cannot access memory at address 0x24>, af=10) at socket.h:617 #1 get_ip_encap_overhead (lsi=0x0, options=0x555555642280) at mss.c:248 #2 frame_calculate_mssfix (lsi=0x0, options=0x555555642280, kt=0x555555642b40, frame=0x555555642dd0) at mss.c:305 #3 frame_calculate_dynamic ([email protected]...=0x555555642dd0, [email protected]...=0x555555642b40, [email protected]...=0x555555642280, lsi=0x0) at mss.c:334#4
0x000055555557b2bbininit_instance([email protected]...=0x555555642280, env=<optimized out>, [email protected]...=10) at init.c:4234 #50x000055555557c4a6ininherit_context_child([email protected]...=0x555555642280, [email protected]...=0x7fffffffc4b0) at init.c:4459which looks weird, but is likely due to inlining.
Quoted 8 lines
The culprit is this one:
return datagram_overhead(af, lsi->proto);"lsi" is still NULL...
Not sure how to fix this in a good way.
This function is called to early now and doesn't anything useful anymore apart when used in --static/crypto none context. So I changed it to not crash in these cases and added a comment that the call is superflous for most of OpenVPN's operation. If we at some point remove --static/no crypto (non TLS modes), we can do a lot of cleanup.
Arne
PATCH v5 1/1 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
Patch v5: fix segfault when get_ip_encap_overhead gets called early in
init_instance and note that these calls will always be overwritten by NCP in tls_session_update_crypto_params
--- 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 | 111 +++++++++++++++++++++++-- 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, 185 insertions(+), 114 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 +9 -6
@@ -3361,8 +3361,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
@@ -4230,10 +4230,6 @@ 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)); -/* bind the TCP/UDP socket */ if (c->mode ==CM_P2P || c->mode ==CM_TOP || c->mode ==CM_CHILD_TCP ) {
@@ -4284,6 +4280,13 @@ 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. +* This is only needed for --static or no crypto, NCP will recalculate this +* in tls_session_update_crypto_params (P2MP) */ +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 +102 -9
141 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.
@@ -190,7 +194,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)/*
@@ -198,7 +201,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))/*
@@ -309,6 +311,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
@@ -6159,11 +6159,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
@@ -333,8 +333,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 ;
@@ -1920,9 +1919,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" );/*
@@ -1937,7 +1935,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" ); }
@@ -2990,6 +2988,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,
@@ -3835,17 +3834,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
@@ -388,7 +388,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 */
@@ -398,7 +398,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 */
@@ -412,7 +412,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 );
@@ -440,7 +440,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
[Openvpn-devel] [PATCH applied] Re: Add mtu paramter to --fragment and change fragment calculation
Looked at the code, compared v4. v5 now guards "lsi" against being NULL on lsi->lsa and lsi->proto access in get_ip_encap_overhead(), and also removes the "frame_calculate_mssfix()" call in init_instance() before socket initialization, plus an extra comment about --static. So the change v4->v5 looks very reasonable and also fixes the issue :-)
Ran full set of t_client and t_server tests, all tests passed, including the --fragment instance. Good :-)
Also, ran manual --fragment tests with varying values.
Testing is hard, as OpenVPN will not split the packet at "fragment size + small remainder" but "in the middle" (to get somewhat similar-sized smaller packets). So one needs to test varying sizes to get to the point "ping $size +1 will need one more fragment".
Test case:
AES-256-GCM, over IPv6, --fragment 500 mtu, pinging IPv4 through the tunnel
ping -s 819
13:21:23.241119 ethertype IPv6 (0x86dd), length 514: 2001:608:4::ce:c0f.49924 > 2607:fc50:1001:5200::4.51198: UDP, length 452 13:21:23.241141 ethertype IPv6 (0x86dd), length 514: 2001:608:4::ce:c0f.49924 > 2607:fc50:1001:5200::4.51198: UDP, length 452
(514 is including ethernet headers) -> "full '500 mtu' frames"
ping -s 820
13:21:59.288511 ethertype IPv6 (0x86dd), length 374: 2001:608:4::ce:c0f.49924 > 2607:fc50:1001:5200::4.51198: UDP, length 312 13:21:59.288533 ethertype IPv6 (0x86dd), length 374: 2001:608:4::ce:c0f.49924 > 2607:fc50:1001:5200::4.51198: UDP, length 312 13:21:59.288550 ethertype IPv6 (0x86dd), length 371: 2001:608:4::ce:c0f.49924 > 2607:fc50:1001:5200::4.51198: UDP, length 309
-> too big -> split in 3
IPv4 over IPv4 needs +40 byte for the "2 frag limit" (20 byte per header)
ping -s 859
13:23:40.887343 ethertype IPv4 (0x0800), length 514: 193.149.48.178.12321 > 199.102.77.82.51198: UDP, length 472 13:23:40.887364 ethertype IPv4 (0x0800), length 514: 193.149.48.178.12321 > 199.102.77.82.51198: UDP, length 472
ping -s 860
13:24:23.221704 ethertype IPv4 (0x0800), length 370: 193.149.48.178.12321 > 199.102.77.82.51198: UDP, length 328 13:24:23.221724 ethertype IPv4 (0x0800), length 370: 193.149.48.178.12321 > 199.102.77.82.51198: UDP, length 328 13:24:23.221739 ethertype IPv4 (0x0800), length 359: 193.149.48.178.12321 > 199.102.77.82.51198: UDP, length 317
-> calculation works, "500 mtu" is never exceeded.
I also tested "--fragment 500" without "mtu", and that also looks good:
ping -s 915
13:55:42.542898 ethertype IPv4 (0x0800), length 542: 193.149.48.178.20948 > 199.102.77.82.51198: UDP, length 500 13:55:42.542918 ethertype IPv4 (0x0800), length 486: 193.149.48.178.20948 > 199.102.77.82.51198: UDP, length 444
ping -s 916
13:56:18.962233 ethertype IPv4 (0x0800), length 386: 193.149.48.178.20948 > 199.102.77.82.51198: UDP, length 344 13:56:18.962254 ethertype IPv4 (0x0800), length 386: 193.149.48.178.20948 > 199.102.77.82.51198: UDP, length 344 13:56:18.962270 ethertype IPv4 (0x0800), length 383: 193.149.48.178.20948 > 199.102.77.82.51198: UDP, length 341
I tried to test PMTU discovery, but I'm not sure I know how to do that (or our code is broken)
The naive assumption "run OpenVPN with --fragment 1000 --mtu-disc yes", "run ping -s 951 $target" and "install a route with 'mtu 800'" leads to packets being eaten
write UDPv4: Message too long (fd=3,code=90)
.. but packet size was not reduced. So I assumed "it must be an incoming ICMP", and set up the reduced-route MTU on the next hop router - again:
write UDPv4: Message too long (fd=3,code=90)
.. so the ICMP message arrived on Linux, and Linux cached this:
ip route get 199.102.77.82
199.102.77.82 via 193.149.48.190 dev eno1 src 193.149.48.174 uid 202
cache expires 475sec mtu 800
Running OpenVPN with "--mtu-disc maybe" (wat?) leads to "OpenVPN produces 1000+ byte packets, and Linux fragments to 800"
10:08:53.304953 ethertype IPv4 (0x0800), length 810: 193.149.48.174.51279 > 199.102.77.82.51198: UDP, length 1000 10:08:53.304961 ethertype IPv4 (0x0800), length 266: 193.149.48.174 > 199.102.77.82: ip-proto-17
Which is the same thing than "--mtu-disc no". So it seems MTU-Discovery is just not working in our current code (does not work with older versions either). This needs revisiting, but wasn't broken by *this* patch.
For reference, this was 14/21 in v1+v2 of the patch series (Frank Lichtenheld commented about .rst syntax), 09/14 in v3 of the patch series (which got a NAK from me because it breaks 'ifconfig' MTU settings) and 03/08 in v4 (NAK because UDP server crashed). The patch itself mostly is the same as 09/14, but due 01/08 being applied first, ifconfig is no longer broken.
Some more thoughts:
- should we make '--fragment' be pushable with the new code? As the frame_calculate_dynamic() stuff is truly dynamic now, it might actually work...
- this patch removes one check on reception (tls_pre_decrypt_lite())
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",We need to check if this is still safe against a malicious peer sending arbitrary huge packets (like, one side having set a --tun-mtu 9000).
I did a bit of testing, and the results are... interesting. Server side with tun-mtu 1500, client with tun-mtu 9000.
Up to a certain ping size, I can see pings going in and out on the server tun (tcpdump) just fine (with fragmentation being different back and forth):
10:20:08.382092 IP 10.204.2.30 > 10.204.2.1: ICMP echo request, id 8606, seq 1, length 1708 10:20:08.382131 IP 10.204.2.1 > 10.204.2.30: ICMP echo reply, id 8606, seq 1, length 1480 10:20:08.382137 IP 10.204.2.1 > 10.204.2.30: ip-proto-1
over a certain size, network->tun ends up in OpenVPN refusing to put the packet into the tun interface
Feb 13 10:20:11 gentoo tun-udp-p2mp[20590]: cron2-gentoo-i386/193.149.48.178:39702 tun packet too large on write (tried=1828,max=1736)
(but no crash, this is good)
Now, increasing the packets to really huge sizes, we hit a buffer cap somewhere in the decrypt path
Feb 13 10:21:21 gentoo tun-udp-p2mp[20590]: cron2-gentoo-i386/193.149.48.178:39702 AEAD Decrypt error: cipher final failed
(still no crash, this is good)
So this *looks* as if OpenVPN is handling the szenario correctly, but I'd appreciate if someone knowledgeable would look into this as well.
commit 0d969976a338471869957d78867329b74ecf8bea
Author: Arne Schwabe Date: Sat Feb 12 01:33:31 2022 +0100
Add mtu paramter to --fragment and change fragment calculation
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]/msg23764.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH applied] Re: Add mtu paramter to --fragment and change fragment calculation
Hi,
Quoted 2 lines · Gert Doering
I tried to test PMTU discovery, but I'm not sure I know how to do that (or our code is broken)
To track this, I have opened
https://community.openvpn.net/openvpn/ticket/1452
and I intend to eventually look into this :-) - but if someone else who understand socket APIs and "extended socket error reporting" wants to have a go...
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 4/8 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 Patch v4: Rebase
--- src/openvpn/init.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
src/openvpn/init.c +10 -5
@@ -3184,12 +3184,17 @@ do_init_frame(struct context *c)#endif #ifdef ENABLE_FRAGMENT -if ((c->options.ce.mssfix || c->options.ce.fragment) - && c->c2.frame.tun_mtu !=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 , c->c2.frame.tun_mtu); +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
[Openvpn-devel] [PATCH applied] Re: Update fragment and mssfix related warnings
Have not actually tried triggering these warnings, but the logic is sane, and the code looks reasonable.
Client-side tested "just for completeness".
For reference, this was 15/21 in v1+v2 of this series and 06/14 in v3, and 15/21 got an ACK from Frank Lichtenfeld with a comment about the wording of the "the mtu" warning, which was addressed in v2.
Your patch has been applied to the master branch.
commit f1e06301c71e8c8d4eb9c93939e775596fc2f998
Author: Arne Schwabe Date: Thu Feb 10 17:26:28 2022 +0100
Update fragment and mssfix related warnings
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]/msg23753.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v4 5/8 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
[Openvpn-devel] [PATCH applied] Re: Use new frame header methods to calculate OCC_MTU_LOAD payload size
.. though I'm not sure I understand any of this code, or how to trigger it. So I've only run client/server tests, and stared at the code changes for a bit.
I think it actually breaks the original intent, as the "changes per iteration" variable "entry->delta" is gone now - so this is a semi-NAK, as in "we need to come back here and fix this". But I want to move forward with the frame stuff, and 7/8 can not go in without this.
Can anyone tell me how to actually trigger an "OCC MTU test"? --mtu-disc is doing socket level stuff ("only supported on OSes ... necessary system call") - so maybe this was broken / inactive already before...
Your patch has been applied to the master branch.
commit fb76954a232decc86e071a76861c1e4fdd2507ab
Author: Arne Schwabe Date: Thu Feb 10 17:26:29 2022 +0100
Use new frame header methods to calculate OCC_MTU_LOAD payload size
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]/msg23750.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v4 6/8 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
@@ -3110,14 +3110,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. */
@@ -3150,17 +3142,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 */
@@ -378,12 +371,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
[Openvpn-devel] [PATCH applied] Re: Remove extra_link from frame
This patch series is coming to an end, and now we get to reap the benefits - code gets simpler, old cruft gets removed.
Stared at the change (looks good and fairly straightforward), still ran full set of client side tests (including SOCKS). Not run the server side tests as there really isn't anthing that looks relevant.
Your patch has been applied to the master branch.
commit 625c4063a543700713c8fdde7dd911343dcc4dcc
Author: Arne Schwabe Date: Thu Feb 10 17:26:30 2022 +0100
Remove extra_link from frame
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]/msg23751.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v4 7/8 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
@@ -1545,7 +1545,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
@@ -1673,7 +1673,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
@@ -2140,24 +2140,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) {
@@ -2166,11 +2148,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,
@@ -2292,7 +2269,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 */
@@ -2528,14 +2504,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); - }/*
@@ -3043,8 +3011,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" ); }
@@ -3136,9 +3104,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 (frame->tun_mtu <TUN_MTU_MIN ) - { -msg (M_WARN ,"TUN MTU value (%d) must be at least %d" , frame->tun_mtu,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 ;
@@ -1931,9 +1925,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
[Openvpn-devel] [PATCH applied] Re: Remove frame->link_mtu
And another one in the "reap the benefits" series :-)
Stared at the code, ran client and server tests. All good.
(For reference: this was 20/21 in v1+v2, 13/14 in v3, received no comments in either series)
Your patch has been applied to the master branch.
commit 986559bfa3c0a21c2ce4a486125aa03040fde849
Author: Arne Schwabe Date: Thu Feb 10 17:26:31 2022 +0100
Remove frame->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]/msg23749.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v4 8/8 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
@@ -251,13 +251,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
@@ -210,9 +210,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
@@ -331,8 +331,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 ;
@@ -1908,10 +1891,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
[Openvpn-devel] [PATCH applied] Re: Remove frame.extra_frame and frame.extra_buffer
And this is the final one in the "frame rewrite" series, hooray! (Well, with the not-yet-sent "documentation cleanup" and "OCC MTU Test" fixes pending, but still...)
Stared at the code - lots of changes, but all "remove old cruft" :-) - and ran client and server tests (all good). It even passes some of my long standing "this is broken" test cases now, where P2P-NCP going to non-GCM ciphers would break full-sized packet, so even better.
It might be worth testing if this now fixes --disable-lzo --disable-lz4 (no COMP at all) for good... MaxF, you listening? ;-)
For reference, this was 21/21 in v1+v2, and 14/14 in v3, neither of which got any comments.
Your patch has been applied to the master branch.
commit 75a3e8599d2740704a8b705692a6f28541e8d514
Author: Arne Schwabe Date: Thu Feb 10 17:26:32 2022 +0100
Remove frame.extra_frame and frame.extra_buffer
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]/msg23755.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Code change looks very straight forward :-)
Passes all my torture tests on client and server (except frame max setting on P2P TAP, but that's known and will be fixed at the end of the series).
For reference, this was 19/21 in v1 and 12/14 in v3 of the series, which could not go in because it broke compilation. The difference v3 -> v4 is "more TUN_MTU_SIZE() calls get converted" - all of these in code parts that got removed in other parts of the v3 patch series, but breaking compilation nonetheless.
Doing this as 01/08 now will also magically fix the "ifconfig has the wrong mtu value" problem that made me stall 09/14 v3.
Your patch has been applied to the master branch.
commit 364b7b4f04985600e0a0a46e79555379b5df9977
Author: Arne Schwabe Date: Thu Feb 10 17:26:25 2022 +0100
Replace TUN_MTU_SIZE with frame->tun_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]/msg23752.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering