From patchwork Wed Apr 20 22:24:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mat Martineau X-Patchwork-Id: 12820863 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D8F2C433F5 for ; Wed, 20 Apr 2022 22:25:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382695AbiDTW2R (ORCPT ); Wed, 20 Apr 2022 18:28:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354750AbiDTW2H (ORCPT ); Wed, 20 Apr 2022 18:28:07 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03F2040A24; Wed, 20 Apr 2022 15:25:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650493519; x=1682029519; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CPu4e6OUHz5baMW3HN5yprGNNE3W9upTmbpPnEKQkfk=; b=Mzqaa9TLg61IOQKtgwIahZ6DUvrO/XdfDJ8Uuv3/PhtY6FRZ4btpcSB5 F74QLwW+j8Z3Fq8PMMCbO3RPZ+JVhazO3y3AfJ6X+LtqFZ9Lt7AvvXZV2 umzmCs9ob7rv1HIq2THCR/vfk5OIRPrjnMtwwD5mgF2m+XqbOD4DS2NFO sYpYDZo1cBCCu8TmwR6Mjr9u2zxDyThDS+g7+ALQApaDwgme2KPygLMaA 5x8VQBWDdsxyGUsrFya8Czk1qiqqt8Mk/de/JaYvym3YrMqkF/3aZTyAX 8oLb13A9W6ovvkY0iHiJW/JpMyJ1/62iQf28gjEUU3HkwSh5uEhWQYV5b w==; X-IronPort-AV: E=McAfee;i="6400,9594,10323"; a="289277613" X-IronPort-AV: E=Sophos;i="5.90,276,1643702400"; d="scan'208";a="289277613" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2022 15:25:19 -0700 X-IronPort-AV: E=Sophos;i="5.90,276,1643702400"; d="scan'208";a="555422613" Received: from mjmartin-desk2.amr.corp.intel.com (HELO mjmartin-desk2.intel.com) ([10.209.100.38]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2022 15:25:18 -0700 From: Mat Martineau To: netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Geliang Tang , ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, mptcp@lists.linux.dev, Matthieu Baerts , Mat Martineau Subject: [PATCH bpf-next 7/7] selftests: bpf: verify first of struct mptcp_sock Date: Wed, 20 Apr 2022 15:24:59 -0700 Message-Id: <20220420222459.307649-8-mathew.j.martineau@linux.intel.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220420222459.307649-1-mathew.j.martineau@linux.intel.com> References: <20220420222459.307649-1-mathew.j.martineau@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang This patch verifies the 'first' struct member of struct mptcp_sock, which points to the first subflow of msk. Save 'sk' in mptcp_storage, and verify it with 'first' in verify_msk(). Acked-by: Matthieu Baerts Signed-off-by: Geliang Tang Signed-off-by: Mat Martineau --- tools/testing/selftests/bpf/bpf_mptcp_helpers.h | 1 + tools/testing/selftests/bpf/prog_tests/mptcp.c | 8 ++++++++ tools/testing/selftests/bpf/progs/mptcp_sock.c | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/tools/testing/selftests/bpf/bpf_mptcp_helpers.h b/tools/testing/selftests/bpf/bpf_mptcp_helpers.h index 463e4e061c96..b5a43b108982 100644 --- a/tools/testing/selftests/bpf/bpf_mptcp_helpers.h +++ b/tools/testing/selftests/bpf/bpf_mptcp_helpers.h @@ -10,6 +10,7 @@ struct mptcp_sock { struct inet_connection_sock sk; __u32 token; + struct sock *first; char ca_name[TCP_CA_NAME_MAX]; } __attribute__((preserve_access_index)); diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 4518aa6e661e..7e704f5aab05 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -12,7 +12,9 @@ struct mptcp_storage { __u32 invoked; __u32 is_mptcp; + struct sock *sk; __u32 token; + struct sock *first; char ca_name[TCP_CA_NAME_MAX]; }; @@ -133,6 +135,12 @@ static int verify_msk(int map_fd, int client_fd) err++; } + if (val.first != val.sk) { + log_err("Unexpected mptcp_sock.first %p != %p", + val.first, val.sk); + err++; + } + if (strncmp(val.ca_name, ca_name, TCP_CA_NAME_MAX)) { log_err("Unexpected mptcp_sock.ca_name %s != %s", val.ca_name, ca_name); diff --git a/tools/testing/selftests/bpf/progs/mptcp_sock.c b/tools/testing/selftests/bpf/progs/mptcp_sock.c index 53bf67580010..1d1ac7cda2a2 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_sock.c +++ b/tools/testing/selftests/bpf/progs/mptcp_sock.c @@ -12,7 +12,9 @@ __u32 _version SEC("version") = 1; struct mptcp_storage { __u32 invoked; __u32 is_mptcp; + struct sock *sk; __u32 token; + struct sock *first; char ca_name[TCP_CA_NAME_MAX]; }; @@ -51,6 +53,7 @@ int _sockops(struct bpf_sock_ops *ctx) storage->token = 0; bzero(storage->ca_name, TCP_CA_NAME_MAX); + storage->first = NULL; } else { msk = bpf_skc_to_mptcp_sock(sk); if (!msk) @@ -63,9 +66,11 @@ int _sockops(struct bpf_sock_ops *ctx) storage->token = msk->token; memcpy(storage->ca_name, msk->ca_name, TCP_CA_NAME_MAX); + storage->first = msk->first; } storage->invoked++; storage->is_mptcp = tcp_sk->is_mptcp; + storage->sk = (struct sock *)sk; return 1; }