From patchwork Sat Oct 12 14:19:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13833591 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 3E7381898F2 for ; Sat, 12 Oct 2024 14:20: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=1728742802; cv=none; b=Kdgh/p/M21J7bxTGwauzQNlAV1kxUTPD2ktqcZG/dRL52vnk+TN1+BL7GV32kjMunsOuCgXKk0hueZvGrXz7k0Lw9sTuhdnSskKc20usOOMozN7cE8iU+xOI0iGikqc4SnD6CTqPGVajZ5F+F1oats6YIQ9fzodW5Zl0ajV7xHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728742802; c=relaxed/simple; bh=R5R80HRboK5w8C3/4xRGcUQ8Uaa3bg7sNhcnXfOg5ro=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iVg1q1vA05vNByX8oQGZJ+k4HejXv8kFfAKtslgrzxevBHpMuJbixY+5ek7/7dzGdjGFKsZwiR+o4SNSx1z4rv+/00OfIqMjns6WlHX9J1KfOST3kuA3iWWrcPlT3tXYI/9Hle3yrqBMTSUK4gI17RmJLKvnMSpj7svte+8rHBo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WXQOTC5h; 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="WXQOTC5h" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECF4FC4CEC6; Sat, 12 Oct 2024 14:20:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728742801; bh=R5R80HRboK5w8C3/4xRGcUQ8Uaa3bg7sNhcnXfOg5ro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WXQOTC5hd2d2q9/80cy88D1RTqw/xLtjZxMalSG3XEnEml6Vo149Ode7WV/3E25Gz uqmeSlAhuGaiyUlF9fRp0ZjF3Nb5cAd1YkO/3BwuWAA+4rOzxBkW+IxPvBp+SZeqGW 2d+jkVBBRpSTvTl+OKFfn2EYeufONiaTpk4uSVtlxxhjLk6ZdjVTanNJgpdJE2tLi8 XXW8tbdTASxnFm+wHuEYjX3pZmp6Hq5gMcmves8y+ezXZa/6jzguYLraUoPR0jL7Ty 7sBSbVo/vAsoDeRChhPknXpaxtHigd9loq66IB/oJX6BNB8O0EFQoDOvuQWoCZEi/G wy8VfatNwWlWg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 01/11] mptcp: add struct mptcp_id_bitmap Date: Sat, 12 Oct 2024 22:19:41 +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 A new struct mptcp_id_bitmap is defined to unify all bitmap type of address IDs for both in-kernel PM and userspace PM. This type can be used to easily refactor dump_addr() interface of the path managers to accept an mptcp_id_bitmap type parameter. It also allows this parameter of dump_addr() can be modified by BPF program when implementing this interface of a BFP path manager. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 2 +- net/mptcp/pm_netlink.c | 42 ++++++++++++++++++++-------------------- net/mptcp/pm_userspace.c | 14 ++++++-------- net/mptcp/protocol.h | 6 +++++- 4 files changed, 33 insertions(+), 31 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 16c336c51940..5afc1f8e5ca7 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -536,7 +536,7 @@ void mptcp_pm_data_reset(struct mptcp_sock *msk) WRITE_ONCE(pm->addr_signal, 0); WRITE_ONCE(pm->remote_deny_join_id0, false); pm->status = 0; - bitmap_fill(msk->pm.id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + bitmap_fill(msk->pm.id_avail_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); } void mptcp_pm_data_init(struct mptcp_sock *msk) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index d37fefbaf34f..20dab8158c93 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -37,7 +37,7 @@ struct pm_nl_pernet { unsigned int local_addr_max; unsigned int subflows_max; unsigned int next_id; - DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + struct mptcp_id_bitmap id_bitmap; }; #define MPTCP_PM_ADDR_MAX 8 @@ -161,7 +161,7 @@ select_local_address(const struct pm_nl_pernet *pernet, if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)) continue; - if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap)) + if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap.map)) continue; new_local->addr = entry->addr; @@ -189,7 +189,7 @@ select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock *msk, * can lead to additional addresses not being announced. */ list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) { - if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap)) + if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap.map)) continue; if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) @@ -243,7 +243,7 @@ bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk) struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk); if (msk->pm.subflows == mptcp_pm_get_subflows_max(msk) || - (find_next_and_bit(pernet->id_bitmap, msk->pm.id_avail_bitmap, + (find_next_and_bit(pernet->id_bitmap.map, msk->pm.id_avail_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1, 0) == MPTCP_PM_MAX_ADDR_ID + 1)) { WRITE_ONCE(msk->pm.work_pending, false); return false; @@ -443,15 +443,15 @@ static unsigned int fill_remote_addresses_vec(struct mptcp_sock *msk, msk->pm.subflows++; addrs[i++] = remote; } else { - DECLARE_BITMAP(unavail_id, MPTCP_PM_MAX_ADDR_ID + 1); + struct mptcp_id_bitmap unavail_id; /* Forbid creation of new subflows matching existing * ones, possibly already created by incoming ADD_ADDR */ - bitmap_zero(unavail_id, MPTCP_PM_MAX_ADDR_ID + 1); + bitmap_zero(unavail_id.map, MPTCP_PM_MAX_ADDR_ID + 1); mptcp_for_each_subflow(msk, subflow) if (READ_ONCE(subflow->local_id) == local->id) - __set_bit(subflow->remote_id, unavail_id); + __set_bit(subflow->remote_id, unavail_id.map); mptcp_for_each_subflow(msk, subflow) { ssk = mptcp_subflow_tcp_sock(subflow); @@ -460,7 +460,7 @@ static unsigned int fill_remote_addresses_vec(struct mptcp_sock *msk, if (deny_id0 && !addrs[i].id) continue; - if (test_bit(addrs[i].id, unavail_id)) + if (test_bit(addrs[i].id, unavail_id.map)) continue; if (!mptcp_pm_addr_families_match(sk, local, &addrs[i])) @@ -470,7 +470,7 @@ static unsigned int fill_remote_addresses_vec(struct mptcp_sock *msk, /* forbid creating multiple address towards * this id */ - __set_bit(addrs[i].id, unavail_id); + __set_bit(addrs[i].id, unavail_id.map); msk->pm.subflows++; i++; } @@ -558,7 +558,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) rcu_read_lock(); entry = __lookup_addr(pernet, &mpc_addr); if (entry) { - __clear_bit(entry->addr.id, msk->pm.id_avail_bitmap); + __clear_bit(entry->addr.id, msk->pm.id_avail_bitmap.map); msk->mpc_endpoint_id = entry->addr.id; backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); } @@ -596,7 +596,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) if (!mptcp_pm_alloc_anno_list(msk, &local.addr)) return; - __clear_bit(local.addr.id, msk->pm.id_avail_bitmap); + __clear_bit(local.addr.id, msk->pm.id_avail_bitmap.map); msk->pm.add_addr_signaled++; /* Special case for ID0: set the correct ID */ @@ -625,7 +625,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) fullmesh = !!(local.flags & MPTCP_PM_ADDR_FLAG_FULLMESH); - __clear_bit(local.addr.id, msk->pm.id_avail_bitmap); + __clear_bit(local.addr.id, msk->pm.id_avail_bitmap.map); /* Special case for ID0: set the correct ID */ if (local.addr.id == msk->mpc_endpoint_id) @@ -991,7 +991,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet, ret = -ERANGE; goto out; } - if (test_bit(entry->addr.id, pernet->id_bitmap)) { + if (test_bit(entry->addr.id, pernet->id_bitmap.map)) { ret = -EBUSY; goto out; } @@ -1025,7 +1025,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet, if (!entry->addr.id && needs_id) { find_next: - entry->addr.id = find_next_zero_bit(pernet->id_bitmap, + entry->addr.id = find_next_zero_bit(pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1, pernet->next_id); if (!entry->addr.id && pernet->next_id != 1) { @@ -1037,7 +1037,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet, if (!entry->addr.id && needs_id) goto out; - __set_bit(entry->addr.id, pernet->id_bitmap); + __set_bit(entry->addr.id, pernet->id_bitmap.map); if (entry->addr.id > pernet->next_id) pernet->next_id = entry->addr.id; @@ -1486,7 +1486,7 @@ static bool mptcp_pm_remove_anno_addr(struct mptcp_sock *msk, if (ret || force) { spin_lock_bh(&msk->pm.lock); if (ret) { - __set_bit(addr->id, msk->pm.id_avail_bitmap); + __set_bit(addr->id, msk->pm.id_avail_bitmap.map); msk->pm.add_addr_signaled--; } mptcp_pm_remove_addr(msk, &list); @@ -1498,7 +1498,7 @@ static bool mptcp_pm_remove_anno_addr(struct mptcp_sock *msk, static void __mark_subflow_endp_available(struct mptcp_sock *msk, u8 id) { /* If it was marked as used, and not ID 0, decrement local_addr_used */ - if (!__test_and_set_bit(id ? : msk->mpc_endpoint_id, msk->pm.id_avail_bitmap) && + if (!__test_and_set_bit(id ? : msk->mpc_endpoint_id, msk->pm.id_avail_bitmap.map) && id && !WARN_ON_ONCE(msk->pm.local_addr_used == 0)) msk->pm.local_addr_used--; } @@ -1629,7 +1629,7 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info) pernet->addrs--; list_del_rcu(&entry->list); - __clear_bit(entry->addr.id, pernet->id_bitmap); + __clear_bit(entry->addr.id, pernet->id_bitmap.map); spin_unlock_bh(&pernet->lock); mptcp_nl_remove_subflow_and_signal_addr(sock_net(skb->sk), entry); @@ -1693,7 +1693,7 @@ static void mptcp_pm_flush_addrs_and_subflows(struct mptcp_sock *msk, if (slist.nr) mptcp_pm_nl_rm_subflow_received(msk, &slist); /* Reset counters: maybe some subflows have been removed before */ - bitmap_fill(msk->pm.id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + bitmap_fill(msk->pm.id_avail_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); msk->pm.local_addr_used = 0; spin_unlock_bh(&msk->pm.lock); } @@ -1751,7 +1751,7 @@ int mptcp_pm_nl_flush_addrs_doit(struct sk_buff *skb, struct genl_info *info) list_splice_init(&pernet->local_addr_list, &free_list); __reset_counters(pernet); pernet->next_id = 1; - bitmap_zero(pernet->id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + bitmap_zero(pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); spin_unlock_bh(&pernet->lock); mptcp_nl_flush_addrs_list(sock_net(skb->sk), &free_list); synchronize_rcu(); @@ -1867,7 +1867,7 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, spin_lock_bh(&pernet->lock); for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { - if (test_bit(i, pernet->id_bitmap)) { + if (test_bit(i, pernet->id_bitmap.map)) { entry = __lookup_addr_by_id(pernet, i); if (!entry) break; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 2cceded3a83a..e3f29d8865f4 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -30,15 +30,15 @@ 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_entry *match = NULL; struct sock *sk = (struct sock *)msk; + struct mptcp_id_bitmap id_bitmap; struct mptcp_pm_addr_entry *e; bool addr_match = false; 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); list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) { @@ -52,7 +52,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) { @@ -67,7 +67,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); @@ -612,19 +612,17 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) 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 net *net = sock_net(msg->sk); struct mptcp_pm_addr_entry *entry; + struct mptcp_id_bitmap *bitmap; struct mptcp_sock *msk; struct nlattr *token; int ret = -EINVAL; struct sock *sk; void *hdr; - bitmap = (struct id_bitmap *)cb->ctx; + bitmap = (struct mptcp_id_bitmap *)cb->ctx; token = info->attrs[MPTCP_PM_ATTR_TOKEN]; msk = mptcp_token_get_sock(net, nla_get_u32(token)); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 7848a1989d17..56b2c431dcb5 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -211,6 +211,10 @@ enum mptcp_addr_signal_status { /* max value of mptcp_addr_info.id */ #define MPTCP_PM_MAX_ADDR_ID U8_MAX +struct mptcp_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; @@ -231,7 +235,7 @@ struct mptcp_pm_data { u8 pm_type; u8 subflows; u8 status; - DECLARE_BITMAP(id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + struct mptcp_id_bitmap id_avail_bitmap; struct mptcp_rm_list rm_list_tx; struct mptcp_rm_list rm_list_rx; }; From patchwork Sat Oct 12 14:19:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13833592 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 5E38638384 for ; Sat, 12 Oct 2024 14:20: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=1728742803; cv=none; b=k7TtEcrsQx5iYgzxgbCTrsOZ90cbrgAe8xIyBCBCmUtbYaSKhwHrD47N+LJj33yjsiJwaf9Xbar78GCKXHRtr5FpVVYHxQMGcfVkaYMj/6lBRnf7viwfqSFkGoa1/wUxPeL/jOiSiUfpUh0iQCS4jDWlaaQtsa9d9qF5fCtlh/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728742803; c=relaxed/simple; bh=zdST2xDFuP+5+cIVwp1WkZprydoGrJPC52sz/VBBBdM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lgw2f525F2yHWrSAqWOlOxyI3W1OEYoLrZsBHpnUCeRgdR9XithU/VV3ZTbaKxKq6vT3diHzUvwm/WK/Wu0yJ618Jg4QHj/Q0JyDc7k8TdaiyntDdw/I4w56ORh+umZoTuDaNitwPvprChd6997lbPAcexz4AGJryPNQwwf1x6U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Bklj3+Gp; 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="Bklj3+Gp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31337C4CECC; Sat, 12 Oct 2024 14:20:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728742802; bh=zdST2xDFuP+5+cIVwp1WkZprydoGrJPC52sz/VBBBdM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bklj3+Gp+QtSqbO0xJEcIh09dUaEXW7Ck4qkSj04VfVE3nV+Z1Dq2EqN10Dx1Ck2u bhnPcjbQ5JASDiYQnhQPdW85u0hU8iA+09AoMavFHfORjuOTgorfFFGMLSATaDzCA7 mHVX3KVIBP/XfWjKT6sno350L/GpFS6L/y63BcyN6fv2k2BHSOX2G1EjggFZs/NZPn nCc9AHbZLv2hVYsAitbyv/syxtrWJ8nZXyC902bl0wr4xUQsSFq6EkLMBWfAVj+ED/ fmGaX0UDSSUgV75+mjOtNCOx+uDUcwlBiXbXLoyBqA69MOD/gZAaE+h3k8+V5vOdvs wSorKFyT+/rmA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 02/11] mptcp: add mptcp_userspace_pm_get_sock helper Date: Sat, 12 Oct 2024 22:19:42 +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 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. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 137 +++++++++++++-------------------------- 1 file changed, 44 insertions(+), 93 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index e3f29d8865f4..6aaf10b8ddd1 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -166,36 +166,51 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, return backup; } -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_info *info) { struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; + struct mptcp_sock *msk = NULL; + + if (!token) { + GENL_SET_ERR_MSG(info, "missing required inputs"); + goto out; + } + + msk = mptcp_token_get_sock(genl_info_net(info), nla_get_u32(token)); + if (!msk) { + NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + goto out; + } + + if (!mptcp_pm_is_userspace(msk)) { + GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); + sock_put((struct sock *)msk); + msk = NULL; + } + +out: + return msk; +} + +int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) +{ struct nlattr *addr = info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry addr_val; struct mptcp_sock *msk; int err = -EINVAL; struct sock *sk; - u32 token_val; - if (!addr || !token) { + if (!addr) { GENL_SET_ERR_MSG(info, "missing required inputs"); return err; } - token_val = nla_get_u32(token); - - msk = mptcp_token_get_sock(sock_net(skb->sk), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk = mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } sk = (struct sock *)msk; - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto announce_err; - } - err = mptcp_pm_parse_entry(addr, info, true, &addr_val); if (err < 0) { GENL_SET_ERR_MSG(info, "error parsing local address"); @@ -268,7 +283,6 @@ static int mptcp_userspace_pm_remove_id_zero_address(struct mptcp_sock *msk, int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *id = info->attrs[MPTCP_PM_ATTR_LOC_ID]; struct mptcp_pm_addr_entry *match; struct mptcp_pm_addr_entry *entry; @@ -276,30 +290,21 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) LIST_HEAD(free_list); int err = -EINVAL; struct sock *sk; - u32 token_val; u8 id_val; - if (!id || !token) { + if (!id) { GENL_SET_ERR_MSG(info, "missing required inputs"); return err; } id_val = nla_get_u8(id); - token_val = nla_get_u32(token); - msk = mptcp_token_get_sock(sock_net(skb->sk), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk = mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } sk = (struct sock *)msk; - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto out; - } - if (id_val == 0) { err = mptcp_userspace_pm_remove_id_zero_address(msk, info); goto out; @@ -333,7 +338,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 = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry entry = { 0 }; struct mptcp_addr_info addr_r; @@ -341,28 +345,18 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info *info) struct mptcp_sock *msk; int err = -EINVAL; struct sock *sk; - u32 token_val; - if (!laddr || !raddr || !token) { + if (!laddr || !raddr) { GENL_SET_ERR_MSG(info, "missing required inputs"); return err; } - token_val = nla_get_u32(token); - - msk = mptcp_token_get_sock(genl_info_net(info), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk = mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } sk = (struct sock *)msk; - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto create_err; - } - err = mptcp_pm_parse_entry(laddr, info, true, &entry); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); @@ -465,35 +459,24 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_sock *msk, int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *laddr = 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 = -EINVAL; - u32 token_val; - if (!laddr || !raddr || !token) { + if (!laddr || !raddr) { GENL_SET_ERR_MSG(info, "missing required inputs"); return err; } - token_val = nla_get_u32(token); - - msk = mptcp_token_get_sock(genl_info_net(info), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk = mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } sk = (struct sock *)msk; - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto destroy_err; - } - err = mptcp_pm_parse_addr(laddr, info, &addr_l); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); @@ -556,30 +539,18 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, }; struct mptcp_pm_addr_entry rem = { .addr = { .family = AF_UNSPEC }, }; struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; - struct net *net = sock_net(skb->sk); struct mptcp_sock *msk; int ret = -EINVAL; struct sock *sk; - u32 token_val; u8 bkup = 0; - token_val = nla_get_u32(token); - - msk = mptcp_token_get_sock(net, token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk = mptcp_userspace_pm_get_sock(info); + if (!msk) return ret; - } sk = (struct sock *)msk; - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "userspace PM not selected"); - goto set_flags_err; - } - ret = mptcp_pm_parse_entry(attr, info, false, &loc); if (ret < 0) goto set_flags_err; @@ -613,31 +584,21 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { const struct genl_info *info = genl_info_dump(cb); - struct net *net = sock_net(msg->sk); struct mptcp_pm_addr_entry *entry; struct mptcp_id_bitmap *bitmap; struct mptcp_sock *msk; - struct nlattr *token; int ret = -EINVAL; struct sock *sk; void *hdr; bitmap = (struct mptcp_id_bitmap *)cb->ctx; - token = info->attrs[MPTCP_PM_ATTR_TOKEN]; - msk = mptcp_token_get_sock(net, nla_get_u32(token)); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk = mptcp_userspace_pm_get_sock(info); + if (!msk) return ret; - } sk = (struct sock *)msk; - 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); list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { @@ -662,7 +623,6 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, release_sock(sk); ret = msg->len; -out: sock_put(sk); return ret; } @@ -671,28 +631,19 @@ int mptcp_userspace_pm_get_addr(struct sk_buff *skb, struct genl_info *info) { struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; - struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; struct mptcp_pm_addr_entry addr, *entry; - struct net *net = sock_net(skb->sk); struct mptcp_sock *msk; struct sk_buff *msg; int ret = -EINVAL; struct sock *sk; void *reply; - msk = mptcp_token_get_sock(net, nla_get_u32(token)); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk = mptcp_userspace_pm_get_sock(info); + if (!msk) return ret; - } sk = (struct sock *)msk; - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto out; - } - ret = mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) goto out; From patchwork Sat Oct 12 14:19:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13833593 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 AA1191922CA for ; Sat, 12 Oct 2024 14:20:04 +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=1728742804; cv=none; b=B9pA/nq5jaParsJ8c/aaNRUoPhXdCoCJD0JzOFsZVvknaG81PE3Lt+IgfNY75tCLvS+F+Rnx2k1Lx5+Z60+KrKfgMucbSYe1c/kmfDCmSGOiSSZB+ouch60fc10YPDJXA5hSylXUjy9C6QtPk2USahgtKqPjJMKQk3k1UcvPU9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728742804; c=relaxed/simple; bh=EpfqCeh7iwHgaOQQPw5oaL7RdTD7elimm+LB7+83eck=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=My8HJ5OzLtkmIFcAyuXtTaaxS7C/Z+hPBBFhmGgrybMIbxuGi8lRxA1ZJBNpKQzUfEv7PhjlGdJwi+gUHU0tez2RNIuprrZkVo5/2LqM+ZW04oVTOURRqghpnS0Q8zzPDwDXzSv3kts8KRQ5p9TV7Em73NYA3woPqOzgSAYvHF4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eT7M1ItV; 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="eT7M1ItV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62651C4CEC6; Sat, 12 Oct 2024 14:20:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728742804; bh=EpfqCeh7iwHgaOQQPw5oaL7RdTD7elimm+LB7+83eck=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eT7M1ItVkcv/FVJdFPQg4RzMoi8SccOOj3xLqh6MRaYg7Zxrmkqa8DgT3d6omPBe7 Qnam0ZP9znSW6D5FrxaXNnfBe2jKuwQSrMc3rUuTJBVT6HgnPzKYDqTn1O8lm75Da+ 9hLag3GYIg4znsKhEeeI8PMmzui6+QxUEcDcfJTJDYDSkTNcyKvuk3dUzZWDPNudPV K4s5Pxd/+cmvmREPzqf4pvCD2HutxvpRPkjKfeBR7ELIP050rjXXyYUfh0GOCfdve1 oXDxFBisNoPr+8WSTstoqh2ZdEiM80GayfXMIxtzZCDIQ0zq9wJUIfXqUas8nG4tiS FNL24DbQZzyJg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 03/11] mptcp: use __lookup_addr in pm_netlink Date: Sat, 12 Oct 2024 22:19:43 +0800 Message-ID: <5a76491bbf4901c1c76741ec048cc31c03e8f400.1728742592.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 helper __lookup_addr() can be used in mptcp_pm_nl_get_local_id() and mptcp_pm_nl_is_backup() to simplify the code if using list_for_each_entry_rcu() instead of list_for_each_entry() in it. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 20dab8158c93..9a77395956ef 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -524,7 +524,7 @@ __lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info) { struct mptcp_pm_addr_entry *entry; - list_for_each_entry(entry, &pernet->local_addr_list, list) { + list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) { if (mptcp_addresses_equal(&entry->addr, info, entry->addr.port)) return entry; } @@ -1146,12 +1146,9 @@ 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(); - list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) { - if (mptcp_addresses_equal(&entry->addr, skc, entry->addr.port)) { - ret = entry->addr.id; - break; - } - } + entry = __lookup_addr(pernet, skc); + if (entry) + ret = entry->addr.id; rcu_read_unlock(); if (ret >= 0) return ret; @@ -1181,12 +1178,9 @@ bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc) bool backup = false; rcu_read_lock(); - list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) { - if (mptcp_addresses_equal(&entry->addr, skc, entry->addr.port)) { - backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); - break; - } - } + entry = __lookup_addr(pernet, skc); + if (entry) + backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); rcu_read_unlock(); return backup; From patchwork Sat Oct 12 14:19:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13833594 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 EDD271922CA for ; Sat, 12 Oct 2024 14:20: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=1728742806; cv=none; b=oSrxLx56wNKIPDALcEA2imBA6fIMU+UrDxMXvOuPVmSuJPLVxpqBXwVIL5U/cwLRh9dAqtqWb0R/G53Z5+p5QrLIihRvEG6UNdcW6/kgb/qAAy+VP+tEEC+Apab42opLHWZ8TACAsrklbBCfUKYfuTtvxt37O+L4FXy9lCokD0k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728742806; c=relaxed/simple; bh=TpN68kbKXHxCrx1JwqvHFzDXhArZtu6TA9dlbd/rY2o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nou7wfS1oQEPYRRgrdHnlQUdKSe6AMZv2Y7RuHXndy3Nk2hcq/JNceFTSfXws5UZLzHUU3Id5fQO71SB28sR1D9cm2qhaJgUdQz2etDTwYO6lmA2UMAiCoazlWhkSvzHToqYSw5/keF2xT6qGNjKewSJr37TP5N5K7YOUlWI38g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Uaw5C1J6; 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="Uaw5C1J6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B97D6C4CECC; Sat, 12 Oct 2024 14:20:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728742805; bh=TpN68kbKXHxCrx1JwqvHFzDXhArZtu6TA9dlbd/rY2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Uaw5C1J6dRAAsAoyb+MsNZgBvIkykSHllJfOAE4GFXZdUqXt2p0fP9dO1WMvJ6QdX IZLks9kcxOC2ks0SZYxTwURUBBMZowk0sJF/jfbU8jGMwiRsOek9VLvbzBn61Flmf8 64VJXlsz1+yB6w0F79fFM698Vlxt8Zu4QjlsmZdC7f7I9465ILpBwxquUFyQAyXaRK j916n9O8yJEYEsbX0e+qpFnYpC2/wxG9AHuJ4I4vnBVGYpfrQ4kygRDfxQMttAg4YA 2+nfHh/Hfh1ub8Ozx3EtXhp0GgO27/wIGXIzWs9nyf/y56FjoIaBuYoTsOks/0uLry K+/1qo9c5/skA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 04/11] mptcp: add mptcp_for_each_address macros Date: Sat, 12 Oct 2024 22:19:44 +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 Similar to mptcp_for_each_subflow() and mptcp_for_each_subflow_safe() macros, this patch adds two new macros mptcp_for_each_address() and mptcp_for_each_address_safe() to iterate over the address entries on userspace_pm_local_addr_list of the mptcp socket. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 12 ++++++------ net/mptcp/protocol.h | 5 +++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 6aaf10b8ddd1..4baa2a7dfd26 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -41,7 +41,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, bitmap_zero(id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); spin_lock_bh(&msk->pm.lock); - list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_address(msk, e) { addr_match = mptcp_addresses_equal(&e->addr, &entry->addr, true); if (addr_match && entry->addr.id == 0 && needs_id) entry->addr.id = e->addr.id; @@ -92,7 +92,7 @@ static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk, { struct mptcp_pm_addr_entry *entry, *tmp; - list_for_each_entry_safe(entry, tmp, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_address_safe(msk, entry, tmp) { if (mptcp_addresses_equal(&entry->addr, &addr->addr, false)) { /* TODO: a refcount is needed because the entry can * be used multiple times (e.g. fullmesh mode). @@ -112,7 +112,7 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *msk, unsigned int id) { struct mptcp_pm_addr_entry *entry; - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_address(msk, entry) { if (entry->addr.id == id) return entry; } @@ -127,7 +127,7 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, inet_sk((struct sock *)msk))->inet_sport; spin_lock_bh(&msk->pm.lock); - list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_address(msk, e) { if (mptcp_addresses_equal(&e->addr, skc, false)) { entry = e; break; @@ -155,7 +155,7 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, bool backup = false; spin_lock_bh(&msk->pm.lock); - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + mptcp_for_each_address(msk, entry) { if (mptcp_addresses_equal(&entry->addr, skc, false)) { backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); break; @@ -601,7 +601,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, 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_address(msk, entry) { if (test_bit(entry->addr.id, bitmap->map)) continue; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 56b2c431dcb5..dc777a3e05a2 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -358,6 +358,11 @@ struct mptcp_sock { #define mptcp_for_each_subflow_safe(__msk, __subflow, __tmp) \ list_for_each_entry_safe(__subflow, __tmp, &((__msk)->conn_list), node) +#define mptcp_for_each_address(__msk, __entry) \ + list_for_each_entry(__entry, &((__msk)->pm.userspace_pm_local_addr_list), list) +#define mptcp_for_each_address_safe(__msk, __entry, __tmp) \ + list_for_each_entry_safe(__entry, __tmp, &((__msk)->pm.userspace_pm_local_addr_list), list) + extern struct genl_family mptcp_genl_family; static inline void msk_owned_by_me(const struct mptcp_sock *msk) From patchwork Sat Oct 12 14:19:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13833595 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 4D5521922CA for ; Sat, 12 Oct 2024 14:20:06 +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=1728742807; cv=none; b=h7MDoYEZchfwU4vZvhSSivAFrFIHpAIjHxamB6Q+OcilLRX8PCkMM7zi9ls/df4huiu+ItaYUW4amKqxVkXn806V5oO+pNgO6174uPC7xisLK6IP2mCrZvQtDk4ipIFhp5LxjLjedtYJLekFj0lv/jo8BwuDihehEeYEmItPt8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728742807; c=relaxed/simple; bh=zDs5f+dKLug4HQh5+daVjeNyaW4UwNZ0HjcVHGItBa8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GfBHA6NX9QKHrb4DKgiCspLU/tUTXRv/FnB9VrJszgyeLsJYodm+aTG0QJj1WHSTBcJ+nUsc+pbMSuv26s9+qyamEqSqJN/ZlY97y34y3ZYXv4t/RDuczel4NLN3A6Q68S52EZ02AKyJ+lc1BUmpcqAraWoRo07AlqVhid+w+/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tbMSJow3; 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="tbMSJow3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15FFFC4CEC6; Sat, 12 Oct 2024 14:20:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728742806; bh=zDs5f+dKLug4HQh5+daVjeNyaW4UwNZ0HjcVHGItBa8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tbMSJow3EX0i24dc1tWJMrVLk3y+SW8kyZA+N7gK6DHyJk6D0mqG2VZd079VDjYTi l5ept9vgHNL5nn9d9M255YJQ486w0RicYwQ/vKSBoeof4yHwdBOygF7VGMaSmAsiNB 8z4ErF7GwBsp/42AXmJE+8hVq2PsZiDDrjxGQi17XPTGxJj4H6cdgItLn5ANcxCrLq fHYtjw4E8DNH3fDJYee4zpUQrq2FP0VnQLyGt9dmIf8E/Ml57BGtSPqQWA+vdarxbw kZ5Jxf2dOM0LAFIvbGjQY5nWHpVOvJ9Ydj2DVI0RZcal1+5sVvtli2xHNE3b7ofjxe sMt2iUId2Xn9w== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 05/11] mptcp: use sock_kfree_s instead of kfree Date: Sat, 12 Oct 2024 22:19:45 +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 The local address entries on the userspace_pm_local_addr_list are allocated by sock_kmalloc(). It's better to use sock_kfree_s() to free them, instead of using kfree(). Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 4baa2a7dfd26..a06b83fd42e2 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -91,6 +91,7 @@ static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *addr) { struct mptcp_pm_addr_entry *entry, *tmp; + struct sock *sk = (struct sock *)msk; mptcp_for_each_address_safe(msk, entry, tmp) { if (mptcp_addresses_equal(&entry->addr, &addr->addr, false)) { @@ -98,7 +99,7 @@ static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk, * be used multiple times (e.g. fullmesh mode). */ list_del_rcu(&entry->list); - kfree(entry); + sock_kfree_s(sk, entry, sizeof(*entry)); msk->pm.local_addr_used--; return 0; } From patchwork Sat Oct 12 14:19:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13833596 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 A08FF38384 for ; Sat, 12 Oct 2024 14:20:08 +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=1728742808; cv=none; b=BMC/loLPlwHcRcYILJJ6xbFkrkPdhfMS01i/ZvdCU/8I73d4mVfyt+BxEXq+5U6if0a1iHNzmCJ9echc/o2w1mQ/LnLfRFfv/O7rKhKCDbVAFjN3urLTqPaUQqq2rFwU1skv0YV6aoK1wXceDKLVPUe0BmcVTeQUayvzrnvhtcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728742808; c=relaxed/simple; bh=0E5aH9mdao6+3jFaO9MNPPu1Xe+HuRwqeZXXoK0ezoU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M/0V3KZzIfb7F6IfTM42FzH+kLS77n4EjhvEuG/vQYy+l3bweof7RyRbkbQVNSiop1KMbIpd/phyV/JsK0jtaVQGXTTySgQT1n/ReD2h1FfdFLJMUhdNIH+XjbytnbWBUKaPWBAM6lHMGGel4NV3+9h7+x24ImEm2bmYJRcQxvs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DgTEs46S; 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="DgTEs46S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6145AC4CECC; Sat, 12 Oct 2024 14:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728742808; bh=0E5aH9mdao6+3jFaO9MNPPu1Xe+HuRwqeZXXoK0ezoU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DgTEs46S2v9C7UEqFtEi8BVTPFWFu6dckZGjZ4hflo+Bnaglq+ExGZWFILq5uoIWx ZiFz5ElHKEU16/kSmemny+X/BtBAtNZlTPfh3MISdmBLfVn0OVpbo533aH49KUTbnu Sh2fMq3XK9CpEZ/WtXXtfCYwialyCvDVZ8WanTYbi+84xOeK3Vkk6H4Px+bNDEheeN bW8I4RVRKpUpT63Qhmi1pbMWxjRger3DZ48O07iAJB5ZAIQcj+r5VeK3lz8A8MiiNu MvDPuMB6LQfhv10lvHq04c0r+EZWSc5RPA63UEoH4VnE1NHfw9UW2MYIxpvCzm1liB FoJdUQ3laqMHQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 06/11] mptcp: add lookup_addr for userspace pm Date: Sat, 12 Oct 2024 22:19:46 +0800 Message-ID: <9657733e03ad38c5c01d2899cfd7d5b0c4ffffd7.1728742592.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 Like __lookup_addr() helper in pm_netlink.c, a new helper mptcp_userspace_pm_lookup_addr() is also defined in pm_userspace.c. It looks up the corresponding mptcp_pm_addr_entry address in userspace_pm_local_addr_list through the passed "addr" parameter and returns it. This helper can be used in mptcp_userspace_pm_delete_local_addr(), mptcp_userspace_pm_get_local_id() and mptcp_userspace_pm_is_backup() to simplify the code. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 56 +++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index a06b83fd42e2..e8edbe3a2600 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -26,6 +26,18 @@ void mptcp_free_local_addr_list(struct mptcp_sock *msk) } } +static struct mptcp_pm_addr_entry * +mptcp_userspace_pm_lookup_addr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr) +{ + struct mptcp_pm_addr_entry *entry, *tmp; + + mptcp_for_each_address_safe(msk, entry, tmp) { + if (mptcp_addresses_equal(&entry->addr, addr, false)) + return entry; + } + return NULL; +} + static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *entry, bool needs_id) @@ -90,22 +102,20 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *addr) { - struct mptcp_pm_addr_entry *entry, *tmp; struct sock *sk = (struct sock *)msk; + struct mptcp_pm_addr_entry *entry; - mptcp_for_each_address_safe(msk, entry, tmp) { - if (mptcp_addresses_equal(&entry->addr, &addr->addr, false)) { - /* TODO: a refcount is needed because the entry can - * be used multiple times (e.g. fullmesh mode). - */ - list_del_rcu(&entry->list); - sock_kfree_s(sk, entry, sizeof(*entry)); - msk->pm.local_addr_used--; - return 0; - } - } - - return -EINVAL; + entry = mptcp_userspace_pm_lookup_addr(msk, &addr->addr); + if (!entry) + return -EINVAL; + + /* TODO: a refcount is needed because the entry can + * be used multiple times (e.g. fullmesh mode). + */ + list_del_rcu(&entry->list); + sock_kfree_s(sk, entry, sizeof(*entry)); + msk->pm.local_addr_used--; + return 0; } static struct mptcp_pm_addr_entry * @@ -123,17 +133,12 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *msk, unsigned int id) int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc) { - struct mptcp_pm_addr_entry *entry = NULL, *e, new_entry; + struct mptcp_pm_addr_entry *entry = NULL, new_entry; __be16 msk_sport = ((struct inet_sock *) inet_sk((struct sock *)msk))->inet_sport; spin_lock_bh(&msk->pm.lock); - mptcp_for_each_address(msk, e) { - if (mptcp_addresses_equal(&e->addr, skc, false)) { - entry = e; - break; - } - } + entry = mptcp_userspace_pm_lookup_addr(msk, skc); spin_unlock_bh(&msk->pm.lock); if (entry) return entry->addr.id; @@ -156,12 +161,9 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, bool backup = false; spin_lock_bh(&msk->pm.lock); - mptcp_for_each_address(msk, entry) { - if (mptcp_addresses_equal(&entry->addr, skc, false)) { - backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); - break; - } - } + entry = mptcp_userspace_pm_lookup_addr(msk, skc); + if (entry) + backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); spin_unlock_bh(&msk->pm.lock); return backup; From patchwork Sat Oct 12 14:19:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13833597 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 EBB64178395 for ; Sat, 12 Oct 2024 14:20:09 +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=1728742810; cv=none; b=XXlei4YFfSSd9VYyFfshCQlrP4zxl8i9FSGVs9oD7RWQDlcenOkTN8g/P2dR3TyUYwEfCWsld/7aZ0GZqLLd4i7JBq4pBn+iOPTC4vume92pYUSN0EH4hUkB5Rl41A5OUndPgAeDzLiGVbY5oUSBV3pzErFMBE5082WY3vMWGJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728742810; c=relaxed/simple; bh=HgcnOJp7BoG7+XWL3+KkCN8XJ0aLr9B4V4kGhZ6HQQI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n6TD5CLymDBVaTzo/yD+gEBtw9SN2XzfCbkk4B/a6wEHa5UOip69Gmab8JJOdY03xxL2pWUsbgSLjvj2QtzItQ0RI8Z28zpYyYpp4nXzTy78lT/LYDBPFEcW97uC4CIsl/799ml3sFnvzO+SAwrG7/MYZ1Uj6EAMK+bjgbHmsyE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mLuYHq5X; 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="mLuYHq5X" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8036C4CEC6; Sat, 12 Oct 2024 14:20:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728742809; bh=HgcnOJp7BoG7+XWL3+KkCN8XJ0aLr9B4V4kGhZ6HQQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mLuYHq5XHvTI3twEbQq+PQ6zYeqUxac6Vl+19T8aw/JA/ULUhRsVwZEVHN9P/jxgf jmouYb+8qFM95b/5t0rsh8Z9ogbh3keK5VqYBKl7mhQwvHxWNaU5R9z7trhwRL1baW xiV1Dxf8gGnCCwPCP4l6YHa+ZsmYxLd+FyuBi/dOIS8bTidBszOPd7b1zVXaa9wpIb vfQMCPahb69DJY/a9DAjc/+tIaIodN7JUyeuJowtsgvHLYnPKldj3ztfLEGLheU0D/ CjKKUteHy3xizff+AhhBS3Su7QCA15iv4GD+MU2Aq7wP2XU9tSy5aSR9frifrS/DK1 0KCh3H0y5fxGg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 07/11] mptcp: change remote as mptcp_addr_info Date: Sat, 12 Oct 2024 22:19:47 +0800 Message-ID: <87dd7f80bb8c1f8114326739a911d79fe6e17ef3.1728742592.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 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 the set_flags() interface uses two mptcp_pm_addr_entry type parameters. This patch changes the second one to mptcp_addr_info type and use helper mptcp_pm_parse_addr() to parse it instead of using mptcp_pm_parse_entry(). Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index e8edbe3a2600..5305af015ee6 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -540,9 +540,9 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) { struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, }; - struct mptcp_pm_addr_entry rem = { .addr = { .family = AF_UNSPEC }, }; struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; + struct mptcp_addr_info rem = { .family = AF_UNSPEC, }; struct mptcp_sock *msk; int ret = -EINVAL; struct sock *sk; @@ -559,13 +559,13 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) goto set_flags_err; if (attr_rem) { - ret = mptcp_pm_parse_entry(attr_rem, info, false, &rem); + ret = mptcp_pm_parse_addr(attr_rem, info, &rem); if (ret < 0) goto set_flags_err; } if (loc.addr.family == AF_UNSPEC || - rem.addr.family == AF_UNSPEC) { + rem.family == AF_UNSPEC) { GENL_SET_ERR_MSG(info, "invalid address families"); ret = -EINVAL; goto set_flags_err; @@ -575,7 +575,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) bkup = 1; lock_sock(sk); - ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem.addr, bkup); + ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem, bkup); release_sock(sk); set_flags_err: From patchwork Sat Oct 12 14:19:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13833598 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 4AD3F1925A8 for ; Sat, 12 Oct 2024 14:20: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=1728742811; cv=none; b=ndtIBUVtHLVaC03OzmHKTA27KiPBNRYlqgPoBgUkQNT+u+DSmelvOZpHdxArsXcyWkeJGo7OQnTxEIwq2CPFMQfmTcZeFpo5XbJyWlDCpLNKv5TkRWQBjIKAToU3LEi+8gcoiD/6HNalMzRtVTHEjb40YeujJh1XXoa0tAkq3KM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728742811; c=relaxed/simple; bh=B2GEnrpbiRvP64kXXRSL3pSVxWkLB5beVNPpegIWXMI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T02MynwGxMPMEjt4srr4iFLkSKGnlrvZkoEXoBJVopA/EWTUyMCumO5JE6ClcMnGytPfN3XUVxzSGj7m9+M3rExbQxVWO0+B0YCGwdtotoZqLwvgvqWFStWYF/QBFrNXNr/tQP/HCQ3M0VK2OqF1cNQlejRj1whszaWbxmhb+6Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sxNnFzxO; 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="sxNnFzxO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 144DBC4CECC; Sat, 12 Oct 2024 14:20:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728742810; bh=B2GEnrpbiRvP64kXXRSL3pSVxWkLB5beVNPpegIWXMI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sxNnFzxOf/8ng2D7q2ku1ia/7Ctko+PghC1esL88dXnpsLwAERrxnaYJMbMg8TbEO CHvmLITS5/pBgmxopoy7bAFt9yyFQgKtO1AHHiWcGjQIZANe8faPUSDeb4DW4PZ5X4 7Cbi6SnfxRVGeYitFFE196IzxqOBYDva2Z7nvhkJBxif7ecQ+0330zWVRDEzxw9PNi 6TO4Vnjs4Ej7/1OQlajUizZffAmDAeW8Q4bvNs61mVP3RemOM5Bl2fwXqX91c6WTAc w7jUv1dVVzfGXLoInZT3X5NJMV9qg4xRmPEPDzL4pOUyfgAp1YN3uxdDF+bEksgonj io21fVU6I59jQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 08/11] mptcp: change local as mptcp_pm_addr_entry Date: Sat, 12 Oct 2024 22:19:48 +0800 Message-ID: <0dcd1aa01d6d2359734458a1692b9a178cd23e19.1728742592.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 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(). 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 5305af015ee6..f8a045e4f0cb 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -463,7 +463,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info { struct nlattr *raddr = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; struct nlattr *laddr = info->attrs[MPTCP_PM_ATTR_ADDR]; - struct mptcp_addr_info addr_l; + struct mptcp_pm_addr_entry local; struct mptcp_addr_info addr_r; struct mptcp_sock *msk; struct sock *sk, *ssk; @@ -480,7 +480,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info sk = (struct sock *)msk; - err = mptcp_pm_parse_addr(laddr, info, &addr_l); + err = mptcp_pm_parse_entry(laddr, info, true, &local); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); goto destroy_err; @@ -493,35 +493,34 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info } #if IS_ENABLED(CONFIG_MPTCP_IPV6) - if (addr_l.family == AF_INET && ipv6_addr_v4mapped(&addr_r.addr6)) { - ipv6_addr_set_v4mapped(addr_l.addr.s_addr, &addr_l.addr6); - addr_l.family = AF_INET6; + if (local.addr.family == AF_INET && ipv6_addr_v4mapped(&addr_r.addr6)) { + ipv6_addr_set_v4mapped(local.addr.addr.s_addr, &local.addr.addr6); + local.addr.family = AF_INET6; } - if (addr_r.family == AF_INET && ipv6_addr_v4mapped(&addr_l.addr6)) { - ipv6_addr_set_v4mapped(addr_r.addr.s_addr, &addr_r.addr6); + if (addr_r.family == AF_INET && ipv6_addr_v4mapped(&local.addr.addr6)) { + ipv6_addr_set_v4mapped(addr_r.addr.s_addr, &local.addr.addr6); addr_r.family = AF_INET6; } #endif - if (addr_l.family != addr_r.family) { + if (local.addr.family != addr_r.family) { GENL_SET_ERR_MSG(info, "address families do not match"); err = -EINVAL; goto destroy_err; } - if (!addr_l.port || !addr_r.port) { + if (!local.addr.port || !addr_r.port) { GENL_SET_ERR_MSG(info, "missing local or remote port"); err = -EINVAL; goto destroy_err; } lock_sock(sk); - ssk = mptcp_nl_find_ssk(msk, &addr_l, &addr_r); + ssk = mptcp_nl_find_ssk(msk, &local.addr, &addr_r); if (ssk) { struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); - struct mptcp_pm_addr_entry entry = { .addr = addr_l }; spin_lock_bh(&msk->pm.lock); - mptcp_userspace_pm_delete_local_addr(msk, &entry); + mptcp_userspace_pm_delete_local_addr(msk, &local); spin_unlock_bh(&msk->pm.lock); mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); mptcp_close_ssk(sk, ssk, subflow); From patchwork Sat Oct 12 14:19:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13833599 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 9EC9D38384 for ; Sat, 12 Oct 2024 14:20: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=1728742812; cv=none; b=nS+KVbpIZs4Or1RlUt/FCKWCYuznmKI2hJWMeO3CRktYNeokiIEnOFTLBBTnESpdwu/vv3fmht45fGAqTKnTQAcAjVxiFsiAH2F7uQ7aVSSEqV+IJRlU9kXi1SjdO1e4nvMoSw0RedHK5xpFPTEoiQgW0OkJ6XJyktmSlZn7kfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728742812; c=relaxed/simple; bh=t50svMpoqh/sVzagY8v9BUsehSXq9HBWd63iX1ndULk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nS2RK8Wbau90/GEF6ITXdFwCcOp2Z2r/GSG/ZXVb4hM8BEHvgXFt7SK7KJHgAmveu56lxAUlX/Okp4EqoWGdfcuAf9XCPWfeXdQKayhQx4FWvGnOTP5r311UpKzd5Cd2cf3NEWNSgqmTngrGkmjXrNimJGERGOqCdhHjhRmjU64= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kNE2lZFh; 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="kNE2lZFh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65D17C4CECE; Sat, 12 Oct 2024 14:20:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728742812; bh=t50svMpoqh/sVzagY8v9BUsehSXq9HBWd63iX1ndULk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kNE2lZFhifmNzz56iE9qWFQAcgpkMoZKHA1oHIXGc8AZ75JASLacyTgScwHAq1YOj kI77bhA2z402IjDqZB3rPa4Nj5wAwbaUruL8OlSWpiiBemrX1j4G+jRaOeh/eVa35g BePMCSTXYpBPoejfr9MMN/bHdKFjjMBsnTeEe1HHOywR+uDWCyqArl8LgNPG2lxQyu W32vUOAzLZ8zXvOhw5LPsTENHKC3SrBZiLnTdLJBFCMd9shWPARXoBa2nE3K6zftjL QfK41zKaPNLZXfk9Jaffp3WUZqz35HK/D/R2RkJpGtb5xvR4m306gnxk40epKddIzh hL+QpEeBs3Kiw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 09/11] mptcp: make three pm wrappers static Date: Sat, 12 Oct 2024 22:19:49 +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 Three path manager wrappers, mptcp_pm_get_addr(), mptcp_pm_dump_addr() and mptcp_pm_set_flags() are used to switch the interfaces between in-kernel PM and userspace PM. These wrappers are defined in pm.c but only used in pm_netlink.c. It makes more sense to move them to pm_netlink.c and make them all static. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 23 ----------------------- net/mptcp/pm_netlink.c | 31 +++++++++++++++++++++++++++---- net/mptcp/protocol.h | 7 ------- 3 files changed, 27 insertions(+), 34 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 5afc1f8e5ca7..c051c1ec4de4 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -433,29 +433,6 @@ bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc) return mptcp_pm_nl_is_backup(msk, &skc_local); } -int mptcp_pm_get_addr(struct sk_buff *skb, struct genl_info *info) -{ - if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_get_addr(skb, info); - return mptcp_pm_nl_get_addr(skb, info); -} - -int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) -{ - const struct genl_info *info = genl_info_dump(cb); - - if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_dump_addr(msg, cb); - return mptcp_pm_nl_dump_addr(msg, cb); -} - -int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info) -{ - if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_set_flags(skb, info); - return mptcp_pm_nl_set_flags(skb, info); -} - void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) { struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 9a77395956ef..5a731282618e 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1792,7 +1792,7 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } -int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info) +static int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info) { struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet = genl_info_pm_nl(info); @@ -1842,13 +1842,20 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info) return ret; } +static int mptcp_pm_get_addr(struct sk_buff *skb, struct genl_info *info) +{ + if (info->attrs[MPTCP_PM_ATTR_TOKEN]) + return mptcp_userspace_pm_get_addr(skb, info); + return mptcp_pm_nl_get_addr(skb, info); +} + int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) { return mptcp_pm_get_addr(skb, info); } -int mptcp_pm_nl_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb) +static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, + struct netlink_callback *cb) { struct net *net = sock_net(msg->sk); struct mptcp_pm_addr_entry *entry; @@ -1890,6 +1897,15 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, return msg->len; } +static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) +{ + const struct genl_info *info = genl_info_dump(cb); + + if (info->attrs[MPTCP_PM_ATTR_TOKEN]) + return mptcp_userspace_pm_dump_addr(msg, cb); + return mptcp_pm_nl_dump_addr(msg, cb); +} + int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, struct netlink_callback *cb) { @@ -2011,7 +2027,7 @@ static int mptcp_nl_set_flags(struct net *net, return ret; } -int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) +static int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) { struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, }; struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; @@ -2065,6 +2081,13 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) return 0; } +static int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info) +{ + if (info->attrs[MPTCP_PM_ATTR_TOKEN]) + return mptcp_userspace_pm_set_flags(skb, info); + return mptcp_pm_nl_set_flags(skb, info); +} + int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info) { return mptcp_pm_set_flags(skb, info); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index dc777a3e05a2..f8a08d2ccf1a 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1038,8 +1038,6 @@ 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); -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 *info); int mptcp_pm_announce_addr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, @@ -1130,13 +1128,8 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_in 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); -int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); -int mptcp_pm_nl_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); -int mptcp_pm_get_addr(struct sk_buff *skb, struct genl_info *info); -int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info); int mptcp_userspace_pm_get_addr(struct sk_buff *skb, struct genl_info *info); From patchwork Sat Oct 12 14:19:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13833600 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 83DFD38384 for ; Sat, 12 Oct 2024 14:20:13 +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=1728742813; cv=none; b=EX4fpstkA4fDDcI/JQeik1Ov3gddMBTNkq75kCulECmiwMczXzeC6q53a2DpJ6yt5qUHhEPQYRe+5/YCO5O/frwfhxn6YF6x5F3W1HY1G9de3erUq0fmFNPA+e77sq1NzcodQUrWtGqjOoe5DcA9oW9KBcVJTQPK7fIhkogFfr4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728742813; c=relaxed/simple; bh=GTEfHQ+GOpTEN0crPUauUKK7A+Fw96byp1dEzQF8zaE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NlM/jp6F6f3JrTaRcECFe6wVz886kTcwEM/0dpUyn/5jpyxlXEXiHdXrnkSfVLRJufzWmMVsKd3/kPY0mZo1ac8lTO2pR+n9tF6wgbHCmvOKbpGNjICrKQBk5dIviZgJbhARYdm+7bvXXUHVEm9korZ82P0Lz3GOkkLgOp1/EZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EvycuoVw; 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="EvycuoVw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E6D5C4CEC6; Sat, 12 Oct 2024 14:20:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728742813; bh=GTEfHQ+GOpTEN0crPUauUKK7A+Fw96byp1dEzQF8zaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EvycuoVwrYV2gJaG5I4IR4qoFtfFt362yc3FP2NVuLBUHciwPfVH45/qTxNxwU8vj QxYqUUu861jSMLljXrb3tGUmw2i6LXJHyQ+ituRWMwEwm/ACVcy/+ZXL6IOvvChbO3 EQ2GuU9ZYeTBAyvpyD77ACsqE7GTKmJaLa4wyeMjTjHkOX+96euwpA6AH1Zn4+Qwz9 4MUMjZZNBROhHuMnF74eBlfb2keMg+XtBJZmmlkTvvjj7IlalIZnbIXlLTzWEu+0Z4 wAM7jLm8l7OdWpKfAoKs5URalOYEjt+kJ9Pce+YFH5aEI2z5xsSmlQo9/wkMYeaTDE deq4j5J92vchg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 10/11] mptcp: drop skb parameter of get_addr Date: Sat, 12 Oct 2024 22:19:50 +0800 Message-ID: <4ab1979d352cc735128f607897a7053937c1ca47.1728742592.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 first parameters "skb" of all three get_addr() interfaces are now useless since mptcp_userspace_pm_get_sock() helper is used. This patch drops these useless parameters of them. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 10 +++++----- net/mptcp/pm_userspace.c | 3 +-- net/mptcp/protocol.h | 3 +-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 5a731282618e..c7db0823702a 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1792,7 +1792,7 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } -static int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info) +static int mptcp_pm_nl_get_addr(struct genl_info *info) { struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet = genl_info_pm_nl(info); @@ -1842,16 +1842,16 @@ static int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info) return ret; } -static int mptcp_pm_get_addr(struct sk_buff *skb, struct genl_info *info) +static int mptcp_pm_get_addr(struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_get_addr(skb, info); - return mptcp_pm_nl_get_addr(skb, info); + return mptcp_userspace_pm_get_addr(info); + return mptcp_pm_nl_get_addr(info); } int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) { - return mptcp_pm_get_addr(skb, info); + return mptcp_pm_get_addr(info); } static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index f8a045e4f0cb..a89c91f030db 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -629,8 +629,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, return ret; } -int mptcp_userspace_pm_get_addr(struct sk_buff *skb, - struct genl_info *info) +int mptcp_userspace_pm_get_addr(struct genl_info *info) { struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct mptcp_pm_addr_entry addr, *entry; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index f8a08d2ccf1a..f4bf6f843fe6 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1130,8 +1130,7 @@ 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); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); -int mptcp_userspace_pm_get_addr(struct sk_buff *skb, - struct genl_info *info); +int mptcp_userspace_pm_get_addr(struct genl_info *info); static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflow) { From patchwork Sat Oct 12 14:19:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13833601 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 2FE5838384 for ; Sat, 12 Oct 2024 14:20: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=1728742815; cv=none; b=IcJ+4brAEczCllXg5/JRUtYvaRpiMVJSA1XCzUvuKWa1R1PB0J6uDu8WtU13zB/boV/r3hDie2WOKoJMkJs9gnPjz1VaWes4nJFkDpHPDNGFaMiUXTMIgBulUGsXN2Z6nL4Pd5jtjevLqWopkdEKtUCrdpkAVKTHA5dWNusP6tM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728742815; c=relaxed/simple; bh=AA4jUiBqJ8LRDAXJy4kuxnz9I8RG73PLukeFPXiS37A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aRCsFJkLVK6hdBMdBncIPOi24arUWsGqnGB7SeqAr1baHb7iQaiQAeKTcjOilVH3lMKO71uYrqxNSEQ1jHICAqZwUgZk8hUxGYGKKPCERfNb4b6qvF07KIaogLsZN/jmIsIOMGIIbPL4h5IEHyhaD8QKXnqxsIFHFKYBA3pg+Lc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XYIlVeWI; 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="XYIlVeWI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F23F4C4CEC6; Sat, 12 Oct 2024 14:20:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728742814; bh=AA4jUiBqJ8LRDAXJy4kuxnz9I8RG73PLukeFPXiS37A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XYIlVeWI/NJaWi8wMKE12izGOZiZibC+monJJ/tvc+IFhb2iRGmeFMh+y0AD+hnmS xERuK8wS72Ri+fZr5rMNMbR+Bj2Tn/XrtmOwdnjDvpvpn2YVk3dcEv3fiFeDHRCa6+ gvOfnKYQlyyU5fpmgKPiALP51oOckYvzue0lJtMrZeNZeY2qHnRO+Xd/oq4qNA+SDT 7WPlD/fLjefrdmHWSgq52+4nwypwB8OUU8UCEds5xHmnQK82UAOu7qF7gb64Pt/HBI sw8LF2kt6C68OexsCSlDv/5M2hGIjDGWZlvLsCmNKKtLB3DxrGMvPuuwTkLIz1RUeF D8ZfhqmXMqLvw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 11/11] mptcp: drop skb parameter of set_flags Date: Sat, 12 Oct 2024 22:19:51 +0800 Message-ID: <2004142685fcd149b98e24ad6b0f2afa203a2573.1728742592.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 first parameter "skb" in mptcp_pm_nl_set_flags() is only used to obtained the network namespace, which can also be obtained through the second parameters "info" by using genl_info_net() helper. This patch drops these useless parameters "skb" in all three set_flags() interfaces. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 12 ++++++------ net/mptcp/pm_userspace.c | 2 +- net/mptcp/protocol.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index c7db0823702a..78f8d78f0392 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -2027,13 +2027,13 @@ static int mptcp_nl_set_flags(struct net *net, return ret; } -static int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) +static int mptcp_pm_nl_set_flags(struct genl_info *info) { struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, }; struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP | MPTCP_PM_ADDR_FLAG_FULLMESH; - struct net *net = sock_net(skb->sk); + struct net *net = genl_info_net(info); struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; u8 lookup_by_id = 0; @@ -2081,16 +2081,16 @@ static int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *info) return 0; } -static int mptcp_pm_set_flags(struct sk_buff *skb, struct genl_info *info) +static int mptcp_pm_set_flags(struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_set_flags(skb, info); - return mptcp_pm_nl_set_flags(skb, info); + return mptcp_userspace_pm_set_flags(info); + return mptcp_pm_nl_set_flags(info); } int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info) { - return mptcp_pm_set_flags(skb, info); + return mptcp_pm_set_flags(info); } static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index a89c91f030db..19626b254b76 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -536,7 +536,7 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info return err; } -int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info) +int mptcp_userspace_pm_set_flags(struct genl_info *info) { struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, }; struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index f4bf6f843fe6..5bdddd175799 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1038,7 +1038,7 @@ 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); -int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *info); +int mptcp_userspace_pm_set_flags(struct genl_info *info); int mptcp_pm_announce_addr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, bool echo);