All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steffen Klassert <steffen.klassert@secunet.com>
To: David Miller <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	<netdev@vger.kernel.org>
Subject: [PATCH 09/12] xfrm: Refactor migration setup during the cloning process
Date: Fri, 23 May 2025 09:56:08 +0200	[thread overview]
Message-ID: <20250523075611.3723340-10-steffen.klassert@secunet.com> (raw)
In-Reply-To: <20250523075611.3723340-1-steffen.klassert@secunet.com>

From: Chiachang Wang <chiachangwang@google.com>

Previously, migration related setup, such as updating family,
destination address, and source address, was performed after
the clone was created in `xfrm_state_migrate`. This change
moves this setup into the cloning function itself, improving
code locality and reducing redundancy.

The `xfrm_state_clone_and_setup` function now conditionally
applies the migration parameters from struct xfrm_migrate
if it is provided. This allows the function to be used both
for simple cloning and for cloning with migration setup.

Test: Tested with kernel test in the Android tree located
      in https://android.googlesource.com/kernel/tests/
      The xfrm_tunnel_test.py under the tests folder in
      particular.
Signed-off-by: Chiachang Wang <chiachangwang@google.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/xfrm/xfrm_state.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index 1c5fe1b0b6d6..4bf7a4a8f9d4 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -1958,8 +1958,9 @@ static inline int clone_security(struct xfrm_state *x, struct xfrm_sec_ctx *secu
 	return 0;
 }
 
-static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
-					   struct xfrm_encap_tmpl *encap)
+static struct xfrm_state *xfrm_state_clone_and_setup(struct xfrm_state *orig,
+					   struct xfrm_encap_tmpl *encap,
+					   struct xfrm_migrate *m)
 {
 	struct net *net = xs_net(orig);
 	struct xfrm_state *x = xfrm_state_alloc(net);
@@ -2058,6 +2059,11 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
 			goto error;
 	}
 
+
+	x->props.family = m->new_family;
+	memcpy(&x->id.daddr, &m->new_daddr, sizeof(x->id.daddr));
+	memcpy(&x->props.saddr, &m->new_saddr, sizeof(x->props.saddr));
+
 	return x;
 
  error:
@@ -2127,18 +2133,13 @@ struct xfrm_state *xfrm_state_migrate(struct xfrm_state *x,
 {
 	struct xfrm_state *xc;
 
-	xc = xfrm_state_clone(x, encap);
+	xc = xfrm_state_clone_and_setup(x, encap, m);
 	if (!xc)
 		return NULL;
 
-	xc->props.family = m->new_family;
-
 	if (xfrm_init_state(xc) < 0)
 		goto error;
 
-	memcpy(&xc->id.daddr, &m->new_daddr, sizeof(xc->id.daddr));
-	memcpy(&xc->props.saddr, &m->new_saddr, sizeof(xc->props.saddr));
-
 	/* configure the hardware if offload is requested */
 	if (xuo && xfrm_dev_state_add(net, xc, xuo, extack))
 		goto error;
-- 
2.34.1


  parent reply	other threads:[~2025-05-23  7:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-23  7:55 [PATCH 0/12] pull request (net-next): ipsec-next 2025-05-23 Steffen Klassert
2025-05-23  7:56 ` [PATCH 01/12] xfrm: Remove unnecessary strscpy_pad() size arguments Steffen Klassert
2025-05-26 16:50   ` patchwork-bot+netdevbpf
2025-05-23  7:56 ` [PATCH 02/12] net/mlx5: Avoid using xso.real_dev unnecessarily Steffen Klassert
2025-05-23  7:56 ` [PATCH 03/12] xfrm: Use xdo.dev instead of xdo.real_dev Steffen Klassert
2025-05-23  7:56 ` [PATCH 04/12] xfrm: Remove unneeded device check from validate_xmit_xfrm Steffen Klassert
2025-05-23  7:56 ` [PATCH 05/12] xfrm: Add explicit dev to .xdo_dev_state_{add,delete,free} Steffen Klassert
2025-05-23  7:56 ` [PATCH 06/12] bonding: Mark active offloaded xfrm_states Steffen Klassert
2025-05-23  7:56 ` [PATCH 07/12] bonding: Fix multiple long standing offload races Steffen Klassert
2025-05-23  7:56 ` [PATCH 08/12] xfrm: Migrate offload configuration Steffen Klassert
2025-05-23  7:56 ` Steffen Klassert [this message]
2025-05-23  7:56 ` [PATCH 10/12] xfrm: validate assignment of maximal possible SEQ number Steffen Klassert
2025-05-23  7:56 ` [PATCH 11/12] xfrm: prevent configuration of interface index when offload is used Steffen Klassert
2025-05-23  7:56 ` [PATCH 12/12] xfrm: use kfree_sensitive() for SA secret zeroization Steffen Klassert
2025-05-23 10:36 ` [PATCH 0/12] pull request (net-next): ipsec-next 2025-05-23 Steffen Klassert

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=20250523075611.3723340-10-steffen.klassert@secunet.com \
    --to=steffen.klassert@secunet.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.