mptcp: Miscellaneous cleanup
Subsystems (4)
cover mptcp: Miscellaneous cleanup
Here are some cleanup patches we've collected in the MPTCP tree.
Patches 1-4 do some general tidying.
Patch 5 adds an explicit check at netlink command parsing time to require a port number when the 'signal' flag is set, to catch the error earlier.
Patches 6 & 7 fix up the MPTCP 'enabled' sysctl, enforcing it as a boolean value, and ensuring that the !CONFIG_SYSCTL build still works after the boolean change.
Jianguo Wu (5):
mptcp: fix pr_debug in mptcp_token_new_connect
mptcp: using TOKEN_MAX_RETRIES instead of magic number
mptcp: generate subflow hmac after mptcp_finish_join()
mptcp: remove redundant initialization in pm_nl_init_net()
mptcp: make sure flag signal is set when add addr with port
Matthieu Baerts (2):
mptcp: support SYSCTL only if enabled
mptcp: restrict values of 'enabled' sysctl
Documentation/networking/mptcp-sysctl.rst | 8 ++--- net/mptcp/ctrl.c | 36 +++++++++++++++++------ net/mptcp/pm_netlink.c | 15 ++++++++-- net/mptcp/protocol.h | 2 ++ net/mptcp/subflow.c | 8 ++--- net/mptcp/token.c | 9 +++--- 6 files changed, 53 insertions(+), 25 deletions(-)
base-commit: 91b17a436759e9f3a6f9ff090693564c3299cd9a
Signature · 1 line
2.31.1
PATCH 1/7 mptcp: fix pr_debug in mptcp_token_new_connect
From: Jianguo Wu <[email protected]>
After commit 2c5ebd001d4f ("mptcp: refactor token container"), pr_debug() is called before mptcp_crypto_key_gen_sha() in mptcp_token_new_connect(), so the output local_key, token and idsn are 0, like:
MPTCP: ssk=00000000f6b3c4a2, local_key=0, token=0, idsn=0
Move pr_debug() after mptcp_crypto_key_gen_sha().
--- net/mptcp/token.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/mptcp/token.c +3 -3
@@ -156,9 +156,6 @@ int mptcp_token_new_connect(struct sock *sk)int retries =TOKEN_MAX_RETRIES ;struct token_bucket *bucket; -pr_debug ("ssk=%p, local_key=%llu, token=%u, idsn=%llu\n" , - sk, subflow->local_key, subflow->token, subflow->idsn); - again:mptcp_crypto_key_gen_sha (&subflow->local_key, &subflow->token, &subflow->idsn);
@@ -172,6 +169,9 @@ int mptcp_token_new_connect(struct sock *sk) goto again; } +pr_debug ("ssk=%p, local_key=%llu, token=%u, idsn=%llu\n" , + sk, subflow->local_key, subflow->token, subflow->idsn); +WRITE_ONCE (msk->token, subflow->token);__sk_nulls_add_node_rcu ((struct sock *)msk, &bucket->msk_chain); bucket->chain_len++;
Signature · 1 line
2.31.1
PATCH 2/7 mptcp: using TOKEN_MAX_RETRIES instead of magic number
In reply to Mat MartineauFrom: Jianguo Wu <[email protected]>
We have macro TOKEN_MAX_RETRIES for the number of token generate retries, so using TOKEN_MAX_RETRIES in subflow_check_req().
And rename TOKEN_MAX_RETRIES to MPTCP_TOKEN_MAX_RETRIES as it is now exposed.
--- net/mptcp/protocol.h | 2 ++ net/mptcp/subflow.c | 2 +- net/mptcp/token.c | 3 +-- 3 files changed, 4 insertions(+), 3 deletions(-)
net/mptcp/protocol.h +2 -0
@@ -627,6 +627,8 @@ static inline void mptcp_write_space(struct sock *sk)void mptcp_destroy_common (struct mptcp_sock *msk); +#define MPTCP_TOKEN_MAX_RETRIES 4 +void __init mptcp_token_init (void );static inline void mptcp_token_init_request (struct request_sock *req) {
net/mptcp/subflow.c +1 -1
@@ -162,7 +162,7 @@ static int subflow_check_req(struct request_sock *req, }if (mp_opt.mp_capable && listener->request_mptcp) { -int err, retries =4 ; +int err, retries =MPTCP_TOKEN_MAX_RETRIES ; subflow_req->ssn_offset =TCP_SKB_CB (skb)->seq; again:
net/mptcp/token.c +1 -2
@@ -33,7 +33,6 @@#include <net/mptcp.h> #include "protocol.h" -#define TOKEN_MAX_RETRIES 4#define TOKEN_MAX_CHAIN_LEN 4struct token_bucket {
@@ -153,7 +152,7 @@ int mptcp_token_new_connect(struct sock *sk) {struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (sk);struct mptcp_sock *msk =mptcp_sk (subflow->conn); -int retries =TOKEN_MAX_RETRIES ; +int retries =MPTCP_TOKEN_MAX_RETRIES ;struct token_bucket *bucket; again:
Signature · 1 line
2.31.1
PATCH 3/7 mptcp: generate subflow hmac after mptcp_finish_join()
In reply to Mat MartineauFrom: Jianguo Wu <[email protected]>
For outgoing subflow join, when recv SYNACK, in subflow_finish_connect(), the mptcp_finish_join() may return false in some cases, and send a RESET to remote, and no local hmac is required.
So generate subflow hmac after mptcp_finish_join().
--- net/mptcp/subflow.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/mptcp/subflow.c +3 -3
@@ -430,15 +430,15 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb) goto do_reset; } +if (!mptcp_finish_join (sk)) + goto do_reset; +subflow_generate_hmac (subflow->local_key, subflow->remote_key, subflow->local_nonce, subflow->remote_nonce, hmac);memcpy (subflow->hmac, hmac,MPTCPOPT_HMAC_LEN ); -if (!mptcp_finish_join (sk)) - goto do_reset; - subflow->mp_join =1 ;MPTCP_INC_STATS (sock_net (sk),MPTCP_MIB_JOINSYNACKRX );
Signature · 1 line
2.31.1
PATCH 4/7 mptcp: remove redundant initialization in pm_nl_init_net()
In reply to Mat MartineauFrom: Jianguo Wu <[email protected]>
Memory of struct pm_nl_pernet{} is allocated by kzalloc() in setup_net()->ops_init(), so it's no need to reset counters and zero bitmap in pm_nl_init_net().
--- net/mptcp/pm_netlink.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/mptcp/pm_netlink.c +5 -2
@@ -1913,10 +1913,13 @@ static int __net_init pm_nl_init_net(struct net *net)struct pm_nl_pernet *pernet =net_generic (net, pm_nl_pernet_id);INIT_LIST_HEAD_RCU (&pernet->local_addr_list); -__reset_counters (pernet); pernet->next_id =1 ; -bitmap_zero (pernet->id_bitmap,MAX_ADDR_ID +1 );spin_lock_init (&pernet->lock); + +/* No need to initialize other pernet fields, the struct is zeroed at +* allocation time. +*/ +return 0 ; }
Signature · 1 line
2.31.1
PATCH 5/7 mptcp: make sure flag signal is set when add addr with port
In reply to Mat MartineauFrom: Jianguo Wu <[email protected]>
When add address with port, it is mean to create a listening socket, and send an ADD_ADDR to remote, so it must have flag signal set, add this check in mptcp_pm_parse_addr().
--- net/mptcp/pm_netlink.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/mptcp/pm_netlink.c +7 -1
@@ -971,8 +971,14 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,if (tb[MPTCP_PM_ADDR_ATTR_FLAGS ]) entry->flags =nla_get_u32 (tb[MPTCP_PM_ADDR_ATTR_FLAGS ]); -if (tb[MPTCP_PM_ADDR_ATTR_PORT ]) +if (tb[MPTCP_PM_ADDR_ATTR_PORT ]) { +if (!(entry->flags &MPTCP_PM_ADDR_FLAG_SIGNAL )) { +NL_SET_ERR_MSG_ATTR (info->extack, attr, +"flags must have signal when using port" ); +return -EINVAL ; + } entry->addr.port =htons (nla_get_u16 (tb[MPTCP_PM_ADDR_ATTR_PORT ])); + }return 0 ; }
Signature · 1 line
2.31.1
PATCH 6/7 mptcp: support SYSCTL only if enabled
In reply to Mat MartineauFrom: Matthieu Baerts <[email protected]>
Since the introduction of the sysctl support in MPTCP with commit 784325e9f037 ("mptcp: new sysctl to control the activation per NS"), we don't check CONFIG_SYSCTL.
Until now, that was not an issue: the register and unregister functions were replaced by NO-OP one if SYSCTL was not enabled in the config. The only thing we could have avoid is not to reserve memory for the table but that's for the moment only a small table per net-ns.
But the following commit is going to use SYSCTL_ZERO and SYSCTL_ONE which are not be defined if SYSCTL is not enabled in the config. This causes 'undefined reference' errors from the linker.
--- net/mptcp/ctrl.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
net/mptcp/ctrl.c +22 -6
@@ -4,7 +4,9 @@* Copyright (c) 2019, Tessares SA. */ +#ifdef CONFIG_SYSCTL #include <linux/sysctl.h> +#endif #include <net/net_namespace.h> #include <net/netns/generic.h>
@@ -15,7 +17,9 @@static int mptcp_pernet_id;struct mptcp_pernet { +#ifdef CONFIG_SYSCTL struct ctl_table_header *ctl_table_hdr; +#endif int mptcp_enabled;unsigned int add_addr_timeout;
@@ -36,6 +40,13 @@ unsigned int mptcp_get_add_addr_timeout(struct net *net)return mptcp_get_pernet (net)->add_addr_timeout; } +static void mptcp_pernet_set_defaults (struct mptcp_pernet *pernet) +{ + pernet->mptcp_enabled =1 ; + pernet->add_addr_timeout =TCP_RTO_MAX ; +} + +#ifdef CONFIG_SYSCTL static struct ctl_table mptcp_sysctl_table[] = { { .procname = "enabled",
@@ -55,12 +66,6 @@ static struct ctl_table mptcp_sysctl_table[] = { {} }; -static void mptcp_pernet_set_defaults (struct mptcp_pernet *pernet) -{ - pernet->mptcp_enabled =1 ; - pernet->add_addr_timeout =TCP_RTO_MAX ; -} -static int mptcp_pernet_new_table (struct net *net,struct mptcp_pernet *pernet) {struct ctl_table_header *hdr;
@@ -100,6 +105,17 @@ static void mptcp_pernet_del_table(struct mptcp_pernet *pernet) kfree(table); } +#else + +static int mptcp_pernet_new_table (struct net *net,struct mptcp_pernet *pernet) +{ +return 0 ; +} + +static void mptcp_pernet_del_table (struct mptcp_pernet *pernet) {} + +#endif /* CONFIG_SYSCTL */ +static int __net_init mptcp_net_init (struct net *net) {struct mptcp_pernet *pernet =mptcp_get_pernet (net);
Signature · 1 line
2.31.1
PATCH 7/7 mptcp: restrict values of 'enabled' sysctl
In reply to Mat MartineauFrom: Matthieu Baerts <[email protected]>
To avoid confusions, it seems better to parse this sysctl parameter as a boolean. We use it as a boolean, no need to parse an integer and bring confusions if we see a value different from 0 and 1, especially with this parameter name: enabled.
It seems fine to do this modification because the default value is 1 (enabled). Then the only other interesting value to set is 0 (disabled). All other values would not have changed the default behaviour.
--- Documentation/networking/mptcp-sysctl.rst | 8 ++++---- net/mptcp/ctrl.c | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-)
Documentation/networking/mptcp-sysctl.rst +4 -4
@@ -7,13 +7,13 @@ MPTCP Sysfs variables /proc/sys/net/mptcp/* Variables =============================== -enabled - INTEGER +enabled - BOOLEAN Control whether MPTCP sockets can be created. - MPTCP sockets can be created if the value is nonzero. This is - a per-namespace sysctl. + MPTCP sockets can be created if the value is 1. This is a + per-namespace sysctl. - Default: 1 + Default: 1 (enabled) add_addr_timeout - INTEGER (seconds) Set the timeout after which an ADD_ADDR control message will be
net/mptcp/ctrl.c +5 -3
@@ -21,7 +21,7 @@ struct mptcp_pernet {struct ctl_table_header *ctl_table_hdr;#endif -int mptcp_enabled; +u8 mptcp_enabled;unsigned int add_addr_timeout; };
@@ -50,12 +50,14 @@ static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet)static struct ctl_table mptcp_sysctl_table[] = { { .procname ="enabled" , - .maxlen =sizeof (int ), + .maxlen =sizeof (u8), .mode =0644 ,/* users with CAP_NET_ADMIN or root (not and) can change this * value, same as other sysctl or the 'net' tree. */ - .proc_handler = proc_dointvec, + .proc_handler = proc_dou8vec_minmax, + .extra1 =SYSCTL_ZERO , + .extra2 =SYSCTL_ONE }, { .procname ="add_addr_timeout" ,
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerQuoted 11 lines · On Thu, 27 May 2021 16:54:23 -0700 Mat Martineau wrote:
Here are some cleanup patches we've collected in the MPTCP tree.
Patches 1-4 do some general tidying.
Patch 5 adds an explicit check at netlink command parsing time to require a port number when the 'signal' flag is set, to catch the error earlier.
Patches 6 & 7 fix up the MPTCP 'enabled' sysctl, enforcing it as a boolean value, and ensuring that the !CONFIG_SYSCTL build still works after the boolean change.
Pulled, thanks!
Would you mind making sure that all maintainers and authors of commits pointed to by Fixes tags are always CCed? I assume that those folks usually see the patches on mptcp@ ML before they hit netdev but I'd rather not have to assume..
Quoted 13 lines · Jakub Kicinski
Quoted 11 lines · On Thu, 27 May 2021 16:54:23 -0700 Mat Martineau wrote:
Here are some cleanup patches we've collected in the MPTCP tree.
Patches 1-4 do some general tidying.
Patch 5 adds an explicit check at netlink command parsing time to require a port number when the 'signal' flag is set, to catch the error earlier.
Patches 6 & 7 fix up the MPTCP 'enabled' sysctl, enforcing it as a boolean value, and ensuring that the !CONFIG_SYSCTL build still works after the boolean change.
Quoted 6 lines
Pulled, thanks!
Would you mind making sure that all maintainers and authors of commits pointed to by Fixes tags are always CCed? I assume that those folks usually see the patches on mptcp@ ML before they hit netdev but I'd rather not have to assume..
No problem at all, I will add get_maintainers.pl to my checklist and add Cc: tags to future patch sets.
--
Mat Martineau
Intel