From patchwork Wed Oct 16 09:12:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837966 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 555DE17D378 for ; Wed, 16 Oct 2024 09:12:48 +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=1729069968; cv=none; b=WVy/zBRSJw6cltvarxM0W0upoUaKi+wCQL7JVJ5Oue10SJ9ck/bW8OF3ViJ19d29fpgF2GSoWHYCcITQn7EeFbGg946IpVzOJaTa8ERiKDLcMQ6PCFVuu8saMUMmJmFIpraMgnTAuoCghFYVDgUrG7cUQY7Xwb290CD/ENbbqrg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069968; c=relaxed/simple; bh=ijKOH/eCdFxvz5RnSeeb027EaSLIlLFbnOsrdlM7J40=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A3Mst2nfJRubKNri0GtYwFqDmRSyzFtRZnKFz/xyBUHhLNWsHCZR9qP7G4Ya+8ajQXll5Z/YlXdvPbo6LvsQK7xpxKRrxxOd2pHlBjzB5oBLvEmKh/+EMt7/YgWKQIuLHr0tox7WKB6jRBToC4EWV2vrCmjGSq4umGsT/3JrUSI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KZDEA/e3; 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="KZDEA/e3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1952C4CEC5; Wed, 16 Oct 2024 09:12:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069968; bh=ijKOH/eCdFxvz5RnSeeb027EaSLIlLFbnOsrdlM7J40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KZDEA/e3SzNV8ETf9zzDyd8LRTQq1k7CPD/zsh7WEBv7eF6fJR+TrFnc3NKfzJNat 7fhhI9OIXjIucgqKQsE3v5orClaaggqAejjAK4rdCHxhY5vqZxCEiEZqjUMgIcvH++ zWIjs8EelRmaLTcpbbeY/rOzVYZ3LuV5HaPjJ4/2DAuSr35lpyjis1CEXD9UvUZE2Z O4m86M7iQ3ukkRpl3y41nJexAsKjEkJ5aPDuC7YFGBHREiZgQNPAs44wIJtMP709FQ LtAKe36fwR0LUkYa7K/N0oDjTtDSWI/wBP+MQBRpRC8VEDiP8TB1PX5NDD4mlPvs24 jakPFBkCWYGSg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 01/33] mptcp: drop else in mptcp_pm_addr_families_match Date: Wed, 16 Oct 2024 17:12:05 +0800 Message-ID: <4c1705527b0925af04b4358b4feea1ced5cf8ca0.1729069853.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 helper mptcp_pm_addr_families_match() uses "if-else" to handle IPv6 and IPv4 addresses separately. But the last line of "if" code block is a "return" statement. In this case, no need to use an "else" statement. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 16c336c51940..f3d354a72c94 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -495,9 +495,8 @@ bool mptcp_pm_addr_families_match(const struct sock *sk, return !loc_is_v4 && !rem_is_v4; return loc_is_v4 == rem_is_v4; -#else - return mptcp_is_v4 && loc->family == AF_INET && rem->family == AF_INET; #endif + return mptcp_is_v4 && loc->family == AF_INET && rem->family == AF_INET; } void mptcp_pm_data_reset(struct mptcp_sock *msk) From patchwork Wed Oct 16 09:12:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837967 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 64BD6204F9D for ; Wed, 16 Oct 2024 09:12:50 +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=1729069970; cv=none; b=Hj4mgTAZXlH+zrQLKJGKHy27L1ZTQVvPgeoCUjVfk+Cyv5I9813DWwsrxgZXwiCDeg14VLrFNgL3qGAjfiS75oX1+k9gIwLM9LJg9onJx7bAulf0VPTPDXwEK5wBvJZAYupPIFBpxFWOJaXosIz6/IYCXLeVTekODTyVUBNOpDI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069970; c=relaxed/simple; bh=t1Vs7CzvUMnE0bifUeMFM2eeNfmqwTgytf+gcz9YhaE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ugAzCfxpL3JWMEb8yGXpfW7K8mZyJqv+kGn3gEpWsyDv4IB6zkgtlB3tZo2KEVy5KZXRdybGPQ2YNH+H2BYKZVu8//QIznITABSL1bc73hppPBjnrXucB8xNbStJg96j8NDvP03eqDR3LI3S3mqKLDBxl2qjjuvKcWGdC7d5yvQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WXI7kkQ7; 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="WXI7kkQ7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCD7BC4CEC5; Wed, 16 Oct 2024 09:12:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069970; bh=t1Vs7CzvUMnE0bifUeMFM2eeNfmqwTgytf+gcz9YhaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WXI7kkQ7vSgqNABnd9EEXGA7zLxLaB0C3cx56/E8aDeEM7UItlAL2kejFCD4rQDeg OfU2WprS1fBEhARE7aJGBP44vClIrn0PjKfP0VxjxBD9bNJcR/I1AKWjoWdWNudTKe NMIxpgQsIcVvKXe6XVuCJJbOtR2ZxQKVBsVWljopXx41d6ESFivOXoVS1Dz325vFrK pepdeZioXj6GGe3nVkCwHWoyzIi77NyuF6LHpqNKHceZLHl+JYsJ8JVyz9Xrcyvy+4 kYvVtYyfUhOvTeFDfLeM6j9mJ1H4dgZKqMCXpD8fyT5juSPP1f6HoGidWJbfE7ubk+ a0mrY0E8KxGGg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 02/33] mptcp: use __lookup_addr in pm_netlink Date: Wed, 16 Oct 2024 17:12:06 +0800 Message-ID: <02d8e47d8900fe16587b8fb33b4ccdc21b4852a0.1729069853.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 helper __lookup_addr() can be used in mptcp_pm_nl_get_local_id() and mptcp_pm_nl_is_backup() to simplify the code if using list_for_each_entry_rcu() instead of list_for_each_entry() in it. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index d37fefbaf34f..1664fa993058 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -524,7 +524,7 @@ __lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info) { struct mptcp_pm_addr_entry *entry; - list_for_each_entry(entry, &pernet->local_addr_list, list) { + list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) { if (mptcp_addresses_equal(&entry->addr, info, entry->addr.port)) return entry; } @@ -1146,12 +1146,9 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc pernet = pm_nl_get_pernet_from_msk(msk); rcu_read_lock(); - list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) { - if (mptcp_addresses_equal(&entry->addr, skc, entry->addr.port)) { - ret = entry->addr.id; - break; - } - } + entry = __lookup_addr(pernet, skc); + if (entry) + ret = entry->addr.id; rcu_read_unlock(); if (ret >= 0) return ret; @@ -1181,12 +1178,9 @@ bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc) bool backup = false; rcu_read_lock(); - list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) { - if (mptcp_addresses_equal(&entry->addr, skc, entry->addr.port)) { - backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); - break; - } - } + entry = __lookup_addr(pernet, skc); + if (entry) + backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); rcu_read_unlock(); return backup; From patchwork Wed Oct 16 09:12:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837968 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 386CF18D626 for ; Wed, 16 Oct 2024 09:12:51 +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=1729069972; cv=none; b=dYtlS8h5BF6UREAAcs+pdPY/Csh+ZPOLOktYXmxIUxhsQ3yi4xRoKPMLBZ8QWbZm+zXHWkSJ5sNbjRuqN70x17wXpv9PfAmcnphbOPo8KUaSaXNUA68NqQ1MluhIOR7BEU+ctoK9tVTJtNS9B+7iU0peZvnB+T+IoCRTiRkVIwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069972; c=relaxed/simple; bh=nKkyplpOdqOaKeJCh1uW60xTSN8hbuvpssiZOQ0nLc0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IS7HHCOQ1ebsw1uOFIDew1JoOykRDTfX1zRsAPSlCk0GoPNJGRxt6BG5stSJdZt4x2Z7IM3JnCEW3KeiSEIpRy3gwM+0NCGYSYkaqfwRX+7ksSp44MfwPOVgwpOMAH9VoMjXrZuBtcX3M477iAeUFj1OkEM8zfwoWOzNO3weIMw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YIM9QWcZ; 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="YIM9QWcZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A78D9C4CECF; Wed, 16 Oct 2024 09:12:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069971; bh=nKkyplpOdqOaKeJCh1uW60xTSN8hbuvpssiZOQ0nLc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YIM9QWcZgXUUsK0bQXFRu0YQ9Mixp+de5U7O5TNEKTVBCgd7dwL2QDJnOfviE8zMj ccRXGhWUAB0r+aDUsUYOs41emdkoMbYGbKVbs2yo/QkD1XBiiqWvaw1T/wFlXQwVFk tnyljbhiOgzS8AjNWy38BrKw8GLFF6CsmyYHygrAzXjcQejyN7CT32spWcf4bA2T9P XmAJVXlA6HwvfxTHJII0EiOkqHMHPKML2CdmXkO18zaM0/O6c1JKAMDTbWXCf9uKof 4Mcf607slAMrjRfikoamudLB8hAhrplv3eXbWYpni9vnetty+NwD1TZOOsnlb8FweI +2Qe4Z9AEM3pw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 03/33] mptcp: add mptcp_for_each_address macros Date: Wed, 16 Oct 2024 17:12:07 +0800 Message-ID: <36d6f8988939d9cdbfd83b0fb804d322eeb106fb.1729069853.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 Similar to mptcp_for_each_subflow() and mptcp_for_each_subflow_safe() macros, this patch adds two new macros mptcp_for_each_address() and mptcp_for_each_address_safe() to iterate over the address entries on userspace_pm_local_addr_list of the mptcp socket. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 12 ++++++------ net/mptcp/protocol.h | 5 +++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 2cceded3a83a..00a7f9dd90cf 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -41,7 +41,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, bitmap_zero(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); spin_lock_bh(&msk->pm.lock); - list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_address(msk, e) { addr_match = mptcp_addresses_equal(&e->addr, &entry->addr, true); if (addr_match && entry->addr.id == 0 && needs_id) entry->addr.id = e->addr.id; @@ -92,7 +92,7 @@ static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk, { struct mptcp_pm_addr_entry *entry, *tmp; - list_for_each_entry_safe(entry, tmp, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_address_safe(msk, entry, tmp) { 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). @@ -112,7 +112,7 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *msk, unsigned int id) { struct mptcp_pm_addr_entry *entry; - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_address(msk, entry) { if (entry->addr.id == id) return entry; } @@ -127,7 +127,7 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, inet_sk((struct sock *)msk))->inet_sport; spin_lock_bh(&msk->pm.lock); - list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_address(msk, e) { if (mptcp_addresses_equal(&e->addr, skc, false)) { entry = e; break; @@ -155,7 +155,7 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, bool backup = false; spin_lock_bh(&msk->pm.lock); - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_address(msk, entry) { if (mptcp_addresses_equal(&entry->addr, skc, false)) { backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); break; @@ -642,7 +642,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, 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_address(msk, entry) { if (test_bit(entry->addr.id, bitmap->map)) continue; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 7848a1989d17..a0f7b62c8c12 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -354,6 +354,11 @@ struct mptcp_sock { #define mptcp_for_each_subflow_safe(__msk, __subflow, __tmp) \ list_for_each_entry_safe(__subflow, __tmp, &((__msk)->conn_list), node) +#define mptcp_for_each_address(__msk, __entry) \ + list_for_each_entry(__entry, &((__msk)->pm.userspace_pm_local_addr_list), list) +#define mptcp_for_each_address_safe(__msk, __entry, __tmp) \ + list_for_each_entry_safe(__entry, __tmp, &((__msk)->pm.userspace_pm_local_addr_list), list) + extern struct genl_family mptcp_genl_family; static inline void msk_owned_by_me(const struct mptcp_sock *msk) From patchwork Wed Oct 16 09:12:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837969 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 ACF3C205125 for ; Wed, 16 Oct 2024 09:12:53 +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=1729069973; cv=none; b=YnTEEO55tN1FVS1Ivy2prYBQBDYrl3qMpLpDcIaDf438kTI0pDL9hs6XbzBpb1kAtm6JhAY3c8GJ69ti1nGXTOL5vCndKKvu9wif1DIE3cLRyxzriUssW3JO8bgYD1r1iWnbSnaE6ZK69rtYDegX1eN7ENJnp7PSHEwXs6CxhM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069973; c=relaxed/simple; bh=ZJXQ8uNJ3Z4VO1rjzECqY1E+6bKfK8oP5+YnjMOQb70=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VkWJu9ADfrBiJ75I68ko3OGzcaEqjGNZrj157jtP7TuVKwXBqz9GK3wFKI9Os6vF7+z2hZuwTS0ski3dc2j4kYps7X1eff7lcuzYWITGBBcaEzEpBlb/u+8fIRd+ElVFFtWLkGG7X1Tbtcx8Dh3B3iSg8zePmDZTBePsI756Y2E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Zjri2RH1; 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="Zjri2RH1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F236C4CEC5; Wed, 16 Oct 2024 09:12:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069973; bh=ZJXQ8uNJ3Z4VO1rjzECqY1E+6bKfK8oP5+YnjMOQb70=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zjri2RH1q0PzghYkYdKw2BBndUb486gh/3fbbEM5Rn6zocl6JC0ER2whBj5dSpCj2 H7/cK2vozSkkDLzOsBo8LclRYB4UBFn+lIGElnHp0LQG1xnROOP5IsFUOg9Cy/InF8 MhfC8Aj2/LCu3DSLNejleuKDQ7UT2XlikOFxfgDQK7scLWynHFcuGrZ0mJp1s6PyAg MrpX4Q5ylOhza9qDhoPdNwt7ZLfhtq7PGry8WkmIjz5DtgSD6W2i+e+aLyOMJOHSkG yV7bwmqklZKK2sop/ArV0LKG11mLmDCmPuaGt1L/+XPw/yJjIXRBdeJhngknkBb9w4 RmKmYbnAdpPdw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 04/33] mptcp: use sock_kfree_s instead of kfree Date: Wed, 16 Oct 2024 17:12:08 +0800 Message-ID: <6f1789ccf1cbe2db89b95a08ad2ef0467b1de028.1729069853.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 local address entries on the userspace_pm_local_addr_list are allocated by sock_kmalloc(). It's better to use sock_kfree_s() to free them, instead of using kfree(). Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 00a7f9dd90cf..3fb5713cd988 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -91,6 +91,7 @@ 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 = (struct sock *)msk; mptcp_for_each_address_safe(msk, entry, tmp) { if (mptcp_addresses_equal(&entry->addr, &addr->addr, false)) { @@ -98,7 +99,7 @@ static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk, * be used multiple times (e.g. fullmesh mode). */ list_del_rcu(&entry->list); - kfree(entry); + sock_kfree_s(sk, entry, sizeof(*entry)); msk->pm.local_addr_used--; return 0; } From patchwork Wed Oct 16 09:12:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837970 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 1B7EC18D626 for ; Wed, 16 Oct 2024 09:12:54 +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=1729069975; cv=none; b=fGMfqPoF8DgpB6vPre6upXTUjhnj/YZCllctBmbim3UeN4eZ4MUMRIZELPYRCzw3y7DrIcFVI8PnvW6YW/M6QA94RmFnU4ih6UInFZ+Q5Sdz23LSdA8ttapPgZ1JXJcLixlKwmWUZtu0EQahhuG+/x0e2MZSpxhEyIKoKYAEv2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069975; c=relaxed/simple; bh=B5nYLAXYrkgiPqTT3SqCU8tHkpgoP2QHSdM6l/QyU6U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jwa8kNbt7M8f/mGE0urvUp9TfLSst5kiiKPWfR3D9w0KC/wOTWPwzgbDr3m2ZwlHfO7dd/YFxg60J8sEQYy2mjHdcvd1tkHC1tF7B/oSInPmfzPnHZ1pHDwHSbrfk2EI2Jx1Oatr15UflcLud57f2Q4OJvC2zFu9QnndaZMbxzM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nLVm4txY; 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="nLVm4txY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C85CCC4CED0; Wed, 16 Oct 2024 09:12:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069974; bh=B5nYLAXYrkgiPqTT3SqCU8tHkpgoP2QHSdM6l/QyU6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nLVm4txYAFQfLShqOyB/HOF/ychLhBxT2wu29uqpychP4OhCqvZ7+zfGgLvNZtulz tFcuT8c5U4MexzqDXZ19Z/6liRSHbb9pv0syUTAUwmq7AYWyrTsjTT96uPvU1r+O6r TQyp3WGdX+L5uC8UyuKWXtnVec/Hq97J1JoREGlfAJUlfNjsm4zfvtZwlWqtSJRDIY aXxSrdIajdQxdF1AFexsBtQQUNEtQlfEqCH6pnFo+BiXT4SA2HbDHwTQGOCUN6et8G 6fHxhhlTKW00uhOzi3pv0ztNqZzFSYHOLjMcQnsH4bhosQX7wKXaxWTcpGtpjDwI8T uiXzTf2T04Jlg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 05/33] mptcp: add lookup_addr for userspace pm Date: Wed, 16 Oct 2024 17:12:09 +0800 Message-ID: <70ba6915c9d654f691528bf3aa4e47198388d01e.1729069853.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 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 it. This helper can be used in mptcp_userspace_pm_delete_local_addr(), mptcp_userspace_pm_get_local_id() and mptcp_userspace_pm_is_backup() to simplify the code. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 56 +++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 3fb5713cd988..ce0f7131c701 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -26,6 +26,18 @@ void mptcp_free_local_addr_list(struct mptcp_sock *msk) } } +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, *tmp; + + mptcp_for_each_address_safe(msk, entry, tmp) { + 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 +102,20 @@ static int mptcp_userspace_pm_append_new_local_addr(struct 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 = (struct sock *)msk; + struct mptcp_pm_addr_entry *entry; - mptcp_for_each_address_safe(msk, entry, tmp) { - 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; - } - } - - return -EINVAL; + entry = mptcp_userspace_pm_lookup_addr(msk, &addr->addr); + if (!entry) + 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; } static struct mptcp_pm_addr_entry * @@ -123,17 +133,12 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *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 = NULL, *e, new_entry; + struct mptcp_pm_addr_entry *entry = NULL, new_entry; __be16 msk_sport = ((struct inet_sock *) inet_sk((struct sock *)msk))->inet_sport; spin_lock_bh(&msk->pm.lock); - mptcp_for_each_address(msk, e) { - if (mptcp_addresses_equal(&e->addr, skc, false)) { - entry = e; - break; - } - } + entry = mptcp_userspace_pm_lookup_addr(msk, skc); spin_unlock_bh(&msk->pm.lock); if (entry) return entry->addr.id; @@ -156,12 +161,9 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, bool backup = false; spin_lock_bh(&msk->pm.lock); - mptcp_for_each_address(msk, entry) { - if (mptcp_addresses_equal(&entry->addr, skc, false)) { - backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); - break; - } - } + entry = mptcp_userspace_pm_lookup_addr(msk, skc); + if (entry) + backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); spin_unlock_bh(&msk->pm.lock); return backup; From patchwork Wed Oct 16 09:12:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837971 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 8E54618D626 for ; Wed, 16 Oct 2024 09:12:56 +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=1729069976; cv=none; b=TbDOZ93nJUVLr3jN8iBWYvLrg4ESr2WlJ9irkg0aA/Qlvba2dMPbFmBSJS2HMSGmqlZPZ9kKRCu9K+25Wauf5ZI5kbmldhwDFxS2qgbSJWcQmoiX/+SdgRVRQAVw12D6NXqhOd7gkXKVMm586Ws8zfsQs2vO5JAUGIEYrevU+bs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069976; c=relaxed/simple; bh=NRHw9P2ONxn8aUcs8tWFvd5uoauks3WL00DaLxKCi/Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pub4p+daoHQ4OwPfGSLQ5eTbm5xU5sU6mDWVAPhidORK/BeyDeIshRs3SUnoylvaIJHhfHPq56ry8NOZq6/2iDnDvgdXgtpgMo3JmRMojVzhhCPuhCF3TOs8deyVFb5AJwR8/KMEuY5JVxZ9xHLSN3CEziu0XbIjHEVZxE33PQw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SO7qBXZi; 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="SO7qBXZi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40FE2C4CECE; Wed, 16 Oct 2024 09:12:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069976; bh=NRHw9P2ONxn8aUcs8tWFvd5uoauks3WL00DaLxKCi/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SO7qBXZiL/LIaK45atykEe48Tjxo7BOagVf7eXNPbk9EJDXOJDCqSJXAH1kIevqlN gJFReq3blWT3rCfdfQXkCgyNSJrc+i7qTekU5oivG8k96Q3ehHoaiSAWKUqjtXkhmK qoGIzVvx//WXJgu6RtBjlqfJR8cenM31+RjJUSE4lY/ZUyMd2gVCuVcN6UaVsta7jj KXpN9eR0HRO5DAPDaVGwdrqTN+OxbQQjrVderKOwQwDxkS1kwfcqPiJc7vUw+7pvtP PsKDWGf6STilS5kYY+7PQinq4ataDCWsI0A7bGacZRJsEPxqBFk/Mm6OBLMbqb+gHL /Tm98sdkpk+IA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 06/33] mptcp: add mptcp_userspace_pm_get_sock helper Date: Wed, 16 Oct 2024 17:12:10 +0800 Message-ID: <0b4f91aa7d9e71df017b58d35fd00b7dbaf1069f.1729069853.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 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. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 137 +++++++++++++-------------------------- 1 file changed, 44 insertions(+), 93 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index ce0f7131c701..79ae32c921b7 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -169,36 +169,51 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, return backup; } -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_info *info) { struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; + struct mptcp_sock *msk = NULL; + + if (!token) { + GENL_SET_ERR_MSG(info, "missing required inputs"); + goto out; + } + + msk = mptcp_token_get_sock(genl_info_net(info), nla_get_u32(token)); + if (!msk) { + NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + goto out; + } + + if (!mptcp_pm_is_userspace(msk)) { + GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); + sock_put((struct sock *)msk); + msk = NULL; + } + +out: + return msk; +} + +int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) +{ struct nlattr *addr = info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry addr_val; struct mptcp_sock *msk; int err = -EINVAL; struct sock *sk; - u32 token_val; - if (!addr || !token) { + if (!addr) { GENL_SET_ERR_MSG(info, "missing required inputs"); return err; } - token_val = nla_get_u32(token); - - msk = mptcp_token_get_sock(sock_net(skb->sk), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk = mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } sk = (struct sock *)msk; - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto announce_err; - } - err = mptcp_pm_parse_entry(addr, info, true, &addr_val); if (err < 0) { GENL_SET_ERR_MSG(info, "error parsing local address"); @@ -271,7 +286,6 @@ static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk, int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *id = info->attrs[MPTCP_PM_ATTR_LOC_ID]; struct mptcp_pm_addr_entry *match; struct mptcp_pm_addr_entry *entry; @@ -279,30 +293,21 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) LIST_HEAD(free_list); int err = -EINVAL; struct sock *sk; - u32 token_val; u8 id_val; - if (!id || !token) { + if (!id) { GENL_SET_ERR_MSG(info, "missing required inputs"); return err; } id_val = nla_get_u8(id); - token_val = nla_get_u32(token); - msk = mptcp_token_get_sock(sock_net(skb->sk), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk = mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } sk = (struct sock *)msk; - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto out; - } - if (id_val == 0) { err = mptcp_userspace_pm_remove_id_zero_address(msk, info); goto out; @@ -336,7 +341,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 = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry entry = { 0 }; struct mptcp_addr_info addr_r; @@ -344,28 +348,18 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) struct mptcp_sock *msk; int err = -EINVAL; struct sock *sk; - u32 token_val; - if (!laddr || !raddr || !token) { + if (!laddr || !raddr) { GENL_SET_ERR_MSG(info, "missing required inputs"); return err; } - token_val = nla_get_u32(token); - - msk = mptcp_token_get_sock(genl_info_net(info), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk = mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } sk = (struct sock *)msk; - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto create_err; - } - err = mptcp_pm_parse_entry(laddr, info, true, &entry); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); @@ -468,35 +462,24 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_sock *msk, int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *laddr = 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 = -EINVAL; - u32 token_val; - if (!laddr || !raddr || !token) { + if (!laddr || !raddr) { GENL_SET_ERR_MSG(info, "missing required inputs"); return err; } - token_val = nla_get_u32(token); - - msk = mptcp_token_get_sock(genl_info_net(info), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk = mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } sk = (struct sock *)msk; - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto destroy_err; - } - err = mptcp_pm_parse_addr(laddr, info, &addr_l); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); @@ -559,30 +542,18 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, }; struct mptcp_pm_addr_entry rem = { .addr = { .family = AF_UNSPEC }, }; struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; - struct net *net = sock_net(skb->sk); struct mptcp_sock *msk; int ret = -EINVAL; struct sock *sk; - u32 token_val; u8 bkup = 0; - token_val = nla_get_u32(token); - - msk = mptcp_token_get_sock(net, token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk = mptcp_userspace_pm_get_sock(info); + if (!msk) return ret; - } sk = (struct sock *)msk; - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "userspace PM not selected"); - goto set_flags_err; - } - ret = mptcp_pm_parse_entry(attr, info, false, &loc); if (ret < 0) goto set_flags_err; @@ -619,30 +590,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 = genl_info_dump(cb); - struct net *net = sock_net(msg->sk); struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; - struct nlattr *token; int ret = -EINVAL; struct sock *sk; void *hdr; bitmap = (struct id_bitmap *)cb->ctx; - token = info->attrs[MPTCP_PM_ATTR_TOKEN]; - msk = mptcp_token_get_sock(net, nla_get_u32(token)); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk = mptcp_userspace_pm_get_sock(info); + if (!msk) return ret; - } sk = (struct sock *)msk; - 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_address(msk, entry) { @@ -667,7 +628,6 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, release_sock(sk); ret = msg->len; -out: sock_put(sk); return ret; } @@ -676,28 +636,19 @@ int mptcp_userspace_pm_get_addr(struct sk_buff *skb, struct genl_info *info) { struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; - struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; struct mptcp_pm_addr_entry addr, *entry; - struct net *net = sock_net(skb->sk); struct mptcp_sock *msk; struct sk_buff *msg; int ret = -EINVAL; struct sock *sk; void *reply; - msk = mptcp_token_get_sock(net, nla_get_u32(token)); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk = mptcp_userspace_pm_get_sock(info); + if (!msk) return ret; - } sk = (struct sock *)msk; - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto out; - } - ret = mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) goto out; From patchwork Wed Oct 16 09:12:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837972 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 1947318D626 for ; Wed, 16 Oct 2024 09:12:57 +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=1729069978; cv=none; b=FyJYZCtgq0+S/QuI8xUOQpkRjnBMon5qbSljW0hSFkqb4WyJ4s+cpk6KNDARstXsb2qiU9K8MgL5bGdV5raTFI89bnmKnmKBvi/Vbmb4fM5dyGQwPIg+oqQiw4SUSwd7D3wlkjCMdLcS7/DUyR5avM9QkbEsEeOXT2/FDzNx36I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069978; c=relaxed/simple; bh=Y7dagt275L2Uu6LtKNImGprjF0TYena2yh243+QvCZQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O9biOqzuX8twYfL7YO/pKv+mOGiB3t7CvJtL2pBkJauP0u3sp4qtZ3P6pizEirlhinyDEOANSIS8IaTB1VDLqrT9aHXqY9cI92JiZdDP7SsoaHiozAECtEB+lbzwAaePZ0DAXi/AAlI9KSiPhlGsh5zX/byuOIy3iyhsm6HjP3s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Hz7A7JyJ; 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="Hz7A7JyJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB4FBC4CED0; Wed, 16 Oct 2024 09:12:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069977; bh=Y7dagt275L2Uu6LtKNImGprjF0TYena2yh243+QvCZQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hz7A7JyJl6/Ap+R6NXy0hM1Ae/C8V8a7Y21QrL4Sir6I+7H+9qcxc0wJcb0fpnTUa 3P8Nw228sufUvOoIFTBquCNGCKJ++k0ZLECW2Dh9/QryL3+bWopg1He26bSk1Lu4PV Ojosy3kMDSzyjCEqMOIIm9v4tN76bvD0bTPfng/penuoVTyWNG+3rcDncjL2U83Cfl gtOHY3DTf8/uZp/jzTNRpunq/XM6wBpJnS37uZqt9zjOMPgLpJ+Sv+fusehQlJHTJy zC1G26I+rZd8cVgjD48TLwUgN1K1H7xAcNwXbKXcX9oLOg50zbPMu+YevLh+hT/uNw 2VZ5B5WEQzfvA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 07/33] mptcp: make three pm wrappers static Date: Wed, 16 Oct 2024 17:12:11 +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 Three path manager wrappers, mptcp_pm_get_addr(), mptcp_pm_dump_addr() and mptcp_pm_set_flags() are used to switch the interfaces between in-kernel PM and userspace PM. These wrappers are defined in pm.c but only used in pm_netlink.c. It makes more sense to move them to pm_netlink.c and make them all static. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 23 ----------------------- net/mptcp/pm_netlink.c | 31 +++++++++++++++++++++++++++---- net/mptcp/protocol.h | 7 ------- 3 files changed, 27 insertions(+), 34 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index f3d354a72c94..f5725c00eb70 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -433,29 +433,6 @@ bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc) return mptcp_pm_nl_is_backup(msk, &skc_local); } -int mptcp_pm_get_addr(struct sk_buff *skb, struct genl_info *info) -{ - if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_get_addr(skb, info); - return mptcp_pm_nl_get_addr(skb, info); -} - -int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) -{ - const struct genl_info *info = genl_info_dump(cb); - - if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_dump_addr(msg, cb); - return mptcp_pm_nl_dump_addr(msg, cb); -} - -int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info) -{ - if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_set_flags(skb, info); - return mptcp_pm_nl_set_flags(skb, info); -} - void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) { struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 1664fa993058..f4b9f44796a4 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1792,7 +1792,7 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } -int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info) +static int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info) { struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet = genl_info_pm_nl(info); @@ -1842,13 +1842,20 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info) return ret; } +static int mptcp_pm_get_addr(struct sk_buff *skb, struct genl_info *info) +{ + if (info->attrs[MPTCP_PM_ATTR_TOKEN]) + return mptcp_userspace_pm_get_addr(skb, info); + return mptcp_pm_nl_get_addr(skb, info); +} + int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) { return mptcp_pm_get_addr(skb, info); } -int mptcp_pm_nl_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb) +static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, + struct netlink_callback *cb) { struct net *net = sock_net(msg->sk); struct mptcp_pm_addr_entry *entry; @@ -1890,6 +1897,15 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, return msg->len; } +static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) +{ + const struct genl_info *info = genl_info_dump(cb); + + if (info->attrs[MPTCP_PM_ATTR_TOKEN]) + return mptcp_userspace_pm_dump_addr(msg, cb); + return mptcp_pm_nl_dump_addr(msg, cb); +} + int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, struct netlink_callback *cb) { @@ -2011,7 +2027,7 @@ static int mptcp_nl_set_flags(struct net *net, return ret; } -int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) +static int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) { struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, }; struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; @@ -2065,6 +2081,13 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) return 0; } +static int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info) +{ + if (info->attrs[MPTCP_PM_ATTR_TOKEN]) + return mptcp_userspace_pm_set_flags(skb, info); + return mptcp_pm_nl_set_flags(skb, info); +} + int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info) { return mptcp_pm_set_flags(skb, info); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index a0f7b62c8c12..726b1561d204 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1034,8 +1034,6 @@ 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); -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 *info); int mptcp_pm_announce_addr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, @@ -1126,13 +1124,8 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_in bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc); bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); -int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); -int mptcp_pm_nl_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); -int mptcp_pm_get_addr(struct sk_buff *skb, struct genl_info *info); -int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info); int mptcp_userspace_pm_get_addr(struct sk_buff *skb, struct genl_info *info); From patchwork Wed Oct 16 09:12:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837973 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 77C0117D378 for ; Wed, 16 Oct 2024 09:12:59 +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=1729069979; cv=none; b=us6io0J41b7peP73fx1Gc1w/seNC2IGyq0UwWtiq+i8Hlqwev13951JM2v+6Sfm/5yvMvniVRARZGwpJXsKs/+SiM/S/3XliHu1F4Qd3y1ns8Xa4bp1flNix9TQMFkH6KuCrdMeXSLNe9a/hDNeiiTfOqZO9CXPO7cK6DsH3QOY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069979; c=relaxed/simple; bh=8fWtnK4RyD5s7JHpfoWaVXyGrNw6wsz2iGW10NV5GAs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BFW7Pj582Xg4cn0ZZJe7GpnTrwYSDZP1GQ7M5mqAcpj3307w1is2buTatRy7tkUd6V6e/jThyXp36VNk93aeuxLk+0HL6uF+5bC/UEPSLIOHiHmmCp2AGP4dxW+0mS5piRVQF0IU9s2OiWDxsD8nf8TePnMhJ8rBQ6qkacfqiDM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LbhUiEzo; 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="LbhUiEzo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 407E3C4CEC5; Wed, 16 Oct 2024 09:12:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069979; bh=8fWtnK4RyD5s7JHpfoWaVXyGrNw6wsz2iGW10NV5GAs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LbhUiEzoQG9QrJi00iuVOa9wwa//8g+O3xJDJBQCsLaGiytUcP/IF3Sbiw8ggA9H/ Sib03qWx/z9GS5JYvqyFtdKN9+Pvr8OyWxY+V+B4D0yyLk3vMZpnI0aocKjPJeWqh7 d8OX2KNu3yYrzEECBbBjB6v/10Y2edBFfjY3hb6ao0Jxp1HrZ6WiiiUt2+o3+BwX9a 1HWzWRxlmhVxuEZiUI1Vln2ssAJ+YZELcFaZ1nUWT3qnKIbucnDUSEJcb1MD+rOGkV /jqh7DXv+NzuvVi24sqmEh0hhqVYnPxpZxr1KogcCVWWsqW6DBb7DYerlgXsw+YWwe nq/LLAnPyF3vw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 08/33] mptcp: drop skb parameter of get_addr Date: Wed, 16 Oct 2024 17:12:12 +0800 Message-ID: <603352e2447b2b7b936c97e670d3acb911457c3c.1729069853.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 first parameters "skb" of all three get_addr() interfaces are now useless since mptcp_userspace_pm_get_sock() helper is used. This patch drops these useless parameters of them. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 10 +++++----- net/mptcp/pm_userspace.c | 3 +-- net/mptcp/protocol.h | 3 +-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index f4b9f44796a4..fa320bdf2647 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1792,7 +1792,7 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } -static int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info) +static int mptcp_pm_nl_get_addr(struct genl_info *info) { struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet = genl_info_pm_nl(info); @@ -1842,16 +1842,16 @@ static int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info) return ret; } -static int mptcp_pm_get_addr(struct sk_buff *skb, struct genl_info *info) +static int mptcp_pm_get_addr(struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_get_addr(skb, info); - return mptcp_pm_nl_get_addr(skb, info); + return mptcp_userspace_pm_get_addr(info); + return mptcp_pm_nl_get_addr(info); } int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) { - return mptcp_pm_get_addr(skb, info); + return mptcp_pm_get_addr(info); } static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 79ae32c921b7..e61cc1805cee 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -632,8 +632,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, return ret; } -int mptcp_userspace_pm_get_addr(struct sk_buff *skb, - struct genl_info *info) +int mptcp_userspace_pm_get_addr(struct genl_info *info) { struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct mptcp_pm_addr_entry addr, *entry; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 726b1561d204..93deec8f0557 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1126,8 +1126,7 @@ bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); -int mptcp_userspace_pm_get_addr(struct sk_buff *skb, - struct genl_info *info); +int mptcp_userspace_pm_get_addr(struct genl_info *info); static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflow) { From patchwork Wed Oct 16 09:12:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837974 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 1A903204F9A for ; Wed, 16 Oct 2024 09:13:01 +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=1729069981; cv=none; b=JBfE682kv/UhMWE/AcLi0h2iiy9yey96Kj6UBH8+AgHOjF9q0tvlcgt+Vw/Lcb4nmLLFzd9mYblw4qQzotCto93gqcpDZOlugECD3kOvkVgwBsuysjqTpVnQnDeliHOZFmnz+Ydwqxlo2nh3nF5DpWzKBGw/sigXhoKTftQJQ4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069981; c=relaxed/simple; bh=/2Ee9VHNFGNC0ZQYPlRj3ngzOQBhYFClmWFOzZnQLWk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZfBWr59almt04RBoao3l+jXoI/0zSTHExb3GeO8ST1/KoPAD5cQqo9qM90BCsY523qkXspgDCNlADeO0LLeGzV8lOSuVV3ruOAKp00WoJiRDZtrq9GNQWNnlgN1h4E8CmNCrw9aF2XjRN6rWciJ9qIvZYU1Ly79v1VYegCojXYI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jXHnGrtk; 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="jXHnGrtk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C24C2C4CEC5; Wed, 16 Oct 2024 09:12:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069981; bh=/2Ee9VHNFGNC0ZQYPlRj3ngzOQBhYFClmWFOzZnQLWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jXHnGrtkl+rLr60UyG6w+2L+NyurnLQyAvdGxD6DFPJojXzdTE2zi9Igm5OL4vahE tY1uBvaCVZjK8QrYRTPaLlZyIuYf5DjKLUXyVEdZJStiPGl5LUh6CXZajQPnT/hydj OahUQW33eIhJHuedcFeEnZm+K58uHwX/4FVioap6MmIeq8U7k8DFhhIR8cTD2wNc9k MVA3hZmD0KwfosfP8quPfCyvGsHSbQjGo195bYvgIa5JppiyvCtE2tHuJc6/7X3w3i msnddJ4P/j2mBiMB7j2NS+sdhZxM+9VBP+xj9wP5LduzyqRL3ixGuPlmZgZvSFs10D AqAIO3BzOSwLw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 09/33] mptcp: add id parameter for get_addr Date: Wed, 16 Oct 2024 17:12:13 +0800 Message-ID: <6e31cc5a923722e9354229acfd45d18584e4bdef.1729069854.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 address id is parsed both in mptcp_pm_nl_get_addr() and mptcp_userspace_pm_get_addr(), this makes the code somewhat repetitive. So this patch adds a new parameter "id" for all get_addr() interfaces. The address id is only parsed in mptcp_pm_nl_get_addr_doit(), then pass it to both mptcp_pm_nl_get_addr() and mptcp_userspace_pm_get_addr(). Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 28 ++++++++++++++++------------ net/mptcp/pm_userspace.c | 11 +++-------- net/mptcp/protocol.h | 2 +- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index fa320bdf2647..be9d1aa3377f 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1792,19 +1792,14 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } -static int mptcp_pm_nl_get_addr(struct genl_info *info) +static int mptcp_pm_nl_get_addr(u8 id, struct genl_info *info) { - struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet = genl_info_pm_nl(info); - struct mptcp_pm_addr_entry addr, *entry; + struct mptcp_pm_addr_entry *entry; struct sk_buff *msg; void *reply; int ret; - ret = mptcp_pm_parse_entry(attr, info, false, &addr); - if (ret < 0) - return ret; - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) return -ENOMEM; @@ -1818,7 +1813,7 @@ static int mptcp_pm_nl_get_addr(struct genl_info *info) } spin_lock_bh(&pernet->lock); - entry = __lookup_addr_by_id(pernet, addr.addr.id); + entry = __lookup_addr_by_id(pernet, id); if (!entry) { GENL_SET_ERR_MSG(info, "address not found"); ret = -EINVAL; @@ -1842,16 +1837,25 @@ static int mptcp_pm_nl_get_addr(struct genl_info *info) return ret; } -static int mptcp_pm_get_addr(struct genl_info *info) +static int mptcp_pm_get_addr(u8 id, struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_get_addr(info); - return mptcp_pm_nl_get_addr(info); + return mptcp_userspace_pm_get_addr(id, info); + return mptcp_pm_nl_get_addr(id, info); } int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) { - return mptcp_pm_get_addr(info); + struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; + struct mptcp_pm_addr_entry addr; + int ret; + + ret = mptcp_pm_parse_entry(attr, info, false, &addr); + if (ret < 0) + return ret; + + ret = mptcp_pm_get_addr(addr.addr.id, info); + return ret; } static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index e61cc1805cee..079baceb9ca1 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -632,10 +632,9 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, return ret; } -int mptcp_userspace_pm_get_addr(struct genl_info *info) +int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info) { - struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; - struct mptcp_pm_addr_entry addr, *entry; + struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; struct sk_buff *msg; int ret = -EINVAL; @@ -648,10 +647,6 @@ int mptcp_userspace_pm_get_addr(struct genl_info *info) sk = (struct sock *)msk; - ret = mptcp_pm_parse_entry(attr, info, false, &addr); - if (ret < 0) - goto out; - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) { ret = -ENOMEM; @@ -668,7 +663,7 @@ int mptcp_userspace_pm_get_addr(struct genl_info *info) lock_sock(sk); spin_lock_bh(&msk->pm.lock); - entry = mptcp_userspace_pm_lookup_addr_by_id(msk, addr.addr.id); + entry = mptcp_userspace_pm_lookup_addr_by_id(msk, id); if (!entry) { GENL_SET_ERR_MSG(info, "address not found"); ret = -EINVAL; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 93deec8f0557..8ee0617209af 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1126,7 +1126,7 @@ bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); -int mptcp_userspace_pm_get_addr(struct genl_info *info); +int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info); static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflow) { From patchwork Wed Oct 16 09:12:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837975 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 E6601205E04 for ; Wed, 16 Oct 2024 09:13:02 +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=1729069983; cv=none; b=tTJkt5IUOWWwOcZGhi646M0ZyKoMJzvz1QwqI8+Nyg0rWVQlDp/Oalt2Easl+6e9+aDrT8oCNzM/b5+lcxXWRkOMb1uKNMV/useNuqeE0QhW+2l2aK65vF5Z6e9sZIIOjtH3XuyhniuwA57WfPInArtC9BqtdBGsN/6fYiXl8Fo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069983; c=relaxed/simple; bh=NnpShtCsmWhqFIS0vooxuASxjfo2lXyGvepMupASBis=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OqGpD0Z7nRityve3GGD0IXYyFn29270kBR+QKS8Rt2jAXcL99zmA9+ZWX5HqE4GL4qdK1c2S1axBlOtYsi5ZcVPSdCtg9Tp43msWBvO3Qy8z839sTf3QrdOiUisYwrsk+f2x8YQBhk4pZO6gweWLlS5Ei+it7HUbEcP0DUwjmCc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ACN4qeyr; 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="ACN4qeyr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C364C4CEC5; Wed, 16 Oct 2024 09:13:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069982; bh=NnpShtCsmWhqFIS0vooxuASxjfo2lXyGvepMupASBis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ACN4qeyrlX2V6fyanFteurFh+6eSo/ulq/0sZIIEdqSHw73LUhWB3hydMkdn1VFUN lPpIpMvEEHA9sCwf4zmkmYaVPBDUhu7XE1rVf1ZS5LuzvE+/70yZo54UHCm0fgUBw7 NSxT12Nt/Gdsn9iRFsC3/taoiXEnoYMljLElHppUyWv6bEzKTSfFHLI93u865eYp7L ufADE27w0CUswAw3TWf1xY78Gaai9Wrm6qM1hUovaA9YlAMxPlqzjqVqR6BZbpExky GuhyFyxPt9/R8OM3f1bd2QOyAUpIhZMg4g5q8U34oIRWzcED1wXyYr3ucg3FdOrjTa muVpnWHgfmOXA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 10/33] mptcp: add addr parameter for get_addr Date: Wed, 16 Oct 2024 17:12:14 +0800 Message-ID: <862b1207f395a4a45c709eec5e67308e9adad801.1729069854.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 netlink messages are sent both in mptcp_pm_nl_get_addr() and mptcp_userspace_pm_get_addr(), this makes the code somewhat repetitive. This is because the netlink PM and userspace PM use different locks to protect the address entry that needs to be sent via the netlink message. The former uses pernet->lock, and the latter uses msk->pm.lock. The current get_addr() flow looks like this: lock(); entry = get_entry(); send_nlmsg(entry); unlock(); After holding the lock, get the entry from the list, send the entry, and finally release the lock. This patch changes the process by getting the entry while holding the lock, then making a copy of the entry so that the lock can be released. Finally, the copy of the entry is sent without locking: lock(); entry = get_entry(); *copy = *entry; unlock(); send_nlmsg(copy); This way we can reuse this send_nlmsg() code between the netlink PM and userspace PM. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 33 ++++++++++++++++++--------------- net/mptcp/pm_userspace.c | 24 +++++++++++++----------- net/mptcp/protocol.h | 3 ++- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index be9d1aa3377f..5d9e72fbddf3 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1792,13 +1792,14 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } -static int mptcp_pm_nl_get_addr(u8 id, struct genl_info *info) +static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info) { struct pm_nl_pernet *pernet = genl_info_pm_nl(info); struct mptcp_pm_addr_entry *entry; struct sk_buff *msg; + int ret = -EINVAL; void *reply; - int ret; msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) @@ -1814,34 +1815,36 @@ static int mptcp_pm_nl_get_addr(u8 id, struct genl_info *info) spin_lock_bh(&pernet->lock); entry = __lookup_addr_by_id(pernet, id); - if (!entry) { + if (entry) { + *addr = *entry; + ret = 0; + } + spin_unlock_bh(&pernet->lock); + + if (ret) { GENL_SET_ERR_MSG(info, "address not found"); - ret = -EINVAL; - goto unlock_fail; + goto fail; } - ret = mptcp_nl_fill_addr(msg, entry); + ret = mptcp_nl_fill_addr(msg, addr); if (ret) - goto unlock_fail; + goto fail; genlmsg_end(msg, reply); ret = genlmsg_reply(msg, info); - spin_unlock_bh(&pernet->lock); return ret; -unlock_fail: - spin_unlock_bh(&pernet->lock); - fail: nlmsg_free(msg); return ret; } -static int mptcp_pm_get_addr(u8 id, struct genl_info *info) +static int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_get_addr(id, info); - return mptcp_pm_nl_get_addr(id, info); + return mptcp_userspace_pm_get_addr(id, addr, info); + return mptcp_pm_nl_get_addr(id, addr, info); } int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) @@ -1854,7 +1857,7 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) if (ret < 0) return ret; - ret = mptcp_pm_get_addr(addr.addr.id, info); + ret = mptcp_pm_get_addr(addr.addr.id, &addr, info); return ret; } diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 079baceb9ca1..d1f2b592b47c 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -632,7 +632,8 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, return ret; } -int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info) +int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info) { struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; @@ -664,26 +665,27 @@ int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info) lock_sock(sk); spin_lock_bh(&msk->pm.lock); entry = mptcp_userspace_pm_lookup_addr_by_id(msk, id); - if (!entry) { + if (entry) { + *addr = *entry; + ret = 0; + } + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); + + if (ret) { GENL_SET_ERR_MSG(info, "address not found"); - ret = -EINVAL; - goto unlock_fail; + goto fail; } - ret = mptcp_nl_fill_addr(msg, entry); + ret = mptcp_nl_fill_addr(msg, addr); if (ret) - goto unlock_fail; + goto fail; genlmsg_end(msg, reply); ret = genlmsg_reply(msg, info); - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); sock_put(sk); return ret; -unlock_fail: - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); fail: nlmsg_free(msg); out: diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 8ee0617209af..364f121f69c8 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1126,7 +1126,8 @@ bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); -int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info); +int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info); static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflow) { From patchwork Wed Oct 16 09:12:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837976 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 2D616205E0E for ; Wed, 16 Oct 2024 09:13:04 +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=1729069985; cv=none; b=XJZWTZi3SKFDXbwoL64zYtPPvRNY6wDvxkjj9BzJ5z1EhL8qGbYwBpDunylWmwqkzfEzjvNo2yzhRREESnqeT0Se82H/IkzqgVSTEQGjmT0bwhw29tYY2Ji2d1xknMhd0OABeab5ML5qlOt91zmreRUGtWpTKQlSBERbXyfIAuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069985; c=relaxed/simple; bh=g4KgSz4gEF1/26hFv8JtHtal+mo1D1dY6Goi+gEOCwQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iiHo5PeGIKZ4MY0ZhZCkKD4g+WX9MXPHHYF9FldBIKRamHpm8WzYM8gtu+mqE+tYWIHhC+2jpf+knEfUSlq2q5IHHTIzyD9IC0amA/IetKMstPDe291d+O/hHVZ4qvMkSJ1op6WonTyNag4PSdpwVIUq1AP4LXFnbyJ7JnX2e0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iasHek68; 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="iasHek68" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76104C4CED6; Wed, 16 Oct 2024 09:13:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069984; bh=g4KgSz4gEF1/26hFv8JtHtal+mo1D1dY6Goi+gEOCwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iasHek68BpLdK/FkRYxwTUPfcVfh4SDpmI8TW/Gk/CUbSHh3xV2EKRTDXw67uZf67 ZkIhOudiSyF7TEaQjxpbCvuOpekScxXNp1i7b39EdtSIprBJb5AhNvQeXRy0NdtqpT eeI4yPbSP2MPp+YLED2TvV/PxDaiQSrYC/PQNWNYTmcb5CakbU678uN3iQdmXgqyBZ JNGGXgxXaXMXJ2XJkbZ43rZqeWIOSPl3lIxovAYVOqESVWJi+SOvWuvAmpaAro8swc lny6BVUmQ0ZjFAoLR0EU7xuZ+d/bVsglACQXwkJLLwTlzoJpMh8FdlK4/0PPkqRsBj FvDt1eVAMXQ0g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 11/33] mptcp: reuse sending nlmsg code in get_addr Date: Wed, 16 Oct 2024 17:12:15 +0800 Message-ID: <02bd1fffd31d586945abbb16f59a0254ee1cb699.1729069854.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 With the previous commit, we can reuse the send_nlmsg() code in get_addr() interfaces between the netlink PM and userspace PM. They only need to implement their own get_addr() interfaces to hold the different locks, get the entry from the different lists, then release the locks. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 58 ++++++++++++++++++++-------------------- net/mptcp/pm_userspace.c | 33 ----------------------- 2 files changed, 29 insertions(+), 62 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 5d9e72fbddf3..173d36f91274 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1797,21 +1797,7 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, { struct pm_nl_pernet *pernet = genl_info_pm_nl(info); struct mptcp_pm_addr_entry *entry; - struct sk_buff *msg; int ret = -EINVAL; - void *reply; - - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); - if (!msg) - return -ENOMEM; - - reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0, - info->genlhdr->cmd); - if (!reply) { - GENL_SET_ERR_MSG(info, "not enough space in Netlink message"); - ret = -EMSGSIZE; - goto fail; - } spin_lock_bh(&pernet->lock); entry = __lookup_addr_by_id(pernet, id); @@ -1821,21 +1807,6 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, } spin_unlock_bh(&pernet->lock); - if (ret) { - GENL_SET_ERR_MSG(info, "address not found"); - goto fail; - } - - ret = mptcp_nl_fill_addr(msg, addr); - if (ret) - goto fail; - - genlmsg_end(msg, reply); - ret = genlmsg_reply(msg, info); - return ret; - -fail: - nlmsg_free(msg); return ret; } @@ -1851,13 +1822,42 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct mptcp_pm_addr_entry addr; + struct sk_buff *msg; + void *reply; int ret; ret = mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) return ret; + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0, + info->genlhdr->cmd); + if (!reply) { + GENL_SET_ERR_MSG(info, "not enough space in Netlink message"); + ret = -EMSGSIZE; + goto fail; + } + ret = mptcp_pm_get_addr(addr.addr.id, &addr, info); + if (ret) { + GENL_SET_ERR_MSG(info, "address not found"); + goto fail; + } + + ret = mptcp_nl_fill_addr(msg, &addr); + if (ret) + goto fail; + + genlmsg_end(msg, reply); + ret = genlmsg_reply(msg, info); + return ret; + +fail: + nlmsg_free(msg); return ret; } diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index d1f2b592b47c..dd2ecc9ee6d5 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -637,10 +637,8 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, { struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; - struct sk_buff *msg; int ret = -EINVAL; struct sock *sk; - void *reply; msk = mptcp_userspace_pm_get_sock(info); if (!msk) @@ -648,20 +646,6 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, sk = (struct sock *)msk; - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); - if (!msg) { - ret = -ENOMEM; - goto out; - } - - reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0, - info->genlhdr->cmd); - if (!reply) { - GENL_SET_ERR_MSG(info, "not enough space in Netlink message"); - ret = -EMSGSIZE; - goto fail; - } - lock_sock(sk); spin_lock_bh(&msk->pm.lock); entry = mptcp_userspace_pm_lookup_addr_by_id(msk, id); @@ -672,23 +656,6 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, spin_unlock_bh(&msk->pm.lock); release_sock(sk); - if (ret) { - GENL_SET_ERR_MSG(info, "address not found"); - goto fail; - } - - ret = mptcp_nl_fill_addr(msg, addr); - if (ret) - goto fail; - - genlmsg_end(msg, reply); - ret = genlmsg_reply(msg, info); - sock_put(sk); - return ret; - -fail: - nlmsg_free(msg); -out: sock_put(sk); return ret; } From patchwork Wed Oct 16 09:12:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837977 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 A59E1206067 for ; Wed, 16 Oct 2024 09:13:06 +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=1729069986; cv=none; b=fRrbGHU+1gXNIhJVCMEOm5NmiOlilg7qv5VrrfhMF4mU3pkVwAqQ2Ff8aYckDUP4CPjT55jkKTUFYQT7kM1z6wSe5f3SyUYso+m4CeQd8myRjQkjwsHybwY2hdKdzFuYsx6qWL4hjH8Q3DTF06B0mOgq6MqlBEM/z+ER7yEdhIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069986; c=relaxed/simple; bh=vN77zTOlh1ttnBeT0h4+rM7J8prBWaD83n+ewBsv2Bs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qygnA0Wc7tg6C5Kswu0X4ZS9IRZX1C1XRvc0l2upGX0G+jS6ckMeBDKWgURDhbTH4+YZefZPxvf5SPG7aC4fgF5iTxzMuKsWFeKBaeF/hVrPKce7gpMAcpimW4c5OZ2XxiUiI+fnDuVcruHpRRbdHdKe/DvzXaS8MYXuCMSzR24= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p/xyVmGY; 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="p/xyVmGY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F4B6C4CED2; Wed, 16 Oct 2024 09:13:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069986; bh=vN77zTOlh1ttnBeT0h4+rM7J8prBWaD83n+ewBsv2Bs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p/xyVmGYp3uW32JemGYNvZ3Q7Fsrz6a25ReZkM1A3XOXc1WWXGOLeBbjltpqeW2N0 VYM0nhH+FEAn/ELQpt87KL54tRwkbMF6p7CiibK8UdupscoBVYewSYmfHp9Xskoy00 LlV39yl65iLegGNKHmmSKkLGpAZTMv6WMDxTcCJrUHRoGxhyK5TVUrCu7+o1eopL2i u6Uvvl17tyRtiIbXlD7ir+F+F3+/zJhhwvafnG/nTVaCaoRsiXKLiw6+9vFpRSl/L3 kCNX+UZWu/T7ZGuyd144kTCBhyyk8pkB+0ysnjkoVG53Dm3vu0HFfXMHltUkIG2G9E xHqZml6r4ABBA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 12/33] mptcp: change info of get_addr as const Date: Wed, 16 Oct 2024 17:12:16 +0800 Message-ID: <32e740721a1b1d12293334783764258f2401ff40.1729069854.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 get_addr() interfeces will be invoked by dump_addr(), which using const parameters "info", so this patch changes "info" parameters of get_addr() as const too. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 9 ++++++--- net/mptcp/pm_userspace.c | 2 +- net/mptcp/protocol.h | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 173d36f91274..e71e7e55b046 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1793,12 +1793,15 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, } static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info) + const struct genl_info *info) { - struct pm_nl_pernet *pernet = genl_info_pm_nl(info); + struct net *net = genl_info_net(info); struct mptcp_pm_addr_entry *entry; + struct pm_nl_pernet *pernet; int ret = -EINVAL; + pernet = pm_nl_get_pernet(net); + spin_lock_bh(&pernet->lock); entry = __lookup_addr_by_id(pernet, id); if (entry) { @@ -1811,7 +1814,7 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, } static int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info) + const struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) return mptcp_userspace_pm_get_addr(id, addr, info); diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index dd2ecc9ee6d5..c10794154187 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -633,7 +633,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, } int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info) + const struct genl_info *info) { struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 364f121f69c8..f8e79f477609 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1127,7 +1127,7 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info); + const struct genl_info *info); static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflow) { From patchwork Wed Oct 16 09:12:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837978 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 BE55F205149 for ; Wed, 16 Oct 2024 09:13:08 +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=1729069988; cv=none; b=Mu0Tnv1L5LymzKBHTcbIpRM0n0Gn+gY38V3caSIiA2IJM3PNklzv7VjrqDOfsCUF9iVUMNG5GbPqiBRm7bxOw45Xn7Yp0dkErwMNzNbKr4HkA5d1YvwlQy3aDFoEwIR8pwULYd8iAH1AvPPjDNpdnsbPPPJw1+F049NJRQwy2tI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069988; c=relaxed/simple; bh=ACp+xj82CHFiPd36sOe4ewgFGB/Qz5dBrTvFrGsA2XM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=di4HSG4MsVIH1dfTZnzvR5XsO+h/ApVSCmeu7bHu/y/IM5PCb2t+Eh7rRHt8kBVK4GpHTvhPEsQODSO/N7t5rNMkldFZoq5hNrUT/HVO1qDjxL/eYHjOtOcxKCV6N9J5lZymWl1JW9ylhPsM4UL0I5rU9P2hdqBeWfGRU1O3+gk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cCgP358o; 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="cCgP358o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EBA7C4CECE; Wed, 16 Oct 2024 09:13:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069988; bh=ACp+xj82CHFiPd36sOe4ewgFGB/Qz5dBrTvFrGsA2XM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cCgP358o8FT2G2/MteG87WejoSX2227FJ6b1sBKgxdCrufAeiScqUqtj9q3jiU8Ob Z7ZZ/zytgERd7UQommxzIP6SfN/amv0wi5qouXmDCETS2O0QOgYse5HwFDVHdt6Xmm RoSTHTkQJMkTxPKFxkuQwu/+DOnSKk9xFposHmJ1Qcqq51R+5zYjTpH6/QOyIYlxZ+ IUHqD2ofV8qCmBv5Dzr/uqFBaSiPnfBZkc8GZP0o7UJA43E8ofstkJfCIZXM9Cve1U UqH7tFuW9mrgPt7i+qVvDcvO7OL0ceDgOt1TASePpzzUsbYhthFMKrSp4UD9FnGRej HD8b+HFPUk95A== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 13/33] mptcp: add struct mptcp_id_bitmap Date: Wed, 16 Oct 2024 17:12:17 +0800 Message-ID: <2f13a49c56f06882c5f245585b202825b7db5201.1729069854.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 A new struct mptcp_id_bitmap is defined to unify all bitmap type of address IDs for both in-kernel PM and userspace PM. This type can be used to easily refactor dump_addr() interface of the path managers to accept an mptcp_id_bitmap type parameter. It also allows this parameter of dump_addr() can be modified by BPF program when implementing this interface of a BFP path manager. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 2 +- net/mptcp/pm_netlink.c | 42 ++++++++++++++++++++-------------------- net/mptcp/pm_userspace.c | 14 ++++++-------- net/mptcp/protocol.h | 6 +++++- 4 files changed, 33 insertions(+), 31 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index f5725c00eb70..b6e6859903ef 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -512,7 +512,7 @@ void mptcp_pm_data_reset(struct mptcp_sock *msk) WRITE_ONCE(pm->addr_signal, 0); WRITE_ONCE(pm->remote_deny_join_id0, false); pm->status = 0; - bitmap_fill(msk->pm.id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + bitmap_fill(msk->pm.id_avail_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); } void mptcp_pm_data_init(struct mptcp_sock *msk) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index e71e7e55b046..75c07db55409 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -37,7 +37,7 @@ struct pm_nl_pernet { unsigned int local_addr_max; unsigned int subflows_max; unsigned int next_id; - DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + struct mptcp_id_bitmap id_bitmap; }; #define MPTCP_PM_ADDR_MAX 8 @@ -161,7 +161,7 @@ select_local_address(const struct pm_nl_pernet *pernet, if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)) continue; - if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap)) + if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap.map)) continue; new_local->addr = entry->addr; @@ -189,7 +189,7 @@ select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock *msk, * can lead to additional addresses not being announced. */ list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) { - if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap)) + if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap.map)) continue; if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) @@ -243,7 +243,7 @@ bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk) struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk); if (msk->pm.subflows == mptcp_pm_get_subflows_max(msk) || - (find_next_and_bit(pernet->id_bitmap, msk->pm.id_avail_bitmap, + (find_next_and_bit(pernet->id_bitmap.map, msk->pm.id_avail_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1, 0) == MPTCP_PM_MAX_ADDR_ID + 1)) { WRITE_ONCE(msk->pm.work_pending, false); return false; @@ -443,15 +443,15 @@ static unsigned int fill_remote_addresses_vec(struct mptcp_sock *msk, msk->pm.subflows++; addrs[i++] = remote; } else { - DECLARE_BITMAP(unavail_id, MPTCP_PM_MAX_ADDR_ID + 1); + struct mptcp_id_bitmap unavail_id; /* Forbid creation of new subflows matching existing * ones, possibly already created by incoming ADD_ADDR */ - bitmap_zero(unavail_id, MPTCP_PM_MAX_ADDR_ID + 1); + bitmap_zero(unavail_id.map, MPTCP_PM_MAX_ADDR_ID + 1); mptcp_for_each_subflow(msk, subflow) if (READ_ONCE(subflow->local_id) == local->id) - __set_bit(subflow->remote_id, unavail_id); + __set_bit(subflow->remote_id, unavail_id.map); mptcp_for_each_subflow(msk, subflow) { ssk = mptcp_subflow_tcp_sock(subflow); @@ -460,7 +460,7 @@ static unsigned int fill_remote_addresses_vec(struct mptcp_sock *msk, if (deny_id0 && !addrs[i].id) continue; - if (test_bit(addrs[i].id, unavail_id)) + if (test_bit(addrs[i].id, unavail_id.map)) continue; if (!mptcp_pm_addr_families_match(sk, local, &addrs[i])) @@ -470,7 +470,7 @@ static unsigned int fill_remote_addresses_vec(struct mptcp_sock *msk, /* forbid creating multiple address towards * this id */ - __set_bit(addrs[i].id, unavail_id); + __set_bit(addrs[i].id, unavail_id.map); msk->pm.subflows++; i++; } @@ -558,7 +558,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) rcu_read_lock(); entry = __lookup_addr(pernet, &mpc_addr); if (entry) { - __clear_bit(entry->addr.id, msk->pm.id_avail_bitmap); + __clear_bit(entry->addr.id, msk->pm.id_avail_bitmap.map); msk->mpc_endpoint_id = entry->addr.id; backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); } @@ -596,7 +596,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) if (!mptcp_pm_alloc_anno_list(msk, &local.addr)) return; - __clear_bit(local.addr.id, msk->pm.id_avail_bitmap); + __clear_bit(local.addr.id, msk->pm.id_avail_bitmap.map); msk->pm.add_addr_signaled++; /* Special case for ID0: set the correct ID */ @@ -625,7 +625,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) fullmesh = !!(local.flags & MPTCP_PM_ADDR_FLAG_FULLMESH); - __clear_bit(local.addr.id, msk->pm.id_avail_bitmap); + __clear_bit(local.addr.id, msk->pm.id_avail_bitmap.map); /* Special case for ID0: set the correct ID */ if (local.addr.id == msk->mpc_endpoint_id) @@ -991,7 +991,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet, ret = -ERANGE; goto out; } - if (test_bit(entry->addr.id, pernet->id_bitmap)) { + if (test_bit(entry->addr.id, pernet->id_bitmap.map)) { ret = -EBUSY; goto out; } @@ -1025,7 +1025,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet, if (!entry->addr.id && needs_id) { find_next: - entry->addr.id = find_next_zero_bit(pernet->id_bitmap, + entry->addr.id = find_next_zero_bit(pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1, pernet->next_id); if (!entry->addr.id && pernet->next_id != 1) { @@ -1037,7 +1037,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet, if (!entry->addr.id && needs_id) goto out; - __set_bit(entry->addr.id, pernet->id_bitmap); + __set_bit(entry->addr.id, pernet->id_bitmap.map); if (entry->addr.id > pernet->next_id) pernet->next_id = entry->addr.id; @@ -1480,7 +1480,7 @@ static bool mptcp_pm_remove_anno_addr(struct mptcp_sock *msk, if (ret || force) { spin_lock_bh(&msk->pm.lock); if (ret) { - __set_bit(addr->id, msk->pm.id_avail_bitmap); + __set_bit(addr->id, msk->pm.id_avail_bitmap.map); msk->pm.add_addr_signaled--; } mptcp_pm_remove_addr(msk, &list); @@ -1492,7 +1492,7 @@ static bool mptcp_pm_remove_anno_addr(struct mptcp_sock *msk, static void __mark_subflow_endp_available(struct mptcp_sock *msk, u8 id) { /* If it was marked as used, and not ID 0, decrement local_addr_used */ - if (!__test_and_set_bit(id ? : msk->mpc_endpoint_id, msk->pm.id_avail_bitmap) && + if (!__test_and_set_bit(id ? : msk->mpc_endpoint_id, msk->pm.id_avail_bitmap.map) && id && !WARN_ON_ONCE(msk->pm.local_addr_used == 0)) msk->pm.local_addr_used--; } @@ -1623,7 +1623,7 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info) pernet->addrs--; list_del_rcu(&entry->list); - __clear_bit(entry->addr.id, pernet->id_bitmap); + __clear_bit(entry->addr.id, pernet->id_bitmap.map); spin_unlock_bh(&pernet->lock); mptcp_nl_remove_subflow_and_signal_addr(sock_net(skb->sk), entry); @@ -1687,7 +1687,7 @@ static void mptcp_pm_flush_addrs_and_subflows(struct mptcp_sock *msk, if (slist.nr) mptcp_pm_nl_rm_subflow_received(msk, &slist); /* Reset counters: maybe some subflows have been removed before */ - bitmap_fill(msk->pm.id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + bitmap_fill(msk->pm.id_avail_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); msk->pm.local_addr_used = 0; spin_unlock_bh(&msk->pm.lock); } @@ -1745,7 +1745,7 @@ int mptcp_pm_nl_flush_addrs_doit(struct sk_buff *skb, struct genl_info *info) list_splice_init(&pernet->local_addr_list, &free_list); __reset_counters(pernet); pernet->next_id = 1; - bitmap_zero(pernet->id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + bitmap_zero(pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); spin_unlock_bh(&pernet->lock); mptcp_nl_flush_addrs_list(sock_net(skb->sk), &free_list); synchronize_rcu(); @@ -1878,7 +1878,7 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, spin_lock_bh(&pernet->lock); for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { - if (test_bit(i, pernet->id_bitmap)) { + if (test_bit(i, pernet->id_bitmap.map)) { entry = __lookup_addr_by_id(pernet, i); if (!entry) break; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index c10794154187..cb4f2a174d0d 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -42,15 +42,15 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *entry, bool needs_id) { - DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); struct mptcp_pm_addr_entry *match = NULL; struct sock *sk = (struct sock *)msk; + struct mptcp_id_bitmap id_bitmap; struct mptcp_pm_addr_entry *e; bool addr_match = false; bool id_match = false; int ret = -EINVAL; - bitmap_zero(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + bitmap_zero(id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); spin_lock_bh(&msk->pm.lock); mptcp_for_each_address(msk, e) { @@ -64,7 +64,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, } else if (addr_match || id_match) { break; } - __set_bit(e->addr.id, id_bitmap); + __set_bit(e->addr.id, id_bitmap.map); } if (!match && !addr_match && !id_match) { @@ -79,7 +79,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, *e = *entry; if (!e->addr.id && needs_id) - e->addr.id = find_next_zero_bit(id_bitmap, + e->addr.id = find_next_zero_bit(id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1, 1); list_add_tail_rcu(&e->list, &msk->pm.userspace_pm_local_addr_list); @@ -586,17 +586,15 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { - struct id_bitmap { - DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1); - } *bitmap; const struct genl_info *info = genl_info_dump(cb); struct mptcp_pm_addr_entry *entry; + struct mptcp_id_bitmap *bitmap; struct mptcp_sock *msk; int ret = -EINVAL; struct sock *sk; void *hdr; - bitmap = (struct id_bitmap *)cb->ctx; + bitmap = (struct mptcp_id_bitmap *)cb->ctx; msk = mptcp_userspace_pm_get_sock(info); if (!msk) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index f8e79f477609..5d050d284930 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -211,6 +211,10 @@ enum mptcp_addr_signal_status { /* max value of mptcp_addr_info.id */ #define MPTCP_PM_MAX_ADDR_ID U8_MAX +struct mptcp_id_bitmap { + DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1); +}; + struct mptcp_pm_data { struct mptcp_addr_info local; struct mptcp_addr_info remote; @@ -231,7 +235,7 @@ struct mptcp_pm_data { u8 pm_type; u8 subflows; u8 status; - DECLARE_BITMAP(id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + struct mptcp_id_bitmap id_avail_bitmap; struct mptcp_rm_list rm_list_tx; struct mptcp_rm_list rm_list_rx; }; From patchwork Wed Oct 16 09:12:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837979 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 CE148205145 for ; Wed, 16 Oct 2024 09:13:10 +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=1729069990; cv=none; b=oyTXLbcBzN1jlfTljvL86NJhkpXgJtZmz2+h5GmihIKlcGBQEV1ZmFcguuPxaPeeJqX5rZhLwXJhjB+MflQw/VXDT+A+HhqFF8e5oDqyu1Wg54LJCKsrR8yKQyHJ34xdrH2I7qfPY+LeLI0V6fcLTfK5PywkMDNsSogfrYaPcpQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069990; c=relaxed/simple; bh=Ph8tZq87IS+7lVLVzP9KA5mELMgiXG30fYoH5AZQIi4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JpDdKexjeCsYKJeCbGdhg4fuE3AsiL/nioMtd0XPwsphhbIM6/aJZj3NPBTDA1BAeB0dNYoweU4Cjs3j42hqsdMwb5hbN17vVv1xAlQyO2SsxxZZ8J4dMWlKr7UdK1AV71Mh+pfJcR+yle12SjIokm4TyR0sUMoXUpZKYrVfaxQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ux4XjVmr; 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="ux4XjVmr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EDBCC4CECE; Wed, 16 Oct 2024 09:13:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069990; bh=Ph8tZq87IS+7lVLVzP9KA5mELMgiXG30fYoH5AZQIi4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ux4XjVmr/K978qfCyimYfsdbST9KmhbIo/Udi/OGbX4Z6CLiR1DNZFfR8m/dYgxtC /+D0jwohh26IIsqrl2BsgKavF5tLLrGr1RSPUhBUWVR+8mkS5TxgfLkv8IQA28rKMS LRr7I6xjk/tAlDnqQhK6HjDvPa2hH+ONyxH/w9uOeKm9XD6eOdO6IGhw9uEJjpEvDm buMe9mY5nMIwLDsjVb+gRC/YpyYL9GXS1/m69/rUUX3KR7g1lc6EUCqN44IIXLwKij HmB8R2LLYbKdEaJKL4C2dzkMxQJkHY/yQ1UbHGXncv6AXMn3aDpnqVqhJDiASsEQNh ZFTuZYWiOHIcA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 14/33] mptcp: refactor dump_addr with id bitmap Date: Wed, 16 Oct 2024 17:12:18 +0800 Message-ID: <017c79b8733dbca0a81621cec202c6817e79f751.1729069854.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 With the help of get_addr(), we can refactor dump_addr() interfaces to reuse send_nlmsg code between the netlink PM and userspace PM. The current dump_addr() flow looks like this: lock(); for_each_entry(entry) send_nlmsg(entry); unlock(); After holding the lock, get every entry by walking the address list, send each one looply, and finally release the lock. This set changes the process by copying the address list to an id bitmap while holding the lock, then release the lock immediately. After that, without locking, walking the copied id bitmap to get every copy of entry by using get_addr(), and send each one looply. This patch is the first part of refactoring dump_addr(). Without changing the position of the locks, the dump process is split into two parts: copying the ID bitmap first, and then traversing the ID bitmap, use lookup_addr_by_id() to get the entry, then send each one through nlmsg: lock(); for_each_entry(entry) set_bit(bitmap); for_each_bit(bitmap) { entry = lookup_addr_by_id(); send_nlmsg(entry); } unlock(); Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 6 ++++- net/mptcp/pm_userspace.c | 54 +++++++++++++++++++++++++++++----------- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 75c07db55409..0f107564fcfd 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1869,16 +1869,20 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, { struct net *net = sock_net(msg->sk); struct mptcp_pm_addr_entry *entry; + struct mptcp_id_bitmap *bitmap; struct pm_nl_pernet *pernet; int id = cb->args[0]; void *hdr; int i; + bitmap = (struct mptcp_id_bitmap *)cb->ctx; pernet = pm_nl_get_pernet(net); spin_lock_bh(&pernet->lock); + if (!id) + bitmap_copy(bitmap->map, pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { - if (test_bit(i, pernet->id_bitmap.map)) { + if (test_bit(i, bitmap->map)) { entry = __lookup_addr_by_id(pernet, i); if (!entry) break; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index cb4f2a174d0d..237383cfd12e 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -583,6 +583,21 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) return ret; } +static int mptcp_userspace_pm_set_bitmap(struct mptcp_sock *msk, + struct mptcp_id_bitmap *bitmap) +{ + struct mptcp_pm_addr_entry *entry; + + mptcp_for_each_address(msk, entry) { + if (test_bit(entry->addr.id, bitmap->map)) + continue; + + __set_bit(entry->addr.id, bitmap->map); + } + + return 0; +} + int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { @@ -590,9 +605,11 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct mptcp_pm_addr_entry *entry; struct mptcp_id_bitmap *bitmap; struct mptcp_sock *msk; + int id = cb->args[0]; int ret = -EINVAL; struct sock *sk; void *hdr; + int i; bitmap = (struct mptcp_id_bitmap *)cb->ctx; @@ -604,24 +621,33 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, lock_sock(sk); spin_lock_bh(&msk->pm.lock); - mptcp_for_each_address(msk, entry) { - if (test_bit(entry->addr.id, bitmap->map)) - continue; + if (!id) + ret = mptcp_userspace_pm_set_bitmap(msk, bitmap); + for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { + if (test_bit(i, bitmap->map)) { + entry = mptcp_userspace_pm_lookup_addr_by_id(msk, i); + if (!entry) + break; + + if (id && entry->addr.id <= id) + continue; - hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, &mptcp_genl_family, - NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); - if (!hdr) - break; + hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, &mptcp_genl_family, + NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); + if (!hdr) + break; - if (mptcp_nl_fill_addr(msg, entry) < 0) { - genlmsg_cancel(msg, hdr); - break; - } + if (mptcp_nl_fill_addr(msg, entry) < 0) { + genlmsg_cancel(msg, hdr); + break; + } - __set_bit(entry->addr.id, bitmap->map); - genlmsg_end(msg, hdr); + id = entry->addr.id; + genlmsg_end(msg, hdr); + } } + cb->args[0] = id; spin_unlock_bh(&msk->pm.lock); release_sock(sk); ret = msg->len; From patchwork Wed Oct 16 09:12:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837980 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 75635205145 for ; Wed, 16 Oct 2024 09:13:12 +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=1729069992; cv=none; b=Ua+xxDrsgPReyovz/hwTl2RF9EHI2BtkUD0A0iMQ7PtcNTww/uYI9apeT867z5D5kxPdCctoFhn8lJuslRMU2lonxHb7B6yqoEEbEUMWthv2t7DTk/ri5kQpoCtAu9AJrHo3DfNke3ZPhVacMTuebUNCtU3E13jRQWhS+NLv+40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069992; c=relaxed/simple; bh=fS25HspfdwV/SIJKYDmGSEbgSzFfNuNX5z7IQvNR6s8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qADu9q5u1wpgeVLXsvy4zLG7TSD0j/7morKswsn6Nl7sWoBkPNtSubRCwmLncB8xiUflOTyeagRcenf4OXQGpj5/U80NOyujBiJ2LUpeg6UM3QkBB3SMj7mX70s0/GsuEgMxrEiqvpvlWRZudRdgxNz9DAJwRFeEd0i4xKm0oDA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jXaTdAzi; 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="jXaTdAzi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28712C4CECF; Wed, 16 Oct 2024 09:13:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069992; bh=fS25HspfdwV/SIJKYDmGSEbgSzFfNuNX5z7IQvNR6s8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jXaTdAzi+a0Phu8pGJvqSvR6wd6Eg4isnY0dUfeaEW+owrcdmsZDvxmzySgJKKcFM X+6pqNFfdBf6+xae23mbAC4LFjNQybWrFfH/YZJFpzljtlX8MmFtMlEMFEVEYLIRzh yAalfjX8i0T1bea5k0fmvo6Ib5A/uHpB/ceSMg54StWCeGKslSUodKXap9oB51vgLR ws8USR+db10fBKycVr6ycNqm5BvU9wmCasfHuLDu/aRQQSdJ9H1AYNW4QMWgbqG338 AMT6kVxQSu2PqEOJZFX0k0xc+/vhTOQlI2hRa7+UAdQCqVrG7Lx+9OS3nrvsYT/YTZ MjlYPCFg75S4g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 15/33] mptcp: refactor dump_addr with get_addr Date: Wed, 16 Oct 2024 17:12:19 +0800 Message-ID: <81ce998b590fab2912dcdffd89d670fa9ee26e6f.1729069854.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 is the second part of refactoring dump_addr(). With the help of get_addr(), only copy the address list to an id bitmap while holding the lock, then release the lock immediately. After that, without locking, walking the copied id bitmap to get every copy of entry by using get_addr(), and send each one looply: lock(); for_each_entry(entry) set_bit(bitmap); unlock(); for_each_bit(bitmap) { copy = get_addr(); send_nlmsg(copy); } Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 20 +++++++++++--------- net/mptcp/pm_userspace.c | 23 ++++++++++++----------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 0f107564fcfd..ce6385d8fdb4 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1867,8 +1867,9 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { + const struct genl_info *info = genl_info_dump(cb); struct net *net = sock_net(msg->sk); - struct mptcp_pm_addr_entry *entry; + struct mptcp_pm_addr_entry entry; struct mptcp_id_bitmap *bitmap; struct pm_nl_pernet *pernet; int id = cb->args[0]; @@ -1878,16 +1879,18 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, bitmap = (struct mptcp_id_bitmap *)cb->ctx; pernet = pm_nl_get_pernet(net); - spin_lock_bh(&pernet->lock); - if (!id) + if (!id) { + spin_lock_bh(&pernet->lock); bitmap_copy(bitmap->map, pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); + spin_unlock_bh(&pernet->lock); + } + for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { if (test_bit(i, bitmap->map)) { - entry = __lookup_addr_by_id(pernet, i); - if (!entry) + if (mptcp_pm_nl_get_addr(i, &entry, info)) break; - if (entry->addr.id <= id) + if (entry.addr.id <= id) continue; hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, @@ -1896,16 +1899,15 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, if (!hdr) break; - if (mptcp_nl_fill_addr(msg, entry) < 0) { + if (mptcp_nl_fill_addr(msg, &entry) < 0) { genlmsg_cancel(msg, hdr); break; } - id = entry->addr.id; + id = entry.addr.id; genlmsg_end(msg, hdr); } } - spin_unlock_bh(&pernet->lock); cb->args[0] = id; return msg->len; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 237383cfd12e..8c7fc1fd1e2b 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -602,7 +602,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { const struct genl_info *info = genl_info_dump(cb); - struct mptcp_pm_addr_entry *entry; + struct mptcp_pm_addr_entry entry; struct mptcp_id_bitmap *bitmap; struct mptcp_sock *msk; int id = cb->args[0]; @@ -619,17 +619,20 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, sk = (struct sock *)msk; - lock_sock(sk); - spin_lock_bh(&msk->pm.lock); - if (!id) + if (!id) { + lock_sock(sk); + spin_lock_bh(&msk->pm.lock); ret = mptcp_userspace_pm_set_bitmap(msk, bitmap); + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); + } + for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { if (test_bit(i, bitmap->map)) { - entry = mptcp_userspace_pm_lookup_addr_by_id(msk, i); - if (!entry) + if (mptcp_userspace_pm_get_addr(i, &entry, info)) break; - if (id && entry->addr.id <= id) + if (id && entry.addr.id <= id) continue; hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, @@ -638,18 +641,16 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, if (!hdr) break; - if (mptcp_nl_fill_addr(msg, entry) < 0) { + if (mptcp_nl_fill_addr(msg, &entry) < 0) { genlmsg_cancel(msg, hdr); break; } - id = entry->addr.id; + id = entry.addr.id; genlmsg_end(msg, hdr); } } cb->args[0] = id; - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); ret = msg->len; sock_put(sk); From patchwork Wed Oct 16 09:12:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837981 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 BBEF120514E for ; Wed, 16 Oct 2024 09:13:14 +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=1729069994; cv=none; b=hCpxgqax0tfufwfTHR8nP1XChIyjY/P2lNcZ1+oeM3RSELoiaGEtIn+vDOosblV5/PpBDfxmUM/MpYGrTw3yQPqdRvzR2qNJoViKaACohm0HEjEtI4+xLn4dIGfMtv4baPBTvTqtm6oCvFTG3IzCBPAXumSkWqHpnZNLBnepVZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069994; c=relaxed/simple; bh=/GqgaJcUqu0tz6qZmEONTuvOkPl7y+qfYB2f2pueq0E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dfDdMcLE8GKhESgX2TTzbhwh4qDLTjc0QVz7hDIIXuwCZDSlt0gj7S6ZH8R8hViMPdbnDFyFnduphcAgocj53k3IUU1FztMDjJqAiI/TK4lb7DqFq3eK1J49QbnxQPU77u6X1YO1IgVjhtA0VuE3+4AMHtlye9sdyFULAvS6bf4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VHFzzKdK; 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="VHFzzKdK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 017B8C4CEC5; Wed, 16 Oct 2024 09:13:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069994; bh=/GqgaJcUqu0tz6qZmEONTuvOkPl7y+qfYB2f2pueq0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VHFzzKdKd6gXZnMbN6TGXlLn5uXq3zugdI3gy6+i4yeDJukH2lSy7oWX08KBjvF82 WQiUu06ULetPXK4V1fLO2S1WLd1y/jiYhcZXQ3BWAfQrzBVCIPOroriztn+nVaXnD4 qURRYpD6Da1SRyzs3n1I83VtnuxoMf+oKYfX/BEmvrOSCYkkp4PfVigw8n7CPwQ7uj QtsuifGjK5lnhf+l9f/5X0SfTFS9RUv57J9iSfpeLqA3wcSa/b6bbaZJedeE+xiQp3 +kwdENRWQ2lhN6GugCOWkrtHRnFDa8bdw2MO5s8kWH4onECR5Mmo0J7jJBqoYcLReJ eiIMu+00BqfuQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 16/33] mptcp: reuse sending nlmsg code in dump_addr Date: Wed, 16 Oct 2024 17:12:20 +0800 Message-ID: <3da78d9b13772018e51dc500febbe145e8c06623.1729069854.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 With the previous commit, we can reuse the send_nlmsg() code in dump_addr interfaces between the netlink PM and userspace PM. They only need to implement their own dump_addr() interfaces to hold the different locks, copy the different address lists to an id bitmap, then release the locks. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 56 +++++++++++++++++++++------------------- net/mptcp/pm_userspace.c | 50 +++++------------------------------ net/mptcp/protocol.h | 4 +-- 3 files changed, 38 insertions(+), 72 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index ce6385d8fdb4..558a7da8d995 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1864,33 +1864,50 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) return ret; } -static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb) +static int mptcp_pm_nl_dump_addr(struct mptcp_id_bitmap *bitmap, + const struct genl_info *info) +{ + struct net *net = genl_info_net(info); + struct pm_nl_pernet *pernet; + + pernet = pm_nl_get_pernet(net); + + spin_lock_bh(&pernet->lock); + bitmap_copy(bitmap->map, pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); + spin_unlock_bh(&pernet->lock); + + return 0; +} + +static int mptcp_pm_dump_addr(struct mptcp_id_bitmap *bitmap, + const struct genl_info *info) +{ + if (info->attrs[MPTCP_PM_ATTR_TOKEN]) + return mptcp_userspace_pm_dump_addr(bitmap, info); + return mptcp_pm_nl_dump_addr(bitmap, info); +} + +int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, + struct netlink_callback *cb) { const struct genl_info *info = genl_info_dump(cb); - struct net *net = sock_net(msg->sk); struct mptcp_pm_addr_entry entry; struct mptcp_id_bitmap *bitmap; - struct pm_nl_pernet *pernet; int id = cb->args[0]; void *hdr; int i; bitmap = (struct mptcp_id_bitmap *)cb->ctx; - pernet = pm_nl_get_pernet(net); - if (!id) { - spin_lock_bh(&pernet->lock); - bitmap_copy(bitmap->map, pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); - spin_unlock_bh(&pernet->lock); - } + if (!id) + mptcp_pm_dump_addr(bitmap, info); for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { if (test_bit(i, bitmap->map)) { - if (mptcp_pm_nl_get_addr(i, &entry, info)) + if (mptcp_pm_get_addr(i, &entry, info)) break; - if (entry.addr.id <= id) + if (id && entry.addr.id <= id) continue; hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, @@ -1913,21 +1930,6 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, return msg->len; } -static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) -{ - const struct genl_info *info = genl_info_dump(cb); - - if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_dump_addr(msg, cb); - return mptcp_pm_nl_dump_addr(msg, cb); -} - -int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, - struct netlink_callback *cb) -{ - return mptcp_pm_dump_addr(msg, cb); -} - static int parse_limit(struct genl_info *info, int id, unsigned int *limit) { struct nlattr *attr = info->attrs[id]; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 8c7fc1fd1e2b..d815bfa57532 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -598,20 +598,12 @@ static int mptcp_userspace_pm_set_bitmap(struct mptcp_sock *msk, return 0; } -int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb) +int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap, + const struct genl_info *info) { - const struct genl_info *info = genl_info_dump(cb); - struct mptcp_pm_addr_entry entry; - struct mptcp_id_bitmap *bitmap; struct mptcp_sock *msk; - int id = cb->args[0]; int ret = -EINVAL; struct sock *sk; - void *hdr; - int i; - - bitmap = (struct mptcp_id_bitmap *)cb->ctx; msk = mptcp_userspace_pm_get_sock(info); if (!msk) @@ -619,39 +611,11 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, sk = (struct sock *)msk; - if (!id) { - lock_sock(sk); - spin_lock_bh(&msk->pm.lock); - ret = mptcp_userspace_pm_set_bitmap(msk, bitmap); - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); - } - - for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { - if (test_bit(i, bitmap->map)) { - if (mptcp_userspace_pm_get_addr(i, &entry, info)) - break; - - if (id && entry.addr.id <= id) - continue; - - hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, &mptcp_genl_family, - NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); - if (!hdr) - break; - - if (mptcp_nl_fill_addr(msg, &entry) < 0) { - genlmsg_cancel(msg, hdr); - break; - } - - id = entry.addr.id; - genlmsg_end(msg, hdr); - } - } - cb->args[0] = id; - ret = msg->len; + lock_sock(sk); + spin_lock_bh(&msk->pm.lock); + ret = mptcp_userspace_pm_set_bitmap(msk, bitmap); + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); sock_put(sk); return ret; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 5d050d284930..9ac39781a681 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1128,8 +1128,8 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_in bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc); bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); -int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb); +int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap, + const struct genl_info *info); int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, const struct genl_info *info); From patchwork Wed Oct 16 09:12:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837982 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 47120205E00 for ; Wed, 16 Oct 2024 09:13:16 +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=1729069996; cv=none; b=MLFsuw6xx2WzqfAchIxrpF275TtxjgqBc6k1EzZ5MDhQIV6XL5SsyoahcygJEwqdOI6IKtEeQ+zQiPfzRSSgUvnazA/otvv4qiD4C7PDHkIc+Ww5DYpxMQaj1ynrXEqvr/rqFgNuV5GdYURIGnXVcfou9je87VFW+e/fO6CX+K4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069996; c=relaxed/simple; bh=Q338E+VwlIkdV2vjVcsMJnGwflObkj/6tW2uxwTY3cE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u0polZp7Acaoc+VV6Ybbu2AH35+7vBIQQo1Ke1/PjRKt1TjheKqy3M6M6FQgQQ/TeVz/mJZ/qs+uLKIbe5bDqhTToBtUgbo8TQv7CFz3QIzSkM4bo6hEc0qZtezuQUMfDgBqtWT4Bg7oTtHVV1/BTCMTzxbo8l2dcC0drTHsMLY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XKUQctGT; 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="XKUQctGT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E84D7C4CEC5; Wed, 16 Oct 2024 09:13:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069996; bh=Q338E+VwlIkdV2vjVcsMJnGwflObkj/6tW2uxwTY3cE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XKUQctGTk1ft+S9bSgr/JvhzpymfkePgzymxp6NAexGed+nMOqqXEm4PLpAiB7xav VyDnVSR0WlGoirqPxpzUyRQTMhpbTzMAsaPnBDnEEiWF/89ofnB+fNkTvLloGjTqyv 5WawLxvEz9Gj65m7t4lL3Ljksb5KVH/Tu79PJHdNEbu0G08oFHaXa0FoBw7ccIlWId sPDz32MH5RRzP7r0XUdSAkWIeKijIigh8WnXSQJaJ9tiBBK9h1clZoYjN8MZtPUqwO 4G7slnY95Mov/SBwZ3ytUculGL2DFAUTcAz6nQ5/fIk/dPsJ3rl0ID+zTGsNOSDQry 9eD7+7l88aR9Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 17/33] mptcp: update local address flags when setting it Date: Wed, 16 Oct 2024 17:12:21 +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 Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index d815bfa57532..ec2ac0f9c8f5 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -543,6 +543,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) struct mptcp_pm_addr_entry rem = { .addr = { .family = AF_UNSPEC }, }; struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; + struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; int ret = -EINVAL; struct sock *sk; @@ -574,6 +575,16 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) if (loc.flags & MPTCP_PM_ADDR_FLAG_BACKUP) bkup = 1; + spin_lock_bh(&msk->pm.lock); + entry = mptcp_userspace_pm_lookup_addr(msk, &loc.addr); + if (entry) { + if (bkup) + entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP; + else + entry->flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP; + } + spin_unlock_bh(&msk->pm.lock); + lock_sock(sk); ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem.addr, bkup); release_sock(sk); From patchwork Wed Oct 16 09:12:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837983 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 17D1218D626 for ; Wed, 16 Oct 2024 09:13:18 +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=1729069998; cv=none; b=jy2sEJ3m88c0aPTguf3jRg18F9jVAGGeCQFwfnzfnC6jLCo84mi7kj9wVNGnmi6LtNjP6FuNq+Z2kU0CyGb+FCQDlvfk64fnQw3TYEwpytRBS1Y9cOoRyZEfo4i9CcM9KXuYQOuXdJIcrJZ7x/4qJujs/QR4bR/ufqoqcsbG2S0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729069998; c=relaxed/simple; bh=yVXLgDK8B4RuUBdGwxzukvD52DNseQh6Tl+65e+njO0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lbmphWPLflOIvDv5KIapbFXvcwJaf9MUKY+9WXCDNqqEbG0OjOBcCp/htoFtHoHyrGXG8muXL2ACHuN+EK5dM2hvu5BmtWR9vFrvON0IBrGMVtRt0Q/mqRmFBX29jCQj1JMIYEzn5OChIzmR+ek1DyM1+iSYo/vONXZUmisuEbE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h3pvDENa; 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="h3pvDENa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1C0FC4CECF; Wed, 16 Oct 2024 09:13:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069998; bh=yVXLgDK8B4RuUBdGwxzukvD52DNseQh6Tl+65e+njO0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h3pvDENanz4mMTj5SkJ7QrU19VTAoWXT53juBIliJH50X2xF5UbkFeHC2taaW0YB+ zcU4GP0oGgRQhb9gvdM+75eKzdL1S7nxrhBJsAvGMsVMNNsUf/bpxO7tykXPunPajW WPXCwjNTOC4U6Ufr89RkaDsibDRL+BX6ZLSIly7DiAvFg60T1MATgVkoF0CAJl6im7 dbv96u+36HPegQBzZl1LQxZZMmqvZT7ZSlhba4I8+i0YqUom74aC5C78ut/Yt+8Hir Ok0+I+M/TdTOLcuFOYHjQ3Rze36SuvK0+C1vb9kgIa/m220gLPRgZ+BNMTdbfaGUvj z2kLhhEeTbOxA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 18/33] mptcp: change rem type of set_flags Date: Wed, 16 Oct 2024 17:12:22 +0800 Message-ID: <133cadea8da99bc6dbb4d1b838c42d1b46a7dd17.1729069854.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 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 the set_flags() interface uses two mptcp_pm_addr_entry type parameters. This patch changes the second one to mptcp_addr_info type and use helper mptcp_pm_parse_addr() to parse it instead of using mptcp_pm_parse_entry(). Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index ec2ac0f9c8f5..b83f4af632b5 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -540,9 +540,9 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) { struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, }; - struct mptcp_pm_addr_entry rem = { .addr = { .family = AF_UNSPEC }, }; struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; + struct mptcp_addr_info rem = { .family = AF_UNSPEC, }; struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; int ret = -EINVAL; @@ -560,13 +560,13 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) goto set_flags_err; if (attr_rem) { - ret = mptcp_pm_parse_entry(attr_rem, info, false, &rem); + ret = mptcp_pm_parse_addr(attr_rem, info, &rem); if (ret < 0) goto set_flags_err; } if (loc.addr.family == AF_UNSPEC || - rem.addr.family == AF_UNSPEC) { + rem.family == AF_UNSPEC) { GENL_SET_ERR_MSG(info, "invalid address families"); ret = -EINVAL; goto set_flags_err; @@ -586,7 +586,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) spin_unlock_bh(&msk->pm.lock); lock_sock(sk); - ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem.addr, bkup); + ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem, bkup); release_sock(sk); set_flags_err: From patchwork Wed Oct 16 09:12:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837984 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 E5B0020514C for ; Wed, 16 Oct 2024 09:13:19 +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=1729070000; cv=none; b=ehWfxNyBLYwQ2xARyvHuRUDX01BwTvCVHf/aEFjxPg/s0LigEr/BUMHi3HymSIdr5uxYuDTr+NRpGHn63mnxlLYZ8j5EZP8KCSE0450n7Ppys1+A1C+rELbbH4yuP5yfkbCHQVGtVPn3p+2Xouhrz/vmOV0WJQI2jdQ+DVxc+mo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729070000; c=relaxed/simple; bh=kfUD30z+wuwB3UVmoWg+8iIHWv3vLqopR3g5/nbKku8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rOxbuLDHqpJWbtL6W1oRrWhvqzLfz581ZbVROOy09lhMKpW5dvXAmIL4bO+SVh08enRz+ouGG3l7CfBwIASpdAwiWR0n7CgvD8QSqRwvSGvtD7xT8+gB9xZYTPSPYQaBrNGJio6fjBGETq+zDWO1nX3Oa3EPBhHVuHFX3X2Yye4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jSuuMw5q; 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="jSuuMw5q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B6CCC4CECE; Wed, 16 Oct 2024 09:13:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729069999; bh=kfUD30z+wuwB3UVmoWg+8iIHWv3vLqopR3g5/nbKku8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jSuuMw5qFol+QYlS2qnMYAHRStpr4YGJsfNxSlf9XkYq95NP0WjTUU+wg6JRDFP+L pAdxMs2FOZe1sNRTR79YSys51Aux5hpDcfJv/+TsrINwEEHFG29CmV0GGq4jWLHGZE goLtyemXz27zE6PK5uKbxLpQvK7QUG+N1BLOPCzUPhNB9rIrwnelAy8TkzQFF3D18g HAIqHGFqkDk84Zqg1RVX3XolsUbc2KCyiaV6dDN8r+HgH2TAvOLaSw/nKxP/EBrCRb hEOOMZgnV8+CZv9ggkw4+z9BH9LzHmKTuxXIPlVbVzHnF00gnBk4z7t2htazHBLH1e bVx46InD9U7sw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 19/33] mptcp: drop skb parameter of set_flags Date: Wed, 16 Oct 2024 17:12:23 +0800 Message-ID: <7785a9908fe2d2c2172f7ab0a6c695d8ad43c61a.1729069854.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 first parameter "skb" in mptcp_pm_nl_set_flags() is only used to obtained the network namespace, which can also be obtained through the second parameters "info" by using genl_info_net() helper. This patch drops these useless parameters "skb" in all three set_flags() interfaces. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 12 ++++++------ net/mptcp/pm_userspace.c | 2 +- net/mptcp/protocol.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 558a7da8d995..0309f7dbd23b 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -2045,13 +2045,13 @@ static int mptcp_nl_set_flags(struct net *net, return ret; } -static int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) +static int mptcp_pm_nl_set_flags(struct genl_info *info) { struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, }; struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP | MPTCP_PM_ADDR_FLAG_FULLMESH; - struct net *net = sock_net(skb->sk); + struct net *net = genl_info_net(info); struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; u8 lookup_by_id = 0; @@ -2099,16 +2099,16 @@ static int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) return 0; } -static int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info) +static int mptcp_pm_set_flags(struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_set_flags(skb, info); - return mptcp_pm_nl_set_flags(skb, info); + return mptcp_userspace_pm_set_flags(info); + return mptcp_pm_nl_set_flags(info); } int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info) { - return mptcp_pm_set_flags(skb, info); + return mptcp_pm_set_flags(info); } static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index b83f4af632b5..4db39bf26cf4 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -537,7 +537,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info return err; } -int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) +int mptcp_userspace_pm_set_flags(struct genl_info *info) { struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, }; struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 9ac39781a681..7fd5a7644a8d 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1038,7 +1038,7 @@ 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); -int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info); +int mptcp_userspace_pm_set_flags(struct genl_info *info); int mptcp_pm_announce_addr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, bool echo); From patchwork Wed Oct 16 09:12:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837985 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 1800B205136 for ; Wed, 16 Oct 2024 09:13:21 +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=1729070002; cv=none; b=qscMUT66Cjn6Mo5PbtGKuwZsKER3watCx+DO7TTr9bwHIfNM0OTneabA95d5cXbIL/zBqqD2PdxBrtiCxzC+bJ9iZhd/3Xs5j4+3jprxsXnqts/XlHNMPf00QrSscrORCdXJBZWWQdzib989Aqfy+bY3tMZ1xX9/zaqTKRlK+Wo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729070002; c=relaxed/simple; bh=0WacToPcH/djLoibQglKigJoj8OqjuikUBlLO9zRQ5I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j5i9mP8A64SbSK24XWsxNpBV5lH32SSyaMmT+p1BJc+9cok+0hGI+yUjylVJexmlKARWCFghcjvKhXVR1li7N1B2EAQyfxVU04HZpUrPJXKxWkC8/rCm/ouPSqEGTAN3G/LsgM2PqDFKBNujaEwspEmebupiUxM/Yj/TJ/FSOgg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eH/DBQSM; 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="eH/DBQSM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7592BC4CEC5; Wed, 16 Oct 2024 09:13:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729070001; bh=0WacToPcH/djLoibQglKigJoj8OqjuikUBlLO9zRQ5I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eH/DBQSMDWliKN/rlfUdAxFaiWuLV8NJVvhmycPILqFw8dOygt0PAergn1cZygzfH Z7T/2+vHcKYJ/tHTrfZ3W5+L8h+lTAgjceLB819Vypi4Cmkw87lgoOsN05v9WvXtaQ ABo1YgrNs8cyXDpxZt7oRhP5vrgAFk3RyYiWx2nWr5s01IK0GXE9rma+fphOnxfnsl rklm1XrUoPysaCd5jJOb+y12axiutqBpNaqgA5dB+5QjSGsY6FxjFBQ84UQCvQNouj ILwqDpaBNEbR5s0/FWeJVWJYnVt7MN/oe7XnwmbbjXvLNJ1lIGtsad+6EsSqhVLreP phsZipzv9mEWA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 20/33] mptcp: add loc and rem for set_flags Date: Wed, 16 Oct 2024 17:12:24 +0800 Message-ID: <386abd0563329d5abd01e0b7dfa9f199e19ed542.1729069854.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 updates the interfaces set_flags to reduce repetitive code, adds two more parameters "loc" and "rem" for them. These addresses are parsed in public helper mptcp_pm_nl_set_flags_doit(), then pass them to mptcp_pm_nl_set_flags() and mptcp_userspace_pm_set_flags(). Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 57 ++++++++++++++++++++++++---------------- net/mptcp/pm_userspace.c | 28 ++++++-------------- net/mptcp/protocol.h | 4 ++- 3 files changed, 46 insertions(+), 43 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 0309f7dbd23b..a0d9e3e7b0f2 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -2045,10 +2045,10 @@ static int mptcp_nl_set_flags(struct net *net, return ret; } -static int mptcp_pm_nl_set_flags(struct genl_info *info) +static int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *loc, + struct mptcp_addr_info *rem, + struct genl_info *info) { - struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, }; - struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP | MPTCP_PM_ADDR_FLAG_FULLMESH; struct net *net = genl_info_net(info); @@ -2056,59 +2056,72 @@ static int mptcp_pm_nl_set_flags(struct genl_info *info) struct pm_nl_pernet *pernet; u8 lookup_by_id = 0; u8 bkup = 0; - int ret; pernet = pm_nl_get_pernet(net); - ret = mptcp_pm_parse_entry(attr, info, false, &addr); - if (ret < 0) - return ret; - - if (addr.addr.family == AF_UNSPEC) { + if (loc->addr.family == AF_UNSPEC) { lookup_by_id = 1; - if (!addr.addr.id) { + if (!loc->addr.id) { GENL_SET_ERR_MSG(info, "missing required inputs"); return -EOPNOTSUPP; } } - if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP) + if (loc->flags & MPTCP_PM_ADDR_FLAG_BACKUP) bkup = 1; spin_lock_bh(&pernet->lock); - entry = lookup_by_id ? __lookup_addr_by_id(pernet, addr.addr.id) : - __lookup_addr(pernet, &addr.addr); + entry = lookup_by_id ? __lookup_addr_by_id(pernet, loc->addr.id) : + __lookup_addr(pernet, &loc->addr); if (!entry) { spin_unlock_bh(&pernet->lock); GENL_SET_ERR_MSG(info, "address not found"); return -EINVAL; } - if ((addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) && + if ((loc->flags & MPTCP_PM_ADDR_FLAG_FULLMESH) && (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) { spin_unlock_bh(&pernet->lock); GENL_SET_ERR_MSG(info, "invalid addr flags"); return -EINVAL; } - changed = (addr.flags ^ entry->flags) & mask; - entry->flags = (entry->flags & ~mask) | (addr.flags & mask); - addr = *entry; + changed = (loc->flags ^ entry->flags) & mask; + entry->flags = (entry->flags & ~mask) | (loc->flags & mask); + *loc = *entry; spin_unlock_bh(&pernet->lock); - mptcp_nl_set_flags(net, &addr.addr, bkup, changed); + mptcp_nl_set_flags(net, &loc->addr, bkup, changed); return 0; } -static int mptcp_pm_set_flags(struct genl_info *info) +static int mptcp_pm_set_flags(struct mptcp_pm_addr_entry *loc, + struct mptcp_addr_info *rem, + struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_set_flags(info); - return mptcp_pm_nl_set_flags(info); + return mptcp_userspace_pm_set_flags(loc, rem, info); + return mptcp_pm_nl_set_flags(loc, rem, info); } int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info) { - return mptcp_pm_set_flags(info); + struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, }; + struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; + struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; + struct mptcp_addr_info rem = { .family = AF_UNSPEC, }; + int ret; + + ret = mptcp_pm_parse_entry(attr, info, false, &loc); + if (ret < 0) + return ret; + + if (attr_rem) { + ret = mptcp_pm_parse_addr(attr_rem, info, &rem); + if (ret < 0) + return ret; + } + + return mptcp_pm_set_flags(&loc, &rem, info); } static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 4db39bf26cf4..aa4a5d110376 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -537,12 +537,10 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info return err; } -int mptcp_userspace_pm_set_flags(struct genl_info *info) +int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc, + struct mptcp_addr_info *rem, + struct genl_info *info) { - struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, }; - struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; - struct mptcp_addr_info rem = { .family = AF_UNSPEC, }; struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; int ret = -EINVAL; @@ -555,28 +553,18 @@ int mptcp_userspace_pm_set_flags(struct genl_info *info) sk = (struct sock *)msk; - ret = mptcp_pm_parse_entry(attr, info, false, &loc); - if (ret < 0) - goto set_flags_err; - - if (attr_rem) { - ret = mptcp_pm_parse_addr(attr_rem, info, &rem); - if (ret < 0) - goto set_flags_err; - } - - if (loc.addr.family == AF_UNSPEC || - rem.family == AF_UNSPEC) { + if (loc->addr.family == AF_UNSPEC || + rem->family == AF_UNSPEC) { GENL_SET_ERR_MSG(info, "invalid address families"); ret = -EINVAL; goto set_flags_err; } - if (loc.flags & MPTCP_PM_ADDR_FLAG_BACKUP) + if (loc->flags & MPTCP_PM_ADDR_FLAG_BACKUP) bkup = 1; spin_lock_bh(&msk->pm.lock); - entry = mptcp_userspace_pm_lookup_addr(msk, &loc.addr); + entry = mptcp_userspace_pm_lookup_addr(msk, &loc->addr); if (entry) { if (bkup) entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP; @@ -586,7 +574,7 @@ int mptcp_userspace_pm_set_flags(struct genl_info *info) spin_unlock_bh(&msk->pm.lock); lock_sock(sk); - ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem, bkup); + ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc->addr, rem, bkup); release_sock(sk); set_flags_err: diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 7fd5a7644a8d..07e7baec7cbe 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1038,7 +1038,9 @@ 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); -int mptcp_userspace_pm_set_flags(struct genl_info *info); +int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc, + struct mptcp_addr_info *rem, + struct genl_info *info); int mptcp_pm_announce_addr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, bool echo); From patchwork Wed Oct 16 09:12:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837986 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 82761204F6F for ; Wed, 16 Oct 2024 09:13:23 +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=1729070003; cv=none; b=i4Vf2WAs+OpA01iKZ3TGHRkZ48FIlp5DWLqOuGP1JR9Wt6LB1Po9SeatEkwpuxjYZiZ12yvRQZ2cEWaqA1cVCJxSHdsuKDT3DSpFxS3/06ePpM4Cp/wLDsYUe7kU6UQ1QhULydmlLRb/T+7fg80X/nEERahcCoMi3jU6CBrtRhw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729070003; c=relaxed/simple; bh=rdK9WGm18K95FHxDaEhCCUPoQa+WcA/UQjfXIuHF8Do=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=keAeeQmUsaSGfUn+O7yCbnW/wQVrPJ50hDTfHF8Iq2ceKHnMaYrwa7yAewetPVg1aW/l3Y414C/qe7PiTRv4b4iIYaOF1uj1zUMZ7n1HhACQwaCAL2D9vAP9/1q6kSJdKl+hIHIHBhDUlBXKmDdPJMg5L2vN1cUDRSa081w8uaM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fmEE5rlF; 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="fmEE5rlF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A8FDC4CEC5; Wed, 16 Oct 2024 09:13:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729070003; bh=rdK9WGm18K95FHxDaEhCCUPoQa+WcA/UQjfXIuHF8Do=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fmEE5rlFcFXDzu352sCJDP9w8qIEsuY931KWDBBRHaqv9rZNkawvEzhvTLGuAmDYT vW0SMLNx4OQeEnfF1hvxbcWdyX9kRTktv2YWjor2pw7kAnLUlDGQ6pKUTWsQPzLa+q pH1jWfILUxPgouuikdFObDnMgurNIhi+Py3ZJ1qGAYRbVtLBzldU/rh2AvQ7bU18Jw 7k3wCC0D8qkEzivaMiDpsG2yIGz5OzoMvwkj8XU8oYDXobHinuW5oifzqKVEDlsr5Q JPBH3Y/hMze0pNMRx6Mg2j6Y16D4rEsXo+C7BFo6Bc49hIezCkJt6CyT18anwLeBah RN0NTARbbvFQg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 21/33] mptcp: update address type of get_local_id Date: Wed, 16 Oct 2024 17:12:25 +0800 Message-ID: <291a467908a1aff6ccae62f4939947017af11e94.1729069854.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 following code in mptcp_userspace_pm_get_local_id() that assigns "skc" to "new_entry" is not allowed in BPF if we use the same code to implement the get_local_id() interface of a BFP path manager: memset(&new_entry, 0, sizeof(struct mptcp_pm_addr_entry)); new_entry.addr = *skc; new_entry.addr.id = 0; new_entry.flags = MPTCP_PM_ADDR_FLAG_IMPLICIT; To solve the issue, this patch moves this assignment to "new_entry" forward to mptcp_pm_get_local_id(), and then passing "new_entry" as a parameter to both mptcp_pm_nl_get_local_id() and mptcp_userspace_pm_get_local_id(). Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 10 ++++++++-- net/mptcp/pm_netlink.c | 11 +++-------- net/mptcp/pm_userspace.c | 17 ++++++----------- net/mptcp/protocol.h | 4 ++-- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index b6e6859903ef..d28e844eba2d 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -404,6 +404,7 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) { struct mptcp_addr_info skc_local; struct mptcp_addr_info msk_local; + struct mptcp_pm_addr_entry local; if (WARN_ON_ONCE(!msk)) return -1; @@ -416,9 +417,14 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) if (mptcp_addresses_equal(&msk_local, &skc_local, false)) return 0; + memset(&local, 0, sizeof(struct mptcp_pm_addr_entry)); + local.addr = skc_local; + local.addr.id = 0; + local.flags = MPTCP_PM_ADDR_FLAG_IMPLICIT; + if (mptcp_pm_is_userspace(msk)) - return mptcp_userspace_pm_get_local_id(msk, &skc_local); - return mptcp_pm_nl_get_local_id(msk, &skc_local); + return mptcp_userspace_pm_get_local_id(msk, &local); + return mptcp_pm_nl_get_local_id(msk, &local); } bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index a0d9e3e7b0f2..8ef7faaf9c4a 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1137,7 +1137,7 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, return err; } -int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc) +int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local) { struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; @@ -1146,7 +1146,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc pernet = pm_nl_get_pernet_from_msk(msk); rcu_read_lock(); - entry = __lookup_addr(pernet, skc); + entry = __lookup_addr(pernet, &local->addr); if (entry) ret = entry->addr.id; rcu_read_unlock(); @@ -1158,12 +1158,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc if (!entry) return -ENOMEM; - entry->addr = *skc; - entry->addr.id = 0; - entry->addr.port = 0; - entry->ifindex = 0; - entry->flags = MPTCP_PM_ADDR_FLAG_IMPLICIT; - entry->lsk = NULL; + *entry = *local; ret = mptcp_pm_nl_append_new_local_addr(pernet, entry, true); if (ret < 0) kfree(entry); diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index aa4a5d110376..c749f5dccdf9 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -131,27 +131,22 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *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 *local) { - struct mptcp_pm_addr_entry *entry = NULL, new_entry; + struct mptcp_pm_addr_entry *entry = NULL; __be16 msk_sport = ((struct inet_sock *) inet_sk((struct sock *)msk))->inet_sport; spin_lock_bh(&msk->pm.lock); - entry = mptcp_userspace_pm_lookup_addr(msk, skc); + entry = mptcp_userspace_pm_lookup_addr(msk, &local->addr); spin_unlock_bh(&msk->pm.lock); if (entry) return entry->addr.id; - memset(&new_entry, 0, sizeof(struct mptcp_pm_addr_entry)); - new_entry.addr = *skc; - new_entry.addr.id = 0; - new_entry.flags = MPTCP_PM_ADDR_FLAG_IMPLICIT; - - if (new_entry.addr.port == msk_sport) - new_entry.addr.port = 0; + if (local->addr.port == msk_sport) + local->addr.port = 0; - return mptcp_userspace_pm_append_new_local_addr(msk, &new_entry, true); + return mptcp_userspace_pm_append_new_local_addr(msk, local, true); } bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 07e7baec7cbe..0ae9eef173ea 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1125,8 +1125,8 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, const struct sk_buff *skb, bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining, struct mptcp_rm_list *rm_list); int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc); -int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc); -int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc); +int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local); +int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local); bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc); bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); From patchwork Wed Oct 16 09:12:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837987 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 1DF7B205158 for ; Wed, 16 Oct 2024 09:13:25 +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=1729070005; cv=none; b=J3UrWbqAYuC1UOzw8sI0a6NQr8EO0iYGpBQmOCUXFpJnR72JifpFPk8wzEQ8LuvKbrCivJ4Jx/VTUBlROcqvmKybJ/Hv5YBR/97lCtAYBCSA+H6H3uB6A9VVHqn7okKsBsLz92qn5Z1G5JNmXEvRE30OBfY16oyRgLjix4wu66o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729070005; c=relaxed/simple; bh=AM9SIRM6WggImMgxDMfZRW+hJBiC/supZILv4eH611U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FRS+P9dDVguEQ6hRnZqDPwomL/XfI5FsCqKY0DZjriMPZ2bfZyTRpR4jdwyAhmb/fOujcoAfqZ+bBUpuf3IaxleLWmQ/e4PvVASzqiOL4ZekvDAXF0ykV35CpfXaOdo2JHcIMPzvp45sCGAx0orICskeLtCjZeG4vrhHtYdT9Yk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tZUclAUh; 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="tZUclAUh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBF14C4CEC5; Wed, 16 Oct 2024 09:13:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729070004; bh=AM9SIRM6WggImMgxDMfZRW+hJBiC/supZILv4eH611U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tZUclAUh16bbjTCtSzcVyiKtC45qv75NwUCIFacC8+zlbNOU3xUna5apGwkCOKeuc kOG0Wytf+XiYTC7CfeevIiKE9jWmfqiGxju9QFp9c6jaql0hlj9yWGQyPG+czZMMRn fT83MQOWuVrfMRRiwCP6ju1j9nCce4Pc2KOkds91Cte31YvaIeEjYgVMpYCahMC4XT Vn5Z/GC5RJMKrtCsnlNvtHh3zCLMfbOoRu9d22BBw1mmdYPA1bujvVYKIwdUpJaNXD cQnAYdR12j/T/FIzPPPTUi7m714q5/aD79FpAk7hETV/+DDss548mzXUZfI7kvblK/ QB5xzzq6cZCeA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 22/33] mptcp: change is_backup interfaces as get_flags Date: Wed, 16 Oct 2024 17:12:26 +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 The is_backup() interface of path manager is not very common. A more common approach is to add a get_flags() interface to obtain the flags value of a given address. Then is_backup() can be implemented through get_flags() by test whether backup flag is set in the flags value. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 7 +++++-- net/mptcp/pm_netlink.c | 8 ++++---- net/mptcp/pm_userspace.c | 10 +++++----- net/mptcp/protocol.h | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index d28e844eba2d..c2229e46de1a 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -430,13 +430,16 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc) { struct mptcp_addr_info skc_local; + u8 flags; mptcp_local_address((struct sock_common *)skc, &skc_local); if (mptcp_pm_is_userspace(msk)) - return mptcp_userspace_pm_is_backup(msk, &skc_local); + flags = mptcp_userspace_pm_get_flags(msk, &skc_local); + else + flags = mptcp_pm_nl_get_flags(msk, &skc_local); - return mptcp_pm_nl_is_backup(msk, &skc_local); + return !!(flags & MPTCP_PM_ADDR_FLAG_BACKUP); } void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 8ef7faaf9c4a..3029b4e3c1f7 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1166,19 +1166,19 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entry return ret; } -bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc) +u8 mptcp_pm_nl_get_flags(struct mptcp_sock *msk, struct mptcp_addr_info *skc) { struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk); struct mptcp_pm_addr_entry *entry; - bool backup = false; + u8 flags = 0; rcu_read_lock(); entry = __lookup_addr(pernet, skc); if (entry) - backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); + flags = entry->flags; rcu_read_unlock(); - return backup; + return flags; } #define MPTCP_PM_CMD_GRP_OFFSET 0 diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index c749f5dccdf9..0012b1965421 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -149,19 +149,19 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, return mptcp_userspace_pm_append_new_local_addr(msk, local, true); } -bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, - struct mptcp_addr_info *skc) +u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, + struct mptcp_addr_info *skc) { struct mptcp_pm_addr_entry *entry; - bool backup = false; + u8 flags = 0; spin_lock_bh(&msk->pm.lock); entry = mptcp_userspace_pm_lookup_addr(msk, skc); if (entry) - backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); + flags = entry->flags; spin_unlock_bh(&msk->pm.lock); - return backup; + return flags; } static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *info) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 0ae9eef173ea..314f20a436b1 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1128,8 +1128,8 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc); int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local); int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local); bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc); -bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); -bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); +u8 mptcp_pm_nl_get_flags(struct mptcp_sock *msk, struct mptcp_addr_info *skc); +u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, struct mptcp_addr_info *skc); int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap, const struct genl_info *info); int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, From patchwork Wed Oct 16 09:12:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837988 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 C4135205E00 for ; Wed, 16 Oct 2024 09:13:26 +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=1729070006; cv=none; b=fiu8FTraKhKzi6mCzY8iUfJ7JrwFXn4F/5KzidaQDvbun/4+Iw9En66xjk94sqHvEa235rtik1AxIsImRNzpsyHntQKOUGYMS05dNs/t2pFjyMC73t1bWG/uI3Ui28oReA7Rrywgyxw8ENIyLayXhgOULlrtxbsimWtnD+uwh2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729070006; c=relaxed/simple; bh=gsFr4QHcWTGOUKnHBxjmC7ex3RoNl2UxYGe3yAbAWCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E4eA8iwrMx4gjI2wrSyyCTYJfMLbFrlihHpLT9QE5fEKKbuU9oRh9LB7U/SdbgwGWep/H/unUJUeTxqCMHn/d+8dL9gIVmABm15AGsuPIwGoCKYo5oiRMC/br8X/x7omytr28VKLHD6WAV3SurrAgMDrfK0MjlrNmHjgnShdb9g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X4Ri2FFh; 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="X4Ri2FFh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94448C4CECF; Wed, 16 Oct 2024 09:13:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729070006; bh=gsFr4QHcWTGOUKnHBxjmC7ex3RoNl2UxYGe3yAbAWCg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X4Ri2FFh4LzL9963+ZDOqSbC9kfCiAYTD2BAGHgkNysSMvynS5HCCm/iC88kqb7GM guc8Ao0daxAh0ylG59QgAQnU3NQXfNiL/Q7tuxloSnRkyx69wg0wuuMf0sCUbqp51K Fw7R2ECtfRrw+3wKJyeX3XZn/X+oFw4GRDCDGh7n8gbh1XOc40u2Yph6Yi+Zo8Q/jI pyDYWhH4Tn/UElqG9qFO/cCPKRWITb1/0vifKH9rMiVgjVDG92svOr/08/lF5jt+9d gnbN164FwZLQYDVGcZ6LgrGvxI7yHkgqh4y6F9WqSXBdXFbRc9geKlYG/rXX6K2Rj7 vQnSMUtVyqv7g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 23/33] mptcp: drop struct mptcp_pm_local Date: Wed, 16 Oct 2024 17:12:27 +0800 Message-ID: <82ee6fff2bffda751e680b836dc1d58220bc6158.1729069854.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 following code in mptcp_pm_nl_subflow_create_doit() that assigns struct mptcp_pm_addr_entry "entry" to the local struct mptcp_pm_local variable "local" is not allowed in BPF if we use the same code to implement the subflow_create() interface of a BFP path manager: struct mptcp_pm_local local; local.addr = entry.addr; local.flags = entry.flags; local.ifindex = entry.ifindex; We should avoid this type of assignment from struct mptcp_pm_addr_entry to struct mptcp_pm_local. In fact, there is no need to add a dedicated address entry type for local address entry. All its fields are the same as struct mptcp_pm_addr_entry, except that it lacks a "lsk" for the listening socket. So we can use struct mptcp_pm_addr_entry directly. This makes the path manager code simpler. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 22 ++++++++-------------- net/mptcp/pm_userspace.c | 7 +------ net/mptcp/protocol.h | 8 +------- net/mptcp/subflow.c | 2 +- 4 files changed, 11 insertions(+), 28 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 3029b4e3c1f7..8f91fa2c398b 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -149,7 +149,7 @@ static bool lookup_subflow_by_daddr(const struct list_head *list, static bool select_local_address(const struct pm_nl_pernet *pernet, const struct mptcp_sock *msk, - struct mptcp_pm_local *new_local) + struct mptcp_pm_addr_entry *new_local) { struct mptcp_pm_addr_entry *entry; bool found = false; @@ -164,9 +164,7 @@ select_local_address(const struct pm_nl_pernet *pernet, if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap.map)) continue; - new_local->addr = entry->addr; - new_local->flags = entry->flags; - new_local->ifindex = entry->ifindex; + *new_local = *entry; found = true; break; } @@ -177,7 +175,7 @@ select_local_address(const struct pm_nl_pernet *pernet, static bool select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock *msk, - struct mptcp_pm_local *new_local) + struct mptcp_pm_addr_entry *new_local) { struct mptcp_pm_addr_entry *entry; bool found = false; @@ -195,9 +193,7 @@ select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock *msk, if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) continue; - new_local->addr = entry->addr; - new_local->flags = entry->flags; - new_local->ifindex = entry->ifindex; + *new_local = *entry; found = true; break; } @@ -534,11 +530,11 @@ __lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info) static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) { struct sock *sk = (struct sock *)msk; + struct mptcp_pm_addr_entry local; unsigned int add_addr_signal_max; bool signal_and_subflow = false; unsigned int local_addr_max; struct pm_nl_pernet *pernet; - struct mptcp_pm_local local; unsigned int subflows_max; pernet = pm_nl_get_pernet(sock_net(sk)); @@ -660,7 +656,7 @@ static void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk) */ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, struct mptcp_addr_info *remote, - struct mptcp_pm_local *locals) + struct mptcp_pm_addr_entry *locals) { struct sock *sk = (struct sock *)msk; struct mptcp_pm_addr_entry *entry; @@ -683,9 +679,7 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, continue; if (msk->pm.subflows < subflows_max) { - locals[i].addr = entry->addr; - locals[i].flags = entry->flags; - locals[i].ifindex = entry->ifindex; + locals[i] = *entry; /* Special case for ID0: set the correct ID */ if (mptcp_addresses_equal(&locals[i].addr, &mpc_addr, locals[i].addr.port)) @@ -721,7 +715,7 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) { - struct mptcp_pm_local locals[MPTCP_PM_ADDR_MAX]; + struct mptcp_pm_addr_entry locals[MPTCP_PM_ADDR_MAX]; struct sock *sk = (struct sock *)msk; unsigned int add_addr_accept_max; struct mptcp_addr_info remote; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 0012b1965421..c1bc668cce1e 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -339,7 +339,6 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry entry = { 0 }; struct mptcp_addr_info addr_r; - struct mptcp_pm_local local; struct mptcp_sock *msk; int err = -EINVAL; struct sock *sk; @@ -386,12 +385,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) goto create_err; } - local.addr = entry.addr; - local.flags = entry.flags; - local.ifindex = entry.ifindex; - lock_sock(sk); - err = __mptcp_subflow_connect(sk, &local, &addr_r); + err = __mptcp_subflow_connect(sk, &entry, &addr_r); release_sock(sk); spin_lock_bh(&msk->pm.lock); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 314f20a436b1..038b50c8e211 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -240,12 +240,6 @@ struct mptcp_pm_data { struct mptcp_rm_list rm_list_rx; }; -struct mptcp_pm_local { - struct mptcp_addr_info addr; - u8 flags; - int ifindex; -}; - struct mptcp_pm_addr_entry { struct list_head list; struct mptcp_addr_info addr; @@ -743,7 +737,7 @@ bool mptcp_addresses_equal(const struct mptcp_addr_info *a, void mptcp_local_address(const struct sock_common *skc, struct mptcp_addr_info *addr); /* called with sk socket lock held */ -int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_local *local, +int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_addr_entry *local, const struct mptcp_addr_info *remote); int mptcp_subflow_create_socket(struct sock *sk, unsigned short family, struct socket **new_sock); diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 07352b15f145..2ae8f467abc1 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -1586,7 +1586,7 @@ void mptcp_info2sockaddr(const struct mptcp_addr_info *info, #endif } -int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_local *local, +int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_addr_entry *local, const struct mptcp_addr_info *remote) { struct mptcp_sock *msk = mptcp_sk(sk); From patchwork Wed Oct 16 09:12:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837989 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 EB863204F6F for ; Wed, 16 Oct 2024 09:13:28 +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=1729070009; cv=none; b=luNb9kLPnN+rlKygR91fZ7u9KDDn2joAcZqig0/4yZJMRAvdUN2/raEV0O/aF89YaU6d7o/ScYDpAdHXnJVq3V35rLhdwTIGgqu4USBQmbNaITC27Le+D0p4DjDRxzrEkcZYqQjpvtEUec/X1f/FBhpbu6Qkt2GQdVKTDiRgDvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729070009; c=relaxed/simple; bh=wr5QJf611vpFPwPSZ9wJV0QzzUvva39TBierFt5EFS8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z6sILmgaC8qS3mijJbMzMP1f8QPzhYL4+UqXz2fhCOGGJOdGJxzcan2wZ7XhyFrep8sv/iCf9TumMZSfBCjkxPZwuGO8tanG5fBracOV8j+vbPNx4BLhkeTQ3BQPv9vfrPcg4CvLff4eDyhUvCjImAA7/nqRMq2+Bb2uvT/HWE4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BpW7JdU9; 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="BpW7JdU9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54498C4CECE; Wed, 16 Oct 2024 09:13:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729070008; bh=wr5QJf611vpFPwPSZ9wJV0QzzUvva39TBierFt5EFS8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BpW7JdU9z7Eg4E0Zr/ixikci5lvHorW+yOZGhvqGy97QARGwFr8GT2yxmQnweX9jJ 1pR3ifM6btdLRcDgHmQpD9cyZTTWFahQdgxYYQ6ksJ6OF0+Ly3FqOyXXkzaXmRPxA6 VAQ1XGoMweLvWmFsIkWR1sUrQgkF7Y0hTwkgO4pC4d2L8lQt8Ky5scjIvUBEguwrrV i9VcrHwD/9efGbE3QDEA4ShKeraOJ1s3PTC6SOe024ljuV4HTsoWGfIqivYS26kuk2 ENDJK3hKU77zqltbCPk8x2c+LfbTctFmWjbgN2k2yIcgpfNMbIqO8EWHOrs/DobuT2 MepyoebgHjuow== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 24/33] mptcp: drop struct mptcp_pm_add_entry Date: Wed, 16 Oct 2024 17:12:28 +0800 Message-ID: <7c25953b40bcf0e686e5b6bc8cf8ec89222cecc3.1729069854.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 There is no need to add a dedicated address entry type "mptcp_pm_add_entry" to represent ADD_ADDR addresses. Additional fields for ADD_ADDR addresses can be added into struct mptcp_pm_addr_entry directly. This makes the path manager code simpler. Here "union" can be used to merge struct mptcp_pm_addr_entry and struct mptcp_pm_add_entry into one. Then all mptcp_pm_add_entry can be replaced by mptcp_pm_addr_entry. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 26 +++++++++----------------- net/mptcp/protocol.h | 20 +++++++++++++++----- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 8f91fa2c398b..016ea8aba625 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -18,14 +18,6 @@ static int pm_nl_pernet_id; -struct mptcp_pm_add_entry { - struct list_head list; - struct mptcp_addr_info addr; - u8 retrans_times; - struct timer_list add_timer; - struct mptcp_sock *sock; -}; - struct pm_nl_pernet { /* protects pernet updates */ spinlock_t lock; @@ -247,11 +239,11 @@ bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk) return true; } -struct mptcp_pm_add_entry * +struct mptcp_pm_addr_entry * mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk, const struct mptcp_addr_info *addr) { - struct mptcp_pm_add_entry *entry; + struct mptcp_pm_addr_entry *entry; lockdep_assert_held(&msk->pm.lock); @@ -265,7 +257,7 @@ mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk, bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk) { - struct mptcp_pm_add_entry *entry; + struct mptcp_pm_addr_entry *entry; struct mptcp_addr_info saddr; bool ret = false; @@ -286,7 +278,7 @@ bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk) static void mptcp_pm_add_timer(struct timer_list *timer) { - struct mptcp_pm_add_entry *entry = from_timer(entry, timer, add_timer); + struct mptcp_pm_addr_entry *entry = from_timer(entry, timer, add_timer); struct mptcp_sock *msk = entry->sock; struct sock *sk = (struct sock *)msk; @@ -328,11 +320,11 @@ static void mptcp_pm_add_timer(struct timer_list *timer) __sock_put(sk); } -struct mptcp_pm_add_entry * +struct mptcp_pm_addr_entry * mptcp_pm_del_add_timer(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, bool check_id) { - struct mptcp_pm_add_entry *entry; + struct mptcp_pm_addr_entry *entry; struct sock *sk = (struct sock *)msk; struct timer_list *add_timer = NULL; @@ -356,7 +348,7 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk, bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, const struct mptcp_addr_info *addr) { - struct mptcp_pm_add_entry *add_entry = NULL; + struct mptcp_pm_addr_entry *add_entry = NULL; struct sock *sk = (struct sock *)msk; struct net *net = sock_net(sk); @@ -392,7 +384,7 @@ bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, void mptcp_pm_free_anno_list(struct mptcp_sock *msk) { - struct mptcp_pm_add_entry *entry, *tmp; + struct mptcp_pm_addr_entry *entry, *tmp; struct sock *sk = (struct sock *)msk; LIST_HEAD(free_list); @@ -1439,7 +1431,7 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info) static bool remove_anno_list_by_saddr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr) { - struct mptcp_pm_add_entry *entry; + struct mptcp_pm_addr_entry *entry; entry = mptcp_pm_del_add_timer(msk, addr, false); if (entry) { diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 038b50c8e211..2423079662d8 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -243,9 +243,19 @@ struct mptcp_pm_data { struct mptcp_pm_addr_entry { struct list_head list; struct mptcp_addr_info addr; - u8 flags; - int ifindex; - struct socket *lsk; + union { + struct { + u8 flags; + int ifindex; + struct socket *lsk; + }; + /* mptcp_pm_add_entry */ + struct { + u8 retrans_times; + struct timer_list add_timer; + struct mptcp_sock *sock; + }; + }; }; struct mptcp_data_frag { @@ -1026,10 +1036,10 @@ bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, const struct mptcp_addr_info *addr); void mptcp_pm_free_anno_list(struct mptcp_sock *msk); bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk); -struct mptcp_pm_add_entry * +struct mptcp_pm_addr_entry * mptcp_pm_del_add_timer(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, bool check_id); -struct mptcp_pm_add_entry * +struct mptcp_pm_addr_entry * mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk, const struct mptcp_addr_info *addr); int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc, From patchwork Wed Oct 16 09:12:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837990 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 772D0205E00 for ; Wed, 16 Oct 2024 09:13: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=1729070010; cv=none; b=J4X5/5YdeRy2duvYMk6J4yu5fRLiXoNJgzsic7yHvNAf6TLLz/fmGivXh4m79+t2eGFDrQyRZf9JxpMlS5w6pEZ3PXoNge16UV7+Pg9R9uT4rCkUrS5r+QjiabELMG29ps8Uw9rpplKrE/+laoCMxd0zXAX8IDA1CAZXKlNjOUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729070010; c=relaxed/simple; bh=aTh4YTBhhBQOtK2+ClSjCjDdV3hs0LZVNi/xJVU+1MI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KX5GjwjLEyZ4OTHnssMnGC9de7X/0dUBo2KBxEPXWLhxrqohbjx/Ubk/TB6UoFcPJpFXmRtANqidBJJJ3W7uKS8/N54OoyGylWNuGCnXAAfVqZ8RS/yR4pIjF5l9B0SFiYetse4PaTE5Z6H6HQjKBGpkIM8MQbpANQfUJkcrFyc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UzJhZ37L; 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="UzJhZ37L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E403C4CEC5; Wed, 16 Oct 2024 09:13:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729070010; bh=aTh4YTBhhBQOtK2+ClSjCjDdV3hs0LZVNi/xJVU+1MI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UzJhZ37LQg7NTp4HFXr/VqGEGGHnLGFJG/W5btFqMUOxEzqNEojuMFthwrcPpMcHw wbuwZJ8ouq8S80rakc9wgVftahkwrgPSvoI29ijXRr+xpL32+39nFxmrm+E6BNMv/V 6njSJEkyuI+CXrOXO2h00tR44+BHko9gMYgAW50eomH18Wyc7KqdcXqq7BC3zOQt26 oAyZtiv+oUStauuBa6OU2+EgkzdnGsr96GDpoSMopm42ygR+OLAIXSTPgzXJFqSom4 KsNrZ75/rVQ8/P8dEJMT6RFYvrCMNkVcoQxxg6u/sECjb8crOWHXUGlYWTOiuUxXnj e4Gd6cjR8htrw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 25/33] mptcp: change local type of subflow_destroy Date: Wed, 16 Oct 2024 17:12:29 +0800 Message-ID: <2d2002e24456abb3d8449d7bc797d9511c27a6d0.1729069854.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 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(). Signed-off-by: Geliang Tang --- 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 c1bc668cce1e..7c23f6f27626 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -453,7 +453,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info { struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR]; - struct mptcp_addr_info addr_l; + struct mptcp_pm_addr_entry local; struct mptcp_addr_info addr_r; struct mptcp_sock *msk; struct sock *sk, *ssk; @@ -470,7 +470,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info sk = (struct sock *)msk; - err = mptcp_pm_parse_addr(laddr, info, &addr_l); + err = mptcp_pm_parse_entry(laddr, info, true, &local); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); goto destroy_err; @@ -483,35 +483,34 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info } #if IS_ENABLED(CONFIG_MPTCP_IPV6) - if (addr_l.family == AF_INET && ipv6_addr_v4mapped(&addr_r.addr6)) { - ipv6_addr_set_v4mapped(addr_l.addr.s_addr, &addr_l.addr6); - addr_l.family = AF_INET6; + if (local.addr.family == AF_INET && ipv6_addr_v4mapped(&addr_r.addr6)) { + ipv6_addr_set_v4mapped(local.addr.addr.s_addr, &local.addr.addr6); + local.addr.family = AF_INET6; } - if (addr_r.family == AF_INET && ipv6_addr_v4mapped(&addr_l.addr6)) { - ipv6_addr_set_v4mapped(addr_r.addr.s_addr, &addr_r.addr6); + if (addr_r.family == AF_INET && ipv6_addr_v4mapped(&local.addr.addr6)) { + ipv6_addr_set_v4mapped(addr_r.addr.s_addr, &local.addr.addr6); addr_r.family = AF_INET6; } #endif - if (addr_l.family != addr_r.family) { + if (local.addr.family != addr_r.family) { GENL_SET_ERR_MSG(info, "address families do not match"); err = -EINVAL; goto destroy_err; } - if (!addr_l.port || !addr_r.port) { + if (!local.addr.port || !addr_r.port) { GENL_SET_ERR_MSG(info, "missing local or remote port"); err = -EINVAL; goto destroy_err; } lock_sock(sk); - ssk = mptcp_nl_find_ssk(msk, &addr_l, &addr_r); + ssk = mptcp_nl_find_ssk(msk, &local.addr, &addr_r); if (ssk) { struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); - struct mptcp_pm_addr_entry entry = { .addr = addr_l }; spin_lock_bh(&msk->pm.lock); - mptcp_userspace_pm_delete_local_addr(msk, &entry); + mptcp_userspace_pm_delete_local_addr(msk, &local); spin_unlock_bh(&msk->pm.lock); mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); mptcp_close_ssk(sk, ssk, subflow); From patchwork Wed Oct 16 09:12:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837991 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 55AA917D378 for ; Wed, 16 Oct 2024 09:13:32 +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=1729070012; cv=none; b=RbDcrR7NdZZoE4LT3d5vBkmEWc2iU6CveexN/FJJK9MeDiK/011o2HN9njmBoM/hFcVAt+DiVTgVQcH4BbEguj9JMKinM+Kfjs/mPFqW/MbqX5Npyl/CAM+WChjKTlocIle9MC5y9fkd7FgWM14EkkcpGgLnO5dmmGYjKO/+230= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729070012; c=relaxed/simple; bh=5tiU3/NqMdSOpzLHTkGlUsiReoRGKrah8GYOP1kp7k8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t82UxgpRPdCYDOFC0ui3ncwwoBxwPILFp+3JAItmeMQHvh1BDGSWA9qNLLLKqTemXtKk9HD6GUD8e2lSZW+wqrOD18o+nnb+PQqtwoJ6AkJgZ5Fepy1uitrL3LPVCaDzVl90h9+b/ph5+VZtIeMC2tOMGPv0PsyzTeWc98rUNTE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z9UQQvuX; 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="Z9UQQvuX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 080EEC4CEC5; Wed, 16 Oct 2024 09:13:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729070012; bh=5tiU3/NqMdSOpzLHTkGlUsiReoRGKrah8GYOP1kp7k8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z9UQQvuX+Yqv3CxQD+RCFWcQO9d+sLiOA2CXMNupaeMkWRYaBvJN/tgjfIhRc6GUu 3AVgIsOz/zD7tXAYK00Xs+NMt9cz+nNetagFCNDmcTkuTXDaCYXXp/CdnKrbBklcvp kzNjK9mT4YD/JoqOF0ZzOxp/fzHED7S587W/R7XfXpm5ebBXS92MKcQIb7u4P/4eoN 0DMj829rh6R7C7U+X3vhspxjUYHscxr1pfij/r45vrD1dzcA/eDbO+C5Plj/C5UbJD +8r9E1AxaHh/K/3hdHMAXx9kCgxkNgZnVB+uuOhAS3/SZxKcnetW2r0VSpaWPiuKor c5sdhixEm23Xg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 26/33] mptcp: hold pm lock when deleting entry Date: Wed, 16 Oct 2024 17:12:30 +0800 Message-ID: <80d439c5214a721750b1f77a097502a4a32d478e.1729069854.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 When traversing userspace_pm_local_addr_list and deleting an entry from it in mptcp_pm_nl_remove_doit(), msk->pm.lock should be held. Fixes: d9a4594edabf ("mptcp: netlink: Add MPTCP_PM_CMD_REMOVE") Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 7c23f6f27626..3ad10d8062d9 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -310,14 +310,17 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) lock_sock(sk); + spin_lock_bh(&msk->pm.lock); match = mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); if (!match) { GENL_SET_ERR_MSG(info, "address with specified id not found"); + spin_unlock_bh(&msk->pm.lock); release_sock(sk); goto out; } list_move(&match->list, &free_list); + spin_unlock_bh(&msk->pm.lock); mptcp_pm_remove_addrs(msk, &free_list); From patchwork Wed Oct 16 09:12:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837992 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 2D33B205E00 for ; Wed, 16 Oct 2024 09:13:34 +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=1729070014; cv=none; b=kqXgpAf6eC6raOGAVe9zRsO/hMv+kJ/UU5535kBIxcCaqbkEK6d2H2pKqtLsjzPw/uAXPdMEGPAJ9Op32Su9tktK4riwBZD3/Ii8cKwo2KJJZ+H0n3NMYz65/86fz3Ttp1ZvJd+UX+1Zo1DV9BPk7rtzmlSUXJSS2hSMhmIWmYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729070014; c=relaxed/simple; bh=AVWBP72aKbyfSXSlrmm7V5GSquEAqs5+weXMdIvfEDg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HC+R+AO0VA6JNZq3jkfLX4XiTT5b2u0983hxWw6yPTy0Jx+43AIMEerEup5UaFiMG10Pb0Fqmp+LoSZN5nDeRXLJjGu0fW1gCNuVP3Yun1pRi7mlxGlS7qqZSdesMsuYg78fk+2Yx9Wbr8ZG5Nih7lmFsDsT0/xHTdjDKh2HBtk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f1qwauWH; 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="f1qwauWH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D58B0C4CEC5; Wed, 16 Oct 2024 09:13:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729070014; bh=AVWBP72aKbyfSXSlrmm7V5GSquEAqs5+weXMdIvfEDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f1qwauWHPysbJdJbTHaeQxFEStqZYQ39lt89M5nBh1+sBlsi5/MaagHsWmKEccY40 YRrclAr7J4loOq+I/NjFaGiEhPkD9kOb0l2ESnp1xMHvkYh+ikoL/Ej5uB5DWeRyAb kL5xLYzSUPM/csxiIcsAjuc99pVdqAqWjIPa3oTLq6ZyZZzlNsCNs9bYqnTUii952L IkeFCUdIGcqKw4i69YYhmCcIqREkkM+Nj/okGkcxIaMPWIvVOnaYhI/7xWqkTC/rEB GElmoFeusq2hK58MyveU/2PW460IXYiDjWtu39RDWGy4gS6jCVJGVSbLEypq+HIsay vVJLSQIANzVJQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 27/33] mptcp: rename mptcp_pm_remove_addrs Date: Wed, 16 Oct 2024 17:12:31 +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 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". Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 24 ++++++++++-------------- net/mptcp/pm_userspace.c | 2 +- net/mptcp/protocol.h | 3 ++- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 016ea8aba625..bb65f8614134 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1615,26 +1615,22 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info) } /* Called from the userspace PM only */ -void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_list) +void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *entry) { struct mptcp_rm_list alist = { .nr = 0 }; - struct mptcp_pm_addr_entry *entry; int anno_nr = 0; - list_for_each_entry(entry, rm_list, list) { - if (alist.nr >= 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; + /* 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)) + goto out; - alist.ids[alist.nr++] = entry->addr.id; - } + alist.ids[alist.nr++] = entry->addr.id; +out: if (alist.nr) { spin_lock_bh(&msk->pm.lock); msk->pm.add_addr_signaled -= anno_nr; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 3ad10d8062d9..21b2a3b02cfe 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -322,7 +322,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) list_move(&match->list, &free_list); spin_unlock_bh(&msk->pm.lock); - mptcp_pm_remove_addrs(msk, &free_list); + mptcp_pm_remove_addr_entry(msk, match); release_sock(sk); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 2423079662d8..b1669c36a3a8 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1049,7 +1049,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_list *rm_list); -void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_list); +void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *entry); void mptcp_free_local_addr_list(struct mptcp_sock *msk); From patchwork Wed Oct 16 09:12:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837993 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 2FF03205139 for ; Wed, 16 Oct 2024 09:13:35 +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=1729070016; cv=none; b=UPwvIXoBRkOldrThLm7S9PEql9/xeEM5YHBh0VBwmlfQuJX2R1LSCSFtiS+sLEBw544wWbweZ8RSH4nVrKkgPJu6s4MIrc6NkLk9Y70bFyTgWhEp18wJrcYm/H1D6PQT0D6kckCgOUZUAiAfWOu49c/ujK2Tzs3q98aysQxo/ws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729070016; c=relaxed/simple; bh=BBUzVs3auqsq70ZKrGPUiTID457xHbiqoHg+mFLFqyY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XtVCHqDbtDz0aByTQdvASZ2iOkrjxjVLt6b4GPCnHOE8Z1HkrDe6VFhwzsbUM8nAJxVUVTDr31tnm6JvE+ZwJSlxKMNJWScrw5OWwh/qgXGgw6ztWBXf9zmWo2DM5uXOV1006adFqAlhnoNos4Kzgi/mIA+YYlNqWNH5eJz7O0o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PQJtk6yM; 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="PQJtk6yM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF047C4CECE; Wed, 16 Oct 2024 09:13:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729070015; bh=BBUzVs3auqsq70ZKrGPUiTID457xHbiqoHg+mFLFqyY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PQJtk6yMVQ+zv0KTm0XVnT+6QIiKTfQMccVgSCN3nzFDrd8KgmNiIxvg3B5BN6qCc KJ1LSvrm3pIbB+Cxm1ZhSAFq/bPiDErl9fJNyw85905SidNx1VaYKX/gLXS9a6tue+ EkRTIhrk5cARZQW08rGMkcofehwe55nSGN+LCt8T74A0SzmgEesUS8Gg0Ts8vVaSMZ 5qlx7JZieWpEmqyQAnqoyAD09npuqy3luN+X8QP5/TCO0ZCIgE8o9MTpV0M3gR80Nm 9qtsfgXify2wiHvzqh8CYoAzDT1OeOyoZasHgaGK99xEZvUWMm1u4De+K3in5WIPcV BCPbK7jIcPzOw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 28/33] mptcp: drop free_list for deleting entries Date: Wed, 16 Oct 2024 17:12:32 +0800 Message-ID: <1697f988f696e0e2898dbc61c4615f33ff9605bf.1729069854.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 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 --- net/mptcp/pm_userspace.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 21b2a3b02cfe..e5dfa1a6db31 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -283,9 +283,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *id = 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 = -EINVAL; struct sock *sk; u8 id_val; @@ -312,23 +310,21 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) spin_lock_bh(&msk->pm.lock); match = mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); + spin_unlock_bh(&msk->pm.lock); if (!match) { GENL_SET_ERR_MSG(info, "address with specified id not found"); - spin_unlock_bh(&msk->pm.lock); release_sock(sk); goto out; } - list_move(&match->list, &free_list); - spin_unlock_bh(&msk->pm.lock); - mptcp_pm_remove_addr_entry(msk, match); release_sock(sk); - list_for_each_entry_safe(match, entry, &free_list, list) { - sock_kfree_s(sk, match, sizeof(*match)); - } + spin_lock_bh(&msk->pm.lock); + list_del_rcu(&match->list); + sock_kfree_s(sk, match, sizeof(*match)); + spin_unlock_bh(&msk->pm.lock); err = 0; out: From patchwork Wed Oct 16 09:12:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837994 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 CB818205E00 for ; Wed, 16 Oct 2024 09:13:37 +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=1729070017; cv=none; b=FdY0v64t/9tdOT2Ccc4Y1q+LGifhGTyCJvA+zPG95kXV9380IobNkdoADL0hmGo7RPNVX7UgddIVy1fdqDtPjf7fUbfL6CivdQeBEdzO+unfEWJv0+iNGSmDxckc1AZWhnp8prMCmvvFX1kNktq9Uip2yFVpkO2abTHnO0FNZws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729070017; c=relaxed/simple; bh=C1O7C8fTcnZ0Wg4df1YR5DCWCFMa8SFujLnWeevShHA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qbjvBTnsxZaUrAEpxr3TIrt0wmyZ2RwVX5mjGCgpwsxqtbH67G/aSy/U/UVmWnUbHQQZxyDqdGWDGmcnn4bFmFToq/FpYKg+wRK3rymyZec7e7gQo56+kChcC8DxYDMS9JmKGwXYRUNZhnUPCuLRTvkAJkbPMJ9unu1hdJb0LhM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=el2P3hI7; 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="el2P3hI7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70710C4CEC5; Wed, 16 Oct 2024 09:13:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729070017; bh=C1O7C8fTcnZ0Wg4df1YR5DCWCFMa8SFujLnWeevShHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=el2P3hI7FPaueKiH620cy7qOzyHlbAAEeo8U6ixOvDIXeuH1Sv8k3QHy1OWjwN/nF JrTpzMW0MLBU4ql7kQVlWTX3COinlbc0BLSBijOK0vF3pZWmNSk/+1LO40FB3ruePr wM9559Wf/X3Rp3n8oXrf7C4NzwjU0KtCLfybPPrwp4wKYaix7yQa8mJS9T53mMBCEg Ae2jdVMula8Jka9e0/9aAYIgKKBwMByaZLGY0wdNK3ksuEFSJg1y53E8NF1DM4pVBT 0rdjX+ZA3dBGWlg6XTrw/8I8KRZJb/0ZYqwxnS+kKW6i7puIEob+CEDDf9vZx/iPB1 Fu3LjGgK0Zk4g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 29/33] mptcp: define struct mptcp_pm_ops Date: Wed, 16 Oct 2024 17:12:33 +0800 Message-ID: <09a555ce0fcab9201871335652ad8d1c0e658a95.1729069854.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 In order to allow users to develop their own BPF-based path manager, this patch defines a struct ops "mptcp_pm_ops" for an userspace path manager, which contains a set of interfaces. Add a set of functions to register, unregister and find this struct ops. Signed-off-by: Geliang Tang --- include/net/mptcp.h | 32 ++++++++++++++++++++++++++++ net/mptcp/pm_userspace.c | 45 ++++++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 4 ++++ 3 files changed, 81 insertions(+) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 84d67947a517..b00ad7665d71 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -15,6 +15,8 @@ struct mptcp_info; struct mptcp_sock; struct seq_file; +struct mptcp_pm_addr_entry; +struct mptcp_id_bitmap; /* MPTCP sk_buff extension data */ struct mptcp_ext { @@ -118,6 +120,36 @@ struct mptcp_sched_ops { void (*release)(struct mptcp_sock *msk); } ____cacheline_aligned_in_smp; +struct mptcp_pm_ops { + int (*address_announce)(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local); + int (*address_remove)(struct mptcp_sock *msk, u8 id); + int (*subflow_create)(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local, + struct mptcp_addr_info *remote); + int (*subflow_destroy)(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local, + struct mptcp_addr_info *remote); + int (*get_local_id)(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local); + u8 (*get_flags)(struct mptcp_sock *msk, + struct mptcp_addr_info *skc); + struct mptcp_pm_addr_entry *(*get_addr)(struct mptcp_sock *msk, + u8 id); + int (*dump_addr)(struct mptcp_sock *msk, + struct mptcp_id_bitmap *bitmap); + int (*set_flags)(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local, + struct mptcp_addr_info *remote); + + u8 type; + struct module *owner; + struct list_head list; + + void (*init)(struct mptcp_sock *msk); + void (*release)(struct mptcp_sock *msk); +} ____cacheline_aligned_in_smp; + #ifdef CONFIG_MPTCP void mptcp_init(void); diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index e5dfa1a6db31..3cc8bf26ffb0 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -4,10 +4,15 @@ * Copyright (c) 2022, Intel Corporation. */ +#include +#include #include "protocol.h" #include "mib.h" #include "mptcp_pm_gen.h" +static DEFINE_SPINLOCK(mptcp_pm_list_lock); +static LIST_HEAD(mptcp_pm_list); + void mptcp_free_local_addr_list(struct mptcp_sock *msk) { struct mptcp_pm_addr_entry *entry, *tmp; @@ -635,3 +640,43 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, sock_put(sk); return ret; } + +/* Must be called with rcu read lock held */ +struct mptcp_pm_ops *mptcp_pm_find(enum mptcp_pm_type type) +{ + struct mptcp_pm_ops *pm; + + list_for_each_entry_rcu(pm, &mptcp_pm_list, list) { + if (pm->type == type) + return pm; + } + + return NULL; +} + +int mptcp_register_path_manager(struct mptcp_pm_ops *pm) +{ + if (!pm->address_announce && !pm->address_remove && + !pm->subflow_create && !pm->subflow_destroy && + !pm->get_local_id && !pm->get_flags && + !pm->get_addr && !pm->dump_addr && !pm->set_flags) + return -EINVAL; + + spin_lock(&mptcp_pm_list_lock); + if (mptcp_pm_find(pm->type)) { + spin_unlock(&mptcp_pm_list_lock); + return -EEXIST; + } + list_add_tail_rcu(&pm->list, &mptcp_pm_list); + spin_unlock(&mptcp_pm_list_lock); + + pr_debug("userspace_pm type %u registered\n", pm->type); + return 0; +} + +void mptcp_unregister_path_manager(struct mptcp_pm_ops *pm) +{ + spin_lock(&mptcp_pm_list_lock); + list_del_rcu(&pm->list); + spin_unlock(&mptcp_pm_list_lock); +} diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index b1669c36a3a8..5b21d1f1ba16 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1052,6 +1052,10 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_ void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *entry); +struct mptcp_pm_ops *mptcp_pm_find(enum mptcp_pm_type type); +int mptcp_register_path_manager(struct mptcp_pm_ops *pm); +void mptcp_unregister_path_manager(struct mptcp_pm_ops *pm); + void mptcp_free_local_addr_list(struct mptcp_sock *msk); void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk, From patchwork Wed Oct 16 09:12:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837995 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 EF26A17D378 for ; Wed, 16 Oct 2024 09:13: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=1729070020; cv=none; b=Vm6ggd10S200W6c7Zx+JqIQftMC47kxtVCrxnK8LzmRNPB7TAwdbbGa3K71WaL2xNLr8u3z0c/3xz0h1JfLSY4ou7UAuNo6hHEcGgkVPQmri/mhQBIuwMV12dvV2LHuMsAo1/ziPrXEGukyHCTHKwAlplwnMtWe0NPmlkTDrt1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729070020; c=relaxed/simple; bh=JyFRrbOuTWDBqfUobiyMmyG5mYpvqPKwXVtX68H4aNA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ivyb+h2e31SWg+IBj/IUSVesc6mIcICiAl03t/anKwGi3Uu0TLopU3crrMcN5/DmKAoHmqekghKqZY69aU9eDbIuiMOyutl46BDDil9SCzFOwQI2Vfpg41QCECBMveKGMj6udbAq1rUPbJx/KR7mBYL2Rt8AYp1tpD3g7SkhcU0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UeT8+3kr; 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="UeT8+3kr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49582C4CEC5; Wed, 16 Oct 2024 09:13:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729070019; bh=JyFRrbOuTWDBqfUobiyMmyG5mYpvqPKwXVtX68H4aNA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UeT8+3krY1sjqEggzmwEPoNHCgY69h3t4QxhDROdUcDASGwIRtHrfR8fh0+8A3ser +vJBl3Sgksz5N+U31zBnBCOm+xTVjpG0oRmnKjmcE7iXbGqhOCgCBw1kkQVEUpsEjO L3u2ZZW6yjoWZBOvFXUQsmwIkd0wEt8Ujb/PgPfgdrKBr6MpTpSfpn89LAVrD/tiAU mu3CkvtdiunCfzezq4XcrFT65PiRkQfDP2aBKxnUQ9MvqF/3aeCSYr8nrQpRPhscxd UFGyzWadQ7zy7QWl+K3/IwxkhFIqjgYxMUh+XNAsq7YWLAUIK9HyoCWWeIGVnanEU6 V9Ia1g0vaswBQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 30/33] mptcp: implement userspace pm address interfaces Date: Wed, 16 Oct 2024 17:12:34 +0800 Message-ID: <87c4d3dfcf3dc290b95e7f7c3221ae6597342f2f.1729069854.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 implements address_announce() and address_remove() interfaces of the userspace PM. Extract address_announce() interface from the handler of netlink commond MPTCP_PM_CMD_ANNOUNCE mptcp_pm_nl_announce_doit(), only leave the code for obtaining msk through "info" and parsing address entry in the handler. Extract address_remove() interface from the handler of netlink commond MPTCP_PM_CMD_REMOVE mptcp_pm_nl_remove_doit(), only leave the code for parsing address id and obtaining msk through "info" in the handler. Both interfaces are invoked under holding the msk socket lock. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 110 ++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 53 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 3cc8bf26ffb0..68eec0672743 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -195,6 +195,31 @@ static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *in return msk; } +static int userspace_pm_address_announce(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local) +{ + int err; + + if (local->addr.id == 0 || !(local->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) + return -EINVAL; + + err = mptcp_userspace_pm_append_new_local_addr(msk, local, false); + if (err < 0) + return err; + + spin_lock_bh(&msk->pm.lock); + + if (mptcp_pm_alloc_anno_list(msk, &local->addr)) { + msk->pm.add_addr_signaled++; + mptcp_pm_announce_addr(msk, &local->addr, false); + mptcp_pm_nl_addr_send_ack(msk); + } + + spin_unlock_bh(&msk->pm.lock); + + return 0; +} + int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *addr = info->attrs[MPTCP_PM_ATTR_ADDR]; @@ -220,46 +245,24 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) goto announce_err; } - if (addr_val.addr.id == 0 || !(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) { - GENL_SET_ERR_MSG(info, "invalid addr id or flags"); - err = -EINVAL; - goto announce_err; - } - - err = mptcp_userspace_pm_append_new_local_addr(msk, &addr_val, false); - if (err < 0) { - GENL_SET_ERR_MSG(info, "did not match address and id"); - goto announce_err; - } - lock_sock(sk); - spin_lock_bh(&msk->pm.lock); - - if (mptcp_pm_alloc_anno_list(msk, &addr_val.addr)) { - msk->pm.add_addr_signaled++; - mptcp_pm_announce_addr(msk, &addr_val.addr, false); - mptcp_pm_nl_addr_send_ack(msk); - } - - spin_unlock_bh(&msk->pm.lock); + err = userspace_pm_address_announce(msk, &addr_val); release_sock(sk); + if (err) + GENL_SET_ERR_MSG(info, "address_announce failed"); - err = 0; announce_err: sock_put(sk); return err; } -static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk, - struct genl_info *info) +static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk) { struct mptcp_rm_list list = { .nr = 0 }; struct mptcp_subflow_context *subflow; - struct sock *sk = (struct sock *)msk; bool has_id_0 = false; int err = -EINVAL; - lock_sock(sk); mptcp_for_each_subflow(msk, subflow) { if (READ_ONCE(subflow->local_id) == 0) { has_id_0 = true; @@ -267,7 +270,7 @@ static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk, } } if (!has_id_0) { - GENL_SET_ERR_MSG(info, "address with id 0 not found"); + pr_debug("address with id 0 not found\n"); goto remove_err; } @@ -280,14 +283,36 @@ static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk, err = 0; remove_err: - release_sock(sk); return err; } +static int userspace_pm_address_remove(struct mptcp_sock *msk, u8 id) +{ + struct sock *sk = (struct sock *)msk; + struct mptcp_pm_addr_entry *match; + + if (id == 0) + return mptcp_userspace_pm_remove_id_zero_address(msk); + + spin_lock_bh(&msk->pm.lock); + match = mptcp_userspace_pm_lookup_addr_by_id(msk, id); + spin_unlock_bh(&msk->pm.lock); + if (!match) + return -EINVAL; + + mptcp_pm_remove_addr_entry(msk, match); + + spin_lock_bh(&msk->pm.lock); + list_del_rcu(&match->list); + sock_kfree_s(sk, match, sizeof(*match)); + spin_unlock_bh(&msk->pm.lock); + + return 0; +} + int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *id = info->attrs[MPTCP_PM_ATTR_LOC_ID]; - struct mptcp_pm_addr_entry *match; struct mptcp_sock *msk; int err = -EINVAL; struct sock *sk; @@ -306,33 +331,12 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) sk = (struct sock *)msk; - if (id_val == 0) { - err = mptcp_userspace_pm_remove_id_zero_address(msk, info); - goto out; - } - lock_sock(sk); - - spin_lock_bh(&msk->pm.lock); - match = mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); - spin_unlock_bh(&msk->pm.lock); - if (!match) { - GENL_SET_ERR_MSG(info, "address with specified id not found"); - release_sock(sk); - goto out; - } - - mptcp_pm_remove_addr_entry(msk, match); - + err = userspace_pm_address_remove(msk, id_val); release_sock(sk); + if (err) + GENL_SET_ERR_MSG(info, "address_remove failed"); - spin_lock_bh(&msk->pm.lock); - list_del_rcu(&match->list); - sock_kfree_s(sk, match, sizeof(*match)); - spin_unlock_bh(&msk->pm.lock); - - err = 0; -out: sock_put(sk); return err; } From patchwork Wed Oct 16 09:12:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837996 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 6D06317D378 for ; Wed, 16 Oct 2024 09:13: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=1729070021; cv=none; b=a+vWX4WGqaC1Vf8OBSOd9T8lnmLcOYRfK3LuXiELrJHMEgiOD/3/QtzA6sm7cXbkz8A/3p4ikR+RvIx9daiG+VhrGphBgGhlH94kNyO83fcsYFwEH1b38QkPAeoEgE9NMC6HlxZJianYm60oK3XypPwsfvVydFZtsnv+Il6KqDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729070021; c=relaxed/simple; bh=vC0jTeebxJMuV02V9VMvlyexLr75w489vELa1ZH8oX0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JCvQz8UnbrfU1WDVvZ1pQ2mM3YGMarG+hHsDmiub6abigCQPIaA1XcDf6Dp7tYNZkTBMGyQB9fhgDZahenKivDERIUcjv539UwIvlILXMnh2ideUWc0ZmDV38sUbuIqC2yDjmsLFcby5rkGcW70r1p/I/I7OUSA8TOv7WDvC+xI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bshi+Fz1; 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="bshi+Fz1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23AF7C4CECE; Wed, 16 Oct 2024 09:13:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729070021; bh=vC0jTeebxJMuV02V9VMvlyexLr75w489vELa1ZH8oX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bshi+Fz10i0MarG5XIjbcpcjMYhtEe4oe2msl8TELnSVfc9w1cZqTNER3Ey5RfVsT 2UBcjxiy+/3UFaLXdkiL2RUKjCCLraA8/WdV6AeY0gZVBnzKbg6/wvxhGM+fqDCO+O CJ9vPVYIEtLzzjhEW3KiNnsgr+84mHY2j5EBfeyIWdOuPuvjFPoVE0AJcFPIBpQ4Ms 5ZP/+KzVL3Xs351L4BXmztkJovvq0tWzBsK2NcaVhy0kB2YwjwY/HbaOb9p8RhA57K wEp5JFCo1NYwL8KiGuFa8JWg6dGJKVFqITBudj9Uoja9KwAnrHDNKiyo4YoQYa+yRz dtTWBbtsfXPgA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 31/33] mptcp: implement userspace pm subflow interfaces Date: Wed, 16 Oct 2024 17:12:35 +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 This patch implements subflow_create() and subflow_destroy() interfaces of the userspace PM. Extract subflow_create() interface from the handler of netlink commond MPTCP_PM_CMD_SUBFLOW_CREATE mptcp_pm_nl_subflow_create_doit(), only leave the code for obtaining msk through "info", parsing local address entry and parsing remote address info in the handler. Extract subflow_destroy() interface from the handler of netlink commond MPTCP_PM_CMD_SUBFLOW_DESTROY mptcp_pm_nl_subflow_destroy_doit(), only leave the code for obtaining msk through "info", parsing local address entry and parsing remote address info in the handler. Both interfaces are invoked under holding the msk socket lock. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 138 +++++++++++++++++++++------------------ 1 file changed, 75 insertions(+), 63 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 68eec0672743..0ab37f31eee9 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -341,6 +341,35 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) return err; } +static int userspace_pm_subflow_create(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local, + struct mptcp_addr_info *remote) +{ + struct sock *sk = (struct sock *)msk; + int err; + + if (local->flags & MPTCP_PM_ADDR_FLAG_SIGNAL) + return -EINVAL; + local->flags |= MPTCP_PM_ADDR_FLAG_SUBFLOW; + + if (!mptcp_pm_addr_families_match(sk, &local->addr, remote)) + return -EINVAL; + + err = mptcp_userspace_pm_append_new_local_addr(msk, local, false); + if (err < 0) + return err; + + err = __mptcp_subflow_connect(sk, local, remote); + spin_lock_bh(&msk->pm.lock); + if (err) + mptcp_userspace_pm_delete_local_addr(msk, local); + else + msk->pm.subflows++; + spin_unlock_bh(&msk->pm.lock); + + return err; +} + int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; @@ -368,41 +397,17 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) goto create_err; } - if (entry.flags & MPTCP_PM_ADDR_FLAG_SIGNAL) { - GENL_SET_ERR_MSG(info, "invalid addr flags"); - err = -EINVAL; - goto create_err; - } - entry.flags |= MPTCP_PM_ADDR_FLAG_SUBFLOW; - err = mptcp_pm_parse_addr(raddr, info, &addr_r); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, raddr, "error parsing remote addr"); goto create_err; } - if (!mptcp_pm_addr_families_match(sk, &entry.addr, &addr_r)) { - GENL_SET_ERR_MSG(info, "families mismatch"); - err = -EINVAL; - goto create_err; - } - - err = mptcp_userspace_pm_append_new_local_addr(msk, &entry, false); - if (err < 0) { - GENL_SET_ERR_MSG(info, "did not match address and id"); - goto create_err; - } - lock_sock(sk); - err = __mptcp_subflow_connect(sk, &entry, &addr_r); + err = userspace_pm_subflow_create(msk, &entry, &addr_r); release_sock(sk); - - spin_lock_bh(&msk->pm.lock); if (err) - mptcp_userspace_pm_delete_local_addr(msk, &entry); - else - msk->pm.subflows++; - spin_unlock_bh(&msk->pm.lock); + GENL_SET_ERR_MSG(info, "subflow_create failed"); create_err: sock_put(sk); @@ -457,6 +462,46 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_sock *msk, return NULL; } +static int userspace_pm_subflow_destroy(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local, + struct mptcp_addr_info *remote) +{ + struct sock *sk = (struct sock *)msk; + struct sock *ssk; + int err = -ESRCH; + +#if IS_ENABLED(CONFIG_MPTCP_IPV6) + if (local->addr.family == AF_INET && ipv6_addr_v4mapped(&remote->addr6)) { + ipv6_addr_set_v4mapped(local->addr.addr.s_addr, &remote->addr6); + local->addr.family = AF_INET6; + } + if (remote->family == AF_INET && ipv6_addr_v4mapped(&local->addr.addr6)) { + ipv6_addr_set_v4mapped(remote->addr.s_addr, &local->addr.addr6); + remote->family = AF_INET6; + } +#endif + if (local->addr.family != remote->family) + return -EINVAL; + + if (!local->addr.port || !remote->port) + return -EINVAL; + + ssk = mptcp_nl_find_ssk(msk, &local->addr, remote); + if (ssk) { + struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); + + spin_lock_bh(&msk->pm.lock); + mptcp_userspace_pm_delete_local_addr(msk, local); + 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 = 0; + } + + return err; +} + int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; @@ -464,8 +509,8 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info struct mptcp_pm_addr_entry local; struct mptcp_addr_info addr_r; struct mptcp_sock *msk; - struct sock *sk, *ssk; int err = -EINVAL; + struct sock *sk; if (!laddr || !raddr) { GENL_SET_ERR_MSG(info, "missing required inputs"); @@ -490,44 +535,11 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info goto destroy_err; } -#if IS_ENABLED(CONFIG_MPTCP_IPV6) - if (local.addr.family == AF_INET && ipv6_addr_v4mapped(&addr_r.addr6)) { - ipv6_addr_set_v4mapped(local.addr.addr.s_addr, &local.addr.addr6); - local.addr.family = AF_INET6; - } - if (addr_r.family == AF_INET && ipv6_addr_v4mapped(&local.addr.addr6)) { - ipv6_addr_set_v4mapped(addr_r.addr.s_addr, &local.addr.addr6); - addr_r.family = AF_INET6; - } -#endif - if (local.addr.family != addr_r.family) { - GENL_SET_ERR_MSG(info, "address families do not match"); - err = -EINVAL; - goto destroy_err; - } - - if (!local.addr.port || !addr_r.port) { - GENL_SET_ERR_MSG(info, "missing local or remote port"); - err = -EINVAL; - goto destroy_err; - } - lock_sock(sk); - ssk = mptcp_nl_find_ssk(msk, &local.addr, &addr_r); - if (ssk) { - struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); - - spin_lock_bh(&msk->pm.lock); - mptcp_userspace_pm_delete_local_addr(msk, &local); - 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 = 0; - } else { - err = -ESRCH; - } + err = userspace_pm_subflow_destroy(msk, &local, &addr_r); release_sock(sk); + if (err) + GENL_SET_ERR_MSG(info, "subflow_destroy failed"); destroy_err: sock_put(sk); From patchwork Wed Oct 16 09:12:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837997 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 4A25C20514D for ; Wed, 16 Oct 2024 09:13:43 +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=1729070023; cv=none; b=RpDEfcmWZ/vOcNN1GwcnVXf6xQvs/w+lPlNE9rMYJxkT+NNnyB3xP+Dm2Vs4OY5sMw4kQe5iL+uvk+NEiSvx3dym4XcaQJUM9q4bWhJ8WtYaUj3H6Fp3OO+kPxY3xT6TTpKZ5Js+muTj141X/eGPANjIQ9XAgQY4oVou/Gqy/FE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729070023; c=relaxed/simple; bh=Avb+Mu8qOS9006sZBjkNAwrFOK2Yr/ih0x0UKoO2OTQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dmg321+Pnxy5ZjjTA0qdasc3Mt0Lhhso1GkwpXRTMFp+ZTAIgqGqprOBtdRAA0S32ak15/6fGOsktOKpTJWNDZBC7UF9WP1jm2JnU/yCH3vKTh1XBZSJZ+ARhV+0t0PUhHAYXdVy9wVdfk6rdDVjaEtTrVtA3JyjXkDUM5JUIg4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UvhpL1cZ; 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="UvhpL1cZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F26B9C4CEC5; Wed, 16 Oct 2024 09:13:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729070023; bh=Avb+Mu8qOS9006sZBjkNAwrFOK2Yr/ih0x0UKoO2OTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UvhpL1cZRE5ao4EveL5X5E8vgr5pA2+l03D5zz639pfcJmeLnnhif23XU0YnFyNGd cxuwh2pd52rwMfiTjraxpv8kbOvjDdhTC17yWkq7KZuvLx3bTR60B8RJoxmi+r9jlg Ce8atk+99kdeot4gd5kMFixqt/EPfswU/olG9I4Y+fgYHI/mVhFjhCVARF1LRoOdqY fcHteZ/Vvyf+tayVnBDFK6LGiQT2VoVPCyOiOeN+QZsgaXTmabEpnNzMgRkpSuvLZL 6mA5GIPsRVsFvZmFDVL8v6wUCQRP7I+ogB0JrUyz0XmIu52s56/gF2Yo93Blmxn6YA PMXUyWT1BNQPg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 32/33] mptcp: implement userspace pm others interfaces Date: Wed, 16 Oct 2024 17:12:36 +0800 Message-ID: <60e916cec3bfa62100a7011bd157f3ad4f683964.1729069854.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 implements get_local_id(), get_flags(), get_addr(), dump_addr() and set_flags() interfaces of the userspace PM. get_local_id() interface is the same as mptcp_userspace_pm_get_local_id(), which now can be defined as a wrapper of the interface. While get_flags() interface is the same as mptcp_userspace_pm_get_flags() too, which now can be defined as a wrapper of get_flags() interface. get_addr() interface is a wrapper of mptcp_userspace_pm_lookup_addr_by_id() helper. While dump_addr() is a wrapper of mptcp_userspace_pm_set_bitmap() helper. These two interfaces are invoked under holding both the msk socket lock and the msk pm lock. Extract set_flags() interface from function mptcp_userspace_pm_set_flags(), only leave the code for obtaining msk through "info" in this function. This interface is invoked under holding the msk socket lock. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 86 +++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 27 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 0ab37f31eee9..f07c77dca84b 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -135,8 +135,8 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *msk, unsigned int id) return NULL; } -int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, - struct mptcp_pm_addr_entry *local) +static int userspace_pm_get_local_id(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local) { struct mptcp_pm_addr_entry *entry = NULL; __be16 msk_sport = ((struct inet_sock *) @@ -154,8 +154,14 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, return mptcp_userspace_pm_append_new_local_addr(msk, local, true); } -u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, - struct mptcp_addr_info *skc) +int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local) +{ + return userspace_pm_get_local_id(msk, local); +} + +static u8 userspace_pm_get_flags(struct mptcp_sock *msk, + struct mptcp_addr_info *skc) { struct mptcp_pm_addr_entry *entry; u8 flags = 0; @@ -169,6 +175,12 @@ u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, return flags; } +u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, + struct mptcp_addr_info *skc) +{ + return userspace_pm_get_flags(msk, skc); +} + static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *info) { struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; @@ -546,34 +558,24 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info return err; } -int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc, - struct mptcp_addr_info *rem, - struct genl_info *info) +static int userspace_pm_set_flags(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local, + struct mptcp_addr_info *remote) { struct mptcp_pm_addr_entry *entry; - struct mptcp_sock *msk; - int ret = -EINVAL; - struct sock *sk; u8 bkup = 0; - msk = mptcp_userspace_pm_get_sock(info); - if (!msk) - return ret; - - sk = (struct sock *)msk; - - if (loc->addr.family == AF_UNSPEC || - rem->family == AF_UNSPEC) { - GENL_SET_ERR_MSG(info, "invalid address families"); - ret = -EINVAL; - goto set_flags_err; + if (local->addr.family == AF_UNSPEC || + remote->family == AF_UNSPEC) { + pr_debug("invalid address families\n"); + return -EINVAL; } - if (loc->flags & MPTCP_PM_ADDR_FLAG_BACKUP) + if (local->flags & MPTCP_PM_ADDR_FLAG_BACKUP) bkup = 1; spin_lock_bh(&msk->pm.lock); - entry = mptcp_userspace_pm_lookup_addr(msk, &loc->addr); + entry = mptcp_userspace_pm_lookup_addr(msk, &local->addr); if (entry) { if (bkup) entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP; @@ -582,11 +584,29 @@ int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc, } spin_unlock_bh(&msk->pm.lock); + return mptcp_pm_nl_mp_prio_send_ack(msk, &local->addr, remote, bkup); +} + +int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc, + struct mptcp_addr_info *rem, + struct genl_info *info) +{ + struct mptcp_sock *msk; + int ret = -EINVAL; + struct sock *sk; + + msk = mptcp_userspace_pm_get_sock(info); + if (!msk) + return ret; + + sk = (struct sock *)msk; + lock_sock(sk); - ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc->addr, rem, bkup); + ret = userspace_pm_set_flags(msk, loc, rem); release_sock(sk); + if (ret) + GENL_SET_ERR_MSG(info, "set_flags failed"); -set_flags_err: sock_put(sk); return ret; } @@ -606,6 +626,12 @@ static int mptcp_userspace_pm_set_bitmap(struct mptcp_sock *msk, return 0; } +static int userspace_pm_dump_addr(struct mptcp_sock *msk, + struct mptcp_id_bitmap *bitmap) +{ + return mptcp_userspace_pm_set_bitmap(msk, bitmap); +} + int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap, const struct genl_info *info) { @@ -621,7 +647,7 @@ int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap, lock_sock(sk); spin_lock_bh(&msk->pm.lock); - ret = mptcp_userspace_pm_set_bitmap(msk, bitmap); + ret = userspace_pm_dump_addr(msk, bitmap); spin_unlock_bh(&msk->pm.lock); release_sock(sk); @@ -629,6 +655,12 @@ int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap, return ret; } +static struct mptcp_pm_addr_entry * +userspace_pm_get_addr(struct mptcp_sock *msk, u8 id) +{ + return mptcp_userspace_pm_lookup_addr_by_id(msk, id); +} + int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, const struct genl_info *info) { @@ -645,7 +677,7 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, lock_sock(sk); spin_lock_bh(&msk->pm.lock); - entry = mptcp_userspace_pm_lookup_addr_by_id(msk, id); + entry = userspace_pm_get_addr(msk, id); if (entry) { *addr = *entry; ret = 0; From patchwork Wed Oct 16 09:12:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13837998 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 7C89F205126 for ; Wed, 16 Oct 2024 09:13:45 +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=1729070025; cv=none; b=GgXfR2+YPRjB75BalHb0mTd7rLKGdi8kP/NM1TsiSx1Sf3ghHM9yap+J9/xOP2MXtaHdp0qIveFFhRSyq3dODr9kKNw1FbqgNOaAk5dSes1ofiQ2wbwI5Rt89zvO4zmDsK49rBTAUTUxDjCjoAalsgeRDzVx3WFSFqzg9Kpw8H0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729070025; c=relaxed/simple; bh=nPmKUiwmjEgfDfDp6B6/vil9iPWYlLioNJiYNhtJNok=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qAq89cW/snybggDfWUIRtgFZQc+iY8wHfZOxKoGdMcBbJKDQcOYaVW+bJjtalPy8zVIWv7K7KP/X/BmN45TtB8jU6T6JstdSHqe9mZQ/GIjj24vJcLzZZE5hjOanvEgXuA9OvX1deJF8BxAV7eHqVCxUOeYkfLzkdOqNOsMBf2Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H1rUM3bJ; 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="H1rUM3bJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA9EEC4CEC5; Wed, 16 Oct 2024 09:13:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729070025; bh=nPmKUiwmjEgfDfDp6B6/vil9iPWYlLioNJiYNhtJNok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H1rUM3bJc3g+5+qzkGMMTwSfZxCUXpGDXweX08NxVVNsxYPMArFCvFpuV43Ddot/A ugXYAv31lBqSf4P1SB52Qgjyfuk38EMWI3z/cVrzNE/ZaSW3zx0CB6R1aU30p0m3gK 0vETT92UtCGD5vtPFVoBrD3IaSzyLStiQYacp7F4PqooUr9y+kx8/GWp+uSYRT94ou JuzcIe79sFaazyXpvzJ2Z6kYqnzw28ySvnYksIX5plKDGMfXQ7oK/nHR6uid3YKdUn hpdhwRvQ8JYaANSu6ceTw1GK5ewlftxsdij5Nh6Q4DuKP7jUn5bfyA/b3rQt7XkIma cqK1N6jHyczOQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 33/33] mptcp: register default userspace pm Date: Wed, 16 Oct 2024 17:12:37 +0800 Message-ID: <109bde463401881d74b860a8349a845096ba0705.1729069854.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 defines the original userspace pm as the default path manager, named mptcp_userspace_pm, and register it in mptcp_pm_data_init(). Add a struct mptcp_pm_ops pointer "ops" in struct mptcp_pm_data, and two functions mptcp_init_pm() and mptcp_release_pm(), to set and release this pointer. mptcp_init_pm() is invoked in mptcp_pm_data_reset(), while mptcp_release_pm() is invoked in __mptcp_destroy_sock(). In this way, different userspace path managers can be initialized through the pm_type sysctl, and then called into their respective interfaces through "ops" of "msk->pm". Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 4 ++ net/mptcp/pm_userspace.c | 88 ++++++++++++++++++++++++++++++++++++---- net/mptcp/protocol.c | 1 + net/mptcp/protocol.h | 4 ++ 4 files changed, 88 insertions(+), 9 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index c2229e46de1a..3b9249c34d5a 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -516,6 +516,9 @@ void mptcp_pm_data_reset(struct mptcp_sock *msk) WRITE_ONCE(pm->work_pending, 0); WRITE_ONCE(pm->accept_addr, 0); WRITE_ONCE(pm->accept_subflow, 0); + + if (mptcp_init_pm(msk, mptcp_pm_find(pm_type))) + return; } WRITE_ONCE(pm->addr_signal, 0); @@ -535,4 +538,5 @@ void mptcp_pm_data_init(struct mptcp_sock *msk) void __init mptcp_pm_init(void) { mptcp_pm_nl_init(); + mptcp_userspace_pm_init(); } diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index f07c77dca84b..a3d4a11daf65 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -157,7 +157,9 @@ static int userspace_pm_get_local_id(struct mptcp_sock *msk, int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local) { - return userspace_pm_get_local_id(msk, local); + return INDIRECT_CALL_1(msk->pm.ops->get_local_id, + userspace_pm_get_local_id, + msk, local); } static u8 userspace_pm_get_flags(struct mptcp_sock *msk, @@ -178,7 +180,9 @@ static u8 userspace_pm_get_flags(struct mptcp_sock *msk, u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, struct mptcp_addr_info *skc) { - return userspace_pm_get_flags(msk, skc); + return INDIRECT_CALL_1(msk->pm.ops->get_flags, + userspace_pm_get_flags, + msk, skc); } static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *info) @@ -258,7 +262,9 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) } lock_sock(sk); - err = userspace_pm_address_announce(msk, &addr_val); + err = INDIRECT_CALL_1(msk->pm.ops->address_announce, + userspace_pm_address_announce, + msk, &addr_val); release_sock(sk); if (err) GENL_SET_ERR_MSG(info, "address_announce failed"); @@ -344,7 +350,9 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) sk = (struct sock *)msk; lock_sock(sk); - err = userspace_pm_address_remove(msk, id_val); + err = INDIRECT_CALL_1(msk->pm.ops->address_remove, + userspace_pm_address_remove, + msk, id_val); release_sock(sk); if (err) GENL_SET_ERR_MSG(info, "address_remove failed"); @@ -416,7 +424,9 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) } lock_sock(sk); - err = userspace_pm_subflow_create(msk, &entry, &addr_r); + err = INDIRECT_CALL_1(msk->pm.ops->subflow_create, + userspace_pm_subflow_create, + msk, &entry, &addr_r); release_sock(sk); if (err) GENL_SET_ERR_MSG(info, "subflow_create failed"); @@ -548,7 +558,9 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info } lock_sock(sk); - err = userspace_pm_subflow_destroy(msk, &local, &addr_r); + err = INDIRECT_CALL_1(msk->pm.ops->subflow_destroy, + userspace_pm_subflow_destroy, + msk, &local, &addr_r); release_sock(sk); if (err) GENL_SET_ERR_MSG(info, "subflow_destroy failed"); @@ -602,7 +614,9 @@ int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc, sk = (struct sock *)msk; lock_sock(sk); - ret = userspace_pm_set_flags(msk, loc, rem); + ret = INDIRECT_CALL_1(msk->pm.ops->set_flags, + userspace_pm_set_flags, + msk, loc, rem); release_sock(sk); if (ret) GENL_SET_ERR_MSG(info, "set_flags failed"); @@ -647,7 +661,9 @@ int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap, lock_sock(sk); spin_lock_bh(&msk->pm.lock); - ret = userspace_pm_dump_addr(msk, bitmap); + ret = INDIRECT_CALL_1(msk->pm.ops->dump_addr, + userspace_pm_dump_addr, + msk, bitmap); spin_unlock_bh(&msk->pm.lock); release_sock(sk); @@ -677,7 +693,9 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, lock_sock(sk); spin_lock_bh(&msk->pm.lock); - entry = userspace_pm_get_addr(msk, id); + entry = INDIRECT_CALL_1(msk->pm.ops->get_addr, + userspace_pm_get_addr, + msk, id); if (entry) { *addr = *entry; ret = 0; @@ -689,6 +707,20 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, return ret; } +static struct mptcp_pm_ops mptcp_userspace_pm = { + .address_announce = userspace_pm_address_announce, + .address_remove = userspace_pm_address_remove, + .subflow_create = userspace_pm_subflow_create, + .subflow_destroy = userspace_pm_subflow_destroy, + .get_local_id = userspace_pm_get_local_id, + .get_flags = userspace_pm_get_flags, + .get_addr = userspace_pm_get_addr, + .dump_addr = userspace_pm_dump_addr, + .set_flags = userspace_pm_set_flags, + .type = MPTCP_PM_TYPE_USERSPACE, + .owner = THIS_MODULE, +}; + /* Must be called with rcu read lock held */ struct mptcp_pm_ops *mptcp_pm_find(enum mptcp_pm_type type) { @@ -724,7 +756,45 @@ int mptcp_register_path_manager(struct mptcp_pm_ops *pm) void mptcp_unregister_path_manager(struct mptcp_pm_ops *pm) { + if (pm == &mptcp_userspace_pm) + return; + spin_lock(&mptcp_pm_list_lock); list_del_rcu(&pm->list); spin_unlock(&mptcp_pm_list_lock); } + +int mptcp_init_pm(struct mptcp_sock *msk, struct mptcp_pm_ops *pm) +{ + if (!pm) + pm = &mptcp_userspace_pm; + + if (!bpf_try_module_get(pm, pm->owner)) + return -EBUSY; + + msk->pm.ops = pm; + if (msk->pm.ops->init) + msk->pm.ops->init(msk); + + pr_debug("userspace_pm type %u initialized\n", msk->pm.ops->type); + return 0; +} + +void mptcp_release_pm(struct mptcp_sock *msk) +{ + struct mptcp_pm_ops *pm = msk->pm.ops; + + if (!pm) + return; + + msk->pm.ops = NULL; + if (pm->release) + pm->release(msk); + + bpf_module_put(pm, pm->owner); +} + +void __init mptcp_userspace_pm_init(void) +{ + mptcp_register_path_manager(&mptcp_userspace_pm); +} diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index e420ce9bbfb6..0f4305379e58 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3038,6 +3038,7 @@ static void __mptcp_destroy_sock(struct sock *sk) sk_stop_timer(sk, &sk->sk_timer); msk->pm.status = 0; mptcp_release_sched(msk); + mptcp_release_pm(msk); sk->sk_prot->destroy(sk); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 5b21d1f1ba16..c81fe379b0f8 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -220,6 +220,7 @@ struct mptcp_pm_data { struct mptcp_addr_info remote; struct list_head anno_list; struct list_head userspace_pm_local_addr_list; + struct mptcp_pm_ops *ops; spinlock_t lock; /*protects the whole PM data */ @@ -1055,6 +1056,8 @@ void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, struct mptcp_pm_ops *mptcp_pm_find(enum mptcp_pm_type type); int mptcp_register_path_manager(struct mptcp_pm_ops *pm); void mptcp_unregister_path_manager(struct mptcp_pm_ops *pm); +int mptcp_init_pm(struct mptcp_sock *msk, struct mptcp_pm_ops *pm); +void mptcp_release_pm(struct mptcp_sock *msk); void mptcp_free_local_addr_list(struct mptcp_sock *msk); @@ -1154,6 +1157,7 @@ static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflo } void __init mptcp_pm_nl_init(void); +void __init mptcp_userspace_pm_init(void); void mptcp_pm_nl_work(struct mptcp_sock *msk); unsigned int mptcp_pm_get_add_addr_signal_max(const struct mptcp_sock *msk); unsigned int mptcp_pm_get_add_addr_accept_max(const struct mptcp_sock *msk);