]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 LT |
2 | /* -*- linux-c -*- |
3 | * sysctl_net_core.c: sysctl interface to net core subsystem. | |
4 | * | |
5 | * Begun April 1, 1996, Mike Shaver. | |
6 | * Added /proc/sys/net/core directory entry (empty =) ). [MS] | |
7 | */ | |
8 | ||
9 | #include <linux/mm.h> | |
10 | #include <linux/sysctl.h> | |
1da177e4 | 11 | #include <linux/module.h> |
20380731 | 12 | #include <linux/socket.h> |
a37ae408 | 13 | #include <linux/netdevice.h> |
3fff4c42 | 14 | #include <linux/ratelimit.h> |
fec5e652 | 15 | #include <linux/vmalloc.h> |
33eb9cfc | 16 | #include <linux/init.h> |
5a0e3ad6 | 17 | #include <linux/slab.h> |
3fff4c42 | 18 | |
63d819ca | 19 | #include <net/ip.h> |
20380731 | 20 | #include <net/sock.h> |
c5c177b4 | 21 | #include <net/net_ratelimit.h> |
076bb0c8 | 22 | #include <net/busy_poll.h> |
6da7c8fc | 23 | #include <net/pkt_sched.h> |
1da177e4 | 24 | |
fa9dd599 | 25 | static int two __maybe_unused = 2; |
b1cb59cf AK |
26 | static int min_sndbuf = SOCK_MIN_SNDBUF; |
27 | static int min_rcvbuf = SOCK_MIN_RCVBUF; | |
5f74f82e | 28 | static int max_skb_frags = MAX_SKB_FRAGS; |
fdadd049 DB |
29 | static long long_one __maybe_unused = 1; |
30 | static long long_max __maybe_unused = LONG_MAX; | |
cdda8891 | 31 | |
ba7a46f1 JP |
32 | static int net_msg_warn; /* Unused, but still a sysctl */ |
33 | ||
79134e6c ED |
34 | int sysctl_fb_tunnels_only_for_init_net __read_mostly = 0; |
35 | EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net); | |
36 | ||
856c395c CW |
37 | /* 0 - Keep current behavior: |
38 | * IPv4: inherit all current settings from init_net | |
39 | * IPv6: reset all settings to default | |
40 | * 1 - Both inherit all current settings from init_net | |
41 | * 2 - Both reset all settings to default | |
42 | */ | |
43 | int sysctl_devconf_inherit_init_net __read_mostly; | |
44 | EXPORT_SYMBOL(sysctl_devconf_inherit_init_net); | |
45 | ||
fec5e652 | 46 | #ifdef CONFIG_RPS |
fe2c6338 | 47 | static int rps_sock_flow_sysctl(struct ctl_table *table, int write, |
fec5e652 TH |
48 | void __user *buffer, size_t *lenp, loff_t *ppos) |
49 | { | |
50 | unsigned int orig_size, size; | |
51 | int ret, i; | |
fe2c6338 | 52 | struct ctl_table tmp = { |
fec5e652 TH |
53 | .data = &size, |
54 | .maxlen = sizeof(size), | |
55 | .mode = table->mode | |
56 | }; | |
57 | struct rps_sock_flow_table *orig_sock_table, *sock_table; | |
58 | static DEFINE_MUTEX(sock_flow_mutex); | |
59 | ||
60 | mutex_lock(&sock_flow_mutex); | |
61 | ||
6e3f7faf ED |
62 | orig_sock_table = rcu_dereference_protected(rps_sock_flow_table, |
63 | lockdep_is_held(&sock_flow_mutex)); | |
fec5e652 TH |
64 | size = orig_size = orig_sock_table ? orig_sock_table->mask + 1 : 0; |
65 | ||
66 | ret = proc_dointvec(&tmp, write, buffer, lenp, ppos); | |
67 | ||
68 | if (write) { | |
69 | if (size) { | |
93c1af6c | 70 | if (size > 1<<29) { |
fec5e652 TH |
71 | /* Enforce limit to prevent overflow */ |
72 | mutex_unlock(&sock_flow_mutex); | |
73 | return -EINVAL; | |
74 | } | |
75 | size = roundup_pow_of_two(size); | |
76 | if (size != orig_size) { | |
77 | sock_table = | |
78 | vmalloc(RPS_SOCK_FLOW_TABLE_SIZE(size)); | |
79 | if (!sock_table) { | |
80 | mutex_unlock(&sock_flow_mutex); | |
81 | return -ENOMEM; | |
82 | } | |
567e4b79 | 83 | rps_cpu_mask = roundup_pow_of_two(nr_cpu_ids) - 1; |
fec5e652 TH |
84 | sock_table->mask = size - 1; |
85 | } else | |
86 | sock_table = orig_sock_table; | |
87 | ||
88 | for (i = 0; i < size; i++) | |
89 | sock_table->ents[i] = RPS_NO_CPU; | |
90 | } else | |
91 | sock_table = NULL; | |
92 | ||
93 | if (sock_table != orig_sock_table) { | |
94 | rcu_assign_pointer(rps_sock_flow_table, sock_table); | |
13bfff25 | 95 | if (sock_table) { |
dc05360f ED |
96 | static_branch_inc(&rps_needed); |
97 | static_branch_inc(&rfs_needed); | |
13bfff25 | 98 | } |
adc9300e | 99 | if (orig_sock_table) { |
dc05360f ED |
100 | static_branch_dec(&rps_needed); |
101 | static_branch_dec(&rfs_needed); | |
adc9300e ED |
102 | synchronize_rcu(); |
103 | vfree(orig_sock_table); | |
104 | } | |
fec5e652 TH |
105 | } |
106 | } | |
107 | ||
108 | mutex_unlock(&sock_flow_mutex); | |
109 | ||
110 | return ret; | |
111 | } | |
112 | #endif /* CONFIG_RPS */ | |
113 | ||
99bbc707 WB |
114 | #ifdef CONFIG_NET_FLOW_LIMIT |
115 | static DEFINE_MUTEX(flow_limit_update_mutex); | |
116 | ||
fe2c6338 | 117 | static int flow_limit_cpu_sysctl(struct ctl_table *table, int write, |
99bbc707 WB |
118 | void __user *buffer, size_t *lenp, |
119 | loff_t *ppos) | |
120 | { | |
121 | struct sd_flow_limit *cur; | |
122 | struct softnet_data *sd; | |
123 | cpumask_var_t mask; | |
124 | int i, len, ret = 0; | |
125 | ||
126 | if (!alloc_cpumask_var(&mask, GFP_KERNEL)) | |
127 | return -ENOMEM; | |
128 | ||
129 | if (write) { | |
130 | ret = cpumask_parse_user(buffer, *lenp, mask); | |
131 | if (ret) | |
132 | goto done; | |
133 | ||
134 | mutex_lock(&flow_limit_update_mutex); | |
135 | len = sizeof(*cur) + netdev_flow_limit_table_len; | |
136 | for_each_possible_cpu(i) { | |
137 | sd = &per_cpu(softnet_data, i); | |
138 | cur = rcu_dereference_protected(sd->flow_limit, | |
139 | lockdep_is_held(&flow_limit_update_mutex)); | |
140 | if (cur && !cpumask_test_cpu(i, mask)) { | |
141 | RCU_INIT_POINTER(sd->flow_limit, NULL); | |
142 | synchronize_rcu(); | |
143 | kfree(cur); | |
144 | } else if (!cur && cpumask_test_cpu(i, mask)) { | |
5b59d467 ED |
145 | cur = kzalloc_node(len, GFP_KERNEL, |
146 | cpu_to_node(i)); | |
99bbc707 WB |
147 | if (!cur) { |
148 | /* not unwinding previous changes */ | |
149 | ret = -ENOMEM; | |
150 | goto write_unlock; | |
151 | } | |
152 | cur->num_buckets = netdev_flow_limit_table_len; | |
153 | rcu_assign_pointer(sd->flow_limit, cur); | |
154 | } | |
155 | } | |
156 | write_unlock: | |
157 | mutex_unlock(&flow_limit_update_mutex); | |
158 | } else { | |
5f121b9a WB |
159 | char kbuf[128]; |
160 | ||
99bbc707 WB |
161 | if (*ppos || !*lenp) { |
162 | *lenp = 0; | |
163 | goto done; | |
164 | } | |
165 | ||
166 | cpumask_clear(mask); | |
167 | rcu_read_lock(); | |
168 | for_each_possible_cpu(i) { | |
169 | sd = &per_cpu(softnet_data, i); | |
170 | if (rcu_dereference(sd->flow_limit)) | |
171 | cpumask_set_cpu(i, mask); | |
172 | } | |
173 | rcu_read_unlock(); | |
174 | ||
5f121b9a | 175 | len = min(sizeof(kbuf) - 1, *lenp); |
f0906827 | 176 | len = scnprintf(kbuf, len, "%*pb", cpumask_pr_args(mask)); |
5f121b9a WB |
177 | if (!len) { |
178 | *lenp = 0; | |
179 | goto done; | |
180 | } | |
181 | if (len < *lenp) | |
182 | kbuf[len++] = '\n'; | |
183 | if (copy_to_user(buffer, kbuf, len)) { | |
184 | ret = -EFAULT; | |
185 | goto done; | |
186 | } | |
187 | *lenp = len; | |
188 | *ppos += len; | |
99bbc707 WB |
189 | } |
190 | ||
191 | done: | |
192 | free_cpumask_var(mask); | |
193 | return ret; | |
194 | } | |
195 | ||
fe2c6338 | 196 | static int flow_limit_table_len_sysctl(struct ctl_table *table, int write, |
99bbc707 WB |
197 | void __user *buffer, size_t *lenp, |
198 | loff_t *ppos) | |
199 | { | |
200 | unsigned int old, *ptr; | |
201 | int ret; | |
202 | ||
203 | mutex_lock(&flow_limit_update_mutex); | |
204 | ||
205 | ptr = table->data; | |
206 | old = *ptr; | |
207 | ret = proc_dointvec(table, write, buffer, lenp, ppos); | |
208 | if (!ret && write && !is_power_of_2(*ptr)) { | |
209 | *ptr = old; | |
210 | ret = -EINVAL; | |
211 | } | |
212 | ||
213 | mutex_unlock(&flow_limit_update_mutex); | |
214 | return ret; | |
215 | } | |
216 | #endif /* CONFIG_NET_FLOW_LIMIT */ | |
217 | ||
6da7c8fc | 218 | #ifdef CONFIG_NET_SCHED |
219 | static int set_default_qdisc(struct ctl_table *table, int write, | |
220 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
221 | { | |
222 | char id[IFNAMSIZ]; | |
223 | struct ctl_table tbl = { | |
224 | .data = id, | |
225 | .maxlen = IFNAMSIZ, | |
226 | }; | |
227 | int ret; | |
228 | ||
229 | qdisc_get_default(id, IFNAMSIZ); | |
230 | ||
231 | ret = proc_dostring(&tbl, write, buffer, lenp, ppos); | |
232 | if (write && ret == 0) | |
233 | ret = qdisc_set_default(id); | |
234 | return ret; | |
235 | } | |
236 | #endif | |
237 | ||
3d48b53f MT |
238 | static int proc_do_dev_weight(struct ctl_table *table, int write, |
239 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
240 | { | |
241 | int ret; | |
242 | ||
243 | ret = proc_dointvec(table, write, buffer, lenp, ppos); | |
244 | if (ret != 0) | |
245 | return ret; | |
246 | ||
247 | dev_rx_weight = weight_p * dev_weight_rx_bias; | |
248 | dev_tx_weight = weight_p * dev_weight_tx_bias; | |
249 | ||
250 | return ret; | |
251 | } | |
252 | ||
960fb622 ED |
253 | static int proc_do_rss_key(struct ctl_table *table, int write, |
254 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
255 | { | |
256 | struct ctl_table fake_table; | |
257 | char buf[NETDEV_RSS_KEY_LEN * 3]; | |
258 | ||
259 | snprintf(buf, sizeof(buf), "%*phC", NETDEV_RSS_KEY_LEN, netdev_rss_key); | |
260 | fake_table.data = buf; | |
261 | fake_table.maxlen = sizeof(buf); | |
262 | return proc_dostring(&fake_table, write, buffer, lenp, ppos); | |
263 | } | |
264 | ||
2e4a3098 DB |
265 | #ifdef CONFIG_BPF_JIT |
266 | static int proc_dointvec_minmax_bpf_enable(struct ctl_table *table, int write, | |
267 | void __user *buffer, size_t *lenp, | |
268 | loff_t *ppos) | |
269 | { | |
270 | int ret, jit_enable = *(int *)table->data; | |
271 | struct ctl_table tmp = *table; | |
272 | ||
273 | if (write && !capable(CAP_SYS_ADMIN)) | |
274 | return -EPERM; | |
275 | ||
276 | tmp.data = &jit_enable; | |
277 | ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); | |
278 | if (write && !ret) { | |
279 | if (jit_enable < 2 || | |
393c79c6 | 280 | (jit_enable == 2 && bpf_dump_raw_ok(current_cred()))) { |
2e4a3098 DB |
281 | *(int *)table->data = jit_enable; |
282 | if (jit_enable == 2) | |
283 | pr_warn("bpf_jit_enable = 2 was set! NEVER use this in production, only for JIT debugging!\n"); | |
284 | } else { | |
285 | ret = -EPERM; | |
286 | } | |
287 | } | |
288 | return ret; | |
289 | } | |
290 | ||
48c35560 | 291 | # ifdef CONFIG_HAVE_EBPF_JIT |
2e4a3098 DB |
292 | static int |
293 | proc_dointvec_minmax_bpf_restricted(struct ctl_table *table, int write, | |
294 | void __user *buffer, size_t *lenp, | |
295 | loff_t *ppos) | |
296 | { | |
297 | if (!capable(CAP_SYS_ADMIN)) | |
298 | return -EPERM; | |
299 | ||
300 | return proc_dointvec_minmax(table, write, buffer, lenp, ppos); | |
301 | } | |
48c35560 | 302 | # endif /* CONFIG_HAVE_EBPF_JIT */ |
fdadd049 DB |
303 | |
304 | static int | |
305 | proc_dolongvec_minmax_bpf_restricted(struct ctl_table *table, int write, | |
306 | void __user *buffer, size_t *lenp, | |
307 | loff_t *ppos) | |
308 | { | |
309 | if (!capable(CAP_SYS_ADMIN)) | |
310 | return -EPERM; | |
311 | ||
312 | return proc_doulongvec_minmax(table, write, buffer, lenp, ppos); | |
313 | } | |
2e4a3098 DB |
314 | #endif |
315 | ||
33eb9cfc | 316 | static struct ctl_table net_core_table[] = { |
1da177e4 LT |
317 | #ifdef CONFIG_NET |
318 | { | |
1da177e4 LT |
319 | .procname = "wmem_max", |
320 | .data = &sysctl_wmem_max, | |
321 | .maxlen = sizeof(int), | |
322 | .mode = 0644, | |
cdda8891 | 323 | .proc_handler = proc_dointvec_minmax, |
b1cb59cf | 324 | .extra1 = &min_sndbuf, |
1da177e4 LT |
325 | }, |
326 | { | |
1da177e4 LT |
327 | .procname = "rmem_max", |
328 | .data = &sysctl_rmem_max, | |
329 | .maxlen = sizeof(int), | |
330 | .mode = 0644, | |
cdda8891 | 331 | .proc_handler = proc_dointvec_minmax, |
b1cb59cf | 332 | .extra1 = &min_rcvbuf, |
1da177e4 LT |
333 | }, |
334 | { | |
1da177e4 LT |
335 | .procname = "wmem_default", |
336 | .data = &sysctl_wmem_default, | |
337 | .maxlen = sizeof(int), | |
338 | .mode = 0644, | |
cdda8891 | 339 | .proc_handler = proc_dointvec_minmax, |
b1cb59cf | 340 | .extra1 = &min_sndbuf, |
1da177e4 LT |
341 | }, |
342 | { | |
1da177e4 LT |
343 | .procname = "rmem_default", |
344 | .data = &sysctl_rmem_default, | |
345 | .maxlen = sizeof(int), | |
346 | .mode = 0644, | |
cdda8891 | 347 | .proc_handler = proc_dointvec_minmax, |
b1cb59cf | 348 | .extra1 = &min_rcvbuf, |
1da177e4 LT |
349 | }, |
350 | { | |
1da177e4 LT |
351 | .procname = "dev_weight", |
352 | .data = &weight_p, | |
353 | .maxlen = sizeof(int), | |
354 | .mode = 0644, | |
3d48b53f MT |
355 | .proc_handler = proc_do_dev_weight, |
356 | }, | |
357 | { | |
358 | .procname = "dev_weight_rx_bias", | |
359 | .data = &dev_weight_rx_bias, | |
360 | .maxlen = sizeof(int), | |
361 | .mode = 0644, | |
362 | .proc_handler = proc_do_dev_weight, | |
363 | }, | |
364 | { | |
365 | .procname = "dev_weight_tx_bias", | |
366 | .data = &dev_weight_tx_bias, | |
367 | .maxlen = sizeof(int), | |
368 | .mode = 0644, | |
369 | .proc_handler = proc_do_dev_weight, | |
1da177e4 LT |
370 | }, |
371 | { | |
1da177e4 LT |
372 | .procname = "netdev_max_backlog", |
373 | .data = &netdev_max_backlog, | |
374 | .maxlen = sizeof(int), | |
375 | .mode = 0644, | |
6d9f239a | 376 | .proc_handler = proc_dointvec |
1da177e4 | 377 | }, |
960fb622 ED |
378 | { |
379 | .procname = "netdev_rss_key", | |
380 | .data = &netdev_rss_key, | |
381 | .maxlen = sizeof(int), | |
382 | .mode = 0444, | |
383 | .proc_handler = proc_do_rss_key, | |
384 | }, | |
0a14842f ED |
385 | #ifdef CONFIG_BPF_JIT |
386 | { | |
387 | .procname = "bpf_jit_enable", | |
388 | .data = &bpf_jit_enable, | |
389 | .maxlen = sizeof(int), | |
390 | .mode = 0644, | |
2e4a3098 | 391 | .proc_handler = proc_dointvec_minmax_bpf_enable, |
fa9dd599 | 392 | # ifdef CONFIG_BPF_JIT_ALWAYS_ON |
eec4844f MC |
393 | .extra1 = SYSCTL_ONE, |
394 | .extra2 = SYSCTL_ONE, | |
fa9dd599 | 395 | # else |
eec4844f | 396 | .extra1 = SYSCTL_ZERO, |
fa9dd599 DB |
397 | .extra2 = &two, |
398 | # endif | |
0a14842f | 399 | }, |
4f3446bb DB |
400 | # ifdef CONFIG_HAVE_EBPF_JIT |
401 | { | |
402 | .procname = "bpf_jit_harden", | |
403 | .data = &bpf_jit_harden, | |
404 | .maxlen = sizeof(int), | |
405 | .mode = 0600, | |
2e4a3098 | 406 | .proc_handler = proc_dointvec_minmax_bpf_restricted, |
eec4844f | 407 | .extra1 = SYSCTL_ZERO, |
fa9dd599 | 408 | .extra2 = &two, |
4f3446bb | 409 | }, |
74451e66 DB |
410 | { |
411 | .procname = "bpf_jit_kallsyms", | |
412 | .data = &bpf_jit_kallsyms, | |
413 | .maxlen = sizeof(int), | |
414 | .mode = 0600, | |
2e4a3098 | 415 | .proc_handler = proc_dointvec_minmax_bpf_restricted, |
eec4844f MC |
416 | .extra1 = SYSCTL_ZERO, |
417 | .extra2 = SYSCTL_ONE, | |
74451e66 | 418 | }, |
4f3446bb | 419 | # endif |
ede95a63 DB |
420 | { |
421 | .procname = "bpf_jit_limit", | |
422 | .data = &bpf_jit_limit, | |
fdadd049 | 423 | .maxlen = sizeof(long), |
ede95a63 | 424 | .mode = 0600, |
fdadd049 DB |
425 | .proc_handler = proc_dolongvec_minmax_bpf_restricted, |
426 | .extra1 = &long_one, | |
22bca93f | 427 | .extra2 = &bpf_jit_limit_max, |
ede95a63 | 428 | }, |
0a14842f | 429 | #endif |
3b098e2d ED |
430 | { |
431 | .procname = "netdev_tstamp_prequeue", | |
432 | .data = &netdev_tstamp_prequeue, | |
433 | .maxlen = sizeof(int), | |
434 | .mode = 0644, | |
435 | .proc_handler = proc_dointvec | |
436 | }, | |
1da177e4 | 437 | { |
1da177e4 | 438 | .procname = "message_cost", |
717115e1 | 439 | .data = &net_ratelimit_state.interval, |
1da177e4 LT |
440 | .maxlen = sizeof(int), |
441 | .mode = 0644, | |
6d9f239a | 442 | .proc_handler = proc_dointvec_jiffies, |
1da177e4 LT |
443 | }, |
444 | { | |
1da177e4 | 445 | .procname = "message_burst", |
717115e1 | 446 | .data = &net_ratelimit_state.burst, |
1da177e4 LT |
447 | .maxlen = sizeof(int), |
448 | .mode = 0644, | |
6d9f239a | 449 | .proc_handler = proc_dointvec, |
1da177e4 LT |
450 | }, |
451 | { | |
1da177e4 LT |
452 | .procname = "optmem_max", |
453 | .data = &sysctl_optmem_max, | |
454 | .maxlen = sizeof(int), | |
455 | .mode = 0644, | |
6d9f239a | 456 | .proc_handler = proc_dointvec |
1da177e4 | 457 | }, |
b245be1f WB |
458 | { |
459 | .procname = "tstamp_allow_data", | |
460 | .data = &sysctl_tstamp_allow_data, | |
461 | .maxlen = sizeof(int), | |
462 | .mode = 0644, | |
463 | .proc_handler = proc_dointvec_minmax, | |
eec4844f MC |
464 | .extra1 = SYSCTL_ZERO, |
465 | .extra2 = SYSCTL_ONE | |
b245be1f | 466 | }, |
fec5e652 TH |
467 | #ifdef CONFIG_RPS |
468 | { | |
469 | .procname = "rps_sock_flow_entries", | |
470 | .maxlen = sizeof(int), | |
471 | .mode = 0644, | |
472 | .proc_handler = rps_sock_flow_sysctl | |
473 | }, | |
474 | #endif | |
99bbc707 WB |
475 | #ifdef CONFIG_NET_FLOW_LIMIT |
476 | { | |
477 | .procname = "flow_limit_cpu_bitmap", | |
478 | .mode = 0644, | |
479 | .proc_handler = flow_limit_cpu_sysctl | |
480 | }, | |
481 | { | |
482 | .procname = "flow_limit_table_len", | |
483 | .data = &netdev_flow_limit_table_len, | |
484 | .maxlen = sizeof(int), | |
485 | .mode = 0644, | |
486 | .proc_handler = flow_limit_table_len_sysctl | |
487 | }, | |
488 | #endif /* CONFIG_NET_FLOW_LIMIT */ | |
e0d1095a | 489 | #ifdef CONFIG_NET_RX_BUSY_POLL |
06021292 | 490 | { |
64b0dc51 ET |
491 | .procname = "busy_poll", |
492 | .data = &sysctl_net_busy_poll, | |
eb6db622 | 493 | .maxlen = sizeof(unsigned int), |
06021292 | 494 | .mode = 0644, |
95f25521 | 495 | .proc_handler = proc_dointvec_minmax, |
eec4844f | 496 | .extra1 = SYSCTL_ZERO, |
06021292 | 497 | }, |
2d48d67f | 498 | { |
64b0dc51 ET |
499 | .procname = "busy_read", |
500 | .data = &sysctl_net_busy_read, | |
2d48d67f ET |
501 | .maxlen = sizeof(unsigned int), |
502 | .mode = 0644, | |
95f25521 | 503 | .proc_handler = proc_dointvec_minmax, |
eec4844f | 504 | .extra1 = SYSCTL_ZERO, |
2d48d67f | 505 | }, |
6da7c8fc | 506 | #endif |
507 | #ifdef CONFIG_NET_SCHED | |
508 | { | |
509 | .procname = "default_qdisc", | |
510 | .mode = 0644, | |
511 | .maxlen = IFNAMSIZ, | |
512 | .proc_handler = set_default_qdisc | |
513 | }, | |
06021292 | 514 | #endif |
1da177e4 | 515 | #endif /* CONFIG_NET */ |
51b0bded | 516 | { |
51b0bded SH |
517 | .procname = "netdev_budget", |
518 | .data = &netdev_budget, | |
519 | .maxlen = sizeof(int), | |
520 | .mode = 0644, | |
6d9f239a | 521 | .proc_handler = proc_dointvec |
51b0bded | 522 | }, |
a2a316fd | 523 | { |
a2a316fd SH |
524 | .procname = "warnings", |
525 | .data = &net_msg_warn, | |
526 | .maxlen = sizeof(int), | |
527 | .mode = 0644, | |
6d9f239a | 528 | .proc_handler = proc_dointvec |
a2a316fd | 529 | }, |
5f74f82e HWR |
530 | { |
531 | .procname = "max_skb_frags", | |
532 | .data = &sysctl_max_skb_frags, | |
533 | .maxlen = sizeof(int), | |
534 | .mode = 0644, | |
535 | .proc_handler = proc_dointvec_minmax, | |
eec4844f | 536 | .extra1 = SYSCTL_ONE, |
5f74f82e HWR |
537 | .extra2 = &max_skb_frags, |
538 | }, | |
7acf8a1e MW |
539 | { |
540 | .procname = "netdev_budget_usecs", | |
541 | .data = &netdev_budget_usecs, | |
542 | .maxlen = sizeof(unsigned int), | |
543 | .mode = 0644, | |
544 | .proc_handler = proc_dointvec_minmax, | |
eec4844f | 545 | .extra1 = SYSCTL_ZERO, |
7acf8a1e | 546 | }, |
79134e6c ED |
547 | { |
548 | .procname = "fb_tunnels_only_for_init_net", | |
549 | .data = &sysctl_fb_tunnels_only_for_init_net, | |
550 | .maxlen = sizeof(int), | |
551 | .mode = 0644, | |
552 | .proc_handler = proc_dointvec_minmax, | |
eec4844f MC |
553 | .extra1 = SYSCTL_ZERO, |
554 | .extra2 = SYSCTL_ONE, | |
79134e6c | 555 | }, |
856c395c CW |
556 | { |
557 | .procname = "devconf_inherit_init_net", | |
558 | .data = &sysctl_devconf_inherit_init_net, | |
559 | .maxlen = sizeof(int), | |
560 | .mode = 0644, | |
561 | .proc_handler = proc_dointvec_minmax, | |
eec4844f | 562 | .extra1 = SYSCTL_ZERO, |
856c395c CW |
563 | .extra2 = &two, |
564 | }, | |
ce27ec60 ED |
565 | { |
566 | .procname = "high_order_alloc_disable", | |
567 | .data = &net_high_order_alloc_disable_key.key, | |
568 | .maxlen = sizeof(net_high_order_alloc_disable_key), | |
569 | .mode = 0644, | |
570 | .proc_handler = proc_do_static_key, | |
571 | }, | |
323ebb61 EC |
572 | { |
573 | .procname = "gro_normal_batch", | |
574 | .data = &gro_normal_batch, | |
575 | .maxlen = sizeof(unsigned int), | |
576 | .mode = 0644, | |
577 | .proc_handler = proc_dointvec_minmax, | |
578 | .extra1 = SYSCTL_ONE, | |
579 | }, | |
f8572d8f | 580 | { } |
1da177e4 | 581 | }; |
33eb9cfc | 582 | |
d5a4502e PE |
583 | static struct ctl_table netns_core_table[] = { |
584 | { | |
d5a4502e PE |
585 | .procname = "somaxconn", |
586 | .data = &init_net.core.sysctl_somaxconn, | |
587 | .maxlen = sizeof(int), | |
588 | .mode = 0644, | |
eec4844f | 589 | .extra1 = SYSCTL_ZERO, |
5f671d6b | 590 | .proc_handler = proc_dointvec_minmax |
d5a4502e | 591 | }, |
f8572d8f | 592 | { } |
d5a4502e PE |
593 | }; |
594 | ||
024626e3 | 595 | static __net_init int sysctl_core_net_init(struct net *net) |
33eb9cfc | 596 | { |
d5a4502e | 597 | struct ctl_table *tbl; |
024626e3 | 598 | |
d5a4502e | 599 | tbl = netns_core_table; |
09ad9bc7 | 600 | if (!net_eq(net, &init_net)) { |
d5a4502e | 601 | tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL); |
024626e3 PE |
602 | if (tbl == NULL) |
603 | goto err_dup; | |
604 | ||
d5a4502e | 605 | tbl[0].data = &net->core.sysctl_somaxconn; |
464dc801 EB |
606 | |
607 | /* Don't export any sysctls to unprivileged users */ | |
608 | if (net->user_ns != &init_user_ns) { | |
609 | tbl[0].procname = NULL; | |
610 | } | |
024626e3 PE |
611 | } |
612 | ||
ec8f23ce | 613 | net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl); |
8efa6e93 | 614 | if (net->core.sysctl_hdr == NULL) |
024626e3 | 615 | goto err_reg; |
33eb9cfc | 616 | |
024626e3 PE |
617 | return 0; |
618 | ||
619 | err_reg: | |
d5a4502e | 620 | if (tbl != netns_core_table) |
024626e3 PE |
621 | kfree(tbl); |
622 | err_dup: | |
623 | return -ENOMEM; | |
624 | } | |
625 | ||
626 | static __net_exit void sysctl_core_net_exit(struct net *net) | |
627 | { | |
628 | struct ctl_table *tbl; | |
629 | ||
8efa6e93 PE |
630 | tbl = net->core.sysctl_hdr->ctl_table_arg; |
631 | unregister_net_sysctl_table(net->core.sysctl_hdr); | |
d5a4502e | 632 | BUG_ON(tbl == netns_core_table); |
024626e3 PE |
633 | kfree(tbl); |
634 | } | |
635 | ||
636 | static __net_initdata struct pernet_operations sysctl_core_ops = { | |
637 | .init = sysctl_core_net_init, | |
638 | .exit = sysctl_core_net_exit, | |
639 | }; | |
640 | ||
641 | static __init int sysctl_core_init(void) | |
642 | { | |
43444757 | 643 | register_net_sysctl(&init_net, "net/core", net_core_table); |
024626e3 | 644 | return register_pernet_subsys(&sysctl_core_ops); |
33eb9cfc PE |
645 | } |
646 | ||
b27aeadb | 647 | fs_initcall(sysctl_core_init); |