netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sabrina Dubroca <sd@queasysnail.net>
To: Antonio Quartulli <antonio@openvpn.net>
Cc: netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com,
	ryazanov.s.a@gmail.com, edumazet@google.com, andrew@lunn.ch
Subject: Re: [PATCH net-next v6 12/25] ovpn: implement packet processing
Date: Tue, 10 Sep 2024 15:04:45 +0200	[thread overview]
Message-ID: <ZuBD7TWOQ7huO7_7@hog> (raw)
In-Reply-To: <9ab97386-b83d-484e-8e6d-9f67a325669d@openvpn.net>

2024-09-06, 15:19:08 +0200, Antonio Quartulli wrote:
> On 04/09/2024 17:01, Sabrina Dubroca wrote:
> > 2024-09-04, 14:07:23 +0200, Antonio Quartulli wrote:
> > > On 02/09/2024 16:42, Sabrina Dubroca wrote:
> > > > 2024-08-27, 14:07:52 +0200, Antonio Quartulli wrote:
> > I can think of a few possibilities if this causes too many unwanted
> > drops:
> > 
> >   - use a linked list of keys, set the primary instead of swapping, and
> >     let delete remove the unused key(s) by ID instead of slot
> > 
> >   - decouple the TX and RX keys, which also means you don't really need
> >     to swap keys (swap for the TX key becomes "set primary", swap on RX
> >     can become a noop since you check both slots for the correct keyid)
> >     -- and here too delete becomes based on key ID
> > 
> >   - if cs->mutex becomes a spinlock, take it in the datapath when
> >     looking up keys. this will make sure we get a consistent view of
> >     the keys state.
> > 
> >   - come up with a scheme to let the datapath retry the key lookup if
> >     it didn't find the key it wanted (maybe something like a seqcount,
> >     or maybe taking the lock and retrying if the lookup failed)
> > 
> > I don't know if options 1 and 2 are possible based on how openvpn (the
> > protocol and the userspace application) models keys, but they seem a
> > bit "cleaner" on the datapath side (no locking, no retry). But they
> > require a different API.
> 
> After chewing over all these ideas I think we can summarize the requirements
> as follows:
> 
> * PRIMARY and SECONDARY in the API is just an abstraction for "KEY FOR TX"
> and "THE OTHER KEY";
> * SWAP means "mark for TX the key that currently was not marked";
> * we only need a pointer to the key for TX;
> * key for RX is picked up by key ID;
> 
> Therefore, how about having an array large enough to store all key IDs (max
> ID is 7):

Right, I forgot about that. For 8 keys, sure, array sounds ok. MACsec
has only 4 and I also implemented it as an array
(include/net/macsec.h: macsec_{tx,rx}_sc, sa array).

> * array index is the key ID (fast lookup on RX);
> * upon SET_KEY we store the provided keys and erase the rest;

I'm not sure about erasing the rest. If you're installing the
secondary ("next primary") key, you can't just erase the current
primary? ("erase the rest" also means you'd only ever have one key in
the array, which contradicts your last item in this list)

> * upon SET_KEY we store in a new field the index/ID of the PRIMARY (fast
> lookup on TX), namely primary_id;
> * upon SWAP we just save in primary_id the "other" index/ID;

I'm confused by these two. Both SET_KEY and SWAP modify the primary_id?

> * at any given time we will have only two keys in the array.

This needs to be enforced in the SET_KEY implementation, otherwise
SWAP will have inconsistent effects.


> It's pretty much like your option 1 and 2, but using an array
> indexed by key ID.

Are you decoupling TX and RX keys (so that they can be installed
independently) in this proposal? I can't really tell, the array could
be key pairs or separate.


> The concept of slot is a bit lost, but it is not important as long as we can
> keep the API and its semantics the same.

Would it be a problem for userspace to keep track of key IDs, and use
that (instead of slots) to communicate with the kernel? Make
setkey/delkey be based on keyid, and replace swap with a set_tx
operation which updates the current keyid for TX. That would seem like
a better API, especially for the per-ID array you're proposing
here. The concept of slots would be almost completely lost (only
"current tx key" is left, which is similar to the "primary slot").
(it becomes almost identical to the way MACsec does things, except
possibly that in MACsec the TX and RX keys are not paired at all, so
you can install/delete a TX key without touching any RX key)


Maybe you can also rework the current code to look a bit like this
array-based proposal, and not give up the notion of slots, if that's
something strongly built into the core of openvpn:

- primary/secondary in ovpn_crypto_state become slots[2]
- add a one-bit "primary" reference, used to look into the slots array
- swap just flips that "primary" bit
- TX uses slots[primary]
- RX keeps inspecting both slots (now slot[0] and slot[1] instead of
  primary/secondary) looking for the correct keyid
- setkey/delkey still operate on primary/secondary, but need to figure
  out whether slot[0] or slot[1] is primary/secondary based on
  ->primary

It's almost identical to the current code (and API), except you don't
need to reassign any pointers to swap keys, so it should avoid the
rekey issue.

-- 
Sabrina


  reply	other threads:[~2024-09-10 13:05 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-27 12:07 [PATCH net-next v6 00/25] Introducing OpenVPN Data Channel Offload Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 01/25] netlink: add NLA_POLICY_MAX_LEN macro Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 02/25] rtnetlink: don't crash on unregister if no dellink exists Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 03/25] net: introduce OpenVPN Data Channel Offload (ovpn) Antonio Quartulli
2024-09-05 14:38   ` Sabrina Dubroca
2024-09-06 12:26     ` Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 04/25] ovpn: add basic netlink support Antonio Quartulli
2024-09-06 19:26   ` Simon Horman
2024-09-09  8:35     ` Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 05/25] ovpn: add basic interface creation/destruction/management routines Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 06/25] ovpn: implement interface creation/destruction via netlink Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 07/25] ovpn: keep carrier always on Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 08/25] ovpn: introduce the ovpn_peer object Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 09/25] ovpn: introduce the ovpn_socket object Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 10/25] ovpn: implement basic TX path (UDP) Antonio Quartulli
2024-08-30 17:02   ` Sabrina Dubroca
2024-09-02 12:03     ` Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 11/25] ovpn: implement basic RX " Antonio Quartulli
2024-09-02 11:22   ` Sabrina Dubroca
2024-09-02 12:24     ` Antonio Quartulli
2024-09-06 19:18   ` Simon Horman
2024-09-09  8:37     ` Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 12/25] ovpn: implement packet processing Antonio Quartulli
2024-09-02 14:42   ` Sabrina Dubroca
2024-09-04 12:07     ` Antonio Quartulli
2024-09-04 15:01       ` Sabrina Dubroca
2024-09-06 13:19         ` Antonio Quartulli
2024-09-10 13:04           ` Sabrina Dubroca [this message]
2024-09-11 12:52             ` Antonio Quartulli
2024-09-11 13:30               ` Sabrina Dubroca
2024-09-12  8:33                 ` Antonio Quartulli
2024-09-22 19:51                   ` Sergey Ryazanov
2024-09-23 12:48                     ` Antonio Quartulli
2024-09-06 19:29   ` Simon Horman
2024-09-09  8:38     ` Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 13/25] ovpn: store tunnel and transport statistics Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 14/25] ovpn: implement TCP transport Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 15/25] ovpn: implement multi-peer support Antonio Quartulli
2024-09-03 14:40   ` Sabrina Dubroca
2024-09-04 10:10     ` Sabrina Dubroca
2024-09-06 13:26       ` Antonio Quartulli
2024-09-05  8:02     ` Antonio Quartulli
2024-09-05 10:47       ` Sabrina Dubroca
2024-09-09  9:12         ` Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 16/25] ovpn: implement peer lookup logic Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 17/25] ovpn: implement keepalive mechanism Antonio Quartulli
2024-09-03 15:17   ` Sabrina Dubroca
2024-09-09  9:17     ` Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 18/25] ovpn: add support for updating local UDP endpoint Antonio Quartulli
2024-08-27 12:07 ` [PATCH net-next v6 19/25] ovpn: add support for peer floating Antonio Quartulli
2024-09-05  9:55   ` Sabrina Dubroca
2024-09-09  8:52     ` Antonio Quartulli
2024-08-27 12:08 ` [PATCH net-next v6 20/25] ovpn: implement peer add/dump/delete via netlink Antonio Quartulli
2024-08-27 12:08 ` [PATCH net-next v6 21/25] ovpn: implement key add/del/swap " Antonio Quartulli
2024-08-27 12:08 ` [PATCH net-next v6 22/25] ovpn: kill key and notify userspace in case of IV exhaustion Antonio Quartulli
2024-08-27 12:08 ` [PATCH net-next v6 23/25] ovpn: notify userspace when a peer is deleted Antonio Quartulli
2024-08-27 12:08 ` [PATCH net-next v6 24/25] ovpn: add basic ethtool support Antonio Quartulli
2024-08-27 12:08 ` [PATCH net-next v6 25/25] testing/selftest: add test tool and scripts for ovpn module 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=ZuBD7TWOQ7huO7_7@hog \
    --to=sd@queasysnail.net \
    --cc=andrew@lunn.ch \
    --cc=antonio@openvpn.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ryazanov.s.a@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).