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>
20 #include <net/net_ratelimit.h>
23 static int ushort_max = USHRT_MAX;
24 static int min_sndbuf = SOCK_MIN_SNDBUF;
25 static int min_rcvbuf = SOCK_MIN_RCVBUF;
28 static int rps_sock_flow_sysctl(ctl_table *table, int write,
29 void __user *buffer, size_t *lenp, loff_t *ppos)
31 unsigned int orig_size, size;
35 .maxlen = sizeof(size),
38 struct rps_sock_flow_table *orig_sock_table, *sock_table;
39 static DEFINE_MUTEX(sock_flow_mutex);
41 mutex_lock(&sock_flow_mutex);
43 orig_sock_table = rcu_dereference_protected(rps_sock_flow_table,
44 lockdep_is_held(&sock_flow_mutex));
45 size = orig_size = orig_sock_table ? orig_sock_table->mask + 1 : 0;
47 ret = proc_dointvec(&tmp, write, buffer, lenp, ppos);
52 /* Enforce limit to prevent overflow */
53 mutex_unlock(&sock_flow_mutex);
56 size = roundup_pow_of_two(size);
57 if (size != orig_size) {
59 vmalloc(RPS_SOCK_FLOW_TABLE_SIZE(size));
61 mutex_unlock(&sock_flow_mutex);
65 sock_table->mask = size - 1;
67 sock_table = orig_sock_table;
69 for (i = 0; i < size; i++)
70 sock_table->ents[i] = RPS_NO_CPU;
74 if (sock_table != orig_sock_table) {
75 rcu_assign_pointer(rps_sock_flow_table, sock_table);
77 vfree(orig_sock_table);
81 mutex_unlock(&sock_flow_mutex);
85 #endif /* CONFIG_RPS */
87 static struct ctl_table net_core_table[] = {
90 .procname = "wmem_max",
91 .data = &sysctl_wmem_max,
92 .maxlen = sizeof(int),
94 .proc_handler = proc_dointvec_minmax,
95 .extra1 = &min_sndbuf,
98 .procname = "rmem_max",
99 .data = &sysctl_rmem_max,
100 .maxlen = sizeof(int),
102 .proc_handler = proc_dointvec_minmax,
103 .extra1 = &min_rcvbuf,
106 .procname = "wmem_default",
107 .data = &sysctl_wmem_default,
108 .maxlen = sizeof(int),
110 .proc_handler = proc_dointvec_minmax,
111 .extra1 = &min_sndbuf,
114 .procname = "rmem_default",
115 .data = &sysctl_rmem_default,
116 .maxlen = sizeof(int),
118 .proc_handler = proc_dointvec_minmax,
119 .extra1 = &min_rcvbuf,
122 .procname = "dev_weight",
124 .maxlen = sizeof(int),
126 .proc_handler = proc_dointvec
129 .procname = "netdev_max_backlog",
130 .data = &netdev_max_backlog,
131 .maxlen = sizeof(int),
133 .proc_handler = proc_dointvec
135 #ifdef CONFIG_BPF_JIT
137 .procname = "bpf_jit_enable",
138 .data = &bpf_jit_enable,
139 .maxlen = sizeof(int),
141 .proc_handler = proc_dointvec
145 .procname = "netdev_tstamp_prequeue",
146 .data = &netdev_tstamp_prequeue,
147 .maxlen = sizeof(int),
149 .proc_handler = proc_dointvec
152 .procname = "message_cost",
153 .data = &net_ratelimit_state.interval,
154 .maxlen = sizeof(int),
156 .proc_handler = proc_dointvec_jiffies,
159 .procname = "message_burst",
160 .data = &net_ratelimit_state.burst,
161 .maxlen = sizeof(int),
163 .proc_handler = proc_dointvec,
166 .procname = "optmem_max",
167 .data = &sysctl_optmem_max,
168 .maxlen = sizeof(int),
170 .proc_handler = proc_dointvec
174 .procname = "rps_sock_flow_entries",
175 .maxlen = sizeof(int),
177 .proc_handler = rps_sock_flow_sysctl
180 #endif /* CONFIG_NET */
182 .procname = "netdev_budget",
183 .data = &netdev_budget,
184 .maxlen = sizeof(int),
186 .proc_handler = proc_dointvec
189 .procname = "warnings",
190 .data = &net_msg_warn,
191 .maxlen = sizeof(int),
193 .proc_handler = proc_dointvec
198 static struct ctl_table netns_core_table[] = {
200 .procname = "somaxconn",
201 .data = &init_net.core.sysctl_somaxconn,
202 .maxlen = sizeof(int),
205 .extra2 = &ushort_max,
206 .proc_handler = proc_dointvec_minmax
211 __net_initdata struct ctl_path net_core_path[] = {
212 { .procname = "net", },
213 { .procname = "core", },
217 static __net_init int sysctl_core_net_init(struct net *net)
219 struct ctl_table *tbl;
221 net->core.sysctl_somaxconn = SOMAXCONN;
223 tbl = netns_core_table;
224 if (!net_eq(net, &init_net)) {
225 tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
229 tbl[0].data = &net->core.sysctl_somaxconn;
232 net->core.sysctl_hdr = register_net_sysctl_table(net,
234 if (net->core.sysctl_hdr == NULL)
240 if (tbl != netns_core_table)
246 static __net_exit void sysctl_core_net_exit(struct net *net)
248 struct ctl_table *tbl;
250 tbl = net->core.sysctl_hdr->ctl_table_arg;
251 unregister_net_sysctl_table(net->core.sysctl_hdr);
252 BUG_ON(tbl == netns_core_table);
256 static __net_initdata struct pernet_operations sysctl_core_ops = {
257 .init = sysctl_core_net_init,
258 .exit = sysctl_core_net_exit,
261 static __init int sysctl_core_init(void)
263 static struct ctl_table empty[1];
265 register_sysctl_paths(net_core_path, empty);
266 register_net_sysctl_rotable(net_core_path, net_core_table);
267 return register_pernet_subsys(&sysctl_core_ops);
270 fs_initcall(sysctl_core_init);