0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 04:02:15 +02:00
Commit Graph

50 Commits

Author SHA1 Message Date
Heiko Hund
b47c72b458
add tun_builder method to check DCO availability
While using GeNLImpl::available() for ovpn-dco works, it requires more
privileges than currently granted by SElinux for openvpn3-linux to work.

Instead of extending the privileges, add method tun_builder_dco_available()
to the TUN builder API, so that the check can be done context sensitive
by the client.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-09-29 17:34:13 +02:00
Heiko Hund
0d32d45ab7 process pushed remote-cache-timeout option
Take option value if pushed for the next round of remote address
caching.

Since the push replies are processed in Session, we need to extend the
transport slightly to process pushed options. There was no need so far,
since transport options are used before the session starts. The remote
cache timeout is currently the only exception to this rule.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-09-28 15:29:03 +02:00
Lev Stipakov
fd0655969d
Merge release of OpenVPN Core library 3.6.4 to master 2021-09-22 13:56:37 +02:00
Heiko Hund
dd104e8392 make it possible to specify dc algorithms
DCO only supports a limited set of ciphers, currently it is
discovered quite late if a unsupported algorithm is configured
(or pushed).

This introduces CryptoAlgs::allow_dc_algs() with which the
supported set of data channel algorithms can be specified.

The DCO code makes use of this, at the time a new_controller()
is created.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-06-18 15:09:35 +02:00
Antonio Quartulli
cbbe9d1768
ovpndcocli.hpp: implement SessionStats::DCOTransportSource
The DCO component now implements the SessionStats::DCOTransportSource interface.
This interface is already used by ovpncli.cpp to retrieve the peer stats
from DCO.

With this patch, also the OvpnDcoCli object can be used to retrieve the
peer stats from kernel space.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2021-06-09 17:23:03 +02:00
Antonio Quartulli
73664bb85a
ovpndcocli.hpp: properly parse and store peer statistics
After invoking the get_peer() API, let the DCOClient component
extract the statistics and store them locally.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2021-06-09 17:23:03 +02:00
Heiko Hund
51bd6d4201 use DCO opportunistically
If DCO support is compiled in, detect if it is available (i.e. Windows driver
or Linux kernel module is loaded) and then use it, if it is.

This changes the default configuration for DCO from off to on, so users of
the library need to set ClientAPI::Config::dco to false in case they do not
want to use dco for a connection.

The change is also reflected in the reference client "ovpncli". If DCO is
enabled in a build, it will detect and use it. The previously available
"ovpncliovpndco" and "ovpncliovpndcowin" clients have thus been removed.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-05-27 17:20:24 +02:00
Heiko Hund
ef45b80a97
support async connect in dco-win
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-04-14 22:44:51 +02:00
Heiko Hund
32a32cf04c
add support for dco-win to agent service
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-04-14 22:44:50 +02:00
Heiko Hund
9b03cddea9
add support for ovpn-dco-win TAP driver
Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-04-14 22:44:49 +02:00
Heiko Hund
63d38ba278 add results_type to class AsyncResolvable
Makes code more readable and implicitly declares the
correct internet protocol.

Signed-off-by: Heiko Hund <heiko@openvpn.net>
2021-03-18 18:10:30 +01:00
Antonio Quartulli
7b9db69e0f
ovpndcocli: prepend control packet with peer-id when using TunBuilder
The TunBuilder implementation needs to know which peer to send the
control packet to and for this reason the ovpndcocli component is now
prepending the data with 4 bytes representing the peer-id of the
destination.

Since this approach is incompatible with sending a const Buffer (as it
cannot be modified), send() has to allocate a temporary buffer for the
purpose.

While at it, make transport_send(Buffer) obsolete, as ovpndcocli
is not expected to handle data packets (sent as non-const).

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2021-02-24 09:10:51 +01:00
Antonio Quartulli
49e1e1748f
dco: restyle source files with clang-format --style=LLVM
We are trying to adhere to the LLVM style as dictated by clang-format.
For this reason reformat all files in the dco/ subfolder with:

clang-fromat --style=LLVM -i $filename

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2021-02-23 01:37:43 +01:00
Antonio Quartulli
e30146bfb6
dco: implement new ovpn-dco logic
With the recent changes in ovpn-dco, aimed at accommodating the new
multi-peer logic, userspace has to adapt as well in order to follow the
expected flow. In particular we require userspace to act as following:
1) create TCP/UDP transport socket towards peer/server;
2) perform initial handshare over TCP/UDP socket
3) when handshake is complete, add peer/server to ovpn-dco kernel module
   via CMD_NEW_PEER by passing peer address, port and socket fd;
4) handle further control channel communication over netlink.

To implement the logic above, the OvpnDcoClient has lost its
"Protowrapper" template and now it basically implemente the
TransportClient and TransportParent at the same time.
This way, it can instantiate a TCP/UDP TransportClient internally and
use it for point 1 and 2. This change greatly simplify the OvpnDcoClient
itself as several operations are directly handled by the TCP/UDP
TransportClient.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2021-02-23 01:37:21 +01:00
Lev Stipakov
7646cd3764 ovpn-dco: tunbuilder support for various protocols
This adds support for various transport protocols to tunbuilder
code branch of ovpn-dco support code, which is used by openvpn3-linux
client.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-11-18 18:02:00 +02:00
Lev Stipakov
4eda030060 ovpn-dco: handle TCP transport errors
When kernel detects TCP transport error, it notifies
userspace. Handle this error by doing reconnect.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-11-18 18:02:00 +02:00
Lev Stipakov
9437974b60 ovpn-dco: support for TCP transport
Make client code protocol-agnostic by encapsulating UDP/TCP
differences into ProtoBase/ProtoImpl/TCP/UDP classes.

Slightly change GeNL API to accomodate abovementioned changes.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-11-18 18:02:00 +02:00
Antonio Quartulli
6eb1680099
ovpn-dco: add support for configuring ChaCha20Poly1305 as data channel cipher
Extend the ovpn-dco module to allow the user to specify ChaCha20Poly1305
as data channel cipher.
Same as AES-GCM, it also belongs to the AEAD family and its nonce length
is 12 bytes.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2020-11-17 15:49:36 +01:00
Lev Stipakov
8ce41b76f8
ovpn-dco: remove cbc-hmac crypto
Since modern OpenVPN deployments negotiate AES-GCM,
there is no need to support AES-CBC / HMAC.

ovpn-dco doesn't support it, so clean up core as well.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-11-16 01:24:02 +01:00
Lev Stipakov
9574172560
ovpn-dco: change nonce_tail length to 8 bytes
AES-GCM nonce is 12 bytes. OpenVPN obtains it by concatenating 4 bytes
packet id and rest (nonce_tail) from key material generated during TLS
handshake.

By some reasons ovpn-dco required userspace to provide 12 bytes
nonce_tail and generated 16 bytes nonce, even though kernel crypto API
uses only 12 bytes. This has been fixed in ovpn-dco and therefore has to
be fixed in userspace.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-11-16 01:23:52 +01:00
Lev Stipakov
23d2203ff2 ovpn-dco: send START_VPN command first
ovpn-dco requires START_VPN command come first,
so subscribe for control channel packets after that.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-10-27 20:07:06 +02:00
Lev Stipakov
99f5285bcc kovpn: move away kovpn code
Since our plans have changed and we released
ovpn-dco instead of kovpn, move kovpn-specific code away.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-10-14 14:16:19 +03:00
Lev Stipakov
4fcb3624f7 ovpn-dco: linux client support
- add tunbuilder support to OvpnDcoClient

Linux client uses core library in non-privileged
process which cannot do modify routing, add/remove interfaces etc.

Those operartions are executed in separate privileged
process via tunbuilder API.

 - pass data between userspace/kernel via pipe

In Linux client, control channel packets are handled by
unprivileged process, which doesn't have direct access to netlink
socket to talk directly to kernel module. In order to enable
communication with kernel by unprivileged process, receiving side
of tunbuilder API, which itself is ran in privileged process,
creates socketpair and connects netlink socket with another socket,
which is passed back to unprivileged process. Unpriviled process
uses that socket to communicate with kernel module instead of GeNL
object.

 - remove remnants of kovpn support from tunbuilder and tunbuilder
support from kovpn tun/transport client.

Kovpn doesn't need tunbuilder support, so relevant code is removed.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 14:59:24 +00:00
Lev Stipakov
f24f1fd089 ovpn-dco: handle keepalive
Since userspace doesn't know anything about data
channel traffic, keepalive should be handled in kernel.

Disable keepalive in userspace and implement
OVPN_CMD_SET_PEER ovpn-dco command, which sets
keepalive settings in kernel.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 14:59:24 +00:00
Lev Stipakov
60e43763a4 ovpn-dco: init data channel keys
Implement OvpnDcoRekey, which parses key info
into format consumed by ovpn-dco.

Use KoRekey abstractions to hook into protocol layer
and get notified about rekeying events.

Pass new key to kernel or swap keys when commanded by
protocol layer.

Implement ovpn-dco netlink commands:

 - OVPN_CMD_NEW_KEY
 - OVPN_CMD_DEL_KEY
 - OVPN_CMD_SWAP_KEYS

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 14:59:24 +00:00
Lev Stipakov
9a15079d25 kocrypto.hpp: factor out kovpn-specific code
In preparation for ovpn-dco support, move kovpn-specific code
out of KoRekey::Key into own Korekey::KovpnKey class.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 14:59:24 +00:00
Lev Stipakov
275e422501 ovpn-dco: configure network properties
Upon connecting, set network device IP address,
configure routes etc.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 14:59:24 +00:00
Lev Stipakov
8593c41540 ovpn-dco: basic communication with kernel module
Add dependency to libnl-genl, which is C library
for generic netlink communication.

Implement C++ wrapper for libnl-genl, inspired by
ovpn-cli - a test client for ovpn-dco kernel module.

Implement ovpn-dco netlink commands:

  - OVPN_CMD_START_VPN - pass transport socket,
protocol (UDP) and mode (client).

  - OVPN_CMD_NEW_PEER - pass local and remote
endpoint info.

  - OVPN_CMD_PACKET - move (control channel) packets
between userspace and kernel.

  - OVPN_CMD_DEL_PEER - sent by kernel when peer is deleted
due to keepalive timeout (causes reconnect) or any other
reason (considered as fatal).

This change allows to perform openvpn handshake and
establish connection which doesn't work, since data channel
keys are not passed to kernel yet.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 14:59:24 +00:00
Lev Stipakov
3761f2ff89 ovpn-dco: initial support
Add tun/transport client skeleton for ovpn-dco,
which doesn't do any work except creating/removing
ovpn-dco device.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 10:53:27 +00:00
Lev Stipakov
e419e07c7f dcocli.cpp: add missing socket_protect call
As other transport clients, call socket_protect()
before establishing connection.

This gives ability to create bypass route.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 10:53:27 +00:00
Lev Stipakov
5bc16a71ef dcocli.hpp: refactor dco transport client
In preparation of ovpn-dco support, split dco transport
client into two parts:

 - generic dco support in dcocli.hpp
 - kovpn-specific code in kovpncli.hpp

Add build directory (used by VS Code) to .gitignore

Use #pragma once instead of #ifndef/#define/#endif

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-08-26 10:53:27 +00:00
James Yonan
0f2ef39c25 Refactored RPS/XPS configuration into its own class Configure_RPS_XPS
Signed-off-by: James Yonan <james@openvpn.net>
2020-06-09 15:44:57 -06:00
James Yonan
ab5cf6b308 dcocli: set new kovpn cpu_affinity var to OVPN_CPU_AFFINITY_UNDEF
Signed-off-by: James Yonan <james@openvpn.net>
2020-06-09 15:44:57 -06:00
Arne Schwabe
f8fe13e07c Add missing overrides
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-04-29 11:55:38 +02:00
David Sommerseth
3fbe0a2701
Update copyrights
Signed-off-by: David Sommerseth <davids@openvpn.net>
2020-03-18 19:37:32 +01:00
Arne Schwabe
984c601090
Fix multiple instances of comparison of signed with unsigned 2020-01-15 23:08:30 +01:00
David Sommerseth
22d0f2bf28 dcocli: Do not use KoTun with ENABLE_PG and USE_TUN_BUILDER
Signed-off-by: David Sommerseth <davids@openvpn.net>
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 17:11:50 +01:00
Arne Schwabe
d1fd4ef1f1 Minor code style clean up
- use explicit for non copy single argument constructor
- add override where applicable

Signed-off-by: Arne Schwabe <arne@openvpn.net>
Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-27 17:11:50 +01:00
Arne Schwabe
e7799e32ee Fix missing parameter introduce by add_bypass_routes commit
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 17:11:50 +01:00
Arne Schwabe
3817b8072e Refactor selecting tun methods into a common header file
This fixes DCO client only including iproute and using methods of
TUN_LINUX

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 17:11:50 +01:00
Arne Schwabe
6228165f37 Implement configuring DCO dev via tun builder
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 17:11:50 +01:00
Arne Schwabe
1e2d7b1c81 Implement opening /dev/net/ovpn via tun builder interface
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-27 17:11:50 +01:00
Antonio Quartulli
2c5435a000
dcocli: use compile time define for Tun methods instead of hardcoded iproute
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2019-08-29 16:38:53 +02:00
David Sommerseth
69d72ed64f
DCOTransport: Fix server side specific trunk handling
Commit 089aec00b pulled in a dependency for a very server specific
feature not normally needed in more basic implementations.  This
resulted in the code not being able to compile unless the advanced
implementation would be available.  This only happens when ENABLE_DCO is
enabled.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-08-07 17:10:23 +02:00
James Yonan
089aec00b1 DCOTransport: new routing code for trunk links
Also:

* removed IPCollisionDetectBase
* added ping-restart-override

Signed-off-by: James Yonan <james@openvpn.net>
2019-07-17 10:53:46 -06:00
Lev Stipakov
5771dfc0ee transport: remove ip_hole_punch API
That API was introduced in commit 5c00943
to implement persistence for macOS. That functionality
was refactored in 0609c76, but framework was left intact.

Since socket_protect() is called almost at the
same time as ip_hole_punch() and also receives
remote address, there is no need in this unused
API anymore.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-09 16:40:24 +03:00
Lev Stipakov
7150f72e09 tun: remove code duplications in Linux tun implementations
There are two ways how Linux tun can be manipulated -
by using iproute2 or netlink. Both implementations have
defined identical Setup class implementation.

This commit factors out Setup class from tun implementations
and templatizes it, which removes need in duplicated code.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-05-02 21:34:20 +03:00
Antonio Quartulli
8c87c76969
[UCONNECT-1027] use proper io_context when initializing AsyncResolve class 2019-02-07 18:23:12 +10:00
Antonio Quartulli
f33fe76658
[UCONNECT-1027] perform async DNS resolution in a detached thread
When ASIO performs an async DNS resolution, it relies on the
getaddrinfo() syscall in order to obtain a result.

This syscall is non-interruptible by design, which means that, in case
of sudden stop command received by the user, the core will not be able
to terminate all its threads until the getaddrinfo() has returned
(either by timeout or with a result).

If the the external core user is synchronously waiting for it to
terminate (i.e. like a UI), this behaviour will lead to the entire
client hanging.

To avoid this issue, this commit converts each asynchronous DNS
resolution to a synchrnous one performed in a detached thread.

This way, if the core wants to stop, it can do so without waiting for
the DNS thread to join. Otherwise, this change should not lead to any
functional difference.

Signed-off-by: Yuriy Barnovych <yuriy@openvpn.net>
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2019-02-07 09:07:00 +10:00
Lev Stipakov
643ada4395 [OVPN3-230] Add client-side dco code
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2018-05-31 16:27:50 +03:00