Skip to content

Commit f6bb63c

Browse files
committed
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/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents af9207a + 744ee14 commit f6bb63c

File tree

6 files changed

+53
-25
lines changed

6 files changed

+53
-25
lines changed

Documentation/networking/mptcp-sysctl.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ MPTCP Sysfs variables
77
/proc/sys/net/mptcp/* Variables
88
===============================
99

10-
enabled - INTEGER
10+
enabled - BOOLEAN
1111
Control whether MPTCP sockets can be created.
1212

13-
MPTCP sockets can be created if the value is nonzero. This is
14-
a per-namespace sysctl.
13+
MPTCP sockets can be created if the value is 1. This is a
14+
per-namespace sysctl.
1515

16-
Default: 1
16+
Default: 1 (enabled)
1717

1818
add_addr_timeout - INTEGER (seconds)
1919
Set the timeout after which an ADD_ADDR control message will be

net/mptcp/ctrl.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
* Copyright (c) 2019, Tessares SA.
55
*/
66

7+
#ifdef CONFIG_SYSCTL
78
#include <linux/sysctl.h>
9+
#endif
810

911
#include <net/net_namespace.h>
1012
#include <net/netns/generic.h>
@@ -15,9 +17,11 @@
1517

1618
static int mptcp_pernet_id;
1719
struct mptcp_pernet {
20+
#ifdef CONFIG_SYSCTL
1821
struct ctl_table_header *ctl_table_hdr;
22+
#endif
1923

20-
int mptcp_enabled;
24+
u8 mptcp_enabled;
2125
unsigned int add_addr_timeout;
2226
};
2327

@@ -36,15 +40,24 @@ unsigned int mptcp_get_add_addr_timeout(struct net *net)
3640
return mptcp_get_pernet(net)->add_addr_timeout;
3741
}
3842

43+
static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet)
44+
{
45+
pernet->mptcp_enabled = 1;
46+
pernet->add_addr_timeout = TCP_RTO_MAX;
47+
}
48+
49+
#ifdef CONFIG_SYSCTL
3950
static struct ctl_table mptcp_sysctl_table[] = {
4051
{
4152
.procname = "enabled",
42-
.maxlen = sizeof(int),
53+
.maxlen = sizeof(u8),
4354
.mode = 0644,
4455
/* users with CAP_NET_ADMIN or root (not and) can change this
4556
* value, same as other sysctl or the 'net' tree.
4657
*/
47-
.proc_handler = proc_dointvec,
58+
.proc_handler = proc_dou8vec_minmax,
59+
.extra1 = SYSCTL_ZERO,
60+
.extra2 = SYSCTL_ONE
4861
},
4962
{
5063
.procname = "add_addr_timeout",
@@ -55,12 +68,6 @@ static struct ctl_table mptcp_sysctl_table[] = {
5568
{}
5669
};
5770

58-
static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet)
59-
{
60-
pernet->mptcp_enabled = 1;
61-
pernet->add_addr_timeout = TCP_RTO_MAX;
62-
}
63-
6471
static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet)
6572
{
6673
struct ctl_table_header *hdr;
@@ -100,6 +107,17 @@ static void mptcp_pernet_del_table(struct mptcp_pernet *pernet)
100107
kfree(table);
101108
}
102109

110+
#else
111+
112+
static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet)
113+
{
114+
return 0;
115+
}
116+
117+
static void mptcp_pernet_del_table(struct mptcp_pernet *pernet) {}
118+
119+
#endif /* CONFIG_SYSCTL */
120+
103121
static int __net_init mptcp_net_init(struct net *net)
104122
{
105123
struct mptcp_pernet *pernet = mptcp_get_pernet(net);

net/mptcp/pm_netlink.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -971,8 +971,14 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,
971971
if (tb[MPTCP_PM_ADDR_ATTR_FLAGS])
972972
entry->flags = nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);
973973

974-
if (tb[MPTCP_PM_ADDR_ATTR_PORT])
974+
if (tb[MPTCP_PM_ADDR_ATTR_PORT]) {
975+
if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
976+
NL_SET_ERR_MSG_ATTR(info->extack, attr,
977+
"flags must have signal when using port");
978+
return -EINVAL;
979+
}
975980
entry->addr.port = htons(nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_PORT]));
981+
}
976982

977983
return 0;
978984
}
@@ -1913,10 +1919,13 @@ static int __net_init pm_nl_init_net(struct net *net)
19131919
struct pm_nl_pernet *pernet = net_generic(net, pm_nl_pernet_id);
19141920

19151921
INIT_LIST_HEAD_RCU(&pernet->local_addr_list);
1916-
__reset_counters(pernet);
19171922
pernet->next_id = 1;
1918-
bitmap_zero(pernet->id_bitmap, MAX_ADDR_ID + 1);
19191923
spin_lock_init(&pernet->lock);
1924+
1925+
/* No need to initialize other pernet fields, the struct is zeroed at
1926+
* allocation time.
1927+
*/
1928+
19201929
return 0;
19211930
}
19221931

net/mptcp/protocol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ static inline void mptcp_write_space(struct sock *sk)
627627

628628
void mptcp_destroy_common(struct mptcp_sock *msk);
629629

630+
#define MPTCP_TOKEN_MAX_RETRIES 4
631+
630632
void __init mptcp_token_init(void);
631633
static inline void mptcp_token_init_request(struct request_sock *req)
632634
{

net/mptcp/subflow.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static int subflow_check_req(struct request_sock *req,
162162
}
163163

164164
if (mp_opt.mp_capable && listener->request_mptcp) {
165-
int err, retries = 4;
165+
int err, retries = MPTCP_TOKEN_MAX_RETRIES;
166166

167167
subflow_req->ssn_offset = TCP_SKB_CB(skb)->seq;
168168
again:
@@ -430,15 +430,15 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)
430430
goto do_reset;
431431
}
432432

433+
if (!mptcp_finish_join(sk))
434+
goto do_reset;
435+
433436
subflow_generate_hmac(subflow->local_key, subflow->remote_key,
434437
subflow->local_nonce,
435438
subflow->remote_nonce,
436439
hmac);
437440
memcpy(subflow->hmac, hmac, MPTCPOPT_HMAC_LEN);
438441

439-
if (!mptcp_finish_join(sk))
440-
goto do_reset;
441-
442442
subflow->mp_join = 1;
443443
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_JOINSYNACKRX);
444444

net/mptcp/token.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <net/mptcp.h>
3434
#include "protocol.h"
3535

36-
#define TOKEN_MAX_RETRIES 4
3736
#define TOKEN_MAX_CHAIN_LEN 4
3837

3938
struct token_bucket {
@@ -153,12 +152,9 @@ int mptcp_token_new_connect(struct sock *sk)
153152
{
154153
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
155154
struct mptcp_sock *msk = mptcp_sk(subflow->conn);
156-
int retries = TOKEN_MAX_RETRIES;
155+
int retries = MPTCP_TOKEN_MAX_RETRIES;
157156
struct token_bucket *bucket;
158157

159-
pr_debug("ssk=%p, local_key=%llu, token=%u, idsn=%llu\n",
160-
sk, subflow->local_key, subflow->token, subflow->idsn);
161-
162158
again:
163159
mptcp_crypto_key_gen_sha(&subflow->local_key, &subflow->token,
164160
&subflow->idsn);
@@ -172,6 +168,9 @@ int mptcp_token_new_connect(struct sock *sk)
172168
goto again;
173169
}
174170

171+
pr_debug("ssk=%p, local_key=%llu, token=%u, idsn=%llu\n",
172+
sk, subflow->local_key, subflow->token, subflow->idsn);
173+
175174
WRITE_ONCE(msk->token, subflow->token);
176175
__sk_nulls_add_node_rcu((struct sock *)msk, &bucket->msk_chain);
177176
bucket->chain_len++;

0 commit comments

Comments
 (0)