From patchwork Tue Oct 22 09:14: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: 13845378 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 20E721547F5 for ; Tue, 22 Oct 2024 09:15:00 +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=1729588501; cv=none; b=qYjZLd+sHRs42r6AIvPW+6q1RZ2+SzdKg9zdZ8QbyZm6wX5WazWDHnDbXClvRV84AGosXTmxqYBJnIqYUt4nUlRdE9ltAmGkpWGxsQs3kFS2ttffVqLPMvhfirEvqkY8gFrcKBZrVGJcgLUud8Ftq8Ux/acTyEpBzRBp0XyZwy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729588501; c=relaxed/simple; bh=yU08YxXXPOAYy+D7KXFU+aECJ4un9Ws+nD95K+1p9uA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kcBX+fJJvB5c48PixiwuW6R8PMix3E3NLzm0Qj5+odkAUyuCZv+daacD9l4WhvuW3xeMf2leEbzgzsJ7XrpzioBUYPi+o/JsaMUa+PWiIMMdg2l9xl7FzK/FhG06TWXdSTUjTsUuSb5NScO/DGWsjHppmtHyb3gyb9I3xG6MMvU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z4IZMN9S; 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="Z4IZMN9S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0E8FC4CEE3; Tue, 22 Oct 2024 09:14:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729588500; bh=yU08YxXXPOAYy+D7KXFU+aECJ4un9Ws+nD95K+1p9uA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z4IZMN9SQRFuznSLXwNC90wdeSwudWOBS5zVMrvMQ6D3jN6ufASHu4swsFaLs1cFO CMR1/jLtYgwXLc0rwyKTYyZmz06+fUUx99baQSgQZV8xZrzdYrrxQV7c7kvGvIhEs7 RXzhGz8XSJiB4wMH8rKqauuLGb/I721gWYQkhzWsAWLCxQ6fP0ipByYs9n7YbOzsbr 33XDJD5Bg9EoqjRXL67iPkrtfwhXq2FeofeAyxEgXjsjT1gw+J++/Hxf1W0xwU0zRy vZn6HBkoY2iqEQIsV7zz6DPXYGw+RZYWPPlJKI3BaZMFtVD4V/+vaKp0W4PBgLEfCl 4K8N+46YWyFJQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 05/36] mptcp: add lookup_addr for userspace pm Date: Tue, 22 Oct 2024 17:14:13 +0800 Message-ID: <6d30431fd64e8c17d163ab5656838e1c3be78b97.1729588019.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 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;