From nobody Mon Nov 23 20:27:01 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.54 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795437501; b=1oewhiK4ZmOys20FIfsTfO2oeUinrxGveahQintXgkqNpzPKIKrHDmManvg9lJRHW0Mk 2pMmUkGJw1VIl7wFcoyC2mVJFXPelgbjxb3gDrDNqwR6WSvSMkOQL9vO2Pk+qQxZwQm/k ZaUsTV51Z9rr99rt1SAycvI3MirmTMxEt/dw5bAj45voxOTh82k0mD6kjGM/si57ypgQM dOek6ELNxneL5VH7bYbQch6P3PQReFrNRFGA0W0NnmXHpEQmeOzL+1QhyugpclktfYYYH EayBUS9FZEe9QwEFmMSRv4RqJI57Oq56A6zT1YOzv5kL0GhxTcLNzSfdJ5rD1CWVqow== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795437501; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-ZohoMailClient; bh=uF0SgHYiwUp2jRHtFW+Plv06XPuN5g0RAoVUUL6yCRU=; b=l/n0RcozyOa4B+nNNmtnuWJyeCfnOSv/Zwk47pmQS0QLsuHju6jozkDa7EQW2t1F9e/1 K8QxyPhWSCItzduVTkzmUrvvN6HEkI9BOSirj0fjZPojqDz0eOSNi3gavHYlst82lEO+k X0g5gLfChXJmJNY1lr2a2jGXp3BEf9leeeAm/hAS3hoNyBZO5YCrsui1sptEU19U3GNGz cDMM6T78swFFQxV94pfx97HSwB/Y+p5j6YhbsJfidFTHvTSLVPL36CzE8fSfeGBm5A/xo Wjvo4Tyd2XqxXKm5sHp6zn8J+UE3mmZNjmzH4CNJOs0TkbYxJcND03uv141NdUsqvlw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=mpiricsoftware.com; spf=pass smtp.mailfrom=mpiricsoftware.com; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.54 Received: from sender6-of-o54.zoho.com (sender6-of-o54.zoho.com [165.173.180.54]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B412606A32E for ; Mon, 23 Nov 2026 12:38:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3B412606A32E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mpiricsoftware.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mpiricsoftware.com ARC-Seal: i=1; a=rsa-sha256; t=1795437471; cv=none; d=zohomail.com; s=zohoarc; b=HqhYwbYwJA4tzY2stam3FUsU5SiUxKu3WTkgigtP+FsxU6YP1PI4X8YTyPgRI6tU5q9GdEn1jSTV2leUy9CXEl2Wq1K/4Bp9MY+XBUBZ5gpxKuVmmGuv4AAl1LueUC0OBnqimEKfbtMgpjO001uL9A7zzEGLDqu9BSIy2E0SAaY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795437471; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=uF0SgHYiwUp2jRHtFW+Plv06XPuN5g0RAoVUUL6yCRU=; b=KaN3K6VJkD4Cyer3cbalj1dHHfKoePsNmX1qrZczyhF9umOiF+7BqP/wiMCLVrmHpGFrV0wnjLqLxIr+QP7+D93KTV//l2Yn7qQQNTF9RjTccUXuqlN7mbqQgwD/sLC8G9dg2vZfF99QP2D9yu5Suz4wULwRotcxFfuRgJj+Yg4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=mpiricsoftware.com; spf=pass smtp.mailfrom=kalpan.jani@mpiricsoftware.com; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=XkEtK5NGt3WczB8pPDG8DQw5QIYQu3j3WUCEnOqcg2IdD9jrrOX6I8Dh7VPWy5hL/+PhyyjmnjzZ4flb88jvLQ8xb+OrZerQm7BPlXSnrVl/FvrMX2PHpVGXXTQbELJ/ihTOtTrh2iRxnp+kr2Gr0dW8/7beRZ733r+CPaOVULQ=; c=relaxed/relaxed; s=mpiric; d=mpiricsoftware.com; v=1; bh=uF0SgHYiwUp2jRHtFW+Plv06XPuN5g0RAoVUUL6yCRU=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1795437469250737.5816325045392; Mon, 23 Nov 2026 04:37:49 -0800 (PST) From: Kalpan Jani To: mptcp@lists.linux.dev Cc: shardul.b@mpiricsoftware.com, janak@mpiric.us, kalpanjani009@gmail.com, Kalpan Jani , Paolo Abeni Subject: [PATCH mptcp-next v7 1/2] mptcp: sched: add subflow avoid flag for BPF schedulers Date: Mon, 23 Nov 2026 18:07:29 +0530 Message-ID: <20261123123730.3265284-2-kalpan.jani@mpiricsoftware.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261123123730.3265284-1-kalpan.jani@mpiricsoftware.com> References: <20261123123730.3265284-1-kalpan.jani@mpiricsoftware.com> X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" The core benches a subflow via the "stale" bit after net.mptcp.stale_loss_cnt retransmission intervals without progress. That bit belongs to the core and is tightly coupled to the RTO: it gets cleared as soon as a packet is acked on the subflow (mptcp_subflow_active() calls mptcp_subflow_set_active() once rcv_tstamp moves forward). "scheduled" doesn't cover this either. The core clears it right after every send/retrans pass the scheduler set it in, so there's no way to express "leave this subflow alone across future rounds" with it, and nothing outside the scheduler that set it ever sees the value. Add a scheduler-owned "avoid" bool to mptcp_subflow_context: - only mptcp_subflow_set_avoid() writes it. It is exposed to BPF struct_ops schedulers as a kfunc with the same registration and filter as mptcp_subflow_set_scheduled(), so only a BPF scheduler can change its value; - it is a standalone bool, alongside "scheduled" and "data_avail", rather than a bit in the adjacent flag bitfield. mptcp_subflow_data_available() clears map_valid, a bit in that bitfield, from the subflow's own receive path without holding the msk lock, while set_avoid() runs under the msk lock from BPF scheduler context. Bitfield writes are a non-atomic read-modify-write on the whole containing word, so placing avoid there would race with that update and risk silently corrupting map_valid or other neighbouring bits. The standalone bool is accessed with READ_ONCE()/WRITE_ONCE() for the same reason; - the flag is exported through MPTCP diagnostics, allowing userspace to observe whether a subflow has been marked as avoided. BPF schedulers must explicitly check subflow->avoid when selecting subflows. The flag is scheduler-owned and does not change the behavior of the default in-kernel scheduler. Link: https://github.com/multipath-tcp/mptcp_net-next/issues/349 Suggested-by: Paolo Abeni Signed-off-by: Kalpan Jani --- Changes since v6: - Removed the unreachable avoid checks from the default send and retransmission subflow pickers. - Clarified that the avoid flag is owned and enforced by BPF schedulers. v6: https://lore.kernel.org/all/20261123100821.2228839-2-kalpan.jani@mpiric= software.com/ --- include/uapi/linux/mptcp.h | 1 + net/mptcp/bpf.c | 1 + net/mptcp/diag.c | 2 ++ net/mptcp/protocol.h | 3 +++ net/mptcp/sched.c | 6 ++++++ 5 files changed, 13 insertions(+) diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h index 72a5d030154e1..b4ca97e074453 100644 --- a/include/uapi/linux/mptcp.h +++ b/include/uapi/linux/mptcp.h @@ -22,6 +22,7 @@ #define MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED _BITUL(6) #define MPTCP_SUBFLOW_FLAG_CONNECTED _BITUL(7) #define MPTCP_SUBFLOW_FLAG_MAPVALID _BITUL(8) +#define MPTCP_SUBFLOW_FLAG_AVOID _BITUL(9) =20 #define MPTCP_PM_CMD_GRP_NAME "mptcp_pm_cmds" #define MPTCP_PM_EV_GRP_NAME "mptcp_pm_events" diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 74648ca1e99b5..6fcd2bb5e6bdd 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -312,6 +312,7 @@ BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids) BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx, KF_RET_NULL) BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock, KF_RET_NULL) BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled) +BTF_ID_FLAGS(func, mptcp_subflow_set_avoid) BTF_ID_FLAGS(func, mptcp_subflow_active) BTF_ID_FLAGS(func, mptcp_set_timeout) BTF_ID_FLAGS(func, mptcp_wnd_end) diff --git a/net/mptcp/diag.c b/net/mptcp/diag.c index 70cf9ebce8338..7a2c40a63dfa4 100644 --- a/net/mptcp/diag.c +++ b/net/mptcp/diag.c @@ -49,6 +49,8 @@ static int subflow_get_info(struct sock *sk, struct sk_bu= ff *skb, bool net_admin flags |=3D MPTCP_SUBFLOW_FLAG_BKUP_LOC; if (READ_ONCE(sf->fully_established)) flags |=3D MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED; + if (READ_ONCE(sf->avoid)) + flags |=3D MPTCP_SUBFLOW_FLAG_AVOID; if (sf->conn_finished) flags |=3D MPTCP_SUBFLOW_FLAG_CONNECTED; if (sf->map_valid) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 9febcaf84762d..24e2540c05caa 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -607,6 +607,7 @@ struct mptcp_subflow_context { __unused : 9; bool data_avail; bool scheduled; + bool avoid; /* pkt scheduler: skip subflow if possible */ bool pm_listener; /* a listener managed by the kernel PM? */ bool fully_established; /* path validated */ bool close_event_done; /* has done the post-closed part, @@ -935,6 +936,8 @@ static inline bool __mptcp_subflow_active(struct mptcp_= subflow_context *subflow) =20 void mptcp_subflow_set_active(struct mptcp_subflow_context *subflow); =20 +void mptcp_subflow_set_avoid(struct mptcp_subflow_context *subflow, bool a= void); + bool mptcp_subflow_active(struct mptcp_subflow_context *subflow); =20 void mptcp_subflow_drop_ctx(struct sock *ssk); diff --git a/net/mptcp/sched.c b/net/mptcp/sched.c index 1e59072d478c9..0ce59eb093df6 100644 --- a/net/mptcp/sched.c +++ b/net/mptcp/sched.c @@ -165,6 +165,12 @@ void mptcp_subflow_set_scheduled(struct mptcp_subflow_= context *subflow, WRITE_ONCE(subflow->scheduled, scheduled); } =20 +__bpf_kfunc void mptcp_subflow_set_avoid(struct mptcp_subflow_context *sub= flow, + bool avoid) +{ + WRITE_ONCE(subflow->avoid, avoid); +} + int mptcp_sched_get_send(struct mptcp_sock *msk) { struct mptcp_subflow_context *subflow; --=20 2.43.0 From nobody Mon Nov 23 20:27:01 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.182.54 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795437515; b=VwiFMNIaWq7o7/wvYYeID8YKR4zj5rvcBYnb/ZMQ4oUk04sr0vIT0lKDELF6vaqrZHwg Ck1IpCEgQsoBN5Me2E8rPH9jC4/fAbtetD3lSw38jA1TU4hAGGo9xUKXKtiC4ADecRPGh 0nS8DIJohT1yd6Xebqs22XnlQzHFDrWuJu0DLwB6eLzT6T0LQkmgXBiY9tgBdAQT4W3gR 6h9qwhGpQPpF0wydKrh0L+PYqR77fxLYVm2A15/X7jrl5pTP8TtWAfN1KNKVkf0lSO0vD tici4MItND/1VxGkjQgzuQlDymWnlHUXjNHjADtTfAR68LdpHBkAmnMRSD9X8fUMEag== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795437515; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-ZohoMailClient; bh=dDJ86tOBRnsW9dFh+36OPAHgLKR0yh0qbfy6/F+hbKM=; b=K/fMQYUcAM2glK9hMEzSNpuTecA/Z1r3Qkq48OCuCRUfx9ofDfKwgO8qBhJSulnvZmcB 3srXgEze3eplSXvsQsT21sxJ5Qmu0f8OcnRobDutPzXJVC742ifiEMaHqma68kTphysVE 0dzKWg0E1tFnkVdLedTriRxYtJa3MKCOYKeWu56nO1YVbbacnsPp2aSEEH+x6+ZD4pNRZ JerwrMwU6IouLPMx7RB25FefjT0Ev7MC9RXLcIKsIY33U1z6lxASd5pUmkHwhEnzV3l78 ICfU+1mPK0BJ94Dmi+6LNTlSeA9eqIF8qiIHAY4Hmge96Z4n4luCBF10SqdsomtRfrg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=mpiricsoftware.com; spf=pass smtp.mailfrom=mpiricsoftware.com; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.182.54 Received: from sender5-of-o54.zoho.com (sender5-of-o54.zoho.com [165.173.182.54]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C128F606A31E for ; Mon, 23 Nov 2026 12:38:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C128F606A31E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mpiricsoftware.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mpiricsoftware.com ARC-Seal: i=1; a=rsa-sha256; t=1795437475; cv=none; d=zohomail.com; s=zohoarc; b=c79UE46YOFqh//Rm2wSoegMWUgRmsxvyCGisFf60X1Dm3K6Oy7EU1i7le8aiKzTnZ1OkAt/P/1BnEOpflDYOoICGdykXX12zJJR6JF+Mtw5qwod0S9fingpzQYlutN9nKpA4CUSys8jJ08YnSJfNXvxR3oO3lYU2eaJWB/eayIU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795437475; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=dDJ86tOBRnsW9dFh+36OPAHgLKR0yh0qbfy6/F+hbKM=; b=l3xDd/SAL4h4jgsYvwcEoVeDzVZ8BUR1KaoAVGkideV14PoTmRzUGL3FXJiqiTdmP6j2QwFTuiy1iP5MntUJEcufK8VnhEV8in5ZvSabTbgrfmzKqXPG+f89TLD59Xb9BogLc1r//2A9Dh5kKBybtKKlwTlq+Km/mcSEUndObGY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=mpiricsoftware.com; spf=pass smtp.mailfrom=kalpan.jani@mpiricsoftware.com; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=i8Ds4mvvDPOJYZiKepuUY7QcN2ZNBsjU+3ZP0kkBQM3dkrvOjqCAPwKH8ZvWGgnpGcStkOkNsE1me2DZzN0y/4UnEUKPhQ1eD40la5kLoq3Bk13qBEdGGqQPd3wNUTbi5BNJg7fRKHqm6h2eZs2H+br0dQsTzGPiI8Ol8LfDhu4=; c=relaxed/relaxed; s=mpiric; d=mpiricsoftware.com; v=1; bh=dDJ86tOBRnsW9dFh+36OPAHgLKR0yh0qbfy6/F+hbKM=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1795437473234871.2473021885332; Mon, 23 Nov 2026 04:37:53 -0800 (PST) From: Kalpan Jani To: mptcp@lists.linux.dev Cc: shardul.b@mpiricsoftware.com, janak@mpiric.us, kalpanjani009@gmail.com, Kalpan Jani , Paolo Abeni Subject: [PATCH mptcp-next v7 2/2] selftests: mptcp: bpf: exercise the subflow avoid flag across rounds Date: Mon, 23 Nov 2026 18:07:30 +0530 Message-ID: <20261123123730.3265284-3-kalpan.jani@mpiricsoftware.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261123123730.3265284-1-kalpan.jani@mpiricsoftware.com> References: <20261123123730.3265284-1-kalpan.jani@mpiricsoftware.com> X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" Add a BPF struct_ops scheduler selftest for mptcp_subflow_set_avoid(), and add the required extern declarations for it and for mptcp_subflow_active(), both declared locally in this file rather than in the shared mptcp_bpf.h. mptcp_subflow_active()'s extern was missing here even though the other BPF scheduler progs already have it (see mptcp_bpf_burst.c). "scheduled" gets cleared by the core after every single send/retrans pass, so a scheduler has to set it again every round. This test's scheduler does the opposite on purpose: it marks a subflow avoided exactly once, once a second subflow is available, and never calls set_avoid() again after that. Every later round skips the marked subflow purely by reading back state set earlier, and the harness's own byte-count checks confirm the avoided path carried no data across the whole transfer. Per-msk state (whether avoid has been asserted yet) is kept in BPF_MAP_TYPE_SK_STORAGE keyed on msk, the same pattern mptcp_bpf_rr.c already uses, rather than in BPF global variables: globals are process-wide, not per-socket, so they would be shared and reset across any concurrent connections attached to this scheduler. Link: https://github.com/multipath-tcp/mptcp_net-next/issues/349 Suggested-by: Paolo Abeni Signed-off-by: Kalpan Jani --- v6: https://lore.kernel.org/all/20261123100821.2228839-3-kalpan.jani@mpiric= software.com/ --- .../testing/selftests/bpf/prog_tests/mptcp.c | 15 ++++ .../selftests/bpf/progs/mptcp_bpf_avoid.c | 87 +++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing= /selftests/bpf/prog_tests/mptcp.c index d77c9f8c53c75..3bff30d0d5300 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -18,6 +18,7 @@ #include "mptcp_bpf_rr.skel.h" #include "mptcp_bpf_red.skel.h" #include "mptcp_bpf_burst.skel.h" +#include "mptcp_bpf_avoid.skel.h" =20 #define NS_TEST "mptcp_ns" #define ADDR_1 "10.0.1.1" @@ -820,6 +821,18 @@ static void test_burst(void) mptcp_bpf_burst__destroy(skel); } =20 +static void test_avoid(void) +{ + struct mptcp_bpf_avoid *skel; + + skel =3D mptcp_bpf_avoid__open_and_load(); + if (!ASSERT_OK_PTR(skel, "open_and_load: avoid")) + return; + + test_bpf_sched(skel->maps.avoid, "avoid", WITH_DATA, WITHOUT_DATA); + mptcp_bpf_avoid__destroy(skel); +} + void test_mptcp(void) { if (test__start_subtest("base")) @@ -842,4 +855,6 @@ void test_mptcp(void) test_red(); if (test__start_subtest("burst")) test_burst(); + if (test__start_subtest("avoid")) + test_avoid(); } diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c b/tools/te= sting/selftests/bpf/progs/mptcp_bpf_avoid.c new file mode 100644 index 0000000000000..8276ceb0e5397 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_avoid.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2026, MPTCP. */ + +#include "mptcp_bpf.h" +#include + +extern bool mptcp_subflow_active(struct mptcp_subflow_context *subflow) __= ksym; +extern void mptcp_subflow_set_avoid(struct mptcp_subflow_context *subflow, + bool avoid) __ksym; + +char _license[] SEC("license") =3D "GPL"; + +struct mptcp_avoid_storage { + bool avoid_marked; +}; + +struct { + __uint(type, BPF_MAP_TYPE_SK_STORAGE); + __uint(map_flags, BPF_F_NO_PREALLOC); + __type(key, int); + __type(value, struct mptcp_avoid_storage); +} mptcp_avoid_map SEC(".maps"); + +SEC("struct_ops") +void BPF_PROG(mptcp_sched_avoid_init, struct mptcp_sock *msk) +{ + bpf_sk_storage_get(&mptcp_avoid_map, msk, 0, + BPF_LOCAL_STORAGE_GET_F_CREATE); +} + +SEC("struct_ops") +void BPF_PROG(mptcp_sched_avoid_release, struct mptcp_sock *msk) +{ + bpf_sk_storage_delete(&mptcp_avoid_map, msk); +} + +SEC("struct_ops") +int BPF_PROG(bpf_avoid_get_send, struct mptcp_sock *msk) +{ + struct mptcp_subflow_context *subflow; + struct mptcp_subflow_context *first =3D NULL; + struct mptcp_avoid_storage *ptr; + + ptr =3D bpf_sk_storage_get(&mptcp_avoid_map, msk, 0, + BPF_LOCAL_STORAGE_GET_F_CREATE); + if (!ptr) + return -1; + + /* + * Wait until a second subflow exists before marking it avoided. + * This keeps the state unset until there is actually a subflow + * to exercise. + */ + bpf_for_each(mptcp_subflow, subflow, (struct sock *)msk) { + if (!first) { + first =3D subflow; + continue; + } + + if (!ptr->avoid_marked) { + mptcp_subflow_set_avoid(subflow, true); + ptr->avoid_marked =3D true; + continue; + } + + if (subflow->avoid) + continue; + + if (mptcp_subflow_active(subflow)) { + mptcp_subflow_set_scheduled(subflow, true); + return 0; + } + } + + if (first && mptcp_subflow_active(first) && !first->avoid) + mptcp_subflow_set_scheduled(first, true); + + return 0; +} + +SEC(".struct_ops.link") +struct mptcp_sched_ops avoid =3D { + .init =3D (void *)mptcp_sched_avoid_init, + .release =3D (void *)mptcp_sched_avoid_release, + .get_send =3D (void *)bpf_avoid_get_send, + .name =3D "bpf_avoid", +}; --=20 2.43.0