From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 63C4423FD03 for ; Wed, 11 Dec 2024 12:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733921498; cv=none; b=DF6UofD3syU2ys2SnokB4Jm+WuoqDMChTyNGLYzYovBwuLUByuKvGdv7laA5vRTsSW/HK3jWJTdi513sktJbYUXZ5NBS4QTKHgSa5OnLg2wF39aPFZAzNqZ9qNtxmgI9paZ4w6AYGx6fEtBmFcPPliuMo1VDf26lUaBiTHOLWcQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733921498; c=relaxed/simple; bh=0OUWphyTbf6xBZM1dUwTwW/QFrk4VopnS/m0vm8v1vI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=jJyrq1lpFsVbl6aQXrmZUTojnKHsgB+NbFgJabaveEF9yBsM39eJZQqCoZ643KLQgS0Iq1YOaVQ8G5BRv3YfQXj1ZsNzPFBfZRTsHZAcbtF5B8a5gTY7W0lJBo3S2yYpEN3zdN1Uk3VB3Sakn42OfbadPXj0A1EHYRWY/3rfNso= 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=X9SRhYUO; arc=none smtp.client-ip=209.85.128.45 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="X9SRhYUO" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-434a2033562so57833705e9.1 for ; Wed, 11 Dec 2024 04:51:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1733921495; x=1734526295; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=Nd4cR7VNkiPh4DainW3uYEi6+FSg1iou6ceeUwexMCU=; b=X9SRhYUOJaS8NI3ZiDbv1Ma9afDl9N1WQvLeabFxRxdrL0V7oreMdcEg2kZaXVVxMp /F1TwX0qB0E7JFUwjQQpAWVI9toRCXSE2O9LNpfXhXwc/dfXnlksvjK3GJJU/+0Tqw07 xrmq2yCdp1M0pWFLxl6gLmPWEhS0Nyk2Njqks1qjwr7oEa20+zUsPwvBgDxo6s3tVmaW VwARXTvaD422lsoCe9maNU0RSHaA5ipO3cLew6eoGip/7glFUENf+ltfLzuyyPc2yYmo 7TLY1VYzHCMP5i3P5Pc5J8yfs1aV++FB+lTdLgrMETrVY2b0nCSLFLTOqjqXuJ0qKyn0 rAag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733921495; x=1734526295; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Nd4cR7VNkiPh4DainW3uYEi6+FSg1iou6ceeUwexMCU=; b=tACMbGEkeMzBVGgY6Wfc+8INqrGW5/MJL+otJn0aOPsVbdqbI3ep4tO0gCH7W1rmTW OWVSEhwIzXlOvvyfr6ORXa1jZh1cPsSzqycj0Fvh6qs0aXUiN+a5AZxbQWQPXsD1WfKX S5+ueO55RimPC3fNo8OogGNagQp5naxphOta2ZeyojpGpOMYe3EiJfLph6wu4CKRdxNz qLLChoidRm5foFwBES7g+J+D9NUyiSCXtHwif8Ce8jDUeYqkitKb92BuHlws1UD9Inbj QXhbpRlQ/0X+uWtDRhb4V7q6/BV9BI3OjUEPkK8eNb3ZuDcAvw0sPXut/haUBOu3kTvL Gxqw== X-Forwarded-Encrypted: i=1; AJvYcCUdEIEJQsUJBv7FuwekMqmMozQ29iJjjOaNQ1RY8CAII9QXzBpjCQg35r3Xx19EzMgTuCZL9RUllPm9b4U=@vger.kernel.org X-Gm-Message-State: AOJu0YzLFuMkeK8J1OGzvQrte9ezEDG9hMpv1TmFdZy9S9RrklLdFULR DyaUYjZNchsdMYycMRc7DaNnVaNkOIyAviBX9Jxkj+b4KZtYDL7UMJJ35WR8RYU= X-Gm-Gg: ASbGncvc9kGOxbyneU/uwPZbciDO1pLy5arovWEe9SbWNJLjssk+fopLSnW5YdlYKbM tksFKc+YmmyycFORroxM/cHTqRDqVWQ4fMqVUrttjqsAsJ9Hsk5HTzfawgKxNPJIBRKn/xP+/3Z bH/kiTV+5cBN011Vx+vJrnZwb7o2TzjIY1UpnNkZq5wxGySJEoycfURAdjX3iaSDJt4N53kfiAv AcYn06IthB+H4vyKbHkZUtjSo5x4iwQ9FsgrEzsnYqIq+moLVUeWiNSwnnbri+VxFtbDkljWClk Y0BK0X7YIZHYrA== X-Google-Smtp-Source: AGHT+IEAhSjKj7WdnSQujhKoCbXsLtfE3ig+PhAU836+YP/N5IG6Z7pZ3cnPntdYmIp9qR/MmIzbzw== X-Received: by 2002:a05:600c:4e4b:b0:435:306:e5dd with SMTP id 5b1f17b1804b1-4361c42c70bmr17359425e9.22.1733921494713; Wed, 11 Dec 2024 04:51:34 -0800 (PST) Received: from ?IPV6:2001:67c:2fbc:1:f6e8:f722:d96d:abb? ([2001:67c:2fbc:1:f6e8:f722:d96d:abb]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-387824a5005sm1229367f8f.41.2024.12.11.04.51.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Dec 2024 04:51:34 -0800 (PST) Message-ID: <4471b912-d8df-41ba-9c3b-a46906ca797d@openvpn.net> Date: Wed, 11 Dec 2024 13:52:18 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next v14 17/22] ovpn: implement peer add/get/dump/delete via netlink To: Xiao Liang Cc: netdev@vger.kernel.org, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Donald Hunter , Shuah Khan , sd@queasysnail.net, ryazanov.s.a@gmail.com, Andrew Lunn , Simon Horman , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org References: <20241209-b4-ovpn-v14-0-ea243cf16417@openvpn.net> <20241209-b4-ovpn-v14-17-ea243cf16417@openvpn.net> <5a3d1c9b-f000-45c1-afd3-c7a10d2a50e8@openvpn.net> Content-Language: en-US From: Antonio Quartulli Autocrypt: addr=antonio@openvpn.net; keydata= xsFNBFN3k+ABEADEvXdJZVUfqxGOKByfkExNpKzFzAwHYjhOb3MTlzSLlVKLRIHxe/Etj13I X6tcViNYiIiJxmeHAH7FUj/yAISW56lynAEt7OdkGpZf3HGXRQz1Xi0PWuUINa4QW+ipaKmv voR4b1wZQ9cZ787KLmu10VF1duHW/IewDx9GUQIzChqQVI3lSHRCo90Z/NQ75ZL/rbR3UHB+ EWLIh8Lz1cdE47VaVyX6f0yr3Itx0ZuyIWPrctlHwV5bUdA4JnyY3QvJh4yJPYh9I69HZWsj qplU2WxEfM6+OlaM9iKOUhVxjpkFXheD57EGdVkuG0YhizVF4p9MKGB42D70pfS3EiYdTaKf WzbiFUunOHLJ4hyAi75d4ugxU02DsUjw/0t0kfHtj2V0x1169Hp/NTW1jkqgPWtIsjn+dkde dG9mXk5QrvbpihgpcmNbtloSdkRZ02lsxkUzpG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BnRX9nFx9kPSO42TkFK55Dr5EDeBO3v33recscuB8VVN5xvh0GV57Qre+9sJrEq7Es9W609a +M0yRJWJEjFnMa/jsGZ+QyLD5QTL6SGuZ9gKI3W1SfFZOzV7hHsxPTZ6 Organization: OpenVPN Inc. In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 11/12/2024 13:35, Xiao Liang wrote: > On Wed, Dec 11, 2024 at 7:30 PM Antonio Quartulli wrote: >> >> Hi Xiao and thanks for chiming in, >> >> On 11/12/2024 04:08, Xiao Liang wrote: >>> On Mon, Dec 9, 2024 at 6:48 PM Antonio Quartulli wrote: >>> [...] >>>> +/** >>>> + * ovpn_nl_peer_modify - modify the peer attributes according to the incoming msg >>>> + * @peer: the peer to modify >>>> + * @info: generic netlink info from the user request >>>> + * @attrs: the attributes from the user request >>>> + * >>>> + * Return: a negative error code in case of failure, 0 on success or 1 on >>>> + * success and the VPN IPs have been modified (requires rehashing in MP >>>> + * mode) >>>> + */ >>>> +static int ovpn_nl_peer_modify(struct ovpn_peer *peer, struct genl_info *info, >>>> + struct nlattr **attrs) >>>> +{ >>>> + struct sockaddr_storage ss = {}; >>>> + struct ovpn_socket *ovpn_sock; >>>> + u32 sockfd, interv, timeout; >>>> + struct socket *sock = NULL; >>>> + u8 *local_ip = NULL; >>>> + bool rehash = false; >>>> + int ret; >>>> + >>>> + if (attrs[OVPN_A_PEER_SOCKET]) { >>> >>> Similar to link attributes in other tunnel drivers (e.g. IFLA_GRE_LINK, >>> IFLA_GRE_FWMARK), user-supplied sockets could have sockopts >>> (e.g. oif, fwmark, TOS). Since some of them may affect encapsulation >>> and routing decision, which are supported in datapath? And do we need >>> some validation here? >> >> Thanks for pointing this out. >> At the moment ovpn doesn't expect any specific socket option. >> I haven't investigated how they could be used and what effect they would >> have on the packet processing. >> This is something we may consider later. >> >> At this point, do you still think I should add a check here of some sort? >> > > I think some sockopts are important. Especially when oif is a VRF, > the destination can be totally different than using the default routing > table. If we don't support them now, it would be good to deny sockets > with non-default values. I see - openvpn in userspace doesn't set any specific oif for the socket, but I understand ovpn should at least claim that those options are not supported. I am a bit lost regarding this aspect. Do you have a pointer for me where I can see how other modules are doing similar checks? > >>> >>> [...] >>>> +static int ovpn_nl_send_peer(struct sk_buff *skb, const struct genl_info *info, >>>> + const struct ovpn_peer *peer, u32 portid, u32 seq, >>>> + int flags) >>>> +{ >>>> + const struct ovpn_bind *bind; >>>> + struct nlattr *attr; >>>> + void *hdr; >>>> + >>>> + hdr = genlmsg_put(skb, portid, seq, &ovpn_nl_family, flags, >>>> + OVPN_CMD_PEER_GET); >>>> + if (!hdr) >>>> + return -ENOBUFS; >>>> + >>>> + attr = nla_nest_start(skb, OVPN_A_PEER); >>>> + if (!attr) >>>> + goto err; >>>> + >>>> + if (nla_put_u32(skb, OVPN_A_PEER_ID, peer->id)) >>>> + goto err; >>>> + >>> >>> I think it would be helpful to include the netns ID and supported sockopts >>> of the peer socket in peer info message. >> >> Technically the netns is the same as where the openvpn process in >> userspace is running, because it'll be it to open the socket and pass it >> down to ovpn. > > A userspace process could open UDP sockets in one namespace > and the netlink socket in another. And the ovpn link could also be > moved around. At this moment, we can remember the initial netns, > or perhaps link-netns, of the ovpn link, and validate if the socket > is in the same one. > You are correct, but we don't want to force sockets and link to be in the same netns. Openvpn in userspace may have been started in the global netns, where all sockets are expected to live (transport layer), but then the link/device is moved - or maybe created - somewhere else (tunnel layer). This is not an issue. Does it clarify? Thanks -- Antonio Quartulli OpenVPN Inc.