MAINTAINERS: Update tegra maintainer information
[linux-btrfs-devel.git] / net / core / sysctl_net_core.c
blob77a65f031488b3f222e13d1f071a2d3f44218c70
1 /* -*- linux-c -*-
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]
6 */
8 #include <linux/mm.h>
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>
18 #include <net/ip.h>
19 #include <net/sock.h>
20 #include <net/net_ratelimit.h>
22 #ifdef CONFIG_RPS
23 static int rps_sock_flow_sysctl(ctl_table *table, int write,
24 void __user *buffer, size_t *lenp, loff_t *ppos)
26 unsigned int orig_size, size;
27 int ret, i;
28 ctl_table tmp = {
29 .data = &size,
30 .maxlen = sizeof(size),
31 .mode = table->mode
33 struct rps_sock_flow_table *orig_sock_table, *sock_table;
34 static DEFINE_MUTEX(sock_flow_mutex);
36 mutex_lock(&sock_flow_mutex);
38 orig_sock_table = rcu_dereference_protected(rps_sock_flow_table,
39 lockdep_is_held(&sock_flow_mutex));
40 size = orig_size = orig_sock_table ? orig_sock_table->mask + 1 : 0;
42 ret = proc_dointvec(&tmp, write, buffer, lenp, ppos);
44 if (write) {
45 if (size) {
46 if (size > 1<<30) {
47 /* Enforce limit to prevent overflow */
48 mutex_unlock(&sock_flow_mutex);
49 return -EINVAL;
51 size = roundup_pow_of_two(size);
52 if (size != orig_size) {
53 sock_table =
54 vmalloc(RPS_SOCK_FLOW_TABLE_SIZE(size));
55 if (!sock_table) {
56 mutex_unlock(&sock_flow_mutex);
57 return -ENOMEM;
60 sock_table->mask = size - 1;
61 } else
62 sock_table = orig_sock_table;
64 for (i = 0; i < size; i++)
65 sock_table->ents[i] = RPS_NO_CPU;
66 } else
67 sock_table = NULL;
69 if (sock_table != orig_sock_table) {
70 rcu_assign_pointer(rps_sock_flow_table, sock_table);
71 synchronize_rcu();
72 vfree(orig_sock_table);
76 mutex_unlock(&sock_flow_mutex);
78 return ret;
80 #endif /* CONFIG_RPS */
82 static struct ctl_table net_core_table[] = {
83 #ifdef CONFIG_NET
85 .procname = "wmem_max",
86 .data = &sysctl_wmem_max,
87 .maxlen = sizeof(int),
88 .mode = 0644,
89 .proc_handler = proc_dointvec
92 .procname = "rmem_max",
93 .data = &sysctl_rmem_max,
94 .maxlen = sizeof(int),
95 .mode = 0644,
96 .proc_handler = proc_dointvec
99 .procname = "wmem_default",
100 .data = &sysctl_wmem_default,
101 .maxlen = sizeof(int),
102 .mode = 0644,
103 .proc_handler = proc_dointvec
106 .procname = "rmem_default",
107 .data = &sysctl_rmem_default,
108 .maxlen = sizeof(int),
109 .mode = 0644,
110 .proc_handler = proc_dointvec
113 .procname = "dev_weight",
114 .data = &weight_p,
115 .maxlen = sizeof(int),
116 .mode = 0644,
117 .proc_handler = proc_dointvec
120 .procname = "netdev_max_backlog",
121 .data = &netdev_max_backlog,
122 .maxlen = sizeof(int),
123 .mode = 0644,
124 .proc_handler = proc_dointvec
126 #ifdef CONFIG_BPF_JIT
128 .procname = "bpf_jit_enable",
129 .data = &bpf_jit_enable,
130 .maxlen = sizeof(int),
131 .mode = 0644,
132 .proc_handler = proc_dointvec
134 #endif
136 .procname = "netdev_tstamp_prequeue",
137 .data = &netdev_tstamp_prequeue,
138 .maxlen = sizeof(int),
139 .mode = 0644,
140 .proc_handler = proc_dointvec
143 .procname = "message_cost",
144 .data = &net_ratelimit_state.interval,
145 .maxlen = sizeof(int),
146 .mode = 0644,
147 .proc_handler = proc_dointvec_jiffies,
150 .procname = "message_burst",
151 .data = &net_ratelimit_state.burst,
152 .maxlen = sizeof(int),
153 .mode = 0644,
154 .proc_handler = proc_dointvec,
157 .procname = "optmem_max",
158 .data = &sysctl_optmem_max,
159 .maxlen = sizeof(int),
160 .mode = 0644,
161 .proc_handler = proc_dointvec
163 #ifdef CONFIG_RPS
165 .procname = "rps_sock_flow_entries",
166 .maxlen = sizeof(int),
167 .mode = 0644,
168 .proc_handler = rps_sock_flow_sysctl
170 #endif
171 #endif /* CONFIG_NET */
173 .procname = "netdev_budget",
174 .data = &netdev_budget,
175 .maxlen = sizeof(int),
176 .mode = 0644,
177 .proc_handler = proc_dointvec
180 .procname = "warnings",
181 .data = &net_msg_warn,
182 .maxlen = sizeof(int),
183 .mode = 0644,
184 .proc_handler = proc_dointvec
189 static struct ctl_table netns_core_table[] = {
191 .procname = "somaxconn",
192 .data = &init_net.core.sysctl_somaxconn,
193 .maxlen = sizeof(int),
194 .mode = 0644,
195 .proc_handler = proc_dointvec
200 __net_initdata struct ctl_path net_core_path[] = {
201 { .procname = "net", },
202 { .procname = "core", },
203 { },
206 static __net_init int sysctl_core_net_init(struct net *net)
208 struct ctl_table *tbl;
210 net->core.sysctl_somaxconn = SOMAXCONN;
212 tbl = netns_core_table;
213 if (!net_eq(net, &init_net)) {
214 tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
215 if (tbl == NULL)
216 goto err_dup;
218 tbl[0].data = &net->core.sysctl_somaxconn;
221 net->core.sysctl_hdr = register_net_sysctl_table(net,
222 net_core_path, tbl);
223 if (net->core.sysctl_hdr == NULL)
224 goto err_reg;
226 return 0;
228 err_reg:
229 if (tbl != netns_core_table)
230 kfree(tbl);
231 err_dup:
232 return -ENOMEM;
235 static __net_exit void sysctl_core_net_exit(struct net *net)
237 struct ctl_table *tbl;
239 tbl = net->core.sysctl_hdr->ctl_table_arg;
240 unregister_net_sysctl_table(net->core.sysctl_hdr);
241 BUG_ON(tbl == netns_core_table);
242 kfree(tbl);
245 static __net_initdata struct pernet_operations sysctl_core_ops = {
246 .init = sysctl_core_net_init,
247 .exit = sysctl_core_net_exit,
250 static __init int sysctl_core_init(void)
252 static struct ctl_table empty[1];
254 register_sysctl_paths(net_core_path, empty);
255 register_net_sysctl_rotable(net_core_path, net_core_table);
256 return register_pernet_subsys(&sysctl_core_ops);
259 fs_initcall(sysctl_core_init);