From nobody Fri Dec 19 17:17:26 2025 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEE053EA98 for ; Tue, 11 Feb 2025 00:40:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739234455; cv=none; b=FF+EaArar1Ax0tR55ZR+RzkhsCGMjIHieMXApX7EXzZeCwpf9lvQjtbq/XeaNw0PAO+9eaQAJ97iGIjEhM7UjqPkfdQjrdnmRnLtBlkdMKACbb/v5x2ruhe0Ty0/hYnBn1i1tiluwAdJOslt0uJJJyJLMi1vvKK5kJJAhmMpfYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739234455; c=relaxed/simple; bh=KxQPDC0IGV3JPrTkjp/xBlK1I8aT6xVA+pSKGHDLnz0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=m8Tc3D2/gfIu7/QBJRPwRCjGLE7Q3xw45cpMDO7xTRMtCZbvOcxC9bFN8a4VcepVwvbnz585rdgI1i1l7rh/ZCFVShD3ADF19OH3Bl4K8dKceHrEAFjn9O+IKOE6yw5cHflyo6IJXvBiJ5vGnH0LEApIJZMJ3K4ohl0R0bp2JQM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=openvpn.net; spf=pass smtp.mailfrom=openvpn.com; dkim=pass (2048-bit key) header.d=openvpn.net header.i=@openvpn.net header.b=Wa/C7eT1; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=openvpn.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=openvpn.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=openvpn.net header.i=@openvpn.net header.b="Wa/C7eT1" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4361815b96cso33255385e9.1 for ; Mon, 10 Feb 2025 16:40:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1739234451; x=1739839251; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=SP8PSAJGZ8/sf3FwiWPvck6rSUcyuSXhk8wA7GgebUo=; b=Wa/C7eT1L8OGgdMkip18F0FYn6E1jVujUXeadr35wNmNAKpYs9rj0wVd2NHf4l+1OJ 1O/XuNciyetvx7+agmzXgTn4ELVkK9w5IN2l1m9w9kd719i2U8CCPjJGg5Z7BGxQxYRT 0GtIet2azwiwptqU7QxOKww4VhcWXL7iLQhuONP7ioKt1IPIp4RM2Ghfjv5ZHsLHwfLp ccUr6+wS4XxH7t8zva+cXrzkGBwR6Z0s2PnpSq6v/QYu1p4Kg7BbDDUA+aJmCVp2zHyW Od/A0j159vuGWAzlp+czMdt1eMQecH9o0vfsfpfyS7J1QZbb07jqyfocqpRaeXd0yrP0 IboQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739234451; x=1739839251; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SP8PSAJGZ8/sf3FwiWPvck6rSUcyuSXhk8wA7GgebUo=; b=M3OFe3+t6UwcEoljX621iGxkl5a6JxfBV6dFdN8O+FLSGj8CSj27IRCmSzcPMc+W1t kBL1+MeG8PYxacK3j0hPipQztfExUu15y99XM96ioCR7JxgNjmi1HdlJuqmsXnByNOAY iSDL8tuh33GYkcMUKJz+Sc1TtxBhmGon0gxoJNLVG7P+D5+u+sjQxj73/RsqSQuOeMc7 LuSP4vvdPoY5BxQ11veFB1cHBxfQQBSdQbwBP+9OGGh21yzkqEknkJThHluSzgoVDi+0 UeXB6hgu+TudKwPc4i9ML2ciL8Hz46/Yr+whXCzwUBpOEwR65NVFO5zm3yz4/LI6h9pm yTIw== X-Forwarded-Encrypted: i=1; AJvYcCU6vOgvIUe1JAH6B+/VLb9czY0Nz8zEdKLlkqC9Amk3ektLjYm6402TZ2yrSpgoDZZRjEdSI1S/slQiB4Q=@vger.kernel.org X-Gm-Message-State: AOJu0YxJJ4Ayl1t4dntPTIs9ZW+W9xAnztLBti/mO8yjKEH9+AnEJW/m Xj6ZVR6PdYWBB3f1dZXypFMX1tsCsKb1faJjWZbSQnz35YNF/lt1xkzDBDFt5tg= X-Gm-Gg: ASbGnctfX3G9O5W4jYa6HY05TUgQ9jcFY+BRidj46rVWTD0wj4lG2YJhXB0G/i979Ug QZVFHAj6GXpWpwdt49HdLmoUhZvkBvRZhOV9/VGyuVgy0a7j04uBo3dXG0LJzN2XY6t30eS3gwx NKwJslqYt4YsCNmnFJKgMJcthfZZeNrrh1ZQCYoCAMrtUVBHh1uUBCkTqGqmlqu0NBC0C16e54N TaJnJuhaG8q1b5mbMOHw/otavvOjZxg/yqXJT6TRLqjXlscCNRVBa574KmEDxiPkKIBZdzh/XfP VN0UpYJOo09xSZuH6cum8Y2fBho= X-Google-Smtp-Source: AGHT+IFQEe/GmKWmiznMHG1EOMcodxvUJSmQAHilk1m60dcg37tjbUb6O0oSe9N6aZs7i3pJN9W++Q== X-Received: by 2002:a05:600c:3b86:b0:439:4696:c071 with SMTP id 5b1f17b1804b1-4394696c404mr40546005e9.19.1739234451272; Mon, 10 Feb 2025 16:40:51 -0800 (PST) Received: from serenity.mandelbit.com ([2001:67c:2fbc:1:1255:949f:f81c:4f95]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4394dc1bed2sm3388435e9.0.2025.02.10.16.40.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 16:40:49 -0800 (PST) From: Antonio Quartulli Date: Tue, 11 Feb 2025 01:39:54 +0100 Subject: [PATCH net-next v19 01/26] net: introduce OpenVPN Data Channel Offload (ovpn) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250211-b4-ovpn-v19-1-86d5daf2a47a@openvpn.net> References: <20250211-b4-ovpn-v19-0-86d5daf2a47a@openvpn.net> In-Reply-To: <20250211-b4-ovpn-v19-0-86d5daf2a47a@openvpn.net> To: netdev@vger.kernel.org, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Donald Hunter , Antonio Quartulli , Shuah Khan , sd@queasysnail.net, ryazanov.s.a@gmail.com, Andrew Lunn Cc: Simon Horman , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Xiao Liang , steffen.klassert@secunet.com, antony.antony@secunet.com X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=8929; i=antonio@openvpn.net; h=from:subject:message-id; bh=KxQPDC0IGV3JPrTkjp/xBlK1I8aT6xVA+pSKGHDLnz0=; b=owEBbQGS/pANAwAIAQtw5TqgONWHAcsmYgBnqpyMEFvrpOvWAZb+tpodoLK51WD4NEa7v60kk N5hhMdzVm2JATMEAAEIAB0WIQSZq9xs+NQS5N5fwPwLcOU6oDjVhwUCZ6qcjAAKCRALcOU6oDjV h61wB/9r92pKzMBVmjwLMzCQ1R14zI0OfwaNbjuwv9T4lovD9Aq6R2Xliv96D78hHyXLbnJqrcO BoFyw2hrl6gmfgu7Ha4fefymx1ApFH5O3UJhu6EO7HvoucXknY9v3yT2z0H8s4vZPQuFiw3kPom LCSqPwC6qWerEi4UKmDVrG/TSQgGlDGh5hPWoA93sLPCiwIfWeNoEpiK/8aTIEdCuvO+C83icbi otfOM3ztNpSSAGYqsLpLs/loC9uVxZiBBBYzsjK0SbUDv6GFHQP6M1Ins1y+l+tyXbLJ1QLI0kp JpImrO3jp72wV+UNn01GXEA1Spr+kKhQdpfjVWbcRfEOYP5I X-Developer-Key: i=antonio@openvpn.net; a=openpgp; fpr=CABDA1282017C267219885C748F0CCB68F59D14C 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` we intend to move the fast path (data channel) entirely in kernel space and thus improve user measured throughput over the tunnel. `ovpn` 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` 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 or peer-to-peer 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 and their keys. 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` codebase is kept as compact as possible while focusing on handling data traffic only (fast path). 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 the `ovpn` kernel module, which takes ownership. From this moment on `ovpn` will handle data traffic for the new peer. When control packets are received on the link, they are forwarded to userspace through the same transport socket they were received on, as userspace is still listening to them. Some events (like peer deletion) are sent to a Netlink multicast group. Although it wasn't easy to convince the community, `ovpn` implements only a limited number of the data-channel features supported by the userspace program. Each feature that made it to `ovpn` 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. Both UDP and TCP sockets are supported. 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 the `ovpn` kernel module. This kernel module can be enabled by selecting the CONFIG_OVPN entry in the networking drivers section. NOTE: this first patch introduces the very basic framework only. Features are then added patch by patch, however, although each patch will compile and possibly not break at runtime, only after having applied the full set it is expected to see the ovpn module fully working. Cc: steffen.klassert@secunet.com Cc: antony.antony@secunet.com Signed-off-by: Antonio Quartulli --- MAINTAINERS | 8 ++++ drivers/net/Kconfig | 8 ++++ drivers/net/Makefile | 1 + drivers/net/ovpn/Makefile | 10 +++++ drivers/net/ovpn/main.c | 112 ++++++++++++++++++++++++++++++++++++++++++= ++++ 5 files changed, 139 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 873aa2cce4d7fd5fd31613edbf3d99faaf7810bd..cf138c769e6402230da346dbf71= 17dd08911d7a9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17749,6 +17749,14 @@ F: arch/openrisc/ F: drivers/irqchip/irq-ompic.c F: drivers/irqchip/irq-or1k-* =20 +OPENVPN DATA CHANNEL OFFLOAD +M: Antonio Quartulli +L: openvpn-devel@lists.sourceforge.net (subscribers-only) +L: netdev@vger.kernel.org +S: Supported +T: git https://github.com/OpenVPN/linux-kernel-ovpn.git +F: drivers/net/ovpn/ + OPENVSWITCH M: Pravin B Shelar L: netdev@vger.kernel.org diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 1fd5acdc73c6af0e1a861867039c3624fc618e25..2ace5e27c37ed3bad2e0000775c= d172cb6de3225 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -115,6 +115,14 @@ config WIREGUARD_DEBUG =20 Say N here unless you know what you're doing. =20 +config OVPN + tristate "OpenVPN data channel offload" + depends on NET && INET + depends on IPV6 || !IPV6 + help + This module enhances the performance of the OpenVPN userspace software + by offloading the data channel processing to kernelspace. + config EQUALIZER tristate "EQL (serial line load balancing) support" help diff --git a/drivers/net/Makefile b/drivers/net/Makefile index 13743d0e83b5fde479e9b30ad736be402d880dee..5152b3330e28da7eaec821018a2= 6c973bb33ce0c 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_IPVLAN) +=3D ipvlan/ obj-$(CONFIG_IPVTAP) +=3D ipvlan/ obj-$(CONFIG_DUMMY) +=3D dummy.o obj-$(CONFIG_WIREGUARD) +=3D wireguard/ +obj-$(CONFIG_OVPN) +=3D ovpn/ obj-$(CONFIG_EQUALIZER) +=3D eql.o obj-$(CONFIG_IFB) +=3D ifb.o obj-$(CONFIG_MACSEC) +=3D macsec.o diff --git a/drivers/net/ovpn/Makefile b/drivers/net/ovpn/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..ae19cf445b29367da680e226f06= a341c42c892c2 --- /dev/null +++ b/drivers/net/ovpn/Makefile @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# ovpn -- OpenVPN data channel offload in kernel space +# +# Copyright (C) 2020-2024 OpenVPN, Inc. +# +# Author: Antonio Quartulli + +obj-$(CONFIG_OVPN) :=3D ovpn.o +ovpn-y +=3D main.o diff --git a/drivers/net/ovpn/main.c b/drivers/net/ovpn/main.c new file mode 100644 index 0000000000000000000000000000000000000000..72c56e73771cdece22e50645b29= c79962f06caf3 --- /dev/null +++ b/drivers/net/ovpn/main.c @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: GPL-2.0 +/* OpenVPN data channel offload + * + * Copyright (C) 2020-2024 OpenVPN, Inc. + * + * Author: Antonio Quartulli + * James Yonan + */ + +#include +#include +#include + +static const struct net_device_ops ovpn_netdev_ops =3D { +}; + +/** + * ovpn_dev_is_valid - check if the netdevice is of type 'ovpn' + * @dev: the interface to check + * + * Return: whether the netdevice is of type 'ovpn' + */ +static bool ovpn_dev_is_valid(const struct net_device *dev) +{ + return dev->netdev_ops =3D=3D &ovpn_netdev_ops; +} + +static int ovpn_newlink(struct net *src_net, struct net_device *dev, + struct nlattr *tb[], struct nlattr *data[], + struct netlink_ext_ack *extack) +{ + return -EOPNOTSUPP; +} + +static struct rtnl_link_ops ovpn_link_ops =3D { + .kind =3D "ovpn", + .netns_refund =3D false, + .newlink =3D ovpn_newlink, + .dellink =3D unregister_netdevice_queue, +}; + +static int ovpn_netdev_notifier_call(struct notifier_block *nb, + unsigned long state, void *ptr) +{ + struct net_device *dev =3D netdev_notifier_info_to_dev(ptr); + + if (!ovpn_dev_is_valid(dev)) + return NOTIFY_DONE; + + switch (state) { + case NETDEV_REGISTER: + /* add device to internal list for later destruction upon + * unregistration + */ + break; + case NETDEV_UNREGISTER: + /* can be delivered multiple times, so check registered flag, + * then destroy the interface + */ + break; + case NETDEV_POST_INIT: + case NETDEV_GOING_DOWN: + case NETDEV_DOWN: + case NETDEV_UP: + case NETDEV_PRE_UP: + default: + return NOTIFY_DONE; + } + + return NOTIFY_OK; +} + +static struct notifier_block ovpn_netdev_notifier =3D { + .notifier_call =3D ovpn_netdev_notifier_call, +}; + +static int __init ovpn_init(void) +{ + int err =3D register_netdevice_notifier(&ovpn_netdev_notifier); + + if (err) { + pr_err("ovpn: can't register netdevice notifier: %d\n", err); + return err; + } + + err =3D rtnl_link_register(&ovpn_link_ops); + if (err) { + pr_err("ovpn: can't register rtnl link ops: %d\n", err); + goto unreg_netdev; + } + + return 0; + +unreg_netdev: + unregister_netdevice_notifier(&ovpn_netdev_notifier); + return err; +} + +static __exit void ovpn_cleanup(void) +{ + rtnl_link_unregister(&ovpn_link_ops); + unregister_netdevice_notifier(&ovpn_netdev_notifier); + + rcu_barrier(); +} + +module_init(ovpn_init); +module_exit(ovpn_cleanup); + +MODULE_DESCRIPTION("OpenVPN data channel offload (ovpn)"); +MODULE_AUTHOR("(C) 2020-2024 OpenVPN, Inc."); +MODULE_LICENSE("GPL"); --=20 2.45.3