2 * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
4 * $Id: sysctl_net_ipv4.c,v 1.50 2001/10/20 00:00:11 davem Exp $
6 * Begun April 1, 1996, Mike Shaver.
7 * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
11 #include <linux/module.h>
12 #include <linux/sysctl.h>
13 #include <linux/igmp.h>
14 #include <linux/inetdevice.h>
18 #include <net/route.h>
20 #include <net/cipso_ipv4.h>
23 extern int sysctl_ip_nonlocal_bind;
27 static int tcp_retr1_max = 255;
28 static int ip_local_port_range_min[] = { 1, 1 };
29 static int ip_local_port_range_max[] = { 65535, 65535 };
32 struct ipv4_config ipv4_config;
37 int ipv4_sysctl_forward(ctl_table *ctl, int write, struct file * filp,
38 void __user *buffer, size_t *lenp, loff_t *ppos)
40 int val = ipv4_devconf.forwarding;
43 ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos);
45 if (write && ipv4_devconf.forwarding != val)
46 inet_forward_change();
51 static int ipv4_sysctl_forward_strategy(ctl_table *table,
52 int __user *name, int nlen,
53 void __user *oldval, size_t __user *oldlenp,
54 void __user *newval, size_t newlen)
56 int *valp = table->data;
59 if (!newval || !newlen)
62 if (newlen != sizeof(int))
65 if (get_user(new, (int __user *)newval))
71 if (oldval && oldlenp) {
74 if (get_user(len, oldlenp))
78 if (len > table->maxlen)
80 if (copy_to_user(oldval, valp, len))
82 if (put_user(len, oldlenp))
88 inet_forward_change();
92 static int proc_tcp_congestion_control(ctl_table *ctl, int write, struct file * filp,
93 void __user *buffer, size_t *lenp, loff_t *ppos)
95 char val[TCP_CA_NAME_MAX];
98 .maxlen = TCP_CA_NAME_MAX,
102 tcp_get_default_congestion_control(val);
104 ret = proc_dostring(&tbl, write, filp, buffer, lenp, ppos);
105 if (write && ret == 0)
106 ret = tcp_set_default_congestion_control(val);
110 static int sysctl_tcp_congestion_control(ctl_table *table, int __user *name,
111 int nlen, void __user *oldval,
112 size_t __user *oldlenp,
113 void __user *newval, size_t newlen)
115 char val[TCP_CA_NAME_MAX];
118 .maxlen = TCP_CA_NAME_MAX,
122 tcp_get_default_congestion_control(val);
123 ret = sysctl_string(&tbl, name, nlen, oldval, oldlenp, newval, newlen);
124 if (ret == 0 && newval && newlen)
125 ret = tcp_set_default_congestion_control(val);
129 static int proc_tcp_available_congestion_control(ctl_table *ctl,
130 int write, struct file * filp,
131 void __user *buffer, size_t *lenp,
134 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
137 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
140 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
141 ret = proc_dostring(&tbl, write, filp, buffer, lenp, ppos);
146 static int proc_allowed_congestion_control(ctl_table *ctl,
147 int write, struct file * filp,
148 void __user *buffer, size_t *lenp,
151 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
154 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
158 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
159 ret = proc_dostring(&tbl, write, filp, buffer, lenp, ppos);
160 if (write && ret == 0)
161 ret = tcp_set_allowed_congestion_control(tbl.data);
166 static int strategy_allowed_congestion_control(ctl_table *table, int __user *name,
167 int nlen, void __user *oldval,
168 size_t __user *oldlenp,
172 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
175 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
179 tcp_get_available_congestion_control(tbl.data, tbl.maxlen);
180 ret = sysctl_string(&tbl, name, nlen, oldval, oldlenp, newval, newlen);
181 if (ret == 0 && newval && newlen)
182 ret = tcp_set_allowed_congestion_control(tbl.data);
189 ctl_table ipv4_table[] = {
191 .ctl_name = NET_IPV4_TCP_TIMESTAMPS,
192 .procname = "tcp_timestamps",
193 .data = &sysctl_tcp_timestamps,
194 .maxlen = sizeof(int),
196 .proc_handler = &proc_dointvec
199 .ctl_name = NET_IPV4_TCP_WINDOW_SCALING,
200 .procname = "tcp_window_scaling",
201 .data = &sysctl_tcp_window_scaling,
202 .maxlen = sizeof(int),
204 .proc_handler = &proc_dointvec
207 .ctl_name = NET_IPV4_TCP_SACK,
208 .procname = "tcp_sack",
209 .data = &sysctl_tcp_sack,
210 .maxlen = sizeof(int),
212 .proc_handler = &proc_dointvec
215 .ctl_name = NET_IPV4_TCP_RETRANS_COLLAPSE,
216 .procname = "tcp_retrans_collapse",
217 .data = &sysctl_tcp_retrans_collapse,
218 .maxlen = sizeof(int),
220 .proc_handler = &proc_dointvec
223 .ctl_name = NET_IPV4_FORWARD,
224 .procname = "ip_forward",
225 .data = &ipv4_devconf.forwarding,
226 .maxlen = sizeof(int),
228 .proc_handler = &ipv4_sysctl_forward,
229 .strategy = &ipv4_sysctl_forward_strategy
232 .ctl_name = NET_IPV4_DEFAULT_TTL,
233 .procname = "ip_default_ttl",
234 .data = &sysctl_ip_default_ttl,
235 .maxlen = sizeof(int),
237 .proc_handler = &ipv4_doint_and_flush,
238 .strategy = &ipv4_doint_and_flush_strategy,
241 .ctl_name = NET_IPV4_NO_PMTU_DISC,
242 .procname = "ip_no_pmtu_disc",
243 .data = &ipv4_config.no_pmtu_disc,
244 .maxlen = sizeof(int),
246 .proc_handler = &proc_dointvec
249 .ctl_name = NET_IPV4_NONLOCAL_BIND,
250 .procname = "ip_nonlocal_bind",
251 .data = &sysctl_ip_nonlocal_bind,
252 .maxlen = sizeof(int),
254 .proc_handler = &proc_dointvec
257 .ctl_name = NET_IPV4_TCP_SYN_RETRIES,
258 .procname = "tcp_syn_retries",
259 .data = &sysctl_tcp_syn_retries,
260 .maxlen = sizeof(int),
262 .proc_handler = &proc_dointvec
265 .ctl_name = NET_TCP_SYNACK_RETRIES,
266 .procname = "tcp_synack_retries",
267 .data = &sysctl_tcp_synack_retries,
268 .maxlen = sizeof(int),
270 .proc_handler = &proc_dointvec
273 .ctl_name = NET_TCP_MAX_ORPHANS,
274 .procname = "tcp_max_orphans",
275 .data = &sysctl_tcp_max_orphans,
276 .maxlen = sizeof(int),
278 .proc_handler = &proc_dointvec
281 .ctl_name = NET_TCP_MAX_TW_BUCKETS,
282 .procname = "tcp_max_tw_buckets",
283 .data = &tcp_death_row.sysctl_max_tw_buckets,
284 .maxlen = sizeof(int),
286 .proc_handler = &proc_dointvec
289 .ctl_name = NET_IPV4_IPFRAG_HIGH_THRESH,
290 .procname = "ipfrag_high_thresh",
291 .data = &sysctl_ipfrag_high_thresh,
292 .maxlen = sizeof(int),
294 .proc_handler = &proc_dointvec
297 .ctl_name = NET_IPV4_IPFRAG_LOW_THRESH,
298 .procname = "ipfrag_low_thresh",
299 .data = &sysctl_ipfrag_low_thresh,
300 .maxlen = sizeof(int),
302 .proc_handler = &proc_dointvec
305 .ctl_name = NET_IPV4_DYNADDR,
306 .procname = "ip_dynaddr",
307 .data = &sysctl_ip_dynaddr,
308 .maxlen = sizeof(int),
310 .proc_handler = &proc_dointvec
313 .ctl_name = NET_IPV4_IPFRAG_TIME,
314 .procname = "ipfrag_time",
315 .data = &sysctl_ipfrag_time,
316 .maxlen = sizeof(int),
318 .proc_handler = &proc_dointvec_jiffies,
319 .strategy = &sysctl_jiffies
322 .ctl_name = NET_IPV4_TCP_KEEPALIVE_TIME,
323 .procname = "tcp_keepalive_time",
324 .data = &sysctl_tcp_keepalive_time,
325 .maxlen = sizeof(int),
327 .proc_handler = &proc_dointvec_jiffies,
328 .strategy = &sysctl_jiffies
331 .ctl_name = NET_IPV4_TCP_KEEPALIVE_PROBES,
332 .procname = "tcp_keepalive_probes",
333 .data = &sysctl_tcp_keepalive_probes,
334 .maxlen = sizeof(int),
336 .proc_handler = &proc_dointvec
339 .ctl_name = NET_IPV4_TCP_KEEPALIVE_INTVL,
340 .procname = "tcp_keepalive_intvl",
341 .data = &sysctl_tcp_keepalive_intvl,
342 .maxlen = sizeof(int),
344 .proc_handler = &proc_dointvec_jiffies,
345 .strategy = &sysctl_jiffies
348 .ctl_name = NET_IPV4_TCP_RETRIES1,
349 .procname = "tcp_retries1",
350 .data = &sysctl_tcp_retries1,
351 .maxlen = sizeof(int),
353 .proc_handler = &proc_dointvec_minmax,
354 .strategy = &sysctl_intvec,
355 .extra2 = &tcp_retr1_max
358 .ctl_name = NET_IPV4_TCP_RETRIES2,
359 .procname = "tcp_retries2",
360 .data = &sysctl_tcp_retries2,
361 .maxlen = sizeof(int),
363 .proc_handler = &proc_dointvec
366 .ctl_name = NET_IPV4_TCP_FIN_TIMEOUT,
367 .procname = "tcp_fin_timeout",
368 .data = &sysctl_tcp_fin_timeout,
369 .maxlen = sizeof(int),
371 .proc_handler = &proc_dointvec_jiffies,
372 .strategy = &sysctl_jiffies
374 #ifdef CONFIG_SYN_COOKIES
376 .ctl_name = NET_TCP_SYNCOOKIES,
377 .procname = "tcp_syncookies",
378 .data = &sysctl_tcp_syncookies,
379 .maxlen = sizeof(int),
381 .proc_handler = &proc_dointvec
385 .ctl_name = NET_TCP_TW_RECYCLE,
386 .procname = "tcp_tw_recycle",
387 .data = &tcp_death_row.sysctl_tw_recycle,
388 .maxlen = sizeof(int),
390 .proc_handler = &proc_dointvec
393 .ctl_name = NET_TCP_ABORT_ON_OVERFLOW,
394 .procname = "tcp_abort_on_overflow",
395 .data = &sysctl_tcp_abort_on_overflow,
396 .maxlen = sizeof(int),
398 .proc_handler = &proc_dointvec
401 .ctl_name = NET_TCP_STDURG,
402 .procname = "tcp_stdurg",
403 .data = &sysctl_tcp_stdurg,
404 .maxlen = sizeof(int),
406 .proc_handler = &proc_dointvec
409 .ctl_name = NET_TCP_RFC1337,
410 .procname = "tcp_rfc1337",
411 .data = &sysctl_tcp_rfc1337,
412 .maxlen = sizeof(int),
414 .proc_handler = &proc_dointvec
417 .ctl_name = NET_TCP_MAX_SYN_BACKLOG,
418 .procname = "tcp_max_syn_backlog",
419 .data = &sysctl_max_syn_backlog,
420 .maxlen = sizeof(int),
422 .proc_handler = &proc_dointvec
425 .ctl_name = NET_IPV4_LOCAL_PORT_RANGE,
426 .procname = "ip_local_port_range",
427 .data = &sysctl_local_port_range,
428 .maxlen = sizeof(sysctl_local_port_range),
430 .proc_handler = &proc_dointvec_minmax,
431 .strategy = &sysctl_intvec,
432 .extra1 = ip_local_port_range_min,
433 .extra2 = ip_local_port_range_max
436 .ctl_name = NET_IPV4_ICMP_ECHO_IGNORE_ALL,
437 .procname = "icmp_echo_ignore_all",
438 .data = &sysctl_icmp_echo_ignore_all,
439 .maxlen = sizeof(int),
441 .proc_handler = &proc_dointvec
444 .ctl_name = NET_IPV4_ICMP_ECHO_IGNORE_BROADCASTS,
445 .procname = "icmp_echo_ignore_broadcasts",
446 .data = &sysctl_icmp_echo_ignore_broadcasts,
447 .maxlen = sizeof(int),
449 .proc_handler = &proc_dointvec
452 .ctl_name = NET_IPV4_ICMP_IGNORE_BOGUS_ERROR_RESPONSES,
453 .procname = "icmp_ignore_bogus_error_responses",
454 .data = &sysctl_icmp_ignore_bogus_error_responses,
455 .maxlen = sizeof(int),
457 .proc_handler = &proc_dointvec
460 .ctl_name = NET_IPV4_ICMP_ERRORS_USE_INBOUND_IFADDR,
461 .procname = "icmp_errors_use_inbound_ifaddr",
462 .data = &sysctl_icmp_errors_use_inbound_ifaddr,
463 .maxlen = sizeof(int),
465 .proc_handler = &proc_dointvec
468 .ctl_name = NET_IPV4_ROUTE,
472 .child = ipv4_route_table
474 #ifdef CONFIG_IP_MULTICAST
476 .ctl_name = NET_IPV4_IGMP_MAX_MEMBERSHIPS,
477 .procname = "igmp_max_memberships",
478 .data = &sysctl_igmp_max_memberships,
479 .maxlen = sizeof(int),
481 .proc_handler = &proc_dointvec
486 .ctl_name = NET_IPV4_IGMP_MAX_MSF,
487 .procname = "igmp_max_msf",
488 .data = &sysctl_igmp_max_msf,
489 .maxlen = sizeof(int),
491 .proc_handler = &proc_dointvec
494 .ctl_name = NET_IPV4_INET_PEER_THRESHOLD,
495 .procname = "inet_peer_threshold",
496 .data = &inet_peer_threshold,
497 .maxlen = sizeof(int),
499 .proc_handler = &proc_dointvec
502 .ctl_name = NET_IPV4_INET_PEER_MINTTL,
503 .procname = "inet_peer_minttl",
504 .data = &inet_peer_minttl,
505 .maxlen = sizeof(int),
507 .proc_handler = &proc_dointvec_jiffies,
508 .strategy = &sysctl_jiffies
511 .ctl_name = NET_IPV4_INET_PEER_MAXTTL,
512 .procname = "inet_peer_maxttl",
513 .data = &inet_peer_maxttl,
514 .maxlen = sizeof(int),
516 .proc_handler = &proc_dointvec_jiffies,
517 .strategy = &sysctl_jiffies
520 .ctl_name = NET_IPV4_INET_PEER_GC_MINTIME,
521 .procname = "inet_peer_gc_mintime",
522 .data = &inet_peer_gc_mintime,
523 .maxlen = sizeof(int),
525 .proc_handler = &proc_dointvec_jiffies,
526 .strategy = &sysctl_jiffies
529 .ctl_name = NET_IPV4_INET_PEER_GC_MAXTIME,
530 .procname = "inet_peer_gc_maxtime",
531 .data = &inet_peer_gc_maxtime,
532 .maxlen = sizeof(int),
534 .proc_handler = &proc_dointvec_jiffies,
535 .strategy = &sysctl_jiffies
538 .ctl_name = NET_TCP_ORPHAN_RETRIES,
539 .procname = "tcp_orphan_retries",
540 .data = &sysctl_tcp_orphan_retries,
541 .maxlen = sizeof(int),
543 .proc_handler = &proc_dointvec
546 .ctl_name = NET_TCP_FACK,
547 .procname = "tcp_fack",
548 .data = &sysctl_tcp_fack,
549 .maxlen = sizeof(int),
551 .proc_handler = &proc_dointvec
554 .ctl_name = NET_TCP_REORDERING,
555 .procname = "tcp_reordering",
556 .data = &sysctl_tcp_reordering,
557 .maxlen = sizeof(int),
559 .proc_handler = &proc_dointvec
562 .ctl_name = NET_TCP_ECN,
563 .procname = "tcp_ecn",
564 .data = &sysctl_tcp_ecn,
565 .maxlen = sizeof(int),
567 .proc_handler = &proc_dointvec
570 .ctl_name = NET_TCP_DSACK,
571 .procname = "tcp_dsack",
572 .data = &sysctl_tcp_dsack,
573 .maxlen = sizeof(int),
575 .proc_handler = &proc_dointvec
578 .ctl_name = NET_TCP_MEM,
579 .procname = "tcp_mem",
580 .data = &sysctl_tcp_mem,
581 .maxlen = sizeof(sysctl_tcp_mem),
583 .proc_handler = &proc_dointvec
586 .ctl_name = NET_TCP_WMEM,
587 .procname = "tcp_wmem",
588 .data = &sysctl_tcp_wmem,
589 .maxlen = sizeof(sysctl_tcp_wmem),
591 .proc_handler = &proc_dointvec
594 .ctl_name = NET_TCP_RMEM,
595 .procname = "tcp_rmem",
596 .data = &sysctl_tcp_rmem,
597 .maxlen = sizeof(sysctl_tcp_rmem),
599 .proc_handler = &proc_dointvec
602 .ctl_name = NET_TCP_APP_WIN,
603 .procname = "tcp_app_win",
604 .data = &sysctl_tcp_app_win,
605 .maxlen = sizeof(int),
607 .proc_handler = &proc_dointvec
610 .ctl_name = NET_TCP_ADV_WIN_SCALE,
611 .procname = "tcp_adv_win_scale",
612 .data = &sysctl_tcp_adv_win_scale,
613 .maxlen = sizeof(int),
615 .proc_handler = &proc_dointvec
618 .ctl_name = NET_IPV4_ICMP_RATELIMIT,
619 .procname = "icmp_ratelimit",
620 .data = &sysctl_icmp_ratelimit,
621 .maxlen = sizeof(int),
623 .proc_handler = &proc_dointvec
626 .ctl_name = NET_IPV4_ICMP_RATEMASK,
627 .procname = "icmp_ratemask",
628 .data = &sysctl_icmp_ratemask,
629 .maxlen = sizeof(int),
631 .proc_handler = &proc_dointvec
634 .ctl_name = NET_TCP_TW_REUSE,
635 .procname = "tcp_tw_reuse",
636 .data = &sysctl_tcp_tw_reuse,
637 .maxlen = sizeof(int),
639 .proc_handler = &proc_dointvec
642 .ctl_name = NET_TCP_FRTO,
643 .procname = "tcp_frto",
644 .data = &sysctl_tcp_frto,
645 .maxlen = sizeof(int),
647 .proc_handler = &proc_dointvec
650 .ctl_name = NET_TCP_LOW_LATENCY,
651 .procname = "tcp_low_latency",
652 .data = &sysctl_tcp_low_latency,
653 .maxlen = sizeof(int),
655 .proc_handler = &proc_dointvec
658 .ctl_name = NET_IPV4_IPFRAG_SECRET_INTERVAL,
659 .procname = "ipfrag_secret_interval",
660 .data = &sysctl_ipfrag_secret_interval,
661 .maxlen = sizeof(int),
663 .proc_handler = &proc_dointvec_jiffies,
664 .strategy = &sysctl_jiffies
667 .ctl_name = NET_IPV4_IPFRAG_MAX_DIST,
668 .procname = "ipfrag_max_dist",
669 .data = &sysctl_ipfrag_max_dist,
670 .maxlen = sizeof(int),
672 .proc_handler = &proc_dointvec_minmax,
676 .ctl_name = NET_TCP_NO_METRICS_SAVE,
677 .procname = "tcp_no_metrics_save",
678 .data = &sysctl_tcp_nometrics_save,
679 .maxlen = sizeof(int),
681 .proc_handler = &proc_dointvec,
684 .ctl_name = NET_TCP_MODERATE_RCVBUF,
685 .procname = "tcp_moderate_rcvbuf",
686 .data = &sysctl_tcp_moderate_rcvbuf,
687 .maxlen = sizeof(int),
689 .proc_handler = &proc_dointvec,
692 .ctl_name = NET_TCP_TSO_WIN_DIVISOR,
693 .procname = "tcp_tso_win_divisor",
694 .data = &sysctl_tcp_tso_win_divisor,
695 .maxlen = sizeof(int),
697 .proc_handler = &proc_dointvec,
700 .ctl_name = NET_TCP_CONG_CONTROL,
701 .procname = "tcp_congestion_control",
703 .maxlen = TCP_CA_NAME_MAX,
704 .proc_handler = &proc_tcp_congestion_control,
705 .strategy = &sysctl_tcp_congestion_control,
708 .ctl_name = NET_TCP_ABC,
709 .procname = "tcp_abc",
710 .data = &sysctl_tcp_abc,
711 .maxlen = sizeof(int),
713 .proc_handler = &proc_dointvec,
716 .ctl_name = NET_TCP_MTU_PROBING,
717 .procname = "tcp_mtu_probing",
718 .data = &sysctl_tcp_mtu_probing,
719 .maxlen = sizeof(int),
721 .proc_handler = &proc_dointvec,
724 .ctl_name = NET_TCP_BASE_MSS,
725 .procname = "tcp_base_mss",
726 .data = &sysctl_tcp_base_mss,
727 .maxlen = sizeof(int),
729 .proc_handler = &proc_dointvec,
732 .ctl_name = NET_IPV4_TCP_WORKAROUND_SIGNED_WINDOWS,
733 .procname = "tcp_workaround_signed_windows",
734 .data = &sysctl_tcp_workaround_signed_windows,
735 .maxlen = sizeof(int),
737 .proc_handler = &proc_dointvec
739 #ifdef CONFIG_NET_DMA
741 .ctl_name = NET_TCP_DMA_COPYBREAK,
742 .procname = "tcp_dma_copybreak",
743 .data = &sysctl_tcp_dma_copybreak,
744 .maxlen = sizeof(int),
746 .proc_handler = &proc_dointvec
750 .ctl_name = NET_TCP_SLOW_START_AFTER_IDLE,
751 .procname = "tcp_slow_start_after_idle",
752 .data = &sysctl_tcp_slow_start_after_idle,
753 .maxlen = sizeof(int),
755 .proc_handler = &proc_dointvec
757 #ifdef CONFIG_NETLABEL
759 .ctl_name = NET_CIPSOV4_CACHE_ENABLE,
760 .procname = "cipso_cache_enable",
761 .data = &cipso_v4_cache_enabled,
762 .maxlen = sizeof(int),
764 .proc_handler = &proc_dointvec,
767 .ctl_name = NET_CIPSOV4_CACHE_BUCKET_SIZE,
768 .procname = "cipso_cache_bucket_size",
769 .data = &cipso_v4_cache_bucketsize,
770 .maxlen = sizeof(int),
772 .proc_handler = &proc_dointvec,
775 .ctl_name = NET_CIPSOV4_RBM_OPTFMT,
776 .procname = "cipso_rbm_optfmt",
777 .data = &cipso_v4_rbm_optfmt,
778 .maxlen = sizeof(int),
780 .proc_handler = &proc_dointvec,
783 .ctl_name = NET_CIPSOV4_RBM_STRICTVALID,
784 .procname = "cipso_rbm_strictvalid",
785 .data = &cipso_v4_rbm_strictvalid,
786 .maxlen = sizeof(int),
788 .proc_handler = &proc_dointvec,
790 #endif /* CONFIG_NETLABEL */
792 .ctl_name = NET_TCP_AVAIL_CONG_CONTROL,
793 .procname = "tcp_available_congestion_control",
794 .maxlen = TCP_CA_BUF_MAX,
796 .proc_handler = &proc_tcp_available_congestion_control,
799 .ctl_name = NET_TCP_ALLOWED_CONG_CONTROL,
800 .procname = "tcp_allowed_congestion_control",
801 .maxlen = TCP_CA_BUF_MAX,
803 .proc_handler = &proc_allowed_congestion_control,
804 .strategy = &strategy_allowed_congestion_control,
809 #endif /* CONFIG_SYSCTL */
811 EXPORT_SYMBOL(ipv4_config);