mptcp: pm: code reorganisation
Subsystems (2)
Matthieu Baerts (NGI0)
maintainercover mptcp: pm: code reorganisation
I have been thinking about that during the past couple of months, but now, with the recent modifications done by Geliang, and the associated reviews, I really think it is time to reorganise the code around the path-managers to avoid confusions, and a mix of code used in different conditions.
Here is a first proposition, feel free to comment! :)
Please look at the last patch for more details about the why and why now.
I hope this will not cause too many issues with the in-progress patches. I tried only to move the code around, and minimise the functions renaming. Then, to switch to the new code, it might be easier to simply copy your modified code from the old place to the new one. In other words, duplicate the net/mptcp directory, then do a rebase, resolve the conflicts with 'git restore --ours', then reapply the modifications by copying your old code to the new place. If it is too difficult, please let me know.
---
Cc: Geliang Tang <[email protected]>
---
Matthieu Baerts (NGI0) (7):
mptcp: pm: remove '_nl' from mptcp_pm_nl_addr_send_ack
mptcp: pm: remove '_nl' from mptcp_pm_nl_mp_prio_send_ack
mptcp: pm: remove '_nl' from mptcp_pm_nl_work
mptcp: pm: remove '_nl' from mptcp_pm_nl_rm_addr_or_subflow
mptcp: pm: avoid calling PM specific code from core
mptcp: pm: worker: split in-kernel and common tasks
mptcp: pm: code reorganisation
net/mptcp/Makefile | 2 +- net/mptcp/pm.c | 685 ++++++++++++---- net/mptcp/pm_kernel.c | 1410 +++++++++++++++++++++++++++++++++ net/mptcp/pm_netlink.c | 1934 ++-------------------------------------------- net/mptcp/pm_userspace.c | 11 +- net/mptcp/protocol.c | 5 +- net/mptcp/protocol.h | 37 +- 7 files changed, 2051 insertions(+), 2033 deletions(-)
---
base-commit: 6b32949274eb9e32fe867ba9a8f8cb98587ecf36
change-id: 20250227-mptcp-pm-reorg-code-13227530bd05
Best regards,
Signature · 1 line
Matthieu Baerts (NGI0) <[email protected]>
Matthieu Baerts (NGI0)
maintainerPATCH 1/7 mptcp: pm: remove '_nl' from mptcp_pm_nl_addr_send_ack
Currently, in-kernel PM specific helpers are prefixed with 'mptcp_pm_nl_'. But here 'mptcp_pm_nl_addr_send_ack()' is not specific to this PM: it is used by both the in-kernel and userspace PMs.
To avoid confusions, the '_nl' bit has been removed from the name.
No behavioural changes intended.
--- net/mptcp/pm.c | 2 +- net/mptcp/pm_netlink.c | 8 ++++---- net/mptcp/pm_userspace.c | 2 +- net/mptcp/protocol.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-)
net/mptcp/pm.c +1 -1
@@ -57,7 +57,7 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_ msk->pm.rm_list_tx = *rm_list; rm_addr |=BIT (MPTCP_RM_ADDR_SIGNAL );WRITE_ONCE (msk->pm.addr_signal, rm_addr); -mptcp_pm_nl_addr_send_ack (msk); +mptcp_pm_addr_send_ack (msk);return 0 ; }
net/mptcp/pm_netlink.c +4 -4
@@ -606,7 +606,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) local.addr.id =0 ;mptcp_pm_announce_addr (msk, &local.addr, false); -mptcp_pm_nl_addr_send_ack (msk); +mptcp_pm_addr_send_ack (msk);if (local.flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ) signal_and_subflow = true;
@@ -740,7 +740,7 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) remote = msk->pm.remote;mptcp_pm_announce_addr (msk, &remote, true); -mptcp_pm_nl_addr_send_ack (msk); +mptcp_pm_addr_send_ack (msk);if (lookup_subflow_by_daddr (&msk->conn_list, &remote))return ;
@@ -781,7 +781,7 @@ bool mptcp_pm_nl_is_init_remote_addr(struct mptcp_sock *msk,return mptcp_addresses_equal (&mpc_remote, remote, remote->port); } -void mptcp_pm_nl_addr_send_ack (struct mptcp_sock *msk) +void mptcp_pm_addr_send_ack (struct mptcp_sock *msk) {struct mptcp_subflow_context *subflow, *alt =NULL ;
@@ -942,7 +942,7 @@ void mptcp_pm_nl_work(struct mptcp_sock *msk) }if (pm->status &BIT (MPTCP_PM_ADD_ADDR_SEND_ACK )) { pm->status &= ~BIT (MPTCP_PM_ADD_ADDR_SEND_ACK ); -mptcp_pm_nl_addr_send_ack (msk); +mptcp_pm_addr_send_ack (msk); }if (pm->status &BIT (MPTCP_PM_RM_ADDR_RECEIVED )) { pm->status &= ~BIT (MPTCP_PM_RM_ADDR_RECEIVED );
net/mptcp/pm_userspace.c +1 -1
@@ -235,7 +235,7 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info)if (mptcp_pm_alloc_anno_list (msk, &addr_val.addr)) { msk->pm.add_addr_signaled++;mptcp_pm_announce_addr (msk, &addr_val.addr, false); -mptcp_pm_nl_addr_send_ack (msk); +mptcp_pm_addr_send_ack (msk); }spin_unlock_bh (&msk->pm.lock);
net/mptcp/protocol.h +1 -1
@@ -1013,7 +1013,7 @@ void mptcp_pm_add_addr_echoed(struct mptcp_sock *msk,void mptcp_pm_add_addr_send_ack (struct mptcp_sock *msk);bool mptcp_pm_nl_is_init_remote_addr (struct mptcp_sock *msk,const struct mptcp_addr_info *remote); -void mptcp_pm_nl_addr_send_ack (struct mptcp_sock *msk); +void mptcp_pm_addr_send_ack (struct mptcp_sock *msk);void mptcp_pm_rm_addr_received (struct mptcp_sock *msk,const struct mptcp_rm_list *rm_list);void mptcp_pm_mp_prio_received (struct sock *sk,u8 bkup);
Signature · 1 line
2.47.1
Matthieu Baerts (NGI0)
maintainerPATCH 2/7 mptcp: pm: remove '_nl' from mptcp_pm_nl_mp_prio_send_ack
In reply to Matthieu Baerts (NGI0)Currently, in-kernel PM specific helpers are prefixed with 'mptcp_pm_nl_'. But here 'mptcp_pm_nl_mp_prio_send_ack()' is not specific to this PM: it is used by both the in-kernel and userspace PMs.
To avoid confusions, the '_nl' bit has been removed from the name.
No behavioural changes intended.
--- net/mptcp/pm_netlink.c | 10 +++++----- net/mptcp/pm_userspace.c | 4 ++-- net/mptcp/protocol.h | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-)
net/mptcp/pm_netlink.c +5 -5
@@ -808,10 +808,10 @@ void mptcp_pm_addr_send_ack(struct mptcp_sock *msk)mptcp_pm_send_ack (msk, alt, false, false); } -int mptcp_pm_nl_mp_prio_send_ack (struct mptcp_sock *msk, -struct mptcp_addr_info *addr, -struct mptcp_addr_info *rem, -u8 bkup) +int mptcp_pm_mp_prio_send_ack (struct mptcp_sock *msk, +struct mptcp_addr_info *addr, +struct mptcp_addr_info *rem, +u8 bkup) {struct mptcp_subflow_context *subflow;
@@ -1936,7 +1936,7 @@ static void mptcp_nl_set_flags(struct net *net,lock_sock (sk);if (changed &MPTCP_PM_ADDR_FLAG_BACKUP ) -mptcp_pm_nl_mp_prio_send_ack (msk, &local->addr,NULL , bkup); +mptcp_pm_mp_prio_send_ack (msk, &local->addr,NULL , bkup);/* Subflows will only be recreated if the SUBFLOW flag is set */ if (is_subflow && (changed &MPTCP_PM_ADDR_FLAG_FULLMESH ))mptcp_pm_nl_fullmesh (msk, &local->addr);
net/mptcp/pm_userspace.c +2 -2
@@ -606,10 +606,10 @@ int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local,spin_unlock_bh (&msk->pm.lock);lock_sock (sk); - ret =mptcp_pm_nl_mp_prio_send_ack (msk, &local->addr, &rem, bkup); + ret =mptcp_pm_mp_prio_send_ack (msk, &local->addr, &rem, bkup);release_sock (sk); -/* mptcp_pm_nl_mp_prio_send_ack() only fails in one case */ +/* mptcp_pm_mp_prio_send_ack() only fails in one case */ if (ret <0 )GENL_SET_ERR_MSG (info,"subflow not found" );
net/mptcp/protocol.h +4 -4
@@ -1018,10 +1018,10 @@ void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list);void mptcp_pm_mp_prio_received (struct sock *sk,u8 bkup);void mptcp_pm_mp_fail_received (struct sock *sk,u64 fail_seq); -int mptcp_pm_nl_mp_prio_send_ack (struct mptcp_sock *msk, -struct mptcp_addr_info *addr, -struct mptcp_addr_info *rem, -u8 bkup); +int mptcp_pm_mp_prio_send_ack (struct mptcp_sock *msk, +struct mptcp_addr_info *addr, +struct mptcp_addr_info *rem, +u8 bkup);bool mptcp_pm_alloc_anno_list (struct mptcp_sock *msk,const struct mptcp_addr_info *addr);void mptcp_pm_free_anno_list (struct mptcp_sock *msk);
Signature · 1 line
2.47.1
Matthieu Baerts (NGI0)
maintainerPATCH 3/7 mptcp: pm: remove '_nl' from mptcp_pm_nl_work
In reply to Matthieu Baerts (NGI0)Currently, in-kernel PM specific helpers are prefixed with 'mptcp_pm_nl_'. But here 'mptcp_pm_nl_work' is not specific to this PM:
it is called from the core to call helpers, some of them needed by both the in-kernel and userspace PMs.
To avoid confusions, the '_nl' bit has been removed from the name.
Also used 'worker' instead of 'work', similar to protocol.c's worker.
No behavioural changes intended.
--- net/mptcp/pm_netlink.c | 2 +- net/mptcp/protocol.c | 2 +- net/mptcp/protocol.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
net/mptcp/pm_netlink.c +1 -1
@@ -924,7 +924,7 @@ static void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk,mptcp_pm_nl_rm_addr_or_subflow (msk, rm_list,MPTCP_MIB_RMSUBFLOW ); } -void mptcp_pm_nl_work (struct mptcp_sock *msk) +void mptcp_pm_worker (struct mptcp_sock *msk) {struct mptcp_pm_data *pm = &msk->pm;
net/mptcp/protocol.c +1 -1
@@ -2681,7 +2681,7 @@ static void mptcp_worker(struct work_struct *work)mptcp_check_fastclose (msk); -mptcp_pm_nl_work (msk); +mptcp_pm_worker (msk);mptcp_check_send_data_fin (sk);mptcp_check_data_fin_ack (sk);
net/mptcp/protocol.h +1 -1
@@ -1152,7 +1152,7 @@ static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflo }void __init mptcp_pm_nl_init (void ); -void mptcp_pm_nl_work (struct mptcp_sock *msk); +void mptcp_pm_worker (struct mptcp_sock *msk);unsigned int mptcp_pm_get_add_addr_signal_max (const struct mptcp_sock *msk);unsigned int mptcp_pm_get_add_addr_accept_max (const struct mptcp_sock *msk);unsigned int mptcp_pm_get_subflows_max (const struct mptcp_sock *msk);
Signature · 1 line
2.47.1
Matthieu Baerts (NGI0)
maintainerPATCH 4/7 mptcp: pm: remove '_nl' from mptcp_pm_nl_rm_addr_or_subflow
In reply to Matthieu Baerts (NGI0)Currently, in-kernel PM specific helpers are prefixed with 'mptcp_pm_nl_'. But here 'mptcp_pm_nl_rm_addr_or_subflow' and 'mptcp_pm_nl_rm_addr_received' are not specific to this PM: the latter is called from the PM worker, and used by both the in-kernel and userspace PMs.
To avoid confusions, the '_nl' bit has been removed from the name.
No behavioural changes intended.
--- net/mptcp/pm_netlink.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
net/mptcp/pm_netlink.c +7 -7
@@ -838,9 +838,9 @@ int mptcp_pm_mp_prio_send_ack(struct mptcp_sock *msk,return -EINVAL ; } -static void mptcp_pm_nl_rm_addr_or_subflow (struct mptcp_sock *msk, -const struct mptcp_rm_list *rm_list, -enum linux_mptcp_mib_field rm_type) +static void mptcp_pm_rm_addr_or_subflow (struct mptcp_sock *msk, +const struct mptcp_rm_list *rm_list, +enum linux_mptcp_mib_field rm_type) {struct mptcp_subflow_context *subflow, *tmp;struct sock *sk = (struct sock *)msk;
@@ -913,15 +913,15 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk, } } -static void mptcp_pm_nl_rm_addr_received (struct mptcp_sock *msk) +static void mptcp_pm_rm_addr_recv (struct mptcp_sock *msk) { -mptcp_pm_nl_rm_addr_or_subflow (msk, &msk->pm.rm_list_rx,MPTCP_MIB_RMADDR ); +mptcp_pm_rm_addr_or_subflow (msk, &msk->pm.rm_list_rx,MPTCP_MIB_RMADDR ); }static void mptcp_pm_nl_rm_subflow_received (struct mptcp_sock *msk,const struct mptcp_rm_list *rm_list) { -mptcp_pm_nl_rm_addr_or_subflow (msk, rm_list,MPTCP_MIB_RMSUBFLOW ); +mptcp_pm_rm_addr_or_subflow (msk, rm_list,MPTCP_MIB_RMSUBFLOW ); }void mptcp_pm_worker (struct mptcp_sock *msk)
@@ -946,7 +946,7 @@ void mptcp_pm_worker(struct mptcp_sock *msk) }if (pm->status &BIT (MPTCP_PM_RM_ADDR_RECEIVED )) { pm->status &= ~BIT (MPTCP_PM_RM_ADDR_RECEIVED ); -mptcp_pm_nl_rm_addr_received (msk); +mptcp_pm_rm_addr_recv (msk); }if (pm->status &BIT (MPTCP_PM_ESTABLISHED )) { pm->status &= ~BIT (MPTCP_PM_ESTABLISHED );
Signature · 1 line
2.47.1
Matthieu Baerts (NGI0)
maintainerPATCH 5/7 mptcp: pm: avoid calling PM specific code from core
In reply to Matthieu Baerts (NGI0)When destroying an MPTCP socket, some userspace PM specific code was called from mptcp_destroy_common() in protocol.c. That feels wrong, and it is the only case.
Instead, the core now calls mptcp_pm_destroy() from pm.c which is now in charge of cleaning the announced addresses list, and ask the different PMs to do extra cleaning if needed, e.g. the userspace PM, if used, will clean the local addresses list.
While at it, the userspace PM specific helper has been prefixed with 'mptcp_userspace_pm_' like the other ones.
No behavioural changes intended.
--- net/mptcp/pm.c | 8 ++++++++ net/mptcp/pm_userspace.c | 5 +---- net/mptcp/protocol.c | 3 +-- net/mptcp/protocol.h | 3 ++- 4 files changed, 12 insertions(+), 7 deletions(-)
net/mptcp/pm.c +8 -0
@@ -599,6 +599,14 @@ bool mptcp_pm_addr_families_match(const struct sock *sk,#endif } +void mptcp_pm_destroy (struct mptcp_sock *msk) +{ +mptcp_pm_free_anno_list (msk); + +if (mptcp_pm_is_userspace (msk)) +mptcp_userspace_pm_free_local_addr_list (msk); +} +void mptcp_pm_data_reset (struct mptcp_sock *msk) {u8 pm_type =mptcp_get_pm_type (sock_net ((struct sock *)msk));
net/mptcp/pm_userspace.c +1 -4
@@ -12,15 +12,12 @@list_for_each_entry (__entry, \ &((__msk)->pm.userspace_pm_local_addr_list), list) -void mptcp_free_local_addr_list (struct mptcp_sock *msk) +void mptcp_userspace_pm_free_local_addr_list (struct mptcp_sock *msk) {struct mptcp_pm_addr_entry *entry, *tmp;struct sock *sk = (struct sock *)msk;LIST_HEAD (free_list); -if (!mptcp_pm_is_userspace (msk)) -return ; -spin_lock_bh (&msk->pm.lock);list_splice_init (&msk->pm.userspace_pm_local_addr_list, &free_list);spin_unlock_bh (&msk->pm.lock);
net/mptcp/protocol.c +1 -2
@@ -3305,8 +3305,7 @@ void mptcp_destroy_common(struct mptcp_sock *msk, unsigned int flags)* inet_sock_destruct() will dispose it */ mptcp_token_destroy (msk); -mptcp_pm_free_anno_list (msk); -mptcp_free_local_addr_list (msk); +mptcp_pm_destroy (msk); }static void mptcp_destroy (struct sock *sk)
net/mptcp/protocol.h +2 -1
@@ -988,6 +988,7 @@ __sum16 __mptcp_make_csum(u64 data_seq, u32 subflow_seq, u16 data_len, __wsum suvoid __init mptcp_pm_init (void );void mptcp_pm_data_init (struct mptcp_sock *msk);void mptcp_pm_data_reset (struct mptcp_sock *msk); +void mptcp_pm_destroy (struct mptcp_sock *msk);int mptcp_pm_parse_addr (struct nlattr *attr,struct genl_info *info,struct mptcp_addr_info *addr); int mptcp_pm_parse_entry(struct nlattr *attr, struct genl_info *info,
@@ -1047,7 +1048,7 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_void mptcp_pm_remove_addr_entry (struct mptcp_sock *msk,struct mptcp_pm_addr_entry *entry); -void mptcp_free_local_addr_list (struct mptcp_sock *msk); +void mptcp_userspace_pm_free_local_addr_list (struct mptcp_sock *msk);void mptcp_event (enum mptcp_event_type type,const struct mptcp_sock *msk,const struct sock *ssk,gfp_t gfp);
Signature · 1 line
2.47.1
Matthieu Baerts (NGI0)
maintainerPATCH 6/7 mptcp: pm: worker: split in-kernel and common tasks
In reply to Matthieu Baerts (NGI0)To make it clear what actions are in-kernel PM specific and which ones are not and done for all PMs, e.g. sending ADD_ADDR and close associated subflows when a RM_ADDR is received.
--- net/mptcp/pm.c | 25 +++++++++++++++++++++++++ net/mptcp/pm_netlink.c | 21 ++------------------- net/mptcp/protocol.h | 1 + 3 files changed, 28 insertions(+), 19 deletions(-)
net/mptcp/pm.c +25 -0
@@ -599,6 +599,31 @@ bool mptcp_pm_addr_families_match(const struct sock *sk,#endif } +void mptcp_pm_worker (struct mptcp_sock *msk) +{ +struct mptcp_pm_data *pm = &msk->pm; + +msk_owned_by_me (msk); + +if (!(pm->status &MPTCP_PM_WORK_MASK )) +return ; + +spin_lock_bh (&msk->pm.lock); + +pr_debug ("msk=%p status=%x\n" , msk, pm->status); +if (pm->status &BIT (MPTCP_PM_ADD_ADDR_SEND_ACK )) { + pm->status &= ~BIT (MPTCP_PM_ADD_ADDR_SEND_ACK ); +mptcp_pm_addr_send_ack (msk); + } +if (pm->status &BIT (MPTCP_PM_RM_ADDR_RECEIVED )) { + pm->status &= ~BIT (MPTCP_PM_RM_ADDR_RECEIVED ); +mptcp_pm_rm_addr_recv (msk); + } +__mptcp_pm_kernel_worker (msk); + +spin_unlock_bh (&msk->pm.lock); +} +void mptcp_pm_destroy (struct mptcp_sock *msk) {mptcp_pm_free_anno_list (msk);
net/mptcp/pm_netlink.c +2 -19
@@ -924,30 +924,15 @@ static void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk,mptcp_pm_rm_addr_or_subflow (msk, rm_list,MPTCP_MIB_RMSUBFLOW ); } -void mptcp_pm_worker (struct mptcp_sock *msk) +/* Called under PM lock */ +void __mptcp_pm_kernel_worker (struct mptcp_sock *msk) {struct mptcp_pm_data *pm = &msk->pm; -msk_owned_by_me (msk); - -if (!(pm->status &MPTCP_PM_WORK_MASK )) -return ; - -spin_lock_bh (&msk->pm.lock); - -pr_debug ("msk=%p status=%x\n" , msk, pm->status);if (pm->status &BIT (MPTCP_PM_ADD_ADDR_RECEIVED )) { pm->status &= ~BIT (MPTCP_PM_ADD_ADDR_RECEIVED );mptcp_pm_nl_add_addr_received (msk); } -if (pm->status &BIT (MPTCP_PM_ADD_ADDR_SEND_ACK )) { - pm->status &= ~BIT (MPTCP_PM_ADD_ADDR_SEND_ACK ); -mptcp_pm_addr_send_ack (msk); - } -if (pm->status &BIT (MPTCP_PM_RM_ADDR_RECEIVED )) { - pm->status &= ~BIT (MPTCP_PM_RM_ADDR_RECEIVED ); -mptcp_pm_rm_addr_recv (msk); - }if (pm->status &BIT (MPTCP_PM_ESTABLISHED )) { pm->status &= ~BIT (MPTCP_PM_ESTABLISHED );mptcp_pm_nl_fully_established (msk);
@@ -956,8 +941,6 @@ void mptcp_pm_worker(struct mptcp_sock *msk) pm->status &= ~BIT (MPTCP_PM_SUBFLOW_ESTABLISHED );mptcp_pm_nl_subflow_established (msk); } - -spin_unlock_bh (&msk->pm.lock); }static bool address_use_port (struct mptcp_pm_addr_entry *entry)
net/mptcp/protocol.h +1 -0
@@ -1154,6 +1154,7 @@ static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflovoid __init mptcp_pm_nl_init (void );void mptcp_pm_worker (struct mptcp_sock *msk); +void __mptcp_pm_kernel_worker (struct mptcp_sock *msk);unsigned int mptcp_pm_get_add_addr_signal_max (const struct mptcp_sock *msk);unsigned int mptcp_pm_get_add_addr_accept_max (const struct mptcp_sock *msk);unsigned int mptcp_pm_get_subflows_max (const struct mptcp_sock *msk);
Signature · 1 line
2.47.1
Geliang Tang
reviewerRe: [PATCH mptcp-next 6/7] mptcp: pm: worker: split in-kernel and common tasks
Hi Matt,
Quoted 33 lines · On Thu, 2025-02-27 at 21:08 +0100, Matthieu Baerts (NGI0) wrote:
To make it clear what actions are in-kernel PM specific and which ones
are not and done for all PMs, e.g. sendingADD_ADDRand close associated
subflows when aRM_ADDRis received.Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
net/mptcp/pm.c | 25 +++++++++++++++++++++++++net/mptcp/pm_netlink.c| 21 ++------------------- net/mptcp/protocol.h | 1 +3 files changed, 28 insertions(+), 19 deletions(-)net/mptcp/pm.c +0
-0index
e1ca90701fd92abbf6d8b92d461ddb18d2652391..c17828981dd6400b2ed74dd28a95e21f76ed37b9100644net/mptcp/pm.c +0
-0@@ -599,6 +599,31 @@ bool mptcp_pm_addr_families_match(const struct sock *sk, #endif }net/mptcp/pm.c +9
-0+void mptcp_pm_worker (struct mptcp_sock *msk) +{ +struct mptcp_pm_data *pm = &msk->pm; + +msk_owned_by_me (msk); + +if (!(pm->status &MPTCP_PM_WORK_MASK )) +return ; +
net/mptcp/pm.c bool mptcp_pm_addr_families_match(const struct sock *sk, · line 620
Quoted 10 lines
net/mptcp/pm.c +10
-0+spin_lock_bh (&msk->pm.lock); + +pr_debug ("msk=%p status=%x\n" , msk, pm->status); +if (pm->status &BIT (MPTCP_PM_ADD_ADDR_SEND_ACK )) { + pm->status &= ~BIT (MPTCP_PM_ADD_ADDR_SEND_ACK ); +mptcp_pm_addr_send_ack (msk); + } +if (pm->status &BIT (MPTCP_PM_RM_ADDR_RECEIVED )) { + pm->status &= ~BIT (MPTCP_PM_RM_ADDR_RECEIVED ); +mptcp_pm_rm_addr_recv (msk);
CI made the following complaint:
net/mptcp/pm.c: In function 'mptcp_pm_worker':
net/mptcp/pm.c:620:17: error: implicit declaration of function
'mptcp_pm_rm_addr_recv'; did you mean 'mptcp_pm_rm_addr_received'? [- Wimplicit-function-declaration]
620 | mptcp_pm_rm_addr_recv(msk);
| ^~~~~~~~~~~~~~~~~~~~~
| mptcp_pm_rm_addr_receivedQuoted 78 lines
net/mptcp/pm.c +6
-0+ } +__mptcp_pm_kernel_worker (msk); + +spin_unlock_bh (&msk->pm.lock); +} +void
mptcp_pm_destroy(struct mptcp_sock *msk)
{
mptcp_pm_free_anno_list(msk);net/mptcp/pm_netlink.c +0
-0index
44362b0f7ee4f131482705439eb96c0374177c1d..2a8652886fce6ba9743d0efba576ac57f35a0077100644net/mptcp/pm_netlink.c +0
-0@@ -924,30 +924,15 @@ static void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk, mptcp_pm_rm_addr_or_subflow(msk, rm_list, MPTCP_MIB_RMSUBFLOW); }net/mptcp/pm_netlink.c +2
-1-void mptcp_pm_worker (struct mptcp_sock *msk) +/* Called under PM lock */ +void __mptcp_pm_kernel_worker (struct mptcp_sock *msk){
structmptcp_pm_data*pm =&msk->pm;net/mptcp/pm_netlink.c +0
-8-msk_owned_by_me (msk); - -if (!(pm->status &MPTCP_PM_WORK_MASK )) -return ; - -spin_lock_bh (&msk->pm.lock); - -pr_debug ("msk=%p status=%x\n" , msk, pm->status);if (
pm->status&BIT(MPTCP_PM_ADD_ADDR_RECEIVED)) {pm->status&= ~BIT(MPTCP_PM_ADD_ADDR_RECEIVED);mptcp_pm_nl_add_addr_received(msk);
}net/mptcp/pm_netlink.c +0
-8-if (pm->status &BIT (MPTCP_PM_ADD_ADDR_SEND_ACK )) { - pm->status &= ~BIT (MPTCP_PM_ADD_ADDR_SEND_ACK ); -mptcp_pm_addr_send_ack (msk); - } -if (pm->status &BIT (MPTCP_PM_RM_ADDR_RECEIVED )) { - pm->status &= ~BIT (MPTCP_PM_RM_ADDR_RECEIVED ); -mptcp_pm_rm_addr_recv (msk); - }if (
pm->status&BIT(MPTCP_PM_ESTABLISHED)) {pm->status&= ~BIT(MPTCP_PM_ESTABLISHED);mptcp_pm_nl_fully_established(msk);net/mptcp/pm_netlink.c +0
-2@@ -956,8 +941,6 @@ void mptcp_pm_worker(struct mptcp_sock *msk) pm->status &= ~BIT(MPTCP_PM_SUBFLOW_ESTABLISHED); mptcp_pm_nl_subflow_established(msk); } - -spin_unlock_bh (&msk->pm.lock); }
static booladdress_use_port(struct mptcp_pm_addr_entry *entry)net/mptcp/protocol.h +0
-0index
93faf203d987100f22e507c7f443d937284881e4..8742527196887598eb242c82f06004107d29ef92100644net/mptcp/protocol.h +0
-0@@ -1154,6 +1154,7 @@ static inline u8 subflow_get_local_id(conststruct
mptcp_subflow_context*subflo
void__initmptcp_pm_nl_init(void);
voidmptcp_pm_worker(struct mptcp_sock *msk);
+void__mptcp_pm_kernel_worker(struct mptcp_sock *msk); unsigned intmptcp_pm_get_add_addr_signal_max(const struct mptcp_sock *msk);
unsigned intmptcp_pm_get_add_addr_accept_max(const struct mptcp_sock *msk);
unsigned intmptcp_pm_get_subflows_max(const struct mptcp_sock *msk);
Matthieu Baerts (NGI0)
maintainerPATCH 7/7 mptcp: pm: code reorganisation
In reply to Matthieu Baerts (NGI0)Before this patch, the PM code was dispersed in different places:
- pm.c had common code for all PMs
- pm_netlink.c was supposed to be about the in-kernel PM, but also had exported common helpers, callbacks used by the different PMs, NL events for PM userspace daemon, etc. quite confusing.
- pm_userspace.c had userspace PM only code, but using specific in-kernel PM helpers
To clarify the code, a reorganisation is suggested here, only by moving code around, and small helper renaming to avoid confusions:
- pm_netlink.c now only contains common PM Netlink code:
- PM events: this code was already there
- shared helpers around Netlink code that were already there as well
- shared Netlink commands code from pm.c
- pm_kernel.c now contains only code that is specific to the in-kernel PM. Now all functions are either called from:
- pm.c: events coming from the core, when this PM is being used
- pm_netlink.c: for shared Netlink commands
- mptcp_pm_gen.c: for Netlink commands specific to the in-kernel PM
- sockopt.c: for the exported counters per netns
- (while at it, two checkpatch warnings have been fixed: remove unneeded return, and the duplicated condition before a kfree())
- pm.c got many code from pm_netlink.c:
- helpers used from both PMs and not linked to Netlink
- callbacks used by different PMs, e.g. ADD_ADDR management
- some helpers have been renamed to remove the '_nl' prefix, and they have been marked as 'static'.
- protocol.h has been updated accordingly:
- some helpers no longer need to be exported
- new ones needed to be exported: they have been prefixed if needed.
The code around the PM is now less confusing, which should help for the maintenance in the long term.
This will certainly impact future backports, but because other cleanups have already done recently, and more are coming to ease the addition of a new path-manager controlled with BPF (struct_ops), doing that now seems to be a good time. Also, many issues around the PM have been fixed a few months ago while increasing the code coverage in the selftests, so such big reorganisation can be done with more confidence now.
No behavioural changes intended.
--- net/mptcp/Makefile | 2 +- net/mptcp/pm.c | 664 +++++++++++++---- net/mptcp/pm_kernel.c | 1410 +++++++++++++++++++++++++++++++++++ net/mptcp/pm_netlink.c | 1917 +++--------------------------------------------- net/mptcp/protocol.h | 21 +- 5 files changed, 2009 insertions(+), 2005 deletions(-)
net/mptcp/Makefile +1 -1
@@ -3,7 +3,7 @@ obj-$(CONFIG_MPTCP) += mptcp.o mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o \ mib.o pm_netlink.o sockopt.o pm_userspace.o fastopen.o sched.o \ - mptcp_pm_gen.o + mptcp_pm_gen.o pm_kernel.o obj-$(CONFIG_SYN_COOKIES) += syncookies.o obj-$(CONFIG_INET_MPTCP_DIAG) += mptcp_diag.o
net/mptcp/pm.c +504 -160
728 lines not on this page · raw message
net/mptcp/pm_kernel.c new file +1410 -0
1,410 lines not on this page · raw message
net/mptcp/pm_netlink.c +84 -1833
854 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.47.1
Part of the diff is not shown here. View the raw message.
Geliang Tang
reviewerHi Matt,
Thanks for this set, it's useful for me to implement mptcp_pm_ops.
Quoted 678 lines · On Thu, 2025-02-27 at 21:08 +0100, Matthieu Baerts (NGI0) wrote:
Before this patch, the PM code was dispersed in different places:
-
pm.chad common code for all PMs-
pm_netlink.cwas supposed to be about the in-kernel PM, but also had
exported common helpers, callbacks used by the different PMs, NL events for PM userspace daemon, etc. quite confusing.-
pm_userspace.chad userspace PM only code, but using specific in-kernel PM helpersTo clarify the code, a reorganisation is suggested here, only by moving
code around, and small helper renaming to avoid confusions:-
pm_netlink.cnow only contains common PM Netlink code:
- PM events: this code was already there
- shared helpers around Netlink code that were already there as well
- shared Netlink commands code frompm.c-
pm_kernel.cnow contains only code that is specific to the in- kernel
PM. Now all functions are either called from:
-pm.c: events coming from the core, when this PM is being used
-pm_netlink.c: for shared Netlink commands
-mptcp_pm_gen.c: for Netlink commands specific to the in-kernel PM
-sockopt.c: for the exported counters per netns
- (while at it, two checkpatch warnings have been fixed: remove unneeded return, and the duplicated condition before akfree())-
pm.cgot many code frompm_netlink.c:
- helpers used from both PMs and not linked to Netlink
- callbacks used by different PMs, e.g.ADD_ADDRmanagement
- some helpers have been renamed to remove the '_nl' prefix, and they
have been marked as 'static'.-
protocol.hhas been updated accordingly:
- some helpers no longer need to be exported
- new ones needed to be exported: they have been prefixed if needed.The code around the PM is now less confusing, which should help for the
maintenance in the long term.This will certainly impact future backports, but because other cleanups
have already done recently, and more are coming to ease the addition of
a new path-manager controlled with BPF (struct_ops), doing that now seems to be a good time. Also, many issues around the PM have been fixed
a few months ago while increasing the code coverage in the selftests, so
such big reorganisation can be done with more confidence now.No behavioural changes intended.
Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
net/mptcp/Makefile | 2 +-
net/mptcp/pm.c | 664 +++++++++++++---- net/mptcp/pm_kernel.c | 1410 +++++++++++++++++++++++++++++++++++net/mptcp/pm_netlink.c| 1917 +++-----------------------------------
----------
net/mptcp/protocol.h | 21 +-5 files changed, 2009 insertions(+), 2005 deletions(-)net/mptcp/Makefile +0
-0index
5dbc37d38d7a4b0779c71e7b291ef83a49e46648..bd72b300a0f68fa862bcae5aa1e1e913f595f315100644net/mptcp/Makefile +0
-0@@ -3,7 +3,7 @@ obj-$(CONFIG_MPTCP) += mptcp.o
mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o \
mib.o pm_netlink.o sockopt.o pm_userspace.o fastopen.o sched.o \net/mptcp/Makefile +1
-1- mptcp_pm_gen.o + mptcp_pm_gen.o pm_kernel.o
obj-$(CONFIG_SYN_COOKIES) += syncookies.o
obj-$(CONFIG_INET_MPTCP_DIAG) += mptcp_diag.onet/mptcp/pm.c +0
-0index
c17828981dd6400b2ed74dd28a95e21f76ed37b9..8b9117abbe7cd22e8770810e9d5aeb9ee0e001e6100644net/mptcp/pm.c +0
-0@@ -5,12 +5,399 @@*/ #define pr_fmt(fmt) "MPTCP: " fmtnet/mptcp/pm.c +0
-2-#include <linux/kernel.h> -#include <net/mptcp.h> #include "
protocol.h"
-
#include "mib.h"net/mptcp/pm.c +15
-1-#include "mptcp_pm_gen.h" + +#define ADD_ADDR_RETRANS_MAX 3 + +struct mptcp_pm_add_entry { +struct list_head list; +struct mptcp_addr_info addr; +u8 retrans_times; +struct timer_list add_timer; +struct mptcp_sock *sock; +}; + +/* path manager helpers */ + +bool mptcp_addresses_equal (const struct mptcp_addr_info *a, + const struct mptcp_addr_info *b, bool
use_port)net/mptcp/pm.c +6
-0+{ +bool addr_equals = false; + +if (a->family == b->family) { +if (a->family ==AF_INET ) + addr_equals = a->addr.s_addr == b-Quoted 1 line
addr.s_addr;
net/mptcp/pm.c +3
-0+#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) + else + addr_equals = ipv6_addr_equal(&a->addr6, &b-Quoted 1 line
addr6);
net/mptcp/pm.c +3
-0+ }else if (a->family ==AF_INET ) { +if (ipv6_addr_v4mapped (&b->addr6)) + addr_equals = a->addr.s_addr == b-Quoted 1 line
addr6.s6_addr32[3];
net/mptcp/pm.c +3
-0+ }else if (b->family ==AF_INET ) { +if (ipv6_addr_v4mapped (&a->addr6)) + addr_equals = a->addr6.s6_addr32[3] == b-Quoted 1 line
addr.s_addr;
net/mptcp/pm.c +38
-0+#endif + } + +if (!addr_equals) +return false; +if (!use_port) +return true; + +return a->port == b->port; +} + +void mptcp_remote_address (const struct sock_common *skc, + struct mptcp_addr_info *addr) +{ + addr->family = skc->skc_family; + addr->port = skc->skc_dport; +if (addr->family ==AF_INET ) + addr->addr.s_addr = skc->skc_daddr; +#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) + else if (addr->family == AF_INET6) + addr->addr6 = skc->skc_v6_daddr; +#endif +} + +void mptcp_local_address (const struct sock_common *skc, +struct mptcp_addr_info *addr) +{ + addr->family = skc->skc_family; + addr->port =htons (skc->skc_num); +if (addr->family ==AF_INET ) + addr->addr.s_addr = skc->skc_rcv_saddr; +#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) + else if (addr->family == AF_INET6) + addr->addr6 = skc->skc_v6_rcv_saddr; +#endif +} + +/* if sk is ipv4 or ipv6_only allows only same-family local and remote addresses,
+ * otherwise allow any matching local/remote pair
+ */net/mptcp/pm.c +8
-0+bool mptcp_pm_addr_families_match (const struct sock *sk, + const struct mptcp_addr_info *loc, + const struct mptcp_addr_info *rem) +{ +bool mptcp_is_v4 = sk->sk_family ==AF_INET ; + +#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) + bool loc_is_v4 = loc->family == AF_INET ||
ipv6_addr_v4mapped(&loc->addr6);net/mptcp/pm.c +1
-0+ bool rem_is_v4 = rem->family == AF_INET ||
ipv6_addr_v4mapped(&rem->addr6);net/mptcp/pm.c +10
-0+ +if (mptcp_is_v4) +return loc_is_v4 && rem_is_v4; + +if (ipv6_only_sock (sk)) +return !loc_is_v4 && !rem_is_v4; + +return loc_is_v4 == rem_is_v4; +#else +return mptcp_is_v4 && loc->family ==AF_INET && rem->family==
AF_INET;net/mptcp/pm.c +5
-0+#endif +} + +bool mptcp_lookup_subflow_by_saddr (const struct list_head *list, + const struct mptcp_addr_info*saddr)
net/mptcp/pm.c +7
-0+{ +struct mptcp_subflow_context *subflow; +struct mptcp_addr_info cur; +struct sock_common *skc; + +list_for_each_entry (subflow, list, node) { + skc = (struct sock_common*)mptcp_subflow_tcp_sock(subflow);
net/mptcp/pm.c +27
-0+ +mptcp_local_address (skc, &cur); +if (mptcp_addresses_equal (&cur, saddr, saddr->port)) +return true; + } + +return false; +} + +static struct mptcp_pm_add_entry * +mptcp_lookup_anno_list_by_saddr (const struct mptcp_sock *msk, +const struct mptcp_addr_info *addr) +{ +struct mptcp_pm_add_entry *entry; + +lockdep_assert_held (&msk->pm.lock); + +list_for_each_entry (entry, &msk->pm.anno_list, list) { +if (mptcp_addresses_equal (&entry->addr, addr, true)) +return entry; + } + +return NULL ; +} + +bool mptcp_remove_anno_list_by_saddr (struct mptcp_sock *msk, + const struct mptcp_addr_info*addr)
net/mptcp/pm.c +9
-0+{ +struct mptcp_pm_add_entry *entry; + + entry =mptcp_pm_del_add_timer (msk, addr, false); +kfree (entry); +return entry; +} + +bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, conststruct sock *sk)
net/mptcp/pm.c +10
-0+{ +struct mptcp_pm_add_entry *entry; +struct mptcp_addr_info saddr; +bool ret = false; + +mptcp_local_address ((struct sock_common *)sk, &saddr); + +spin_lock_bh (&msk->pm.lock); +list_for_each_entry (entry, &msk->pm.anno_list, list) { + if (mptcp_addresses_equal(&entry->addr, &saddr,true)) {
net/mptcp/pm.c +11
-0+ ret = true; + goto out; + } + } + +out: +spin_unlock_bh (&msk->pm.lock); +return ret; +} + +/* return true if the new status bit is currently cleared, that is, this event
+ * can be server, eventually by an already scheduled work
+ */net/mptcp/pm.c +23
-0+static bool mptcp_pm_schedule_work (struct mptcp_sock *msk, + enum mptcp_pm_status new_status) +{ +pr_debug ("msk=%p status=%x new=%lx\n" , msk, msk->pm.status, +BIT (new_status)); +if (msk->pm.status &BIT (new_status)) +return false; + + msk->pm.status |=BIT (new_status); +mptcp_schedule_work ((struct sock *)msk); +return true; +} + +static void mptcp_pm_add_addr_send_ack (struct mptcp_sock *msk) +{ +if (!mptcp_pm_should_add_signal (msk)) +return ; + +mptcp_pm_schedule_work (msk,MPTCP_PM_ADD_ADDR_SEND_ACK ); +} + +static void __mptcp_pm_send_ack (struct mptcp_sock *msk, + struct mptcp_subflow_context*subflow,
net/mptcp/pm.c +8
-0+ bool prio, bool backup) +{ +struct sock *ssk =mptcp_subflow_tcp_sock (subflow); +bool slow; + + pr_debug("send ack for %s\n", + prio ? "mp_prio" : + (mptcp_pm_should_add_signal(msk) ? "add_addr" :"
rm_addr"));net/mptcp/pm.c +35
-0+ + slow =lock_sock_fast (ssk); +if (prio) { + subflow->send_mp_prio =1 ; + subflow->request_bkup = backup; + } + +__mptcp_subflow_send_ack (ssk); +unlock_sock_fast (ssk, slow); +} + +void mptcp_pm_send_ack (struct mptcp_sock *msk, + struct mptcp_subflow_context *subflow, + bool prio, bool backup) +{ +spin_unlock_bh (&msk->pm.lock); +__mptcp_pm_send_ack (msk, subflow, prio, backup); +spin_lock_bh (&msk->pm.lock); +} + +void mptcp_pm_addr_send_ack (struct mptcp_sock *msk) +{ +struct mptcp_subflow_context *subflow, *alt =NULL ; + +msk_owned_by_me (msk); +lockdep_assert_held (&msk->pm.lock); + +if (!mptcp_pm_should_add_signal (msk) && + !mptcp_pm_should_rm_signal(msk)) +return ; + +mptcp_for_each_subflow (msk, subflow) { +if (__mptcp_subflow_active (subflow)) { +if (!subflow->stale) { + mptcp_pm_send_ack(msk, subflow,false, false);
net/mptcp/pm.c +26
-0+return ; + } + +if (!alt) + alt = subflow; + } + } + +if (alt) +mptcp_pm_send_ack (msk, alt, false, false); +} + +int mptcp_pm_mp_prio_send_ack (struct mptcp_sock *msk, + struct mptcp_addr_info *addr, + struct mptcp_addr_info *rem, + u8 bkup) +{ +struct mptcp_subflow_context *subflow; + +pr_debug ("bkup=%d\n" , bkup); + +mptcp_for_each_subflow (msk, subflow) { +struct sock *ssk =mptcp_subflow_tcp_sock (subflow); +struct mptcp_addr_info local, remote; + + mptcp_local_address((struct sock_common *)ssk,&local);
net/mptcp/pm.c +1
-0+ if (!mptcp_addresses_equal(&local, addr, addr-Quoted 1 line
port))
net/mptcp/pm.c +4
-0+continue ; + +if (rem && rem->family !=AF_UNSPEC ) { + mptcp_remote_address((struct sock_common*)ssk, &remote);
net/mptcp/pm.c +1
-0+ if (!mptcp_addresses_equal(&remote, rem,
rem->port))net/mptcp/pm.c +13
-0+continue ; + } + +__mptcp_pm_send_ack (msk, subflow, true, bkup); +return 0 ; + } + +return -EINVAL ; +} + +static void mptcp_pm_add_timer (struct timer_list *timer) +{ + struct mptcp_pm_add_entry *entry = from_timer(entry, timer,
add_timer);net/mptcp/pm.c +16
-0+struct mptcp_sock *msk = entry->sock; +struct sock *sk = (struct sock *)msk; + +pr_debug ("msk=%p\n" , msk); + +if (!msk) +return ; + +if (inet_sk_state_load (sk) ==TCP_CLOSE ) +return ; + +if (!entry->addr.id) +return ; + + if (mptcp_pm_should_add_signal_addr(msk)) { + sk_reset_timer(sk, timer, jiffies + TCP_RTO_MAX /8);
net/mptcp/pm.c +7
-0+ goto out; + } + +spin_lock_bh (&msk->pm.lock); + +if (!mptcp_pm_should_add_signal_addr (msk)) { + pr_debug("retransmit ADD_ADDR id=%d\n", entry-Quoted 1 line
addr.id);
net/mptcp/pm.c +8
-0+mptcp_pm_announce_addr (msk, &entry->addr, false); +mptcp_pm_add_addr_send_ack (msk); + entry->retrans_times++; + } + +if (entry->retrans_times <ADD_ADDR_RETRANS_MAX ) + sk_reset_timer(sk, timer, + jiffies +mptcp_get_add_addr_timeout(sock_net(sk)));
net/mptcp/pm.c +13
-0+ +spin_unlock_bh (&msk->pm.lock); + +if (entry->retrans_times ==ADD_ADDR_RETRANS_MAX ) +mptcp_pm_subflow_established (msk); + +out: +__sock_put (sk); +} + +struct mptcp_pm_add_entry * +mptcp_pm_del_add_timer (struct mptcp_sock *msk, + const struct mptcp_addr_info *addr, bool
check_id)net/mptcp/pm.c +16
-0+{ +struct mptcp_pm_add_entry *entry; +struct sock *sk = (struct sock *)msk; +struct timer_list *add_timer =NULL ; + +spin_lock_bh (&msk->pm.lock); + entry =mptcp_lookup_anno_list_by_saddr (msk, addr); +if (entry && (!check_id || entry->addr.id == addr->id)) { + entry->retrans_times =ADD_ADDR_RETRANS_MAX ; + add_timer = &entry->add_timer; + } +if (!check_id && entry) +list_del (&entry->list); +spin_unlock_bh (&msk->pm.lock); + +/* no lock, because sk_stop_timer_sync() is calling
del_timer_sync()*/net/mptcp/pm.c +23
-0+if (add_timer) +sk_stop_timer_sync (sk, add_timer); + +return entry; +} + +bool mptcp_pm_alloc_anno_list (struct mptcp_sock *msk, + const struct mptcp_addr_info *addr) +{ +struct mptcp_pm_add_entry *add_entry =NULL ; +struct sock *sk = (struct sock *)msk; +struct net *net =sock_net (sk); + +lockdep_assert_held (&msk->pm.lock); + + add_entry =mptcp_lookup_anno_list_by_saddr (msk, addr); + +if (add_entry) { +if (WARN_ON_ONCE (mptcp_pm_is_kernel (msk))) +return false; + + sk_reset_timer(sk, &add_entry->add_timer, + jiffies +
mptcp_get_add_addr_timeout(net));net/mptcp/pm.c +37
-0+return true; + } + + add_entry =kmalloc (sizeof (*add_entry),GFP_ATOMIC ); +if (!add_entry) +return false; + +list_add (&add_entry->list, &msk->pm.anno_list); + + add_entry->addr = *addr; + add_entry->sock = msk; + add_entry->retrans_times =0 ; + +timer_setup (&add_entry->add_timer, mptcp_pm_add_timer,0 ); +sk_reset_timer (sk, &add_entry->add_timer, + jiffies + mptcp_get_add_addr_timeout(net)); + +return true; +} + +static void mptcp_pm_free_anno_list (struct mptcp_sock *msk) +{ +struct mptcp_pm_add_entry *entry, *tmp; +struct sock *sk = (struct sock *)msk; +LIST_HEAD (free_list); + +pr_debug ("msk=%p\n" , msk); + +spin_lock_bh (&msk->pm.lock); +list_splice_init (&msk->pm.anno_list, &free_list); +spin_unlock_bh (&msk->pm.lock); + +list_for_each_entry_safe (entry, tmp, &free_list, list) { +sk_stop_timer_sync (sk, &entry->add_timer); +kfree (entry); + } +}
/* path manager command handlers */net/mptcp/pm.c +0
-0@@ -109,22 +496,6 @@ bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk) return ret; }
-/* return true if the new status bit is currently cleared, that is, this event
- * can be server, eventually by an already scheduled work
- */net/mptcp/pm.c +0
-13-static bool mptcp_pm_schedule_work (struct mptcp_sock *msk, - enum mptcp_pm_status new_status) -{ -pr_debug ("msk=%p status=%x new=%lx\n" , msk, msk->pm.status, -BIT (new_status)); -if (msk->pm.status &BIT (new_status)) -return false; - - msk->pm.status |=BIT (new_status); -mptcp_schedule_work ((struct sock *)msk); -return true; -} -void
mptcp_pm_fully_established(struct mptcp_sock *msk, const struct sock *ssk)
{
structmptcp_pm_data*pm =&msk->pm;net/mptcp/pm.c +0
-0@@ -209,6 +580,15 @@ void mptcp_pm_subflow_check_next(structmptcp_sock *msk, spin_unlock_bh(&pm->lock); }net/mptcp/pm.c +2
-0+static bool mptcp_pm_is_init_remote_addr(struct mptcp_sock *msk, + const struct
mptcp_addr_info*remote)net/mptcp/pm.c +4
-0+{ +struct mptcp_addr_info mpc_remote; + + mptcp_remote_address((struct sock_common *)msk,
&mpc_remote);net/mptcp/pm.c +1
-0+ return mptcp_addresses_equal(&mpc_remote, remote, remote-Quoted 1 line
port);
net/mptcp/pm.c +2
-0+} +void
mptcp_pm_add_addr_received(const struct sock *ssk, const struct mptcp_addr_info *addr){net/mptcp/pm.c +0
-0@@ -231,7 +611,7 @@ void mptcp_pm_add_addr_received(const struct sock *ssk,
__MPTCP_INC_STATS(sock_net((struct sock *)msk), MPTCP_MIB_ADDADDRDROP);
}
/* id0 should not have a different address */net/mptcp/pm.c +0
-1- } else if ((addr->id == 0 &&!mptcp_pm_nl_is_init_remote_addr(msk, addr)) ||
net/mptcp/pm.c +1
-0+ } else if ((addr->id == 0 &&!mptcp_pm_is_init_remote_addr(msk, addr)) ||
(addr->id> 0 && !READ_ONCE(pm->accept_addr))) {mptcp_pm_announce_addr(msk, addr, true);mptcp_pm_add_addr_send_ack(msk);net/mptcp/pm.c +0
-0@@ -262,12 +642,81 @@ void mptcp_pm_add_addr_echoed(struct mptcp_sock *msk, spin_unlock_bh(&pm->lock); }net/mptcp/pm.c +2
-1-void mptcp_pm_add_addr_send_ack (struct mptcp_sock *msk) +static void mptcp_pm_rm_addr_or_subflow (struct mptcp_sock *msk, + const struct mptcp_rm_list
*rm_list,net/mptcp/pm.c +1
-0+enum linux_mptcp_mib_field
rm_type)
{net/mptcp/pm.c +6
-1-if (!mptcp_pm_should_add_signal (msk)) +struct mptcp_subflow_context *subflow, *tmp; +struct sock *sk = (struct sock *)msk; +u8 i; + + pr_debug("%s rm_list_nr %d\n", + rm_type == MPTCP_MIB_RMADDR ? "address" :"subflow",
rm_list->nr);net/mptcp/pm.c +4
-0+ +msk_owned_by_me (msk); + +if (sk->sk_state ==TCP_LISTEN )return;
net/mptcp/pm.c +12
-1-mptcp_pm_schedule_work (msk,MPTCP_PM_ADD_ADDR_SEND_ACK ); +if (!rm_list->nr) +return ; + +if (list_empty (&msk->conn_list)) +return ; + +for (i =0 ; i < rm_list->nr; i++) { +u8 rm_id = rm_list->ids[i]; +bool removed = false; + +mptcp_for_each_subflow_safe (msk, subflow, tmp) { + struct sock *ssk =
mptcp_subflow_tcp_sock(subflow);net/mptcp/pm.c +1
-0+ u8 remote_id = READ_ONCE(subflow-Quoted 1 line
remote_id);net/mptcp/pm.c +5
-0+int how =RCV_SHUTDOWN |SEND_SHUTDOWN ; +u8 id =subflow_get_local_id (subflow); + + if ((1 << inet_sk_state_load(ssk)) & + (TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2 |
TCPF_CLOSING|TCPF_CLOSE))net/mptcp/pm.c +2
-0+continue ; + if (rm_type == MPTCP_MIB_RMADDR && remote_id!=
rm_id)net/mptcp/pm.c +2
-0+continue ; + if (rm_type == MPTCP_MIB_RMSUBFLOW && id !=
rm_id)net/mptcp/pm.c +3
-0+continue ; + + pr_debug(" -> %s rm_list_ids[%d]=%ulocal_id=%u remote_id=%u mpc_id=%u\n",
net/mptcp/pm.c +1
-0+ rm_type == MPTCP_MIB_RMADDR ?"address" : "subflow",
net/mptcp/pm.c +1
-0+ i, rm_id, id, remote_id, msk-Quoted 1 line
mpc_endpoint_id);net/mptcp/pm.c +5
-0+spin_unlock_bh (&msk->pm.lock); +mptcp_subflow_shutdown (sk, ssk, how); + removed |= subflow->request_join; + +/* the following takes care of updating the subflows counter */
net/mptcp/pm.c +5
-0+mptcp_close_ssk (sk, ssk, subflow); +spin_lock_bh (&msk->pm.lock); + +if (rm_type ==MPTCP_MIB_RMSUBFLOW ) + __MPTCP_INC_STATS(sock_net(sk),
rm_type);net/mptcp/pm.c +9
-0+ } + +if (rm_type ==MPTCP_MIB_RMADDR ) +__MPTCP_INC_STATS (sock_net (sk), rm_type); + +if (!removed) +continue ; + + if (mptcp_pm_is_kernel(msk) && rm_type ==
MPTCP_MIB_RMADDR)net/mptcp/pm.c +7
-0+mptcp_pm_nl_rm_addr (msk, rm_id); + } +} + +static void mptcp_pm_rm_addr_recv (struct mptcp_sock *msk) +{ + mptcp_pm_rm_addr_or_subflow(msk, &msk->pm.rm_list_rx,
MPTCP_MIB_RMADDR);
net/mptcp/pm.c void mptcp_pm_add_addr_echoed(struct mptcp_sock *msk, · line 717
Quoted 4 lines
net/mptcp/pm.c +4
-0+} + +void mptcp_pm_rm_subflow (struct mptcp_sock *msk, +const struct mptcp_rm_list *rm_list)
Is this mptcp_pm_rm_subflow() renamed from mptcp_pm_nl_rm_subflow_received()? It's better to rename it in a separate patch.
Quoted 798 lines
net/mptcp/pm.c +2
-0+{ + mptcp_pm_rm_addr_or_subflow(msk, rm_list,
MPTCP_MIB_RMSUBFLOW);
}
void mptcp_pm_rm_addr_received(structmptcp_sock*msk,net/mptcp/pm.c +0
-0@@ -325,8 +774,6 @@ void mptcp_pm_mp_fail_received(struct sock *sk, u64 fail_seq) } }net/mptcp/pm.c +0
-2-/* path manager helpers */ -bool mptcp_pm_add_addr_signal(struct
mptcp_sock*msk, const structsk_buff*skb,
unsigned intopt_size, unsigned int remaining,
structmptcp_addr_info*addr, bool *echo,net/mptcp/pm.c +0
-0@@ -440,119 +887,41 @@ bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc) return mptcp_pm_nl_is_backup(msk, &skc_local); }
-static int mptcp_pm_get_addr(u8 id, structmptcp_pm_addr_entry*addr,net/mptcp/pm.c +1
-1- struct genl_info *info) +static void mptcp_pm_subflows_chk_stale(const struct mptcp_sock*msk, struct sock *ssk)
{net/mptcp/pm.c +1
-4-if (info->attrs[MPTCP_PM_ATTR_TOKEN ]) -return mptcp_userspace_pm_get_addr (id, addr, info); -return mptcp_pm_nl_get_addr (id, addr, info); -} + struct mptcp_subflow_context *iter, *subflow =
mptcp_subflow_ctx(ssk);net/mptcp/pm.c +5
-0+struct sock *sk = (struct sock *)msk; +unsigned int active_max_loss_cnt; +struct net *net =sock_net (sk); +unsigned int stale_loss_cnt; +bool slow;
-intmptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)net/mptcp/pm.c +2
-6-{ -struct mptcp_pm_addr_entry addr; -struct nlattr *attr; -struct sk_buff *msg; -void *reply; -int ret; + stale_loss_cnt =mptcp_stale_loss_cnt (net); + if (subflow->stale || !stale_loss_cnt || subflow-Quoted 1 line
stale_count<=stale_loss_cnt)net/mptcp/pm.c +1
-0+return ;net/mptcp/pm.c +6
-2-if (GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ENDPOINT_ADDR )) -return -EINVAL ; +/* look for another available subflow not in loss state */ + active_max_loss_cnt =max_t (int, stale_loss_cnt -1 ,1 ); +mptcp_for_each_subflow (msk, iter) { +if (iter != subflow &&mptcp_subflow_active (iter) && + iter->stale_count < active_max_loss_cnt) { +/* we have some alternatives, try to mark this subflow as idle ...*/
net/mptcp/pm.c +5
-0+ slow =lock_sock_fast (ssk); +if (!tcp_rtx_and_write_queues_empty (ssk)) { + subflow->stale =1 ; +__mptcp_retransmit_pending_data (sk); + MPTCP_INC_STATS(net,
MPTCP_MIB_SUBFLOWSTALE);net/mptcp/pm.c +2
-0+ } +unlock_sock_fast (ssk, slow);net/mptcp/pm.c +0
-13- attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR ]; - ret =mptcp_pm_parse_entry (attr, info, false, &addr); -if (ret <0 ) -return ret; - - msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); -if (!msg) -return -ENOMEM ; - - reply =genlmsg_put_reply (msg, info, &mptcp_genl_family,0 , - info->genlhdr->cmd); -if (!reply) { - GENL_SET_ERR_MSG(info, "not enough space in Netlinkmessage");
net/mptcp/pm.c +1
-2- ret = -EMSGSIZE ; - goto fail; +/* always try to push the pending data regardless of re-injections:
net/mptcp/pm.c +1
-0+* we can possibly use backup subflows now, and subflow selection
net/mptcp/pm.c +5
-0+* is cheap under the msk socket lock +*/ +__mptcp_push_pending (sk,0 ); +return ; + }}
net/mptcp/pm.c +0
-4- - ret =mptcp_pm_get_addr (addr.addr.id, &addr, info); -if (ret) { - NL_SET_ERR_MSG_ATTR(info->extack, attr, "address notfound");
net/mptcp/pm.c +0
-38- goto fail; - } - - ret =mptcp_nl_fill_addr (msg, &addr); -if (ret) - goto fail; - -genlmsg_end (msg, reply); - ret =genlmsg_reply (msg, info); -return ret; - -fail: -nlmsg_free (msg); -return ret; -} - -int mptcp_pm_genl_fill_addr (struct sk_buff *msg, - struct netlink_callback *cb, - struct mptcp_pm_addr_entry *entry) -{ -void *hdr; - - hdr =genlmsg_put (msg,NETLINK_CB (cb->skb).portid, - cb->nlh->nlmsg_seq, &mptcp_genl_family, - NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); -if (!hdr) -return -EINVAL ; - -if (mptcp_nl_fill_addr (msg, entry) <0 ) { -genlmsg_cancel (msg, hdr); -return -EINVAL ; - } - -genlmsg_end (msg, hdr); -return 0 ; -} - -static int mptcp_pm_dump_addr(struct sk_buff *msg, struct
netlink_callback*cb)net/mptcp/pm.c +0
-17-{ -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) -{ -return mptcp_pm_dump_addr (msg, cb); -} - -static int mptcp_pm_set_flags(struct genl_info *info) -{ - struct mptcp_pm_addr_entry loc = { .addr = { .family =
AF_UNSPEC}, };net/mptcp/pm.c +0
-17-struct nlattr *attr_loc; -int ret = -EINVAL ; - -if (GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ATTR_ADDR )) -return ret; - - attr_loc = info->attrs[MPTCP_PM_ATTR_ADDR ]; - ret =mptcp_pm_parse_entry (attr_loc, info, false, &loc); -if (ret <0 ) -return ret; - -if (info->attrs[MPTCP_PM_ATTR_TOKEN ]) -return mptcp_userspace_pm_set_flags (&loc, info); -return mptcp_pm_nl_set_flags (&loc, info); -} - -int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info*info)
net/mptcp/pm.c +0
-2-{ -return mptcp_pm_set_flags (info);}
voidmptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)net/mptcp/pm.c +1
-1@@ -567,38 +936,13 @@ void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) } else if (subflow->stale_rcv_tstamp == rcv_tstamp) { if (subflow->stale_count < U8_MAX) subflow->stale_count++; -mptcp_pm_nl_subflow_chk_stale (msk, ssk); +mptcp_pm_subflows_chk_stale (msk, ssk); } else { subflow->stale_count = 0; mptcp_subflow_set_active(subflow); } }
-/* if sk is ipv4 oripv6_onlyallows only same-family local and remote addresses,
- * otherwise allow any matching local/remote pair
- */net/mptcp/pm.c +0
-8-bool mptcp_pm_addr_families_match (const struct sock *sk, - const struct mptcp_addr_info *loc, - const struct mptcp_addr_info *rem) -{ -bool mptcp_is_v4 = sk->sk_family ==AF_INET ; - -#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) - bool loc_is_v4 = loc->family == AF_INET ||
ipv6_addr_v4mapped(&loc->addr6);net/mptcp/pm.c +0
-1- bool rem_is_v4 = rem->family == AF_INET ||
ipv6_addr_v4mapped(&rem->addr6);net/mptcp/pm.c +0
-10- -if (mptcp_is_v4) -return loc_is_v4 && rem_is_v4; - -if (ipv6_only_sock (sk)) -return !loc_is_v4 && !rem_is_v4; - -return loc_is_v4 == rem_is_v4; -#else -return mptcp_is_v4 && loc->family ==AF_INET && rem->family==
AF_INET;net/mptcp/pm.c +0
-3-#endif -} -void
mptcp_pm_worker(struct mptcp_sock *msk)
{
structmptcp_pm_data*pm =&msk->pm;net/mptcp/pm_kernel.c new file +0
-0index 0000000000000000000000000000000000000000..daf8f98a316439a67c12f63f238
8ef497dae08ddnet/mptcp/pm_kernel.c new file +49
-0@@ -0,0 +1,1410 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Multipath TCP +* +* Copyright (c) 2025, Matthieu Baerts. +*/ + +#define pr_fmt (fmt) "MPTCP: " fmt + +#include <net/netns/generic.h> + +#include "protocol.h" +#include "mib.h" +#include "mptcp_pm_gen.h" + +static int pm_nl_pernet_id; + +struct pm_nl_pernet { +/* protects pernet updates */ +spinlock_t lock; +struct list_head local_addr_list; +unsigned int addrs; +unsigned int stale_loss_cnt; +unsigned int add_addr_signal_max; +unsigned int add_addr_accept_max; +unsigned int local_addr_max; +unsigned int subflows_max; +unsigned int next_id; + DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); +}; + +#define MPTCP_PM_ADDR_MAX 8 + +static struct pm_nl_pernet *pm_nl_get_pernet (const struct net *net) +{ +return net_generic (net, pm_nl_pernet_id); +} + +static struct pm_nl_pernet * +pm_nl_get_pernet_from_msk (const struct mptcp_sock *msk) +{ +return pm_nl_get_pernet (sock_net ((struct sock *)msk)); +} + +static struct pm_nl_pernet *genl_info_pm_nl (struct genl_info *info) +{ +return pm_nl_get_pernet (genl_info_net (info)); +} + +unsigned int mptcp_pm_get_add_addr_signal_max(const struct
mptcp_sock*msk)net/mptcp/pm_kernel.c new file +2
-0+{ + const struct pm_nl_pernet *pernet =
pm_nl_get_pernet_from_msk(msk);net/mptcp/pm_kernel.c new file +6
-0+ +return READ_ONCE (pernet->add_addr_signal_max); +} +EXPORT_SYMBOL_GPL (mptcp_pm_get_add_addr_signal_max); + +unsigned int mptcp_pm_get_add_addr_accept_max(const struct
mptcp_sock*msk)net/mptcp/pm_kernel.c new file +2
-0+{ + struct pm_nl_pernet *pernet =
pm_nl_get_pernet_from_msk(msk);net/mptcp/pm_kernel.c new file +8
-0+ +return READ_ONCE (pernet->add_addr_accept_max); +} +EXPORT_SYMBOL_GPL (mptcp_pm_get_add_addr_accept_max); + +unsigned int mptcp_pm_get_subflows_max (const struct mptcp_sock *msk) +{ + struct pm_nl_pernet *pernet =
pm_nl_get_pernet_from_msk(msk);net/mptcp/pm_kernel.c new file +6
-0+ +return READ_ONCE (pernet->subflows_max); +} +EXPORT_SYMBOL_GPL (mptcp_pm_get_subflows_max); + +unsigned int mptcp_pm_get_local_addr_max(const struct mptcp_sock*msk)
net/mptcp/pm_kernel.c new file +2
-0+{ + struct pm_nl_pernet *pernet =
pm_nl_get_pernet_from_msk(msk);net/mptcp/pm_kernel.c new file +7
-0+ +return READ_ONCE (pernet->local_addr_max); +} +EXPORT_SYMBOL_GPL (mptcp_pm_get_local_addr_max); + +static bool lookup_subflow_by_daddr (const struct list_head *list, + const struct mptcp_addr_info*daddr)
net/mptcp/pm_kernel.c new file +9
-0+{ +struct mptcp_subflow_context *subflow; +struct mptcp_addr_info cur; + +list_for_each_entry (subflow, list, node) { +struct sock *ssk =mptcp_subflow_tcp_sock (subflow); + + if (!((1 << inet_sk_state_load(ssk)) & + (TCPF_ESTABLISHED | TCPF_SYN_SENT |
TCPF_SYN_RECV)))net/mptcp/pm_kernel.c new file +3
-0+continue ; + + mptcp_remote_address((struct sock_common *)ssk,&cur);
net/mptcp/pm_kernel.c new file +19
-0+if (mptcp_addresses_equal (&cur, daddr, daddr->port)) +return true; + } + +return false; +} + +static bool +select_local_address (const struct pm_nl_pernet *pernet, + const struct mptcp_sock *msk, + struct mptcp_pm_local *new_local) +{ +struct mptcp_pm_addr_entry *entry; +bool found = false; + +msk_owned_by_me (msk); + +rcu_read_lock (); + list_for_each_entry_rcu(entry, &pernet->local_addr_list,list) {
net/mptcp/pm_kernel.c new file +4
-0+if (!(entry->flags &MPTCP_PM_ADDR_FLAG_SUBFLOW )) +continue ; + + if (!test_bit(entry->addr.id, msk-Quoted 1 line
pm.id_avail_bitmap))
net/mptcp/pm_kernel.c new file +15
-0+continue ; + + new_local->addr = entry->addr; + new_local->flags = entry->flags; + new_local->ifindex = entry->ifindex; + found = true; +break ; + } +rcu_read_unlock (); + +return found; +} + +static bool +select_signal_address(struct pm_nl_pernet *pernet, const struct
mptcp_sock*msk,net/mptcp/pm_kernel.c new file +9
-0+ struct mptcp_pm_local *new_local) +{ +struct mptcp_pm_addr_entry *entry; +bool found = false; + +rcu_read_lock (); +/* do not keep any additional per socket state, just signal +* the address list in order. +* Note: removal from the local address list during the msk life-cycle
net/mptcp/pm_kernel.c new file +3
-0+* can lead to additional addresses not being announced. +*/ + list_for_each_entry_rcu(entry, &pernet->local_addr_list,list) {
net/mptcp/pm_kernel.c new file +1
-0+ if (!test_bit(entry->addr.id, msk-Quoted 1 line
pm.id_avail_bitmap))
net/mptcp/pm_kernel.c new file +20
-0+continue ; + +if (!(entry->flags &MPTCP_PM_ADDR_FLAG_SIGNAL )) +continue ; + + new_local->addr = entry->addr; + new_local->flags = entry->flags; + new_local->ifindex = entry->ifindex; + found = true; +break ; + } +rcu_read_unlock (); + +return found; +} + +/* 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,
net/mptcp/pm_kernel.c new file +1
-0+ struct mptcp_addr_info*local,
net/mptcp/pm_kernel.c new file +2
-0+ bool fullmesh, + struct mptcp_addr_info*addrs)
net/mptcp/pm_kernel.c new file +19
-0+{ + 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 }; + unsigned int subflows_max; + 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) + return 0; + + if (!mptcp_pm_addr_families_match(sk, local,&remote))
net/mptcp/pm_kernel.c new file +6
-0+return 0 ; + + msk->pm.subflows++; + addrs[i++] = remote; + }else { + DECLARE_BITMAP(unavail_id, MPTCP_PM_MAX_ADDR_ID +1);
net/mptcp/pm_kernel.c new file +3
-0+ +/* Forbid creation of new subflows matching existing +* ones, possibly already created by incoming
ADD_ADDRnet/mptcp/pm_kernel.c new file +4
-0+*/ +bitmap_zero (unavail_id,MPTCP_PM_MAX_ADDR_ID +1 ); +mptcp_for_each_subflow (msk, subflow) + if (READ_ONCE(subflow->local_id) == local-Quoted 1 line
id)
net/mptcp/pm_kernel.c new file +1
-0+ __set_bit(subflow->remote_id,
unavail_id);net/mptcp/pm_kernel.c new file +4
-0+ +mptcp_for_each_subflow (msk, subflow) { + ssk =mptcp_subflow_tcp_sock (subflow); + mptcp_remote_address((struct sock_common*)ssk, &addrs[i]);
net/mptcp/pm_kernel.c new file +8
-0+ addrs[i].id =READ_ONCE (subflow->remote_id); +if (deny_id0 && !addrs[i].id) +continue ; + +if (test_bit (addrs[i].id, unavail_id)) +continue ; + + if (!mptcp_pm_addr_families_match(sk, local,&addrs[i]))
net/mptcp/pm_kernel.c new file +4
-0+continue ; + +if (msk->pm.subflows < subflows_max) { +/* forbid creating multiple address towards
net/mptcp/pm_kernel.c new file +18
-0+* this id +*/ +__set_bit (addrs[i].id, unavail_id); + msk->pm.subflows++; + i++; + } + } + } + +return i; +} + +static struct mptcp_pm_addr_entry * +__lookup_addr_by_id (struct pm_nl_pernet *pernet,unsigned int id) +{ +struct mptcp_pm_addr_entry *entry; + + list_for_each_entry_rcu(entry, &pernet->local_addr_list,list,
net/mptcp/pm_kernel.c new file +9
-0+ lockdep_is_held(&pernet->lock)) { +if (entry->addr.id == id) +return entry; + } +return NULL ; +} + +static struct mptcp_pm_addr_entry * +__lookup_addr(struct pm_nl_pernet *pernet, const struct
mptcp_addr_info*info)net/mptcp/pm_kernel.c new file +4
-0+{ +struct mptcp_pm_addr_entry *entry; + + list_for_each_entry_rcu(entry, &pernet->local_addr_list,list,
net/mptcp/pm_kernel.c new file +2
-0+ lockdep_is_held(&pernet->lock)) { + if (mptcp_addresses_equal(&entry->addr, info, entry-Quoted 1 line
addr.port))
net/mptcp/pm_kernel.c new file +6
-0+return entry; + } +return NULL ; +} + +static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock*msk)
net/mptcp/pm_kernel.c new file +17
-0+{ +struct sock *sk = (struct sock *)msk; +unsigned int add_addr_signal_max; +bool signal_and_subflow = false; +unsigned int local_addr_max; +struct pm_nl_pernet *pernet; +struct mptcp_pm_local local; +unsigned int subflows_max; + + pernet =pm_nl_get_pernet (sock_net (sk)); + + add_addr_signal_max =mptcp_pm_get_add_addr_signal_max (msk); + local_addr_max =mptcp_pm_get_local_addr_max (msk); + subflows_max =mptcp_pm_get_subflows_max (msk); + +/* do lazy endpoint usage accounting for the MPC subflows */ + if (unlikely(!(msk->pm.status &
BIT(MPTCP_PM_MPC_ENDPOINT_ACCOUNTED))) &&msk->first) {net/mptcp/pm_kernel.c new file +1
-0+ struct mptcp_subflow_context *subflow =
mptcp_subflow_ctx(msk->first);net/mptcp/pm_kernel.c new file +5
-0+struct mptcp_pm_addr_entry *entry; +struct mptcp_addr_info mpc_addr; +bool backup = false; + + mptcp_local_address((struct sock_common *)msk-Quoted 1 line
first,
&mpc_addr);net/mptcp/pm_kernel.c new file +4
-0+rcu_read_lock (); + entry =__lookup_addr (pernet, &mpc_addr); +if (entry) { + __clear_bit(entry->addr.id, msk-Quoted 1 line
pm.id_avail_bitmap);
net/mptcp/pm_kernel.c new file +2
-0+ msk->mpc_endpoint_id = entry->addr.id; + backup = !!(entry->flags &
MPTCP_PM_ADDR_FLAG_BACKUP);net/mptcp/pm_kernel.c new file +5
-0+ } +rcu_read_unlock (); + +if (backup) + mptcp_pm_send_ack(msk, subflow, true,backup);
net/mptcp/pm_kernel.c new file +2
-0+ + msk->pm.status |=
BIT(MPTCP_PM_MPC_ENDPOINT_ACCOUNTED);net/mptcp/pm_kernel.c new file +10
-0+ } + +pr_debug ("local %d:%d signal %d:%d subflows %d:%d\n" , + msk->pm.local_addr_used, local_addr_max, + msk->pm.add_addr_signaled, add_addr_signal_max, + msk->pm.subflows, subflows_max); + +/* check first for announce */ +if (msk->pm.add_addr_signaled < add_addr_signal_max) { +/* due to racing events on both ends we can reach here while
net/mptcp/pm_kernel.c new file +1
-0+* previous add address is still running: if we invoke now
net/mptcp/pm_kernel.c new file +3
-0+* mptcp_pm_announce_addr(), that will fail and the +* corresponding id will be marked as used. +* Instead let the PM machinery reschedule us when the
net/mptcp/pm_kernel.c new file +3
-0+* current address announce will be completed. +*/ + if (msk->pm.addr_signal &
BIT(MPTCP_ADD_ADDR_SIGNAL))net/mptcp/pm_kernel.c new file +6
-0+return ; + +if (!select_signal_address (pernet, msk, &local)) + goto subflow; + +/* If the alloc fails, we are on memory pressure, not worth
net/mptcp/pm_kernel.c new file +33
-0+* continuing, and trying to create subflows. +*/ +if (!mptcp_pm_alloc_anno_list (msk, &local.addr)) +return ; + +__clear_bit (local.addr.id, msk->pm.id_avail_bitmap); + msk->pm.add_addr_signaled++; + +/* Special case for ID0: set the correct ID */ +if (local.addr.id == msk->mpc_endpoint_id) + local.addr.id =0 ; + +mptcp_pm_announce_addr (msk, &local.addr, false); +mptcp_pm_addr_send_ack (msk); + +if (local.flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ) + signal_and_subflow = true; + } + +subflow: +/* check if should create a new subflow */ +while (msk->pm.local_addr_used < local_addr_max && + msk->pm.subflows < subflows_max) { +struct mptcp_addr_info addrs[MPTCP_PM_ADDR_MAX ]; +bool fullmesh; +int i, nr; + +if (signal_and_subflow) + signal_and_subflow = false; +else if (!select_local_address (pernet, msk, &local)) +break ; + + fullmesh = !!(local.flags &
MPTCP_PM_ADDR_FLAG_FULLMESH);net/mptcp/pm_kernel.c new file +10
-0+ +__clear_bit (local.addr.id, msk->pm.id_avail_bitmap); + +/* Special case for ID0: set the correct ID */ +if (local.addr.id == msk->mpc_endpoint_id) + local.addr.id =0 ; +else /* local_addr_used is not decr for ID 0 */ + msk->pm.local_addr_used++; + + nr = fill_remote_addresses_vec(msk, &local.addr,fullmesh, addrs);
net/mptcp/pm_kernel.c new file +6
-0+if (nr ==0 ) +continue ; + +spin_unlock_bh (&msk->pm.lock); +for (i =0 ; i < nr; i++) + __mptcp_subflow_connect(sk, &local,&addrs[i]);
net/mptcp/pm_kernel.c new file +20
-0+spin_lock_bh (&msk->pm.lock); + } +mptcp_pm_nl_check_work_pending (msk); +} + +static void mptcp_pm_nl_fully_established (struct mptcp_sock *msk) +{ +mptcp_pm_create_subflow_or_signal_addr (msk); +} + +static void mptcp_pm_nl_subflow_established (struct mptcp_sock *msk) +{ +mptcp_pm_create_subflow_or_signal_addr (msk); +} + +/* Fill all the local addresses into the array addrs[], +* and return the array size. +*/ +static unsigned int fill_local_addresses_vec (struct mptcp_sock *msk, + struct mptcp_addr_info*remote,
net/mptcp/pm_kernel.c new file +1
-0+ struct mptcp_pm_local*locals)
net/mptcp/pm_kernel.c new file +15
-0+{ +struct sock *sk = (struct sock *)msk; +struct mptcp_pm_addr_entry *entry; +struct mptcp_addr_info mpc_addr; +struct pm_nl_pernet *pernet; +unsigned int subflows_max; +int i =0 ; + + pernet =pm_nl_get_pernet_from_msk (msk); + subflows_max =mptcp_pm_get_subflows_max (msk); + +mptcp_local_address ((struct sock_common *)msk, &mpc_addr); + +rcu_read_lock (); + list_for_each_entry_rcu(entry, &pernet->local_addr_list,list) {
net/mptcp/pm_kernel.c new file +4
-0+if (!(entry->flags &MPTCP_PM_ADDR_FLAG_FULLMESH )) +continue ; + + if (!mptcp_pm_addr_families_match(sk, &entry->addr,remote))
net/mptcp/pm_kernel.c new file +8
-0+continue ; + +if (msk->pm.subflows < subflows_max) { + locals[i].addr = entry->addr; + locals[i].flags = entry->flags; + locals[i].ifindex = entry->ifindex; + +/* Special case for ID0: set the correct ID */
net/mptcp/pm_kernel.c new file +1
-0+ if (mptcp_addresses_equal(&locals[i].addr,
&mpc_addr, locals[i].addr.port))net/mptcp/pm_kernel.c new file +17
-0+ locals[i].addr.id =0 ; + + msk->pm.subflows++; + i++; + } + } +rcu_read_unlock (); + +/* If the array is empty, fill in the single +* 'IPADDRANY' local address +*/ +if (!i) { +memset (&locals[i],0 ,sizeof (locals[i])); + locals[i].addr.family = +#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) + remote->family == AF_INET6 && + ipv6_addr_v4mapped(&remote->addr6) ?
AF_INET:net/mptcp/pm_kernel.c new file +4
-0+#endif + remote->family; + + if (!mptcp_pm_addr_families_match(sk,&locals[i].addr, remote))
net/mptcp/pm_kernel.c new file +47
-0+return 0 ; + + msk->pm.subflows++; + i++; + } + +return i; +} + +static void mptcp_pm_nl_add_addr_received (struct mptcp_sock *msk) +{ +struct mptcp_pm_local locals[MPTCP_PM_ADDR_MAX ]; +struct sock *sk = (struct sock *)msk; +unsigned int add_addr_accept_max; +struct mptcp_addr_info remote; +unsigned int subflows_max; +bool sf_created = false; +int i, nr; + + add_addr_accept_max =mptcp_pm_get_add_addr_accept_max (msk); + subflows_max =mptcp_pm_get_subflows_max (msk); + +pr_debug ("accepted %d:%d remote family %d\n" , + msk->pm.add_addr_accepted, add_addr_accept_max, + msk->pm.remote.family); + + remote = msk->pm.remote; +mptcp_pm_announce_addr (msk, &remote, true); +mptcp_pm_addr_send_ack (msk); + +if (lookup_subflow_by_daddr (&msk->conn_list, &remote)) +return ; + +/* pick id 0 port, if none is provided the remote address */ +if (!remote.port) + remote.port = sk->sk_dport; + +/* connect to the specified remote address, using whatever +* local address the routing configuration will pick. +*/ + nr =fill_local_addresses_vec (msk, &remote, locals); +if (nr ==0 ) +return ; + +spin_unlock_bh (&msk->pm.lock); +for (i =0 ; i < nr; i++) + if (__mptcp_subflow_connect(sk, &locals[i], &remote)== 0)
net/mptcp/pm_kernel.c new file +8
-0+ sf_created = true; +spin_lock_bh (&msk->pm.lock); + +if (sf_created) { +/* add_addr_accepted is not decr for ID 0 */ +if (remote.id) + msk->pm.add_addr_accepted++; + if (msk->pm.add_addr_accepted >= add_addr_accept_max||
net/mptcp/pm_kernel.c new file +10
-0+ msk->pm.subflows >= subflows_max) +WRITE_ONCE (msk->pm.accept_addr, false); + } +} + +void mptcp_pm_nl_rm_addr (struct mptcp_sock *msk,u8 rm_id) +{ +if (rm_id &&WARN_ON_ONCE (msk->pm.add_addr_accepted ==0 )) { +/* Note: if the subflow has been closed before, this +* add_addr_accepted counter will not be decremented.
net/mptcp/pm_kernel.c new file +2
-0+*/ + if (--msk->pm.add_addr_accepted <
mptcp_pm_get_add_addr_accept_max(msk))
net/mptcp/pm_kernel.c line 504
Quoted 3 lines
net/mptcp/pm_kernel.c new file +3
-0+WRITE_ONCE (msk->pm.accept_addr, true); + } +}
This mptcp_pm_nl_rm_addr() is a new helper, it's better to add it in a separate patch.
net/mptcp/protocol.h
Quoted 3,311 lines
net/mptcp/pm_kernel.c new file +5
-0+ +static bool address_use_port (struct mptcp_pm_addr_entry *entry) +{ + return (entry->flags & + (MPTCP_PM_ADDR_FLAG_SIGNAL |
MPTCP_PM_ADDR_FLAG_SUBFLOW)) ==net/mptcp/pm_kernel.c new file +5
-0+MPTCP_PM_ADDR_FLAG_SIGNAL ; +} + +/* caller must ensure the RCU grace period is already elapsed */ +static void __mptcp_pm_release_addr_entry(struct mptcp_pm_addr_entry*entry)
net/mptcp/pm_kernel.c new file +7
-0+{ +if (entry->lsk) +sock_release (entry->lsk); +kfree (entry); +} + +static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet*pernet,
net/mptcp/pm_kernel.c new file +1
-0+ struct
mptcp_pm_addr_entry*entry,net/mptcp/pm_kernel.c new file +1
-0+ bool needs_id, boolreplace)
net/mptcp/pm_kernel.c new file +7
-0+{ +struct mptcp_pm_addr_entry *cur, *del_entry =NULL ; +unsigned int addr_max; +int ret = -EINVAL ; + +spin_lock_bh (&pernet->lock); +/* to keep the code simple, don't do IDR-like allocation for address ID,
net/mptcp/pm_kernel.c new file +14
-0+* just bail when we exceed limits +*/ +if (pernet->next_id ==MPTCP_PM_MAX_ADDR_ID ) + pernet->next_id =1 ; +if (pernet->addrs >=MPTCP_PM_ADDR_MAX ) { + ret = -ERANGE ; + goto out; + } +if (test_bit (entry->addr.id, pernet->id_bitmap)) { + ret = -EBUSY ; + goto out; + } + +/* do not insert duplicate address, differentiate on port only
net/mptcp/pm_kernel.c new file +7
-0+* singled addresses +*/ +if (!address_use_port (entry)) + entry->addr.port =0 ; + list_for_each_entry(cur, &pernet->local_addr_list, list) { + if (mptcp_addresses_equal(&cur->addr, &entry->addr, + cur->addr.port || entry-Quoted 1 line
addr.port)) {
net/mptcp/pm_kernel.c new file +1
-0+/* allow replacing the exiting endpoint only if such
net/mptcp/pm_kernel.c new file +1
-0+* endpoint is an implicit one and the user- space
net/mptcp/pm_kernel.c new file +3
-0+* did not provide an endpoint id +*/ + if (!(cur->flags &
MPTCP_PM_ADDR_FLAG_IMPLICIT)) {net/mptcp/pm_kernel.c new file +7
-0+ ret = -EEXIST ; + goto out; + } +if (entry->addr.id) + goto out; + +/* allow callers that only need to look up the local
net/mptcp/pm_kernel.c new file +1
-0+* addr's id to skip replacement. This allows them to
net/mptcp/pm_kernel.c new file +1
-0+* avoid calling synchronize_rcu in the packet recv
net/mptcp/pm_kernel.c new file +19
-0+* path. +*/ +if (!replace) { +kfree (entry); + ret = cur->addr.id; + goto out; + } + + pernet->addrs--; + entry->addr.id = cur->addr.id; +list_del_rcu (&cur->list); + del_entry = cur; +break ; + } + } + +if (!entry->addr.id && needs_id) { +find_next: + entry->addr.id = find_next_zero_bit(pernet-Quoted 1 line
id_bitmap,net/mptcp/pm_kernel.c new file +1
-0+
MPTCP_PM_MAX_ADDR_ID+ 1,net/mptcp/pm_kernel.c new file +1
-0+ pernet-Quoted 1 line
next_id);net/mptcp/pm_kernel.c new file +16
-0+if (!entry->addr.id && pernet->next_id !=1 ) { + pernet->next_id =1 ; + goto find_next; + } + } + +if (!entry->addr.id && needs_id) + goto out; + +__set_bit (entry->addr.id, pernet->id_bitmap); +if (entry->addr.id > pernet->next_id) + pernet->next_id = entry->addr.id; + +if (entry->flags &MPTCP_PM_ADDR_FLAG_SIGNAL ) { + addr_max = pernet->add_addr_signal_max; + WRITE_ONCE(pernet->add_addr_signal_max, addr_max +1);
net/mptcp/pm_kernel.c new file +9
-0+ } +if (entry->flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ) { + addr_max = pernet->local_addr_max; +WRITE_ONCE (pernet->local_addr_max, addr_max +1 ); + } + + pernet->addrs++; +if (!entry->addr.port) + list_add_tail_rcu(&entry->list, &pernet-Quoted 1 line
local_addr_list);net/mptcp/pm_kernel.c new file +2
-0+else + list_add_rcu(&entry->list, &pernet-Quoted 1 line
local_addr_list);net/mptcp/pm_kernel.c new file +18
-0+ ret = entry->addr.id; + +out: +spin_unlock_bh (&pernet->lock); + +/* just replaced an existing entry, free it */ +if (del_entry) { +synchronize_rcu (); +__mptcp_pm_release_addr_entry (del_entry); + } +return ret; +} + +static struct lock_class_key mptcp_slock_keys[2 ]; +static struct lock_class_key mptcp_keys[2 ]; + +static int mptcp_pm_nl_create_listen_socket(struct sock *sk, + struct
mptcp_pm_addr_entry*entry)net/mptcp/pm_kernel.c new file +10
-0+{ +bool is_ipv6 = sk->sk_family ==AF_INET6 ; +int addrlen =sizeof (struct sockaddr_in ); +struct sockaddr_storage addr; +struct sock *newsk, *ssk; +int backlog =1024 ; +int err; + + err = sock_create_kern(sock_net(sk), entry->addr.family, + SOCK_STREAM, IPPROTO_MPTCP, &entry-Quoted 1 line
lsk);
net/mptcp/pm_kernel.c new file +8
-0+if (err) +return err; + + newsk = entry->lsk->sk; +if (!newsk) +return -EINVAL ; + +/* The subflow socket lock is acquired in a nested to the msk one
net/mptcp/pm_kernel.c new file +1
-0+* in several places, even by the TCP stack, and this msk is a kernel
net/mptcp/pm_kernel.c new file +1
-0+* socket: lockdep complains. Instead of propagating the
_nestednet/mptcp/pm_kernel.c new file +1
-0+* modifiers in several places, re-init the lock class for the msk
net/mptcp/pm_kernel.c new file +4
-0+* socket to an mptcp specific one. +*/ + sock_lock_init_class_and_name(newsk, + is_ipv6 ? "mlock-AF_INET6" :"mlock-AF_INET",
net/mptcp/pm_kernel.c new file +2
-0+ &mptcp_slock_keys[is_ipv6], + is_ipv6 ? "msk_lock-AF_INET6": "msk_lock-AF_INET",
net/mptcp/pm_kernel.c new file +9
-0+ &mptcp_keys[is_ipv6]); + +lock_sock (newsk); + ssk =__mptcp_nmpc_sk (mptcp_sk (newsk)); +release_sock (newsk); +if (IS_ERR (ssk)) +return PTR_ERR (ssk); + + mptcp_info2sockaddr(&entry->addr, &addr, entry-Quoted 1 line
addr.family);
net/mptcp/pm_kernel.c new file +6
-0+#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) +if (entry->addr.family ==AF_INET6 ) + addrlen =sizeof (struct sockaddr_in6 ); +#endif +if (ssk->sk_family ==AF_INET ) + err = inet_bind_sk(ssk, (struct sockaddr *)&addr,addrlen);
net/mptcp/pm_kernel.c new file +3
-0+#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) + else if (ssk->sk_family == AF_INET6) + err = inet6_bind_sk(ssk, (struct sockaddr *)&addr,addrlen);
net/mptcp/pm_kernel.c new file +5
-0+#endif +if (err) +return err; + +/* We don't use mptcp_set_state() here because it needs to be called
net/mptcp/pm_kernel.c new file +1
-0+* under the msk socket lock. For the moment, that will not bring
net/mptcp/pm_kernel.c new file +1
-0+* anything more than only calling inet_sk_state_store(), because the
net/mptcp/pm_kernel.c new file +8
-0+* old status is known (TCP_CLOSE). +*/ +inet_sk_state_store (newsk,TCP_LISTEN ); +lock_sock (ssk); +WRITE_ONCE (mptcp_subflow_ctx (ssk)->pm_listener, true); + err =__inet_listen_sk (ssk, backlog); +if (!err) + mptcp_event_pm_listener(ssk,
MPTCP_EVENT_LISTENER_CREATED);net/mptcp/pm_kernel.c new file +28
-0+release_sock (ssk); +return err; +} + +int mptcp_pm_nl_get_local_id (struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *skc) +{ +struct mptcp_pm_addr_entry *entry; +struct pm_nl_pernet *pernet; +int ret; + + pernet =pm_nl_get_pernet_from_msk (msk); + +rcu_read_lock (); + entry =__lookup_addr (pernet, &skc->addr); + ret = entry ? entry->addr.id :-1 ; +rcu_read_unlock (); +if (ret >=0 ) +return ret; + +/* address not found, add to local list */ + entry =kmalloc (sizeof (*entry),GFP_ATOMIC ); +if (!entry) +return -ENOMEM ; + + *entry = *skc; + entry->addr.port =0 ; + ret = mptcp_pm_nl_append_new_local_addr(pernet, entry, true,false);
net/mptcp/pm_kernel.c new file +7
-0+if (ret <0 ) +kfree (entry); + +return ret; +} + +bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct
mptcp_addr_info*skc)net/mptcp/pm_kernel.c new file +2
-0+{ + struct pm_nl_pernet *pernet =
pm_nl_get_pernet_from_msk(msk);net/mptcp/pm_kernel.c new file +6
-0+struct mptcp_pm_addr_entry *entry; +bool backup; + +rcu_read_lock (); + entry =__lookup_addr (pernet, skc); + backup = entry && !!(entry->flags &
MPTCP_PM_ADDR_FLAG_BACKUP);net/mptcp/pm_kernel.c new file +7
-0+rcu_read_unlock (); + +return backup; +} + +static int mptcp_nl_add_subflow_or_signal_addr(struct net *net, + struct
mptcp_addr_info*addr)net/mptcp/pm_kernel.c new file +5
-0+{ +struct mptcp_sock *msk; +long s_slot =0 , s_num =0 ; + + while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num))!= NULL) {
net/mptcp/pm_kernel.c new file +8
-0+struct sock *sk = (struct sock *)msk; +struct mptcp_addr_info mpc_addr; + +if (!READ_ONCE (msk->fully_established) || + mptcp_pm_is_userspace(msk)) + goto next; + +/* if the endp linked to the init sf is re-added with a != ID */
net/mptcp/pm_kernel.c new file +1
-0+ mptcp_local_address((struct sock_common *)msk,
&mpc_addr);net/mptcp/pm_kernel.c new file +4
-0+ +lock_sock (sk); +spin_lock_bh (&msk->pm.lock); + if (mptcp_addresses_equal(addr, &mpc_addr, addr-Quoted 1 line
port))
net/mptcp/pm_kernel.c new file +19
-0+ msk->mpc_endpoint_id = addr->id; +mptcp_pm_create_subflow_or_signal_addr (msk); +spin_unlock_bh (&msk->pm.lock); +release_sock (sk); + +next: +sock_put (sk); +cond_resched (); + } + +return 0 ; +} + +static bool mptcp_pm_has_addr_attr_id(const struct nlattr *attr, + struct genl_info *info) +{ + struct nlattr *tb[MPTCP_PM_ADDR_ATTR_MAX + 1]; + + if (!nla_parse_nested_deprecated(tb, MPTCP_PM_ADDR_ATTR_MAX,attr,
net/mptcp/pm_kernel.c new file +1
-0+ mptcp_pm_address_nl_policy,
info->extack) &&net/mptcp/pm_kernel.c new file +7
-0+ tb[MPTCP_PM_ADDR_ATTR_ID]) +return true; +return false; +} + +/* Add an MPTCP endpoint */ +int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info*info)
net/mptcp/pm_kernel.c new file +17
-0+{ +struct pm_nl_pernet *pernet =genl_info_pm_nl (info); +struct mptcp_pm_addr_entry addr, *entry; +struct nlattr *attr; +int ret; + +if (GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ENDPOINT_ADDR )) +return -EINVAL ; + + attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR ]; + ret =mptcp_pm_parse_entry (attr, info, true, &addr); +if (ret <0 ) +return ret; + +if (addr.addr.port && !address_use_port (&addr)) { + NL_SET_ERR_MSG_ATTR(info->extack, attr, + "flags must have signal and notsubflow when using port");
net/mptcp/pm_kernel.c new file +7
-0+return -EINVAL ; + } + +if (addr.flags &MPTCP_PM_ADDR_FLAG_SIGNAL && + addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) { + NL_SET_ERR_MSG_ATTR(info->extack, attr, + "flags mustn't have both signaland fullmesh");
net/mptcp/pm_kernel.c new file +6
-0+return -EINVAL ; + } + +if (addr.flags &MPTCP_PM_ADDR_FLAG_IMPLICIT ) { + NL_SET_ERR_MSG_ATTR(info->extack, attr, + "can't create IMPLICITendpoint");
net/mptcp/pm_kernel.c new file +12
-0+return -EINVAL ; + } + + entry =kzalloc (sizeof (*entry),GFP_KERNEL_ACCOUNT ); +if (!entry) { +GENL_SET_ERR_MSG (info,"can't allocate addr" ); +return -ENOMEM ; + } + + *entry = addr; +if (entry->addr.port) { + ret = mptcp_pm_nl_create_listen_socket(skb->sk,entry);
net/mptcp/pm_kernel.c new file +2
-0+if (ret) { + GENL_SET_ERR_MSG_FMT(info, "create listensocket error: %d", ret);
net/mptcp/pm_kernel.c new file +5
-0+ goto out_free; + } + } + ret =mptcp_pm_nl_append_new_local_addr (pernet, entry, + !mptcp_pm_has_addr_a
ttr_id(attr, info),net/mptcp/pm_kernel.c new file +3
-0+ true); +if (ret <0 ) { + GENL_SET_ERR_MSG_FMT(info, "too many addresses orduplicate one: %d", ret);
net/mptcp/pm_kernel.c new file +4
-0+ goto out_free; + } + + mptcp_nl_add_subflow_or_signal_addr(sock_net(skb->sk),
&entry->addr);net/mptcp/pm_kernel.c new file +9
-0+return 0 ; + +out_free: +__mptcp_pm_release_addr_entry (entry); +return ret; +} + +static u8 mptcp_endp_get_local_id (struct mptcp_sock *msk, + const struct mptcp_addr_info*addr)
net/mptcp/pm_kernel.c new file +6
-0+{ +return msk->mpc_endpoint_id == addr->id ?0 : addr->id; +} + +static bool mptcp_pm_remove_anno_addr (struct mptcp_sock *msk, + const struct mptcp_addr_info*addr,
net/mptcp/pm_kernel.c new file +12
-0+ bool force) +{ +struct mptcp_rm_list list = { .nr =0 }; +bool ret; + + list.ids[list.nr++] =mptcp_endp_get_local_id (msk, addr); + + ret =mptcp_remove_anno_list_by_saddr (msk, addr); +if (ret || force) { +spin_lock_bh (&msk->pm.lock); +if (ret) { + __set_bit(addr->id, msk-Quoted 1 line
pm.id_avail_bitmap);
net/mptcp/pm_kernel.c new file +9
-0+ msk->pm.add_addr_signaled--; + } +mptcp_pm_remove_addr (msk, &list); +spin_unlock_bh (&msk->pm.lock); + } +return ret; +} + +static void __mark_subflow_endp_available(struct mptcp_sock *msk, u8id)
net/mptcp/pm_kernel.c new file +2
-0+{ +/* If it was marked as used, and not ID 0, decrement
local_addr_used*/net/mptcp/pm_kernel.c new file +1
-0+ if (!__test_and_set_bit(id ? : msk->mpc_endpoint_id, msk-Quoted 1 line
pm.id_avail_bitmap) &&
net/mptcp/pm_kernel.c new file +6
-0+ id && !WARN_ON_ONCE(msk->pm.local_addr_used == 0)) + msk->pm.local_addr_used--; +} + +static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net, + const struct
mptcp_pm_addr_entry*entry)net/mptcp/pm_kernel.c new file +9
-0+{ +const struct mptcp_addr_info *addr = &entry->addr; +struct mptcp_rm_list list = { .nr =1 }; +long s_slot =0 , s_num =0 ; +struct mptcp_sock *msk; + +pr_debug ("remove_id=%d\n" , addr->id); + + while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num))!= NULL) {
net/mptcp/pm_kernel.c new file +8
-0+struct sock *sk = (struct sock *)msk; +bool remove_subflow; + +if (mptcp_pm_is_userspace (msk)) + goto next; + +lock_sock (sk); + remove_subflow = mptcp_lookup_subflow_by_saddr(&msk-Quoted 1 line
conn_list, addr);net/mptcp/pm_kernel.c new file +1
-0+ mptcp_pm_remove_anno_addr(msk, addr, remove_subflow&&
net/mptcp/pm_kernel.c new file +1
-0+ !(entry->flags &
MPTCP_PM_ADDR_FLAG_IMPLICIT));net/mptcp/pm_kernel.c new file +11
-0+ + list.ids[0 ] =mptcp_endp_get_local_id (msk, addr); +if (remove_subflow) { +spin_lock_bh (&msk->pm.lock); +mptcp_pm_rm_subflow (msk, &list); +spin_unlock_bh (&msk->pm.lock); + } + +if (entry->flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ) { +spin_lock_bh (&msk->pm.lock); + __mark_subflow_endp_available(msk,list.ids[0]);
net/mptcp/pm_kernel.c new file +17
-0+spin_unlock_bh (&msk->pm.lock); + } + +if (msk->mpc_endpoint_id == entry->addr.id) + msk->mpc_endpoint_id =0 ; +release_sock (sk); + +next: +sock_put (sk); +cond_resched (); + } + +return 0 ; +} + +static int mptcp_nl_remove_id_zero_address (struct net *net, + struct mptcp_addr_info*addr)
net/mptcp/pm_kernel.c new file +8
-0+{ +struct mptcp_rm_list list = { .nr =0 }; +long s_slot =0 , s_num =0 ; +struct mptcp_sock *msk; + + list.ids[list.nr++] =0 ; + + while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num))!= NULL) {
net/mptcp/pm_kernel.c new file +4
-0+struct sock *sk = (struct sock *)msk; +struct mptcp_addr_info msk_local; + + if (list_empty(&msk->conn_list) ||
mptcp_pm_is_userspace(msk))net/mptcp/pm_kernel.c new file +3
-0+ goto next; + + mptcp_local_address((struct sock_common *)msk,
&msk_local);net/mptcp/pm_kernel.c new file +1
-0+ if (!mptcp_addresses_equal(&msk_local, addr, addr-Quoted 1 line
port))
net/mptcp/pm_kernel.c new file +20
-0+ goto next; + +lock_sock (sk); +spin_lock_bh (&msk->pm.lock); +mptcp_pm_remove_addr (msk, &list); +mptcp_pm_rm_subflow (msk, &list); +__mark_subflow_endp_available (msk,0 ); +spin_unlock_bh (&msk->pm.lock); +release_sock (sk); + +next: +sock_put (sk); +cond_resched (); + } + +return 0 ; +} + +/* Remove an MPTCP endpoint */ +int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info*info)
net/mptcp/pm_kernel.c new file +16
-0+{ +struct pm_nl_pernet *pernet =genl_info_pm_nl (info); +struct mptcp_pm_addr_entry addr, *entry; +unsigned int addr_max; +struct nlattr *attr; +int ret; + +if (GENL_REQ_ATTR_CHECK (info,MPTCP_PM_ENDPOINT_ADDR )) +return -EINVAL ; + + attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR ]; + ret =mptcp_pm_parse_entry (attr, info, false, &addr); +if (ret <0 ) +return ret; + +/* the zero id address is special: the first address used by the msk
net/mptcp/pm_kernel.c new file +1
-0+* always gets such an id, so different subflows can have different zero
net/mptcp/pm_kernel.c new file +1
-0+* id addresses. Additionally zero id is not accounted for in
id_bitmap.net/mptcp/pm_kernel.c new file +1
-0+* Let's use an 'mptcp_rm_list' instead of the common remove code.
net/mptcp/pm_kernel.c new file +3
-0+*/ +if (addr.addr.id ==0 ) + return mptcp_nl_remove_id_zero_address(sock_net(skb-Quoted 1 line
sk), &addr.addr);
net/mptcp/pm_kernel.c new file +5
-0+ +spin_lock_bh (&pernet->lock); + entry =__lookup_addr_by_id (pernet, addr.addr.id); +if (!entry) { + NL_SET_ERR_MSG_ATTR(info->extack, attr, "address notfound");
net/mptcp/pm_kernel.c new file +6
-0+spin_unlock_bh (&pernet->lock); +return -EINVAL ; + } +if (entry->flags &MPTCP_PM_ADDR_FLAG_SIGNAL ) { + addr_max = pernet->add_addr_signal_max; + WRITE_ONCE(pernet->add_addr_signal_max, addr_max -1);
net/mptcp/pm_kernel.c new file +12
-0+ } +if (entry->flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ) { + addr_max = pernet->local_addr_max; +WRITE_ONCE (pernet->local_addr_max, addr_max -1 ); + } + + pernet->addrs--; +list_del_rcu (&entry->list); +__clear_bit (entry->addr.id, pernet->id_bitmap); +spin_unlock_bh (&pernet->lock); + + mptcp_nl_remove_subflow_and_signal_addr(sock_net(skb->sk),entry);
net/mptcp/pm_kernel.c new file +7
-0+synchronize_rcu (); +__mptcp_pm_release_addr_entry (entry); + +return ret; +} + +static void mptcp_pm_flush_addrs_and_subflows(struct mptcp_sock*msk,
net/mptcp/pm_kernel.c new file +1
-0+ struct list_head
*rm_list)net/mptcp/pm_kernel.c new file +2
-0+{ +struct mptcp_rm_list alist = { .nr =0 }, slist = { .nr =0 };
net/mptcp/pm_kernel.c new file +5
-0+struct mptcp_pm_addr_entry *entry; + + list_for_each_entry(entry, rm_list, list) { + if (slist.nr < MPTCP_RM_IDS_MAX && + mptcp_lookup_subflow_by_saddr(&msk->conn_list,
&entry->addr))net/mptcp/pm_kernel.c new file +1
-0+ slist.ids[slist.nr++] =
mptcp_endp_get_local_id(msk, &entry->addr);net/mptcp/pm_kernel.c new file +3
-0+ +if (alist.nr <MPTCP_RM_IDS_MAX && + mptcp_remove_anno_list_by_saddr(msk, &entry-Quoted 1 line
addr))
net/mptcp/pm_kernel.c new file +1
-0+ alist.ids[alist.nr++] =
mptcp_endp_get_local_id(msk, &entry->addr);net/mptcp/pm_kernel.c new file +10
-0+ } + +spin_lock_bh (&msk->pm.lock); +if (alist.nr) { + msk->pm.add_addr_signaled -= alist.nr; +mptcp_pm_remove_addr (msk, &alist); + } +if (slist.nr) +mptcp_pm_rm_subflow (msk, &slist); +/* Reset counters: maybe some subflows have been removed before */
net/mptcp/pm_kernel.c new file +1
-0+ bitmap_fill(msk->pm.id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID +1);
net/mptcp/pm_kernel.c new file +14
-0+ msk->pm.local_addr_used =0 ; +spin_unlock_bh (&msk->pm.lock); +} + +static void mptcp_nl_flush_addrs_list (struct net *net, + struct list_head *rm_list) +{ +long s_slot =0 , s_num =0 ; +struct mptcp_sock *msk; + +if (list_empty (rm_list)) +return ; + + while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num))!= NULL) {
net/mptcp/pm_kernel.c new file +5
-0+struct sock *sk = (struct sock *)msk; + +if (!mptcp_pm_is_userspace (msk)) { +lock_sock (sk); + mptcp_pm_flush_addrs_and_subflows(msk,
rm_list);net/mptcp/pm_kernel.c new file +30
-0+release_sock (sk); + } + +sock_put (sk); +cond_resched (); + } +} + +/* caller must ensure the RCU grace period is already elapsed */ +static void __flush_addrs (struct list_head *list) +{ +while (!list_empty (list)) { +struct mptcp_pm_addr_entry *cur; + + cur =list_entry (list->next, + struct mptcp_pm_addr_entry, list); +list_del_rcu (&cur->list); +__mptcp_pm_release_addr_entry (cur); + } +} + +static void __reset_counters (struct pm_nl_pernet *pernet) +{ +WRITE_ONCE (pernet->add_addr_signal_max,0 ); +WRITE_ONCE (pernet->add_addr_accept_max,0 ); +WRITE_ONCE (pernet->local_addr_max,0 ); + pernet->addrs =0 ; +} + +int mptcp_pm_nl_flush_addrs_doit(struct sk_buff *skb, struct
genl_info*info)net/mptcp/pm_kernel.c new file +56
-0+{ +struct pm_nl_pernet *pernet =genl_info_pm_nl (info); +LIST_HEAD (free_list); + +spin_lock_bh (&pernet->lock); +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 ); +spin_unlock_bh (&pernet->lock); +mptcp_nl_flush_addrs_list (sock_net (skb->sk), &free_list); +synchronize_rcu (); +__flush_addrs (&free_list); +return 0 ; +} + +int mptcp_pm_nl_get_addr (u8 id,struct mptcp_pm_addr_entry *addr, +struct genl_info *info) +{ +struct pm_nl_pernet *pernet =genl_info_pm_nl (info); +struct mptcp_pm_addr_entry *entry; +int ret = -EINVAL ; + +rcu_read_lock (); + entry =__lookup_addr_by_id (pernet, id); +if (entry) { + *addr = *entry; + ret =0 ; + } +rcu_read_unlock (); + +return ret; +} + +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; +struct pm_nl_pernet *pernet; +int id = cb->args[0 ]; +int i; + + pernet =pm_nl_get_pernet (net); + +rcu_read_lock (); +for (i = id; i <MPTCP_PM_MAX_ADDR_ID +1 ; i++) { +if (test_bit (i, pernet->id_bitmap)) { + entry =__lookup_addr_by_id (pernet, i); +if (!entry) +break ; + +if (entry->addr.id <= id) +continue ; + + if (mptcp_pm_genl_fill_addr(msg, cb, entry)< 0)
net/mptcp/pm_kernel.c new file +12
-0+break ; + + id = entry->addr.id; + } + } +rcu_read_unlock (); + + cb->args[0 ] = id; +return msg->len; +} + +static int parse_limit(struct genl_info *info, int id, unsigned int*limit)
net/mptcp/pm_kernel.c new file +10
-0+{ +struct nlattr *attr = info->attrs[id]; + +if (!attr) +return 0 ; + + *limit =nla_get_u32 (attr); +if (*limit >MPTCP_PM_ADDR_MAX ) { + NL_SET_ERR_MSG_ATTR_FMT(info->extack, attr, + "limit greater than maximum(%u)",
net/mptcp/pm_kernel.c new file +7
-0+ MPTCP_PM_ADDR_MAX); +return -EINVAL ; + } +return 0 ; +} + +int mptcp_pm_nl_set_limits_doit(struct sk_buff *skb, struct
genl_info*info)net/mptcp/pm_kernel.c new file +8
-0+{ +struct pm_nl_pernet *pernet =genl_info_pm_nl (info); +unsigned int rcv_addrs, subflows; +int ret; + +spin_lock_bh (&pernet->lock); + rcv_addrs = pernet->add_addr_accept_max; + ret = parse_limit(info, MPTCP_PM_ATTR_RCV_ADD_ADDRS,
&rcv_addrs);net/mptcp/pm_kernel.c new file +17
-0+if (ret) + goto unlock; + + subflows = pernet->subflows_max; + ret =parse_limit (info,MPTCP_PM_ATTR_SUBFLOWS , &subflows); +if (ret) + goto unlock; + +WRITE_ONCE (pernet->add_addr_accept_max, rcv_addrs); +WRITE_ONCE (pernet->subflows_max, subflows); + +unlock: +spin_unlock_bh (&pernet->lock); +return ret; +} + +int mptcp_pm_nl_get_limits_doit(struct sk_buff *skb, struct
genl_info*info)net/mptcp/pm_kernel.c new file +27
-0+{ +struct pm_nl_pernet *pernet =genl_info_pm_nl (info); +struct sk_buff *msg; +void *reply; + + msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL ); +if (!msg) +return -ENOMEM ; + + reply =genlmsg_put_reply (msg, info, &mptcp_genl_family,0 , + MPTCP_PM_CMD_GET_LIMITS); +if (!reply) + goto fail; + +if (nla_put_u32 (msg,MPTCP_PM_ATTR_RCV_ADD_ADDRS , +READ_ONCE (pernet->add_addr_accept_max))) + goto fail; + +if (nla_put_u32 (msg,MPTCP_PM_ATTR_SUBFLOWS , +READ_ONCE (pernet->subflows_max))) + goto fail; + +genlmsg_end (msg, reply); +return genlmsg_reply (msg, info); + +fail: + GENL_SET_ERR_MSG(info, "not enough space in Netlinkmessage");
net/mptcp/pm_kernel.c new file +20
-0+nlmsg_free (msg); +return -EMSGSIZE ; +} + +static void mptcp_pm_nl_fullmesh (struct mptcp_sock *msk, +struct mptcp_addr_info *addr) +{ +struct mptcp_rm_list list = { .nr =0 }; + + list.ids[list.nr++] =mptcp_endp_get_local_id (msk, addr); + +spin_lock_bh (&msk->pm.lock); +mptcp_pm_rm_subflow (msk, &list); +__mark_subflow_endp_available (msk, list.ids[0 ]); +mptcp_pm_create_subflow_or_signal_addr (msk); +spin_unlock_bh (&msk->pm.lock); +} + +static void mptcp_pm_nl_set_flags_all (struct net *net, + struct mptcp_pm_addr_entry*local,
net/mptcp/pm_kernel.c new file +3
-0+ u8 changed) +{ + u8 is_subflow = !!(local->flags &
MPTCP_PM_ADDR_FLAG_SUBFLOW);net/mptcp/pm_kernel.c new file +8
-0+u8 bkup = !!(local->flags &MPTCP_PM_ADDR_FLAG_BACKUP ); +long s_slot =0 , s_num =0 ; +struct mptcp_sock *msk; + +if (changed ==MPTCP_PM_ADDR_FLAG_FULLMESH && !is_subflow) +return ; + + while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num))!= NULL) {
net/mptcp/pm_kernel.c new file +3
-0+struct sock *sk = (struct sock *)msk; + + if (list_empty(&msk->conn_list) ||
mptcp_pm_is_userspace(msk))net/mptcp/pm_kernel.c new file +5
-0+ goto next; + +lock_sock (sk); +if (changed &MPTCP_PM_ADDR_FLAG_BACKUP ) + mptcp_pm_mp_prio_send_ack(msk, &local->addr,NULL, bkup);
net/mptcp/pm_kernel.c new file +1
-0+/* Subflows will only be recreated if the SUBFLOW flag is set */
net/mptcp/pm_kernel.c new file +1
-0+ if (is_subflow && (changed &
MPTCP_PM_ADDR_FLAG_FULLMESH))net/mptcp/pm_kernel.c new file +33
-0+mptcp_pm_nl_fullmesh (msk, &local->addr); +release_sock (sk); + +next: +sock_put (sk); +cond_resched (); + } +} + +int mptcp_pm_nl_set_flags (struct mptcp_pm_addr_entry *local, + struct genl_info *info) +{ +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 =genl_info_net (info); +struct mptcp_pm_addr_entry *entry; +struct pm_nl_pernet *pernet; +u8 lookup_by_id =0 ; + + pernet =pm_nl_get_pernet (net); + +if (local->addr.family ==AF_UNSPEC ) { + lookup_by_id =1 ; +if (!local->addr.id) { +NL_SET_ERR_MSG_ATTR (info->extack, attr, + "missing address ID"); +return -EOPNOTSUPP ; + } + } + +spin_lock_bh (&pernet->lock); + entry = lookup_by_id ? __lookup_addr_by_id(pernet, local-Quoted 1 line
addr.id) :
net/mptcp/pm_kernel.c new file +4
-0+ __lookup_addr(pernet, &local->addr); +if (!entry) { +spin_unlock_bh (&pernet->lock); + NL_SET_ERR_MSG_ATTR(info->extack, attr, "address notfound");
net/mptcp/pm_kernel.c new file +7
-0+return -EINVAL ; + } +if ((local->flags &MPTCP_PM_ADDR_FLAG_FULLMESH ) && + (entry->flags & (MPTCP_PM_ADDR_FLAG_SIGNAL | + MPTCP_PM_ADDR_FLAG_IMPLICIT))) { +spin_unlock_bh (&pernet->lock); + NL_SET_ERR_MSG_ATTR(info->extack, attr, "invalidaddr flags");
net/mptcp/pm_kernel.c new file +5
-0+return -EINVAL ; + } + + changed = (local->flags ^ entry->flags) & mask; + entry->flags = (entry->flags & ~mask) | (local->flags &mask);
net/mptcp/pm_kernel.c new file +10
-0+ *local = *entry; +spin_unlock_bh (&pernet->lock); + +mptcp_pm_nl_set_flags_all (net, local, changed); +return 0 ; +} + +bool mptcp_pm_nl_check_work_pending (struct mptcp_sock *msk) +{ + struct pm_nl_pernet *pernet =
pm_nl_get_pernet_from_msk(msk);net/mptcp/pm_kernel.c new file +3
-0+ + if (msk->pm.subflows == mptcp_pm_get_subflows_max(msk) || + (find_next_and_bit(pernet->id_bitmap, msk-Quoted 1 line
pm.id_avail_bitmap,
net/mptcp/pm_kernel.c new file +1
-0+ MPTCP_PM_MAX_ADDR_ID + 1, 0) ==
MPTCP_PM_MAX_ADDR_ID+ 1)) {net/mptcp/pm_kernel.c new file +38
-0+WRITE_ONCE (msk->pm.work_pending, false); +return false; + } +return true; +} + +/* Called under PM lock */ +void __mptcp_pm_kernel_worker (struct mptcp_sock *msk) +{ +struct mptcp_pm_data *pm = &msk->pm; + +if (pm->status &BIT (MPTCP_PM_ADD_ADDR_RECEIVED )) { + pm->status &= ~BIT (MPTCP_PM_ADD_ADDR_RECEIVED ); +mptcp_pm_nl_add_addr_received (msk); + } +if (pm->status &BIT (MPTCP_PM_ESTABLISHED )) { + pm->status &= ~BIT (MPTCP_PM_ESTABLISHED ); +mptcp_pm_nl_fully_established (msk); + } +if (pm->status &BIT (MPTCP_PM_SUBFLOW_ESTABLISHED )) { + pm->status &= ~BIT (MPTCP_PM_SUBFLOW_ESTABLISHED ); +mptcp_pm_nl_subflow_established (msk); + } +} + +static int __net_init pm_nl_init_net (struct net *net) +{ +struct pm_nl_pernet *pernet =pm_nl_get_pernet (net); + +INIT_LIST_HEAD_RCU (&pernet->local_addr_list); + +/* Cit. 2 subflows ought to be enough for anybody. */ + pernet->subflows_max =2 ; + pernet->next_id =1 ; + pernet->stale_loss_cnt =4 ; +spin_lock_init (&pernet->lock); + +/* No need to initialize other pernet fields, the struct is zeroed at
net/mptcp/pm_kernel.c new file +14
-0+* allocation time. +*/ + +return 0 ; +} + +static void __net_exit pm_nl_exit_net(struct list_head *net_list) +{ +struct net *net; + +list_for_each_entry (net, net_list, exit_list) { +struct pm_nl_pernet *pernet =pm_nl_get_pernet (net); + +/* net is removed from namespace list, can't race with
net/mptcp/pm_kernel.c new file +1
-0+* other modifiers, also netns core already waited for a
net/mptcp/pm_kernel.c new file +17
-0+* RCU grace period. +*/ +__flush_addrs (&pernet->local_addr_list); + } +} + +static struct pernet_operations mptcp_pm_pernet_ops = { + .init = pm_nl_init_net, + .exit_batch = pm_nl_exit_net, + .id = &pm_nl_pernet_id, + .size =sizeof (struct pm_nl_pernet ), +}; + +void __init mptcp_pm_nl_init (void ) +{ +if (register_pernet_subsys (&mptcp_pm_pernet_ops) <0 ) + panic("Failed to register MPTCP PM pernetsubsystem.\n");
net/mptcp/pm_kernel.c new file +3
-0+ +if (genl_register_family (&mptcp_genl_family)) + panic("Failed to register MPTCP PM netlinkfamily\n");
net/mptcp/pm_kernel.c new file +1
-0+}net/mptcp/pm_netlink.c +0
-0index
2a8652886fce6ba9743d0efba576ac57f35a0077..2a9a87cad5b80787c683b0ee89e7ac3be31bfbf0100644net/mptcp/pm_netlink.c +0
-0@@ -6,1177 +6,9 @@
#definepr_fmt(fmt)"MPTCP: " fmtnet/mptcp/pm_netlink.c +0
-6-#include <linux/inet.h> -#include <linux/kernel.h> -#include <net/inet_common.h> -#include <net/netns/generic.h> -#include <net/mptcp.h> -#include "
protocol.h"
-#include "mib.h"
#include "mptcp_pm_gen.h"net/mptcp/pm_netlink.c +0
-40-static int pm_nl_pernet_id; - -struct mptcp_pm_add_entry { -struct list_head list; -struct mptcp_addr_info addr; -u8 retrans_times; -struct timer_list add_timer; -struct mptcp_sock *sock; -}; - -struct pm_nl_pernet { -/* protects pernet updates */ -spinlock_t lock; -struct list_head local_addr_list; -unsigned int addrs; -unsigned int stale_loss_cnt; -unsigned int add_addr_signal_max; -unsigned int add_addr_accept_max; -unsigned int local_addr_max; -unsigned int subflows_max; -unsigned int next_id; - DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); -}; - -#define MPTCP_PM_ADDR_MAX 8 -#define ADD_ADDR_RETRANS_MAX 3 - -static struct pm_nl_pernet *pm_nl_get_pernet (const struct net *net) -{ -return net_generic (net, pm_nl_pernet_id); -} - -static struct pm_nl_pernet * -pm_nl_get_pernet_from_msk (const struct mptcp_sock *msk) -{ -return pm_nl_get_pernet (sock_net ((struct sock *)msk)); -} - -bool mptcp_addresses_equal (const struct mptcp_addr_info *a, - const struct mptcp_addr_info *b, bool
use_port)net/mptcp/pm_netlink.c +0
-6-{ -bool addr_equals = false; - -if (a->family == b->family) { -if (a->family ==AF_INET ) - addr_equals = a->addr.s_addr == b-Quoted 1 line
addr.s_addr;
net/mptcp/pm_netlink.c +0
-3-#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) - else - addr_equals = ipv6_addr_equal(&a->addr6, &b-Quoted 1 line
addr6);
net/mptcp/pm_netlink.c +0
-3- }else if (a->family ==AF_INET ) { -if (ipv6_addr_v4mapped (&b->addr6)) - addr_equals = a->addr.s_addr == b-Quoted 1 line
addr6.s6_addr32[3];
net/mptcp/pm_netlink.c +0
-3- }else if (b->family ==AF_INET ) { -if (ipv6_addr_v4mapped (&a->addr6)) - addr_equals = a->addr6.s6_addr32[3] == b-Quoted 1 line
addr.s_addr;
net/mptcp/pm_netlink.c +0
-12-#endif - } - -if (!addr_equals) -return false; -if (!use_port) -return true; - -return a->port == b->port; -} - -void mptcp_local_address(const struct sock_common *skc, struct
mptcp_addr_info*addr)net/mptcp/pm_netlink.c +0
-26-{ - addr->family = skc->skc_family; - addr->port =htons (skc->skc_num); -if (addr->family ==AF_INET ) - addr->addr.s_addr = skc->skc_rcv_saddr; -#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) - else if (addr->family == AF_INET6) - addr->addr6 = skc->skc_v6_rcv_saddr; -#endif -} - -static void remote_address (const struct sock_common *skc, - struct mptcp_addr_info *addr) -{ - addr->family = skc->skc_family; - addr->port = skc->skc_dport; -if (addr->family ==AF_INET ) - addr->addr.s_addr = skc->skc_daddr; -#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) - else if (addr->family == AF_INET6) - addr->addr6 = skc->skc_v6_daddr; -#endif -} - -bool mptcp_lookup_subflow_by_saddr (const struct list_head *list, - const struct mptcp_addr_info*saddr)
net/mptcp/pm_netlink.c +0
-7-{ -struct mptcp_subflow_context *subflow; -struct mptcp_addr_info cur; -struct sock_common *skc; - -list_for_each_entry (subflow, list, node) { - skc = (struct sock_common*)mptcp_subflow_tcp_sock(subflow);
net/mptcp/pm_netlink.c +0
-11- -mptcp_local_address (skc, &cur); -if (mptcp_addresses_equal (&cur, saddr, saddr->port)) -return true; - } - -return false; -} - -static bool lookup_subflow_by_daddr (const struct list_head *list, - const struct mptcp_addr_info*daddr)
net/mptcp/pm_netlink.c +0
-9-{ -struct mptcp_subflow_context *subflow; -struct mptcp_addr_info cur; - -list_for_each_entry (subflow, list, node) { -struct sock *ssk =mptcp_subflow_tcp_sock (subflow); - - if (!((1 << inet_sk_state_load(ssk)) & - (TCPF_ESTABLISHED | TCPF_SYN_SENT |
TCPF_SYN_RECV)))net/mptcp/pm_netlink.c +0
-22-continue ; - -remote_address ((struct sock_common *)ssk, &cur); -if (mptcp_addresses_equal (&cur, daddr, daddr->port)) -return true; - } - -return false; -} - -static bool -select_local_address (const struct pm_nl_pernet *pernet, - const struct mptcp_sock *msk, - struct mptcp_pm_local *new_local) -{ -struct mptcp_pm_addr_entry *entry; -bool found = false; - -msk_owned_by_me (msk); - -rcu_read_lock (); - list_for_each_entry_rcu(entry, &pernet->local_addr_list,list) {
net/mptcp/pm_netlink.c +0
-4-if (!(entry->flags &MPTCP_PM_ADDR_FLAG_SUBFLOW )) -continue ; - - if (!test_bit(entry->addr.id, msk-Quoted 1 line
pm.id_avail_bitmap))
net/mptcp/pm_netlink.c +0
-15-continue ; - - new_local->addr = entry->addr; - new_local->flags = entry->flags; - new_local->ifindex = entry->ifindex; - found = true; -break ; - } -rcu_read_unlock (); - -return found; -} - -static bool -select_signal_address(struct pm_nl_pernet *pernet, const struct
mptcp_sock*msk,net/mptcp/pm_netlink.c +0
-9- struct mptcp_pm_local *new_local) -{ -struct mptcp_pm_addr_entry *entry; -bool found = false; - -rcu_read_lock (); -/* do not keep any additional per socket state, just signal -* the address list in order. -* Note: removal from the local address list during the msk life-cycle
net/mptcp/pm_netlink.c +0
-3-* can lead to additional addresses not being announced. -*/ - list_for_each_entry_rcu(entry, &pernet->local_addr_list,list) {
net/mptcp/pm_netlink.c +0
-1- if (!test_bit(entry->addr.id, msk-Quoted 1 line
pm.id_avail_bitmap))
net/mptcp/pm_netlink.c +0
-17-continue ; - -if (!(entry->flags &MPTCP_PM_ADDR_FLAG_SIGNAL )) -continue ; - - new_local->addr = entry->addr; - new_local->flags = entry->flags; - new_local->ifindex = entry->ifindex; - found = true; -break ; - } -rcu_read_unlock (); - -return found; -} - -unsigned int mptcp_pm_get_add_addr_signal_max(const struct
mptcp_sock*msk)net/mptcp/pm_netlink.c +0
-2-{ - const struct pm_nl_pernet *pernet =
pm_nl_get_pernet_from_msk(msk);net/mptcp/pm_netlink.c +0
-6- -return READ_ONCE (pernet->add_addr_signal_max); -} -EXPORT_SYMBOL_GPL (mptcp_pm_get_add_addr_signal_max); - -unsigned int mptcp_pm_get_add_addr_accept_max(const struct
mptcp_sock*msk)net/mptcp/pm_netlink.c +0
-2-{ - struct pm_nl_pernet *pernet =
pm_nl_get_pernet_from_msk(msk);net/mptcp/pm_netlink.c +0
-8- -return READ_ONCE (pernet->add_addr_accept_max); -} -EXPORT_SYMBOL_GPL (mptcp_pm_get_add_addr_accept_max); - -unsigned int mptcp_pm_get_subflows_max (const struct mptcp_sock *msk) -{ - struct pm_nl_pernet *pernet =
pm_nl_get_pernet_from_msk(msk);net/mptcp/pm_netlink.c +0
-6- -return READ_ONCE (pernet->subflows_max); -} -EXPORT_SYMBOL_GPL (mptcp_pm_get_subflows_max); - -unsigned int mptcp_pm_get_local_addr_max(const struct mptcp_sock*msk)
net/mptcp/pm_netlink.c +0
-2-{ - struct pm_nl_pernet *pernet =
pm_nl_get_pernet_from_msk(msk);net/mptcp/pm_netlink.c +0
-8- -return READ_ONCE (pernet->local_addr_max); -} -EXPORT_SYMBOL_GPL (mptcp_pm_get_local_addr_max); - -bool mptcp_pm_nl_check_work_pending (struct mptcp_sock *msk) -{ - struct pm_nl_pernet *pernet =
pm_nl_get_pernet_from_msk(msk);net/mptcp/pm_netlink.c +0
-3- - if (msk->pm.subflows == mptcp_pm_get_subflows_max(msk) || - (find_next_and_bit(pernet->id_bitmap, msk-Quoted 1 line
pm.id_avail_bitmap,
net/mptcp/pm_netlink.c +0
-1- MPTCP_PM_MAX_ADDR_ID + 1, 0) ==
MPTCP_PM_MAX_ADDR_ID+ 1)) {net/mptcp/pm_netlink.c +0
-23-WRITE_ONCE (msk->pm.work_pending, false); -return false; - } -return true; -} - -struct mptcp_pm_add_entry * -mptcp_lookup_anno_list_by_saddr (const struct mptcp_sock *msk, -const struct mptcp_addr_info *addr) -{ -struct mptcp_pm_add_entry *entry; - -lockdep_assert_held (&msk->pm.lock); - -list_for_each_entry (entry, &msk->pm.anno_list, list) { -if (mptcp_addresses_equal (&entry->addr, addr, true)) -return entry; - } - -return NULL ; -} - -bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, conststruct sock *sk)
net/mptcp/pm_netlink.c +0
-10-{ -struct mptcp_pm_add_entry *entry; -struct mptcp_addr_info saddr; -bool ret = false; - -mptcp_local_address ((struct sock_common *)sk, &saddr); - -spin_lock_bh (&msk->pm.lock); -list_for_each_entry (entry, &msk->pm.anno_list, list) { - if (mptcp_addresses_equal(&entry->addr, &saddr,true)) {
net/mptcp/pm_netlink.c +0
-13- ret = true; - goto out; - } - } - -out: -spin_unlock_bh (&msk->pm.lock); -return ret; -} - -static void mptcp_pm_add_timer (struct timer_list *timer) -{ - struct mptcp_pm_add_entry *entry = from_timer(entry, timer,
add_timer);net/mptcp/pm_netlink.c +0
-16-struct mptcp_sock *msk = entry->sock; -struct sock *sk = (struct sock *)msk; - -pr_debug ("msk=%p\n" , msk); - -if (!msk) -return ; - -if (inet_sk_state_load (sk) ==TCP_CLOSE ) -return ; - -if (!entry->addr.id) -return ; - - if (mptcp_pm_should_add_signal_addr(msk)) { - sk_reset_timer(sk, timer, jiffies + TCP_RTO_MAX /8);
net/mptcp/pm_netlink.c +0
-7- goto out; - } - -spin_lock_bh (&msk->pm.lock); - -if (!mptcp_pm_should_add_signal_addr (msk)) { - pr_debug("retransmit ADD_ADDR id=%d\n", entry-Quoted 1 line
addr.id);
net/mptcp/pm_netlink.c +0
-8-mptcp_pm_announce_addr (msk, &entry->addr, false); -mptcp_pm_add_addr_send_ack (msk); - entry->retrans_times++; - } - -if (entry->retrans_times <ADD_ADDR_RETRANS_MAX ) - sk_reset_timer(sk, timer, - jiffies +mptcp_get_add_addr_timeout(sock_net(sk)));
net/mptcp/pm_netlink.c +0
-13- -spin_unlock_bh (&msk->pm.lock); - -if (entry->retrans_times ==ADD_ADDR_RETRANS_MAX ) -mptcp_pm_subflow_established (msk); - -out: -__sock_put (sk); -} - -struct mptcp_pm_add_entry * -mptcp_pm_del_add_timer (struct mptcp_sock *msk, - const struct mptcp_addr_info *addr, bool
check_id)net/mptcp/pm_netlink.c +0
-16-{ -struct mptcp_pm_add_entry *entry; -struct sock *sk = (struct sock *)msk; -struct timer_list *add_timer =NULL ; - -spin_lock_bh (&msk->pm.lock); - entry =mptcp_lookup_anno_list_by_saddr (msk, addr); -if (entry && (!check_id || entry->addr.id == addr->id)) { - entry->retrans_times =ADD_ADDR_RETRANS_MAX ; - add_timer = &entry->add_timer; - } -if (!check_id && entry) -list_del (&entry->list); -spin_unlock_bh (&msk->pm.lock); - -/* no lock, because sk_stop_timer_sync() is calling
del_timer_sync()*/net/mptcp/pm_netlink.c +0
-23-if (add_timer) -sk_stop_timer_sync (sk, add_timer); - -return entry; -} - -bool mptcp_pm_alloc_anno_list (struct mptcp_sock *msk, - const struct mptcp_addr_info *addr) -{ -struct mptcp_pm_add_entry *add_entry =NULL ; -struct sock *sk = (struct sock *)msk; -struct net *net =sock_net (sk); - -lockdep_assert_held (&msk->pm.lock); - - add_entry =mptcp_lookup_anno_list_by_saddr (msk, addr); - -if (add_entry) { -if (WARN_ON_ONCE (mptcp_pm_is_kernel (msk))) -return false; - - sk_reset_timer(sk, &add_entry->add_timer, - jiffies +
mptcp_get_add_addr_timeout(net));net/mptcp/pm_netlink.c +0
-42-return true; - } - - add_entry =kmalloc (sizeof (*add_entry),GFP_ATOMIC ); -if (!add_entry) -return false; - -list_add (&add_entry->list, &msk->pm.anno_list); - - add_entry->addr = *addr; - add_entry->sock = msk; - add_entry->retrans_times =0 ; - -timer_setup (&add_entry->add_timer, mptcp_pm_add_timer,0 ); -sk_reset_timer (sk, &add_entry->add_timer, - jiffies + mptcp_get_add_addr_timeout(net)); - -return true; -} - -void mptcp_pm_free_anno_list (struct mptcp_sock *msk) -{ -struct mptcp_pm_add_entry *entry, *tmp; -struct sock *sk = (struct sock *)msk; -LIST_HEAD (free_list); - -pr_debug ("msk=%p\n" , msk); - -spin_lock_bh (&msk->pm.lock); -list_splice_init (&msk->pm.anno_list, &free_list); -spin_unlock_bh (&msk->pm.lock); - -list_for_each_entry_safe (entry, tmp, &free_list, list) { -sk_stop_timer_sync (sk, &entry->add_timer); -kfree (entry); - } -} - -/* 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,
net/mptcp/pm_netlink.c +0
-1- struct mptcp_addr_info*local,
net/mptcp/pm_netlink.c +0
-2- bool fullmesh, - struct mptcp_addr_info*addrs)
net/mptcp/pm_netlink.c +0
-19-{ - 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 }; - unsigned int subflows_max; - int i = 0; - - subflows_max = mptcp_pm_get_subflows_max(msk); - 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) - return 0; - - if (!mptcp_pm_addr_families_match(sk, local,&remote))
net/mptcp/pm_netlink.c +0
-6-return 0 ; - - msk->pm.subflows++; - addrs[i++] = remote; - }else { - DECLARE_BITMAP(unavail_id, MPTCP_PM_MAX_ADDR_ID +1);
net/mptcp/pm_netlink.c +0
-3- -/* Forbid creation of new subflows matching existing -* ones, possibly already created by incoming
ADD_ADDRnet/mptcp/pm_netlink.c +0
-4-*/ -bitmap_zero (unavail_id,MPTCP_PM_MAX_ADDR_ID +1 ); -mptcp_for_each_subflow (msk, subflow) - if (READ_ONCE(subflow->local_id) == local-Quoted 1 line
id)
net/mptcp/pm_netlink.c +0
-1- __set_bit(subflow->remote_id,
unavail_id);net/mptcp/pm_netlink.c +0
-4- -mptcp_for_each_subflow (msk, subflow) { - ssk =mptcp_subflow_tcp_sock (subflow); - remote_address((struct sock_common *)ssk,&addrs[i]);
net/mptcp/pm_netlink.c +0
-8- addrs[i].id =READ_ONCE (subflow->remote_id); -if (deny_id0 && !addrs[i].id) -continue ; - -if (test_bit (addrs[i].id, unavail_id)) -continue ; - - if (!mptcp_pm_addr_families_match(sk, local,&addrs[i]))
net/mptcp/pm_netlink.c +0
-4-continue ; - -if (msk->pm.subflows < subflows_max) { -/* forbid creating multiple address towards
net/mptcp/pm_netlink.c +0
-13-* this id -*/ -__set_bit (addrs[i].id, unavail_id); - msk->pm.subflows++; - i++; - } - } - } - -return i; -} - -static void __mptcp_pm_send_ack(struct mptcp_sock *msk, struct
mptcp_subflow_context*subflow,net/mptcp/pm_netlink.c +0
-7- bool prio, bool backup) -{ -struct sock *ssk =mptcp_subflow_tcp_sock (subflow); -bool slow; - - pr_debug("send ack for %s\n", - prio ? "mp_prio" : (mptcp_pm_should_add_signal(msk)? "
add_addr" : "rm_addr"));net/mptcp/pm_netlink.c +0
-12- - slow =lock_sock_fast (ssk); -if (prio) { - subflow->send_mp_prio =1 ; - subflow->request_bkup = backup; - } - -__mptcp_subflow_send_ack (ssk); -unlock_sock_fast (ssk, slow); -} - -static void mptcp_pm_send_ack(struct mptcp_sock *msk, struct
mptcp_subflow_context*subflow,net/mptcp/pm_netlink.c +0
-13- bool prio, bool backup) -{ -spin_unlock_bh (&msk->pm.lock); -__mptcp_pm_send_ack (msk, subflow, prio, backup); -spin_lock_bh (&msk->pm.lock); -} - -static struct mptcp_pm_addr_entry * -__lookup_addr_by_id (struct pm_nl_pernet *pernet,unsigned int id) -{ -struct mptcp_pm_addr_entry *entry; - - list_for_each_entry_rcu(entry, &pernet->local_addr_list,list,
net/mptcp/pm_netlink.c +0
-9- lockdep_is_held(&pernet->lock)) { -if (entry->addr.id == id) -return entry; - } -return NULL ; -} - -static struct mptcp_pm_addr_entry * -__lookup_addr(struct pm_nl_pernet *pernet, const struct
mptcp_addr_info*info)net/mptcp/pm_netlink.c +0
-4-{ -struct mptcp_pm_addr_entry *entry; - - list_for_each_entry_rcu(entry, &pernet->local_addr_list,list,
net/mptcp/pm_netlink.c +0
-2- lockdep_is_held(&pernet->lock)) { - if (mptcp_addresses_equal(&entry->addr, info, entry-Quoted 1 line
addr.port))
net/mptcp/pm_netlink.c +0
-6-return entry; - } -return NULL ; -} - -static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock*msk)
net/mptcp/pm_netlink.c +0
-17-{ -struct sock *sk = (struct sock *)msk; -unsigned int add_addr_signal_max; -bool signal_and_subflow = false; -unsigned int local_addr_max; -struct pm_nl_pernet *pernet; -struct mptcp_pm_local local; -unsigned int subflows_max; - - pernet =pm_nl_get_pernet (sock_net (sk)); - - add_addr_signal_max =mptcp_pm_get_add_addr_signal_max (msk); - local_addr_max =mptcp_pm_get_local_addr_max (msk); - subflows_max =mptcp_pm_get_subflows_max (msk); - -/* do lazy endpoint usage accounting for the MPC subflows */ - if (unlikely(!(msk->pm.status &
BIT(MPTCP_PM_MPC_ENDPOINT_ACCOUNTED))) &&msk->first) {net/mptcp/pm_netlink.c +0
-1- struct mptcp_subflow_context *subflow =
mptcp_subflow_ctx(msk->first);net/mptcp/pm_netlink.c +0
-5-struct mptcp_pm_addr_entry *entry; -struct mptcp_addr_info mpc_addr; -bool backup = false; - - mptcp_local_address((struct sock_common *)msk-Quoted 1 line
first,
&mpc_addr);net/mptcp/pm_netlink.c +0
-4-rcu_read_lock (); - entry =__lookup_addr (pernet, &mpc_addr); -if (entry) { - __clear_bit(entry->addr.id, msk-Quoted 1 line
pm.id_avail_bitmap);
net/mptcp/pm_netlink.c +0
-2- msk->mpc_endpoint_id = entry->addr.id; - backup = !!(entry->flags &
MPTCP_PM_ADDR_FLAG_BACKUP);net/mptcp/pm_netlink.c +0
-5- } -rcu_read_unlock (); - -if (backup) - mptcp_pm_send_ack(msk, subflow, true,backup);
net/mptcp/pm_netlink.c +0
-2- - msk->pm.status |=
BIT(MPTCP_PM_MPC_ENDPOINT_ACCOUNTED);net/mptcp/pm_netlink.c +0
-10- } - -pr_debug ("local %d:%d signal %d:%d subflows %d:%d\n" , - msk->pm.local_addr_used, local_addr_max, - msk->pm.add_addr_signaled, add_addr_signal_max, - msk->pm.subflows, subflows_max); - -/* check first for announce */ -if (msk->pm.add_addr_signaled < add_addr_signal_max) { -/* due to racing events on both ends we can reach here while
net/mptcp/pm_netlink.c +0
-1-* previous add address is still running: if we invoke now
net/mptcp/pm_netlink.c +0
-3-* mptcp_pm_announce_addr(), that will fail and the -* corresponding id will be marked as used. -* Instead let the PM machinery reschedule us when the
net/mptcp/pm_netlink.c +0
-3-* current address announce will be completed. -*/ - if (msk->pm.addr_signal &
BIT(MPTCP_ADD_ADDR_SIGNAL))net/mptcp/pm_netlink.c +0
-6-return ; - -if (!select_signal_address (pernet, msk, &local)) - goto subflow; - -/* If the alloc fails, we are on memory pressure, not worth
net/mptcp/pm_netlink.c +0
-33-* continuing, and trying to create subflows. -*/ -if (!mptcp_pm_alloc_anno_list (msk, &local.addr)) -return ; - -__clear_bit (local.addr.id, msk->pm.id_avail_bitmap); - msk->pm.add_addr_signaled++; - -/* Special case for ID0: set the correct ID */ -if (local.addr.id == msk->mpc_endpoint_id) - local.addr.id =0 ; - -mptcp_pm_announce_addr (msk, &local.addr, false); -mptcp_pm_addr_send_ack (msk); - -if (local.flags &MPTCP_PM_ADDR_FLAG_SUBFLOW ) - signal_and_subflow = true; - } - -subflow: -/* check if should create a new subflow */ -while (msk->pm.local_addr_used < local_addr_max && - msk->pm.subflows < subflows_max) { -struct mptcp_addr_info addrs[MPTCP_PM_ADDR_MAX ]; -bool fullmesh; -int i, nr; - -if (signal_and_subflow) - signal_and_subflow = false; -else if (!select_local_address (pernet, msk, &local)) -break ; - - fullmesh = !!(local.flags &
MPTCP_PM_ADDR_FLAG_FULLMESH);net/mptcp/pm_netlink.c +0
-10- -__clear_bit (local.addr.id, msk->pm.id_avail_bitmap); - -/* Special case for ID0: set the correct ID */ -if (local.addr.id == msk->mpc_endpoint_id) - local.addr.id =0 ; -else /* local_addr_used is not decr for ID 0 */ - msk->pm.local_addr_used++; - - nr = fill_remote_addresses_vec(msk, &local.addr,fullmesh, addrs);
net/mptcp/pm_netlink.c +0
-6-if (nr ==0 ) -continue ; - -spin_unlock_bh (&msk->pm.lock); -for (i =0 ; i < nr; i++) - __mptcp_subflow_connect(sk, &local,&addrs[i]);
net/mptcp/pm_netlink.c +0
-20-spin_lock_bh (&msk->pm.lock); - } -mptcp_pm_nl_check_work_pending (msk); -} - -static void mptcp_pm_nl_fully_established (struct mptcp_sock *msk) -{ -mptcp_pm_create_subflow_or_signal_addr (msk); -} - -static void mptcp_pm_nl_subflow_established (struct mptcp_sock *msk) -{ -mptcp_pm_create_subflow_or_signal_addr (msk); -} - -/* Fill all the local addresses into the array addrs[], -* and return the array size. -*/ -static unsigned int fill_local_addresses_vec (struct mptcp_sock *msk, - struct mptcp_addr_info*remote,
net/mptcp/pm_netlink.c +0
-1- struct mptcp_pm_local*locals)
net/mptcp/pm_netlink.c +0
-15-{ -struct sock *sk = (struct sock *)msk; -struct mptcp_pm_addr_entry *entry; -struct mptcp_addr_info mpc_addr; -struct pm_nl_pernet *pernet; -unsigned int subflows_max; -int i =0 ; - - pernet =pm_nl_get_pernet_from_msk (msk); - subflows_max =mptcp_pm_get_subflows_max (msk); - -mptcp_local_address ((struct sock_common *)msk, &mpc_addr); - -rcu_read_lock (); - list_for_each_entry_rcu(entry, &pernet->local_addr_list,list) {
net/mptcp/pm_netlink.c +0
-4-if (!(entry->flags &MPTCP_PM_ADDR_FLAG_FULLMESH )) -continue ; - - if (!mptcp_pm_addr_families_match(sk, &entry->addr,remote))
net/mptcp/pm_netlink.c +0
-8-continue ; - -if (msk->pm.subflows < subflows_max) { - locals[i].addr = entry->addr; - locals[i].flags = entry->flags; - locals[i].ifindex = entry->ifindex; - -/* Special case for ID0: set the correct ID */
net/mptcp/pm_netlink.c +0
-1- if (mptcp_addresses_equal(&locals[i].addr,
&mpc_addr, locals[i].addr.port))net/mptcp/pm_netlink.c +0
-17- locals[i].addr.id =0 ; - - msk->pm.subflows++; - i++; - } - } -rcu_read_unlock (); - -/* If the array is empty, fill in the single -* 'IPADDRANY' local address -*/ -if (!i) { -memset (&locals[i],0 ,sizeof (locals[i])); - locals[i].addr.family = -#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) - remote->family == AF_INET6 && - ipv6_addr_v4mapped(&remote->addr6) ?
AF_INET:net/mptcp/pm_netlink.c +0
-4-#endif - remote->family; - - if (!mptcp_pm_addr_families_match(sk,&locals[i].addr, remote))
net/mptcp/pm_netlink.c +0
-47-return 0 ; - - msk->pm.subflows++; - i++; - } - -return i; -} - -static void mptcp_pm_nl_add_addr_received (struct mptcp_sock *msk) -{ -struct mptcp_pm_local locals[MPTCP_PM_ADDR_MAX ]; -struct sock *sk = (struct sock *)msk; -unsigned int add_addr_accept_max; -struct mptcp_addr_info remote; -unsigned int subflows_max; -bool sf_created = false; -int i, nr; - - add_addr_accept_max =mptcp_pm_get_add_addr_accept_max (msk); - subflows_max =mptcp_pm_get_subflows_max (msk); - -pr_debug ("accepted %d:%d remote family %d\n" , - msk->pm.add_addr_accepted, add_addr_accept_max, - msk->pm.remote.family); - - remote = msk->pm.remote; -mptcp_pm_announce_addr (msk, &remote, true); -mptcp_pm_addr_send_ack (msk); - -if (lookup_subflow_by_daddr (&msk->conn_list, &remote)) -return ; - -/* pick id 0 port, if none is provided the remote address */ -if (!remote.port) - remote.port = sk->sk_dport; - -/* connect to the specified remote address, using whatever -* local address the routing configuration will pick. -*/ - nr =fill_local_addresses_vec (msk, &remote, locals); -if (nr ==0 ) -return ; - -spin_unlock_bh (&msk->pm.lock); -for (i =0 ; i < nr; i++) - if (__mptcp_subflow_connect(sk, &locals[i], &remote)== 0)
net/mptcp/pm_netlink.c +0
-8- sf_created = true; -spin_lock_bh (&msk->pm.lock); - -if (sf_created) { -/* add_addr_accepted is not decr for ID 0 */ -if (remote.id) - msk->pm.add_addr_accepted++; - if (msk->pm.add_addr_accepted >= add_addr_accept_max||
net/mptcp/pm_netlink.c +0
-7- msk->pm.subflows >= subflows_max) -WRITE_ONCE (msk->pm.accept_addr, false); - } -} - -bool mptcp_pm_nl_is_init_remote_addr (struct mptcp_sock *msk, - const struct mptcp_addr_info*remote)
net/mptcp/pm_netlink.c +0
-5-{ -struct mptcp_addr_info mpc_remote; - -remote_address ((struct sock_common *)msk, &mpc_remote); - return mptcp_addresses_equal(&mpc_remote, remote, remote-Quoted 1 line
port);
net/mptcp/pm_netlink.c +0
-17-} - -void mptcp_pm_addr_send_ack (struct mptcp_sock *msk) -{ -struct mptcp_subflow_context *subflow, *alt =NULL ; - -msk_owned_by_me (msk); -lockdep_assert_held (&msk->pm.lock); - -if (!mptcp_pm_should_add_signal (msk) && - !mptcp_pm_should_rm_signal(msk)) -return ; - -mptcp_for_each_subflow (msk, subflow) { -if (__mptcp_subflow_active (subflow)) { -if (!subflow->stale) { - mptcp_pm_send_ack(msk, subflow,false, false);
net/mptcp/pm_netlink.c +0
-26-return ; - } - -if (!alt) - alt = subflow; - } - } - -if (alt) -mptcp_pm_send_ack (msk, alt, false, false); -} - -int mptcp_pm_mp_prio_send_ack (struct mptcp_sock *msk, - struct mptcp_addr_info *addr, - struct mptcp_addr_info *rem, - u8 bkup) -{ -struct mptcp_subflow_context *subflow; - -pr_debug ("bkup=%d\n" , bkup); - -mptcp_for_each_subflow (msk, subflow) { -struct sock *ssk =mptcp_subflow_tcp_sock (subflow); -struct mptcp_addr_info local, remote; - - mptcp_local_address((struct sock_common *)ssk,&local);
net/mptcp/pm_netlink.c +0
-1- if (!mptcp_addresses_equal(&local, addr, addr-Quoted 1 line
port))
net/mptcp/pm_netlink.c +0
-4-continue ; - -if (rem && rem->family !=AF_UNSPEC ) { - remote_address((struct sock_common *)ssk,&remote);
net/mptcp/pm_netlink.c +0
-1- if (!mptcp_addresses_equal(&remote, rem,
rem->port))net/mptcp/pm_netlink.c +0
-12-continue ; - } - -__mptcp_pm_send_ack (msk, subflow, true, bkup); -return 0 ; - } - -return -EINVAL ; -} - -static void mptcp_pm_rm_addr_or_subflow (struct mptcp_sock *msk, - const struct mptcp_rm_list
*rm_list,net/mptcp/pm_netlink.c +0
-1-enum linux_mptcp_mib_field
rm_type)net/mptcp/pm_netlink.c +0
-7-{ -struct mptcp_subflow_context *subflow, *tmp; -struct sock *sk = (struct sock *)msk; -u8 i; - - pr_debug("%s rm_list_nr %d\n", - rm_type == MPTCP_MIB_RMADDR ? "address" :"subflow",
rm_list->nr);net/mptcp/pm_netlink.c +0
-18- -msk_owned_by_me (msk); - -if (sk->sk_state ==TCP_LISTEN ) -return ; - -if (!rm_list->nr) -return ; - -if (list_empty (&msk->conn_list)) -return ; - -for (i =0 ; i < rm_list->nr; i++) { -u8 rm_id = rm_list->ids[i]; -bool removed = false; - -mptcp_for_each_subflow_safe (msk, subflow, tmp) { - struct sock *ssk =
mptcp_subflow_tcp_sock(subflow);net/mptcp/pm_netlink.c +0
-1- u8 remote_id = READ_ONCE(subflow-Quoted 1 line
remote_id);net/mptcp/pm_netlink.c +0
-5-int how =RCV_SHUTDOWN |SEND_SHUTDOWN ; -u8 id =subflow_get_local_id (subflow); - - if ((1 << inet_sk_state_load(ssk)) & - (TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2 |
TCPF_CLOSING|TCPF_CLOSE))net/mptcp/pm_netlink.c +0
-2-continue ; - if (rm_type == MPTCP_MIB_RMADDR && remote_id!=
rm_id)net/mptcp/pm_netlink.c +0
-2-continue ; - if (rm_type == MPTCP_MIB_RMSUBFLOW && id !=
rm_id)net/mptcp/pm_netlink.c +0
-3-continue ; - - pr_debug(" -> %s rm_list_ids[%d]=%ulocal_id=%u remote_id=%u mpc_id=%u\n",
net/mptcp/pm_netlink.c +0
-1- rm_type == MPTCP_MIB_RMADDR ?"address" : "subflow",
net/mptcp/pm_netlink.c +0
-1- i, rm_id, id, remote_id, msk-Quoted 1 line
mpc_endpoint_id);net/mptcp/pm_netlink.c +0
-5-spin_unlock_bh (&msk->pm.lock); -mptcp_subflow_shutdown (sk, ssk, how); - removed |= subflow->request_join; - -/* the following takes care of updating the subflows counter */
net/mptcp/pm_netlink.c +0
-5-mptcp_close_ssk (sk, ssk, subflow); -spin_lock_bh (&msk->pm.lock); - -if (rm_type ==MPTCP_MIB_RMSUBFLOW ) - __MPTCP_INC_STATS(sock_net(sk),
rm_type);net/mptcp/pm_netlink.c +0
-14- } - -if (rm_type ==MPTCP_MIB_RMADDR ) -__MPTCP_INC_STATS (sock_net (sk), rm_type); - -if (!removed) -continue ; - -if (!mptcp_pm_is_kernel (msk)) -continue ; - -if (rm_type ==MPTCP_MIB_RMADDR && rm_id && - !WARN_ON_ONCE(msk->pm.add_addr_accepted == 0)) { -/* Note: if the subflow has been closed before, this
net/mptcp/pm_netlink.c +0
-1-* add_addr_accepted counter will not be decremented.
net/mptcp/pm_netlink.c +0
-2-*/ - if (--msk->pm.add_addr_accepted <
mptcp_pm_get_add_addr_accept_max(msk))net/mptcp/pm_netlink.c +0
-1- WRITE_ONCE(msk->pm.accept_addr,true);
net/mptcp/pm_netlink.c +0
-7- } - } -} - -static void mptcp_pm_rm_addr_recv (struct mptcp_sock *msk) -{ - mptcp_pm_rm_addr_or_subflow(msk, &msk->pm.rm_list_rx,
MPTCP_MIB_RMADDR);net/mptcp/pm_netlink.c +0
-4-} - -static void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk, - const struct
mptcp_rm_list*rm_list)net/mptcp/pm_netlink.c +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
MPTCP_MIB_RMSUBFLOW);net/mptcp/pm_netlink.c +0
-25Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
MPTCP_PM_ADDR_FLAG_SUBFLOW)) ==net/mptcp/pm_netlink.c +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*entry)
net/mptcp/pm_netlink.c +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*pernet,
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mptcp_pm_addr_entry*entry,net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
replace)
net/mptcp/pm_netlink.c +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
address ID,
net/mptcp/pm_netlink.c +0
-14Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
only
net/mptcp/pm_netlink.c +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 1 line
addr.port)) {
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
if such
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
space
net/mptcp/pm_netlink.c +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
MPTCP_PM_ADDR_FLAG_IMPLICIT)) {net/mptcp/pm_netlink.c +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
the local
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
allows them to
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
packet recv
net/mptcp/pm_netlink.c +0
-19Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 1 line
id_bitmap,net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
MPTCP_PM_MAX_ADDR_ID+ 1,net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 1 line
next_id);net/mptcp/pm_netlink.c +0
-16Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
1);
net/mptcp/pm_netlink.c +0
-9Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 1 line
local_addr_list);net/mptcp/pm_netlink.c +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 1 line
local_addr_list);net/mptcp/pm_netlink.c +0
-18Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mptcp_pm_addr_entry*entry)net/mptcp/pm_netlink.c +0
-10Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 1 line
lsk);
net/mptcp/pm_netlink.c +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
msk one
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
a kernel
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
_nestednet/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
the msk
net/mptcp/pm_netlink.c +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
"mlock-AF_INET",
net/mptcp/pm_netlink.c +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
: "msk_lock-AF_INET",
net/mptcp/pm_netlink.c +0
-9Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 1 line
addr.family);
net/mptcp/pm_netlink.c +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
addrlen);
net/mptcp/pm_netlink.c +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
addrlen);
net/mptcp/pm_netlink.c +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
be called
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
bring
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
because the
net/mptcp/pm_netlink.c +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
MPTCP_EVENT_LISTENER_CREATED);net/mptcp/pm_netlink.c +0
-28Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
false);
net/mptcp/pm_netlink.c +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mptcp_addr_info*skc)net/mptcp/pm_netlink.c +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
pm_nl_get_pernet_from_msk(msk);net/mptcp/pm_netlink.c +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
MPTCP_PM_ADDR_FLAG_BACKUP);net/mptcp/pm_netlink.c +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
#define MPTCP_PM_CMD_GRP_OFFSET 0
#define MPTCP_PM_EV_GRP_OFFSET 1net/mptcp/pm_netlink.c +0
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
-voidmptcp_pm_nl_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
+static voidmptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp)
{net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mptcp_subflow_ctx(ssk);net/mptcp/pm_netlink.c +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 1 line
stale_count<=stale_loss_cnt)net/mptcp/pm_netlink.c +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
this subflow as idle ...*/
net/mptcp/pm_netlink.c +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
MPTCP_MIB_SUBFLOWSTALE);net/mptcp/pm_netlink.c +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
regardless of re-injections:
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
and subflow selection
net/mptcp/pm_netlink.c +2
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gfp);
}
static intmptcp_pm_family_to_addr(int family)net/mptcp/pm_netlink.c +0
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
net/mptcp/pm_netlink.c +1
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*addr,
net/mptcp/pm_netlink.c +1
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
{
net/mptcp/pm_netlink.c +3
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
}
net/mptcp/pm_netlink.c +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mptcp_addr_info*addr)net/mptcp/pm_netlink.c +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
!= NULL) {
net/mptcp/pm_netlink.c +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
with a != ID */
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
&mpc_addr);net/mptcp/pm_netlink.c +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 1 line
port))
net/mptcp/pm_netlink.c +0
-19Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
attr,
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
info->extack) &&net/mptcp/pm_netlink.c +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*info)
net/mptcp/pm_netlink.c +0
-17Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
subflow when using port");
net/mptcp/pm_netlink.c +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
and fullmesh");
net/mptcp/pm_netlink.c +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
endpoint");
net/mptcp/pm_netlink.c +0
-12Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
entry);
net/mptcp/pm_netlink.c +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
socket error: %d", ret);
net/mptcp/pm_netlink.c +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
!mptcp_pm_has_addr_attr_id(attr, info),net/mptcp/pm_netlink.c +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
duplicate one: %d", ret);
net/mptcp/pm_netlink.c +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
&entry->addr);net/mptcp/pm_netlink.c +0
-9Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*addr)
net/mptcp/pm_netlink.c +0
-14Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*addr)
net/mptcp/pm_netlink.c +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*addr,
net/mptcp/pm_netlink.c +0
-12Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 1 line
pm.id_avail_bitmap);
net/mptcp/pm_netlink.c +0
-9Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
id)
net/mptcp/pm_netlink.c +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
local_addr_used*/net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 1 line
pm.id_avail_bitmap) &&
net/mptcp/pm_netlink.c +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mptcp_pm_addr_entry*entry)net/mptcp/pm_netlink.c +0
-9Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
!= NULL) {
net/mptcp/pm_netlink.c +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 1 line
conn_list, addr);net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
&&
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
MPTCP_PM_ADDR_FLAG_IMPLICIT));net/mptcp/pm_netlink.c +0
-11Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
list.ids[0]);
net/mptcp/pm_netlink.c +0
-17Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*addr)
net/mptcp/pm_netlink.c +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
!= NULL) {
net/mptcp/pm_netlink.c +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mptcp_pm_is_userspace(msk))net/mptcp/pm_netlink.c +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
&msk_local);net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 1 line
port))
net/mptcp/pm_netlink.c +0
-19Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*info)
net/mptcp/pm_netlink.c +0
-16Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
the msk
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
different zero
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
in
id_bitmap.net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
code.
net/mptcp/pm_netlink.c +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 1 line
sk), &addr.addr);
net/mptcp/pm_netlink.c +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
found");
net/mptcp/pm_netlink.c +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
1);
net/mptcp/pm_netlink.c +0
-12Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
entry);
net/mptcp/pm_netlink.c +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*msk,
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*rm_list)net/mptcp/pm_netlink.c +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
};
net/mptcp/pm_netlink.c +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
&entry->addr))net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mptcp_endp_get_local_id(msk, &entry->addr);net/mptcp/pm_netlink.c +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 1 line
addr))
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mptcp_endp_get_local_id(msk, &entry->addr);net/mptcp/pm_netlink.c +0
-10Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
before */
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
1);
net/mptcp/pm_netlink.c +0
-14Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
!= NULL) {
net/mptcp/pm_netlink.c +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
rm_list);net/mptcp/pm_netlink.c +0
-30Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
genl_info*info)net/mptcp/pm_netlink.c +2
-18Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
{
structmptcp_addr_info*addr =&entry->addr; struct nlattr *attr;net/mptcp/pm_netlink.c +0
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
net/mptcp/pm_netlink.c +1
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*info)
{net/mptcp/pm_netlink.c +0
-37Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
< 0)
net/mptcp/pm_netlink.c +0
-12Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*limit)
net/mptcp/pm_netlink.c +0
-10Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
(%u)",
net/mptcp/pm_netlink.c +0
-7Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
genl_info*info)net/mptcp/pm_netlink.c +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
&rcv_addrs);net/mptcp/pm_netlink.c +0
-17Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
genl_info*info)net/mptcp/pm_netlink.c +2
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
struct
sk_buff*msg;
void *reply;net/mptcp/pm_netlink.c +9
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
msg =nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg)
return-ENOMEM;
reply = genlmsg_put_reply(msg, info,&mptcp_genl_family, 0,net/mptcp/pm_netlink.c +3
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
message");
net/mptcp/pm_netlink.c +1
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
goto fail;
net/mptcp/pm_netlink.c +1
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
net/mptcp/pm_netlink.c +3
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
found");
goto fail;net/mptcp/pm_netlink.c +1
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
net/mptcp/pm_netlink.c +2
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
goto fail;
genlmsg_end(msg, reply);net/mptcp/pm_netlink.c +2
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
fail:net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
message");
nlmsg_free(msg);net/mptcp/pm_netlink.c +1
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
}
net/mptcp/pm_netlink.c +3
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
{
net/mptcp/pm_netlink.c +1
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
net/mptcp/pm_netlink.c +0
-14Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
MPTCP_PM_ADDR_FLAG_SUBFLOW);net/mptcp/pm_netlink.c +0
-8Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
!= NULL) {
net/mptcp/pm_netlink.c +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mptcp_pm_is_userspace(msk))net/mptcp/pm_netlink.c +0
-5Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
NULL, bkup);
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
flag is set */
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
MPTCP_PM_ADDR_FLAG_FULLMESH))net/mptcp/pm_netlink.c +0
-35Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 1 line
addr.id) :
net/mptcp/pm_netlink.c +0
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
found");
net/mptcp/pm_netlink.c +4
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
return
-EINVAL;net/mptcp/pm_netlink.c +0
-6Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
addr flags");
net/mptcp/pm_netlink.c +3
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
return
-EINVAL;
}net/mptcp/pm_netlink.c +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
mask);
net/mptcp/pm_netlink.c +1
-4Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
return 0;
}
-static voidmptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp)
+static intmptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb)
{net/mptcp/pm_netlink.c +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
gfp);
net/mptcp/pm_netlink.c +16
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
AF_UNSPEC}, };net/mptcp/pm_netlink.c +17
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
*info)
net/mptcp/pm_netlink.c +2
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
}
boolmptcp_userspace_pm_active(const struct mptcp_sock *msk)net/mptcp/pm_netlink.c +0
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
};
net/mptcp/pm_netlink.c +0
-14Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
zeroed at
net/mptcp/pm_netlink.c +0
-14Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
with
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
for a
net/mptcp/pm_netlink.c +0
-17Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
subsystem.\n");
net/mptcp/pm_netlink.c +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
family\n");
net/mptcp/pm_netlink.c +0
-1Lines of this file are not shown. View the raw message.
net/mptcp/protocol.h +0
-0The rest of this diff is not shown. View the raw message.
index
8742527196887598eb242c82f06004107d29ef92..380b61be4cf65bc42f791bf2254c8a2b4aa333fe100644net/mptcp/protocol.h +0
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
boolmptcp_addresses_equal(const struct mptcp_addr_info *a, const struct mptcp_addr_info *b, bool use_port);
-voidmptcp_local_address(const struct sock_common *skc, struct mptcp_addr_info *addr);net/mptcp/protocol.h +4
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
/* called with sk socket lock held */
int __mptcp_subflow_connect(struct sock *sk, const structmptcp_pm_local*local,net/mptcp/protocol.h +0
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
const struct
mptcp_addr_info*rem);
voidmptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk);
-voidmptcp_pm_nl_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk);
voidmptcp_pm_new_connection(struct mptcp_sock *msk, const struct sock *ssk, int server_side);
voidmptcp_pm_fully_established(struct mptcp_sock *msk, const struct sock *ssk);
boolmptcp_pm_allow_new_subflow(struct mptcp_sock *msk);net/mptcp/protocol.h +4
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
I propose to add a new patch to rearrange the function declarations in this header, grouping the functions in pm.c together, and grouping the functions in pm_netlink.c, pm_userspace.c, and pm_kernel.c separately. WDYT?
Thanks,
-Geliang
Quoted 37 lines
net/mptcp/protocol.h +2
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
const struct
mptcp_rm_list*rm_list); voidmptcp_pm_mp_prio_received(struct sock *sk, u8 bkup);net/mptcp/protocol.h +0
-1Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
bool
mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk);
structmptcp_pm_add_entry* mptcp_pm_del_add_timer(structmptcp_sock*msk,
const structmptcp_addr_info*addr, boolcheck_id);net/mptcp/protocol.h +0
-3Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
bool
mptcp_lookup_subflow_by_saddr(const struct list_head *list, const struct mptcp_addr_info *saddr);
bool mptcp_remove_anno_list_by_saddr(structmptcp_sock*msk,net/mptcp/protocol.h +0
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
void mptcp_fastopen_subflow_synack_set_params(structmptcp_subflow_context*subflow,
structrequest_sock*req);net/mptcp/protocol.h +0
-2Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
int
mptcp_pm_genl_fill_addr(struct sk_buff *msg, struct netlink_callback *cb, struct mptcp_pm_addr_entry *entry);
Part of the diff is not shown here. View the raw message.
Matthieu Baerts
maintainerHi Geliang,
Quoted 1 line · Geliang Tang
Thanks for this set, it's useful for me to implement
mptcp_pm_ops.
Great, I hope it is!
I will move the renaming to different patches as you suggested.
Quoted 1 line · On Thu, 2025-02-27 at 21:08 +0100, Matthieu Baerts (NGI0) wrote:
(...)
Quoted 6 lines
Quoted 6 lines
net/mptcp/protocol.h +0
-0index
8742527196887598eb242c82f06004107d29ef92..380b61be4cf65bc42f791bf2254c8a2b4aa333fe100644net/mptcp/protocol.h +0
-0
(...)
Quoted 8 lines
Quoted 8 lines
void
mptcp_pm_add_addr_echoed(struct mptcp_sock *msk, const struct mptcp_addr_info *addr);net/mptcp/protocol.h +0
-3-void mptcp_pm_add_addr_send_ack (struct mptcp_sock *msk); -bool mptcp_pm_nl_is_init_remote_addr (struct mptcp_sock *msk, - const struct mptcp_addr_info*remote);
net/mptcp/protocol.h +2
-0+void mptcp_pm_send_ack(struct mptcp_sock *msk, + struct mptcp_subflow_context *subflow,
Quoted 8 lines
Quoted 3 lines
net/mptcp/protocol.h +1
-0+ bool prio, bool backup);void
mptcp_pm_addr_send_ack(struct mptcp_sock *msk); +voidmptcp_pm_nl_rm_addr(struct mptcp_sock *msk, u8 rm_id);I propose to add a new patch to rearrange the function declarations in this header, grouping the functions in
pm.ctogether, and grouping the functions inpm_netlink.c,pm_userspace.c, andpm_kernel.cseparately. WDYT?
I don't know: I think protocol.h is a bit of a mess, not only around the pm files. We should have probably added one header file per associated .c one from the beginning.
It is then tempting to re-order that too, but I think it is too late: if we do that for all files, that will cause conflicts during backports, and conflicts in such files will be a nightmare I think, easy to miss one or something like that.
At the end, protocol.h just contains a lot of function signatures, semi ordered, and we can probably live with it. I don't think it is then worth it to reorder it now, I don't think that will help with the long term maintenance. WDYT?
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerQuoted 152 lines · On Thu, 2025-02-27 at 21:08 +0100, Matthieu Baerts (NGI0) wrote:
Before this patch, the PM code was dispersed in different places:
-
pm.chad common code for all PMs-
pm_netlink.cwas supposed to be about the in-kernel PM, but also had
exported common helpers, callbacks used by the different PMs, NL events for PM userspace daemon, etc. quite confusing.-
pm_userspace.chad userspace PM only code, but using specific in-kernel PM helpersTo clarify the code, a reorganisation is suggested here, only by moving
code around, and small helper renaming to avoid confusions:-
pm_netlink.cnow only contains common PM Netlink code:
- PM events: this code was already there
- shared helpers around Netlink code that were already there as well
- shared Netlink commands code frompm.c-
pm_kernel.cnow contains only code that is specific to the in- kernel
PM. Now all functions are either called from:
-pm.c: events coming from the core, when this PM is being used
-pm_netlink.c: for shared Netlink commands
-mptcp_pm_gen.c: for Netlink commands specific to the in-kernel PM
-sockopt.c: for the exported counters per netns
- (while at it, two checkpatch warnings have been fixed: remove unneeded return, and the duplicated condition before akfree())-
pm.cgot many code frompm_netlink.c:
- helpers used from both PMs and not linked to Netlink
- callbacks used by different PMs, e.g.ADD_ADDRmanagement
- some helpers have been renamed to remove the '_nl' prefix, and they
have been marked as 'static'.-
protocol.hhas been updated accordingly:
- some helpers no longer need to be exported
- new ones needed to be exported: they have been prefixed if needed.The code around the PM is now less confusing, which should help for the
maintenance in the long term.This will certainly impact future backports, but because other cleanups
have already done recently, and more are coming to ease the addition of
a new path-manager controlled with BPF (struct_ops), doing that now seems to be a good time. Also, many issues around the PM have been fixed
a few months ago while increasing the code coverage in the selftests, so
such big reorganisation can be done with more confidence now.No behavioural changes intended.
Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
net/mptcp/Makefile | 2 +-
net/mptcp/pm.c | 664 +++++++++++++---- net/mptcp/pm_kernel.c | 1410 +++++++++++++++++++++++++++++++++++net/mptcp/pm_netlink.c| 1917 +++-----------------------------------
----------
net/mptcp/protocol.h | 21 +-5 files changed, 2009 insertions(+), 2005 deletions(-)net/mptcp/Makefile +0
-0index
5dbc37d38d7a4b0779c71e7b291ef83a49e46648..bd72b300a0f68fa862bcae5aa1e1e913f595f315100644net/mptcp/Makefile +0
-0@@ -3,7 +3,7 @@ obj-$(CONFIG_MPTCP) += mptcp.o
mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o \
mib.o pm_netlink.o sockopt.o pm_userspace.o fastopen.o sched.o \net/mptcp/Makefile +1
-1- mptcp_pm_gen.o + mptcp_pm_gen.o pm_kernel.o
obj-$(CONFIG_SYN_COOKIES) += syncookies.o
obj-$(CONFIG_INET_MPTCP_DIAG) += mptcp_diag.onet/mptcp/pm.c +0
-0index
c17828981dd6400b2ed74dd28a95e21f76ed37b9..8b9117abbe7cd22e8770810e9d5aeb9ee0e001e6100644net/mptcp/pm.c +0
-0@@ -5,12 +5,399 @@*/ #define pr_fmt(fmt) "MPTCP: " fmtnet/mptcp/pm.c +0
-2-#include <linux/kernel.h> -#include <net/mptcp.h> #include "
protocol.h"
-
#include "mib.h"net/mptcp/pm.c +15
-1-#include "mptcp_pm_gen.h" + +#define ADD_ADDR_RETRANS_MAX 3 + +struct mptcp_pm_add_entry { +struct list_head list; +struct mptcp_addr_info addr; +u8 retrans_times; +struct timer_list add_timer; +struct mptcp_sock *sock; +}; + +/* path manager helpers */ + +bool mptcp_addresses_equal (const struct mptcp_addr_info *a, + const struct mptcp_addr_info *b, bool
use_port)net/mptcp/pm.c +6
-0+{ +bool addr_equals = false; + +if (a->family == b->family) { +if (a->family ==AF_INET ) + addr_equals = a->addr.s_addr == b-Quoted 1 line
addr.s_addr;
net/mptcp/pm.c +3
-0+#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) + else + addr_equals = ipv6_addr_equal(&a->addr6, &b-Quoted 1 line
addr6);
net/mptcp/pm.c +3
-0+ }else if (a->family ==AF_INET ) { +if (ipv6_addr_v4mapped (&b->addr6)) + addr_equals = a->addr.s_addr == b-Quoted 1 line
addr6.s6_addr32[3];
net/mptcp/pm.c +3
-0+ }else if (b->family ==AF_INET ) { +if (ipv6_addr_v4mapped (&a->addr6)) + addr_equals = a->addr6.s6_addr32[3] == b-Quoted 1 line
addr.s_addr;
net/mptcp/pm.c +13
-0+#endif + } + +if (!addr_equals) +return false; +if (!use_port) +return true; + +return a->port == b->port; +} + +void mptcp_remote_address (const struct sock_common *skc, + struct mptcp_addr_info *addr)
net/mptcp/pm.c line 62
Quoted 10 lines
net/mptcp/pm.c +10
-0+{ + addr->family = skc->skc_family; + addr->port = skc->skc_dport; +if (addr->family ==AF_INET ) + addr->addr.s_addr = skc->skc_daddr; +#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) + else if (addr->family == AF_INET6) + addr->addr6 = skc->skc_v6_daddr; +#endif +}
nit: remote_address() is after mptcp_local_address() in pm_netlink.c, how about keeping this order after moving here?
Quoted 15 lines
net/mptcp/pm.c +14
-0+ +void mptcp_local_address (const struct sock_common *skc, +struct mptcp_addr_info *addr) +{ + addr->family = skc->skc_family; + addr->port =htons (skc->skc_num); +if (addr->family ==AF_INET ) + addr->addr.s_addr = skc->skc_rcv_saddr; +#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) + else if (addr->family == AF_INET6) + addr->addr6 = skc->skc_v6_rcv_saddr; +#endif +} +
... ...
Quoted 14 lines
net/mptcp/protocol.h +0
-0index
8742527196887598eb242c82f06004107d29ef92..380b61be4cf65bc42f791bf2254c8a2b4aa333fe100644net/mptcp/protocol.h +0
-0@@ -729,7 +729,10 @@ void mptcp_set_state(struct sock *sk, int state);
boolmptcp_addresses_equal(const struct mptcp_addr_info *a, const struct mptcp_addr_info *b, bool use_port);
-voidmptcp_local_address(const struct sock_common *skc, struct mptcp_addr_info *addr);
net/mptcp/protocol.h void mptcp_set_state(struct sock *sk, int state); · line 735
Quoted 4 lines
net/mptcp/protocol.h +4
-0+void mptcp_remote_address (const struct sock_common *skc, + struct mptcp_addr_info *addr); +void mptcp_local_address (const struct sock_common *skc, +struct mptcp_addr_info *addr);
Same here.
Thanks,
-Geliang
Quoted 2 lines
/* called with sk socket lock held */
Geliang Tang
reviewernet/mptcp/pm.c void mptcp_pm_subflow_chk_stale(const struct · line 940
Quoted 10 lines
void
mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)net/mptcp/pm.c +1
-1@@ -567,38 +936,13 @@ void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) } else if (subflow->stale_rcv_tstamp == rcv_tstamp) { if (subflow->stale_count < U8_MAX) subflow->stale_count++; -mptcp_pm_nl_subflow_chk_stale (msk, ssk); +mptcp_pm_subflows_chk_stale (msk, ssk);
mptcp_pm_nl_subflow_chk_stale() is renamed, a separate patch is needed.
Quoted 7 lines
net/mptcp/pm.c +0
-0} else { subflow->stale_count = 0; mptcp_subflow_set_active(subflow); } }
... ...
net/mptcp/pm_kernel.c line 1253
Quoted 6 lines
net/mptcp/pm_kernel.c new file +4
-0+} + +static void mptcp_pm_nl_set_flags_all (struct net *net, + struct mptcp_pm_addr_entry*local,
net/mptcp/pm_kernel.c new file +1
-0+ u8 changed)
mptcp_pm_nl_set_flags_all() is renamed, do this in a separate patch too.
Thanks,
-Geliang
Hi Matthieu,
Thank you for your modifications, that's great!
But sadly, our CI spotted some issues with it when trying to build it.
You can find more details there:
https://github.com/multipath-tcp/mptcp_net-next/actions/runs/13575269560
Status: failure
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/423721784d18
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=938681
Feel free to reply to this email if you cannot access logs, if you need some support to fix the error, if this doesn't seem to be caused by your modifications or if the error is a false positive one.
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Matthieu Baerts
maintainerHello,
27 Feb 2025 21:39:01 MPTCP CI <[email protected]>:
Quoted 5 lines
But sadly, our CI spotted some issues with it when trying to build it.
You can find more details there:
https://github.com/multipath-tcp/mptcp_net-next/actions/runs/13575269560
One of the errors is a false positive one, just because the ignore list needs to be adapted because two functions have been moved to another fine.
The other one is a small issue due to a last minute commit split, I can fix that in a v2 or when applying the patches.
Cheers,
Matt
Hi Matthieu,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/13575269556
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/423721784d18
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=938681
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Geliang Tang
reviewerHi Matt,
Quoted 41 lines · On Thu, 2025-02-27 at 21:08 +0100, Matthieu Baerts (NGI0) wrote:
I have been thinking about that during the past couple of months, but now, with the recent modifications done by Geliang, and the associated
reviews, I really think it is time to reorganise the code around the path-managers to avoid confusions, and a mix of code used in different
conditions.Here is a first proposition, feel free to comment! :)
Please look at the last patch for more details about the why and why now.
I hope this will not cause too many issues with the in-progress patches.
I tried only to move the code around, and minimise the functions renaming. Then, to switch to the new code, it might be easier to simply
copy your modified code from the old place to the new one. In other words, duplicate the net/mptcp directory, then do a rebase, resolve the
conflicts with 'git restore --ours', then reapply the modifications by
copying your old code to the new place. If it is too difficult, please
let me know.Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
Cc: Geliang Tang <[email protected]>---
Matthieu Baerts (NGI0) (7):
mptcp: pm: remove '_nl' frommptcp_pm_nl_addr_send_ack
mptcp: pm: remove '_nl' frommptcp_pm_nl_mp_prio_send_ack
mptcp: pm: remove '_nl' frommptcp_pm_nl_work
mptcp: pm: remove '_nl' frommptcp_pm_nl_rm_addr_or_subflow
mptcp: pm: avoid calling PM specific code from core
mptcp: pm: worker: split in-kernel and common tasks
mptcp: pm: code reorganisation
Quoted 5 lines
net/mptcp/Makefile | 2 +-
net/mptcp/pm.c | 685 ++++++++++++---- net/mptcp/pm_kernel.c | 1410 +++++++++++++++++++++++++++++++++ net/mptcp/pm_netlink.c | 1934 ++----------------------------------
----------
Patch 7 has too many changes to review, so I suggest splitting it into multiple small patches for review, and then merging them into a large patch after review.
I think it is possible to make "move the code from pm_netlink.c to pm.c" as a separate patch, and "move the code from pm_netlink.c to pm_kernel.c" as another separate patch. Moreover, these two patches only involve the movement of code, without any renaming or relocation of functions, and these changes should be done by separate patches.
In addition, we can try to keep the original positions of the functions that were originally in pm.c, such as mptcp_pm_addr_families_match, mptcp_pm_schedule_work, and mptcp_pm_add_addr_send_ack.
WDYT?
Thanks,
-Geliang
Quoted 9 lines
net/mptcp/pm_userspace.c | 11 +-
net/mptcp/protocol.c | 5 +-
net/mptcp/protocol.h | 37 +-7 files changed, 2051 insertions(+), 2033 deletions(-)---
base-commit:6b32949274eb9e32fe867ba9a8f8cb98587ecf36
change-id: 20250227-mptcp-pm-reorg-code-13227530bd05Best regards,
Matthieu Baerts
maintainerHi Geliang,
Quoted 48 lines · Geliang Tang
Quoted 41 lines · On Thu, 2025-02-27 at 21:08 +0100, Matthieu Baerts (NGI0) wrote:
I have been thinking about that during the past couple of months, but now, with the recent modifications done by Geliang, and the associated
reviews, I really think it is time to reorganise the code around the path-managers to avoid confusions, and a mix of code used in different
conditions.Here is a first proposition, feel free to comment! :)
Please look at the last patch for more details about the why and why now.
I hope this will not cause too many issues with the in-progress patches.
I tried only to move the code around, and minimise the functions renaming. Then, to switch to the new code, it might be easier to simply
copy your modified code from the old place to the new one. In other words, duplicate the net/mptcp directory, then do a rebase, resolve the
conflicts with 'git restore --ours', then reapply the modifications by
copying your old code to the new place. If it is too difficult, please
let me know.Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
Cc: Geliang Tang <[email protected]>---
Matthieu Baerts (NGI0) (7):
mptcp: pm: remove '_nl' frommptcp_pm_nl_addr_send_ack
mptcp: pm: remove '_nl' frommptcp_pm_nl_mp_prio_send_ack
mptcp: pm: remove '_nl' frommptcp_pm_nl_work
mptcp: pm: remove '_nl' frommptcp_pm_nl_rm_addr_or_subflow
mptcp: pm: avoid calling PM specific code from core
mptcp: pm: worker: split in-kernel and common tasks
mptcp: pm: code reorganisationQuoted 5 lines
net/mptcp/Makefile | 2 +-
net/mptcp/pm.c | 685 ++++++++++++---- net/mptcp/pm_kernel.c | 1410 +++++++++++++++++++++++++++++++++ net/mptcp/pm_netlink.c | 1934 ++----------------------------------
----------
Quoted 3 lines
Patch 7 has too many changes to review, so I suggest splitting it into multiple small patches for review, and then merging them into a large patch after review.
Thank you for looking at that. If we split, maybe no need to merge them later.
Quoted 5 lines
I think it is possible to make "move the code from
pm_netlink.ctopm.c" as a separate patch, and "move the code frompm_netlink.ctopm_kernel.c" as another separate patch. Moreover, these two patches only involve the movement of code, without any renaming or relocation of functions, and these changes should be done by separate patches.
OK, I will try to do that.
Quoted 3 lines
In addition, we can try to keep the original positions of the functions that were originally in
pm.c, such asmptcp_pm_addr_families_match,mptcp_pm_schedule_work, andmptcp_pm_add_addr_send_ack.
I moved mptcp_pm_addr_families_match() to be with all the new "addr helpers" coming from pm_netlink.c. It looks better there. Maybe I can do the move in a separated patch.
For the two other helpers, that's because mptcp_pm_add_addr_send_ack() is now static, but called by code imported from pm_netlink.c. Maybe I can add a signature above to ease the review here. Would that be OK?
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerHi Matt,
Quoted 36 lines · Matthieu Baerts
Hi Geliang,
Quoted 33 lines · Geliang Tang
Quoted 32 lines · On Thu, 2025-02-27 at 21:08 +0100, Matthieu Baerts (NGI0) wrote:
I have been thinking about that during the past couple of months, but
now, with the recent modifications done by Geliang, and the associated
reviews, I really think it is time to reorganise the code around the
path-managers to avoid confusions, and a mix of code used in different
conditions.Here is a first proposition, feel free to comment! :)
Please look at the last patch for more details about the why and why
now.I hope this will not cause too many issues with the in-progress patches.
I tried only to move the code around, and minimise the functions renaming. Then, to switch to the new code, it might be easier to simply
copy your modified code from the old place to the new one. In other
words, duplicate the net/mptcp directory, then do a rebase, resolve
the
conflicts with 'git restore --ours', then reapply the modifications
by
copying your old code to the new place. If it is too difficult, please
let me know.
I have successfully rebased all of my in-progress patches on this set today.
Quoted 47 lines
Quoted 23 lines
Quoted 15 lines
Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
Cc: Geliang Tang <[email protected]>---
Matthieu Baerts (NGI0) (7):
mptcp: pm: remove '_nl' frommptcp_pm_nl_addr_send_ack
mptcp: pm: remove '_nl' frommptcp_pm_nl_mp_prio_send_ack
mptcp: pm: remove '_nl' frommptcp_pm_nl_work
mptcp: pm: remove '_nl' frommptcp_pm_nl_rm_addr_or_subflow
mptcp: pm: avoid calling PM specific code from core
mptcp: pm: worker: split in-kernel and common tasks
mptcp: pm: code reorganisationQuoted 7 lines
net/mptcp/Makefile | 2 +-
net/mptcp/pm.c | 685 ++++++++++++---- net/mptcp/pm_kernel.c | 1410
+++++++++++++++++++++++++++++++++
net/mptcp/pm_netlink.c | 1934 ++------------------------------
----
----------Quoted 5 lines
Patch 7 has too many changes to review, so I suggest splitting it into
multiple small patches for review, and then merging them into a large
patch after review.Thank you for looking at that. If we split, maybe no need to merge them
later.Quoted 6 lines
I think it is possible to make "move the code from
pm_netlink.ctopm.c" as a separate patch, and "move the code frompm_netlink.ctopm_kernel.c" as another separate patch. Moreover, these two patches only involve the movement of code, without any renaming or relocation
of functions, and these changes should be done by separate patches.OK, I will try to do that.
Quoted 4 lines
In addition, we can try to keep the original positions of the functions
that were originally inpm.c, such asmptcp_pm_addr_families_match,mptcp_pm_schedule_work, andmptcp_pm_add_addr_send_ack.
Quoted 7 lines
I moved
mptcp_pm_addr_families_match()to be with all the new "addr helpers" coming frompm_netlink.c. It looks better there. Maybe I can do
the move in a separated patch.For the two other helpers, that's because
mptcp_pm_add_addr_send_ack()
It's better not to change mptcp_pm_add_addr_send_ack() to static. There's such code in mptcp_pm_add_addr_received():
if (mptcp_pm_is_userspace(msk)) {
if (mptcp_userspace_pm_active(msk)) {
mptcp_pm_announce_addr(msk, addr, true);
mptcp_pm_add_addr_send_ack(msk);
} else {This part will be moved into pm_userspace.c later, then it will invoke mptcp_pm_add_addr_send_ack() from outside. So it's better to keep mptcp_pm_add_addr_send_ack() as it.
Thanks,
-Geliang
Quoted 5 lines
is now static, but called by code imported from
pm_netlink.c. Maybe I can add a signature above to ease the review here. Would that be OK?Cheers,
Matt
Matthieu Baerts
maintainerQuoted 40 lines · Geliang Tang
Hi Matt,
Quoted 36 lines · Matthieu Baerts
Hi Geliang,
Quoted 33 lines · Geliang Tang
Quoted 32 lines · On Thu, 2025-02-27 at 21:08 +0100, Matthieu Baerts (NGI0) wrote:
I have been thinking about that during the past couple of months, but
now, with the recent modifications done by Geliang, and the associated
reviews, I really think it is time to reorganise the code around the
path-managers to avoid confusions, and a mix of code used in different
conditions.Here is a first proposition, feel free to comment! :)
Please look at the last patch for more details about the why and why
now.I hope this will not cause too many issues with the in-progress patches.
I tried only to move the code around, and minimise the functions renaming. Then, to switch to the new code, it might be easier to simply
copy your modified code from the old place to the new one. In other
words, duplicate the net/mptcp directory, then do a rebase, resolve
the
conflicts with 'git restore --ours', then reapply the modifications
by
copying your old code to the new place. If it is too difficult, please
let me know.
Quoted 2 lines
I have successfully rebased all of my in-progress patches on this set today.
Great, I hope that didn't break too many things. If it did, hopefully, it was for good reasons!
Quoted 65 lines
Quoted 48 lines
Quoted 24 lines
Quoted 16 lines
Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
Cc: Geliang Tang <[email protected]>---
Matthieu Baerts (NGI0) (7):
mptcp: pm: remove '_nl' frommptcp_pm_nl_addr_send_ack
mptcp: pm: remove '_nl' frommptcp_pm_nl_mp_prio_send_ack
mptcp: pm: remove '_nl' frommptcp_pm_nl_work
mptcp: pm: remove '_nl' frommptcp_pm_nl_rm_addr_or_subflow
mptcp: pm: avoid calling PM specific code from core
mptcp: pm: worker: split in-kernel and common tasks
mptcp: pm: code reorganisationQuoted 7 lines
net/mptcp/Makefile | 2 +-
net/mptcp/pm.c | 685 ++++++++++++---- net/mptcp/pm_kernel.c | 1410
+++++++++++++++++++++++++++++++++
net/mptcp/pm_netlink.c | 1934 ++------------------------------
----
----------Quoted 5 lines
Patch 7 has too many changes to review, so I suggest splitting it into
multiple small patches for review, and then merging them into a large
patch after review.Thank you for looking at that. If we split, maybe no need to merge them
later.Quoted 6 lines
I think it is possible to make "move the code from
pm_netlink.ctopm.c" as a separate patch, and "move the code frompm_netlink.ctopm_kernel.c" as another separate patch. Moreover, these two patches only involve the movement of code, without any renaming or relocation
of functions, and these changes should be done by separate patches.OK, I will try to do that.
Quoted 4 lines
In addition, we can try to keep the original positions of the functions
that were originally inpm.c, such asmptcp_pm_addr_families_match,mptcp_pm_schedule_work, andmptcp_pm_add_addr_send_ack.Quoted 7 lines
I moved
mptcp_pm_addr_families_match()to be with all the new "addr helpers" coming frompm_netlink.c. It looks better there. Maybe I can do
the move in a separated patch.For the two other helpers, that's because
mptcp_pm_add_addr_send_ack()It's better not to change
mptcp_pm_add_addr_send_ack()to static. There's such code inmptcp_pm_add_addr_received():if (mptcp_pm_is_userspace(msk)) { if (mptcp_userspace_pm_active(msk)) { mptcp_pm_announce_addr(msk, addr, true); mptcp_pm_add_addr_send_ack(msk); } else {
Quoted 3 lines
This part will be moved into
pm_userspace.clater, then it will invokemptcp_pm_add_addr_send_ack()from outside. So it's better to keepmptcp_pm_add_addr_send_ack()as it.
OK, I can undo that.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.