diff mbox series

[net-next,1/2] netdevsim: print human readable IP address

Message ID 20241008122134.4343-2-liuhangbin@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series netdevsim: better ipsec output format. | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 6 this patch: 6
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 6 this patch: 6
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 5 this patch: 5
netdev/checkpatch warning WARNING: line length of 82 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-10-09--06-00 (tests: 775)

Commit Message

Hangbin Liu Oct. 8, 2024, 12:21 p.m. UTC
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(-)

Comments

Simon Horman Oct. 9, 2024, 12:21 p.m. UTC | #1
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>
Stanislav Fomichev Oct. 9, 2024, 3:22 p.m. UTC | #2
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
Hangbin Liu Oct. 10, 2024, 3 a.m. UTC | #3
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.
diff mbox series

Patch

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