netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] netdevsim: better ipsec output format.
@ 2024-10-08 12:21 Hangbin Liu
  2024-10-08 12:21 ` [PATCH net-next 1/2] netdevsim: print human readable IP address Hangbin Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Hangbin Liu @ 2024-10-08 12:21 UTC (permalink / raw)
  To: netdev
  Cc: Jakub Kicinski, David S. Miller, Eric Dumazet, Paolo Abeni,
	Shannon Nelson, Jiri Pirko, linux-kernel, Hangbin Liu

These 2 patches improve the netdevsim ipsec debug output with better
format.

Hangbin Liu (2):
  netdevsim: print human readable IP address
  netdevsim: copy addresses for both in and out paths

 drivers/net/netdevsim/ipsec.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

-- 
2.46.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH net-next 1/2] netdevsim: print human readable IP address
  2024-10-08 12:21 [PATCH net-next 0/2] netdevsim: better ipsec output format Hangbin Liu
@ 2024-10-08 12:21 ` Hangbin Liu
  2024-10-09 12:21   ` Simon Horman
  2024-10-08 12:21 ` [PATCH net-next 2/2] netdevsim: copy addresses for both in and out paths Hangbin Liu
  2024-10-09 17:13 ` [PATCH net-next 0/2] netdevsim: better ipsec output format Jakub Kicinski
  2 siblings, 1 reply; 8+ messages in thread
From: Hangbin Liu @ 2024-10-08 12:21 UTC (permalink / raw)
  To: netdev
  Cc: Jakub Kicinski, David S. Miller, Eric Dumazet, Paolo Abeni,
	Shannon Nelson, Jiri Pirko, linux-kernel, Hangbin Liu

Currently, IPSec addresses are printed in hexadecimal format, which is
not user-friendly. e.g.

  # cat /sys/kernel/debug/netdevsim/netdevsim0/ports/0/ipsec
  SA count=2 tx=20
  sa[0] rx ipaddr=0x00000000 00000000 00000000 0100a8c0
  sa[0]    spi=0x00000101 proto=0x32 salt=0x0adecc3a crypt=1
  sa[0]    key=0x3167608a ca4f1397 43565909 941fa627
  sa[1] tx ipaddr=0x00000000 00000000 00000000 00000000
  sa[1]    spi=0x00000100 proto=0x32 salt=0x0adecc3a crypt=1
  sa[1]    key=0x3167608a ca4f1397 43565909 941fa627

This patch updates the code to print the IPSec address in a human-readable
format for easier debug. e.g.

 # cat /sys/kernel/debug/netdevsim/netdevsim0/ports/0/ipsec
 SA count=4 tx=40
 sa[0] tx ipaddr=0.0.0.0
 sa[0]    spi=0x00000100 proto=0x32 salt=0x0adecc3a crypt=1
 sa[0]    key=0x3167608a ca4f1397 43565909 941fa627
 sa[1] rx ipaddr=192.168.0.1
 sa[1]    spi=0x00000101 proto=0x32 salt=0x0adecc3a crypt=1
 sa[1]    key=0x3167608a ca4f1397 43565909 941fa627
 sa[2] tx ipaddr=::
 sa[2]    spi=0x00000100 proto=0x32 salt=0x0adecc3a crypt=1
 sa[2]    key=0x3167608a ca4f1397 43565909 941fa627
 sa[3] rx ipaddr=2000::1
 sa[3]    spi=0x00000101 proto=0x32 salt=0x0adecc3a crypt=1
 sa[3]    key=0x3167608a ca4f1397 43565909 941fa627

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 drivers/net/netdevsim/ipsec.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/netdevsim/ipsec.c b/drivers/net/netdevsim/ipsec.c
index f0d58092e7e9..102b0955eb04 100644
--- a/drivers/net/netdevsim/ipsec.c
+++ b/drivers/net/netdevsim/ipsec.c
@@ -39,10 +39,14 @@ static ssize_t nsim_dbg_netdev_ops_read(struct file *filp,
 		if (!sap->used)
 			continue;
 
-		p += scnprintf(p, bufsize - (p - buf),
-			       "sa[%i] %cx ipaddr=0x%08x %08x %08x %08x\n",
-			       i, (sap->rx ? 'r' : 't'), sap->ipaddr[0],
-			       sap->ipaddr[1], sap->ipaddr[2], sap->ipaddr[3]);
+		if (sap->xs->props.family == AF_INET6)
+			p += scnprintf(p, bufsize - (p - buf),
+				       "sa[%i] %cx ipaddr=%pI6c\n",
+				       i, (sap->rx ? 'r' : 't'), &sap->ipaddr);
+		else
+			p += scnprintf(p, bufsize - (p - buf),
+				       "sa[%i] %cx ipaddr=%pI4\n",
+				       i, (sap->rx ? 'r' : 't'), &sap->ipaddr[3]);
 		p += scnprintf(p, bufsize - (p - buf),
 			       "sa[%i]    spi=0x%08x proto=0x%x salt=0x%08x crypt=%d\n",
 			       i, be32_to_cpu(sap->xs->id.spi),
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net-next 2/2] netdevsim: copy addresses for both in and out paths
  2024-10-08 12:21 [PATCH net-next 0/2] netdevsim: better ipsec output format Hangbin Liu
  2024-10-08 12:21 ` [PATCH net-next 1/2] netdevsim: print human readable IP address Hangbin Liu
@ 2024-10-08 12:21 ` Hangbin Liu
  2024-10-09 12:21   ` Simon Horman
  2024-10-09 17:13 ` [PATCH net-next 0/2] netdevsim: better ipsec output format Jakub Kicinski
  2 siblings, 1 reply; 8+ messages in thread
From: Hangbin Liu @ 2024-10-08 12:21 UTC (permalink / raw)
  To: netdev
  Cc: Jakub Kicinski, David S. Miller, Eric Dumazet, Paolo Abeni,
	Shannon Nelson, Jiri Pirko, linux-kernel, Hangbin Liu

The current code only copies the address for the in path, leaving the out
path address set to 0. This patch corrects the issue by copying the addresses
for both the in and out paths. Before this patch:

  # cat /sys/kernel/debug/netdevsim/netdevsim0/ports/0/ipsec
  SA count=2 tx=20
  sa[0] tx ipaddr=0.0.0.0
  sa[0]    spi=0x00000100 proto=0x32 salt=0x0adecc3a crypt=1
  sa[0]    key=0x3167608a ca4f1397 43565909 941fa627
  sa[1] rx ipaddr=192.168.0.1
  sa[1]    spi=0x00000101 proto=0x32 salt=0x0adecc3a crypt=1
  sa[1]    key=0x3167608a ca4f1397 43565909 941fa627

After this patch:

  = cat /sys/kernel/debug/netdevsim/netdevsim0/ports/0/ipsec
  SA count=2 tx=20
  sa[0] tx ipaddr=192.168.0.2
  sa[0]    spi=0x00000100 proto=0x32 salt=0x0adecc3a crypt=1
  sa[0]    key=0x3167608a ca4f1397 43565909 941fa627
  sa[1] rx ipaddr=192.168.0.1
  sa[1]    spi=0x00000101 proto=0x32 salt=0x0adecc3a crypt=1
  sa[1]    key=0x3167608a ca4f1397 43565909 941fa627

Fixes: 7699353da875 ("netdevsim: add ipsec offload testing")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 drivers/net/netdevsim/ipsec.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/net/netdevsim/ipsec.c b/drivers/net/netdevsim/ipsec.c
index 102b0955eb04..88187dd4eb2d 100644
--- a/drivers/net/netdevsim/ipsec.c
+++ b/drivers/net/netdevsim/ipsec.c
@@ -180,14 +180,13 @@ static int nsim_ipsec_add_sa(struct xfrm_state *xs,
 		return ret;
 	}
 
-	if (xs->xso.dir == XFRM_DEV_OFFLOAD_IN) {
+	if (xs->xso.dir == XFRM_DEV_OFFLOAD_IN)
 		sa.rx = true;
 
-		if (xs->props.family == AF_INET6)
-			memcpy(sa.ipaddr, &xs->id.daddr.a6, 16);
-		else
-			memcpy(&sa.ipaddr[3], &xs->id.daddr.a4, 4);
-	}
+	if (xs->props.family == AF_INET6)
+		memcpy(sa.ipaddr, &xs->id.daddr.a6, 16);
+	else
+		memcpy(&sa.ipaddr[3], &xs->id.daddr.a4, 4);
 
 	/* the preparations worked, so save the info */
 	memcpy(&ipsec->sa[sa_idx], &sa, sizeof(sa));
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next 1/2] netdevsim: print human readable IP address
  2024-10-08 12:21 ` [PATCH net-next 1/2] netdevsim: print human readable IP address Hangbin Liu
@ 2024-10-09 12:21   ` Simon Horman
  2024-10-09 15:22     ` Stanislav Fomichev
  0 siblings, 1 reply; 8+ messages in thread
From: Simon Horman @ 2024-10-09 12:21 UTC (permalink / raw)
  To: Hangbin Liu
  Cc: netdev, Jakub Kicinski, David S. Miller, Eric Dumazet,
	Paolo Abeni, Shannon Nelson, Jiri Pirko, linux-kernel

On Tue, Oct 08, 2024 at 12:21:33PM +0000, Hangbin Liu wrote:
> Currently, IPSec addresses are printed in hexadecimal format, which is
> not user-friendly. e.g.
> 
>   # cat /sys/kernel/debug/netdevsim/netdevsim0/ports/0/ipsec
>   SA count=2 tx=20
>   sa[0] rx ipaddr=0x00000000 00000000 00000000 0100a8c0
>   sa[0]    spi=0x00000101 proto=0x32 salt=0x0adecc3a crypt=1
>   sa[0]    key=0x3167608a ca4f1397 43565909 941fa627
>   sa[1] tx ipaddr=0x00000000 00000000 00000000 00000000
>   sa[1]    spi=0x00000100 proto=0x32 salt=0x0adecc3a crypt=1
>   sa[1]    key=0x3167608a ca4f1397 43565909 941fa627
> 
> This patch updates the code to print the IPSec address in a human-readable
> format for easier debug. e.g.
> 
>  # cat /sys/kernel/debug/netdevsim/netdevsim0/ports/0/ipsec
>  SA count=4 tx=40
>  sa[0] tx ipaddr=0.0.0.0
>  sa[0]    spi=0x00000100 proto=0x32 salt=0x0adecc3a crypt=1
>  sa[0]    key=0x3167608a ca4f1397 43565909 941fa627
>  sa[1] rx ipaddr=192.168.0.1
>  sa[1]    spi=0x00000101 proto=0x32 salt=0x0adecc3a crypt=1
>  sa[1]    key=0x3167608a ca4f1397 43565909 941fa627
>  sa[2] tx ipaddr=::
>  sa[2]    spi=0x00000100 proto=0x32 salt=0x0adecc3a crypt=1
>  sa[2]    key=0x3167608a ca4f1397 43565909 941fa627
>  sa[3] rx ipaddr=2000::1
>  sa[3]    spi=0x00000101 proto=0x32 salt=0x0adecc3a crypt=1
>  sa[3]    key=0x3167608a ca4f1397 43565909 941fa627
> 
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next 2/2] netdevsim: copy addresses for both in and out paths
  2024-10-08 12:21 ` [PATCH net-next 2/2] netdevsim: copy addresses for both in and out paths Hangbin Liu
@ 2024-10-09 12:21   ` Simon Horman
  0 siblings, 0 replies; 8+ messages in thread
From: Simon Horman @ 2024-10-09 12:21 UTC (permalink / raw)
  To: Hangbin Liu
  Cc: netdev, Jakub Kicinski, David S. Miller, Eric Dumazet,
	Paolo Abeni, Shannon Nelson, Jiri Pirko, linux-kernel

On Tue, Oct 08, 2024 at 12:21:34PM +0000, Hangbin Liu wrote:
> The current code only copies the address for the in path, leaving the out
> path address set to 0. This patch corrects the issue by copying the addresses
> for both the in and out paths. Before this patch:
> 
>   # cat /sys/kernel/debug/netdevsim/netdevsim0/ports/0/ipsec
>   SA count=2 tx=20
>   sa[0] tx ipaddr=0.0.0.0
>   sa[0]    spi=0x00000100 proto=0x32 salt=0x0adecc3a crypt=1
>   sa[0]    key=0x3167608a ca4f1397 43565909 941fa627
>   sa[1] rx ipaddr=192.168.0.1
>   sa[1]    spi=0x00000101 proto=0x32 salt=0x0adecc3a crypt=1
>   sa[1]    key=0x3167608a ca4f1397 43565909 941fa627
> 
> After this patch:
> 
>   = cat /sys/kernel/debug/netdevsim/netdevsim0/ports/0/ipsec
>   SA count=2 tx=20
>   sa[0] tx ipaddr=192.168.0.2
>   sa[0]    spi=0x00000100 proto=0x32 salt=0x0adecc3a crypt=1
>   sa[0]    key=0x3167608a ca4f1397 43565909 941fa627
>   sa[1] rx ipaddr=192.168.0.1
>   sa[1]    spi=0x00000101 proto=0x32 salt=0x0adecc3a crypt=1
>   sa[1]    key=0x3167608a ca4f1397 43565909 941fa627
> 
> Fixes: 7699353da875 ("netdevsim: add ipsec offload testing")
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next 1/2] netdevsim: print human readable IP address
  2024-10-09 12:21   ` Simon Horman
@ 2024-10-09 15:22     ` Stanislav Fomichev
  2024-10-10  3:00       ` Hangbin Liu
  0 siblings, 1 reply; 8+ messages in thread
From: Stanislav Fomichev @ 2024-10-09 15:22 UTC (permalink / raw)
  To: Simon Horman
  Cc: Hangbin Liu, netdev, Jakub Kicinski, David S. Miller,
	Eric Dumazet, Paolo Abeni, Shannon Nelson, Jiri Pirko,
	linux-kernel

On 10/09, Simon Horman wrote:
> On Tue, Oct 08, 2024 at 12:21:33PM +0000, Hangbin Liu wrote:
> > Currently, IPSec addresses are printed in hexadecimal format, which is
> > not user-friendly. e.g.
> > 
> >   # cat /sys/kernel/debug/netdevsim/netdevsim0/ports/0/ipsec
> >   SA count=2 tx=20
> >   sa[0] rx ipaddr=0x00000000 00000000 00000000 0100a8c0
> >   sa[0]    spi=0x00000101 proto=0x32 salt=0x0adecc3a crypt=1
> >   sa[0]    key=0x3167608a ca4f1397 43565909 941fa627
> >   sa[1] tx ipaddr=0x00000000 00000000 00000000 00000000
> >   sa[1]    spi=0x00000100 proto=0x32 salt=0x0adecc3a crypt=1
> >   sa[1]    key=0x3167608a ca4f1397 43565909 941fa627
> > 
> > This patch updates the code to print the IPSec address in a human-readable
> > format for easier debug. e.g.
> > 
> >  # cat /sys/kernel/debug/netdevsim/netdevsim0/ports/0/ipsec
> >  SA count=4 tx=40
> >  sa[0] tx ipaddr=0.0.0.0
> >  sa[0]    spi=0x00000100 proto=0x32 salt=0x0adecc3a crypt=1
> >  sa[0]    key=0x3167608a ca4f1397 43565909 941fa627
> >  sa[1] rx ipaddr=192.168.0.1
> >  sa[1]    spi=0x00000101 proto=0x32 salt=0x0adecc3a crypt=1
> >  sa[1]    key=0x3167608a ca4f1397 43565909 941fa627
> >  sa[2] tx ipaddr=::
> >  sa[2]    spi=0x00000100 proto=0x32 salt=0x0adecc3a crypt=1
> >  sa[2]    key=0x3167608a ca4f1397 43565909 941fa627
> >  sa[3] rx ipaddr=2000::1
> >  sa[3]    spi=0x00000101 proto=0x32 salt=0x0adecc3a crypt=1
> >  sa[3]    key=0x3167608a ca4f1397 43565909 941fa627
> > 
> > Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> 
> Reviewed-by: Simon Horman <horms@kernel.org>
> 

Can you also update tools/testing/selftests/net/rtnetlink.sh
accordingly? There is a part that diffs this file and it now fails due
to new format.

---
pw-bot: cr

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next 0/2] netdevsim: better ipsec output format.
  2024-10-08 12:21 [PATCH net-next 0/2] netdevsim: better ipsec output format Hangbin Liu
  2024-10-08 12:21 ` [PATCH net-next 1/2] netdevsim: print human readable IP address Hangbin Liu
  2024-10-08 12:21 ` [PATCH net-next 2/2] netdevsim: copy addresses for both in and out paths Hangbin Liu
@ 2024-10-09 17:13 ` Jakub Kicinski
  2 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2024-10-09 17:13 UTC (permalink / raw)
  To: Hangbin Liu
  Cc: netdev, David S. Miller, Eric Dumazet, Paolo Abeni,
	Shannon Nelson, Jiri Pirko, linux-kernel

On Tue,  8 Oct 2024 12:21:32 +0000 Hangbin Liu wrote:
> These 2 patches improve the netdevsim ipsec debug output with better
> format.

Hi! looks like you need to adjust the rtnetlink.sh test for the new
output format.
-- 
pw-bot: cr

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net-next 1/2] netdevsim: print human readable IP address
  2024-10-09 15:22     ` Stanislav Fomichev
@ 2024-10-10  3:00       ` Hangbin Liu
  0 siblings, 0 replies; 8+ messages in thread
From: Hangbin Liu @ 2024-10-10  3:00 UTC (permalink / raw)
  To: Stanislav Fomichev
  Cc: Simon Horman, netdev, Jakub Kicinski, David S. Miller,
	Eric Dumazet, Paolo Abeni, Shannon Nelson, Jiri Pirko,
	linux-kernel

On Wed, Oct 09, 2024 at 08:22:12AM -0700, Stanislav Fomichev wrote:
> Can you also update tools/testing/selftests/net/rtnetlink.sh
> accordingly? There is a part that diffs this file and it now fails due
> to new format.

Thanks for the reminding, I will update it.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-10-10  3:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-08 12:21 [PATCH net-next 0/2] netdevsim: better ipsec output format Hangbin Liu
2024-10-08 12:21 ` [PATCH net-next 1/2] netdevsim: print human readable IP address Hangbin Liu
2024-10-09 12:21   ` Simon Horman
2024-10-09 15:22     ` Stanislav Fomichev
2024-10-10  3:00       ` Hangbin Liu
2024-10-08 12:21 ` [PATCH net-next 2/2] netdevsim: copy addresses for both in and out paths Hangbin Liu
2024-10-09 12:21   ` Simon Horman
2024-10-09 17:13 ` [PATCH net-next 0/2] netdevsim: better ipsec output format Jakub Kicinski

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).