Commit f6bb63cd authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'mptcp-miscellaneous-cleanup'

Mat Martineau says:

====================
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.
====================

Link: https://lore.kernel.org/r/20210527235430.183465-1-mathew.j.martineau@linux.intel.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents af9207ad 744ee140
...@@ -7,13 +7,13 @@ MPTCP Sysfs variables ...@@ -7,13 +7,13 @@ MPTCP Sysfs variables
/proc/sys/net/mptcp/* Variables /proc/sys/net/mptcp/* Variables
=============================== ===============================
enabled - INTEGER enabled - BOOLEAN
Control whether MPTCP sockets can be created. Control whether MPTCP sockets can be created.
MPTCP sockets can be created if the value is nonzero. This is MPTCP sockets can be created if the value is 1. This is a
a per-namespace sysctl. per-namespace sysctl.
Default: 1 Default: 1 (enabled)
add_addr_timeout - INTEGER (seconds) add_addr_timeout - INTEGER (seconds)
Set the timeout after which an ADD_ADDR control message will be Set the timeout after which an ADD_ADDR control message will be
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
* Copyright (c) 2019, Tessares SA. * Copyright (c) 2019, Tessares SA.
*/ */
#ifdef CONFIG_SYSCTL
#include <linux/sysctl.h> #include <linux/sysctl.h>
#endif
#include <net/net_namespace.h> #include <net/net_namespace.h>
#include <net/netns/generic.h> #include <net/netns/generic.h>
...@@ -15,9 +17,11 @@ ...@@ -15,9 +17,11 @@
static int mptcp_pernet_id; static int mptcp_pernet_id;
struct mptcp_pernet { struct mptcp_pernet {
#ifdef CONFIG_SYSCTL
struct ctl_table_header *ctl_table_hdr; struct ctl_table_header *ctl_table_hdr;
#endif
int mptcp_enabled; u8 mptcp_enabled;
unsigned int add_addr_timeout; unsigned int add_addr_timeout;
}; };
...@@ -36,15 +40,24 @@ unsigned int mptcp_get_add_addr_timeout(struct net *net) ...@@ -36,15 +40,24 @@ unsigned int mptcp_get_add_addr_timeout(struct net *net)
return mptcp_get_pernet(net)->add_addr_timeout; 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[] = { static struct ctl_table mptcp_sysctl_table[] = {
{ {
.procname = "enabled", .procname = "enabled",
.maxlen = sizeof(int), .maxlen = sizeof(u8),
.mode = 0644, .mode = 0644,
/* users with CAP_NET_ADMIN or root (not and) can change this /* users with CAP_NET_ADMIN or root (not and) can change this
* value, same as other sysctl or the 'net' tree. * 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", .procname = "add_addr_timeout",
...@@ -55,12 +68,6 @@ static struct ctl_table mptcp_sysctl_table[] = { ...@@ -55,12 +68,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) static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet)
{ {
struct ctl_table_header *hdr; struct ctl_table_header *hdr;
...@@ -100,6 +107,17 @@ static void mptcp_pernet_del_table(struct mptcp_pernet *pernet) ...@@ -100,6 +107,17 @@ static void mptcp_pernet_del_table(struct mptcp_pernet *pernet)
kfree(table); 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) static int __net_init mptcp_net_init(struct net *net)
{ {
struct mptcp_pernet *pernet = mptcp_get_pernet(net); struct mptcp_pernet *pernet = mptcp_get_pernet(net);
......
...@@ -971,8 +971,14 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info, ...@@ -971,8 +971,14 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,
if (tb[MPTCP_PM_ADDR_ATTR_FLAGS]) if (tb[MPTCP_PM_ADDR_ATTR_FLAGS])
entry->flags = nla_get_u32(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])); entry->addr.port = htons(nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_PORT]));
}
return 0; return 0;
} }
...@@ -1913,10 +1919,13 @@ static int __net_init pm_nl_init_net(struct net *net) ...@@ -1913,10 +1919,13 @@ static int __net_init pm_nl_init_net(struct net *net)
struct pm_nl_pernet *pernet = net_generic(net, pm_nl_pernet_id); struct pm_nl_pernet *pernet = net_generic(net, pm_nl_pernet_id);
INIT_LIST_HEAD_RCU(&pernet->local_addr_list); INIT_LIST_HEAD_RCU(&pernet->local_addr_list);
__reset_counters(pernet);
pernet->next_id = 1; pernet->next_id = 1;
bitmap_zero(pernet->id_bitmap, MAX_ADDR_ID + 1);
spin_lock_init(&pernet->lock); spin_lock_init(&pernet->lock);
/* No need to initialize other pernet fields, the struct is zeroed at
* allocation time.
*/
return 0; return 0;
} }
......
...@@ -627,6 +627,8 @@ static inline void mptcp_write_space(struct sock *sk) ...@@ -627,6 +627,8 @@ static inline void mptcp_write_space(struct sock *sk)
void mptcp_destroy_common(struct mptcp_sock *msk); void mptcp_destroy_common(struct mptcp_sock *msk);
#define MPTCP_TOKEN_MAX_RETRIES 4
void __init mptcp_token_init(void); void __init mptcp_token_init(void);
static inline void mptcp_token_init_request(struct request_sock *req) static inline void mptcp_token_init_request(struct request_sock *req)
{ {
......
...@@ -162,7 +162,7 @@ static int subflow_check_req(struct request_sock *req, ...@@ -162,7 +162,7 @@ static int subflow_check_req(struct request_sock *req,
} }
if (mp_opt.mp_capable && listener->request_mptcp) { 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; subflow_req->ssn_offset = TCP_SKB_CB(skb)->seq;
again: again:
...@@ -430,15 +430,15 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb) ...@@ -430,15 +430,15 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)
goto do_reset; goto do_reset;
} }
if (!mptcp_finish_join(sk))
goto do_reset;
subflow_generate_hmac(subflow->local_key, subflow->remote_key, subflow_generate_hmac(subflow->local_key, subflow->remote_key,
subflow->local_nonce, subflow->local_nonce,
subflow->remote_nonce, subflow->remote_nonce,
hmac); hmac);
memcpy(subflow->hmac, hmac, MPTCPOPT_HMAC_LEN); memcpy(subflow->hmac, hmac, MPTCPOPT_HMAC_LEN);
if (!mptcp_finish_join(sk))
goto do_reset;
subflow->mp_join = 1; subflow->mp_join = 1;
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_JOINSYNACKRX); MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_JOINSYNACKRX);
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include <net/mptcp.h> #include <net/mptcp.h>
#include "protocol.h" #include "protocol.h"
#define TOKEN_MAX_RETRIES 4
#define TOKEN_MAX_CHAIN_LEN 4 #define TOKEN_MAX_CHAIN_LEN 4
struct token_bucket { struct token_bucket {
...@@ -153,12 +152,9 @@ int mptcp_token_new_connect(struct sock *sk) ...@@ -153,12 +152,9 @@ int mptcp_token_new_connect(struct sock *sk)
{ {
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
struct mptcp_sock *msk = mptcp_sk(subflow->conn); struct mptcp_sock *msk = mptcp_sk(subflow->conn);
int retries = TOKEN_MAX_RETRIES; int retries = MPTCP_TOKEN_MAX_RETRIES;
struct token_bucket *bucket; 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: again:
mptcp_crypto_key_gen_sha(&subflow->local_key, &subflow->token, mptcp_crypto_key_gen_sha(&subflow->local_key, &subflow->token,
&subflow->idsn); &subflow->idsn);
...@@ -172,6 +168,9 @@ int mptcp_token_new_connect(struct sock *sk) ...@@ -172,6 +168,9 @@ int mptcp_token_new_connect(struct sock *sk)
goto again; 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); WRITE_ONCE(msk->token, subflow->token);
__sk_nulls_add_node_rcu((struct sock *)msk, &bucket->msk_chain); __sk_nulls_add_node_rcu((struct sock *)msk, &bucket->msk_chain);
bucket->chain_len++; bucket->chain_len++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment