netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <simon.horman@corigine.com>
To: Leon Romanovsky <leon@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	netdev@vger.kernel.org, Saeed Mahameed <saeedm@nvidia.com>,
	Raed Salem <raeds@nvidia.com>, Emeel Hakim <ehakim@nvidia.com>
Subject: Re: [PATCH net-next v1 06/10] net/mlx5e: Support IPsec TX packet offload in tunnel mode
Date: Tue, 18 Apr 2023 09:09:13 +0200	[thread overview]
Message-ID: <ZD5CGQZQ2tWBeXQ1@corigine.com> (raw)
In-Reply-To: <20230418064827.GA9740@unreal>

On Tue, Apr 18, 2023 at 09:48:27AM +0300, Leon Romanovsky wrote:
> On Mon, Apr 17, 2023 at 03:23:55PM +0200, Simon Horman wrote:
> > On Thu, Apr 13, 2023 at 03:29:24PM +0300, Leon Romanovsky wrote:
> > > From: Leon Romanovsky <leonro@nvidia.com>
> > > 
> > > Extend mlx5 driver with logic to support IPsec TX packet offload
> > > in tunnel mode.
> > > 
> > > Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
> 
> <...>
> 
> > > --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c
> > > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c
> > > @@ -271,6 +271,18 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,
> > >  		neigh_ha_snapshot(addr, n, netdev);
> > >  		ether_addr_copy(attrs->smac, addr);
> > >  		break;
> > > +	case XFRM_DEV_OFFLOAD_OUT:
> > > +		ether_addr_copy(attrs->smac, addr);
> > > +		n = neigh_lookup(&arp_tbl, &attrs->daddr.a4, netdev);
> > > +		if (!n) {
> > > +			n = neigh_create(&arp_tbl, &attrs->daddr.a4, netdev);
> > > +			if (IS_ERR(n))
> > > +				return;
> > > +			neigh_event_send(n, NULL);
> > > +		}
> > > +		neigh_ha_snapshot(addr, n, netdev);
> > > +		ether_addr_copy(attrs->dmac, addr);
> > > +		break;
> > 
> > I see no problem with the above code.
> > However, it does seem very similar to the code for the previous case,
> > XFRM_DEV_OFFLOAD_IN. Perhaps this could be refactored somehow.
> 
> Yes, it can be refactored to something like this:

Thanks Leon,

this looks good to me.

> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c
> index 59b9927ac90f..55b38544422f 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c
> @@ -252,6 +252,8 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,
>  	struct net_device *netdev;
>  	struct neighbour *n;
>  	u8 addr[ETH_ALEN];
> +	const void *pkey;
> +	u8 *dst, *src;
>  
>  	if (attrs->mode != XFRM_MODE_TUNNEL ||
>  	    attrs->type != XFRM_DEV_OFFLOAD_PACKET)
> @@ -262,36 +264,31 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,
>  	mlx5_query_mac_address(mdev, addr);
>  	switch (attrs->dir) {
>  	case XFRM_DEV_OFFLOAD_IN:
> -		ether_addr_copy(attrs->dmac, addr);
> -		n = neigh_lookup(&arp_tbl, &attrs->saddr.a4, netdev);
> -		if (!n) {
> -			n = neigh_create(&arp_tbl, &attrs->saddr.a4, netdev);
> -			if (IS_ERR(n))
> -				return;
> -			neigh_event_send(n, NULL);
> -			attrs->drop = true;
> -			break;
> -		}
> -		neigh_ha_snapshot(addr, n, netdev);
> -		ether_addr_copy(attrs->smac, addr);
> +		src = attrs->dmac;
> +		dst = attrs->smac;
> +		pkey = &attrs->saddr.a4;
>  		break;
>  	case XFRM_DEV_OFFLOAD_OUT:
> -		ether_addr_copy(attrs->smac, addr);
> -		n = neigh_lookup(&arp_tbl, &attrs->daddr.a4, netdev);
> -		if (!n) {
> -			n = neigh_create(&arp_tbl, &attrs->daddr.a4, netdev);
> -			if (IS_ERR(n))
> -				return;
> -			neigh_event_send(n, NULL);
> -			attrs->drop = true;
> -			break;
> -		}
> -		neigh_ha_snapshot(addr, n, netdev);
> -		ether_addr_copy(attrs->dmac, addr);
> +		src = attrs->smac;
> +		dst = attrs->dmac;
> +		pkey = &attrs->daddr.a4;
>  		break;
>  	default:
>  		return;
>  	}
> +
> +	ether_addr_copy(src, addr);
> +	n = neigh_lookup(&arp_tbl, pkey, netdev);
> +	if (!n) {
> +		n = neigh_create(&arp_tbl, pkey, netdev);
> +		if (IS_ERR(n))
> +			return;
> +		neigh_event_send(n, NULL);
> +		attrs->drop = true;
> +	} else {
> +		neigh_ha_snapshot(addr, n, netdev);
> +		ether_addr_copy(dst, addr);
> +	}
>  	neigh_release(n);
>  }
>  
> 
> Thanks

  reply	other threads:[~2023-04-18  7:09 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-13 12:29 [PATCH net-next v1 00/10] Support tunnel mode in mlx5 IPsec packet offload Leon Romanovsky
2023-04-13 12:29 ` [PATCH net-next v1 01/10] net/mlx5e: Add IPsec packet offload tunnel bits Leon Romanovsky
2023-04-13 12:29 ` [PATCH net-next v1 02/10] net/mlx5e: Check IPsec packet offload tunnel capabilities Leon Romanovsky
2023-04-13 12:29 ` [PATCH net-next v1 03/10] net/mlx5e: Configure IPsec SA tables to support tunnel mode Leon Romanovsky
2023-04-13 12:29 ` [PATCH net-next v1 04/10] net/mlx5e: Prepare IPsec packet reformat code for " Leon Romanovsky
2023-04-14 22:40   ` Samudrala, Sridhar
2023-04-15  8:49     ` Leon Romanovsky
2023-04-17 13:32   ` Simon Horman
2023-04-13 12:29 ` [PATCH net-next v1 05/10] net/mlx5e: Support IPsec RX packet offload in " Leon Romanovsky
2023-04-17 13:33   ` Simon Horman
2023-04-13 12:29 ` [PATCH net-next v1 06/10] net/mlx5e: Support IPsec TX " Leon Romanovsky
2023-04-17 13:23   ` Simon Horman
2023-04-18  6:48     ` Leon Romanovsky
2023-04-18  7:09       ` Simon Horman [this message]
2023-04-18  7:58         ` Leon Romanovsky
2023-04-13 12:29 ` [PATCH net-next v1 07/10] net/mlx5e: Listen to ARP events to update IPsec L2 headers " Leon Romanovsky
2023-04-17 13:34   ` Simon Horman
2023-04-13 12:29 ` [PATCH net-next v1 08/10] net/mlx5: Allow blocking encap changes in eswitch Leon Romanovsky
2023-04-17 13:34   ` Simon Horman
2023-04-13 12:29 ` [PATCH net-next v1 09/10] net/mlx5e: Create IPsec table with tunnel support only when encap is disabled Leon Romanovsky
2023-04-17 13:35   ` Simon Horman
2023-04-13 12:29 ` [PATCH net-next v1 10/10] net/mlx5e: Accept tunnel mode for IPsec packet offload Leon Romanovsky
2023-04-17 13:36   ` Simon Horman
2023-04-16 14:41 ` [PATCH net-next v1 00/10] Support tunnel mode in mlx5 " Samudrala, Sridhar
2023-04-17  4:05 ` Jakub Kicinski
2023-04-17 13:10   ` Simon Horman
2023-04-17 13:38     ` Simon Horman
2023-04-17 17:58       ` Leon Romanovsky
2023-04-17 19:25       ` Jakub Kicinski
2023-04-18  2:00 ` patchwork-bot+netdevbpf

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=ZD5CGQZQ2tWBeXQ1@corigine.com \
    --to=simon.horman@corigine.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=ehakim@nvidia.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=raeds@nvidia.com \
    --cc=saeedm@nvidia.com \
    --cc=steffen.klassert@secunet.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).