From nobody Sun Dec 22 08:40:51 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AE591D0B9E for ; Wed, 2 Oct 2024 15:02:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881331; cv=none; b=I1Fm0RHYphax7O4QoWIkw6BEbeFpMaGTIczvGuYdj0+pTJQozyN5iPFV7j/ZZpAjalCRdzH44oFBNYdvWQbdBJRDf7wvdzmcsYl3kNOtGeRxFgp1iV4NFNOxCxpZlJSeuwaWrIVZXQuqWENNP0RAcKEA9QBeKoZfW25zXDtIFNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881331; c=relaxed/simple; bh=z2yRi7K6XCEsqHp3xSXisf2GpuQFdeedQm9+CyqQ35c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X2kH3CDy1LF6UXBQbm7zymlVnx/fxXwgVJgCyN4X8UNsQNufgPa1iAsW6V2ivCiAYhdgIUlY9Bv6zLCyY8A7UYWBDt+F4tz6Z2ZRP9lSmwENxFs6ENTACsgb9Ceoo8vuZ5UrhVczno7bRcKk+vxquH05EYPO6nUV1HqfzZVrj/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GpLrHZy0; 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="GpLrHZy0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38ACAC4CEC2; Wed, 2 Oct 2024 15:02:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727881331; bh=z2yRi7K6XCEsqHp3xSXisf2GpuQFdeedQm9+CyqQ35c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GpLrHZy0VwpfuvJiphYM3a7d1KrNi/KSozD5lilSiADxXGuRTUz8tSa781OOj7u8H qdaxLLz5DK9hJ8tZMAMyJdHfTYK0F6b2GNzo+KBT7VVmFD5EyF/2gFukdbK+oDYJRO qq7SUYSscj95nm9NYQePuPPfIESpbkGGgZ/xwa3Hb+yZ1RXTrkGbUul4VjBHsWITYx a77PF+jmQIKLdh44cLSokkRT7uyUqDcwdfALVMx/+wniHjgoLdyf7nvX0uNTxh6U9Z d+CLlmpw9k9m5JnQ/T68sFCYIixDutYW6jF744ZRwf7kSbvfm27wbV3XTsnxqYyXrf gNH0TJtWiiV+Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 4/9] mptcp: add lookup_addr for userspace pm Date: Wed, 2 Oct 2024 23:01:54 +0800 Message-ID: <17072ea6d29ff84bc2c2fe1a93cc5aa4a03c214d.1727881073.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 add30ea72c6b..7f62a45bae76 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) } } =20 +static struct mptcp_pm_addr_entry * +mptcp_userspace_pm_lookup_addr(struct mptcp_sock *msk, const struct mptcp_= addr_info *addr) +{ + struct mptcp_pm_addr_entry *entry, *tmp; + + list_for_each_entry_safe(entry, tmp, &msk->pm.userspace_pm_local_addr_lis= t, list) { + if (mptcp_addresses_equal(&entry->addr, addr, false)) + return entry; + } + return NULL; +} + static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *entry, bool needs_id) @@ -90,21 +102,19 @@ static int mptcp_userspace_pm_append_new_local_addr(st= ruct mptcp_sock *msk, static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *addr) { - struct mptcp_pm_addr_entry *entry, *tmp; - - list_for_each_entry_safe(entry, tmp, &msk->pm.userspace_pm_local_addr_lis= t, list) { - if (mptcp_addresses_equal(&entry->addr, &addr->addr, false)) { - /* TODO: a refcount is needed because the entry can - * be used multiple times (e.g. fullmesh mode). - */ - list_del_rcu(&entry->list); - kfree(entry); - msk->pm.local_addr_used--; - return 0; - } - } + struct mptcp_pm_addr_entry *entry; =20 - return -EINVAL; + entry =3D 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); + kfree(entry); + msk->pm.local_addr_used--; + return 0; } =20 static struct mptcp_pm_addr_entry * @@ -122,17 +132,12 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_soc= k *msk, unsigned int id) int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc) { - struct mptcp_pm_addr_entry *entry =3D NULL, *e, new_entry; + struct mptcp_pm_addr_entry *entry =3D NULL, new_entry; __be16 msk_sport =3D ((struct inet_sock *) inet_sk((struct sock *)msk))->inet_sport; =20 spin_lock_bh(&msk->pm.lock); - list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) { - if (mptcp_addresses_equal(&e->addr, skc, false)) { - entry =3D e; - break; - } - } + entry =3D mptcp_userspace_pm_lookup_addr(msk, skc); spin_unlock_bh(&msk->pm.lock); if (entry) return entry->addr.id; @@ -155,12 +160,9 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *m= sk, bool backup =3D false; =20 spin_lock_bh(&msk->pm.lock); - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { - if (mptcp_addresses_equal(&entry->addr, skc, false)) { - backup =3D !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); - break; - } - } + entry =3D mptcp_userspace_pm_lookup_addr(msk, skc); + if (entry) + backup =3D !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); spin_unlock_bh(&msk->pm.lock); =20 return backup; --=20 2.43.0