mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] net: netdevsim: fix byte order on ipsec debugfs file
@ 2022-03-08 13:51 Kleber Sacilotto de Souza
  2022-03-09  5:58 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Kleber Sacilotto de Souza @ 2022-03-08 13:51 UTC (permalink / raw)
  To: kuba, davem, shuah; +Cc: netdev, linux-kernel, linux-kselftest

When adding a new xfrm state, the data provided via struct xfrm_state
is stored in network byte order. This needs to be taken into
consideration when exporting the SAs data to userspace via debugfs,
otherwise the content will depend on the system endianness. Fix this by
converting all multi-byte fields from network to host order.

Also fix the selftest script which was expecting the data as exported by
a little-endian system, which was inverted.

Fixes: 7699353da875 ("netdevsim: add ipsec offload testing")
Fixes: 2766a11161cc ("selftests: rtnetlink: add ipsec offload API test")
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
---
 drivers/net/netdevsim/ipsec.c            | 13 +++++++------
 tools/testing/selftests/net/rtnetlink.sh | 10 +++++-----
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/net/netdevsim/ipsec.c b/drivers/net/netdevsim/ipsec.c
index b80ed2ffd45e..03fb8b56edc4 100644
--- a/drivers/net/netdevsim/ipsec.c
+++ b/drivers/net/netdevsim/ipsec.c
@@ -41,16 +41,17 @@ static ssize_t nsim_dbg_netdev_ops_read(struct file *filp,
 
 		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]);
+			       i, (sap->rx ? 'r' : 't'), ntohl(sap->ipaddr[0]),
+			       ntohl(sap->ipaddr[1]), ntohl(sap->ipaddr[2]),
+			       ntohl(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),
-			       sap->xs->id.proto, sap->salt, sap->crypt);
+			       i, ntohl(sap->xs->id.spi),
+			       sap->xs->id.proto, ntohl(sap->salt), sap->crypt);
 		p += scnprintf(p, bufsize - (p - buf),
 			       "sa[%i]    key=0x%08x %08x %08x %08x\n",
-			       i, sap->key[0], sap->key[1],
-			       sap->key[2], sap->key[3]);
+			       i, ntohl(sap->key[0]), ntohl(sap->key[1]),
+			       ntohl(sap->key[2]), ntohl(sap->key[3]));
 	}
 
 	len = simple_read_from_buffer(buffer, count, ppos, buf, p - buf);
diff --git a/tools/testing/selftests/net/rtnetlink.sh b/tools/testing/selftests/net/rtnetlink.sh
index c9ce3dfa42ee..8b1f20947673 100755
--- a/tools/testing/selftests/net/rtnetlink.sh
+++ b/tools/testing/selftests/net/rtnetlink.sh
@@ -814,11 +814,11 @@ kci_test_ipsec_offload()
 	diff $sysfsf - << EOF
 SA count=2 tx=3
 sa[0] tx ipaddr=0x00000000 00000000 00000000 00000000
-sa[0]    spi=0x00000009 proto=0x32 salt=0x61626364 crypt=1
-sa[0]    key=0x34333231 38373635 32313039 36353433
-sa[1] rx ipaddr=0x00000000 00000000 00000000 037ba8c0
-sa[1]    spi=0x00000009 proto=0x32 salt=0x61626364 crypt=1
-sa[1]    key=0x34333231 38373635 32313039 36353433
+sa[0]    spi=0x00000009 proto=0x32 salt=0x64636261 crypt=1
+sa[0]    key=0x31323334 35363738 39303132 33343536
+sa[1] rx ipaddr=0x00000000 00000000 00000000 c0a87b03
+sa[1]    spi=0x00000009 proto=0x32 salt=0x64636261 crypt=1
+sa[1]    key=0x31323334 35363738 39303132 33343536
 EOF
 	if [ $? -ne 0 ] ; then
 		echo "FAIL: ipsec_offload incorrect driver data"
-- 
2.32.0


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

end of thread, other threads:[~2022-03-09  9:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08 13:51 [PATCH] net: netdevsim: fix byte order on ipsec debugfs file Kleber Sacilotto de Souza
2022-03-09  5:58 ` Jakub Kicinski
2022-03-09  9:13   ` Kleber Souza

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®