From: Antonio Quartulli <antonio@openvpn.net>
To: Xiao Liang <shaw.leon@gmail.com>
Cc: netdev@vger.kernel.org, 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+netdev@lunn.ch>,
Simon Horman <horms@kernel.org>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net-next v14 17/22] ovpn: implement peer add/get/dump/delete via netlink
Date: Wed, 11 Dec 2024 15:07:49 +0100 [thread overview]
Message-ID: <42e268a6-e0d1-4892-b76a-68ba937e29bf@openvpn.net> (raw)
In-Reply-To: <CABAhCOT-waHW4HJ30a6qLoRBTQN67Y4PmFD0djCoP4iRYnQ5Kg@mail.gmail.com>
On 11/12/2024 14:53, Xiao Liang wrote:
> On Wed, Dec 11, 2024 at 8:51 PM Antonio Quartulli <antonio@openvpn.net> wrote:
>>
>> On 11/12/2024 13:35, Xiao Liang wrote:
>>> On Wed, Dec 11, 2024 at 7:30 PM Antonio Quartulli <antonio@openvpn.net> 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 <antonio@openvpn.net> 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?
>>
>
> The closest thing I can find is L2TP, which has some checks in
> l2tp_validate_socket(). However, it uses ip_queue_xmit() /
> inet6_csk_xmit() to send packets, where many sockopts are handled.
mhh l2tp_sk_to_tunnel() doesn't have more checks than what we already have.
> Maybe someone else can give a more suitable example. I guess we
> can start with sockopts relevant to fields in struct flowi{4,6} and encap
> headers?
Since I have little experience with sockopts in general, and this is not
truly mission critical, how would you feel about sending a patch for
this once ovpn has been merged?
I'd truly appreciate it.
>
>>>
>>>>>
>>>>> [...]
>>>>>> +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?
>
> If netns id is not included, then when the link has been moved,
> we can't infer which netns the socket is in from peer info message,
> thus can not figure out how packets are routed. Other tunnel drivers
> usually use IFLA_LINK_NETNSID for this. Probably have a look at
> rtnl_fill_link_netnsid()?
>
Ok, I see what you mean.
I was assuming this was not needed, because we'd always have a running
openvpn process and it would live in the socket netns.
But it still makes sense to report it with the peer info.
I'll add this new attribute and fill it on PEER_GET.
Thanks a lot.
> Thanks.
--
Antonio Quartulli
OpenVPN Inc.
next prev parent reply other threads:[~2024-12-11 14:07 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-09 8:53 [PATCH net-next v14 00/22] Introducing OpenVPN Data Channel Offload Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 01/22] net: introduce OpenVPN Data Channel Offload (ovpn) Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 02/22] ovpn: add basic netlink support Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 03/22] ovpn: add basic interface creation/destruction/management routines Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 04/22] ovpn: keep carrier always on for MP interfaces Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 05/22] ovpn: introduce the ovpn_peer object Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 06/22] ovpn: introduce the ovpn_socket object Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 07/22] ovpn: implement basic TX path (UDP) Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 08/22] ovpn: implement basic RX " Antonio Quartulli
2024-12-10 16:44 ` Simon Horman
2024-12-11 10:00 ` Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 09/22] ovpn: implement packet processing Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 10/22] ovpn: store tunnel and transport statistics Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 11/22] ovpn: implement TCP transport Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 12/22] ovpn: implement multi-peer support Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 13/22] ovpn: implement peer lookup logic Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 14/22] ovpn: implement keepalive mechanism Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 15/22] ovpn: add support for updating local UDP endpoint Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 16/22] ovpn: add support for peer floating Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 17/22] ovpn: implement peer add/get/dump/delete via netlink Antonio Quartulli
2024-12-11 3:08 ` Xiao Liang
2024-12-11 11:31 ` Antonio Quartulli
2024-12-11 12:35 ` Xiao Liang
2024-12-11 12:52 ` Antonio Quartulli
2024-12-11 13:53 ` Xiao Liang
2024-12-11 14:07 ` Antonio Quartulli [this message]
2024-12-11 14:37 ` Xiao Liang
2024-12-09 8:53 ` [PATCH net-next v14 18/22] ovpn: implement key add/get/del/swap " Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 19/22] ovpn: kill key and notify userspace in case of IV exhaustion Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 20/22] ovpn: notify userspace when a peer is deleted Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 21/22] ovpn: add basic ethtool support Antonio Quartulli
2024-12-09 8:53 ` [PATCH net-next v14 22/22] testing/selftests: add test tool and scripts for ovpn module Antonio Quartulli
2024-12-10 16:47 ` Simon Horman
2024-12-11 10:01 ` 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=42e268a6-e0d1-4892-b76a-68ba937e29bf@openvpn.net \
--to=antonio@openvpn.net \
--cc=andrew+netdev@lunn.ch \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--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=shaw.leon@gmail.com \
--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