2 * sysctl_net_core.c: sysctl interface to net core subsystem.
4 * Begun April 1, 1996, Mike Shaver.
5 * Added /proc/sys/net/core directory entry (empty =) ). [MS]
9 #include <linux/sysctl.h>
10 #include <linux/module.h>
11 #include <linux/socket.h>
12 #include <linux/netdevice.h>
13 #include <linux/ratelimit.h>
14 #include <linux/vmalloc.h>
15 #include <linux/init.h>
16 #include <linux/slab.h>
17 #include <linux/kmemleak.h>
21 #include <net/net_ratelimit.h>
22 #include <net/ll_poll.h>
27 static int rps_sock_flow_sysctl(struct ctl_table
*table
, int write
,
28 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
30 unsigned int orig_size
, size
;
32 struct ctl_table tmp
= {
34 .maxlen
= sizeof(size
),
37 struct rps_sock_flow_table
*orig_sock_table
, *sock_table
;
38 static DEFINE_MUTEX(sock_flow_mutex
);
40 mutex_lock(&sock_flow_mutex
);
42 orig_sock_table
= rcu_dereference_protected(rps_sock_flow_table
,
43 lockdep_is_held(&sock_flow_mutex
));
44 size
= orig_size
= orig_sock_table
? orig_sock_table
->mask
+ 1 : 0;
46 ret
= proc_dointvec(&tmp
, write
, buffer
, lenp
, ppos
);
51 /* Enforce limit to prevent overflow */
52 mutex_unlock(&sock_flow_mutex
);
55 size
= roundup_pow_of_two(size
);
56 if (size
!= orig_size
) {
58 vmalloc(RPS_SOCK_FLOW_TABLE_SIZE(size
));
60 mutex_unlock(&sock_flow_mutex
);
64 sock_table
->mask
= size
- 1;
66 sock_table
= orig_sock_table
;
68 for (i
= 0; i
< size
; i
++)
69 sock_table
->ents
[i
] = RPS_NO_CPU
;
73 if (sock_table
!= orig_sock_table
) {
74 rcu_assign_pointer(rps_sock_flow_table
, sock_table
);
76 static_key_slow_inc(&rps_needed
);
77 if (orig_sock_table
) {
78 static_key_slow_dec(&rps_needed
);
80 vfree(orig_sock_table
);
85 mutex_unlock(&sock_flow_mutex
);
89 #endif /* CONFIG_RPS */
91 #ifdef CONFIG_NET_FLOW_LIMIT
92 static DEFINE_MUTEX(flow_limit_update_mutex
);
94 static int flow_limit_cpu_sysctl(struct ctl_table
*table
, int write
,
95 void __user
*buffer
, size_t *lenp
,
98 struct sd_flow_limit
*cur
;
99 struct softnet_data
*sd
;
103 if (!alloc_cpumask_var(&mask
, GFP_KERNEL
))
107 ret
= cpumask_parse_user(buffer
, *lenp
, mask
);
111 mutex_lock(&flow_limit_update_mutex
);
112 len
= sizeof(*cur
) + netdev_flow_limit_table_len
;
113 for_each_possible_cpu(i
) {
114 sd
= &per_cpu(softnet_data
, i
);
115 cur
= rcu_dereference_protected(sd
->flow_limit
,
116 lockdep_is_held(&flow_limit_update_mutex
));
117 if (cur
&& !cpumask_test_cpu(i
, mask
)) {
118 RCU_INIT_POINTER(sd
->flow_limit
, NULL
);
121 } else if (!cur
&& cpumask_test_cpu(i
, mask
)) {
122 cur
= kzalloc(len
, GFP_KERNEL
);
124 /* not unwinding previous changes */
128 cur
->num_buckets
= netdev_flow_limit_table_len
;
129 rcu_assign_pointer(sd
->flow_limit
, cur
);
133 mutex_unlock(&flow_limit_update_mutex
);
135 if (*ppos
|| !*lenp
) {
142 for_each_possible_cpu(i
) {
143 sd
= &per_cpu(softnet_data
, i
);
144 if (rcu_dereference(sd
->flow_limit
))
145 cpumask_set_cpu(i
, mask
);
149 len
= cpumask_scnprintf(buffer
, *lenp
, mask
);
155 free_cpumask_var(mask
);
159 static int flow_limit_table_len_sysctl(struct ctl_table
*table
, int write
,
160 void __user
*buffer
, size_t *lenp
,
163 unsigned int old
, *ptr
;
166 mutex_lock(&flow_limit_update_mutex
);
170 ret
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
171 if (!ret
&& write
&& !is_power_of_2(*ptr
)) {
176 mutex_unlock(&flow_limit_update_mutex
);
179 #endif /* CONFIG_NET_FLOW_LIMIT */
181 static struct ctl_table net_core_table
[] = {
184 .procname
= "wmem_max",
185 .data
= &sysctl_wmem_max
,
186 .maxlen
= sizeof(int),
188 .proc_handler
= proc_dointvec_minmax
,
192 .procname
= "rmem_max",
193 .data
= &sysctl_rmem_max
,
194 .maxlen
= sizeof(int),
196 .proc_handler
= proc_dointvec_minmax
,
200 .procname
= "wmem_default",
201 .data
= &sysctl_wmem_default
,
202 .maxlen
= sizeof(int),
204 .proc_handler
= proc_dointvec_minmax
,
208 .procname
= "rmem_default",
209 .data
= &sysctl_rmem_default
,
210 .maxlen
= sizeof(int),
212 .proc_handler
= proc_dointvec_minmax
,
216 .procname
= "dev_weight",
218 .maxlen
= sizeof(int),
220 .proc_handler
= proc_dointvec
223 .procname
= "netdev_max_backlog",
224 .data
= &netdev_max_backlog
,
225 .maxlen
= sizeof(int),
227 .proc_handler
= proc_dointvec
229 #ifdef CONFIG_BPF_JIT
231 .procname
= "bpf_jit_enable",
232 .data
= &bpf_jit_enable
,
233 .maxlen
= sizeof(int),
235 .proc_handler
= proc_dointvec
239 .procname
= "netdev_tstamp_prequeue",
240 .data
= &netdev_tstamp_prequeue
,
241 .maxlen
= sizeof(int),
243 .proc_handler
= proc_dointvec
246 .procname
= "message_cost",
247 .data
= &net_ratelimit_state
.interval
,
248 .maxlen
= sizeof(int),
250 .proc_handler
= proc_dointvec_jiffies
,
253 .procname
= "message_burst",
254 .data
= &net_ratelimit_state
.burst
,
255 .maxlen
= sizeof(int),
257 .proc_handler
= proc_dointvec
,
260 .procname
= "optmem_max",
261 .data
= &sysctl_optmem_max
,
262 .maxlen
= sizeof(int),
264 .proc_handler
= proc_dointvec
268 .procname
= "rps_sock_flow_entries",
269 .maxlen
= sizeof(int),
271 .proc_handler
= rps_sock_flow_sysctl
274 #ifdef CONFIG_NET_FLOW_LIMIT
276 .procname
= "flow_limit_cpu_bitmap",
278 .proc_handler
= flow_limit_cpu_sysctl
281 .procname
= "flow_limit_table_len",
282 .data
= &netdev_flow_limit_table_len
,
283 .maxlen
= sizeof(int),
285 .proc_handler
= flow_limit_table_len_sysctl
287 #endif /* CONFIG_NET_FLOW_LIMIT */
288 #ifdef CONFIG_NET_LL_RX_POLL
290 .procname
= "low_latency_poll",
291 .data
= &sysctl_net_ll_poll
,
292 .maxlen
= sizeof(unsigned long),
294 .proc_handler
= proc_doulongvec_minmax
297 #endif /* CONFIG_NET */
299 .procname
= "netdev_budget",
300 .data
= &netdev_budget
,
301 .maxlen
= sizeof(int),
303 .proc_handler
= proc_dointvec
306 .procname
= "warnings",
307 .data
= &net_msg_warn
,
308 .maxlen
= sizeof(int),
310 .proc_handler
= proc_dointvec
315 static struct ctl_table netns_core_table
[] = {
317 .procname
= "somaxconn",
318 .data
= &init_net
.core
.sysctl_somaxconn
,
319 .maxlen
= sizeof(int),
321 .proc_handler
= proc_dointvec
326 static __net_init
int sysctl_core_net_init(struct net
*net
)
328 struct ctl_table
*tbl
;
330 net
->core
.sysctl_somaxconn
= SOMAXCONN
;
332 tbl
= netns_core_table
;
333 if (!net_eq(net
, &init_net
)) {
334 tbl
= kmemdup(tbl
, sizeof(netns_core_table
), GFP_KERNEL
);
338 tbl
[0].data
= &net
->core
.sysctl_somaxconn
;
340 /* Don't export any sysctls to unprivileged users */
341 if (net
->user_ns
!= &init_user_ns
) {
342 tbl
[0].procname
= NULL
;
346 net
->core
.sysctl_hdr
= register_net_sysctl(net
, "net/core", tbl
);
347 if (net
->core
.sysctl_hdr
== NULL
)
353 if (tbl
!= netns_core_table
)
359 static __net_exit
void sysctl_core_net_exit(struct net
*net
)
361 struct ctl_table
*tbl
;
363 tbl
= net
->core
.sysctl_hdr
->ctl_table_arg
;
364 unregister_net_sysctl_table(net
->core
.sysctl_hdr
);
365 BUG_ON(tbl
== netns_core_table
);
369 static __net_initdata
struct pernet_operations sysctl_core_ops
= {
370 .init
= sysctl_core_net_init
,
371 .exit
= sysctl_core_net_exit
,
374 static __init
int sysctl_core_init(void)
376 register_net_sysctl(&init_net
, "net/core", net_core_table
);
377 return register_pernet_subsys(&sysctl_core_ops
);
380 fs_initcall(sysctl_core_init
);