Skip to contentSkip to conversation

Introducing OpenVPN Data Channel Offload

RFC Superseded Antonio Quartulli 6 participants 27 messages Jul 19, 2022 – Sep 13, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Introducing OpenVPN Data Channel Offload

Hi all!

With this RFC I want to introduce OpenVPN Data Channel Offload (DCO), also known as ovpn-dco.

The OpenVPN community has since long been interested in moving the fast path to kernel space. Ovpn-dco finally helps achieving this goal.

Ovpn-dco is essentialy a device driver that allows creating a virtual network interface to handle the OpenVPN data channel. Any traffic entering the interface is encrypted, encapsulated and sent to the appropriate destination.

Despite technically possible, ovpn-dco requires OpenVPN in userspace to run along its side in order to be properly configured and maintained during its life cycle.

The ovpn-dco interface can be created/destroyed via RTNL and then configured via Netlink API.

Specifically OpenVPN in userspace will:
* create the ovpn-dco interface
* establish the connection with one or more peers
* perform TLS handshake and negotiate any protocol parameter
* configure the ovpn-dco interface with peer data (ip/port, keys, etc.)
* handle any subsequent control channel communication

I'd like to point out the control channel is fully handles in userspace. The idea is to keep the ovpn-dco kernel module as simple as possible and let userspace handle all the non-data (non-fast-path) features.

Please note that the userspace code requires to driver an ovpn-dco interface is currently under review and is still being merged to the OpenVPN master branch. This code will be released with OpenVPN 2.6 (later this year).

If you want to test ovpn-dco, for the time being you need to switch to the "dco" branch of the official repo hosted at
https://github.com/OpenVPN/openvpn (or at our GitLab mirror).

Note that OpenVPN3-Linux (https://github.com/OpenVPN/openvpn3-linux)
already supports ovpn-dco since a while, but this software is client only.

The ovpn-dco code that can be built as out-of-tree module is available here https://github.com/OpenVPN/ovpn-dco (we try to keep some compatibility with older kernels too).

In the past months I also created an OpenWRT feed in order to allow developers to test ovpn-dco, available at
https://github.com/OpenVPN/openvpn-dev-openwrt

For more technical details please refer to the actual patch commit message.

Please note that the patch touches also a few files outside of the ovpn-dco folder.
Specifically it adds a new macro named NLA_POLICY_MAX_LEN to net/netlink.h and also adds a new constant named UDP_ENCAP_OVPNINUDP to linux/udp.h.

With this RFC I would love to get some feedback from the netdev and kernel community in the attempt of reaching a status where ovpn-dco could be merged upstream.

Any comment, concern, statement will be appreciated.

Thanks a lot!

Best Regards,

Antonio Quartulli
OpenVPN Inc.

---

Antonio Quartulli (1):
net: introduce OpenVPN Data Channel Offload (ovpn-dco)

 MAINTAINERS                        |    8 +
 drivers/net/Kconfig                |   19 +
 drivers/net/Makefile               |    1 +
 drivers/net/ovpn-dco/Makefile      |   21 +
 drivers/net/ovpn-dco/addr.h        |   41 +
 drivers/net/ovpn-dco/bind.c        |   62 ++
 drivers/net/ovpn-dco/bind.h        |   67 ++
 drivers/net/ovpn-dco/crypto.c      |  154 ++++
 drivers/net/ovpn-dco/crypto.h      |  144 ++++
 drivers/net/ovpn-dco/crypto_aead.c |  369 +++++++++
 drivers/net/ovpn-dco/crypto_aead.h |   27 +
 drivers/net/ovpn-dco/main.c        |  281 +++++++
 drivers/net/ovpn-dco/main.h        |   39 +
 drivers/net/ovpn-dco/netlink.c     | 1132 ++++++++++++++++++++++++++++
 drivers/net/ovpn-dco/netlink.h     |   22 +
 drivers/net/ovpn-dco/ovpn.c        |  597 +++++++++++++++
 drivers/net/ovpn-dco/ovpn.h        |   43 ++
 drivers/net/ovpn-dco/ovpnstruct.h  |   59 ++
 drivers/net/ovpn-dco/peer.c        |  878 +++++++++++++++++++++
 drivers/net/ovpn-dco/peer.h        |  168 +++++
 drivers/net/ovpn-dco/pktid.c       |  127 ++++
 drivers/net/ovpn-dco/pktid.h       |  116 +++
 drivers/net/ovpn-dco/proto.h       |  101 +++
 drivers/net/ovpn-dco/rcu.h         |   21 +
 drivers/net/ovpn-dco/skb.h         |   54 ++
 drivers/net/ovpn-dco/sock.c        |  134 ++++
 drivers/net/ovpn-dco/sock.h        |   54 ++
 drivers/net/ovpn-dco/stats.c       |   20 +
 drivers/net/ovpn-dco/stats.h       |   67 ++
 drivers/net/ovpn-dco/tcp.c         |  324 ++++++++
 drivers/net/ovpn-dco/tcp.h         |   38 +
 drivers/net/ovpn-dco/udp.c         |  338 +++++++++
 drivers/net/ovpn-dco/udp.h         |   25 +
 include/net/netlink.h              |    1 +
 include/uapi/linux/ovpn_dco.h      |  265 +++++++
 include/uapi/linux/udp.h           |    1 +
 36 files changed, 5818 insertions(+)
 create mode 100644 drivers/net/ovpn-dco/Makefile
 create mode 100644 drivers/net/ovpn-dco/addr.h
 create mode 100644 drivers/net/ovpn-dco/bind.c
 create mode 100644 drivers/net/ovpn-dco/bind.h
 create mode 100644 drivers/net/ovpn-dco/crypto.c
 create mode 100644 drivers/net/ovpn-dco/crypto.h
 create mode 100644 drivers/net/ovpn-dco/crypto_aead.c
 create mode 100644 drivers/net/ovpn-dco/crypto_aead.h
 create mode 100644 drivers/net/ovpn-dco/main.c
 create mode 100644 drivers/net/ovpn-dco/main.h
 create mode 100644 drivers/net/ovpn-dco/netlink.c
 create mode 100644 drivers/net/ovpn-dco/netlink.h
 create mode 100644 drivers/net/ovpn-dco/ovpn.c
 create mode 100644 drivers/net/ovpn-dco/ovpn.h
 create mode 100644 drivers/net/ovpn-dco/ovpnstruct.h
 create mode 100644 drivers/net/ovpn-dco/peer.c
 create mode 100644 drivers/net/ovpn-dco/peer.h
 create mode 100644 drivers/net/ovpn-dco/pktid.c
 create mode 100644 drivers/net/ovpn-dco/pktid.h
 create mode 100644 drivers/net/ovpn-dco/proto.h
 create mode 100644 drivers/net/ovpn-dco/rcu.h
 create mode 100644 drivers/net/ovpn-dco/skb.h
 create mode 100644 drivers/net/ovpn-dco/sock.c
 create mode 100644 drivers/net/ovpn-dco/sock.h
 create mode 100644 drivers/net/ovpn-dco/stats.c
 create mode 100644 drivers/net/ovpn-dco/stats.h
 create mode 100644 drivers/net/ovpn-dco/tcp.c
 create mode 100644 drivers/net/ovpn-dco/tcp.h
 create mode 100644 drivers/net/ovpn-dco/udp.c
 create mode 100644 drivers/net/ovpn-dco/udp.h
 create mode 100644 include/uapi/linux/ovpn_dco.h
Signature · 1 line
2.35.1
#1 lore raw

RFC 1/1 net: introduce OpenVPN Data Channel Offload (ovpn-dco)

OpenVPN is a userspace software existing since around 2005 that allows users to create secure tunnels.

So far OpenVPN has implemented all operations in userspace, which implies several back and forth between kernel and user land in order to process packets (encapsulate/decapsulate, encrypt/decrypt, rerouting..).

With ovpn-dco, we intend to move the fast path (data channel) entirely in kernel space and thus improve user measured throughput over the tunnel.

ovpn-dco is implemented as a simple virtual network device driver, that can be manipulated by means of the standard RTNL APIs. A device of kind 'ovpn-dco' allows only IPv4/6 traffic and can be of type:
* P2P (peer-to-peer): any packet sent over the interface will be encapsulated and transmitted to the other side (typical OpenVPN client behaviour);
* P2MP (point-to-multipoint): packets sent over the interface are transmitted to peers based on existing routes (typical OpenVPN server behaviour).

After the interface has been created, OpenVPN in userspace can configure it using a new Netlink API. Specifically it is possible to manage peers, configure per-peer keys and exchange packets with userspace.

The OpenVPN control channel is multiplexed over the same transport socket by means of OP codes. Anything that is not DATA_V2 (OpenVPN OP code for data traffic) is sent to userspace and handled there. This way the ovpn-dco codebase is kept as compact as possible while focusing on handling data traffic only.

Any OpenVPN control feature (like cipher negotiation, TLS handshake, rekeying, etc.) is still fully handled by the userspace process.

When userspace establishes a new connection with a peer, it first performs the handshake and then passes the socket to ovpn-dco, which takes ownership. From this moment on ovpn-dco will handle data traffic for the new peer. When control packets are received on the link, they are forwarded to userspace via Netlink.

(this approach is somewhat inspired by hostapd+mac80211)

Some events (like peer deletion) are sent to a Netlink multicast group.

Although it wasn't easy to convince the community, ovpn-dco implements only a limited number of the data-channel features supported by the userspace program.

Each feature that made it to ovpn-dco was attentively vetted to avoid carrying too much legacy along with us (and to give a clear cut to old and probalby-not-so-useful features).

Notably, only encryption using AEAD ciphers (specifically ChaCha20Poly1305 and AES-GCM) was implemented. Supporting any other cipher out there was not deemed useful.

As explained above, in case of P2MP mode, OpenVPN will use the main system routing table to decide which packet goes to which peer. This implies that no routing table was re-implemented in ovpn-dco.

This kernel module can be enabled by selecting the CONFIG_OVPN_DCO entry in the networking drivers section.

---
 MAINTAINERS                        |    8 +
 drivers/net/Kconfig                |   19 +
 drivers/net/Makefile               |    1 +
 drivers/net/ovpn-dco/Makefile      |   21 +
 drivers/net/ovpn-dco/addr.h        |   41 +
 drivers/net/ovpn-dco/bind.c        |   62 ++
 drivers/net/ovpn-dco/bind.h        |   67 ++
 drivers/net/ovpn-dco/crypto.c      |  154 ++++
 drivers/net/ovpn-dco/crypto.h      |  144 ++++
 drivers/net/ovpn-dco/crypto_aead.c |  369 +++++++++
 drivers/net/ovpn-dco/crypto_aead.h |   27 +
 drivers/net/ovpn-dco/main.c        |  281 +++++++
 drivers/net/ovpn-dco/main.h        |   39 +
 drivers/net/ovpn-dco/netlink.c     | 1132 ++++++++++++++++++++++++++++
 drivers/net/ovpn-dco/netlink.h     |   22 +
 drivers/net/ovpn-dco/ovpn.c        |  597 +++++++++++++++
 drivers/net/ovpn-dco/ovpn.h        |   43 ++
 drivers/net/ovpn-dco/ovpnstruct.h  |   59 ++
 drivers/net/ovpn-dco/peer.c        |  878 +++++++++++++++++++++
 drivers/net/ovpn-dco/peer.h        |  168 +++++
 drivers/net/ovpn-dco/pktid.c       |  127 ++++
 drivers/net/ovpn-dco/pktid.h       |  116 +++
 drivers/net/ovpn-dco/proto.h       |  101 +++
 drivers/net/ovpn-dco/rcu.h         |   21 +
 drivers/net/ovpn-dco/skb.h         |   54 ++
 drivers/net/ovpn-dco/sock.c        |  134 ++++
 drivers/net/ovpn-dco/sock.h        |   54 ++
 drivers/net/ovpn-dco/stats.c       |   20 +
 drivers/net/ovpn-dco/stats.h       |   67 ++
 drivers/net/ovpn-dco/tcp.c         |  324 ++++++++
 drivers/net/ovpn-dco/tcp.h         |   38 +
 drivers/net/ovpn-dco/udp.c         |  338 +++++++++
 drivers/net/ovpn-dco/udp.h         |   25 +
 include/net/netlink.h              |    1 +
 include/uapi/linux/ovpn_dco.h      |  265 +++++++
 include/uapi/linux/udp.h           |    1 +
 36 files changed, 5818 insertions(+)
 create mode 100644 drivers/net/ovpn-dco/Makefile
 create mode 100644 drivers/net/ovpn-dco/addr.h
 create mode 100644 drivers/net/ovpn-dco/bind.c
 create mode 100644 drivers/net/ovpn-dco/bind.h
 create mode 100644 drivers/net/ovpn-dco/crypto.c
 create mode 100644 drivers/net/ovpn-dco/crypto.h
 create mode 100644 drivers/net/ovpn-dco/crypto_aead.c
 create mode 100644 drivers/net/ovpn-dco/crypto_aead.h
 create mode 100644 drivers/net/ovpn-dco/main.c
 create mode 100644 drivers/net/ovpn-dco/main.h
 create mode 100644 drivers/net/ovpn-dco/netlink.c
 create mode 100644 drivers/net/ovpn-dco/netlink.h
 create mode 100644 drivers/net/ovpn-dco/ovpn.c
 create mode 100644 drivers/net/ovpn-dco/ovpn.h
 create mode 100644 drivers/net/ovpn-dco/ovpnstruct.h
 create mode 100644 drivers/net/ovpn-dco/peer.c
 create mode 100644 drivers/net/ovpn-dco/peer.h
 create mode 100644 drivers/net/ovpn-dco/pktid.c
 create mode 100644 drivers/net/ovpn-dco/pktid.h
 create mode 100644 drivers/net/ovpn-dco/proto.h
 create mode 100644 drivers/net/ovpn-dco/rcu.h
 create mode 100644 drivers/net/ovpn-dco/skb.h
 create mode 100644 drivers/net/ovpn-dco/sock.c
 create mode 100644 drivers/net/ovpn-dco/sock.h
 create mode 100644 drivers/net/ovpn-dco/stats.c
 create mode 100644 drivers/net/ovpn-dco/stats.h
 create mode 100644 drivers/net/ovpn-dco/tcp.c
 create mode 100644 drivers/net/ovpn-dco/tcp.h
 create mode 100644 drivers/net/ovpn-dco/udp.c
 create mode 100644 drivers/net/ovpn-dco/udp.h
 create mode 100644 include/uapi/linux/ovpn_dco.h
MAINTAINERS +8 -0
index 66738c8330db..1120a44f694e 100644
@@ -15104,6 +15104,14 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs.git
 F:	Documentation/filesystems/overlayfs.rst
 F:	fs/overlayfs/
 
+OVPN-DCO NETWORK DRIVER
+M:	Antonio Quartulli <[email protected]>
+L:	[email protected] (moderated for non-subscribers)
+L:	[email protected]
+S:	Maintained
+F:	drivers/net/ovpn-dco/
+F:	include/uapi/linux/ovpn_dco.h
+
 P54 WIRELESS DRIVER
 M:	Christian Lamparter <[email protected]>
 L:	[email protected]
drivers/net/Kconfig +19 -0
index 94c889802566..349866bd4448 100644
@@ -116,6 +116,25 @@ config WIREGUARD_DEBUG
 
 	  Say N here unless you know what you're doing.
 
+config OVPN_DCO
+	tristate "OpenVPN data channel offload"
+	depends on NET && INET
+	select NET_UDP_TUNNEL
+	select DST_CACHE
+	select CRYPTO
+	select CRYPTO_AES
+	select CRYPTO_GCM
+	select CRYPTO_CHACHA20POLY1305
+	help
+	  This module enhances the performance of an OpenVPN connection by
+	  allowing the user to offload the data channel processing to
+	  kernelspace.
+	  Connection handshake, parameters negotiation and other non-data
+	  related mechanisms are still performed in userspace.
+
+	  The OpenVPN userspace software at version 2.6 or higher is required
+	  to use this functionality.
+
 config EQUALIZER
 	tristate "EQL (serial line load balancing) support"
 	help
drivers/net/Makefile +1 -0
index 3f1192d3c52d..8ed151e8d233 100644
@@ -11,6 +11,7 @@ obj-$(CONFIG_IPVLAN) += ipvlan/
 obj-$(CONFIG_IPVTAP) += ipvlan/
 obj-$(CONFIG_DUMMY) += dummy.o
 obj-$(CONFIG_WIREGUARD) += wireguard/
+obj-$(CONFIG_OVPN_DCO) += ovpn-dco/
 obj-$(CONFIG_EQUALIZER) += eql.o
 obj-$(CONFIG_IFB) += ifb.o
 obj-$(CONFIG_MACSEC) += macsec.o
drivers/net/ovpn-dco/Makefile new file +21 -0
new file mode 100644
index 000000000000..7efefe8f13a9
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# ovpn-dco -- OpenVPN data channel offload
+#
+# Copyright (C) 2020-2022 OpenVPN, Inc.
+#
+# Author:	Antonio Quartulli <[email protected]>
+
+obj-$(CONFIG_OVPN_DCO) += ovpn-dco.o
+ovpn-dco-y += main.o
+ovpn-dco-y += bind.o
+ovpn-dco-y += crypto.o
+ovpn-dco-y += ovpn.o
+ovpn-dco-y += peer.o
+ovpn-dco-y += sock.o
+ovpn-dco-y += stats.o
+ovpn-dco-y += netlink.o
+ovpn-dco-y += crypto_aead.o
+ovpn-dco-y += pktid.o
+ovpn-dco-y += tcp.o
+ovpn-dco-y += udp.o
drivers/net/ovpn-dco/addr.h new file +41 -0

41 lines not on this page · raw message

drivers/net/ovpn-dco/bind.c new file +62 -0

62 lines not on this page · raw message

drivers/net/ovpn-dco/bind.h new file +67 -0

67 lines not on this page · raw message

drivers/net/ovpn-dco/crypto.c new file +154 -0

154 lines not on this page · raw message

drivers/net/ovpn-dco/crypto.h new file +144 -0

144 lines not on this page · raw message

drivers/net/ovpn-dco/crypto_aead.c new file +369 -0

369 lines not on this page · raw message

drivers/net/ovpn-dco/crypto_aead.h new file +27 -0
new file mode 100644
index 000000000000..1e3054e7d5a4
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*  OpenVPN data channel accelerator
+ *
+ *  Copyright (C) 2020-2022 OpenVPN, Inc.
+ *
+ *  Author:	James Yonan <[email protected]>
+ *		Antonio Quartulli <[email protected]>
+ */
+
+#ifndef _NET_OVPN_DCO_OVPNAEAD_H_
+#define _NET_OVPN_DCO_OVPNAEAD_H_
+
+#include "crypto.h"
+
+#include <asm/types.h>
+#include <linux/skbuff.h>
+
+struct crypto_aead *ovpn_aead_init(const char *title, const char *alg_name,
+				   const unsigned char *key, unsigned int keylen);
+
+int ovpn_aead_encrypt(struct ovpn_crypto_key_slot *ks, struct sk_buff *skb, u32 peer_id);
+int ovpn_aead_decrypt(struct ovpn_crypto_key_slot *ks, struct sk_buff *skb);
+
+struct ovpn_crypto_key_slot *ovpn_aead_crypto_key_slot_new(const struct ovpn_key_config *kc);
+void ovpn_aead_crypto_key_slot_destroy(struct ovpn_crypto_key_slot *ks);
+
+#endif /* _NET_OVPN_DCO_OVPNAEAD_H_ */
drivers/net/ovpn-dco/main.c new file +281 -0

281 lines not on this page · raw message

drivers/net/ovpn-dco/main.h new file +39 -0
new file mode 100644
index 000000000000..5407d403201e
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*  OpenVPN data channel accelerator
+ *
+ *  Copyright (C) 2019-2022 OpenVPN, Inc.
+ *
+ *  Author:	James Yonan <[email protected]>
+ *		Antonio Quartulli <[email protected]>
+ */
+
+#ifndef _NET_OVPN_DCO_MAIN_H_
+#define _NET_OVPN_DCO_MAIN_H_
+
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <linux/printk.h>
+#include <linux/udp.h>
+
+#ifndef OVPN_DCO_VERSION
+#define OVPN_DCO_VERSION "2.0.0"
+#endif
+
+/* Our UDP encapsulation types, must be unique
+ * (other values in include/uapi/linux/udp.h)
+ */
+#define UDP_ENCAP_OVPNINUDP 100  /* transport layer */
+
+struct net_device;
+bool ovpn_dev_is_valid(const struct net_device *dev);
+
+#define SKB_HEADER_LEN                                       \
+	(max(sizeof(struct iphdr), sizeof(struct ipv6hdr)) + \
+	 sizeof(struct udphdr) + NET_SKB_PAD)
+
+#define OVPN_HEAD_ROOM ALIGN(16 + SKB_HEADER_LEN, 4)
+#define OVPN_MAX_PADDING 16
+#define OVPN_QUEUE_LEN 1024
+#define OVPN_MAX_TUN_QUEUE_LEN 0x10000
+
+#endif /* _NET_OVPN_DCO_OVPN_DCO_H_ */
drivers/net/ovpn-dco/netlink.c new file +1132 -0

1,132 lines not on this page · raw message

drivers/net/ovpn-dco/netlink.h new file +22 -0
new file mode 100644
index 000000000000..843daf052c03
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*  OpenVPN data channel accelerator
+ *
+ *  Copyright (C) 2020-2022 OpenVPN, Inc.
+ *
+ *  Author:	Antonio Quartulli <[email protected]>
+ */
+
+#ifndef _NET_OVPN_DCO_NETLINK_H_
+#define _NET_OVPN_DCO_NETLINK_H_
+
+struct ovpn_struct;
+struct ovpn_peer;
+
+int ovpn_netlink_init(struct ovpn_struct *ovpn);
+int ovpn_netlink_register(void);
+void ovpn_netlink_unregister(void);
+int ovpn_netlink_send_packet(struct ovpn_struct *ovpn, const struct ovpn_peer *peer,
+			     const u8 *buf, size_t len);
+int ovpn_netlink_notify_del_peer(struct ovpn_peer *peer);
+
+#endif /* _NET_OVPN_DCO_NETLINK_H_ */
drivers/net/ovpn-dco/ovpn.c new file +597 -0

595 lines not on this page · raw message

drivers/net/ovpn-dco/ovpn.h new file +43 -0

43 lines not on this page · raw message

drivers/net/ovpn-dco/ovpnstruct.h new file +59 -0

59 lines not on this page · raw message

drivers/net/ovpn-dco/peer.c new file +878 -0

878 lines not on this page · raw message

drivers/net/ovpn-dco/peer.h new file +168 -0

168 lines not on this page · raw message

drivers/net/ovpn-dco/pktid.c new file +127 -0

127 lines not on this page · raw message

drivers/net/ovpn-dco/pktid.h new file +116 -0

116 lines not on this page · raw message

drivers/net/ovpn-dco/proto.h new file +101 -0

101 lines not on this page · raw message

drivers/net/ovpn-dco/rcu.h new file +21 -0
new file mode 100644
index 000000000000..02a50f49ba2e

Lines of this file are not shown. View the raw message.

drivers/net/ovpn-dco/skb.h new file +54 -0

54 lines not on this page · raw message

drivers/net/ovpn-dco/sock.c new file +134 -0

134 lines not on this page · raw message

drivers/net/ovpn-dco/sock.h new file +54 -0

54 lines not on this page · raw message

drivers/net/ovpn-dco/stats.c new file +20 -0
new file mode 100644
index 000000000000..ee000b2a2177

Lines of this file are not shown. View the raw message.

drivers/net/ovpn-dco/stats.h new file +67 -0

67 lines not on this page · raw message

drivers/net/ovpn-dco/tcp.c new file +324 -0

324 lines not on this page · raw message

drivers/net/ovpn-dco/tcp.h new file +38 -0
new file mode 100644
index 000000000000..d243a8e1c34e

Lines of this file are not shown. View the raw message.

drivers/net/ovpn-dco/udp.c new file +338 -0

338 lines not on this page · raw message

drivers/net/ovpn-dco/udp.h new file +25 -0
new file mode 100644
index 000000000000..be94fb74669b

Lines of this file are not shown. View the raw message.

include/net/netlink.h +1 -0
index 7a2a9d3144ba..335f44871529 100644

Lines of this file are not shown. View the raw message.

include/uapi/linux/ovpn_dco.h new file +265 -0

265 lines not on this page · raw message

include/uapi/linux/udp.h +1 -0
index 4828794efcf8..8008c762e6b8 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.35.1

Part of the diff is not shown here. View the raw message.

#2 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Quoted 16 lines
drivers/net/ovpn-dco/crypto.c new file +16 -0
+void ovpn_crypto_key_slot_delete(struct ovpn_crypto_state *cs,
+				 enum ovpn_key_slot slot)
+{
+	struct ovpn_crypto_key_slot *ks = NULL;
+
+	mutex_lock(&cs->mutex);
+	switch (slot) {
+	case OVPN_KEY_SLOT_PRIMARY:
+		ks = rcu_replace_pointer(cs->primary, NULL,
+					 lockdep_is_held(&cs->mutex));
+		break;
+	case OVPN_KEY_SLOT_SECONDARY:
+		ks = rcu_replace_pointer(cs->secondary, NULL,
+					 lockdep_is_held(&cs->mutex));
+		break;
+	default:

drivers/net/ovpn-dco/crypto.c line 128

Quoted 10 lines
drivers/net/ovpn-dco/crypto.c new file +10 -0
+		pr_warn("Invalid slot to release: %u\n", slot);
+		break;
+	}
+	mutex_unlock(&cs->mutex);
+
+	if (!ks) {
+		pr_debug("Key slot already released: %u\n", slot);
+		return;
+	}
+	pr_debug("deleting key slot %u, key_id=%u\n", slot, ks->key_id);

As a general comment throughout the code, pr_ functions are not liked. Since this is a network device, it would be better to use netdev_debug(), netdev_warn() etc, so indicating which device is outputting warnings or debug info.

Andrew

#3 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Quoted 4 lines · Andrew Lunn

As a general comment throughout the code, pr_ functions are not liked. Since this is a network device, it would be better to use netdev_debug(), netdev_warn() etc, so indicating which device is outputting warnings or debug info.

Thanks for the hint, Andrew!
I will convert the pr_* calls to netdev_*.

Regards,

Signature · 2 lines
Antonio Quartulli
OpenVPN Inc.
#4 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

In reply to Antonio Quartulli

drivers/net/ovpn-dco/main.c line 107

Quoted 6 lines
drivers/net/ovpn-dco/main.c new file +6 -0
+static void ovpn_get_drvinfo(struct net_device *dev,
+			     struct ethtool_drvinfo *info)
+{
+	strscpy(info->driver, DRV_NAME, sizeof(info->driver));
+	strscpy(info->version, DRV_VERSION, sizeof(info->version));
+	strscpy(info->bus_info, "ovpn", sizeof(info->bus_info));

version is generally considered useless information if it comes from the driver. You have no idea if this is version 42 in net-next, or some backported version in an enterprise kernel with lots of out of tree patches. The driver is not standalone, it runs inside the kernel. So in order to understand a bug report, you need to know what kernel it is. If you don't fill in version, the core will with the kernel version, which is much more useful.

Andrew

#5 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Hi,

Quoted 7 lines · Andrew Lunn

drivers/net/ovpn-dco/main.c line 107

Quoted 6 lines
drivers/net/ovpn-dco/main.c new file +6 -0
+static void ovpn_get_drvinfo(struct net_device *dev,
+			     struct ethtool_drvinfo *info)
+{
+	strscpy(info->driver, DRV_NAME, sizeof(info->driver));
+	strscpy(info->version, DRV_VERSION, sizeof(info->version));
+	strscpy(info->bus_info, "ovpn", sizeof(info->bus_info));
Quoted 7 lines

version is generally considered useless information if it comes from the driver. You have no idea if this is version 42 in net-next, or some backported version in an enterprise kernel with lots of out of tree patches. The driver is not standalone, it runs inside the kernel. So in order to understand a bug report, you need to know what kernel it is. If you don't fill in version, the core will with the kernel version, which is much more useful.

True.

However, I guess I will still fill MODULE_VERSION() with a custom string. This may also be useful when building the module out-of-tree.

Thanks for the hint!

Regards,

Signature · 2 lines
Antonio Quartulli
OpenVPN Inc.
#6 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Quoted 18 lines · Antonio Quartulli

Hi,

Quoted 7 lines · Andrew Lunn

drivers/net/ovpn-dco/main.c line 107

Quoted 6 lines
drivers/net/ovpn-dco/main.c new file +6 -0
+static void ovpn_get_drvinfo(struct net_device *dev,
+			     struct ethtool_drvinfo *info)
+{
+	strscpy(info->driver, DRV_NAME, sizeof(info->driver));
+	strscpy(info->version, DRV_VERSION, sizeof(info->version));
+	strscpy(info->bus_info, "ovpn", sizeof(info->bus_info));
Quoted 7 lines

version is generally considered useless information if it comes from the driver. You have no idea if this is version 42 in net-next, or some backported version in an enterprise kernel with lots of out of tree patches. The driver is not standalone, it runs inside the kernel. So in order to understand a bug report, you need to know what kernel it is. If you don't fill in version, the core will with the kernel version, which is much more useful.

Quoted 4 lines

True.

However, I guess I will still fill MODULE_VERSION() with a custom string. This may also be useful when building the module out-of-tree.

You could, but out of tree is even worse. You have even less idea what environment the driver is running in, so the version is even less meaningful. You need to ask be bug reported for even more information.

Also, using a mainline driver out of tree is not easy. The code will make use of the latest APIs, and internal APIs are not stable, making it hard to use in older kernels. So you end up with out of tree wrapper code for whatever version of out of tree Linux you decide to support. Take a look at

https://github.com/open-mesh-mirror/batman-adv

for an example of this.

Andrew

#7 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Hi Andrew,

Quoted 7 lines · Andrew Lunn

Also, using a mainline driver out of tree is not easy. The code will make use of the latest APIs, and internal APIs are not stable, making it hard to use in older kernels. So you end up with out of tree wrapper code for whatever version of out of tree Linux you decide to support. Take a look at

https://github.com/open-mesh-mirror/batman-adv

Yeah, this is exactly what we are already doing. We're just trying to keep is as simple as possible for now:

https://github.com/OpenVPN/ovpn-dco/blob/master/linux-compat.h

Thanks for the pointer anyway (I am already deeply inspired by batman-adv, as you may imagine ;-)),

Signature · 2 lines
Antonio Quartulli
OpenVPN Inc.
#8 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Quoted 11 lines · On Thu, 28 Jul 2022 15:16:10 +0200 Antonio Quartulli <[email protected]>…

Hi Andrew,

Quoted 7 lines · Andrew Lunn

Also, using a mainline driver out of tree is not easy. The code will make use of the latest APIs, and internal APIs are not stable, making it hard to use in older kernels. So you end up with out of tree wrapper code for whatever version of out of tree Linux you decide to support. Take a look at

https://github.com/open-mesh-mirror/batman-adv

Quoted 8 lines

Yeah, this is exactly what we are already doing. We're just trying to keep is as simple as possible for now:

https://github.com/OpenVPN/ovpn-dco/blob/master/linux-compat.h

Thanks for the pointer anyway (I am already deeply inspired by batman-adv, as you may imagine ;-)),

Kernel submissions for upstream must be standalone, and any infrastructure that is only used by an out of tree kernel driver will not be accepted.

The version you propose upstream must have no linux-compat wrappers. Sorry kernel developers don't care or want to be concerned about some out of tree project.

#9 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Hi Stephen,

Quoted 6 lines · Stephen Hemminger

Kernel submissions for upstream must be standalone, and any infrastructure that is only used by an out of tree kernel driver will not be accepted.

The version you propose upstream must have no linux-compat wrappers. Sorry kernel developers don't care or want to be concerned about some out of tree project.

There must have been some confusion - sorry about that.

The repository I linked in my previous email is this very same driver packaged as "out-of-tree" module (i.e. for people running a kernel that does not yet ship ovpn-dco) and contains some compat wrapper.

The driver I have submitted to the list is 100% standalone and does not contain any compat code.

The only extra component required to do something useful with this driver is the OpenVPN software in userspace.

I hope this clarifies.

Regards,

Signature · 2 lines
Antonio Quartulli
OpenVPN Inc.
#10 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Quoted 7 lines · On Wed, 3 Aug 2022 17:48:45 +0200 Antonio Quartulli <[email protected]> wrote:

There must have been some confusion - sorry about that.

The repository I linked in my previous email is this very same driver packaged as "out-of-tree" module (i.e. for people running a kernel that does not yet ship ovpn-dco) and contains some compat wrapper.

Quoted 6 lines

The driver I have submitted to the list is 100% standalone and does not contain any compat code.

The only extra component required to do something useful with this driver is the OpenVPN software in userspace.

Good to here thanks.
I wonder if there is any chance of having multiple VPN projects using same infrastructure. There seems to be some parallel effort in L2TP, OpenVPN, etc.

#11 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Quoted 14 lines · Stephen Hemminger
Quoted 11 lines · On Wed, 3 Aug 2022 17:48:45 +0200 Antonio Quartulli <[email protected]> wrote:

There must have been some confusion - sorry about that.

The repository I linked in my previous email is this very same driver packaged as "out-of-tree" module (i.e. for people running a kernel that does not yet ship ovpn-dco) and contains some compat wrapper.

The driver I have submitted to the list is 100% standalone and does not contain any compat code.

Quoted 8 lines
Quoted 2 lines

The only extra component required to do something useful with this driver is the OpenVPN software in userspace.

Good to here thanks.
I wonder if there is any chance of having multiple VPN projects using same infrastructure. There seems to be some parallel effort in L2TP, OpenVPN, etc.

Thanks for rising this point, Stephen.

I also believe it would be nice to re-use as much infrastructure as possible (I always strive to reduce code duplication, while keeping core building blocks simple and re-usable), however, it seems that the various implementations currently do not share much logic.

What could be shared is already shared (i.e. crypto, napi, gso, netdev, etc). Handling the data traffic is something that can hardly be shared due to different packet manipulation (i.e. encapsulation).

One area that could still be worth exploring might be the queuing mechanism that handles packet reception+decryption and encryption+transmission. If we factor out the protocol specific bits, we might be able to make the high level logic common.

However, so far all my attempts did not lead to anything that could be implemented in a reasonable manner.

Still, I believe this is something we could work on in the medium/long-term.

Regards,

Signature · 2 lines
Antonio Quartulli
OpenVPN Inc.
maintainer
#12 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

In reply to Antonio Quartulli
Quoted 2 lines · On Thu, 28 Jul 2022 09:41:11 +0200 Antonio Quartulli wrote:

However, I guess I will still fill MODULE_VERSION() with a custom string. This may also be useful when building the module out-of-tree.

Please use the kernel versions for versioning the out of tree code. Whenever a new release is cut upstream you bump the number appropriately in oot, and adjust whatever compat code needs adjusting.

#13 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Quoted 7 lines · Jakub Kicinski
Quoted 2 lines · On Thu, 28 Jul 2022 09:41:11 +0200 Antonio Quartulli wrote:

However, I guess I will still fill MODULE_VERSION() with a custom string. This may also be useful when building the module out-of-tree.

Please use the kernel versions for versioning the out of tree code. Whenever a new release is cut upstream you bump the number appropriately in oot, and adjust whatever compat code needs adjusting.

Thanks for the hint about the versioning!
Will definitely use the kernel version once we are hooked.

Signature · 2 lines
Antonio Quartulli
OpenVPN Inc.
#14 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

In reply to Antonio Quartulli

drivers/net/ovpn-dco/main.c line 76

Quoted 5 lines
drivers/net/ovpn-dco/main.c new file +5 -0
+static int ovpn_net_change_mtu(struct net_device *dev, int new_mtu)
+{
+	if (new_mtu < IPV4_MIN_MTU ||
+	    new_mtu + dev->hard_header_len > IP_MAX_MTU)
+		return -EINVAL;

If you set dev->min_mtu and dev->max_mtu, the core will validate this for you, see dev_validate_mtu().

drivers/net/ovpn-dco/main.c line 91

Quoted 5 lines
drivers/net/ovpn-dco/main.c new file +5 -0
+static int ovpn_get_link_ksettings(struct net_device *dev,
+				   struct ethtool_link_ksettings *cmd)
+{
+	ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, 0);
+	ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, 0);

These two should not be needed. Look at tun, veth etc, they don't set them.

Andrew

#15 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Hi,

Quoted 8 lines · Andrew Lunn

drivers/net/ovpn-dco/main.c line 76

Quoted 5 lines
drivers/net/ovpn-dco/main.c new file +5 -0
+static int ovpn_net_change_mtu(struct net_device *dev, int new_mtu)
+{
+	if (new_mtu < IPV4_MIN_MTU ||
+	    new_mtu + dev->hard_header_len > IP_MAX_MTU)
+		return -EINVAL;

If you set dev->min_mtu and dev->max_mtu, the core will validate this for you, see dev_validate_mtu().

Yeah, thanks for the pointer.

Quoted 9 lines

drivers/net/ovpn-dco/main.c line 91

Quoted 6 lines
drivers/net/ovpn-dco/main.c new file +5 -0
+static int ovpn_get_link_ksettings(struct net_device *dev,
+				   struct ethtool_link_ksettings *cmd)
+{
+	ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, 0);
+	ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, 0);

These two should not be needed. Look at tun, veth etc, they don't set them.

I found this in tun.c:

3512 ethtool_link_ksettings_zero_link_mode(cmd, supported);
3513 ethtool_link_ksettings_zero_link_mode(cmd, advertising);

Which seems a more appropriate version of my code, no?

Regards,

Signature · 2 lines
Antonio Quartulli
OpenVPN Inc.
#16 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Quoted 24 lines · Antonio Quartulli

Hi,

Quoted 8 lines · Andrew Lunn

drivers/net/ovpn-dco/main.c line 76

Quoted 5 lines
drivers/net/ovpn-dco/main.c new file +5 -0
+static int ovpn_net_change_mtu(struct net_device *dev, int new_mtu)
+{
+	if (new_mtu < IPV4_MIN_MTU ||
+	    new_mtu + dev->hard_header_len > IP_MAX_MTU)
+		return -EINVAL;

If you set dev->min_mtu and dev->max_mtu, the core will validate this for you, see dev_validate_mtu().

Yeah, thanks for the pointer.

Quoted 9 lines

drivers/net/ovpn-dco/main.c line 91

Quoted 6 lines
drivers/net/ovpn-dco/main.c new file +5 -0
+static int ovpn_get_link_ksettings(struct net_device *dev,
+				   struct ethtool_link_ksettings *cmd)
+{
+	ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, 0);
+	ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, 0);

These two should not be needed. Look at tun, veth etc, they don't set them.

Quoted 6 lines

I found this in tun.c:

3512 ethtool_link_ksettings_zero_link_mode(cmd, supported);
3513 ethtool_link_ksettings_zero_link_mode(cmd, advertising);

Which seems a more appropriate version of my code, no?

I would trace is backwards. Where is cmd coming from? In order to avoid unintentional information leaks, the core should be clearing any memory which gets passed to a driver which might optionally be filled in and then returned to user space. So take a look in net/ethtool, and see if there is a memset() or a kzalloc() etc. If it is already been zero'ed, you don't need this.

Andrew

#17 lore raw

RFC v2 1/1 net: introduce OpenVPN Data Channel Offload (ovpn-dco)

In reply to Antonio Quartulli

OpenVPN is a userspace software existing since around 2005 that allows users to create secure tunnels.

So far OpenVPN has implemented all operations in userspace, which implies several back and forth between kernel and user land in order to process packets (encapsulate/decapsulate, encrypt/decrypt, rerouting..).

With ovpn-dco, we intend to move the fast path (data channel) entirely in kernel space and thus improve user measured throughput over the tunnel.

ovpn-dco is implemented as a simple virtual network device driver, that can be manipulated by means of the standard RTNL APIs. A device of kind 'ovpn-dco' allows only IPv4/6 traffic and can be of type:
* P2P (peer-to-peer): any packet sent over the interface will be encapsulated and transmitted to the other side (typical OpenVPN client behaviour);
* P2MP (point-to-multipoint): packets sent over the interface are transmitted to peers based on existing routes (typical OpenVPN server behaviour).

After the interface has been created, OpenVPN in userspace can configure it using a new Netlink API. Specifically it is possible to manage peers, configure per-peer keys and exchange packets with userspace.

The OpenVPN control channel is multiplexed over the same transport socket by means of OP codes. Anything that is not DATA_V2 (OpenVPN OP code for data traffic) is sent to userspace and handled there. This way the ovpn-dco codebase is kept as compact as possible while focusing on handling data traffic only.

Any OpenVPN control feature (like cipher negotiation, TLS handshake, rekeying, etc.) is still fully handled by the userspace process.

When userspace establishes a new connection with a peer, it first performs the handshake and then passes the socket to ovpn-dco, which takes ownership. From this moment on ovpn-dco will handle data traffic for the new peer. When control packets are received on the link, they are forwarded to userspace via Netlink.

(this approach is somewhat inspired by hostapd+mac80211)

Some events (like peer deletion) are sent to a Netlink multicast group.

Although it wasn't easy to convince the community, ovpn-dco implements only a limited number of the data-channel features supported by the userspace program.

Each feature that made it to ovpn-dco was attentively vetted to avoid carrying too much legacy along with us (and to give a clear cut to old and probalby-not-so-useful features).

Notably, only encryption using AEAD ciphers (specifically ChaCha20Poly1305 and AES-GCM) was implemented. Supporting any other cipher out there was not deemed useful.

As explained above, in case of P2MP mode, OpenVPN will use the main system routing table to decide which packet goes to which peer. This implies that no routing table was re-implemented in ovpn-dco.

This kernel module can be enabled by selecting the CONFIG_OVPN_DCO entry in the networking drivers section.

---

Changes from v1:
* use net/netdev print helpers when possible
* properly set min/max_mtu
* get rid of ndo_change_mtu
* don't set version in ethtool output
* ensure can be compiled also when no IPv6 support exists

---
 MAINTAINERS                        |    8 +
 drivers/net/Kconfig                |   19 +
 drivers/net/Makefile               |    1 +
 drivers/net/ovpn-dco/Makefile      |   21 +
 drivers/net/ovpn-dco/addr.h        |   41 +
 drivers/net/ovpn-dco/bind.c        |   62 ++
 drivers/net/ovpn-dco/bind.h        |   67 ++
 drivers/net/ovpn-dco/crypto.c      |  154 ++++
 drivers/net/ovpn-dco/crypto.h      |  144 ++++
 drivers/net/ovpn-dco/crypto_aead.c |  367 +++++++++
 drivers/net/ovpn-dco/crypto_aead.h |   27 +
 drivers/net/ovpn-dco/main.c        |  271 +++++++
 drivers/net/ovpn-dco/main.h        |   32 +
 drivers/net/ovpn-dco/netlink.c     | 1143 ++++++++++++++++++++++++++++
 drivers/net/ovpn-dco/netlink.h     |   22 +
 drivers/net/ovpn-dco/ovpn.c        |  600 +++++++++++++++
 drivers/net/ovpn-dco/ovpn.h        |   43 ++
 drivers/net/ovpn-dco/ovpnstruct.h  |   59 ++
 drivers/net/ovpn-dco/peer.c        |  906 ++++++++++++++++++++++
 drivers/net/ovpn-dco/peer.h        |  168 ++++
 drivers/net/ovpn-dco/pktid.c       |  127 ++++
 drivers/net/ovpn-dco/pktid.h       |  116 +++
 drivers/net/ovpn-dco/proto.h       |  101 +++
 drivers/net/ovpn-dco/rcu.h         |   21 +
 drivers/net/ovpn-dco/skb.h         |   54 ++
 drivers/net/ovpn-dco/sock.c        |  134 ++++
 drivers/net/ovpn-dco/sock.h        |   54 ++
 drivers/net/ovpn-dco/stats.c       |   20 +
 drivers/net/ovpn-dco/stats.h       |   67 ++
 drivers/net/ovpn-dco/tcp.c         |  326 ++++++++
 drivers/net/ovpn-dco/tcp.h         |   38 +
 drivers/net/ovpn-dco/udp.c         |  343 +++++++++
 drivers/net/ovpn-dco/udp.h         |   25 +
 include/net/netlink.h              |    1 +
 include/uapi/linux/ovpn_dco.h      |  265 +++++++
 include/uapi/linux/udp.h           |    1 +
 36 files changed, 5848 insertions(+)
 create mode 100644 drivers/net/ovpn-dco/Makefile
 create mode 100644 drivers/net/ovpn-dco/addr.h
 create mode 100644 drivers/net/ovpn-dco/bind.c
 create mode 100644 drivers/net/ovpn-dco/bind.h
 create mode 100644 drivers/net/ovpn-dco/crypto.c
 create mode 100644 drivers/net/ovpn-dco/crypto.h
 create mode 100644 drivers/net/ovpn-dco/crypto_aead.c
 create mode 100644 drivers/net/ovpn-dco/crypto_aead.h
 create mode 100644 drivers/net/ovpn-dco/main.c
 create mode 100644 drivers/net/ovpn-dco/main.h
 create mode 100644 drivers/net/ovpn-dco/netlink.c
 create mode 100644 drivers/net/ovpn-dco/netlink.h
 create mode 100644 drivers/net/ovpn-dco/ovpn.c
 create mode 100644 drivers/net/ovpn-dco/ovpn.h
 create mode 100644 drivers/net/ovpn-dco/ovpnstruct.h
 create mode 100644 drivers/net/ovpn-dco/peer.c
 create mode 100644 drivers/net/ovpn-dco/peer.h
 create mode 100644 drivers/net/ovpn-dco/pktid.c
 create mode 100644 drivers/net/ovpn-dco/pktid.h
 create mode 100644 drivers/net/ovpn-dco/proto.h
 create mode 100644 drivers/net/ovpn-dco/rcu.h
 create mode 100644 drivers/net/ovpn-dco/skb.h
 create mode 100644 drivers/net/ovpn-dco/sock.c
 create mode 100644 drivers/net/ovpn-dco/sock.h
 create mode 100644 drivers/net/ovpn-dco/stats.c
 create mode 100644 drivers/net/ovpn-dco/stats.h
 create mode 100644 drivers/net/ovpn-dco/tcp.c
 create mode 100644 drivers/net/ovpn-dco/tcp.h
 create mode 100644 drivers/net/ovpn-dco/udp.c
 create mode 100644 drivers/net/ovpn-dco/udp.h
 create mode 100644 include/uapi/linux/ovpn_dco.h
MAINTAINERS +8 -0
index 1920d82db83e..7cb16007dd5c 100644
@@ -15103,6 +15103,14 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs.git
 F:	Documentation/filesystems/overlayfs.rst
 F:	fs/overlayfs/
 
+OVPN-DCO NETWORK DRIVER
+M:	Antonio Quartulli <[email protected]>
+L:	[email protected] (moderated for non-subscribers)
+L:	[email protected]
+S:	Maintained
+F:	drivers/net/ovpn-dco/
+F:	include/uapi/linux/ovpn_dco.h
+
 P54 WIRELESS DRIVER
 M:	Christian Lamparter <[email protected]>
 L:	[email protected]
drivers/net/Kconfig +19 -0
index 94c889802566..349866bd4448 100644
@@ -116,6 +116,25 @@ config WIREGUARD_DEBUG
 
 	  Say N here unless you know what you're doing.
 
+config OVPN_DCO
+	tristate "OpenVPN data channel offload"
+	depends on NET && INET
+	select NET_UDP_TUNNEL
+	select DST_CACHE
+	select CRYPTO
+	select CRYPTO_AES
+	select CRYPTO_GCM
+	select CRYPTO_CHACHA20POLY1305
+	help
+	  This module enhances the performance of an OpenVPN connection by
+	  allowing the user to offload the data channel processing to
+	  kernelspace.
+	  Connection handshake, parameters negotiation and other non-data
+	  related mechanisms are still performed in userspace.
+
+	  The OpenVPN userspace software at version 2.6 or higher is required
+	  to use this functionality.
+
 config EQUALIZER
 	tristate "EQL (serial line load balancing) support"
 	help
drivers/net/Makefile +1 -0
index 3f1192d3c52d..8ed151e8d233 100644
@@ -11,6 +11,7 @@ obj-$(CONFIG_IPVLAN) += ipvlan/
 obj-$(CONFIG_IPVTAP) += ipvlan/
 obj-$(CONFIG_DUMMY) += dummy.o
 obj-$(CONFIG_WIREGUARD) += wireguard/
+obj-$(CONFIG_OVPN_DCO) += ovpn-dco/
 obj-$(CONFIG_EQUALIZER) += eql.o
 obj-$(CONFIG_IFB) += ifb.o
 obj-$(CONFIG_MACSEC) += macsec.o
drivers/net/ovpn-dco/Makefile new file +21 -0
new file mode 100644
index 000000000000..7efefe8f13a9
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# ovpn-dco -- OpenVPN data channel offload
+#
+# Copyright (C) 2020-2022 OpenVPN, Inc.
+#
+# Author:	Antonio Quartulli <[email protected]>
+
+obj-$(CONFIG_OVPN_DCO) += ovpn-dco.o
+ovpn-dco-y += main.o
+ovpn-dco-y += bind.o
+ovpn-dco-y += crypto.o
+ovpn-dco-y += ovpn.o
+ovpn-dco-y += peer.o
+ovpn-dco-y += sock.o
+ovpn-dco-y += stats.o
+ovpn-dco-y += netlink.o
+ovpn-dco-y += crypto_aead.o
+ovpn-dco-y += pktid.o
+ovpn-dco-y += tcp.o
+ovpn-dco-y += udp.o
drivers/net/ovpn-dco/addr.h new file +41 -0

41 lines not on this page · raw message

drivers/net/ovpn-dco/bind.c new file +62 -0

62 lines not on this page · raw message

drivers/net/ovpn-dco/bind.h new file +67 -0

67 lines not on this page · raw message

drivers/net/ovpn-dco/crypto.c new file +154 -0

154 lines not on this page · raw message

drivers/net/ovpn-dco/crypto.h new file +144 -0

144 lines not on this page · raw message

drivers/net/ovpn-dco/crypto_aead.c new file +367 -0

367 lines not on this page · raw message

drivers/net/ovpn-dco/crypto_aead.h new file +27 -0
new file mode 100644
index 000000000000..1e3054e7d5a4
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*  OpenVPN data channel accelerator
+ *
+ *  Copyright (C) 2020-2022 OpenVPN, Inc.
+ *
+ *  Author:	James Yonan <[email protected]>
+ *		Antonio Quartulli <[email protected]>
+ */
+
+#ifndef _NET_OVPN_DCO_OVPNAEAD_H_
+#define _NET_OVPN_DCO_OVPNAEAD_H_
+
+#include "crypto.h"
+
+#include <asm/types.h>
+#include <linux/skbuff.h>
+
+struct crypto_aead *ovpn_aead_init(const char *title, const char *alg_name,
+				   const unsigned char *key, unsigned int keylen);
+
+int ovpn_aead_encrypt(struct ovpn_crypto_key_slot *ks, struct sk_buff *skb, u32 peer_id);
+int ovpn_aead_decrypt(struct ovpn_crypto_key_slot *ks, struct sk_buff *skb);
+
+struct ovpn_crypto_key_slot *ovpn_aead_crypto_key_slot_new(const struct ovpn_key_config *kc);
+void ovpn_aead_crypto_key_slot_destroy(struct ovpn_crypto_key_slot *ks);
+
+#endif /* _NET_OVPN_DCO_OVPNAEAD_H_ */
drivers/net/ovpn-dco/main.c new file +271 -0

271 lines not on this page · raw message

drivers/net/ovpn-dco/main.h new file +32 -0
new file mode 100644
index 000000000000..c4ef200b30f4
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*  OpenVPN data channel accelerator
+ *
+ *  Copyright (C) 2019-2022 OpenVPN, Inc.
+ *
+ *  Author:	James Yonan <[email protected]>
+ *		Antonio Quartulli <[email protected]>
+ */
+
+#ifndef _NET_OVPN_DCO_MAIN_H_
+#define _NET_OVPN_DCO_MAIN_H_
+
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <linux/printk.h>
+#include <linux/udp.h>
+
+#define OVPN_DCO_VERSION "2.0.0"
+
+struct net_device;
+bool ovpn_dev_is_valid(const struct net_device *dev);
+
+#define SKB_HEADER_LEN                                       \
+	(max(sizeof(struct iphdr), sizeof(struct ipv6hdr)) + \
+	 sizeof(struct udphdr) + NET_SKB_PAD)
+
+#define OVPN_HEAD_ROOM ALIGN(16 + SKB_HEADER_LEN, 4)
+#define OVPN_MAX_PADDING 16
+#define OVPN_QUEUE_LEN 1024
+#define OVPN_MAX_TUN_QUEUE_LEN 0x10000
+
+#endif /* _NET_OVPN_DCO_OVPN_DCO_H_ */
drivers/net/ovpn-dco/netlink.c new file +1143 -0

1,143 lines not on this page · raw message

drivers/net/ovpn-dco/netlink.h new file +22 -0
new file mode 100644
index 000000000000..843daf052c03
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*  OpenVPN data channel accelerator
+ *
+ *  Copyright (C) 2020-2022 OpenVPN, Inc.
+ *
+ *  Author:	Antonio Quartulli <[email protected]>
+ */
+
+#ifndef _NET_OVPN_DCO_NETLINK_H_
+#define _NET_OVPN_DCO_NETLINK_H_
+
+struct ovpn_struct;
+struct ovpn_peer;
+
+int ovpn_netlink_init(struct ovpn_struct *ovpn);
+int ovpn_netlink_register(void);
+void ovpn_netlink_unregister(void);
+int ovpn_netlink_send_packet(struct ovpn_struct *ovpn, const struct ovpn_peer *peer,
+			     const u8 *buf, size_t len);
+int ovpn_netlink_notify_del_peer(struct ovpn_peer *peer);
+
+#endif /* _NET_OVPN_DCO_NETLINK_H_ */
drivers/net/ovpn-dco/ovpn.c new file +600 -0

600 lines not on this page · raw message

drivers/net/ovpn-dco/ovpn.h new file +43 -0

3 lines not on this page · raw message

drivers/net/ovpn-dco/ovpnstruct.h new file +59 -0

59 lines not on this page · raw message

drivers/net/ovpn-dco/peer.c new file +906 -0

906 lines not on this page · raw message

drivers/net/ovpn-dco/peer.h new file +168 -0

168 lines not on this page · raw message

drivers/net/ovpn-dco/pktid.c new file +127 -0

127 lines not on this page · raw message

drivers/net/ovpn-dco/pktid.h new file +116 -0

116 lines not on this page · raw message

drivers/net/ovpn-dco/proto.h new file +101 -0

101 lines not on this page · raw message

drivers/net/ovpn-dco/rcu.h new file +21 -0
new file mode 100644
index 000000000000..02a50f49ba2e

Lines of this file are not shown. View the raw message.

drivers/net/ovpn-dco/skb.h new file +54 -0

54 lines not on this page · raw message

drivers/net/ovpn-dco/sock.c new file +134 -0

134 lines not on this page · raw message

drivers/net/ovpn-dco/sock.h new file +54 -0

54 lines not on this page · raw message

drivers/net/ovpn-dco/stats.c new file +20 -0
new file mode 100644
index 000000000000..ee000b2a2177

Lines of this file are not shown. View the raw message.

drivers/net/ovpn-dco/stats.h new file +67 -0

67 lines not on this page · raw message

drivers/net/ovpn-dco/tcp.c new file +326 -0

326 lines not on this page · raw message

drivers/net/ovpn-dco/tcp.h new file +38 -0
new file mode 100644
index 000000000000..d243a8e1c34e

Lines of this file are not shown. View the raw message.

drivers/net/ovpn-dco/udp.c new file +343 -0

343 lines not on this page · raw message

drivers/net/ovpn-dco/udp.h new file +25 -0
new file mode 100644
index 000000000000..be94fb74669b

Lines of this file are not shown. View the raw message.

include/net/netlink.h +1 -0
index 7a2a9d3144ba..335f44871529 100644

Lines of this file are not shown. View the raw message.

include/uapi/linux/ovpn_dco.h new file +265 -0

265 lines not on this page · raw message

include/uapi/linux/udp.h +1 -0
index 4828794efcf8..8008c762e6b8 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.35.1

Part of the diff is not shown here. View the raw message.

#18 lore raw

Re: [RFC v2] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Hello Antonio,

first of all, I would like to say thank you for taking care of this. Such useful software as OpenVPN deserves a kernel accelerated rate, and probably a lot of users, including me, are waiting for such feature.

Quoted 108 lines · Antonio Quartulli

OpenVPN is a userspace software existing since around 2005 that allows users to create secure tunnels.

So far OpenVPN has implemented all operations in userspace, which implies several back and forth between kernel and user land in order to process packets (encapsulate/decapsulate, encrypt/decrypt, rerouting..).

With ovpn-dco, we intend to move the fast path (data channel) entirely in kernel space and thus improve user measured throughput over the tunnel.

ovpn-dco is implemented as a simple virtual network device driver, that can be manipulated by means of the standard RTNL APIs. A device of kind 'ovpn-dco' allows only IPv4/6 traffic and can be of type:
* P2P (peer-to-peer): any packet sent over the interface will be encapsulated and transmitted to the other side (typical OpenVPN client behaviour);
* P2MP (point-to-multipoint): packets sent over the interface are transmitted to peers based on existing routes (typical OpenVPN server behaviour).

After the interface has been created, OpenVPN in userspace can configure it using a new Netlink API. Specifically it is possible to manage peers, configure per-peer keys and exchange packets with userspace.

The OpenVPN control channel is multiplexed over the same transport socket by means of OP codes. Anything that is not DATA_V2 (OpenVPN OP code for data traffic) is sent to userspace and handled there. This way the ovpn-dco codebase is kept as compact as possible while focusing on handling data traffic only.

Any OpenVPN control feature (like cipher negotiation, TLS handshake, rekeying, etc.) is still fully handled by the userspace process.

When userspace establishes a new connection with a peer, it first performs the handshake and then passes the socket to ovpn-dco, which takes ownership. From this moment on ovpn-dco will handle data traffic for the new peer. When control packets are received on the link, they are forwarded to userspace via Netlink.

(this approach is somewhat inspired by hostapd+mac80211)

Some events (like peer deletion) are sent to a Netlink multicast group.

Although it wasn't easy to convince the community, ovpn-dco implements only a limited number of the data-channel features supported by the userspace program.

Each feature that made it to ovpn-dco was attentively vetted to avoid carrying too much legacy along with us (and to give a clear cut to old and probalby-not-so-useful features).

Notably, only encryption using AEAD ciphers (specifically ChaCha20Poly1305 and AES-GCM) was implemented. Supporting any other cipher out there was not deemed useful.

As explained above, in case of P2MP mode, OpenVPN will use the main system routing table to decide which packet goes to which peer. This implies that no routing table was re-implemented in ovpn-dco.

This kernel module can be enabled by selecting the CONFIG_OVPN_DCO entry in the networking drivers section.

---

Changes from v1:
* use net/netdev print helpers when possible
* properly set min/max_mtu
* get rid of ndo_change_mtu
* don't set version in ethtool output
* ensure can be compiled also when no IPv6 support exists

---
 MAINTAINERS                        |    8 +
 drivers/net/Kconfig                |   19 +
 drivers/net/Makefile               |    1 +
 drivers/net/ovpn-dco/Makefile      |   21 +
 drivers/net/ovpn-dco/addr.h        |   41 +
 drivers/net/ovpn-dco/bind.c        |   62 ++
 drivers/net/ovpn-dco/bind.h        |   67 ++
 drivers/net/ovpn-dco/crypto.c      |  154 ++++
 drivers/net/ovpn-dco/crypto.h      |  144 ++++
 drivers/net/ovpn-dco/crypto_aead.c |  367 +++++++++
 drivers/net/ovpn-dco/crypto_aead.h |   27 +
 drivers/net/ovpn-dco/main.c        |  271 +++++++
 drivers/net/ovpn-dco/main.h        |   32 +
 drivers/net/ovpn-dco/netlink.c     | 1143 ++++++++++++++++++++++++++++
 drivers/net/ovpn-dco/netlink.h     |   22 +
 drivers/net/ovpn-dco/ovpn.c        |  600 +++++++++++++++
 drivers/net/ovpn-dco/ovpn.h        |   43 ++
 drivers/net/ovpn-dco/ovpnstruct.h  |   59 ++
 drivers/net/ovpn-dco/peer.c        |  906 ++++++++++++++++++++++
 drivers/net/ovpn-dco/peer.h        |  168 ++++
 drivers/net/ovpn-dco/pktid.c       |  127 ++++
 drivers/net/ovpn-dco/pktid.h       |  116 +++
 drivers/net/ovpn-dco/proto.h       |  101 +++
 drivers/net/ovpn-dco/rcu.h         |   21 +
 drivers/net/ovpn-dco/skb.h         |   54 ++
 drivers/net/ovpn-dco/sock.c        |  134 ++++
 drivers/net/ovpn-dco/sock.h        |   54 ++
 drivers/net/ovpn-dco/stats.c       |   20 +
 drivers/net/ovpn-dco/stats.h       |   67 ++
Quoted 8 lines
 drivers/net/ovpn-dco/tcp.c         |  326 ++++++++
 drivers/net/ovpn-dco/tcp.h         |   38 +
 drivers/net/ovpn-dco/udp.c         |  343 +++++++++
 drivers/net/ovpn-dco/udp.h         |   25 +
 include/net/netlink.h              |    1 +
 include/uapi/linux/ovpn_dco.h      |  265 +++++++
 include/uapi/linux/udp.h           |    1 +
 36 files changed, 5848 insertions(+)

It is very hard to review almost 6 thousand lines of code at once. Some issues may be overlooked. I would like to ask you to do the following submission as a series of patches. It is easier to review the code separated into patches by logically completed functional blocks. E.g., module skeleton, management API framework, crypto framework, minimal data handling utils, UDP transport support, TCP transport support, other supplementary features like ethtools API, statistics, etc. This was just an example, you better know internal code dependencies and a best way to introduce the functionality.

Quoted 24 lines
MAINTAINERS +8 -0
index 1920d82db83e..7cb16007dd5c 100644
@@ -15103,6 +15103,14 @@ T:     git git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs.git
 F:     Documentation/filesystems/overlayfs.rst
 F:     fs/overlayfs/
 
+OVPN-DCO NETWORK DRIVER
+M:     Antonio Quartulli <[email protected]>
+L:     [email protected] (moderated for non-subscribers)
+L:     [email protected]
+S:     Maintained
+F:     drivers/net/ovpn-dco/
+F:     include/uapi/linux/ovpn_dco.h
+
 P54 WIRELESS DRIVER
 M:     Christian Lamparter <[email protected]>
 L:     [email protected]
drivers/net/Kconfig +0 -0
index 94c889802566..349866bd4448 100644

drivers/net/Kconfig config WIREGUARD_DEBUG · line 120

Quoted 5 lines
drivers/net/Kconfig +2 -0
@@ -116,6 +116,25 @@ config WIREGUARD_DEBUG
 
          Say N here unless you know what you're doing.
 
+config OVPN_DCO
+       tristate "OpenVPN data channel offload"

Just curious, why do you need this "DCO" suffix? It is not some commonly recognized abbreviation. Why not just call this module "OpenVPN"? Or are you planning to move some other components into the kernel and reserve some naming space?

Quoted 20 lines
drivers/net/Kconfig +17 -0
+       depends on NET && INET
+       select NET_UDP_TUNNEL
+       select DST_CACHE
+       select CRYPTO
+       select CRYPTO_AES
+       select CRYPTO_GCM
+       select CRYPTO_CHACHA20POLY1305
+       help
+         This module enhances the performance of an OpenVPN connection by
+         allowing the user to offload the data channel processing to
+         kernelspace.
+         Connection handshake, parameters negotiation and other non-data
+         related mechanisms are still performed in userspace.
+
+         The OpenVPN userspace software at version 2.6 or higher is required
+         to use this functionality.
+
 config EQUALIZER
        tristate "EQL (serial line load balancing) support"
        help

[skipped]

Quoted 11 lines
drivers/net/Kconfig +11 -0
+/**
+ * ovpn_num_queues - define number of queues to allocate per device
+ *
+ * The value returned by this function is used to decide how many RX and TX
+ * queues to allocate when creating the netdev object
+ *
+ * Return the number of queues to allocate
+ */
+static unsigned int ovpn_num_queues(void)
+{
+       return num_online_cpus();

drivers/net/Kconfig

Quoted 10 lines
drivers/net/Kconfig +10 -0
+}
+
+static struct rtnl_link_ops ovpn_link_ops __read_mostly = {
+       .kind                   = DRV_NAME,
+       .priv_size              = sizeof(struct ovpn_struct),
+       .setup                  = ovpn_setup,
+       .policy                 = ovpn_policy,
+       .maxtype                = IFLA_OVPN_MAX,
+       .newlink                = ovpn_newlink,
+       .dellink                = ovpn_dellink,

What is the purpose of creating and destroying interfaces via RTNL, but performing all other operations using the dedicated netlink protocol?

RTNL interface usually implemented for some standalone interface types, e.g. VLAN, GRE, etc. Here we need a userspace application anyway to be able to use the network device to forward traffic, and the module implements the dedicated GENL protocol. So why not just introduce OVPN_CMD_NEW_IFACE and OVPN_CMD_DEL_IFACE commands to the GENL interface? It looks like this will simplify the userspace part by using the single GENL interface for any management operations.

drivers/net/Kconfig

Quoted 2 lines
drivers/net/Kconfig +2 -0
+       .get_num_tx_queues      = ovpn_num_queues,
+       .get_num_rx_queues      = ovpn_num_queues,

What is the benefit of requesting multiple queues if the xmit callback places all packets from those kernel queues into the single internal queue anyway?

drivers/net/Kconfig

Quoted 7 lines
drivers/net/Kconfig +7 -0
+};
+
+static int __init ovpn_init(void)
+{
+       int err = 0;
+
+       pr_info("%s %s -- %s\n", DRV_DESCRIPTION, DRV_VERSION, DRV_COPYRIGHT);

Is this log line really necessary for the regular module usage?

Quoted 22 lines
drivers/net/Kconfig +22 -0
+
+       /* init RTNL link ops */
+       err = rtnl_link_register(&ovpn_link_ops);
+       if (err) {
+               pr_err("ovpn: can't register RTNL link ops\n");
+               goto err;
+       }
+
+       err = ovpn_netlink_register();
+       if (err) {
+               pr_err("ovpn: can't register netlink family\n");
+               goto err_rtnl_unregister;
+       }
+
+       return 0;
+
+err_rtnl_unregister:
+       rtnl_link_unregister(&ovpn_link_ops);
+err:
+       pr_err("ovpn: initialization failed, error status=%d\n", err);
+       return err;
+}

[skipped]

drivers/net/Kconfig

Quoted 4 lines
drivers/net/Kconfig +4 -0
+static const struct genl_ops ovpn_netlink_ops[] = {
+       {
+               .cmd = OVPN_CMD_NEW_PEER,
+               .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,

AFAIK, the "don't validate strict" flag is for compatibility with old users of earlier existing subsystems. For new GENL families, it is better to avoid using this flag and strictly implement the netlink protocol.

Quoted 7 lines
drivers/net/Kconfig +4 -0
+               .flags = GENL_ADMIN_PERM,
+               .doit = ovpn_netlink_new_peer,
+       },
 
...
 
+};

[skipped]

drivers/net/Kconfig

Quoted 12 lines
drivers/net/Kconfig +12 -0
+static int ovpn_transport_to_userspace(struct ovpn_struct *ovpn, const struct ovpn_peer *peer,
+                                      struct sk_buff *skb)
+{
+       int ret;
+
+       ret = skb_linearize(skb);
+       if (ret < 0)
+               return ret;
+
+       ret = ovpn_netlink_send_packet(ovpn, peer, skb->data, skb->len);
+       if (ret < 0)
+               return ret;

Another interesting decision. Why are you transporting the control messages via Netlink? Why not just pass them to userspace via an already existing TCP/UDP socket, like the LT2P module do, for example? Such design usually requires less changes to the userspace application since it is still able to process control messages as earlier by reading them from the socket.

Quoted 3 lines
drivers/net/Kconfig +3 -0
+       consume_skb(skb);
+       return 0;
+}

[skipped]

Quoted 62 lines
drivers/net/Kconfig +62 -0
+/* Net device start xmit
+ */
+netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+       struct ovpn_struct *ovpn = netdev_priv(dev);
+       struct sk_buff *segments, *tmp, *curr, *next;
+       struct sk_buff_head skb_list;
+       __be16 proto;
+       int ret;
+
+       /* reset netfilter state */
+       nf_reset_ct(skb);
+
+       /* verify IP header size in network packet */
+       proto = ovpn_ip_check_protocol(skb);
+       if (unlikely(!proto || skb->protocol != proto)) {
+               net_dbg_ratelimited("%s: dropping malformed payload packet\n",
+                                   dev->name);
+               goto drop;
+       }
+
+       if (skb_is_gso(skb)) {
+               segments = skb_gso_segment(skb, 0);
+               if (IS_ERR(segments)) {
+                       ret = PTR_ERR(segments);
+                       net_dbg_ratelimited("%s: cannot segment packet: %d\n", dev->name, ret);
+                       goto drop;
+               }
+
+               consume_skb(skb);
+               skb = segments;
+       }
+
+       /* from this moment on, "skb" might be a list */
+
+       __skb_queue_head_init(&skb_list);
+       skb_list_walk_safe(skb, curr, next) {
+               skb_mark_not_on_list(curr);
+
+               tmp = skb_share_check(curr, GFP_ATOMIC);
+               if (unlikely(!tmp)) {
+                       kfree_skb_list(next);
+                       net_dbg_ratelimited("%s: skb_share_check failed\n", dev->name);
+                       goto drop_list;
+               }
+
+               __skb_queue_tail(&skb_list, tmp);
+       }
+       skb_list.prev->next = NULL;
+
+       ovpn_queue_skb(ovpn, skb_list.next, NULL);
+
+       return NETDEV_TX_OK;
+
+drop_list:
+       skb_queue_walk_safe(&skb_list, curr, next)
+               kfree_skb(curr);
+drop:
+       skb_tx_error(skb);
+       kfree_skb_list(skb);
+       return NET_XMIT_DROP;
+}

[skipped]

Quoted 99 lines
include/uapi/linux/ovpn_dco.h new file +93 -0
new file mode 100644
index 000000000000..6afee8b3fedd
@@ -0,0 +1,265 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ *  OpenVPN data channel accelerator
+ *
+ *  Copyright (C) 2019-2022 OpenVPN, Inc.
+ *
+ *  Author:    James Yonan <[email protected]>
+ *             Antonio Quartulli <[email protected]>
+ */
+
+#ifndef _UAPI_LINUX_OVPN_DCO_H_
+#define _UAPI_LINUX_OVPN_DCO_H_
+
+#define OVPN_NL_NAME "ovpn-dco"
+
+#define OVPN_NL_MULTICAST_GROUP_PEERS "peers"
+
+/**
+ * enum ovpn_nl_commands - supported netlink commands
+ */
+enum ovpn_nl_commands {
+       /**
+        * @OVPN_CMD_UNSPEC: unspecified command to catch errors
+        */
+       OVPN_CMD_UNSPEC = 0,
+
+       /**
+        * @OVPN_CMD_NEW_PEER: Configure peer with its crypto keys
+        */
+       OVPN_CMD_NEW_PEER,
+
+       /**
+        * @OVPN_CMD_SET_PEER: Tweak parameters for an existing peer
+        */
+       OVPN_CMD_SET_PEER,
+
+       /**
+        * @OVPN_CMD_DEL_PEER: Remove peer from internal table
+        */
+       OVPN_CMD_DEL_PEER,
+
+       OVPN_CMD_NEW_KEY,
+
+       OVPN_CMD_SWAP_KEYS,
+
+       OVPN_CMD_DEL_KEY,
+
+       /**
+        * @OVPN_CMD_REGISTER_PACKET: Register for specific packet types to be
+        * forwarded to userspace
+        */
+       OVPN_CMD_REGISTER_PACKET,
+
+       /**
+        * @OVPN_CMD_PACKET: Send a packet from userspace to kernelspace. Also
+        * used to send to userspace packets for which a process had registered
+        * with OVPN_CMD_REGISTER_PACKET
+        */
+       OVPN_CMD_PACKET,
+
+       /**
+        * @OVPN_CMD_GET_PEER: Retrieve the status of a peer or all peers
+        */
+       OVPN_CMD_GET_PEER,
+};
+
+enum ovpn_cipher_alg {
+       /**
+        * @OVPN_CIPHER_ALG_NONE: No encryption - reserved for debugging only
+        */
+       OVPN_CIPHER_ALG_NONE = 0,
+       /**
+        * @OVPN_CIPHER_ALG_AES_GCM: AES-GCM AEAD cipher with any allowed key size
+        */
+       OVPN_CIPHER_ALG_AES_GCM,
+       /**
+        * @OVPN_CIPHER_ALG_CHACHA20_POLY1305: ChaCha20Poly1305 AEAD cipher
+        */
+       OVPN_CIPHER_ALG_CHACHA20_POLY1305,
+};
+
+enum ovpn_del_peer_reason {
+       __OVPN_DEL_PEER_REASON_FIRST,
+       OVPN_DEL_PEER_REASON_TEARDOWN = __OVPN_DEL_PEER_REASON_FIRST,
+       OVPN_DEL_PEER_REASON_USERSPACE,
+       OVPN_DEL_PEER_REASON_EXPIRED,
+       OVPN_DEL_PEER_REASON_TRANSPORT_ERROR,
+       __OVPN_DEL_PEER_REASON_AFTER_LAST
+};
+
+enum ovpn_key_slot {
+       __OVPN_KEY_SLOT_FIRST,
+       OVPN_KEY_SLOT_PRIMARY = __OVPN_KEY_SLOT_FIRST,

include/uapi/linux/ovpn_dco.h line 103

Quoted 10 lines
include/uapi/linux/ovpn_dco.h new file +10 -0
+       OVPN_KEY_SLOT_SECONDARY,
+       __OVPN_KEY_SLOT_AFTER_LAST,
+};
+
+enum ovpn_netlink_attrs {
+       OVPN_ATTR_UNSPEC = 0,
+       OVPN_ATTR_IFINDEX,
+       OVPN_ATTR_NEW_PEER,
+       OVPN_ATTR_SET_PEER,
+       OVPN_ATTR_DEL_PEER,

What is the purpose of introducing separate attributes for each NEW/SET/GET/DEL operation? Why not just use a single OVPN_ATTR_PEER attribute?

BTW, generic netlink for some time allows you to have a dedicated set of attributes (and corresponding policies) for each message. So, if you have different object types (e.g. peers, interfaces, keys) you can avoid creating a common set of attributes to cover them all at once, but just create several attribute sets, one set per each object type with corresponding policies (see policy field of the genl_ops struct).

Quoted 79 lines
include/uapi/linux/ovpn_dco.h new file +79 -0
+       OVPN_ATTR_NEW_KEY,
+       OVPN_ATTR_SWAP_KEYS,
+       OVPN_ATTR_DEL_KEY,
+       OVPN_ATTR_PACKET,
+       OVPN_ATTR_GET_PEER,
+
+       __OVPN_ATTR_AFTER_LAST,
+       OVPN_ATTR_MAX = __OVPN_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_key_dir_attrs {
+       OVPN_KEY_DIR_ATTR_UNSPEC = 0,
+       OVPN_KEY_DIR_ATTR_CIPHER_KEY,
+       OVPN_KEY_DIR_ATTR_NONCE_TAIL,
+
+       __OVPN_KEY_DIR_ATTR_AFTER_LAST,
+       OVPN_KEY_DIR_ATTR_MAX = __OVPN_KEY_DIR_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_new_key_attrs {
+       OVPN_NEW_KEY_ATTR_UNSPEC = 0,
+       OVPN_NEW_KEY_ATTR_PEER_ID,
+       OVPN_NEW_KEY_ATTR_KEY_SLOT,
+       OVPN_NEW_KEY_ATTR_KEY_ID,
+       OVPN_NEW_KEY_ATTR_CIPHER_ALG,
+       OVPN_NEW_KEY_ATTR_ENCRYPT_KEY,
+       OVPN_NEW_KEY_ATTR_DECRYPT_KEY,
+
+       __OVPN_NEW_KEY_ATTR_AFTER_LAST,
+       OVPN_NEW_KEY_ATTR_MAX = __OVPN_NEW_KEY_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_del_key_attrs {
+       OVPN_DEL_KEY_ATTR_UNSPEC = 0,
+       OVPN_DEL_KEY_ATTR_PEER_ID,
+       OVPN_DEL_KEY_ATTR_KEY_SLOT,
+
+       __OVPN_DEL_KEY_ATTR_AFTER_LAST,
+       OVPN_DEL_KEY_ATTR_MAX = __OVPN_DEL_KEY_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_swap_keys_attrs {
+       OVPN_SWAP_KEYS_ATTR_UNSPEC = 0,
+       OVPN_SWAP_KEYS_ATTR_PEER_ID,
+
+       __OVPN_SWAP_KEYS_ATTR_AFTER_LAST,
+       OVPN_SWAP_KEYS_ATTR_MAX = __OVPN_SWAP_KEYS_ATTR_AFTER_LAST - 1,
+
+};
+
+enum ovpn_netlink_new_peer_attrs {
+       OVPN_NEW_PEER_ATTR_UNSPEC = 0,
+       OVPN_NEW_PEER_ATTR_PEER_ID,
+       OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE,
+       OVPN_NEW_PEER_ATTR_SOCKET,
+       OVPN_NEW_PEER_ATTR_IPV4,
+       OVPN_NEW_PEER_ATTR_IPV6,
+       OVPN_NEW_PEER_ATTR_LOCAL_IP,
+
+       __OVPN_NEW_PEER_ATTR_AFTER_LAST,
+       OVPN_NEW_PEER_ATTR_MAX = __OVPN_NEW_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_set_peer_attrs {
+       OVPN_SET_PEER_ATTR_UNSPEC = 0,
+       OVPN_SET_PEER_ATTR_PEER_ID,
+       OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL,
+       OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT,
+
+       __OVPN_SET_PEER_ATTR_AFTER_LAST,
+       OVPN_SET_PEER_ATTR_MAX = __OVPN_SET_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_del_peer_attrs {
+       OVPN_DEL_PEER_ATTR_UNSPEC = 0,
+       OVPN_DEL_PEER_ATTR_REASON,
+       OVPN_DEL_PEER_ATTR_PEER_ID,
+
+       __OVPN_DEL_PEER_ATTR_AFTER_LAST,

include/uapi/linux/ovpn_dco.h line 192

Quoted 10 lines
include/uapi/linux/ovpn_dco.h new file +10 -0
+       OVPN_DEL_PEER_ATTR_MAX = __OVPN_DEL_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_get_peer_attrs {
+       OVPN_GET_PEER_ATTR_UNSPEC = 0,
+       OVPN_GET_PEER_ATTR_PEER_ID,
+
+       __OVPN_GET_PEER_ATTR_AFTER_LAST,
+       OVPN_GET_PEER_ATTR_MAX = __OVPN_GET_PEER_ATTR_AFTER_LAST - 1,
+};

What is the reason to create a separate set of attributes per each operation? In my experience, it is easier to use a common set of attributes for all operations on the same object type. At least it is easier to manage one enum instead of four. And you are always sure that attributes with the same semantics (e.g. remote IP) have the same id in any GET/SET message.

Quoted 62 lines
include/uapi/linux/ovpn_dco.h new file +62 -0
+enum ovpn_netlink_get_peer_response_attrs {
+       OVPN_GET_PEER_RESP_ATTR_UNSPEC = 0,
+       OVPN_GET_PEER_RESP_ATTR_PEER_ID,
+       OVPN_GET_PEER_RESP_ATTR_SOCKADDR_REMOTE,
+       OVPN_GET_PEER_RESP_ATTR_IPV4,
+       OVPN_GET_PEER_RESP_ATTR_IPV6,
+       OVPN_GET_PEER_RESP_ATTR_LOCAL_IP,
+       OVPN_GET_PEER_RESP_ATTR_LOCAL_PORT,
+       OVPN_GET_PEER_RESP_ATTR_KEEPALIVE_INTERVAL,
+       OVPN_GET_PEER_RESP_ATTR_KEEPALIVE_TIMEOUT,
+       OVPN_GET_PEER_RESP_ATTR_RX_BYTES,
+       OVPN_GET_PEER_RESP_ATTR_TX_BYTES,
+       OVPN_GET_PEER_RESP_ATTR_RX_PACKETS,
+       OVPN_GET_PEER_RESP_ATTR_TX_PACKETS,
+
+       __OVPN_GET_PEER_RESP_ATTR_AFTER_LAST,
+       OVPN_GET_PEER_RESP_ATTR_MAX = __OVPN_GET_PEER_RESP_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_peer_stats_attrs {
+       OVPN_PEER_STATS_ATTR_UNSPEC = 0,
+       OVPN_PEER_STATS_BYTES,
+       OVPN_PEER_STATS_PACKETS,
+
+       __OVPN_PEER_STATS_ATTR_AFTER_LAST,
+       OVPN_PEER_STATS_ATTR_MAX = __OVPN_PEER_STATS_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_peer_attrs {
+       OVPN_PEER_ATTR_UNSPEC = 0,
+       OVPN_PEER_ATTR_PEER_ID,
+       OVPN_PEER_ATTR_SOCKADDR_REMOTE,
+       OVPN_PEER_ATTR_IPV4,
+       OVPN_PEER_ATTR_IPV6,
+       OVPN_PEER_ATTR_LOCAL_IP,
+       OVPN_PEER_ATTR_KEEPALIVE_INTERVAL,
+       OVPN_PEER_ATTR_KEEPALIVE_TIMEOUT,
+       OVPN_PEER_ATTR_ENCRYPT_KEY,
+       OVPN_PEER_ATTR_DECRYPT_KEY,
+       OVPN_PEER_ATTR_RX_STATS,
+       OVPN_PEER_ATTR_TX_STATS,
+
+       __OVPN_PEER_ATTR_AFTER_LAST,
+       OVPN_PEER_ATTR_MAX = __OVPN_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_packet_attrs {
+       OVPN_PACKET_ATTR_UNSPEC = 0,
+       OVPN_PACKET_ATTR_PACKET,
+       OVPN_PACKET_ATTR_PEER_ID,
+
+       __OVPN_PACKET_ATTR_AFTER_LAST,
+       OVPN_PACKET_ATTR_MAX = __OVPN_PACKET_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_ifla_attrs {
+       IFLA_OVPN_UNSPEC = 0,
+       IFLA_OVPN_MODE,
+
+       __IFLA_OVPN_AFTER_LAST,
+       IFLA_OVPN_MAX = __IFLA_OVPN_AFTER_LAST - 1,
+};

include/uapi/linux/ovpn_dco.h line 265

Quoted 10 lines
include/uapi/linux/ovpn_dco.h new file +10 -0
+
+enum ovpn_mode {
+       __OVPN_MODE_FIRST = 0,
+       OVPN_MODE_P2P = __OVPN_MODE_FIRST,
+       OVPN_MODE_MP,
+
+       __OVPN_MODE_AFTER_LAST,
+};
+
+#endif /* _UAPI_LINUX_OVPN_DCO_H_ */

--
BR,
Sergey

#19 lore raw

Re: [RFC v2] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Quoted 11 lines · On Fri, 12 Aug 2022 21:34:33 +0300 Sergey Ryazanov <[email protected]>…

What is the purpose of creating and destroying interfaces via RTNL, but performing all other operations using the dedicated netlink protocol?

RTNL interface usually implemented for some standalone interface types, e.g. VLAN, GRE, etc. Here we need a userspace application anyway to be able to use the network device to forward traffic, and the module implements the dedicated GENL protocol. So why not just introduce OVPN_CMD_NEW_IFACE and OVPN_CMD_DEL_IFACE commands to the GENL interface? It looks like this will simplify the userspace part by using the single GENL interface for any management operations.

RTNL is netlink. The standard way to create network devices should be available with newlink message as in:

 # ip link add dev myvpn type ovpn <options>
#20 lore raw

Re: [RFC v2] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Hello Stephen,

Quoted 14 lines · Stephen Hemminger
Quoted 11 lines · On Fri, 12 Aug 2022 21:34:33 +0300 Sergey Ryazanov <[email protected]>…

What is the purpose of creating and destroying interfaces via RTNL, but performing all other operations using the dedicated netlink protocol?

RTNL interface usually implemented for some standalone interface types, e.g. VLAN, GRE, etc. Here we need a userspace application anyway to be able to use the network device to forward traffic, and the module implements the dedicated GENL protocol. So why not just introduce OVPN_CMD_NEW_IFACE and OVPN_CMD_DEL_IFACE commands to the GENL interface? It looks like this will simplify the userspace part by using the single GENL interface for any management operations.

Quoted 4 lines

RTNL is netlink. The standard way to create network devices should be available with newlink message as in:

 # ip link add dev myvpn type ovpn <options>

If you do not mind, then I would like to say that RTNL is not a standard way, but a common way to create a virtual network interface.

The RTNL ability to create network devices is very useful for standalone interface types (VLANs, GRE, etc.). But there are other types that require much more care to be brought into a usable state. E.g., WLAN devices can only be managed by GENL. Even L2TP that can be created with ip(8) actually utilizes the GENL based interface and completely ignores RTNL.

An OpenVPN network device created with ip-link(8) will remain useless until the control daemon establishes a connection, negotiates params, adds a peer, etc. And all these actions should be performed using a separate GENL interface. I mean that the RTNL support in the OpenVPN module is a dead-end.

That is why I suggested Antonio to save his time by ignoring the network interface creation with RTNL and focus on the GENL interface. Using only the GENL-based interface will also simplify development of the control daemon. Does this strategy sound reasonable in this particular context?

--
Sergey

#21 lore raw

Re: [RFC v2] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

In reply to Sergey Ryazanov

Hello Sergey,

Thank you VERY much for your feedback!

Please, see my comments inline

Quoted 125 lines · Sergey Ryazanov

Hello Antonio,

first of all, I would like to say thank you for taking care of this. Such useful software as OpenVPN deserves a kernel accelerated rate, and probably a lot of users, including me, are waiting for such feature.

Quoted 108 lines · Antonio Quartulli

OpenVPN is a userspace software existing since around 2005 that allows users to create secure tunnels.

So far OpenVPN has implemented all operations in userspace, which implies several back and forth between kernel and user land in order to process packets (encapsulate/decapsulate, encrypt/decrypt, rerouting..).

With ovpn-dco, we intend to move the fast path (data channel) entirely in kernel space and thus improve user measured throughput over the tunnel.

ovpn-dco is implemented as a simple virtual network device driver, that can be manipulated by means of the standard RTNL APIs. A device of kind 'ovpn-dco' allows only IPv4/6 traffic and can be of type:
* P2P (peer-to-peer): any packet sent over the interface will be encapsulated and transmitted to the other side (typical OpenVPN client behaviour);
* P2MP (point-to-multipoint): packets sent over the interface are transmitted to peers based on existing routes (typical OpenVPN server behaviour).

After the interface has been created, OpenVPN in userspace can configure it using a new Netlink API. Specifically it is possible to manage peers, configure per-peer keys and exchange packets with userspace.

The OpenVPN control channel is multiplexed over the same transport socket by means of OP codes. Anything that is not DATA_V2 (OpenVPN OP code for data traffic) is sent to userspace and handled there. This way the ovpn-dco codebase is kept as compact as possible while focusing on handling data traffic only.

Any OpenVPN control feature (like cipher negotiation, TLS handshake, rekeying, etc.) is still fully handled by the userspace process.

When userspace establishes a new connection with a peer, it first performs the handshake and then passes the socket to ovpn-dco, which takes ownership. From this moment on ovpn-dco will handle data traffic for the new peer. When control packets are received on the link, they are forwarded to userspace via Netlink.

(this approach is somewhat inspired by hostapd+mac80211)

Some events (like peer deletion) are sent to a Netlink multicast group.

Although it wasn't easy to convince the community, ovpn-dco implements only a limited number of the data-channel features supported by the userspace program.

Each feature that made it to ovpn-dco was attentively vetted to avoid carrying too much legacy along with us (and to give a clear cut to old and probalby-not-so-useful features).

Notably, only encryption using AEAD ciphers (specifically ChaCha20Poly1305 and AES-GCM) was implemented. Supporting any other cipher out there was not deemed useful.

As explained above, in case of P2MP mode, OpenVPN will use the main system routing table to decide which packet goes to which peer. This implies that no routing table was re-implemented in ovpn-dco.

This kernel module can be enabled by selecting the CONFIG_OVPN_DCO entry in the networking drivers section.

---

Changes from v1:
* use net/netdev print helpers when possible
* properly set min/max_mtu
* get rid of ndo_change_mtu
* don't set version in ethtool output
* ensure can be compiled also when no IPv6 support exists

---
  MAINTAINERS                        |    8 +
  drivers/net/Kconfig                |   19 +
  drivers/net/Makefile               |    1 +
  drivers/net/ovpn-dco/Makefile      |   21 +
  drivers/net/ovpn-dco/addr.h        |   41 +
  drivers/net/ovpn-dco/bind.c        |   62 ++
  drivers/net/ovpn-dco/bind.h        |   67 ++
  drivers/net/ovpn-dco/crypto.c      |  154 ++++
  drivers/net/ovpn-dco/crypto.h      |  144 ++++
  drivers/net/ovpn-dco/crypto_aead.c |  367 +++++++++
  drivers/net/ovpn-dco/crypto_aead.h |   27 +
  drivers/net/ovpn-dco/main.c        |  271 +++++++
  drivers/net/ovpn-dco/main.h        |   32 +
  drivers/net/ovpn-dco/netlink.c     | 1143 ++++++++++++++++++++++++++++
  drivers/net/ovpn-dco/netlink.h     |   22 +
  drivers/net/ovpn-dco/ovpn.c        |  600 +++++++++++++++
  drivers/net/ovpn-dco/ovpn.h        |   43 ++
  drivers/net/ovpn-dco/ovpnstruct.h  |   59 ++
  drivers/net/ovpn-dco/peer.c        |  906 ++++++++++++++++++++++
  drivers/net/ovpn-dco/peer.h        |  168 ++++
  drivers/net/ovpn-dco/pktid.c       |  127 ++++
  drivers/net/ovpn-dco/pktid.h       |  116 +++
  drivers/net/ovpn-dco/proto.h       |  101 +++
  drivers/net/ovpn-dco/rcu.h         |   21 +
  drivers/net/ovpn-dco/skb.h         |   54 ++
  drivers/net/ovpn-dco/sock.c        |  134 ++++
  drivers/net/ovpn-dco/sock.h        |   54 ++
  drivers/net/ovpn-dco/stats.c       |   20 +
  drivers/net/ovpn-dco/stats.h       |   67 ++
Quoted 8 lines
  drivers/net/ovpn-dco/tcp.c         |  326 ++++++++
  drivers/net/ovpn-dco/tcp.h         |   38 +
  drivers/net/ovpn-dco/udp.c         |  343 +++++++++
  drivers/net/ovpn-dco/udp.h         |   25 +
  include/net/netlink.h              |    1 +
  include/uapi/linux/ovpn_dco.h      |  265 +++++++
  include/uapi/linux/udp.h           |    1 +
  36 files changed, 5848 insertions(+)
Quoted 9 lines

It is very hard to review almost 6 thousand lines of code at once. Some issues may be overlooked. I would like to ask you to do the following submission as a series of patches. It is easier to review the code separated into patches by logically completed functional blocks. E.g., module skeleton, management API framework, crypto framework, minimal data handling utils, UDP transport support, TCP transport support, other supplementary features like ethtools API, statistics, etc. This was just an example, you better know internal code dependencies and a best way to introduce the functionality.

You are right about the review being a bit harder, but I did not know what was the preferred approach.

It seemed that other modules are also introduced in one commit, so I just did the same.

But if it's accepted to have "compiling" commits that do not really deliver a working driver, I am fine with splitting this up.

Quoted 28 lines
Quoted 28 lines
MAINTAINERS +8 -0
index 1920d82db83e..7cb16007dd5c 100644
@@ -15103,6 +15103,14 @@ T:     git git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs.git
  F:     Documentation/filesystems/overlayfs.rst
  F:     fs/overlayfs/
 
+OVPN-DCO NETWORK DRIVER
+M:     Antonio Quartulli <[email protected]>
+L:     [email protected] (moderated for non-subscribers)
+L:     [email protected]
+S:     Maintained
+F:     drivers/net/ovpn-dco/
+F:     include/uapi/linux/ovpn_dco.h
+
  P54 WIRELESS DRIVER
  M:     Christian Lamparter <[email protected]>
  L:     [email protected]
drivers/net/Kconfig +0 -0
index 94c889802566..349866bd4448 100644
@@ -116,6 +116,25 @@ config WIREGUARD_DEBUG
 
           Say N here unless you know what you're doing.
 
Quoted 7 lines

drivers/net/Kconfig config WIREGUARD_DEBUG · line 120

Quoted 2 lines
drivers/net/Kconfig +2 -0
+config OVPN_DCO
+       tristate "OpenVPN data channel offload"

Just curious, why do you need this "DCO" suffix? It is not some commonly recognized abbreviation. Why not just call this module "OpenVPN"? Or are you planning to move some other components into the kernel and reserve some naming space?

This device driver just implements data channel offloading and it is not a fully fledged OpenVPN impementation, so I thought it was meaningful to make this explicit.

Calling the driver just openvpn/ovpn may give the false impression that this is a reimplementation of the whole OpenVPN protocol in kernelspace.

Does it make sense?

The "DCO" acronym may not be so common in other areas, but in the OpenVPN community we have been talking about DCO (Data Channel Offload) since a while, so it was pretty natural for us to use this suffix.

Quoted 50 lines
Quoted 21 lines
drivers/net/Kconfig +17 -0
+       depends on NET && INET
+       select NET_UDP_TUNNEL
+       select DST_CACHE
+       select CRYPTO
+       select CRYPTO_AES
+       select CRYPTO_GCM
+       select CRYPTO_CHACHA20POLY1305
+       help
+         This module enhances the performance of an OpenVPN connection by
+         allowing the user to offload the data channel processing to
+         kernelspace.
+         Connection handshake, parameters negotiation and other non-data
+         related mechanisms are still performed in userspace.
+
+         The OpenVPN userspace software at version 2.6 or higher is required
+         to use this functionality.
+
  config EQUALIZER
         tristate "EQL (serial line load balancing) support"
         help

[skipped]

Quoted 11 lines
drivers/net/Kconfig +11 -0
+/**
+ * ovpn_num_queues - define number of queues to allocate per device
+ *
+ * The value returned by this function is used to decide how many RX and TX
+ * queues to allocate when creating the netdev object
+ *
+ * Return the number of queues to allocate
+ */
+static unsigned int ovpn_num_queues(void)
+{
+       return num_online_cpus();

drivers/net/Kconfig

Quoted 10 lines
drivers/net/Kconfig +10 -0
+}
+
+static struct rtnl_link_ops ovpn_link_ops __read_mostly = {
+       .kind                   = DRV_NAME,
+       .priv_size              = sizeof(struct ovpn_struct),
+       .setup                  = ovpn_setup,
+       .policy                 = ovpn_policy,
+       .maxtype                = IFLA_OVPN_MAX,
+       .newlink                = ovpn_newlink,
+       .dellink                = ovpn_dellink,

What is the purpose of creating and destroying interfaces via RTNL, but performing all other operations using the dedicated netlink protocol?

Quoted 7 lines

RTNL interface usually implemented for some standalone interface types, e.g. VLAN, GRE, etc. Here we need a userspace application anyway to be able to use the network device to forward traffic, and the module implements the dedicated GENL protocol. So why not just introduce OVPN_CMD_NEW_IFACE and OVPN_CMD_DEL_IFACE commands to the GENL interface? It looks like this will simplify the userspace part by using the single GENL interface for any management operations.

As Stephen also said in his reply, I tried to stick to the standard approach of creating interface via RTNL (which is also netlink).

With this implementation you can already create an interface as:

ip link add vpn0 type ovpn-dco

Eventually I will patch iproute2 to support some options as well (we have one only for now).

Quoted 7 lines

drivers/net/Kconfig

Quoted 3 lines
drivers/net/Kconfig +2 -0
+       .get_num_tx_queues      = ovpn_num_queues,
+       .get_num_rx_queues      = ovpn_num_queues,

What is the benefit of requesting multiple queues if the xmit callback places all packets from those kernel queues into the single internal queue anyway?

Good point. This is one of those aspects where I was hoping to get some guidance. In any case, I will double check if having more than one queue is really what we want or not.

Quoted 10 lines

drivers/net/Kconfig

Quoted 8 lines
drivers/net/Kconfig +7 -0
+};
+
+static int __init ovpn_init(void)
+{
+       int err = 0;
+
+       pr_info("%s %s -- %s\n", DRV_DESCRIPTION, DRV_VERSION, DRV_COPYRIGHT);

Is this log line really necessary for the regular module usage?

Well, it's a reasonable way to give users feedback about the module loading successfully. I see it's pretty common across drivers, so I thought to use the same approach.

Quoted 31 lines
Quoted 23 lines
drivers/net/Kconfig +22 -0
+
+       /* init RTNL link ops */
+       err = rtnl_link_register(&ovpn_link_ops);
+       if (err) {
+               pr_err("ovpn: can't register RTNL link ops\n");
+               goto err;
+       }
+
+       err = ovpn_netlink_register();
+       if (err) {
+               pr_err("ovpn: can't register netlink family\n");
+               goto err_rtnl_unregister;
+       }
+
+       return 0;
+
+err_rtnl_unregister:
+       rtnl_link_unregister(&ovpn_link_ops);
+err:
+       pr_err("ovpn: initialization failed, error status=%d\n", err);
+       return err;
+}

[skipped]

drivers/net/Kconfig

Quoted 4 lines
drivers/net/Kconfig +4 -0
+static const struct genl_ops ovpn_netlink_ops[] = {
+       {
+               .cmd = OVPN_CMD_NEW_PEER,
+               .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Quoted 4 lines

AFAIK, the "don't validate strict" flag is for compatibility with old users of earlier existing subsystems. For new GENL families, it is better to avoid using this flag and strictly implement the netlink protocol.

Good point. I can probably just get rid of this flag then.

Quoted 22 lines
Quoted 8 lines
drivers/net/Kconfig +4 -0
+               .flags = GENL_ADMIN_PERM,
+               .doit = ovpn_netlink_new_peer,
+       },
 
...
 
+};

[skipped]

Quoted 11 lines
drivers/net/Kconfig +11 -0
+static int ovpn_transport_to_userspace(struct ovpn_struct *ovpn, const struct ovpn_peer *peer,
+                                      struct sk_buff *skb)
+{
+       int ret;
+
+       ret = skb_linearize(skb);
+       if (ret < 0)
+               return ret;
+
+       ret = ovpn_netlink_send_packet(ovpn, peer, skb->data, skb->len);
+       if (ret < 0)
Quoted 8 lines
Quoted 1 line

+ return ret;

Another interesting decision. Why are you transporting the control messages via Netlink? Why not just pass them to userspace via an already existing TCP/UDP socket, like the LT2P module do, for example? Such design usually requires less changes to the userspace application since it is still able to process control messages as earlier by reading them from the socket.

As far as I understand the L2TP module implementes its own protocol (IPPROTO_L2TP).

In the ovpn-dco case userspace simply opens a normal UDP or TCP socket (as it always used to do), which is later passed to the kernel.

In ovpn-dco (kernel) we then use udp_tunnel to take over the UDP socket, while we change the socket ops in case of TCP.

While in the UDP case it would be possible to still use the socket to send control packets, in the TCP case this would not work and we would need another method (which is netlink) to send/receive packets from userspace.

At this point we did not want to treat TCP and UDP sockets differently, so we decided to always use netlink to send control packets to/from userspace.

Quoted 177 lines
Quoted 4 lines
drivers/net/Kconfig +3 -0
+       consume_skb(skb);
+       return 0;
+}

[skipped]

Quoted 62 lines
drivers/net/Kconfig +62 -0
+/* Net device start xmit
+ */
+netdev_tx_t ovpn_net_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+       struct ovpn_struct *ovpn = netdev_priv(dev);
+       struct sk_buff *segments, *tmp, *curr, *next;
+       struct sk_buff_head skb_list;
+       __be16 proto;
+       int ret;
+
+       /* reset netfilter state */
+       nf_reset_ct(skb);
+
+       /* verify IP header size in network packet */
+       proto = ovpn_ip_check_protocol(skb);
+       if (unlikely(!proto || skb->protocol != proto)) {
+               net_dbg_ratelimited("%s: dropping malformed payload packet\n",
+                                   dev->name);
+               goto drop;
+       }
+
+       if (skb_is_gso(skb)) {
+               segments = skb_gso_segment(skb, 0);
+               if (IS_ERR(segments)) {
+                       ret = PTR_ERR(segments);
+                       net_dbg_ratelimited("%s: cannot segment packet: %d\n", dev->name, ret);
+                       goto drop;
+               }
+
+               consume_skb(skb);
+               skb = segments;
+       }
+
+       /* from this moment on, "skb" might be a list */
+
+       __skb_queue_head_init(&skb_list);
+       skb_list_walk_safe(skb, curr, next) {
+               skb_mark_not_on_list(curr);
+
+               tmp = skb_share_check(curr, GFP_ATOMIC);
+               if (unlikely(!tmp)) {
+                       kfree_skb_list(next);
+                       net_dbg_ratelimited("%s: skb_share_check failed\n", dev->name);
+                       goto drop_list;
+               }
+
+               __skb_queue_tail(&skb_list, tmp);
+       }
+       skb_list.prev->next = NULL;
+
+       ovpn_queue_skb(ovpn, skb_list.next, NULL);
+
+       return NETDEV_TX_OK;
+
+drop_list:
+       skb_queue_walk_safe(&skb_list, curr, next)
+               kfree_skb(curr);
+drop:
+       skb_tx_error(skb);
+       kfree_skb_list(skb);
+       return NET_XMIT_DROP;
+}

[skipped]

Quoted 105 lines
include/uapi/linux/ovpn_dco.h new file +99 -0
new file mode 100644
index 000000000000..6afee8b3fedd
@@ -0,0 +1,265 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ *  OpenVPN data channel accelerator
+ *
+ *  Copyright (C) 2019-2022 OpenVPN, Inc.
+ *
+ *  Author:    James Yonan <[email protected]>
+ *             Antonio Quartulli <[email protected]>
+ */
+
+#ifndef _UAPI_LINUX_OVPN_DCO_H_
+#define _UAPI_LINUX_OVPN_DCO_H_
+
+#define OVPN_NL_NAME "ovpn-dco"
+
+#define OVPN_NL_MULTICAST_GROUP_PEERS "peers"
+
+/**
+ * enum ovpn_nl_commands - supported netlink commands
+ */
+enum ovpn_nl_commands {
+       /**
+        * @OVPN_CMD_UNSPEC: unspecified command to catch errors
+        */
+       OVPN_CMD_UNSPEC = 0,
+
+       /**
+        * @OVPN_CMD_NEW_PEER: Configure peer with its crypto keys
+        */
+       OVPN_CMD_NEW_PEER,
+
+       /**
+        * @OVPN_CMD_SET_PEER: Tweak parameters for an existing peer
+        */
+       OVPN_CMD_SET_PEER,
+
+       /**
+        * @OVPN_CMD_DEL_PEER: Remove peer from internal table
+        */
+       OVPN_CMD_DEL_PEER,
+
+       OVPN_CMD_NEW_KEY,
+
+       OVPN_CMD_SWAP_KEYS,
+
+       OVPN_CMD_DEL_KEY,
+
+       /**
+        * @OVPN_CMD_REGISTER_PACKET: Register for specific packet types to be
+        * forwarded to userspace
+        */
+       OVPN_CMD_REGISTER_PACKET,
+
+       /**
+        * @OVPN_CMD_PACKET: Send a packet from userspace to kernelspace. Also
+        * used to send to userspace packets for which a process had registered
+        * with OVPN_CMD_REGISTER_PACKET
+        */
+       OVPN_CMD_PACKET,
+
+       /**
+        * @OVPN_CMD_GET_PEER: Retrieve the status of a peer or all peers
+        */
+       OVPN_CMD_GET_PEER,
+};
+
+enum ovpn_cipher_alg {
+       /**
+        * @OVPN_CIPHER_ALG_NONE: No encryption - reserved for debugging only
+        */
+       OVPN_CIPHER_ALG_NONE = 0,
+       /**
+        * @OVPN_CIPHER_ALG_AES_GCM: AES-GCM AEAD cipher with any allowed key size
+        */
+       OVPN_CIPHER_ALG_AES_GCM,
+       /**
+        * @OVPN_CIPHER_ALG_CHACHA20_POLY1305: ChaCha20Poly1305 AEAD cipher
+        */
+       OVPN_CIPHER_ALG_CHACHA20_POLY1305,
+};
+
+enum ovpn_del_peer_reason {
+       __OVPN_DEL_PEER_REASON_FIRST,
+       OVPN_DEL_PEER_REASON_TEARDOWN = __OVPN_DEL_PEER_REASON_FIRST,
+       OVPN_DEL_PEER_REASON_USERSPACE,
+       OVPN_DEL_PEER_REASON_EXPIRED,
+       OVPN_DEL_PEER_REASON_TRANSPORT_ERROR,
+       __OVPN_DEL_PEER_REASON_AFTER_LAST
+};
+
+enum ovpn_key_slot {
+       __OVPN_KEY_SLOT_FIRST,
+       OVPN_KEY_SLOT_PRIMARY = __OVPN_KEY_SLOT_FIRST,
+       OVPN_KEY_SLOT_SECONDARY,
+       __OVPN_KEY_SLOT_AFTER_LAST,
+};
+
+enum ovpn_netlink_attrs {
+       OVPN_ATTR_UNSPEC = 0,
Quoted 8 lines

include/uapi/linux/ovpn_dco.h line 103

Quoted 4 lines
include/uapi/linux/ovpn_dco.h new file +4 -0
+       OVPN_ATTR_IFINDEX,
+       OVPN_ATTR_NEW_PEER,
+       OVPN_ATTR_SET_PEER,
+       OVPN_ATTR_DEL_PEER,

What is the purpose of introducing separate attributes for each NEW/SET/GET/DEL operation? Why not just use a single OVPN_ATTR_PEER attribute?

The idea is to have a subobject for each operation. Each specific subobject would then contain only the specific attributes allowed for that object. This way attributes from different operations are not mixed.

Quoted 7 lines

BTW, generic netlink for some time allows you to have a dedicated set of attributes (and corresponding policies) for each message. So, if you have different object types (e.g. peers, interfaces, keys) you can avoid creating a common set of attributes to cover them all at once, but just create several attribute sets, one set per each object type with corresponding policies (see policy field of the genl_ops struct).

mh interesting. Any module I could look at that implements this approach?

Quoted 89 lines
Quoted 89 lines
include/uapi/linux/ovpn_dco.h new file +88 -0
+       OVPN_ATTR_NEW_KEY,
+       OVPN_ATTR_SWAP_KEYS,
+       OVPN_ATTR_DEL_KEY,
+       OVPN_ATTR_PACKET,
+       OVPN_ATTR_GET_PEER,
+
+       __OVPN_ATTR_AFTER_LAST,
+       OVPN_ATTR_MAX = __OVPN_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_key_dir_attrs {
+       OVPN_KEY_DIR_ATTR_UNSPEC = 0,
+       OVPN_KEY_DIR_ATTR_CIPHER_KEY,
+       OVPN_KEY_DIR_ATTR_NONCE_TAIL,
+
+       __OVPN_KEY_DIR_ATTR_AFTER_LAST,
+       OVPN_KEY_DIR_ATTR_MAX = __OVPN_KEY_DIR_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_new_key_attrs {
+       OVPN_NEW_KEY_ATTR_UNSPEC = 0,
+       OVPN_NEW_KEY_ATTR_PEER_ID,
+       OVPN_NEW_KEY_ATTR_KEY_SLOT,
+       OVPN_NEW_KEY_ATTR_KEY_ID,
+       OVPN_NEW_KEY_ATTR_CIPHER_ALG,
+       OVPN_NEW_KEY_ATTR_ENCRYPT_KEY,
+       OVPN_NEW_KEY_ATTR_DECRYPT_KEY,
+
+       __OVPN_NEW_KEY_ATTR_AFTER_LAST,
+       OVPN_NEW_KEY_ATTR_MAX = __OVPN_NEW_KEY_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_del_key_attrs {
+       OVPN_DEL_KEY_ATTR_UNSPEC = 0,
+       OVPN_DEL_KEY_ATTR_PEER_ID,
+       OVPN_DEL_KEY_ATTR_KEY_SLOT,
+
+       __OVPN_DEL_KEY_ATTR_AFTER_LAST,
+       OVPN_DEL_KEY_ATTR_MAX = __OVPN_DEL_KEY_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_swap_keys_attrs {
+       OVPN_SWAP_KEYS_ATTR_UNSPEC = 0,
+       OVPN_SWAP_KEYS_ATTR_PEER_ID,
+
+       __OVPN_SWAP_KEYS_ATTR_AFTER_LAST,
+       OVPN_SWAP_KEYS_ATTR_MAX = __OVPN_SWAP_KEYS_ATTR_AFTER_LAST - 1,
+
+};
+
+enum ovpn_netlink_new_peer_attrs {
+       OVPN_NEW_PEER_ATTR_UNSPEC = 0,
+       OVPN_NEW_PEER_ATTR_PEER_ID,
+       OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE,
+       OVPN_NEW_PEER_ATTR_SOCKET,
+       OVPN_NEW_PEER_ATTR_IPV4,
+       OVPN_NEW_PEER_ATTR_IPV6,
+       OVPN_NEW_PEER_ATTR_LOCAL_IP,
+
+       __OVPN_NEW_PEER_ATTR_AFTER_LAST,
+       OVPN_NEW_PEER_ATTR_MAX = __OVPN_NEW_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_set_peer_attrs {
+       OVPN_SET_PEER_ATTR_UNSPEC = 0,
+       OVPN_SET_PEER_ATTR_PEER_ID,
+       OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL,
+       OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT,
+
+       __OVPN_SET_PEER_ATTR_AFTER_LAST,
+       OVPN_SET_PEER_ATTR_MAX = __OVPN_SET_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_del_peer_attrs {
+       OVPN_DEL_PEER_ATTR_UNSPEC = 0,
+       OVPN_DEL_PEER_ATTR_REASON,
+       OVPN_DEL_PEER_ATTR_PEER_ID,
+
+       __OVPN_DEL_PEER_ATTR_AFTER_LAST,
+       OVPN_DEL_PEER_ATTR_MAX = __OVPN_DEL_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_get_peer_attrs {
+       OVPN_GET_PEER_ATTR_UNSPEC = 0,
+       OVPN_GET_PEER_ATTR_PEER_ID,
+
+       __OVPN_GET_PEER_ATTR_AFTER_LAST,
+       OVPN_GET_PEER_ATTR_MAX = __OVPN_GET_PEER_ATTR_AFTER_LAST - 1,
Quoted 8 lines

include/uapi/linux/ovpn_dco.h line 192

Quoted 1 line
include/uapi/linux/ovpn_dco.h new file +1 -0
+};

What is the reason to create a separate set of attributes per each operation? In my experience, it is easier to use a common set of attributes for all operations on the same object type. At least it is easier to manage one enum instead of four. And you are always sure that attributes with the same semantics (e.g. remote IP) have the same id in any GET/SET message.

The reason is mostly documentation.

In my experience (which is mostly wifi related), when using a single set of attributes is (almost) impossible to understand which attributes have to be sent along with a specific command. I always had to look at the actual netlink handlers implementation.

With this approach, instead, I can point out immediately what attributes are related to which command.

Maybe this is not the best approach, but I wanted a way that allows a developer to immediately understand the ovpn-dco API without having to read the code in ovpn-dco/netlink.c

What do you think?

Quoted 69 lines
Quoted 69 lines
include/uapi/linux/ovpn_dco.h new file +68 -0
+enum ovpn_netlink_get_peer_response_attrs {
+       OVPN_GET_PEER_RESP_ATTR_UNSPEC = 0,
+       OVPN_GET_PEER_RESP_ATTR_PEER_ID,
+       OVPN_GET_PEER_RESP_ATTR_SOCKADDR_REMOTE,
+       OVPN_GET_PEER_RESP_ATTR_IPV4,
+       OVPN_GET_PEER_RESP_ATTR_IPV6,
+       OVPN_GET_PEER_RESP_ATTR_LOCAL_IP,
+       OVPN_GET_PEER_RESP_ATTR_LOCAL_PORT,
+       OVPN_GET_PEER_RESP_ATTR_KEEPALIVE_INTERVAL,
+       OVPN_GET_PEER_RESP_ATTR_KEEPALIVE_TIMEOUT,
+       OVPN_GET_PEER_RESP_ATTR_RX_BYTES,
+       OVPN_GET_PEER_RESP_ATTR_TX_BYTES,
+       OVPN_GET_PEER_RESP_ATTR_RX_PACKETS,
+       OVPN_GET_PEER_RESP_ATTR_TX_PACKETS,
+
+       __OVPN_GET_PEER_RESP_ATTR_AFTER_LAST,
+       OVPN_GET_PEER_RESP_ATTR_MAX = __OVPN_GET_PEER_RESP_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_peer_stats_attrs {
+       OVPN_PEER_STATS_ATTR_UNSPEC = 0,
+       OVPN_PEER_STATS_BYTES,
+       OVPN_PEER_STATS_PACKETS,
+
+       __OVPN_PEER_STATS_ATTR_AFTER_LAST,
+       OVPN_PEER_STATS_ATTR_MAX = __OVPN_PEER_STATS_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_peer_attrs {
+       OVPN_PEER_ATTR_UNSPEC = 0,
+       OVPN_PEER_ATTR_PEER_ID,
+       OVPN_PEER_ATTR_SOCKADDR_REMOTE,
+       OVPN_PEER_ATTR_IPV4,
+       OVPN_PEER_ATTR_IPV6,
+       OVPN_PEER_ATTR_LOCAL_IP,
+       OVPN_PEER_ATTR_KEEPALIVE_INTERVAL,
+       OVPN_PEER_ATTR_KEEPALIVE_TIMEOUT,
+       OVPN_PEER_ATTR_ENCRYPT_KEY,
+       OVPN_PEER_ATTR_DECRYPT_KEY,
+       OVPN_PEER_ATTR_RX_STATS,
+       OVPN_PEER_ATTR_TX_STATS,
+
+       __OVPN_PEER_ATTR_AFTER_LAST,
+       OVPN_PEER_ATTR_MAX = __OVPN_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_packet_attrs {
+       OVPN_PACKET_ATTR_UNSPEC = 0,
+       OVPN_PACKET_ATTR_PACKET,
+       OVPN_PACKET_ATTR_PEER_ID,
+
+       __OVPN_PACKET_ATTR_AFTER_LAST,
+       OVPN_PACKET_ATTR_MAX = __OVPN_PACKET_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_ifla_attrs {
+       IFLA_OVPN_UNSPEC = 0,
+       IFLA_OVPN_MODE,
+
+       __IFLA_OVPN_AFTER_LAST,
+       IFLA_OVPN_MAX = __IFLA_OVPN_AFTER_LAST - 1,
+};
+
+enum ovpn_mode {
+       __OVPN_MODE_FIRST = 0,
+       OVPN_MODE_P2P = __OVPN_MODE_FIRST,
+       OVPN_MODE_MP,
+
Quoted 8 lines

include/uapi/linux/ovpn_dco.h line 265

Quoted 4 lines
include/uapi/linux/ovpn_dco.h new file +4 -0
+       __OVPN_MODE_AFTER_LAST,
+};
+
+#endif /* _UAPI_LINUX_OVPN_DCO_H_ */

--
BR,
Sergey

Thanks again!

Best Regards,

Signature · 2 lines
Antonio Quartulli
OpenVPN Inc.
#22 lore raw

Re: [RFC v2] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Hello Antonio,

I am sorry to be late with the reply. Please find answers below.

Quoted 129 lines · Antonio Quartulli
Quoted 118 lines · Sergey Ryazanov
Quoted 108 lines · Antonio Quartulli

OpenVPN is a userspace software existing since around 2005 that allows users to create secure tunnels.

So far OpenVPN has implemented all operations in userspace, which implies several back and forth between kernel and user land in order to process packets (encapsulate/decapsulate, encrypt/decrypt, rerouting..).

With ovpn-dco, we intend to move the fast path (data channel) entirely in kernel space and thus improve user measured throughput over the tunnel.

ovpn-dco is implemented as a simple virtual network device driver, that can be manipulated by means of the standard RTNL APIs. A device of kind 'ovpn-dco' allows only IPv4/6 traffic and can be of type:
* P2P (peer-to-peer): any packet sent over the interface will be encapsulated and transmitted to the other side (typical OpenVPN client behaviour);
* P2MP (point-to-multipoint): packets sent over the interface are transmitted to peers based on existing routes (typical OpenVPN server behaviour).

After the interface has been created, OpenVPN in userspace can configure it using a new Netlink API. Specifically it is possible to manage peers, configure per-peer keys and exchange packets with userspace.

The OpenVPN control channel is multiplexed over the same transport socket by means of OP codes. Anything that is not DATA_V2 (OpenVPN OP code for data traffic) is sent to userspace and handled there. This way the ovpn-dco codebase is kept as compact as possible while focusing on handling data traffic only.

Any OpenVPN control feature (like cipher negotiation, TLS handshake, rekeying, etc.) is still fully handled by the userspace process.

When userspace establishes a new connection with a peer, it first performs the handshake and then passes the socket to ovpn-dco, which takes ownership. From this moment on ovpn-dco will handle data traffic for the new peer. When control packets are received on the link, they are forwarded to userspace via Netlink.

(this approach is somewhat inspired by hostapd+mac80211)

Some events (like peer deletion) are sent to a Netlink multicast group.

Although it wasn't easy to convince the community, ovpn-dco implements only a limited number of the data-channel features supported by the userspace program.

Each feature that made it to ovpn-dco was attentively vetted to avoid carrying too much legacy along with us (and to give a clear cut to old and probalby-not-so-useful features).

Notably, only encryption using AEAD ciphers (specifically ChaCha20Poly1305 and AES-GCM) was implemented. Supporting any other cipher out there was not deemed useful.

As explained above, in case of P2MP mode, OpenVPN will use the main system routing table to decide which packet goes to which peer. This implies that no routing table was re-implemented in ovpn-dco.

This kernel module can be enabled by selecting the CONFIG_OVPN_DCO entry in the networking drivers section.

---

Changes from v1:
* use net/netdev print helpers when possible
* properly set min/max_mtu
* get rid of ndo_change_mtu
* don't set version in ethtool output
* ensure can be compiled also when no IPv6 support exists

---
  MAINTAINERS                        |    8 +
  drivers/net/Kconfig                |   19 +
  drivers/net/Makefile               |    1 +
  drivers/net/ovpn-dco/Makefile      |   21 +
  drivers/net/ovpn-dco/addr.h        |   41 +
  drivers/net/ovpn-dco/bind.c        |   62 ++
  drivers/net/ovpn-dco/bind.h        |   67 ++
  drivers/net/ovpn-dco/crypto.c      |  154 ++++
  drivers/net/ovpn-dco/crypto.h      |  144 ++++
  drivers/net/ovpn-dco/crypto_aead.c |  367 +++++++++
  drivers/net/ovpn-dco/crypto_aead.h |   27 +
  drivers/net/ovpn-dco/main.c        |  271 +++++++
  drivers/net/ovpn-dco/main.h        |   32 +
  drivers/net/ovpn-dco/netlink.c     | 1143 ++++++++++++++++++++++++++++
  drivers/net/ovpn-dco/netlink.h     |   22 +
  drivers/net/ovpn-dco/ovpn.c        |  600 +++++++++++++++
  drivers/net/ovpn-dco/ovpn.h        |   43 ++
  drivers/net/ovpn-dco/ovpnstruct.h  |   59 ++
  drivers/net/ovpn-dco/peer.c        |  906 ++++++++++++++++++++++
  drivers/net/ovpn-dco/peer.h        |  168 ++++
  drivers/net/ovpn-dco/pktid.c       |  127 ++++
  drivers/net/ovpn-dco/pktid.h       |  116 +++
  drivers/net/ovpn-dco/proto.h       |  101 +++
  drivers/net/ovpn-dco/rcu.h         |   21 +
  drivers/net/ovpn-dco/skb.h         |   54 ++
  drivers/net/ovpn-dco/sock.c        |  134 ++++
  drivers/net/ovpn-dco/sock.h        |   54 ++
  drivers/net/ovpn-dco/stats.c       |   20 +
  drivers/net/ovpn-dco/stats.h       |   67 ++
Quoted 8 lines
  drivers/net/ovpn-dco/tcp.c         |  326 ++++++++
  drivers/net/ovpn-dco/tcp.h         |   38 +
  drivers/net/ovpn-dco/udp.c         |  343 +++++++++
  drivers/net/ovpn-dco/udp.h         |   25 +
  include/net/netlink.h              |    1 +
  include/uapi/linux/ovpn_dco.h      |  265 +++++++
  include/uapi/linux/udp.h           |    1 +
  36 files changed, 5848 insertions(+)
Quoted 9 lines

It is very hard to review almost 6 thousand lines of code at once. Some issues may be overlooked. I would like to ask you to do the following submission as a series of patches. It is easier to review the code separated into patches by logically completed functional blocks. E.g., module skeleton, management API framework, crypto framework, minimal data handling utils, UDP transport support, TCP transport support, other supplementary features like ethtools API, statistics, etc. This was just an example, you better know internal code dependencies and a best way to introduce the functionality.

Quoted 2 lines

You are right about the review being a bit harder, but I did not know what was the preferred approach.

From the reviewer's point of view, the best case is a series of logically completed patches.

Quoted 2 lines

It seemed that other modules are also introduced in one commit, so I just did the same.

That is true. Sometimes contributors submit a series of patches for review and then, when the series collects enough reviews and acknowledges, resend the same code as one huge patch for merging. This approach solves two tasks: the initial review becomes simple and pleasant, and all the code is still introduced into the repository atomically in a single commit. This strategy is well suited for new modules. Just your case.

If you prefer this way, add a note for the maintainer somewhere in a cover letter during the review stage. In the note, simply state that the series is for review only and the code will then be resent as a single patch for merging.

Quoted 2 lines

But if it's accepted to have "compiling" commits that do not really deliver a working driver, I am fine with splitting this up.

For the review, it is more than acceptable, it is appreciated :)

Quoted 35 lines
Quoted 27 lines
Quoted 27 lines
MAINTAINERS +8 -0
index 1920d82db83e..7cb16007dd5c 100644
@@ -15103,6 +15103,14 @@ T:     git git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs.git
  F:     Documentation/filesystems/overlayfs.rst
  F:     fs/overlayfs/
 
+OVPN-DCO NETWORK DRIVER
+M:     Antonio Quartulli <[email protected]>
+L:     [email protected] (moderated for non-subscribers)
+L:     [email protected]
+S:     Maintained
+F:     drivers/net/ovpn-dco/
+F:     include/uapi/linux/ovpn_dco.h
+
  P54 WIRELESS DRIVER
  M:     Christian Lamparter <[email protected]>
  L:     [email protected]
drivers/net/Kconfig +0 -0
index 94c889802566..349866bd4448 100644
@@ -116,6 +116,25 @@ config WIREGUARD_DEBUG
 
           Say N here unless you know what you're doing.
 
Quoted 7 lines

drivers/net/Kconfig config WIREGUARD_DEBUG · line 120

Quoted 2 lines
drivers/net/Kconfig +2 -0
+config OVPN_DCO
+       tristate "OpenVPN data channel offload"

Just curious, why do you need this "DCO" suffix? It is not some commonly recognized abbreviation. Why not just call this module "OpenVPN"? Or are you planning to move some other components into the kernel and reserve some naming space?

Quoted 8 lines

This device driver just implements data channel offloading and it is not a fully fledged OpenVPN impementation, so I thought it was meaningful to make this explicit.

Calling the driver just openvpn/ovpn may give the false impression that this is a reimplementation of the whole OpenVPN protocol in kernelspace.

Does it make sense?

Yep, that sounds like a reasonable assumption. But this "DCO" suffix just sounds confusing (see my experiment results below).

There are many data plane implementations in the kernel that are named after a protocol, but do not implement a control part at all (e.g. L2TP, PPTP, GTP, TLS, etc.). These names are not confusing since an "average developer" knows that it is normal practice to implement a data plane part in the kernel for performance reasons, while keeping a control plane in userspace.

To be clear, I do not mind specifying in the title and description of the option that the module only implements data processing. Such remark will only help end users. BTW, you wrote a very clear and simple description for the option. But meeting this abbreviation in the file names, I want to ask: why is it needed here?

Quoted 3 lines

The "DCO" acronym may not be so common in other areas, but in the OpenVPN community we have been talking about DCO (Data Channel Offload) since a while, so it was pretty natural for us to use this suffix.

In the context of OpenVPN development, this can help distinguish the components. But outside this context, it may be confusing.

I did an experiment. I told a couple of developers who was not aware about this patch that the OpenVPN community has created and is begining a kernel module upstreaming process and that module will be called 'openvpn-dco'. Each of them first said "wow, what a good news", but then each of them asked me "What does DCO mean?".

Quoted 57 lines
Quoted 49 lines
Quoted 20 lines
drivers/net/Kconfig +17 -0
+       depends on NET && INET
+       select NET_UDP_TUNNEL
+       select DST_CACHE
+       select CRYPTO
+       select CRYPTO_AES
+       select CRYPTO_GCM
+       select CRYPTO_CHACHA20POLY1305
+       help
+         This module enhances the performance of an OpenVPN connection by
+         allowing the user to offload the data channel processing to
+         kernelspace.
+         Connection handshake, parameters negotiation and other non-data
+         related mechanisms are still performed in userspace.
+
+         The OpenVPN userspace software at version 2.6 or higher is required
+         to use this functionality.
+
  config EQUALIZER
         tristate "EQL (serial line load balancing) support"
         help

[skipped]

Quoted 11 lines
drivers/net/Kconfig +11 -0
+/**
+ * ovpn_num_queues - define number of queues to allocate per device
+ *
+ * The value returned by this function is used to decide how many RX and TX
+ * queues to allocate when creating the netdev object
+ *
+ * Return the number of queues to allocate
+ */
+static unsigned int ovpn_num_queues(void)
+{
+       return num_online_cpus();

drivers/net/Kconfig

Quoted 10 lines
drivers/net/Kconfig +10 -0
+}
+
+static struct rtnl_link_ops ovpn_link_ops __read_mostly = {
+       .kind                   = DRV_NAME,
+       .priv_size              = sizeof(struct ovpn_struct),
+       .setup                  = ovpn_setup,
+       .policy                 = ovpn_policy,
+       .maxtype                = IFLA_OVPN_MAX,
+       .newlink                = ovpn_newlink,
+       .dellink                = ovpn_dellink,

What is the purpose of creating and destroying interfaces via RTNL, but performing all other operations using the dedicated netlink protocol?

Quoted 7 lines

RTNL interface usually implemented for some standalone interface types, e.g. VLAN, GRE, etc. Here we need a userspace application anyway to be able to use the network device to forward traffic, and the module implements the dedicated GENL protocol. So why not just introduce OVPN_CMD_NEW_IFACE and OVPN_CMD_DEL_IFACE commands to the GENL interface? It looks like this will simplify the userspace part by using the single GENL interface for any management operations.

Quoted 2 lines

As Stephen also said in his reply, I tried to stick to the standard approach of creating interface via RTNL (which is also netlink).

Probably there is no such thing as a standard here. There is a common good practice to use RTNL to create a virtual network device if it can be used just after creation. What is a quite common case. But an openvpn network device remains useless once created until someone adds a peer configuration using the GENL-based management interface. Therefore, I still think that the RTNL management in this particular case is a dead-end. See my answer to Stephen for more details and examples.

Quoted 6 lines

With this implementation you can already create an interface as:

ip link add vpn0 type ovpn-dco

Eventually I will patch iproute2 to support some options as well (we have one only for now).

What do you think about using ip-l2tp(8) instead of ip-link(8) as a reference implementation for the openvpn devices management?

Quoted 11 lines
Quoted 6 lines

drivers/net/Kconfig

Quoted 2 lines
drivers/net/Kconfig +2 -0
+       .get_num_tx_queues      = ovpn_num_queues,
+       .get_num_rx_queues      = ovpn_num_queues,

What is the benefit of requesting multiple queues if the xmit callback places all packets from those kernel queues into the single internal queue anyway?

Good point. This is one of those aspects where I was hoping to get some guidance.
In any case, I will double check if having more than one queue is really what we want or not.

Start with a single queue, make a stable implementation, merge it into the kernel so you have a good basis for future performance optimizations. Anyway, the single queue implementation inside the kernel will be much faster than the userspace implementation with the double memory copying.

Quoted 10 lines
Quoted 9 lines

drivers/net/Kconfig

Quoted 7 lines
drivers/net/Kconfig +7 -0
+};
+
+static int __init ovpn_init(void)
+{
+       int err = 0;
+
+       pr_info("%s %s -- %s\n", DRV_DESCRIPTION, DRV_VERSION, DRV_COPYRIGHT);

Is this log line really necessary for the regular module usage?

Quoted 3 lines

Well, it's a reasonable way to give users feedback about the module loading successfully. I see it's pretty common across drivers, so I thought to use the same approach.

Maybe it is a matter of taste, but I always consider such "hello" messages as noise in the boot log. User can check the loaded modules list with lsmod(8).

Quoted 50 lines
Quoted 35 lines
Quoted 21 lines
drivers/net/Kconfig +21 -0
+       /* init RTNL link ops */
+       err = rtnl_link_register(&ovpn_link_ops);
+       if (err) {
+               pr_err("ovpn: can't register RTNL link ops\n");
+               goto err;
+       }
+
+       err = ovpn_netlink_register();
+       if (err) {
+               pr_err("ovpn: can't register netlink family\n");
+               goto err_rtnl_unregister;
+       }
+
+       return 0;
+
+err_rtnl_unregister:
+       rtnl_link_unregister(&ovpn_link_ops);
+err:
+       pr_err("ovpn: initialization failed, error status=%d\n", err);
+       return err;
+}

[skipped]

Quoted 11 lines
drivers/net/Kconfig +11 -0
+static int ovpn_transport_to_userspace(struct ovpn_struct *ovpn, const struct ovpn_peer *peer,
+                                      struct sk_buff *skb)
+{
+       int ret;
+
+       ret = skb_linearize(skb);
+       if (ret < 0)
+               return ret;
+
+       ret = ovpn_netlink_send_packet(ovpn, peer, skb->data, skb->len);
+       if (ret < 0)
Quoted 8 lines
Quoted 1 line

+ return ret;

Another interesting decision. Why are you transporting the control messages via Netlink? Why not just pass them to userspace via an already existing TCP/UDP socket, like the LT2P module do, for example? Such design usually requires less changes to the userspace application since it is still able to process control messages as earlier by reading them from the socket.

As far as I understand the L2TP module implementes its own protocol (IPPROTO_L2TP).

In the ovpn-dco case userspace simply opens a normal UDP or TCP socket (as it always used to do), which is later passed to the kernel.

Quoted 7 lines

In ovpn-dco (kernel) we then use udp_tunnel to take over the UDP socket, while we change the socket ops in case of TCP.

While in the UDP case it would be possible to still use the socket to send control packets, in the TCP case this would not work and we would need another method (which is netlink) to send/receive packets from userspace.

Even if you intercept the whole incoming traffic in the kernel, you can still pass some of it to userspace. You just need to override some socket protocol ops. See TLS implementation for example (/net/tls/{tls_main.c,tls_sw.c}) and c46234ebb4d1 ("tls: RX path for ktls"). The same is possible for outgoing traffic too.

Quoted 125 lines

At this point we did not want to treat TCP and UDP sockets differently, so we decided to always use netlink to send control packets to/from userspace.

Quoted 112 lines
Quoted 4 lines
drivers/net/Kconfig +3 -0
+       consume_skb(skb);
+       return 0;
+}

[skipped]

Quoted 105 lines
include/uapi/linux/ovpn_dco.h new file +99 -0
new file mode 100644
index 000000000000..6afee8b3fedd
@@ -0,0 +1,265 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ *  OpenVPN data channel accelerator
+ *
+ *  Copyright (C) 2019-2022 OpenVPN, Inc.
+ *
+ *  Author:    James Yonan <[email protected]>
+ *             Antonio Quartulli <[email protected]>
+ */
+
+#ifndef _UAPI_LINUX_OVPN_DCO_H_
+#define _UAPI_LINUX_OVPN_DCO_H_
+
+#define OVPN_NL_NAME "ovpn-dco"
+
+#define OVPN_NL_MULTICAST_GROUP_PEERS "peers"
+
+/**
+ * enum ovpn_nl_commands - supported netlink commands
+ */
+enum ovpn_nl_commands {
+       /**
+        * @OVPN_CMD_UNSPEC: unspecified command to catch errors
+        */
+       OVPN_CMD_UNSPEC = 0,
+
+       /**
+        * @OVPN_CMD_NEW_PEER: Configure peer with its crypto keys
+        */
+       OVPN_CMD_NEW_PEER,
+
+       /**
+        * @OVPN_CMD_SET_PEER: Tweak parameters for an existing peer
+        */
+       OVPN_CMD_SET_PEER,
+
+       /**
+        * @OVPN_CMD_DEL_PEER: Remove peer from internal table
+        */
+       OVPN_CMD_DEL_PEER,
+
+       OVPN_CMD_NEW_KEY,
+
+       OVPN_CMD_SWAP_KEYS,
+
+       OVPN_CMD_DEL_KEY,
+
+       /**
+        * @OVPN_CMD_REGISTER_PACKET: Register for specific packet types to be
+        * forwarded to userspace
+        */
+       OVPN_CMD_REGISTER_PACKET,
+
+       /**
+        * @OVPN_CMD_PACKET: Send a packet from userspace to kernelspace. Also
+        * used to send to userspace packets for which a process had registered
+        * with OVPN_CMD_REGISTER_PACKET
+        */
+       OVPN_CMD_PACKET,
+
+       /**
+        * @OVPN_CMD_GET_PEER: Retrieve the status of a peer or all peers
+        */
+       OVPN_CMD_GET_PEER,
+};
+
+enum ovpn_cipher_alg {
+       /**
+        * @OVPN_CIPHER_ALG_NONE: No encryption - reserved for debugging only
+        */
+       OVPN_CIPHER_ALG_NONE = 0,
+       /**
+        * @OVPN_CIPHER_ALG_AES_GCM: AES-GCM AEAD cipher with any allowed key size
+        */
+       OVPN_CIPHER_ALG_AES_GCM,
+       /**
+        * @OVPN_CIPHER_ALG_CHACHA20_POLY1305: ChaCha20Poly1305 AEAD cipher
+        */
+       OVPN_CIPHER_ALG_CHACHA20_POLY1305,
+};
+
+enum ovpn_del_peer_reason {
+       __OVPN_DEL_PEER_REASON_FIRST,
+       OVPN_DEL_PEER_REASON_TEARDOWN = __OVPN_DEL_PEER_REASON_FIRST,
+       OVPN_DEL_PEER_REASON_USERSPACE,
+       OVPN_DEL_PEER_REASON_EXPIRED,
+       OVPN_DEL_PEER_REASON_TRANSPORT_ERROR,
+       __OVPN_DEL_PEER_REASON_AFTER_LAST
+};
+
+enum ovpn_key_slot {
+       __OVPN_KEY_SLOT_FIRST,
+       OVPN_KEY_SLOT_PRIMARY = __OVPN_KEY_SLOT_FIRST,
+       OVPN_KEY_SLOT_SECONDARY,
+       __OVPN_KEY_SLOT_AFTER_LAST,
+};
+
+enum ovpn_netlink_attrs {
+       OVPN_ATTR_UNSPEC = 0,
Quoted 8 lines

include/uapi/linux/ovpn_dco.h line 103

Quoted 4 lines
include/uapi/linux/ovpn_dco.h new file +4 -0
+       OVPN_ATTR_IFINDEX,
+       OVPN_ATTR_NEW_PEER,
+       OVPN_ATTR_SET_PEER,
+       OVPN_ATTR_DEL_PEER,

What is the purpose of introducing separate attributes for each NEW/SET/GET/DEL operation? Why not just use a single OVPN_ATTR_PEER attribute?

Quoted 3 lines

The idea is to have a subobject for each operation. Each specific subobject would then contain only the specific attributes allowed for that object. This way attributes from different operations are not mixed.

I am still puzzled. What is the reason to not mix attributes from different operations if they are operations on the same object?

Quoted 8 lines
Quoted 6 lines

BTW, generic netlink for some time allows you to have a dedicated set of attributes (and corresponding policies) for each message. So, if you have different object types (e.g. peers, interfaces, keys) you can avoid creating a common set of attributes to cover them all at once, but just create several attribute sets, one set per each object type with corresponding policies (see policy field of the genl_ops struct).

mh interesting. Any module I could look at that implements this approach?

See ./kernel/taskstats.c:672 for example

Quoted 104 lines
Quoted 88 lines
Quoted 88 lines
include/uapi/linux/ovpn_dco.h new file +88 -0
+       OVPN_ATTR_NEW_KEY,
+       OVPN_ATTR_SWAP_KEYS,
+       OVPN_ATTR_DEL_KEY,
+       OVPN_ATTR_PACKET,
+       OVPN_ATTR_GET_PEER,
+
+       __OVPN_ATTR_AFTER_LAST,
+       OVPN_ATTR_MAX = __OVPN_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_key_dir_attrs {
+       OVPN_KEY_DIR_ATTR_UNSPEC = 0,
+       OVPN_KEY_DIR_ATTR_CIPHER_KEY,
+       OVPN_KEY_DIR_ATTR_NONCE_TAIL,
+
+       __OVPN_KEY_DIR_ATTR_AFTER_LAST,
+       OVPN_KEY_DIR_ATTR_MAX = __OVPN_KEY_DIR_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_new_key_attrs {
+       OVPN_NEW_KEY_ATTR_UNSPEC = 0,
+       OVPN_NEW_KEY_ATTR_PEER_ID,
+       OVPN_NEW_KEY_ATTR_KEY_SLOT,
+       OVPN_NEW_KEY_ATTR_KEY_ID,
+       OVPN_NEW_KEY_ATTR_CIPHER_ALG,
+       OVPN_NEW_KEY_ATTR_ENCRYPT_KEY,
+       OVPN_NEW_KEY_ATTR_DECRYPT_KEY,
+
+       __OVPN_NEW_KEY_ATTR_AFTER_LAST,
+       OVPN_NEW_KEY_ATTR_MAX = __OVPN_NEW_KEY_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_del_key_attrs {
+       OVPN_DEL_KEY_ATTR_UNSPEC = 0,
+       OVPN_DEL_KEY_ATTR_PEER_ID,
+       OVPN_DEL_KEY_ATTR_KEY_SLOT,
+
+       __OVPN_DEL_KEY_ATTR_AFTER_LAST,
+       OVPN_DEL_KEY_ATTR_MAX = __OVPN_DEL_KEY_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_swap_keys_attrs {
+       OVPN_SWAP_KEYS_ATTR_UNSPEC = 0,
+       OVPN_SWAP_KEYS_ATTR_PEER_ID,
+
+       __OVPN_SWAP_KEYS_ATTR_AFTER_LAST,
+       OVPN_SWAP_KEYS_ATTR_MAX = __OVPN_SWAP_KEYS_ATTR_AFTER_LAST - 1,
+
+};
+
+enum ovpn_netlink_new_peer_attrs {
+       OVPN_NEW_PEER_ATTR_UNSPEC = 0,
+       OVPN_NEW_PEER_ATTR_PEER_ID,
+       OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE,
+       OVPN_NEW_PEER_ATTR_SOCKET,
+       OVPN_NEW_PEER_ATTR_IPV4,
+       OVPN_NEW_PEER_ATTR_IPV6,
+       OVPN_NEW_PEER_ATTR_LOCAL_IP,
+
+       __OVPN_NEW_PEER_ATTR_AFTER_LAST,
+       OVPN_NEW_PEER_ATTR_MAX = __OVPN_NEW_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_set_peer_attrs {
+       OVPN_SET_PEER_ATTR_UNSPEC = 0,
+       OVPN_SET_PEER_ATTR_PEER_ID,
+       OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL,
+       OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT,
+
+       __OVPN_SET_PEER_ATTR_AFTER_LAST,
+       OVPN_SET_PEER_ATTR_MAX = __OVPN_SET_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_del_peer_attrs {
+       OVPN_DEL_PEER_ATTR_UNSPEC = 0,
+       OVPN_DEL_PEER_ATTR_REASON,
+       OVPN_DEL_PEER_ATTR_PEER_ID,
+
+       __OVPN_DEL_PEER_ATTR_AFTER_LAST,
+       OVPN_DEL_PEER_ATTR_MAX = __OVPN_DEL_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_get_peer_attrs {
+       OVPN_GET_PEER_ATTR_UNSPEC = 0,
+       OVPN_GET_PEER_ATTR_PEER_ID,
+
+       __OVPN_GET_PEER_ATTR_AFTER_LAST,
+       OVPN_GET_PEER_ATTR_MAX = __OVPN_GET_PEER_ATTR_AFTER_LAST - 1,
Quoted 8 lines

include/uapi/linux/ovpn_dco.h line 192

Quoted 1 line
include/uapi/linux/ovpn_dco.h new file +1 -0
+};

What is the reason to create a separate set of attributes per each operation? In my experience, it is easier to use a common set of attributes for all operations on the same object type. At least it is easier to manage one enum instead of four. And you are always sure that attributes with the same semantics (e.g. remote IP) have the same id in any GET/SET message.

The reason is mostly documentation.

In my experience (which is mostly wifi related), when using a single set of attributes is (almost) impossible to understand which attributes have to be sent along with a specific command.
I always had to look at the actual netlink handlers implementation.

Quoted 8 lines

With this approach, instead, I can point out immediately what attributes are related to which command.

Maybe this is not the best approach, but I wanted a way that allows a developer to immediately understand the ovpn-dco API without having to read the code in ovpn-dco/netlink.c

What do you think?

Looks like the other extreme. By avoiding the case of one set of attributes for any command, we got a special set of attributes per each command.

Is it conceptually possible to implement the approach with a per-object set of attributes?

Quoted 72 lines
Quoted 72 lines
Quoted 72 lines
include/uapi/linux/ovpn_dco.h new file +72 -0
+enum ovpn_netlink_get_peer_response_attrs {
+       OVPN_GET_PEER_RESP_ATTR_UNSPEC = 0,
+       OVPN_GET_PEER_RESP_ATTR_PEER_ID,
+       OVPN_GET_PEER_RESP_ATTR_SOCKADDR_REMOTE,
+       OVPN_GET_PEER_RESP_ATTR_IPV4,
+       OVPN_GET_PEER_RESP_ATTR_IPV6,
+       OVPN_GET_PEER_RESP_ATTR_LOCAL_IP,
+       OVPN_GET_PEER_RESP_ATTR_LOCAL_PORT,
+       OVPN_GET_PEER_RESP_ATTR_KEEPALIVE_INTERVAL,
+       OVPN_GET_PEER_RESP_ATTR_KEEPALIVE_TIMEOUT,
+       OVPN_GET_PEER_RESP_ATTR_RX_BYTES,
+       OVPN_GET_PEER_RESP_ATTR_TX_BYTES,
+       OVPN_GET_PEER_RESP_ATTR_RX_PACKETS,
+       OVPN_GET_PEER_RESP_ATTR_TX_PACKETS,
+
+       __OVPN_GET_PEER_RESP_ATTR_AFTER_LAST,
+       OVPN_GET_PEER_RESP_ATTR_MAX = __OVPN_GET_PEER_RESP_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_peer_stats_attrs {
+       OVPN_PEER_STATS_ATTR_UNSPEC = 0,
+       OVPN_PEER_STATS_BYTES,
+       OVPN_PEER_STATS_PACKETS,
+
+       __OVPN_PEER_STATS_ATTR_AFTER_LAST,
+       OVPN_PEER_STATS_ATTR_MAX = __OVPN_PEER_STATS_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_peer_attrs {
+       OVPN_PEER_ATTR_UNSPEC = 0,
+       OVPN_PEER_ATTR_PEER_ID,
+       OVPN_PEER_ATTR_SOCKADDR_REMOTE,
+       OVPN_PEER_ATTR_IPV4,
+       OVPN_PEER_ATTR_IPV6,
+       OVPN_PEER_ATTR_LOCAL_IP,
+       OVPN_PEER_ATTR_KEEPALIVE_INTERVAL,
+       OVPN_PEER_ATTR_KEEPALIVE_TIMEOUT,
+       OVPN_PEER_ATTR_ENCRYPT_KEY,
+       OVPN_PEER_ATTR_DECRYPT_KEY,
+       OVPN_PEER_ATTR_RX_STATS,
+       OVPN_PEER_ATTR_TX_STATS,
+
+       __OVPN_PEER_ATTR_AFTER_LAST,
+       OVPN_PEER_ATTR_MAX = __OVPN_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_packet_attrs {
+       OVPN_PACKET_ATTR_UNSPEC = 0,
+       OVPN_PACKET_ATTR_PACKET,
+       OVPN_PACKET_ATTR_PEER_ID,
+
+       __OVPN_PACKET_ATTR_AFTER_LAST,
+       OVPN_PACKET_ATTR_MAX = __OVPN_PACKET_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_ifla_attrs {
+       IFLA_OVPN_UNSPEC = 0,
+       IFLA_OVPN_MODE,
+
+       __IFLA_OVPN_AFTER_LAST,
+       IFLA_OVPN_MAX = __IFLA_OVPN_AFTER_LAST - 1,
+};
+
+enum ovpn_mode {
+       __OVPN_MODE_FIRST = 0,
+       OVPN_MODE_P2P = __OVPN_MODE_FIRST,
+       OVPN_MODE_MP,
+
+       __OVPN_MODE_AFTER_LAST,
+};
+
+#endif /* _UAPI_LINUX_OVPN_DCO_H_ */
Signature · 1 line
Sergey
#23 lore raw

Re: [RFC v2] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Hello Sergey,

apologies on my side this time - I was still out of office until early this week and I did not have a chance to reply.

Please see below.

On 31/08/2022 05:15, Sergey Ryazanov wrote:
[cut]

Quoted 2 lines

For the review, it is more than acceptable, it is appreciated :)

will proceed with the split up then.

[cut]

Quoted 37 lines
Quoted 8 lines
Quoted 7 lines

drivers/net/Kconfig config WIREGUARD_DEBUG · line 120

Quoted 2 lines
drivers/net/Kconfig +2 -0
+config OVPN_DCO
+       tristate "OpenVPN data channel offload"

Just curious, why do you need this "DCO" suffix? It is not some commonly recognized abbreviation. Why not just call this module "OpenVPN"? Or are you planning to move some other components into the kernel and reserve some naming space?

Quoted 8 lines

This device driver just implements data channel offloading and it is not a fully fledged OpenVPN impementation, so I thought it was meaningful to make this explicit.

Calling the driver just openvpn/ovpn may give the false impression that this is a reimplementation of the whole OpenVPN protocol in kernelspace.

Does it make sense?

Yep, that sounds like a reasonable assumption. But this "DCO" suffix just sounds confusing (see my experiment results below).

There are many data plane implementations in the kernel that are named after a protocol, but do not implement a control part at all (e.g. L2TP, PPTP, GTP, TLS, etc.). These names are not confusing since an "average developer" knows that it is normal practice to implement a data plane part in the kernel for performance reasons, while keeping a control plane in userspace.

To be clear, I do not mind specifying in the title and description of the option that the module only implements data processing. Such remark will only help end users. BTW, you wrote a very clear and simple description for the option. But meeting this abbreviation in the file names, I want to ask: why is it needed here?

Quoted 3 lines

The "DCO" acronym may not be so common in other areas, but in the OpenVPN community we have been talking about DCO (Data Channel Offload) since a while, so it was pretty natural for us to use this suffix.

Quoted 8 lines

In the context of OpenVPN development, this can help distinguish the components. But outside this context, it may be confusing.

I did an experiment. I told a couple of developers who was not aware about this patch that the OpenVPN community has created and is begining a kernel module upstreaming process and that module will be called 'openvpn-dco'. Each of them first said "wow, what a good news", but then each of them asked me "What does DCO mean?".

Thanks for elaborating your point and for taking the time to conduct this little experiment.

I agree with you, like other protocols that have the control plane implemented in userspace, also in this case we should go with "ovpn" only.

I think that I'll rename the folder and the config knob :-)

[cut]

Quoted 24 lines
Quoted 21 lines
Quoted 13 lines

drivers/net/ovpn-dco/main.c line 223

Quoted 8 lines
drivers/net/ovpn-dco/main.c new file +8 -0
+static struct rtnl_link_ops ovpn_link_ops __read_mostly = {
+       .kind                   = DRV_NAME,
+       .priv_size              = sizeof(struct ovpn_struct),
+       .setup                  = ovpn_setup,
+       .policy                 = ovpn_policy,
+       .maxtype                = IFLA_OVPN_MAX,
+       .newlink                = ovpn_newlink,
+       .dellink                = ovpn_dellink,

What is the purpose of creating and destroying interfaces via RTNL, but performing all other operations using the dedicated netlink protocol?

Quoted 7 lines

RTNL interface usually implemented for some standalone interface types, e.g. VLAN, GRE, etc. Here we need a userspace application anyway to be able to use the network device to forward traffic, and the module implements the dedicated GENL protocol. So why not just introduce OVPN_CMD_NEW_IFACE and OVPN_CMD_DEL_IFACE commands to the GENL interface? It looks like this will simplify the userspace part by using the single GENL interface for any management operations.

Quoted 2 lines

As Stephen also said in his reply, I tried to stick to the standard approach of creating interface via RTNL (which is also netlink).

Quoted 8 lines

Probably there is no such thing as a standard here. There is a common good practice to use RTNL to create a virtual network device if it can be used just after creation. What is a quite common case. But an openvpn network device remains useless once created until someone adds a peer configuration using the GENL-based management interface. Therefore, I still think that the RTNL management in this particular case is a dead-end. See my answer to Stephen for more details and examples.

Yeah, you have very good points here as well.

I am thinking at wifi/vap interfaces: they are also created via GENL (nl80211) and not via RTNL. On top of that, in order to create an AP iface you are really supposed to run hostapd - you can't normally create a standalone AP iface without the daemon running.

And OpenVPN is somewhat similar as you need the daemon to be running in order to do something useful with the iface.

Quoted 10 lines
Quoted 7 lines

With this implementation you can already create an interface as:

ip link add vpn0 type ovpn-dco

Eventually I will patch iproute2 to support some options as well (we have one only for now).

What do you think about using ip-l2tp(8) instead of ip-link(8) as a reference implementation for the openvpn devices management?

I had a look - L2TP is a bit simpler as it does not carry encryption, keys and key renewal. Other than that I think the approach the approach I took is somewhat similar.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
drivers/net/ovpn-dco/main.c new file +2 -0
+       .get_num_tx_queues      = ovpn_num_queues,
+       .get_num_rx_queues      = ovpn_num_queues,
Quoted 8 lines
Quoted 3 lines

What is the benefit of requesting multiple queues if the xmit callback places all packets from those kernel queues into the single internal queue anyway?

Good point. This is one of those aspects where I was hoping to get some guidance.
In any case, I will double check if having more than one queue is really what we want or not.

Quoted 5 lines

Start with a single queue, make a stable implementation, merge it into the kernel so you have a good basis for future performance optimizations. Anyway, the single queue implementation inside the kernel will be much faster than the userspace implementation with the double memory copying.

Makes sense. Will branch off my implementation and test a bit with a single queue.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

drivers/net/ovpn-dco/main.c line 232

Quoted 8 lines
drivers/net/ovpn-dco/main.c new file +7 -0
+};
+
+static int __init ovpn_init(void)
+{
+       int err = 0;
+
+       pr_info("%s %s -- %s\n", DRV_DESCRIPTION, DRV_VERSION, DRV_COPYRIGHT);

Is this log line really necessary for the regular module usage?

Quoted 7 lines
Quoted 3 lines

Well, it's a reasonable way to give users feedback about the module loading successfully. I see it's pretty common across drivers, so I thought to use the same approach.

Maybe it is a matter of taste, but I always consider such "hello" messages as noise in the boot log. User can check the loaded modules list with lsmod(8).

To be honest I don't have a strong opinion.
I just looked at what other drivers do and I did the same. Personally I prefer consistency across the various drivers.

Should the community decide that the "hellos" are bad, then we should probably remove them all, no?
Having all other modules say something when loaded, while ovpn stays silent may make the average user think that something went wrong, imho.

Quoted 36 lines
Quoted 28 lines
Quoted 13 lines

[skipped]

Quoted 11 lines
drivers/net/ovpn-dco/ovpn.c new file +11 -0
+static int ovpn_transport_to_userspace(struct ovpn_struct *ovpn, const struct ovpn_peer *peer,
+                                      struct sk_buff *skb)
+{
+       int ret;
+
+       ret = skb_linearize(skb);
+       if (ret < 0)
+               return ret;
+
+       ret = ovpn_netlink_send_packet(ovpn, peer, skb->data, skb->len);
+       if (ret < 0)
Quoted 8 lines
Quoted 1 line

+ return ret;

Another interesting decision. Why are you transporting the control messages via Netlink? Why not just pass them to userspace via an already existing TCP/UDP socket, like the LT2P module do, for example? Such design usually requires less changes to the userspace application since it is still able to process control messages as earlier by reading them from the socket.

As far as I understand the L2TP module implementes its own protocol (IPPROTO_L2TP).

In the ovpn-dco case userspace simply opens a normal UDP or TCP socket (as it always used to do), which is later passed to the kernel.

Quoted 7 lines

In ovpn-dco (kernel) we then use udp_tunnel to take over the UDP socket, while we change the socket ops in case of TCP.

While in the UDP case it would be possible to still use the socket to send control packets, in the TCP case this would not work and we would need another method (which is netlink) to send/receive packets from userspace.

Quoted 6 lines

Even if you intercept the whole incoming traffic in the kernel, you can still pass some of it to userspace. You just need to override some socket protocol ops. See TLS implementation for example (/net/tls/{tls_main.c,tls_sw.c}) and c46234ebb4d1 ("tls: RX path for ktls"). The same is possible for outgoing traffic too.

Thanks for the pointer!

It's indeed interesting although not straightforward.
I am diving in the ktls code to understand if this is applicable to ovpn as well.

Quoted 125 lines
Quoted 125 lines

At this point we did not want to treat TCP and UDP sockets differently, so we decided to always use netlink to send control packets to/from userspace.

Quoted 120 lines
Quoted 4 lines
drivers/net/ovpn-dco/ovpn.c new file +3 -0
+       consume_skb(skb);
+       return 0;
+}

[skipped]

Quoted 99 lines
include/uapi/linux/ovpn_dco.h new file +93 -0
new file mode 100644
index 000000000000..6afee8b3fedd
@@ -0,0 +1,265 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ *  OpenVPN data channel accelerator
+ *
+ *  Copyright (C) 2019-2022 OpenVPN, Inc.
+ *
+ *  Author:    James Yonan <[email protected]>
+ *             Antonio Quartulli <[email protected]>
+ */
+
+#ifndef _UAPI_LINUX_OVPN_DCO_H_
+#define _UAPI_LINUX_OVPN_DCO_H_
+
+#define OVPN_NL_NAME "ovpn-dco"
+
+#define OVPN_NL_MULTICAST_GROUP_PEERS "peers"
+
+/**
+ * enum ovpn_nl_commands - supported netlink commands
+ */
+enum ovpn_nl_commands {
+       /**
+        * @OVPN_CMD_UNSPEC: unspecified command to catch errors
+        */
+       OVPN_CMD_UNSPEC = 0,
+
+       /**
+        * @OVPN_CMD_NEW_PEER: Configure peer with its crypto keys
+        */
+       OVPN_CMD_NEW_PEER,
+
+       /**
+        * @OVPN_CMD_SET_PEER: Tweak parameters for an existing peer
+        */
+       OVPN_CMD_SET_PEER,
+
+       /**
+        * @OVPN_CMD_DEL_PEER: Remove peer from internal table
+        */
+       OVPN_CMD_DEL_PEER,
+
+       OVPN_CMD_NEW_KEY,
+
+       OVPN_CMD_SWAP_KEYS,
+
+       OVPN_CMD_DEL_KEY,
+
+       /**
+        * @OVPN_CMD_REGISTER_PACKET: Register for specific packet types to be
+        * forwarded to userspace
+        */
+       OVPN_CMD_REGISTER_PACKET,
+
+       /**
+        * @OVPN_CMD_PACKET: Send a packet from userspace to kernelspace. Also
+        * used to send to userspace packets for which a process had registered
+        * with OVPN_CMD_REGISTER_PACKET
+        */
+       OVPN_CMD_PACKET,
+
+       /**
+        * @OVPN_CMD_GET_PEER: Retrieve the status of a peer or all peers
+        */
+       OVPN_CMD_GET_PEER,
+};
+
+enum ovpn_cipher_alg {
+       /**
+        * @OVPN_CIPHER_ALG_NONE: No encryption - reserved for debugging only
+        */
+       OVPN_CIPHER_ALG_NONE = 0,
+       /**
+        * @OVPN_CIPHER_ALG_AES_GCM: AES-GCM AEAD cipher with any allowed key size
+        */
+       OVPN_CIPHER_ALG_AES_GCM,
+       /**
+        * @OVPN_CIPHER_ALG_CHACHA20_POLY1305: ChaCha20Poly1305 AEAD cipher
+        */
+       OVPN_CIPHER_ALG_CHACHA20_POLY1305,
+};
+
+enum ovpn_del_peer_reason {
+       __OVPN_DEL_PEER_REASON_FIRST,
+       OVPN_DEL_PEER_REASON_TEARDOWN = __OVPN_DEL_PEER_REASON_FIRST,
+       OVPN_DEL_PEER_REASON_USERSPACE,
+       OVPN_DEL_PEER_REASON_EXPIRED,
+       OVPN_DEL_PEER_REASON_TRANSPORT_ERROR,
+       __OVPN_DEL_PEER_REASON_AFTER_LAST
+};
+
+enum ovpn_key_slot {
+       __OVPN_KEY_SLOT_FIRST,
+       OVPN_KEY_SLOT_PRIMARY = __OVPN_KEY_SLOT_FIRST,

include/uapi/linux/ovpn_dco.h line 103

Quoted 10 lines
include/uapi/linux/ovpn_dco.h new file +10 -0
+       OVPN_KEY_SLOT_SECONDARY,
+       __OVPN_KEY_SLOT_AFTER_LAST,
+};
+
+enum ovpn_netlink_attrs {
+       OVPN_ATTR_UNSPEC = 0,
+       OVPN_ATTR_IFINDEX,
+       OVPN_ATTR_NEW_PEER,
+       OVPN_ATTR_SET_PEER,
+       OVPN_ATTR_DEL_PEER,

What is the purpose of introducing separate attributes for each NEW/SET/GET/DEL operation? Why not just use a single OVPN_ATTR_PEER attribute?

Quoted 6 lines
Quoted 3 lines

The idea is to have a subobject for each operation. Each specific subobject would then contain only the specific attributes allowed for that object. This way attributes from different operations are not mixed.

I am still puzzled. What is the reason to not mix attributes from different operations if they are operations on the same object?

The reason is that different operations on the same object may expect different attributes.

For example, the current implementation expects the user calling NEW_PEER to pass the fd of the transport socket and the VPN IP associated with the client.

Those two are not supposed to be changed later on, therefore the SET_PEER does not allow such attributes to be specified.

If we had all the attributes in one single set, the user would not know which attributes are expected by NEW_PEER and which by SET_PEER.

Makes any sense? :-)

Quoted 123 lines
Quoted 9 lines
Quoted 7 lines

BTW, generic netlink for some time allows you to have a dedicated set of attributes (and corresponding policies) for each message. So, if you have different object types (e.g. peers, interfaces, keys) you can avoid creating a common set of attributes to cover them all at once, but just create several attribute sets, one set per each object type with corresponding policies (see policy field of the genl_ops struct).

mh interesting. Any module I could look at that implements this approach?

See ./kernel/taskstats.c:672 for example

Quoted 111 lines
Quoted 88 lines
Quoted 88 lines
include/uapi/linux/ovpn_dco.h new file +88 -0
+       OVPN_ATTR_NEW_KEY,
+       OVPN_ATTR_SWAP_KEYS,
+       OVPN_ATTR_DEL_KEY,
+       OVPN_ATTR_PACKET,
+       OVPN_ATTR_GET_PEER,
+
+       __OVPN_ATTR_AFTER_LAST,
+       OVPN_ATTR_MAX = __OVPN_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_key_dir_attrs {
+       OVPN_KEY_DIR_ATTR_UNSPEC = 0,
+       OVPN_KEY_DIR_ATTR_CIPHER_KEY,
+       OVPN_KEY_DIR_ATTR_NONCE_TAIL,
+
+       __OVPN_KEY_DIR_ATTR_AFTER_LAST,
+       OVPN_KEY_DIR_ATTR_MAX = __OVPN_KEY_DIR_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_new_key_attrs {
+       OVPN_NEW_KEY_ATTR_UNSPEC = 0,
+       OVPN_NEW_KEY_ATTR_PEER_ID,
+       OVPN_NEW_KEY_ATTR_KEY_SLOT,
+       OVPN_NEW_KEY_ATTR_KEY_ID,
+       OVPN_NEW_KEY_ATTR_CIPHER_ALG,
+       OVPN_NEW_KEY_ATTR_ENCRYPT_KEY,
+       OVPN_NEW_KEY_ATTR_DECRYPT_KEY,
+
+       __OVPN_NEW_KEY_ATTR_AFTER_LAST,
+       OVPN_NEW_KEY_ATTR_MAX = __OVPN_NEW_KEY_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_del_key_attrs {
+       OVPN_DEL_KEY_ATTR_UNSPEC = 0,
+       OVPN_DEL_KEY_ATTR_PEER_ID,
+       OVPN_DEL_KEY_ATTR_KEY_SLOT,
+
+       __OVPN_DEL_KEY_ATTR_AFTER_LAST,
+       OVPN_DEL_KEY_ATTR_MAX = __OVPN_DEL_KEY_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_swap_keys_attrs {
+       OVPN_SWAP_KEYS_ATTR_UNSPEC = 0,
+       OVPN_SWAP_KEYS_ATTR_PEER_ID,
+
+       __OVPN_SWAP_KEYS_ATTR_AFTER_LAST,
+       OVPN_SWAP_KEYS_ATTR_MAX = __OVPN_SWAP_KEYS_ATTR_AFTER_LAST - 1,
+
+};
+
+enum ovpn_netlink_new_peer_attrs {
+       OVPN_NEW_PEER_ATTR_UNSPEC = 0,
+       OVPN_NEW_PEER_ATTR_PEER_ID,
+       OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE,
+       OVPN_NEW_PEER_ATTR_SOCKET,
+       OVPN_NEW_PEER_ATTR_IPV4,
+       OVPN_NEW_PEER_ATTR_IPV6,
+       OVPN_NEW_PEER_ATTR_LOCAL_IP,
+
+       __OVPN_NEW_PEER_ATTR_AFTER_LAST,
+       OVPN_NEW_PEER_ATTR_MAX = __OVPN_NEW_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_set_peer_attrs {
+       OVPN_SET_PEER_ATTR_UNSPEC = 0,
+       OVPN_SET_PEER_ATTR_PEER_ID,
+       OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL,
+       OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT,
+
+       __OVPN_SET_PEER_ATTR_AFTER_LAST,
+       OVPN_SET_PEER_ATTR_MAX = __OVPN_SET_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_del_peer_attrs {
+       OVPN_DEL_PEER_ATTR_UNSPEC = 0,
+       OVPN_DEL_PEER_ATTR_REASON,
+       OVPN_DEL_PEER_ATTR_PEER_ID,
+
+       __OVPN_DEL_PEER_ATTR_AFTER_LAST,
+       OVPN_DEL_PEER_ATTR_MAX = __OVPN_DEL_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_get_peer_attrs {
+       OVPN_GET_PEER_ATTR_UNSPEC = 0,
+       OVPN_GET_PEER_ATTR_PEER_ID,
+
+       __OVPN_GET_PEER_ATTR_AFTER_LAST,
+       OVPN_GET_PEER_ATTR_MAX = __OVPN_GET_PEER_ATTR_AFTER_LAST - 1,
Quoted 8 lines

include/uapi/linux/ovpn_dco.h line 192

Quoted 1 line
include/uapi/linux/ovpn_dco.h new file +1 -0
+};

What is the reason to create a separate set of attributes per each operation? In my experience, it is easier to use a common set of attributes for all operations on the same object type. At least it is easier to manage one enum instead of four. And you are always sure that attributes with the same semantics (e.g. remote IP) have the same id in any GET/SET message.

The reason is mostly documentation.

In my experience (which is mostly wifi related), when using a single set of attributes is (almost) impossible to understand which attributes have to be sent along with a specific command.
I always had to look at the actual netlink handlers implementation.

With this approach, instead, I can point out immediately what attributes are related to which command.

Maybe this is not the best approach, but I wanted a way that allows a developer to immediately understand the ovpn-dco API without having to read the code in ovpn-dco/netlink.c

Quoted 8 lines
Quoted 1 line

What do you think?

Looks like the other extreme. By avoiding the case of one set of attributes for any command, we got a special set of attributes per each command.

Is it conceptually possible to implement the approach with a per-object set of attributes?

I believe my answer above addresses this question as well.

Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
include/uapi/linux/ovpn_dco.h new file +64 -0
+enum ovpn_netlink_get_peer_response_attrs {
+       OVPN_GET_PEER_RESP_ATTR_UNSPEC = 0,
+       OVPN_GET_PEER_RESP_ATTR_PEER_ID,
+       OVPN_GET_PEER_RESP_ATTR_SOCKADDR_REMOTE,
+       OVPN_GET_PEER_RESP_ATTR_IPV4,
+       OVPN_GET_PEER_RESP_ATTR_IPV6,
+       OVPN_GET_PEER_RESP_ATTR_LOCAL_IP,
+       OVPN_GET_PEER_RESP_ATTR_LOCAL_PORT,
+       OVPN_GET_PEER_RESP_ATTR_KEEPALIVE_INTERVAL,
+       OVPN_GET_PEER_RESP_ATTR_KEEPALIVE_TIMEOUT,
+       OVPN_GET_PEER_RESP_ATTR_RX_BYTES,
+       OVPN_GET_PEER_RESP_ATTR_TX_BYTES,
+       OVPN_GET_PEER_RESP_ATTR_RX_PACKETS,
+       OVPN_GET_PEER_RESP_ATTR_TX_PACKETS,
+
+       __OVPN_GET_PEER_RESP_ATTR_AFTER_LAST,
+       OVPN_GET_PEER_RESP_ATTR_MAX = __OVPN_GET_PEER_RESP_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_peer_stats_attrs {
+       OVPN_PEER_STATS_ATTR_UNSPEC = 0,
+       OVPN_PEER_STATS_BYTES,
+       OVPN_PEER_STATS_PACKETS,
+
+       __OVPN_PEER_STATS_ATTR_AFTER_LAST,
+       OVPN_PEER_STATS_ATTR_MAX = __OVPN_PEER_STATS_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_peer_attrs {
+       OVPN_PEER_ATTR_UNSPEC = 0,
+       OVPN_PEER_ATTR_PEER_ID,
+       OVPN_PEER_ATTR_SOCKADDR_REMOTE,
+       OVPN_PEER_ATTR_IPV4,
+       OVPN_PEER_ATTR_IPV6,
+       OVPN_PEER_ATTR_LOCAL_IP,
+       OVPN_PEER_ATTR_KEEPALIVE_INTERVAL,
+       OVPN_PEER_ATTR_KEEPALIVE_TIMEOUT,
+       OVPN_PEER_ATTR_ENCRYPT_KEY,
+       OVPN_PEER_ATTR_DECRYPT_KEY,
+       OVPN_PEER_ATTR_RX_STATS,
+       OVPN_PEER_ATTR_TX_STATS,
+
+       __OVPN_PEER_ATTR_AFTER_LAST,
+       OVPN_PEER_ATTR_MAX = __OVPN_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_packet_attrs {
+       OVPN_PACKET_ATTR_UNSPEC = 0,
+       OVPN_PACKET_ATTR_PACKET,
+       OVPN_PACKET_ATTR_PEER_ID,
+
+       __OVPN_PACKET_ATTR_AFTER_LAST,
+       OVPN_PACKET_ATTR_MAX = __OVPN_PACKET_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_ifla_attrs {
+       IFLA_OVPN_UNSPEC = 0,
+       IFLA_OVPN_MODE,
+
+       __IFLA_OVPN_AFTER_LAST,
+       IFLA_OVPN_MAX = __IFLA_OVPN_AFTER_LAST - 1,
+};
+
+enum ovpn_mode {
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines

include/uapi/linux/ovpn_dco.h line 265

Quoted 8 lines
include/uapi/linux/ovpn_dco.h new file +8 -0
+       __OVPN_MODE_FIRST = 0,
+       OVPN_MODE_P2P = __OVPN_MODE_FIRST,
+       OVPN_MODE_MP,
+
+       __OVPN_MODE_AFTER_LAST,
+};
+
+#endif /* _UAPI_LINUX_OVPN_DCO_H_ */

Cheers,

Signature · 2 lines
Antonio Quartulli
OpenVPN Inc.
#24 lore raw

Re: [RFC v2] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Hello Antonio,

Quoted 36 lines · Antonio Quartulli
Quoted 24 lines · Sergey Ryazanov
Quoted 21 lines
Quoted 13 lines

drivers/net/ovpn-dco/main.c line 223

Quoted 8 lines
drivers/net/ovpn-dco/main.c new file +8 -0
+static struct rtnl_link_ops ovpn_link_ops __read_mostly = {
+       .kind                   = DRV_NAME,
+       .priv_size              = sizeof(struct ovpn_struct),
+       .setup                  = ovpn_setup,
+       .policy                 = ovpn_policy,
+       .maxtype                = IFLA_OVPN_MAX,
+       .newlink                = ovpn_newlink,
+       .dellink                = ovpn_dellink,

What is the purpose of creating and destroying interfaces via RTNL, but performing all other operations using the dedicated netlink protocol?

Quoted 7 lines

RTNL interface usually implemented for some standalone interface types, e.g. VLAN, GRE, etc. Here we need a userspace application anyway to be able to use the network device to forward traffic, and the module implements the dedicated GENL protocol. So why not just introduce OVPN_CMD_NEW_IFACE and OVPN_CMD_DEL_IFACE commands to the GENL interface? It looks like this will simplify the userspace part by using the single GENL interface for any management operations.

Quoted 2 lines

As Stephen also said in his reply, I tried to stick to the standard approach of creating interface via RTNL (which is also netlink).

Quoted 8 lines

Probably there is no such thing as a standard here. There is a common good practice to use RTNL to create a virtual network device if it can be used just after creation. What is a quite common case. But an openvpn network device remains useless once created until someone adds a peer configuration using the GENL-based management interface. Therefore, I still think that the RTNL management in this particular case is a dead-end. See my answer to Stephen for more details and examples.

Yeah, you have very good points here as well.

Quoted 7 lines

I am thinking at wifi/vap interfaces: they are also created via GENL (nl80211) and not via RTNL. On top of that, in order to create an AP iface you are really supposed to run hostapd - you can't normally create a standalone AP iface without the daemon running.

And OpenVPN is somewhat similar as you need the daemon to be running in order to do something useful with the iface.

Yep, NL80211 is also a good example. Probably, some wireless management operations can be expressed using RTNL. But in general this interface will never be fully functional due to the inability of augmenting it with new subsystem specific message types (new objects). So cfg80211 does not have an RTNL interface at all.

Quoted 28 lines
Quoted 9 lines
Quoted 6 lines

With this implementation you can already create an interface as:

ip link add vpn0 type ovpn-dco

Eventually I will patch iproute2 to support some options as well (we have one only for now).

What do you think about using ip-l2tp(8) instead of ip-link(8) as a reference implementation for the openvpn devices management?

I had a look - L2TP is a bit simpler as it does not carry encryption, keys and key renewal. Other than that I think the approach the approach I took is somewhat similar.

Quoted 14 lines
Quoted 13 lines
Quoted 9 lines

drivers/net/ovpn-dco/main.c line 232

Quoted 7 lines
drivers/net/ovpn-dco/main.c new file +7 -0
+};
+
+static int __init ovpn_init(void)
+{
+       int err = 0;
+
+       pr_info("%s %s -- %s\n", DRV_DESCRIPTION, DRV_VERSION, DRV_COPYRIGHT);

Is this log line really necessary for the regular module usage?

Well, it's a reasonable way to give users feedback about the module loading successfully. I see it's pretty common across drivers, so I thought to use the same approach.

Quoted 7 lines
Quoted 3 lines

Maybe it is a matter of taste, but I always consider such "hello" messages as noise in the boot log. User can check the loaded modules list with lsmod(8).

To be honest I don't have a strong opinion.
I just looked at what other drivers do and I did the same. Personally I prefer consistency across the various drivers.

I also like to add hello/tracing messages to init and exit functions at the earlier module development stage. But then I drop this trace before release, due to the rule of silence: when a program has nothing surprising to say, it should say nothing.

As far as I know, there are no rules related to printing a hello message. So it is up to you to print or not to print. I just want to show that there are some reasons not to.

Quoted 2 lines

Should the community decide that the "hellos" are bad, then we should probably remove them all, no?

Yes, you are right. Perhaps someday I or someone else will get tired of digging into dmesg so much that they will overcome their laziness and send an RFC patch that removes most of these messages.

Quoted 2 lines

Having all other modules say something when loaded, while ovpn stays silent may make the average user think that something went wrong, imho.

It is possible that some drivers are still printing a hello message in the log. And, most likely, these are old drivers that were developed out-of-tree for a long time, and then were merged into the tree as is. But I can not agree that this is a common practice. E.g. my laptop runs a kernel with 50+ modules, and only a few of them print a hello
message: USB HID, Intel Ethernet and Wi-Fi drivers, and the VLAN supporting module. The last one, in earlier times, printed as many as two lines of hello, so now it behaves decently :)

Quoted 128 lines
Quoted 114 lines
Quoted 114 lines
Quoted 113 lines
Quoted 99 lines
include/uapi/linux/ovpn_dco.h new file +93 -0
new file mode 100644
index 000000000000..6afee8b3fedd
@@ -0,0 +1,265 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ *  OpenVPN data channel accelerator
+ *
+ *  Copyright (C) 2019-2022 OpenVPN, Inc.
+ *
+ *  Author:    James Yonan <[email protected]>
+ *             Antonio Quartulli <[email protected]>
+ */
+
+#ifndef _UAPI_LINUX_OVPN_DCO_H_
+#define _UAPI_LINUX_OVPN_DCO_H_
+
+#define OVPN_NL_NAME "ovpn-dco"
+
+#define OVPN_NL_MULTICAST_GROUP_PEERS "peers"
+
+/**
+ * enum ovpn_nl_commands - supported netlink commands
+ */
+enum ovpn_nl_commands {
+       /**
+        * @OVPN_CMD_UNSPEC: unspecified command to catch errors
+        */
+       OVPN_CMD_UNSPEC = 0,
+
+       /**
+        * @OVPN_CMD_NEW_PEER: Configure peer with its crypto keys
+        */
+       OVPN_CMD_NEW_PEER,
+
+       /**
+        * @OVPN_CMD_SET_PEER: Tweak parameters for an existing peer
+        */
+       OVPN_CMD_SET_PEER,
+
+       /**
+        * @OVPN_CMD_DEL_PEER: Remove peer from internal table
+        */
+       OVPN_CMD_DEL_PEER,
+
+       OVPN_CMD_NEW_KEY,
+
+       OVPN_CMD_SWAP_KEYS,
+
+       OVPN_CMD_DEL_KEY,
+
+       /**
+        * @OVPN_CMD_REGISTER_PACKET: Register for specific packet types to be
+        * forwarded to userspace
+        */
+       OVPN_CMD_REGISTER_PACKET,
+
+       /**
+        * @OVPN_CMD_PACKET: Send a packet from userspace to kernelspace. Also
+        * used to send to userspace packets for which a process had registered
+        * with OVPN_CMD_REGISTER_PACKET
+        */
+       OVPN_CMD_PACKET,
+
+       /**
+        * @OVPN_CMD_GET_PEER: Retrieve the status of a peer or all peers
+        */
+       OVPN_CMD_GET_PEER,
+};
+
+enum ovpn_cipher_alg {
+       /**
+        * @OVPN_CIPHER_ALG_NONE: No encryption - reserved for debugging only
+        */
+       OVPN_CIPHER_ALG_NONE = 0,
+       /**
+        * @OVPN_CIPHER_ALG_AES_GCM: AES-GCM AEAD cipher with any allowed key size
+        */
+       OVPN_CIPHER_ALG_AES_GCM,
+       /**
+        * @OVPN_CIPHER_ALG_CHACHA20_POLY1305: ChaCha20Poly1305 AEAD cipher
+        */
+       OVPN_CIPHER_ALG_CHACHA20_POLY1305,
+};
+
+enum ovpn_del_peer_reason {
+       __OVPN_DEL_PEER_REASON_FIRST,
+       OVPN_DEL_PEER_REASON_TEARDOWN = __OVPN_DEL_PEER_REASON_FIRST,
+       OVPN_DEL_PEER_REASON_USERSPACE,
+       OVPN_DEL_PEER_REASON_EXPIRED,
+       OVPN_DEL_PEER_REASON_TRANSPORT_ERROR,
+       __OVPN_DEL_PEER_REASON_AFTER_LAST
+};
+
+enum ovpn_key_slot {
+       __OVPN_KEY_SLOT_FIRST,
+       OVPN_KEY_SLOT_PRIMARY = __OVPN_KEY_SLOT_FIRST,

include/uapi/linux/ovpn_dco.h line 103

Quoted 10 lines
include/uapi/linux/ovpn_dco.h new file +10 -0
+       OVPN_KEY_SLOT_SECONDARY,
+       __OVPN_KEY_SLOT_AFTER_LAST,
+};
+
+enum ovpn_netlink_attrs {
+       OVPN_ATTR_UNSPEC = 0,
+       OVPN_ATTR_IFINDEX,
+       OVPN_ATTR_NEW_PEER,
+       OVPN_ATTR_SET_PEER,
+       OVPN_ATTR_DEL_PEER,

What is the purpose of introducing separate attributes for each NEW/SET/GET/DEL operation? Why not just use a single OVPN_ATTR_PEER attribute?

Quoted 6 lines
Quoted 3 lines

The idea is to have a subobject for each operation. Each specific subobject would then contain only the specific attributes allowed for that object. This way attributes from different operations are not mixed.

I am still puzzled. What is the reason to not mix attributes from different operations if they are operations on the same object?

The reason is that different operations on the same object may expect different attributes.

For example, the current implementation expects the user calling NEW_PEER to pass the fd of the transport socket and the VPN IP associated with the client.

Quoted 7 lines

Those two are not supposed to be changed later on, therefore the SET_PEER does not allow such attributes to be specified.

If we had all the attributes in one single set, the user would not know which attributes are expected by NEW_PEER and which by SET_PEER.

Makes any sense? :-)

Hmm, sounds interesting. What do you think about limiting attributes with the GENL policies? Are they not enough to clearly show which attributes are allowed and which are not for each operation?

BTW, thanks to Johannes, since the v5.10 release, usespace may dump GENL family policies from the kernel to discover what the kernel actually supports.

I spend so much time discussing attribute sets since they are hard to change as soon as they become an API. And I am afraid of hard-to-debug errors caused by similar constant names. E.g.

enum ovpn_netlink_get_peer_response_attrs {
...
OVPN_GET_PEER_RESP_ATTR_LOCAL_PORT = 6, OVPN_GET_PEER_RESP_ATTR_KEEPALIVE_INTERVAL = 7,
...
};

enum ovpn_netlink_peer_attrs {
    ...
    OVPN_PEER_ATTR_KEEPALIVE_INTERVAL = 6,
    ...
};

In userspace, it is easy to write code like this (assuming libnl usage):

void peer_nlmsg2data(struct genlmsghdr *msg, struct peer *p)

{
    ...
    nla_parse(tb, ..., genlmsg_attrdata(msg, 0), ...);
    ...
    p->ka_int = tb[OVPN_PEER_ATTR_KEEPALIVE_INTERVAL];
    ...
}

Now the ka_int field contains the local port number.

The similar error could be made in the kernel code:

static int send_peer_data(..., struct peer *p)

{
    ...
    genlmsg_put(skb, ..., OVPN_CMD_NEW_PEER);
    nla_put_u32(skb, OVPN_PEER_ATTR_KEEPALIVE_INTERVAL, p->ka_it);
    ...
    return genlmsg_reply(skb, ...);
}

Here, the kernel will return the keep-alive interval inside the local port attribute.

By these examples, I would like to show how easy it is to make a mistake when you have many constants with similar names. The worst thing about this case is that a code will compile successfully, but will not work as expected. And such bugs can stay unnoticed for a long time.

Quoted 206 lines
Quoted 122 lines
Quoted 8 lines
Quoted 6 lines

BTW, generic netlink for some time allows you to have a dedicated set of attributes (and corresponding policies) for each message. So, if you have different object types (e.g. peers, interfaces, keys) you can avoid creating a common set of attributes to cover them all at once, but just create several attribute sets, one set per each object type with corresponding policies (see policy field of the genl_ops struct).

mh interesting. Any module I could look at that implements this approach?

See ./kernel/taskstats.c:672 for example

Quoted 111 lines
Quoted 88 lines
Quoted 88 lines
include/uapi/linux/ovpn_dco.h new file +88 -0
+       OVPN_ATTR_NEW_KEY,
+       OVPN_ATTR_SWAP_KEYS,
+       OVPN_ATTR_DEL_KEY,
+       OVPN_ATTR_PACKET,
+       OVPN_ATTR_GET_PEER,
+
+       __OVPN_ATTR_AFTER_LAST,
+       OVPN_ATTR_MAX = __OVPN_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_key_dir_attrs {
+       OVPN_KEY_DIR_ATTR_UNSPEC = 0,
+       OVPN_KEY_DIR_ATTR_CIPHER_KEY,
+       OVPN_KEY_DIR_ATTR_NONCE_TAIL,
+
+       __OVPN_KEY_DIR_ATTR_AFTER_LAST,
+       OVPN_KEY_DIR_ATTR_MAX = __OVPN_KEY_DIR_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_new_key_attrs {
+       OVPN_NEW_KEY_ATTR_UNSPEC = 0,
+       OVPN_NEW_KEY_ATTR_PEER_ID,
+       OVPN_NEW_KEY_ATTR_KEY_SLOT,
+       OVPN_NEW_KEY_ATTR_KEY_ID,
+       OVPN_NEW_KEY_ATTR_CIPHER_ALG,
+       OVPN_NEW_KEY_ATTR_ENCRYPT_KEY,
+       OVPN_NEW_KEY_ATTR_DECRYPT_KEY,
+
+       __OVPN_NEW_KEY_ATTR_AFTER_LAST,
+       OVPN_NEW_KEY_ATTR_MAX = __OVPN_NEW_KEY_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_del_key_attrs {
+       OVPN_DEL_KEY_ATTR_UNSPEC = 0,
+       OVPN_DEL_KEY_ATTR_PEER_ID,
+       OVPN_DEL_KEY_ATTR_KEY_SLOT,
+
+       __OVPN_DEL_KEY_ATTR_AFTER_LAST,
+       OVPN_DEL_KEY_ATTR_MAX = __OVPN_DEL_KEY_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_swap_keys_attrs {
+       OVPN_SWAP_KEYS_ATTR_UNSPEC = 0,
+       OVPN_SWAP_KEYS_ATTR_PEER_ID,
+
+       __OVPN_SWAP_KEYS_ATTR_AFTER_LAST,
+       OVPN_SWAP_KEYS_ATTR_MAX = __OVPN_SWAP_KEYS_ATTR_AFTER_LAST - 1,
+
+};
+
+enum ovpn_netlink_new_peer_attrs {
+       OVPN_NEW_PEER_ATTR_UNSPEC = 0,
+       OVPN_NEW_PEER_ATTR_PEER_ID,
+       OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE,
+       OVPN_NEW_PEER_ATTR_SOCKET,
+       OVPN_NEW_PEER_ATTR_IPV4,
+       OVPN_NEW_PEER_ATTR_IPV6,
+       OVPN_NEW_PEER_ATTR_LOCAL_IP,
+
+       __OVPN_NEW_PEER_ATTR_AFTER_LAST,
+       OVPN_NEW_PEER_ATTR_MAX = __OVPN_NEW_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_set_peer_attrs {
+       OVPN_SET_PEER_ATTR_UNSPEC = 0,
+       OVPN_SET_PEER_ATTR_PEER_ID,
+       OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL,
+       OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT,
+
+       __OVPN_SET_PEER_ATTR_AFTER_LAST,
+       OVPN_SET_PEER_ATTR_MAX = __OVPN_SET_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_del_peer_attrs {
+       OVPN_DEL_PEER_ATTR_UNSPEC = 0,
+       OVPN_DEL_PEER_ATTR_REASON,
+       OVPN_DEL_PEER_ATTR_PEER_ID,
+
+       __OVPN_DEL_PEER_ATTR_AFTER_LAST,
+       OVPN_DEL_PEER_ATTR_MAX = __OVPN_DEL_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_get_peer_attrs {
+       OVPN_GET_PEER_ATTR_UNSPEC = 0,
+       OVPN_GET_PEER_ATTR_PEER_ID,
+
+       __OVPN_GET_PEER_ATTR_AFTER_LAST,
+       OVPN_GET_PEER_ATTR_MAX = __OVPN_GET_PEER_ATTR_AFTER_LAST - 1,
Quoted 8 lines

include/uapi/linux/ovpn_dco.h line 192

Quoted 1 line
include/uapi/linux/ovpn_dco.h new file +1 -0
+};

What is the reason to create a separate set of attributes per each operation? In my experience, it is easier to use a common set of attributes for all operations on the same object type. At least it is easier to manage one enum instead of four. And you are always sure that attributes with the same semantics (e.g. remote IP) have the same id in any GET/SET message.

The reason is mostly documentation.

In my experience (which is mostly wifi related), when using a single set of attributes is (almost) impossible to understand which attributes have to be sent along with a specific command.
I always had to look at the actual netlink handlers implementation.

With this approach, instead, I can point out immediately what attributes are related to which command.

Maybe this is not the best approach, but I wanted a way that allows a developer to immediately understand the ovpn-dco API without having to read the code in ovpn-dco/netlink.c

Quoted 8 lines
Quoted 1 line

What do you think?

Looks like the other extreme. By avoiding the case of one set of attributes for any command, we got a special set of attributes per each command.

Is it conceptually possible to implement the approach with a per-object set of attributes?

I believe my answer above addresses this question as well.

Quoted 73 lines
Quoted 73 lines
Quoted 73 lines
Quoted 73 lines
include/uapi/linux/ovpn_dco.h new file +72 -0
+enum ovpn_netlink_get_peer_response_attrs {
+       OVPN_GET_PEER_RESP_ATTR_UNSPEC = 0,
+       OVPN_GET_PEER_RESP_ATTR_PEER_ID,
+       OVPN_GET_PEER_RESP_ATTR_SOCKADDR_REMOTE,
+       OVPN_GET_PEER_RESP_ATTR_IPV4,
+       OVPN_GET_PEER_RESP_ATTR_IPV6,
+       OVPN_GET_PEER_RESP_ATTR_LOCAL_IP,
+       OVPN_GET_PEER_RESP_ATTR_LOCAL_PORT,
+       OVPN_GET_PEER_RESP_ATTR_KEEPALIVE_INTERVAL,
+       OVPN_GET_PEER_RESP_ATTR_KEEPALIVE_TIMEOUT,
+       OVPN_GET_PEER_RESP_ATTR_RX_BYTES,
+       OVPN_GET_PEER_RESP_ATTR_TX_BYTES,
+       OVPN_GET_PEER_RESP_ATTR_RX_PACKETS,
+       OVPN_GET_PEER_RESP_ATTR_TX_PACKETS,
+
+       __OVPN_GET_PEER_RESP_ATTR_AFTER_LAST,
+       OVPN_GET_PEER_RESP_ATTR_MAX = __OVPN_GET_PEER_RESP_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_peer_stats_attrs {
+       OVPN_PEER_STATS_ATTR_UNSPEC = 0,
+       OVPN_PEER_STATS_BYTES,
+       OVPN_PEER_STATS_PACKETS,
+
+       __OVPN_PEER_STATS_ATTR_AFTER_LAST,
+       OVPN_PEER_STATS_ATTR_MAX = __OVPN_PEER_STATS_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_peer_attrs {
+       OVPN_PEER_ATTR_UNSPEC = 0,
+       OVPN_PEER_ATTR_PEER_ID,
+       OVPN_PEER_ATTR_SOCKADDR_REMOTE,
+       OVPN_PEER_ATTR_IPV4,
+       OVPN_PEER_ATTR_IPV6,
+       OVPN_PEER_ATTR_LOCAL_IP,
+       OVPN_PEER_ATTR_KEEPALIVE_INTERVAL,
+       OVPN_PEER_ATTR_KEEPALIVE_TIMEOUT,
+       OVPN_PEER_ATTR_ENCRYPT_KEY,
+       OVPN_PEER_ATTR_DECRYPT_KEY,
+       OVPN_PEER_ATTR_RX_STATS,
+       OVPN_PEER_ATTR_TX_STATS,
+
+       __OVPN_PEER_ATTR_AFTER_LAST,
+       OVPN_PEER_ATTR_MAX = __OVPN_PEER_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_netlink_packet_attrs {
+       OVPN_PACKET_ATTR_UNSPEC = 0,
+       OVPN_PACKET_ATTR_PACKET,
+       OVPN_PACKET_ATTR_PEER_ID,
+
+       __OVPN_PACKET_ATTR_AFTER_LAST,
+       OVPN_PACKET_ATTR_MAX = __OVPN_PACKET_ATTR_AFTER_LAST - 1,
+};
+
+enum ovpn_ifla_attrs {
+       IFLA_OVPN_UNSPEC = 0,
+       IFLA_OVPN_MODE,
+
+       __IFLA_OVPN_AFTER_LAST,
+       IFLA_OVPN_MAX = __IFLA_OVPN_AFTER_LAST - 1,
+};
+
+enum ovpn_mode {
+       __OVPN_MODE_FIRST = 0,
+       OVPN_MODE_P2P = __OVPN_MODE_FIRST,
+       OVPN_MODE_MP,
+
+       __OVPN_MODE_AFTER_LAST,
+};
+
+#endif /* _UAPI_LINUX_OVPN_DCO_H_ */
Signature · 1 line
Sergey
#25 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

In reply to Antonio Quartulli
Quoted 10 lines · Antonio Quartulli

OpenVPN is a userspace software existing since around 2005 that allows users to create secure tunnels.

So far OpenVPN has implemented all operations in userspace, which implies several back and forth between kernel and user land in order to process packets (encapsulate/decapsulate, encrypt/decrypt, rerouting..).

With ovpn-dco, we intend to move the fast path (data channel) entirely in kernel space and thus improve user measured throughput over the tunnel.

Logging trivia:

Quoted 6 lines
drivers/net/ovpn-dco/crypto.c new file +0 -0
new file mode 100644
index 000000000000..fcc3a351ba9d

drivers/net/ovpn-dco/crypto.c line 8

Quoted 8 lines
drivers/net/ovpn-dco/crypto.c new file +8 -0
@@ -0,0 +1,154 @@
+// SPDX-License-Identifier: GPL-2.0
+/*  OpenVPN data channel accelerator
+ *
+ *  Copyright (C) 2020-2022 OpenVPN, Inc.
+ *
+ *  Author:	James Yonan <[email protected]>
+ *		Antonio Quartulli <[email protected]>
+ */

Please add

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

before any #include when a logging message is output

[]

Quoted 7 lines
drivers/net/ovpn-dco/crypto.c new file +7 -0
+void ovpn_crypto_key_slot_delete(struct ovpn_crypto_state *cs,
+				 enum ovpn_key_slot slot)
+{
+	struct ovpn_crypto_key_slot *ks = NULL;
+
+	mutex_lock(&cs->mutex);
+	switch (slot) {

drivers/net/ovpn-dco/crypto.c line 119

Quoted 10 lines
drivers/net/ovpn-dco/crypto.c new file +10 -0
+	case OVPN_KEY_SLOT_PRIMARY:
+		ks = rcu_replace_pointer(cs->primary, NULL,
+					 lockdep_is_held(&cs->mutex));
+		break;
+	case OVPN_KEY_SLOT_SECONDARY:
+		ks = rcu_replace_pointer(cs->secondary, NULL,
+					 lockdep_is_held(&cs->mutex));
+		break;
+	default:
+		pr_warn("Invalid slot to release: %u\n", slot);

So messages like these are prefixed appropriately.

drivers/net/ovpn-dco/crypto_aead.c

Quoted 14 lines
drivers/net/ovpn-dco/crypto.c new file +12 -0
+		break;
+	}
+	mutex_unlock(&cs->mutex);
+
+	if (!ks) {
+		pr_debug("Key slot already released: %u\n", slot);
+		return;
+	}
+	pr_debug("deleting key slot %u, key_id=%u\n", slot, ks->key_id);
+
+	ovpn_crypto_key_slot_put(ks);
+}
drivers/net/ovpn-dco/crypto_aead.c +0 -0

[]

Quoted 16 lines
drivers/net/ovpn-dco/crypto_aead.c +16 -0
+/* Initialize a struct crypto_aead object */
+struct crypto_aead *ovpn_aead_init(const char *title, const char *alg_name,
+				   const unsigned char *key, unsigned int keylen)
+{
+	struct crypto_aead *aead;
+	int ret;
+
+	aead = crypto_alloc_aead(alg_name, 0, 0);
+	if (IS_ERR(aead)) {
+		ret = PTR_ERR(aead);
+		pr_err("%s crypto_alloc_aead failed, err=%d\n", title, ret);
+		aead = NULL;
+		goto error;
+	}
+
+	ret = crypto_aead_setkey(aead, key, keylen);

drivers/net/ovpn-dco/crypto_aead.c line 245

Quoted 10 lines
drivers/net/ovpn-dco/crypto_aead.c +10 -0
+	if (ret) {
+		pr_err("%s crypto_aead_setkey size=%u failed, err=%d\n", title,
+		       keylen, ret);
+		goto error;
+	}
+
+	ret = crypto_aead_setauthsize(aead, AUTH_TAG_SIZE);
+	if (ret) {
+		pr_err("%s crypto_aead_setauthsize failed, err=%d\n", title,
+		       ret);

Could use another #define pr_fmt(fmt) etc...

#26 lore raw

Re: [RFC 1/1] net: introduce OpenVPN Data Channel Offload (ovpn-dco)

Hello Joe,

Quoted 4 lines · Joe Perches

Please add

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

Thanks for your suggestion! Will take care of this.

Regards,

Signature · 2 lines
Antonio Quartulli
OpenVPN Inc.