From nobody Sun Dec 22 02:03:13 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF36F1D0B86 for ; Wed, 2 Oct 2024 15:02: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=1727881327; cv=none; b=kKE33pQixim85QYVC+wir8xYAvzi/jw2+/W8HZ5K2a4GMLBUFWrB16zZ3K/ysAhLvT5gm2u07fSaC+DxuhhoqLcbc87quR0iGkB1SNXJi/BrS5beF/4xAnB942syNkKlM7bdDtQOsvbZDDFc8WCaJ+NQR/i9IJIf/cChhCJ1q5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881327; c=relaxed/simple; bh=eRZ+fRXE0e719NQXc0auY59zeAdA7p1VlW2/ij3npP8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QIJmfUNhs9tmoNGtY7fRpffOQkgL62hE70R66EwpeGKFaLK/D/Ur7MBdaC1D4mTyi/QXf4Hq5tkbok18Oo7EmWX2dhCGvvNErWLV2CB8DLjf8DK9rUprA5GUZscXTfCnIxdFw/a3vjqm2xvKdYEp47AA2UNzCtpTEvJCmp7KScc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WngG3oo1; 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="WngG3oo1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98AFAC4CED7; Wed, 2 Oct 2024 15:02:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727881326; bh=eRZ+fRXE0e719NQXc0auY59zeAdA7p1VlW2/ij3npP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WngG3oo1ZF4zDyzvJEXeNI5UKqStw9qHaJuIzlW9jpawEpHNcx00lcI2GR6BbeJcH mHvYXe7i+gr/JyZ7yBHYD1byAHtSDIiLUl2QQZP7wUTB8eWzN/55781BTfclqokVZi exoteGXUyvBARQqaKN7SPhKoD7v7YSkwQ5U3XPQBmFni4QFGdaN7Ve2vwPLAG+cEKb KfGODE8pJ6ERlc/f3crb/r+riykvCfS8z663LR+Kaq5oBkbTRF0zWE8enVBzHwOYLE zncZcfqUh2ib1KgRBcmLobv7Gw+sV4u1ZL7WydbR7zooIHFMiTUxuJZXbxuWSqoBsl MS5kC7uP+5Xlw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 1/9] mptcp: add struct mptcp_id_bitmap Date: Wed, 2 Oct 2024 23:01:51 +0800 Message-ID: <0edf54c2e6c48abb03b0a017da3bbf32c252bdb7.1727881073.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang A new struct mptcp_id_bitmap is defined to unify all bitmap type of address ids. This type can be used to easily define dump_addr() interface of the path managers as: int (*dump_addr)(struct mptcp_sock *msk, struct mptcp_id_bitmap *bitmap); It also allows this parameter to be modified in BPF. 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 =3D 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); } =20 void mptcp_pm_data_init(struct mptcp_sock *msk) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index fe34297ea6dc..6fcbfcbc0edb 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; }; =20 #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; =20 - if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap)) + if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap.map)) continue; =20 new_local->addr =3D entry->addr; @@ -189,7 +189,7 @@ select_signal_address(struct pm_nl_pernet *pernet, cons= t 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; =20 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 =3D pm_nl_get_pernet_from_msk(msk); =20 if (msk->pm.subflows =3D=3D 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) =3D=3D 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++] =3D remote; } else { - DECLARE_BITMAP(unavail_id, MPTCP_PM_MAX_ADDR_ID + 1); + struct mptcp_id_bitmap unavail_id; =20 /* 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) =3D=3D local->id) - __set_bit(subflow->remote_id, unavail_id); + __set_bit(subflow->remote_id, unavail_id.map); =20 mptcp_for_each_subflow(msk, subflow) { ssk =3D mptcp_subflow_tcp_sock(subflow); @@ -460,7 +460,7 @@ static unsigned int fill_remote_addresses_vec(struct mp= tcp_sock *msk, if (deny_id0 && !addrs[i].id) continue; =20 - if (test_bit(addrs[i].id, unavail_id)) + if (test_bit(addrs[i].id, unavail_id.map)) continue; =20 if (!mptcp_pm_addr_families_match(sk, local, &addrs[i])) @@ -470,7 +470,7 @@ static unsigned int fill_remote_addresses_vec(struct mp= tcp_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(stru= ct mptcp_sock *msk) rcu_read_lock(); entry =3D __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 =3D entry->addr.id; backup =3D !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); } @@ -596,7 +596,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(stru= ct mptcp_sock *msk) if (!mptcp_pm_alloc_anno_list(msk, &local.addr)) return; =20 - __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++; =20 /* Special case for ID0: set the correct ID */ @@ -625,7 +625,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(stru= ct mptcp_sock *msk) =20 fullmesh =3D !!(local.flags & MPTCP_PM_ADDR_FLAG_FULLMESH); =20 - __clear_bit(local.addr.id, msk->pm.id_avail_bitmap); + __clear_bit(local.addr.id, msk->pm.id_avail_bitmap.map); =20 /* Special case for ID0: set the correct ID */ if (local.addr.id =3D=3D msk->mpc_endpoint_id) @@ -990,7 +990,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_= nl_pernet *pernet, ret =3D -ERANGE; goto out; } - if (test_bit(entry->addr.id, pernet->id_bitmap)) { + if (test_bit(entry->addr.id, pernet->id_bitmap.map)) { ret =3D -EBUSY; goto out; } @@ -1024,7 +1024,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct p= m_nl_pernet *pernet, =20 if (!entry->addr.id && needs_id) { find_next: - entry->addr.id =3D find_next_zero_bit(pernet->id_bitmap, + entry->addr.id =3D find_next_zero_bit(pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1, pernet->next_id); if (!entry->addr.id && pernet->next_id !=3D 1) { @@ -1036,7 +1036,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct p= m_nl_pernet *pernet, if (!entry->addr.id && needs_id) goto out; =20 - __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 =3D entry->addr.id; =20 @@ -1484,7 +1484,7 @@ static bool mptcp_pm_remove_anno_addr(struct mptcp_so= ck *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); @@ -1496,7 +1496,7 @@ static bool mptcp_pm_remove_anno_addr(struct mptcp_so= ck *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_bit= map) && + if (!__test_and_set_bit(id ? : msk->mpc_endpoint_id, msk->pm.id_avail_bit= map.map) && id && !WARN_ON_ONCE(msk->pm.local_addr_used =3D=3D 0)) msk->pm.local_addr_used--; } @@ -1627,7 +1627,7 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, st= ruct genl_info *info) =20 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); =20 mptcp_nl_remove_subflow_and_signal_addr(sock_net(skb->sk), entry); @@ -1691,7 +1691,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 =3D 0; spin_unlock_bh(&msk->pm.lock); } @@ -1749,7 +1749,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 =3D 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(); @@ -1865,7 +1865,7 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, =20 spin_lock_bh(&pernet->lock); for (i =3D 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 =3D __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(str= uct 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 =3D NULL; struct sock *sk =3D (struct sock *)msk; + struct mptcp_id_bitmap id_bitmap; struct mptcp_pm_addr_entry *e; bool addr_match =3D false; bool id_match =3D false; int ret =3D -EINVAL; =20 - bitmap_zero(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + bitmap_zero(id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); =20 spin_lock_bh(&msk->pm.lock); list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) { @@ -52,7 +52,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struc= t 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); } =20 if (!match && !addr_match && !id_match) { @@ -67,7 +67,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struc= t mptcp_sock *msk, =20 *e =3D *entry; if (!e->addr.id && needs_id) - e->addr.id =3D find_next_zero_bit(id_bitmap, + e->addr.id =3D 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 =3D genl_info_dump(cb); struct net *net =3D sock_net(msg->sk); struct mptcp_pm_addr_entry *entry; + struct mptcp_id_bitmap *bitmap; struct mptcp_sock *msk; struct nlattr *token; int ret =3D -EINVAL; struct sock *sk; void *hdr; =20 - bitmap =3D (struct id_bitmap *)cb->ctx; + bitmap =3D (struct mptcp_id_bitmap *)cb->ctx; token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; =20 msk =3D mptcp_token_get_sock(net, nla_get_u32(token)); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index c3942416fa3a..ef50ef0c0829 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 =20 +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; }; --=20 2.43.0 From nobody Sun Dec 22 02:03:13 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 482101EEE6 for ; Wed, 2 Oct 2024 15:02:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881328; cv=none; b=DlSmz4hZwDZWjQkznmKxwDIFr2Vzsp60d1z6hsSI1wxV4zH2BmpXTN5dT0ROYBJ+f/6/Hez+1srNfcA/GMEJJwDl/Dbr/9z9eu6J3NKwkfXCHkGH15VXWo3VkcUXxPlYWM5ietkn3oppDp0YrCJ0aEZC66vSPJGOs5DpQEwpcYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881328; c=relaxed/simple; bh=QlPPv5Y+rj6Otg//Sj8stHI8SXs586TV3GH+TNpg/rA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lLi/sUig1ywbZO6XGO7TpeX9EpV76lvT6hAk0VJdVgW/0ZNQszfZLm1O5J4e0lXk2B/INb6WRygmym5EIKqjBao6ehqn8ws+M78sbeKhhgIY7p2UxAmMcCeen/Lo1U0aeXFg1l1PAYs0UQvTcsM7lAaaDcxV+TyVosNCyH36iEs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pxmajoyR; 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="pxmajoyR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E3A9C4CECD; Wed, 2 Oct 2024 15:02:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727881327; bh=QlPPv5Y+rj6Otg//Sj8stHI8SXs586TV3GH+TNpg/rA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pxmajoyRp+e7SQUAZKYOWrJzjUGhAK85XrOa42c4s9m8HKzBn2c79rOIZ06bdjrcK wGn+IhO1UcmvQdZZPkyBuKkaZURkZooH6oNyKtbgQwwilJm4MzN+kI3sUN8t7Fffzg 0SdthquYIsGPJ61halUaJfqiB6euPSG2YSIrk31LNJpzNzMgtlWmQ8iEmmRj+u5i0E VHWrZTcDokaE7wlCxNbj7mf65G3w1Ey+Ek57FhjGu724xO0sSCfsQX5+LBCZ4NCN82 JquEgNnR9bbhSjuuedJXEQBl+l3Dajtyp34rb/O0tLrdJR4MKYg3w/weH3te4FHS+S j/qRj7IqxOzeQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 2/9] mptcp: add mptcp_userspace_pm_get_sock helper Date: Wed, 2 Oct 2024 23:01:52 +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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Each userspace pm netlink function uses nla_get_u32() to get the msk token value, then pass it to mptcp_token_get_sock() to get the msk. Finally check whether userspace pm is selected on this msk. It makes sense to wrap them into a helper, named mptcp_userspace_pm_get_sock(), to do this. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 138 +++++++++++++-------------------------- 1 file changed, 45 insertions(+), 93 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index e3f29d8865f4..add30ea72c6b 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -166,36 +166,52 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *= msk, return backup; } =20 -int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) +static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_in= fo *info) { struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; + struct mptcp_sock *msk =3D NULL; + + if (!token) { + GENL_SET_ERR_MSG(info, "missing required inputs"); + goto out; + } + + msk =3D mptcp_token_get_sock(genl_info_net(info), nla_get_u32(token)); + if (!msk) { + NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + 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 =3D NULL; + goto out; + } + +out: + return msk; +} + +int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) +{ struct nlattr *addr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry addr_val; struct mptcp_sock *msk; int err =3D -EINVAL; struct sock *sk; - u32 token_val; =20 - if (!addr || !token) { + if (!addr) { GENL_SET_ERR_MSG(info, "missing required inputs"); return err; } =20 - token_val =3D nla_get_u32(token); - - msk =3D mptcp_token_get_sock(sock_net(skb->sk), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto announce_err; - } - err =3D mptcp_pm_parse_entry(addr, info, true, &addr_val); if (err < 0) { GENL_SET_ERR_MSG(info, "error parsing local address"); @@ -268,7 +284,6 @@ static int mptcp_userspace_pm_remove_id_zero_address(st= ruct mptcp_sock *msk, =20 int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) { - struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *id =3D info->attrs[MPTCP_PM_ATTR_LOC_ID]; struct mptcp_pm_addr_entry *match; struct mptcp_pm_addr_entry *entry; @@ -276,30 +291,21 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, stru= ct genl_info *info) LIST_HEAD(free_list); int err =3D -EINVAL; struct sock *sk; - u32 token_val; u8 id_val; =20 - if (!id || !token) { + if (!id) { GENL_SET_ERR_MSG(info, "missing required inputs"); return err; } =20 id_val =3D nla_get_u8(id); - token_val =3D nla_get_u32(token); =20 - msk =3D mptcp_token_get_sock(sock_net(skb->sk), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto out; - } - if (id_val =3D=3D 0) { err =3D mptcp_userspace_pm_remove_id_zero_address(msk, info); goto out; @@ -333,7 +339,6 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct= genl_info *info) int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb, struct genl_info = *info) { struct nlattr *raddr =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_pm_addr_entry entry =3D { 0 }; struct mptcp_addr_info addr_r; @@ -341,28 +346,18 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *s= kb, struct genl_info *info) struct mptcp_sock *msk; int err =3D -EINVAL; struct sock *sk; - u32 token_val; =20 - if (!laddr || !raddr || !token) { + if (!laddr || !raddr) { GENL_SET_ERR_MSG(info, "missing required inputs"); return err; } =20 - token_val =3D nla_get_u32(token); - - msk =3D mptcp_token_get_sock(genl_info_net(info), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto create_err; - } - err =3D mptcp_pm_parse_entry(laddr, info, true, &entry); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); @@ -465,35 +460,24 @@ static struct sock *mptcp_nl_find_ssk(struct mptcp_so= ck *msk, int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info= *info) { struct nlattr *raddr =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; struct mptcp_addr_info addr_l; struct mptcp_addr_info addr_r; struct mptcp_sock *msk; struct sock *sk, *ssk; int err =3D -EINVAL; - u32 token_val; =20 - if (!laddr || !raddr || !token) { + if (!laddr || !raddr) { GENL_SET_ERR_MSG(info, "missing required inputs"); return err; } =20 - token_val =3D nla_get_u32(token); - - msk =3D mptcp_token_get_sock(genl_info_net(info), token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return err; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto destroy_err; - } - err =3D mptcp_pm_parse_addr(laddr, info, &addr_l); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); @@ -556,30 +540,18 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb,= struct genl_info *info) struct mptcp_pm_addr_entry loc =3D { .addr =3D { .family =3D AF_UNSPEC },= }; struct mptcp_pm_addr_entry rem =3D { .addr =3D { .family =3D AF_UNSPEC },= }; struct nlattr *attr_rem =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; - struct net *net =3D sock_net(skb->sk); struct mptcp_sock *msk; int ret =3D -EINVAL; struct sock *sk; - u32 token_val; u8 bkup =3D 0; =20 - token_val =3D nla_get_u32(token); - - msk =3D mptcp_token_get_sock(net, token_val); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return ret; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "userspace PM not selected"); - goto set_flags_err; - } - ret =3D mptcp_pm_parse_entry(attr, info, false, &loc); if (ret < 0) goto set_flags_err; @@ -613,31 +585,21 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { const struct genl_info *info =3D genl_info_dump(cb); - struct net *net =3D sock_net(msg->sk); struct mptcp_pm_addr_entry *entry; struct mptcp_id_bitmap *bitmap; struct mptcp_sock *msk; - struct nlattr *token; int ret =3D -EINVAL; struct sock *sk; void *hdr; =20 bitmap =3D (struct mptcp_id_bitmap *)cb->ctx; - token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; =20 - msk =3D mptcp_token_get_sock(net, nla_get_u32(token)); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return ret; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto out; - } - lock_sock(sk); spin_lock_bh(&msk->pm.lock); list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { @@ -662,7 +624,6 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, release_sock(sk); ret =3D msg->len; =20 -out: sock_put(sk); return ret; } @@ -671,28 +632,19 @@ int mptcp_userspace_pm_get_addr(struct sk_buff *skb, struct genl_info *info) { struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; - struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct mptcp_pm_addr_entry addr, *entry; - struct net *net =3D sock_net(skb->sk); struct mptcp_sock *msk; struct sk_buff *msg; int ret =3D -EINVAL; struct sock *sk; void *reply; =20 - msk =3D mptcp_token_get_sock(net, nla_get_u32(token)); - if (!msk) { - NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + msk =3D mptcp_userspace_pm_get_sock(info); + if (!msk) return ret; - } =20 sk =3D (struct sock *)msk; =20 - if (!mptcp_pm_is_userspace(msk)) { - GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); - goto out; - } - ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) goto out; --=20 2.43.0 From nobody Sun Dec 22 02:03:13 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1880A1CF7D4 for ; Wed, 2 Oct 2024 15:02: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=1727881330; cv=none; b=e4a1SAx+6vTS+5k9N8ewI2vTV7psyagFlGZk9Udtwrf/RsRgRIM5awSi9VYMlBlPo+ZGhV1M4CYK4LsKZnye2nXIy6+q7Ti85wl3HDlLjvItBaBc59n1+oh6ZpFSO6XeAIOWymC4fk1od+Hu6nic6dGYFXGyUZ7a0bived9yMsQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881330; c=relaxed/simple; bh=G/L/qe+cBFfXmT3vO7fZ9m3E8qsGSV8Hh3uQMPlRCag=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jTsYi5LphxWm532QrXC3Ns0xGC6/w4ytBptpZg9WU5oYXGyXM8KjPxOx+2zpXNUqcXGeurYAdFiapWF8PVMGuMLtyDCdPEXDwhNmj/SHsRsdi+Bg4WlJGNLq88LMOduUggj53Zm4FIK7ZMjrwEODlFjjz+2hBSrm9xLRU1Fujw4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Bhp2ODTU; 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="Bhp2ODTU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBA34C4CED1; Wed, 2 Oct 2024 15:02:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727881329; bh=G/L/qe+cBFfXmT3vO7fZ9m3E8qsGSV8Hh3uQMPlRCag=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bhp2ODTUNNq6Dx8gyxDB5IPqFDqB3kCS/LA0/6bEGLLxwzjrXUl1A9ByPxiX8DEyG X9o15WRZgDKTIErN5r8dSguwZPk+/rl3TajPuXeyQzDe4mq9YHLJqo+lXJS4gzl6FK 56YDt2Qeke4vm2OJFn3qIlmu7eDuYQYNXd8ukEq+Pc76MscjWvSFiO2WyFHhBt5t7B O6sH03XTjwV6EbemvrdgTidBD6iQ0NxWeU5zD5Xdw5tT77nuJwcl9WPZpVD1ZiuiVc nOVzJgXutoLdJXlXMFC1O17NvF+oORyb+DLDpNByDCuZ96iemTtiaOCIOIjH8fmOkn Rg9OqJTvm+lFA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 3/9] mptcp: use __lookup_addr in pm_netlink Date: Wed, 2 Oct 2024 23:01:53 +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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 6fcbfcbc0edb..e1907dad3bc4 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; =20 - 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; } @@ -1144,12 +1144,9 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk,= struct mptcp_addr_info *skc pernet =3D pm_nl_get_pernet_from_msk(msk); =20 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 =3D entry->addr.id; - break; - } - } + entry =3D __lookup_addr(pernet, skc); + if (entry) + ret =3D entry->addr.id; rcu_read_unlock(); if (ret >=3D 0) return ret; @@ -1179,12 +1176,9 @@ bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, s= truct mptcp_addr_info *skc) bool backup =3D false; =20 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 =3D !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); - break; - } - } + entry =3D __lookup_addr(pernet, skc); + if (entry) + backup =3D !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); rcu_read_unlock(); =20 return backup; --=20 2.43.0 From nobody Sun Dec 22 02:03:13 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AE591D0B9E for ; Wed, 2 Oct 2024 15:02:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881331; cv=none; b=I1Fm0RHYphax7O4QoWIkw6BEbeFpMaGTIczvGuYdj0+pTJQozyN5iPFV7j/ZZpAjalCRdzH44oFBNYdvWQbdBJRDf7wvdzmcsYl3kNOtGeRxFgp1iV4NFNOxCxpZlJSeuwaWrIVZXQuqWENNP0RAcKEA9QBeKoZfW25zXDtIFNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881331; c=relaxed/simple; bh=z2yRi7K6XCEsqHp3xSXisf2GpuQFdeedQm9+CyqQ35c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X2kH3CDy1LF6UXBQbm7zymlVnx/fxXwgVJgCyN4X8UNsQNufgPa1iAsW6V2ivCiAYhdgIUlY9Bv6zLCyY8A7UYWBDt+F4tz6Z2ZRP9lSmwENxFs6ENTACsgb9Ceoo8vuZ5UrhVczno7bRcKk+vxquH05EYPO6nUV1HqfzZVrj/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GpLrHZy0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GpLrHZy0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38ACAC4CEC2; Wed, 2 Oct 2024 15:02:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727881331; bh=z2yRi7K6XCEsqHp3xSXisf2GpuQFdeedQm9+CyqQ35c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GpLrHZy0VwpfuvJiphYM3a7d1KrNi/KSozD5lilSiADxXGuRTUz8tSa781OOj7u8H qdaxLLz5DK9hJ8tZMAMyJdHfTYK0F6b2GNzo+KBT7VVmFD5EyF/2gFukdbK+oDYJRO qq7SUYSscj95nm9NYQePuPPfIESpbkGGgZ/xwa3Hb+yZ1RXTrkGbUul4VjBHsWITYx a77PF+jmQIKLdh44cLSokkRT7uyUqDcwdfALVMx/+wniHjgoLdyf7nvX0uNTxh6U9Z d+CLlmpw9k9m5JnQ/T68sFCYIixDutYW6jF744ZRwf7kSbvfm27wbV3XTsnxqYyXrf gNH0TJtWiiV+Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 4/9] mptcp: add lookup_addr for userspace pm Date: Wed, 2 Oct 2024 23:01:54 +0800 Message-ID: <17072ea6d29ff84bc2c2fe1a93cc5aa4a03c214d.1727881073.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Like __lookup_addr() helper in pm_netlink.c, a new helper mptcp_userspace_pm_lookup_addr() is also defined in pm_userspace.c. It looks up the corresponding mptcp_pm_addr_entry address in userspace_pm_local_addr_list through the passed "addr" parameter and returns it. This helper can be used in mptcp_userspace_pm_delete_local_addr(), mptcp_userspace_pm_get_local_id() and mptcp_userspace_pm_is_backup() to simplify the code. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 56 +++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index add30ea72c6b..7f62a45bae76 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -26,6 +26,18 @@ void mptcp_free_local_addr_list(struct mptcp_sock *msk) } } =20 +static struct mptcp_pm_addr_entry * +mptcp_userspace_pm_lookup_addr(struct mptcp_sock *msk, const struct mptcp_= addr_info *addr) +{ + struct mptcp_pm_addr_entry *entry, *tmp; + + list_for_each_entry_safe(entry, tmp, &msk->pm.userspace_pm_local_addr_lis= t, list) { + if (mptcp_addresses_equal(&entry->addr, addr, false)) + return entry; + } + return NULL; +} + static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *entry, bool needs_id) @@ -90,21 +102,19 @@ static int mptcp_userspace_pm_append_new_local_addr(st= ruct mptcp_sock *msk, static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *addr) { - struct mptcp_pm_addr_entry *entry, *tmp; - - list_for_each_entry_safe(entry, tmp, &msk->pm.userspace_pm_local_addr_lis= t, list) { - if (mptcp_addresses_equal(&entry->addr, &addr->addr, false)) { - /* TODO: a refcount is needed because the entry can - * be used multiple times (e.g. fullmesh mode). - */ - list_del_rcu(&entry->list); - kfree(entry); - msk->pm.local_addr_used--; - return 0; - } - } + struct mptcp_pm_addr_entry *entry; =20 - return -EINVAL; + entry =3D mptcp_userspace_pm_lookup_addr(msk, &addr->addr); + if (!entry) + return -EINVAL; + + /* TODO: a refcount is needed because the entry can + * be used multiple times (e.g. fullmesh mode). + */ + list_del_rcu(&entry->list); + kfree(entry); + msk->pm.local_addr_used--; + return 0; } =20 static struct mptcp_pm_addr_entry * @@ -122,17 +132,12 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_soc= k *msk, unsigned int id) int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc) { - struct mptcp_pm_addr_entry *entry =3D NULL, *e, new_entry; + struct mptcp_pm_addr_entry *entry =3D NULL, new_entry; __be16 msk_sport =3D ((struct inet_sock *) inet_sk((struct sock *)msk))->inet_sport; =20 spin_lock_bh(&msk->pm.lock); - list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) { - if (mptcp_addresses_equal(&e->addr, skc, false)) { - entry =3D e; - break; - } - } + entry =3D mptcp_userspace_pm_lookup_addr(msk, skc); spin_unlock_bh(&msk->pm.lock); if (entry) return entry->addr.id; @@ -155,12 +160,9 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *m= sk, bool backup =3D false; =20 spin_lock_bh(&msk->pm.lock); - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { - if (mptcp_addresses_equal(&entry->addr, skc, false)) { - backup =3D !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); - break; - } - } + entry =3D mptcp_userspace_pm_lookup_addr(msk, skc); + if (entry) + backup =3D !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); spin_unlock_bh(&msk->pm.lock); =20 return backup; --=20 2.43.0 From nobody Sun Dec 22 02:03:13 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC6ED1D0BAF for ; Wed, 2 Oct 2024 15:02: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=1727881332; cv=none; b=MeD0sTwGtSQXJFUgMv/c7keup6NInpozkYooXZxu/TPZvpMij53S7B6xF7eHE7LBP8inJilS85yPEdRZFqDlvO2EOIwbWIanrNgcSeC8LYSWBGh/lF6w/pE3GOS3glqVnM6sKy6TjTGbJboIQoD3CQGX3ftSUrj4lL4TyXRakBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881332; c=relaxed/simple; bh=GVHf7qUuTah6a55QfZ2IslORg40skKkTiSidD872Jto=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZNq72ILjuxrkt2tmYoIoP5mVyPa9SIvZdHgakBJoXZRnSAxsQ9FURmlQJH2OnFeRxKMJLeWjkcVu4lQVscvhFFqdy6oELHr4ohOrWaH1QxHQKlIWHlOkLK1lAYZMdDYHk5Ri4h+SBi9DA3PjE90Hld2otSarF4v9T2IqkMgUoi0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L54/1+CC; 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="L54/1+CC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88D6EC4CED8; Wed, 2 Oct 2024 15:02:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727881332; bh=GVHf7qUuTah6a55QfZ2IslORg40skKkTiSidD872Jto=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L54/1+CC+GgD2eOSy3hu90UpOh1/5ENXdkpkMqZEouA8SzIk6Pux/HToeCMqD/4eY HibHZqRwf1N7mIC8+MjAccCl2b1xWrOD+0xpphj3fhBjOzbmGiL6WXyWeGyxHZkBrN 2CehD+gttgpkSxj0EQdlKya26B+78QXdkNxBLIJjHqqdPzdKOQDdJAu8DjsM80MMFt P6tLiIWxzzFP/ZY1EBt8FM8VzCdbZPz8WbGG+TQsbt8zcgAVRWcEVe7EEnA8Dc/h0n QgEyQoSWY9fXOH7czaHZkR4QK6vdS34TdrcE0X0y1di0vxeG7P8cb5R1VmfrPK43z/ aiat2sHV2Umqw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 5/9] mptcp: change remote as mptcp_addr_info Date: Wed, 2 Oct 2024 23:01:55 +0800 Message-ID: <7d0cc64bb775c622d0fd003dfbe566e486ef750e.1727881073.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang 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 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 7f62a45bae76..f4a4fa465136 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 *sk= b, struct genl_info *info int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *in= fo) { struct mptcp_pm_addr_entry loc =3D { .addr =3D { .family =3D AF_UNSPEC },= }; - struct mptcp_pm_addr_entry rem =3D { .addr =3D { .family =3D AF_UNSPEC },= }; struct nlattr *attr_rem =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; + struct mptcp_addr_info rem =3D { .family =3D AF_UNSPEC, }; struct mptcp_sock *msk; int ret =3D -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; =20 if (attr_rem) { - ret =3D mptcp_pm_parse_entry(attr_rem, info, false, &rem); + ret =3D mptcp_pm_parse_addr(attr_rem, info, &rem); if (ret < 0) goto set_flags_err; } =20 if (loc.addr.family =3D=3D AF_UNSPEC || - rem.addr.family =3D=3D AF_UNSPEC) { + rem.family =3D=3D AF_UNSPEC) { GENL_SET_ERR_MSG(info, "invalid address families"); ret =3D -EINVAL; goto set_flags_err; @@ -575,7 +575,7 @@ int mptcp_userspace_pm_set_flags(struct sk_buff *skb, s= truct genl_info *info) bkup =3D 1; =20 lock_sock(sk); - ret =3D mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem.addr, bkup); + ret =3D mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem, bkup); release_sock(sk); =20 set_flags_err: --=20 2.43.0 From nobody Sun Dec 22 02:03:13 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B40F21D0BBE for ; Wed, 2 Oct 2024 15:02: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=1727881333; cv=none; b=nkhnxF8yZz07dqdOQj8fDXLfr2CV+jke2AjUyeD+UdPVWmBKUz2TAy0cMAnn/h0acLKPMVPyNQY4eU/5lF6xQ4q4DQ4uCWDA1MVqdUOWDOdq6jLJmnjkZ3i1MX3lYaJLav03cfDErOeHUb13LK0kzwCfAY7R1cAAXtbFTAJFOrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881333; c=relaxed/simple; bh=x5ZDptBZP7lvUt5corPdiXuOHk/QPqpKMiJOvNlcDto=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b6reZt82Wxt/x654WtctG7LGSAEWywylc6oyZIQXzjXEo90n1iqQB9+NbQjDkB4IrdankX6r9zvD8qmmaiHcpG/LRO5qkTQ8l7QASGKBo6UN2T2HS3uoJnlR8W2aY+8btLJHIp6mTqg4fXHUX4VK3uKEA3zglIlSbjOg9QsaD+4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Rr6nDfLI; 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="Rr6nDfLI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9E31C4CECD; Wed, 2 Oct 2024 15:02:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727881333; bh=x5ZDptBZP7lvUt5corPdiXuOHk/QPqpKMiJOvNlcDto=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rr6nDfLIP5A5jtTPrCiZBzZ0HQayBwSHniQxyqyAPsPw1/+znArHCUefLao2Q65e7 DlOxpjtmJh/kU8FEC2NrEvsP4idGntmiPVZVLyIHIaX+2XWWYIps6K4BWnag3e3Vhx QGCb6/Yq33Y0mtlNFPs2/ffqfUovZYoXTGFcdvp4KyNhZ5KFueHnxDPcGxBej2UVzt Hfss8y8P/hQpXrfFF6sPgff+gwH/4L5aN2xcjhhwhi1Vbx5MTBAZMiBHGn3cDzdE/J 4EClxQhtXEAP+Dty9ElybDWfql3TFIre2iFQC9y90jzNPaKFvhkCW6SaulM4orT8MS exOs0M/YmYSXA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 6/9] mptcp: change local as mptcp_pm_addr_entry Date: Wed, 2 Oct 2024 23:01:56 +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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Generally, in the path manager interfaces, the local address is defined as an mptcp_pm_addr_entry type address, while the remote address is defined as an mptcp_addr_info 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 f4a4fa465136..9ff441beebe6 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 *sk= b, struct genl_info *info { struct nlattr *raddr =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; struct nlattr *laddr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; - struct mptcp_addr_info addr_l; + struct mptcp_pm_addr_entry 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 *sk= b, struct genl_info *info =20 sk =3D (struct sock *)msk; =20 - err =3D mptcp_pm_parse_addr(laddr, info, &addr_l); + err =3D mptcp_pm_parse_entry(laddr, info, true, &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 } =20 #if IS_ENABLED(CONFIG_MPTCP_IPV6) - if (addr_l.family =3D=3D AF_INET && ipv6_addr_v4mapped(&addr_r.addr6)) { - ipv6_addr_set_v4mapped(addr_l.addr.s_addr, &addr_l.addr6); - addr_l.family =3D AF_INET6; + if (local.addr.family =3D=3D AF_INET && ipv6_addr_v4mapped(&addr_r.addr6)= ) { + ipv6_addr_set_v4mapped(local.addr.addr.s_addr, &local.addr.addr6); + local.addr.family =3D AF_INET6; } - if (addr_r.family =3D=3D AF_INET && ipv6_addr_v4mapped(&addr_l.addr6)) { - ipv6_addr_set_v4mapped(addr_r.addr.s_addr, &addr_r.addr6); + if (addr_r.family =3D=3D AF_INET && ipv6_addr_v4mapped(&local.addr.addr6)= ) { + ipv6_addr_set_v4mapped(addr_r.addr.s_addr, &local.addr.addr6); addr_r.family =3D AF_INET6; } #endif - if (addr_l.family !=3D addr_r.family) { + if (local.addr.family !=3D addr_r.family) { GENL_SET_ERR_MSG(info, "address families do not match"); err =3D -EINVAL; goto destroy_err; } =20 - if (!addr_l.port || !addr_r.port) { + if (!local.addr.port || !addr_r.port) { GENL_SET_ERR_MSG(info, "missing local or remote port"); err =3D -EINVAL; goto destroy_err; } =20 lock_sock(sk); - ssk =3D mptcp_nl_find_ssk(msk, &addr_l, &addr_r); + ssk =3D mptcp_nl_find_ssk(msk, &local.addr, &addr_r); if (ssk) { struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(ssk); - struct mptcp_pm_addr_entry entry =3D { .addr =3D addr_l }; =20 spin_lock_bh(&msk->pm.lock); - mptcp_userspace_pm_delete_local_addr(msk, &entry); + mptcp_userspace_pm_delete_local_addr(msk, &local); spin_unlock_bh(&msk->pm.lock); mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN); mptcp_close_ssk(sk, ssk, subflow); --=20 2.43.0 From nobody Sun Dec 22 02:03:13 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FE016FB0 for ; Wed, 2 Oct 2024 15:02:15 +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=1727881335; cv=none; b=VNoLSek55Trmcj/VQV22vNkaAHC0ZzrcHz9QNZ9ErxVYxSvLNuvtT7lU0yn48EUKoyZqNeQ6AJ2Y+lFVzFAJhIrt2E29qmYLbZ0eAQxX+bqBmG34jVSsL+CVk6i/IxFbaWJOnNTaQCCk9rvss3jQgII1+3lDpge/5dwrd4RR53I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881335; c=relaxed/simple; bh=mmzc7mLX/pp+4/834DqQqofFdcapSC05ny0izEtmmpM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pz9T0HHJwrhqH6ZMSnfml+6bW0shlQ47FEdt+XK11ha6hBs5Fh7oDcA7U4TrReP7wM7t3U3iuhJTOeJv8p+FEXXBXJ2alhCb/20EJ8UjrBYHE2QadYOVSaQWZMZLFTOccPBb6lZwzaH4iFiHGzToX3E62D4TpJA2eNXNZIwY8DU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tVXKzDKl; 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="tVXKzDKl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D310C4CED1; Wed, 2 Oct 2024 15:02:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727881334; bh=mmzc7mLX/pp+4/834DqQqofFdcapSC05ny0izEtmmpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tVXKzDKlu2B/GY8L5REvkH/mILcPZQPpxfbmOVEpgyhE8vLl6Xpx8Kn4knzCM6e7W dcItZ6gCtKzLpKVd8e2outd0+EwGTWhruT6XkIyA0HTekWTRfGKdLssxXQzUI1I/ps TB1mc5RAGAPgzn7YdU8SbDOjojItWipG5YaTmHaVh/PbsPXNAIi0uQd7dLVTN+yyeB 3TkweEeo1RwwVniGczWACskDjC7hU5Ol3QR0EC6PirkTMQfMUAj7t76xuJBZ53qaXx RWtU+zrzUa+xl5tNIAZPsONpWWUauzR//vXlXyF6RXPH284zW7LcX+ea0mG2MyJEt9 oSDwS6WQGc0Sg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 7/9] mptcp: make pm wrappers static Date: Wed, 2 Oct 2024 23:01:57 +0800 Message-ID: <58030bde64496b632614feaa8c9f29050b66e8db.1727881073.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang The 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); } =20 -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 =3D 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 =3D mptcp_subflow_ctx(ssk); diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index e1907dad3bc4..d7a4199b142e 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1790,7 +1790,7 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } =20 -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 *inf= o) { struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet =3D genl_info_pm_nl(info); @@ -1840,13 +1840,20 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struc= t genl_info *info) return ret; } =20 +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); } =20 -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 =3D sock_net(msg->sk); struct mptcp_pm_addr_entry *entry; @@ -1888,6 +1895,15 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, return msg->len; } =20 +static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback= *cb) +{ + const struct genl_info *info =3D 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) { @@ -2009,7 +2025,7 @@ static int mptcp_nl_set_flags(struct net *net, return ret; } =20 -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 *in= fo) { struct mptcp_pm_addr_entry addr =3D { .addr =3D { .family =3D AF_UNSPEC }= , }; struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; @@ -2063,6 +2079,13 @@ int mptcp_pm_nl_set_flags(struct sk_buff *skb, struc= t genl_info *info) return 0; } =20 +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 ef50ef0c0829..95533d5b82c4 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1035,8 +1035,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 *in= fo); int mptcp_pm_announce_addr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, @@ -1127,13 +1125,8 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_soc= k *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_add= r_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); =20 --=20 2.43.0 From nobody Sun Dec 22 02:03:13 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A041567D for ; Wed, 2 Oct 2024 15:02:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881336; cv=none; b=U/HgTD38pZ7U96vrvcycTxCWqWsk9ZYzvnd5dT70nde4p2nhIWyC6uN65z53Kx03DcdJo0Hef9OmAqsQH9iBQGcD9qUm+KaIAfMQwmOKt3Nirrn7iz6avrwGna1EFHs/AUPkpZyGUpKmsWyeEJeXymnNLq4OGlsePLbFQ8/BEWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881336; c=relaxed/simple; bh=9gAMrj3rtc/c79aZHt7/nZg85VuJDwemdMmn6OAOFDk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZxQj/4R8I2mDXeVPBQDiRk5dmF8LwaArt5UlcjKu1Y3GKEpvzauW3p/CxkbW13oREhHG5mpO4azah0sFWxNDIBE0Yus4SKyh7n9WXWp7JIbSKT36v694B93Gb4EAjh9IhCUp3nOLrwsD9Fgtk5sAZ0jlLKt0V68/qYQe4VoCZjY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Kyq5+9em; 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="Kyq5+9em" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F807C4CECD; Wed, 2 Oct 2024 15:02:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727881336; bh=9gAMrj3rtc/c79aZHt7/nZg85VuJDwemdMmn6OAOFDk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kyq5+9emVD14NRfBAo/pSTwseYeGRGC1542KVFIcpzWh0shLsCctbYLq3YJbvVQLt pxHm5eD5IRV+PA6GTPTW3nJ+WohepIp4fV0UndZYB2xNi8Gd0u81mncuuG58fGYfHt m7PiFbm0H52CWOQXOx3ayaM+HbO3bm2X+5/eLYi/LTvG2qA3NPm0KUqvGJQqDYEyNE 53eGT+q/GcDjpnTvs1x//gg8eBTn/KYEq5rj5uUI+ua3qiwUh/JyAPOG9MPwQCepvC SfpK5KvCXQnq3Ss7T+6vy/g1TxOeogbFP+AR+xI8kzFIZ4fh8MquC7YL52UpoJ/hs+ 88JX2oQ3TDvMg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 8/9] mptcp: drop skb parameter of get_addr Date: Wed, 2 Oct 2024 23:01:58 +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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang The first parameters "skb" of all three get_addr() interfaces are now useless. This patch drops 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 d7a4199b142e..f02378e9a9c8 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1790,7 +1790,7 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } =20 -static int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *inf= o) +static int mptcp_pm_nl_get_addr(struct genl_info *info) { struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet =3D genl_info_pm_nl(info); @@ -1840,16 +1840,16 @@ static int mptcp_pm_nl_get_addr(struct sk_buff *skb= , struct genl_info *info) return ret; } =20 -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); } =20 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); } =20 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 9ff441beebe6..6711c1e1dac7 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; } =20 -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 =3D 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 95533d5b82c4..238fb2ddb68a 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1127,8 +1127,7 @@ bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, st= ruct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_add= r_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); =20 static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *= subflow) { --=20 2.43.0 From nobody Sun Dec 22 02:03:13 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A80631D0493 for ; Wed, 2 Oct 2024 15:02:17 +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=1727881337; cv=none; b=tWle9M4PSR9+OCRXxdleXJwcXwC4NPXfqp9uilJZkDTygFww+ga+yt6jqo6I78ITJxp/qAdvBy1rzQChMLUJrggA3mVadDQvxRQHd+2wYam+12RQqpGunZNRT7lZnNLfI/NqxsKhZ7q+JvU/8/O9Z0ZLyPrGu7MeavpDi1YjTfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727881337; c=relaxed/simple; bh=XpojAtqqO9J2VcQRB1KZlG+XmYpULxs8EOGboWAXy5s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gGTiE4/JIs34cI6MoU7kenUnQaFatHe62kZOyHdsKWJO3feajYvmckVEYTZ2bVwyhBqSVQN6VraLzRrJrhc82nOUdR3R+t1tjc5u+I0qq1SpBcZXTJuYNXrlcL/Nx3wss7qbaP+DgDb9If6OcZvAV8+pzy/Uq/dRuP/n2UjkHy4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QjmUDlMR; 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="QjmUDlMR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B09D4C4CEC2; Wed, 2 Oct 2024 15:02:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727881337; bh=XpojAtqqO9J2VcQRB1KZlG+XmYpULxs8EOGboWAXy5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QjmUDlMReW56jq3jSNc+pnDwrcIhY9VFbvnUD3CtcHiNh0XTenrqP7ucSh8fajP5k t4RVsZWYMmECYc68GTLRFLqIJWUYb9u1kXdg7JsVjWGioY9dewC/A2LD/RcFZkAFGw X84G1U/gEk2Xt16lPDaGRPGdckmiz2j7sRwlnTIEdx0F2+29EzNSSwGmcbsB7i8Wqa U/A9GEDfXwyaX4f/Gt/jC5KhnYnq/4XU6OEOdIVnTgZLPaHdz/ypw3qw7NCO1Or4RO pSX2JxMlERhybPqlArk8Q7qnV9a43aWheL6Tzsf+X3wJqVYhqHoB4yvlQ6RWrOwU49 Yi+pWDHbPZObQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 9/9] mptcp: drop skb parameter of set_flags Date: Wed, 2 Oct 2024 23:01:59 +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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 f02378e9a9c8..0f2fe64fd568 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -2025,13 +2025,13 @@ static int mptcp_nl_set_flags(struct net *net, return ret; } =20 -static int mptcp_pm_nl_set_flags(struct sk_buff *skb, struct genl_info *in= fo) +static int mptcp_pm_nl_set_flags(struct genl_info *info) { struct mptcp_pm_addr_entry addr =3D { .addr =3D { .family =3D AF_UNSPEC }= , }; struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; u8 changed, mask =3D MPTCP_PM_ADDR_FLAG_BACKUP | MPTCP_PM_ADDR_FLAG_FULLMESH; - struct net *net =3D sock_net(skb->sk); + struct net *net =3D genl_info_net(info); struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; u8 lookup_by_id =3D 0; @@ -2079,16 +2079,16 @@ static int mptcp_pm_nl_set_flags(struct sk_buff *sk= b, struct genl_info *info) return 0; } =20 -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); } =20 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); } =20 static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gf= p_t gfp) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 6711c1e1dac7..79531c949cc5 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 *sk= b, struct genl_info *info return err; } =20 -int mptcp_userspace_pm_set_flags(struct sk_buff *skb, struct genl_info *in= fo) +int mptcp_userspace_pm_set_flags(struct genl_info *info) { struct mptcp_pm_addr_entry loc =3D { .addr =3D { .family =3D AF_UNSPEC },= }; struct nlattr *attr_rem =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 238fb2ddb68a..41d01a046e27 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1035,7 +1035,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 *in= fo); +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); --=20 2.43.0