public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: Antonio Quartulli <antonio@openvpn.net>
Cc: Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Donald Hunter <donald.hunter@gmail.com>,
	Shuah Khan <shuah@kernel.org>,
	sd@queasysnail.net, ryazanov.s.a@gmail.com,
	Andrew Lunn <andrew@lunn.ch>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net-next v9 04/23] ovpn: add basic interface creation/destruction/management routines
Date: Thu, 17 Oct 2024 08:39:04 +0200	[thread overview]
Message-ID: <ZxCxCJk6RFtc-g0F@nanopsycho.orion> (raw)
In-Reply-To: <e8e46092-c954-4579-9bdc-563bf30f68f5@openvpn.net>

Wed, Oct 16, 2024 at 04:24:09PM CEST, antonio@openvpn.net wrote:
>On 16/10/2024 10:27, Jiri Pirko wrote:
>> Wed, Oct 16, 2024 at 03:03:04AM CEST, antonio@openvpn.net wrote:
>> > Add basic infrastructure for handling ovpn interfaces.
>> > 
>> > Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
>> > ---
>> > drivers/net/ovpn/main.c       | 115 ++++++++++++++++++++++++++++++++++++++++--
>> > drivers/net/ovpn/main.h       |   7 +++
>> > drivers/net/ovpn/ovpnstruct.h |   8 +++
>> > drivers/net/ovpn/packet.h     |  40 +++++++++++++++
>> > include/uapi/linux/if_link.h  |  15 ++++++
>> > 5 files changed, 180 insertions(+), 5 deletions(-)
>> > 
>> > diff --git a/drivers/net/ovpn/main.c b/drivers/net/ovpn/main.c
>> > index d5bdb0055f4dd3a6e32dc6e792bed1e7fd59e101..eead7677b8239eb3c48bb26ca95492d88512b8d4 100644
>> > --- a/drivers/net/ovpn/main.c
>> > +++ b/drivers/net/ovpn/main.c
>> > @@ -10,18 +10,52 @@
>> > #include <linux/genetlink.h>
>> > #include <linux/module.h>
>> > #include <linux/netdevice.h>
>> > +#include <linux/inetdevice.h>
>> > +#include <net/ip.h>
>> > #include <net/rtnetlink.h>
>> > -#include <uapi/linux/ovpn.h>
>> > +#include <uapi/linux/if_arp.h>
>> > 
>> > #include "ovpnstruct.h"
>> > #include "main.h"
>> > #include "netlink.h"
>> > #include "io.h"
>> > +#include "packet.h"
>> > 
>> > /* Driver info */
>> > #define DRV_DESCRIPTION	"OpenVPN data channel offload (ovpn)"
>> > #define DRV_COPYRIGHT	"(C) 2020-2024 OpenVPN, Inc."
>> > 
>> > +static void ovpn_struct_free(struct net_device *net)
>> > +{
>> > +}
>> > +
>> > +static int ovpn_net_open(struct net_device *dev)
>> > +{
>> > +	netif_tx_start_all_queues(dev);
>> > +	return 0;
>> > +}
>> > +
>> > +static int ovpn_net_stop(struct net_device *dev)
>> > +{
>> > +	netif_tx_stop_all_queues(dev);
>> > +	return 0;
>> > +}
>> > +
>> > +static const struct net_device_ops ovpn_netdev_ops = {
>> > +	.ndo_open		= ovpn_net_open,
>> > +	.ndo_stop		= ovpn_net_stop,
>> > +	.ndo_start_xmit		= ovpn_net_xmit,
>> > +};
>> > +
>> > +static const struct device_type ovpn_type = {
>> > +	.name = OVPN_FAMILY_NAME,
>> > +};
>> > +
>> > +static const struct nla_policy ovpn_policy[IFLA_OVPN_MAX + 1] = {
>> > +	[IFLA_OVPN_MODE] = NLA_POLICY_RANGE(NLA_U8, OVPN_MODE_P2P,
>> > +					    OVPN_MODE_MP),
>> > +};
>> > +
>> > /**
>> >   * ovpn_dev_is_valid - check if the netdevice is of type 'ovpn'
>> >   * @dev: the interface to check
>> > @@ -33,16 +67,76 @@ bool ovpn_dev_is_valid(const struct net_device *dev)
>> > 	return dev->netdev_ops->ndo_start_xmit == ovpn_net_xmit;
>> > }
>> > 
>> > +static void ovpn_setup(struct net_device *dev)
>> > +{
>> > +	/* compute the overhead considering AEAD encryption */
>> > +	const int overhead = sizeof(u32) + NONCE_WIRE_SIZE + 16 +
>> > +			     sizeof(struct udphdr) +
>> > +			     max(sizeof(struct ipv6hdr), sizeof(struct iphdr));
>> > +
>> > +	netdev_features_t feat = NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_RXCSUM |
>> > +				 NETIF_F_GSO | NETIF_F_GSO_SOFTWARE |
>> > +				 NETIF_F_HIGHDMA;
>> > +
>> > +	dev->needs_free_netdev = true;
>> > +
>> > +	dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
>> > +
>> > +	dev->netdev_ops = &ovpn_netdev_ops;
>> > +
>> > +	dev->priv_destructor = ovpn_struct_free;
>> > +
>> > +	dev->hard_header_len = 0;
>> > +	dev->addr_len = 0;
>> > +	dev->mtu = ETH_DATA_LEN - overhead;
>> > +	dev->min_mtu = IPV4_MIN_MTU;
>> > +	dev->max_mtu = IP_MAX_MTU - overhead;
>> > +
>> > +	dev->type = ARPHRD_NONE;
>> > +	dev->flags = IFF_POINTOPOINT | IFF_NOARP;
>> > +	dev->priv_flags |= IFF_NO_QUEUE;
>> > +
>> > +	dev->lltx = true;
>> > +	dev->features |= feat;
>> > +	dev->hw_features |= feat;
>> > +	dev->hw_enc_features |= feat;
>> > +
>> > +	dev->needed_headroom = OVPN_HEAD_ROOM;
>> > +	dev->needed_tailroom = OVPN_MAX_PADDING;
>> > +
>> > +	SET_NETDEV_DEVTYPE(dev, &ovpn_type);
>> > +}
>> > +
>> > 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;
>> > +	struct ovpn_struct *ovpn = netdev_priv(dev);
>> > +	enum ovpn_mode mode = OVPN_MODE_P2P;
>> > +
>> > +	if (data && data[IFLA_OVPN_MODE]) {
>> > +		mode = nla_get_u8(data[IFLA_OVPN_MODE]);
>> 
>> Some sanity check perhaps? "validate" op is here for that purpose.
>
>Isn't the parsing happening here enough
>
>https://elixir.bootlin.com/linux/v6.12-rc3/source/net/core/rtnetlink.c#L3659
>
>The IFINFO_DATA is parsed using the policy I provided (which comes with
>limits for the mode attribute).

You are right, that seems enough for mode.

>
>Or am I misreading the code and I still need to provide an implementation for
>.validate?
>
>Regards,
>
>> 
>> 
>> > +		netdev_dbg(dev, "setting device mode: %u\n", mode);
>> > +	}
>> > +
>> > +	ovpn->dev = dev;
>> > +	ovpn->mode = mode;
>> > +
>> > +	/* turn carrier explicitly off after registration, this way state is
>> > +	 * clearly defined
>> > +	 */
>> > +	netif_carrier_off(dev);
>> > +
>> > +	return register_netdevice(dev);
>> 
>> [...]
>
>-- 
>Antonio Quartulli
>OpenVPN Inc.
>

  reply	other threads:[~2024-10-17  6:39 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-16  1:03 [PATCH net-next v9 00/23] Introducing OpenVPN Data Channel Offload Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 01/23] netlink: add NLA_POLICY_MAX_LEN macro Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 02/23] net: introduce OpenVPN Data Channel Offload (ovpn) Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 03/23] ovpn: add basic netlink support Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 04/23] ovpn: add basic interface creation/destruction/management routines Antonio Quartulli
2024-10-16  8:27   ` Jiri Pirko
2024-10-16 14:24     ` Antonio Quartulli
2024-10-17  6:39       ` Jiri Pirko [this message]
2024-10-16  1:03 ` [PATCH net-next v9 05/23] ovpn: keep carrier always on Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 06/23] ovpn: introduce the ovpn_peer object Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 07/23] ovpn: introduce the ovpn_socket object Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 08/23] ovpn: implement basic TX path (UDP) Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 09/23] ovpn: implement basic RX " Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 10/23] ovpn: implement packet processing Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 11/23] ovpn: store tunnel and transport statistics Antonio Quartulli
2024-10-19 11:38   ` kernel test robot
2024-10-16  1:03 ` [PATCH net-next v9 12/23] ovpn: implement TCP transport Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 13/23] ovpn: implement multi-peer support Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 14/23] ovpn: implement peer lookup logic Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 15/23] ovpn: implement keepalive mechanism Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 16/23] ovpn: add support for updating local UDP endpoint Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 17/23] ovpn: add support for peer floating Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 18/23] ovpn: implement peer add/dump/delete via netlink Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 19/23] ovpn: implement key add/del/swap " Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 20/23] ovpn: kill key and notify userspace in case of IV exhaustion Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 21/23] ovpn: notify userspace when a peer is deleted Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 22/23] ovpn: add basic ethtool support Antonio Quartulli
2024-10-16  1:03 ` [PATCH net-next v9 23/23] testing/selftest: add test tool and scripts for ovpn module Antonio Quartulli
2024-10-16 21:14   ` Shuah Khan
2024-10-17  7:56     ` Antonio Quartulli
2024-10-17 11:27     ` Antonio Quartulli
2024-10-17 21:40       ` Shuah Khan
2024-10-18  8:20         ` Antonio Quartulli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZxCxCJk6RFtc-g0F@nanopsycho.orion \
    --to=jiri@resnulli.us \
    --cc=andrew@lunn.ch \
    --cc=antonio@openvpn.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ryazanov.s.a@gmail.com \
    --cc=sd@queasysnail.net \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox