mptcp: pm: in-kernel: usable client side with C-flag
Subsystems (3)
Matthieu Baerts (NGI0)
maintainercover mptcp: pm: in-kernel: usable client side with C-flag
When servers set the C-flag in their MP_CAPABLE to tell clients not to create subflows to the initial address and port, clients will likely not use their other endpoints. That's because the in-kernel path-manager uses the 'subflow' endpoints to create subflows only to the initial address and port.
The first patch fixes that, and the second one validates it.
More details: https://github.com/multipath-tcp/mptcp_net-next/issues/536
Please see the comment in the first patch, and don't hesitate to reply :)
---
Matthieu Baerts (NGI0) (2):
mptcp: pm: in-kernel: usable client side with C-flag
selftests: mptcp: join: validate C-flag + def limit
net/mptcp/pm.c | 9 ++++-- net/mptcp/pm_kernel.c | 40 +++++++++++++++++++++++++ tools/testing/selftests/net/mptcp/mptcp_join.sh | 11 +++++++ 3 files changed, 58 insertions(+), 2 deletions(-)
---
base-commit: 01d3ba86f43b6fe8e91cfd00ba178d6997095a04
change-id: 20250912-pm-c-flag-client-default-f676d8acfdc7
Best regards,
Signature · 1 line
Matthieu Baerts (NGI0) <[email protected]>
Matthieu Baerts (NGI0)
maintainerPATCH 1/2 mptcp: pm: in-kernel: usable client side with C-flag
When servers set the C-flag in their MP_CAPABLE to tell clients not to create subflows to the initial address and port, clients will likely not use their other endpoints. That's because the in-kernel path-manager uses the 'subflow' endpoints to create subflows only to the initial address and port.
If the limits have not been modified to accept ADD_ADDR, the client doesn't try to establish new subflows. If the limits accept ADD_ADDR, the routing routes will be used to select the source IP.
The C-flag is typically set when the server is operating behind a legacy Layer 4 load balancer, or using anycast IP address. Clients having their different 'subflow' endpoints setup, don't end up creating multiple subflows as expected, and causing some deployment issues.
A special case is then added here: when servers set the C-flag in the MPC and directly sends an ADD_ADDR, this single ADD_ADDR is accepted. The 'subflows' endpoints will then be used with this new remote IP and port. This exception is only allowed when the ADD_ADDR is sent immediately after the 3WHS, and makes the client switching to the 'fully established' mode. After that, 'select_local_address()' will not be able to find any subflows, because 'id_avail_bitmap' will be filled in mptcp_pm_create_subflow_or_signal_addr(), when switching to 'fully established' mode.
---
Notes:
- I tried to find a simple solution that can hopefully be backported to cover the 'CDN' use-case.
- I tried to find a solution respecting the 'accepted add addr' limit, but I don't see how to... That's why here I limit the exception a
maximum: when this limit is 0 (default case), only the first ADD_ADDR, etc. Feel free to share what you think about that.
- I have some additional code doing some cleanup, and I started to look at #503, which is a bit linked to that.
--- net/mptcp/pm.c | 7 +++++-- net/mptcp/pm_kernel.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-)
net/mptcp/pm.c +5 -2
@@ -637,9 +637,12 @@ void mptcp_pm_add_addr_received(const struct sock *ssk, }else {__MPTCP_INC_STATS (sock_net ((struct sock *)msk),MPTCP_MIB_ADDADDRDROP ); } -/* id0 should not have a different address */ +/* id0 should not have a different address ; special case for C-flag */ }else if ((addr->id ==0 && !mptcp_pm_is_init_remote_addr (msk, addr)) || - (addr->id >0 && !READ_ONCE (pm->accept_addr))) { + (addr->id >0 && !READ_ONCE (pm->accept_addr) && + (!READ_ONCE (msk->pm.remote_deny_join_id0) || + msk->pm.local_addr_used !=0 || +mptcp_pm_get_add_addr_accept_max (msk) !=0 ))) {mptcp_pm_announce_addr (msk, addr, true);mptcp_pm_add_addr_send_ack (msk); }else if (mptcp_pm_schedule_work (msk,MPTCP_PM_ADD_ADDR_RECEIVED )) {
net/mptcp/pm_kernel.c +39 -0
@@ -389,10 +389,15 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,struct mptcp_addr_info mpc_addr;struct pm_nl_pernet *pernet;unsigned int subflows_max; +bool deny_join_id0;int i =0 ; pernet =pm_nl_get_pernet_from_msk (msk); subflows_max =mptcp_pm_get_subflows_max (msk); + deny_join_id0 = remote->id &&READ_ONCE (msk->pm.remote_deny_join_id0) && + !READ_ONCE (msk->pm.accept_addr) && + msk->pm.local_addr_used ==0 && +mptcp_pm_get_add_addr_accept_max (msk) ==0 ;mptcp_local_address ((struct sock_common *)msk, &mpc_addr);
@@ -409,6 +414,9 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, locals[i].flags = entry->flags; locals[i].ifindex = entry->ifindex; +if (deny_join_id0) +__clear_bit (locals[i].addr.id, msk->pm.id_avail_bitmap); +/* Special case for ID0: set the correct ID */ if (mptcp_addresses_equal (&locals[i].addr, &mpc_addr, locals[i].addr.port)) locals[i].addr.id =0 ;
@@ -419,6 +427,37 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, }rcu_read_unlock (); +/* Special case: peer sets the C flag, accept one ADD_ADDR if default +* limits are used -- accepting no ADD_ADDR -- and use subflow endpoints +*/ +if (!i && deny_join_id0) { +unsigned int local_addr_max =mptcp_pm_get_local_addr_max (msk); + +while (msk->pm.local_addr_used < local_addr_max && + msk->pm.subflows < subflows_max) { +struct mptcp_pm_local *local = &locals[i]; + +if (!select_local_address (pernet, msk, local)) +break ; + +__clear_bit (local->addr.id, msk->pm.id_avail_bitmap); + +if (!mptcp_pm_addr_families_match (sk, &local->addr, + remote)) +continue ; + +if (mptcp_addresses_equal (&local->addr, &mpc_addr, + local->addr.port)) +continue ; + + msk->pm.local_addr_used++; + msk->pm.subflows++; + i++; + } + +return i; + } +/* If the array is empty, fill in the single * 'IPADDRANY' local address */
Signature · 1 line
2.51.0
Geliang Tang
reviewerHi Matt,
Thanks for this set. I have some comments below.
Quoted 72 lines · On Mon, 2025-09-15 at 20:11 +0200, Matthieu Baerts (NGI0) wrote:
When servers set the C-flag in their
MP_CAPABLEto tell clients not to
create subflows to the initial address and port, clients will likely not
use their other endpoints. That's because the in-kernel path-manager uses the 'subflow' endpoints to create subflows only to the initial address and port.If the limits have not been modified to accept
ADD_ADDR, the client doesn't try to establish new subflows. If the limits acceptADD_ADDR, the routing routes will be used to select the source IP.The C-flag is typically set when the server is operating behind a legacy
Layer 4 load balancer, or using anycast IP address. Clients having their
different 'subflow' endpoints setup, don't end up creating multiple subflows as expected, and causing some deployment issues.A special case is then added here: when servers set the C-flag in the MPC and directly sends an
ADD_ADDR, this singleADD_ADDRis accepted. The 'subflows' endpoints will then be used with this new remote IP and
port. This exception is only allowed when theADD_ADDRis sent immediately after the 3WHS, and makes the client switching to the 'fully
established' mode. After that, 'select_local_address()' will not be able
to find any subflows, because 'id_avail_bitmap' will be filled inmptcp_pm_create_subflow_or_signal_addr(), when switching to 'fully established' mode.Fixes df377be38725 ("mptcp: add deny_join_id0 in
mptcp_options_received")Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
Notes:
- I tried to find a simple solution that can hopefully be backported to
cover the 'CDN' use-case.
- I tried to find a solution respecting the 'accepted add addr' limit,
but I don't see how to... That's why here I limit the exception a
maximum: when this limit is 0 (default case), only the firstADD_ADDR,
etc. Feel free to share what you think about that.
- I have some additional code doing some cleanup, and I started to look
at #503, which is a bit linked to that.
---
net/mptcp/pm.c | 7 +++++--
net/mptcp/pm_kernel.c | 39 +++++++++++++++++++++++++++++++++++++++2 files changed, 44 insertions(+), 2 deletions(-)net/mptcp/pm.c +0
-0index
02dfb379417e2843301f121039ec0d370b040ef7..fda8d1880224dedbbfb20954f93a04da435346df100644net/mptcp/pm.c +0
-0@@ -637,9 +637,12 @@ void mptcp_pm_add_addr_received(const struct sock *ssk, } else {
__MPTCP_INC_STATS(sock_net((struct sock *)msk), MPTCP_MIB_ADDADDRDROP);
}net/mptcp/pm.c +1
-1-/* id0 should not have a different address */ +/* id0 should not have a different address ; special case for C-flag */
} else if ((addr->id== 0 &&
!mptcp_pm_is_init_remote_addr(msk, addr)) ||
net/mptcp/pm.c void mptcp_pm_add_addr_received(const struct sock *ssk, · line 645
Quoted 5 lines
net/mptcp/pm.c +4
-1- (addr->id > 0 && !READ_ONCE(pm->accept_addr))) { + (addr->id > 0 && !READ_ONCE(pm->accept_addr) && + (!READ_ONCE(msk->pm.remote_deny_join_id0) || + msk->pm.local_addr_used != 0 || + mptcp_pm_get_add_addr_accept_max(msk) != 0))) {
I think we can define an mptcp_pm_deny_join_id0(struct mptcp_sock *msk) helper, then use !mptcp_pm_deny_join_id0(msk) here, and use mptcp_pm_deny_join_id0(msk) in fill_local_addresses_vec().
For example:
static inline bool mptcp_pm_deny_join_id0(struct mptcp_sock *msk)
{
return (READ_ONCE(msk->pm.remote_deny_join_id0) &&
msk->pm.local_addr_used == 0 &&
mptcp_pm_get_add_addr_accept_max(msk) == 0);
}Quoted 22 lines
mptcp_pm_announce_addr(msk, addr, true);mptcp_pm_add_addr_send_ack(msk); } else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED)) {net/mptcp/pm_kernel.c +0
-0index
f30df8e884a0b3de9fb092e5774cafe08f6350ce..408801e20ed6e874b80ccbf38af76abc13615a3a100644net/mptcp/pm_kernel.c +1
-0@@ -389,10 +389,15 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, struct mptcp_addr_info mpc_addr; struct pm_nl_pernet *pernet; unsigned int subflows_max; +bool deny_join_id0; int i = 0;
pernet =pm_nl_get_pernet_from_msk(msk);subflows_max=mptcp_pm_get_subflows_max(msk);net/mptcp/pm_kernel.c +1
-0+ deny_join_id0 = remote->id && READ_ONCE(msk-Quoted 1 line
pm.remote_deny_join_id0) &&
net/mptcp/pm_kernel.c static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, · line 400
Quoted 3 lines
net/mptcp/pm_kernel.c +3
-0+ !READ_ONCE (msk->pm.accept_addr) && + msk->pm.local_addr_used ==0 && +mptcp_pm_get_add_addr_accept_max (msk) ==0 ;
I think it's unnecessary to check msk->pm.accept_addr again here, as it has already been verified in mptcp_pm_add_addr_received, which should be sufficient:
deny_join_id0 = remote->id && mptcp_pm_deny_join_id0(msk);
Quoted 29 lines
mptcp_local_address((struct sock_common *)msk, &mpc_addr);net/mptcp/pm_kernel.c +0
-0@@ -409,6 +414,9 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, locals[i].flags = entry->flags; locals[i].ifindex = entry->ifindex;net/mptcp/pm_kernel.c +2
-0+if (deny_join_id0) + __clear_bit(locals[i].addr.id, msk-Quoted 1 line
pm.id_avail_bitmap);
+
/* Special case for ID0: set the correct ID */
if (mptcp_addresses_equal(&locals[i].addr, &mpc_addr, locals[i].addr.port))
locals[i].addr.id = 0;net/mptcp/pm_kernel.c +0
-0@@ -419,6 +427,37 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, } rcu_read_unlock();net/mptcp/pm_kernel.c +1
-0+/* Special case: peer sets the C flag, accept one ADD_ADDR if default
net/mptcp/pm_kernel.c +1
-0+* limits are used -- accepting no ADD_ADDR -- and use subflow endpoints
net/mptcp/pm_kernel.c +3
-0+*/ +if (!i && deny_join_id0) { + unsigned int local_addr_max =
Quoted 1 line
mptcp_pm_get_local_addr_max(msk);
How about moving this line to after
subflows_max = mptcp_pm_get_subflows_max(msk);?
They are similar and can be grouped together.
Quoted 19 lines
net/mptcp/pm_kernel.c +6
-0+ + while (msk->pm.local_addr_used < local_addr_max && + msk->pm.subflows < subflows_max) { + struct mptcp_pm_local *local = &locals[i]; + + if (!select_local_address(pernet, msk,local))
net/mptcp/pm_kernel.c +3
-0+break ; + + __clear_bit(local->addr.id, msk-Quoted 1 line
pm.id_avail_bitmap);
net/mptcp/pm_kernel.c +2
-0+ + if (!mptcp_pm_addr_families_match(sk,
&local->addr,net/mptcp/pm_kernel.c +4
-0+ remote)) +continue ; + + if (mptcp_addresses_equal(&local->addr,
&mpc_addr,
net/mptcp/pm_kernel.c static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, · line 458
Quoted 9 lines
net/mptcp/pm_kernel.c +9
-0+ local->addr.port)) +continue ; + + msk->pm.local_addr_used++; + msk->pm.subflows++; + i++; + } + +return i;
Here, we can avoid using a return statement to allow the subsequent array empty check to proceed.
Quoted 5 lines
net/mptcp/pm_kernel.c +2
-0+ } +/* If the array is empty, fill in the single
* 'IPADDRANY' local address
*/
Matthieu Baerts
maintainerHi Geliang,
Quoted 87 lines · Geliang Tang
Hi Matt,
Thanks for this set. I have some comments below.
Quoted 72 lines · On Mon, 2025-09-15 at 20:11 +0200, Matthieu Baerts (NGI0) wrote:
When servers set the C-flag in their
MP_CAPABLEto tell clients not to
create subflows to the initial address and port, clients will likely not
use their other endpoints. That's because the in-kernel path-manager uses the 'subflow' endpoints to create subflows only to the initial address and port.If the limits have not been modified to accept
ADD_ADDR, the client doesn't try to establish new subflows. If the limits acceptADD_ADDR, the routing routes will be used to select the source IP.The C-flag is typically set when the server is operating behind a legacy
Layer 4 load balancer, or using anycast IP address. Clients having their
different 'subflow' endpoints setup, don't end up creating multiple subflows as expected, and causing some deployment issues.A special case is then added here: when servers set the C-flag in the MPC and directly sends an
ADD_ADDR, this singleADD_ADDRis accepted. The 'subflows' endpoints will then be used with this new remote IP and
port. This exception is only allowed when theADD_ADDRis sent immediately after the 3WHS, and makes the client switching to the 'fully
established' mode. After that, 'select_local_address()' will not be able
to find any subflows, because 'id_avail_bitmap' will be filled inmptcp_pm_create_subflow_or_signal_addr(), when switching to 'fully established' mode.Fixes df377be38725 ("mptcp: add deny_join_id0 in
mptcp_options_received")Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
Notes:
- I tried to find a simple solution that can hopefully be backported to
cover the 'CDN' use-case.
- I tried to find a solution respecting the 'accepted add addr' limit,
but I don't see how to... That's why here I limit the exception a
maximum: when this limit is 0 (default case), only the firstADD_ADDR,
etc. Feel free to share what you think about that.
- I have some additional code doing some cleanup, and I started to look
at #503, which is a bit linked to that.
---
net/mptcp/pm.c | 7 +++++--
net/mptcp/pm_kernel.c | 39 +++++++++++++++++++++++++++++++++++++++2 files changed, 44 insertions(+), 2 deletions(-)net/mptcp/pm.c +0
-0index
02dfb379417e2843301f121039ec0d370b040ef7..fda8d1880224dedbbfb20954f93a04da435346df100644net/mptcp/pm.c +0
-0@@ -637,9 +637,12 @@ void mptcp_pm_add_addr_received(const struct sock *ssk, } else {
__MPTCP_INC_STATS(sock_net((struct sock *)msk), MPTCP_MIB_ADDADDRDROP);
}net/mptcp/pm.c +1
-1-/* id0 should not have a different address */ +/* id0 should not have a different address ; special case for C-flag */
} else if ((addr->id== 0 &&
!mptcp_pm_is_init_remote_addr(msk, addr)) ||net/mptcp/pm.c void mptcp_pm_add_addr_received(const struct sock *ssk, · line 645
Quoted 5 lines
net/mptcp/pm.c +4
-1- (addr->id > 0 && !READ_ONCE(pm->accept_addr))) { + (addr->id > 0 && !READ_ONCE(pm->accept_addr) && + (!READ_ONCE(msk->pm.remote_deny_join_id0) || + msk->pm.local_addr_used != 0 || + mptcp_pm_get_add_addr_accept_max(msk) != 0))) {I think we can define an
mptcp_pm_deny_join_id0(struct mptcp_sock *msk)helper, then use !mptcp_pm_deny_join_id0(msk) here, and usemptcp_pm_deny_join_id0(msk)infill_local_addresses_vec().
Quoted 8 lines
For example:
static inline bool
mptcp_pm_deny_join_id0(struct mptcp_sock *msk){ return (READ_ONCE(msk->pm.remote_deny_join_id0) && msk->pm.local_addr_used == 0 && mptcp_pm_get_add_addr_accept_max(msk) == 0); }
I initially didn't want to add such helper which means modifying more
files: this will cause more troubles for the backports just for that. But now thinking about that again, I guess we will have issues with the backports anyway, because the code has been moved around in pm_kernel.c. So I suppose it is fine to introduce more conflicts, and we can add a new helper.
Quoted 31 lines
Quoted 23 lines
mptcp_pm_announce_addr(msk, addr, true);mptcp_pm_add_addr_send_ack(msk); } else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED)) {net/mptcp/pm_kernel.c +0
-0index
f30df8e884a0b3de9fb092e5774cafe08f6350ce..408801e20ed6e874b80ccbf38af76abc13615a3a100644net/mptcp/pm_kernel.c +1
-0@@ -389,10 +389,15 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, struct mptcp_addr_info mpc_addr; struct pm_nl_pernet *pernet; unsigned int subflows_max; +bool deny_join_id0; int i = 0;
pernet =pm_nl_get_pernet_from_msk(msk);subflows_max=mptcp_pm_get_subflows_max(msk);net/mptcp/pm_kernel.c +1
-0+ deny_join_id0 = remote->id && READ_ONCE(msk-Quoted 1 line
pm.remote_deny_join_id0) &&
net/mptcp/pm_kernel.c static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, · line 400
Quoted 3 lines
net/mptcp/pm_kernel.c +3
-0+ !READ_ONCE (msk->pm.accept_addr) && + msk->pm.local_addr_used ==0 && +mptcp_pm_get_add_addr_accept_max (msk) ==0 ;I think it's unnecessary to check
msk->pm.accept_addragain here, as it has already been verified inmptcp_pm_add_addr_received, which should be sufficient:
Quoted 1 line
deny_join_id0=remote->id&&mptcp_pm_deny_join_id0(msk);
Mmh, we can be in a situation where remote_deny_join_id0 is true, but accept_addr is true as well, and in this case, we don't want the exception.
But I suppose that mptcp_pm_get_add_addr_accept_max(msk) == 0 implies accept_addr being false. So I guess we can drop this condition.
Quoted 34 lines
Quoted 30 lines
mptcp_local_address((struct sock_common *)msk, &mpc_addr);net/mptcp/pm_kernel.c +0
-0@@ -409,6 +414,9 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, locals[i].flags = entry->flags; locals[i].ifindex = entry->ifindex;net/mptcp/pm_kernel.c +2
-0+if (deny_join_id0) + __clear_bit(locals[i].addr.id, msk-Quoted 1 line
pm.id_avail_bitmap);
+
/* Special case for ID0: set the correct ID */
if (mptcp_addresses_equal(&locals[i].addr, &mpc_addr, locals[i].addr.port))
locals[i].addr.id = 0;net/mptcp/pm_kernel.c +0
-0@@ -419,6 +427,37 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, } rcu_read_unlock();net/mptcp/pm_kernel.c +1
-0+/* Special case: peer sets the C flag, accept one ADD_ADDR if default
net/mptcp/pm_kernel.c +1
-0+* limits are used -- accepting no ADD_ADDR -- and use subflow endpoints
net/mptcp/pm_kernel.c +3
-0+*/ +if (!i && deny_join_id0) { + unsigned int local_addr_max =Quoted 1 line
mptcp_pm_get_local_addr_max(msk);How about moving this line to after
Quoted 3 lines
subflows_max=mptcp_pm_get_subflows_max(msk);?They are similar and can be grouped together.
Simply to restrict the scope to the block where it is used:local_addr_max is only used here.
Quoted 24 lines
Quoted 24 lines
net/mptcp/pm_kernel.c +6
-0+ + while (msk->pm.local_addr_used < local_addr_max && + msk->pm.subflows < subflows_max) { + struct mptcp_pm_local *local = &locals[i]; + + if (!select_local_address(pernet, msk,local))
net/mptcp/pm_kernel.c +3
-0+break ; + + __clear_bit(local->addr.id, msk-Quoted 1 line
pm.id_avail_bitmap);
net/mptcp/pm_kernel.c +2
-0+ + if (!mptcp_pm_addr_families_match(sk,
&local->addr,net/mptcp/pm_kernel.c +4
-0+ remote)) +continue ; + + if (mptcp_addresses_equal(&local->addr,
&mpc_addr,net/mptcp/pm_kernel.c +4
-0+ local->addr.port)) +continue ; + + msk->pm.local_addr_used++;
Quoted 8 lines
net/mptcp/pm_kernel.c static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, · line 458
Quoted 5 lines
net/mptcp/pm_kernel.c +5
-0+ msk->pm.subflows++; + i++; + } + +return i;Here, we can avoid using a return statement to allow the subsequent array empty check to proceed.
No, we cannot: if we are in the exception (deny_join_id0), it is possible we are not allowed to create additional subflows using the 'subflow' endpoints, see the conditions in the 'while()'. In this case, we don't want to create a new subflow below, because the idea is to use the 'subflow' endpoints if we can.
Or we need to check these conditions before, but that's a lot of conditions, and it seems safer to return here, no,
Quoted 6 lines
Quoted 6 lines
net/mptcp/pm_kernel.c +2
-0+ } +/* If the array is empty, fill in the single
* 'IPADDRANY' local address
*/
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerHi Matt,
Quoted 146 lines · On Mon, 2025-09-15 at 20:11 +0200, Matthieu Baerts (NGI0) wrote:
When servers set the C-flag in their
MP_CAPABLEto tell clients not to
create subflows to the initial address and port, clients will likely not
use their other endpoints. That's because the in-kernel path-manager uses the 'subflow' endpoints to create subflows only to the initial address and port.If the limits have not been modified to accept
ADD_ADDR, the client doesn't try to establish new subflows. If the limits acceptADD_ADDR, the routing routes will be used to select the source IP.The C-flag is typically set when the server is operating behind a legacy
Layer 4 load balancer, or using anycast IP address. Clients having their
different 'subflow' endpoints setup, don't end up creating multiple subflows as expected, and causing some deployment issues.A special case is then added here: when servers set the C-flag in the MPC and directly sends an
ADD_ADDR, this singleADD_ADDRis accepted. The 'subflows' endpoints will then be used with this new remote IP and
port. This exception is only allowed when theADD_ADDRis sent immediately after the 3WHS, and makes the client switching to the 'fully
established' mode. After that, 'select_local_address()' will not be able
to find any subflows, because 'id_avail_bitmap' will be filled inmptcp_pm_create_subflow_or_signal_addr(), when switching to 'fully established' mode.Fixes df377be38725 ("mptcp: add deny_join_id0 in
mptcp_options_received")Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
Notes:
- I tried to find a simple solution that can hopefully be backported to
cover the 'CDN' use-case.
- I tried to find a solution respecting the 'accepted add addr' limit,
but I don't see how to... That's why here I limit the exception a
maximum: when this limit is 0 (default case), only the firstADD_ADDR,
etc. Feel free to share what you think about that.
- I have some additional code doing some cleanup, and I started to look
at #503, which is a bit linked to that.
---
net/mptcp/pm.c | 7 +++++--
net/mptcp/pm_kernel.c | 39 +++++++++++++++++++++++++++++++++++++++2 files changed, 44 insertions(+), 2 deletions(-)net/mptcp/pm.c +0
-0index
02dfb379417e2843301f121039ec0d370b040ef7..fda8d1880224dedbbfb20954f93a04da435346df100644net/mptcp/pm.c +0
-0@@ -637,9 +637,12 @@ void mptcp_pm_add_addr_received(const struct sock *ssk, } else {
__MPTCP_INC_STATS(sock_net((struct sock *)msk), MPTCP_MIB_ADDADDRDROP);
}net/mptcp/pm.c +1
-1-/* id0 should not have a different address */ +/* id0 should not have a different address ; special case for C-flag */
} else if ((addr->id== 0 &&
!mptcp_pm_is_init_remote_addr(msk, addr)) ||net/mptcp/pm.c +4
-1- (addr->id > 0 && !READ_ONCE(pm->accept_addr))) { + (addr->id > 0 && !READ_ONCE(pm->accept_addr) && + (!READ_ONCE(msk->pm.remote_deny_join_id0) || + msk->pm.local_addr_used != 0 || + mptcp_pm_get_add_addr_accept_max(msk) != 0))) {
mptcp_pm_announce_addr(msk, addr, true);mptcp_pm_add_addr_send_ack(msk); } else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED)) {net/mptcp/pm_kernel.c +0
-0index
f30df8e884a0b3de9fb092e5774cafe08f6350ce..408801e20ed6e874b80ccbf38af76abc13615a3a100644net/mptcp/pm_kernel.c +1
-0@@ -389,10 +389,15 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, struct mptcp_addr_info mpc_addr; struct pm_nl_pernet *pernet; unsigned int subflows_max; +bool deny_join_id0; int i = 0;
pernet =pm_nl_get_pernet_from_msk(msk);subflows_max=mptcp_pm_get_subflows_max(msk);net/mptcp/pm_kernel.c +1
-0+ deny_join_id0 = remote->id && READ_ONCE(msk-Quoted 1 line
pm.remote_deny_join_id0) &&
net/mptcp/pm_kernel.c +3
-0+ !READ_ONCE (msk->pm.accept_addr) && + msk->pm.local_addr_used ==0 && +mptcp_pm_get_add_addr_accept_max (msk) ==0 ;
mptcp_local_address((struct sock_common *)msk, &mpc_addr);net/mptcp/pm_kernel.c +0
-0@@ -409,6 +414,9 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, locals[i].flags = entry->flags; locals[i].ifindex = entry->ifindex;net/mptcp/pm_kernel.c +2
-0+if (deny_join_id0) + __clear_bit(locals[i].addr.id, msk-Quoted 1 line
pm.id_avail_bitmap);
+
/* Special case for ID0: set the correct ID */
if (mptcp_addresses_equal(&locals[i].addr, &mpc_addr, locals[i].addr.port))
locals[i].addr.id = 0;net/mptcp/pm_kernel.c +0
-0@@ -419,6 +427,37 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, } rcu_read_unlock();net/mptcp/pm_kernel.c +1
-0+/* Special case: peer sets the C flag, accept one ADD_ADDR if default
net/mptcp/pm_kernel.c +1
-0+* limits are used -- accepting no ADD_ADDR -- and use subflow endpoints
net/mptcp/pm_kernel.c +3
-0+*/ +if (!i && deny_join_id0) { + unsigned int local_addr_max =
mptcp_pm_get_local_addr_max(msk);net/mptcp/pm_kernel.c +6
-0+ + while (msk->pm.local_addr_used < local_addr_max && + msk->pm.subflows < subflows_max) { + struct mptcp_pm_local *local = &locals[i]; + + if (!select_local_address(pernet, msk,local))
net/mptcp/pm_kernel.c +3
-0+break ; + + __clear_bit(local->addr.id, msk-Quoted 1 line
pm.id_avail_bitmap);
net/mptcp/pm_kernel.c +2
-0+ + if (!mptcp_pm_addr_families_match(sk,
&local->addr,
net/mptcp/pm_kernel.c static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, · line 446
Quoted 1 line
net/mptcp/pm_kernel.c +1
-0+ remote))
Here we need to consider the case of v4mapped addresses, same as in the section below "/* If the array is empty */".
Thanks,
-Geliang
Quoted 18 lines
net/mptcp/pm_kernel.c +3
-0+continue ; + + if (mptcp_addresses_equal(&local->addr,
&mpc_addr,net/mptcp/pm_kernel.c +11
-0+ local->addr.port)) +continue ; + + msk->pm.local_addr_used++; + msk->pm.subflows++; + i++; + } + +return i; + } +/* If the array is empty, fill in the single
* 'IPADDRANY' local address
*/
Matthieu Baerts
maintainerHi Geliang,
Quoted 34 lines · Geliang Tang
Hi Matt,
Quoted 31 lines · On Mon, 2025-09-15 at 20:11 +0200, Matthieu Baerts (NGI0) wrote:
When servers set the C-flag in their
MP_CAPABLEto tell clients not to
create subflows to the initial address and port, clients will likely not
use their other endpoints. That's because the in-kernel path-manager uses the 'subflow' endpoints to create subflows only to the initial address and port.If the limits have not been modified to accept
ADD_ADDR, the client doesn't try to establish new subflows. If the limits acceptADD_ADDR, the routing routes will be used to select the source IP.The C-flag is typically set when the server is operating behind a legacy
Layer 4 load balancer, or using anycast IP address. Clients having their
different 'subflow' endpoints setup, don't end up creating multiple subflows as expected, and causing some deployment issues.A special case is then added here: when servers set the C-flag in the MPC and directly sends an
ADD_ADDR, this singleADD_ADDRis accepted. The 'subflows' endpoints will then be used with this new remote IP and
port. This exception is only allowed when theADD_ADDRis sent immediately after the 3WHS, and makes the client switching to the 'fully
established' mode. After that, 'select_local_address()' will not be able
to find any subflows, because 'id_avail_bitmap' will be filled inmptcp_pm_create_subflow_or_signal_addr(), when switching to 'fully established' mode.
(...)
Quoted 6 lines
Quoted 6 lines
net/mptcp/pm_kernel.c +0
-0index
f30df8e884a0b3de9fb092e5774cafe08f6350ce..408801e20ed6e874b80ccbf38af76abc13615a3a100644net/mptcp/pm_kernel.c +0
-0
(...)
Quoted 23 lines
Quoted 23 lines
net/mptcp/pm_kernel.c +0
-0@@ -419,6 +427,37 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, } rcu_read_unlock();net/mptcp/pm_kernel.c +1
-0+/* Special case: peer sets the C flag, accept one ADD_ADDR if default
net/mptcp/pm_kernel.c +1
-0+* limits are used -- accepting no ADD_ADDR -- and use subflow endpoints
net/mptcp/pm_kernel.c +3
-0+*/ +if (!i && deny_join_id0) { + unsigned int local_addr_max =
mptcp_pm_get_local_addr_max(msk);net/mptcp/pm_kernel.c +6
-0+ + while (msk->pm.local_addr_used < local_addr_max && + msk->pm.subflows < subflows_max) { + struct mptcp_pm_local *local = &locals[i]; + + if (!select_local_address(pernet, msk,local))
net/mptcp/pm_kernel.c +3
-0+break ; + + __clear_bit(local->addr.id, msk-
Quoted 8 lines
net/mptcp/pm_kernel.c static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, · line 446
Quoted 5 lines
Quoted 1 line
pm.id_avail_bitmap);
net/mptcp/pm_kernel.c +2
-0+ + if (!mptcp_pm_addr_families_match(sk,
&local->addr,net/mptcp/pm_kernel.c +1
-0+ remote))Here we need to consider the case of v4mapped addresses, same as in the section below "/* If the array is empty */".
I'm not sure to understand: here, we pick a local, then mptcp_pm_addr_families_match() takes care of the v4mapped addresses.
Here under, we define a local, and we want to take one for the same address family. We still need the check just in case we receive a v6 address via the ADD_ADDR, and v6 is not supported.
So I don't need to change anything here. Or did I miss something?
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts (NGI0)
maintainerPATCH 2/2 selftests: mptcp: join: validate C-flag + def limit
In reply to Matthieu Baerts (NGI0)The previous commit adds an exception for the C-flag case. The 'mptcp_join.sh' selftest is extended to validate this case.
In this subtest, there is a typical CDN deployment with a client where MPTCP endpoints have been 'automatically' configured:
- the server set net.mptcp.allow_join_initial_addr_port=0
- the client has multiple 'subflow' endpoints, and the default limits:
not accepting ADD_ADDRs.
Without the parent patch, the client is not able to establish new subflows using its 'subflow' endpoints. The parent commit fixes that.
The 'Fixes' tag here below is the same as the one from the previous
commit: this patch here is not fixing anything wrong in the selftests, but it validates the previous fix for an issue introduced by this commit ID.
--- net/mptcp/pm.c | 4 +++- net/mptcp/pm_kernel.c | 1 + tools/testing/selftests/net/mptcp/mptcp_join.sh | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-)
net/mptcp/pm.c +3 -1
@@ -637,7 +637,9 @@ void mptcp_pm_add_addr_received(const struct sock *ssk, }else {__MPTCP_INC_STATS (sock_net ((struct sock *)msk),MPTCP_MIB_ADDADDRDROP ); } -/* id0 should not have a different address ; special case for C-flag */ +/* - id0 should not have a different address +* - special case for C-flag: linked to fill_local_addresses_vec() +*/ } else if ((addr->id == 0 && !mptcp_pm_is_init_remote_addr(msk, addr)) || (addr->id > 0 && !READ_ONCE(pm->accept_addr) && (!READ_ONCE(msk->pm.remote_deny_join_id0) ||
net/mptcp/pm_kernel.c +1 -0
@@ -394,6 +394,7 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, pernet =pm_nl_get_pernet_from_msk (msk); subflows_max =mptcp_pm_get_subflows_max (msk); +/* linked to conditions in mptcp_pm_add_addr_received() */ deny_join_id0 = remote->id &&READ_ONCE (msk->pm.remote_deny_join_id0) && !READ_ONCE (msk->pm.accept_addr) && msk->pm.local_addr_used == 0 &&
tools/testing/selftests/net/mptcp/mptcp_join.sh +11 -0
@@ -3306,6 +3306,17 @@ deny_join_id0_tests() run_tests $ns1 $ns2 10.0.1.1 chk_join_nr 1 1 1 fi + + # default limit, server deny join id 0 + signal + if reset_with_allow_join_id0 "default limit, server deny join id 0" 0 1; then + pm_nl_set_limits $ns1 0 2 + pm_nl_set_limits $ns2 0 2 + pm_nl_add_endpoint $ns1 10.0.2.1 flags signal + pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow + pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow + run_tests $ns1 $ns2 10.0.1.1 + chk_join_nr 2 2 2 + fi } fullmesh_tests()
Signature · 1 line
2.51.0
Geliang Tang
reviewerRe: [PATCH mptcp-net 2/2] selftests: mptcp: join: validate C-flag + def limit
Quoted 49 lines · On Mon, 2025-09-15 at 20:11 +0200, Matthieu Baerts (NGI0) wrote:
The previous commit adds an exception for the C-flag case. The '
mptcp_join.sh' selftest is extended to validate this case.In this subtest, there is a typical CDN deployment with a client where
MPTCP endpoints have been 'automatically' configured:- the server set net.mptcp.allow_join_initial_addr_port=0
- the client has multiple 'subflow' endpoints, and the default limits:
not acceptingADD_ADDRs.Without the parent patch, the client is not able to establish new subflows using its 'subflow' endpoints. The parent commit fixes that.
The 'Fixes' tag here below is the same as the one from the previous
commit: this patch here is not fixing anything wrong in the selftests,
but it validates the previous fix for an issue introduced by this commit
ID.Fixes df377be38725 ("mptcp: add deny_join_id0 in
mptcp_options_received")Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
net/mptcp/pm.c | 4 +++- net/mptcp/pm_kernel.c | 1 +tools/testing/selftests/net/mptcp/mptcp_join.sh| 11 +++++++++++3 files changed, 15 insertions(+), 1 deletion(-)net/mptcp/pm.c +0
-0index
fda8d1880224dedbbfb20954f93a04da435346df..5d037f9d4e0b4d158beaaa5a48c4efb50fe9b5cb100644net/mptcp/pm.c +0
-0@@ -637,7 +637,9 @@ void mptcp_pm_add_addr_received(const struct sock *ssk, } else {
__MPTCP_INC_STATS(sock_net((struct sock *)msk), MPTCP_MIB_ADDADDRDROP);
}net/mptcp/pm.c +0
-1-/* id0 should not have a different address ; special case for C-flag */
net/mptcp/pm.c +2
-0+/* - id0 should not have a different address +* - special case for C-flag: linked to
fill_local_addresses_vec()
net/mptcp/pm.c void mptcp_pm_add_addr_received(const struct sock *ssk, · line 642
Quoted 1 line
net/mptcp/pm.c +1
-0+*/
How about squashing this into patch 1.
Quoted 15 lines
} else if ((
addr->id== 0 && !mptcp_pm_is_init_remote_addr(msk, addr)) ||
(addr->id> 0 && !READ_ONCE(pm->accept_addr) && (!READ_ONCE(msk->pm.remote_deny_join_id0) ||net/mptcp/pm_kernel.c +0
-0index
408801e20ed6e874b80ccbf38af76abc13615a3a..aae9b92aea4715dabaf3101a0341ab7eab16f407100644net/mptcp/pm_kernel.c +0
-0@@ -394,6 +394,7 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,
pernet =pm_nl_get_pernet_from_msk(msk);subflows_max=mptcp_pm_get_subflows_max(msk);
net/mptcp/pm_kernel.c static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, · line 397
Quoted 1 line
net/mptcp/pm_kernel.c +1
-0+/* linked to conditions in mptcp_pm_add_addr_received() */
And squash this too.
WDYT?
Thanks,
-Geliang
Quoted 30 lines
deny_join_id0=remote->id&& READ_ONCE(msk-Quoted 1 line
pm.remote_deny_join_id0) &&
!READ_ONCE(msk->pm.accept_addr) &&
msk->pm.local_addr_used== 0 &&tools/testing/selftests/net/mptcp/mptcp_join.sh +0
-0index
6055ee5762e13108e5e2924a0e77d58da584d008..e80f90581a2531ac31339ae3543604c68677c232100755tools/testing/selftests/net/mptcp/mptcp_join.sh +0
-0@@ -3306,6 +3306,17 @@ deny_join_id0_tests()
run_tests$ns1 $ns2 10.0.1.1
chk_join_nr1 1 1
fitools/testing/selftests/net/mptcp/mptcp_join.sh +3
-0+ + # default limit, server deny join id 0 + signal + if reset_with_allow_join_id0 "default limit, server denyjoin id 0" 0 1; then
tools/testing/selftests/net/mptcp/mptcp_join.sh +8
-0+ pm_nl_set_limits $ns1 0 2 + pm_nl_set_limits $ns2 0 2 + pm_nl_add_endpoint $ns1 10.0.2.1 flags signal + pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow + pm_nl_add_endpoint $ns2 10.0.4.2 flags subflow + run_tests $ns1 $ns2 10.0.1.1 + chk_join_nr 2 2 2 + fi}
fullmesh_tests()
Matthieu Baerts
maintainerRe: [PATCH mptcp-net 2/2] selftests: mptcp: join: validate C-flag + def limit
Hi Geliang,
Quoted 64 lines · Geliang Tang
Quoted 49 lines · On Mon, 2025-09-15 at 20:11 +0200, Matthieu Baerts (NGI0) wrote:
The previous commit adds an exception for the C-flag case. The '
mptcp_join.sh' selftest is extended to validate this case.In this subtest, there is a typical CDN deployment with a client where
MPTCP endpoints have been 'automatically' configured:- the server set net.mptcp.allow_join_initial_addr_port=0
- the client has multiple 'subflow' endpoints, and the default limits:
not acceptingADD_ADDRs.Without the parent patch, the client is not able to establish new subflows using its 'subflow' endpoints. The parent commit fixes that.
The 'Fixes' tag here below is the same as the one from the previous
commit: this patch here is not fixing anything wrong in the selftests,
but it validates the previous fix for an issue introduced by this commit
ID.Fixes df377be38725 ("mptcp: add deny_join_id0 in
mptcp_options_received")Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
net/mptcp/pm.c | 4 +++- net/mptcp/pm_kernel.c | 1 +tools/testing/selftests/net/mptcp/mptcp_join.sh| 11 +++++++++++3 files changed, 15 insertions(+), 1 deletion(-)net/mptcp/pm.c +0
-0index
fda8d1880224dedbbfb20954f93a04da435346df..5d037f9d4e0b4d158beaaa5a48c4efb50fe9b5cb100644net/mptcp/pm.c +0
-0@@ -637,7 +637,9 @@ void mptcp_pm_add_addr_received(const struct sock *ssk, } else {
__MPTCP_INC_STATS(sock_net((struct sock *)msk), MPTCP_MIB_ADDADDRDROP);
}net/mptcp/pm.c +0
-1-/* id0 should not have a different address ; special case for C-flag */
net/mptcp/pm.c +2
-0+/* - id0 should not have a different address +* - special case for C-flag: linked to
fill_local_addresses_vec()net/mptcp/pm.c void mptcp_pm_add_addr_received(const struct sock *ssk, · line 642
Quoted 1 line
net/mptcp/pm.c +1
-0+*/ How about squashing this into patch 1.
Quoted 10 lines
} else if ((
addr->id== 0 && !mptcp_pm_is_init_remote_addr(msk, addr)) ||
(addr->id> 0 && !READ_ONCE(pm->accept_addr) && (!READ_ONCE(msk->pm.remote_deny_join_id0) ||net/mptcp/pm_kernel.c +0
-0index
408801e20ed6e874b80ccbf38af76abc13615a3a..aae9b92aea4715dabaf3101a0341ab7eab16f407100644net/mptcp/pm_kernel.c +0
-0
Quoted 8 lines
net/mptcp/pm_kernel.c static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk, · line 397
Quoted 6 lines
net/mptcp/pm_kernel.c +0
-0@@ -394,6 +394,7 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,
pernet =pm_nl_get_pernet_from_msk(msk);subflows_max=mptcp_pm_get_subflows_max(msk);net/mptcp/pm_kernel.c +1
-0+/* linked to conditions in mptcp_pm_add_addr_received() */ And squash this too.
Arf, sorry, I missed that and squash these modifications in the wrong commit. Yes, it is for patch 1/2.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
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/17742884126
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/078cd3767749
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1002618
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)