blob: 7e3712ce399476be6cfdbc631654a5863fb68bc4 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <net/snmp.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030016#include <net/icmp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <net/ip.h>
18#include <net/route.h>
19#include <net/tcp.h>
Hideo Aoki95766ff2007-12-31 00:29:24 -080020#include <net/udp.h>
Paul Moore446fda42006-08-03 16:48:06 -070021#include <net/cipso_ipv4.h>
Pavel Emelyanov04128f22007-10-15 02:33:45 -070022#include <net/inet_frag.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Herbert Xu89cee8b2005-12-13 23:14:27 -080024static int zero;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090025static int tcp_retr1_max = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026static int ip_local_port_range_min[] = { 1, 1 };
27static int ip_local_port_range_max[] = { 65535, 65535 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Stephen Hemminger227b60f2007-10-10 17:30:46 -070029/* Update system visible IP port range */
30static void set_local_port_range(int range[2])
31{
Eric Dumazet3c689b72008-10-08 14:18:04 -070032 write_seqlock(&sysctl_local_ports.lock);
33 sysctl_local_ports.range[0] = range[0];
34 sysctl_local_ports.range[1] = range[1];
35 write_sequnlock(&sysctl_local_ports.lock);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070036}
37
38/* Validate changes from /proc interface. */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070039static int ipv4_local_port_range(ctl_table *table, int write,
Stephen Hemminger227b60f2007-10-10 17:30:46 -070040 void __user *buffer,
41 size_t *lenp, loff_t *ppos)
42{
43 int ret;
Eric Dumazet3c689b72008-10-08 14:18:04 -070044 int range[2];
Stephen Hemminger227b60f2007-10-10 17:30:46 -070045 ctl_table tmp = {
46 .data = &range,
47 .maxlen = sizeof(range),
48 .mode = table->mode,
49 .extra1 = &ip_local_port_range_min,
50 .extra2 = &ip_local_port_range_max,
51 };
52
Eric Dumazet3c689b72008-10-08 14:18:04 -070053 inet_get_local_port_range(range, range + 1);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070054 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070055
56 if (write && ret == 0) {
Anton Arapova25de532007-10-18 22:00:17 -070057 if (range[1] < range[0])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070058 ret = -EINVAL;
59 else
60 set_local_port_range(range);
61 }
62
63 return ret;
64}
65
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070066static int proc_tcp_congestion_control(ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -070067 void __user *buffer, size_t *lenp, loff_t *ppos)
68{
69 char val[TCP_CA_NAME_MAX];
70 ctl_table tbl = {
71 .data = val,
72 .maxlen = TCP_CA_NAME_MAX,
73 };
74 int ret;
75
76 tcp_get_default_congestion_control(val);
77
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070078 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -070079 if (write && ret == 0)
80 ret = tcp_set_default_congestion_control(val);
81 return ret;
82}
83
Stephen Hemminger3ff825b2006-11-09 16:32:06 -080084static int proc_tcp_available_congestion_control(ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070085 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -080086 void __user *buffer, size_t *lenp,
87 loff_t *ppos)
88{
89 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
90 int ret;
91
92 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
93 if (!tbl.data)
94 return -ENOMEM;
95 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070096 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -080097 kfree(tbl.data);
98 return ret;
99}
100
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800101static int proc_allowed_congestion_control(ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700102 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800103 void __user *buffer, size_t *lenp,
104 loff_t *ppos)
105{
106 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
107 int ret;
108
109 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
110 if (!tbl.data)
111 return -ENOMEM;
112
113 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700114 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800115 if (write && ret == 0)
116 ret = tcp_set_allowed_congestion_control(tbl.data);
117 kfree(tbl.data);
118 return ret;
119}
120
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800121static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900122 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 .procname = "tcp_timestamps",
124 .data = &sysctl_tcp_timestamps,
125 .maxlen = sizeof(int),
126 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800127 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900129 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .procname = "tcp_window_scaling",
131 .data = &sysctl_tcp_window_scaling,
132 .maxlen = sizeof(int),
133 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800134 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900136 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 .procname = "tcp_sack",
138 .data = &sysctl_tcp_sack,
139 .maxlen = sizeof(int),
140 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800141 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900143 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 .procname = "tcp_retrans_collapse",
145 .data = &sysctl_tcp_retrans_collapse,
146 .maxlen = sizeof(int),
147 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800148 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900150 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 .procname = "ip_default_ttl",
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900152 .data = &sysctl_ip_default_ttl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 .maxlen = sizeof(int),
154 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800155 .proc_handler = ipv4_doint_and_flush,
Sven Wegeneradf044c2008-08-03 14:06:44 -0700156 .extra2 = &init_net,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900158 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 .procname = "ip_no_pmtu_disc",
160 .data = &ipv4_config.no_pmtu_disc,
161 .maxlen = sizeof(int),
162 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800163 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 },
165 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 .procname = "ip_nonlocal_bind",
167 .data = &sysctl_ip_nonlocal_bind,
168 .maxlen = sizeof(int),
169 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800170 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 },
172 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 .procname = "tcp_syn_retries",
174 .data = &sysctl_tcp_syn_retries,
175 .maxlen = sizeof(int),
176 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800177 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 },
179 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 .procname = "tcp_synack_retries",
181 .data = &sysctl_tcp_synack_retries,
182 .maxlen = sizeof(int),
183 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800184 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 },
186 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 .procname = "tcp_max_orphans",
188 .data = &sysctl_tcp_max_orphans,
189 .maxlen = sizeof(int),
190 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800191 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 },
193 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 .procname = "tcp_max_tw_buckets",
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -0700195 .data = &tcp_death_row.sysctl_max_tw_buckets,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 .maxlen = sizeof(int),
197 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800198 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 },
200 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 .procname = "ip_dynaddr",
202 .data = &sysctl_ip_dynaddr,
203 .maxlen = sizeof(int),
204 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800205 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 },
207 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 .procname = "tcp_keepalive_time",
209 .data = &sysctl_tcp_keepalive_time,
210 .maxlen = sizeof(int),
211 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800212 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 },
214 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 .procname = "tcp_keepalive_probes",
216 .data = &sysctl_tcp_keepalive_probes,
217 .maxlen = sizeof(int),
218 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800219 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 },
221 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 .procname = "tcp_keepalive_intvl",
223 .data = &sysctl_tcp_keepalive_intvl,
224 .maxlen = sizeof(int),
225 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800226 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 },
228 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 .procname = "tcp_retries1",
230 .data = &sysctl_tcp_retries1,
231 .maxlen = sizeof(int),
232 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800233 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 .extra2 = &tcp_retr1_max
235 },
236 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 .procname = "tcp_retries2",
238 .data = &sysctl_tcp_retries2,
239 .maxlen = sizeof(int),
240 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800241 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 },
243 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 .procname = "tcp_fin_timeout",
245 .data = &sysctl_tcp_fin_timeout,
246 .maxlen = sizeof(int),
247 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800248 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 },
250#ifdef CONFIG_SYN_COOKIES
251 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 .procname = "tcp_syncookies",
253 .data = &sysctl_tcp_syncookies,
254 .maxlen = sizeof(int),
255 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800256 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 },
258#endif
259 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 .procname = "tcp_tw_recycle",
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -0700261 .data = &tcp_death_row.sysctl_tw_recycle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 .maxlen = sizeof(int),
263 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800264 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 },
266 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 .procname = "tcp_abort_on_overflow",
268 .data = &sysctl_tcp_abort_on_overflow,
269 .maxlen = sizeof(int),
270 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800271 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 },
273 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 .procname = "tcp_stdurg",
275 .data = &sysctl_tcp_stdurg,
276 .maxlen = sizeof(int),
277 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800278 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 },
280 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 .procname = "tcp_rfc1337",
282 .data = &sysctl_tcp_rfc1337,
283 .maxlen = sizeof(int),
284 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800285 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 },
287 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 .procname = "tcp_max_syn_backlog",
289 .data = &sysctl_max_syn_backlog,
290 .maxlen = sizeof(int),
291 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800292 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 },
294 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 .procname = "ip_local_port_range",
Eric Dumazet3c689b72008-10-08 14:18:04 -0700296 .data = &sysctl_local_ports.range,
297 .maxlen = sizeof(sysctl_local_ports.range),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800299 .proc_handler = ipv4_local_port_range,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301#ifdef CONFIG_IP_MULTICAST
302 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 .procname = "igmp_max_memberships",
304 .data = &sysctl_igmp_max_memberships,
305 .maxlen = sizeof(int),
306 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800307 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 },
309
310#endif
311 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 .procname = "igmp_max_msf",
313 .data = &sysctl_igmp_max_msf,
314 .maxlen = sizeof(int),
315 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800316 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 },
318 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 .procname = "inet_peer_threshold",
320 .data = &inet_peer_threshold,
321 .maxlen = sizeof(int),
322 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800323 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 },
325 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 .procname = "inet_peer_minttl",
327 .data = &inet_peer_minttl,
328 .maxlen = sizeof(int),
329 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800330 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 },
332 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 .procname = "inet_peer_maxttl",
334 .data = &inet_peer_maxttl,
335 .maxlen = sizeof(int),
336 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800337 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 },
339 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 .procname = "inet_peer_gc_mintime",
341 .data = &inet_peer_gc_mintime,
342 .maxlen = sizeof(int),
343 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800344 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 },
346 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 .procname = "inet_peer_gc_maxtime",
348 .data = &inet_peer_gc_maxtime,
349 .maxlen = sizeof(int),
350 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800351 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 },
353 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 .procname = "tcp_orphan_retries",
355 .data = &sysctl_tcp_orphan_retries,
356 .maxlen = sizeof(int),
357 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800358 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 },
360 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 .procname = "tcp_fack",
362 .data = &sysctl_tcp_fack,
363 .maxlen = sizeof(int),
364 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800365 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 },
367 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 .procname = "tcp_reordering",
369 .data = &sysctl_tcp_reordering,
370 .maxlen = sizeof(int),
371 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800372 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 },
374 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 .procname = "tcp_ecn",
376 .data = &sysctl_tcp_ecn,
377 .maxlen = sizeof(int),
378 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800379 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 },
381 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 .procname = "tcp_dsack",
383 .data = &sysctl_tcp_dsack,
384 .maxlen = sizeof(int),
385 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800386 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 },
388 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 .procname = "tcp_mem",
390 .data = &sysctl_tcp_mem,
391 .maxlen = sizeof(sysctl_tcp_mem),
392 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800393 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 },
395 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 .procname = "tcp_wmem",
397 .data = &sysctl_tcp_wmem,
398 .maxlen = sizeof(sysctl_tcp_wmem),
399 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800400 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 },
402 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 .procname = "tcp_rmem",
404 .data = &sysctl_tcp_rmem,
405 .maxlen = sizeof(sysctl_tcp_rmem),
406 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800407 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 },
409 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 .procname = "tcp_app_win",
411 .data = &sysctl_tcp_app_win,
412 .maxlen = sizeof(int),
413 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800414 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 },
416 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 .procname = "tcp_adv_win_scale",
418 .data = &sysctl_tcp_adv_win_scale,
419 .maxlen = sizeof(int),
420 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800421 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 },
423 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 .procname = "tcp_tw_reuse",
425 .data = &sysctl_tcp_tw_reuse,
426 .maxlen = sizeof(int),
427 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800428 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 },
430 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 .procname = "tcp_frto",
432 .data = &sysctl_tcp_frto,
433 .maxlen = sizeof(int),
434 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800435 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 },
437 {
Ilpo Järvinen3cfe3ba2007-02-27 10:09:49 -0800438 .procname = "tcp_frto_response",
439 .data = &sysctl_tcp_frto_response,
440 .maxlen = sizeof(int),
441 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800442 .proc_handler = proc_dointvec
Ilpo Järvinen3cfe3ba2007-02-27 10:09:49 -0800443 },
444 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 .procname = "tcp_low_latency",
446 .data = &sysctl_tcp_low_latency,
447 .maxlen = sizeof(int),
448 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800449 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 },
451 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 .procname = "tcp_no_metrics_save",
453 .data = &sysctl_tcp_nometrics_save,
454 .maxlen = sizeof(int),
455 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800456 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 },
458 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 .procname = "tcp_moderate_rcvbuf",
460 .data = &sysctl_tcp_moderate_rcvbuf,
461 .maxlen = sizeof(int),
462 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800463 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 },
465 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 .procname = "tcp_tso_win_divisor",
467 .data = &sysctl_tcp_tso_win_divisor,
468 .maxlen = sizeof(int),
469 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800470 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 },
472 {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700473 .procname = "tcp_congestion_control",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 .mode = 0644,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700475 .maxlen = TCP_CA_NAME_MAX,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800476 .proc_handler = proc_tcp_congestion_control,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 },
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800478 {
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800479 .procname = "tcp_abc",
480 .data = &sysctl_tcp_abc,
481 .maxlen = sizeof(int),
482 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800483 .proc_handler = proc_dointvec,
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800484 },
John Heffner5d424d52006-03-20 17:53:41 -0800485 {
John Heffner5d424d52006-03-20 17:53:41 -0800486 .procname = "tcp_mtu_probing",
487 .data = &sysctl_tcp_mtu_probing,
488 .maxlen = sizeof(int),
489 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800490 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800491 },
492 {
John Heffner5d424d52006-03-20 17:53:41 -0800493 .procname = "tcp_base_mss",
494 .data = &sysctl_tcp_base_mss,
495 .maxlen = sizeof(int),
496 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800497 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800498 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900499 {
Rick Jones15d99e02006-03-20 22:40:29 -0800500 .procname = "tcp_workaround_signed_windows",
501 .data = &sysctl_tcp_workaround_signed_windows,
502 .maxlen = sizeof(int),
503 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800504 .proc_handler = proc_dointvec
Rick Jones15d99e02006-03-20 22:40:29 -0800505 },
Chris Leech95937822006-05-23 18:02:55 -0700506#ifdef CONFIG_NET_DMA
507 {
Chris Leech95937822006-05-23 18:02:55 -0700508 .procname = "tcp_dma_copybreak",
509 .data = &sysctl_tcp_dma_copybreak,
510 .maxlen = sizeof(int),
511 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800512 .proc_handler = proc_dointvec
Chris Leech95937822006-05-23 18:02:55 -0700513 },
514#endif
David S. Miller35089bb2006-06-13 22:33:04 -0700515 {
David S. Miller35089bb2006-06-13 22:33:04 -0700516 .procname = "tcp_slow_start_after_idle",
517 .data = &sysctl_tcp_slow_start_after_idle,
518 .maxlen = sizeof(int),
519 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800520 .proc_handler = proc_dointvec
David S. Miller35089bb2006-06-13 22:33:04 -0700521 },
Paul Moore446fda42006-08-03 16:48:06 -0700522#ifdef CONFIG_NETLABEL
523 {
Paul Moore446fda42006-08-03 16:48:06 -0700524 .procname = "cipso_cache_enable",
525 .data = &cipso_v4_cache_enabled,
526 .maxlen = sizeof(int),
527 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800528 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700529 },
530 {
Paul Moore446fda42006-08-03 16:48:06 -0700531 .procname = "cipso_cache_bucket_size",
532 .data = &cipso_v4_cache_bucketsize,
533 .maxlen = sizeof(int),
534 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800535 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700536 },
537 {
Paul Moore446fda42006-08-03 16:48:06 -0700538 .procname = "cipso_rbm_optfmt",
539 .data = &cipso_v4_rbm_optfmt,
540 .maxlen = sizeof(int),
541 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800542 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700543 },
544 {
Paul Moore446fda42006-08-03 16:48:06 -0700545 .procname = "cipso_rbm_strictvalid",
546 .data = &cipso_v4_rbm_strictvalid,
547 .maxlen = sizeof(int),
548 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800549 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700550 },
551#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800552 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800553 .procname = "tcp_available_congestion_control",
554 .maxlen = TCP_CA_BUF_MAX,
555 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800556 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800557 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800558 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800559 .procname = "tcp_allowed_congestion_control",
560 .maxlen = TCP_CA_BUF_MAX,
561 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800562 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800563 },
John Heffner886236c2007-03-25 19:21:45 -0700564 {
John Heffner886236c2007-03-25 19:21:45 -0700565 .procname = "tcp_max_ssthresh",
566 .data = &sysctl_tcp_max_ssthresh,
567 .maxlen = sizeof(int),
568 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800569 .proc_handler = proc_dointvec,
John Heffner886236c2007-03-25 19:21:45 -0700570 },
Hideo Aoki95766ff2007-12-31 00:29:24 -0800571 {
William Allen Simpson519855c2009-12-02 18:14:19 +0000572 .procname = "tcp_cookie_size",
573 .data = &sysctl_tcp_cookie_size,
574 .maxlen = sizeof(int),
575 .mode = 0644,
576 .proc_handler = proc_dointvec
577 },
578 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800579 .procname = "udp_mem",
580 .data = &sysctl_udp_mem,
581 .maxlen = sizeof(sysctl_udp_mem),
582 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800583 .proc_handler = proc_dointvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800584 .extra1 = &zero
585 },
586 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800587 .procname = "udp_rmem_min",
588 .data = &sysctl_udp_rmem_min,
589 .maxlen = sizeof(sysctl_udp_rmem_min),
590 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800591 .proc_handler = proc_dointvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800592 .extra1 = &zero
593 },
594 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800595 .procname = "udp_wmem_min",
596 .data = &sysctl_udp_wmem_min,
597 .maxlen = sizeof(sysctl_udp_wmem_min),
598 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800599 .proc_handler = proc_dointvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800600 .extra1 = &zero
601 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800602 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800604
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700605static struct ctl_table ipv4_net_table[] = {
606 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700607 .procname = "icmp_echo_ignore_all",
608 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
609 .maxlen = sizeof(int),
610 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800611 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700612 },
613 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700614 .procname = "icmp_echo_ignore_broadcasts",
615 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
616 .maxlen = sizeof(int),
617 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800618 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700619 },
620 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700621 .procname = "icmp_ignore_bogus_error_responses",
622 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
623 .maxlen = sizeof(int),
624 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800625 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700626 },
627 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700628 .procname = "icmp_errors_use_inbound_ifaddr",
629 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
630 .maxlen = sizeof(int),
631 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800632 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700633 },
634 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700635 .procname = "icmp_ratelimit",
636 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
637 .maxlen = sizeof(int),
638 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800639 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700640 },
641 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700642 .procname = "icmp_ratemask",
643 .data = &init_net.ipv4.sysctl_icmp_ratemask,
644 .maxlen = sizeof(int),
645 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800646 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700647 },
Neil Horman1080d702008-10-27 12:28:25 -0700648 {
Neil Horman1080d702008-10-27 12:28:25 -0700649 .procname = "rt_cache_rebuild_count",
650 .data = &init_net.ipv4.sysctl_rt_cache_rebuild_count,
651 .maxlen = sizeof(int),
652 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800653 .proc_handler = proc_dointvec
Neil Horman1080d702008-10-27 12:28:25 -0700654 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700655 { }
656};
657
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800658struct ctl_path net_ipv4_ctl_path[] = {
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800659 { .procname = "net", },
660 { .procname = "ipv4", },
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800661 { },
662};
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800663EXPORT_SYMBOL_GPL(net_ipv4_ctl_path);
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800664
Pavel Emelyanov15775192008-03-26 01:54:18 -0700665static __net_init int ipv4_sysctl_init_net(struct net *net)
666{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700667 struct ctl_table *table;
668
669 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800670 if (!net_eq(net, &init_net)) {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700671 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
672 if (table == NULL)
673 goto err_alloc;
674
675 table[0].data =
676 &net->ipv4.sysctl_icmp_echo_ignore_all;
677 table[1].data =
678 &net->ipv4.sysctl_icmp_echo_ignore_broadcasts;
679 table[2].data =
680 &net->ipv4.sysctl_icmp_ignore_bogus_error_responses;
681 table[3].data =
682 &net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr;
683 table[4].data =
684 &net->ipv4.sysctl_icmp_ratelimit;
685 table[5].data =
686 &net->ipv4.sysctl_icmp_ratemask;
Neil Horman1080d702008-10-27 12:28:25 -0700687 table[6].data =
688 &net->ipv4.sysctl_rt_cache_rebuild_count;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700689 }
690
Neil Horman1080d702008-10-27 12:28:25 -0700691 net->ipv4.sysctl_rt_cache_rebuild_count = 4;
692
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700693 net->ipv4.ipv4_hdr = register_net_sysctl_table(net,
694 net_ipv4_ctl_path, table);
695 if (net->ipv4.ipv4_hdr == NULL)
696 goto err_reg;
697
Pavel Emelyanov15775192008-03-26 01:54:18 -0700698 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700699
700err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800701 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700702 kfree(table);
703err_alloc:
704 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -0700705}
706
707static __net_exit void ipv4_sysctl_exit_net(struct net *net)
708{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700709 struct ctl_table *table;
710
711 table = net->ipv4.ipv4_hdr->ctl_table_arg;
712 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
713 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700714}
715
716static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
717 .init = ipv4_sysctl_init_net,
718 .exit = ipv4_sysctl_exit_net,
719};
720
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800721static __init int sysctl_ipv4_init(void)
722{
723 struct ctl_table_header *hdr;
724
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800725 hdr = register_sysctl_paths(net_ipv4_ctl_path, ipv4_table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700726 if (hdr == NULL)
727 return -ENOMEM;
728
729 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
730 unregister_sysctl_table(hdr);
731 return -ENOMEM;
732 }
733
734 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800735}
736
737__initcall(sysctl_ipv4_init);