From nobody Sun Dec 22 01:42:47 2024 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 EB40519047A; Fri, 13 Dec 2024 19:54:30 +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=1734119671; cv=none; b=I2n7zCE0WXUAbLJYc7LjHrvlK2vsyikr0sQfKJzj5DVfWsUUoMR0KOLSabzmmFFfWB7L1xx2Pz9Ko+rQWDeUOwGrjDHcEnkIErRW1+Cx+paxZpI5bf86xU6wa3tbcA1wX4he4hfOKmwSNXCFjlkwij7htu4+I4z5FeJml9K5nts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734119671; c=relaxed/simple; bh=YeEo0FQpu4HwzsK5d2IHwd99nWxzPy4eCH/vibmZDvs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PH1b8ChPxMKPsLoALWqdcnDkrfrRWhRqcmYULx/Y1+vy5EXneI1NM6RIxpo6Dbc3q9rkLqtR4ACQY7xqGBD/22OchCjJS0qX3MnvXDVMxDA522OkykeKdtwq8G2Qs48WDDtds1Phcp/MT0vAINTdnOc/l3bC+cgXb7sJ0QcKsas= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NvebfEfg; 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="NvebfEfg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84CC6C4CED7; Fri, 13 Dec 2024 19:54:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734119670; bh=YeEo0FQpu4HwzsK5d2IHwd99nWxzPy4eCH/vibmZDvs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NvebfEfgYUNmRFtzFNs59JomyIuV5Ng9c5+JQe2LlXI5BcN4J7Kg9Dy3wNCCenzER AZBtUohb3oGKEg0DaJQI8wdPiulUB0kJsLSN9yzSqkTiciAXfWvczozhm1f3s7nx7h adT7YpL2dtCUiKMjVGc+3uWQDQdR74vtf/EUgNhbkNi8vgVE8g2m+5yTo31Ig6K1IW IW5qGtbxB+vYjPmRX30siqx/PvVcoQCDyiPdkXJFGwJS3kHP/ZXKM6ryX+3D7Ga2wI Mmt/KZHhJKBz8IJwDT2pjjAGLwQRI03sZ9N6RgPcvuwqUKrh05Khi0tp0Wj/MLvcSl l12BsX+xqFOqw== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Dec 2024 20:52:52 +0100 Subject: [PATCH net-next 1/7] mptcp: add mptcp_userspace_pm_lookup_addr helper Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241213-net-next-mptcp-pm-misc-cleanup-v1-1-ddb6d00109a8@kernel.org> References: <20241213-net-next-mptcp-pm-misc-cleanup-v1-0-ddb6d00109a8@kernel.org> In-Reply-To: <20241213-net-next-mptcp-pm-misc-cleanup-v1-0-ddb6d00109a8@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" , Geliang Tang X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5130; i=matttbe@kernel.org; h=from:subject:message-id; bh=DWCBSaHTHFhWfsXP07JxK1bsLPN/FA8ensLxvz+BmKk=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnXJDxMuObpi/F3ZfZMzBsOSUUXZ+wmiIEuunvJ jwHjRqdfhyJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZ1yQ8QAKCRD2t4JPQmmg c9FVD/9k9kQ3ZBpNgSMmmMh2v6QvYvNInFt0Bi3R/6QsHn8ARXdti8dElAGeWB7vk8Y6Myqad7v RIIpwsGM+o4B7q1qjNDF7g1v0GXL+7OtoWbc92A2N+lB4d6Uc9L0g725g7xXWbKJ1Gw4mxrU6eR 9A/V068JTYgrbZI3DmTE6X+veGQjbXkUBejnD1Jz7LyRGL4QQ7N7XfpPIlyebfu+6nrqt/F1ocv 5pT0LbW6ZE5qRW8NnfIwOVQOy8dmX2wyU05Lnh6ex3HoDW+Eld+GndJtUxVSUkg42oE8fA2qzmN gBWO7GhxsbJPPQEUxyK/ojYMr7tYNTUk8SmmHDn7JHrIAzjplml9cnnNfkLsGRGYyrUFTmMPcB0 Wc5pD0i3AqocpkZvTMu1/jp9vsVsgvRKzjGUFMjapum9vIUv6QcM/84kFTwZJWX3+SDzoKFW3ie YqCp4NMMDtDqzoHyZct3kgiiHFMb9rfkkrHHq+ZzCcOHn40gYtMDHs+OF8LXFE1QpULMqW9aEav tLvw7NRgursWPzTwXTHsCbwDggf5eKfp8Qa5pb4rM5hL5CKK8/JiHbWq6sKMCyGFv8XMEFCbbAN lIZN4XhLkVoV22sov6DA9KixSl3rMT/QdjZB/d0zNSgzkKniz4wG0qPWFa16GIe34/wZIX41HR6 UWJ5SLSgVOh3WTA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang Like __lookup_addr() helper in pm_netlink.c, a new helper mptcp_userspace_pm_lookup_addr() is also defined in pm_userspace.c. It looks up the corresponding mptcp_pm_addr_entry address in userspace_pm_local_addr_list through the passed "addr" parameter and returns the found address entry. This helper can be used in mptcp_userspace_pm_delete_local_addr(), mptcp_userspace_pm_set_flags(), mptcp_userspace_pm_get_local_id() and mptcp_userspace_pm_is_backup() to simplify the code. Please note that with this change now list_for_each_entry() is used in mptcp_userspace_pm_append_new_local_addr(), not list_for_each_entry_safe(), but that's OK to do so because mptcp_userspace_pm_lookup_addr() only returns an entry from the list, the list hasn't been modified here. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 69 ++++++++++++++++++++++++--------------------= ---- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index e35178f5205faac4a9199df1ffca79085e4b7c68..3664f3c1572e269fd7c74ea1d86= a49389ed5c0c1 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -26,6 +26,19 @@ void mptcp_free_local_addr_list(struct mptcp_sock *msk) } } =20 +static struct mptcp_pm_addr_entry * +mptcp_userspace_pm_lookup_addr(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr) +{ + struct mptcp_pm_addr_entry *entry; + + list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + if (mptcp_addresses_equal(&entry->addr, addr, false)) + return entry; + } + return NULL; +} + static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *entry, bool needs_id) @@ -90,22 +103,20 @@ static int mptcp_userspace_pm_append_new_local_addr(st= ruct mptcp_sock *msk, static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *addr) { - struct mptcp_pm_addr_entry *entry, *tmp; struct sock *sk =3D (struct sock *)msk; + struct mptcp_pm_addr_entry *entry; =20 - list_for_each_entry_safe(entry, tmp, &msk->pm.userspace_pm_local_addr_lis= t, list) { - if (mptcp_addresses_equal(&entry->addr, &addr->addr, false)) { - /* TODO: a refcount is needed because the entry can - * be used multiple times (e.g. fullmesh mode). - */ - list_del_rcu(&entry->list); - sock_kfree_s(sk, entry, sizeof(*entry)); - msk->pm.local_addr_used--; - return 0; - } - } + entry =3D mptcp_userspace_pm_lookup_addr(msk, &addr->addr); + if (!entry) + return -EINVAL; =20 - return -EINVAL; + /* TODO: a refcount is needed because the entry can + * be used multiple times (e.g. fullmesh mode). + */ + list_del_rcu(&entry->list); + sock_kfree_s(sk, entry, sizeof(*entry)); + msk->pm.local_addr_used--; + return 0; } =20 static struct mptcp_pm_addr_entry * @@ -123,17 +134,12 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_soc= k *msk, unsigned int id) int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc) { - struct mptcp_pm_addr_entry *entry =3D NULL, *e, new_entry; + struct mptcp_pm_addr_entry *entry =3D NULL, new_entry; __be16 msk_sport =3D ((struct inet_sock *) inet_sk((struct sock *)msk))->inet_sport; =20 spin_lock_bh(&msk->pm.lock); - list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) { - if (mptcp_addresses_equal(&e->addr, skc, false)) { - entry =3D e; - break; - } - } + entry =3D mptcp_userspace_pm_lookup_addr(msk, skc); spin_unlock_bh(&msk->pm.lock); if (entry) return entry->addr.id; @@ -153,15 +159,11 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *= msk, struct mptcp_addr_info *skc) { struct mptcp_pm_addr_entry *entry; - bool backup =3D false; + bool backup; =20 spin_lock_bh(&msk->pm.lock); - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { - if (mptcp_addresses_equal(&entry->addr, skc, false)) { - backup =3D !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); - break; - } - } + entry =3D mptcp_userspace_pm_lookup_addr(msk, skc); + backup =3D entry && !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); spin_unlock_bh(&msk->pm.lock); =20 return backup; @@ -606,13 +608,12 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb,= struct genl_info *info) bkup =3D 1; =20 spin_lock_bh(&msk->pm.lock); - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { - if (mptcp_addresses_equal(&entry->addr, &loc.addr, false)) { - if (bkup) - entry->flags |=3D MPTCP_PM_ADDR_FLAG_BACKUP; - else - entry->flags &=3D ~MPTCP_PM_ADDR_FLAG_BACKUP; - } + entry =3D mptcp_userspace_pm_lookup_addr(msk, &loc.addr); + if (entry) { + if (bkup) + entry->flags |=3D MPTCP_PM_ADDR_FLAG_BACKUP; + else + entry->flags &=3D ~MPTCP_PM_ADDR_FLAG_BACKUP; } spin_unlock_bh(&msk->pm.lock); =20 --=20 2.45.2 From nobody Sun Dec 22 01:42:47 2024 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 9F2841922F5; Fri, 13 Dec 2024 19:54:33 +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=1734119673; cv=none; b=MYIOcGt0JL9ueU8dmkhxECLHvgD5fJVaV6pkS79IiP/lKSoZXDl0LdHnpKI4yQ2gxqRsjWsIFw3zl+f5986RXkI2Ou5njMOCViGN6Dp2ax7A9dfg+BxfX+R11O7q+OW+Z2yEZfurOIPV3JbRSdMit1f0HAYAyg93ir6OqlC1mgs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734119673; c=relaxed/simple; bh=ahdJp3dJDP2d6bk+EFEpUx7qhNP/bGaBb7kaEZWi21s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NFwnuCa+W0LnDrkF94XrbytSwqlnJrdSMrpm2hfsygZ3NTxb60KQrg95oZXTa0w7WT4aFlXiy9qwRgJiF7YbGwOPgRcAVdKeAKF9T5lpOppGxSwni+pcK2El3aGtJJXOjLwpGrwXRZN9rFrvQoSoxmoz+esLJWQR8MXoFUGVD0I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TTkXgXmN; 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="TTkXgXmN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D414C4CED0; Fri, 13 Dec 2024 19:54:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734119673; bh=ahdJp3dJDP2d6bk+EFEpUx7qhNP/bGaBb7kaEZWi21s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TTkXgXmNd1xQ7u+A3ouaJZ93KaP113TQ2qur9ZD7Jyp4IAtKdGPkjWD+SAHc4sEAA fMFKJ+pCfqE2URAyxKQ7bhz1uKyuSQxIe23Qe9Ey0uz9wfshepzZNVid241exFLFny lE6vk/ywWEV2jVziuxcyarf9m7pKjo1R8G/B54mNqK5LQMwOJuw7C+0jl/nXPodU/F JC6tjn/dw8mGcPWQdEkTMUlcyYCHg//RB4yJVonHzL2S8LwcwhUtue+qdgPjzNkcYu QkrajRqkwYfgsyXQnQKAospqOIsatvLdvSKloVbM9Pj7iGjn2qruwBuzLQYogS2Je8 RIWxA9SikKU7w== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Dec 2024 20:52:53 +0100 Subject: [PATCH net-next 2/7] mptcp: add mptcp_for_each_userspace_pm_addr macro Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241213-net-next-mptcp-pm-misc-cleanup-v1-2-ddb6d00109a8@kernel.org> References: <20241213-net-next-mptcp-pm-misc-cleanup-v1-0-ddb6d00109a8@kernel.org> In-Reply-To: <20241213-net-next-mptcp-pm-misc-cleanup-v1-0-ddb6d00109a8@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" , Geliang Tang X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2604; i=matttbe@kernel.org; h=from:subject:message-id; bh=0oPYOdV4cYEweeRear2GUoPeFWizDuCJIBsUhNclTL4=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnXJDxDpv6zmIUb0Wr/Z7Op5oOpmBWZyo46UkK+ uHXuNL0P42JAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZ1yQ8QAKCRD2t4JPQmmg cyzyD/4ojWBjyCehGHLOXfVueOTsheseuIoBJW6b7l7D9vES3I0UQfDrSzNVRmsmP5ChjYlfJd4 hqLOH+lktGi7qPo5Ik77zqgKG/onsyd0WAj6t787Z21QuGBWPUNwAokF+xKiZBMWcZe9hBTJD+b NwmQYn1KAg9aehoGGLUckXDAmAcRjvntya35yD8tfeOX5tDfMkj2l61/IDkAtj0ptstUzTM4nji 2XUDchOGA3Kzo+SeoKFKFRpBCii3/eKVtMNJ+A8hE6ZfW20DCKqnFAi45Z5zHBwGdIOsnw/c3Ol ZA+mrNpgT23TejruEdYHzQuRcn9hRSrtgcSnAydzx+RLY63pqCgUvt/7l/UZMObKw1x3gW8Hm3E Zk3NX4IiO3/pUpkWVxiB0N4MGSh61mtbTtQqMZv687qqbJ9Ovd4og4KNp2v8dteItzr0r5PiO8g wePGmWKQMH9xQvBLDG9pKV8wC6aMtQfpUTv/2EzciAwt5mZvU+24OPxjbCaCJDOdMjRRF5Z/DF/ fEkB0+MCYq/RI8W5YwEMgGSwmdLq9kbHSw68+qABLuQE5N454ksiZJJDirBzPLFTQyJFMtTQBG3 SHOWmRutAT5jAyiVZyWHWz0OSivGk4r5cO7KS5tTfIDFyT+o+U3KEKeI97T5YjG8N6eSgiurNFl 6QiIWAqcBkIklRQ== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang Similar to mptcp_for_each_subflow() macro, this patch adds a new macro mptcp_for_each_userspace_pm_addr() for userspace PM to iterate over the address entries on the local address list userspace_pm_local_addr_list of the mptcp socket. This patch doesn't change the behaviour of the code, just refactoring. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 3664f3c1572e269fd7c74ea1d86a49389ed5c0c1..6a27fab238f15b577e1e17225d4= 450e60ffd25d7 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -8,6 +8,10 @@ #include "mib.h" #include "mptcp_pm_gen.h" =20 +#define mptcp_for_each_userspace_pm_addr(__msk, __entry) \ + list_for_each_entry(__entry, \ + &((__msk)->pm.userspace_pm_local_addr_list), list) + void mptcp_free_local_addr_list(struct mptcp_sock *msk) { struct mptcp_pm_addr_entry *entry, *tmp; @@ -32,7 +36,7 @@ mptcp_userspace_pm_lookup_addr(struct mptcp_sock *msk, { struct mptcp_pm_addr_entry *entry; =20 - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_userspace_pm_addr(msk, entry) { if (mptcp_addresses_equal(&entry->addr, addr, false)) return entry; } @@ -54,7 +58,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struc= t mptcp_sock *msk, bitmap_zero(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); =20 spin_lock_bh(&msk->pm.lock); - list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_userspace_pm_addr(msk, e) { addr_match =3D mptcp_addresses_equal(&e->addr, &entry->addr, true); if (addr_match && entry->addr.id =3D=3D 0 && needs_id) entry->addr.id =3D e->addr.id; @@ -124,7 +128,7 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock = *msk, unsigned int id) { struct mptcp_pm_addr_entry *entry; =20 - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_userspace_pm_addr(msk, entry) { if (entry->addr.id =3D=3D id) return entry; } @@ -659,7 +663,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, =20 lock_sock(sk); spin_lock_bh(&msk->pm.lock); - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_userspace_pm_addr(msk, entry) { if (test_bit(entry->addr.id, bitmap->map)) continue; =20 --=20 2.45.2 From nobody Sun Dec 22 01:42:47 2024 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 A674A1946B9; Fri, 13 Dec 2024 19:54:36 +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=1734119676; cv=none; b=WwmOfgSucFm3izJRAqSDhtY29fn79FSgYRlJachQD8NzQIVS1WfEyRb7TtkCEbKZuu2Q75Dmav7KyctpUM1F9dQfKsVarYH6bGM1UIS7Qk0C3f7WEdjTfpHMD2JpG0jWdAe2KRSQGAXohPxHYXLJngB85YvLiJCilv1sDe8Sy7c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734119676; c=relaxed/simple; bh=FT2pYxMpVRHpQWvyHdsqFN9olabaHp1QF/cpNxwp+Ac=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EjolJNC3vmx5AZ5+pbLYfCh9fTpVan03u8GIj7YHWk2xYlPrLKvoRvVfKlhdiHB/LpSEiYYz8bK4Z28V/l3NIC9iOPXcCD7t0VacXfbfbPU6zPI0QsHh5lEx7djDSCQ3u5RgZCslM0xPT05CMUTmaIP7Fa5Cuzvm9296e/NVhlg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FhDEWliM; 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="FhDEWliM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E764AC4CEDE; Fri, 13 Dec 2024 19:54:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734119676; bh=FT2pYxMpVRHpQWvyHdsqFN9olabaHp1QF/cpNxwp+Ac=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FhDEWliMHhI23eesC0WuJblRR2HUCUaJHGqZ13JjUp4S2ENL8edmxiuLlfY8HX760 slQxVixCuZNKOAHg2m8JCUpBoI//X7NhWQ0s99KNivjg4GjshHo32EFcJKCKdA4FPz zy1f4TWD2aSxH3Wh4deiJEgn92XiRrci1z8oJmfzHqL9rKDsD+CsTHLvd1CjYiZPlY oPG29lJp41gcLBvE/R3wUpD0JYpchTp5lsvzi9Vk2rwqjYwAvo0miV/cuXPXbkcSz6 f6LD9TqIbjEEJveQEOSSvZ7typL/91Y8qvhT/zZMmecSvlZqtlA7Y9Y7NlZPe4QIuX LMkfg63D3cWWQ== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Dec 2024 20:52:54 +0100 Subject: [PATCH net-next 3/7] mptcp: add mptcp_userspace_pm_get_sock helper Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241213-net-next-mptcp-pm-misc-cleanup-v1-3-ddb6d00109a8@kernel.org> References: <20241213-net-next-mptcp-pm-misc-cleanup-v1-0-ddb6d00109a8@kernel.org> In-Reply-To: <20241213-net-next-mptcp-pm-misc-cleanup-v1-0-ddb6d00109a8@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" , Geliang Tang X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=9911; i=matttbe@kernel.org; h=from:subject:message-id; bh=oBnPGAcUV2dukp02f4TOPoUnQ0TE0k8I2ssrLqJk+aQ=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnXJDxTi/hFDK43OkDnKKzx8Cvu7NKrKF02XRiL LVikCgrIP6JAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZ1yQ8QAKCRD2t4JPQmmg c060EADZTK86I2NFO0sWb0cJ/ARjBXiO1hSNJ5YxwXKfuxNxv4uSeodIJ3sa1b8O/I1za18oXi1 KjNDzPKzQy2pry7wHV/qcKGynLdIKgyRWd5LurEIt7AqXkoLVozXYCNTS9mGBECh3Nh03q5hE7T Gwv0R3cDHMk2bmgN5vucfZPzjRnJwaypmxY4xTMlMJ1Le/W+6UBgjCoa3V2QKrS37lVH0wGk31O 2N20+qPH/moJAugx4BmwtjlXWl0ub6yMZE+SAQ8+eXzYJlUolZsNY8WX+vmccwA2oBPwuEW2Kin meD7ewYk6qBVQdScNGAHUQb//dCi77zzf/vHL8pPkuL21rUExl9/6xKtORFNepYUgaaGL0Tf5US VuqstM85L5jbonIYeN2w1OpI843r7mt2DvWKzDmtkxIe58Q/dJeoKtgRBQkIzg5BcchFdrEwfQ2 fPRwkNUzcVRClW3nNxrd22A0adJLVDlT2QKZl830kxNO2bvsBAtOElteY//BmlG+QKaJoI8LO+j aNMlMxI8eGm8dNqtJg7NZJQZsR22ijXNZNhDUf7FJ9mWmqaxRKAZDIylkT8Hj0J/9N596BeOpUG Rl6yIkxibMahOPN8jsiFWb9P3qwcx2798blc548heIXt8aEb477mG/KD5J6aelmTJidiwrGc3v0 upj8gLSqtFv0eAg== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang Each userspace pm netlink function uses nla_get_u32() to get the msk token value, then pass it to mptcp_token_get_sock() to get the msk. Finally check whether userspace PM is selected on this msk. It makes sense to wrap them into a helper, named mptcp_userspace_pm_get_sock(), to do this. This patch doesn't change the behaviour of the code, just refactoring. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 144 ++++++++++++++++---------------------------= ---- 1 file changed, 47 insertions(+), 97 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 6a27fab238f15b577e1e17225d4450e60ffd25d7..afb04343e74d2340cd77e298489= b55340dda0899 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -173,36 +173,50 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *= msk, return backup; } =20 -int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) +static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_in= fo *info) { struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; + struct mptcp_sock *msk; + + if (!token) { + GENL_SET_ERR_MSG(info, "missing required token"); + return NULL; + } + + msk =3D mptcp_token_get_sock(genl_info_net(info), nla_get_u32(token)); + if (!msk) { + NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + return NULL; + } + + if (!mptcp_pm_is_userspace(msk)) { + GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); + sock_put((struct sock *)msk); + return NULL; + } + + return msk; +} + +int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) +{ struct nlattr *addr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry addr_val; struct mptcp_sock *msk; int err =3D -EINVAL; struct sock *sk; - u32 token_val; =20 - if (!addr || !token) { - GENL_SET_ERR_MSG(info, "missing required inputs"); + if (!addr) { + GENL_SET_ERR_MSG(info, "missing required address"); return err; } =20 - token_val =3D nla_get_u32(token); - - msk =3D mptcp_token_get_sock(sock_net(skb->sk), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto announce_err; - } - err =3D mptcp_pm_parse_entry(addr, info, true, &addr_val); if (err < 0) { GENL_SET_ERR_MSG(info, "error parsing local address"); @@ -275,7 +289,6 @@ static int mptcp_userspace_pm_remove_id_zero_address(st= ruct mptcp_sock *msk, =20 int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *id =3D info->attrs[MPTCP_PM_ATTR_LOC_ID]; struct mptcp_pm_addr_entry *match; struct mptcp_pm_addr_entry *entry; @@ -283,30 +296,21 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, stru= ct genl_info *info) LIST_HEAD(free_list); int err =3D -EINVAL; struct sock *sk; - u32 token_val; u8 id_val; =20 - if (!id || !token) { - GENL_SET_ERR_MSG(info, "missing required inputs"); + if (!id) { + GENL_SET_ERR_MSG(info, "missing required ID"); return err; } =20 id_val =3D nla_get_u8(id); - token_val =3D nla_get_u32(token); =20 - msk =3D mptcp_token_get_sock(sock_net(skb->sk), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto out; - } - if (id_val =3D=3D 0) { err =3D mptcp_userspace_pm_remove_id_zero_address(msk, info); goto out; @@ -343,7 +347,6 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct= genl_info *info) int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info = *info) { struct nlattr *raddr =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry entry =3D { 0 }; struct mptcp_addr_info addr_r; @@ -351,28 +354,18 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *s= kb, struct genl_info *info) struct mptcp_sock *msk; int err =3D -EINVAL; struct sock *sk; - u32 token_val; =20 - if (!laddr || !raddr || !token) { - GENL_SET_ERR_MSG(info, "missing required inputs"); + if (!laddr || !raddr) { + GENL_SET_ERR_MSG(info, "missing required address(es)"); return err; } =20 - token_val =3D nla_get_u32(token); - - msk =3D mptcp_token_get_sock(genl_info_net(info), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto create_err; - } - err =3D mptcp_pm_parse_entry(laddr, info, true, &entry); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); @@ -475,35 +468,24 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_so= ck *msk, int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info= *info) { struct nlattr *raddr =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_addr_info addr_l; struct mptcp_addr_info addr_r; struct mptcp_sock *msk; struct sock *sk, *ssk; int err =3D -EINVAL; - u32 token_val; =20 - if (!laddr || !raddr || !token) { - GENL_SET_ERR_MSG(info, "missing required inputs"); + if (!laddr || !raddr) { + GENL_SET_ERR_MSG(info, "missing required address(es)"); return err; } =20 - token_val =3D nla_get_u32(token); - - msk =3D mptcp_token_get_sock(genl_info_net(info), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto destroy_err; - } - err =3D mptcp_pm_parse_addr(laddr, info, &addr_l); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); @@ -566,31 +548,19 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb,= struct genl_info *info) struct mptcp_pm_addr_entry loc =3D { .addr =3D { .family =3D AF_UNSPEC },= }; struct mptcp_pm_addr_entry rem =3D { .addr =3D { .family =3D AF_UNSPEC },= }; struct nlattr *attr_rem =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; - struct net *net =3D sock_net(skb->sk); struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; int ret =3D -EINVAL; struct sock *sk; - u32 token_val; u8 bkup =3D 0; =20 - token_val =3D nla_get_u32(token); - - msk =3D mptcp_token_get_sock(net, token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return ret; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "userspace PM not selected"); - goto set_flags_err; - } - ret =3D mptcp_pm_parse_entry(attr, info, false, &loc); if (ret < 0) goto set_flags_err; @@ -637,30 +607,20 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1); } *bitmap; const struct genl_info *info =3D genl_info_dump(cb); - struct net *net =3D sock_net(msg->sk); struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; - struct nlattr *token; int ret =3D -EINVAL; struct sock *sk; void *hdr; =20 bitmap =3D (struct id_bitmap *)cb->ctx; - token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; =20 - msk =3D mptcp_token_get_sock(net, nla_get_u32(token)); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return ret; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto out; - } - lock_sock(sk); spin_lock_bh(&msk->pm.lock); mptcp_for_each_userspace_pm_addr(msk, entry) { @@ -685,7 +645,6 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, release_sock(sk); ret =3D msg->len; =20 -out: sock_put(sk); return ret; } @@ -694,28 +653,19 @@ int mptcp_userspace_pm_get_addr(struct sk_buff *skb, struct genl_info *info) { struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; - struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct mptcp_pm_addr_entry addr, *entry; - struct net *net =3D sock_net(skb->sk); struct mptcp_sock *msk; struct sk_buff *msg; int ret =3D -EINVAL; struct sock *sk; void *reply; =20 - msk =3D mptcp_token_get_sock(net, nla_get_u32(token)); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return ret; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto out; - } - ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) goto out; --=20 2.45.2 From nobody Sun Dec 22 01:42:47 2024 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 0CBB919580F; Fri, 13 Dec 2024 19:54:39 +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=1734119679; cv=none; b=aq60dAAHNPVPsJWzG11KOomxjkZl9C7SrVp/SwylFRGF1SzL55nIcZnU1PR1/wIbiX7Yu/Nx765cy8TrStsDXxDTs4WMK5td1g7+jFXSUYdTJ61veyoXBPrlAAdMKcPHRApUVLXmQlL6BTUasmWxEP49DTi5T4luUDKFk4NOACU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734119679; c=relaxed/simple; bh=3g50c6HBn+t7c/kMlsP5mIHLE9A+Iv7BvIt3rAwhsRs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dNbAI1OuHc1IKzLM6EZUTmzkd7XyFAnwjCV+X0Edagom2r+cOHJLB8ENOMpjcLT05FYkid1hY7sR0MlelLeXDCq6EzlIeHnWWdPWDNb1au4GZIVS6a3MUbDDYmgKDWdq8qIEoO/irEKHGxUov2uq4zT1PWDdeHgMXjGA/1qJZrM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XVLp3zcw; 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="XVLp3zcw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DA1DC4CED7; Fri, 13 Dec 2024 19:54:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734119678; bh=3g50c6HBn+t7c/kMlsP5mIHLE9A+Iv7BvIt3rAwhsRs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XVLp3zcwXrZTSCJ+IaG3tj8Ux2UpG8IbNx7GT1otWVRUoY4KW70RlFHtKcq+Vb+Dd otirepW3XnACGPRmX9w6Af6qfZfaXIxt3eOBHxepfUqOSfV8MzzzYv2eekd0m+Gpwz wJZkk4UZwsQ6r8ecOsD9NceCY1NS2/Q/jayU9Hy+GwLh18klcF3ux5/EqkyDPRMh5L bjyepBJtrvf7PJzAqn2C6FQHJ8ix5KXAi5MzKbHScYSPpQBM0E14HDq9csWYEeAOt4 Qt2w1YjHDZm5KujPpjh5nlIvJY7Jyirqh6xo3ppukg3q0VtSQm/pZAAze0WcTj1ehT pJ4KRVYgDGgqw== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Dec 2024 20:52:55 +0100 Subject: [PATCH net-next 4/7] mptcp: move mptcp_pm_remove_addrs into pm_userspace Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241213-net-next-mptcp-pm-misc-cleanup-v1-4-ddb6d00109a8@kernel.org> References: <20241213-net-next-mptcp-pm-misc-cleanup-v1-0-ddb6d00109a8@kernel.org> In-Reply-To: <20241213-net-next-mptcp-pm-misc-cleanup-v1-0-ddb6d00109a8@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" , Geliang Tang X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6419; i=matttbe@kernel.org; h=from:subject:message-id; bh=cL+GKxNWOp5RCIUkUynjWxXQuFxEFi2FPnZGxZ/+qkA=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnXJDxCo3At+1nzWrn288cTpAlFqWJcpH9gB7qt eSJeZUbA/qJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZ1yQ8QAKCRD2t4JPQmmg c//8D/41Jgv2NOyXLNHYLDpfQvQ99tpNy0C1AzwyYFiDg2NUVlVOI2M4J39KhfAgfFsDf3KIEts V8D3HE3OhM5+GUj9xgtUvZVq38ezEWEXHgltjJuNgqPv00UxMjFwEiMPcm6DxlV/YHr9VxV+rIe WgW4yk+FMIO5LXXUuulrXud1VkLUFYWBYkewoY5rYKsKiqtNdEb+wVhjeDG14IvVsTgf0cHgWGq nkkhZOzUD8Cbt396gSOl5YDIcCz+vzySfXOvWKBj4ITn0x8d2Tyzx74LyoFezOKKrwlMA4EtGL2 P0C6hBUB+S0Bel1HZWp/91oUOpZzc4C5BsZpSxp0f+TcPbC+cjjJatj/uhuJFFVrCZx8VsRpzke oYH+L3mXdSxl990QNkH1NRqIQKpZAMH0HCmbFLh/fHgQiUywYcODcFdjxBiqCAttzJemuoSLCnS AvxIPkYWtcAbB3B3olA20Q+CPuNLfJb6KRiP+GpbyKYBinaUQ28szgPItiWpWj4y9Rbpp7dgIZP 1nYeAoayqMDK5E30YTOMytkcwii9mvhP/ejKC29RbI6PzVDc98RNdhlMPuiBddrfqNvMLDJDvqt E1IopuxdAEpHF3UsWe16ZUTq0yguHFfZ9DQ3hCtyB9clfZv+FXEeiPevEsoRL9ojKeoZcr9rMAA bEmSimC5i9MVItw== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang Since mptcp_pm_remove_addrs() is only called from the userspace PM, this patch moves it into pm_userspace.c. For this, lookup_subflow_by_saddr() and remove_anno_list_by_saddr() helpers need to be exported in protocol.h. Also add "mptcp_" prefix for these helpers. Here, mptcp_pm_remove_addrs() is not changed to a static function because it will be used in BPF Path Manager. This patch doesn't change the behaviour of the code, just refactoring. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_netlink.c | 46 ++++++++------------------------------------= -- net/mptcp/pm_userspace.c | 28 ++++++++++++++++++++++++++++ net/mptcp/protocol.h | 4 ++++ 3 files changed, 40 insertions(+), 38 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 7a0f7998376a5bb73a37829f9a6b3cdb9a3236a2..98ac73938bd8196e196d5ee8c26= 4784ba8d37645 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -107,8 +107,8 @@ static void remote_address(const struct sock_common *sk= c, #endif } =20 -static bool lookup_subflow_by_saddr(const struct list_head *list, - const struct mptcp_addr_info *saddr) +bool mptcp_lookup_subflow_by_saddr(const struct list_head *list, + const struct mptcp_addr_info *saddr) { struct mptcp_subflow_context *subflow; struct mptcp_addr_info cur; @@ -1447,8 +1447,8 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, st= ruct genl_info *info) return ret; } =20 -static bool remove_anno_list_by_saddr(struct mptcp_sock *msk, - const struct mptcp_addr_info *addr) +bool mptcp_remove_anno_list_by_saddr(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr) { struct mptcp_pm_add_entry *entry; =20 @@ -1476,7 +1476,7 @@ static bool mptcp_pm_remove_anno_addr(struct mptcp_so= ck *msk, =20 list.ids[list.nr++] =3D mptcp_endp_get_local_id(msk, addr); =20 - ret =3D remove_anno_list_by_saddr(msk, addr); + ret =3D mptcp_remove_anno_list_by_saddr(msk, addr); if (ret || force) { spin_lock_bh(&msk->pm.lock); if (ret) { @@ -1520,7 +1520,7 @@ static int mptcp_nl_remove_subflow_and_signal_addr(st= ruct net *net, } =20 lock_sock(sk); - remove_subflow =3D lookup_subflow_by_saddr(&msk->conn_list, addr); + remove_subflow =3D mptcp_lookup_subflow_by_saddr(&msk->conn_list, addr); mptcp_pm_remove_anno_addr(msk, addr, remove_subflow && !(entry->flags & MPTCP_PM_ADDR_FLAG_IMPLICIT)); =20 @@ -1633,36 +1633,6 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, s= truct genl_info *info) return ret; } =20 -/* Called from the userspace PM only */ -void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_li= st) -{ - struct mptcp_rm_list alist =3D { .nr =3D 0 }; - struct mptcp_pm_addr_entry *entry; - int anno_nr =3D 0; - - list_for_each_entry(entry, rm_list, list) { - if (alist.nr >=3D MPTCP_RM_IDS_MAX) - break; - - /* only delete if either announced or matching a subflow */ - if (remove_anno_list_by_saddr(msk, &entry->addr)) - anno_nr++; - else if (!lookup_subflow_by_saddr(&msk->conn_list, - &entry->addr)) - continue; - - alist.ids[alist.nr++] =3D entry->addr.id; - } - - if (alist.nr) { - spin_lock_bh(&msk->pm.lock); - msk->pm.add_addr_signaled -=3D anno_nr; - mptcp_pm_remove_addr(msk, &alist); - spin_unlock_bh(&msk->pm.lock); - } -} - -/* Called from the in-kernel PM only */ static void mptcp_pm_flush_addrs_and_subflows(struct mptcp_sock *msk, struct list_head *rm_list) { @@ -1671,11 +1641,11 @@ static void mptcp_pm_flush_addrs_and_subflows(struc= t mptcp_sock *msk, =20 list_for_each_entry(entry, rm_list, list) { if (slist.nr < MPTCP_RM_IDS_MAX && - lookup_subflow_by_saddr(&msk->conn_list, &entry->addr)) + mptcp_lookup_subflow_by_saddr(&msk->conn_list, &entry->addr)) slist.ids[slist.nr++] =3D mptcp_endp_get_local_id(msk, &entry->addr); =20 if (alist.nr < MPTCP_RM_IDS_MAX && - remove_anno_list_by_saddr(msk, &entry->addr)) + mptcp_remove_anno_list_by_saddr(msk, &entry->addr)) alist.ids[alist.nr++] =3D mptcp_endp_get_local_id(msk, &entry->addr); } =20 diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index afb04343e74d2340cd77e298489b55340dda0899..cac4b4a7b1e586b66d86c7a1546= 2f642a7b0314f 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -287,6 +287,34 @@ static int mptcp_userspace_pm_remove_id_zero_address(s= truct mptcp_sock *msk, return err; } =20 +void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_li= st) +{ + struct mptcp_rm_list alist =3D { .nr =3D 0 }; + struct mptcp_pm_addr_entry *entry; + int anno_nr =3D 0; + + list_for_each_entry(entry, rm_list, list) { + if (alist.nr >=3D MPTCP_RM_IDS_MAX) + break; + + /* only delete if either announced or matching a subflow */ + if (mptcp_remove_anno_list_by_saddr(msk, &entry->addr)) + anno_nr++; + else if (!mptcp_lookup_subflow_by_saddr(&msk->conn_list, + &entry->addr)) + continue; + + alist.ids[alist.nr++] =3D entry->addr.id; + } + + if (alist.nr) { + spin_lock_bh(&msk->pm.lock); + msk->pm.add_addr_signaled -=3D anno_nr; + mptcp_pm_remove_addr(msk, &alist); + spin_unlock_bh(&msk->pm.lock); + } +} + int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *id =3D info->attrs[MPTCP_PM_ATTR_LOC_ID]; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index a93e661ef5c435155066ce9cc109092661f0711c..5ba67cb601e02902ca6fcd91028= ce36d30f45fc3 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1027,6 +1027,10 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk, struct mptcp_pm_add_entry * mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk, const struct mptcp_addr_info *addr); +bool mptcp_lookup_subflow_by_saddr(const struct list_head *list, + const struct mptcp_addr_info *saddr); +bool mptcp_remove_anno_list_by_saddr(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr); int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info); int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info); int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *in= fo); --=20 2.45.2 From nobody Sun Dec 22 01:42:47 2024 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 0D93E199921; Fri, 13 Dec 2024 19:54:41 +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=1734119682; cv=none; b=KKdbW5tbWaYQCBuZEobzMhUvG0eE9lO2IfqRQKj3e9brPvz99/K9ioIN5nheYw+41VwgJwohxiGlRHcq7YOPAfWfQWSzrlO/dWbVjgtpX9bJ72FW3nRIP5c3Hf9JRZREMt5rk0KDpYwU6CaICdEiGierGDIgbB1SKfUdDi6j/pE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734119682; c=relaxed/simple; bh=b5vVbASD/+U9TlDn04S+Fi5osjg+Wd/T5nHLXZLbOKA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hFTc7NAVBvNBEUkiOrZS2notOW4AMgeMDgvAFq1wWfL5h0sP4AVWHm+mIR/+6Ze9p5BmFH7BQHcQGIqbinRufu5/uOuy2xvPBcT1Zs9KJKojr5pwE2oYtlyVIq1RcbmltxeNJf4bRXDpSJdaCc9XDNiuuwADSEBy3OtBq6bSsQI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gv17vZw4; 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="gv17vZw4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51DC2C4CEE2; Fri, 13 Dec 2024 19:54:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734119681; bh=b5vVbASD/+U9TlDn04S+Fi5osjg+Wd/T5nHLXZLbOKA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gv17vZw4NsMF7qhcbhRTmmcJDtrYCm3wSOH54fqBJkCmthjue1PboCPri2920Gb4y FFgEYbt4QqFvCsRyQD8+pmNKvTzhl162TbOIwhVQ6tWsPyHCC/+eRBvY8DB+5UgNKR EN0GJ22EnOB5QAZQX2MmcjpQaPcj0xTuyoi4z9AYB857D6dGZtjnLTM4FGhFPRDvdY ZqLZxq4iK4DOZOLP7hHaCMyOYZwWNJ8TfoHbD8rnx38YaA2is4ScL99kuNAnRjq5xn XK/TB06YX79b21CBoSWz79OqxjtKAeqUd3Yi6/UMO1C2WUCkzOxr358R31py61ZWMs 1lqWBqzF2R1Pg== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Dec 2024 20:52:56 +0100 Subject: [PATCH net-next 5/7] mptcp: drop free_list for deleting entries Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241213-net-next-mptcp-pm-misc-cleanup-v1-5-ddb6d00109a8@kernel.org> References: <20241213-net-next-mptcp-pm-misc-cleanup-v1-0-ddb6d00109a8@kernel.org> In-Reply-To: <20241213-net-next-mptcp-pm-misc-cleanup-v1-0-ddb6d00109a8@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" , Geliang Tang X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3983; i=matttbe@kernel.org; h=from:subject:message-id; bh=TRx8Ib8e0IRHyTHl/67CzmebJSbQHIWBfNaEJnvqAvU=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnXJDxYy3Y9jgHSW2jHXQrl8m7f1Om9b782N+1+ VpQMTfxTgiJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZ1yQ8QAKCRD2t4JPQmmg c2V4EACrcHO15PIdrCf7memqk1nHi7cYRgjEsXQkuNa+8ktpGAYnFC2IjPxx2bdG/i3a/j2u6BL VRewb2CumcjOlAkXrGnrGpu/L4Y8yeAerYcbRQBS0rXPOXTORTmUpwvhimhveM2kv5bBCPa4HW/ dcjmxjnHSMjrOIERxjNS+g1ys0niS4qQKvxF5ZLxHJWt1OHM4tvR8jS8GpwEtkCOFegAO/euYn+ QYg/1TKfYFDTZ5TBYBODQPq+U/x8XwHgYgrq0kszUjCjFKtV/2sCoyomlg6hSt8PzoUxLn5EpSd aBprr3fSGMvBaUJkvGDySyBdJsB9kMTd7AecPq3xDA9HD2OJzFny91nFE/+xQ9LEcW4xbwsBPg+ 1XFEra95eNTivLszu71sx+s8oQtvsk03dcYYTWWnLXyRHzDiwEGSaUvpsBnUQiha+NkZcd/CHp8 pOG0DPLdwl6TjALen6PIxirZWfsMJPjBkvLG9MOwBumGvpU7BbaxojqoY/2a4cKDtVEfga3km3S CvKKVgZV2xrxBHHQ8iFYwIrw4NHDYVppuZvtcJkiLU3/RN6TKZZE2NM6/93H4N94STzSSLG4zTw P7qJB9HDhZtdCmrsL52YCkTXxxry+uKVBMp/D9UWJ+03nwg9FskNA8HMXgDzCz7prItJY31t3Mn O9mTW4hwtPDaYkA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang mptcp_pm_remove_addrs() actually only deletes one address, which does not match its name. This patch renames it to mptcp_pm_remove_addr_entry() and changes the parameter "rm_list" to "entry". With the help of mptcp_pm_remove_addr_entry(), it's no longer necessary to move the entry to be deleted to free_list and then traverse the list to delete the entry, which is not allowed in BPF. The entry can be directly deleted through list_del_rcu() and sock_kfree_s() now. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 42 +++++++++++++++--------------------------- net/mptcp/protocol.h | 3 ++- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index cac4b4a7b1e586b66d86c7a15462f642a7b0314f..7689ea987be35aa9e9b87c7add1= 08a08566e974f 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -287,41 +287,31 @@ static int mptcp_userspace_pm_remove_id_zero_address(= struct mptcp_sock *msk, return err; } =20 -void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_li= st) +void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *entry) { struct mptcp_rm_list alist =3D { .nr =3D 0 }; - struct mptcp_pm_addr_entry *entry; int anno_nr =3D 0; =20 - list_for_each_entry(entry, rm_list, list) { - if (alist.nr >=3D MPTCP_RM_IDS_MAX) - break; + /* only delete if either announced or matching a subflow */ + if (mptcp_remove_anno_list_by_saddr(msk, &entry->addr)) + anno_nr++; + else if (!mptcp_lookup_subflow_by_saddr(&msk->conn_list, &entry->addr)) + return; =20 - /* only delete if either announced or matching a subflow */ - if (mptcp_remove_anno_list_by_saddr(msk, &entry->addr)) - anno_nr++; - else if (!mptcp_lookup_subflow_by_saddr(&msk->conn_list, - &entry->addr)) - continue; + alist.ids[alist.nr++] =3D entry->addr.id; =20 - alist.ids[alist.nr++] =3D entry->addr.id; - } - - if (alist.nr) { - spin_lock_bh(&msk->pm.lock); - msk->pm.add_addr_signaled -=3D anno_nr; - mptcp_pm_remove_addr(msk, &alist); - spin_unlock_bh(&msk->pm.lock); - } + spin_lock_bh(&msk->pm.lock); + msk->pm.add_addr_signaled -=3D anno_nr; + mptcp_pm_remove_addr(msk, &alist); + spin_unlock_bh(&msk->pm.lock); } =20 int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *id =3D info->attrs[MPTCP_PM_ATTR_LOC_ID]; struct mptcp_pm_addr_entry *match; - struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; - LIST_HEAD(free_list); int err =3D -EINVAL; struct sock *sk; u8 id_val; @@ -355,16 +345,14 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, stru= ct genl_info *info) goto out; } =20 - list_move(&match->list, &free_list); + list_del_rcu(&match->list); spin_unlock_bh(&msk->pm.lock); =20 - mptcp_pm_remove_addrs(msk, &free_list); + mptcp_pm_remove_addr_entry(msk, match); =20 release_sock(sk); =20 - list_for_each_entry_safe(match, entry, &free_list, list) { - sock_kfree_s(sk, match, sizeof(*match)); - } + sock_kfree_s(sk, match, sizeof(*match)); =20 err =3D 0; out: diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 5ba67cb601e02902ca6fcd91028ce36d30f45fc3..cd5132fe7d22096dbf6867510c1= 0693d42255a82 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1038,7 +1038,8 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, bool echo); int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_lis= t *rm_list); -void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_li= st); +void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *entry); =20 void mptcp_free_local_addr_list(struct mptcp_sock *msk); =20 --=20 2.45.2 From nobody Sun Dec 22 01:42:47 2024 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 58B961EBFE8; Fri, 13 Dec 2024 19:54:44 +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=1734119684; cv=none; b=st3Um6C0zVRx2KtXXfhz9s4qVoxTmRPgjzYDWjbgjKgSpuZOOIndHpAIhX/aX/UIKFBXp6YSKiB1y5m5d9y9zKZ1Cc1YW3o0G8I6ztwrWnPJzECiO2UbfbVlnA+g8SI9JNCWcuyYUliL/8KhvTkzdGsHaP9CKFCh6FDUfqlA6WY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734119684; c=relaxed/simple; bh=XYimpMwHKzxu/xlRyqbufMgM2CAFOTSTeqqmj4NVsqI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Z94z3fsIg0vLA/12UPpkmcgdAK96T8BBAv/GyYbdRnCZqe0ui7FUnbw/eyaM0+6Bx74ru8NpSFA7MEy3djXTbA1J7MPiiCFdz+PqQ25vB47fV1uZQgZ+Rb6Q2zVU3FdKji1zuNIBZhI3TzxJgiBvvLHRjbUu/rJjSL+7f69eaiI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ski15LLs; 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="Ski15LLs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03CEFC4CED0; Fri, 13 Dec 2024 19:54:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734119684; bh=XYimpMwHKzxu/xlRyqbufMgM2CAFOTSTeqqmj4NVsqI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Ski15LLs0Pp9/dP7BTTLlJAjOTCJO7z1R4Re1iiT8vcwvLhUydK2rd5CLr5SzTxfm 0AnmP5EeLYZKclgu2buyVasswuhUtbNXXB8Uhjj8AtQNnj8/TGld/4oajtqav8rVfH TeEbF1xdrbXGu2G7hOhWPBWHR249sDaU9mRNQErZg/3eUmtzTg7UPde7zpb0Y9r3RA 95BjfTKmFT/E4rpmT+7XOZBmJfB5tP91FD/iRIdfjG33lwrOzDh2BIgKUmVt0QnEEz JiU0WDcA3yvkHzs629MVrWBc8wNGwJycbOqthfO18fF+T1tZ7V7a/cX3WXojBLTmD3 hocutpDJhLabg== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Dec 2024 20:52:57 +0100 Subject: [PATCH net-next 6/7] mptcp: change local addr type of subflow_destroy Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241213-net-next-mptcp-pm-misc-cleanup-v1-6-ddb6d00109a8@kernel.org> References: <20241213-net-next-mptcp-pm-misc-cleanup-v1-0-ddb6d00109a8@kernel.org> In-Reply-To: <20241213-net-next-mptcp-pm-misc-cleanup-v1-0-ddb6d00109a8@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" , Geliang Tang X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3618; i=matttbe@kernel.org; h=from:subject:message-id; bh=WZc11LXDW5RCot2xKVUu7oZMqukne6n1CK2wcrRNuwI=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnXJDxIptG9MwD7PcbPa9+zn5Y7r5kXcWNzhr1l XNmiYXFdiWJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZ1yQ8QAKCRD2t4JPQmmg cwgJD/41Qmz2tP7ZR8UAOCSIgpJlktZWWxuKDqQ+P7ae6pQO9Mz3ndWT5x4Rf1+tXZB6nFeoarf sP3CXhhxkJ6lj4Utvo4sixTcai6EE371cNTwmmi2S2QIfwtxk5JtgzmTEels6V5wvuKpf4LexGa PtEDCc5LyXnMMQ8EV69XlomHZ1sKS2EbsPfBifeliS0azqM7a4czkmp9O6/nEzWpmCMbvnE0DMn oDTkVo8/wVAMK1qkph38BrhQUxUzS+Dxi6S6KqAtTdtqCX6JdRZI5Tz3rcSbM7IOz+X4yTIUCBt WPTqu/PrvqAsNbQLf4icfytzh1FTX80602jx8raKWIH1SAoQx0ujxSDqkPLsc+L205/xxYbL4wh NFt8Z4/6MCA5IiOAu5qLYpc6XZPc669gXbHMk2BCtxN4+iA2uXwmBfJniIQe3k9+ClLh/rbdof2 q+XdHrDqQnRBskaOnXrVXW+2Xif92bfeU2u//LjfTI6XUJmLNtINQiQYJxhYHdT3i8Ue+W3wjBQ 7D3m5K2EKw7ou31J9mvNSy+oEzP9GTE2jUx+sAVxvpCFuURvJGsZhSGjEi7IFvx4UoXnHIA0sOW rbX8w9lqcHODgcWddChheByPfZDixAaTMD3+z99fOY6GvqqXxRsqbHdRgvQv2GNuerrwAFxL28Y uefAMMTrRfb2S4g== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang Generally, in the path manager interfaces, the local address is defined as an mptcp_pm_addr_entry type address, while the remote address is defined as an mptcp_addr_info type one: (struct mptcp_pm_addr_entry *local, struct mptcp_addr_info *remote) But subflow_destroy() interface uses two mptcp_addr_info type parameters. This patch changes the first one to mptcp_pm_addr_entry type and use helper mptcp_pm_parse_entry() to parse it instead of using mptcp_pm_parse_addr(). This patch doesn't change the behaviour of the code, just refactoring. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 7689ea987be35aa9e9b87c7add108a08566e974f..1d5b77e0a722de74f25c9731659= b2c938122c025 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -485,7 +485,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *sk= b, struct genl_info *info { struct nlattr *raddr =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; struct nlattr *laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; - struct mptcp_addr_info addr_l; + struct mptcp_pm_addr_entry addr_l; struct mptcp_addr_info addr_r; struct mptcp_sock *msk; struct sock *sk, *ssk; @@ -502,7 +502,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *sk= b, struct genl_info *info =20 sk =3D (struct sock *)msk; =20 - err =3D mptcp_pm_parse_addr(laddr, info, &addr_l); + err =3D mptcp_pm_parse_entry(laddr, info, true, &addr_l); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); goto destroy_err; @@ -515,35 +515,34 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *= skb, struct genl_info *info } =20 #if IS_ENABLED(CONFIG_MPTCP_IPV6) - if (addr_l.family =3D=3D AF_INET && ipv6_addr_v4mapped(&addr_r.addr6)) { - ipv6_addr_set_v4mapped(addr_l.addr.s_addr, &addr_l.addr6); - addr_l.family =3D AF_INET6; + if (addr_l.addr.family =3D=3D AF_INET && ipv6_addr_v4mapped(&addr_r.addr6= )) { + ipv6_addr_set_v4mapped(addr_l.addr.addr.s_addr, &addr_l.addr.addr6); + addr_l.addr.family =3D AF_INET6; } - if (addr_r.family =3D=3D AF_INET && ipv6_addr_v4mapped(&addr_l.addr6)) { - ipv6_addr_set_v4mapped(addr_r.addr.s_addr, &addr_r.addr6); + if (addr_r.family =3D=3D AF_INET && ipv6_addr_v4mapped(&addr_l.addr.addr6= )) { + ipv6_addr_set_v4mapped(addr_r.addr.s_addr, &addr_l.addr.addr6); addr_r.family =3D AF_INET6; } #endif - if (addr_l.family !=3D addr_r.family) { + if (addr_l.addr.family !=3D addr_r.family) { GENL_SET_ERR_MSG(info, "address families do not match"); err =3D -EINVAL; goto destroy_err; } =20 - if (!addr_l.port || !addr_r.port) { + if (!addr_l.addr.port || !addr_r.port) { GENL_SET_ERR_MSG(info, "missing local or remote port"); err =3D -EINVAL; goto destroy_err; } =20 lock_sock(sk); - ssk =3D mptcp_nl_find_ssk(msk, &addr_l, &addr_r); + ssk =3D mptcp_nl_find_ssk(msk, &addr_l.addr, &addr_r); if (ssk) { struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(ssk); - struct mptcp_pm_addr_entry entry =3D { .addr =3D addr_l }; =20 spin_lock_bh(&msk->pm.lock); - mptcp_userspace_pm_delete_local_addr(msk, &entry); + mptcp_userspace_pm_delete_local_addr(msk, &addr_l); spin_unlock_bh(&msk->pm.lock); mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); mptcp_close_ssk(sk, ssk, subflow); --=20 2.45.2 From nobody Sun Dec 22 01:42:47 2024 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 5AB961EE00E; Fri, 13 Dec 2024 19:54:47 +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=1734119687; cv=none; b=WNxJYVq9vQtyfv24LzExo/aCE4oibfuz8t513+lDJw0nYiUlls8vJhHZOAe+5X5WYxyZK81/SO2SlwLfq4ffIHw+OwwMDxJ4JbOP16cDZF36Gf9rmtF69h2V6fv1Xzu07fbI7dSEnP/5+ik01NfBFQVvd58Q7ezm87cXwIJ7hMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734119687; c=relaxed/simple; bh=7oL25jhFXzdbLw5+wM5A5ckyzaIWred6kZBGWuVszro=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HeZIcZWCAJNNloMJfFX8nldjRiH6CVVphZ4pCmIkSIfIqWBzuEQVwbd6Vwaq2dUE7Xgyf24YuSY7vQC80MfB/csLOIVRYJopC/abQeIb9CM5sJ/LoO0YcIw6tn89KzDY7e7i09Wc9xGtEw3hta2+u0dYzD1DJUFTEJZTrhu75sc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z0IEwRBB; 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="Z0IEwRBB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9FBEC4CED0; Fri, 13 Dec 2024 19:54:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734119686; bh=7oL25jhFXzdbLw5+wM5A5ckyzaIWred6kZBGWuVszro=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Z0IEwRBBq1aJbH5BQBb7wG2L5dnWK2rseQ7exB3z3io7IzzkwiqsZT/hZlGY+qp0P BhDrg3Skmjg5ThxJKym0FIXHPxRy7N/QiagskD5v6/G9LJMfHa8tQ3yY6Ki36zTiNj e/PNvs1oe+cyI/bWv4HiUaNPxI7hACaSOyXymyp3P0mXE6k9LRBZJM4zJwh8yzXLyg 3mINu447aa/4AYPPQ52mdm89MbkcE4aYCPpQ+eKqXYb337EaCN/UColTylUGLtbCzo DAOMjaBtdupnZ8KQL47S+hW6eIFq9G8dj9JeOcQ2lcMl5mnEN5IpM2UZeuT14FdN/K n8hOSJVWadBlA== From: "Matthieu Baerts (NGI0)" Date: Fri, 13 Dec 2024 20:52:58 +0100 Subject: [PATCH net-next 7/7] mptcp: drop useless "err = 0" in subflow_destroy Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241213-net-next-mptcp-pm-misc-cleanup-v1-7-ddb6d00109a8@kernel.org> References: <20241213-net-next-mptcp-pm-misc-cleanup-v1-0-ddb6d00109a8@kernel.org> In-Reply-To: <20241213-net-next-mptcp-pm-misc-cleanup-v1-0-ddb6d00109a8@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" , Geliang Tang X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1935; i=matttbe@kernel.org; h=from:subject:message-id; bh=rsC7IsSRZXPkUerMAAj+cBgM1aGHI4tEFgkPXwpi7nw=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnXJDxsnXB+CRb9Ph5EgoNY/WPHborbSYNMoaXt OMDtI2pUzGJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZ1yQ8QAKCRD2t4JPQmmg c2y3D/90W3msnUl0x14ifXGyjR9XoFZOZpWoHdrYNpKncGXgAa/s7388ulrw2UXTYqq5C5k/lIX MFjPIS/CBle6OXe5nal9IfI2xiUjt9dbleIvlSgTvyebG6580b30E/qZBTZtunsD8uM21+wyBPZ q80V2c4AjikZ5edjeYmFbxYvGNLIdvWCXNa10l7NhIA8ss1J2TRTKwv8UEaiXG5vGg3iQtnVRHK hmk5/C+Yc3idfU6b9C1fnlR1oZxcHkdiiYcsZT23tmo8Vr+2etN4gUpo6YyLg+VuR+OH6CQqSw3 SI8QdjaDIlmkSYhE4VlWGFoz1mi6jpPG24piKQPUGUvlg4SqZGFdZK+dUgQw7LqBDYMclU0F812 7urADlamsg8pTmSaWgh+hDRVaC4JhAANvZRLaNnVF8MSnGCCoPJr6tLzY4zMT5qmz864Ira0VLJ uKCTqSNEQKB99d/ro3EpLKcpNVNsTRgAgz0BfMT1HLvAoJXnhqSyBMlHxHyhPSqSvQUUinOXD13 PZjJxhborHj+4ha/TMolrHIlP7q54lkUBO209Qm0NO2ESNWpUKbxAxgdt6eJww0qjV54QdC3uey G1ZPRuR00DXy6FegswOrBsRasBwXATsKXUn/APkQA3Y6KoRwnviC/C675T5HcZ8K1/TBFDnhHm1 mebeauR6ocbMwkg== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang Upon successful return, mptcp_pm_parse_addr() returns 0. There is no need to set "err =3D 0" after this. So after mptcp_nl_find_ssk() returns, just need to set "err =3D -ESRCH", then release and free msk socket if it returns NULL. Also, no need to define the variable "subflow" in subflow_destroy(), use mptcp_subflow_ctx(ssk) directly. This patch doesn't change the behaviour of the code, just refactoring. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 1d5b77e0a722de74f25c9731659b2c938122c025..740a10d669f859baec975556f1d= 7c4e90df62c4a 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -538,19 +538,18 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *= skb, struct genl_info *info =20 lock_sock(sk); ssk =3D mptcp_nl_find_ssk(msk, &addr_l.addr, &addr_r); - if (ssk) { - struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(ssk); - - spin_lock_bh(&msk->pm.lock); - mptcp_userspace_pm_delete_local_addr(msk, &addr_l); - spin_unlock_bh(&msk->pm.lock); - mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); - mptcp_close_ssk(sk, ssk, subflow); - MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW); - err =3D 0; - } else { + if (!ssk) { err =3D -ESRCH; + goto release_sock; } + + spin_lock_bh(&msk->pm.lock); + mptcp_userspace_pm_delete_local_addr(msk, &addr_l); + spin_unlock_bh(&msk->pm.lock); + mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); + mptcp_close_ssk(sk, ssk, mptcp_subflow_ctx(ssk)); + MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW); +release_sock: release_sock(sk); =20 destroy_err: --=20 2.45.2