From patchwork Wed Jan 15 07:01:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13939916 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 93CB523243D for ; Wed, 15 Jan 2025 07:01:49 +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=1736924509; cv=none; b=BJZIvLm1D6cx8TigivKiToFboQgQCyhzLoBmtRYACAG8jnB0gyCHvqYGnNTYOE01e4dRMMpVDo/oZAEBzkkPRhNZJ9syJ3GeekEDkekfSb+i9iqV5wk3moRITgHoq/V3MvvM2OqhvTpovJ4AQ4X7jjag6odAgbB1a0Kk09vSr5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736924509; c=relaxed/simple; bh=mReufQBMfhEAFgVxSJjYHyXTepa6JXN6QhJtShKUhQ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rj5H7Jxd6ozLRvns9WCNVSoXKYIj3NTceSC2ZcSfvi6xRyBBPTwGbNy0y9D+dRsI8G3R++ju6/CS5t2Y+DlKAhgWU0i/CpfaYx9xBjJub6Q1hFdi8yJ0bKfsVDOJfBMXp0ceSnQkjWCs8upfly4/KkHtMGpHFEcF73GeVv01gZ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bXM56MD8; 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="bXM56MD8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 304ABC4CEDF; Wed, 15 Jan 2025 07:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736924509; bh=mReufQBMfhEAFgVxSJjYHyXTepa6JXN6QhJtShKUhQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bXM56MD8fXK6HZHM0cHbR0EFOAxceKDabU64lOUQ8e83eLtVjj7MFC8/0MDhIyjJp 7QFoA12KX9PlvBIwS0YH4o7s83Gr/jcVuXLU8NRcaFnFcShCvk8iL8rijVjPQhzK1+ 8pn53LwiKH7HEz4R4dirfLeYknAE3FuWVTitdyeRJmjBdf1lgf3GcW1c6yThS3W2Iy ri6W+Yybc51gi4u8h6110jnEtHohVDkFnI0k0uaiduXyztCAYSGrFOCahL9M47f8Tr /XHmKfJPn7v/mFNvemPTkH4PulU9QG5qxmOKDgJ/OW4aTKK3od/6rFdsw3Y+jbTcif xHXAx7HW4PzLw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 1/7] mptcp: add mptcp_pm_genl_fill_addr helper Date: Wed, 15 Jan 2025 15:01:34 +0800 Message-ID: <8a5ebc5f76b29640f5a706eb4acf881ce1d35e48.1736924314.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang To save some redundant code in dump_addr() interfaces of both the netlink PM and userspace PM, the code that calls netlink message helpers (genlmsg_put/cancel/end) and mptcp_nl_fill_addr() is wrapped into a new helper mptcp_pm_genl_fill_addr(). This helper will also be used in BPF path managers. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 21 +++++++++++++++++++++ net/mptcp/pm_netlink.c | 12 +----------- net/mptcp/pm_userspace.c | 12 +----------- net/mptcp/protocol.h | 3 +++ 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index b1f36dc1a091..16cacce6c10f 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -489,6 +489,27 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) return ret; } +int mptcp_pm_genl_fill_addr(struct sk_buff *msg, + struct netlink_callback *cb, + struct mptcp_pm_addr_entry *entry) +{ + void *hdr; + + hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, &mptcp_genl_family, + NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); + if (!hdr) + return -EINVAL; + + if (mptcp_nl_fill_addr(msg, entry) < 0) { + genlmsg_cancel(msg, hdr); + return -EINVAL; + } + + genlmsg_end(msg, hdr); + return 0; +} + static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { const struct genl_info *info = genl_info_dump(cb); diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index fef01692eaed..afd517ff260c 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1798,7 +1798,6 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; int id = cb->args[0]; - void *hdr; int i; pernet = pm_nl_get_pernet(net); @@ -1813,19 +1812,10 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, if (entry->addr.id <= id) continue; - hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, &mptcp_genl_family, - NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); - if (!hdr) + if (mptcp_pm_genl_fill_addr(msg, cb, entry)) break; - if (mptcp_nl_fill_addr(msg, entry) < 0) { - genlmsg_cancel(msg, hdr); - break; - } - id = entry->addr.id; - genlmsg_end(msg, hdr); } } rcu_read_unlock(); diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 277cf092a870..b50462b527bd 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -641,7 +641,6 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct mptcp_sock *msk; int ret = -EINVAL; struct sock *sk; - void *hdr; bitmap = (struct id_bitmap *)cb->ctx; @@ -657,19 +656,10 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, if (test_bit(entry->addr.id, bitmap->map)) continue; - hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, &mptcp_genl_family, - NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); - if (!hdr) + if (mptcp_pm_genl_fill_addr(msg, cb, entry)) break; - if (mptcp_nl_fill_addr(msg, entry) < 0) { - genlmsg_cancel(msg, hdr); - break; - } - __set_bit(entry->addr.id, bitmap->map); - genlmsg_end(msg, hdr); } spin_unlock_bh(&msk->pm.lock); release_sock(sk); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 6fb536de9981..20941405a1ea 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1060,6 +1060,9 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf struct request_sock *req); int mptcp_nl_fill_addr(struct sk_buff *skb, struct mptcp_pm_addr_entry *entry); +int mptcp_pm_genl_fill_addr(struct sk_buff *msg, + struct netlink_callback *cb, + struct mptcp_pm_addr_entry *entry); static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk) { From patchwork Wed Jan 15 07:01:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13939917 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 97C5522DFA4 for ; Wed, 15 Jan 2025 07:01:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736924511; cv=none; b=GFx3u2lTWraQUK59oSMhxRd4YxJrTZ2Qu11TON3gwJil53eZXxXT01UcecwD1wINqkXQ6U45d+z+4s9pUAGOnjFb5TLoQHP86dDmXOZQXUAz9VpgPBpkr0Q9SHIv96k6APKpSwVs7G4debdgDNKSPXy+fTgREpbEzl+4hocs/R8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736924511; c=relaxed/simple; bh=VQTbXInIocsUug3Gaqad5FUcamm3egJMgNUOEl9m6Tg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X3zM5oaRrBPeq0Sz2S6GYs09Z7arIQKhP3nhImJjkyWPlZiaNDgcTF3EmABuvxNlqy5gVkE/+q8Frq5Rs40pWr+O28PPg5igxM65qbhhtFsht33/TXPkAnLqNDUsTN8AjNFjGaSVlUOCynWB0W6Rn1cWFP0R00z/lalxKeMPeLQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tUmEV1jX; 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="tUmEV1jX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E71BFC4CEDF; Wed, 15 Jan 2025 07:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736924511; bh=VQTbXInIocsUug3Gaqad5FUcamm3egJMgNUOEl9m6Tg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tUmEV1jXgLFu2F4LvpG2n+L1s0ECncHOfNZxYeBoQBPBFoEAtLO6ZjMxYzId3Ya97 dlSEp0bR71PsEqeeOcS3rvmlA98X67KsOArv7JD4XG5IbXlbKH/G1SkG343Hai+T1/ +CZsEVkZQi6C/iEmE5eRL3tHVveSSBGkUHWKNVewvg3gPtBmJt12UC0QoDangl3t0c Q+Tm4OAJs1T2Dn+drtgAEDmcJEQjyHrAttWUeHNwyVVnicCn7+VF3CVQAvHmq5ywrZ mnDEQ8gUjso0ESiT6iMTcvyO7u7Lg4yD9AdE2Q9ZdtQWYwl2GvN3fRzOM1JHGCtLSM A1qvgF4IgaOTw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 2/7] mptcp: add struct mptcp_pm_addr_id_bitmap Date: Wed, 15 Jan 2025 15:01:35 +0800 Message-ID: <19ea261f2ff5d7bb5b2333f6294d30c092a5df3e.1736924314.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang To simplify the use of bitmap in BPF, a new type for MPTCP userspace pm id bitmap, struct mptcp_pm_addr_id_bitmap is defined. Because there's no way to use DECLARE_BITMAP macro in BPF program, and it's not easy to reimplement it in BPF. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 14 ++++++-------- net/mptcp/protocol.h | 4 ++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index b50462b527bd..e53426a5fc52 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -47,7 +47,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *entry, bool needs_id) { - DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + struct mptcp_pm_addr_id_bitmap id_bitmap; struct mptcp_pm_addr_entry *match = NULL; struct sock *sk = (struct sock *)msk; struct mptcp_pm_addr_entry *e; @@ -55,7 +55,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, bool id_match = false; int ret = -EINVAL; - bitmap_zero(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + bitmap_zero(id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); spin_lock_bh(&msk->pm.lock); mptcp_for_each_userspace_pm_addr(msk, e) { @@ -69,7 +69,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, } else if (addr_match || id_match) { break; } - __set_bit(e->addr.id, id_bitmap); + __set_bit(e->addr.id, id_bitmap.map); } if (!match && !addr_match && !id_match) { @@ -84,7 +84,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, *e = *entry; if (!e->addr.id && needs_id) - e->addr.id = find_next_zero_bit(id_bitmap, + e->addr.id = find_next_zero_bit(id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1, 1); list_add_tail_rcu(&e->list, &msk->pm.userspace_pm_local_addr_list); @@ -633,16 +633,14 @@ int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local, int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { - struct id_bitmap { - DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1); - } *bitmap; const struct genl_info *info = genl_info_dump(cb); + struct mptcp_pm_addr_id_bitmap *bitmap; struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; int ret = -EINVAL; struct sock *sk; - bitmap = (struct id_bitmap *)cb->ctx; + bitmap = (struct mptcp_pm_addr_id_bitmap *)cb->ctx; msk = mptcp_userspace_pm_get_sock(info); if (!msk) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 20941405a1ea..aca3de2baf81 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -212,6 +212,10 @@ enum mptcp_addr_signal_status { /* max value of mptcp_addr_info.id */ #define MPTCP_PM_MAX_ADDR_ID U8_MAX +struct mptcp_pm_addr_id_bitmap { + DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1); +}; + struct mptcp_pm_data { struct mptcp_addr_info local; struct mptcp_addr_info remote; From patchwork Wed Jan 15 07:01:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13939918 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 691A922F82F for ; Wed, 15 Jan 2025 07:01:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736924514; cv=none; b=Kh418fGsao0Ju+p9zJnjHdd7DW39clzJNVm2A/VF/4cH90s/O3GDNgQhE/pz7UlTIgJu/XngTt4NeKlow8t6hPR/vrYODPjfC2OaFFwkO+GYwkxh3D5aRR5HZMAb7tjIVP1LR2WD9pFT5Gl2Xa/XZw0o5BhVcvKVh9mftYHv+gE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736924514; c=relaxed/simple; bh=wgDmtBTPbeJRMEXqfy9UulGSZmSZ3VD6Zw43FACGutQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=orOmTvCJO3uCvG8Omrgw/x9CT9wFRX743v4lH1PaQVFIgt6gBq74APrYVaCzfeSP+0Log50JBrA0OaTqo+yhd5ilcD4wS1rECSxSb/z2TW3aBT9NdL0vhUmyVRBAs5ulpGZr3WctkY/WnqvGLnNx/5ZFOpN73Y0++GE8e4Ak5xE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SqEYH8Rf; 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="SqEYH8Rf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF9D7C4CEDF; Wed, 15 Jan 2025 07:01:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736924513; bh=wgDmtBTPbeJRMEXqfy9UulGSZmSZ3VD6Zw43FACGutQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SqEYH8Rf3HQ8tH3XewfDCYTTgwlSQCc+kfiF3S9z6m7YlYjHEmsEAxBDCrIOZvb/s 60grcbGJZzKXQWuUlioSNv+urLrhLTJxFsCPBiF3U5SjhQMGwn5/JX9oO96kJD1QDh cbr1XtSOxT0sVV7uoiO+Xs8Tf0UuE7/VnBcdrPN7YXkNhf72daiycto8dDotJX8y4G mUkJ/kFGKliHgKcBOJt9mfUX9N5kkKTZse0hWcbRtFJGDOltd+oXEuLYAV22DoXvff 2uVIGqc9OrIe+lF+IsxBZmx2/L5Wo7LVxEENztA4wjJrTSaARVlb76Xkcbz25BB93s ku6P31lIV2uLA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 3/7] mptcp: drop inet6_sk in mptcp_nl_find_ssk Date: Wed, 15 Jan 2025 15:01:36 +0800 Message-ID: <4b85fda724470edcb98a82c2f01c91cc72b3439a.1736924314.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang In mptcp_nl_find_ssk(), 'issk' has already been got through inet_sk(). No need to use inet6_sk() to get 'pinfo' again, just use issk->pinet6 instead. This patch also drops this 'pinfo' variable. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index e53426a5fc52..de17b18b78fe 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -465,9 +465,7 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_sock *msk, break; #if IS_ENABLED(CONFIG_MPTCP_IPV6) case AF_INET6: { - const struct ipv6_pinfo *pinfo = inet6_sk(ssk); - - if (!ipv6_addr_equal(&local->addr6, &pinfo->saddr) || + if (!ipv6_addr_equal(&local->addr6, &issk->pinet6->saddr) || !ipv6_addr_equal(&remote->addr6, &ssk->sk_v6_daddr)) continue; break; From patchwork Wed Jan 15 07:01:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13939919 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 3A30622F853 for ; Wed, 15 Jan 2025 07:01: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=1736924515; cv=none; b=a4e1j7M4NOpy3D4RFb842P3jIezhKRnzMFX6/MySl5Ko6UBaghdU0alVbdS78TQR9H9KCPiy6cvvyWBzNmp7zSo1r8SREBxR1ZN6ayLF32WCgx6zb21Rzx1HOwzZxO+ptj78PWTQnAi/5MYufaOGvSnjM8DN3njDsbC3a+FiCVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736924515; c=relaxed/simple; bh=Xw3wlccCqpdwPt88Y4SCvZLPmSfjOGk3ELg4WNOmO6A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nDEGemgQY5I/w+cfTaWKe79B4+G9Eau2XsnfTOr87IZ0axFMfoBtQCUIhBtVp0DegqyI5UUUWCJ14A/ZqcWBFhY5D7LBMrE/P6i+dO4iuwKMgGA9jE4OakR5Wa9IXVSR7jpRHrfqE2w6LCoZgSC3Oh7q/B1CHqkMIYQSUuFWi5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=at6sKBNl; 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="at6sKBNl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99207C4CEE3; Wed, 15 Jan 2025 07:01:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736924514; bh=Xw3wlccCqpdwPt88Y4SCvZLPmSfjOGk3ELg4WNOmO6A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=at6sKBNlq/LO6Zx8m1rffyiVp6LEkCde1kWtEmSlJPCHVgNRgyjoF68jRZW8vGA1i DcmwCToEWMNzGGwj0eDnwuwOibiNSy1Qc81k/nAs8hTvavheAGNQbctGWcpNgad9bB 6zvEtGFgYvGJt76PA4TNdQQtoha7qmfWyHU93vHFtR0cCq8CVbW9EcwG3SpJgDOTy0 fX5+VNRoJlmPVtGb9tfMwmvwZW980PNBcut0wGxPWaUTsKh84qrAo840VDocb3lYWO Fk+6ihM5i5hw3bDsF4efHxs79v642KG11AiBB6XciCWV8gtnA5qI52HLDD6/eDDOmC +t6nIHSflBrSw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 4/7] mptcp: drop match in userspace_pm_append_new_local_addr Date: Wed, 15 Jan 2025 15:01:37 +0800 Message-ID: <7cef5a603af13cace6b8acd466320a10f9cf6349.1736924314.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang The variable 'match' in mptcp_userspace_pm_append_new_local_addr() is a redundant one, and this patch drops it. No need to define 'match' as 'struct mptcp_pm_addr_entry *' type. In this function, it's only used to check whether it's NULL. It can be defined as a Boolean one. Also other variables 'addr_match' and 'id_match' make 'match' a redundant one, which can be replaced by directly checking 'addr_match && id_match'. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index de17b18b78fe..7075c7f7229f 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -48,7 +48,6 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, bool needs_id) { struct mptcp_pm_addr_id_bitmap id_bitmap; - struct mptcp_pm_addr_entry *match = NULL; struct sock *sk = (struct sock *)msk; struct mptcp_pm_addr_entry *e; bool addr_match = false; @@ -63,16 +62,12 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, if (addr_match && entry->addr.id == 0 && needs_id) entry->addr.id = e->addr.id; id_match = (e->addr.id == entry->addr.id); - if (addr_match && id_match) { - match = e; + if (addr_match || id_match) break; - } else if (addr_match || id_match) { - break; - } __set_bit(e->addr.id, id_bitmap.map); } - if (!match && !addr_match && !id_match) { + if (!addr_match && !id_match) { /* Memory for the entry is allocated from the * sock option buffer. */ @@ -90,7 +85,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, list_add_tail_rcu(&e->list, &msk->pm.userspace_pm_local_addr_list); msk->pm.local_addr_used++; ret = e->addr.id; - } else if (match) { + } else if (addr_match && id_match) { ret = entry->addr.id; } From patchwork Wed Jan 15 07:01:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13939920 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 16C6622FDF0 for ; Wed, 15 Jan 2025 07:01: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=1736924517; cv=none; b=UHqlP62rVI+mvJ55Zy8uLCEtQdlxSq8Li7J9eVCkz5MkswqboFkBFTaK8aF4ypY5HBT/Hf/DIgawwjVOtRlbUMvDw6NQcbKd/LipdfRfYFIDEkyQG84mBA4Qn4PXO/DFYoiyU9jvUohuYK+Dbb0HAYXjUhvTLv9s3w4OChVdtXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736924517; c=relaxed/simple; bh=rXH8FpolB35Qn7+rHdrsYKPOEuRbjgNNE0VlMv4qb6o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CB8+TF2kCM9RrTtjy/08aarzZtkBrKQ5pvfjHiW7WVBByus4Ms+q3cArKA8c0LD7EExmOHn0r0ik4KZs3NUjMQg7Wq0QMNTEAmdvHmNzYxIm8eHz3vxoInlp6mbEMWYg4kH4ewxeiSrHgC59zuD0l/duuB5q+JiZSrn9muYe2GQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WPquQcvS; 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="WPquQcvS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7233DC4CEDF; Wed, 15 Jan 2025 07:01:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736924516; bh=rXH8FpolB35Qn7+rHdrsYKPOEuRbjgNNE0VlMv4qb6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WPquQcvSvx4WgfGtZtg6pvdpPYZqLOUFuK1nnkSh7Cr3hist1L539D45VES/xZFDG fgosin1OquWeZeo3dwUhdngwGvuALScKlOH30CTHho3ftxa/k5XbKlYcF6GnWKWmLl nr7TBcKUVTNb/CNhsXZr3fPIwELpMCbePq00lJXXZSqgqV8wy+58xFhTyegQGJGKp4 SvP2Es293VuUgyjQEm8U1yncWtG0T2u0V5YINtdAVQGKC4jI9bZeQwJrEXx96cFVul J2saVsUSFg9pKJBZdfuhosStJ1KQ9xYa9trrQf94PFjwgRWeWPJ67MvGHE2R1qa0iW 8dRKAg0F4+lYQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 5/7] mptcp: hold msk lock before removing id 0 address Date: Wed, 15 Jan 2025 15:01:38 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang In mptcp_pm_nl_remove_doit(), move 'lock_sock(sk)' before invoking the function mptcp_userspace_pm_remove_id_zero_address(). Then no need to hold and release this lock in this function. And 'sk' and 'err' variables and 'remove_err' label in it can be dropped. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 7075c7f7229f..eda4277bfff4 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -256,11 +256,8 @@ static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk) { struct mptcp_rm_list list = { .nr = 0 }; struct mptcp_subflow_context *subflow; - struct sock *sk = (struct sock *)msk; bool has_id_0 = false; - int err = -EINVAL; - lock_sock(sk); mptcp_for_each_subflow(msk, subflow) { if (READ_ONCE(subflow->local_id) == 0) { has_id_0 = true; @@ -268,7 +265,7 @@ static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk) } } if (!has_id_0) - goto remove_err; + return -EINVAL; list.ids[list.nr++] = 0; @@ -276,11 +273,7 @@ static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk) mptcp_pm_remove_addr(msk, &list); spin_unlock_bh(&msk->pm.lock); - err = 0; - -remove_err: - release_sock(sk); - return err; + return 0; } void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, @@ -324,13 +317,14 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) sk = (struct sock *)msk; + lock_sock(sk); + if (id_val == 0) { err = mptcp_userspace_pm_remove_id_zero_address(msk); + release_sock(sk); goto out; } - lock_sock(sk); - spin_lock_bh(&msk->pm.lock); match = mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); if (!match) { From patchwork Wed Jan 15 07:01:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13939921 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 CC07E22E41E for ; Wed, 15 Jan 2025 07:01: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=1736924518; cv=none; b=nJ9p0fdFAnju4+WvW4yYIYQAxhTZRJtwAiuEGulR24q2QceKp7Vf2A3bUvEND6b6JbELh9zxOnOedxxFqUq8gQmLz5noLmOaMzzS56sm6DK3y2YTdQ5l9Z62ELExjVYdy0CT+jhg/u+DQXyuAJ27Z+r8RYlCcDX3cCqRLdtdwSY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736924518; c=relaxed/simple; bh=vbo1MeBj54yhSnKdcYJ9yRu/z0wysu894AvA45TtkM0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d73Lyp//I9lyeCTcgx+SLXkqDu9eE7N5goHSroJf1t4Qree9KEWuB9OTvtj3lo9txFKTlusdCOq07WB2U1qAkxz6Pj3JTscBrmOOr+kNz2mT9bRAfR42VtU9K+pVuuPS3WJbmQcadainJAmWrH5PMOnyKtprmNKlcGyinKj2200= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r5S3p7Xw; 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="r5S3p7Xw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DBD0C4CEE4; Wed, 15 Jan 2025 07:01:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736924518; bh=vbo1MeBj54yhSnKdcYJ9yRu/z0wysu894AvA45TtkM0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r5S3p7XwKpxTkIbMpVPTKBmkMy12xOOXN57+osmBTRTnp3z7/0cEhw1fBJ8oOEda+ r1Wp+8J455Ebg937mWd7v6CM2bR+PrhW8iWEadzFr7nOMPCpx8O6OJ8qTs5bW/pilu XY0Q2LZQRR2wU0aGIwOXhdsVjkyOihKFF7AJAlGtzp/Wry/on313H6flNDa/XW5ve4 Wo0dfmBIjw11iHXGBEnHCeKDKVqe/yed/e2W5e7Gr64g/obJLu9Z8tuQyYG67TZl12 NFJvFryWxBJiQE28hCXwSoWsuqxzaX48uWIHf5QKsIQ/e3h6vN+1TOTN8EkCfj2XDI hNAHqvUTsnE5g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 6/7] mptcp: update address type of get_local_id Date: Wed, 15 Jan 2025 15:01:39 +0800 Message-ID: <049fa7d83e8e1d3ebde8599169006128f3fb0ec7.1736924314.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang The following code in mptcp_userspace_pm_get_local_id() that assigns 'skc' to 'new_entry' is not allowed in BPF if we use the same code to implement get_local_id() interface of a BFP path manager: memset(&new_entry, 0, sizeof(struct mptcp_pm_addr_entry)); new_entry.addr = *skc; new_entry.addr.id = 0; new_entry.flags = MPTCP_PM_ADDR_FLAG_IMPLICIT; To solve the issue, this patch moves this assignment to 'new_entry' forward to mptcp_pm_get_local_id(), and then passing 'new_entry' as a parameter to both mptcp_pm_nl_get_local_id() and mptcp_userspace_pm_get_local_id(). Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 10 +++++++--- net/mptcp/pm_netlink.c | 12 ++++-------- net/mptcp/pm_userspace.c | 17 ++++++----------- net/mptcp/protocol.h | 6 ++++-- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 16cacce6c10f..8d9acc984a36 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -403,7 +403,7 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining, int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) { - struct mptcp_addr_info skc_local; + struct mptcp_pm_addr_entry skc_local = { 0 }; struct mptcp_addr_info msk_local; if (WARN_ON_ONCE(!msk)) @@ -413,12 +413,16 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) * addr */ mptcp_local_address((struct sock_common *)msk, &msk_local); - mptcp_local_address((struct sock_common *)skc, &skc_local); - if (mptcp_addresses_equal(&msk_local, &skc_local, false)) + mptcp_local_address((struct sock_common *)skc, &skc_local.addr); + if (mptcp_addresses_equal(&msk_local, &skc_local.addr, false)) return 0; + skc_local.addr.id = 0; + skc_local.flags = MPTCP_PM_ADDR_FLAG_IMPLICIT; + if (mptcp_pm_is_userspace(msk)) return mptcp_userspace_pm_get_local_id(msk, &skc_local); + skc_local.addr.port = 0; return mptcp_pm_nl_get_local_id(msk, &skc_local); } diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index afd517ff260c..16c901fabfa2 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1139,7 +1139,8 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, return err; } -int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc) +int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local) { struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; @@ -1148,7 +1149,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc pernet = pm_nl_get_pernet_from_msk(msk); rcu_read_lock(); - entry = __lookup_addr(pernet, skc); + entry = __lookup_addr(pernet, &local->addr); ret = entry ? entry->addr.id : -1; rcu_read_unlock(); if (ret >= 0) @@ -1159,12 +1160,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc if (!entry) return -ENOMEM; - entry->addr = *skc; - entry->addr.id = 0; - entry->addr.port = 0; - entry->ifindex = 0; - entry->flags = MPTCP_PM_ADDR_FLAG_IMPLICIT; - entry->lsk = NULL; + *entry = *local; ret = mptcp_pm_nl_append_new_local_addr(pernet, entry, true); if (ret < 0) kfree(entry); diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index eda4277bfff4..4f3e742ee41b 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -131,27 +131,22 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *msk, unsigned int id) } int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, - struct mptcp_addr_info *skc) + struct mptcp_pm_addr_entry *local) { - struct mptcp_pm_addr_entry *entry = NULL, new_entry; __be16 msk_sport = ((struct inet_sock *) inet_sk((struct sock *)msk))->inet_sport; + struct mptcp_pm_addr_entry *entry; spin_lock_bh(&msk->pm.lock); - entry = mptcp_userspace_pm_lookup_addr(msk, skc); + entry = mptcp_userspace_pm_lookup_addr(msk, &local->addr); spin_unlock_bh(&msk->pm.lock); if (entry) return entry->addr.id; - memset(&new_entry, 0, sizeof(struct mptcp_pm_addr_entry)); - new_entry.addr = *skc; - new_entry.addr.id = 0; - new_entry.flags = MPTCP_PM_ADDR_FLAG_IMPLICIT; - - if (new_entry.addr.port == msk_sport) - new_entry.addr.port = 0; + if (local->addr.port == msk_sport) + local->addr.port = 0; - return mptcp_userspace_pm_append_new_local_addr(msk, &new_entry, true); + return mptcp_userspace_pm_append_new_local_addr(msk, local, true); } bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index aca3de2baf81..318b293d0be1 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1129,8 +1129,10 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, const struct sk_buff *skb, bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining, struct mptcp_rm_list *rm_list); int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc); -int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc); -int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc); +int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local); +int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *local); bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc); bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); From patchwork Wed Jan 15 07:01:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13939922 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 2FA8123243D for ; Wed, 15 Jan 2025 07:01: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=1736924520; cv=none; b=YGIi9NRGFYwox4a9m4I76RLjlFtgB7Rh7M1TS+JU7dZ3Vv7LbW00EP+WuGAfRvWChLVtalxd57sCgcRH3ByKF9BDBhVyUaGrN4tGkg3jnKmprvVSbPvkrnayR+vVaQZuNpc6UA+W4wu4XcZe3HatAo1hqSFIe0v43HTlQj9zN34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736924520; c=relaxed/simple; bh=p/cY8bi5/8Li20u+/3HfOi4iyUK6++jVt8KeFPy9WYc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YLa6sPkItADBKpq/GtI/Uiq0n+5ZjEluRdPSWeYfETvmXZq6RRHBtC/Q/uouJw0PdPWCc2HqYF/E41nyBUozXITZheaXIdl+6f90ZpkktUcI49r9+rx42Cnxv6z2oIHhAIxCH2VVSxuylAgf3FQQDgRzxDkDsqnjZBETZ0E30L4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ov79ekO1; 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="ov79ekO1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6703C4CEDF; Wed, 15 Jan 2025 07:01:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736924519; bh=p/cY8bi5/8Li20u+/3HfOi4iyUK6++jVt8KeFPy9WYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ov79ekO1b08ltZLuvhcNCivemfB6jg4xF8ULzV7C1P2Vkd8ZeDGzLpnV7o14YsXrj AUkr0AlHvntQIiGUavndOxNbs8mfy7v6E6x7VA/A2WDsIotKm/rtdS84zHON4wBJMp 1nuxon6bRyJ8d5gKCHySBDXOWNqq3+R5ewp7mSRAY3GxJcjEzKznwRf95buBzn287/ vckSw78p5TzLfTDc+leZMe3iyas8+gJMxh/XqZH3/DAPgSpf9PD0w4ZO8O6y5uoItb Qhp3XJnDazoKW+8A16JbPn9a9iMi3ULqfEF/c9XBukY6aqfGeEig/ixa/xV6ER5gUj iTW4FDs/Qn0Bg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 7/7] mptcp: change is_backup interfaces as get_flags Date: Wed, 15 Jan 2025 15:01:40 +0800 Message-ID: <95a0cce72e48504cffcb5050a90f2a93d4be5651.1736924314.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang is_backup() interface of the path managers is not very common. A more common approach is to add a get_flags() interface to obtain the flags value of a given address. Then is_backup() can be implemented through get_flags() by test whether backup flag is set in the flags value. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 7 +++++-- net/mptcp/pm_netlink.c | 9 +++++---- net/mptcp/pm_userspace.c | 10 +++++----- net/mptcp/protocol.h | 6 ++++-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 8d9acc984a36..a0f4d06692cc 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -429,13 +429,16 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc) { struct mptcp_addr_info skc_local; + u8 flags; mptcp_local_address((struct sock_common *)skc, &skc_local); if (mptcp_pm_is_userspace(msk)) - return mptcp_userspace_pm_is_backup(msk, &skc_local); + flags = mptcp_userspace_pm_get_flags(msk, &skc_local); + else + flags = mptcp_pm_nl_get_flags(msk, &skc_local); - return mptcp_pm_nl_is_backup(msk, &skc_local); + return !!(flags & MPTCP_PM_ADDR_FLAG_BACKUP); } static int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 16c901fabfa2..4be4214cad34 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1168,18 +1168,19 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, return ret; } -bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc) +u8 mptcp_pm_nl_get_flags(struct mptcp_sock *msk, + struct mptcp_addr_info *skc) { struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk); struct mptcp_pm_addr_entry *entry; - bool backup; + u8 flags; rcu_read_lock(); entry = __lookup_addr(pernet, skc); - backup = entry && !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); + flags = entry ? entry->flags : 0; rcu_read_unlock(); - return backup; + return flags; } #define MPTCP_PM_CMD_GRP_OFFSET 0 diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 4f3e742ee41b..a7b836309d2b 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -149,18 +149,18 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, return mptcp_userspace_pm_append_new_local_addr(msk, local, true); } -bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, - struct mptcp_addr_info *skc) +u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, + struct mptcp_addr_info *skc) { struct mptcp_pm_addr_entry *entry; - bool backup; + u8 flags; spin_lock_bh(&msk->pm.lock); entry = mptcp_userspace_pm_lookup_addr(msk, skc); - backup = entry && !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); + flags = entry ? entry->flags : 0; spin_unlock_bh(&msk->pm.lock); - return backup; + return flags; } static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *info) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 318b293d0be1..80a18877e47d 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1134,8 +1134,10 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local); bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc); -bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); -bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); +u8 mptcp_pm_nl_get_flags(struct mptcp_sock *msk, + struct mptcp_addr_info *skc); +u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, + struct mptcp_addr_info *skc); int mptcp_pm_nl_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,