From patchwork Fri Oct 18 10:51:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13841581 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 242A320262C for ; Fri, 18 Oct 2024 10:52:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729248728; cv=none; b=Ut8i50nzUXFpXjRNaKOXkttrbRnHsJvGo9n4qIF4D6Cz0gwPGrmFAp1X0Ow6wMigEnIszNAmSAnDckg3e0OBX2Tv2of2sISa5ohvB0fSHIn34jfCVwCYqQveaN4Lp5GQJlO8Wzi9fMqS+316WaujjD8yHwoHjeL0wiiUN1Bgshw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729248728; c=relaxed/simple; bh=rRzqr3wY62rjS/C8qthJ5Nu/aL3fmuLtnvCutyE6NqE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vgi0RAWc8jXsKblY3e/FXrayoWIsskg5z6yspNyWjJwOktgCykqQ8/FxNdhfiuTE9JQz702rt6gz5Sg4CSEOT/KbntxytMstNXr6ryS70PEe6jwVdtQeMy+K3asW3r1nZYtZ/am2HURYiBVKgiyn1TcESjJEWdaQjwMcD8bHLjg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AsgID2iW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AsgID2iW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B4E0C4CED2; Fri, 18 Oct 2024 10:52:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729248727; bh=rRzqr3wY62rjS/C8qthJ5Nu/aL3fmuLtnvCutyE6NqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AsgID2iWwn2PconDiWFDrImceFAsiW1/XoXV0CELpWi9TxeqtT4hcGHeGmjeZL8bp RqVkbId+VagtKFDveLaQo8Vo3pZzTRMd5knooUjqvBkwByEWmq9mX1ByiX7ISWDGan kc5xnMfibhIeNeqtjx0odmUor+wh1T+2TZXx/uE0CWVw6CEQRjO9ZZZrgIDAqj2Cs0 zWPt41zehn7cXuZTd8+wOGU4YLIit08Nc+4rAUZu6PyTAKJjRItNpivuLa4XLfzIkF 7HzeaC6CWJhGcJMgYVcNtK1tyTSZlDN9kTn8Ugmmp8L0FkHtDGhQ8GL5ZppRB5eTWj +SkrmmJOorkZA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Matthieu Baerts Subject: [PATCH mptcp-next 1/6] selftests/bpf: Add mptcp pm_nl_ctl link Date: Fri, 18 Oct 2024 18:51:53 +0800 Message-ID: <9ca197c4d95a73d6fda8ab8f6f6c3a33dd23f0bc.1729248083.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang This patch adds a symlink to MPTCP's pm_nl_ctl tool into bpf selftests, and updates Makefile to compile it. This is useful to run MPTCP BPF selftests on systems with an old version of IPRoute2. This tool can be used as an alternative to 'ip mptcp'. In addition, this tool is used as userspace path manager. "csf" and "dsf" commands of pm_nl_ctl for creating and destroying subflows, and "ann" and "rem" commands for signaling ADD_ADDR and RM_ADDR. These commands are not currently supported in 'ip mptcp' yet. MAINTAINERS needs to be updated since a new file is added in a non covered place. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) --- MAINTAINERS | 1 + tools/testing/selftests/bpf/Makefile | 3 ++- tools/testing/selftests/bpf/mptcp_pm_nl_ctl.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) create mode 120000 tools/testing/selftests/bpf/mptcp_pm_nl_ctl.c diff --git a/MAINTAINERS b/MAINTAINERS index c7a86efbfee1..07baea76e3e8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16302,6 +16302,7 @@ F: include/trace/events/mptcp.h F: include/uapi/linux/mptcp*.h F: net/mptcp/ F: tools/testing/selftests/bpf/*/*mptcp*.[ch] +F: tools/testing/selftests/bpf/*mptcp*.[ch] F: tools/testing/selftests/net/mptcp/ NETWORKING [TCP] diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index f04af11df8eb..662825f55f99 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -157,7 +157,7 @@ TEST_GEN_PROGS_EXTENDED = \ flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \ test_lirc_mode2_user xdping test_cpp runqslower bench bpf_testmod.ko \ xskxceiver xdp_redirect_multi xdp_synproxy veristat xdp_hw_metadata \ - xdp_features bpf_test_no_cfi.ko + xdp_features bpf_test_no_cfi.ko mptcp_pm_nl_ctl TEST_GEN_FILES += liburandom_read.so urandom_read sign-file uprobe_multi @@ -726,6 +726,7 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko \ $(OUTPUT)/xdp_synproxy \ $(OUTPUT)/sign-file \ $(OUTPUT)/uprobe_multi \ + $(OUTPUT)/mptcp_pm_nl_ctl \ ima_setup.sh \ verify_sig_setup.sh \ $(wildcard progs/btf_dump_test_case_*.c) \ diff --git a/tools/testing/selftests/bpf/mptcp_pm_nl_ctl.c b/tools/testing/selftests/bpf/mptcp_pm_nl_ctl.c new file mode 120000 index 000000000000..5a08c255b278 --- /dev/null +++ b/tools/testing/selftests/bpf/mptcp_pm_nl_ctl.c @@ -0,0 +1 @@ +../net/mptcp/pm_nl_ctl.c \ No newline at end of file From patchwork Fri Oct 18 10:51:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13841582 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BD7A202640 for ; Fri, 18 Oct 2024 10:52:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729248730; cv=none; b=DWLP96RCvdguxiYn9GehpEHSI5QybNz1zU9A/8ZPxUt9Lxte5deKN31jdwapGOeA3EGk92g26cihAwzC/qvju1Ufd2o1ObrFQ3OQdW/za7evCEPcqUERauUnjjY2xxzZZtYQPJznlKEed/cmok1fquBLPQJakNtGillaCSqibNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729248730; c=relaxed/simple; bh=nCc+ZGl2AOHIzUpNwJFTs9+TtaIxwJP5L0FTigb7pjw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GqcqvoqNS0c5SKYlKlH65UEmti35todw+Ir8e0twCMZCk03LST3x4RTJbuLxh+8r30r0r2gRjafLqvgad89HMcDpr2oZF4fv/znI+twpLp89rr5W5x0F0FCbGvAiWKUBmk8t6iE5q/iJfD8YPVONaNtfeQs+MLnqTLgSBahtme4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mULKEWKE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mULKEWKE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 367F0C4CEC3; Fri, 18 Oct 2024 10:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729248729; bh=nCc+ZGl2AOHIzUpNwJFTs9+TtaIxwJP5L0FTigb7pjw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mULKEWKENfQc3BDLJA4NLI9RjtPBp6QCYEcLiB2K6R5jih/1b9RAwqRmS8ekoC8eN UgWnP0Lp7fHL99vJQ6e9gsfRyZUURMVWKjRR/VeU6XmOR8PMoGhQMJRTRRK1UGxh6t 1fPI9HxC43mOSJBiFcPoB1m78KLj3yP3JrMLhg+ggWghwwsxQAc0DoRnH60+i6lZaZ 9QHxZS964VLvU/uTQHkveDBiWf+rDLIqp3GuQQF4ctY4JnnUEigt+Bpa52nO2j/NZS f5BAmeAdCduz9B0M4tpmZXu0WXYwDSz/N9s04J23Ox42JXhTlBLRUrDqseHcEKSiNF 3bMJLaQ2MZwHA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 2/6] selftests/bpf: Use pm_nl_ctl if ip mptcp not supported Date: Fri, 18 Oct 2024 18:51:54 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang If running MPTCP BPF selftests on systems with an old version of IPRoute2, 'ip mptcp' command is not supported. In this case, instead of skipping the test, falling back to using 'pm_nl_ctl' tool is a better option. This patch adds an 'ip_mptcp' argument for endpoint_add() to control whether to use 'ip mptcp' or 'pm_nl_ctl' to add an endpoint. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 5b9f29a569a6..439dfee42ffd 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -28,6 +28,7 @@ #define ADDR6_3 "dead:beef:3::1" #define ADDR6_4 "dead:beef:4::1" #define PORT_1 10001 +#define PM_CTL "./mptcp_pm_nl_ctl" #define WITH_DATA true #define WITHOUT_DATA false @@ -381,13 +382,18 @@ static int address_init(void) return -1; } -static int endpoint_add(char *addr, char *flags) +static int endpoint_add(char *addr, char *flags, bool ip_mptcp) { - return SYS_NOFAIL("ip -net %s mptcp endpoint add %s %s", NS_TEST, addr, flags); + if (ip_mptcp) + return SYS_NOFAIL("ip -net %s mptcp endpoint add %s %s", + NS_TEST, addr, flags); + return SYS_NOFAIL("ip netns exec %s %s add %s flags %s", + NS_TEST, PM_CTL, addr, flags); } static int endpoint_init(char *flags, u8 endpoints) { + bool ip_mptcp = true; int ret = -1; if (!endpoints || endpoints > 4) @@ -398,17 +404,16 @@ static int endpoint_init(char *flags, u8 endpoints) if (SYS_NOFAIL("ip -net %s mptcp limits set add_addr_accepted 4 subflows 4", NS_TEST)) { - printf("'ip mptcp' not supported, skip this test.\n"); - test__skip(); - goto fail; + SYS(fail, "ip netns exec %s %s limits 4 4", NS_TEST, PM_CTL); + ip_mptcp = false; } if (endpoints > 1) - ret = endpoint_add(ADDR_2, flags); + ret = endpoint_add(ADDR_2, flags, ip_mptcp); if (endpoints > 2) - ret = ret ?: endpoint_add(ADDR_3, flags); + ret = ret ?: endpoint_add(ADDR_3, flags, ip_mptcp); if (endpoints > 3) - ret = ret ?: endpoint_add(ADDR_4, flags); + ret = ret ?: endpoint_add(ADDR_4, flags, ip_mptcp); fail: return ret; From patchwork Fri Oct 18 10:51:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13841583 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D698520262C for ; Fri, 18 Oct 2024 10:52:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729248731; cv=none; b=MN7SiPfXqbuVAJlJXlhEDWqBFiVx4uf6pBCAyahgVHaFdDqw/cOYK0AMyhIyAFYJXYspB1Q+3+9qaZQRseKHzJtHtMT4wEN11XBVwSf3VUFyKorA6pfkwSzd7/EIuxlYLEtYEO6halOuuLpC+4WVk1LkvsPQhZwPU1WmZtFmAUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729248731; c=relaxed/simple; bh=stCVvQ6rKIxdGUpMlz/ijnf/vQEvvqxYoS3QLSlidrQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bVoRJWNbq1j+EMa6dvNFOz2FSbLKvOr5TeczBXIY09YLELjeaRIiqTBoUtBoldbHgiM3/XGiU/CIqGltDhNkCSzadtrEUe54tydHNVrycsl9vh/7/p7IFDxXJ8renLekbZxvimJkodnVBHkCDPuAfXAo0GwGquO5RjLJwTUEWJY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IU0g17G4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IU0g17G4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4398FC4CEC3; Fri, 18 Oct 2024 10:52:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729248731; bh=stCVvQ6rKIxdGUpMlz/ijnf/vQEvvqxYoS3QLSlidrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IU0g17G4ZiXv+bLQNRcwVh+o2kucmEwyLoqD7sANHUZNBbWe9B8TsROEZeCx+nzqt h/YGgZ+XFOgNhc4EiVOOy/4FEyPCWEtjeWbd8sP/nXrY9qaKY/hPCtJETOfUSqUYWw OwX/mcXHWBWtoaAn/fZ68Wb853fYF22AHclWwmEsdqbk3pRLKxwJ0mqm2IjpnhC5Uy ++WJ6m9OcmwNWjQBuLufbqQT9ms/uRS1Ggn8OYD687hE2a0J3eFqy64njfQb9pacZe Ux2uHoAfoUfXDdHlUdchQArKNVXGHWgzXuX2TKsgtnLnZ3nKyeWEHy4gPHDd5wLvju 8QhcdgF2GqkpQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 3/6] bpf: Add mptcp_address bpf_iter Date: Fri, 18 Oct 2024 18:51:55 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Just like the mptcp_subflow bpf_iter used to implement the MPTCP BPF packet scheduler, another bpf_iter is also needed, named mptcp_address, to traverse all address entries on userspace_pm_local_addr_list of an MPTCP socket for implementing the MPTCP BPF path manager. In kernel space, we walk this list like this: list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) kfunc(entry); With the mptcp_address bpf_iter, bpf_for_each() can be used to do the same thing in BPF program: bpf_for_each(mptcp_address, entry, msk) kfunc(entry); This bpf_iter should be invoked under holding the msk pm lock, so use spin_is_locked() to check whether the lock is holding. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 1ad7f703abb2..102d4d63f390 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -214,6 +214,15 @@ struct bpf_iter_mptcp_subflow_kern { struct list_head *pos; } __attribute__((aligned(8))); +struct bpf_iter_mptcp_address { + __u64 __opaque[2]; +} __attribute__((aligned(8))); + +struct bpf_iter_mptcp_address_kern { + struct mptcp_sock *msk; + struct list_head *pos; +} __attribute__((aligned(8))); + __bpf_kfunc_start_defs(); __bpf_kfunc static struct mptcp_sock *bpf_mptcp_sk(struct sock *sk) @@ -264,6 +273,37 @@ __bpf_kfunc static void bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_sub { } +__bpf_kfunc static int bpf_iter_mptcp_address_new(struct bpf_iter_mptcp_address *it, + struct mptcp_sock *msk) +{ + struct bpf_iter_mptcp_address_kern *kit = (void *)it; + + kit->msk = msk; + if (!msk) + return -EINVAL; + + WARN_ON_ONCE(!spin_is_locked(&msk->pm.lock)); + + kit->pos = &msk->pm.userspace_pm_local_addr_list; + return 0; +} + +__bpf_kfunc static struct mptcp_pm_addr_entry * +bpf_iter_mptcp_address_next(struct bpf_iter_mptcp_address *it) +{ + struct bpf_iter_mptcp_address_kern *kit = (void *)it; + + if (!kit->msk || list_is_last(kit->pos, &kit->msk->pm.userspace_pm_local_addr_list)) + return NULL; + + kit->pos = kit->pos->next; + return list_entry(kit->pos, struct mptcp_pm_addr_entry, list); +} + +__bpf_kfunc static void bpf_iter_mptcp_address_destroy(struct bpf_iter_mptcp_address *it) +{ +} + __bpf_kfunc static struct mptcp_sock *bpf_mptcp_sock_acquire(struct mptcp_sock *msk) { struct sock *sk = (struct sock *)msk; @@ -302,6 +342,9 @@ BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock) BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new, KF_ITER_NEW | KF_TRUSTED_ARGS) BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next, KF_ITER_NEXT | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_destroy, KF_ITER_DESTROY) +BTF_ID_FLAGS(func, bpf_iter_mptcp_address_new, KF_ITER_NEW | KF_TRUSTED_ARGS) +BTF_ID_FLAGS(func, bpf_iter_mptcp_address_next, KF_ITER_NEXT | KF_RET_NULL) +BTF_ID_FLAGS(func, bpf_iter_mptcp_address_destroy, KF_ITER_DESTROY) BTF_ID_FLAGS(func, bpf_mptcp_sock_acquire, KF_ACQUIRE | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_mptcp_sock_release, KF_RELEASE) BTF_KFUNCS_END(bpf_mptcp_common_kfunc_ids) From patchwork Fri Oct 18 10:51:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13841584 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D252D202625 for ; Fri, 18 Oct 2024 10:52:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729248733; cv=none; b=tH1z1l7PHpOot8MvtnZXZMD5m/hOiZ6vV0bSTFvTCj3/Yr/5tuQ7omFqV2zOPCpLH6YXTds/u7g0x7SCKGjkRwaP5UHpix4xwclyj933we1MTob62xUlR4GMSUWskEtNZw5gPEu55dS3D6jW0ojvjORVWxsJgZKtHgAMmzVqBjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729248733; c=relaxed/simple; bh=nu+axcIHmBoHjKkvuSAudbDn1f6k4kUqvtK4lNSSWZQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ULui2KDZc3GXnCSGfYz5efN8dNXELmTdk9mpl5PlWXl9YwJ/CYeN/BE2/EDkEE84vapt00DFKC4zfwRM0E5ilPHAufSkIh1+T3KHvFm3+vuzqanfWCvC8WWaiRQfrvln8PO8AV2KDoYTyQaORCm3MNPAhpK2BL+VLx+arbjn/Kw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BlUObWxz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BlUObWxz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35B82C4CEC6; Fri, 18 Oct 2024 10:52:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729248733; bh=nu+axcIHmBoHjKkvuSAudbDn1f6k4kUqvtK4lNSSWZQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BlUObWxz2BhVr7RWXBXrP4rm4BujzOc5X/CbqNGqy93z07RnDUvwg1qodDZh/5rb6 g4WJ69plpUKngFdQV4QLrtkTt/+iePGgfB0yq/3WCP8cpuwHzBpMPgQHZ9VjDbx52K Av7n2c7M+iQEiO8+BGHHBWFQ4RuDIsoRZcvaQcj5vxaChupyj9fNTyb8ezVR0dhb77 D7t6rTqq6wS+OAKcNtzLwpVvq5tuzY7+b/rfxvkx2Wp36nU5BPsex6PJjsOSVGqfez ZdU7Z6fgvx0OWcvFXuSmmmXWHbf1FdSkU/ft6nVkql+TmDbKS30n5rHwr0CEX4V/fR hnmdf8rSxXk9A== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 4/6] bpf: Export more helpers used by mptcp_address test Date: Fri, 18 Oct 2024 18:51:56 +0800 Message-ID: <518f962f7005352f6fae4c2c3e31541b5c9b67bb.1729248083.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang The mptcp_address bpf_iter should be invoked under holding the msk pm lock, so spin_lock_bh() and spin_unlock_bh() are needed in BPF program to hold or release the msk pm lock. And bpf_ipv6_addr_v4mapped() helper is also needed by the mptcp_address bpf_iter selftest program. This patch adds the corresponding BPF wrappers for these helpers and adds them to the mptcp common kfunc_set. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 102d4d63f390..350fdff6a205 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -320,6 +320,24 @@ __bpf_kfunc static void bpf_mptcp_sock_release(struct mptcp_sock *msk) WARN_ON_ONCE(!sk || !refcount_dec_not_one(&sk->sk_refcnt)); } +__bpf_kfunc static void bpf_spin_lock_bh(spinlock_t *lock) +{ + spin_lock_bh(lock); +} + +__bpf_kfunc static void bpf_spin_unlock_bh(spinlock_t *lock) +{ + spin_unlock_bh(lock); +} + +__bpf_kfunc static bool bpf_ipv6_addr_v4mapped(const struct mptcp_addr_info *a) +{ +#if IS_ENABLED(CONFIG_MPTCP_IPV6) + return ipv6_addr_v4mapped(&a->addr6); +#endif + return false; +} + __bpf_kfunc struct mptcp_subflow_context * bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned int pos) { @@ -347,6 +365,9 @@ BTF_ID_FLAGS(func, bpf_iter_mptcp_address_next, KF_ITER_NEXT | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_iter_mptcp_address_destroy, KF_ITER_DESTROY) BTF_ID_FLAGS(func, bpf_mptcp_sock_acquire, KF_ACQUIRE | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_mptcp_sock_release, KF_RELEASE) +BTF_ID_FLAGS(func, bpf_spin_lock_bh) +BTF_ID_FLAGS(func, bpf_spin_unlock_bh) +BTF_ID_FLAGS(func, bpf_ipv6_addr_v4mapped) BTF_KFUNCS_END(bpf_mptcp_common_kfunc_ids) static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = { From patchwork Fri Oct 18 10:51:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13841585 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68549202642 for ; Fri, 18 Oct 2024 10:52:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729248735; cv=none; b=QlLatvFsXs2tD4f3oH5Xykz6GmwbavucCZrberseQiS928GRZtZ3t0I9O2Ig3Zi5xDhgjao7TJeab5bqsNn6p2RqFV1M9myzbenKuYDoXjjT+be/4HETCv4Hi+C7+1HFGYOlBHAYQeoYbWWzeZXQgTxBQdTLiC4lQBajAzDYv+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729248735; c=relaxed/simple; bh=Ug1Y1GMWSEQ8/ec0m1xspvrZLUB5hAm3Fo4JLCG0Uak=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JYNjvWfXNtwPjPO1YCQkLlQNbcEHj6A8mM4BLbefuB895/plkCdwezgjnRmZMiXcdadR1KBedT3PGgYtDvhw7eE6BtvbosXM8FI7fZ36eW0/Yr7NC9JsSylbk5XRH2LTnFA7aPTEDNwwhyhEBl3G5dIhTehh5CNCXNYfBqJXwSg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MWFNtKQl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MWFNtKQl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12FB3C4CEC3; Fri, 18 Oct 2024 10:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729248735; bh=Ug1Y1GMWSEQ8/ec0m1xspvrZLUB5hAm3Fo4JLCG0Uak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MWFNtKQlCefJXIKwsJl1aR5PFBhE5jA6wUvALx/DpGapDMt3Bgyff9BRyraeXvZXp swwRBgP4qDW7AONKpK5vk34B7vc8SIC9CoOEfXeEtjIPtJSJWAUjbagPR9K1/TNfpw r3i9XDJZyXRrqQ+mzEtM5F/snuXFSxoO7vy5p2P2zaCVCWwiKkwfghL6YIt48FnlOq VeuiLThgs0Aft8AHkUp7QnXTdWBfY4go7LLH+uouV3xUCoxbaO4Mq1xtLbjNPPZ7pJ CCvofh0IXa7TuGOGe3nDlsPuZoR402mBWW1dSbO2c8NJhPSPPEtnxCA+/zbOvYILHF V/DcIzYQWsgpQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 5/6] selftests/bpf: Add mptcp_address bpf_iter test prog Date: Fri, 18 Oct 2024 18:51:57 +0800 Message-ID: <56151a024fbd4dacbfb919ca499641a88229e796.1729248083.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang This patch adds a test program for the newly added mptcp_address bpf_iter in SEC "cgroup/getsockopt". This test iterates over all address entries on the local address list of userspace PM and check whether each one is an IPv4mapped address. Export mptcp_address helpers bpf_iter_mptcp_address_new/_next/_destroy into bpf_experimental.h. Use bpf_mptcp_sock_acquire() to acquire the msk, then lock the msk pm lock and use bpf_for_each(mptcp_address) to walk the local address list of this msk. Invoke bpf_ipv6_addr_v4mapped() in the loop to check whether the address is an IPv4mapped one. Then Add the address ID of each entry to local veriable local_ids. Out of the loop, unlock the msk pm lock and use bpf_mptcp_sock_release() to release the msk. Finally, assign local_ids to global variable ids so that the application can obtain this value. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/bpf_experimental.h | 7 ++++ tools/testing/selftests/bpf/progs/mptcp_bpf.h | 5 +++ .../selftests/bpf/progs/mptcp_bpf_iters.c | 39 +++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h index d43690b17468..e6db7797539c 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -582,6 +582,13 @@ extern struct mptcp_subflow_context * bpf_iter_mptcp_subflow_next(struct bpf_iter_mptcp_subflow *it) __weak __ksym; extern void bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it) __weak __ksym; +struct bpf_iter_mptcp_address; +extern int bpf_iter_mptcp_address_new(struct bpf_iter_mptcp_address *it, + struct mptcp_sock *msk) __weak __ksym; +extern struct mptcp_pm_addr_entry * +bpf_iter_mptcp_address_next(struct bpf_iter_mptcp_address *it) __weak __ksym; +extern void bpf_iter_mptcp_address_destroy(struct bpf_iter_mptcp_address *it) __weak __ksym; + extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags) __weak __ksym; extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ksym; extern int bpf_wq_set_callback_impl(struct bpf_wq *wq, diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf.h b/tools/testing/selftests/bpf/progs/mptcp_bpf.h index 3b20cfd44505..376979a9c4f0 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf.h +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf.h @@ -52,6 +52,11 @@ bpf_mptcp_subflow_ctx(const struct sock *sk) __ksym; extern struct sock * bpf_mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) __ksym; +extern void bpf_spin_lock_bh(spinlock_t *lock) __ksym; +extern void bpf_spin_unlock_bh(spinlock_t *lock) __ksym; + +extern bool bpf_ipv6_addr_v4mapped(const struct mptcp_addr_info *a) __ksym; + extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, bool scheduled) __ksym; diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c index 263221ea6feb..2423cf392b79 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c @@ -58,3 +58,42 @@ int iters_subflow(struct bpf_sockopt *ctx) bpf_mptcp_sock_release(msk); return 1; } + +SEC("cgroup/getsockopt") +int iters_address(struct bpf_sockopt *ctx) +{ + struct mptcp_pm_addr_entry *entry; + struct bpf_sock *sk = ctx->sk; + struct mptcp_sock *msk; + int local_ids = 0; + + if (!sk || sk->protocol != IPPROTO_MPTCP || + ctx->level != SOL_TCP || ctx->optname != TCP_CONGESTION) + return 1; + + msk = bpf_mptcp_sk((struct sock *)sk); + if (msk->pm.server_side) + return 1; + + msk = bpf_mptcp_sock_acquire(msk); + if (!msk) + return 1; + bpf_spin_lock_bh(&msk->pm.lock); + bpf_for_each(mptcp_address, entry, msk) { + /* Here MPTCP-specific path manager kfunc can be called: + * this test is not doing anything really useful, only to + * verify the iteration works. + */ + + if (!bpf_ipv6_addr_v4mapped(&entry->addr)) + break; + + local_ids += entry->addr.id; + } + bpf_spin_unlock_bh(&msk->pm.lock); + bpf_mptcp_sock_release(msk); + + ids = local_ids; + + return 1; +} From patchwork Fri Oct 18 10:51:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13841586 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E66020263D for ; Fri, 18 Oct 2024 10:52:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729248737; cv=none; b=a2fIcXVYhhW/5mFrwdOXfwo6XRU9ExdSBsswS4tQvHNrG/mq3UCjKdEdSqKfGEEj25aptihTfhFFEfOIq9Oo1UFfBHtS4cE0gFeaDdRhmgVmuJrjLBYd1KWEfFwYRRmBZD7GXimzwwSOzQC4tU6Wa40qaDshwOmiIyWirvFTO4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729248737; c=relaxed/simple; bh=W1fF6zR56V1CSSFP+NlA8nMT8WbVcn9lIW0M935KqEY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qo1PYLiZb2Arm15+0WrAPEPP/AeK2dAluGD34eqYRbHv2Dl1DcFSs0sy+FN6N1NruIuJax6JpZOLRbaMYHP6SfxLxo1VL9C/G4uUqOe9BX+Ts3/M5EFBPsRUCI4GAigo6Yk4Zvq47XdqQVn7dxMMhKz62J9K+DAq9FhVjeNYis8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LSYsizod; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LSYsizod" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD766C4CEC6; Fri, 18 Oct 2024 10:52:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729248737; bh=W1fF6zR56V1CSSFP+NlA8nMT8WbVcn9lIW0M935KqEY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LSYsizodF6jMlVr7OjrzfVca71nJ1GwAnS2523qTPNndbfQsw+9VGTOTbMabQzWTx bi/SJkltHbeBjhjMDbPv/O3XFQagqQrrqSoh/HozClr9G5jzzaaeqFv1zL23ke0Az0 nKQ/0ZGjyoJ8oFWUMdAOYMCuKx4zWT4mMLAj0vWeibWtw9r+QejWQzU/NZYY4uMaXw OpEK+Ji4dcxIv3EXl9O+D/1IUDtVhJgmVxYfZtH1zdD8DIFdTTtKwXt8Z6Db38MCoa d7MPOx6gzu/dZmDmSajmO48kltdJu0FQ0Cowg6L4ZkGLGIqfykSkY4NhodidRSNl0g pSZfvImpLqxgw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 6/6] selftests/bpf: Add mptcp_address bpf_iter subtest Date: Fri, 18 Oct 2024 18:51:58 +0800 Message-ID: <5a583f06e60dff7fef8bd918e2dd23e08dee7dcc.1729248083.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang This patch adds a subtest named test_iters_address to load and verify the newly added mptcp_address type bpf_iter example in test_mptcp. Since mptcp_address bpf_iter iterates over all address entries on the local address list of userspace PM. A set of userspace PM helpers are added. Set pm_type and start "pm_nl_ctl events" command to save pm events into the log file /tmp/bpf_userspace_pm_events in userspace_pm_init(). Kill "pm_nl_ctl" command and remove the log file in userspace_pm_cleanup(). Parse the log file in userspace_pm_add_subflow() to get the token, sport and dport values, then use "pm_nl_ctl csf" command to create a subflow. Use the helper userspace_pm_add_subflow() to add 3 new subflow endpoints. Send a byte of message to start the mptcp connection, and receive the message. getsockopt() is invoked to trigger the "cgroup/getsockopt" test program. Check if skel->bss->ids equals 60 to verify whether the program loops three times as expected. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 177 ++++++++++++++++++ 1 file changed, 177 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 439dfee42ffd..a8f49041aaf1 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -29,6 +29,7 @@ #define ADDR6_4 "dead:beef:4::1" #define PORT_1 10001 #define PM_CTL "./mptcp_pm_nl_ctl" +#define PM_EVENTS "/tmp/bpf_userspace_pm_events" #define WITH_DATA true #define WITHOUT_DATA false @@ -54,6 +55,14 @@ #endif #define MPTCP_SCHED_NAME_MAX 16 +enum mptcp_pm_type { + MPTCP_PM_TYPE_KERNEL = 0, + MPTCP_PM_TYPE_USERSPACE, + + __MPTCP_PM_TYPE_NR, + __MPTCP_PM_TYPE_MAX = __MPTCP_PM_TYPE_NR - 1, +}; + static const unsigned int total_bytes = 10 * 1024 * 1024; static int duration; @@ -267,6 +276,19 @@ static void send_byte(int fd) ASSERT_EQ(write(fd, &b, sizeof(b)), 1, "send single byte"); } +static int recv_byte(int fd) +{ + char buf[1]; + ssize_t n; + + n = recv(fd, buf, sizeof(buf), 0); + if (CHECK(n <= 0, "recv_byte", "recv")) { + log_err("failed/partial recv"); + return -1; + } + return 0; +} + static int verify_mptcpify(int server_fd, int client_fd) { struct __mptcp_info info; @@ -581,6 +603,159 @@ static void test_iters_subflow(void) close(cgroup_fd); } +static int userspace_pm_init(enum mptcp_pm_type pm_type) +{ + if (address_init()) + goto fail; + + SYS(fail, "ip netns exec %s sysctl -qw net.mptcp.pm_type=%u", + NS_TEST, pm_type); + SYS(fail, "ip netns exec %s %s limits 4 4", + NS_TEST, PM_CTL); + SYS(fail, "ip netns exec %s %s events >> %s 2>&1 &", + NS_TEST, PM_CTL, PM_EVENTS); + + return 0; +fail: + return -1; +} + +static void userspace_pm_cleanup(void) +{ + SYS_NOFAIL("ip netns exec %s killall %s > /dev/null 2>&1", + NS_TEST, PM_CTL); + SYS_NOFAIL("ip netns exec %s rm -rf %s", NS_TEST, PM_EVENTS); +} + +static char *get_events_str(char *type) +{ + char buf[1024]; + size_t len; + int fd; + + fd = open(PM_EVENTS, O_RDONLY); + if (!ASSERT_OK_FD(fd, "failed to open pm events")) + return NULL; + + len = read(fd, buf, sizeof(buf)); + ASSERT_GT(len, 0, "failed to read pm events"); + + close(fd); + + return strstr(buf, type); +} + +static int userspace_pm_add_subflow(char *addr, __u8 id) +{ + bool ipv6 = strstr(addr, ":"); + __u32 token, sport, dport; + char *str; + int n; + + str = get_events_str("type:2"); + if (!str) + return -1; + + n = sscanf(strstr(str, "token"), "token:%u,", &token); + if (n != 1) + return -1; + n = sscanf(strstr(str, "sport"), "sport:%u,dport:%u,", &sport, &dport); + if (n != 2) + return -1; + str = ipv6 ? (strstr(addr, ".") ? "::ffff:"ADDR_1 : ADDR6_1) : ADDR_1; + SYS_NOFAIL("ip netns exec %s %s csf lip %s lid %u rip %s rport %u token %u", + NS_TEST, PM_CTL, addr, id, str, dport, token); + + return 0; +} + +static void run_iters_address(void) +{ + int server_fd, client_fd, accept_fd; + char cc[TCP_CA_NAME_MAX]; + socklen_t len; + int err; + + server_fd = start_mptcp_server(AF_INET6, "::ffff:"ADDR_1, PORT_1, 0); + if (!ASSERT_OK_FD(server_fd, "start_mptcp_server")) + return; + + client_fd = connect_to_fd(server_fd, 0); + if (!ASSERT_OK_FD(client_fd, "connect_to_fd")) + goto close_server; + + accept_fd = accept(server_fd, NULL, NULL); + if (!ASSERT_OK_FD(accept_fd, "accept")) + goto close_client; + + usleep(100000); + send_byte(client_fd); + recv_byte(accept_fd); + usleep(100000); + + err = userspace_pm_add_subflow("::ffff:"ADDR_2, 10); + err = err ?: userspace_pm_add_subflow("::ffff:"ADDR_3, 20); + err = err ?: userspace_pm_add_subflow("::ffff:"ADDR_4, 30); + if (!ASSERT_OK(err, "userspace_pm_add_subflow")) + goto close_accept; + + send_byte(accept_fd); + recv_byte(client_fd); + + len = sizeof(cc); + err = getsockopt(client_fd, SOL_TCP, TCP_CONGESTION, cc, &len); + if (ASSERT_OK(err, "getsockopt(client_fd, TCP_CONGESTION)")) + ASSERT_STREQ(cc, "cubic", "cc"); + +close_accept: + close(accept_fd); +close_client: + close(client_fd); +close_server: + close(server_fd); +} + +static void test_iters_address(void) +{ + struct mptcp_bpf_iters *skel; + struct nstoken *nstoken; + int cgroup_fd; + int err; + + cgroup_fd = test__join_cgroup("/iters_address"); + if (!ASSERT_OK_FD(cgroup_fd, "join_cgroup: iters_address")) + return; + + skel = mptcp_bpf_iters__open_and_load(); + if (!ASSERT_OK_PTR(skel, "skel_open_load: iters_address")) + goto close_cgroup; + + skel->links.iters_address = bpf_program__attach_cgroup(skel->progs.iters_address, + cgroup_fd); + if (!ASSERT_OK_PTR(skel->links.iters_address, "attach getsockopt")) + goto skel_destroy; + + nstoken = create_netns(); + if (!ASSERT_OK_PTR(nstoken, "create_netns")) + goto skel_destroy; + + err = userspace_pm_init(MPTCP_PM_TYPE_USERSPACE); + if (!ASSERT_OK(err, "userspace_pm_init: iters_address")) + goto close_netns; + + run_iters_address(); + + ASSERT_EQ(skel->bss->ids, 60, "address ids"); + + userspace_pm_cleanup(); +close_netns: + cleanup_netns(nstoken); +skel_destroy: + mptcp_bpf_iters__destroy(skel); +close_cgroup: + close(cgroup_fd); +} + static struct nstoken *sched_init(char *flags, char *sched) { struct nstoken *nstoken; @@ -764,6 +939,8 @@ void test_mptcp(void) test_subflow(); if (test__start_subtest("iters_subflow")) test_iters_subflow(); + if (test__start_subtest("iters_address")) + test_iters_address(); if (test__start_subtest("default")) test_default(); if (test__start_subtest("first"))