From patchwork Fri May 14 14:32:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 12258525 X-Patchwork-Delegate: mat@martineau.name Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B07CC71 for ; Fri, 14 May 2021 14:32:25 +0000 (UTC) Received: by mail-pj1-f50.google.com with SMTP id pi6-20020a17090b1e46b029015cec51d7cdso1721870pjb.5 for ; Fri, 14 May 2021 07:32:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VJjBYpYoSd9fcpkY6wdrXT5dYkJikOPUmbJyJiITcXY=; b=IlWw/oOQNNwmihXzRuS8ZIG1/LjBlMx1Whg0g/7CtVKjoJeaO548fE98YizijL2831 grTM+JOENDnnzak9JCmOVDqMHwQ6ztDdAHlra80wyytDQqAhOhSain+2QuF9zUL5A+bt v0zRTu399dQtkjKlWhpA1LSgdIYZjR2YTw8QwOltInyzbO0nYh4YIqF08HACLfaAh3BL EFR1Gl3wXIH5nlAN5RHbPOLHKYY4XLn0y02qLVeabfWLb93PZ6btrKhN1Vw3a+wuXYqE cbBPbARGoFIhln0I2L2dey1Ovc5Azo0MSmmn/jLvX15NEc9WJmjkJlljW4QxW2HGbxVu HDDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VJjBYpYoSd9fcpkY6wdrXT5dYkJikOPUmbJyJiITcXY=; b=CZWvzg5eHr2w13S/kZBrxrHLvfMKe6BB6SNS/D/58PF52gmUC8eNvwVtcQTOODkXM5 gCsmnqZt7Men+P+LvjqGxBuQ45EJjFuJvcqVVZMhyT5QHPUb/x+2dGr7q2k628OeNtz2 gQg20g6yEwJkiH8o9+Hr+RhLvRCayEhK38uT+5OWnnt6xCijipA5K5lux38M3XPq1mWT B2z3u4DQBbWyILBVS2LYTobiBjXm6U3FrVmB1qQOEmuciffFLnMbFZdcksbf0VWeNaYR p2TtKu0Ux4cDAGHwq6PNFxpWYz8t/G4PsR9BNjFR88o04dVwz+UrbYpBi5EQMnB4pLio VY1A== X-Gm-Message-State: AOAM532NkTAhckQRaJa9bsH9wW88eYlZkHn1ns2pnQ61xFwt6slFAv0D k6JaPabhSc7zSt+s5DonelBuDWOqypc= X-Google-Smtp-Source: ABdhPJz3Lj8cRCd4CW55mBscLpiJ2/O22zDXeFAjXFht+zbJGzPL5MfvPckss3m646ZZcP87WgFFjA== X-Received: by 2002:a17:90a:ba01:: with SMTP id s1mr11596770pjr.74.1621002745165; Fri, 14 May 2021 07:32:25 -0700 (PDT) Received: from localhost ([43.224.245.180]) by smtp.gmail.com with ESMTPSA id n9sm4573293pgt.35.2021.05.14.07.32.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 07:32:24 -0700 (PDT) From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Florian Westphal Subject: [MPTCP][PATCH v6 mptcp-next 1/6] mptcp: add sysctl allow_join_initial_addr_port Date: Fri, 14 May 2021 22:32:14 +0800 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This patch added a new sysctl, named allow_join_initial_addr_port, to control whether allow peers to send join requests to the IP address and port number used by the initial subflow. Suggested-by: Florian Westphal Signed-off-by: Geliang Tang --- Documentation/networking/mptcp-sysctl.rst | 13 +++++++++++++ net/mptcp/ctrl.c | 16 ++++++++++++++++ net/mptcp/protocol.h | 1 + 3 files changed, 30 insertions(+) diff --git a/Documentation/networking/mptcp-sysctl.rst b/Documentation/networking/mptcp-sysctl.rst index ee06fd782465..76d939e688b8 100644 --- a/Documentation/networking/mptcp-sysctl.rst +++ b/Documentation/networking/mptcp-sysctl.rst @@ -32,3 +32,16 @@ checksum_enabled - BOOLEAN per-namespace sysctl. Default: 0 + +allow_join_initial_addr_port - BOOLEAN + Allow peers to send join requests to the IP address and port number used + by the initial subflow if the value is 1. This controls a flag that is + sent to the peer at connection time, and whether such join requests are + accepted or denied. + + Joins to addresses advertised with ADD_ADDR are not affected by this + value. + + This is a per-namespace sysctl. + + Default: 1 diff --git a/net/mptcp/ctrl.c b/net/mptcp/ctrl.c index 6c2639bb9c19..7d738bd06f2c 100644 --- a/net/mptcp/ctrl.c +++ b/net/mptcp/ctrl.c @@ -24,6 +24,7 @@ struct mptcp_pernet { u8 mptcp_enabled; unsigned int add_addr_timeout; u8 checksum_enabled; + u8 allow_join_initial_addr_port; }; static struct mptcp_pernet *mptcp_get_pernet(struct net *net) @@ -46,11 +47,17 @@ int mptcp_is_checksum_enabled(struct net *net) return mptcp_get_pernet(net)->checksum_enabled; } +int mptcp_allow_join_id0(struct net *net) +{ + return mptcp_get_pernet(net)->allow_join_initial_addr_port; +} + static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet) { pernet->mptcp_enabled = 1; pernet->add_addr_timeout = TCP_RTO_MAX; pernet->checksum_enabled = 0; + pernet->allow_join_initial_addr_port = 1; } #ifdef CONFIG_SYSCTL @@ -80,6 +87,14 @@ static struct ctl_table mptcp_sysctl_table[] = { .extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_ONE }, + { + .procname = "allow_join_initial_addr_port", + .maxlen = sizeof(u8), + .mode = 0644, + .proc_handler = proc_dou8vec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE + }, {} }; @@ -98,6 +113,7 @@ static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet) table[0].data = &pernet->mptcp_enabled; table[1].data = &pernet->add_addr_timeout; table[2].data = &pernet->checksum_enabled; + table[3].data = &pernet->allow_join_initial_addr_port; hdr = register_net_sysctl(net, MPTCP_SYSCTL_PATH, table); if (!hdr) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 868e878af526..3d6bbdf00bfb 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -543,6 +543,7 @@ static inline void mptcp_subflow_delegated_done(struct mptcp_subflow_context *su int mptcp_is_enabled(struct net *net); unsigned int mptcp_get_add_addr_timeout(struct net *net); int mptcp_is_checksum_enabled(struct net *net); +int mptcp_allow_join_id0(struct net *net); void mptcp_subflow_fully_established(struct mptcp_subflow_context *subflow, struct mptcp_options_received *mp_opt); bool mptcp_subflow_data_available(struct sock *sk); From patchwork Fri May 14 14:32:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 12258527 X-Patchwork-Delegate: mat@martineau.name Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4C0871 for ; Fri, 14 May 2021 14:32:27 +0000 (UTC) Received: by mail-pl1-f178.google.com with SMTP id p17so16234436plf.12 for ; Fri, 14 May 2021 07:32:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qAQ2UsWFkoPWk8owoG7ng0el05DFsOUPOKMldpsNAQc=; b=olBxpyJXHKxjgnS7VTLI3q6s0Z5kGPbZln8rsRwA9dL4JGfSXIclzZxSVn8iMsAS11 FoHSfDvosx7SS+NCCYOQZUo14BBThKeBSfpi5MCRKcMTIJ0iq6eo6DpkB3W29aNINDeu M7W9LSKIlEPZSomG+80UHTrldzvu82dmFFwOMxB8A1UinVA0hKa0CP+SawDgISi9ggyy p1KYN/cLy9Ply2x4aGe5RLfjAELyBNemPzYK/8g+Kvme1Mpaodvknst4VRvruP3u/pAY 0Dzq4W+EyAHtwOz3Y6SXpjVITMu545lzgwzbWU0rRUTSDgwnE3NKtXInSi+ZXUqI/tC2 lEmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qAQ2UsWFkoPWk8owoG7ng0el05DFsOUPOKMldpsNAQc=; b=od3za9dLmvNRi+CQ9hfD05H5ENttiNBDDkXVp18WWz1gK7koun2YouthmoZ7hYgQLd c5mBS38Zhj8e+4MXoHo4KjYNJwwn0iSQ4uj0yvT3whCQETP74/xpu8dVuoYd4XkZGbfC +5TMn15nnWCuM0Fo/XE9DNSdZ6hnmOm1ycdl1ib3jVW7gxCaDl8Ot8nNW2el6UodwCd1 6w+njFGn0C+igbhYvJAdbNVhDos8uBxuiFd6kb9ig26aplNxRnxRCRclBnKFO/9cT9ba 35sEoLP6/ICZzrQXkOxXtyAl8xjkziCBKaQs1VoeXeHjQBRGSZskPr50kGF+LKlOsVKm r66A== X-Gm-Message-State: AOAM5330ZXg8KBeqlEGjSgL2/xdJskMxjmxtdxa/coj40KiQaXTHqX4M cBTeay0f8mZjvHajimu5N1vuPC0D2vQ= X-Google-Smtp-Source: ABdhPJxVpYHXWEsUSeErBogqosZZE0YN6w4fw8LrWteUegiFkmd6IFgpH408DWN5meHRLNRUs/B93A== X-Received: by 2002:a17:90a:4092:: with SMTP id l18mr11425131pjg.35.1621002747461; Fri, 14 May 2021 07:32:27 -0700 (PDT) Received: from localhost ([43.224.245.180]) by smtp.gmail.com with ESMTPSA id y13sm4225682pff.163.2021.05.14.07.32.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 07:32:27 -0700 (PDT) From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [MPTCP][PATCH v6 mptcp-next 2/6] mptcp: add allow_join_id0 in mptcp_out_options Date: Fri, 14 May 2021 22:32:15 +0800 Message-Id: <2a6a925510a7d79f0c2101d5d353f6b74f0e69bb.1621002341.git.geliangtang@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This patch defined a new flag MPTCP_CAP_DENY_JOIN_ID0 for the third bit, labeled "C" of the MP_CAPABLE option. Add a new flag allow_join_id0 in struct mptcp_out_options. If this flag is set, send out the MP_CAPABLE option with the flag MPTCP_CAP_DENY_JOIN_ID0. Signed-off-by: Geliang Tang --- include/net/mptcp.h | 3 ++- net/mptcp/options.c | 6 ++++++ net/mptcp/protocol.h | 6 ++++-- net/mptcp/subflow.c | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index d61bbbf11979..cb580b06152f 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -67,7 +67,8 @@ struct mptcp_out_options { u8 backup; u8 reset_reason:4, reset_transient:1, - csum_reqd:1; + csum_reqd:1, + allow_join_id0:1; u32 nonce; u64 thmac; u32 token; diff --git a/net/mptcp/options.c b/net/mptcp/options.c index b713828819b6..ab9e39d2e645 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -401,6 +401,7 @@ bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb, if (subflow->request_mptcp) { opts->suboptions = OPTION_MPTCP_MPC_SYN; opts->csum_reqd = mptcp_is_checksum_enabled(sock_net(sk)); + opts->allow_join_id0 = mptcp_allow_join_id0(sock_net(sk)); *size = TCPOLEN_MPTCP_MPC_SYN; return true; } else if (subflow->request_join) { @@ -489,6 +490,7 @@ static bool mptcp_established_options_mp(struct sock *sk, struct sk_buff *skb, opts->sndr_key = subflow->local_key; opts->rcvr_key = subflow->remote_key; opts->csum_reqd = READ_ONCE(msk->csum_enabled); + opts->allow_join_id0 = mptcp_allow_join_id0(sock_net(sk)); /* Section 3.1. * The MP_CAPABLE option is carried on the SYN, SYN/ACK, and ACK @@ -826,6 +828,7 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size, opts->suboptions = OPTION_MPTCP_MPC_SYNACK; opts->sndr_key = subflow_req->local_key; opts->csum_reqd = subflow_req->csum_reqd; + opts->allow_join_id0 = subflow_req->allow_join_id0; *size = TCPOLEN_MPTCP_MPC_SYNACK; pr_debug("subflow_req=%p, local_key=%llu", subflow_req, subflow_req->local_key); @@ -1200,6 +1203,9 @@ void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp, if (opts->csum_reqd) flag |= MPTCP_CAP_CHECKSUM_REQD; + if (!opts->allow_join_id0) + flag |= MPTCP_CAP_DENY_JOIN_ID0; + *ptr++ = mptcp_option(MPTCPOPT_MP_CAPABLE, len, MPTCP_SUPPORTED_VERSION, flag); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 3d6bbdf00bfb..fd7ff2d28cb3 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -79,8 +79,9 @@ #define MPTCP_VERSION_MASK (0x0F) #define MPTCP_CAP_CHECKSUM_REQD BIT(7) #define MPTCP_CAP_EXTENSIBILITY BIT(6) +#define MPTCP_CAP_DENY_JOIN_ID0 BIT(5) #define MPTCP_CAP_HMAC_SHA256 BIT(0) -#define MPTCP_CAP_FLAG_MASK (0x3F) +#define MPTCP_CAP_FLAG_MASK (0x1F) /* MPTCP DSS flags */ #define MPTCP_DSS_DATA_FIN BIT(4) @@ -352,7 +353,8 @@ struct mptcp_subflow_request_sock { u16 mp_capable : 1, mp_join : 1, backup : 1, - csum_reqd : 1; + csum_reqd : 1, + allow_join_id0 : 1; u8 local_id; u8 remote_id; u64 local_key; diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 554e7ccee02a..41e1b5091e42 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -109,6 +109,7 @@ static void subflow_init_req(struct request_sock *req, const struct sock *sk_lis subflow_req->mp_capable = 0; subflow_req->mp_join = 0; subflow_req->csum_reqd = mptcp_is_checksum_enabled(sock_net(sk_listener)); + subflow_req->allow_join_id0 = mptcp_allow_join_id0(sock_net(sk_listener)); subflow_req->msk = NULL; mptcp_token_init_request(req); } From patchwork Fri May 14 14:32:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 12258529 X-Patchwork-Delegate: mat@martineau.name Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C091C71 for ; Fri, 14 May 2021 14:32:30 +0000 (UTC) Received: by mail-pl1-f170.google.com with SMTP id b21so16285055plz.0 for ; Fri, 14 May 2021 07:32:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kb4lQO/B4ZAxVnczchP2wus1g/xQmtlfox0+hykADG0=; b=s9/rMF6oEYJyrcvPmwC59gQ8X2Y7gdxgqJ18HxGlEN/niLd+FJzwhOhfgQwGZGMTtM iQfYilQU1zU3ULc3nQDpml0IahYCB/36jVK3Sx1EhAIktpjvs+QREJlc8XqBkMzfH6Rx LDURB0EXe3ZyhLI6Wwa/Gf1SbPwWCmAxCWcbs4DbkUb+l0R/W7tpK3DXQmEOC7VLPEel DOAsWPKkQctAtf3Lrfogb+75/mw4cV8EphS6kkDBCEr6YDTopMySmam5xJ9NOkVA1x6w pK9AogvnNkaHFndns3Fy7oM1XH7/ehBTBFw1DmhLUdvTOXFCQMxj5rwiIhpwVXA/NEpr ds3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kb4lQO/B4ZAxVnczchP2wus1g/xQmtlfox0+hykADG0=; b=EULSQtr+zuRcnm/jA2YZQ2MVrfmG7JuapJqkSwSmaNI2qVSrdg2F48jInbwC5ei5L9 ILnsqWdVzIqf5J6NHm6n+guApstMAVSQVYSU8TH4OnIxdzh2+8vMJoYJdxK/6dPBbIW+ 6loFvH4qmL/7399H6vZj6KfImWOzKRiL3tbDyivWi/JOO/kGqg/MAzACRi+/usl6TQN9 Ei9XHOVUIxwYa0cRquvf+/rZHFVTVsH35KwKXNacsu8hI5yWf8wR3AvolACc7XZ0zsYF nKS/kHTE+8yEnaF6hdBE0lzGWuo23xc4a46Gfx55OiaxWJ9ZvnpyHdUImnO+rt1KQZAu uRBQ== X-Gm-Message-State: AOAM531PRokgQhd8L5SLthnH5d2HGMBmvkGcWCYWSo23ZEnA4XWbh3uI YQtBMkyurFUdWB3i8otwLopEzoD83BE= X-Google-Smtp-Source: ABdhPJxhDSdN2qC3r5pwtkjYyFFIzBr2JAfDnRWixjP4LFZ3GwpU0G9o8b/IiNT6yg/4V6/5oXatFg== X-Received: by 2002:a17:90a:1d44:: with SMTP id u4mr11536646pju.46.1621002750305; Fri, 14 May 2021 07:32:30 -0700 (PDT) Received: from localhost ([43.224.245.180]) by smtp.gmail.com with ESMTPSA id d9sm9350876pjx.41.2021.05.14.07.32.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 07:32:30 -0700 (PDT) From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [MPTCP][PATCH v6 mptcp-next 3/6] mptcp: rename mptcp_pm_add_entry to mptcp_pm_anno_entry Date: Fri, 14 May 2021 22:32:16 +0800 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: <2a6a925510a7d79f0c2101d5d353f6b74f0e69bb.1621002341.git.geliangtang@gmail.com> References: <2a6a925510a7d79f0c2101d5d353f6b74f0e69bb.1621002341.git.geliangtang@gmail.com> X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This patch renamed struct mptcp_pm_add_entry to mptcp_pm_anno_entry, since these entries will be added to the anno_list of PM. Also rename the struct member add_timer to anno_timer. Signed-off-by: Geliang Tang --- net/mptcp/options.c | 2 +- net/mptcp/pm_netlink.c | 50 +++++++++++++++++++++--------------------- net/mptcp/protocol.h | 8 +++---- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index ab9e39d2e645..82fc481a25f0 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -1063,7 +1063,7 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb) MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDR); } else { mptcp_pm_add_addr_echoed(msk, &mp_opt.addr); - mptcp_pm_del_add_timer(msk, &mp_opt.addr); + mptcp_pm_del_anno_timer(msk, &mp_opt.addr); MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ECHOADD); } diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index d094588afad8..4fff8aef45e4 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -31,10 +31,10 @@ struct mptcp_pm_addr_entry { struct socket *lsk; }; -struct mptcp_pm_add_entry { +struct mptcp_pm_anno_entry { struct list_head list; struct mptcp_addr_info addr; - struct timer_list add_timer; + struct timer_list anno_timer; struct mptcp_sock *sock; u8 retrans_times; }; @@ -263,11 +263,11 @@ static void check_work_pending(struct mptcp_sock *msk) WRITE_ONCE(msk->pm.work_pending, false); } -struct mptcp_pm_add_entry * +struct mptcp_pm_anno_entry * mptcp_lookup_anno_list_by_saddr(struct mptcp_sock *msk, struct mptcp_addr_info *addr) { - struct mptcp_pm_add_entry *entry; + struct mptcp_pm_anno_entry *entry; lockdep_assert_held(&msk->pm.lock); @@ -281,7 +281,7 @@ mptcp_lookup_anno_list_by_saddr(struct mptcp_sock *msk, bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk) { - struct mptcp_pm_add_entry *entry; + struct mptcp_pm_anno_entry *entry; struct mptcp_addr_info saddr; bool ret = false; @@ -300,9 +300,9 @@ bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk) return ret; } -static void mptcp_pm_add_timer(struct timer_list *timer) +static void mptcp_pm_anno_timer(struct timer_list *timer) { - struct mptcp_pm_add_entry *entry = from_timer(entry, timer, add_timer); + struct mptcp_pm_anno_entry *entry = from_timer(entry, timer, anno_timer); struct mptcp_sock *msk = entry->sock; struct sock *sk = (struct sock *)msk; @@ -344,11 +344,11 @@ static void mptcp_pm_add_timer(struct timer_list *timer) __sock_put(sk); } -struct mptcp_pm_add_entry * -mptcp_pm_del_add_timer(struct mptcp_sock *msk, - struct mptcp_addr_info *addr) +struct mptcp_pm_anno_entry * +mptcp_pm_del_anno_timer(struct mptcp_sock *msk, + struct mptcp_addr_info *addr) { - struct mptcp_pm_add_entry *entry; + struct mptcp_pm_anno_entry *entry; struct sock *sk = (struct sock *)msk; spin_lock_bh(&msk->pm.lock); @@ -358,7 +358,7 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk, spin_unlock_bh(&msk->pm.lock); if (entry) - sk_stop_timer_sync(sk, &entry->add_timer); + sk_stop_timer_sync(sk, &entry->anno_timer); return entry; } @@ -366,7 +366,7 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk, static bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *entry) { - struct mptcp_pm_add_entry *add_entry = NULL; + struct mptcp_pm_anno_entry *anno_entry = NULL; struct sock *sk = (struct sock *)msk; struct net *net = sock_net(sk); @@ -375,18 +375,18 @@ static bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, if (mptcp_lookup_anno_list_by_saddr(msk, &entry->addr)) return false; - add_entry = kmalloc(sizeof(*add_entry), GFP_ATOMIC); - if (!add_entry) + anno_entry = kmalloc(sizeof(*anno_entry), GFP_ATOMIC); + if (!anno_entry) return false; - list_add(&add_entry->list, &msk->pm.anno_list); + list_add(&anno_entry->list, &msk->pm.anno_list); - add_entry->addr = entry->addr; - add_entry->sock = msk; - add_entry->retrans_times = 0; + anno_entry->addr = entry->addr; + anno_entry->sock = msk; + anno_entry->retrans_times = 0; - timer_setup(&add_entry->add_timer, mptcp_pm_add_timer, 0); - sk_reset_timer(sk, &add_entry->add_timer, + timer_setup(&anno_entry->anno_timer, mptcp_pm_anno_timer, 0); + sk_reset_timer(sk, &anno_entry->anno_timer, jiffies + mptcp_get_add_addr_timeout(net)); return true; @@ -394,7 +394,7 @@ static bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, void mptcp_pm_free_anno_list(struct mptcp_sock *msk) { - struct mptcp_pm_add_entry *entry, *tmp; + struct mptcp_pm_anno_entry *entry, *tmp; struct sock *sk = (struct sock *)msk; LIST_HEAD(free_list); @@ -405,7 +405,7 @@ void mptcp_pm_free_anno_list(struct mptcp_sock *msk) spin_unlock_bh(&msk->pm.lock); list_for_each_entry_safe(entry, tmp, &free_list, list) { - sk_stop_timer_sync(sk, &entry->add_timer); + sk_stop_timer_sync(sk, &entry->anno_timer); kfree(entry); } } @@ -1068,9 +1068,9 @@ __lookup_addr_by_id(struct pm_nl_pernet *pernet, unsigned int id) static bool remove_anno_list_by_saddr(struct mptcp_sock *msk, struct mptcp_addr_info *addr) { - struct mptcp_pm_add_entry *entry; + struct mptcp_pm_anno_entry *entry; - entry = mptcp_pm_del_add_timer(msk, addr); + entry = mptcp_pm_del_anno_timer(msk, addr); if (entry) { list_del(&entry->list); kfree(entry); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index fd7ff2d28cb3..5ccc0d3e5693 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -694,10 +694,10 @@ int mptcp_pm_nl_mp_prio_send_ack(struct mptcp_sock *msk, u8 bkup); void mptcp_pm_free_anno_list(struct mptcp_sock *msk); bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk); -struct mptcp_pm_add_entry * -mptcp_pm_del_add_timer(struct mptcp_sock *msk, - struct mptcp_addr_info *addr); -struct mptcp_pm_add_entry * +struct mptcp_pm_anno_entry * +mptcp_pm_del_anno_timer(struct mptcp_sock *msk, + struct mptcp_addr_info *addr); +struct mptcp_pm_anno_entry * mptcp_lookup_anno_list_by_saddr(struct mptcp_sock *msk, struct mptcp_addr_info *addr); From patchwork Fri May 14 14:32:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 12258531 X-Patchwork-Delegate: mat@martineau.name Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E53D71 for ; Fri, 14 May 2021 14:32:33 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id g24so15506839pji.4 for ; Fri, 14 May 2021 07:32:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=79Qfskin4lRmdCASxoMQEuJjJJ4j5q81EEEvfHmpc2c=; b=vGff3VHmGw3LMUlTcA0xiEiyt52t2/ZXHO8ryu3mb816eAupt5s02qvYZYrDqMnLN/ /GGU2tnEMlagjlTsNQPihrwq7TsKQKO89vG5zfsyMUJXh7/iP1CJmvcqIqvr4Fm8pX+m Drjcr6ssFXJRgIUIHhqDDGcQv9khqv/ANvu9yVWi56Jz0bAZmWhvGEh0R8SPqVsCxDEj bVEzWM5eFGdCiJVHHtrAeqU/XHdLMHvqxu3m/6J+AAl0EaT6qts4LBUZQXRW07l4e+pV iqEmL0pUGZQB1HllJW6dQ5D711j+mMTA0+qAsa34SlqAvF92hfUerkx05xj/MA0WfbAH HRRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=79Qfskin4lRmdCASxoMQEuJjJJ4j5q81EEEvfHmpc2c=; b=osmm12AlNppp+sIAgFH3uPLZj+Q3nIrt0kejqqBAZIYfUNhfprRFZrm8YtfO3A63PU L0yu5kkXkeWV5SLoJXS8JhIItuHtAYENOXbGPieVd6JKwLBz7PH9nUn/vUGRH8QPW4AG Tfa9jPExHw1QAybytz2LbYVGOacOU+UwttgwvSVJqtxht6rDZouGJf8RPXeqY3g74WPU IOhTDiIhy6h5yZ1BQMhad9ksPUFEyCimEO39VmavCYM689Dan/zAp9019WQqInLLcH3Q aIBQ2uNMkKK15/588zxB110hnVzhzRXjD04nZWy61WF5BQf64V7I90h8aSv2BqkOqYf4 uaxA== X-Gm-Message-State: AOAM533Nm8T2hQfsYmKwodccmp+O2tZuxL5ZTXVKZYXwhpxok5dqg5A5 3B8KHa0Fa1wzTm2DVcSyxgQ3ZDpDpHY= X-Google-Smtp-Source: ABdhPJx5vqzWjXDm67iMD503Q6gIMLAhsHr4kiNmpMf4PvG93tBrkzt+tJLN5oBS/NAxLLxoIDKNFQ== X-Received: by 2002:a17:90a:6be1:: with SMTP id w88mr11509958pjj.101.1621002752663; Fri, 14 May 2021 07:32:32 -0700 (PDT) Received: from localhost ([43.224.245.180]) by smtp.gmail.com with ESMTPSA id n129sm4390208pfn.54.2021.05.14.07.32.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 07:32:32 -0700 (PDT) From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [MPTCP][PATCH v6 mptcp-next 4/6] mptcp: add add_list in mptcp_pm_data Date: Fri, 14 May 2021 22:32:17 +0800 Message-Id: <850406b0f49fa0a76b4825b36c55426a0d033d52.1621002341.git.geliangtang@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: <2a6a925510a7d79f0c2101d5d353f6b74f0e69bb.1621002341.git.geliangtang@gmail.com> X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Like the anno_list member in struct mptcp_pm_data, this patch added a new member named add_list in it, to save all the received ADD_ADDRs in this add_list. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 1 + net/mptcp/pm_netlink.c | 89 +++++++++++++++++++++++++++++++++++++++--- net/mptcp/protocol.c | 1 + net/mptcp/protocol.h | 2 + 4 files changed, 87 insertions(+), 6 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 9d00fa6d22e9..9456fe17b6a3 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -324,6 +324,7 @@ void mptcp_pm_data_init(struct mptcp_sock *msk) spin_lock_init(&msk->pm.lock); INIT_LIST_HEAD(&msk->pm.anno_list); + INIT_LIST_HEAD(&msk->pm.add_list); mptcp_pm_nl_data_init(msk); } diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 4fff8aef45e4..3fcc167ea702 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -39,6 +39,11 @@ struct mptcp_pm_anno_entry { u8 retrans_times; }; +struct mptcp_pm_add_entry { + struct list_head list; + struct mptcp_addr_info addr; +}; + #define MAX_ADDR_ID 255 #define BITMAP_SZ DIV_ROUND_UP(MAX_ADDR_ID + 1, BITS_PER_LONG) @@ -483,6 +488,69 @@ static void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk) mptcp_pm_create_subflow_or_signal_addr(msk); } +struct mptcp_pm_add_entry * +mptcp_lookup_add_list_by_id(struct mptcp_sock *msk, u8 id) +{ + struct mptcp_pm_add_entry *entry; + + lockdep_assert_held(&msk->pm.lock); + + list_for_each_entry(entry, &msk->pm.add_list, list) { + if (entry->addr.id == id) + return entry; + } + + return NULL; +} + +struct mptcp_pm_add_entry * +mptcp_lookup_add_list_by_saddr(struct mptcp_sock *msk, + struct mptcp_addr_info *addr) +{ + struct mptcp_pm_add_entry *entry; + + lockdep_assert_held(&msk->pm.lock); + + list_for_each_entry(entry, &msk->pm.add_list, list) { + if (addresses_equal(&entry->addr, addr, true)) + return entry; + } + + return NULL; +} + +static bool mptcp_pm_alloc_add_list(struct mptcp_sock *msk, + struct mptcp_addr_info *addr) +{ + struct mptcp_pm_add_entry *add_entry = NULL; + + lockdep_assert_held(&msk->pm.lock); + + if (mptcp_lookup_add_list_by_saddr(msk, addr)) + return false; + + add_entry = kmalloc(sizeof(*add_entry), GFP_ATOMIC); + if (!add_entry) + return false; + + list_add(&add_entry->list, &msk->pm.add_list); + add_entry->addr = *addr; + + return true; +} + +void mptcp_pm_free_add_list(struct mptcp_sock *msk) +{ + struct mptcp_pm_add_entry *entry, *tmp; + + pr_debug("msk=%p", msk); + + spin_lock_bh(&msk->pm.lock); + list_for_each_entry_safe(entry, tmp, &msk->pm.add_list, list) + kfree(entry); + spin_unlock_bh(&msk->pm.lock); +} + static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) { struct sock *sk = (struct sock *)msk; @@ -501,12 +569,6 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) if (lookup_subflow_by_daddr(&msk->conn_list, &msk->pm.remote)) goto add_addr_echo; - msk->pm.add_addr_accepted++; - msk->pm.subflows++; - if (msk->pm.add_addr_accepted >= add_addr_accept_max || - msk->pm.subflows >= subflows_max) - WRITE_ONCE(msk->pm.accept_addr, false); - /* connect to the specified remote address, using whatever * local address the routing configuration will pick. */ @@ -516,6 +578,15 @@ static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk) memset(&local, 0, sizeof(local)); local.family = remote.family; + if (!mptcp_pm_alloc_add_list(msk, &remote)) + return; + + msk->pm.add_addr_accepted++; + msk->pm.subflows++; + if (msk->pm.add_addr_accepted >= add_addr_accept_max || + msk->pm.subflows >= subflows_max) + WRITE_ONCE(msk->pm.accept_addr, false); + spin_unlock_bh(&msk->pm.lock); __mptcp_subflow_connect(sk, &local, &remote, 0, 0); spin_lock_bh(&msk->pm.lock); @@ -612,6 +683,7 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk, list_for_each_entry_safe(subflow, tmp, &msk->conn_list, node) { struct sock *ssk = mptcp_subflow_tcp_sock(subflow); int how = RCV_SHUTDOWN | SEND_SHUTDOWN; + struct mptcp_pm_add_entry *entry; u8 id = subflow->local_id; if (rm_type == MPTCP_MIB_RMADDR) @@ -631,6 +703,11 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk, if (rm_type == MPTCP_MIB_RMADDR) { msk->pm.add_addr_accepted--; WRITE_ONCE(msk->pm.accept_addr, true); + entry = mptcp_lookup_add_list_by_id(msk, id); + if (entry) { + list_del(&entry->list); + kfree(entry); + } } else if (rm_type == MPTCP_MIB_RMSUBFLOW) { msk->pm.local_addr_used--; } diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 35c0b1ca95c3..05ceba3972f6 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -2888,6 +2888,7 @@ void mptcp_destroy_common(struct mptcp_sock *msk) skb_rbtree_purge(&msk->out_of_order_queue); mptcp_token_destroy(msk); mptcp_pm_free_anno_list(msk); + mptcp_pm_free_add_list(msk); } static void mptcp_destroy(struct sock *sk) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 5ccc0d3e5693..1df8da3da695 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -185,6 +185,7 @@ struct mptcp_pm_data { struct mptcp_addr_info local; struct mptcp_addr_info remote; struct list_head anno_list; + struct list_head add_list; spinlock_t lock; /*protects the whole PM data */ @@ -693,6 +694,7 @@ int mptcp_pm_nl_mp_prio_send_ack(struct mptcp_sock *msk, struct mptcp_addr_info *addr, u8 bkup); void mptcp_pm_free_anno_list(struct mptcp_sock *msk); +void mptcp_pm_free_add_list(struct mptcp_sock *msk); bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk); struct mptcp_pm_anno_entry * mptcp_pm_del_anno_timer(struct mptcp_sock *msk, From patchwork Fri May 14 14:32:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 12258533 X-Patchwork-Delegate: mat@martineau.name Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECF9071 for ; Fri, 14 May 2021 14:32:35 +0000 (UTC) Received: by mail-pg1-f169.google.com with SMTP id q15so20003636pgg.12 for ; Fri, 14 May 2021 07:32:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q6DPdU5vqqgpdTQhmTCh06KwCubJVcwvk7HBBp+dh5Y=; b=bF/kd4qG0cvX8qbVa2P2ZntDxzgsTWU0zYS+jh/5S8w4bhJyM3HY/ZB3Vc/3zinVZb pzlUY9vZ8nr2jaPA01RuB+uuMKH/5SMMozBqxsQlgyGhi+axYHXMNbNtIdfeE2IItm01 4X6U7iHjGRjXZctofeBsseNzvGGi5IcKRwE2pm259wc0bbPIW7koWocFgPpuFsdBXZDL UY1rIQTHSaiszRy10Nex+HlvoctfLOY/sGe/kU5xEXb18K0BIwzOGNb73Hcp/gHA334Q amakNkeiuQWyTrJP/UK26fC5jIrqz3NAz3PEo5OmpO2/NBgnXvwTBWWj4G5EPBtO7wHE cP2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q6DPdU5vqqgpdTQhmTCh06KwCubJVcwvk7HBBp+dh5Y=; b=jq1NDzMsBdPSvoDt640O6FOApqA16kWtmjdhYbh7X+UaLyu4fAEU40fddQHSy8dKkX v5FxpC6V2ZWVc+NAphANwimfU5kyRvdhJYdH6X9JbejKyO/8MekbOeouufeQd6ISMBAi wPzJeviJArMRRX2ng6xi/+SjZyQAnL0wP3RNDnPFUtub5WwdoWvwgk+tn9GqNZUrb+i5 9uN81PTN0MccCNOroF3MLM5E2MgLSlc7av6Zr1OmROkcfUzuewbsVz6ova98tjj4/Aer BR13Hg+5Etuo4bpIxgUambRerQHR3Jt1/aI8o7Qd908XxbQZmyLLzX0mr6WEStnXDIZ9 bw0A== X-Gm-Message-State: AOAM531ShjRgmbTjEcOPorjGkhc84DLOb3wrPVgN1Y9Ex+Ixx9MjPUdq 1wv8kZX3Af0uCiPWp+l7JiRQ7TEGYQo= X-Google-Smtp-Source: ABdhPJw3yNJOdzkP6IgC2wGZzd7xQaGoULXev1Xr9A2OawzK1whfRP4OqqI3JZXcHe9ev/fTiLh2Og== X-Received: by 2002:a65:50c5:: with SMTP id s5mr47204261pgp.138.1621002755404; Fri, 14 May 2021 07:32:35 -0700 (PDT) Received: from localhost ([43.224.245.180]) by smtp.gmail.com with ESMTPSA id ha14sm4924926pjb.40.2021.05.14.07.32.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 07:32:35 -0700 (PDT) From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Florian Westphal Subject: [MPTCP][PATCH v6 mptcp-next 5/6] mptcp: add deny_join_id0 in mptcp_options_received Date: Fri, 14 May 2021 22:32:18 +0800 Message-Id: <774cef61ee52ed2c84c9113205b706e24c4d7c48.1621002341.git.geliangtang@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <850406b0f49fa0a76b4825b36c55426a0d033d52.1621002341.git.geliangtang@gmail.com> References: <2a6a925510a7d79f0c2101d5d353f6b74f0e69bb.1621002341.git.geliangtang@gmail.com> <850406b0f49fa0a76b4825b36c55426a0d033d52.1621002341.git.geliangtang@gmail.com> X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This patch added a new flag named deny_join_id0 in struct mptcp_options_received. Set it when MP_CAPABLE with the flag MPTCP_CAP_DENYJOIN_ID0 is received. Also add a new flag remote_deny_join_id0 in struct mptcp_pm_data. When the flag deny_join_id0 is set, set this remote_deny_join_id0 flag. In mptcp_pm_create_subflow_or_signal_addr, if the remote_deny_join_id0 flag is set, and the remote address id is zero, stop this connection. Suggested-by: Florian Westphal Signed-off-by: Geliang Tang --- net/mptcp/options.c | 6 ++++++ net/mptcp/pm.c | 1 + net/mptcp/pm_netlink.c | 12 +++++++++++- net/mptcp/protocol.h | 4 +++- net/mptcp/subflow.c | 2 ++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/net/mptcp/options.c b/net/mptcp/options.c index 82fc481a25f0..bb600eb29f3c 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -83,6 +83,9 @@ static void mptcp_parse_option(const struct sk_buff *skb, if (flags & MPTCP_CAP_CHECKSUM_REQD) mp_opt->csum_reqd = 1; + if (flags & MPTCP_CAP_DENY_JOIN_ID0) + mp_opt->deny_join_id0 = 1; + mp_opt->mp_capable = 1; if (opsize >= TCPOLEN_MPTCP_MPC_SYNACK) { mp_opt->sndr_key = get_unaligned_be64(ptr); @@ -361,6 +364,7 @@ void mptcp_get_options(const struct sock *sk, mp_opt->mp_prio = 0; mp_opt->reset = 0; mp_opt->csum_reqd = READ_ONCE(msk->csum_enabled); + mp_opt->deny_join_id0 = 0; length = (th->doff * 4) - sizeof(struct tcphdr); ptr = (const unsigned char *)(th + 1); @@ -1048,6 +1052,8 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb) } mptcp_get_options(sk, skb, &mp_opt); + if (mp_opt.deny_join_id0) + WRITE_ONCE(msk->pm.remote_deny_join_id0, true); if (!check_fully_established(msk, sk, subflow, skb, &mp_opt)) return; diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 9456fe17b6a3..23a309f641aa 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -320,6 +320,7 @@ void mptcp_pm_data_init(struct mptcp_sock *msk) WRITE_ONCE(msk->pm.addr_signal, 0); WRITE_ONCE(msk->pm.accept_addr, false); WRITE_ONCE(msk->pm.accept_subflow, false); + WRITE_ONCE(msk->pm.remote_deny_join_id0, false); msk->pm.status = 0; spin_lock_init(&msk->pm.lock); diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 3fcc167ea702..bdc174cdb42e 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -461,10 +461,20 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) if (local) { struct mptcp_addr_info remote = { 0 }; + remote_address((struct sock_common *)sk, &remote); + if (READ_ONCE(msk->pm.remote_deny_join_id0)) { + struct mptcp_pm_add_entry *entry; + + entry = list_first_entry_or_null(&msk->pm.add_list, + typeof(*entry), list); + if (!entry) + return; + + remote = entry->addr; + } msk->pm.local_addr_used++; msk->pm.subflows++; check_work_pending(msk); - remote_address((struct sock_common *)sk, &remote); spin_unlock_bh(&msk->pm.lock); __mptcp_subflow_connect(sk, &local->addr, &remote, local->flags, local->ifindex); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 1df8da3da695..136b7f9b5cd9 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -138,7 +138,8 @@ struct mptcp_options_received { mp_prio : 1, echo : 1, csum_reqd : 1, - backup : 1; + backup : 1, + deny_join_id0 : 1; u32 token; u32 nonce; u64 thmac; @@ -194,6 +195,7 @@ struct mptcp_pm_data { bool work_pending; bool accept_addr; bool accept_subflow; + bool remote_deny_join_id0; u8 add_addr_signaled; u8 add_addr_accepted; u8 local_addr_used; diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 41e1b5091e42..0e6e9c9dc976 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -408,6 +408,8 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb) if (mp_opt.csum_reqd) WRITE_ONCE(mptcp_sk(parent)->csum_enabled, true); + if (mp_opt.deny_join_id0) + WRITE_ONCE(mptcp_sk(parent)->pm.remote_deny_join_id0, true); subflow->mp_capable = 1; subflow->can_ack = 1; subflow->remote_key = mp_opt.sndr_key; From patchwork Fri May 14 14:32:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 12258535 X-Patchwork-Delegate: mat@martineau.name Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E66171 for ; Fri, 14 May 2021 14:32:38 +0000 (UTC) Received: by mail-pj1-f48.google.com with SMTP id ep16-20020a17090ae650b029015d00f578a8so1722819pjb.2 for ; Fri, 14 May 2021 07:32:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vCAtB47EYneB9xZ3pqNAlLvPbgQtyyLLAKTR5G44eUA=; b=OhtXeNaCf+Qu74jlrpgOfKk9UFHPWPhzPScVF+K73bZB+d3t9CKTeUFakRGuv5o+x1 o0s1hJphHmbPHB3ONJgFmzko5McCZfi1Tl6Lrz44a+GVpgk0sCtsG1i+CDMWFHs4SaUD wHZrmXwHAonKzD8KGzjjmRf1+gr1w/18qssnWREi0O3gsgQNbjJaTMB54/aTKC9Eeu/9 QPydGKdNv5286qlqGakAQEztApv3VNB2/lBUiYcn8CSA2GNnQLAK4Oiv3O9sNKwzRocy YPe2VtqDFx/No4A3pyD3QoJm8y42CJoAx6/qQyCHUQu9dFW4eUKH81nZHLXDWoYvfv0k BRhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vCAtB47EYneB9xZ3pqNAlLvPbgQtyyLLAKTR5G44eUA=; b=ZwilKjuaYG64iM9AEiq2jXJNhX/fkHl0APgSkRggPR47kUIuqpOUKFXRrmHOGGqBI1 6I++Mjlaqo0tvtTnbwm8mmZVTysgLou8DncPatNSP9yPQ4Vk+zE6ZcvYjuS48x6P49L+ Igc4Z+bfFRAoxGR7eGKHuZzDe/W+0KoY2ALMXeIYdOUyAEkd7OlF+HKujtLyrEF59fU4 hWX1Hv3FDwmicTEpcJOBbv31wPQc5BE+tApkaHxhd2IUnjaTAF1F1HUJAmupzzM+Vre8 yeHlWCO7b6Mj3kv+Ia8sG7U9ikfCCCX/y3VinYJKweLrhQYbAOCpVyDJbJicE9wyYe+/ Dfjg== X-Gm-Message-State: AOAM531RyGuiUjdpcuUDFSnt0JkqgesvgJfGv8J2afoTDw4DSUEJU/Iy MGckVAZUmmU9x7ApAiYlk6mhCg0SAHU= X-Google-Smtp-Source: ABdhPJxsRfedk+hOeNo24AIJIoveCDLDkyhtlo3nS7T66/yAMHBywbJtFKOSIa1pUeUJFEWsez8JWw== X-Received: by 2002:a17:902:e007:b029:ef:9dd2:be6 with SMTP id o7-20020a170902e007b02900ef9dd20be6mr8079508plo.12.1621002757676; Fri, 14 May 2021 07:32:37 -0700 (PDT) Received: from localhost ([43.224.245.180]) by smtp.gmail.com with ESMTPSA id r11sm4411441pgl.34.2021.05.14.07.32.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 07:32:37 -0700 (PDT) From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [MPTCP][PATCH v6 mptcp-next 6/6] selftests: mptcp: add deny_join_id0 testcases Date: Fri, 14 May 2021 22:32:19 +0800 Message-Id: <26460564eb974520c1d7724c25ef08293450af6e.1621002341.git.geliangtang@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <774cef61ee52ed2c84c9113205b706e24c4d7c48.1621002341.git.geliangtang@gmail.com> References: <2a6a925510a7d79f0c2101d5d353f6b74f0e69bb.1621002341.git.geliangtang@gmail.com> <850406b0f49fa0a76b4825b36c55426a0d033d52.1621002341.git.geliangtang@gmail.com> <774cef61ee52ed2c84c9113205b706e24c4d7c48.1621002341.git.geliangtang@gmail.com> X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This patch added a new argument '-d' for mptcp_join.sh script, to invoke the testcases for the MP_CAPABLE 'C' flag. Signed-off-by: Geliang Tang --- .../testing/selftests/net/mptcp/mptcp_join.sh | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh index 523c7797f30a..17b385f011d2 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -139,6 +139,17 @@ reset_with_checksum() ip netns exec $ns2 sysctl -q net.mptcp.checksum_enabled=$ns2_enable } +reset_with_allow_join_id0() +{ + local ns1_enable=$1 + local ns2_enable=$2 + + reset + + ip netns exec $ns1 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns1_enable + ip netns exec $ns2 sysctl -q net.mptcp.allow_join_initial_addr_port=$ns2_enable +} + ip -Version > /dev/null 2>&1 if [ $? -ne 0 ];then echo "SKIP: Could not run test without ip tool" @@ -1462,6 +1473,44 @@ checksum_tests() chk_csum_nr "checksum test 1 0" } +deny_join_id0_tests() +{ + # subflow allow join id0 ns1 + reset_with_allow_join_id0 1 0 + ip netns exec $ns1 ./pm_nl_ctl limits 1 1 + ip netns exec $ns2 ./pm_nl_ctl limits 1 1 + ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow + run_tests $ns1 $ns2 10.0.1.1 + chk_join_nr "single subflow allow join id0 ns1" 1 1 1 + + # subflow allow join id0 ns2 + reset_with_allow_join_id0 0 1 + ip netns exec $ns1 ./pm_nl_ctl limits 1 1 + ip netns exec $ns2 ./pm_nl_ctl limits 1 1 + ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow + run_tests $ns1 $ns2 10.0.1.1 + chk_join_nr "single subflow allow join id0 ns2" 0 0 0 + + # subflow and address allow join id0 + reset_with_allow_join_id0 0 1 + ip netns exec $ns1 ./pm_nl_ctl limits 2 2 + ip netns exec $ns2 ./pm_nl_ctl limits 2 2 + ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal + ip netns exec $ns2 ./pm_nl_ctl add 10.0.3.2 flags subflow + run_tests $ns1 $ns2 10.0.1.1 + chk_join_nr "subflow and address allow join id0" 2 2 2 + + # signal address allow join id0 + # ADD_ADDRs are not affected by allow_join_id0 value. + reset_with_allow_join_id0 0 0 + ip netns exec $ns1 ./pm_nl_ctl limits 1 1 + ip netns exec $ns2 ./pm_nl_ctl limits 1 1 + ip netns exec $ns1 ./pm_nl_ctl add 10.0.2.1 flags signal + run_tests $ns1 $ns2 10.0.1.1 + chk_join_nr "signal address allow join id0" 1 1 1 + chk_add_nr 1 1 +} + all_tests() { subflows_tests @@ -1476,6 +1525,7 @@ all_tests() add_addr_ports_tests syncookies_tests checksum_tests + deny_join_id0_tests } usage() @@ -1493,6 +1543,7 @@ usage() echo " -p add_addr_ports_tests" echo " -k syncookies_tests" echo " -S checksum_tests" + echo " -d deny_join_id0_tests" echo " -c capture pcap files" echo " -C enable data checksum" echo " -h help" @@ -1528,7 +1579,7 @@ if [ $do_all_tests -eq 1 ]; then exit $ret fi -while getopts 'fsltra64bpkchCS' opt; do +while getopts 'fsltra64bpkdchCS' opt; do case $opt in f) subflows_tests @@ -1566,6 +1617,9 @@ while getopts 'fsltra64bpkchCS' opt; do S) checksum_tests ;; + d) + deny_join_id0_tests + ;; c) ;; C)