Using --inactive and --ping seems to defeat each other
Hi all,
In yesterday's meeting we discussed this issue:
<http://thread.gmane.org/gmane.network.openvpn.devel/3556>
In a nutshell, OpenVPN's ping packets (--ping <seconds>) keep the connection alive even if user uses the --inactive <seconds> option to close inactive connections. Now, the --inactive option has an optional <bytes> parameter, which allows closing the connection if less than <bytes> of traffic is received in <seconds>. Setting all of these parameters correctly should allow --inactivity to "ignore" the OpenVPN ping traffic.
Has somebody already solved this issue by setting correct values for --inactive and --ping parameters? Our idea is to change the code so that the --ping and --inactive options are not mutually exclusive even if the optional <bytes> option is not defined.
I hope I have not been too confusing :). For more information about the --inactive and --ping options, see "man openvpn" or
<http://openvpn.net/index.php/open-source/documentation/manuals/69-openvpn-21.html>
Signature · 5 lines
Samuli Seppänen Community Manager OpenVPN Technologies, Inc irc freenode net: mattock
Quoted 25 lines · Samuli Seppänen
Quoted 23 lines
Hi all,
In yesterday's meeting we discussed this issue:
<http://thread.gmane.org/gmane.network.openvpn.devel/3556>
In a nutshell, OpenVPN's ping packets (--ping<seconds>) keep the connection alive even if user uses the --inactive<seconds> option to close inactive connections. Now, the --inactive option has an optional <bytes> parameter, which allows closing the connection if less than <bytes> of traffic is received in<seconds>. Setting all of these parameters correctly should allow --inactivity to "ignore" the OpenVPN ping traffic.
Has somebody already solved this issue by setting correct values for --inactive and --ping parameters? Our idea is to change the code so that the --ping and --inactive options are not mutually exclusive even if the optional<bytes> option is not defined.
I hope I have not been too confusing :). For more information about the --inactive and --ping options, see "man openvpn" or
Quoted 9 lines
I agree that that would be a wise change. However, I wonder: why change the amount of bytes, if you can also simply not count the ping packets? To me, it would seem a much more accurate way of determining whether the connection is idle or not, because there's always the possibility of duplicate ping packets (even although that's unlikely) or other errors. Or would that cause a too great load on the server?
Sounds like a good idea. Do any devs have an idea how difficult (code-vise) that'd be?
Signature · 5 lines
Samuli Seppänen Community Manager OpenVPN Technologies, Inc irc freenode net: mattock
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 34 lines · Samuli Seppänen
Quoted 25 lines · Samuli Seppänen
Quoted 23 lines
Hi all,
In yesterday's meeting we discussed this issue:
<http://thread.gmane.org/gmane.network.openvpn.devel/3556>
In a nutshell, OpenVPN's ping packets (--ping<seconds>) keep the connection alive even if user uses the --inactive<seconds> option to close inactive connections. Now, the --inactive option has an optional <bytes> parameter, which allows closing the connection if less than <bytes> of traffic is received in<seconds>. Setting all of these parameters correctly should allow --inactivity to "ignore" the OpenVPN ping traffic.
Has somebody already solved this issue by setting correct values for --inactive and --ping parameters? Our idea is to change the code so that the --ping and --inactive options are not mutually exclusive even if the optional<bytes> option is not defined.
I hope I have not been too confusing :). For more information about the --inactive and --ping options, see "man openvpn" or
Quoted 9 lines
I agree that that would be a wise change. However, I wonder: why change the amount of bytes, if you can also simply not count the ping packets? To me, it would seem a much more accurate way of determining whether the connection is idle or not, because there's always the possibility of duplicate ping packets (even although that's unlikely) or other errors. Or would that cause a too great load on the server?
Quoted 2 lines
Sounds like a good idea. Do any devs have an idea how difficult (code-vise) that'd be?
I've not gone too deep into this code path yet, but I believe from what I could see, the byte counter is located on a different place than the "ping initiator". That means that telling the "byte counter code" that "this is our own packet, don't count it" is not as trivial to fix as it sounds like.
It looks like we just put 16 bytes of "static randomness" (defined in ping.c) and push that into the some session buffers. Then later on, in another function pushes what ever is queued up for transmission.
But this need to be investigated further ... and if someone is quicker than me to figure it out, patches are, as always, more than welcome!
kind regards,
David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iEUEARECAAYFAkva6rcACgkQDC186MBRfroTcQCeIZTmEXg2zEAtFiF3v0eQsvY/ /nQAlRSsZWXJSlfPT8L5cJT48uwuZm4=
=NuJi
-----END PGP SIGNATURE-----
Quoted 16 lines · David Sommerseth
Quoted 9 lines
Quoted 6 lines
I agree that that would be a wise change. However, I wonder: why change the amount of bytes, if you can also simply not count the ping packets? To me, it would seem a much more accurate way of determining whether the connection is idle or not, because there's always the possibility of duplicate ping packets (even although that's unlikely) or other errors. Or would that cause a too great load on the server?
Sounds like a good idea. Do any devs have an idea how difficult (code-vise) that'd be?
I've not gone too deep into this code path yet, but I believe from what I could see, the byte counter is located on a different place than the "ping initiator". That means that telling the "byte counter code" that "this is our own packet, don't count it" is not as trivial to fix as it sounds like.
Quoted 6 lines
It looks like we just put 16 bytes of "static randomness" (defined in
ping.c) and push that into the some session buffers. Then later on, in another function pushes what ever is queued up for transmission.But this need to be investigated further ... and if someone is quicker than me to figure it out, patches are, as always, more than welcome!
Well, the obvious (and probably wrong, probably inefficient) way could be to just check if the packet at hand is a ping message, and if it is do not record it as "activity", eg
if (! is_ping_msg (&c->c2.buf))
register_activity (c, size);
This is in two places: in process_outgoing_tun() and process_outgoing_link().
However, I'm not sure about the overhead of performing that for each and every processed packet. is_ping_msg() calls buf_string_match(), which in turn calls memcmp().
But, it should also be noted that process_incoming_link() DOES call is_ping_msg() for every incoming packet, so...
Signature · 1 line
D.
Quoted 5 lines · Davide Brini
if (!
is_ping_msg(&c->c2.buf))
register_activity(c, size);This is in two places: in
process_outgoing_tun()and
process_outgoing_link().
Actually that would probably need to be done only in process_outgoing_link(), as I don't think pings ever make it into the tun device to userspace, since they are discarded by process_incoming_link().
Signature · 1 line
D.
Hi,
Quoted 6 lines · Davide Brini
Well, the obvious (and probably wrong, probably inefficient) way could be to just check if the packet at hand is a ping message, and if it is do not record it as "activity", eg
if (!
is_ping_msg(&c->c2.buf))
register_activity(c, size);
Looks good to me :-) (without having looked at the code in question at all).
Quoted 1 line
This is in two places: in
process_outgoing_tun()andprocess_outgoing_link().
As you wrote in the next e-mail, this won't ever be "outgoing on tun", so only one place needs changing...
Quoted 5 lines
However, I'm not sure about the overhead of performing that for each and every processed packet.
is_ping_msg()callsbuf_string_match(), which in turn callsmemcmp().
But, it should also be noted thatprocess_incoming_link()DOES callis_ping_msg()for every incoming packet, so...
I'm a big fan of symmetry here - if the incoming packet path explictly not-counts ping packets, it's a bit hard to explain to users why the outgoing packet path *does* count them, and they have to fiddle with byte counts to get "inactivity".
I'd go that route...
Efficiency is a valid concern, of course. Since is_ping_msg() and buf_string_match() are both (very short) inline functions, and memcmp() on "normal" architectures is also inlined by gcc, this "should not" add unduly overhead. (Of course, down that road is hell and windows vista).
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...Quoted 8 lines · Gert Doering
Quoted 6 lines · Davide Brini
Well, the obvious (and probably wrong, probably inefficient) way could be to just check if the packet at hand is a ping message, and if it is do not record it as "activity", eg
if (!
is_ping_msg(&c->c2.buf))
register_activity(c, size);
Quoted 8 lines
Looks good to me :-) (without having looked at the code in question at
all).Quoted 2 lines
This is in two places: in
process_outgoing_tun()andprocess_outgoing_link().As you wrote in the next e-mail, this won't ever be "outgoing on tun", so only one place needs changing...
Yes of course, but I realized that too late :) It makes no sense at all to send OpenVPN pings to the kernel.
Quoted 11 lines
Quoted 5 lines
However, I'm not sure about the overhead of performing that for each and every processed packet.
is_ping_msg()callsbuf_string_match(), which in turn callsmemcmp().
But, it should also be noted thatprocess_incoming_link()DOES callis_ping_msg()for every incoming packet, so...I'm a big fan of symmetry here - if the incoming packet path explictly not-counts ping packets, it's a bit hard to explain to users why the outgoing packet path *does* count them, and they have to fiddle with byte counts to get "inactivity".
Quoted 6 lines
I'd go that route...
Efficiency is a valid concern, of course. Since
is_ping_msg()andbuf_string_match()are both (very short) inline functions, andmemcmp()on "normal" architectures is also inlined by gcc, this "should not" add unduly overhead. (Of course, down that road is hell and windows vista).
Ok, thanks for the remarks!
I will try to implement it that way then, and see how it goes (perhaps including some basic benchmarking - not entirely sure how to go about that apart from generating loads of traffic and see, but I'll figure out). Then I'll post back (possibly with a patch including changing the description in the man etc.)
Signature · 1 line
D.
Quoted 6 lines · Davide Brini
Well, the obvious (and probably wrong, probably inefficient) way could be to just check if the packet at hand is a ping message, and if it is do not record it as "activity", eg
if (!
is_ping_msg(&c->c2.buf))
register_activity(c, size);
How was that expression? "Complex problems have simple, easy to understand wrong answers". It seems this is one of those.
The problem with the above approach is that c->c2.buf at the time is_ping_msg() is called is potentially compressed (if compression is used, that is, almost always), so is_ping_msg() cannot detect a ping message.
Now, another approach could be to have a flag (a single byte) in the c2 context whose only function in life is to be 1 is the message is a ping message, and 0 otherwise (or true/false, as seems to be preferred in the OpenVPN code). That way, one could test it (also potentially more efficiently) eg
if (! c->c2.is_ping))
register_activity (c, size);
or something similar. What do people think? Does that look like a waste of space? Other ideas?
Signature · 1 line
D.
PATCH 1/1 Exclude ping and control packets from activity
Problem: using --ping and --inactive together partially defeats the point of using --inactive as periodic ping packets are counted as activity. Here is the original discussion:
http://article.gmane.org/gmane.network.openvpn.devel/3676
It turns out that "activity" is detected and recorded in two places in the code, both in forward.c: in process_outgoing_tun() for received packets, after they've been decrypted and sent to the TUN device; and in process_outgoing_link(), after they've been encrypted and written to the network socket.
In the first case we can be sure that packets that get so far are really due to user activity, whereas in the second case there can be non-user packets (like OpenVPN's internal ping packets, and TLS control packets), and those should not be counted as activity as they are not coming from the user.
So a need arises to detect those control packets and not count them as activity for the purposes of --inactive. Unfortunately, at that stage packets are already compressed and encrypted, so it's not possible to look into them to see what they are. However, there seems to be a convention in the code that packets whose buffer length in the context_2 structure is 0 should be ignored for certain purposes. TLS control packets follow that convention already, so this patch makes a small change in the code that generates the ping packets to set their buffer length to 0 as well.
Finally, the call to register_activity() in process_outgoing_link() is made conditional to the buffer length being > 0.
According to my tests, now --inactive behaves correctly according to the configured parameters (time or time+bytes) even when --ping is being used.
forward.c:
Call register_activity() in process_outgoing_link() only if the packet is not a ping or TLS control packet.
openvpn.8:
Updated the description of --inactive to describe the new semantics.
ping.c:
Set c->c2.buf.len = 0 after the ping packet has been generated and
encrypted.--- forward.c | 5 +++-- openvpn.8 | 20 +++++++++++++++----- ping.c | 2 ++ 3 files changed, 20 insertions(+), 7 deletions(-)
forward.c +3 -2
@@ -1157,8 +1157,9 @@ process_outgoing_link (struct context *c) size); } -/* indicate activity regarding --inactive parameter */ -register_activity (c, size); +/* if not a ping/control message, indicate activity regarding --inactive parameter */ +if (c->c2.buf.len >0 ) +register_activity (c, size); }else {
openvpn.8 +15 -5
@@ -1352,15 +1352,25 @@ to be between 100 bytes/sec and 100 Mbytes/sec. .B --inactive n [bytes] Causes OpenVPN to exit after .B n -seconds of inactivity on the TUN/TAP device. The time length -of inactivity is measured since the last incoming tunnel packet. +seconds of inactivity on the TUN/TAP device. The time length of +inactivity is measured since the last incoming or outgoing tunnel +packet. If the optional .B bytes parameter is included, -exit after n seconds of activity on tun/tap device -produces a combined in/out byte count that is less than -.B bytes. +exit if less than +.B bytes +of combined in/out traffic are produced on the tun/tap device +in +.B n +seconds. + +In any case, OpenVPN's internal ping packets (which are just +keepalives) and TLS control packets are not considered +"activity", nor are they counted as traffic, as they are used +internally by OpenVPN and are not an indication of actual user +activity. .\"********************************************************* .TP .B --ping n
ping.c +2 -0
@@ -86,5 +86,7 @@ check_ping_send_dowork (struct context *c)* encrypt, sign, etc. */ encrypt_sign (c, true); +/* Set length to 0, so it won't be counted as activity */ + c->c2.buf.len =0 ;dmsg (D_PING ,"SENT PING" ); }
Signature · 1 line
1.6.5.6
David Sommerseth
AppliedRe: [Openvpn-devel] [PATCH] Exclude ping and control packets from activity
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 45 lines · Davide Brini
Problem: using --ping and --inactive together partially defeats the point of using --inactive as periodic ping packets are counted as activity. Here is the original discussion:
http://article.gmane.org/gmane.network.openvpn.devel/3676
It turns out that "activity" is detected and recorded in two places in the code, both in
forward.c: inprocess_outgoing_tun()for received packets, after they've been decrypted and sent to the TUN device; and inprocess_outgoing_link(), after they've been encrypted and written to the network socket.In the first case we can be sure that packets that get so far are really due to user activity, whereas in the second case there can be non-user packets (like OpenVPN's internal ping packets, and TLS control packets), and those should not be counted as activity as they are not coming from the user.
So a need arises to detect those control packets and not count them as activity for the purposes of --inactive. Unfortunately, at that stage packets are already compressed and encrypted, so it's not possible to look into them to see what they are. However, there seems to be a convention in the code that packets whose buffer length in the
context_2structure is 0 should be ignored for certain purposes. TLS control packets follow that convention already, so this patch makes a small change in the code that generates the ping packets to set their buffer length to 0 as well.
Finally, the call toregister_activity()inprocess_outgoing_link()is made conditional to the buffer length being > 0.According to my tests, now --inactive behaves correctly according to the configured parameters (time or time+bytes) even when --ping is being used.
forward.c:
Callregister_activity()inprocess_outgoing_link()only if the packet is not a ping or TLS control packet.openvpn.8:
Updated the description of --inactive to describe the new semantics.
ping.c:Set c->c2.buf.len = 0 after the ping packet has been generated and encrypted.
Quoted 6 lines
Signed-off-by Davide Brini <[email protected]...>--- forward.c | 5 +++-- openvpn.8 | 20 +++++++++++++++----- ping.c | 2 ++ 3 files changed, 20 insertions(+), 7 deletions(-)
Applied to bugfix2.1 and merged into allmerged.
commit 2cde039a0add05f071f0f5bc9beee826d8cb8dd8
Author: Davide Brini <[email protected]...> Date: Sun May 2 11:07:38 2010 +0200
[...snip...]
Test routine is described here:
<https://community.openvpn.net/openvpn/wiki/PingInactivePatch?version=6>
Signed-off-by: Davide Brini <[email protected]...>
Acked-by: David Sommerseth <[email protected]...>
Signed-off-by: David Sommerseth <[email protected]...>kind regards,
David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iEYEARECAAYFAkxbDSMACgkQDC186MBRfro1EACfRBzynh1DKH3bE8PMbdeGfK1W 8usAoJ/VTW+CUofc6q+Jr0uUO4xKnHb6
=Ay/s
-----END PGP SIGNATURE-----