blob: 9205e492dc9d8a36b05f18ccedcdf4704867c986 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
3 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Begun April 1, 1996, Mike Shaver.
5 * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
6 */
7
8#include <linux/mm.h>
9#include <linux/module.h>
10#include <linux/sysctl.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030011#include <linux/igmp.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020012#include <linux/inetdevice.h>
Stephen Hemminger227b60f2007-10-10 17:30:46 -070013#include <linux/seqlock.h>
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -080014#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000016#include <linux/nsproxy.h>
Glauber Costa3dc43e32011-12-11 21:47:05 +000017#include <linux/swap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <net/snmp.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030019#include <net/icmp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <net/ip.h>
21#include <net/route.h>
22#include <net/tcp.h>
Hideo Aoki95766ff2007-12-31 00:29:24 -080023#include <net/udp.h>
Paul Moore446fda42006-08-03 16:48:06 -070024#include <net/cipso_ipv4.h>
Pavel Emelyanov04128f22007-10-15 02:33:45 -070025#include <net/inet_frag.h>
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000026#include <net/ping.h>
Glauber Costa3aaabe22011-12-11 21:47:06 +000027#include <net/tcp_memcontrol.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Herbert Xu89cee8b2005-12-13 23:14:27 -080029static int zero;
Yuchung Chengeed530b2012-05-02 13:30:03 +000030static int two = 2;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090031static int tcp_retr1_max = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032static int ip_local_port_range_min[] = { 1, 1 };
33static int ip_local_port_range_max[] = { 65535, 65535 };
Alexey Dobriyan0147fc02010-11-22 12:54:21 +000034static int tcp_adv_win_scale_min = -31;
35static int tcp_adv_win_scale_max = 31;
Eric Dumazet249fab72010-12-13 12:16:14 -080036static int ip_ttl_min = 1;
37static int ip_ttl_max = 255;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000038static int ip_ping_group_range_min[] = { 0, 0 };
39static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Stephen Hemminger227b60f2007-10-10 17:30:46 -070041/* Update system visible IP port range */
42static void set_local_port_range(int range[2])
43{
Eric Dumazet3c689b72008-10-08 14:18:04 -070044 write_seqlock(&sysctl_local_ports.lock);
45 sysctl_local_ports.range[0] = range[0];
46 sysctl_local_ports.range[1] = range[1];
47 write_sequnlock(&sysctl_local_ports.lock);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070048}
49
50/* Validate changes from /proc interface. */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070051static int ipv4_local_port_range(ctl_table *table, int write,
Stephen Hemminger227b60f2007-10-10 17:30:46 -070052 void __user *buffer,
53 size_t *lenp, loff_t *ppos)
54{
55 int ret;
Eric Dumazet3c689b72008-10-08 14:18:04 -070056 int range[2];
Stephen Hemminger227b60f2007-10-10 17:30:46 -070057 ctl_table tmp = {
58 .data = &range,
59 .maxlen = sizeof(range),
60 .mode = table->mode,
61 .extra1 = &ip_local_port_range_min,
62 .extra2 = &ip_local_port_range_max,
63 };
64
Eric Dumazet3c689b72008-10-08 14:18:04 -070065 inet_get_local_port_range(range, range + 1);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070066 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070067
68 if (write && ret == 0) {
Anton Arapova25de532007-10-18 22:00:17 -070069 if (range[1] < range[0])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070070 ret = -EINVAL;
71 else
72 set_local_port_range(range);
73 }
74
75 return ret;
76}
77
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000078
Eric W. Biederman7064d162012-05-24 10:34:21 -060079static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000080{
Eric W. Biederman7064d162012-05-24 10:34:21 -060081 kgid_t *data = table->data;
Eric Dumazet95c96172012-04-15 05:58:06 +000082 unsigned int seq;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000083 do {
84 seq = read_seqbegin(&sysctl_local_ports.lock);
85
86 *low = data[0];
87 *high = data[1];
88 } while (read_seqretry(&sysctl_local_ports.lock, seq));
89}
90
91/* Update system visible IP port range */
Eric W. Biederman7064d162012-05-24 10:34:21 -060092static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000093{
Eric W. Biederman7064d162012-05-24 10:34:21 -060094 kgid_t *data = table->data;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000095 write_seqlock(&sysctl_local_ports.lock);
Eric W. Biederman7064d162012-05-24 10:34:21 -060096 data[0] = low;
97 data[1] = high;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +000098 write_sequnlock(&sysctl_local_ports.lock);
99}
100
101/* Validate changes from /proc interface. */
102static int ipv4_ping_group_range(ctl_table *table, int write,
103 void __user *buffer,
104 size_t *lenp, loff_t *ppos)
105{
Eric W. Biederman7064d162012-05-24 10:34:21 -0600106 struct user_namespace *user_ns = current_user_ns();
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000107 int ret;
Eric W. Biederman7064d162012-05-24 10:34:21 -0600108 gid_t urange[2];
109 kgid_t low, high;
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000110 ctl_table tmp = {
Eric W. Biederman7064d162012-05-24 10:34:21 -0600111 .data = &urange,
112 .maxlen = sizeof(urange),
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000113 .mode = table->mode,
114 .extra1 = &ip_ping_group_range_min,
115 .extra2 = &ip_ping_group_range_max,
116 };
117
Eric W. Biederman7064d162012-05-24 10:34:21 -0600118 inet_get_ping_group_range_table(table, &low, &high);
119 urange[0] = from_kgid_munged(user_ns, low);
120 urange[1] = from_kgid_munged(user_ns, high);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000121 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
122
Eric W. Biederman7064d162012-05-24 10:34:21 -0600123 if (write && ret == 0) {
124 low = make_kgid(user_ns, urange[0]);
125 high = make_kgid(user_ns, urange[1]);
126 if (!gid_valid(low) || !gid_valid(high) ||
127 (urange[1] < urange[0]) || gid_lt(high, low)) {
128 low = make_kgid(&init_user_ns, 1);
129 high = make_kgid(&init_user_ns, 0);
130 }
131 set_ping_group_range(table, low, high);
132 }
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000133
134 return ret;
135}
136
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700137static int proc_tcp_congestion_control(ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700138 void __user *buffer, size_t *lenp, loff_t *ppos)
139{
140 char val[TCP_CA_NAME_MAX];
141 ctl_table tbl = {
142 .data = val,
143 .maxlen = TCP_CA_NAME_MAX,
144 };
145 int ret;
146
147 tcp_get_default_congestion_control(val);
148
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700149 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700150 if (write && ret == 0)
151 ret = tcp_set_default_congestion_control(val);
152 return ret;
153}
154
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800155static int proc_tcp_available_congestion_control(ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700156 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800157 void __user *buffer, size_t *lenp,
158 loff_t *ppos)
159{
160 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
161 int ret;
162
163 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
164 if (!tbl.data)
165 return -ENOMEM;
166 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700167 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800168 kfree(tbl.data);
169 return ret;
170}
171
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800172static int proc_allowed_congestion_control(ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700173 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800174 void __user *buffer, size_t *lenp,
175 loff_t *ppos)
176{
177 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
178 int ret;
179
180 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
181 if (!tbl.data)
182 return -ENOMEM;
183
184 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700185 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800186 if (write && ret == 0)
187 ret = tcp_set_allowed_congestion_control(tbl.data);
188 kfree(tbl.data);
189 return ret;
190}
191
Glauber Costa3dc43e32011-12-11 21:47:05 +0000192static int ipv4_tcp_mem(ctl_table *ctl, int write,
193 void __user *buffer, size_t *lenp,
194 loff_t *ppos)
195{
196 int ret;
197 unsigned long vec[3];
198 struct net *net = current->nsproxy->net_ns;
Andrew Mortonc255a452012-07-31 16:43:02 -0700199#ifdef CONFIG_MEMCG_KMEM
Glauber Costa3aaabe22011-12-11 21:47:06 +0000200 struct mem_cgroup *memcg;
201#endif
Glauber Costa3dc43e32011-12-11 21:47:05 +0000202
203 ctl_table tmp = {
204 .data = &vec,
205 .maxlen = sizeof(vec),
206 .mode = ctl->mode,
207 };
208
209 if (!write) {
210 ctl->data = &net->ipv4.sysctl_tcp_mem;
211 return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
212 }
213
214 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
215 if (ret)
216 return ret;
217
Andrew Mortonc255a452012-07-31 16:43:02 -0700218#ifdef CONFIG_MEMCG_KMEM
Glauber Costa3aaabe22011-12-11 21:47:06 +0000219 rcu_read_lock();
220 memcg = mem_cgroup_from_task(current);
221
222 tcp_prot_mem(memcg, vec[0], 0);
223 tcp_prot_mem(memcg, vec[1], 1);
224 tcp_prot_mem(memcg, vec[2], 2);
225 rcu_read_unlock();
226#endif
227
Glauber Costa3dc43e32011-12-11 21:47:05 +0000228 net->ipv4.sysctl_tcp_mem[0] = vec[0];
229 net->ipv4.sysctl_tcp_mem[1] = vec[1];
230 net->ipv4.sysctl_tcp_mem[2] = vec[2];
231
232 return 0;
233}
234
Jerry Chu10467162012-08-31 12:29:11 +0000235int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
236 size_t *lenp, loff_t *ppos)
237{
238 ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
239 struct tcp_fastopen_context *ctxt;
240 int ret;
241 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
242
243 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
244 if (!tbl.data)
245 return -ENOMEM;
246
247 rcu_read_lock();
248 ctxt = rcu_dereference(tcp_fastopen_ctx);
249 if (ctxt)
250 memcpy(user_key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH);
251 rcu_read_unlock();
252
253 snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x",
254 user_key[0], user_key[1], user_key[2], user_key[3]);
255 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
256
257 if (write && ret == 0) {
258 if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1,
259 user_key + 2, user_key + 3) != 4) {
260 ret = -EINVAL;
261 goto bad_key;
262 }
263 tcp_fastopen_reset_cipher(user_key, TCP_FASTOPEN_KEY_LENGTH);
264 }
265
266bad_key:
267 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
268 user_key[0], user_key[1], user_key[2], user_key[3],
269 (char *)tbl.data, ret);
270 kfree(tbl.data);
271 return ret;
272}
273
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800274static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900275 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 .procname = "tcp_timestamps",
277 .data = &sysctl_tcp_timestamps,
278 .maxlen = sizeof(int),
279 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800280 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900282 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 .procname = "tcp_window_scaling",
284 .data = &sysctl_tcp_window_scaling,
285 .maxlen = sizeof(int),
286 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800287 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900289 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 .procname = "tcp_sack",
291 .data = &sysctl_tcp_sack,
292 .maxlen = sizeof(int),
293 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800294 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900296 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 .procname = "tcp_retrans_collapse",
298 .data = &sysctl_tcp_retrans_collapse,
299 .maxlen = sizeof(int),
300 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800301 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900303 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 .procname = "ip_default_ttl",
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900305 .data = &sysctl_ip_default_ttl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 .maxlen = sizeof(int),
307 .mode = 0644,
Eric Dumazet249fab72010-12-13 12:16:14 -0800308 .proc_handler = proc_dointvec_minmax,
309 .extra1 = &ip_ttl_min,
310 .extra2 = &ip_ttl_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900312 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 .procname = "ip_no_pmtu_disc",
314 .data = &ipv4_config.no_pmtu_disc,
315 .maxlen = sizeof(int),
316 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800317 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 },
319 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 .procname = "ip_nonlocal_bind",
321 .data = &sysctl_ip_nonlocal_bind,
322 .maxlen = sizeof(int),
323 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800324 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 },
326 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 .procname = "tcp_syn_retries",
328 .data = &sysctl_tcp_syn_retries,
329 .maxlen = sizeof(int),
330 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800331 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 },
333 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 .procname = "tcp_synack_retries",
335 .data = &sysctl_tcp_synack_retries,
336 .maxlen = sizeof(int),
337 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800338 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 },
340 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 .procname = "tcp_max_orphans",
342 .data = &sysctl_tcp_max_orphans,
343 .maxlen = sizeof(int),
344 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800345 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 },
347 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 .procname = "tcp_max_tw_buckets",
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -0700349 .data = &tcp_death_row.sysctl_max_tw_buckets,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 .maxlen = sizeof(int),
351 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800352 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 },
354 {
Alexander Duyck6648bd72012-06-21 13:58:31 +0000355 .procname = "ip_early_demux",
356 .data = &sysctl_ip_early_demux,
357 .maxlen = sizeof(int),
358 .mode = 0644,
359 .proc_handler = proc_dointvec
360 },
361 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 .procname = "ip_dynaddr",
363 .data = &sysctl_ip_dynaddr,
364 .maxlen = sizeof(int),
365 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800366 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 },
368 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 .procname = "tcp_keepalive_time",
370 .data = &sysctl_tcp_keepalive_time,
371 .maxlen = sizeof(int),
372 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800373 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 },
375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 .procname = "tcp_keepalive_probes",
377 .data = &sysctl_tcp_keepalive_probes,
378 .maxlen = sizeof(int),
379 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800380 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 },
382 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 .procname = "tcp_keepalive_intvl",
384 .data = &sysctl_tcp_keepalive_intvl,
385 .maxlen = sizeof(int),
386 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800387 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 },
389 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 .procname = "tcp_retries1",
391 .data = &sysctl_tcp_retries1,
392 .maxlen = sizeof(int),
393 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800394 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 .extra2 = &tcp_retr1_max
396 },
397 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 .procname = "tcp_retries2",
399 .data = &sysctl_tcp_retries2,
400 .maxlen = sizeof(int),
401 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800402 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 },
404 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 .procname = "tcp_fin_timeout",
406 .data = &sysctl_tcp_fin_timeout,
407 .maxlen = sizeof(int),
408 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800409 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 },
411#ifdef CONFIG_SYN_COOKIES
412 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 .procname = "tcp_syncookies",
414 .data = &sysctl_tcp_syncookies,
415 .maxlen = sizeof(int),
416 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800417 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 },
419#endif
420 {
Yuchung Cheng2100c8d2012-07-19 06:43:05 +0000421 .procname = "tcp_fastopen",
422 .data = &sysctl_tcp_fastopen,
423 .maxlen = sizeof(int),
424 .mode = 0644,
425 .proc_handler = proc_dointvec,
426 },
427 {
Jerry Chu10467162012-08-31 12:29:11 +0000428 .procname = "tcp_fastopen_key",
429 .mode = 0600,
430 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
431 .proc_handler = proc_tcp_fastopen_key,
432 },
433 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 .procname = "tcp_tw_recycle",
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -0700435 .data = &tcp_death_row.sysctl_tw_recycle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 .maxlen = sizeof(int),
437 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800438 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 },
440 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 .procname = "tcp_abort_on_overflow",
442 .data = &sysctl_tcp_abort_on_overflow,
443 .maxlen = sizeof(int),
444 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800445 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 },
447 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 .procname = "tcp_stdurg",
449 .data = &sysctl_tcp_stdurg,
450 .maxlen = sizeof(int),
451 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800452 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 },
454 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 .procname = "tcp_rfc1337",
456 .data = &sysctl_tcp_rfc1337,
457 .maxlen = sizeof(int),
458 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800459 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 },
461 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 .procname = "tcp_max_syn_backlog",
463 .data = &sysctl_max_syn_backlog,
464 .maxlen = sizeof(int),
465 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800466 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 },
468 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 .procname = "ip_local_port_range",
Eric Dumazet3c689b72008-10-08 14:18:04 -0700470 .data = &sysctl_local_ports.range,
471 .maxlen = sizeof(sysctl_local_ports.range),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800473 .proc_handler = ipv4_local_port_range,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 },
Amerigo Wange3826f12010-05-05 00:27:06 +0000475 {
476 .procname = "ip_local_reserved_ports",
477 .data = NULL, /* initialized in sysctl_ipv4_init */
478 .maxlen = 65536,
479 .mode = 0644,
480 .proc_handler = proc_do_large_bitmap,
481 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 .procname = "igmp_max_memberships",
484 .data = &sysctl_igmp_max_memberships,
485 .maxlen = sizeof(int),
486 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800487 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 .procname = "igmp_max_msf",
491 .data = &sysctl_igmp_max_msf,
492 .maxlen = sizeof(int),
493 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800494 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 },
496 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 .procname = "inet_peer_threshold",
498 .data = &inet_peer_threshold,
499 .maxlen = sizeof(int),
500 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800501 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 },
503 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 .procname = "inet_peer_minttl",
505 .data = &inet_peer_minttl,
506 .maxlen = sizeof(int),
507 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800508 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 },
510 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 .procname = "inet_peer_maxttl",
512 .data = &inet_peer_maxttl,
513 .maxlen = sizeof(int),
514 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800515 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 },
517 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 .procname = "tcp_orphan_retries",
519 .data = &sysctl_tcp_orphan_retries,
520 .maxlen = sizeof(int),
521 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800522 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 },
524 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 .procname = "tcp_fack",
526 .data = &sysctl_tcp_fack,
527 .maxlen = sizeof(int),
528 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800529 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 },
531 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 .procname = "tcp_reordering",
533 .data = &sysctl_tcp_reordering,
534 .maxlen = sizeof(int),
535 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800536 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 },
538 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 .procname = "tcp_ecn",
540 .data = &sysctl_tcp_ecn,
541 .maxlen = sizeof(int),
542 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800543 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 },
545 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 .procname = "tcp_dsack",
547 .data = &sysctl_tcp_dsack,
548 .maxlen = sizeof(int),
549 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800550 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 },
552 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 .procname = "tcp_wmem",
554 .data = &sysctl_tcp_wmem,
555 .maxlen = sizeof(sysctl_tcp_wmem),
556 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800557 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 },
559 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 .procname = "tcp_rmem",
561 .data = &sysctl_tcp_rmem,
562 .maxlen = sizeof(sysctl_tcp_rmem),
563 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800564 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 },
566 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 .procname = "tcp_app_win",
568 .data = &sysctl_tcp_app_win,
569 .maxlen = sizeof(int),
570 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800571 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 },
573 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 .procname = "tcp_adv_win_scale",
575 .data = &sysctl_tcp_adv_win_scale,
576 .maxlen = sizeof(int),
577 .mode = 0644,
Alexey Dobriyan0147fc02010-11-22 12:54:21 +0000578 .proc_handler = proc_dointvec_minmax,
579 .extra1 = &tcp_adv_win_scale_min,
580 .extra2 = &tcp_adv_win_scale_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 },
582 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 .procname = "tcp_tw_reuse",
584 .data = &sysctl_tcp_tw_reuse,
585 .maxlen = sizeof(int),
586 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800587 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 },
589 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 .procname = "tcp_frto",
591 .data = &sysctl_tcp_frto,
592 .maxlen = sizeof(int),
593 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800594 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 },
596 {
Ilpo Järvinen3cfe3ba2007-02-27 10:09:49 -0800597 .procname = "tcp_frto_response",
598 .data = &sysctl_tcp_frto_response,
599 .maxlen = sizeof(int),
600 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800601 .proc_handler = proc_dointvec
Ilpo Järvinen3cfe3ba2007-02-27 10:09:49 -0800602 },
603 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 .procname = "tcp_low_latency",
605 .data = &sysctl_tcp_low_latency,
606 .maxlen = sizeof(int),
607 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800608 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 },
610 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 .procname = "tcp_no_metrics_save",
612 .data = &sysctl_tcp_nometrics_save,
613 .maxlen = sizeof(int),
614 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800615 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 },
617 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 .procname = "tcp_moderate_rcvbuf",
619 .data = &sysctl_tcp_moderate_rcvbuf,
620 .maxlen = sizeof(int),
621 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800622 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 },
624 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 .procname = "tcp_tso_win_divisor",
626 .data = &sysctl_tcp_tso_win_divisor,
627 .maxlen = sizeof(int),
628 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800629 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 },
631 {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700632 .procname = "tcp_congestion_control",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 .mode = 0644,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700634 .maxlen = TCP_CA_NAME_MAX,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800635 .proc_handler = proc_tcp_congestion_control,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 },
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800637 {
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800638 .procname = "tcp_abc",
639 .data = &sysctl_tcp_abc,
640 .maxlen = sizeof(int),
641 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800642 .proc_handler = proc_dointvec,
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800643 },
John Heffner5d424d52006-03-20 17:53:41 -0800644 {
John Heffner5d424d52006-03-20 17:53:41 -0800645 .procname = "tcp_mtu_probing",
646 .data = &sysctl_tcp_mtu_probing,
647 .maxlen = sizeof(int),
648 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800649 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800650 },
651 {
John Heffner5d424d52006-03-20 17:53:41 -0800652 .procname = "tcp_base_mss",
653 .data = &sysctl_tcp_base_mss,
654 .maxlen = sizeof(int),
655 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800656 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800657 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900658 {
Rick Jones15d99e02006-03-20 22:40:29 -0800659 .procname = "tcp_workaround_signed_windows",
660 .data = &sysctl_tcp_workaround_signed_windows,
661 .maxlen = sizeof(int),
662 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800663 .proc_handler = proc_dointvec
Rick Jones15d99e02006-03-20 22:40:29 -0800664 },
Eric Dumazet46d3cea2012-07-11 05:50:31 +0000665 {
666 .procname = "tcp_limit_output_bytes",
667 .data = &sysctl_tcp_limit_output_bytes,
668 .maxlen = sizeof(int),
669 .mode = 0644,
670 .proc_handler = proc_dointvec
671 },
Eric Dumazet282f23c2012-07-17 10:13:05 +0200672 {
673 .procname = "tcp_challenge_ack_limit",
674 .data = &sysctl_tcp_challenge_ack_limit,
675 .maxlen = sizeof(int),
676 .mode = 0644,
677 .proc_handler = proc_dointvec
678 },
Chris Leech95937822006-05-23 18:02:55 -0700679#ifdef CONFIG_NET_DMA
680 {
Chris Leech95937822006-05-23 18:02:55 -0700681 .procname = "tcp_dma_copybreak",
682 .data = &sysctl_tcp_dma_copybreak,
683 .maxlen = sizeof(int),
684 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800685 .proc_handler = proc_dointvec
Chris Leech95937822006-05-23 18:02:55 -0700686 },
687#endif
David S. Miller35089bb2006-06-13 22:33:04 -0700688 {
David S. Miller35089bb2006-06-13 22:33:04 -0700689 .procname = "tcp_slow_start_after_idle",
690 .data = &sysctl_tcp_slow_start_after_idle,
691 .maxlen = sizeof(int),
692 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800693 .proc_handler = proc_dointvec
David S. Miller35089bb2006-06-13 22:33:04 -0700694 },
Paul Moore446fda42006-08-03 16:48:06 -0700695#ifdef CONFIG_NETLABEL
696 {
Paul Moore446fda42006-08-03 16:48:06 -0700697 .procname = "cipso_cache_enable",
698 .data = &cipso_v4_cache_enabled,
699 .maxlen = sizeof(int),
700 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800701 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700702 },
703 {
Paul Moore446fda42006-08-03 16:48:06 -0700704 .procname = "cipso_cache_bucket_size",
705 .data = &cipso_v4_cache_bucketsize,
706 .maxlen = sizeof(int),
707 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800708 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700709 },
710 {
Paul Moore446fda42006-08-03 16:48:06 -0700711 .procname = "cipso_rbm_optfmt",
712 .data = &cipso_v4_rbm_optfmt,
713 .maxlen = sizeof(int),
714 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800715 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700716 },
717 {
Paul Moore446fda42006-08-03 16:48:06 -0700718 .procname = "cipso_rbm_strictvalid",
719 .data = &cipso_v4_rbm_strictvalid,
720 .maxlen = sizeof(int),
721 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800722 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700723 },
724#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800725 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800726 .procname = "tcp_available_congestion_control",
727 .maxlen = TCP_CA_BUF_MAX,
728 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800729 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800730 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800731 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800732 .procname = "tcp_allowed_congestion_control",
733 .maxlen = TCP_CA_BUF_MAX,
734 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800735 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800736 },
John Heffner886236c2007-03-25 19:21:45 -0700737 {
John Heffner886236c2007-03-25 19:21:45 -0700738 .procname = "tcp_max_ssthresh",
739 .data = &sysctl_tcp_max_ssthresh,
740 .maxlen = sizeof(int),
741 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800742 .proc_handler = proc_dointvec,
John Heffner886236c2007-03-25 19:21:45 -0700743 },
Hideo Aoki95766ff2007-12-31 00:29:24 -0800744 {
William Allen Simpson519855c2009-12-02 18:14:19 +0000745 .procname = "tcp_cookie_size",
746 .data = &sysctl_tcp_cookie_size,
747 .maxlen = sizeof(int),
748 .mode = 0644,
749 .proc_handler = proc_dointvec
750 },
751 {
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000752 .procname = "tcp_thin_linear_timeouts",
753 .data = &sysctl_tcp_thin_linear_timeouts,
754 .maxlen = sizeof(int),
755 .mode = 0644,
756 .proc_handler = proc_dointvec
757 },
Andreas Petlund7e380172010-02-18 04:48:19 +0000758 {
759 .procname = "tcp_thin_dupack",
760 .data = &sysctl_tcp_thin_dupack,
761 .maxlen = sizeof(int),
762 .mode = 0644,
763 .proc_handler = proc_dointvec
764 },
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000765 {
Yuchung Chengeed530b2012-05-02 13:30:03 +0000766 .procname = "tcp_early_retrans",
767 .data = &sysctl_tcp_early_retrans,
768 .maxlen = sizeof(int),
769 .mode = 0644,
770 .proc_handler = proc_dointvec_minmax,
771 .extra1 = &zero,
772 .extra2 = &two,
773 },
774 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800775 .procname = "udp_mem",
776 .data = &sysctl_udp_mem,
777 .maxlen = sizeof(sysctl_udp_mem),
778 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +0000779 .proc_handler = proc_doulongvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800780 },
781 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800782 .procname = "udp_rmem_min",
783 .data = &sysctl_udp_rmem_min,
784 .maxlen = sizeof(sysctl_udp_rmem_min),
785 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800786 .proc_handler = proc_dointvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800787 .extra1 = &zero
788 },
789 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800790 .procname = "udp_wmem_min",
791 .data = &sysctl_udp_wmem_min,
792 .maxlen = sizeof(sysctl_udp_wmem_min),
793 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800794 .proc_handler = proc_dointvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800795 .extra1 = &zero
796 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800797 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800799
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700800static struct ctl_table ipv4_net_table[] = {
801 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700802 .procname = "icmp_echo_ignore_all",
803 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
804 .maxlen = sizeof(int),
805 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800806 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700807 },
808 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700809 .procname = "icmp_echo_ignore_broadcasts",
810 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
811 .maxlen = sizeof(int),
812 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800813 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700814 },
815 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700816 .procname = "icmp_ignore_bogus_error_responses",
817 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
818 .maxlen = sizeof(int),
819 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800820 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700821 },
822 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700823 .procname = "icmp_errors_use_inbound_ifaddr",
824 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
825 .maxlen = sizeof(int),
826 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800827 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700828 },
829 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700830 .procname = "icmp_ratelimit",
831 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
832 .maxlen = sizeof(int),
833 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800834 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700835 },
836 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700837 .procname = "icmp_ratemask",
838 .data = &init_net.ipv4.sysctl_icmp_ratemask,
839 .maxlen = sizeof(int),
840 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800841 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700842 },
Neil Horman1080d702008-10-27 12:28:25 -0700843 {
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000844 .procname = "ping_group_range",
845 .data = &init_net.ipv4.sysctl_ping_group_range,
Eric W. Biederman7064d162012-05-24 10:34:21 -0600846 .maxlen = sizeof(gid_t)*2,
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000847 .mode = 0644,
848 .proc_handler = ipv4_ping_group_range,
849 },
Glauber Costa3dc43e32011-12-11 21:47:05 +0000850 {
851 .procname = "tcp_mem",
852 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_mem),
853 .mode = 0644,
854 .proc_handler = ipv4_tcp_mem,
855 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700856 { }
857};
858
Pavel Emelyanov15775192008-03-26 01:54:18 -0700859static __net_init int ipv4_sysctl_init_net(struct net *net)
860{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700861 struct ctl_table *table;
862
863 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800864 if (!net_eq(net, &init_net)) {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700865 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
866 if (table == NULL)
867 goto err_alloc;
868
869 table[0].data =
870 &net->ipv4.sysctl_icmp_echo_ignore_all;
871 table[1].data =
872 &net->ipv4.sysctl_icmp_echo_ignore_broadcasts;
873 table[2].data =
874 &net->ipv4.sysctl_icmp_ignore_bogus_error_responses;
875 table[3].data =
876 &net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr;
877 table[4].data =
878 &net->ipv4.sysctl_icmp_ratelimit;
879 table[5].data =
880 &net->ipv4.sysctl_icmp_ratemask;
Neil Horman1080d702008-10-27 12:28:25 -0700881 table[6].data =
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000882 &net->ipv4.sysctl_ping_group_range;
883
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700884 }
885
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000886 /*
887 * Sane defaults - nobody may create ping sockets.
888 * Boot scripts should set this to distro-specific group.
889 */
Eric W. Biederman7064d162012-05-24 10:34:21 -0600890 net->ipv4.sysctl_ping_group_range[0] = make_kgid(&init_user_ns, 1);
891 net->ipv4.sysctl_ping_group_range[1] = make_kgid(&init_user_ns, 0);
Vasiliy Kulikovc319b4d2011-05-13 10:01:00 +0000892
Glauber Costa4acb4192012-01-30 01:20:17 +0000893 tcp_init_mem(net);
Glauber Costa3dc43e32011-12-11 21:47:05 +0000894
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +0000895 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700896 if (net->ipv4.ipv4_hdr == NULL)
897 goto err_reg;
898
Pavel Emelyanov15775192008-03-26 01:54:18 -0700899 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700900
901err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800902 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700903 kfree(table);
904err_alloc:
905 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -0700906}
907
908static __net_exit void ipv4_sysctl_exit_net(struct net *net)
909{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700910 struct ctl_table *table;
911
912 table = net->ipv4.ipv4_hdr->ctl_table_arg;
913 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
914 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700915}
916
917static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
918 .init = ipv4_sysctl_init_net,
919 .exit = ipv4_sysctl_exit_net,
920};
921
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800922static __init int sysctl_ipv4_init(void)
923{
924 struct ctl_table_header *hdr;
Amerigo Wange3826f12010-05-05 00:27:06 +0000925 struct ctl_table *i;
926
927 for (i = ipv4_table; i->procname; i++) {
928 if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
929 i->data = sysctl_local_reserved_ports;
930 break;
931 }
932 }
933 if (!i->procname)
934 return -EINVAL;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800935
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +0000936 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700937 if (hdr == NULL)
938 return -ENOMEM;
939
940 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
Eric W. Biederman5dd3df12012-04-19 13:24:33 +0000941 unregister_net_sysctl_table(hdr);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700942 return -ENOMEM;
943 }
944
945 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800946}
947
948__initcall(sysctl_ipv4_init);