From patchwork Thu May 19 23:30:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mat Martineau X-Patchwork-Id: 12856127 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 AB795C4332F for ; Thu, 19 May 2022 23:30:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343594AbiESXa1 (ORCPT ); Thu, 19 May 2022 19:30:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343547AbiESXaY (ORCPT ); Thu, 19 May 2022 19:30:24 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C806610788E; Thu, 19 May 2022 16:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653003022; x=1684539022; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kE9fd53xn9fCor2XbVfB6M/J0Fibpx2PlFNL0D/30Q8=; b=PK/8lcnRdz71NyaGnoCzQK6bKwSUqJZIhyxZqFkC1UjrPumuePDiPXuJ MutaW8o0SMDIlVAWyUOQ7WOLlN63SklPxkLX50mcYR1DlZmQl3tnFQ193 XTGVFqYtkL5oBY1sxc6MvzsFoLokhiznGgsH/fSfd38K+86ZHUQdASM2C m8h3pKbt1ukZAQyk/39STu65KhW8lH8fE/nXYhfCKRltPR1jOfSvANaXJ c3AR+KHvRs2oaEq3EElg/r2xpUlawWeIHM8goCn3/5U70f6YUojC1dIGi DFQysQ0CubfHHryZHiS7B0Ufhi3+4gqGwa2PpLvxGl4VtYOgVK0Z3uEfF g==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="272547197" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="272547197" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 16:30:21 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570491192" Received: from mjmartin-desk2.amr.corp.intel.com (HELO mjmartin-desk2.intel.com) ([10.252.132.179]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 16:30:21 -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, Nicolas Rybowski , Matthieu Baerts , Mat Martineau Subject: [PATCH bpf-next v5 1/7] bpf: add bpf_skc_to_mptcp_sock_proto Date: Thu, 19 May 2022 16:30:10 -0700 Message-Id: <20220519233016.105670-2-mathew.j.martineau@linux.intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220519233016.105670-1-mathew.j.martineau@linux.intel.com> References: <20220519233016.105670-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 implements a new struct bpf_func_proto, named bpf_skc_to_mptcp_sock_proto. Define a new bpf_id BTF_SOCK_TYPE_MPTCP, and a new helper bpf_skc_to_mptcp_sock(), which invokes another new helper bpf_mptcp_sock_from_subflow() in net/mptcp/bpf.c to get struct mptcp_sock from a given subflow socket. v2: Emit BTF type, add func_id checks in verifier.c and bpf_trace.c, remove build check for CONFIG_BPF_JIT v5: Drop EXPORT_SYMBOL (Martin) Co-developed-by: Nicolas Rybowski Signed-off-by: Nicolas Rybowski Co-developed-by: Matthieu Baerts Signed-off-by: Matthieu Baerts Signed-off-by: Geliang Tang Signed-off-by: Mat Martineau --- include/linux/bpf.h | 1 + include/linux/btf_ids.h | 3 ++- include/net/mptcp.h | 6 ++++++ include/uapi/linux/bpf.h | 7 +++++++ kernel/bpf/verifier.c | 1 + kernel/trace/bpf_trace.c | 2 ++ net/core/filter.c | 18 ++++++++++++++++++ net/mptcp/Makefile | 2 ++ net/mptcp/bpf.c | 21 +++++++++++++++++++++ scripts/bpf_doc.py | 2 ++ tools/include/uapi/linux/bpf.h | 7 +++++++ 11 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 net/mptcp/bpf.c diff --git a/include/linux/bpf.h b/include/linux/bpf.h index c107392b0ba7..a3ef078401cf 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -2231,6 +2231,7 @@ extern const struct bpf_func_proto bpf_skc_to_tcp_timewait_sock_proto; extern const struct bpf_func_proto bpf_skc_to_tcp_request_sock_proto; extern const struct bpf_func_proto bpf_skc_to_udp6_sock_proto; extern const struct bpf_func_proto bpf_skc_to_unix_sock_proto; +extern const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto; extern const struct bpf_func_proto bpf_copy_from_user_proto; extern const struct bpf_func_proto bpf_snprintf_btf_proto; extern const struct bpf_func_proto bpf_snprintf_proto; diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h index bc5d9cc34e4c..335a19092368 100644 --- a/include/linux/btf_ids.h +++ b/include/linux/btf_ids.h @@ -178,7 +178,8 @@ extern struct btf_id_set name; BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \ BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \ BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) \ - BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) + BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) \ + BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock) enum { #define BTF_SOCK_TYPE(name, str) name, diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 8b1afd6f5cc4..2ba09de955c7 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -284,4 +284,10 @@ static inline int mptcpv6_init(void) { return 0; } static inline void mptcpv6_handle_mapped(struct sock *sk, bool mapped) { } #endif +#if defined(CONFIG_MPTCP) && defined(CONFIG_BPF_SYSCALL) +struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk); +#else +static inline struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk) { return NULL; } +#endif + #endif /* __NET_MPTCP_H */ diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 0210f85131b3..56688bee20d9 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -5172,6 +5172,12 @@ union bpf_attr { * Return * Map value associated to *key* on *cpu*, or **NULL** if no entry * was found or *cpu* is invalid. + * + * struct mptcp_sock *bpf_skc_to_mptcp_sock(void *sk) + * Description + * Dynamically cast a *sk* pointer to a *mptcp_sock* pointer. + * Return + * *sk* if casting is valid, or **NULL** otherwise. */ #define __BPF_FUNC_MAPPER(FN) \ FN(unspec), \ @@ -5370,6 +5376,7 @@ union bpf_attr { FN(ima_file_hash), \ FN(kptr_xchg), \ FN(map_lookup_percpu_elem), \ + FN(skc_to_mptcp_sock), \ /* */ /* integer value in 'imm' field of BPF_CALL instruction selects which helper diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 9b59581026f8..14e8c17d3d8d 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -509,6 +509,7 @@ static bool is_ptr_cast_function(enum bpf_func_id func_id) func_id == BPF_FUNC_skc_to_tcp_sock || func_id == BPF_FUNC_skc_to_tcp6_sock || func_id == BPF_FUNC_skc_to_udp6_sock || + func_id == BPF_FUNC_skc_to_mptcp_sock || func_id == BPF_FUNC_skc_to_tcp_timewait_sock || func_id == BPF_FUNC_skc_to_tcp_request_sock; } diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 7141ca8a1c2d..10b157a6d73e 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -1705,6 +1705,8 @@ tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return &bpf_skc_to_udp6_sock_proto; case BPF_FUNC_skc_to_unix_sock: return &bpf_skc_to_unix_sock_proto; + case BPF_FUNC_skc_to_mptcp_sock: + return &bpf_skc_to_mptcp_sock_proto; case BPF_FUNC_sk_storage_get: return &bpf_sk_storage_get_tracing_proto; case BPF_FUNC_sk_storage_delete: diff --git a/net/core/filter.c b/net/core/filter.c index fe0da529d00f..5af58eb48587 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -78,6 +78,7 @@ #include #include #include +#include static const struct bpf_func_proto * bpf_sk_base_func_proto(enum bpf_func_id func_id); @@ -11281,6 +11282,20 @@ const struct bpf_func_proto bpf_skc_to_unix_sock_proto = { .ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_UNIX], }; +BPF_CALL_1(bpf_skc_to_mptcp_sock, struct sock *, sk) +{ + BTF_TYPE_EMIT(struct mptcp_sock); + return (unsigned long)bpf_mptcp_sock_from_subflow(sk); +} + +const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto = { + .func = bpf_skc_to_mptcp_sock, + .gpl_only = false, + .ret_type = RET_PTR_TO_BTF_ID_OR_NULL, + .arg1_type = ARG_PTR_TO_SOCK_COMMON, + .ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_MPTCP], +}; + BPF_CALL_1(bpf_sock_from_file, struct file *, file) { return (unsigned long)sock_from_file(file); @@ -11323,6 +11338,9 @@ bpf_sk_base_func_proto(enum bpf_func_id func_id) case BPF_FUNC_skc_to_unix_sock: func = &bpf_skc_to_unix_sock_proto; break; + case BPF_FUNC_skc_to_mptcp_sock: + func = &bpf_skc_to_mptcp_sock_proto; + break; case BPF_FUNC_ktime_get_coarse_ns: return &bpf_ktime_get_coarse_ns_proto; default: diff --git a/net/mptcp/Makefile b/net/mptcp/Makefile index e54daceac58b..99dddf08ca73 100644 --- a/net/mptcp/Makefile +++ b/net/mptcp/Makefile @@ -10,3 +10,5 @@ obj-$(CONFIG_INET_MPTCP_DIAG) += mptcp_diag.o mptcp_crypto_test-objs := crypto_test.o mptcp_token_test-objs := token_test.o obj-$(CONFIG_MPTCP_KUNIT_TEST) += mptcp_crypto_test.o mptcp_token_test.o + +obj-$(CONFIG_BPF_SYSCALL) += bpf.o diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c new file mode 100644 index 000000000000..5a0a84ad94af --- /dev/null +++ b/net/mptcp/bpf.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Multipath TCP + * + * Copyright (c) 2020, Tessares SA. + * Copyright (c) 2022, SUSE. + * + * Author: Nicolas Rybowski + */ + +#define pr_fmt(fmt) "MPTCP: " fmt + +#include +#include "protocol.h" + +struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk) +{ + if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk)) + return mptcp_sk(mptcp_subflow_ctx(sk)->conn); + + return NULL; +} diff --git a/scripts/bpf_doc.py b/scripts/bpf_doc.py index 096625242475..d5452f7eb996 100755 --- a/scripts/bpf_doc.py +++ b/scripts/bpf_doc.py @@ -633,6 +633,7 @@ class PrinterHelpers(Printer): 'struct socket', 'struct file', 'struct bpf_timer', + 'struct mptcp_sock', ] known_types = { '...', @@ -682,6 +683,7 @@ class PrinterHelpers(Printer): 'struct socket', 'struct file', 'struct bpf_timer', + 'struct mptcp_sock', } mapped_types = { 'u8': '__u8', diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 0210f85131b3..56688bee20d9 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -5172,6 +5172,12 @@ union bpf_attr { * Return * Map value associated to *key* on *cpu*, or **NULL** if no entry * was found or *cpu* is invalid. + * + * struct mptcp_sock *bpf_skc_to_mptcp_sock(void *sk) + * Description + * Dynamically cast a *sk* pointer to a *mptcp_sock* pointer. + * Return + * *sk* if casting is valid, or **NULL** otherwise. */ #define __BPF_FUNC_MAPPER(FN) \ FN(unspec), \ @@ -5370,6 +5376,7 @@ union bpf_attr { FN(ima_file_hash), \ FN(kptr_xchg), \ FN(map_lookup_percpu_elem), \ + FN(skc_to_mptcp_sock), \ /* */ /* integer value in 'imm' field of BPF_CALL instruction selects which helper From patchwork Thu May 19 23:30:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mat Martineau X-Patchwork-Id: 12856128 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 09281C43219 for ; Thu, 19 May 2022 23:30:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343601AbiESXaa (ORCPT ); Thu, 19 May 2022 19:30:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343550AbiESXaY (ORCPT ); Thu, 19 May 2022 19:30:24 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0520C108A94; Thu, 19 May 2022 16:30:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653003022; x=1684539022; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Fpbu7J+T3sEY5KzKGDHOZcdSlNTcq4FmV5F0zYAzn2c=; b=nJ/ORpCTQ+oYPuwVv/WsHvciamTghyvXzVkkNEe6xubqincrW1yGUaRf w3aUp1HWUcEsypVa76bzs8AypJLyJSLAgRz7CX4t7Xq0okpuDW5LajgGb ixFu49KcYBSIYwa39Z5/K2JjF9OLlb+rE37PVfsU+RGDCe8YEur8uvDVw bB5YsFkO8U02Lqoga4279C9DAJNzbigAoV5byXVNc7orFJuyCtG1nN6g4 O5IyzkfXtm6mrT5GKz47pvoQqWGKJzyWtauqLmqGW5xUNrDwxG+ATMTtQ ulRZH9wJDMH6PpCE3r/SS8ss4MaZn2GMT8F3C8jeOBDy7g1UwdLC79AZ2 w==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="272547198" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="272547198" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 16:30:21 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570491195" Received: from mjmartin-desk2.amr.corp.intel.com (HELO mjmartin-desk2.intel.com) ([10.252.132.179]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 16:30:21 -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, Mat Martineau Subject: [PATCH bpf-next v5 2/7] selftests/bpf: Enable CONFIG_IKCONFIG_PROC in config Date: Thu, 19 May 2022 16:30:11 -0700 Message-Id: <20220519233016.105670-3-mathew.j.martineau@linux.intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220519233016.105670-1-mathew.j.martineau@linux.intel.com> References: <20220519233016.105670-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 CONFIG_IKCONFIG_PROC is required by BPF selftests, otherwise we get errors like this: libbpf: failed to open system Kconfig libbpf: failed to load object 'kprobe_multi' libbpf: failed to load BPF skeleton 'kprobe_multi': -22 It's because /proc/config.gz is opened in bpf_object__read_kconfig_file() in tools/lib/bpf/libbpf.c: file = gzopen("/proc/config.gz", "r"); So this patch enables CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC in tools/testing/selftests/bpf/config. Suggested-by: Mat Martineau Acked-by: Andrii Nakryiko Signed-off-by: Geliang Tang Signed-off-by: Mat Martineau --- tools/testing/selftests/bpf/config | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/bpf/config b/tools/testing/selftests/bpf/config index 08c6e5a66d87..6840d4625e01 100644 --- a/tools/testing/selftests/bpf/config +++ b/tools/testing/selftests/bpf/config @@ -54,3 +54,5 @@ CONFIG_NF_DEFRAG_IPV6=y CONFIG_NF_CONNTRACK=y CONFIG_USERFAULTFD=y CONFIG_FPROBE=y +CONFIG_IKCONFIG=y +CONFIG_IKCONFIG_PROC=y From patchwork Thu May 19 23:30:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mat Martineau X-Patchwork-Id: 12856130 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 C109AC43217 for ; Thu, 19 May 2022 23:30:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343600AbiESXac (ORCPT ); Thu, 19 May 2022 19:30:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343561AbiESXa0 (ORCPT ); Thu, 19 May 2022 19:30:26 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9299106561; Thu, 19 May 2022 16:30:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653003024; x=1684539024; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wAG9yook11rtidlMTTelROrVfsZ/KpX4nTTRFRm0nZE=; b=BB7lrgep63OQe1w8gZSQ3pc/o9D9GA8Xssy5ogIp47Cwd8KxaqMiu2QI YxppXokqvPsGWZ6/EEVd1vCtMagKD3ncHixGAaJgmoWm5w2S9FY7/pTTP 7rZUtxl1liiafpcaL//qFGNCMa8f5klZyyJsw1578vastuP73KsnCQr+B 1B7Yuypb2QgDIK4Z9JBWCtbA6N9kNgq8BCkD/Lb6KpcC1RZhvrCPqVj24 kTv3EiDyNh/O78/uliii2aZw/kiXA7ndhGX/d1thB8UOknsrbo0prQb2W dSrvX5ayJmW3pP07VjcgUaQnq7I0V8i/+iIESczNxcMfkmZptQ40xS47m w==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="272547199" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="272547199" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 16:30:22 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570491196" Received: from mjmartin-desk2.amr.corp.intel.com (HELO mjmartin-desk2.intel.com) ([10.252.132.179]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 16:30:21 -0700 From: Mat Martineau To: netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Nicolas Rybowski , ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, geliang.tang@suse.com, mptcp@lists.linux.dev, Matthieu Baerts , Mat Martineau Subject: [PATCH bpf-next v5 3/7] selftests/bpf: add MPTCP test base Date: Thu, 19 May 2022 16:30:12 -0700 Message-Id: <20220519233016.105670-4-mathew.j.martineau@linux.intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220519233016.105670-1-mathew.j.martineau@linux.intel.com> References: <20220519233016.105670-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: Nicolas Rybowski This patch adds a base for MPTCP specific tests. It is currently limited to the is_mptcp field in case of plain TCP connection because there is no easy way to get the subflow sk from a msk in userspace. This implies that we cannot lookup the sk_storage attached to the subflow sk in the sockops program. v4: - add copyright 2022 (Andrii) - use ASSERT_* instead of CHECK_FAIL (Andrii) - drop SEC("version") (Andrii) - use is_mptcp in tcp_sock, instead of bpf_tcp_sock (Martin & Andrii) v5: - Drop connect_to_mptcp_fd (Martin) - Use BPF test skeleton (Andrii) - Use ASSERT_EQ (Andrii) - Drop the 'msg' parameter of verify_sk Acked-by: Matthieu Baerts Co-developed-by: Geliang Tang Signed-off-by: Geliang Tang Signed-off-by: Nicolas Rybowski Signed-off-by: Mat Martineau --- MAINTAINERS | 1 + tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 + tools/testing/selftests/bpf/config | 1 + tools/testing/selftests/bpf/network_helpers.c | 40 +++++-- tools/testing/selftests/bpf/network_helpers.h | 2 + .../testing/selftests/bpf/prog_tests/mptcp.c | 112 ++++++++++++++++++ .../testing/selftests/bpf/progs/mptcp_sock.c | 53 +++++++++ 7 files changed, 201 insertions(+), 9 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/mptcp.c create mode 100644 tools/testing/selftests/bpf/progs/mptcp_sock.c diff --git a/MAINTAINERS b/MAINTAINERS index cc5559a7fb5c..359afc617b92 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13780,6 +13780,7 @@ F: include/net/mptcp.h F: include/trace/events/mptcp.h F: include/uapi/linux/mptcp.h F: net/mptcp/ +F: tools/testing/selftests/bpf/*/*mptcp*.c F: tools/testing/selftests/net/mptcp/ NETWORKING [TCP] diff --git a/tools/testing/selftests/bpf/bpf_tcp_helpers.h b/tools/testing/selftests/bpf/bpf_tcp_helpers.h index b1ede6f0b821..22e0c8849a17 100644 --- a/tools/testing/selftests/bpf/bpf_tcp_helpers.h +++ b/tools/testing/selftests/bpf/bpf_tcp_helpers.h @@ -81,6 +81,7 @@ struct tcp_sock { __u32 lsndtime; __u32 prior_cwnd; __u64 tcp_mstamp; /* most recent packet received/sent */ + bool is_mptcp; } __attribute__((preserve_access_index)); static __always_inline struct inet_connection_sock *inet_csk(const struct sock *sk) diff --git a/tools/testing/selftests/bpf/config b/tools/testing/selftests/bpf/config index 6840d4625e01..3b3edc0fc8a6 100644 --- a/tools/testing/selftests/bpf/config +++ b/tools/testing/selftests/bpf/config @@ -56,3 +56,4 @@ CONFIG_USERFAULTFD=y CONFIG_FPROBE=y CONFIG_IKCONFIG=y CONFIG_IKCONFIG_PROC=y +CONFIG_MPTCP=y diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 2bb1f9b3841d..59cf81ec55af 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -21,6 +21,10 @@ #include "network_helpers.h" #include "test_progs.h" +#ifndef IPPROTO_MPTCP +#define IPPROTO_MPTCP 262 +#endif + #define clean_errno() (errno == 0 ? "None" : strerror(errno)) #define log_err(MSG, ...) ({ \ int __save = errno; \ @@ -73,13 +77,13 @@ int settimeo(int fd, int timeout_ms) #define save_errno_close(fd) ({ int __save = errno; close(fd); errno = __save; }) -static int __start_server(int type, const struct sockaddr *addr, +static int __start_server(int type, int protocol, const struct sockaddr *addr, socklen_t addrlen, int timeout_ms, bool reuseport) { int on = 1; int fd; - fd = socket(addr->sa_family, type, 0); + fd = socket(addr->sa_family, type, protocol); if (fd < 0) { log_err("Failed to create server socket"); return -1; @@ -113,8 +117,8 @@ static int __start_server(int type, const struct sockaddr *addr, return -1; } -int start_server(int family, int type, const char *addr_str, __u16 port, - int timeout_ms) +static int start_server_proto(int family, int type, int protocol, + const char *addr_str, __u16 port, int timeout_ms) { struct sockaddr_storage addr; socklen_t addrlen; @@ -122,10 +126,23 @@ int start_server(int family, int type, const char *addr_str, __u16 port, if (make_sockaddr(family, addr_str, port, &addr, &addrlen)) return -1; - return __start_server(type, (struct sockaddr *)&addr, + return __start_server(type, protocol, (struct sockaddr *)&addr, addrlen, timeout_ms, false); } +int start_server(int family, int type, const char *addr_str, __u16 port, + int timeout_ms) +{ + return start_server_proto(family, type, 0, addr_str, port, timeout_ms); +} + +int start_mptcp_server(int family, const char *addr_str, __u16 port, + int timeout_ms) +{ + return start_server_proto(family, SOCK_STREAM, IPPROTO_MPTCP, addr_str, + port, timeout_ms); +} + int *start_reuseport_server(int family, int type, const char *addr_str, __u16 port, int timeout_ms, unsigned int nr_listens) { @@ -144,7 +161,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str, if (!fds) return NULL; - fds[0] = __start_server(type, (struct sockaddr *)&addr, addrlen, + fds[0] = __start_server(type, 0, (struct sockaddr *)&addr, addrlen, timeout_ms, true); if (fds[0] == -1) goto close_fds; @@ -154,7 +171,7 @@ int *start_reuseport_server(int family, int type, const char *addr_str, goto close_fds; for (; nr_fds < nr_listens; nr_fds++) { - fds[nr_fds] = __start_server(type, (struct sockaddr *)&addr, + fds[nr_fds] = __start_server(type, 0, (struct sockaddr *)&addr, addrlen, timeout_ms, true); if (fds[nr_fds] == -1) goto close_fds; @@ -247,7 +264,7 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) struct sockaddr_storage addr; struct sockaddr_in *addr_in; socklen_t addrlen, optlen; - int fd, type; + int fd, type, protocol; if (!opts) opts = &default_opts; @@ -258,6 +275,11 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) return -1; } + if (getsockopt(server_fd, SOL_SOCKET, SO_PROTOCOL, &protocol, &optlen)) { + log_err("getsockopt(SOL_PROTOCOL)"); + return -1; + } + addrlen = sizeof(addr); if (getsockname(server_fd, (struct sockaddr *)&addr, &addrlen)) { log_err("Failed to get server addr"); @@ -265,7 +287,7 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) } addr_in = (struct sockaddr_in *)&addr; - fd = socket(addr_in->sin_family, type, 0); + fd = socket(addr_in->sin_family, type, protocol); if (fd < 0) { log_err("Failed to create client socket"); return -1; diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index a4b3b2f9877b..f882c691b790 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -42,6 +42,8 @@ extern struct ipv6_packet pkt_v6; int settimeo(int fd, int timeout_ms); int start_server(int family, int type, const char *addr, __u16 port, int timeout_ms); +int start_mptcp_server(int family, const char *addr, __u16 port, + int timeout_ms); int *start_reuseport_server(int family, int type, const char *addr_str, __u16 port, int timeout_ms, unsigned int nr_listens); diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c new file mode 100644 index 000000000000..7874d8264836 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2020, Tessares SA. */ +/* Copyright (c) 2022, SUSE. */ + +#include +#include "cgroup_helpers.h" +#include "network_helpers.h" +#include "mptcp_sock.skel.h" + +struct mptcp_storage { + __u32 invoked; + __u32 is_mptcp; +}; + +static int verify_sk(int map_fd, int client_fd, __u32 is_mptcp) +{ + int err, cfd = client_fd; + struct mptcp_storage val; + + if (is_mptcp == 1) + return 0; + + err = bpf_map_lookup_elem(map_fd, &cfd, &val); + if (!ASSERT_OK(err, "bpf_map_lookup_elem")) + return err; + + if (!ASSERT_EQ(val.invoked, 1, "unexpected invoked count")) + err++; + + if (!ASSERT_EQ(val.is_mptcp, 0, "unexpected is_mptcp")) + err++; + + return err; +} + +static int run_test(int cgroup_fd, int server_fd, bool is_mptcp) +{ + int client_fd, prog_fd, map_fd, err; + struct mptcp_sock *sock_skel; + + sock_skel = mptcp_sock__open_and_load(); + if (!ASSERT_OK_PTR(sock_skel, "skel_open_load")) + return -EIO; + + prog_fd = bpf_program__fd(sock_skel->progs._sockops); + if (!ASSERT_GE(prog_fd, 0, "bpf_program__fd")) { + err = -EIO; + goto out; + } + + map_fd = bpf_map__fd(sock_skel->maps.socket_storage_map); + if (!ASSERT_GE(map_fd, 0, "bpf_map__fd")) { + err = -EIO; + goto out; + } + + err = bpf_prog_attach(prog_fd, cgroup_fd, BPF_CGROUP_SOCK_OPS, 0); + if (!ASSERT_OK(err, "bpf_prog_attach")) + goto out; + + client_fd = connect_to_fd(server_fd, 0); + if (!ASSERT_GE(client_fd, 0, "connect to fd")) { + err = -EIO; + goto out; + } + + err += is_mptcp ? verify_sk(map_fd, client_fd, 1) : + verify_sk(map_fd, client_fd, 0); + + close(client_fd); + +out: + mptcp_sock__destroy(sock_skel); + return err; +} + +void test_base(void) +{ + int server_fd, cgroup_fd; + + cgroup_fd = test__join_cgroup("/mptcp"); + if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup")) + return; + + /* without MPTCP */ + server_fd = start_server(AF_INET, SOCK_STREAM, NULL, 0, 0); + if (!ASSERT_GE(server_fd, 0, "start_server")) + goto with_mptcp; + + ASSERT_OK(run_test(cgroup_fd, server_fd, false), "run_test tcp"); + + close(server_fd); + +with_mptcp: + /* with MPTCP */ + server_fd = start_mptcp_server(AF_INET, NULL, 0, 0); + if (!ASSERT_GE(server_fd, 0, "start_mptcp_server")) + goto close_cgroup_fd; + + ASSERT_OK(run_test(cgroup_fd, server_fd, true), "run_test mptcp"); + + close(server_fd); + +close_cgroup_fd: + close(cgroup_fd); +} + +void test_mptcp(void) +{ + if (test__start_subtest("base")) + test_base(); +} diff --git a/tools/testing/selftests/bpf/progs/mptcp_sock.c b/tools/testing/selftests/bpf/progs/mptcp_sock.c new file mode 100644 index 000000000000..bc09dba0b078 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/mptcp_sock.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2020, Tessares SA. */ +/* Copyright (c) 2022, SUSE. */ + +#include +#include +#include "bpf_tcp_helpers.h" + +char _license[] SEC("license") = "GPL"; + +struct mptcp_storage { + __u32 invoked; + __u32 is_mptcp; +}; + +struct { + __uint(type, BPF_MAP_TYPE_SK_STORAGE); + __uint(map_flags, BPF_F_NO_PREALLOC); + __type(key, int); + __type(value, struct mptcp_storage); +} socket_storage_map SEC(".maps"); + +SEC("sockops") +int _sockops(struct bpf_sock_ops *ctx) +{ + struct mptcp_storage *storage; + int op = (int)ctx->op; + struct tcp_sock *tsk; + struct bpf_sock *sk; + bool is_mptcp; + + if (op != BPF_SOCK_OPS_TCP_CONNECT_CB) + return 1; + + sk = ctx->sk; + if (!sk) + return 1; + + tsk = bpf_skc_to_tcp_sock(sk); + if (!tsk) + return 1; + + is_mptcp = bpf_core_field_exists(tsk->is_mptcp) ? tsk->is_mptcp : 0; + storage = bpf_sk_storage_get(&socket_storage_map, sk, 0, + BPF_SK_STORAGE_GET_F_CREATE); + if (!storage) + return 1; + + storage->invoked++; + storage->is_mptcp = is_mptcp; + + return 1; +} From patchwork Thu May 19 23:30:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mat Martineau X-Patchwork-Id: 12856129 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 5576DC4321E for ; Thu, 19 May 2022 23:30:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343609AbiESXab (ORCPT ); Thu, 19 May 2022 19:30:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245079AbiESXa0 (ORCPT ); Thu, 19 May 2022 19:30:26 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B955B108A9E; Thu, 19 May 2022 16:30:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653003024; x=1684539024; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yL57FAH7UrgJbVY5BNbdOK3sEJquq2+jOQ3e/t7En0s=; b=dkchTyz6rWba8jDlG9HfHWOoAn0jgjrQa4V8KSXOGgP7aVl0k3Avougs WEKWDxYRpNrs80xc8PhQRBTt5yivdGVtR+NMBX5mb0lYHFzwtUQb01dv9 Nz4lDbkMAFmiULB+qeG6qkhsJsc+eySTTVOzC6wZjkUp9+8p1ir4cdbDq T3RGD6ZUG9FZAu6yCs1qwCT0Tj5ZZCMPkLjr0nsVClg4UXPDRlYrFQjWW mH7glqqfLvbJ5YA66RlKvZAC0NHOBG1kHUQneKtYihNlQB7HW3TK3+VOK 7aQnBO6Zrzj5GjyJa4URLwkJ3r52WjLuDEbJnUlRsCH7/e8//e89lViUe g==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="272547200" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="272547200" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 16:30:22 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570491197" Received: from mjmartin-desk2.amr.corp.intel.com (HELO mjmartin-desk2.intel.com) ([10.252.132.179]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 16:30:21 -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 v5 4/7] selftests/bpf: test bpf_skc_to_mptcp_sock Date: Thu, 19 May 2022 16:30:13 -0700 Message-Id: <20220519233016.105670-5-mathew.j.martineau@linux.intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220519233016.105670-1-mathew.j.martineau@linux.intel.com> References: <20220519233016.105670-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 extends the MPTCP test base, to test the new helper bpf_skc_to_mptcp_sock(). Define struct mptcp_sock in bpf_tcp_helpers.h, use bpf_skc_to_mptcp_sock to get the msk socket in progs/mptcp_sock.c and store the infos in socket_storage_map. Get the infos from socket_storage_map in prog_tests/mptcp.c. Add a new function verify_msk() to verify the infos of MPTCP socket, and rename verify_sk() to verify_tsk() to verify TCP socket only. v2: Add CONFIG_MPTCP check for clearer error messages v4: - use ASSERT_* instead of CHECK_FAIL (Andrii) - drop bpf_mptcp_helpers.h (Andrii) v5: - some 'ASSERT_*' were replaced in the next commit by mistake. - Drop CONFIG_MPTCP (Martin) - Use ASSERT_EQ (Andrii) Acked-by: Matthieu Baerts Signed-off-by: Geliang Tang Signed-off-by: Mat Martineau --- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 5 ++++ .../testing/selftests/bpf/prog_tests/mptcp.c | 27 ++++++++++++++----- .../testing/selftests/bpf/progs/mptcp_sock.c | 19 ++++++++++--- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/bpf/bpf_tcp_helpers.h b/tools/testing/selftests/bpf/bpf_tcp_helpers.h index 22e0c8849a17..90fecafc493d 100644 --- a/tools/testing/selftests/bpf/bpf_tcp_helpers.h +++ b/tools/testing/selftests/bpf/bpf_tcp_helpers.h @@ -226,4 +226,9 @@ static __always_inline bool tcp_cc_eq(const char *a, const char *b) extern __u32 tcp_slow_start(struct tcp_sock *tp, __u32 acked) __ksym; extern void tcp_cong_avoid_ai(struct tcp_sock *tp, __u32 w, __u32 acked) __ksym; +struct mptcp_sock { + struct inet_connection_sock sk; + +} __attribute__((preserve_access_index)); + #endif diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 7874d8264836..6f333e3aba9c 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -12,14 +12,11 @@ struct mptcp_storage { __u32 is_mptcp; }; -static int verify_sk(int map_fd, int client_fd, __u32 is_mptcp) +static int verify_tsk(int map_fd, int client_fd) { int err, cfd = client_fd; struct mptcp_storage val; - if (is_mptcp == 1) - return 0; - err = bpf_map_lookup_elem(map_fd, &cfd, &val); if (!ASSERT_OK(err, "bpf_map_lookup_elem")) return err; @@ -33,6 +30,24 @@ static int verify_sk(int map_fd, int client_fd, __u32 is_mptcp) return err; } +static int verify_msk(int map_fd, int client_fd) +{ + int err, cfd = client_fd; + struct mptcp_storage val; + + err = bpf_map_lookup_elem(map_fd, &cfd, &val); + if (!ASSERT_OK(err, "bpf_map_lookup_elem")) + return err; + + if (!ASSERT_EQ(val.invoked, 1, "unexpected invoked count")) + err++; + + if (!ASSERT_EQ(val.is_mptcp, 1, "unexpected is_mptcp")) + err++; + + return err; +} + static int run_test(int cgroup_fd, int server_fd, bool is_mptcp) { int client_fd, prog_fd, map_fd, err; @@ -64,8 +79,8 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp) goto out; } - err += is_mptcp ? verify_sk(map_fd, client_fd, 1) : - verify_sk(map_fd, client_fd, 0); + err += is_mptcp ? verify_msk(map_fd, client_fd) : + verify_tsk(map_fd, client_fd); close(client_fd); diff --git a/tools/testing/selftests/bpf/progs/mptcp_sock.c b/tools/testing/selftests/bpf/progs/mptcp_sock.c index bc09dba0b078..dc73b3fbb50b 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_sock.c +++ b/tools/testing/selftests/bpf/progs/mptcp_sock.c @@ -24,6 +24,7 @@ SEC("sockops") int _sockops(struct bpf_sock_ops *ctx) { struct mptcp_storage *storage; + struct mptcp_sock *msk; int op = (int)ctx->op; struct tcp_sock *tsk; struct bpf_sock *sk; @@ -41,11 +42,21 @@ int _sockops(struct bpf_sock_ops *ctx) return 1; is_mptcp = bpf_core_field_exists(tsk->is_mptcp) ? tsk->is_mptcp : 0; - storage = bpf_sk_storage_get(&socket_storage_map, sk, 0, - BPF_SK_STORAGE_GET_F_CREATE); - if (!storage) - return 1; + if (!is_mptcp) { + storage = bpf_sk_storage_get(&socket_storage_map, sk, 0, + BPF_SK_STORAGE_GET_F_CREATE); + if (!storage) + return 1; + } else { + msk = bpf_skc_to_mptcp_sock(sk); + if (!msk) + return 1; + storage = bpf_sk_storage_get(&socket_storage_map, msk, 0, + BPF_SK_STORAGE_GET_F_CREATE); + if (!storage) + return 1; + } storage->invoked++; storage->is_mptcp = is_mptcp; From patchwork Thu May 19 23:30:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mat Martineau X-Patchwork-Id: 12856132 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 A5387C433FE for ; Thu, 19 May 2022 23:30:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343617AbiESXaf (ORCPT ); Thu, 19 May 2022 19:30:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343563AbiESXa0 (ORCPT ); Thu, 19 May 2022 19:30:26 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD450108AA0; Thu, 19 May 2022 16:30:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653003024; x=1684539024; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ODbT1+khY/f6Bdz1dRXyxw7XWKQOQC7s2NBBVtoK5wo=; b=McOEwOnNCuT2WHG/ooM3cd8CCgbymdRLhM0X5rjor/wvj2gWlpJM9Fni Go5jl9k/WavSbmjhyan4Qg88rEqeu7X0xtmNJAVS5BZvB9NMgmmnsJN5C CCPvJ5Qfjw3ZticWX8hR784McnpFhC1iMIN6ZYMQqQrqUJHwzMv6XZaHv VYDyizn5bnQtcDzljO/KbbdbzGuVDdiq7ElCFLGoRfJxt9dv++eJ5g/uj UJZMPOI7U4vRalDphP+1bOJbgmQkzAQ1Cr5N/lfpCgTFkrcmJScYlGW4S cMXoG7GhHmBaYVE1TJhBuFoKvthv644tsYE08O35x8Gkvow2xn6epGqNA w==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="272547203" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="272547203" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 16:30:22 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570491199" Received: from mjmartin-desk2.amr.corp.intel.com (HELO mjmartin-desk2.intel.com) ([10.252.132.179]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 16:30:22 -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 v5 5/7] selftests/bpf: verify token of struct mptcp_sock Date: Thu, 19 May 2022 16:30:14 -0700 Message-Id: <20220519233016.105670-6-mathew.j.martineau@linux.intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220519233016.105670-1-mathew.j.martineau@linux.intel.com> References: <20220519233016.105670-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 struct member token of struct mptcp_sock. Add a new member token in struct mptcp_storage to store the token value of the msk socket got by bpf_skc_to_mptcp_sock(). Trace the kernel function mptcp_pm_new_connection() by using bpf fentry prog to obtain the msk token and save it in a global bpf variable. Pass the variable to verify_msk() to verify it with the token saved in socket_storage_map. v4: - use ASSERT_* instead of CHECK_FAIL (Andrii) - skip the test if 'ip mptcp monitor' is not supported (Mat) v5: - Drop 'ip mptcp monitor', trace mptcp_pm_new_connection instead (Martin) - Use ASSERT_EQ (Andrii) 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 | 15 +++++++++++++-- tools/testing/selftests/bpf/progs/mptcp_sock.c | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/bpf_tcp_helpers.h b/tools/testing/selftests/bpf/bpf_tcp_helpers.h index 90fecafc493d..422491872619 100644 --- a/tools/testing/selftests/bpf/bpf_tcp_helpers.h +++ b/tools/testing/selftests/bpf/bpf_tcp_helpers.h @@ -229,6 +229,7 @@ extern void tcp_cong_avoid_ai(struct tcp_sock *tp, __u32 w, __u32 acked) __ksym; struct mptcp_sock { struct inet_connection_sock sk; + __u32 token; } __attribute__((preserve_access_index)); #endif diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 6f333e3aba9c..138bcc80ab9e 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -10,6 +10,7 @@ struct mptcp_storage { __u32 invoked; __u32 is_mptcp; + __u32 token; }; static int verify_tsk(int map_fd, int client_fd) @@ -30,11 +31,14 @@ static int verify_tsk(int map_fd, int client_fd) return err; } -static int verify_msk(int map_fd, int client_fd) +static int verify_msk(int map_fd, int client_fd, __u32 token) { int err, cfd = client_fd; struct mptcp_storage val; + if (!ASSERT_GT(token, 0, "invalid token")) + return -1; + err = bpf_map_lookup_elem(map_fd, &cfd, &val); if (!ASSERT_OK(err, "bpf_map_lookup_elem")) return err; @@ -45,6 +49,9 @@ static int verify_msk(int map_fd, int client_fd) if (!ASSERT_EQ(val.is_mptcp, 1, "unexpected is_mptcp")) err++; + if (!ASSERT_EQ(val.token, token, "unexpected token")) + err++; + return err; } @@ -57,6 +64,10 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp) if (!ASSERT_OK_PTR(sock_skel, "skel_open_load")) return -EIO; + err = mptcp_sock__attach(sock_skel); + if (!ASSERT_OK(err, "skel_attach")) + goto out; + prog_fd = bpf_program__fd(sock_skel->progs._sockops); if (!ASSERT_GE(prog_fd, 0, "bpf_program__fd")) { err = -EIO; @@ -79,7 +90,7 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp) goto out; } - err += is_mptcp ? verify_msk(map_fd, client_fd) : + err += is_mptcp ? verify_msk(map_fd, client_fd, sock_skel->bss->token) : verify_tsk(map_fd, client_fd); close(client_fd); diff --git a/tools/testing/selftests/bpf/progs/mptcp_sock.c b/tools/testing/selftests/bpf/progs/mptcp_sock.c index dc73b3fbb50b..f038b0e699a2 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_sock.c +++ b/tools/testing/selftests/bpf/progs/mptcp_sock.c @@ -7,10 +7,12 @@ #include "bpf_tcp_helpers.h" char _license[] SEC("license") = "GPL"; +__u32 token = 0; struct mptcp_storage { __u32 invoked; __u32 is_mptcp; + __u32 token; }; struct { @@ -47,6 +49,8 @@ int _sockops(struct bpf_sock_ops *ctx) BPF_SK_STORAGE_GET_F_CREATE); if (!storage) return 1; + + storage->token = 0; } else { msk = bpf_skc_to_mptcp_sock(sk); if (!msk) @@ -56,9 +60,21 @@ int _sockops(struct bpf_sock_ops *ctx) BPF_SK_STORAGE_GET_F_CREATE); if (!storage) return 1; + + storage->token = msk->token; } storage->invoked++; storage->is_mptcp = is_mptcp; return 1; } + +SEC("fentry/mptcp_pm_new_connection") +int BPF_PROG(trace_mptcp_pm_new_connection, struct mptcp_sock *msk, + const struct sock *ssk, int server_side) +{ + if (!server_side) + token = msk->token; + + return 0; +} From patchwork Thu May 19 23:30:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mat Martineau X-Patchwork-Id: 12856131 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 2A76CC433EF for ; Thu, 19 May 2022 23:30:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343615AbiESXae (ORCPT ); Thu, 19 May 2022 19:30:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343581AbiESXa1 (ORCPT ); Thu, 19 May 2022 19:30:27 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 549381116EB; Thu, 19 May 2022 16:30:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653003026; x=1684539026; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AT4YZbah9POI/kqLzzON06I7kPuIBXR3qzkfdO8kWdo=; b=PJHualrG6BUX6W38Vy3VGw5ZVE05uAoMaeEVgOewypKsEbqj0V42A6JC 2b6l77U+xuqq/+I3NxphKpL9gQdCgu1aiP+D5QrrxVe5oCN3IzjOZvmFM 2xFv/TmrBIgWjQYNiVnJzOqRgfmFTN3dF3h2wIiRFdQ29L0aDx49t261O MvhREtYtgzg6XQmDwGhKFGK96wlSZqGJoNL2I8y3fgyqjCRJXwGrSPzjW X6OA3rXKCN29lmlDFoKJ0+O/gF4P2TgY0KGn//lJrBIk1CcBZuMoDD6Xq c6CFkQJLtDOcktvzjLagBRXBWA8HsC/wA6cJxroNQ0YK65BNz9rqm+oiL w==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="272547207" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="272547207" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 16:30:22 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570491201" Received: from mjmartin-desk2.amr.corp.intel.com (HELO mjmartin-desk2.intel.com) ([10.252.132.179]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 16:30:22 -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 v5 6/7] selftests/bpf: verify ca_name of struct mptcp_sock Date: Thu, 19 May 2022 16:30:15 -0700 Message-Id: <20220519233016.105670-7-mathew.j.martineau@linux.intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220519233016.105670-1-mathew.j.martineau@linux.intel.com> References: <20220519233016.105670-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 another member of struct mptcp_sock, ca_name. Add a new function get_msk_ca_name() to read the sysctl tcp_congestion_control and verify it in verify_msk(). v3: Access the sysctl through the filesystem to avoid compatibility issues with the busybox sysctl command. v4: use ASSERT_* instead of CHECK_FAIL (Andrii) v5: use ASSERT_STRNEQ() instead of strncmp() (Andrii) Acked-by: Matthieu Baerts Signed-off-by: Geliang Tang Signed-off-by: Mat Martineau --- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 5 +++ .../testing/selftests/bpf/prog_tests/mptcp.c | 31 +++++++++++++++++++ .../testing/selftests/bpf/progs/mptcp_sock.c | 4 +++ 3 files changed, 40 insertions(+) diff --git a/tools/testing/selftests/bpf/bpf_tcp_helpers.h b/tools/testing/selftests/bpf/bpf_tcp_helpers.h index 422491872619..c38c66d5c1e6 100644 --- a/tools/testing/selftests/bpf/bpf_tcp_helpers.h +++ b/tools/testing/selftests/bpf/bpf_tcp_helpers.h @@ -16,6 +16,10 @@ BPF_PROG(name, args) #define SOL_TCP 6 #endif +#ifndef TCP_CA_NAME_MAX +#define TCP_CA_NAME_MAX 16 +#endif + #define tcp_jiffies32 ((__u32)bpf_jiffies64()) struct sock_common { @@ -230,6 +234,7 @@ struct mptcp_sock { struct inet_connection_sock sk; __u32 token; + char ca_name[TCP_CA_NAME_MAX]; } __attribute__((preserve_access_index)); #endif diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 138bcc80ab9e..17ad1cb07339 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -7,10 +7,15 @@ #include "network_helpers.h" #include "mptcp_sock.skel.h" +#ifndef TCP_CA_NAME_MAX +#define TCP_CA_NAME_MAX 16 +#endif + struct mptcp_storage { __u32 invoked; __u32 is_mptcp; __u32 token; + char ca_name[TCP_CA_NAME_MAX]; }; static int verify_tsk(int map_fd, int client_fd) @@ -31,14 +36,37 @@ static int verify_tsk(int map_fd, int client_fd) return err; } +void get_msk_ca_name(char ca_name[]) +{ + size_t len; + int fd; + + fd = open("/proc/sys/net/ipv4/tcp_congestion_control", O_RDONLY); + if (!ASSERT_GE(fd, 0, "failed to open tcp_congestion_control")) + return; + + len = read(fd, ca_name, TCP_CA_NAME_MAX); + if (!ASSERT_GT(len, 0, "failed to read ca_name")) + goto err; + + if (len > 0 && ca_name[len - 1] == '\n') + ca_name[len - 1] = '\0'; + +err: + close(fd); +} + static int verify_msk(int map_fd, int client_fd, __u32 token) { + char ca_name[TCP_CA_NAME_MAX]; int err, cfd = client_fd; struct mptcp_storage val; if (!ASSERT_GT(token, 0, "invalid token")) return -1; + get_msk_ca_name(ca_name); + err = bpf_map_lookup_elem(map_fd, &cfd, &val); if (!ASSERT_OK(err, "bpf_map_lookup_elem")) return err; @@ -52,6 +80,9 @@ static int verify_msk(int map_fd, int client_fd, __u32 token) if (!ASSERT_EQ(val.token, token, "unexpected token")) err++; + if (!ASSERT_STRNEQ(val.ca_name, ca_name, TCP_CA_NAME_MAX, "unexpected ca_name")) + err++; + return err; } diff --git a/tools/testing/selftests/bpf/progs/mptcp_sock.c b/tools/testing/selftests/bpf/progs/mptcp_sock.c index f038b0e699a2..6a78e7b754a8 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_sock.c +++ b/tools/testing/selftests/bpf/progs/mptcp_sock.c @@ -2,6 +2,7 @@ /* Copyright (c) 2020, Tessares SA. */ /* Copyright (c) 2022, SUSE. */ +#include #include #include #include "bpf_tcp_helpers.h" @@ -13,6 +14,7 @@ struct mptcp_storage { __u32 invoked; __u32 is_mptcp; __u32 token; + char ca_name[TCP_CA_NAME_MAX]; }; struct { @@ -51,6 +53,7 @@ int _sockops(struct bpf_sock_ops *ctx) return 1; storage->token = 0; + bzero(storage->ca_name, TCP_CA_NAME_MAX); } else { msk = bpf_skc_to_mptcp_sock(sk); if (!msk) @@ -62,6 +65,7 @@ int _sockops(struct bpf_sock_ops *ctx) return 1; storage->token = msk->token; + memcpy(storage->ca_name, msk->ca_name, TCP_CA_NAME_MAX); } storage->invoked++; storage->is_mptcp = is_mptcp; From patchwork Thu May 19 23:30:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mat Martineau X-Patchwork-Id: 12856133 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 8FB6EC433F5 for ; Thu, 19 May 2022 23:30:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343619AbiESXah (ORCPT ); Thu, 19 May 2022 19:30:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343572AbiESXa1 (ORCPT ); Thu, 19 May 2022 19:30:27 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 586C010788E; Thu, 19 May 2022 16:30:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653003026; x=1684539026; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=la3wcnMhgWCUcLyaEaClOPhyG2MoAKhnFpoSTvrOpAQ=; b=Sk+IQI+zGn3OY8T2Lt0SbcrOJ2w9iqNK/Sm6oanPYaaT7YVsKfPXYqkC VliSvsfit9lL1OqWOjaCavoEugwlqSRo4IoEwgUgOQ8aedGPBJ+HKYJ52 v2eaK/1KYMdU5ot0SB5RpmrcSeJc5FJiECFrN/rdBot1OZAuIq2iVDG1K R5SEgbXQTovwT/apSh5NvGEQgR4rVLSx+3QSN3AaZ81hRgKcNisOgKevo R6Ga3ZdAt7nuIbtpJsSD1Cnfb9QUTyzSmxEw7ejni4/15690NVBCvT7H5 tQi51gb+dIk5gOuHKZPxyB2NG2Yjv8xCz9yIZ3Ri46bIi7iIQSWa3RpcT g==; X-IronPort-AV: E=McAfee;i="6400,9594,10352"; a="272547208" X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="272547208" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 16:30:22 -0700 X-IronPort-AV: E=Sophos;i="5.91,238,1647327600"; d="scan'208";a="570491205" Received: from mjmartin-desk2.amr.corp.intel.com (HELO mjmartin-desk2.intel.com) ([10.252.132.179]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2022 16:30:22 -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 v5 7/7] selftests/bpf: verify first of struct mptcp_sock Date: Thu, 19 May 2022 16:30:16 -0700 Message-Id: <20220519233016.105670-8-mathew.j.martineau@linux.intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220519233016.105670-1-mathew.j.martineau@linux.intel.com> References: <20220519233016.105670-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(). v5: - Use ASSERT_EQ() instead of a manual comparison + log (Andrii). 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 | 5 +++++ tools/testing/selftests/bpf/progs/mptcp_sock.c | 5 +++++ 3 files changed, 11 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 17ad1cb07339..257a8668ad40 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -14,7 +14,9 @@ struct mptcp_storage { __u32 invoked; __u32 is_mptcp; + struct sock *sk; __u32 token; + struct sock *first; char ca_name[TCP_CA_NAME_MAX]; }; @@ -80,6 +82,9 @@ static int verify_msk(int map_fd, int client_fd, __u32 token) if (!ASSERT_EQ(val.token, token, "unexpected token")) err++; + if (!ASSERT_EQ(val.first, val.sk, "unexpected first")) + err++; + if (!ASSERT_STRNEQ(val.ca_name, ca_name, TCP_CA_NAME_MAX, "unexpected ca_name")) err++; diff --git a/tools/testing/selftests/bpf/progs/mptcp_sock.c b/tools/testing/selftests/bpf/progs/mptcp_sock.c index 6a78e7b754a8..f638cb876424 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_sock.c +++ b/tools/testing/selftests/bpf/progs/mptcp_sock.c @@ -13,7 +13,9 @@ __u32 token = 0; 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 { msk = bpf_skc_to_mptcp_sock(sk); if (!msk) @@ -66,9 +69,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; }