File: /usr/src/linux/net/ipv4/sysctl_net_ipv4.c

1     /*
2      * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
3      *
4      * $Id: sysctl_net_ipv4.c,v 1.49 2001/08/22 20:38:41 davem Exp $
5      *
6      * Begun April 1, 1996, Mike Shaver.
7      * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
8      */
9     
10     #include <linux/mm.h>
11     #include <linux/sysctl.h>
12     #include <linux/config.h>
13     #include <net/snmp.h>
14     #include <net/ip.h>
15     #include <net/route.h>
16     #include <net/tcp.h>
17     
18     /* From af_inet.c */
19     extern int sysctl_ip_nonlocal_bind;
20     
21     /* From icmp.c */
22     extern int sysctl_icmp_echo_ignore_all;
23     extern int sysctl_icmp_echo_ignore_broadcasts;
24     extern int sysctl_icmp_ignore_bogus_error_responses;
25     
26     /* From ip_fragment.c */
27     extern int sysctl_ipfrag_low_thresh;
28     extern int sysctl_ipfrag_high_thresh; 
29     extern int sysctl_ipfrag_time;
30     
31     /* From ip_output.c */
32     extern int sysctl_ip_dynaddr;
33     
34     /* From icmp.c */
35     extern int sysctl_icmp_ratelimit;
36     extern int sysctl_icmp_ratemask;
37     
38     /* From igmp.c */
39     extern int sysctl_igmp_max_memberships;
40     
41     /* From inetpeer.c */
42     extern int inet_peer_threshold;
43     extern int inet_peer_minttl;
44     extern int inet_peer_maxttl;
45     extern int inet_peer_gc_mintime;
46     extern int inet_peer_gc_maxtime;
47     
48     #ifdef CONFIG_SYSCTL
49     static int tcp_retr1_max = 255; 
50     static int ip_local_port_range_min[] = { 1, 1 };
51     static int ip_local_port_range_max[] = { 65535, 65535 };
52     #endif
53     
54     struct ipv4_config ipv4_config;
55     
56     extern ctl_table ipv4_route_table[];
57     
58     #ifdef CONFIG_SYSCTL
59     
60     static
61     int ipv4_sysctl_forward(ctl_table *ctl, int write, struct file * filp,
62     			void *buffer, size_t *lenp)
63     {
64     	int val = ipv4_devconf.forwarding;
65     	int ret;
66     
67     	ret = proc_dointvec(ctl, write, filp, buffer, lenp);
68     
69     	if (write && ipv4_devconf.forwarding != val)
70     		inet_forward_change();
71     
72     	return ret;
73     }
74     
75     static int ipv4_sysctl_forward_strategy(ctl_table *table, int *name, int nlen,
76     			 void *oldval, size_t *oldlenp,
77     			 void *newval, size_t newlen, 
78     			 void **context)
79     {
80     	int new;
81     	if (newlen != sizeof(int))
82     		return -EINVAL;
83     	if (get_user(new,(int *)newval))
84     		return -EFAULT; 
85     	if (new != ipv4_devconf.forwarding) 
86     		inet_forward_change(); 
87     	return 0; /* caller does change again and handles handles oldval */ 
88     }
89     
90     ctl_table ipv4_table[] = {
91             {NET_IPV4_TCP_TIMESTAMPS, "tcp_timestamps",
92              &sysctl_tcp_timestamps, sizeof(int), 0644, NULL,
93              &proc_dointvec},
94             {NET_IPV4_TCP_WINDOW_SCALING, "tcp_window_scaling",
95              &sysctl_tcp_window_scaling, sizeof(int), 0644, NULL,
96              &proc_dointvec},
97             {NET_IPV4_TCP_SACK, "tcp_sack",
98              &sysctl_tcp_sack, sizeof(int), 0644, NULL,
99              &proc_dointvec},
100             {NET_IPV4_TCP_RETRANS_COLLAPSE, "tcp_retrans_collapse",
101              &sysctl_tcp_retrans_collapse, sizeof(int), 0644, NULL,
102              &proc_dointvec},
103             {NET_IPV4_FORWARD, "ip_forward",
104              &ipv4_devconf.forwarding, sizeof(int), 0644, NULL,
105              &ipv4_sysctl_forward,&ipv4_sysctl_forward_strategy},
106             {NET_IPV4_DEFAULT_TTL, "ip_default_ttl",
107              &sysctl_ip_default_ttl, sizeof(int), 0644, NULL,
108              &proc_dointvec},
109             {NET_IPV4_AUTOCONFIG, "ip_autoconfig",
110              &ipv4_config.autoconfig, sizeof(int), 0644, NULL,
111              &proc_dointvec},
112             {NET_IPV4_NO_PMTU_DISC, "ip_no_pmtu_disc",
113              &ipv4_config.no_pmtu_disc, sizeof(int), 0644, NULL,
114              &proc_dointvec},
115     	{NET_IPV4_NONLOCAL_BIND, "ip_nonlocal_bind",
116     	 &sysctl_ip_nonlocal_bind, sizeof(int), 0644, NULL,
117     	 &proc_dointvec},
118     	{NET_IPV4_TCP_SYN_RETRIES, "tcp_syn_retries",
119     	 &sysctl_tcp_syn_retries, sizeof(int), 0644, NULL, &proc_dointvec},
120     	{NET_TCP_SYNACK_RETRIES, "tcp_synack_retries",
121     	 &sysctl_tcp_synack_retries, sizeof(int), 0644, NULL, &proc_dointvec},
122     	{NET_TCP_MAX_ORPHANS, "tcp_max_orphans",
123     	 &sysctl_tcp_max_orphans, sizeof(int), 0644, NULL, &proc_dointvec},
124     	{NET_TCP_MAX_TW_BUCKETS, "tcp_max_tw_buckets",
125     	 &sysctl_tcp_max_tw_buckets, sizeof(int), 0644, NULL, &proc_dointvec},
126     	{NET_IPV4_IPFRAG_HIGH_THRESH, "ipfrag_high_thresh",
127     	 &sysctl_ipfrag_high_thresh, sizeof(int), 0644, NULL, &proc_dointvec},
128     	{NET_IPV4_IPFRAG_LOW_THRESH, "ipfrag_low_thresh",
129     	 &sysctl_ipfrag_low_thresh, sizeof(int), 0644, NULL, &proc_dointvec},
130     	{NET_IPV4_DYNADDR, "ip_dynaddr",
131     	 &sysctl_ip_dynaddr, sizeof(int), 0644, NULL, &proc_dointvec},
132     	{NET_IPV4_IPFRAG_TIME, "ipfrag_time",
133     	 &sysctl_ipfrag_time, sizeof(int), 0644, NULL, &proc_dointvec_jiffies, 
134     	 &sysctl_jiffies},
135     	{NET_IPV4_TCP_KEEPALIVE_TIME, "tcp_keepalive_time",
136     	 &sysctl_tcp_keepalive_time, sizeof(int), 0644, NULL, 
137     	 &proc_dointvec_jiffies, &sysctl_jiffies},
138     	{NET_IPV4_TCP_KEEPALIVE_PROBES, "tcp_keepalive_probes",
139     	 &sysctl_tcp_keepalive_probes, sizeof(int), 0644, NULL, 
140     	 &proc_dointvec},
141     	{NET_IPV4_TCP_KEEPALIVE_INTVL, "tcp_keepalive_intvl",
142     	 &sysctl_tcp_keepalive_intvl, sizeof(int), 0644, NULL,
143     	 &proc_dointvec_jiffies, &sysctl_jiffies},
144     	{NET_IPV4_TCP_RETRIES1, "tcp_retries1",
145     	 &sysctl_tcp_retries1, sizeof(int), 0644, NULL, &proc_dointvec_minmax, 
146     	 &sysctl_intvec, NULL, NULL, &tcp_retr1_max},
147     	{NET_IPV4_TCP_RETRIES2, "tcp_retries2",
148     	 &sysctl_tcp_retries2, sizeof(int), 0644, NULL, &proc_dointvec},
149     	{NET_IPV4_TCP_FIN_TIMEOUT, "tcp_fin_timeout",
150     	 &sysctl_tcp_fin_timeout, sizeof(int), 0644, NULL, 
151     	 &proc_dointvec_jiffies, &sysctl_jiffies},
152     #ifdef CONFIG_SYN_COOKIES
153     	{NET_TCP_SYNCOOKIES, "tcp_syncookies",
154     	 &sysctl_tcp_syncookies, sizeof(int), 0644, NULL, &proc_dointvec},
155     #endif
156     	{NET_TCP_TW_RECYCLE, "tcp_tw_recycle",
157     	 &sysctl_tcp_tw_recycle, sizeof(int), 0644, NULL, &proc_dointvec},
158     	{NET_TCP_ABORT_ON_OVERFLOW, "tcp_abort_on_overflow",
159     	 &sysctl_tcp_abort_on_overflow, sizeof(int), 0644, NULL, &proc_dointvec},
160     	{NET_TCP_STDURG, "tcp_stdurg", &sysctl_tcp_stdurg,
161     	 sizeof(int), 0644, NULL, &proc_dointvec},
162     	{NET_TCP_RFC1337, "tcp_rfc1337", &sysctl_tcp_rfc1337,
163     	 sizeof(int), 0644, NULL, &proc_dointvec},
164     	{NET_TCP_MAX_SYN_BACKLOG, "tcp_max_syn_backlog", &sysctl_max_syn_backlog,
165     	 sizeof(int), 0644, NULL, &proc_dointvec},
166     	{NET_IPV4_LOCAL_PORT_RANGE, "ip_local_port_range",
167     	 &sysctl_local_port_range, sizeof(sysctl_local_port_range), 0644, 
168     	 NULL, &proc_dointvec_minmax, &sysctl_intvec, NULL,
169     	 ip_local_port_range_min, ip_local_port_range_max },
170     	{NET_IPV4_ICMP_ECHO_IGNORE_ALL, "icmp_echo_ignore_all",
171     	 &sysctl_icmp_echo_ignore_all, sizeof(int), 0644, NULL,
172     	 &proc_dointvec},
173     	{NET_IPV4_ICMP_ECHO_IGNORE_BROADCASTS, "icmp_echo_ignore_broadcasts",
174     	 &sysctl_icmp_echo_ignore_broadcasts, sizeof(int), 0644, NULL,
175     	 &proc_dointvec},
176     	{NET_IPV4_ICMP_IGNORE_BOGUS_ERROR_RESPONSES, "icmp_ignore_bogus_error_responses",
177     	 &sysctl_icmp_ignore_bogus_error_responses, sizeof(int), 0644, NULL,
178     	 &proc_dointvec},
179     	{NET_IPV4_ROUTE, "route", NULL, 0, 0555, ipv4_route_table},
180     #ifdef CONFIG_IP_MULTICAST
181     	{NET_IPV4_IGMP_MAX_MEMBERSHIPS, "igmp_max_memberships",
182     	 &sysctl_igmp_max_memberships, sizeof(int), 0644, NULL, &proc_dointvec},
183     #endif
184     	{NET_IPV4_INET_PEER_THRESHOLD, "inet_peer_threshold",
185     	 &inet_peer_threshold, sizeof(int), 0644, NULL, &proc_dointvec},
186     	{NET_IPV4_INET_PEER_MINTTL, "inet_peer_minttl",
187     	 &inet_peer_minttl, sizeof(int), 0644, NULL,
188     	 &proc_dointvec_jiffies, &sysctl_jiffies},
189     	{NET_IPV4_INET_PEER_MAXTTL, "inet_peer_maxttl",
190     	 &inet_peer_maxttl, sizeof(int), 0644, NULL,
191     	 &proc_dointvec_jiffies, &sysctl_jiffies},
192     	{NET_IPV4_INET_PEER_GC_MINTIME, "inet_peer_gc_mintime",
193     	 &inet_peer_gc_mintime, sizeof(int), 0644, NULL,
194     	 &proc_dointvec_jiffies, &sysctl_jiffies},
195     	{NET_IPV4_INET_PEER_GC_MAXTIME, "inet_peer_gc_maxtime",
196     	 &inet_peer_gc_maxtime, sizeof(int), 0644, NULL,
197     	 &proc_dointvec_jiffies, &sysctl_jiffies},
198     	{NET_TCP_ORPHAN_RETRIES, "tcp_orphan_retries",
199     	 &sysctl_tcp_orphan_retries, sizeof(int), 0644, NULL, &proc_dointvec},
200     	{NET_TCP_FACK, "tcp_fack",
201     	 &sysctl_tcp_fack, sizeof(int), 0644, NULL, &proc_dointvec},
202     	{NET_TCP_REORDERING, "tcp_reordering",
203     	 &sysctl_tcp_reordering, sizeof(int), 0644, NULL, &proc_dointvec},
204     #ifdef CONFIG_INET_ECN
205     	{NET_TCP_ECN, "tcp_ecn",
206     	 &sysctl_tcp_ecn, sizeof(int), 0644, NULL, &proc_dointvec},
207     #endif
208     	{NET_TCP_DSACK, "tcp_dsack",
209     	 &sysctl_tcp_dsack, sizeof(int), 0644, NULL, &proc_dointvec},
210     	{NET_TCP_MEM, "tcp_mem",
211     	 &sysctl_tcp_mem, sizeof(sysctl_tcp_mem), 0644, NULL, &proc_dointvec},
212     	{NET_TCP_WMEM, "tcp_wmem",
213     	 &sysctl_tcp_wmem, sizeof(sysctl_tcp_wmem), 0644, NULL, &proc_dointvec},
214     	{NET_TCP_RMEM, "tcp_rmem",
215     	 &sysctl_tcp_rmem, sizeof(sysctl_tcp_rmem), 0644, NULL, &proc_dointvec},
216     	{NET_TCP_APP_WIN, "tcp_app_win",
217     	 &sysctl_tcp_app_win, sizeof(int), 0644, NULL, &proc_dointvec},
218     	{NET_TCP_ADV_WIN_SCALE, "tcp_adv_win_scale",
219     	 &sysctl_tcp_adv_win_scale, sizeof(int), 0644, NULL, &proc_dointvec},
220     	{NET_IPV4_ICMP_RATELIMIT, "icmp_ratelimit",
221     	 &sysctl_icmp_ratelimit, sizeof(int), 0644, NULL, &proc_dointvec},
222     	{NET_IPV4_ICMP_RATEMASK, "icmp_ratemask",
223     	 &sysctl_icmp_ratemask, sizeof(int), 0644, NULL, &proc_dointvec},
224     	{0}
225     };
226     
227     #endif /* CONFIG_SYSCTL */
228