[PATCH net-next v1 01/15] psp: get netns from net_device instead of sock

From: Todd Freed

Date: Tue Nov 10 2026 - 19:57:15 EST


every psp skb is related to a socket today, but that will no longer
be true once a psp association can be attached to the skb by other
means, such as tc flower rules added later in the series.

get the netns from the transmitting device instead.

for the outer source port range, psp_write_headers() now explicitly uses
sock_net(sk) in the socket case specifically, to maintain the existing
behavior.

Signed-off-by: Todd Freed <toddfreed@xxxxxxxx>
---
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c | 2 +-
drivers/net/netdevsim/psp.c | 2 +-
net/psp/psp_main.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c
index 348fd7a96261..8b474f75dd61 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c
@@ -165,7 +165,7 @@ bool mlx5e_psp_handle_tx_skb(struct net_device *netdev,
struct mlx5e_accel_tx_psp_state *psp_st)
{
struct mlx5e_priv *priv = netdev_priv(netdev);
- struct net *net = sock_net(skb->sk);
+ struct net *net = dev_net(netdev);

if (!mlx5e_psp_set_state(priv, skb, psp_st))
return true;
diff --git a/drivers/net/netdevsim/psp.c b/drivers/net/netdevsim/psp.c
index b7452c49b581..0701f38aee6d 100644
--- a/drivers/net/netdevsim/psp.c
+++ b/drivers/net/netdevsim/psp.c
@@ -36,7 +36,7 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,
goto out_unlock;
}

- net = sock_net(skb->sk);
+ net = dev_net(ns->netdev);
if (!psp_dev_encapsulate(net, skb, pas->tx.spi, pas->version, 0)) {
rc = SKB_DROP_REASON_PSP_OUTPUT;
goto out_unlock;
diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c
index 273b010d2355..e09f6fec948d 100644
--- a/net/psp/psp_main.c
+++ b/net/psp/psp_main.c
@@ -221,7 +221,7 @@ static void psp_write_headers(struct net *net, struct sk_buff *skb, __be32 spi,
/* These operations are cheap, no need to cache the result
* in another socket field.
*/
- inet_get_local_port_range(net, &min, &max);
+ inet_get_local_port_range(sock_net(sk), &min, &max);
/* Since this is being sent on the wire obfuscate hash a bit
* to minimize possibility that any useful information to an
* attacker is leaked. Only upper 16 bits are relevant in the
--
2.53.0-Meta