New approach to handle peer-id related changes to link-mtu.
PATCH 1/1 New approach to handle peer-id related changes to link-mtu.
Instead of statically increasing link-mtu by +3, keep the old value for OCC compatibility with old servers/clients, and only increase link-mtu if peer-id option is enabled (right now: is pushed by server).
If link-mtu has been set in the config, keep configured value, and log warning (because the extra overhead has to decrease tun-mtu).
Reserve extra +3 bytes in frame->extra_buffer.
This reverts commit f95010ad247a8998e0c39e394236251fca316849.
--- src/openvpn/init.c | 19 +++++++++++++++++++ src/openvpn/ssl.c | 10 ++++++---- 2 files changed, 25 insertions(+), 4 deletions(-)
src/openvpn/init.c +19 -0
@@ -1794,6 +1794,19 @@ 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; +frame_add_to_extra_frame (&c->c2.frame,+3 );/* peer-id overhead */ +if ( !c->options.ce.link_mtu_defined ) + { + c->c2.frame.link_mtu +=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" ,TUN_MTU_SIZE (&c->c2.frame) ); + } }#endif }
@@ -2403,6 +2416,12 @@ do_init_frame (struct context *c)#endif #endif /* USE_COMP */ +/* packets with peer-id (P_DATA_V2) need 3 extra bytes in frame. +* reserve in f->extra_buffer, adjust f->extra_frame when peer-id option +* is push-received (where it's too late to change BUF_SIZE(f) allocations) +*/ +frame_add_to_extra_buffer (&c->c2.frame,3 ); +#ifdef ENABLE_FRAGMENT /* * Set frame parameter for fragment code. This is necessary because
src/openvpn/ssl.c +6 -4
@@ -264,14 +264,16 @@ tls_get_cipher_name_pair (const char * cipher_name, size_t len) {return NULL ; } -/** -* Max number of bytes we will add for data structures common to both data and -* control channel packets (1 byte opcode + 3 bytes peer-id). +/* +* 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 +3 );/* space for opcode + peer-id */ +frame_add_to_extra_frame (frame,1 );/* space for opcode */ }/*
Signature · 1 line
2.1.2
PATCH v2 1/1 New approach to handle peer-id related changes to link-mtu.
Instead of statically increasing link-mtu by +3, keep the old value for OCC compatibility with old servers/clients, and only increase link-mtu if peer-id option is enabled (right now: is pushed by server).
If link-mtu has been set in the config, keep configured value, and log warning (because the extra overhead has to decrease tun-mtu).
Reserve extra +3 bytes in frame->extra_link.
v2: use frame->extra_link, not frame->extra_buffer (receive path on server)
introduce frame_add_to_link_mtu() to manipulate frame->link_mtu value rework comments to make more clear what is happening
This reverts commit f95010ad247a8998e0c39e394236251fca316849.
--- src/openvpn/init.c | 24 ++++++++++++++++++++++++ src/openvpn/mtu.h | 6 ++++++ src/openvpn/ssl.c | 10 ++++++---- 3 files changed, 36 insertions(+), 4 deletions(-)
src/openvpn/init.c +24 -0
@@ -1794,6 +1794,19 @@ 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; +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" ,TUN_MTU_SIZE (&c->c2.frame) ); + } }#endif }
@@ -2403,6 +2416,17 @@ 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). +* +* accomodate 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.h +6 -0
@@ -258,6 +258,12 @@ frame_headroom (const struct frame *f, const unsigned int flag_mask)*/ 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 int increment) { frame->extra_frame += increment;
src/openvpn/ssl.c +6 -4
@@ -264,14 +264,16 @@ tls_get_cipher_name_pair (const char * cipher_name, size_t len) {return NULL ; } -/** -* Max number of bytes we will add for data structures common to both data and -* control channel packets (1 byte opcode + 3 bytes peer-id). +/* +* 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 +3 );/* space for opcode + peer-id */ +frame_add_to_extra_frame (frame,1 );/* space for opcode */ }/*
Signature · 1 line
2.1.2
Am 08.02.15 um 11:18 schrieb Gert Doering:
Quoted 7 lines
Instead of statically increasing link-mtu by +3, keep the old value for OCC compatibility with old servers/clients, and only increase link-mtu if peer-id option is enabled (right now: is pushed by server).
If link-mtu has been set in the config, keep configured value, and log warning (because the extra overhead has to decrease tun-mtu).
Quoted 9 lines
Reserve extra +3 bytes in
frame->extra_link.v2: use
frame->extra_link, notframe->extra_buffer(receive path on server)
introduceframe_add_to_link_mtu()to manipulateframe->link_mtuvalue rework comments to make more clear what is happeningThis reverts commit
f95010ad247a8998e0c39e394236251fca316849.
ACK from me.
Arne
Patch has been applied to the master branch.
Release/2.3 needs a slightly different patch due to different buffer space reservation in the compression code (which means that the extra bytes we need are not there unless comp-lzo is used).
commit 9e0963c11aa439deb382d7d6bc40b6ade999401c (master)
Author: Gert Doering Date: Sun Feb 8 11:18:45 2015 +0100
New approach to handle peer-id related changes to link-mtu.
Signed-off-by: Gert Doering <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/9450--
kind regards,
Gert Doering
PATCH v2 1/1 New approach to handle peer-id related changes to link-mtu.
In reply to Gert DoeringInstead of statically increasing link-mtu by +3, keep the old value for OCC compatibility with old servers/clients, and only increase link-mtu if peer-id option is enabled (right now: is pushed by server).
If link-mtu has been set in the config, keep configured value, and log warning (because the extra overhead has to decrease tun-mtu).
Reserve extra +3 bytes in frame->extra_link.
v2: use frame->extra_link, not frame->extra_buffer (receive path on server)
introduce frame_add_to_link_mtu() to manipulate frame->link_mtu value rework comments to make more clear what is happening
Adaption to 2.3: reserve +8 bytes in frame->extra_buffer - if compression
is not enabled, the 2.3 code does not reserve space for compression overhead (2.4 code does), so the buffer ends up being too small. +3 is not sufficient because the buffer handling code also does some alignment tricks...
This reverts commit 4ec70ca227370380011d072c09b739135e236183.
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/9450
(cherry picked from commit 9e0963c11aa439deb382d7d6bc40b6ade999401c)
--- src/openvpn/init.c | 24 ++++++++++++++++++++++++ src/openvpn/mtu.h | 6 ++++++ src/openvpn/ssl.c | 10 ++++++---- 3 files changed, 36 insertions(+), 4 deletions(-)
src/openvpn/init.c +24 -0
@@ -1798,6 +1798,19 @@ 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; +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" ,TUN_MTU_SIZE (&c->c2.frame) ); + } }#endif }
@@ -2400,6 +2413,17 @@ do_init_frame (struct context *c)*/ frame_finalize_options (c,NULL ); +/* 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). +* +* accomodate receive path in f->extra_link +* send path in f->extra_buffer (+leave room for alignment) +* +* f->extra_frame is adjusted when peer-id option is push-received +*/ +frame_add_to_extra_link (&c->c2.frame,3 ); +frame_add_to_extra_buffer (&c->c2.frame,8 ); +#ifdef ENABLE_FRAGMENT /* * Set frame parameter for fragment code. This is necessary because
src/openvpn/mtu.h +6 -0
@@ -258,6 +258,12 @@ frame_headroom (const struct frame *f, const unsigned int flag_mask)*/ 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 int increment) { frame->extra_frame += increment;
src/openvpn/ssl.c +6 -4
@@ -267,14 +267,16 @@ tls_get_cipher_name_pair (const char * cipher_name, size_t len) {return NULL ; } -/** -* Max number of bytes we will add for data structures common to both data and -* control channel packets (1 byte opcode + 3 bytes peer-id). +/* +* 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 +3 );/* space for opcode + peer-id */ +frame_add_to_extra_frame (frame,1 );/* space for opcode */ }/*
Signature · 1 line
2.1.3
Quoted 19 lines · Gert Doering
Instead of statically increasing link-mtu by +3, keep the old value for OCC compatibility with old servers/clients, and only increase link-mtu if peer-id option is enabled (right now: is pushed by server).
If link-mtu has been set in the config, keep configured value, and log warning (because the extra overhead has to decrease tun-mtu).
Reserve extra +3 bytes in
frame->extra_link.v2: use
frame->extra_link, notframe->extra_buffer(receive path on server)
introduceframe_add_to_link_mtu()to manipulateframe->link_mtuvalue rework comments to make more clear what is happeningAdaption to 2.3: reserve +8 bytes in
frame->extra_buffer- if compression
is not enabled, the 2.3 code does not reserve space for compression overhead (2.4 code does), so the buffer ends up being too small. +3 is not sufficient because the buffer handling code also does some alignment tricks...
Quoted 6 lines
This reverts commit
4ec70ca227370380011d072c09b739135e236183.Signed-off-by Gert Doering <[email protected]...>Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/9450
(cherry picked from commit9e0963c11aa439deb382d7d6bc40b6ade999401c)
ACK. Code looks good, and tests confirm this approach works.
-Steffan
Patch has been applied to the release/2.3 branch.
commit 089d63b2d7ffa98bd40ed1d7eb0e625d37b63c1c (release/2.3)
Author: Gert Doering Date: Sun Feb 8 11:18:45 2015 +0100
New approach to handle peer-id related changes to link-mtu.
Signed-off-by: Gert Doering <[email protected]...>
Acked-by: Steffan Karger <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/9458--
kind regards,
Gert Doering