blob: 1cd5c15174b8a0f286fd9d7a92100841dd341ecd [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <net/snmp.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030017#include <net/icmp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <net/ip.h>
19#include <net/route.h>
20#include <net/tcp.h>
Hideo Aoki95766ff2007-12-31 00:29:24 -080021#include <net/udp.h>
Paul Moore446fda42006-08-03 16:48:06 -070022#include <net/cipso_ipv4.h>
Pavel Emelyanov04128f22007-10-15 02:33:45 -070023#include <net/inet_frag.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Herbert Xu89cee8b2005-12-13 23:14:27 -080025static int zero;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090026static int tcp_retr1_max = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027static int ip_local_port_range_min[] = { 1, 1 };
28static int ip_local_port_range_max[] = { 65535, 65535 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Stephen Hemminger227b60f2007-10-10 17:30:46 -070030/* Update system visible IP port range */
31static void set_local_port_range(int range[2])
32{
Eric Dumazet3c689b72008-10-08 14:18:04 -070033 write_seqlock(&sysctl_local_ports.lock);
34 sysctl_local_ports.range[0] = range[0];
35 sysctl_local_ports.range[1] = range[1];
36 write_sequnlock(&sysctl_local_ports.lock);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070037}
38
39/* Validate changes from /proc interface. */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070040static int ipv4_local_port_range(ctl_table *table, int write,
Stephen Hemminger227b60f2007-10-10 17:30:46 -070041 void __user *buffer,
42 size_t *lenp, loff_t *ppos)
43{
44 int ret;
Eric Dumazet3c689b72008-10-08 14:18:04 -070045 int range[2];
Stephen Hemminger227b60f2007-10-10 17:30:46 -070046 ctl_table tmp = {
47 .data = &range,
48 .maxlen = sizeof(range),
49 .mode = table->mode,
50 .extra1 = &ip_local_port_range_min,
51 .extra2 = &ip_local_port_range_max,
52 };
53
Eric Dumazet3c689b72008-10-08 14:18:04 -070054 inet_get_local_port_range(range, range + 1);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070055 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070056
57 if (write && ret == 0) {
Anton Arapova25de532007-10-18 22:00:17 -070058 if (range[1] < range[0])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070059 ret = -EINVAL;
60 else
61 set_local_port_range(range);
62 }
63
64 return ret;
65}
66
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070067static int proc_tcp_congestion_control(ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -070068 void __user *buffer, size_t *lenp, loff_t *ppos)
69{
70 char val[TCP_CA_NAME_MAX];
71 ctl_table tbl = {
72 .data = val,
73 .maxlen = TCP_CA_NAME_MAX,
74 };
75 int ret;
76
77 tcp_get_default_congestion_control(val);
78
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070079 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -070080 if (write && ret == 0)
81 ret = tcp_set_default_congestion_control(val);
82 return ret;
83}
84
Stephen Hemminger3ff825b2006-11-09 16:32:06 -080085static int proc_tcp_available_congestion_control(ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070086 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -080087 void __user *buffer, size_t *lenp,
88 loff_t *ppos)
89{
90 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
91 int ret;
92
93 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
94 if (!tbl.data)
95 return -ENOMEM;
96 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070097 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -080098 kfree(tbl.data);
99 return ret;
100}
101
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800102static int proc_allowed_congestion_control(ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700103 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800104 void __user *buffer, size_t *lenp,
105 loff_t *ppos)
106{
107 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
108 int ret;
109
110 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
111 if (!tbl.data)
112 return -ENOMEM;
113
114 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700115 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800116 if (write && ret == 0)
117 ret = tcp_set_allowed_congestion_control(tbl.data);
118 kfree(tbl.data);
119 return ret;
120}
121
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800122static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900123 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 .procname = "tcp_timestamps",
125 .data = &sysctl_tcp_timestamps,
126 .maxlen = sizeof(int),
127 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800128 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900130 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 .procname = "tcp_window_scaling",
132 .data = &sysctl_tcp_window_scaling,
133 .maxlen = sizeof(int),
134 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800135 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900137 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 .procname = "tcp_sack",
139 .data = &sysctl_tcp_sack,
140 .maxlen = sizeof(int),
141 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800142 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900144 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 .procname = "tcp_retrans_collapse",
146 .data = &sysctl_tcp_retrans_collapse,
147 .maxlen = sizeof(int),
148 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800149 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900151 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 .procname = "ip_default_ttl",
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900153 .data = &sysctl_ip_default_ttl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 .maxlen = sizeof(int),
155 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800156 .proc_handler = ipv4_doint_and_flush,
Sven Wegeneradf044c2008-08-03 14:06:44 -0700157 .extra2 = &init_net,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900159 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 .procname = "ip_no_pmtu_disc",
161 .data = &ipv4_config.no_pmtu_disc,
162 .maxlen = sizeof(int),
163 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800164 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 },
166 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 .procname = "ip_nonlocal_bind",
168 .data = &sysctl_ip_nonlocal_bind,
169 .maxlen = sizeof(int),
170 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800171 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 },
173 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 .procname = "tcp_syn_retries",
175 .data = &sysctl_tcp_syn_retries,
176 .maxlen = sizeof(int),
177 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800178 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 },
180 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 .procname = "tcp_synack_retries",
182 .data = &sysctl_tcp_synack_retries,
183 .maxlen = sizeof(int),
184 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800185 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 },
187 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 .procname = "tcp_max_orphans",
189 .data = &sysctl_tcp_max_orphans,
190 .maxlen = sizeof(int),
191 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800192 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 },
194 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 .procname = "tcp_max_tw_buckets",
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -0700196 .data = &tcp_death_row.sysctl_max_tw_buckets,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 .maxlen = sizeof(int),
198 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800199 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 },
201 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 .procname = "ip_dynaddr",
203 .data = &sysctl_ip_dynaddr,
204 .maxlen = sizeof(int),
205 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800206 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 },
208 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 .procname = "tcp_keepalive_time",
210 .data = &sysctl_tcp_keepalive_time,
211 .maxlen = sizeof(int),
212 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800213 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 },
215 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 .procname = "tcp_keepalive_probes",
217 .data = &sysctl_tcp_keepalive_probes,
218 .maxlen = sizeof(int),
219 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800220 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 },
222 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 .procname = "tcp_keepalive_intvl",
224 .data = &sysctl_tcp_keepalive_intvl,
225 .maxlen = sizeof(int),
226 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800227 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 },
229 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 .procname = "tcp_retries1",
231 .data = &sysctl_tcp_retries1,
232 .maxlen = sizeof(int),
233 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800234 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 .extra2 = &tcp_retr1_max
236 },
237 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 .procname = "tcp_retries2",
239 .data = &sysctl_tcp_retries2,
240 .maxlen = sizeof(int),
241 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800242 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 },
244 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 .procname = "tcp_fin_timeout",
246 .data = &sysctl_tcp_fin_timeout,
247 .maxlen = sizeof(int),
248 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800249 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 },
251#ifdef CONFIG_SYN_COOKIES
252 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 .procname = "tcp_syncookies",
254 .data = &sysctl_tcp_syncookies,
255 .maxlen = sizeof(int),
256 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800257 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 },
259#endif
260 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 .procname = "tcp_tw_recycle",
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -0700262 .data = &tcp_death_row.sysctl_tw_recycle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 .maxlen = sizeof(int),
264 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800265 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 },
267 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 .procname = "tcp_abort_on_overflow",
269 .data = &sysctl_tcp_abort_on_overflow,
270 .maxlen = sizeof(int),
271 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800272 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 },
274 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 .procname = "tcp_stdurg",
276 .data = &sysctl_tcp_stdurg,
277 .maxlen = sizeof(int),
278 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800279 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 },
281 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 .procname = "tcp_rfc1337",
283 .data = &sysctl_tcp_rfc1337,
284 .maxlen = sizeof(int),
285 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800286 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 },
288 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 .procname = "tcp_max_syn_backlog",
290 .data = &sysctl_max_syn_backlog,
291 .maxlen = sizeof(int),
292 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800293 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 },
295 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 .procname = "ip_local_port_range",
Eric Dumazet3c689b72008-10-08 14:18:04 -0700297 .data = &sysctl_local_ports.range,
298 .maxlen = sizeof(sysctl_local_ports.range),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800300 .proc_handler = ipv4_local_port_range,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302#ifdef CONFIG_IP_MULTICAST
303 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 .procname = "igmp_max_memberships",
305 .data = &sysctl_igmp_max_memberships,
306 .maxlen = sizeof(int),
307 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800308 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 },
310
311#endif
312 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 .procname = "igmp_max_msf",
314 .data = &sysctl_igmp_max_msf,
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 = "inet_peer_threshold",
321 .data = &inet_peer_threshold,
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 = "inet_peer_minttl",
328 .data = &inet_peer_minttl,
329 .maxlen = sizeof(int),
330 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800331 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 },
333 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 .procname = "inet_peer_maxttl",
335 .data = &inet_peer_maxttl,
336 .maxlen = sizeof(int),
337 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800338 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 },
340 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 .procname = "inet_peer_gc_mintime",
342 .data = &inet_peer_gc_mintime,
343 .maxlen = sizeof(int),
344 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800345 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 },
347 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 .procname = "inet_peer_gc_maxtime",
349 .data = &inet_peer_gc_maxtime,
350 .maxlen = sizeof(int),
351 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800352 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 },
354 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 .procname = "tcp_orphan_retries",
356 .data = &sysctl_tcp_orphan_retries,
357 .maxlen = sizeof(int),
358 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800359 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 },
361 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 .procname = "tcp_fack",
363 .data = &sysctl_tcp_fack,
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_reordering",
370 .data = &sysctl_tcp_reordering,
371 .maxlen = sizeof(int),
372 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800373 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 },
375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 .procname = "tcp_ecn",
377 .data = &sysctl_tcp_ecn,
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_dsack",
384 .data = &sysctl_tcp_dsack,
385 .maxlen = sizeof(int),
386 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800387 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 },
389 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 .procname = "tcp_mem",
391 .data = &sysctl_tcp_mem,
392 .maxlen = sizeof(sysctl_tcp_mem),
393 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800394 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 },
396 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 .procname = "tcp_wmem",
398 .data = &sysctl_tcp_wmem,
399 .maxlen = sizeof(sysctl_tcp_wmem),
400 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800401 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 },
403 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 .procname = "tcp_rmem",
405 .data = &sysctl_tcp_rmem,
406 .maxlen = sizeof(sysctl_tcp_rmem),
407 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800408 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 },
410 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 .procname = "tcp_app_win",
412 .data = &sysctl_tcp_app_win,
413 .maxlen = sizeof(int),
414 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800415 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 },
417 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 .procname = "tcp_adv_win_scale",
419 .data = &sysctl_tcp_adv_win_scale,
420 .maxlen = sizeof(int),
421 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800422 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 },
424 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 .procname = "tcp_tw_reuse",
426 .data = &sysctl_tcp_tw_reuse,
427 .maxlen = sizeof(int),
428 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800429 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 },
431 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 .procname = "tcp_frto",
433 .data = &sysctl_tcp_frto,
434 .maxlen = sizeof(int),
435 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800436 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 },
438 {
Ilpo Järvinen3cfe3ba2007-02-27 10:09:49 -0800439 .procname = "tcp_frto_response",
440 .data = &sysctl_tcp_frto_response,
441 .maxlen = sizeof(int),
442 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800443 .proc_handler = proc_dointvec
Ilpo Järvinen3cfe3ba2007-02-27 10:09:49 -0800444 },
445 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 .procname = "tcp_low_latency",
447 .data = &sysctl_tcp_low_latency,
448 .maxlen = sizeof(int),
449 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800450 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 },
452 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 .procname = "tcp_no_metrics_save",
454 .data = &sysctl_tcp_nometrics_save,
455 .maxlen = sizeof(int),
456 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800457 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 },
459 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 .procname = "tcp_moderate_rcvbuf",
461 .data = &sysctl_tcp_moderate_rcvbuf,
462 .maxlen = sizeof(int),
463 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800464 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 },
466 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 .procname = "tcp_tso_win_divisor",
468 .data = &sysctl_tcp_tso_win_divisor,
469 .maxlen = sizeof(int),
470 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800471 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 },
473 {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700474 .procname = "tcp_congestion_control",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 .mode = 0644,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700476 .maxlen = TCP_CA_NAME_MAX,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800477 .proc_handler = proc_tcp_congestion_control,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 },
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800479 {
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800480 .procname = "tcp_abc",
481 .data = &sysctl_tcp_abc,
482 .maxlen = sizeof(int),
483 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800484 .proc_handler = proc_dointvec,
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800485 },
John Heffner5d424d52006-03-20 17:53:41 -0800486 {
John Heffner5d424d52006-03-20 17:53:41 -0800487 .procname = "tcp_mtu_probing",
488 .data = &sysctl_tcp_mtu_probing,
489 .maxlen = sizeof(int),
490 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800491 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800492 },
493 {
John Heffner5d424d52006-03-20 17:53:41 -0800494 .procname = "tcp_base_mss",
495 .data = &sysctl_tcp_base_mss,
496 .maxlen = sizeof(int),
497 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800498 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800499 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900500 {
Rick Jones15d99e02006-03-20 22:40:29 -0800501 .procname = "tcp_workaround_signed_windows",
502 .data = &sysctl_tcp_workaround_signed_windows,
503 .maxlen = sizeof(int),
504 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800505 .proc_handler = proc_dointvec
Rick Jones15d99e02006-03-20 22:40:29 -0800506 },
Chris Leech95937822006-05-23 18:02:55 -0700507#ifdef CONFIG_NET_DMA
508 {
Chris Leech95937822006-05-23 18:02:55 -0700509 .procname = "tcp_dma_copybreak",
510 .data = &sysctl_tcp_dma_copybreak,
511 .maxlen = sizeof(int),
512 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800513 .proc_handler = proc_dointvec
Chris Leech95937822006-05-23 18:02:55 -0700514 },
515#endif
David S. Miller35089bb2006-06-13 22:33:04 -0700516 {
David S. Miller35089bb2006-06-13 22:33:04 -0700517 .procname = "tcp_slow_start_after_idle",
518 .data = &sysctl_tcp_slow_start_after_idle,
519 .maxlen = sizeof(int),
520 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800521 .proc_handler = proc_dointvec
David S. Miller35089bb2006-06-13 22:33:04 -0700522 },
Paul Moore446fda42006-08-03 16:48:06 -0700523#ifdef CONFIG_NETLABEL
524 {
Paul Moore446fda42006-08-03 16:48:06 -0700525 .procname = "cipso_cache_enable",
526 .data = &cipso_v4_cache_enabled,
527 .maxlen = sizeof(int),
528 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800529 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700530 },
531 {
Paul Moore446fda42006-08-03 16:48:06 -0700532 .procname = "cipso_cache_bucket_size",
533 .data = &cipso_v4_cache_bucketsize,
534 .maxlen = sizeof(int),
535 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800536 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700537 },
538 {
Paul Moore446fda42006-08-03 16:48:06 -0700539 .procname = "cipso_rbm_optfmt",
540 .data = &cipso_v4_rbm_optfmt,
541 .maxlen = sizeof(int),
542 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800543 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700544 },
545 {
Paul Moore446fda42006-08-03 16:48:06 -0700546 .procname = "cipso_rbm_strictvalid",
547 .data = &cipso_v4_rbm_strictvalid,
548 .maxlen = sizeof(int),
549 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800550 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700551 },
552#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800553 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800554 .procname = "tcp_available_congestion_control",
555 .maxlen = TCP_CA_BUF_MAX,
556 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800557 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800558 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800559 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800560 .procname = "tcp_allowed_congestion_control",
561 .maxlen = TCP_CA_BUF_MAX,
562 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800563 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800564 },
John Heffner886236c2007-03-25 19:21:45 -0700565 {
John Heffner886236c2007-03-25 19:21:45 -0700566 .procname = "tcp_max_ssthresh",
567 .data = &sysctl_tcp_max_ssthresh,
568 .maxlen = sizeof(int),
569 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800570 .proc_handler = proc_dointvec,
John Heffner886236c2007-03-25 19:21:45 -0700571 },
Hideo Aoki95766ff2007-12-31 00:29:24 -0800572 {
William Allen Simpson519855c2009-12-02 18:14:19 +0000573 .procname = "tcp_cookie_size",
574 .data = &sysctl_tcp_cookie_size,
575 .maxlen = sizeof(int),
576 .mode = 0644,
577 .proc_handler = proc_dointvec
578 },
579 {
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000580 .procname = "tcp_thin_linear_timeouts",
581 .data = &sysctl_tcp_thin_linear_timeouts,
582 .maxlen = sizeof(int),
583 .mode = 0644,
584 .proc_handler = proc_dointvec
585 },
Andreas Petlund7e380172010-02-18 04:48:19 +0000586 {
587 .procname = "tcp_thin_dupack",
588 .data = &sysctl_tcp_thin_dupack,
589 .maxlen = sizeof(int),
590 .mode = 0644,
591 .proc_handler = proc_dointvec
592 },
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000593 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800594 .procname = "udp_mem",
595 .data = &sysctl_udp_mem,
596 .maxlen = sizeof(sysctl_udp_mem),
597 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800598 .proc_handler = proc_dointvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800599 .extra1 = &zero
600 },
601 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800602 .procname = "udp_rmem_min",
603 .data = &sysctl_udp_rmem_min,
604 .maxlen = sizeof(sysctl_udp_rmem_min),
605 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800606 .proc_handler = proc_dointvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800607 .extra1 = &zero
608 },
609 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800610 .procname = "udp_wmem_min",
611 .data = &sysctl_udp_wmem_min,
612 .maxlen = sizeof(sysctl_udp_wmem_min),
613 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800614 .proc_handler = proc_dointvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800615 .extra1 = &zero
616 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800617 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800619
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700620static struct ctl_table ipv4_net_table[] = {
621 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700622 .procname = "icmp_echo_ignore_all",
623 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
624 .maxlen = sizeof(int),
625 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800626 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700627 },
628 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700629 .procname = "icmp_echo_ignore_broadcasts",
630 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
631 .maxlen = sizeof(int),
632 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800633 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700634 },
635 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700636 .procname = "icmp_ignore_bogus_error_responses",
637 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
638 .maxlen = sizeof(int),
639 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800640 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700641 },
642 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700643 .procname = "icmp_errors_use_inbound_ifaddr",
644 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
645 .maxlen = sizeof(int),
646 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800647 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700648 },
649 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700650 .procname = "icmp_ratelimit",
651 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
652 .maxlen = sizeof(int),
653 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800654 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700655 },
656 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700657 .procname = "icmp_ratemask",
658 .data = &init_net.ipv4.sysctl_icmp_ratemask,
659 .maxlen = sizeof(int),
660 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800661 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700662 },
Neil Horman1080d702008-10-27 12:28:25 -0700663 {
Neil Horman1080d702008-10-27 12:28:25 -0700664 .procname = "rt_cache_rebuild_count",
665 .data = &init_net.ipv4.sysctl_rt_cache_rebuild_count,
666 .maxlen = sizeof(int),
667 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800668 .proc_handler = proc_dointvec
Neil Horman1080d702008-10-27 12:28:25 -0700669 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700670 { }
671};
672
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800673struct ctl_path net_ipv4_ctl_path[] = {
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800674 { .procname = "net", },
675 { .procname = "ipv4", },
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800676 { },
677};
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800678EXPORT_SYMBOL_GPL(net_ipv4_ctl_path);
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800679
Pavel Emelyanov15775192008-03-26 01:54:18 -0700680static __net_init int ipv4_sysctl_init_net(struct net *net)
681{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700682 struct ctl_table *table;
683
684 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800685 if (!net_eq(net, &init_net)) {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700686 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
687 if (table == NULL)
688 goto err_alloc;
689
690 table[0].data =
691 &net->ipv4.sysctl_icmp_echo_ignore_all;
692 table[1].data =
693 &net->ipv4.sysctl_icmp_echo_ignore_broadcasts;
694 table[2].data =
695 &net->ipv4.sysctl_icmp_ignore_bogus_error_responses;
696 table[3].data =
697 &net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr;
698 table[4].data =
699 &net->ipv4.sysctl_icmp_ratelimit;
700 table[5].data =
701 &net->ipv4.sysctl_icmp_ratemask;
Neil Horman1080d702008-10-27 12:28:25 -0700702 table[6].data =
703 &net->ipv4.sysctl_rt_cache_rebuild_count;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700704 }
705
Neil Horman1080d702008-10-27 12:28:25 -0700706 net->ipv4.sysctl_rt_cache_rebuild_count = 4;
707
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700708 net->ipv4.ipv4_hdr = register_net_sysctl_table(net,
709 net_ipv4_ctl_path, table);
710 if (net->ipv4.ipv4_hdr == NULL)
711 goto err_reg;
712
Pavel Emelyanov15775192008-03-26 01:54:18 -0700713 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700714
715err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800716 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700717 kfree(table);
718err_alloc:
719 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -0700720}
721
722static __net_exit void ipv4_sysctl_exit_net(struct net *net)
723{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700724 struct ctl_table *table;
725
726 table = net->ipv4.ipv4_hdr->ctl_table_arg;
727 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
728 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700729}
730
731static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
732 .init = ipv4_sysctl_init_net,
733 .exit = ipv4_sysctl_exit_net,
734};
735
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800736static __init int sysctl_ipv4_init(void)
737{
738 struct ctl_table_header *hdr;
739
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800740 hdr = register_sysctl_paths(net_ipv4_ctl_path, ipv4_table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700741 if (hdr == NULL)
742 return -ENOMEM;
743
744 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
745 unregister_sysctl_table(hdr);
746 return -ENOMEM;
747 }
748
749 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800750}
751
752__initcall(sysctl_ipv4_init);