Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0
  2/* Multipath TCP
  3 *
  4 * Copyright (c) 2019, Tessares SA.
  5 */
  6
  7#ifdef CONFIG_SYSCTL
  8#include <linux/sysctl.h>
  9#endif
 10
 11#include <net/net_namespace.h>
 12#include <net/netns/generic.h>
 13
 14#include "protocol.h"
 15
 16#define MPTCP_SYSCTL_PATH "net/mptcp"
 17
 18static int mptcp_pernet_id;
 19
 20#ifdef CONFIG_SYSCTL
 21static int mptcp_pm_type_max = __MPTCP_PM_TYPE_MAX;
 22#endif
 23
 24struct mptcp_pernet {
 25#ifdef CONFIG_SYSCTL
 26	struct ctl_table_header *ctl_table_hdr;
 27#endif
 28
 29	unsigned int add_addr_timeout;
 30	unsigned int close_timeout;
 31	unsigned int stale_loss_cnt;
 32	u8 mptcp_enabled;
 33	u8 checksum_enabled;
 34	u8 allow_join_initial_addr_port;
 35	u8 pm_type;
 36	char scheduler[MPTCP_SCHED_NAME_MAX];
 37};
 38
 39static struct mptcp_pernet *mptcp_get_pernet(const struct net *net)
 40{
 41	return net_generic(net, mptcp_pernet_id);
 42}
 43
 44int mptcp_is_enabled(const struct net *net)
 45{
 46	return mptcp_get_pernet(net)->mptcp_enabled;
 47}
 48
 49unsigned int mptcp_get_add_addr_timeout(const struct net *net)
 50{
 51	return mptcp_get_pernet(net)->add_addr_timeout;
 52}
 53
 54int mptcp_is_checksum_enabled(const struct net *net)
 55{
 56	return mptcp_get_pernet(net)->checksum_enabled;
 57}
 58
 59int mptcp_allow_join_id0(const struct net *net)
 60{
 61	return mptcp_get_pernet(net)->allow_join_initial_addr_port;
 62}
 63
 64unsigned int mptcp_stale_loss_cnt(const struct net *net)
 65{
 66	return mptcp_get_pernet(net)->stale_loss_cnt;
 67}
 68
 69unsigned int mptcp_close_timeout(const struct sock *sk)
 70{
 71	if (sock_flag(sk, SOCK_DEAD))
 72		return TCP_TIMEWAIT_LEN;
 73	return mptcp_get_pernet(sock_net(sk))->close_timeout;
 74}
 75
 76int mptcp_get_pm_type(const struct net *net)
 77{
 78	return mptcp_get_pernet(net)->pm_type;
 79}
 80
 81const char *mptcp_get_scheduler(const struct net *net)
 82{
 83	return mptcp_get_pernet(net)->scheduler;
 84}
 85
 86static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet)
 87{
 88	pernet->mptcp_enabled = 1;
 89	pernet->add_addr_timeout = TCP_RTO_MAX;
 90	pernet->close_timeout = TCP_TIMEWAIT_LEN;
 91	pernet->checksum_enabled = 0;
 92	pernet->allow_join_initial_addr_port = 1;
 93	pernet->stale_loss_cnt = 4;
 94	pernet->pm_type = MPTCP_PM_TYPE_KERNEL;
 95	strcpy(pernet->scheduler, "default");
 96}
 97
 98#ifdef CONFIG_SYSCTL
 99static struct ctl_table mptcp_sysctl_table[] = {
100	{
101		.procname = "enabled",
102		.maxlen = sizeof(u8),
103		.mode = 0644,
104		/* users with CAP_NET_ADMIN or root (not and) can change this
105		 * value, same as other sysctl or the 'net' tree.
106		 */
107		.proc_handler = proc_dou8vec_minmax,
108		.extra1       = SYSCTL_ZERO,
109		.extra2       = SYSCTL_ONE
110	},
111	{
112		.procname = "add_addr_timeout",
113		.maxlen = sizeof(unsigned int),
114		.mode = 0644,
115		.proc_handler = proc_dointvec_jiffies,
116	},
117	{
118		.procname = "checksum_enabled",
119		.maxlen = sizeof(u8),
120		.mode = 0644,
121		.proc_handler = proc_dou8vec_minmax,
122		.extra1       = SYSCTL_ZERO,
123		.extra2       = SYSCTL_ONE
124	},
125	{
126		.procname = "allow_join_initial_addr_port",
127		.maxlen = sizeof(u8),
128		.mode = 0644,
129		.proc_handler = proc_dou8vec_minmax,
130		.extra1       = SYSCTL_ZERO,
131		.extra2       = SYSCTL_ONE
132	},
133	{
134		.procname = "stale_loss_cnt",
135		.maxlen = sizeof(unsigned int),
136		.mode = 0644,
137		.proc_handler = proc_douintvec_minmax,
138	},
139	{
140		.procname = "pm_type",
141		.maxlen = sizeof(u8),
142		.mode = 0644,
143		.proc_handler = proc_dou8vec_minmax,
144		.extra1       = SYSCTL_ZERO,
145		.extra2       = &mptcp_pm_type_max
146	},
147	{
148		.procname = "scheduler",
149		.maxlen	= MPTCP_SCHED_NAME_MAX,
150		.mode = 0644,
151		.proc_handler = proc_dostring,
152	},
153	{
154		.procname = "close_timeout",
155		.maxlen = sizeof(unsigned int),
156		.mode = 0644,
157		.proc_handler = proc_dointvec_jiffies,
158	},
159	{}
160};
161
162static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet)
163{
164	struct ctl_table_header *hdr;
165	struct ctl_table *table;
166
167	table = mptcp_sysctl_table;
168	if (!net_eq(net, &init_net)) {
169		table = kmemdup(table, sizeof(mptcp_sysctl_table), GFP_KERNEL);
170		if (!table)
171			goto err_alloc;
172	}
173
174	table[0].data = &pernet->mptcp_enabled;
175	table[1].data = &pernet->add_addr_timeout;
176	table[2].data = &pernet->checksum_enabled;
177	table[3].data = &pernet->allow_join_initial_addr_port;
178	table[4].data = &pernet->stale_loss_cnt;
179	table[5].data = &pernet->pm_type;
180	table[6].data = &pernet->scheduler;
181	table[7].data = &pernet->close_timeout;
182
183	hdr = register_net_sysctl_sz(net, MPTCP_SYSCTL_PATH, table,
184				     ARRAY_SIZE(mptcp_sysctl_table));
185	if (!hdr)
186		goto err_reg;
187
188	pernet->ctl_table_hdr = hdr;
189
190	return 0;
191
192err_reg:
193	if (!net_eq(net, &init_net))
194		kfree(table);
195err_alloc:
196	return -ENOMEM;
197}
198
199static void mptcp_pernet_del_table(struct mptcp_pernet *pernet)
200{
201	struct ctl_table *table = pernet->ctl_table_hdr->ctl_table_arg;
202
203	unregister_net_sysctl_table(pernet->ctl_table_hdr);
204
205	kfree(table);
206}
207
208#else
209
210static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet)
211{
212	return 0;
213}
214
215static void mptcp_pernet_del_table(struct mptcp_pernet *pernet) {}
216
217#endif /* CONFIG_SYSCTL */
218
219static int __net_init mptcp_net_init(struct net *net)
220{
221	struct mptcp_pernet *pernet = mptcp_get_pernet(net);
222
223	mptcp_pernet_set_defaults(pernet);
224
225	return mptcp_pernet_new_table(net, pernet);
226}
227
228/* Note: the callback will only be called per extra netns */
229static void __net_exit mptcp_net_exit(struct net *net)
230{
231	struct mptcp_pernet *pernet = mptcp_get_pernet(net);
232
233	mptcp_pernet_del_table(pernet);
234}
235
236static struct pernet_operations mptcp_pernet_ops = {
237	.init = mptcp_net_init,
238	.exit = mptcp_net_exit,
239	.id = &mptcp_pernet_id,
240	.size = sizeof(struct mptcp_pernet),
241};
242
243void __init mptcp_init(void)
244{
245	mptcp_join_cookie_init();
246	mptcp_proto_init();
247
248	if (register_pernet_subsys(&mptcp_pernet_ops) < 0)
249		panic("Failed to register MPTCP pernet subsystem.\n");
250}
251
252#if IS_ENABLED(CONFIG_MPTCP_IPV6)
253int __init mptcpv6_init(void)
254{
255	int err;
256
257	err = mptcp_proto_v6_init();
258
259	return err;
260}
261#endif
v6.2
  1// SPDX-License-Identifier: GPL-2.0
  2/* Multipath TCP
  3 *
  4 * Copyright (c) 2019, Tessares SA.
  5 */
  6
  7#ifdef CONFIG_SYSCTL
  8#include <linux/sysctl.h>
  9#endif
 10
 11#include <net/net_namespace.h>
 12#include <net/netns/generic.h>
 13
 14#include "protocol.h"
 15
 16#define MPTCP_SYSCTL_PATH "net/mptcp"
 17
 18static int mptcp_pernet_id;
 19
 20#ifdef CONFIG_SYSCTL
 21static int mptcp_pm_type_max = __MPTCP_PM_TYPE_MAX;
 22#endif
 23
 24struct mptcp_pernet {
 25#ifdef CONFIG_SYSCTL
 26	struct ctl_table_header *ctl_table_hdr;
 27#endif
 28
 29	unsigned int add_addr_timeout;
 
 30	unsigned int stale_loss_cnt;
 31	u8 mptcp_enabled;
 32	u8 checksum_enabled;
 33	u8 allow_join_initial_addr_port;
 34	u8 pm_type;
 
 35};
 36
 37static struct mptcp_pernet *mptcp_get_pernet(const struct net *net)
 38{
 39	return net_generic(net, mptcp_pernet_id);
 40}
 41
 42int mptcp_is_enabled(const struct net *net)
 43{
 44	return mptcp_get_pernet(net)->mptcp_enabled;
 45}
 46
 47unsigned int mptcp_get_add_addr_timeout(const struct net *net)
 48{
 49	return mptcp_get_pernet(net)->add_addr_timeout;
 50}
 51
 52int mptcp_is_checksum_enabled(const struct net *net)
 53{
 54	return mptcp_get_pernet(net)->checksum_enabled;
 55}
 56
 57int mptcp_allow_join_id0(const struct net *net)
 58{
 59	return mptcp_get_pernet(net)->allow_join_initial_addr_port;
 60}
 61
 62unsigned int mptcp_stale_loss_cnt(const struct net *net)
 63{
 64	return mptcp_get_pernet(net)->stale_loss_cnt;
 65}
 66
 
 
 
 
 
 
 
 67int mptcp_get_pm_type(const struct net *net)
 68{
 69	return mptcp_get_pernet(net)->pm_type;
 70}
 71
 
 
 
 
 
 72static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet)
 73{
 74	pernet->mptcp_enabled = 1;
 75	pernet->add_addr_timeout = TCP_RTO_MAX;
 
 76	pernet->checksum_enabled = 0;
 77	pernet->allow_join_initial_addr_port = 1;
 78	pernet->stale_loss_cnt = 4;
 79	pernet->pm_type = MPTCP_PM_TYPE_KERNEL;
 
 80}
 81
 82#ifdef CONFIG_SYSCTL
 83static struct ctl_table mptcp_sysctl_table[] = {
 84	{
 85		.procname = "enabled",
 86		.maxlen = sizeof(u8),
 87		.mode = 0644,
 88		/* users with CAP_NET_ADMIN or root (not and) can change this
 89		 * value, same as other sysctl or the 'net' tree.
 90		 */
 91		.proc_handler = proc_dou8vec_minmax,
 92		.extra1       = SYSCTL_ZERO,
 93		.extra2       = SYSCTL_ONE
 94	},
 95	{
 96		.procname = "add_addr_timeout",
 97		.maxlen = sizeof(unsigned int),
 98		.mode = 0644,
 99		.proc_handler = proc_dointvec_jiffies,
100	},
101	{
102		.procname = "checksum_enabled",
103		.maxlen = sizeof(u8),
104		.mode = 0644,
105		.proc_handler = proc_dou8vec_minmax,
106		.extra1       = SYSCTL_ZERO,
107		.extra2       = SYSCTL_ONE
108	},
109	{
110		.procname = "allow_join_initial_addr_port",
111		.maxlen = sizeof(u8),
112		.mode = 0644,
113		.proc_handler = proc_dou8vec_minmax,
114		.extra1       = SYSCTL_ZERO,
115		.extra2       = SYSCTL_ONE
116	},
117	{
118		.procname = "stale_loss_cnt",
119		.maxlen = sizeof(unsigned int),
120		.mode = 0644,
121		.proc_handler = proc_douintvec_minmax,
122	},
123	{
124		.procname = "pm_type",
125		.maxlen = sizeof(u8),
126		.mode = 0644,
127		.proc_handler = proc_dou8vec_minmax,
128		.extra1       = SYSCTL_ZERO,
129		.extra2       = &mptcp_pm_type_max
130	},
 
 
 
 
 
 
 
 
 
 
 
 
131	{}
132};
133
134static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet)
135{
136	struct ctl_table_header *hdr;
137	struct ctl_table *table;
138
139	table = mptcp_sysctl_table;
140	if (!net_eq(net, &init_net)) {
141		table = kmemdup(table, sizeof(mptcp_sysctl_table), GFP_KERNEL);
142		if (!table)
143			goto err_alloc;
144	}
145
146	table[0].data = &pernet->mptcp_enabled;
147	table[1].data = &pernet->add_addr_timeout;
148	table[2].data = &pernet->checksum_enabled;
149	table[3].data = &pernet->allow_join_initial_addr_port;
150	table[4].data = &pernet->stale_loss_cnt;
151	table[5].data = &pernet->pm_type;
 
 
152
153	hdr = register_net_sysctl(net, MPTCP_SYSCTL_PATH, table);
 
154	if (!hdr)
155		goto err_reg;
156
157	pernet->ctl_table_hdr = hdr;
158
159	return 0;
160
161err_reg:
162	if (!net_eq(net, &init_net))
163		kfree(table);
164err_alloc:
165	return -ENOMEM;
166}
167
168static void mptcp_pernet_del_table(struct mptcp_pernet *pernet)
169{
170	struct ctl_table *table = pernet->ctl_table_hdr->ctl_table_arg;
171
172	unregister_net_sysctl_table(pernet->ctl_table_hdr);
173
174	kfree(table);
175}
176
177#else
178
179static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet)
180{
181	return 0;
182}
183
184static void mptcp_pernet_del_table(struct mptcp_pernet *pernet) {}
185
186#endif /* CONFIG_SYSCTL */
187
188static int __net_init mptcp_net_init(struct net *net)
189{
190	struct mptcp_pernet *pernet = mptcp_get_pernet(net);
191
192	mptcp_pernet_set_defaults(pernet);
193
194	return mptcp_pernet_new_table(net, pernet);
195}
196
197/* Note: the callback will only be called per extra netns */
198static void __net_exit mptcp_net_exit(struct net *net)
199{
200	struct mptcp_pernet *pernet = mptcp_get_pernet(net);
201
202	mptcp_pernet_del_table(pernet);
203}
204
205static struct pernet_operations mptcp_pernet_ops = {
206	.init = mptcp_net_init,
207	.exit = mptcp_net_exit,
208	.id = &mptcp_pernet_id,
209	.size = sizeof(struct mptcp_pernet),
210};
211
212void __init mptcp_init(void)
213{
214	mptcp_join_cookie_init();
215	mptcp_proto_init();
216
217	if (register_pernet_subsys(&mptcp_pernet_ops) < 0)
218		panic("Failed to register MPTCP pernet subsystem.\n");
219}
220
221#if IS_ENABLED(CONFIG_MPTCP_IPV6)
222int __init mptcpv6_init(void)
223{
224	int err;
225
226	err = mptcp_proto_v6_init();
227
228	return err;
229}
230#endif