]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - net/ipv4/sysctl_net_ipv4.c
Merge branch 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[mirror_ubuntu-zesty-kernel.git] / net / ipv4 / sysctl_net_ipv4.c
1 /*
2 * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
3 *
4 * 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>
11 #include <linux/igmp.h>
12 #include <linux/inetdevice.h>
13 #include <linux/seqlock.h>
14 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <linux/nsproxy.h>
17 #include <linux/swap.h>
18 #include <net/snmp.h>
19 #include <net/icmp.h>
20 #include <net/ip.h>
21 #include <net/route.h>
22 #include <net/tcp.h>
23 #include <net/udp.h>
24 #include <net/cipso_ipv4.h>
25 #include <net/inet_frag.h>
26 #include <net/ping.h>
27 #include <net/tcp_memcontrol.h>
28
29 static int zero;
30 static int one = 1;
31 static int four = 4;
32 static int gso_max_segs = GSO_MAX_SEGS;
33 static int tcp_retr1_max = 255;
34 static int ip_local_port_range_min[] = { 1, 1 };
35 static int ip_local_port_range_max[] = { 65535, 65535 };
36 static int tcp_adv_win_scale_min = -31;
37 static int tcp_adv_win_scale_max = 31;
38 static int ip_ttl_min = 1;
39 static int ip_ttl_max = 255;
40 static int tcp_syn_retries_min = 1;
41 static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
42 static int ip_ping_group_range_min[] = { 0, 0 };
43 static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
44
45 /* Update system visible IP port range */
46 static void set_local_port_range(int range[2])
47 {
48 write_seqlock(&sysctl_local_ports.lock);
49 sysctl_local_ports.range[0] = range[0];
50 sysctl_local_ports.range[1] = range[1];
51 write_sequnlock(&sysctl_local_ports.lock);
52 }
53
54 /* Validate changes from /proc interface. */
55 static int ipv4_local_port_range(struct ctl_table *table, int write,
56 void __user *buffer,
57 size_t *lenp, loff_t *ppos)
58 {
59 int ret;
60 int range[2];
61 struct ctl_table tmp = {
62 .data = &range,
63 .maxlen = sizeof(range),
64 .mode = table->mode,
65 .extra1 = &ip_local_port_range_min,
66 .extra2 = &ip_local_port_range_max,
67 };
68
69 inet_get_local_port_range(range, range + 1);
70 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
71
72 if (write && ret == 0) {
73 if (range[1] < range[0])
74 ret = -EINVAL;
75 else
76 set_local_port_range(range);
77 }
78
79 return ret;
80 }
81
82
83 static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
84 {
85 kgid_t *data = table->data;
86 unsigned int seq;
87 do {
88 seq = read_seqbegin(&sysctl_local_ports.lock);
89
90 *low = data[0];
91 *high = data[1];
92 } while (read_seqretry(&sysctl_local_ports.lock, seq));
93 }
94
95 /* Update system visible IP port range */
96 static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
97 {
98 kgid_t *data = table->data;
99 write_seqlock(&sysctl_local_ports.lock);
100 data[0] = low;
101 data[1] = high;
102 write_sequnlock(&sysctl_local_ports.lock);
103 }
104
105 /* Validate changes from /proc interface. */
106 static int ipv4_ping_group_range(struct ctl_table *table, int write,
107 void __user *buffer,
108 size_t *lenp, loff_t *ppos)
109 {
110 struct user_namespace *user_ns = current_user_ns();
111 int ret;
112 gid_t urange[2];
113 kgid_t low, high;
114 struct ctl_table tmp = {
115 .data = &urange,
116 .maxlen = sizeof(urange),
117 .mode = table->mode,
118 .extra1 = &ip_ping_group_range_min,
119 .extra2 = &ip_ping_group_range_max,
120 };
121
122 inet_get_ping_group_range_table(table, &low, &high);
123 urange[0] = from_kgid_munged(user_ns, low);
124 urange[1] = from_kgid_munged(user_ns, high);
125 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
126
127 if (write && ret == 0) {
128 low = make_kgid(user_ns, urange[0]);
129 high = make_kgid(user_ns, urange[1]);
130 if (!gid_valid(low) || !gid_valid(high) ||
131 (urange[1] < urange[0]) || gid_lt(high, low)) {
132 low = make_kgid(&init_user_ns, 1);
133 high = make_kgid(&init_user_ns, 0);
134 }
135 set_ping_group_range(table, low, high);
136 }
137
138 return ret;
139 }
140
141 static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
142 void __user *buffer, size_t *lenp, loff_t *ppos)
143 {
144 char val[TCP_CA_NAME_MAX];
145 struct ctl_table tbl = {
146 .data = val,
147 .maxlen = TCP_CA_NAME_MAX,
148 };
149 int ret;
150
151 tcp_get_default_congestion_control(val);
152
153 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
154 if (write && ret == 0)
155 ret = tcp_set_default_congestion_control(val);
156 return ret;
157 }
158
159 static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
160 int write,
161 void __user *buffer, size_t *lenp,
162 loff_t *ppos)
163 {
164 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
165 int ret;
166
167 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
168 if (!tbl.data)
169 return -ENOMEM;
170 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
171 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
172 kfree(tbl.data);
173 return ret;
174 }
175
176 static int proc_allowed_congestion_control(struct ctl_table *ctl,
177 int write,
178 void __user *buffer, size_t *lenp,
179 loff_t *ppos)
180 {
181 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
182 int ret;
183
184 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
185 if (!tbl.data)
186 return -ENOMEM;
187
188 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
189 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
190 if (write && ret == 0)
191 ret = tcp_set_allowed_congestion_control(tbl.data);
192 kfree(tbl.data);
193 return ret;
194 }
195
196 static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
197 void __user *buffer, size_t *lenp,
198 loff_t *ppos)
199 {
200 int ret;
201 unsigned long vec[3];
202 struct net *net = current->nsproxy->net_ns;
203 #ifdef CONFIG_MEMCG_KMEM
204 struct mem_cgroup *memcg;
205 #endif
206
207 struct ctl_table tmp = {
208 .data = &vec,
209 .maxlen = sizeof(vec),
210 .mode = ctl->mode,
211 };
212
213 if (!write) {
214 ctl->data = &net->ipv4.sysctl_tcp_mem;
215 return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
216 }
217
218 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
219 if (ret)
220 return ret;
221
222 #ifdef CONFIG_MEMCG_KMEM
223 rcu_read_lock();
224 memcg = mem_cgroup_from_task(current);
225
226 tcp_prot_mem(memcg, vec[0], 0);
227 tcp_prot_mem(memcg, vec[1], 1);
228 tcp_prot_mem(memcg, vec[2], 2);
229 rcu_read_unlock();
230 #endif
231
232 net->ipv4.sysctl_tcp_mem[0] = vec[0];
233 net->ipv4.sysctl_tcp_mem[1] = vec[1];
234 net->ipv4.sysctl_tcp_mem[2] = vec[2];
235
236 return 0;
237 }
238
239 static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
240 void __user *buffer, size_t *lenp,
241 loff_t *ppos)
242 {
243 struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
244 struct tcp_fastopen_context *ctxt;
245 int ret;
246 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
247
248 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
249 if (!tbl.data)
250 return -ENOMEM;
251
252 rcu_read_lock();
253 ctxt = rcu_dereference(tcp_fastopen_ctx);
254 if (ctxt)
255 memcpy(user_key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH);
256 else
257 memset(user_key, 0, sizeof(user_key));
258 rcu_read_unlock();
259
260 snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x",
261 user_key[0], user_key[1], user_key[2], user_key[3]);
262 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
263
264 if (write && ret == 0) {
265 if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1,
266 user_key + 2, user_key + 3) != 4) {
267 ret = -EINVAL;
268 goto bad_key;
269 }
270 tcp_fastopen_reset_cipher(user_key, TCP_FASTOPEN_KEY_LENGTH);
271 }
272
273 bad_key:
274 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
275 user_key[0], user_key[1], user_key[2], user_key[3],
276 (char *)tbl.data, ret);
277 kfree(tbl.data);
278 return ret;
279 }
280
281 static struct ctl_table ipv4_table[] = {
282 {
283 .procname = "tcp_timestamps",
284 .data = &sysctl_tcp_timestamps,
285 .maxlen = sizeof(int),
286 .mode = 0644,
287 .proc_handler = proc_dointvec
288 },
289 {
290 .procname = "tcp_window_scaling",
291 .data = &sysctl_tcp_window_scaling,
292 .maxlen = sizeof(int),
293 .mode = 0644,
294 .proc_handler = proc_dointvec
295 },
296 {
297 .procname = "tcp_sack",
298 .data = &sysctl_tcp_sack,
299 .maxlen = sizeof(int),
300 .mode = 0644,
301 .proc_handler = proc_dointvec
302 },
303 {
304 .procname = "tcp_retrans_collapse",
305 .data = &sysctl_tcp_retrans_collapse,
306 .maxlen = sizeof(int),
307 .mode = 0644,
308 .proc_handler = proc_dointvec
309 },
310 {
311 .procname = "ip_default_ttl",
312 .data = &sysctl_ip_default_ttl,
313 .maxlen = sizeof(int),
314 .mode = 0644,
315 .proc_handler = proc_dointvec_minmax,
316 .extra1 = &ip_ttl_min,
317 .extra2 = &ip_ttl_max,
318 },
319 {
320 .procname = "ip_no_pmtu_disc",
321 .data = &ipv4_config.no_pmtu_disc,
322 .maxlen = sizeof(int),
323 .mode = 0644,
324 .proc_handler = proc_dointvec
325 },
326 {
327 .procname = "ip_nonlocal_bind",
328 .data = &sysctl_ip_nonlocal_bind,
329 .maxlen = sizeof(int),
330 .mode = 0644,
331 .proc_handler = proc_dointvec
332 },
333 {
334 .procname = "tcp_syn_retries",
335 .data = &sysctl_tcp_syn_retries,
336 .maxlen = sizeof(int),
337 .mode = 0644,
338 .proc_handler = proc_dointvec_minmax,
339 .extra1 = &tcp_syn_retries_min,
340 .extra2 = &tcp_syn_retries_max
341 },
342 {
343 .procname = "tcp_synack_retries",
344 .data = &sysctl_tcp_synack_retries,
345 .maxlen = sizeof(int),
346 .mode = 0644,
347 .proc_handler = proc_dointvec
348 },
349 {
350 .procname = "tcp_max_orphans",
351 .data = &sysctl_tcp_max_orphans,
352 .maxlen = sizeof(int),
353 .mode = 0644,
354 .proc_handler = proc_dointvec
355 },
356 {
357 .procname = "tcp_max_tw_buckets",
358 .data = &tcp_death_row.sysctl_max_tw_buckets,
359 .maxlen = sizeof(int),
360 .mode = 0644,
361 .proc_handler = proc_dointvec
362 },
363 {
364 .procname = "ip_early_demux",
365 .data = &sysctl_ip_early_demux,
366 .maxlen = sizeof(int),
367 .mode = 0644,
368 .proc_handler = proc_dointvec
369 },
370 {
371 .procname = "ip_dynaddr",
372 .data = &sysctl_ip_dynaddr,
373 .maxlen = sizeof(int),
374 .mode = 0644,
375 .proc_handler = proc_dointvec
376 },
377 {
378 .procname = "tcp_keepalive_time",
379 .data = &sysctl_tcp_keepalive_time,
380 .maxlen = sizeof(int),
381 .mode = 0644,
382 .proc_handler = proc_dointvec_jiffies,
383 },
384 {
385 .procname = "tcp_keepalive_probes",
386 .data = &sysctl_tcp_keepalive_probes,
387 .maxlen = sizeof(int),
388 .mode = 0644,
389 .proc_handler = proc_dointvec
390 },
391 {
392 .procname = "tcp_keepalive_intvl",
393 .data = &sysctl_tcp_keepalive_intvl,
394 .maxlen = sizeof(int),
395 .mode = 0644,
396 .proc_handler = proc_dointvec_jiffies,
397 },
398 {
399 .procname = "tcp_retries1",
400 .data = &sysctl_tcp_retries1,
401 .maxlen = sizeof(int),
402 .mode = 0644,
403 .proc_handler = proc_dointvec_minmax,
404 .extra2 = &tcp_retr1_max
405 },
406 {
407 .procname = "tcp_retries2",
408 .data = &sysctl_tcp_retries2,
409 .maxlen = sizeof(int),
410 .mode = 0644,
411 .proc_handler = proc_dointvec
412 },
413 {
414 .procname = "tcp_fin_timeout",
415 .data = &sysctl_tcp_fin_timeout,
416 .maxlen = sizeof(int),
417 .mode = 0644,
418 .proc_handler = proc_dointvec_jiffies,
419 },
420 #ifdef CONFIG_SYN_COOKIES
421 {
422 .procname = "tcp_syncookies",
423 .data = &sysctl_tcp_syncookies,
424 .maxlen = sizeof(int),
425 .mode = 0644,
426 .proc_handler = proc_dointvec
427 },
428 #endif
429 {
430 .procname = "tcp_fastopen",
431 .data = &sysctl_tcp_fastopen,
432 .maxlen = sizeof(int),
433 .mode = 0644,
434 .proc_handler = proc_dointvec,
435 },
436 {
437 .procname = "tcp_fastopen_key",
438 .mode = 0600,
439 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
440 .proc_handler = proc_tcp_fastopen_key,
441 },
442 {
443 .procname = "tcp_tw_recycle",
444 .data = &tcp_death_row.sysctl_tw_recycle,
445 .maxlen = sizeof(int),
446 .mode = 0644,
447 .proc_handler = proc_dointvec
448 },
449 {
450 .procname = "tcp_abort_on_overflow",
451 .data = &sysctl_tcp_abort_on_overflow,
452 .maxlen = sizeof(int),
453 .mode = 0644,
454 .proc_handler = proc_dointvec
455 },
456 {
457 .procname = "tcp_stdurg",
458 .data = &sysctl_tcp_stdurg,
459 .maxlen = sizeof(int),
460 .mode = 0644,
461 .proc_handler = proc_dointvec
462 },
463 {
464 .procname = "tcp_rfc1337",
465 .data = &sysctl_tcp_rfc1337,
466 .maxlen = sizeof(int),
467 .mode = 0644,
468 .proc_handler = proc_dointvec
469 },
470 {
471 .procname = "tcp_max_syn_backlog",
472 .data = &sysctl_max_syn_backlog,
473 .maxlen = sizeof(int),
474 .mode = 0644,
475 .proc_handler = proc_dointvec
476 },
477 {
478 .procname = "ip_local_port_range",
479 .data = &sysctl_local_ports.range,
480 .maxlen = sizeof(sysctl_local_ports.range),
481 .mode = 0644,
482 .proc_handler = ipv4_local_port_range,
483 },
484 {
485 .procname = "ip_local_reserved_ports",
486 .data = NULL, /* initialized in sysctl_ipv4_init */
487 .maxlen = 65536,
488 .mode = 0644,
489 .proc_handler = proc_do_large_bitmap,
490 },
491 {
492 .procname = "igmp_max_memberships",
493 .data = &sysctl_igmp_max_memberships,
494 .maxlen = sizeof(int),
495 .mode = 0644,
496 .proc_handler = proc_dointvec
497 },
498 {
499 .procname = "igmp_max_msf",
500 .data = &sysctl_igmp_max_msf,
501 .maxlen = sizeof(int),
502 .mode = 0644,
503 .proc_handler = proc_dointvec
504 },
505 {
506 .procname = "inet_peer_threshold",
507 .data = &inet_peer_threshold,
508 .maxlen = sizeof(int),
509 .mode = 0644,
510 .proc_handler = proc_dointvec
511 },
512 {
513 .procname = "inet_peer_minttl",
514 .data = &inet_peer_minttl,
515 .maxlen = sizeof(int),
516 .mode = 0644,
517 .proc_handler = proc_dointvec_jiffies,
518 },
519 {
520 .procname = "inet_peer_maxttl",
521 .data = &inet_peer_maxttl,
522 .maxlen = sizeof(int),
523 .mode = 0644,
524 .proc_handler = proc_dointvec_jiffies,
525 },
526 {
527 .procname = "tcp_orphan_retries",
528 .data = &sysctl_tcp_orphan_retries,
529 .maxlen = sizeof(int),
530 .mode = 0644,
531 .proc_handler = proc_dointvec
532 },
533 {
534 .procname = "tcp_fack",
535 .data = &sysctl_tcp_fack,
536 .maxlen = sizeof(int),
537 .mode = 0644,
538 .proc_handler = proc_dointvec
539 },
540 {
541 .procname = "tcp_reordering",
542 .data = &sysctl_tcp_reordering,
543 .maxlen = sizeof(int),
544 .mode = 0644,
545 .proc_handler = proc_dointvec
546 },
547 {
548 .procname = "tcp_dsack",
549 .data = &sysctl_tcp_dsack,
550 .maxlen = sizeof(int),
551 .mode = 0644,
552 .proc_handler = proc_dointvec
553 },
554 {
555 .procname = "tcp_wmem",
556 .data = &sysctl_tcp_wmem,
557 .maxlen = sizeof(sysctl_tcp_wmem),
558 .mode = 0644,
559 .proc_handler = proc_dointvec_minmax,
560 .extra1 = &one,
561 },
562 {
563 .procname = "tcp_notsent_lowat",
564 .data = &sysctl_tcp_notsent_lowat,
565 .maxlen = sizeof(sysctl_tcp_notsent_lowat),
566 .mode = 0644,
567 .proc_handler = proc_dointvec,
568 },
569 {
570 .procname = "tcp_rmem",
571 .data = &sysctl_tcp_rmem,
572 .maxlen = sizeof(sysctl_tcp_rmem),
573 .mode = 0644,
574 .proc_handler = proc_dointvec_minmax,
575 .extra1 = &one,
576 },
577 {
578 .procname = "tcp_app_win",
579 .data = &sysctl_tcp_app_win,
580 .maxlen = sizeof(int),
581 .mode = 0644,
582 .proc_handler = proc_dointvec
583 },
584 {
585 .procname = "tcp_adv_win_scale",
586 .data = &sysctl_tcp_adv_win_scale,
587 .maxlen = sizeof(int),
588 .mode = 0644,
589 .proc_handler = proc_dointvec_minmax,
590 .extra1 = &tcp_adv_win_scale_min,
591 .extra2 = &tcp_adv_win_scale_max,
592 },
593 {
594 .procname = "tcp_tw_reuse",
595 .data = &sysctl_tcp_tw_reuse,
596 .maxlen = sizeof(int),
597 .mode = 0644,
598 .proc_handler = proc_dointvec
599 },
600 {
601 .procname = "tcp_frto",
602 .data = &sysctl_tcp_frto,
603 .maxlen = sizeof(int),
604 .mode = 0644,
605 .proc_handler = proc_dointvec
606 },
607 {
608 .procname = "tcp_low_latency",
609 .data = &sysctl_tcp_low_latency,
610 .maxlen = sizeof(int),
611 .mode = 0644,
612 .proc_handler = proc_dointvec
613 },
614 {
615 .procname = "tcp_no_metrics_save",
616 .data = &sysctl_tcp_nometrics_save,
617 .maxlen = sizeof(int),
618 .mode = 0644,
619 .proc_handler = proc_dointvec,
620 },
621 {
622 .procname = "tcp_moderate_rcvbuf",
623 .data = &sysctl_tcp_moderate_rcvbuf,
624 .maxlen = sizeof(int),
625 .mode = 0644,
626 .proc_handler = proc_dointvec,
627 },
628 {
629 .procname = "tcp_tso_win_divisor",
630 .data = &sysctl_tcp_tso_win_divisor,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 .proc_handler = proc_dointvec,
634 },
635 {
636 .procname = "tcp_congestion_control",
637 .mode = 0644,
638 .maxlen = TCP_CA_NAME_MAX,
639 .proc_handler = proc_tcp_congestion_control,
640 },
641 {
642 .procname = "tcp_mtu_probing",
643 .data = &sysctl_tcp_mtu_probing,
644 .maxlen = sizeof(int),
645 .mode = 0644,
646 .proc_handler = proc_dointvec,
647 },
648 {
649 .procname = "tcp_base_mss",
650 .data = &sysctl_tcp_base_mss,
651 .maxlen = sizeof(int),
652 .mode = 0644,
653 .proc_handler = proc_dointvec,
654 },
655 {
656 .procname = "tcp_workaround_signed_windows",
657 .data = &sysctl_tcp_workaround_signed_windows,
658 .maxlen = sizeof(int),
659 .mode = 0644,
660 .proc_handler = proc_dointvec
661 },
662 {
663 .procname = "tcp_limit_output_bytes",
664 .data = &sysctl_tcp_limit_output_bytes,
665 .maxlen = sizeof(int),
666 .mode = 0644,
667 .proc_handler = proc_dointvec
668 },
669 {
670 .procname = "tcp_challenge_ack_limit",
671 .data = &sysctl_tcp_challenge_ack_limit,
672 .maxlen = sizeof(int),
673 .mode = 0644,
674 .proc_handler = proc_dointvec
675 },
676 #ifdef CONFIG_NET_DMA
677 {
678 .procname = "tcp_dma_copybreak",
679 .data = &sysctl_tcp_dma_copybreak,
680 .maxlen = sizeof(int),
681 .mode = 0644,
682 .proc_handler = proc_dointvec
683 },
684 #endif
685 {
686 .procname = "tcp_slow_start_after_idle",
687 .data = &sysctl_tcp_slow_start_after_idle,
688 .maxlen = sizeof(int),
689 .mode = 0644,
690 .proc_handler = proc_dointvec
691 },
692 #ifdef CONFIG_NETLABEL
693 {
694 .procname = "cipso_cache_enable",
695 .data = &cipso_v4_cache_enabled,
696 .maxlen = sizeof(int),
697 .mode = 0644,
698 .proc_handler = proc_dointvec,
699 },
700 {
701 .procname = "cipso_cache_bucket_size",
702 .data = &cipso_v4_cache_bucketsize,
703 .maxlen = sizeof(int),
704 .mode = 0644,
705 .proc_handler = proc_dointvec,
706 },
707 {
708 .procname = "cipso_rbm_optfmt",
709 .data = &cipso_v4_rbm_optfmt,
710 .maxlen = sizeof(int),
711 .mode = 0644,
712 .proc_handler = proc_dointvec,
713 },
714 {
715 .procname = "cipso_rbm_strictvalid",
716 .data = &cipso_v4_rbm_strictvalid,
717 .maxlen = sizeof(int),
718 .mode = 0644,
719 .proc_handler = proc_dointvec,
720 },
721 #endif /* CONFIG_NETLABEL */
722 {
723 .procname = "tcp_available_congestion_control",
724 .maxlen = TCP_CA_BUF_MAX,
725 .mode = 0444,
726 .proc_handler = proc_tcp_available_congestion_control,
727 },
728 {
729 .procname = "tcp_allowed_congestion_control",
730 .maxlen = TCP_CA_BUF_MAX,
731 .mode = 0644,
732 .proc_handler = proc_allowed_congestion_control,
733 },
734 {
735 .procname = "tcp_max_ssthresh",
736 .data = &sysctl_tcp_max_ssthresh,
737 .maxlen = sizeof(int),
738 .mode = 0644,
739 .proc_handler = proc_dointvec,
740 },
741 {
742 .procname = "tcp_thin_linear_timeouts",
743 .data = &sysctl_tcp_thin_linear_timeouts,
744 .maxlen = sizeof(int),
745 .mode = 0644,
746 .proc_handler = proc_dointvec
747 },
748 {
749 .procname = "tcp_thin_dupack",
750 .data = &sysctl_tcp_thin_dupack,
751 .maxlen = sizeof(int),
752 .mode = 0644,
753 .proc_handler = proc_dointvec
754 },
755 {
756 .procname = "tcp_early_retrans",
757 .data = &sysctl_tcp_early_retrans,
758 .maxlen = sizeof(int),
759 .mode = 0644,
760 .proc_handler = proc_dointvec_minmax,
761 .extra1 = &zero,
762 .extra2 = &four,
763 },
764 {
765 .procname = "tcp_min_tso_segs",
766 .data = &sysctl_tcp_min_tso_segs,
767 .maxlen = sizeof(int),
768 .mode = 0644,
769 .proc_handler = proc_dointvec_minmax,
770 .extra1 = &zero,
771 .extra2 = &gso_max_segs,
772 },
773 {
774 .procname = "udp_mem",
775 .data = &sysctl_udp_mem,
776 .maxlen = sizeof(sysctl_udp_mem),
777 .mode = 0644,
778 .proc_handler = proc_doulongvec_minmax,
779 },
780 {
781 .procname = "udp_rmem_min",
782 .data = &sysctl_udp_rmem_min,
783 .maxlen = sizeof(sysctl_udp_rmem_min),
784 .mode = 0644,
785 .proc_handler = proc_dointvec_minmax,
786 .extra1 = &one
787 },
788 {
789 .procname = "udp_wmem_min",
790 .data = &sysctl_udp_wmem_min,
791 .maxlen = sizeof(sysctl_udp_wmem_min),
792 .mode = 0644,
793 .proc_handler = proc_dointvec_minmax,
794 .extra1 = &one
795 },
796 { }
797 };
798
799 static struct ctl_table ipv4_net_table[] = {
800 {
801 .procname = "icmp_echo_ignore_all",
802 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
803 .maxlen = sizeof(int),
804 .mode = 0644,
805 .proc_handler = proc_dointvec
806 },
807 {
808 .procname = "icmp_echo_ignore_broadcasts",
809 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
810 .maxlen = sizeof(int),
811 .mode = 0644,
812 .proc_handler = proc_dointvec
813 },
814 {
815 .procname = "icmp_ignore_bogus_error_responses",
816 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
817 .maxlen = sizeof(int),
818 .mode = 0644,
819 .proc_handler = proc_dointvec
820 },
821 {
822 .procname = "icmp_errors_use_inbound_ifaddr",
823 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
824 .maxlen = sizeof(int),
825 .mode = 0644,
826 .proc_handler = proc_dointvec
827 },
828 {
829 .procname = "icmp_ratelimit",
830 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
831 .maxlen = sizeof(int),
832 .mode = 0644,
833 .proc_handler = proc_dointvec_ms_jiffies,
834 },
835 {
836 .procname = "icmp_ratemask",
837 .data = &init_net.ipv4.sysctl_icmp_ratemask,
838 .maxlen = sizeof(int),
839 .mode = 0644,
840 .proc_handler = proc_dointvec
841 },
842 {
843 .procname = "ping_group_range",
844 .data = &init_net.ipv4.sysctl_ping_group_range,
845 .maxlen = sizeof(gid_t)*2,
846 .mode = 0644,
847 .proc_handler = ipv4_ping_group_range,
848 },
849 {
850 .procname = "tcp_ecn",
851 .data = &init_net.ipv4.sysctl_tcp_ecn,
852 .maxlen = sizeof(int),
853 .mode = 0644,
854 .proc_handler = proc_dointvec
855 },
856 {
857 .procname = "tcp_mem",
858 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_mem),
859 .mode = 0644,
860 .proc_handler = ipv4_tcp_mem,
861 },
862 { }
863 };
864
865 static __net_init int ipv4_sysctl_init_net(struct net *net)
866 {
867 struct ctl_table *table;
868
869 table = ipv4_net_table;
870 if (!net_eq(net, &init_net)) {
871 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
872 if (table == NULL)
873 goto err_alloc;
874
875 table[0].data =
876 &net->ipv4.sysctl_icmp_echo_ignore_all;
877 table[1].data =
878 &net->ipv4.sysctl_icmp_echo_ignore_broadcasts;
879 table[2].data =
880 &net->ipv4.sysctl_icmp_ignore_bogus_error_responses;
881 table[3].data =
882 &net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr;
883 table[4].data =
884 &net->ipv4.sysctl_icmp_ratelimit;
885 table[5].data =
886 &net->ipv4.sysctl_icmp_ratemask;
887 table[6].data =
888 &net->ipv4.sysctl_ping_group_range;
889 table[7].data =
890 &net->ipv4.sysctl_tcp_ecn;
891
892 /* Don't export sysctls to unprivileged users */
893 if (net->user_ns != &init_user_ns)
894 table[0].procname = NULL;
895 }
896
897 /*
898 * Sane defaults - nobody may create ping sockets.
899 * Boot scripts should set this to distro-specific group.
900 */
901 net->ipv4.sysctl_ping_group_range[0] = make_kgid(&init_user_ns, 1);
902 net->ipv4.sysctl_ping_group_range[1] = make_kgid(&init_user_ns, 0);
903
904 tcp_init_mem(net);
905
906 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
907 if (net->ipv4.ipv4_hdr == NULL)
908 goto err_reg;
909
910 return 0;
911
912 err_reg:
913 if (!net_eq(net, &init_net))
914 kfree(table);
915 err_alloc:
916 return -ENOMEM;
917 }
918
919 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
920 {
921 struct ctl_table *table;
922
923 table = net->ipv4.ipv4_hdr->ctl_table_arg;
924 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
925 kfree(table);
926 }
927
928 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
929 .init = ipv4_sysctl_init_net,
930 .exit = ipv4_sysctl_exit_net,
931 };
932
933 static __init int sysctl_ipv4_init(void)
934 {
935 struct ctl_table_header *hdr;
936 struct ctl_table *i;
937
938 for (i = ipv4_table; i->procname; i++) {
939 if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
940 i->data = sysctl_local_reserved_ports;
941 break;
942 }
943 }
944 if (!i->procname)
945 return -EINVAL;
946
947 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
948 if (hdr == NULL)
949 return -ENOMEM;
950
951 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
952 unregister_net_sysctl_table(hdr);
953 return -ENOMEM;
954 }
955
956 return 0;
957 }
958
959 __initcall(sysctl_ipv4_init);