Skip to content

Commit

Permalink
openvpn: Disable connection retry attempts when TCP is used as transport
Browse files Browse the repository at this point in the history
By default OpenVPN will retry the connection ad infinitum with TCP
unless the limit is explicitly specified. The process is not restarted,
nor is the error reported via management channel.

When establishing the connection following is being output by OpenVPN
if the TCP connection is reset, but none of this is reported back to
ConnMan and OpenVPN keeps on trying:

openvpn[18161]: Attempting to establish TCP connection with [AF_INET]<IP>:<PORT> [nonblock]
openvpn[18161]: TCP connection established with [AF_INET]<IP>:<PORT>
openvpn[18161]: TCP_CLIENT link local: (not bound)
openvpn[18161]: TCP_CLIENT link remote: [AF_INET]<IP>:<PORT>
openvpn[18161]: Connection reset, restarting [0]
openvpn[18161]: SIGUSR1[soft,connection-reset] received, process restarting
openvpn[18161]: Restart pause, 5 second(s)

The delay will increase up to 300s. And the process may just keep on
going if the connection is only reset.

If the TCP connection breaks while OpenVPN is in connected state, and
hostname of the VPN server is used following is output by OpenVPN - and
still none of this is reported to ConnMan via management socket:

openvpn[5639]: RESOLVE: Cannot resolve host address: <addr> (Temporary failure in name resolution)
openvpn[5639]: RESOLVE: Cannot resolve host address: <addr> (Temporary failure in name resolution)
openvpn[5639]: Could not determine IPv4/IPv6 protocol
openvpn[5639]: SIGUSR1[soft,init_instance] received, process restarting
openvpn[5639]: Restart pause, 160 second(s)

After this network neturally ceases to work, DNS servers set cannot
respond because there is no TCP connection to the VPN server and the VPN
adapter set as default route will drop all packets because of that. For
this reason it is better to let OpenVPN connect only once and report the
error back to ConnMan. Therefore, disable connection retrying by setting
the retry count to 1 (no retry).
  • Loading branch information
LaakkonenJussi committed Jan 31, 2020
1 parent 270fff4 commit d201648
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions connman/vpn/plugins/openvpn.c
Expand Up @@ -506,6 +506,19 @@ static int run_connect(struct ov_private_data *data,
*/
connman_task_add_argument(task, "--ping-restart", "0");

/*
* Disable connetion retrying when OpenVPN is connected over TCP.
* With TCP OpenVPN attempts to handle reconnection silently without
* reporting the error back when establishing a connection or
* reconnecting as succesful one. The latter causes trouble if the
* retries are not limited to 1 (no retry) as the interface is up and
* connman regards it as the default route and network ceases to work,
* including DNS.
*/
option = vpn_provider_get_string(provider, "OpenVPN.Proto");
if (option && g_str_has_prefix(option, "tcp"))
connman_task_add_argument(task, "--connect-retry-max", "1");

err = connman_task_run(task, ov_died, data, NULL, NULL, NULL);
if (err < 0) {
data->cb = NULL;
Expand Down

0 comments on commit d201648

Please sign in to comment.