]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* -*- linux-c -*- |
2 | * sysctl_net_core.c: sysctl interface to net core subsystem. | |
3 | * | |
4 | * Begun April 1, 1996, Mike Shaver. | |
5 | * Added /proc/sys/net/core directory entry (empty =) ). [MS] | |
6 | */ | |
7 | ||
8 | #include <linux/mm.h> | |
9 | #include <linux/sysctl.h> | |
1da177e4 | 10 | #include <linux/module.h> |
20380731 | 11 | #include <linux/socket.h> |
a37ae408 | 12 | #include <linux/netdevice.h> |
3fff4c42 | 13 | #include <linux/ratelimit.h> |
fec5e652 | 14 | #include <linux/vmalloc.h> |
33eb9cfc | 15 | #include <linux/init.h> |
5a0e3ad6 | 16 | #include <linux/slab.h> |
3fff4c42 | 17 | |
63d819ca | 18 | #include <net/ip.h> |
20380731 | 19 | #include <net/sock.h> |
1da177e4 | 20 | |
fec5e652 TH |
21 | #ifdef CONFIG_RPS |
22 | static int rps_sock_flow_sysctl(ctl_table *table, int write, | |
23 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
24 | { | |
25 | unsigned int orig_size, size; | |
26 | int ret, i; | |
27 | ctl_table tmp = { | |
28 | .data = &size, | |
29 | .maxlen = sizeof(size), | |
30 | .mode = table->mode | |
31 | }; | |
32 | struct rps_sock_flow_table *orig_sock_table, *sock_table; | |
33 | static DEFINE_MUTEX(sock_flow_mutex); | |
34 | ||
35 | mutex_lock(&sock_flow_mutex); | |
36 | ||
6e3f7faf ED |
37 | orig_sock_table = rcu_dereference_protected(rps_sock_flow_table, |
38 | lockdep_is_held(&sock_flow_mutex)); | |
fec5e652 TH |
39 | size = orig_size = orig_sock_table ? orig_sock_table->mask + 1 : 0; |
40 | ||
41 | ret = proc_dointvec(&tmp, write, buffer, lenp, ppos); | |
42 | ||
43 | if (write) { | |
44 | if (size) { | |
45 | if (size > 1<<30) { | |
46 | /* Enforce limit to prevent overflow */ | |
47 | mutex_unlock(&sock_flow_mutex); | |
48 | return -EINVAL; | |
49 | } | |
50 | size = roundup_pow_of_two(size); | |
51 | if (size != orig_size) { | |
52 | sock_table = | |
53 | vmalloc(RPS_SOCK_FLOW_TABLE_SIZE(size)); | |
54 | if (!sock_table) { | |
55 | mutex_unlock(&sock_flow_mutex); | |
56 | return -ENOMEM; | |
57 | } | |
58 | ||
59 | sock_table->mask = size - 1; | |
60 | } else | |
61 | sock_table = orig_sock_table; | |
62 | ||
63 | for (i = 0; i < size; i++) | |
64 | sock_table->ents[i] = RPS_NO_CPU; | |
65 | } else | |
66 | sock_table = NULL; | |
67 | ||
68 | if (sock_table != orig_sock_table) { | |
69 | rcu_assign_pointer(rps_sock_flow_table, sock_table); | |
70 | synchronize_rcu(); | |
71 | vfree(orig_sock_table); | |
72 | } | |
73 | } | |
74 | ||
75 | mutex_unlock(&sock_flow_mutex); | |
76 | ||
77 | return ret; | |
78 | } | |
79 | #endif /* CONFIG_RPS */ | |
80 | ||
33eb9cfc | 81 | static struct ctl_table net_core_table[] = { |
1da177e4 LT |
82 | #ifdef CONFIG_NET |
83 | { | |
1da177e4 LT |
84 | .procname = "wmem_max", |
85 | .data = &sysctl_wmem_max, | |
86 | .maxlen = sizeof(int), | |
87 | .mode = 0644, | |
6d9f239a | 88 | .proc_handler = proc_dointvec |
1da177e4 LT |
89 | }, |
90 | { | |
1da177e4 LT |
91 | .procname = "rmem_max", |
92 | .data = &sysctl_rmem_max, | |
93 | .maxlen = sizeof(int), | |
94 | .mode = 0644, | |
6d9f239a | 95 | .proc_handler = proc_dointvec |
1da177e4 LT |
96 | }, |
97 | { | |
1da177e4 LT |
98 | .procname = "wmem_default", |
99 | .data = &sysctl_wmem_default, | |
100 | .maxlen = sizeof(int), | |
101 | .mode = 0644, | |
6d9f239a | 102 | .proc_handler = proc_dointvec |
1da177e4 LT |
103 | }, |
104 | { | |
1da177e4 LT |
105 | .procname = "rmem_default", |
106 | .data = &sysctl_rmem_default, | |
107 | .maxlen = sizeof(int), | |
108 | .mode = 0644, | |
6d9f239a | 109 | .proc_handler = proc_dointvec |
1da177e4 LT |
110 | }, |
111 | { | |
1da177e4 LT |
112 | .procname = "dev_weight", |
113 | .data = &weight_p, | |
114 | .maxlen = sizeof(int), | |
115 | .mode = 0644, | |
6d9f239a | 116 | .proc_handler = proc_dointvec |
1da177e4 LT |
117 | }, |
118 | { | |
1da177e4 LT |
119 | .procname = "netdev_max_backlog", |
120 | .data = &netdev_max_backlog, | |
121 | .maxlen = sizeof(int), | |
122 | .mode = 0644, | |
6d9f239a | 123 | .proc_handler = proc_dointvec |
1da177e4 | 124 | }, |
3b098e2d ED |
125 | { |
126 | .procname = "netdev_tstamp_prequeue", | |
127 | .data = &netdev_tstamp_prequeue, | |
128 | .maxlen = sizeof(int), | |
129 | .mode = 0644, | |
130 | .proc_handler = proc_dointvec | |
131 | }, | |
1da177e4 | 132 | { |
1da177e4 | 133 | .procname = "message_cost", |
717115e1 | 134 | .data = &net_ratelimit_state.interval, |
1da177e4 LT |
135 | .maxlen = sizeof(int), |
136 | .mode = 0644, | |
6d9f239a | 137 | .proc_handler = proc_dointvec_jiffies, |
1da177e4 LT |
138 | }, |
139 | { | |
1da177e4 | 140 | .procname = "message_burst", |
717115e1 | 141 | .data = &net_ratelimit_state.burst, |
1da177e4 LT |
142 | .maxlen = sizeof(int), |
143 | .mode = 0644, | |
6d9f239a | 144 | .proc_handler = proc_dointvec, |
1da177e4 LT |
145 | }, |
146 | { | |
1da177e4 LT |
147 | .procname = "optmem_max", |
148 | .data = &sysctl_optmem_max, | |
149 | .maxlen = sizeof(int), | |
150 | .mode = 0644, | |
6d9f239a | 151 | .proc_handler = proc_dointvec |
1da177e4 | 152 | }, |
fec5e652 TH |
153 | #ifdef CONFIG_RPS |
154 | { | |
155 | .procname = "rps_sock_flow_entries", | |
156 | .maxlen = sizeof(int), | |
157 | .mode = 0644, | |
158 | .proc_handler = rps_sock_flow_sysctl | |
159 | }, | |
160 | #endif | |
1da177e4 | 161 | #endif /* CONFIG_NET */ |
51b0bded | 162 | { |
51b0bded SH |
163 | .procname = "netdev_budget", |
164 | .data = &netdev_budget, | |
165 | .maxlen = sizeof(int), | |
166 | .mode = 0644, | |
6d9f239a | 167 | .proc_handler = proc_dointvec |
51b0bded | 168 | }, |
a2a316fd | 169 | { |
a2a316fd SH |
170 | .procname = "warnings", |
171 | .data = &net_msg_warn, | |
172 | .maxlen = sizeof(int), | |
173 | .mode = 0644, | |
6d9f239a | 174 | .proc_handler = proc_dointvec |
a2a316fd | 175 | }, |
f8572d8f | 176 | { } |
1da177e4 | 177 | }; |
33eb9cfc | 178 | |
d5a4502e PE |
179 | static struct ctl_table netns_core_table[] = { |
180 | { | |
d5a4502e PE |
181 | .procname = "somaxconn", |
182 | .data = &init_net.core.sysctl_somaxconn, | |
183 | .maxlen = sizeof(int), | |
184 | .mode = 0644, | |
6d9f239a | 185 | .proc_handler = proc_dointvec |
d5a4502e | 186 | }, |
f8572d8f | 187 | { } |
d5a4502e PE |
188 | }; |
189 | ||
b27aeadb | 190 | __net_initdata struct ctl_path net_core_path[] = { |
f8572d8f EB |
191 | { .procname = "net", }, |
192 | { .procname = "core", }, | |
33eb9cfc PE |
193 | { }, |
194 | }; | |
195 | ||
024626e3 | 196 | static __net_init int sysctl_core_net_init(struct net *net) |
33eb9cfc | 197 | { |
d5a4502e | 198 | struct ctl_table *tbl; |
024626e3 | 199 | |
8efa6e93 | 200 | net->core.sysctl_somaxconn = SOMAXCONN; |
b8e1f9b5 | 201 | |
d5a4502e | 202 | tbl = netns_core_table; |
09ad9bc7 | 203 | if (!net_eq(net, &init_net)) { |
d5a4502e | 204 | tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL); |
024626e3 PE |
205 | if (tbl == NULL) |
206 | goto err_dup; | |
207 | ||
d5a4502e | 208 | tbl[0].data = &net->core.sysctl_somaxconn; |
024626e3 PE |
209 | } |
210 | ||
8efa6e93 | 211 | net->core.sysctl_hdr = register_net_sysctl_table(net, |
024626e3 | 212 | net_core_path, tbl); |
8efa6e93 | 213 | if (net->core.sysctl_hdr == NULL) |
024626e3 | 214 | goto err_reg; |
33eb9cfc | 215 | |
024626e3 PE |
216 | return 0; |
217 | ||
218 | err_reg: | |
d5a4502e | 219 | if (tbl != netns_core_table) |
024626e3 PE |
220 | kfree(tbl); |
221 | err_dup: | |
222 | return -ENOMEM; | |
223 | } | |
224 | ||
225 | static __net_exit void sysctl_core_net_exit(struct net *net) | |
226 | { | |
227 | struct ctl_table *tbl; | |
228 | ||
8efa6e93 PE |
229 | tbl = net->core.sysctl_hdr->ctl_table_arg; |
230 | unregister_net_sysctl_table(net->core.sysctl_hdr); | |
d5a4502e | 231 | BUG_ON(tbl == netns_core_table); |
024626e3 PE |
232 | kfree(tbl); |
233 | } | |
234 | ||
235 | static __net_initdata struct pernet_operations sysctl_core_ops = { | |
236 | .init = sysctl_core_net_init, | |
237 | .exit = sysctl_core_net_exit, | |
238 | }; | |
239 | ||
240 | static __init int sysctl_core_init(void) | |
241 | { | |
b27aeadb AD |
242 | static struct ctl_table empty[1]; |
243 | ||
244 | register_sysctl_paths(net_core_path, empty); | |
d5a4502e | 245 | register_net_sysctl_rotable(net_core_path, net_core_table); |
024626e3 | 246 | return register_pernet_subsys(&sysctl_core_ops); |
33eb9cfc PE |
247 | } |
248 | ||
b27aeadb | 249 | fs_initcall(sysctl_core_init); |