From nobody Thu Nov 21 12:21:41 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 0751E82C60 for ; Thu, 7 Nov 2024 06:45:52 +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=1730961953; cv=none; b=LqyIW7e0Zxysb93yEDcQsZ20Qlx08347f1I3Vdo1r98bmZkanHHUkLT2UMGlRLY/HQob2Y3PE6RAQTuAYz568CRike9ZgVFtsNmpESCR9VwfPn0MuWLDbmM8fr5lOz+MBMR4h5DwXyE/iXqjYek8cSNRC14Qzv2v9VtfOtvXAiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730961953; c=relaxed/simple; bh=WfIZ9uToCcB1m4Rnuq5v917T8euXNkcfx3sAa9zHLSc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QdoO5FFBYi4FTfoBSWt38W0BXhWo1lAJz7g4d2wGeULfP7QgbMWsxJujXMhgDgpudlhx7jCas8BiNqYP8zlzkmH3TOCjxVueIUUyMmDBgMGEvcoO9Hop9Bqzy/U3nt/186bE8ZCiDJ4j2/uku2KSy6NbKQ6phkW8Z3puyGLyRXo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=C5RaWm9h; 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="C5RaWm9h" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A109C4CED2; Thu, 7 Nov 2024 06:45:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730961952; bh=WfIZ9uToCcB1m4Rnuq5v917T8euXNkcfx3sAa9zHLSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C5RaWm9hJ90vwiPKJN/LYnbqJHp9lPEFBZqqEtFfKvq5W+agvM59J8YqZE9JVX4VM 6gukhQVIEbbif9BiBRvJrRX89astw0LN+2xed9eGk/6sO1GsRBhRB4IVQ0ciWW2zHT cUsMCrG4NFH6N5KC0riBoe2hnOPfAY9xgU7aNi8GPqA6z3BK/1PgNfHjuZvUxdb9nB +hyCElgfeZN1ivKSfS+RmNI8W8SSxgLL1spc2h81nN+VcZbzGkKxnHkwo/WtECKmV7 xBwOZUlQ1+UTwAZILiywc5tnuNIC/ENuHtjNZhiEvxWTnbDDLt9dUDGR/1C7grANMG GslTiumREpzLA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 1/9] mptcp: add mptcp_userspace_pm_lookup_addr helper Date: Thu, 7 Nov 2024 14:45:35 +0800 Message-ID: <3e3198879157a2b94642537d95028643da257c0d.1730961809.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 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 the found address entry. This helper can be used in mptcp_userspace_pm_delete_local_addr(), mptcp_userspace_pm_set_flags(), mptcp_userspace_pm_get_local_id() and mptcp_userspace_pm_is_backup() to simplify the code. Please note that with this change now list_for_each_entry() is used in mptcp_userspace_pm_append_new_local_addr(), not list_for_each_entry_safe(), but that's OK to do so because mptcp_userspace_pm_lookup_addr() only returns an entry from the list, the list hasn't been modified here. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 71 ++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index e35178f5205f..3664f3c1572e 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -26,6 +26,19 @@ void mptcp_free_local_addr_list(struct mptcp_sock *msk) } } =20 +static struct mptcp_pm_addr_entry * +mptcp_userspace_pm_lookup_addr(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr) +{ + struct mptcp_pm_addr_entry *entry; + + list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + if (mptcp_addresses_equal(&entry->addr, addr, false)) + return entry; + } + return NULL; +} + static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *entry, bool needs_id) @@ -90,22 +103,20 @@ static int mptcp_userspace_pm_append_new_local_addr(st= ruct mptcp_sock *msk, static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *addr) { - struct mptcp_pm_addr_entry *entry, *tmp; struct sock *sk =3D (struct sock *)msk; + struct mptcp_pm_addr_entry *entry; =20 - list_for_each_entry_safe(entry, tmp, &msk->pm.userspace_pm_local_addr_lis= t, list) { - if (mptcp_addresses_equal(&entry->addr, &addr->addr, false)) { - /* TODO: a refcount is needed because the entry can - * be used multiple times (e.g. fullmesh mode). - */ - list_del_rcu(&entry->list); - sock_kfree_s(sk, entry, sizeof(*entry)); - msk->pm.local_addr_used--; - return 0; - } - } - - 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); + sock_kfree_s(sk, entry, sizeof(*entry)); + msk->pm.local_addr_used--; + return 0; } =20 static struct mptcp_pm_addr_entry * @@ -123,17 +134,12 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_soc= k *msk, unsigned int id) int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc) { - struct mptcp_pm_addr_entry *entry =3D NULL, *e, new_entry; + struct mptcp_pm_addr_entry *entry =3D NULL, new_entry; __be16 msk_sport =3D ((struct inet_sock *) inet_sk((struct sock *)msk))->inet_sport; =20 spin_lock_bh(&msk->pm.lock); - list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) { - if (mptcp_addresses_equal(&e->addr, skc, false)) { - entry =3D e; - break; - } - } + entry =3D mptcp_userspace_pm_lookup_addr(msk, skc); spin_unlock_bh(&msk->pm.lock); if (entry) return entry->addr.id; @@ -153,15 +159,11 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *= msk, struct mptcp_addr_info *skc) { struct mptcp_pm_addr_entry *entry; - bool backup =3D false; + bool backup; =20 spin_lock_bh(&msk->pm.lock); - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { - if (mptcp_addresses_equal(&entry->addr, skc, false)) { - backup =3D !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); - break; - } - } + entry =3D mptcp_userspace_pm_lookup_addr(msk, skc); + backup =3D entry && !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); spin_unlock_bh(&msk->pm.lock); =20 return backup; @@ -606,13 +608,12 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb,= struct genl_info *info) bkup =3D 1; =20 spin_lock_bh(&msk->pm.lock); - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { - if (mptcp_addresses_equal(&entry->addr, &loc.addr, false)) { - if (bkup) - entry->flags |=3D MPTCP_PM_ADDR_FLAG_BACKUP; - else - entry->flags &=3D ~MPTCP_PM_ADDR_FLAG_BACKUP; - } + entry =3D mptcp_userspace_pm_lookup_addr(msk, &loc.addr); + if (entry) { + if (bkup) + entry->flags |=3D MPTCP_PM_ADDR_FLAG_BACKUP; + else + entry->flags &=3D ~MPTCP_PM_ADDR_FLAG_BACKUP; } spin_unlock_bh(&msk->pm.lock); =20 --=20 2.45.2 From nobody Thu Nov 21 12:21:41 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 8273482C60 for ; Thu, 7 Nov 2024 06:45: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=1730961954; cv=none; b=LIFXtdIlh6Ilw7TNjd4yIzzmIV6VOS1EFP41hnTfLm8W754yZK2r1B/goQnh5xtNqQxdt8a4/0l7AstFcyY45efRGD+ne4B3VHHvcZNMw9KBOosxcmmSkxGY1mBvST9Qq/ypdbKVGzlsqvAgFs3yTkwmX+NBRnQJ8zh+uubavAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730961954; c=relaxed/simple; bh=8+gtOBUHsd1UC+C2OyLbslLF3X4b8omu0pIePHSRbLA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j8S9x6v/sxmSw9XfHjqu+nVchD23jYwwPZ9sa8L8Te7g+yRI5FF4s4hoN1+dUsm7Lrga3LyEd7xwTtrjh2IOa3kB0Kc1vLj6ParuwD15h9KuPw2X9eQsWY12zsEwxed+pGco5SRsJa9cJsQgh0OizTnljM/pXLrtkiBfxPiPdvs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=um7TSqvd; 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="um7TSqvd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 320F5C4CECC; Thu, 7 Nov 2024 06:45:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730961954; bh=8+gtOBUHsd1UC+C2OyLbslLF3X4b8omu0pIePHSRbLA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=um7TSqvdrufI0lUQSxrCymwHeqGhr3m4OjvfeLfdvKTnrxooSRIAQeddB7b+m+GoB Odot4gRwFAE/uu7lBXh6HEwtoUsqMV5OHZXfh/J4dD6wc4K1PjpOWA1WkXf5lX0Qtx jC0229tKoULItpRFOcsU9aC62R/rz4BpjY2gsH65r5dkyiRRy9abjerP6+5xPJMq7H +XaXviGSNrNK3FlCd2FXBHFmo6QxNLU/IzTa/grVgad51YTsc7wOzPHETaqVrI2AZ6 2QoJCKYf3WZ3gcRT8j552JtOpNN2+HvWhIWlT9Szlr1M0UKefPtToi/zQuG4CNn9w8 3jCgl5rIb7LkQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 2/9] mptcp: add mptcp_for_each_userspace_pm_addr macro Date: Thu, 7 Nov 2024 14:45:36 +0800 Message-ID: <445d9405c0cc633058e40f715e38b59b8729eee9.1730961809.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Similar to mptcp_for_each_subflow() macro, this patch adds a new macro mptcp_for_each_userspace_pm_addr() for userspace PM to iterate over the address entries on the local address list userspace_pm_local_addr_list of the mptcp socket. This patch doesn't change the behaviour of the code, just refactoring. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 3664f3c1572e..c99ec28c1bd5 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -8,6 +8,9 @@ #include "mib.h" #include "mptcp_pm_gen.h" =20 +#define mptcp_for_each_userspace_pm_addr(__msk, __entry) \ + list_for_each_entry(__entry, &((__msk)->pm.userspace_pm_local_addr_list),= list) + void mptcp_free_local_addr_list(struct mptcp_sock *msk) { struct mptcp_pm_addr_entry *entry, *tmp; @@ -32,7 +35,7 @@ mptcp_userspace_pm_lookup_addr(struct mptcp_sock *msk, { struct mptcp_pm_addr_entry *entry; =20 - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_userspace_pm_addr(msk, entry) { if (mptcp_addresses_equal(&entry->addr, addr, false)) return entry; } @@ -54,7 +57,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struc= t mptcp_sock *msk, bitmap_zero(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); =20 spin_lock_bh(&msk->pm.lock); - list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_userspace_pm_addr(msk, e) { addr_match =3D mptcp_addresses_equal(&e->addr, &entry->addr, true); if (addr_match && entry->addr.id =3D=3D 0 && needs_id) entry->addr.id =3D e->addr.id; @@ -124,7 +127,7 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock = *msk, unsigned int id) { struct mptcp_pm_addr_entry *entry; =20 - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_userspace_pm_addr(msk, entry) { if (entry->addr.id =3D=3D id) return entry; } @@ -659,7 +662,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, =20 lock_sock(sk); spin_lock_bh(&msk->pm.lock); - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_userspace_pm_addr(msk, entry) { if (test_bit(entry->addr.id, bitmap->map)) continue; =20 --=20 2.45.2 From nobody Thu Nov 21 12:21:41 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 A7A7282C60 for ; Thu, 7 Nov 2024 06:45: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=1730961956; cv=none; b=kXexRHoumsbVzMUu8BaKkv4Fbt2iIgDbksI9K21gCaHkMDM4buozTi94D/sB7RFXyol/OGt6C64EoVyph416JofMMpzyvm8uazJdlm/Bm7lDWLxFyUdMoKdHGh0bKmK2junWhZOyJn2xFsD3OHfgMwv76Zb8p2pVmakhFA31xFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730961956; c=relaxed/simple; bh=iF+yVEngQsM8pod0s4X8LO+fbay/FWDDzOeidkhlsCM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CHFvdn4Tcjd/JT7/xuhq6zQ69MyNtzpZE9Coln3LkyVhaek3G3ouPgunTomssoRN33P5ujpgh9LQKSQqHcxqqukZqf8y1F+1ESaVhcuoZECfCkXotGCn/+1uUE5NVm89Ikoznw1kP7B9jV+ijZdNIV7QNnDs9ZWwEUmSSvmnp6g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LPmCrIz1; 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="LPmCrIz1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C2E4C4CECC; Thu, 7 Nov 2024 06:45:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730961956; bh=iF+yVEngQsM8pod0s4X8LO+fbay/FWDDzOeidkhlsCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LPmCrIz1hqK+64d3gY9QhWckg/Awq/d6QzOmN0diEo+uvvvqVAcEnth9IzZ6EfRaP m6XBkwboGn1+9sd3uDD7YvYaHbaStxI2BP185BXuw1l9o6HqyXhfVLXBGdvxu9l+HB HLticl4ZjuISmIHdMwWlGNNHQ7rmws5W6BLzKUsRGtzNuH81dGek1bG5ROYjOsMil/ BJVxJvNNYCVkj1Rtrz8PfP/Erl09Fd5GOGS5oL6fm17eRcL4LwgkcZ3dkHsF7Qfz9H RqBZ04eieEjPKr3f7FDca+5dYxmkP1eQdPAaAekbYDAAP2wiGhFOmS4zm/LmKXPTUz cxHrY7pKorydg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 3/9] mptcp: add mptcp_userspace_pm_get_sock helper Date: Thu, 7 Nov 2024 14:45:37 +0800 Message-ID: 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Each userspace pm netlink function uses nla_get_u32() to get the msk token value, then pass it to mptcp_token_get_sock() to get the msk. Finally check whether userspace PM is selected on this msk. It makes sense to wrap them into a helper, named mptcp_userspace_pm_get_sock(), to do this. This patch doesn't change the behaviour of the code, just refactoring. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 144 +++++++++++++-------------------------- 1 file changed, 47 insertions(+), 97 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index c99ec28c1bd5..a6de837d8958 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -172,36 +172,50 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *= msk, return backup; } =20 -int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) +static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_in= fo *info) { struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; + struct mptcp_sock *msk; + + if (!token) { + GENL_SET_ERR_MSG(info, "missing required token"); + return NULL; + } + + msk =3D mptcp_token_get_sock(genl_info_net(info), nla_get_u32(token)); + if (!msk) { + NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + return NULL; + } + + if (!mptcp_pm_is_userspace(msk)) { + GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); + sock_put((struct sock *)msk); + return NULL; + } + + return msk; +} + +int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) +{ struct nlattr *addr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry addr_val; struct mptcp_sock *msk; int err =3D -EINVAL; struct sock *sk; - u32 token_val; =20 - if (!addr || !token) { - GENL_SET_ERR_MSG(info, "missing required inputs"); + if (!addr) { + GENL_SET_ERR_MSG(info, "missing required address"); return err; } =20 - token_val =3D nla_get_u32(token); - - msk =3D mptcp_token_get_sock(sock_net(skb->sk), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto announce_err; - } - err =3D mptcp_pm_parse_entry(addr, info, true, &addr_val); if (err < 0) { GENL_SET_ERR_MSG(info, "error parsing local address"); @@ -274,7 +288,6 @@ static int mptcp_userspace_pm_remove_id_zero_address(st= ruct mptcp_sock *msk, =20 int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *id =3D info->attrs[MPTCP_PM_ATTR_LOC_ID]; struct mptcp_pm_addr_entry *match; struct mptcp_pm_addr_entry *entry; @@ -282,30 +295,21 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, stru= ct genl_info *info) LIST_HEAD(free_list); int err =3D -EINVAL; struct sock *sk; - u32 token_val; u8 id_val; =20 - if (!id || !token) { - GENL_SET_ERR_MSG(info, "missing required inputs"); + if (!id) { + GENL_SET_ERR_MSG(info, "missing required ID"); return err; } =20 id_val =3D nla_get_u8(id); - token_val =3D nla_get_u32(token); =20 - msk =3D mptcp_token_get_sock(sock_net(skb->sk), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto out; - } - if (id_val =3D=3D 0) { err =3D mptcp_userspace_pm_remove_id_zero_address(msk, info); goto out; @@ -342,7 +346,6 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct= genl_info *info) int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info = *info) { struct nlattr *raddr =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry entry =3D { 0 }; struct mptcp_addr_info addr_r; @@ -350,28 +353,18 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *s= kb, struct genl_info *info) struct mptcp_sock *msk; int err =3D -EINVAL; struct sock *sk; - u32 token_val; =20 - if (!laddr || !raddr || !token) { - GENL_SET_ERR_MSG(info, "missing required inputs"); + if (!laddr || !raddr) { + GENL_SET_ERR_MSG(info, "missing required address(es)"); return err; } =20 - token_val =3D nla_get_u32(token); - - msk =3D mptcp_token_get_sock(genl_info_net(info), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto create_err; - } - err =3D mptcp_pm_parse_entry(laddr, info, true, &entry); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); @@ -474,35 +467,24 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_so= ck *msk, int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info= *info) { struct nlattr *raddr =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_addr_info addr_l; struct mptcp_addr_info addr_r; struct mptcp_sock *msk; struct sock *sk, *ssk; int err =3D -EINVAL; - u32 token_val; =20 - if (!laddr || !raddr || !token) { - GENL_SET_ERR_MSG(info, "missing required inputs"); + if (!laddr || !raddr) { + GENL_SET_ERR_MSG(info, "missing required address(es)"); return err; } =20 - token_val =3D nla_get_u32(token); - - msk =3D mptcp_token_get_sock(genl_info_net(info), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto destroy_err; - } - err =3D mptcp_pm_parse_addr(laddr, info, &addr_l); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); @@ -565,31 +547,19 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb,= struct genl_info *info) struct mptcp_pm_addr_entry loc =3D { .addr =3D { .family =3D AF_UNSPEC },= }; struct mptcp_pm_addr_entry rem =3D { .addr =3D { .family =3D AF_UNSPEC },= }; struct nlattr *attr_rem =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; - struct net *net =3D sock_net(skb->sk); struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; int ret =3D -EINVAL; struct sock *sk; - u32 token_val; u8 bkup =3D 0; =20 - token_val =3D nla_get_u32(token); - - msk =3D mptcp_token_get_sock(net, token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return ret; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "userspace PM not selected"); - goto set_flags_err; - } - ret =3D mptcp_pm_parse_entry(attr, info, false, &loc); if (ret < 0) goto set_flags_err; @@ -636,30 +606,20 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1); } *bitmap; const struct genl_info *info =3D genl_info_dump(cb); - struct net *net =3D sock_net(msg->sk); struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; - struct nlattr *token; int ret =3D -EINVAL; struct sock *sk; void *hdr; =20 bitmap =3D (struct id_bitmap *)cb->ctx; - token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; =20 - msk =3D mptcp_token_get_sock(net, nla_get_u32(token)); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return ret; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto out; - } - lock_sock(sk); spin_lock_bh(&msk->pm.lock); mptcp_for_each_userspace_pm_addr(msk, entry) { @@ -684,7 +644,6 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, release_sock(sk); ret =3D msg->len; =20 -out: sock_put(sk); return ret; } @@ -693,28 +652,19 @@ int mptcp_userspace_pm_get_addr(struct sk_buff *skb, struct genl_info *info) { struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; - struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct mptcp_pm_addr_entry addr, *entry; - struct net *net =3D sock_net(skb->sk); struct mptcp_sock *msk; struct sk_buff *msg; int ret =3D -EINVAL; struct sock *sk; void *reply; =20 - msk =3D mptcp_token_get_sock(net, nla_get_u32(token)); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return ret; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto out; - } - ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) goto out; --=20 2.45.2 From nobody Thu Nov 21 12:21:41 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 7F8CC82C60 for ; Thu, 7 Nov 2024 06:45:58 +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=1730961958; cv=none; b=uRZboMt0pmw4D5xQ6Sv8Yos2rZdWgqMqmkVjyUXHC5pcUNWfIabrvT9/y8fRvoHydsUNobj7zwu02IDjdrWU+OAW05VRLwFYM4Qw1oNzTfEFU+/JB9T5qcGSBuu2NyYB9fk2YccP8boUipjuGzkSFbU77ylftwxdwkqE2Spdtz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730961958; c=relaxed/simple; bh=/KghofNRJms4fZ0yD9aRixEb8IH1t2Ryl12v+7XBDHE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MzefRuJXjhHGLta6h4wRn/YFo54GYIDDapO2WKuhzF48Tle4liqvCKByaMYtKwVZrDE2hZP/JUJPi0FzFwQgMTja1G5s/c7vnMBTspV16bFqF8EsyoPA7YGcpXyRUtVVsCzfOoGkCJM5iu4mNHYkqjkzem2eyx22HkXg3EfLU4o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=C/mHTFS1; 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="C/mHTFS1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA02EC4CECC; Thu, 7 Nov 2024 06:45:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730961958; bh=/KghofNRJms4fZ0yD9aRixEb8IH1t2Ryl12v+7XBDHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C/mHTFS1nkjzA+Smk7BwY+Wn/sfUGBCxZZSon27iNkoRqJHxQxP4okxQtr0BfOGwO 28yLQUTgzI354ZwcGDJb3ps7+sr44QLcS2MnkguWM9Rz2gxZ6vJmhK4rXL388Gv6Rq 99JZeI3EhOYDEyga7K19ZQaMvsMH/ppipunKEouPexRfZI5EscVOOD2okT43kMIcJ4 OtxmRKiAOiOaXztOPj9J5ypTwnzZ6/WxCItlOGzzigibw4sQK8u4bCg9dQJoe5eMmt adshUN9XFc3uSqy6OCtEUiJJ/8nF+ijh8SeHLYzyJVZVSeCqsQajgMUt1Br5+mIHkw RLnbgmcUbrwLQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 4/9] mptcp: move mptcp_pm_remove_addrs into pm_userspace Date: Thu, 7 Nov 2024 14:45:38 +0800 Message-ID: <92ab4cbf71a2be676481b20c662b2f602aa346e2.1730961809.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Since mptcp_pm_remove_addrs is only called from the userspace PM, this patch moves it into pm_userspace.c. For this, lookup_subflow_by_saddr() and remove_anno_list_by_saddr() helpers need to be exported in protocol.h. Also add "mptcp_" prefix for these helpers. This patch doesn't change the behaviour of the code, just refactoring. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 45 +++++++--------------------------------- net/mptcp/pm_userspace.c | 28 +++++++++++++++++++++++++ net/mptcp/protocol.h | 4 ++++ 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 618289aac0ab..8aba7670345d 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -107,8 +107,8 @@ static void remote_address(const struct sock_common *sk= c, #endif } =20 -static bool lookup_subflow_by_saddr(const struct list_head *list, - const struct mptcp_addr_info *saddr) +bool mptcp_lookup_subflow_by_saddr(const struct list_head *list, + const struct mptcp_addr_info *saddr) { struct mptcp_subflow_context *subflow; struct mptcp_addr_info cur; @@ -1453,8 +1453,8 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, st= ruct genl_info *info) return ret; } =20 -static bool remove_anno_list_by_saddr(struct mptcp_sock *msk, - const struct mptcp_addr_info *addr) +bool mptcp_remove_anno_list_by_saddr(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr) { struct mptcp_pm_add_entry *entry; =20 @@ -1482,7 +1482,7 @@ static bool mptcp_pm_remove_anno_addr(struct mptcp_so= ck *msk, =20 list.ids[list.nr++] =3D mptcp_endp_get_local_id(msk, addr); =20 - ret =3D remove_anno_list_by_saddr(msk, addr); + ret =3D mptcp_remove_anno_list_by_saddr(msk, addr); if (ret || force) { spin_lock_bh(&msk->pm.lock); if (ret) { @@ -1526,7 +1526,7 @@ static int mptcp_nl_remove_subflow_and_signal_addr(st= ruct net *net, } =20 lock_sock(sk); - remove_subflow =3D lookup_subflow_by_saddr(&msk->conn_list, addr); + remove_subflow =3D mptcp_lookup_subflow_by_saddr(&msk->conn_list, addr); mptcp_pm_remove_anno_addr(msk, addr, remove_subflow && !(entry->flags & MPTCP_PM_ADDR_FLAG_IMPLICIT)); =20 @@ -1639,35 +1639,6 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, s= truct genl_info *info) return ret; } =20 -/* Called from the userspace PM only */ -void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_li= st) -{ - struct mptcp_rm_list alist =3D { .nr =3D 0 }; - struct mptcp_pm_addr_entry *entry; - int anno_nr =3D 0; - - list_for_each_entry(entry, rm_list, list) { - if (alist.nr >=3D MPTCP_RM_IDS_MAX) - break; - - /* only delete if either announced or matching a subflow */ - if (remove_anno_list_by_saddr(msk, &entry->addr)) - anno_nr++; - else if (!lookup_subflow_by_saddr(&msk->conn_list, - &entry->addr)) - continue; - - alist.ids[alist.nr++] =3D entry->addr.id; - } - - if (alist.nr) { - spin_lock_bh(&msk->pm.lock); - msk->pm.add_addr_signaled -=3D anno_nr; - mptcp_pm_remove_addr(msk, &alist); - spin_unlock_bh(&msk->pm.lock); - } -} - /* Called from the in-kernel PM only */ static void mptcp_pm_flush_addrs_and_subflows(struct mptcp_sock *msk, struct list_head *rm_list) @@ -1677,11 +1648,11 @@ static void mptcp_pm_flush_addrs_and_subflows(struc= t mptcp_sock *msk, =20 list_for_each_entry(entry, rm_list, list) { if (slist.nr < MPTCP_RM_IDS_MAX && - lookup_subflow_by_saddr(&msk->conn_list, &entry->addr)) + mptcp_lookup_subflow_by_saddr(&msk->conn_list, &entry->addr)) slist.ids[slist.nr++] =3D mptcp_endp_get_local_id(msk, &entry->addr); =20 if (alist.nr < MPTCP_RM_IDS_MAX && - remove_anno_list_by_saddr(msk, &entry->addr)) + mptcp_remove_anno_list_by_saddr(msk, &entry->addr)) alist.ids[alist.nr++] =3D mptcp_endp_get_local_id(msk, &entry->addr); } =20 diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index a6de837d8958..737a07f5defe 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -286,6 +286,34 @@ static int mptcp_userspace_pm_remove_id_zero_address(s= truct mptcp_sock *msk, return err; } =20 +void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_li= st) +{ + struct mptcp_rm_list alist =3D { .nr =3D 0 }; + struct mptcp_pm_addr_entry *entry; + int anno_nr =3D 0; + + list_for_each_entry(entry, rm_list, list) { + if (alist.nr >=3D MPTCP_RM_IDS_MAX) + break; + + /* only delete if either announced or matching a subflow */ + if (mptcp_remove_anno_list_by_saddr(msk, &entry->addr)) + anno_nr++; + else if (!mptcp_lookup_subflow_by_saddr(&msk->conn_list, + &entry->addr)) + continue; + + alist.ids[alist.nr++] =3D entry->addr.id; + } + + if (alist.nr) { + spin_lock_bh(&msk->pm.lock); + msk->pm.add_addr_signaled -=3D anno_nr; + mptcp_pm_remove_addr(msk, &alist); + spin_unlock_bh(&msk->pm.lock); + } +} + int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *id =3D info->attrs[MPTCP_PM_ATTR_LOC_ID]; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index b4c72a73594f..80d355c1dfb4 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1031,6 +1031,10 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk, struct mptcp_pm_add_entry * mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk, const struct mptcp_addr_info *addr); +bool mptcp_lookup_subflow_by_saddr(const struct list_head *list, + const struct mptcp_addr_info *saddr); +bool mptcp_remove_anno_list_by_saddr(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr); int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info); int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info); int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *in= fo); --=20 2.45.2 From nobody Thu Nov 21 12:21:41 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 3B54B82C60 for ; Thu, 7 Nov 2024 06:45: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=1730961960; cv=none; b=T+2n89xwMMg4phZkcwgsE/wmTt2jGYC33fOY1iPGUPBsU61MQ1PVH+FFxjR3kBbRLoiyiMUFN5n63Iyf7Byyc+BC4W/lXKB5erwqGp+1lpEmSTs7y04BKZHFfXyQlJy8H5FJcKQg/v03RWPiAzWEJ6EsI6w0tZmpJXV1z8azNFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730961960; c=relaxed/simple; bh=N1xNWmKoQVDk2+59cslVN+pSL5uLlVnEQqBsGqycZJ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D3HUp4jBxdHanR356YMrW3ml1jZKkbJk3tidyJAKyyBBKyeuwFT1r7UEvUqfZuGpL92sPTsbnh/UJc0nZXkD96VMkBizwe9JJOA6QHO5aXhMFhFA7zNbyIeSaR1rK5nju/NejPudH7rQ570oZuDS/pbEZeGEFqw27H1lw++NC3Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l0vG9yN+; 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="l0vG9yN+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B41EBC4CECC; Thu, 7 Nov 2024 06:45:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730961959; bh=N1xNWmKoQVDk2+59cslVN+pSL5uLlVnEQqBsGqycZJ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l0vG9yN+WNIUjkJNMmQ4vVRk2g9CpvWYumtoZly3/3pdOjyHOR7JhX0vKgpvIvZUE JnA1+yN5KxIciGQaIpD27qsP4YeQ6ku1PB3SUwiPy6hY4ppdddZ73GsWY9TVld6tCP hoO+Fvzt6GhC7yxYfLXKa4k2+8EVgP+AWJGxhoqo2pY0lUgsigz+6RHZMdm2gJxLRu mTSoZTZdf+Xh6CrbPwpaVExaRbSHrRgU/rY+pvJLvnmM9+Omp96mbUOlYI+kTeMMnq kWiAk98cawJu3ObQLryS3t2rOhvGJChSvu7jSkwK0nMHcHO82SMQ8ywaQOw4IA5DEn EpOlMzkG1th8Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 5/9] mptcp: drop free_list for deleting entries Date: Thu, 7 Nov 2024 14:45:39 +0800 Message-ID: <68e7a3deaea7319b4fb36b9ee8a6073a8bbfa37d.1730961810.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang mptcp_pm_remove_addrs() actually only deletes one address, which does not match its name. This patch renames it to mptcp_pm_remove_addr_entry() and changes the parameter "rm_list" to "entry". With the help of mptcp_pm_remove_addr_entry(), it's no longer necessary to move the entry to be deleted to free_list and then traverse the list to delete the entry, which is not allowed in BPF. The entry can be directly deleted through list_del_rcu() and sock_kfree_s() now. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 33 ++++++++++++--------------------- net/mptcp/protocol.h | 3 ++- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 737a07f5defe..a98da9a44bfa 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -286,26 +286,21 @@ static int mptcp_userspace_pm_remove_id_zero_address(= struct mptcp_sock *msk, return err; } =20 -void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_li= st) +void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *entry) { struct mptcp_rm_list alist =3D { .nr =3D 0 }; - struct mptcp_pm_addr_entry *entry; int anno_nr =3D 0; =20 - list_for_each_entry(entry, rm_list, list) { - if (alist.nr >=3D MPTCP_RM_IDS_MAX) - break; - - /* only delete if either announced or matching a subflow */ - if (mptcp_remove_anno_list_by_saddr(msk, &entry->addr)) - anno_nr++; - else if (!mptcp_lookup_subflow_by_saddr(&msk->conn_list, - &entry->addr)) - continue; + /* only delete if either announced or matching a subflow */ + if (mptcp_remove_anno_list_by_saddr(msk, &entry->addr)) + anno_nr++; + else if (!mptcp_lookup_subflow_by_saddr(&msk->conn_list, &entry->addr)) + goto out; =20 - alist.ids[alist.nr++] =3D entry->addr.id; - } + alist.ids[alist.nr++] =3D entry->addr.id; =20 +out: if (alist.nr) { spin_lock_bh(&msk->pm.lock); msk->pm.add_addr_signaled -=3D anno_nr; @@ -318,9 +313,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct= genl_info *info) { struct nlattr *id =3D info->attrs[MPTCP_PM_ATTR_LOC_ID]; struct mptcp_pm_addr_entry *match; - struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; - LIST_HEAD(free_list); int err =3D -EINVAL; struct sock *sk; u8 id_val; @@ -354,16 +347,14 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, stru= ct genl_info *info) goto out; } =20 - list_move(&match->list, &free_list); + list_del_rcu(&match->list); spin_unlock_bh(&msk->pm.lock); =20 - mptcp_pm_remove_addrs(msk, &free_list); + mptcp_pm_remove_addr_entry(msk, match); =20 release_sock(sk); =20 - list_for_each_entry_safe(match, entry, &free_list, list) { - sock_kfree_s(sk, match, sizeof(*match)); - } + sock_kfree_s(sk, match, sizeof(*match)); =20 err =3D 0; out: diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 80d355c1dfb4..19a811220621 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1042,7 +1042,8 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, bool echo); int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_lis= t *rm_list); -void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_li= st); +void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *entry); =20 void mptcp_free_local_addr_list(struct mptcp_sock *msk); =20 --=20 2.45.2 From nobody Thu Nov 21 12:21:41 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 04F5482C60 for ; Thu, 7 Nov 2024 06:46: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=1730961962; cv=none; b=BcS+6np4gAo7Ivt+0icb2lgFQFQ08D+o3Q9MkJcqCA9I0tA934HFZJBdA/PaWE0hqcxfa6Qb/k0gaQ6s35mu7sPSD8bB27noXJoevJZ1fEv8hFWHoDsIfExfRJ9iJyyxa+RHj8GOJdcGeM+PJzEbJG+X82xmK9e0l2NbU+ZZYHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730961962; c=relaxed/simple; bh=KNLyy3WOxdQ4fKinaki2JR9AWUseKrMcP6S6KdqA1IM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VolcbD5M+ewzzBE7ocy6THMBLmKGRuiRGb99OU6XEkXU8DkEmawVEwZn1tbVyK6DZW+2LgSnA99AAA3ydJ2oKEUHnxywvbHGawXW5WF5sRJeVZmgZe5LHl0SdJ25v5/8q6QQrXbUKNhF+QCkDZiTIrVz/FtTVej5BpgN6l2dagk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bYvPTX3y; 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="bYvPTX3y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 747B1C4CECC; Thu, 7 Nov 2024 06:46:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730961961; bh=KNLyy3WOxdQ4fKinaki2JR9AWUseKrMcP6S6KdqA1IM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bYvPTX3yK8mqMeKL6oPjgqxPswFuAeZGF1ukRSr1HVnAJGz2Kt+UM7Wv5TpGOf7ah EAQJtetVAjAfRMHK7o0hd9M2L5Np0HrRDVcYu3yoIvEbZMJ79PjXyiwUUVuUT0RCrB ds1rB1NIaSlFTCAsA4uqVieI/0R1IIUUnHuikWaQcB3LXwmyzJk8uJ31O1eqCc6Y/7 R6/qb+4e6rveIft16kpZKLZvsKhobtnARUFmZZiwuo7gDTeV4AHhVmh4zkhD/qPV7X 4jpFQLJwPY9hB4hn8Wgy2J6X6BwUH/pLHhZmd4Pew8/rykv4HthRwiW7OT8u/4kBPi 73O7bqwZ4fhmA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 6/9] mptcp: use mptcp_pm_local in pm_netlink only Date: Thu, 7 Nov 2024 14:45:40 +0800 Message-ID: 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang struct mptcp_pm_local is used in pm_netlink to reduce memory usage, but it has less effect in pm_userspace because userspace pm doesn't use an array of struct mptcp_pm_addr_entry type. So this patch moves struct mptcp_pm_local to pm_netlink and restores the use of mptcp_pm_addr_entry type parameters in __mptcp_subflow_connect(). In this case, only one "struct mptcp_pm_addr_entry" is needed, that's not reserving too much memory. This patch makes the path manager code simpler, and easier to implement the BPF path manager. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 26 ++++++++++++++++++++++---- net/mptcp/pm_userspace.c | 7 +------ net/mptcp/protocol.h | 8 +------- net/mptcp/subflow.c | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 8aba7670345d..00911fae5d88 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -40,6 +40,12 @@ struct pm_nl_pernet { DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); }; =20 +struct mptcp_pm_local { + struct mptcp_addr_info addr; + u8 flags; + int ifindex; +}; + #define MPTCP_PM_ADDR_MAX 8 #define ADD_ADDR_RETRANS_MAX 3 =20 @@ -638,8 +644,14 @@ static void mptcp_pm_create_subflow_or_signal_addr(str= uct mptcp_sock *msk) continue; =20 spin_unlock_bh(&msk->pm.lock); - for (i =3D 0; i < nr; i++) - __mptcp_subflow_connect(sk, &local, &addrs[i]); + for (i =3D 0; i < nr; i++) { + struct mptcp_pm_addr_entry entry =3D { 0 }; + + entry.addr =3D local.addr; + entry.flags =3D local.flags; + entry.ifindex =3D local.ifindex; + __mptcp_subflow_connect(sk, &entry, &addrs[i]); + } spin_lock_bh(&msk->pm.lock); } mptcp_pm_nl_check_work_pending(msk); @@ -755,9 +767,15 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp= _sock *msk) return; =20 spin_unlock_bh(&msk->pm.lock); - for (i =3D 0; i < nr; i++) - if (__mptcp_subflow_connect(sk, &locals[i], &remote) =3D=3D 0) + for (i =3D 0; i < nr; i++) { + struct mptcp_pm_addr_entry entry =3D { 0 }; + + entry.addr =3D locals[i].addr; + entry.flags =3D locals[i].flags; + entry.ifindex =3D locals[i].ifindex; + if (__mptcp_subflow_connect(sk, &entry, &remote) =3D=3D 0) sf_created =3D true; + } spin_lock_bh(&msk->pm.lock); =20 if (sf_created) { diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index a98da9a44bfa..db09350b5022 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -368,7 +368,6 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb= , struct genl_info *info) struct nlattr *laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry entry =3D { 0 }; struct mptcp_addr_info addr_r; - struct mptcp_pm_local local; struct mptcp_sock *msk; int err =3D -EINVAL; struct sock *sk; @@ -415,12 +414,8 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *sk= b, struct genl_info *info) goto create_err; } =20 - local.addr =3D entry.addr; - local.flags =3D entry.flags; - local.ifindex =3D entry.ifindex; - lock_sock(sk); - err =3D __mptcp_subflow_connect(sk, &local, &addr_r); + err =3D __mptcp_subflow_connect(sk, &entry, &addr_r); release_sock(sk); =20 spin_lock_bh(&msk->pm.lock); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 19a811220621..775ac2fd6854 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -236,12 +236,6 @@ struct mptcp_pm_data { struct mptcp_rm_list rm_list_rx; }; =20 -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; @@ -736,7 +730,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); =20 /* 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_en= try *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 } =20 -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_en= try *local, const struct mptcp_addr_info *remote) { struct mptcp_sock *msk =3D mptcp_sk(sk); --=20 2.45.2 From nobody Thu Nov 21 12:21:41 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 EB53918FDBC for ; Thu, 7 Nov 2024 06:46:03 +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=1730961964; cv=none; b=Fi1Z9qluvaW9mCQ+YVeJvyOINDnY5/utG5N8KrajxJXchMpogjUt4EOakbQe/N2BaOCALKgZDXTc0c+NuaXyyPNRTujrwHlnbF94mXR0schPCEXYUGOO7L1MDLFhX3NAinsvhzj10m3I2Hy3rT9be2QcN2cif20joJgfX+cEZBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730961964; c=relaxed/simple; bh=5o/RexNH5o9ejy7sjm73FIti2A508JVxELeTk+Z/j54=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UvcAEkcR0vvxU2trItib3XcXr1Q1Lg/d3bQbUNkJ/0P9N5PatBEuCYtFXibmEvUAo/PaxdRpoLETaP/ze7fcJ+vDu7mGIacKbyV7LNNsl5b5pvYFzPQ12RrDcVhR6ZmLdtnJhbSXQ90EeNsNCvUklGoPVIXlAj+4F+goG2MxBX0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WcnRxZql; 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="WcnRxZql" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52815C4CECD; Thu, 7 Nov 2024 06:46:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730961963; bh=5o/RexNH5o9ejy7sjm73FIti2A508JVxELeTk+Z/j54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WcnRxZqlc5U6bKu6kmJErUHaGsu8E1yGFNkERIj9zo39v+Ll0O/xNv1x4k4QYvvji CK8cWe2sK0S6BBpf/N/bowiEa23/IqkwraozkkmZY3LJCG9TBM47RmWb5kkTsFbTmt mFgPIaZvFPKYkLX64f8utAIE9wsLzklpkl4/qZoP0IRxheHV8opv4jvUFhJltYplCm QAjqSMdJ0QqH4/1iHbJ40y7agW9iaWdAn5nT/9Cda/epzUwzDd7aaP1StGKfCdgQmJ EJIERqy2VBxD3Rs90j692xeXohN3ZpFKhbrN9kDeWtJ9idbnFlokEbMCAqf7NiuBcy ggRSlq2c+9QfA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 7/9] mptcp: drop struct mptcp_pm_add_entry Date: Thu, 7 Nov 2024 14:45:41 +0800 Message-ID: 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Although this increases the size of the structure even more, but that's OK to do so because it is not used in an array. 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 00911fae5d88..3f3eaa18ffae 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -18,14 +18,6 @@ =20 static int pm_nl_pernet_id; =20 -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; @@ -257,11 +249,11 @@ bool mptcp_pm_nl_check_work_pending(struct mptcp_sock= *msk) return true; } =20 -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; =20 lockdep_assert_held(&msk->pm.lock); =20 @@ -275,7 +267,7 @@ mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock= *msk, =20 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 =3D false; =20 @@ -296,7 +288,7 @@ bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk= , const struct sock *sk) =20 static void mptcp_pm_add_timer(struct timer_list *timer) { - struct mptcp_pm_add_entry *entry =3D from_timer(entry, timer, add_timer); + struct mptcp_pm_addr_entry *entry =3D from_timer(entry, timer, add_timer); struct mptcp_sock *msk =3D entry->sock; struct sock *sk =3D (struct sock *)msk; =20 @@ -338,11 +330,11 @@ static void mptcp_pm_add_timer(struct timer_list *tim= er) __sock_put(sk); } =20 -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 =3D (struct sock *)msk; struct timer_list *add_timer =3D NULL; =20 @@ -366,7 +358,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 =3D NULL; + struct mptcp_pm_addr_entry *add_entry =3D NULL; struct sock *sk =3D (struct sock *)msk; struct net *net =3D sock_net(sk); =20 @@ -402,7 +394,7 @@ bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, =20 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 =3D (struct sock *)msk; LIST_HEAD(free_list); =20 @@ -1474,7 +1466,7 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, st= ruct genl_info *info) bool mptcp_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; =20 entry =3D mptcp_pm_del_add_timer(msk, addr, false); if (entry) { diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 775ac2fd6854..1414e79564c7 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -239,9 +239,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; + }; + }; }; =20 struct mptcp_data_frag { @@ -1019,10 +1029,10 @@ bool mptcp_pm_alloc_anno_list(struct mptcp_sock *ms= k, 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); bool mptcp_lookup_subflow_by_saddr(const struct list_head *list, --=20 2.45.2 From nobody Thu Nov 21 12:21:41 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 7502C18FDBC for ; Thu, 7 Nov 2024 06:46:05 +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=1730961965; cv=none; b=CCW3RUWmPhWyhUAL1fzp1nrSkY2fNHxNeO87NkENNwD+f8bu7gygdD6ndKTIArYbwOvLm7Ok/PDdoWa3ZjOakVENVnqDseaRbnLk2EWeaV4/WWWOHyjpf5oGdlEdgJsY06ec30ihGQ2sUvAjlhW4BdnNY/RryobnEKGrDziRHtI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730961965; c=relaxed/simple; bh=dWVsqhcH0va8FW2f1KpI/2MBZhGeQnfXKP4CDUVhL6w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=njDDVfeDdqYkASHeWoE+XDICQNzMKbHOOlcW5D/dj3jQLM9q45WpCJQMEjrnApkjQLtNOyZhDrStFnMFiSZjElVBFj3X8/RUuq6X4NPptYjSyjKDQ4/tFb1Uz5/FksBqjlpKpzzOfFxShUmxz/qBJi/4JvB5zZw2wu1WaJ31aW4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eCtQwj2L; 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="eCtQwj2L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27FEDC4CECD; Thu, 7 Nov 2024 06:46:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730961965; bh=dWVsqhcH0va8FW2f1KpI/2MBZhGeQnfXKP4CDUVhL6w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eCtQwj2L3BhElD1DofU21TNazyweb4H5v+1dBq4aW0i79aK+CY055rZhW6DMff3ff 9uhtoF3OJccbV7u+9WgWDhzK5xJc2M7ie4nOQbM/NMcXpwcJMa/skqWwxLnCbXlQPU TcG9ApNYwMhc1a7rZH+Lkx9awXUUtbS956DeLLoPpmvPwv1BNPi1a0t1KlcBsfklN0 Ola09iRElJe0ODmJOLFoWP8nG8c8M+fmIjWv/obCPoKRTzJwxKkX+ABiczXTX9uvSm Odsz2sN/IRZTprdupeQ5zb3b2DJJuRZOsX48hLrJDZQyOLxHRG3EEr+qyCk+bZEETw D5AigqAoD8W5Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 8/9] mptcp: change local addr type of subflow_destroy Date: Thu, 7 Nov 2024 14:45:42 +0800 Message-ID: <633182eea41112b834de2f4229a8c917deca82f3.1730961810.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Generally, in the path manager interfaces, the local address is defined as an mptcp_pm_addr_entry type address, while the remote address is defined as an mptcp_addr_info type one: (struct mptcp_pm_addr_entry *local, struct mptcp_addr_info *remote) But subflow_destroy() interface uses two mptcp_addr_info type parameters. This patch changes the first one to mptcp_pm_addr_entry type and use helper mptcp_pm_parse_entry() to parse it instead of using mptcp_pm_parse_addr(). This patch doesn't change the behaviour of the code, just refactoring. Signed-off-by: Geliang Tang --- 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 db09350b5022..07e0c7259494 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -482,7 +482,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *sk= b, struct genl_info *info { struct nlattr *raddr =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; struct nlattr *laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; - struct mptcp_addr_info addr_l; + struct mptcp_pm_addr_entry addr_l; struct mptcp_addr_info addr_r; struct mptcp_sock *msk; struct sock *sk, *ssk; @@ -499,7 +499,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *sk= b, struct genl_info *info =20 sk =3D (struct sock *)msk; =20 - err =3D mptcp_pm_parse_addr(laddr, info, &addr_l); + err =3D mptcp_pm_parse_entry(laddr, info, true, &addr_l); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); goto destroy_err; @@ -512,35 +512,34 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *= skb, struct genl_info *info } =20 #if IS_ENABLED(CONFIG_MPTCP_IPV6) - if (addr_l.family =3D=3D AF_INET && ipv6_addr_v4mapped(&addr_r.addr6)) { - ipv6_addr_set_v4mapped(addr_l.addr.s_addr, &addr_l.addr6); - addr_l.family =3D AF_INET6; + if (addr_l.addr.family =3D=3D AF_INET && ipv6_addr_v4mapped(&addr_r.addr6= )) { + ipv6_addr_set_v4mapped(addr_l.addr.addr.s_addr, &addr_l.addr.addr6); + addr_l.addr.family =3D AF_INET6; } - if (addr_r.family =3D=3D AF_INET && ipv6_addr_v4mapped(&addr_l.addr6)) { - ipv6_addr_set_v4mapped(addr_r.addr.s_addr, &addr_r.addr6); + if (addr_r.family =3D=3D AF_INET && ipv6_addr_v4mapped(&addr_l.addr.addr6= )) { + ipv6_addr_set_v4mapped(addr_r.addr.s_addr, &addr_l.addr.addr6); addr_r.family =3D AF_INET6; } #endif - if (addr_l.family !=3D addr_r.family) { + if (addr_l.addr.family !=3D addr_r.family) { GENL_SET_ERR_MSG(info, "address families do not match"); err =3D -EINVAL; goto destroy_err; } =20 - if (!addr_l.port || !addr_r.port) { + if (!addr_l.addr.port || !addr_r.port) { GENL_SET_ERR_MSG(info, "missing local or remote port"); err =3D -EINVAL; goto destroy_err; } =20 lock_sock(sk); - ssk =3D mptcp_nl_find_ssk(msk, &addr_l, &addr_r); + ssk =3D mptcp_nl_find_ssk(msk, &addr_l.addr, &addr_r); if (ssk) { struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(ssk); - struct mptcp_pm_addr_entry entry =3D { .addr =3D addr_l }; =20 spin_lock_bh(&msk->pm.lock); - mptcp_userspace_pm_delete_local_addr(msk, &entry); + mptcp_userspace_pm_delete_local_addr(msk, &addr_l); spin_unlock_bh(&msk->pm.lock); mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); mptcp_close_ssk(sk, ssk, subflow); --=20 2.45.2 From nobody Thu Nov 21 12:21:41 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 8ADFD18FDBC for ; Thu, 7 Nov 2024 06:46:07 +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=1730961967; cv=none; b=cg0okBwQMC4jr/qY93Ih8KDAUSpcrp4lpRAiJ9hmytqgphx8Js3ex/YBr2DEA9c1WAVl+AYXt/OYRr7RzKns/Wqlgj7+6IdGNjHb3KQKBHsPoDHNgck+e0R1TpNZYmAiE9encAoPVAdFhTyiL/cMpqXcvLgUzM5WOfM6k1Ibs3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730961967; c=relaxed/simple; bh=4G7vkWbUjhcSLDVJQOpc7SWXGApXZs5Ohe/M3yBF87k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oJvk5TKC6KThody8TbNJdwEIvCLKG9YR5XTkM0tquTCrp/HJeI906zF33sjw52WL+9XiT8H+K92n3UfQ4lMycLAPnNPjNGpDuCOwUOnuKkuHeEr7tmIcfbj7vU6bWbK1eu7pBtdBgglUDWcjw6K68nzjL/RH1BZkMfUGgVSRmGI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aaDGT1zJ; 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="aaDGT1zJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC221C4CECC; Thu, 7 Nov 2024 06:46:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730961967; bh=4G7vkWbUjhcSLDVJQOpc7SWXGApXZs5Ohe/M3yBF87k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aaDGT1zJZlP7kxW3nG1EgkMWHQkYMqDQPzSCFzjtmIv/1zRxKVzsakbFET74Akqrp st93fkpYO7sZgAKlRjMxkqoEVCHIqpXOghY4gQpYMh0U4RM36dmocgfUsN117GxvOu EWlpfn5HbwtRjYew4/355Nz55LbOvkFcG8YrXpRxwjNRQ99gZSlkl+WPWKKGjOS62V T/zNA8CuyofX6QqnKTj4OhL0Jc+aNd6EnzPSJcHlwrgumCjml6jNgX1QVsDpnIdrMt DYSutD3PbdbufQFLPPFyEsVq5JXLtN7jwv+G9xw/4iLC9qPLnkneEOqBcfWgTqYhCU ZFmQP5w+YJLDA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 9/9] mptcp: drop useless "err = 0" in subflow_destroy Date: Thu, 7 Nov 2024 14:45:43 +0800 Message-ID: <6606e2c5b8b3536cad35baf722175a932242d820.1730961810.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Upon successful return, mptcp_pm_parse_addr() returns 0. There is no need to set "err =3D 0" after this. So after mptcp_nl_find_ssk() returns, just need to set "err =3D -ESRCH", then release and free msk socket if it returns NULL. Also, no need to define the veriable "subflow" in subflow_destroy(), use mptcp_subflow_ctx(ssk) directly. This patch doesn't change the behaviour of the code, just refactoring. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 07e0c7259494..8545212f023e 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -535,19 +535,18 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *= skb, struct genl_info *info =20 lock_sock(sk); ssk =3D mptcp_nl_find_ssk(msk, &addr_l.addr, &addr_r); - if (ssk) { - struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(ssk); - - spin_lock_bh(&msk->pm.lock); - mptcp_userspace_pm_delete_local_addr(msk, &addr_l); - spin_unlock_bh(&msk->pm.lock); - mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); - mptcp_close_ssk(sk, ssk, subflow); - MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW); - err =3D 0; - } else { + if (!ssk) { err =3D -ESRCH; + release_sock(sk); + goto destroy_err; } + + spin_lock_bh(&msk->pm.lock); + mptcp_userspace_pm_delete_local_addr(msk, &addr_l); + spin_unlock_bh(&msk->pm.lock); + mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); + mptcp_close_ssk(sk, ssk, mptcp_subflow_ctx(ssk)); + MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW); release_sock(sk); =20 destroy_err: --=20 2.45.2