From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (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 5DC86199FC9 for ; Thu, 21 Nov 2024 21:23:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732224192; cv=none; b=fhWXww0qr1fMf1tLxyKOGaoEu823VvTVPkypyS1TIPWuT/J6frKRumAOb17eQOFoZKPtSpGZEOsHD+yRht4dxF0ZAxkyvbEgXswRl+/4dThsp830tUD9Bxl1TRxkgPFC5XLb4GIKgvLZmr0jjPtba2+P1lVi2bPFX0gQZy/aLUI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732224192; c=relaxed/simple; bh=qywTFtD+0BzuPwD45lQta1Z8qCtNKrwLzH2n/AAZxJw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=SwNLCAB2OkKDHcJVjoU7gtNbu9753xj2nbngkdivhRoQGv1igu3eRzjY6CdMnPsrQ1kBvPU/xXCSfn7G5SWsyWtZHloFh7bC7YEnbnQedOWJVU0RCI60uLaNe8+pKEk+q07M/YKiNz7tUy5SPnjge9eYIF4U4vNUs4I4nbqTCt0= 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=UOloufYV; arc=none smtp.client-ip=209.85.208.171 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="UOloufYV" Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2fb4af0b6beso24980921fa.3 for ; Thu, 21 Nov 2024 13:23:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1732224188; x=1732828988; 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=QuEuA2H3TWnIAf5kbxkDhfjOrhOItH/ikPCn+mNuBSA=; b=UOloufYVlw1TfRWIE6x1SbjxXnWauPoymuReaet4eIZrLNO9XN5Gnb9Jjh3yJ41dSt 7cNiB0Esg/3fCXz3XVJK6Q7NTiFjMaoSFKeejEvEpJeJmK3dcd2Umws5lJxOHI5BNGN7 cOlSlrikbaHhNfw5H+E6Okpmz4SAlFWxanu7FMYHhiWe9lHUH26b07dzhBVzs4CrQDZS vvSMurCU+B2lU+8aKARvhOKUGohEV81O+Trd/CDkONTtkdXLsa9ATDGKAOzrhL6N5nwZ 1rfge98Bt9BbAfm9SuqtkBtV4O6qsCKdktVbXxC0bqRnl3ad20C3nSWNmAllKfUsQJWI g9QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732224188; x=1732828988; 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=QuEuA2H3TWnIAf5kbxkDhfjOrhOItH/ikPCn+mNuBSA=; b=GtWSnCXC0lLtDjzSHOkef7DxgBs9U/ZhFHBcp2A4i9jceMhvB47K0LQGZ4mPOHudKc idhI2R6+/22DAgAEp7spcwcjq6UOhLSdAWLHIVKx6ccMRdz0sukcvB/HvcFkZJrYoEv0 a92cFrgVcD9nUn4XZlaK3T3tIYUbKCIhaYRlOneicKF8lbpR8Fa1axav9p5Qgo/lp0Gn uhVhKlAAWW3q7on2iYa5IAjUmVUF0jR+bXRvopfNgFdr8YpqDuRCP+4T6hlKdohxF5Jv k3QFWH/rPxoRj37w6Kxk7nTrFBlY5WKskluAfIdEv9LAMKB3TZ6mgzQQ1YtE5LwnLLN1 af6w== X-Forwarded-Encrypted: i=1; AJvYcCU0ZLGh5VOxdCc5pB1FZVs0WxDfASjYZetwJ20ROEveX1BGE0oFYjUrjlGCwA3mjxw/as77rQdB1VV14GA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3HnNQF7Z9W3q21WkQKC3l91Qdt6Rxv/jNDThfw0Rd1Aw61iNI 0Ygx9AV18fu6MYtyxxK48lpJxtTOHYKJ/8fdNoElTerJe0xOI/ehJyjJkETYD1M= X-Gm-Gg: ASbGnctyH/b8IF1aDjO2tWWFutwyicjIssX7dMv9H7+Zp9RSIuRVQGapT1aanjebf5r 78h1O1IG/uNAC/GWbfRot6gFND3orURRQPZOi/EZqMaUYd1FR9auybQjCEGxyvnbNbbbKk0WOdS MDhqw4f0W7dWltCQiBMAb7PpdJHkFttIwUbwNQljkj9YJKyrHLnCdBiVJNOGNNmrKic6/5+UFXS 0dbeIPy3ea5RY1JauWbSKNNTvP4jtQ4PIeALjzqWKIPm37Qe6DGHAB0a3l11A4e1JOeBtt9B4vC w+vNiUmYZA== X-Google-Smtp-Source: AGHT+IFxBGMOFADHnq6mp//A/vFyhDz1w54VlnkH3inEJ0BvqI+GY5tV6VrB71LNvlVlewsvGohUcQ== X-Received: by 2002:a2e:bc16:0:b0:2fa:d604:e519 with SMTP id 38308e7fff4ca-2ffa7106413mr1944051fa.11.1732224188433; Thu, 21 Nov 2024 13:23:08 -0800 (PST) Received: from ?IPV6:2001:67c:2fbc:1:f55:fe70:5486:7392? ([2001:67c:2fbc:1:f55:fe70:5486:7392]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa50b52fb6asm15223466b.92.2024.11.21.13.23.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Nov 2024 13:23:07 -0800 (PST) Message-ID: <52661fed-f521-4cdc-b9e1-b4f3fa292e78@openvpn.net> Date: Thu, 21 Nov 2024 22:23:36 +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 v11 06/23] ovpn: introduce the ovpn_peer object To: Sergey Ryazanov , Sabrina Dubroca Cc: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Donald Hunter , Shuah Khan , Andrew Lunn , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org References: <20241029-b4-ovpn-v11-0-de4698c73a25@openvpn.net> <20241029-b4-ovpn-v11-6-de4698c73a25@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 dG9mXk5QrvbpihgpcmNbtloSdkRZ02lsxkUzpG8U64X8WK6LuRz7BZ7p5t/WzaR/hCdOiQCG RNup2UTNDrZpWxpwadXMnJsyJcVX4BAKaWGs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RJWJEjFnMa/jsGZ+QyLD5QTL6SGuZ9gKI3W1SfFZOzV7hHsxPTZ6 Organization: OpenVPN Inc. In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 21/11/2024 00:22, Sergey Ryazanov wrote: > On 13.11.2024 12:03, Sabrina Dubroca wrote: >> 2024-11-13, 03:37:13 +0200, Sergey Ryazanov wrote: >>> On 12.11.2024 19:31, Sabrina Dubroca wrote: >>>> 2024-11-10, 15:38:27 +0200, Sergey Ryazanov wrote: >>>>> On 29.10.2024 12:47, Antonio Quartulli wrote: >>>>>> An ovpn_peer object holds the whole status of a remote peer >>>>>> (regardless whether it is a server or a client). >>>>>> >>>>>> This includes status for crypto, tx/rx buffers, napi, etc. >>>>>> >>>>>> Only support for one peer is introduced (P2P mode). >>>>>> Multi peer support is introduced with a later patch. >>>>> >>>>> Reviewing the peer creation/destroying code I came to a generic >>>>> question. >>>>> Did you consider keeping a single P2P peer in the peers table as well? >>>>> >>>>> Looks like such approach can greatly simply the code by dropping >>>>> all these >>>>> 'switch (ovpn->mode)' checks and implementing a unified peer >>>>> management. The >>>>> 'peer' field in the main private data structure can be kept to >>>>> accelerate >>>>> lookups, still using peers table for management tasks like removing >>>>> all the >>>>> peers on the interface teardown. >>>> >>>> It would save a few 'switch(mode)', but force every client to allocate >>>> the hashtable for no reason at all. That tradeoff doesn't look very >>>> beneficial to me, the P2P-specific code is really simple. And if you >>>> keep ovpn->peer to make lookups faster, you're not removing that many >>>> 'switch(mode)'. >>> >>> Looking at the done review, I can retrospectively conclude that I >>> personally >>> do not like short 'switch' statements and special handlers :) >>> >>> Seriously, this module has a highest density of switches per KLOC >>> from what >>> I have seen before and a major part of it dedicated to handle the >>> special >>> case of P2P connection. >> >> I think it's fine. Either way there will be two implementations of >> whatever mode-dependent operation needs to be done. switch doesn't >> make it more complex than an ops structure. >> >> If you're reading the current version and find ovpn_peer_add, you see >> directly that it'll do either ovpn_peer_add_mp or >> ovpn_peer_add_p2p. With an ops structure, you'd have a call to >> ovpn->ops->peer_add, and you'd have to look up all possible ops >> structures to know that it can be either ovpn_peer_add_mp or >> ovpn_peer_add_p2p. If there's an undefined number of implementations >> living in different modules (like net_device_ops, or L4 protocols), >> you don't have a choice. >> >> xfrm went the opposite way to what you're proposing a few years ago >> (see commit 0c620e97b349 ("xfrm: remove output indirection from >> xfrm_mode") and others), and it made the code simpler. > > I checked this. Florian did a nice rework. And the way of implementation > looks reasonable since there are more than two encapsulation modes and > handling is more complex than just selecting a function to call. > > What I don't like about switches, that it requires extra lines of code > and pushes an author to introduce a default case with error handling. It > was mentioned that the module unlikely going to support more than two > modes. In this context shall we consider ternary operator usage. E.g.: the default case can actually be dropped. That way we can have the compiler warn when one of the enum values is not handled in the switch (should there be a new one at some point). However, the default is just a sanity check against future code changes which may introduce a bug. > > next_run = ovpn->mode == OVPN_MODE_P2P ? >            ovpn_peer_keepalive_work_p2p(...) : >            ovpn_peer_keepalive_work_mp(...); I find this ugly to read :-) The switch is much more elegant and straightforward. Do you agree this is getting more into a bike shed coloring discussion? :-D Since there is not much gain in changing approach, I think it is better if the maintainer picks a style that he finds more suitable (or simply likes more). no? > >>> And back to the hashtable(s) size for the MP mode. 8k-bins table looks a >>> good choice for a normal server with 1-2Gb uplink serving up to 1k >>> connections. But it sill unclear, how this choice can affect >>> installations >>> with a bigger number of connections? Or is this module applicable for >>> embedded solutions? E.g. running a couple of VPN servers on a home >>> router >>> with a few actual connections looks like a waste of RAM. I was about to >>> suggest to use rhashtable due to its dynamic sizing feature, but the >>> module >>> needs three tables. Any better idea? >> >> For this initial implementation I think it's fine. Sure, converting to >> rhashtable (or some other type of dynamically-sized hashtable, if >> rhashtable doesn't fit) in the future would make sense. But I don't >> think it's necessary to get the patches into net-next. Agreed. It's in the pipe (along with other features that I have already implemented), but it will come later. Regards, > > Make sense. Thanks for sharing these thoughts. > > -- > Sergey -- Antonio Quartulli OpenVPN Inc.