blob: d96c1da4b17cf97790bb2a426abbe5eb4582356d [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 },
Amerigo Wange3826f12010-05-05 00:27:06 +0000302 {
303 .procname = "ip_local_reserved_ports",
304 .data = NULL, /* initialized in sysctl_ipv4_init */
305 .maxlen = 65536,
306 .mode = 0644,
307 .proc_handler = proc_do_large_bitmap,
308 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309#ifdef CONFIG_IP_MULTICAST
310 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 .procname = "igmp_max_memberships",
312 .data = &sysctl_igmp_max_memberships,
313 .maxlen = sizeof(int),
314 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800315 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 },
317
318#endif
319 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 .procname = "igmp_max_msf",
321 .data = &sysctl_igmp_max_msf,
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_threshold",
328 .data = &inet_peer_threshold,
329 .maxlen = sizeof(int),
330 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800331 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 },
333 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 .procname = "inet_peer_minttl",
335 .data = &inet_peer_minttl,
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_maxttl",
342 .data = &inet_peer_maxttl,
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_mintime",
349 .data = &inet_peer_gc_mintime,
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 = "inet_peer_gc_maxtime",
356 .data = &inet_peer_gc_maxtime,
357 .maxlen = sizeof(int),
358 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800359 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 },
361 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 .procname = "tcp_orphan_retries",
363 .data = &sysctl_tcp_orphan_retries,
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_fack",
370 .data = &sysctl_tcp_fack,
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_reordering",
377 .data = &sysctl_tcp_reordering,
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_ecn",
384 .data = &sysctl_tcp_ecn,
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_dsack",
391 .data = &sysctl_tcp_dsack,
392 .maxlen = sizeof(int),
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_mem",
398 .data = &sysctl_tcp_mem,
399 .maxlen = sizeof(sysctl_tcp_mem),
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_wmem",
405 .data = &sysctl_tcp_wmem,
406 .maxlen = sizeof(sysctl_tcp_wmem),
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_rmem",
412 .data = &sysctl_tcp_rmem,
413 .maxlen = sizeof(sysctl_tcp_rmem),
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_app_win",
419 .data = &sysctl_tcp_app_win,
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_adv_win_scale",
426 .data = &sysctl_tcp_adv_win_scale,
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_tw_reuse",
433 .data = &sysctl_tcp_tw_reuse,
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 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 .procname = "tcp_frto",
440 .data = &sysctl_tcp_frto,
441 .maxlen = sizeof(int),
442 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800443 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 },
445 {
Ilpo Järvinen3cfe3ba2007-02-27 10:09:49 -0800446 .procname = "tcp_frto_response",
447 .data = &sysctl_tcp_frto_response,
448 .maxlen = sizeof(int),
449 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800450 .proc_handler = proc_dointvec
Ilpo Järvinen3cfe3ba2007-02-27 10:09:49 -0800451 },
452 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 .procname = "tcp_low_latency",
454 .data = &sysctl_tcp_low_latency,
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_no_metrics_save",
461 .data = &sysctl_tcp_nometrics_save,
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_moderate_rcvbuf",
468 .data = &sysctl_tcp_moderate_rcvbuf,
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 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 .procname = "tcp_tso_win_divisor",
475 .data = &sysctl_tcp_tso_win_divisor,
476 .maxlen = sizeof(int),
477 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800478 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 },
480 {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700481 .procname = "tcp_congestion_control",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 .mode = 0644,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700483 .maxlen = TCP_CA_NAME_MAX,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800484 .proc_handler = proc_tcp_congestion_control,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 },
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800486 {
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800487 .procname = "tcp_abc",
488 .data = &sysctl_tcp_abc,
489 .maxlen = sizeof(int),
490 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800491 .proc_handler = proc_dointvec,
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800492 },
John Heffner5d424d52006-03-20 17:53:41 -0800493 {
John Heffner5d424d52006-03-20 17:53:41 -0800494 .procname = "tcp_mtu_probing",
495 .data = &sysctl_tcp_mtu_probing,
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 },
500 {
John Heffner5d424d52006-03-20 17:53:41 -0800501 .procname = "tcp_base_mss",
502 .data = &sysctl_tcp_base_mss,
503 .maxlen = sizeof(int),
504 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800505 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800506 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900507 {
Rick Jones15d99e02006-03-20 22:40:29 -0800508 .procname = "tcp_workaround_signed_windows",
509 .data = &sysctl_tcp_workaround_signed_windows,
510 .maxlen = sizeof(int),
511 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800512 .proc_handler = proc_dointvec
Rick Jones15d99e02006-03-20 22:40:29 -0800513 },
Chris Leech95937822006-05-23 18:02:55 -0700514#ifdef CONFIG_NET_DMA
515 {
Chris Leech95937822006-05-23 18:02:55 -0700516 .procname = "tcp_dma_copybreak",
517 .data = &sysctl_tcp_dma_copybreak,
518 .maxlen = sizeof(int),
519 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800520 .proc_handler = proc_dointvec
Chris Leech95937822006-05-23 18:02:55 -0700521 },
522#endif
David S. Miller35089bb2006-06-13 22:33:04 -0700523 {
David S. Miller35089bb2006-06-13 22:33:04 -0700524 .procname = "tcp_slow_start_after_idle",
525 .data = &sysctl_tcp_slow_start_after_idle,
526 .maxlen = sizeof(int),
527 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800528 .proc_handler = proc_dointvec
David S. Miller35089bb2006-06-13 22:33:04 -0700529 },
Paul Moore446fda42006-08-03 16:48:06 -0700530#ifdef CONFIG_NETLABEL
531 {
Paul Moore446fda42006-08-03 16:48:06 -0700532 .procname = "cipso_cache_enable",
533 .data = &cipso_v4_cache_enabled,
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_cache_bucket_size",
540 .data = &cipso_v4_cache_bucketsize,
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_optfmt",
547 .data = &cipso_v4_rbm_optfmt,
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 {
Paul Moore446fda42006-08-03 16:48:06 -0700553 .procname = "cipso_rbm_strictvalid",
554 .data = &cipso_v4_rbm_strictvalid,
555 .maxlen = sizeof(int),
556 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800557 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700558 },
559#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800560 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800561 .procname = "tcp_available_congestion_control",
562 .maxlen = TCP_CA_BUF_MAX,
563 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800564 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800565 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800566 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800567 .procname = "tcp_allowed_congestion_control",
568 .maxlen = TCP_CA_BUF_MAX,
569 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800570 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800571 },
John Heffner886236c2007-03-25 19:21:45 -0700572 {
John Heffner886236c2007-03-25 19:21:45 -0700573 .procname = "tcp_max_ssthresh",
574 .data = &sysctl_tcp_max_ssthresh,
575 .maxlen = sizeof(int),
576 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800577 .proc_handler = proc_dointvec,
John Heffner886236c2007-03-25 19:21:45 -0700578 },
Hideo Aoki95766ff2007-12-31 00:29:24 -0800579 {
William Allen Simpson519855c2009-12-02 18:14:19 +0000580 .procname = "tcp_cookie_size",
581 .data = &sysctl_tcp_cookie_size,
582 .maxlen = sizeof(int),
583 .mode = 0644,
584 .proc_handler = proc_dointvec
585 },
586 {
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000587 .procname = "tcp_thin_linear_timeouts",
588 .data = &sysctl_tcp_thin_linear_timeouts,
589 .maxlen = sizeof(int),
590 .mode = 0644,
591 .proc_handler = proc_dointvec
592 },
Andreas Petlund7e380172010-02-18 04:48:19 +0000593 {
594 .procname = "tcp_thin_dupack",
595 .data = &sysctl_tcp_thin_dupack,
596 .maxlen = sizeof(int),
597 .mode = 0644,
598 .proc_handler = proc_dointvec
599 },
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000600 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800601 .procname = "udp_mem",
602 .data = &sysctl_udp_mem,
603 .maxlen = sizeof(sysctl_udp_mem),
604 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800605 .proc_handler = proc_dointvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800606 .extra1 = &zero
607 },
608 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800609 .procname = "udp_rmem_min",
610 .data = &sysctl_udp_rmem_min,
611 .maxlen = sizeof(sysctl_udp_rmem_min),
612 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800613 .proc_handler = proc_dointvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800614 .extra1 = &zero
615 },
616 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800617 .procname = "udp_wmem_min",
618 .data = &sysctl_udp_wmem_min,
619 .maxlen = sizeof(sysctl_udp_wmem_min),
620 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800621 .proc_handler = proc_dointvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800622 .extra1 = &zero
623 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800624 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800626
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700627static struct ctl_table ipv4_net_table[] = {
628 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700629 .procname = "icmp_echo_ignore_all",
630 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
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_echo_ignore_broadcasts",
637 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
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_ignore_bogus_error_responses",
644 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
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_errors_use_inbound_ifaddr",
651 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
652 .maxlen = sizeof(int),
653 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800654 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700655 },
656 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700657 .procname = "icmp_ratelimit",
658 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
659 .maxlen = sizeof(int),
660 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800661 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700662 },
663 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700664 .procname = "icmp_ratemask",
665 .data = &init_net.ipv4.sysctl_icmp_ratemask,
666 .maxlen = sizeof(int),
667 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800668 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700669 },
Neil Horman1080d702008-10-27 12:28:25 -0700670 {
Neil Horman1080d702008-10-27 12:28:25 -0700671 .procname = "rt_cache_rebuild_count",
672 .data = &init_net.ipv4.sysctl_rt_cache_rebuild_count,
673 .maxlen = sizeof(int),
674 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800675 .proc_handler = proc_dointvec
Neil Horman1080d702008-10-27 12:28:25 -0700676 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700677 { }
678};
679
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800680struct ctl_path net_ipv4_ctl_path[] = {
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800681 { .procname = "net", },
682 { .procname = "ipv4", },
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800683 { },
684};
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800685EXPORT_SYMBOL_GPL(net_ipv4_ctl_path);
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800686
Pavel Emelyanov15775192008-03-26 01:54:18 -0700687static __net_init int ipv4_sysctl_init_net(struct net *net)
688{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700689 struct ctl_table *table;
690
691 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800692 if (!net_eq(net, &init_net)) {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700693 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
694 if (table == NULL)
695 goto err_alloc;
696
697 table[0].data =
698 &net->ipv4.sysctl_icmp_echo_ignore_all;
699 table[1].data =
700 &net->ipv4.sysctl_icmp_echo_ignore_broadcasts;
701 table[2].data =
702 &net->ipv4.sysctl_icmp_ignore_bogus_error_responses;
703 table[3].data =
704 &net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr;
705 table[4].data =
706 &net->ipv4.sysctl_icmp_ratelimit;
707 table[5].data =
708 &net->ipv4.sysctl_icmp_ratemask;
Neil Horman1080d702008-10-27 12:28:25 -0700709 table[6].data =
710 &net->ipv4.sysctl_rt_cache_rebuild_count;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700711 }
712
Neil Horman1080d702008-10-27 12:28:25 -0700713 net->ipv4.sysctl_rt_cache_rebuild_count = 4;
714
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700715 net->ipv4.ipv4_hdr = register_net_sysctl_table(net,
716 net_ipv4_ctl_path, table);
717 if (net->ipv4.ipv4_hdr == NULL)
718 goto err_reg;
719
Pavel Emelyanov15775192008-03-26 01:54:18 -0700720 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700721
722err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800723 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700724 kfree(table);
725err_alloc:
726 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -0700727}
728
729static __net_exit void ipv4_sysctl_exit_net(struct net *net)
730{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700731 struct ctl_table *table;
732
733 table = net->ipv4.ipv4_hdr->ctl_table_arg;
734 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
735 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700736}
737
738static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
739 .init = ipv4_sysctl_init_net,
740 .exit = ipv4_sysctl_exit_net,
741};
742
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800743static __init int sysctl_ipv4_init(void)
744{
745 struct ctl_table_header *hdr;
Amerigo Wange3826f12010-05-05 00:27:06 +0000746 struct ctl_table *i;
747
748 for (i = ipv4_table; i->procname; i++) {
749 if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
750 i->data = sysctl_local_reserved_ports;
751 break;
752 }
753 }
754 if (!i->procname)
755 return -EINVAL;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800756
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800757 hdr = register_sysctl_paths(net_ipv4_ctl_path, ipv4_table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700758 if (hdr == NULL)
759 return -ENOMEM;
760
761 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
762 unregister_sysctl_table(hdr);
763 return -ENOMEM;
764 }
765
766 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800767}
768
769__initcall(sysctl_ipv4_init);