blob: 321e6e84dbccb93e08741263815aaae82610b0a8 [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 };
Alexey Dobriyan0147fc02010-11-22 12:54:21 +000029static int tcp_adv_win_scale_min = -31;
30static int tcp_adv_win_scale_max = 31;
Eric Dumazet249fab72010-12-13 12:16:14 -080031static int ip_ttl_min = 1;
32static int ip_ttl_max = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Stephen Hemminger227b60f2007-10-10 17:30:46 -070034/* Update system visible IP port range */
35static void set_local_port_range(int range[2])
36{
Eric Dumazet3c689b72008-10-08 14:18:04 -070037 write_seqlock(&sysctl_local_ports.lock);
38 sysctl_local_ports.range[0] = range[0];
39 sysctl_local_ports.range[1] = range[1];
40 write_sequnlock(&sysctl_local_ports.lock);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070041}
42
43/* Validate changes from /proc interface. */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070044static int ipv4_local_port_range(ctl_table *table, int write,
Stephen Hemminger227b60f2007-10-10 17:30:46 -070045 void __user *buffer,
46 size_t *lenp, loff_t *ppos)
47{
48 int ret;
Eric Dumazet3c689b72008-10-08 14:18:04 -070049 int range[2];
Stephen Hemminger227b60f2007-10-10 17:30:46 -070050 ctl_table tmp = {
51 .data = &range,
52 .maxlen = sizeof(range),
53 .mode = table->mode,
54 .extra1 = &ip_local_port_range_min,
55 .extra2 = &ip_local_port_range_max,
56 };
57
Eric Dumazet3c689b72008-10-08 14:18:04 -070058 inet_get_local_port_range(range, range + 1);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070059 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
Stephen Hemminger227b60f2007-10-10 17:30:46 -070060
61 if (write && ret == 0) {
Anton Arapova25de532007-10-18 22:00:17 -070062 if (range[1] < range[0])
Stephen Hemminger227b60f2007-10-10 17:30:46 -070063 ret = -EINVAL;
64 else
65 set_local_port_range(range);
66 }
67
68 return ret;
69}
70
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070071static int proc_tcp_congestion_control(ctl_table *ctl, int write,
Stephen Hemminger317a76f2005-06-23 12:19:55 -070072 void __user *buffer, size_t *lenp, loff_t *ppos)
73{
74 char val[TCP_CA_NAME_MAX];
75 ctl_table tbl = {
76 .data = val,
77 .maxlen = TCP_CA_NAME_MAX,
78 };
79 int ret;
80
81 tcp_get_default_congestion_control(val);
82
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070083 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger317a76f2005-06-23 12:19:55 -070084 if (write && ret == 0)
85 ret = tcp_set_default_congestion_control(val);
86 return ret;
87}
88
Stephen Hemminger3ff825b2006-11-09 16:32:06 -080089static int proc_tcp_available_congestion_control(ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070090 int write,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -080091 void __user *buffer, size_t *lenp,
92 loff_t *ppos)
93{
94 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
95 int ret;
96
97 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98 if (!tbl.data)
99 return -ENOMEM;
100 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700101 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800102 kfree(tbl.data);
103 return ret;
104}
105
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800106static int proc_allowed_congestion_control(ctl_table *ctl,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700107 int write,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800108 void __user *buffer, size_t *lenp,
109 loff_t *ppos)
110{
111 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
112 int ret;
113
114 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
115 if (!tbl.data)
116 return -ENOMEM;
117
118 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700119 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800120 if (write && ret == 0)
121 ret = tcp_set_allowed_congestion_control(tbl.data);
122 kfree(tbl.data);
123 return ret;
124}
125
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800126static struct ctl_table ipv4_table[] = {
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900127 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 .procname = "tcp_timestamps",
129 .data = &sysctl_tcp_timestamps,
130 .maxlen = sizeof(int),
131 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800132 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900134 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 .procname = "tcp_window_scaling",
136 .data = &sysctl_tcp_window_scaling,
137 .maxlen = sizeof(int),
138 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800139 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900141 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 .procname = "tcp_sack",
143 .data = &sysctl_tcp_sack,
144 .maxlen = sizeof(int),
145 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800146 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900148 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 .procname = "tcp_retrans_collapse",
150 .data = &sysctl_tcp_retrans_collapse,
151 .maxlen = sizeof(int),
152 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800153 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900155 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 .procname = "ip_default_ttl",
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900157 .data = &sysctl_ip_default_ttl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 .maxlen = sizeof(int),
159 .mode = 0644,
Eric Dumazet249fab72010-12-13 12:16:14 -0800160 .proc_handler = proc_dointvec_minmax,
161 .extra1 = &ip_ttl_min,
162 .extra2 = &ip_ttl_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900164 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 .procname = "ip_no_pmtu_disc",
166 .data = &ipv4_config.no_pmtu_disc,
167 .maxlen = sizeof(int),
168 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800169 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 },
171 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 .procname = "ip_nonlocal_bind",
173 .data = &sysctl_ip_nonlocal_bind,
174 .maxlen = sizeof(int),
175 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800176 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 },
178 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 .procname = "tcp_syn_retries",
180 .data = &sysctl_tcp_syn_retries,
181 .maxlen = sizeof(int),
182 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800183 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 },
185 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 .procname = "tcp_synack_retries",
187 .data = &sysctl_tcp_synack_retries,
188 .maxlen = sizeof(int),
189 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800190 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 },
192 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 .procname = "tcp_max_orphans",
194 .data = &sysctl_tcp_max_orphans,
195 .maxlen = sizeof(int),
196 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800197 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 },
199 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 .procname = "tcp_max_tw_buckets",
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -0700201 .data = &tcp_death_row.sysctl_max_tw_buckets,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 .maxlen = sizeof(int),
203 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800204 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 },
206 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 .procname = "ip_dynaddr",
208 .data = &sysctl_ip_dynaddr,
209 .maxlen = sizeof(int),
210 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800211 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 },
213 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 .procname = "tcp_keepalive_time",
215 .data = &sysctl_tcp_keepalive_time,
216 .maxlen = sizeof(int),
217 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800218 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 },
220 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 .procname = "tcp_keepalive_probes",
222 .data = &sysctl_tcp_keepalive_probes,
223 .maxlen = sizeof(int),
224 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800225 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 },
227 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 .procname = "tcp_keepalive_intvl",
229 .data = &sysctl_tcp_keepalive_intvl,
230 .maxlen = sizeof(int),
231 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800232 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 },
234 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 .procname = "tcp_retries1",
236 .data = &sysctl_tcp_retries1,
237 .maxlen = sizeof(int),
238 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800239 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 .extra2 = &tcp_retr1_max
241 },
242 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 .procname = "tcp_retries2",
244 .data = &sysctl_tcp_retries2,
245 .maxlen = sizeof(int),
246 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800247 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 },
249 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 .procname = "tcp_fin_timeout",
251 .data = &sysctl_tcp_fin_timeout,
252 .maxlen = sizeof(int),
253 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800254 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 },
256#ifdef CONFIG_SYN_COOKIES
257 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 .procname = "tcp_syncookies",
259 .data = &sysctl_tcp_syncookies,
260 .maxlen = sizeof(int),
261 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800262 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 },
264#endif
265 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 .procname = "tcp_tw_recycle",
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -0700267 .data = &tcp_death_row.sysctl_tw_recycle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 .maxlen = sizeof(int),
269 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800270 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 },
272 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 .procname = "tcp_abort_on_overflow",
274 .data = &sysctl_tcp_abort_on_overflow,
275 .maxlen = sizeof(int),
276 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800277 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 },
279 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 .procname = "tcp_stdurg",
281 .data = &sysctl_tcp_stdurg,
282 .maxlen = sizeof(int),
283 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800284 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 },
286 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 .procname = "tcp_rfc1337",
288 .data = &sysctl_tcp_rfc1337,
289 .maxlen = sizeof(int),
290 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800291 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 },
293 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 .procname = "tcp_max_syn_backlog",
295 .data = &sysctl_max_syn_backlog,
296 .maxlen = sizeof(int),
297 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800298 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 },
300 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 .procname = "ip_local_port_range",
Eric Dumazet3c689b72008-10-08 14:18:04 -0700302 .data = &sysctl_local_ports.range,
303 .maxlen = sizeof(sysctl_local_ports.range),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800305 .proc_handler = ipv4_local_port_range,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 },
Amerigo Wange3826f12010-05-05 00:27:06 +0000307 {
308 .procname = "ip_local_reserved_ports",
309 .data = NULL, /* initialized in sysctl_ipv4_init */
310 .maxlen = 65536,
311 .mode = 0644,
312 .proc_handler = proc_do_large_bitmap,
313 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 .procname = "igmp_max_memberships",
316 .data = &sysctl_igmp_max_memberships,
317 .maxlen = sizeof(int),
318 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800319 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 .procname = "igmp_max_msf",
323 .data = &sysctl_igmp_max_msf,
324 .maxlen = sizeof(int),
325 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800326 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 },
328 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 .procname = "inet_peer_threshold",
330 .data = &inet_peer_threshold,
331 .maxlen = sizeof(int),
332 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800333 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 },
335 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 .procname = "inet_peer_minttl",
337 .data = &inet_peer_minttl,
338 .maxlen = sizeof(int),
339 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800340 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 },
342 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 .procname = "inet_peer_maxttl",
344 .data = &inet_peer_maxttl,
345 .maxlen = sizeof(int),
346 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800347 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 },
349 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 .procname = "inet_peer_gc_mintime",
351 .data = &inet_peer_gc_mintime,
352 .maxlen = sizeof(int),
353 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800354 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 },
356 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 .procname = "inet_peer_gc_maxtime",
358 .data = &inet_peer_gc_maxtime,
359 .maxlen = sizeof(int),
360 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800361 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 },
363 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 .procname = "tcp_orphan_retries",
365 .data = &sysctl_tcp_orphan_retries,
366 .maxlen = sizeof(int),
367 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800368 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 },
370 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 .procname = "tcp_fack",
372 .data = &sysctl_tcp_fack,
373 .maxlen = sizeof(int),
374 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800375 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 },
377 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 .procname = "tcp_reordering",
379 .data = &sysctl_tcp_reordering,
380 .maxlen = sizeof(int),
381 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800382 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 },
384 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 .procname = "tcp_ecn",
386 .data = &sysctl_tcp_ecn,
387 .maxlen = sizeof(int),
388 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800389 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 },
391 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 .procname = "tcp_dsack",
393 .data = &sysctl_tcp_dsack,
394 .maxlen = sizeof(int),
395 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800396 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 },
398 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 .procname = "tcp_mem",
400 .data = &sysctl_tcp_mem,
401 .maxlen = sizeof(sysctl_tcp_mem),
402 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +0000403 .proc_handler = proc_doulongvec_minmax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 },
405 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 .procname = "tcp_wmem",
407 .data = &sysctl_tcp_wmem,
408 .maxlen = sizeof(sysctl_tcp_wmem),
409 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800410 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 },
412 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 .procname = "tcp_rmem",
414 .data = &sysctl_tcp_rmem,
415 .maxlen = sizeof(sysctl_tcp_rmem),
416 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800417 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 },
419 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 .procname = "tcp_app_win",
421 .data = &sysctl_tcp_app_win,
422 .maxlen = sizeof(int),
423 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800424 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 },
426 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 .procname = "tcp_adv_win_scale",
428 .data = &sysctl_tcp_adv_win_scale,
429 .maxlen = sizeof(int),
430 .mode = 0644,
Alexey Dobriyan0147fc02010-11-22 12:54:21 +0000431 .proc_handler = proc_dointvec_minmax,
432 .extra1 = &tcp_adv_win_scale_min,
433 .extra2 = &tcp_adv_win_scale_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 },
435 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 .procname = "tcp_tw_reuse",
437 .data = &sysctl_tcp_tw_reuse,
438 .maxlen = sizeof(int),
439 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800440 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 },
442 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 .procname = "tcp_frto",
444 .data = &sysctl_tcp_frto,
445 .maxlen = sizeof(int),
446 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800447 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 },
449 {
Ilpo Järvinen3cfe3ba2007-02-27 10:09:49 -0800450 .procname = "tcp_frto_response",
451 .data = &sysctl_tcp_frto_response,
452 .maxlen = sizeof(int),
453 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800454 .proc_handler = proc_dointvec
Ilpo Järvinen3cfe3ba2007-02-27 10:09:49 -0800455 },
456 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 .procname = "tcp_low_latency",
458 .data = &sysctl_tcp_low_latency,
459 .maxlen = sizeof(int),
460 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800461 .proc_handler = proc_dointvec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 },
463 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 .procname = "tcp_no_metrics_save",
465 .data = &sysctl_tcp_nometrics_save,
466 .maxlen = sizeof(int),
467 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800468 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 },
470 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 .procname = "tcp_moderate_rcvbuf",
472 .data = &sysctl_tcp_moderate_rcvbuf,
473 .maxlen = sizeof(int),
474 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800475 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 },
477 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 .procname = "tcp_tso_win_divisor",
479 .data = &sysctl_tcp_tso_win_divisor,
480 .maxlen = sizeof(int),
481 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800482 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 },
484 {
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700485 .procname = "tcp_congestion_control",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 .mode = 0644,
Stephen Hemminger317a76f2005-06-23 12:19:55 -0700487 .maxlen = TCP_CA_NAME_MAX,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800488 .proc_handler = proc_tcp_congestion_control,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 },
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800490 {
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800491 .procname = "tcp_abc",
492 .data = &sysctl_tcp_abc,
493 .maxlen = sizeof(int),
494 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800495 .proc_handler = proc_dointvec,
Stephen Hemminger9772efb2005-11-10 17:09:53 -0800496 },
John Heffner5d424d52006-03-20 17:53:41 -0800497 {
John Heffner5d424d52006-03-20 17:53:41 -0800498 .procname = "tcp_mtu_probing",
499 .data = &sysctl_tcp_mtu_probing,
500 .maxlen = sizeof(int),
501 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800502 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800503 },
504 {
John Heffner5d424d52006-03-20 17:53:41 -0800505 .procname = "tcp_base_mss",
506 .data = &sysctl_tcp_base_mss,
507 .maxlen = sizeof(int),
508 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800509 .proc_handler = proc_dointvec,
John Heffner5d424d52006-03-20 17:53:41 -0800510 },
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900511 {
Rick Jones15d99e02006-03-20 22:40:29 -0800512 .procname = "tcp_workaround_signed_windows",
513 .data = &sysctl_tcp_workaround_signed_windows,
514 .maxlen = sizeof(int),
515 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800516 .proc_handler = proc_dointvec
Rick Jones15d99e02006-03-20 22:40:29 -0800517 },
Chris Leech95937822006-05-23 18:02:55 -0700518#ifdef CONFIG_NET_DMA
519 {
Chris Leech95937822006-05-23 18:02:55 -0700520 .procname = "tcp_dma_copybreak",
521 .data = &sysctl_tcp_dma_copybreak,
522 .maxlen = sizeof(int),
523 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800524 .proc_handler = proc_dointvec
Chris Leech95937822006-05-23 18:02:55 -0700525 },
526#endif
David S. Miller35089bb2006-06-13 22:33:04 -0700527 {
David S. Miller35089bb2006-06-13 22:33:04 -0700528 .procname = "tcp_slow_start_after_idle",
529 .data = &sysctl_tcp_slow_start_after_idle,
530 .maxlen = sizeof(int),
531 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800532 .proc_handler = proc_dointvec
David S. Miller35089bb2006-06-13 22:33:04 -0700533 },
Paul Moore446fda42006-08-03 16:48:06 -0700534#ifdef CONFIG_NETLABEL
535 {
Paul Moore446fda42006-08-03 16:48:06 -0700536 .procname = "cipso_cache_enable",
537 .data = &cipso_v4_cache_enabled,
538 .maxlen = sizeof(int),
539 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800540 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700541 },
542 {
Paul Moore446fda42006-08-03 16:48:06 -0700543 .procname = "cipso_cache_bucket_size",
544 .data = &cipso_v4_cache_bucketsize,
545 .maxlen = sizeof(int),
546 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800547 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700548 },
549 {
Paul Moore446fda42006-08-03 16:48:06 -0700550 .procname = "cipso_rbm_optfmt",
551 .data = &cipso_v4_rbm_optfmt,
552 .maxlen = sizeof(int),
553 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800554 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700555 },
556 {
Paul Moore446fda42006-08-03 16:48:06 -0700557 .procname = "cipso_rbm_strictvalid",
558 .data = &cipso_v4_rbm_strictvalid,
559 .maxlen = sizeof(int),
560 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800561 .proc_handler = proc_dointvec,
Paul Moore446fda42006-08-03 16:48:06 -0700562 },
563#endif /* CONFIG_NETLABEL */
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800564 {
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800565 .procname = "tcp_available_congestion_control",
566 .maxlen = TCP_CA_BUF_MAX,
567 .mode = 0444,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800568 .proc_handler = proc_tcp_available_congestion_control,
Stephen Hemminger3ff825b2006-11-09 16:32:06 -0800569 },
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800570 {
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800571 .procname = "tcp_allowed_congestion_control",
572 .maxlen = TCP_CA_BUF_MAX,
573 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800574 .proc_handler = proc_allowed_congestion_control,
Stephen Hemmingerce7bc3b2006-11-09 16:35:15 -0800575 },
John Heffner886236c2007-03-25 19:21:45 -0700576 {
John Heffner886236c2007-03-25 19:21:45 -0700577 .procname = "tcp_max_ssthresh",
578 .data = &sysctl_tcp_max_ssthresh,
579 .maxlen = sizeof(int),
580 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800581 .proc_handler = proc_dointvec,
John Heffner886236c2007-03-25 19:21:45 -0700582 },
Hideo Aoki95766ff2007-12-31 00:29:24 -0800583 {
William Allen Simpson519855c2009-12-02 18:14:19 +0000584 .procname = "tcp_cookie_size",
585 .data = &sysctl_tcp_cookie_size,
586 .maxlen = sizeof(int),
587 .mode = 0644,
588 .proc_handler = proc_dointvec
589 },
590 {
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000591 .procname = "tcp_thin_linear_timeouts",
592 .data = &sysctl_tcp_thin_linear_timeouts,
593 .maxlen = sizeof(int),
594 .mode = 0644,
595 .proc_handler = proc_dointvec
596 },
Andreas Petlund7e380172010-02-18 04:48:19 +0000597 {
598 .procname = "tcp_thin_dupack",
599 .data = &sysctl_tcp_thin_dupack,
600 .maxlen = sizeof(int),
601 .mode = 0644,
602 .proc_handler = proc_dointvec
603 },
Andreas Petlund36e31b0a2010-02-18 02:47:01 +0000604 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800605 .procname = "udp_mem",
606 .data = &sysctl_udp_mem,
607 .maxlen = sizeof(sysctl_udp_mem),
608 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +0000609 .proc_handler = proc_doulongvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800610 },
611 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800612 .procname = "udp_rmem_min",
613 .data = &sysctl_udp_rmem_min,
614 .maxlen = sizeof(sysctl_udp_rmem_min),
615 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800616 .proc_handler = proc_dointvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800617 .extra1 = &zero
618 },
619 {
Hideo Aoki95766ff2007-12-31 00:29:24 -0800620 .procname = "udp_wmem_min",
621 .data = &sysctl_udp_wmem_min,
622 .maxlen = sizeof(sysctl_udp_wmem_min),
623 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800624 .proc_handler = proc_dointvec_minmax,
Hideo Aoki95766ff2007-12-31 00:29:24 -0800625 .extra1 = &zero
626 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800627 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628};
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800629
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700630static struct ctl_table ipv4_net_table[] = {
631 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700632 .procname = "icmp_echo_ignore_all",
633 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
634 .maxlen = sizeof(int),
635 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800636 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700637 },
638 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700639 .procname = "icmp_echo_ignore_broadcasts",
640 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
641 .maxlen = sizeof(int),
642 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800643 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700644 },
645 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700646 .procname = "icmp_ignore_bogus_error_responses",
647 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
648 .maxlen = sizeof(int),
649 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800650 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700651 },
652 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700653 .procname = "icmp_errors_use_inbound_ifaddr",
654 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
655 .maxlen = sizeof(int),
656 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800657 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700658 },
659 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700660 .procname = "icmp_ratelimit",
661 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
662 .maxlen = sizeof(int),
663 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800664 .proc_handler = proc_dointvec_ms_jiffies,
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700665 },
666 {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700667 .procname = "icmp_ratemask",
668 .data = &init_net.ipv4.sysctl_icmp_ratemask,
669 .maxlen = sizeof(int),
670 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800671 .proc_handler = proc_dointvec
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700672 },
Neil Horman1080d702008-10-27 12:28:25 -0700673 {
Neil Horman1080d702008-10-27 12:28:25 -0700674 .procname = "rt_cache_rebuild_count",
675 .data = &init_net.ipv4.sysctl_rt_cache_rebuild_count,
676 .maxlen = sizeof(int),
677 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800678 .proc_handler = proc_dointvec
Neil Horman1080d702008-10-27 12:28:25 -0700679 },
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700680 { }
681};
682
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800683struct ctl_path net_ipv4_ctl_path[] = {
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800684 { .procname = "net", },
685 { .procname = "ipv4", },
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800686 { },
687};
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800688EXPORT_SYMBOL_GPL(net_ipv4_ctl_path);
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800689
Pavel Emelyanov15775192008-03-26 01:54:18 -0700690static __net_init int ipv4_sysctl_init_net(struct net *net)
691{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700692 struct ctl_table *table;
693
694 table = ipv4_net_table;
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800695 if (!net_eq(net, &init_net)) {
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700696 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
697 if (table == NULL)
698 goto err_alloc;
699
700 table[0].data =
701 &net->ipv4.sysctl_icmp_echo_ignore_all;
702 table[1].data =
703 &net->ipv4.sysctl_icmp_echo_ignore_broadcasts;
704 table[2].data =
705 &net->ipv4.sysctl_icmp_ignore_bogus_error_responses;
706 table[3].data =
707 &net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr;
708 table[4].data =
709 &net->ipv4.sysctl_icmp_ratelimit;
710 table[5].data =
711 &net->ipv4.sysctl_icmp_ratemask;
Neil Horman1080d702008-10-27 12:28:25 -0700712 table[6].data =
713 &net->ipv4.sysctl_rt_cache_rebuild_count;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700714 }
715
Neil Horman1080d702008-10-27 12:28:25 -0700716 net->ipv4.sysctl_rt_cache_rebuild_count = 4;
717
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700718 net->ipv4.ipv4_hdr = register_net_sysctl_table(net,
719 net_ipv4_ctl_path, table);
720 if (net->ipv4.ipv4_hdr == NULL)
721 goto err_reg;
722
Pavel Emelyanov15775192008-03-26 01:54:18 -0700723 return 0;
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700724
725err_reg:
Octavian Purdila09ad9bc2009-11-25 15:14:13 -0800726 if (!net_eq(net, &init_net))
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700727 kfree(table);
728err_alloc:
729 return -ENOMEM;
Pavel Emelyanov15775192008-03-26 01:54:18 -0700730}
731
732static __net_exit void ipv4_sysctl_exit_net(struct net *net)
733{
Pavel Emelyanov68528f02008-03-26 01:56:24 -0700734 struct ctl_table *table;
735
736 table = net->ipv4.ipv4_hdr->ctl_table_arg;
737 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
738 kfree(table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700739}
740
741static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
742 .init = ipv4_sysctl_init_net,
743 .exit = ipv4_sysctl_exit_net,
744};
745
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800746static __init int sysctl_ipv4_init(void)
747{
748 struct ctl_table_header *hdr;
Amerigo Wange3826f12010-05-05 00:27:06 +0000749 struct ctl_table *i;
750
751 for (i = ipv4_table; i->procname; i++) {
752 if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
753 i->data = sysctl_local_reserved_ports;
754 break;
755 }
756 }
757 if (!i->procname)
758 return -EINVAL;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800759
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -0800760 hdr = register_sysctl_paths(net_ipv4_ctl_path, ipv4_table);
Pavel Emelyanov15775192008-03-26 01:54:18 -0700761 if (hdr == NULL)
762 return -ENOMEM;
763
764 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
765 unregister_sysctl_table(hdr);
766 return -ENOMEM;
767 }
768
769 return 0;
Pavel Emelyanov3e37c3f2007-12-05 01:41:26 -0800770}
771
772__initcall(sysctl_ipv4_init);