Skip to content

Commit 97499e2

Browse files
committed
Merge branch 'mptcp-pm-nl-announce-deny-join-id0-flag'
Matthieu Baerts says: ==================== mptcp: pm: nl: announce deny-join-id0 flag During the connection establishment, a peer can tell the other one that it cannot establish new subflows to the initial IP address and port by setting the 'C' flag [1]. Doing so makes sense when the sender is behind a strict NAT, operating behind a legacy Layer 4 load balancer, or using anycast IP address for example. When this 'C' flag is set, the path-managers must then not try to establish new subflows to the other peer's initial IP address and port. The in-kernel PM has access to this info, but the userspace PM didn't, not letting the userspace daemon able to respect the RFC8684. Here are a few fixes related to this 'C' flag (aka 'deny-join-id0'): - Patch 1: add remote_deny_join_id0 info on passive connections. A fix for v5.14. - Patch 2: let the userspace PM daemon know about the deny_join_id0 attribute, so when set, it can avoid creating new subflows to the initial IP address and port. A fix for v5.19. - Patch 3: a validation for the previous commit. - Patch 4: record the deny_join_id0 info when TFO is used. A fix for v6.2. - Patch 5: not related to deny-join-id0, but it fixes errors messages in the sockopt selftests, not to create confusions. A fix for v6.5. ==================== Link: https://patch.msgid.link/20250912-net-mptcp-pm-uspace-deny_join_id0-v1-0-40171884ade8@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 33a09c6 + b86418b commit 97499e2

File tree

9 files changed

+48
-16
lines changed

9 files changed

+48
-16
lines changed

Documentation/netlink/specs/mptcp_pm.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ definitions:
2828
traffic-patterns it can take a long time until the
2929
MPTCP_EVENT_ESTABLISHED is sent.
3030
Attributes: token, family, saddr4 | saddr6, daddr4 | daddr6, sport,
31-
dport, server-side.
31+
dport, server-side, [flags].
3232
-
3333
name: established
3434
doc: >-
3535
A MPTCP connection is established (can start new subflows).
3636
Attributes: token, family, saddr4 | saddr6, daddr4 | daddr6, sport,
37-
dport, server-side.
37+
dport, server-side, [flags].
3838
-
3939
name: closed
4040
doc: >-

include/uapi/linux/mptcp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#define MPTCP_INFO_FLAG_FALLBACK _BITUL(0)
3232
#define MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED _BITUL(1)
3333

34+
#define MPTCP_PM_EV_FLAG_DENY_JOIN_ID0 _BITUL(0)
35+
3436
#define MPTCP_PM_ADDR_FLAG_SIGNAL (1 << 0)
3537
#define MPTCP_PM_ADDR_FLAG_SUBFLOW (1 << 1)
3638
#define MPTCP_PM_ADDR_FLAG_BACKUP (1 << 2)

include/uapi/linux/mptcp_pm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
* good time to allocate memory and send ADD_ADDR if needed. Depending on the
1717
* traffic-patterns it can take a long time until the MPTCP_EVENT_ESTABLISHED
1818
* is sent. Attributes: token, family, saddr4 | saddr6, daddr4 | daddr6,
19-
* sport, dport, server-side.
19+
* sport, dport, server-side, [flags].
2020
* @MPTCP_EVENT_ESTABLISHED: A MPTCP connection is established (can start new
2121
* subflows). Attributes: token, family, saddr4 | saddr6, daddr4 | daddr6,
22-
* sport, dport, server-side.
22+
* sport, dport, server-side, [flags].
2323
* @MPTCP_EVENT_CLOSED: A MPTCP connection has stopped. Attribute: token.
2424
* @MPTCP_EVENT_ANNOUNCED: A new address has been announced by the peer.
2525
* Attributes: token, rem_id, family, daddr4 | daddr6 [, dport].

net/mptcp/options.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -985,13 +985,13 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
985985
return false;
986986
}
987987

988-
if (mp_opt->deny_join_id0)
989-
WRITE_ONCE(msk->pm.remote_deny_join_id0, true);
990-
991988
if (unlikely(!READ_ONCE(msk->pm.server_side)))
992989
pr_warn_once("bogus mpc option on established client sk");
993990

994991
set_fully_established:
992+
if (mp_opt->deny_join_id0)
993+
WRITE_ONCE(msk->pm.remote_deny_join_id0, true);
994+
995995
mptcp_data_lock((struct sock *)msk);
996996
__mptcp_subflow_fully_established(msk, subflow, mp_opt);
997997
mptcp_data_unlock((struct sock *)msk);

net/mptcp/pm_netlink.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,20 @@ static int mptcp_event_created(struct sk_buff *skb,
408408
const struct sock *ssk)
409409
{
410410
int err = nla_put_u32(skb, MPTCP_ATTR_TOKEN, READ_ONCE(msk->token));
411+
u16 flags = 0;
411412

412413
if (err)
413414
return err;
414415

415416
if (nla_put_u8(skb, MPTCP_ATTR_SERVER_SIDE, READ_ONCE(msk->pm.server_side)))
416417
return -EMSGSIZE;
417418

419+
if (READ_ONCE(msk->pm.remote_deny_join_id0))
420+
flags |= MPTCP_PM_EV_FLAG_DENY_JOIN_ID0;
421+
422+
if (flags && nla_put_u16(skb, MPTCP_ATTR_FLAGS, flags))
423+
return -EMSGSIZE;
424+
418425
return mptcp_event_add_subflow(skb, ssk);
419426
}
420427

net/mptcp/subflow.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,10 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
883883

884884
ctx->subflow_id = 1;
885885
owner = mptcp_sk(ctx->conn);
886+
887+
if (mp_opt.deny_join_id0)
888+
WRITE_ONCE(owner->pm.remote_deny_join_id0, true);
889+
886890
mptcp_pm_new_connection(owner, child, 1);
887891

888892
/* with OoO packets we can reach here without ingress

tools/testing/selftests/net/mptcp/mptcp_sockopt.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -667,22 +667,26 @@ static void process_one_client(int fd, int pipefd)
667667

668668
do_getsockopts(&s, fd, ret, ret2);
669669
if (s.mptcpi_rcv_delta != (uint64_t)ret + 1)
670-
xerror("mptcpi_rcv_delta %" PRIu64 ", expect %" PRIu64, s.mptcpi_rcv_delta, ret + 1, s.mptcpi_rcv_delta - ret);
670+
xerror("mptcpi_rcv_delta %" PRIu64 ", expect %" PRIu64 ", diff %" PRId64,
671+
s.mptcpi_rcv_delta, ret + 1, s.mptcpi_rcv_delta - (ret + 1));
671672

672673
/* be nice when running on top of older kernel */
673674
if (s.pkt_stats_avail) {
674675
if (s.last_sample.mptcpi_bytes_sent != ret2)
675-
xerror("mptcpi_bytes_sent %" PRIu64 ", expect %" PRIu64,
676+
xerror("mptcpi_bytes_sent %" PRIu64 ", expect %" PRIu64
677+
", diff %" PRId64,
676678
s.last_sample.mptcpi_bytes_sent, ret2,
677679
s.last_sample.mptcpi_bytes_sent - ret2);
678680
if (s.last_sample.mptcpi_bytes_received != ret)
679-
xerror("mptcpi_bytes_received %" PRIu64 ", expect %" PRIu64,
681+
xerror("mptcpi_bytes_received %" PRIu64 ", expect %" PRIu64
682+
", diff %" PRId64,
680683
s.last_sample.mptcpi_bytes_received, ret,
681684
s.last_sample.mptcpi_bytes_received - ret);
682685
if (s.last_sample.mptcpi_bytes_acked != ret)
683-
xerror("mptcpi_bytes_acked %" PRIu64 ", expect %" PRIu64,
684-
s.last_sample.mptcpi_bytes_acked, ret2,
685-
s.last_sample.mptcpi_bytes_acked - ret2);
686+
xerror("mptcpi_bytes_acked %" PRIu64 ", expect %" PRIu64
687+
", diff %" PRId64,
688+
s.last_sample.mptcpi_bytes_acked, ret,
689+
s.last_sample.mptcpi_bytes_acked - ret);
686690
}
687691

688692
close(fd);

tools/testing/selftests/net/mptcp/pm_nl_ctl.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ static int capture_events(int fd, int event_group)
188188
fprintf(stderr, ",error:%u", *(__u8 *)RTA_DATA(attrs));
189189
else if (attrs->rta_type == MPTCP_ATTR_SERVER_SIDE)
190190
fprintf(stderr, ",server_side:%u", *(__u8 *)RTA_DATA(attrs));
191+
else if (attrs->rta_type == MPTCP_ATTR_FLAGS) {
192+
__u16 flags = *(__u16 *)RTA_DATA(attrs);
193+
194+
/* only print when present, easier */
195+
if (flags & MPTCP_PM_EV_FLAG_DENY_JOIN_ID0)
196+
fprintf(stderr, ",deny_join_id0:1");
197+
}
191198

192199
attrs = RTA_NEXT(attrs, msg_len);
193200
}

tools/testing/selftests/net/mptcp/userspace_pm.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ make_connection()
201201
is_v6="v4"
202202
fi
203203

204+
# set this on the client side only: will not affect the rest
205+
ip netns exec "$ns2" sysctl -q net.mptcp.allow_join_initial_addr_port=0
206+
204207
:>"$client_evts"
205208
:>"$server_evts"
206209

@@ -223,23 +226,28 @@ make_connection()
223226
local client_token
224227
local client_port
225228
local client_serverside
229+
local client_nojoin
226230
local server_token
227231
local server_serverside
232+
local server_nojoin
228233

229234
client_token=$(mptcp_lib_evts_get_info token "$client_evts")
230235
client_port=$(mptcp_lib_evts_get_info sport "$client_evts")
231236
client_serverside=$(mptcp_lib_evts_get_info server_side "$client_evts")
237+
client_nojoin=$(mptcp_lib_evts_get_info deny_join_id0 "$client_evts")
232238
server_token=$(mptcp_lib_evts_get_info token "$server_evts")
233239
server_serverside=$(mptcp_lib_evts_get_info server_side "$server_evts")
240+
server_nojoin=$(mptcp_lib_evts_get_info deny_join_id0 "$server_evts")
234241

235242
print_test "Established IP${is_v6} MPTCP Connection ns2 => ns1"
236-
if [ "$client_token" != "" ] && [ "$server_token" != "" ] && [ "$client_serverside" = 0 ] &&
237-
[ "$server_serverside" = 1 ]
243+
if [ "${client_token}" != "" ] && [ "${server_token}" != "" ] &&
244+
[ "${client_serverside}" = 0 ] && [ "${server_serverside}" = 1 ] &&
245+
[ "${client_nojoin:-0}" = 0 ] && [ "${server_nojoin:-0}" = 1 ]
238246
then
239247
test_pass
240248
print_title "Connection info: ${client_addr}:${client_port} -> ${connect_addr}:${app_port}"
241249
else
242-
test_fail "Expected tokens (c:${client_token} - s:${server_token}) and server (c:${client_serverside} - s:${server_serverside})"
250+
test_fail "Expected tokens (c:${client_token} - s:${server_token}), server (c:${client_serverside} - s:${server_serverside}), nojoin (c:${client_nojoin} - s:${server_nojoin})"
243251
mptcp_lib_result_print_all_tap
244252
exit ${KSFT_FAIL}
245253
fi

0 commit comments

Comments
 (0)