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>
22 static int rps_sock_flow_sysctl(ctl_table
*table
, int write
,
23 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
25 unsigned int orig_size
, size
;
29 .maxlen
= sizeof(size
),
32 struct rps_sock_flow_table
*orig_sock_table
, *sock_table
;
33 static DEFINE_MUTEX(sock_flow_mutex
);
35 mutex_lock(&sock_flow_mutex
);
37 orig_sock_table
= rcu_dereference_protected(rps_sock_flow_table
,
38 lockdep_is_held(&sock_flow_mutex
));
39 size
= orig_size
= orig_sock_table
? orig_sock_table
->mask
+ 1 : 0;
41 ret
= proc_dointvec(&tmp
, write
, buffer
, lenp
, ppos
);
46 /* Enforce limit to prevent overflow */
47 mutex_unlock(&sock_flow_mutex
);
50 size
= roundup_pow_of_two(size
);
51 if (size
!= orig_size
) {
53 vmalloc(RPS_SOCK_FLOW_TABLE_SIZE(size
));
55 mutex_unlock(&sock_flow_mutex
);
59 sock_table
->mask
= size
- 1;
61 sock_table
= orig_sock_table
;
63 for (i
= 0; i
< size
; i
++)
64 sock_table
->ents
[i
] = RPS_NO_CPU
;
68 if (sock_table
!= orig_sock_table
) {
69 rcu_assign_pointer(rps_sock_flow_table
, sock_table
);
71 vfree(orig_sock_table
);
75 mutex_unlock(&sock_flow_mutex
);
79 #endif /* CONFIG_RPS */
81 static struct ctl_table net_core_table
[] = {
84 .procname
= "wmem_max",
85 .data
= &sysctl_wmem_max
,
86 .maxlen
= sizeof(int),
88 .proc_handler
= proc_dointvec
91 .procname
= "rmem_max",
92 .data
= &sysctl_rmem_max
,
93 .maxlen
= sizeof(int),
95 .proc_handler
= proc_dointvec
98 .procname
= "wmem_default",
99 .data
= &sysctl_wmem_default
,
100 .maxlen
= sizeof(int),
102 .proc_handler
= proc_dointvec
105 .procname
= "rmem_default",
106 .data
= &sysctl_rmem_default
,
107 .maxlen
= sizeof(int),
109 .proc_handler
= proc_dointvec
112 .procname
= "dev_weight",
114 .maxlen
= sizeof(int),
116 .proc_handler
= proc_dointvec
119 .procname
= "netdev_max_backlog",
120 .data
= &netdev_max_backlog
,
121 .maxlen
= sizeof(int),
123 .proc_handler
= proc_dointvec
125 #ifdef CONFIG_BPF_JIT
127 .procname
= "bpf_jit_enable",
128 .data
= &bpf_jit_enable
,
129 .maxlen
= sizeof(int),
131 .proc_handler
= proc_dointvec
135 .procname
= "netdev_tstamp_prequeue",
136 .data
= &netdev_tstamp_prequeue
,
137 .maxlen
= sizeof(int),
139 .proc_handler
= proc_dointvec
142 .procname
= "message_cost",
143 .data
= &net_ratelimit_state
.interval
,
144 .maxlen
= sizeof(int),
146 .proc_handler
= proc_dointvec_jiffies
,
149 .procname
= "message_burst",
150 .data
= &net_ratelimit_state
.burst
,
151 .maxlen
= sizeof(int),
153 .proc_handler
= proc_dointvec
,
156 .procname
= "optmem_max",
157 .data
= &sysctl_optmem_max
,
158 .maxlen
= sizeof(int),
160 .proc_handler
= proc_dointvec
164 .procname
= "rps_sock_flow_entries",
165 .maxlen
= sizeof(int),
167 .proc_handler
= rps_sock_flow_sysctl
170 #endif /* CONFIG_NET */
172 .procname
= "netdev_budget",
173 .data
= &netdev_budget
,
174 .maxlen
= sizeof(int),
176 .proc_handler
= proc_dointvec
179 .procname
= "warnings",
180 .data
= &net_msg_warn
,
181 .maxlen
= sizeof(int),
183 .proc_handler
= proc_dointvec
188 static struct ctl_table netns_core_table
[] = {
190 .procname
= "somaxconn",
191 .data
= &init_net
.core
.sysctl_somaxconn
,
192 .maxlen
= sizeof(int),
194 .proc_handler
= proc_dointvec
199 __net_initdata
struct ctl_path net_core_path
[] = {
200 { .procname
= "net", },
201 { .procname
= "core", },
205 static __net_init
int sysctl_core_net_init(struct net
*net
)
207 struct ctl_table
*tbl
;
209 net
->core
.sysctl_somaxconn
= SOMAXCONN
;
211 tbl
= netns_core_table
;
212 if (!net_eq(net
, &init_net
)) {
213 tbl
= kmemdup(tbl
, sizeof(netns_core_table
), GFP_KERNEL
);
217 tbl
[0].data
= &net
->core
.sysctl_somaxconn
;
220 net
->core
.sysctl_hdr
= register_net_sysctl_table(net
,
222 if (net
->core
.sysctl_hdr
== NULL
)
228 if (tbl
!= netns_core_table
)
234 static __net_exit
void sysctl_core_net_exit(struct net
*net
)
236 struct ctl_table
*tbl
;
238 tbl
= net
->core
.sysctl_hdr
->ctl_table_arg
;
239 unregister_net_sysctl_table(net
->core
.sysctl_hdr
);
240 BUG_ON(tbl
== netns_core_table
);
244 static __net_initdata
struct pernet_operations sysctl_core_ops
= {
245 .init
= sysctl_core_net_init
,
246 .exit
= sysctl_core_net_exit
,
249 static __init
int sysctl_core_init(void)
251 static struct ctl_table empty
[1];
253 register_sysctl_paths(net_core_path
, empty
);
254 register_net_sysctl_rotable(net_core_path
, net_core_table
);
255 return register_pernet_subsys(&sysctl_core_ops
);
258 fs_initcall(sysctl_core_init
);