Skip to content

Commit 6fc5f5b

Browse files
committed
Merge branch 'mptcp-cleanups'
Matthieu Baerts says: ==================== mptcp: a couple of cleanups and improvements Patch 1 removes an unneeded address copy in subflow_syn_recv_sock(). Patch 2 simplifies subflow_syn_recv_sock() to postpone some actions and to avoid a bunch of conditionals. Patch 3 stops reporting limits that are not taken into account when the userspace PM is used. Patch 4 adds a new test to validate that the 'subflows' field reported by the kernel is correct. Such info can be retrieved via Netlink (e.g. with ss) or getsockopt(SOL_MPTCP, MPTCP_INFO). --- Changes in v2: - Patch 3/4's commit message has been updated to use the correct SHA - Rebased on latest net-next - Link to v1: https://lore.kernel.org/r/20230324-upstream-net-next-20230324-misc-features-v1-0-5a29154592bd@tessares.net ==================== Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net> Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 9380d89 + 9095ce9 commit 6fc5f5b

File tree

3 files changed

+72
-38
lines changed

3 files changed

+72
-38
lines changed

net/mptcp/sockopt.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -885,20 +885,26 @@ static int mptcp_getsockopt_first_sf_only(struct mptcp_sock *msk, int level, int
885885
void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
886886
{
887887
u32 flags = 0;
888-
u8 val;
889888

890889
memset(info, 0, sizeof(*info));
891890

892891
info->mptcpi_subflows = READ_ONCE(msk->pm.subflows);
893892
info->mptcpi_add_addr_signal = READ_ONCE(msk->pm.add_addr_signaled);
894893
info->mptcpi_add_addr_accepted = READ_ONCE(msk->pm.add_addr_accepted);
895894
info->mptcpi_local_addr_used = READ_ONCE(msk->pm.local_addr_used);
896-
info->mptcpi_subflows_max = mptcp_pm_get_subflows_max(msk);
897-
val = mptcp_pm_get_add_addr_signal_max(msk);
898-
info->mptcpi_add_addr_signal_max = val;
899-
val = mptcp_pm_get_add_addr_accept_max(msk);
900-
info->mptcpi_add_addr_accepted_max = val;
901-
info->mptcpi_local_addr_max = mptcp_pm_get_local_addr_max(msk);
895+
896+
/* The following limits only make sense for the in-kernel PM */
897+
if (mptcp_pm_is_kernel(msk)) {
898+
info->mptcpi_subflows_max =
899+
mptcp_pm_get_subflows_max(msk);
900+
info->mptcpi_add_addr_signal_max =
901+
mptcp_pm_get_add_addr_signal_max(msk);
902+
info->mptcpi_add_addr_accepted_max =
903+
mptcp_pm_get_add_addr_accept_max(msk);
904+
info->mptcpi_local_addr_max =
905+
mptcp_pm_get_local_addr_max(msk);
906+
}
907+
902908
if (test_bit(MPTCP_FALLBACK_DONE, &msk->flags))
903909
flags |= MPTCP_INFO_FLAG_FALLBACK;
904910
if (READ_ONCE(msk->can_ack))

net/mptcp/subflow.c

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -696,14 +696,6 @@ static bool subflow_hmac_valid(const struct request_sock *req,
696696
return !crypto_memneq(hmac, mp_opt->hmac, MPTCPOPT_HMAC_LEN);
697697
}
698698

699-
static void mptcp_force_close(struct sock *sk)
700-
{
701-
/* the msk is not yet exposed to user-space, and refcount is 2 */
702-
inet_sk_state_store(sk, TCP_CLOSE);
703-
sk_common_release(sk);
704-
sock_put(sk);
705-
}
706-
707699
static void subflow_ulp_fallback(struct sock *sk,
708700
struct mptcp_subflow_context *old_ctx)
709701
{
@@ -755,7 +747,6 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
755747
struct mptcp_subflow_request_sock *subflow_req;
756748
struct mptcp_options_received mp_opt;
757749
bool fallback, fallback_is_fatal;
758-
struct sock *new_msk = NULL;
759750
struct mptcp_sock *owner;
760751
struct sock *child;
761752

@@ -784,14 +775,9 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
784775
* options.
785776
*/
786777
mptcp_get_options(skb, &mp_opt);
787-
if (!(mp_opt.suboptions & OPTIONS_MPTCP_MPC)) {
778+
if (!(mp_opt.suboptions & OPTIONS_MPTCP_MPC))
788779
fallback = true;
789-
goto create_child;
790-
}
791780

792-
new_msk = mptcp_sk_clone(listener->conn, &mp_opt, req);
793-
if (!new_msk)
794-
fallback = true;
795781
} else if (subflow_req->mp_join) {
796782
mptcp_get_options(skb, &mp_opt);
797783
if (!(mp_opt.suboptions & OPTIONS_MPTCP_MPJ) ||
@@ -820,23 +806,23 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
820806
subflow_add_reset_reason(skb, MPTCP_RST_EMPTCP);
821807
goto dispose_child;
822808
}
823-
824-
if (new_msk)
825-
mptcp_copy_inaddrs(new_msk, child);
826-
mptcp_subflow_drop_ctx(child);
827-
goto out;
809+
goto fallback;
828810
}
829811

830812
/* ssk inherits options of listener sk */
831813
ctx->setsockopt_seq = listener->setsockopt_seq;
832814

833815
if (ctx->mp_capable) {
834-
owner = mptcp_sk(new_msk);
816+
ctx->conn = mptcp_sk_clone(listener->conn, &mp_opt, req);
817+
if (!ctx->conn)
818+
goto fallback;
819+
820+
owner = mptcp_sk(ctx->conn);
835821

836822
/* this can't race with mptcp_close(), as the msk is
837823
* not yet exposted to user-space
838824
*/
839-
inet_sk_state_store((void *)new_msk, TCP_ESTABLISHED);
825+
inet_sk_state_store(ctx->conn, TCP_ESTABLISHED);
840826

841827
/* record the newly created socket as the first msk
842828
* subflow, but don't link it yet into conn_list
@@ -846,11 +832,9 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
846832
/* new mpc subflow takes ownership of the newly
847833
* created mptcp socket
848834
*/
849-
mptcp_sk(new_msk)->setsockopt_seq = ctx->setsockopt_seq;
835+
owner->setsockopt_seq = ctx->setsockopt_seq;
850836
mptcp_pm_new_connection(owner, child, 1);
851837
mptcp_token_accept(subflow_req, owner);
852-
ctx->conn = new_msk;
853-
new_msk = NULL;
854838

855839
/* set msk addresses early to ensure mptcp_pm_get_local_id()
856840
* uses the correct data
@@ -900,11 +884,6 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
900884
}
901885
}
902886

903-
out:
904-
/* dispose of the left over mptcp master, if any */
905-
if (unlikely(new_msk))
906-
mptcp_force_close(new_msk);
907-
908887
/* check for expected invariant - should never trigger, just help
909888
* catching eariler subtle bugs
910889
*/
@@ -922,6 +901,10 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
922901

923902
/* The last child reference will be released by the caller */
924903
return child;
904+
905+
fallback:
906+
mptcp_subflow_drop_ctx(child);
907+
return child;
925908
}
926909

927910
static struct inet_connection_sock_af_ops subflow_specific __ro_after_init;

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,46 @@ chk_subflow_nr()
17191719
fi
17201720
}
17211721

1722+
chk_mptcp_info()
1723+
{
1724+
local nr_info=$1
1725+
local info
1726+
local cnt1
1727+
local cnt2
1728+
local dump_stats
1729+
1730+
if [[ $nr_info = "subflows_"* ]]; then
1731+
info="subflows"
1732+
nr_info=${nr_info:9}
1733+
else
1734+
echo "[fail] unsupported argument: $nr_info"
1735+
fail_test
1736+
return 1
1737+
fi
1738+
1739+
printf "%-${nr_blank}s %-30s" " " "mptcp_info $info=$nr_info"
1740+
1741+
cnt1=$(ss -N $ns1 -inmHM | grep "$info:" |
1742+
sed -n 's/.*\('"$info"':\)\([[:digit:]]*\).*$/\2/p;q')
1743+
[ -z "$cnt1" ] && cnt1=0
1744+
cnt2=$(ss -N $ns2 -inmHM | grep "$info:" |
1745+
sed -n 's/.*\('"$info"':\)\([[:digit:]]*\).*$/\2/p;q')
1746+
[ -z "$cnt2" ] && cnt2=0
1747+
if [ "$cnt1" != "$nr_info" ] || [ "$cnt2" != "$nr_info" ]; then
1748+
echo "[fail] got $cnt1:$cnt2 $info expected $nr_info"
1749+
fail_test
1750+
dump_stats=1
1751+
else
1752+
echo "[ ok ]"
1753+
fi
1754+
1755+
if [ "$dump_stats" = 1 ]; then
1756+
ss -N $ns1 -inmHM
1757+
ss -N $ns2 -inmHM
1758+
dump_stats
1759+
fi
1760+
}
1761+
17221762
chk_link_usage()
17231763
{
17241764
local ns=$1
@@ -3118,13 +3158,18 @@ endpoint_tests()
31183158
run_tests $ns1 $ns2 10.0.1.1 4 0 0 speed_20 2>/dev/null &
31193159

31203160
wait_mpj $ns2
3161+
chk_subflow_nr needtitle "before delete" 2
3162+
chk_mptcp_info subflows_1
3163+
31213164
pm_nl_del_endpoint $ns2 2 10.0.2.2
31223165
sleep 0.5
3123-
chk_subflow_nr needtitle "after delete" 1
3166+
chk_subflow_nr "" "after delete" 1
3167+
chk_mptcp_info subflows_0
31243168

31253169
pm_nl_add_endpoint $ns2 10.0.2.2 dev ns2eth2 flags subflow
31263170
wait_mpj $ns2
31273171
chk_subflow_nr "" "after re-add" 2
3172+
chk_mptcp_info subflows_1
31283173
kill_tests_wait
31293174
fi
31303175
}

0 commit comments

Comments
 (0)