[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZD5CGQZQ2tWBeXQ1@corigine.com>
Date: Tue, 18 Apr 2023 09:09:13 +0200
From: Simon Horman <simon.horman@...igine.com>
To: Leon Romanovsky <leon@...nel.org>
Cc: "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Steffen Klassert <steffen.klassert@...unet.com>,
Herbert Xu <herbert@...dor.apana.org.au>,
netdev@...r.kernel.org, Saeed Mahameed <saeedm@...dia.com>,
Raed Salem <raeds@...dia.com>, Emeel Hakim <ehakim@...dia.com>
Subject: Re: [PATCH net-next v1 06/10] net/mlx5e: Support IPsec TX packet
offload in tunnel mode
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@...dia.com>
> > >
> > > Extend mlx5 driver with logic to support IPsec TX packet offload
> > > in tunnel mode.
> > >
> > > Signed-off-by: Leon Romanovsky <leonro@...dia.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
Powered by blists - more mailing lists