Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3586750pxp; Tue, 8 Mar 2022 18:09:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyrGAeYUWNkzK0Xf3Q2BeGwV+Fy9izsn2txNnSnSKSIpJXjbdRs7FD+cwbwKSr0IoawE5hu X-Received: by 2002:a17:902:7207:b0:14d:938e:a88e with SMTP id ba7-20020a170902720700b0014d938ea88emr20414459plb.42.1646791746458; Tue, 08 Mar 2022 18:09:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646791746; cv=none; d=google.com; s=arc-20160816; b=tSft11vpPV8imFD2+QdbaBO28D6zLh0s2l/jmZVt4F+RTJY85JCokolZluydcfUiSe HbsDFKMykafEKUti4LSxnNhZmEV1Ryl08Z8jcWD9KITvi7TPla6/PStMmsGznWz8hp2q 2ff4mlJb80TB7olHOL34FKTBBw/kbw9cfzU8Mpi07/kt+fNKs5wy8bzaW7ltRWZ+QPrM MQyGj3avQeTglYy5ioCk2PWlz4osXTI6KKWdUgUm0yfPKyQlZe4mDQKsHdGBkYViL+ei FhqjUI25+WEOKrDV5V91Q2SUorPPuR7rijm+pjOA9tka6syhwNctwjP8tVtUnROrXgyc r1vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=gfyiehsHSCfxlKgNkCwVdg7pcAcR1+WSTjtuQee0hjc=; b=PGhgJ4VVearhgwiwPBdYc6tD6WmZJEHcC1PlLEGOcHMFO87L2uSglh4KIt40S2fz+q ddncKEbfHWIkOKv+fT0XeoSmQZEjL/MYrObwJ8BIvHQmtjbn7REnC35hJfkKvJEwxSFf d9WQyT67SjbIXrejqLAd0SofdKDqF6augPAk0w7CDN6WdbAZKAyuJTwO6u+nm4T1KdLK guNUER3dWrWHrBg/NsC1CsH4djg9fmje1xVODJx0kshjwqaik2pm2lpEp8SzPAZSVJxf d2SsS4GO8qPl/T4GDnIPT3d3FB610qgAwt4gv679wCMvD2V4IhCdyU60n2Xmo//AmM0a 2hgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=CBEJzHxU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id e12-20020a17090a77cc00b001bf7513fb01si3802137pjs.98.2022.03.08.18.09.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 18:09:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=CBEJzHxU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EB2962571DE; Tue, 8 Mar 2022 16:39:07 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240491AbiCHNwn (ORCPT + 99 others); Tue, 8 Mar 2022 08:52:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230457AbiCHNwl (ORCPT ); Tue, 8 Mar 2022 08:52:41 -0500 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46D7740E56 for ; Tue, 8 Mar 2022 05:51:45 -0800 (PST) Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id E29DC3F4C2 for ; Tue, 8 Mar 2022 13:51:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1646747502; bh=gfyiehsHSCfxlKgNkCwVdg7pcAcR1+WSTjtuQee0hjc=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=CBEJzHxUgr+Qw0BD/FZ/GCN6XoBt1JE/0ywZc4gf2wXJpNXOq6yi2NhHFFBU1/+HB 6RgJVne8zfY2wO1YsixXcVPFkQp4jZPZ3YQtFHlYFgcqFAcv/jn57EArlh/ZXYYc0E oJJVvygotOsXkwPCxpIhiCYwN+BO8leEmRy53H2uPg1siwL/hSZZkXgZGe52sK6TvK 7EvN5yJoanW9mFXdtp/MBr3IPgggnhZXZ3jo8BMk/LHGuflt8OD2cdzRPrNXxJyFmF SzQOjO3Gg735VT2AMMpv6XoVGuHFsZQErp1XLtp0RbsBRpVqc9p1sBO3E57ndITUH4 veqjWod+WdF8w== Received: by mail-ej1-f70.google.com with SMTP id r18-20020a17090609d200b006a6e943d09eso8683248eje.20 for ; Tue, 08 Mar 2022 05:51:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gfyiehsHSCfxlKgNkCwVdg7pcAcR1+WSTjtuQee0hjc=; b=wpjRDg9Y1VRi5vorOoX071uXBq6+oyyAzcVDJF5c8oH8Ma+liqLbqVgkzE183oBOVr ybsKshd9PKbjf4zwV7AcTPzlhMFREfpwJ32YgLrb04VIx30INQ2HBjpR8EmgaGTHwpyK XrPXA39JISPECo/BrRf0Oyybk1biQx1ZLCZKUoWyIYeGV26muA1r9YkuX7svbMoBc6Ya FV6diy9pgJsdOPvLc5OhJTrtQJwl3NnUv8Hi9jQJW9HYNeKVnJiUAxNhVJrb7l8AibxD tPvGo5fzEh8WEy2HObVoka80+iFDlEkBQh6Xx8DOy5crUgX7p2nDNb1Xfg/wvajKMrbx Zy/g== X-Gm-Message-State: AOAM532Zi9j6MmNnV3o9IBO4nWJ/sJt7D7RfFOPzX0CKy+4nd5f1g3Ol M+PktvTVzWtmjWC7HJpe0ueQBnDNTb3yKHPB+vW1RB7XXT5z6Zy7bpIXcW+UYoeJ3iAclzfnfty Ud5HbW+1PaaMyObUMN/5OL3NyiScsCRX+Upzrejl6hw== X-Received: by 2002:a17:906:2b93:b0:6cf:bb48:5a80 with SMTP id m19-20020a1709062b9300b006cfbb485a80mr12934380ejg.681.1646747502549; Tue, 08 Mar 2022 05:51:42 -0800 (PST) X-Received: by 2002:a17:906:2b93:b0:6cf:bb48:5a80 with SMTP id m19-20020a1709062b9300b006cfbb485a80mr12934365ejg.681.1646747502267; Tue, 08 Mar 2022 05:51:42 -0800 (PST) Received: from localhost.localdomain (p5087f509.dip0.t-ipconnect.de. [80.135.245.9]) by smtp.gmail.com with ESMTPSA id b15-20020a50cccf000000b0040f74c6abedsm7606163edj.77.2022.03.08.05.51.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 05:51:41 -0800 (PST) From: Kleber Sacilotto de Souza To: kuba@kernel.org, davem@davemloft.net, shuah@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH] net: netdevsim: fix byte order on ipsec debugfs file Date: Tue, 8 Mar 2022 14:51:06 +0100 Message-Id: <20220308135106.890270-1-kleber.souza@canonical.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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