From nobody Sun Dec 22 03:15:44 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 D0B621A0700 for ; Thu, 5 Dec 2024 07:15: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=1733382910; cv=none; b=bGixLZbl/JqhxzQBegUichXHqduIZUmPWmcsR0XQ31GONIy9647PxF9yUHLwlygOtq9/baZWGpJ37wxod5oZ+H+dymFRa3zmhicZu1Fr4jsgJuYUeFOTIHP3kjT9byY0Z+nb3J95NRxByDnkD7zh2NvPH6qwfPDhoG3nDORqREE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733382910; c=relaxed/simple; bh=WfIZ9uToCcB1m4Rnuq5v917T8euXNkcfx3sAa9zHLSc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fv8MaeSz+GH8RlGwaArLPdIE+u8j7SoKxk7TKWt56Bg65OWJxZY3axIaLUkI8CecAfdegiPl813itch4VgLsCFgiUk6l3u8du8VY9hgAJ/AqbI2NGQHNPWNBIcUZzvmxAmjThyz5QJWFTJzvpj3/O8pIG7ntYIj4Cuw01EXYZ50= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nx0og/rj; 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="nx0og/rj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35650C4CEDF; Thu, 5 Dec 2024 07:15:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733382910; bh=WfIZ9uToCcB1m4Rnuq5v917T8euXNkcfx3sAa9zHLSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nx0og/rjRCdt0Q4KKctqJtPv5CXI2feAJLxpdgB+jWoXXxkIQ4i3GlTKn8O5r4yuX lrh4MfyxqRmw+iv3/YP67FhMeh1FerVlz7sHGnf0CzHfLp1f+89eS2ZgTssh8b7tHL yREkiflvbgT/C1VuFgQliMyrxCP0rNRejBnRf0Juh9kjBX1r33t8gOa9Jrir9RyzOo 8Fj1Pvdc1/yAcPbi8MI4suzRXN/mY8AWD4nZIWJyHZ9Np7eQOk7Y4mlGhrlSWyPrDP EF8lYiQpueSvWthj9ZhOf5mN4BfipeMUEOlDkL7XiUDxanQxut9ubWYboMQOO29B2g 8zUb0yB4dhrpQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 1/7] mptcp: add mptcp_userspace_pm_lookup_addr helper Date: Thu, 5 Dec 2024 15:14:53 +0800 Message-ID: <5af3847288ab1f0ae5906add64855d54e2435cc2.1733382222.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 Reviewed-by: Matthieu Baerts (NGI0) --- 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 Sun Dec 22 03:15:44 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 A21771AD9F9 for ; Thu, 5 Dec 2024 07:15: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=1733382912; cv=none; b=b7GdRlApvatB7CqgYe4Jpq2KJcTRyhrMuHi+dOaq8WxVp1HZ0zLSPqJQGzGBJHWeRTCGrS52p4DSLLfvXa4asLO4yeK4g+tVxe7MsovBEYYg8tjWI+al/WVq5mKdfoi0JbKQKjOFV2hw9Pp5tWEL9aGgDnNYx3UgjBB20sp3YE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733382912; c=relaxed/simple; bh=8+gtOBUHsd1UC+C2OyLbslLF3X4b8omu0pIePHSRbLA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FNkD53wnDwNugAJxZ7Wmtdmrf4PMlWx2uxoqj7UTdHiPbMeUBcDRrWrlAwF4bEr8fhr6xazGc8wQjUK6LnaPy5FR/hz/7dW+NBxhCb5BAp5xQUSUwzRAAc14/TyX/Quru+YviO+RfCNgC7bGY0dFAJC5H1afLWrCVnTw+qawUwI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VwLP024d; 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="VwLP024d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F4BAC4CED1; Thu, 5 Dec 2024 07:15:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733382912; bh=8+gtOBUHsd1UC+C2OyLbslLF3X4b8omu0pIePHSRbLA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VwLP024dNc52I7JO+aiElVYOL5Lb+i7v+dB0saiSLwaQe7Qt9R17uRocGBfMDRRgV G9xUqxJ4MSZxBMs3yLvj4xU77Vb6dpjmpo6tYbYsJY1ohT1m8VK1rFdnQZmd1O90sn jet8hO4klWcszuwEHm6fM32X7GypPwTtLv3kN2iMEXVBT6MCyUI1KU66QtLN9frTwm Q0KWu8vUaQug7ISr2Z8E7F6vGguFe60nJvN37VeKFPL5DSAER5ngjp7UOhhkBaahLT pe30SsgEwDtMuVti7L1Cf+lHkIEOVCez/j5zjsjdbz8mTVwzb3mw3m6mGrFxCzIizZ I9ntHPtvKUv8Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 2/7] mptcp: add mptcp_for_each_userspace_pm_addr macro Date: Thu, 5 Dec 2024 15:14:54 +0800 Message-ID: <9b4d4aa521fc94ce45b2cfa66ec4c94816f2fdc0.1733382223.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 Reviewed-by: Matthieu Baerts (NGI0) --- 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 Sun Dec 22 03:15:44 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 8CC7533987 for ; Thu, 5 Dec 2024 07:15: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=1733382914; cv=none; b=PalIE2qjXZpp+tTPTNEOJEkcvwQbHWDBhVkuFXxHILn7pTJ88bOP0Cwi678yLJUxLftRO1mDkSROHU8jvHO1Z72eO6kZ9bYzQneg868idQuGARi13FQKn0wpqSJiM/cGUJLJxuXM+fK94tlan0NDX7ky649/ldGQYrqM3rXJfhw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733382914; c=relaxed/simple; bh=iF+yVEngQsM8pod0s4X8LO+fbay/FWDDzOeidkhlsCM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aWIhcOrbWO5/1H18QkZYRsbD5Bfld4A2Erp6zJ6F4Ei0B73GOVO72lcSPZi9+umQt7ZD2D1BlgMqwkuwu0y38Py9gcIgReTVhPa+/ne9G83eAyNfqdWT/NReo6wBqXni0WFWNMrt2ng+zs3dNRS8TMkcQ0TuUvrew3nIlELBAHM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rtrAKsPf; 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="rtrAKsPf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCA3AC4CED1; Thu, 5 Dec 2024 07:15:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733382914; bh=iF+yVEngQsM8pod0s4X8LO+fbay/FWDDzOeidkhlsCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rtrAKsPfM6SnDLcey5kL1QrrTq0c7bjdwZxHmh3F0EDqw97yRl7XjssNhS2tK7IyM nqqlzPEfTiaYJbGzLjUVWYoWaqibrG29a3BBL+IopPkWHfW9RYLW08Dh4w3WwRk+8x LRQ8Ax87Gb+kG283Y2PrNfqxWgtS+AMj1OhHb2uouWHUQ/hMzeDmx0hVUxOxK294uf W2kwjIYTPUdyhM/VbYhgI0h5pb061Iu/NWeTIoLIZWDsMdq13l/xsgNi4DUJdHNniz LZFTCKrunPxSyisVftNi5eR6uIheCM1bBxX/NFvJEpHWmP68zD8who5XV/qNVM4RUA vYolO5CQiBlXA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 3/7] mptcp: add mptcp_userspace_pm_get_sock helper Date: Thu, 5 Dec 2024 15:14:55 +0800 Message-ID: <439ccbf577e94905db34b3f97aeeac547b3f6d42.1733382223.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 Each userspace pm netlink function uses nla_get_u32() to get the msk token value, then pass it to mptcp_token_get_sock() to get the msk. Finally check whether userspace PM is selected on this msk. It makes sense to wrap them into a helper, named mptcp_userspace_pm_get_sock(), to do this. This patch doesn't change the behaviour of the code, just refactoring. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) --- 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 Sun Dec 22 03:15:44 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 A65822391AB for ; Thu, 5 Dec 2024 07:15: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=1733382919; cv=none; b=UnMjCUn0kmk1Nf+eB55c5iZeOAwJl3/CHFJYRrvmVTyviXVpxf3ilgnRow13dB/plwyMezscpt5Dx6Cf7HK1bZihkfmFoBE7OTbSnfcaqWz72NH+pn+n6pXGQkdZ9MPQx/ngy0dFr/sJwf1F9GX2eN0l9/IJEJXNANciwI5HBw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733382919; c=relaxed/simple; bh=0Jj9HWHIbFCVbtSh6CXl3ItsNo9oF4CUzr15UbTWLCQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=csFUQS9rJvCqrSUiaGlzSYrimIneVYu1m6gQkp44Jx/WqRwZDji9HUCrbn8rpMMXSetOnNlkYF2BEyBS0D5uXkdrkqg+nUzyu+OWEGmrngmnbrwP0CzO/MuUHmvIxrQKGi3LbN2y2wEuIcUYHhSRpH3TdLeOyFQplcqZ+ASNqcc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CTOlfy/5; 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="CTOlfy/5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B907EC4CED1; Thu, 5 Dec 2024 07:15:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733382916; bh=0Jj9HWHIbFCVbtSh6CXl3ItsNo9oF4CUzr15UbTWLCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CTOlfy/5uth5dUuP+0zlnXrEHqXDzgd2MkXTXNfUrSofp00DIEiMqQsX4WgtwzFzK r89r2ZUPGF+MZH+A8j3FhNYJry/sfH36XpdvZ+Z9dk8NykLEnCECSLjG8rTON+tbbM 6X2wNy4brlMTwJEjHGjZ+38NcTZwMVDPBADSs2oDGJpTri/Ejcbpl/7AyPTC2sLNPV gXawQXkLKjMC9luc6sjPAxGYBMvrXfjNyo8SfrV7WZNM6kUIjyM8FVdC14G68rdX/x nzie33pxc7sGztbGEFFg4900d2RPP9p6lrun0pkEH21ThEyI+iZB4BZIN3wVldgbUz RZ484dV89gXFg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 4/7] mptcp: move mptcp_pm_remove_addrs into pm_userspace Date: Thu, 5 Dec 2024 15:14:56 +0800 Message-ID: <0ace5dfd29f804ee8496632dcf4d41702ed41a9f.1733382223.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. Here, mptcp_pm_remove_addrs() is not changed to a static function because it will be used in BPF Path Manager. This patch doesn't change the behaviour of the code, just refactoring. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_netlink.c | 46 +++++++--------------------------------- net/mptcp/pm_userspace.c | 28 ++++++++++++++++++++++++ net/mptcp/protocol.h | 4 ++++ 3 files changed, 40 insertions(+), 38 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 7a0f7998376a..98ac73938bd8 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -107,8 +107,8 @@ static void remote_address(const struct sock_common *sk= c, #endif } =20 -static bool lookup_subflow_by_saddr(const struct list_head *list, - const struct mptcp_addr_info *saddr) +bool mptcp_lookup_subflow_by_saddr(const struct list_head *list, + const struct mptcp_addr_info *saddr) { struct mptcp_subflow_context *subflow; struct mptcp_addr_info cur; @@ -1447,8 +1447,8 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, st= ruct genl_info *info) return ret; } =20 -static bool remove_anno_list_by_saddr(struct mptcp_sock *msk, - const struct mptcp_addr_info *addr) +bool mptcp_remove_anno_list_by_saddr(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr) { struct mptcp_pm_add_entry *entry; =20 @@ -1476,7 +1476,7 @@ static bool mptcp_pm_remove_anno_addr(struct mptcp_so= ck *msk, =20 list.ids[list.nr++] =3D mptcp_endp_get_local_id(msk, addr); =20 - ret =3D remove_anno_list_by_saddr(msk, addr); + ret =3D mptcp_remove_anno_list_by_saddr(msk, addr); if (ret || force) { spin_lock_bh(&msk->pm.lock); if (ret) { @@ -1520,7 +1520,7 @@ static int mptcp_nl_remove_subflow_and_signal_addr(st= ruct net *net, } =20 lock_sock(sk); - remove_subflow =3D lookup_subflow_by_saddr(&msk->conn_list, addr); + remove_subflow =3D mptcp_lookup_subflow_by_saddr(&msk->conn_list, addr); mptcp_pm_remove_anno_addr(msk, addr, remove_subflow && !(entry->flags & MPTCP_PM_ADDR_FLAG_IMPLICIT)); =20 @@ -1633,36 +1633,6 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, s= truct genl_info *info) return ret; } =20 -/* Called from the userspace PM only */ -void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_li= st) -{ - struct mptcp_rm_list alist =3D { .nr =3D 0 }; - struct mptcp_pm_addr_entry *entry; - int anno_nr =3D 0; - - list_for_each_entry(entry, rm_list, list) { - if (alist.nr >=3D MPTCP_RM_IDS_MAX) - break; - - /* only delete if either announced or matching a subflow */ - if (remove_anno_list_by_saddr(msk, &entry->addr)) - anno_nr++; - else if (!lookup_subflow_by_saddr(&msk->conn_list, - &entry->addr)) - continue; - - alist.ids[alist.nr++] =3D entry->addr.id; - } - - if (alist.nr) { - spin_lock_bh(&msk->pm.lock); - msk->pm.add_addr_signaled -=3D anno_nr; - mptcp_pm_remove_addr(msk, &alist); - spin_unlock_bh(&msk->pm.lock); - } -} - -/* Called from the in-kernel PM only */ static void mptcp_pm_flush_addrs_and_subflows(struct mptcp_sock *msk, struct list_head *rm_list) { @@ -1671,11 +1641,11 @@ static void mptcp_pm_flush_addrs_and_subflows(struc= t mptcp_sock *msk, =20 list_for_each_entry(entry, rm_list, list) { if (slist.nr < MPTCP_RM_IDS_MAX && - lookup_subflow_by_saddr(&msk->conn_list, &entry->addr)) + mptcp_lookup_subflow_by_saddr(&msk->conn_list, &entry->addr)) slist.ids[slist.nr++] =3D mptcp_endp_get_local_id(msk, &entry->addr); =20 if (alist.nr < MPTCP_RM_IDS_MAX && - remove_anno_list_by_saddr(msk, &entry->addr)) + mptcp_remove_anno_list_by_saddr(msk, &entry->addr)) alist.ids[alist.nr++] =3D mptcp_endp_get_local_id(msk, &entry->addr); } =20 diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 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 Sun Dec 22 03:15:44 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 1D4D3653 for ; Thu, 5 Dec 2024 07:15: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=1733382918; cv=none; b=Q+bNxYEc4xxx3Esc3MG9t/bqTrsGlEy2mvvz5fHbKGVl2DvrMQPfjspXJ0m/Qiqz7iOWU3YVxGXdAuxbNbC6xIjER3sdaUXB1pjBugFITp4h28s23a6eF2v38BI87emxtisWjZWcc4lhl95eMtl9Y4YA8EU5X4HR42DNOP+cRr4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733382918; c=relaxed/simple; bh=KxYiRCb97eu/xRjf4MYxvVjWC47YXYzFgHv6uIQM26c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mCD68gI7Gp+NEjyNP0IOn1oHAce+Q5bh47j3cF/mvF2vBRH2eCe/pEpQQ+dVwtUG2GDYYZz89YrdJr9pZQe+IoHjSvedB4bF/DSMNmvbchcNfYk1KaI7+S2y+T8mAgqUMvY2IofNYMUvkS/OngYx5LdwylBLXTHaNz18G3K2+vI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DnnxuAhu; 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="DnnxuAhu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3A43C4CED6; Thu, 5 Dec 2024 07:15:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733382918; bh=KxYiRCb97eu/xRjf4MYxvVjWC47YXYzFgHv6uIQM26c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DnnxuAhulgBNv4mY0U5h0dJ7iFsfoBUivz+4GFwldH4FWisoNJqv/kwiJJHeFvWuP t2u/rQMnYI5fJbj0j/FQjbyvCetC7th68eXKWhAwXLYdakT83dHZklg+k2BYppnYlV GUX+WqVsq4JEv3Fx3uB0FG5BPqIHWQ75GXiRuViile/i0vykCo6OcPzKa+DVAa/ogp /gRqf1/PYYqw2yHh9R1qpr8S+1oolE6gyMW8EtjjrfXlEomtRn5g7timAeUFnTSjuJ 0Ubr8ocKtM1ZoI1jFgVDHnvjtktYzuNpmKhfmxVq7SRZUaIzt85BLaxluovK7PurMk S8fNhDuFkLPJg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 5/7] mptcp: drop free_list for deleting entries Date: Thu, 5 Dec 2024 15:14:57 +0800 Message-ID: <727da6c2412b1d27c079f4cf01d88021e8d478f7.1733382223.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 Reviewed-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 42 ++++++++++++++-------------------------- net/mptcp/protocol.h | 3 ++- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 737a07f5defe..ca302465fecc 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -286,41 +286,31 @@ static int mptcp_userspace_pm_remove_id_zero_address(= struct mptcp_sock *msk, return err; } =20 -void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_li= st) +void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *entry) { struct mptcp_rm_list alist =3D { .nr =3D 0 }; - struct mptcp_pm_addr_entry *entry; int anno_nr =3D 0; =20 - list_for_each_entry(entry, rm_list, list) { - if (alist.nr >=3D MPTCP_RM_IDS_MAX) - break; - - /* only delete if either announced or matching a subflow */ - if (mptcp_remove_anno_list_by_saddr(msk, &entry->addr)) - anno_nr++; - else if (!mptcp_lookup_subflow_by_saddr(&msk->conn_list, - &entry->addr)) - 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)) + return; =20 - alist.ids[alist.nr++] =3D entry->addr.id; - } + alist.ids[alist.nr++] =3D entry->addr.id; =20 - if (alist.nr) { - spin_lock_bh(&msk->pm.lock); - msk->pm.add_addr_signaled -=3D anno_nr; - mptcp_pm_remove_addr(msk, &alist); - spin_unlock_bh(&msk->pm.lock); - } + spin_lock_bh(&msk->pm.lock); + msk->pm.add_addr_signaled -=3D anno_nr; + mptcp_pm_remove_addr(msk, &alist); + spin_unlock_bh(&msk->pm.lock); } =20 int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *id =3D info->attrs[MPTCP_PM_ATTR_LOC_ID]; struct mptcp_pm_addr_entry *match; - struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; - LIST_HEAD(free_list); int err =3D -EINVAL; struct sock *sk; u8 id_val; @@ -354,16 +344,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 Sun Dec 22 03:15:44 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 576122391B5 for ; Thu, 5 Dec 2024 07:15:20 +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=1733382920; cv=none; b=ZWQqqCrW+65yNfPxwlQxIt+IVDi43rmnFwYkYpxcPCOB/LuhiGdiLlLwZ9AbqF8peKC5jkXvVfqAGuJAvZseYfWs5l9DQRUc8jMfQvErEyfgxksE5VT9KIVC5yPyXbACN4tEFAVxDc4tDM/QTP7J0hOPEh2wDpWDF0CamZ2WDnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733382920; c=relaxed/simple; bh=O8LXp49ej8kiS4ermKW2DrXtwSTlJwQCQYGeF/IjCkg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FY1PMwr/X7hRpm4VF/h0vp5rb1aGd+RzuYoupoi0XLxjlIi3JRCrfEfCp+M6v+9tSix+MhNLd5DKjP3cI+t/ortAnmaiBQEmS09QUa6gmBP/mrfJNBMTOq8ABtZ/Ea/GIoAzVZAMil7ofMe5/LrcGqSZAxPC6G0bAzkk7V3DHVI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gBf6zyR2; 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="gBf6zyR2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BBF4C4CED6; Thu, 5 Dec 2024 07:15:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733382919; bh=O8LXp49ej8kiS4ermKW2DrXtwSTlJwQCQYGeF/IjCkg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gBf6zyR2SS52kxyBF3+a1Wed4Z00VAKgnJeCwZvU/rCkzeCgf6gemJeVO1buwGSxz 1B75gHcX02MHqv1Qkjcad7/z0T01J2TvMX4781rKqfd9XVD3EmLEwp1wOjdwPlQ58y IdNjDO862FGKIRN9j3vYUIn9waxZ1wVUm2NK6HTfr2aaatEXkwipY7fXndDxoSMNBg /TKcdHRVQkfQY4uZjTn1vCBzkByodLrARreW1aOn2YqwYx1Oygkq/D7dMAakTFDNfY Cgd2gqB5acceHSpyyO9+BKnuNHsivPDxO6oMhE7pkbzHxccDsW/9ojmfQHyXdEWbFo lAO4ljSAnz1XA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 6/7] mptcp: change local addr type of subflow_destroy Date: Thu, 5 Dec 2024 15:14:58 +0800 Message-ID: <660f017d048bbd563e748cf7169e7a09811fb20c.1733382223.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 Reviewed-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index ca302465fecc..f6ac4cd3b6c3 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -484,7 +484,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; @@ -501,7 +501,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; @@ -514,35 +514,34 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *= skb, struct genl_info *info } =20 #if IS_ENABLED(CONFIG_MPTCP_IPV6) - if (addr_l.family =3D=3D AF_INET && ipv6_addr_v4mapped(&addr_r.addr6)) { - ipv6_addr_set_v4mapped(addr_l.addr.s_addr, &addr_l.addr6); - addr_l.family =3D AF_INET6; + if (addr_l.addr.family =3D=3D AF_INET && ipv6_addr_v4mapped(&addr_r.addr6= )) { + ipv6_addr_set_v4mapped(addr_l.addr.addr.s_addr, &addr_l.addr.addr6); + addr_l.addr.family =3D AF_INET6; } - if (addr_r.family =3D=3D AF_INET && ipv6_addr_v4mapped(&addr_l.addr6)) { - ipv6_addr_set_v4mapped(addr_r.addr.s_addr, &addr_r.addr6); + if (addr_r.family =3D=3D AF_INET && ipv6_addr_v4mapped(&addr_l.addr.addr6= )) { + ipv6_addr_set_v4mapped(addr_r.addr.s_addr, &addr_l.addr.addr6); addr_r.family =3D AF_INET6; } #endif - if (addr_l.family !=3D addr_r.family) { + if (addr_l.addr.family !=3D addr_r.family) { GENL_SET_ERR_MSG(info, "address families do not match"); err =3D -EINVAL; goto destroy_err; } =20 - if (!addr_l.port || !addr_r.port) { + if (!addr_l.addr.port || !addr_r.port) { GENL_SET_ERR_MSG(info, "missing local or remote port"); err =3D -EINVAL; goto destroy_err; } =20 lock_sock(sk); - ssk =3D mptcp_nl_find_ssk(msk, &addr_l, &addr_r); + ssk =3D mptcp_nl_find_ssk(msk, &addr_l.addr, &addr_r); if (ssk) { struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(ssk); - struct mptcp_pm_addr_entry entry =3D { .addr =3D addr_l }; =20 spin_lock_bh(&msk->pm.lock); - mptcp_userspace_pm_delete_local_addr(msk, &entry); + mptcp_userspace_pm_delete_local_addr(msk, &addr_l); spin_unlock_bh(&msk->pm.lock); mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); mptcp_close_ssk(sk, ssk, subflow); --=20 2.45.2 From nobody Sun Dec 22 03:15:44 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 4D0C7653 for ; Thu, 5 Dec 2024 07:15: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=1733382922; cv=none; b=CkuEKK44pxFa7d/a03Cqs8fCQ2dV3Cs4sdjFZOWsIJZsBNAdfAdsPllZFuhY0JuV6tlNroIkXWwbpZG39HlxFHBIGHNRxtzjOdhwoyXqz/SC9glG+JyvjugJQY0NQ7vbS8E2WtqI9A+hN+mdCJG9HkQAI+5QMA1HZlkXnBq2PYk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733382922; c=relaxed/simple; bh=bMsOP7bqSA9DUccHz7v6v8BVuLTwcmSYXGyZaxT1AJk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h+NexxhtX7O68TY3soxzUkxM/Q9rEUinVmkNh4xUZO1YYkN903oW8u0UOLpr4wt822QJcy+6+nVGO0bfWXbczWh0hI5tlcB4zqnzxZ5d+i4xOw7LsTqSt6tRZ05pxsgPZi+vYMKw2rhVqY0AEKWlwE3m4hxUl2aQy+KUy/HckB4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q4NbNN61; 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="Q4NbNN61" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F0FBC4CED1; Thu, 5 Dec 2024 07:15:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733382921; bh=bMsOP7bqSA9DUccHz7v6v8BVuLTwcmSYXGyZaxT1AJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q4NbNN61ODtgTWnm7uxl7MCxqZnsqWZRbZfOwIGdcjpWfIHt5ASuEC0l5iOugBpNG P2RUZqjfSqBChWB3As7uvD4dN+l4TdG0UjiPhlQhMSwslD0DgOW00jOO2qebHo6hu0 F9qY/75o3cLCt5Ttp5HtB5M5Yi9AP7MDbciwPdenmdxXdI/OLTLm5mp4QvT8a8U8u/ dplce2p5xFWpQgT1sMv5XChdmYuyylzshArVla1J4//D3Zz+p5srYS+omWhNsRQYjp 0CDRCmD3RfcWQOHPmbf2HS6AgVxG5yEk7nNJNUWLnHkvQ37w2cR6fUwa/8qHP3saI0 v4Z8geOM9F1wA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 7/7] mptcp: drop useless "err = 0" in subflow_destroy Date: Thu, 5 Dec 2024 15:14:59 +0800 Message-ID: <5e7c6ebc914c22053389526d1a29b2e5d89be4de.1733382223.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 Reviewed-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index f6ac4cd3b6c3..2bb5c0ded22c 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -537,19 +537,18 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *= skb, struct genl_info *info =20 lock_sock(sk); ssk =3D mptcp_nl_find_ssk(msk, &addr_l.addr, &addr_r); - if (ssk) { - struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(ssk); - - spin_lock_bh(&msk->pm.lock); - mptcp_userspace_pm_delete_local_addr(msk, &addr_l); - spin_unlock_bh(&msk->pm.lock); - mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); - mptcp_close_ssk(sk, ssk, subflow); - MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW); - err =3D 0; - } else { + if (!ssk) { err =3D -ESRCH; + goto release_sock; } + + spin_lock_bh(&msk->pm.lock); + mptcp_userspace_pm_delete_local_addr(msk, &addr_l); + spin_unlock_bh(&msk->pm.lock); + mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); + mptcp_close_ssk(sk, ssk, mptcp_subflow_ctx(ssk)); + MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW); +release_sock: release_sock(sk); =20 destroy_err: --=20 2.45.2