mptcp: pm: in-kernel: refactor fill_remote_addresses_vec
Before this modification, this function was quite long with many levels of indentations. Each case can be split in a dedicated function: fullmesh, non-fullmesh. To remove one level of indentation, msk->pm.subflows >= subflows_max is now checked after having added one subflow, and stops the loop if it is no longer possible to add new subflows. This is fine to do this because this function should only be called if msk->pm.subflows < subflows_max. No functional changes intended. Reviewed-by: Geliang Tang <geliang@kernel.org> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Link: https://patch.msgid.link/20250925-net-next-mptcp-c-flag-laminar-v1-4-ad126cc47c6b@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>pull/1354/merge
parent
8dc63ade45
commit
a845b2bbf2
|
|
@ -159,41 +159,44 @@ select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock *msk,
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fill all the remote addresses into the array addrs[],
|
static unsigned int
|
||||||
* and return the array size.
|
fill_remote_addr(struct mptcp_sock *msk, struct mptcp_addr_info *local,
|
||||||
*/
|
|
||||||
static unsigned int fill_remote_addresses_vec(struct mptcp_sock *msk,
|
|
||||||
struct mptcp_addr_info *local,
|
|
||||||
bool fullmesh,
|
|
||||||
struct mptcp_addr_info *addrs)
|
struct mptcp_addr_info *addrs)
|
||||||
{
|
{
|
||||||
bool deny_id0 = READ_ONCE(msk->pm.remote_deny_join_id0);
|
bool deny_id0 = READ_ONCE(msk->pm.remote_deny_join_id0);
|
||||||
struct sock *sk = (struct sock *)msk, *ssk;
|
|
||||||
struct mptcp_subflow_context *subflow;
|
|
||||||
struct mptcp_addr_info remote = { 0 };
|
struct mptcp_addr_info remote = { 0 };
|
||||||
unsigned int subflows_max;
|
struct sock *sk = (struct sock *)msk;
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
subflows_max = mptcp_pm_get_subflows_max(msk);
|
|
||||||
mptcp_remote_address((struct sock_common *)sk, &remote);
|
|
||||||
|
|
||||||
/* Non-fullmesh endpoint, fill in the single entry
|
|
||||||
* corresponding to the primary MPC subflow remote address
|
|
||||||
*/
|
|
||||||
if (!fullmesh) {
|
|
||||||
if (deny_id0)
|
if (deny_id0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
mptcp_remote_address((struct sock_common *)sk, &remote);
|
||||||
|
|
||||||
if (!mptcp_pm_addr_families_match(sk, local, &remote))
|
if (!mptcp_pm_addr_families_match(sk, local, &remote))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
msk->pm.subflows++;
|
msk->pm.subflows++;
|
||||||
addrs[i++] = remote;
|
*addrs = remote;
|
||||||
} else {
|
|
||||||
DECLARE_BITMAP(unavail_id, MPTCP_PM_MAX_ADDR_ID + 1);
|
|
||||||
|
|
||||||
/* Forbid creation of new subflows matching existing
|
return 1;
|
||||||
* ones, possibly already created by incoming ADD_ADDR
|
}
|
||||||
|
|
||||||
|
static unsigned int
|
||||||
|
fill_remote_addresses_fullmesh(struct mptcp_sock *msk,
|
||||||
|
struct mptcp_addr_info *local,
|
||||||
|
struct mptcp_addr_info *addrs)
|
||||||
|
{
|
||||||
|
bool deny_id0 = READ_ONCE(msk->pm.remote_deny_join_id0);
|
||||||
|
DECLARE_BITMAP(unavail_id, MPTCP_PM_MAX_ADDR_ID + 1);
|
||||||
|
struct sock *sk = (struct sock *)msk, *ssk;
|
||||||
|
struct mptcp_subflow_context *subflow;
|
||||||
|
unsigned int subflows_max;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
subflows_max = mptcp_pm_get_subflows_max(msk);
|
||||||
|
|
||||||
|
/* 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, MPTCP_PM_MAX_ADDR_ID + 1);
|
||||||
mptcp_for_each_subflow(msk, subflow)
|
mptcp_for_each_subflow(msk, subflow)
|
||||||
|
|
@ -213,20 +216,35 @@ static unsigned int fill_remote_addresses_vec(struct mptcp_sock *msk,
|
||||||
if (!mptcp_pm_addr_families_match(sk, local, &addrs[i]))
|
if (!mptcp_pm_addr_families_match(sk, local, &addrs[i]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (msk->pm.subflows < subflows_max) {
|
/* forbid creating multiple address towards this id */
|
||||||
/* forbid creating multiple address towards
|
|
||||||
* this id
|
|
||||||
*/
|
|
||||||
__set_bit(addrs[i].id, unavail_id);
|
__set_bit(addrs[i].id, unavail_id);
|
||||||
msk->pm.subflows++;
|
msk->pm.subflows++;
|
||||||
i++;
|
i++;
|
||||||
}
|
|
||||||
}
|
if (msk->pm.subflows >= subflows_max)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Fill all the remote addresses into the array addrs[],
|
||||||
|
* and return the array size.
|
||||||
|
*/
|
||||||
|
static unsigned int
|
||||||
|
fill_remote_addresses_vec(struct mptcp_sock *msk, struct mptcp_addr_info *local,
|
||||||
|
bool fullmesh, struct mptcp_addr_info *addrs)
|
||||||
|
{
|
||||||
|
/* Non-fullmesh: fill in the single entry corresponding to the primary
|
||||||
|
* MPC subflow remote address, and return 1, corresponding to 1 entry.
|
||||||
|
*/
|
||||||
|
if (!fullmesh)
|
||||||
|
return fill_remote_addr(msk, local, addrs);
|
||||||
|
|
||||||
|
/* Fullmesh endpoint: fill all possible remote addresses */
|
||||||
|
return fill_remote_addresses_fullmesh(msk, local, addrs);
|
||||||
|
}
|
||||||
|
|
||||||
static struct mptcp_pm_addr_entry *
|
static struct mptcp_pm_addr_entry *
|
||||||
__lookup_addr_by_id(struct pm_nl_pernet *pernet, unsigned int id)
|
__lookup_addr_by_id(struct pm_nl_pernet *pernet, unsigned int id)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue