From patchwork Fri May 13 22:48:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mat Martineau X-Patchwork-Id: 12849541 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 06BD4C433EF for ; Fri, 13 May 2022 22:48:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384850AbiEMWs5 (ORCPT ); Fri, 13 May 2022 18:48:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384865AbiEMWsj (ORCPT ); Fri, 13 May 2022 18:48:39 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BE5C532C6; Fri, 13 May 2022 15:48:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652482118; x=1684018118; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=URZIdz+kPYwRPTgIUb6zoaKFH5Th8DZkust7oQxgKFc=; b=NNM7JRFYe1wYwZgQzhcAZMQ8793C9ttgwpVfR0fPmcVlht1A0W3o1Lo/ eGNZyd3qziHKZM3REAx6uCv/AplnxZvmX1rmY7wbN/URVAiJYI2U8Q2VZ eF32v0fKPqnpBepcUSKUITyzrdFDm2HH28C7v3MuETV8NwVyNQ8/pZyO9 kiMFn+I0FhlHASH+/kGSYXsO6k3sUN+3dCAxwR85SmvUxUyN9j78ADc+f 048DBcRgohPHZhaV79lE/OJ4Byve7zrct5s6Jo5bZ8d76gIJ/6h7V5ZJP dH1vPZjcKM8xZsUqrCAIYSCPKfzybrmJt529qSyzTVj/ObuWCiGEsUGg1 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10346"; a="270101184" X-IronPort-AV: E=Sophos;i="5.91,223,1647327600"; d="scan'208";a="270101184" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2022 15:48:35 -0700 X-IronPort-AV: E=Sophos;i="5.91,223,1647327600"; d="scan'208";a="815588257" Received: from clakshma-mobl1.amr.corp.intel.com (HELO mjmartin-desk2.intel.com) ([10.212.160.121]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2022 15:48:35 -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 v4 7/7] selftests/bpf: verify first of struct mptcp_sock Date: Fri, 13 May 2022 15:48:27 -0700 Message-Id: <20220513224827.662254-8-mathew.j.martineau@linux.intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220513224827.662254-1-mathew.j.martineau@linux.intel.com> References: <20220513224827.662254-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_tcp_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_tcp_helpers.h b/tools/testing/selftests/bpf/bpf_tcp_helpers.h index c38c66d5c1e6..82a7c9de95f9 100644 --- a/tools/testing/selftests/bpf/bpf_tcp_helpers.h +++ b/tools/testing/selftests/bpf/bpf_tcp_helpers.h @@ -234,6 +234,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 2ff7f18ea0ce..51a3e17acb9e 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -13,7 +13,9 @@ struct mptcp_storage { __u32 invoked; __u32 is_mptcp; + struct sock *sk; __u32 token; + struct sock *first; char ca_name[TCP_CA_NAME_MAX]; }; @@ -136,6 +138,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 c36f2f6bd2f1..ab135edf3ae3 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_sock.c +++ b/tools/testing/selftests/bpf/progs/mptcp_sock.c @@ -13,7 +13,9 @@ extern bool CONFIG_MPTCP __kconfig; struct mptcp_storage { __u32 invoked; __u32 is_mptcp; + struct sock *sk; __u32 token; + struct sock *first; char ca_name[TCP_CA_NAME_MAX]; }; @@ -54,6 +56,7 @@ int _sockops(struct bpf_sock_ops *ctx) storage->token = 0; bzero(storage->ca_name, TCP_CA_NAME_MAX); + storage->first = NULL; } else { if (!CONFIG_MPTCP) return 1; @@ -69,9 +72,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 = is_mptcp; + storage->sk = (struct sock *)sk; return 1; }