1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
4 *
5 * Begun April 1, 1996, Mike Shaver.
6 * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
7 */
8
9 #include <linux/sysctl.h>
10 #include <linux/seqlock.h>
11 #include <linux/init.h>
12 #include <linux/slab.h>
13 #include <net/icmp.h>
14 #include <net/ip.h>
15 #include <net/ip_fib.h>
16 #include <net/tcp.h>
17 #include <net/udp.h>
18 #include <net/cipso_ipv4.h>
19 #include <net/ping.h>
20 #include <net/protocol.h>
21 #include <net/netevent.h>
22
23 static int tcp_retr1_max = 255;
24 static int ip_local_port_range_min[] = { 1, 1 };
25 static int ip_local_port_range_max[] = { 65535, 65535 };
26 static int tcp_adv_win_scale_min = -31;
27 static int tcp_adv_win_scale_max = 31;
28 static int tcp_app_win_max = 31;
29 static int tcp_min_snd_mss_min = TCP_MIN_SND_MSS;
30 static int tcp_min_snd_mss_max = 65535;
31 static int tcp_rto_max_max = TCP_RTO_MAX_SEC * MSEC_PER_SEC;
32 static int ip_privileged_port_min;
33 static int ip_privileged_port_max = 65535;
34 static int ip_ttl_min = 1;
35 static int ip_ttl_max = 255;
36 static int tcp_syn_retries_min = 1;
37 static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
38 static int tcp_syn_linear_timeouts_max = MAX_TCP_SYNCNT;
39 static unsigned long ip_ping_group_range_min[] = { 0, 0 };
40 static unsigned long ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
41 static u32 u32_max_div_HZ = UINT_MAX / HZ;
42 static int one_day_secs = 24 * 3600;
43 static u32 fib_multipath_hash_fields_all_mask __maybe_unused =
44 FIB_MULTIPATH_HASH_FIELD_ALL_MASK;
45 static unsigned int tcp_child_ehash_entries_max = 16 * 1024 * 1024;
46 static unsigned int udp_child_hash_entries_max = UDP_HTABLE_SIZE_MAX;
47 static int tcp_plb_max_rounds = 31;
48 static int tcp_plb_max_cong_thresh = 256;
49 static unsigned int tcp_tw_reuse_delay_max = TCP_PAWS_MSL * MSEC_PER_SEC;
50 static int tcp_ecn_mode_max = 5;
51 static u32 icmp_errors_extension_mask_all =
52 GENMASK_U8(ICMP_ERR_EXT_COUNT - 1, 0);
53
54 /* obsolete */
55 static int sysctl_tcp_low_latency __read_mostly;
56
57 /* Update system visible IP port range */
set_local_port_range(struct net * net,unsigned int low,unsigned int high)58 static void set_local_port_range(struct net *net, unsigned int low, unsigned int high)
59 {
60 bool same_parity = !((low ^ high) & 1);
61
62 if (same_parity && !net->ipv4.ip_local_ports.warned) {
63 net->ipv4.ip_local_ports.warned = true;
64 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
65 }
66 WRITE_ONCE(net->ipv4.ip_local_ports.range, high << 16 | low);
67 }
68
69 /* Validate changes from /proc interface. */
ipv4_local_port_range(const struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)70 static int ipv4_local_port_range(const struct ctl_table *table, int write,
71 void *buffer, size_t *lenp, loff_t *ppos)
72 {
73 struct net *net = table->data;
74 int ret;
75 int range[2];
76 struct ctl_table tmp = {
77 .data = &range,
78 .maxlen = sizeof(range),
79 .mode = table->mode,
80 .extra1 = &ip_local_port_range_min,
81 .extra2 = &ip_local_port_range_max,
82 };
83
84 inet_get_local_port_range(net, &range[0], &range[1]);
85
86 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
87
88 if (write && ret == 0) {
89 /* Ensure that the upper limit is not smaller than the lower,
90 * and that the lower does not encroach upon the privileged
91 * port limit.
92 */
93 if ((range[1] < range[0]) ||
94 (range[0] < READ_ONCE(net->ipv4.sysctl_ip_prot_sock)))
95 ret = -EINVAL;
96 else
97 set_local_port_range(net, range[0], range[1]);
98 }
99
100 return ret;
101 }
102
103 /* Validate changes from /proc interface. */
ipv4_privileged_ports(const struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)104 static int ipv4_privileged_ports(const struct ctl_table *table, int write,
105 void *buffer, size_t *lenp, loff_t *ppos)
106 {
107 struct net *net = container_of(table->data, struct net,
108 ipv4.sysctl_ip_prot_sock);
109 int ret;
110 int pports;
111 int range[2];
112 struct ctl_table tmp = {
113 .data = &pports,
114 .maxlen = sizeof(pports),
115 .mode = table->mode,
116 .extra1 = &ip_privileged_port_min,
117 .extra2 = &ip_privileged_port_max,
118 };
119
120 pports = READ_ONCE(net->ipv4.sysctl_ip_prot_sock);
121
122 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
123
124 if (write && ret == 0) {
125 inet_get_local_port_range(net, &range[0], &range[1]);
126 /* Ensure that the local port range doesn't overlap with the
127 * privileged port range.
128 */
129 if (range[0] < pports)
130 ret = -EINVAL;
131 else
132 WRITE_ONCE(net->ipv4.sysctl_ip_prot_sock, pports);
133 }
134
135 return ret;
136 }
137
inet_get_ping_group_range_table(const struct ctl_table * table,kgid_t * low,kgid_t * high)138 static void inet_get_ping_group_range_table(const struct ctl_table *table,
139 kgid_t *low, kgid_t *high)
140 {
141 kgid_t *data = table->data;
142 struct net *net =
143 container_of(table->data, struct net, ipv4.ping_group_range.range);
144 unsigned int seq;
145 do {
146 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
147
148 *low = data[0];
149 *high = data[1];
150 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
151 }
152
153 /* Update system visible IP port range */
set_ping_group_range(const struct ctl_table * table,kgid_t low,kgid_t high)154 static void set_ping_group_range(const struct ctl_table *table,
155 kgid_t low, kgid_t high)
156 {
157 kgid_t *data = table->data;
158 struct net *net =
159 container_of(table->data, struct net, ipv4.ping_group_range.range);
160 write_seqlock(&net->ipv4.ping_group_range.lock);
161 data[0] = low;
162 data[1] = high;
163 write_sequnlock(&net->ipv4.ping_group_range.lock);
164 }
165
166 /* Validate changes from /proc interface. */
ipv4_ping_group_range(const struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)167 static int ipv4_ping_group_range(const struct ctl_table *table, int write,
168 void *buffer, size_t *lenp, loff_t *ppos)
169 {
170 struct user_namespace *user_ns = current_user_ns();
171 int ret;
172 unsigned long urange[2];
173 kgid_t low, high;
174 struct ctl_table tmp = {
175 .data = &urange,
176 .maxlen = sizeof(urange),
177 .mode = table->mode,
178 .extra1 = &ip_ping_group_range_min,
179 .extra2 = &ip_ping_group_range_max,
180 };
181
182 inet_get_ping_group_range_table(table, &low, &high);
183 urange[0] = from_kgid_munged(user_ns, low);
184 urange[1] = from_kgid_munged(user_ns, high);
185 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
186
187 if (write && ret == 0) {
188 low = make_kgid(user_ns, urange[0]);
189 high = make_kgid(user_ns, urange[1]);
190 if (!gid_valid(low) || !gid_valid(high))
191 return -EINVAL;
192 if (urange[1] < urange[0] || gid_lt(high, low)) {
193 low = make_kgid(&init_user_ns, 1);
194 high = make_kgid(&init_user_ns, 0);
195 }
196 set_ping_group_range(table, low, high);
197 }
198
199 return ret;
200 }
201
ipv4_fwd_update_priority(const struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)202 static int ipv4_fwd_update_priority(const struct ctl_table *table, int write,
203 void *buffer, size_t *lenp, loff_t *ppos)
204 {
205 struct net *net;
206 int ret;
207
208 net = container_of(table->data, struct net,
209 ipv4.sysctl_ip_fwd_update_priority);
210 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
211 if (write && ret == 0)
212 call_netevent_notifiers(NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE,
213 net);
214
215 return ret;
216 }
217
proc_tcp_congestion_control(const struct ctl_table * ctl,int write,void * buffer,size_t * lenp,loff_t * ppos)218 static int proc_tcp_congestion_control(const struct ctl_table *ctl, int write,
219 void *buffer, size_t *lenp, loff_t *ppos)
220 {
221 struct net *net = container_of(ctl->data, struct net,
222 ipv4.tcp_congestion_control);
223 char val[TCP_CA_NAME_MAX];
224 struct ctl_table tbl = {
225 .data = val,
226 .maxlen = TCP_CA_NAME_MAX,
227 };
228 int ret;
229
230 tcp_get_default_congestion_control(net, val);
231
232 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
233 if (write && ret == 0)
234 ret = tcp_set_default_congestion_control(net, val);
235 return ret;
236 }
237
proc_tcp_available_congestion_control(const struct ctl_table * ctl,int write,void * buffer,size_t * lenp,loff_t * ppos)238 static int proc_tcp_available_congestion_control(const struct ctl_table *ctl,
239 int write, void *buffer,
240 size_t *lenp, loff_t *ppos)
241 {
242 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
243 int ret;
244
245 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
246 if (!tbl.data)
247 return -ENOMEM;
248 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
249 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
250 kfree(tbl.data);
251 return ret;
252 }
253
proc_allowed_congestion_control(const struct ctl_table * ctl,int write,void * buffer,size_t * lenp,loff_t * ppos)254 static int proc_allowed_congestion_control(const struct ctl_table *ctl,
255 int write, void *buffer,
256 size_t *lenp, loff_t *ppos)
257 {
258 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
259 int ret;
260
261 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
262 if (!tbl.data)
263 return -ENOMEM;
264
265 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
266 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
267 if (write && ret == 0)
268 ret = tcp_set_allowed_congestion_control(tbl.data);
269 kfree(tbl.data);
270 return ret;
271 }
272
sscanf_key(char * buf,__le32 * key)273 static int sscanf_key(char *buf, __le32 *key)
274 {
275 u32 user_key[4];
276 int i, ret = 0;
277
278 if (sscanf(buf, "%x-%x-%x-%x", user_key, user_key + 1,
279 user_key + 2, user_key + 3) != 4) {
280 ret = -EINVAL;
281 } else {
282 for (i = 0; i < ARRAY_SIZE(user_key); i++)
283 key[i] = cpu_to_le32(user_key[i]);
284 }
285 pr_debug("proc TFO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
286 user_key[0], user_key[1], user_key[2], user_key[3], buf, ret);
287
288 return ret;
289 }
290
proc_tcp_fastopen_key(const struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)291 static int proc_tcp_fastopen_key(const struct ctl_table *table, int write,
292 void *buffer, size_t *lenp, loff_t *ppos)
293 {
294 struct net *net = container_of(table->data, struct net,
295 ipv4.sysctl_tcp_fastopen);
296 /* maxlen to print the list of keys in hex (*2), with dashes
297 * separating doublewords and a comma in between keys.
298 */
299 struct ctl_table tbl = { .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
300 2 * TCP_FASTOPEN_KEY_MAX) +
301 (TCP_FASTOPEN_KEY_MAX * 5)) };
302 u32 user_key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(u32)];
303 __le32 key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(__le32)];
304 char *backup_data;
305 int ret, i = 0, off = 0, n_keys;
306
307 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
308 if (!tbl.data)
309 return -ENOMEM;
310
311 n_keys = tcp_fastopen_get_cipher(net, NULL, (u64 *)key);
312 if (!n_keys) {
313 memset(&key[0], 0, TCP_FASTOPEN_KEY_LENGTH);
314 n_keys = 1;
315 }
316
317 for (i = 0; i < n_keys * 4; i++)
318 user_key[i] = le32_to_cpu(key[i]);
319
320 for (i = 0; i < n_keys; i++) {
321 off += snprintf(tbl.data + off, tbl.maxlen - off,
322 "%08x-%08x-%08x-%08x",
323 user_key[i * 4],
324 user_key[i * 4 + 1],
325 user_key[i * 4 + 2],
326 user_key[i * 4 + 3]);
327
328 if (WARN_ON_ONCE(off >= tbl.maxlen - 1))
329 break;
330
331 if (i + 1 < n_keys)
332 off += snprintf(tbl.data + off, tbl.maxlen - off, ",");
333 }
334
335 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
336
337 if (write && ret == 0) {
338 backup_data = strchr(tbl.data, ',');
339 if (backup_data) {
340 *backup_data = '\0';
341 backup_data++;
342 }
343 if (sscanf_key(tbl.data, key)) {
344 ret = -EINVAL;
345 goto bad_key;
346 }
347 if (backup_data) {
348 if (sscanf_key(backup_data, key + 4)) {
349 ret = -EINVAL;
350 goto bad_key;
351 }
352 }
353 tcp_fastopen_reset_cipher(net, NULL, key,
354 backup_data ? key + 4 : NULL);
355 }
356
357 bad_key:
358 kfree(tbl.data);
359 return ret;
360 }
361
proc_tfo_blackhole_detect_timeout(const struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)362 static int proc_tfo_blackhole_detect_timeout(const struct ctl_table *table,
363 int write, void *buffer,
364 size_t *lenp, loff_t *ppos)
365 {
366 struct net *net = container_of(table->data, struct net,
367 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
368 int ret;
369
370 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
371 if (write && ret == 0)
372 atomic_set(&net->ipv4.tfo_active_disable_times, 0);
373
374 return ret;
375 }
376
proc_tcp_available_ulp(const struct ctl_table * ctl,int write,void * buffer,size_t * lenp,loff_t * ppos)377 static int proc_tcp_available_ulp(const struct ctl_table *ctl,
378 int write, void *buffer, size_t *lenp,
379 loff_t *ppos)
380 {
381 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
382 int ret;
383
384 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
385 if (!tbl.data)
386 return -ENOMEM;
387 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
388 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
389 kfree(tbl.data);
390
391 return ret;
392 }
393
proc_tcp_ehash_entries(const struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)394 static int proc_tcp_ehash_entries(const struct ctl_table *table, int write,
395 void *buffer, size_t *lenp, loff_t *ppos)
396 {
397 struct net *net = container_of(table->data, struct net,
398 ipv4.sysctl_tcp_child_ehash_entries);
399 struct inet_hashinfo *hinfo = net->ipv4.tcp_death_row.hashinfo;
400 int tcp_ehash_entries;
401 struct ctl_table tbl;
402
403 tcp_ehash_entries = hinfo->ehash_mask + 1;
404
405 /* A negative number indicates that the child netns
406 * shares the global ehash.
407 */
408 if (!net_eq(net, &init_net) && !hinfo->pernet)
409 tcp_ehash_entries *= -1;
410
411 memset(&tbl, 0, sizeof(tbl));
412 tbl.data = &tcp_ehash_entries;
413 tbl.maxlen = sizeof(int);
414
415 return proc_dointvec(&tbl, write, buffer, lenp, ppos);
416 }
417
proc_udp_hash_entries(const struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)418 static int proc_udp_hash_entries(const struct ctl_table *table, int write,
419 void *buffer, size_t *lenp, loff_t *ppos)
420 {
421 struct net *net = container_of(table->data, struct net,
422 ipv4.sysctl_udp_child_hash_entries);
423 int udp_hash_entries;
424 struct ctl_table tbl;
425
426 udp_hash_entries = net->ipv4.udp_table->mask + 1;
427
428 /* A negative number indicates that the child netns
429 * shares the global udp_table.
430 */
431 if (!net_eq(net, &init_net) && net->ipv4.udp_table == &udp_table)
432 udp_hash_entries *= -1;
433
434 memset(&tbl, 0, sizeof(tbl));
435 tbl.data = &udp_hash_entries;
436 tbl.maxlen = sizeof(int);
437
438 return proc_dointvec(&tbl, write, buffer, lenp, ppos);
439 }
440
441 #ifdef CONFIG_IP_ROUTE_MULTIPATH
proc_fib_multipath_hash_policy(const struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)442 static int proc_fib_multipath_hash_policy(const struct ctl_table *table, int write,
443 void *buffer, size_t *lenp,
444 loff_t *ppos)
445 {
446 struct net *net = container_of(table->data, struct net,
447 ipv4.sysctl_fib_multipath_hash_policy);
448 int ret;
449
450 ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
451 if (write && ret == 0)
452 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
453
454 return ret;
455 }
456
proc_fib_multipath_hash_fields(const struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)457 static int proc_fib_multipath_hash_fields(const struct ctl_table *table, int write,
458 void *buffer, size_t *lenp,
459 loff_t *ppos)
460 {
461 struct net *net;
462 int ret;
463
464 net = container_of(table->data, struct net,
465 ipv4.sysctl_fib_multipath_hash_fields);
466 ret = proc_douintvec_minmax(table, write, buffer, lenp, ppos);
467 if (write && ret == 0)
468 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
469
470 return ret;
471 }
472
473 static u32 proc_fib_multipath_hash_rand_seed __ro_after_init;
474
proc_fib_multipath_hash_init_rand_seed(void)475 static void proc_fib_multipath_hash_init_rand_seed(void)
476 {
477 get_random_bytes(&proc_fib_multipath_hash_rand_seed,
478 sizeof(proc_fib_multipath_hash_rand_seed));
479 }
480
proc_fib_multipath_hash_set_seed(struct net * net,u32 user_seed)481 static void proc_fib_multipath_hash_set_seed(struct net *net, u32 user_seed)
482 {
483 struct sysctl_fib_multipath_hash_seed new = {
484 .user_seed = user_seed,
485 .mp_seed = (user_seed ? user_seed :
486 proc_fib_multipath_hash_rand_seed),
487 };
488
489 WRITE_ONCE(net->ipv4.sysctl_fib_multipath_hash_seed.user_seed, new.user_seed);
490 WRITE_ONCE(net->ipv4.sysctl_fib_multipath_hash_seed.mp_seed, new.mp_seed);
491 }
492
proc_fib_multipath_hash_seed(const struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)493 static int proc_fib_multipath_hash_seed(const struct ctl_table *table, int write,
494 void *buffer, size_t *lenp,
495 loff_t *ppos)
496 {
497 struct sysctl_fib_multipath_hash_seed *mphs;
498 struct net *net = table->data;
499 struct ctl_table tmp;
500 u32 user_seed;
501 int ret;
502
503 mphs = &net->ipv4.sysctl_fib_multipath_hash_seed;
504 user_seed = READ_ONCE(mphs->user_seed);
505
506 tmp = *table;
507 tmp.data = &user_seed;
508
509 ret = proc_douintvec_minmax(&tmp, write, buffer, lenp, ppos);
510
511 if (write && ret == 0) {
512 proc_fib_multipath_hash_set_seed(net, user_seed);
513 call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
514 }
515
516 return ret;
517 }
518 #else
519
proc_fib_multipath_hash_init_rand_seed(void)520 static void proc_fib_multipath_hash_init_rand_seed(void)
521 {
522 }
523
proc_fib_multipath_hash_set_seed(struct net * net,u32 user_seed)524 static void proc_fib_multipath_hash_set_seed(struct net *net, u32 user_seed)
525 {
526 }
527
528 #endif
529
530 static struct ctl_table ipv4_table[] = {
531 {
532 .procname = "tcp_max_orphans",
533 .data = &sysctl_tcp_max_orphans,
534 .maxlen = sizeof(int),
535 .mode = 0644,
536 .proc_handler = proc_dointvec
537 },
538 {
539 .procname = "inet_peer_threshold",
540 .data = &inet_peer_threshold,
541 .maxlen = sizeof(int),
542 .mode = 0644,
543 .proc_handler = proc_dointvec
544 },
545 {
546 .procname = "inet_peer_minttl",
547 .data = &inet_peer_minttl,
548 .maxlen = sizeof(int),
549 .mode = 0644,
550 .proc_handler = proc_dointvec_jiffies,
551 },
552 {
553 .procname = "inet_peer_maxttl",
554 .data = &inet_peer_maxttl,
555 .maxlen = sizeof(int),
556 .mode = 0644,
557 .proc_handler = proc_dointvec_jiffies,
558 },
559 {
560 .procname = "tcp_mem",
561 .maxlen = sizeof(sysctl_tcp_mem),
562 .data = &sysctl_tcp_mem,
563 .mode = 0644,
564 .proc_handler = proc_doulongvec_minmax,
565 },
566 {
567 .procname = "tcp_low_latency",
568 .data = &sysctl_tcp_low_latency,
569 .maxlen = sizeof(int),
570 .mode = 0644,
571 .proc_handler = proc_dointvec
572 },
573 #ifdef CONFIG_NETLABEL
574 {
575 .procname = "cipso_cache_enable",
576 .data = &cipso_v4_cache_enabled,
577 .maxlen = sizeof(int),
578 .mode = 0644,
579 .proc_handler = proc_dointvec,
580 },
581 {
582 .procname = "cipso_cache_bucket_size",
583 .data = &cipso_v4_cache_bucketsize,
584 .maxlen = sizeof(int),
585 .mode = 0644,
586 .proc_handler = proc_dointvec,
587 },
588 {
589 .procname = "cipso_rbm_optfmt",
590 .data = &cipso_v4_rbm_optfmt,
591 .maxlen = sizeof(int),
592 .mode = 0644,
593 .proc_handler = proc_dointvec,
594 },
595 {
596 .procname = "cipso_rbm_strictvalid",
597 .data = &cipso_v4_rbm_strictvalid,
598 .maxlen = sizeof(int),
599 .mode = 0644,
600 .proc_handler = proc_dointvec,
601 },
602 #endif /* CONFIG_NETLABEL */
603 {
604 .procname = "tcp_available_ulp",
605 .maxlen = TCP_ULP_BUF_MAX,
606 .mode = 0444,
607 .proc_handler = proc_tcp_available_ulp,
608 },
609 {
610 .procname = "udp_mem",
611 .data = &sysctl_udp_mem,
612 .maxlen = sizeof(sysctl_udp_mem),
613 .mode = 0644,
614 .proc_handler = proc_doulongvec_minmax,
615 },
616 {
617 .procname = "fib_sync_mem",
618 .data = &sysctl_fib_sync_mem,
619 .maxlen = sizeof(sysctl_fib_sync_mem),
620 .mode = 0644,
621 .proc_handler = proc_douintvec_minmax,
622 .extra1 = &sysctl_fib_sync_mem_min,
623 .extra2 = &sysctl_fib_sync_mem_max,
624 },
625 };
626
627 static const struct ctl_table ipv4_net_table[] = {
628 {
629 .procname = "tcp_max_tw_buckets",
630 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 .proc_handler = proc_dointvec
634 },
635 {
636 .procname = "icmp_echo_ignore_all",
637 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
638 .maxlen = sizeof(u8),
639 .mode = 0644,
640 .proc_handler = proc_dou8vec_minmax,
641 .extra1 = SYSCTL_ZERO,
642 .extra2 = SYSCTL_ONE
643 },
644 {
645 .procname = "icmp_echo_enable_probe",
646 .data = &init_net.ipv4.sysctl_icmp_echo_enable_probe,
647 .maxlen = sizeof(u8),
648 .mode = 0644,
649 .proc_handler = proc_dou8vec_minmax,
650 .extra1 = SYSCTL_ZERO,
651 .extra2 = SYSCTL_ONE
652 },
653 {
654 .procname = "icmp_echo_ignore_broadcasts",
655 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
656 .maxlen = sizeof(u8),
657 .mode = 0644,
658 .proc_handler = proc_dou8vec_minmax,
659 .extra1 = SYSCTL_ZERO,
660 .extra2 = SYSCTL_ONE
661 },
662 {
663 .procname = "icmp_ignore_bogus_error_responses",
664 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
665 .maxlen = sizeof(u8),
666 .mode = 0644,
667 .proc_handler = proc_dou8vec_minmax,
668 .extra1 = SYSCTL_ZERO,
669 .extra2 = SYSCTL_ONE
670 },
671 {
672 .procname = "icmp_errors_use_inbound_ifaddr",
673 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
674 .maxlen = sizeof(u8),
675 .mode = 0644,
676 .proc_handler = proc_dou8vec_minmax,
677 .extra1 = SYSCTL_ZERO,
678 .extra2 = SYSCTL_ONE
679 },
680 {
681 .procname = "icmp_errors_extension_mask",
682 .data = &init_net.ipv4.sysctl_icmp_errors_extension_mask,
683 .maxlen = sizeof(u8),
684 .mode = 0644,
685 .proc_handler = proc_dou8vec_minmax,
686 .extra1 = SYSCTL_ZERO,
687 .extra2 = &icmp_errors_extension_mask_all,
688 },
689 {
690 .procname = "icmp_ratelimit",
691 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
692 .maxlen = sizeof(int),
693 .mode = 0644,
694 .proc_handler = proc_dointvec_ms_jiffies,
695 },
696 {
697 .procname = "icmp_ratemask",
698 .data = &init_net.ipv4.sysctl_icmp_ratemask,
699 .maxlen = sizeof(int),
700 .mode = 0644,
701 .proc_handler = proc_dointvec
702 },
703 {
704 .procname = "icmp_msgs_per_sec",
705 .data = &init_net.ipv4.sysctl_icmp_msgs_per_sec,
706 .maxlen = sizeof(int),
707 .mode = 0644,
708 .proc_handler = proc_dointvec_minmax,
709 .extra1 = SYSCTL_ZERO,
710 },
711 {
712 .procname = "icmp_msgs_burst",
713 .data = &init_net.ipv4.sysctl_icmp_msgs_burst,
714 .maxlen = sizeof(int),
715 .mode = 0644,
716 .proc_handler = proc_dointvec_minmax,
717 .extra1 = SYSCTL_ZERO,
718 },
719 {
720 .procname = "ping_group_range",
721 .data = &init_net.ipv4.ping_group_range.range,
722 .maxlen = sizeof(gid_t)*2,
723 .mode = 0644,
724 .proc_handler = ipv4_ping_group_range,
725 },
726 #ifdef CONFIG_NET_L3_MASTER_DEV
727 {
728 .procname = "raw_l3mdev_accept",
729 .data = &init_net.ipv4.sysctl_raw_l3mdev_accept,
730 .maxlen = sizeof(u8),
731 .mode = 0644,
732 .proc_handler = proc_dou8vec_minmax,
733 .extra1 = SYSCTL_ZERO,
734 .extra2 = SYSCTL_ONE,
735 },
736 #endif
737 {
738 .procname = "tcp_ecn",
739 .data = &init_net.ipv4.sysctl_tcp_ecn,
740 .maxlen = sizeof(u8),
741 .mode = 0644,
742 .proc_handler = proc_dou8vec_minmax,
743 .extra1 = SYSCTL_ZERO,
744 .extra2 = &tcp_ecn_mode_max,
745 },
746 {
747 .procname = "tcp_ecn_option",
748 .data = &init_net.ipv4.sysctl_tcp_ecn_option,
749 .maxlen = sizeof(u8),
750 .mode = 0644,
751 .proc_handler = proc_dou8vec_minmax,
752 .extra1 = SYSCTL_ZERO,
753 .extra2 = SYSCTL_THREE,
754 },
755 {
756 .procname = "tcp_ecn_option_beacon",
757 .data = &init_net.ipv4.sysctl_tcp_ecn_option_beacon,
758 .maxlen = sizeof(u8),
759 .mode = 0644,
760 .proc_handler = proc_dou8vec_minmax,
761 .extra1 = SYSCTL_ZERO,
762 .extra2 = SYSCTL_THREE,
763 },
764 {
765 .procname = "tcp_ecn_fallback",
766 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
767 .maxlen = sizeof(u8),
768 .mode = 0644,
769 .proc_handler = proc_dou8vec_minmax,
770 .extra1 = SYSCTL_ZERO,
771 .extra2 = SYSCTL_ONE,
772 },
773 {
774 .procname = "ip_dynaddr",
775 .data = &init_net.ipv4.sysctl_ip_dynaddr,
776 .maxlen = sizeof(u8),
777 .mode = 0644,
778 .proc_handler = proc_dou8vec_minmax,
779 },
780 {
781 .procname = "ip_early_demux",
782 .data = &init_net.ipv4.sysctl_ip_early_demux,
783 .maxlen = sizeof(u8),
784 .mode = 0644,
785 .proc_handler = proc_dou8vec_minmax,
786 },
787 {
788 .procname = "udp_early_demux",
789 .data = &init_net.ipv4.sysctl_udp_early_demux,
790 .maxlen = sizeof(u8),
791 .mode = 0644,
792 .proc_handler = proc_dou8vec_minmax,
793 },
794 {
795 .procname = "tcp_early_demux",
796 .data = &init_net.ipv4.sysctl_tcp_early_demux,
797 .maxlen = sizeof(u8),
798 .mode = 0644,
799 .proc_handler = proc_dou8vec_minmax,
800 },
801 {
802 .procname = "nexthop_compat_mode",
803 .data = &init_net.ipv4.sysctl_nexthop_compat_mode,
804 .maxlen = sizeof(u8),
805 .mode = 0644,
806 .proc_handler = proc_dou8vec_minmax,
807 .extra1 = SYSCTL_ZERO,
808 .extra2 = SYSCTL_ONE,
809 },
810 {
811 .procname = "ip_default_ttl",
812 .data = &init_net.ipv4.sysctl_ip_default_ttl,
813 .maxlen = sizeof(u8),
814 .mode = 0644,
815 .proc_handler = proc_dou8vec_minmax,
816 .extra1 = &ip_ttl_min,
817 .extra2 = &ip_ttl_max,
818 },
819 {
820 .procname = "ip_local_port_range",
821 .maxlen = 0,
822 .data = &init_net,
823 .mode = 0644,
824 .proc_handler = ipv4_local_port_range,
825 },
826 {
827 .procname = "ip_local_port_step_width",
828 .maxlen = sizeof(u32),
829 .data = &init_net.ipv4.sysctl_ip_local_port_step_width,
830 .mode = 0644,
831 .proc_handler = proc_douintvec,
832 },
833 {
834 .procname = "ip_local_reserved_ports",
835 .data = &init_net.ipv4.sysctl_local_reserved_ports,
836 .maxlen = 65536,
837 .mode = 0644,
838 .proc_handler = proc_do_large_bitmap,
839 },
840 {
841 .procname = "ip_no_pmtu_disc",
842 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
843 .maxlen = sizeof(u8),
844 .mode = 0644,
845 .proc_handler = proc_dou8vec_minmax,
846 },
847 {
848 .procname = "ip_forward_use_pmtu",
849 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
850 .maxlen = sizeof(u8),
851 .mode = 0644,
852 .proc_handler = proc_dou8vec_minmax,
853 },
854 {
855 .procname = "ip_forward_update_priority",
856 .data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
857 .maxlen = sizeof(u8),
858 .mode = 0644,
859 .proc_handler = ipv4_fwd_update_priority,
860 .extra1 = SYSCTL_ZERO,
861 .extra2 = SYSCTL_ONE,
862 },
863 {
864 .procname = "ip_nonlocal_bind",
865 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
866 .maxlen = sizeof(u8),
867 .mode = 0644,
868 .proc_handler = proc_dou8vec_minmax,
869 },
870 {
871 .procname = "ip_autobind_reuse",
872 .data = &init_net.ipv4.sysctl_ip_autobind_reuse,
873 .maxlen = sizeof(u8),
874 .mode = 0644,
875 .proc_handler = proc_dou8vec_minmax,
876 .extra1 = SYSCTL_ZERO,
877 .extra2 = SYSCTL_ONE,
878 },
879 {
880 .procname = "fwmark_reflect",
881 .data = &init_net.ipv4.sysctl_fwmark_reflect,
882 .maxlen = sizeof(u8),
883 .mode = 0644,
884 .proc_handler = proc_dou8vec_minmax,
885 },
886 {
887 .procname = "tcp_fwmark_accept",
888 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
889 .maxlen = sizeof(u8),
890 .mode = 0644,
891 .proc_handler = proc_dou8vec_minmax,
892 },
893 #ifdef CONFIG_NET_L3_MASTER_DEV
894 {
895 .procname = "tcp_l3mdev_accept",
896 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
897 .maxlen = sizeof(u8),
898 .mode = 0644,
899 .proc_handler = proc_dou8vec_minmax,
900 .extra1 = SYSCTL_ZERO,
901 .extra2 = SYSCTL_ONE,
902 },
903 #endif
904 {
905 .procname = "tcp_mtu_probing",
906 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
907 .maxlen = sizeof(u8),
908 .mode = 0644,
909 .proc_handler = proc_dou8vec_minmax,
910 },
911 {
912 .procname = "tcp_base_mss",
913 .data = &init_net.ipv4.sysctl_tcp_base_mss,
914 .maxlen = sizeof(int),
915 .mode = 0644,
916 .proc_handler = proc_dointvec,
917 },
918 {
919 .procname = "tcp_min_snd_mss",
920 .data = &init_net.ipv4.sysctl_tcp_min_snd_mss,
921 .maxlen = sizeof(int),
922 .mode = 0644,
923 .proc_handler = proc_dointvec_minmax,
924 .extra1 = &tcp_min_snd_mss_min,
925 .extra2 = &tcp_min_snd_mss_max,
926 },
927 {
928 .procname = "tcp_mtu_probe_floor",
929 .data = &init_net.ipv4.sysctl_tcp_mtu_probe_floor,
930 .maxlen = sizeof(int),
931 .mode = 0644,
932 .proc_handler = proc_dointvec_minmax,
933 .extra1 = &tcp_min_snd_mss_min,
934 .extra2 = &tcp_min_snd_mss_max,
935 },
936 {
937 .procname = "tcp_probe_threshold",
938 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
939 .maxlen = sizeof(int),
940 .mode = 0644,
941 .proc_handler = proc_dointvec,
942 },
943 {
944 .procname = "tcp_probe_interval",
945 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
946 .maxlen = sizeof(u32),
947 .mode = 0644,
948 .proc_handler = proc_douintvec_minmax,
949 .extra2 = &u32_max_div_HZ,
950 },
951 {
952 .procname = "igmp_link_local_mcast_reports",
953 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
954 .maxlen = sizeof(u8),
955 .mode = 0644,
956 .proc_handler = proc_dou8vec_minmax,
957 },
958 {
959 .procname = "igmp_max_memberships",
960 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
961 .maxlen = sizeof(int),
962 .mode = 0644,
963 .proc_handler = proc_dointvec
964 },
965 {
966 .procname = "igmp_max_msf",
967 .data = &init_net.ipv4.sysctl_igmp_max_msf,
968 .maxlen = sizeof(int),
969 .mode = 0644,
970 .proc_handler = proc_dointvec
971 },
972 #ifdef CONFIG_IP_MULTICAST
973 {
974 .procname = "igmp_qrv",
975 .data = &init_net.ipv4.sysctl_igmp_qrv,
976 .maxlen = sizeof(int),
977 .mode = 0644,
978 .proc_handler = proc_dointvec_minmax,
979 .extra1 = SYSCTL_ONE
980 },
981 #endif
982 {
983 .procname = "tcp_congestion_control",
984 .data = &init_net.ipv4.tcp_congestion_control,
985 .mode = 0644,
986 .maxlen = TCP_CA_NAME_MAX,
987 .proc_handler = proc_tcp_congestion_control,
988 },
989 {
990 .procname = "tcp_available_congestion_control",
991 .maxlen = TCP_CA_BUF_MAX,
992 .mode = 0444,
993 .proc_handler = proc_tcp_available_congestion_control,
994 },
995 {
996 .procname = "tcp_allowed_congestion_control",
997 .maxlen = TCP_CA_BUF_MAX,
998 .mode = 0644,
999 .proc_handler = proc_allowed_congestion_control,
1000 },
1001 {
1002 .procname = "tcp_keepalive_time",
1003 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
1004 .maxlen = sizeof(int),
1005 .mode = 0644,
1006 .proc_handler = proc_dointvec_jiffies,
1007 },
1008 {
1009 .procname = "tcp_keepalive_probes",
1010 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
1011 .maxlen = sizeof(u8),
1012 .mode = 0644,
1013 .proc_handler = proc_dou8vec_minmax,
1014 },
1015 {
1016 .procname = "tcp_keepalive_intvl",
1017 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
1018 .maxlen = sizeof(int),
1019 .mode = 0644,
1020 .proc_handler = proc_dointvec_jiffies,
1021 },
1022 {
1023 .procname = "tcp_syn_retries",
1024 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
1025 .maxlen = sizeof(u8),
1026 .mode = 0644,
1027 .proc_handler = proc_dou8vec_minmax,
1028 .extra1 = &tcp_syn_retries_min,
1029 .extra2 = &tcp_syn_retries_max
1030 },
1031 {
1032 .procname = "tcp_synack_retries",
1033 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
1034 .maxlen = sizeof(u8),
1035 .mode = 0644,
1036 .proc_handler = proc_dou8vec_minmax,
1037 },
1038 #ifdef CONFIG_SYN_COOKIES
1039 {
1040 .procname = "tcp_syncookies",
1041 .data = &init_net.ipv4.sysctl_tcp_syncookies,
1042 .maxlen = sizeof(u8),
1043 .mode = 0644,
1044 .proc_handler = proc_dou8vec_minmax,
1045 },
1046 #endif
1047 {
1048 .procname = "tcp_migrate_req",
1049 .data = &init_net.ipv4.sysctl_tcp_migrate_req,
1050 .maxlen = sizeof(u8),
1051 .mode = 0644,
1052 .proc_handler = proc_dou8vec_minmax,
1053 .extra1 = SYSCTL_ZERO,
1054 .extra2 = SYSCTL_ONE
1055 },
1056 {
1057 .procname = "tcp_reordering",
1058 .data = &init_net.ipv4.sysctl_tcp_reordering,
1059 .maxlen = sizeof(int),
1060 .mode = 0644,
1061 .proc_handler = proc_dointvec_minmax,
1062 .extra1 = SYSCTL_ONE,
1063 .extra2 = &init_net.ipv4.sysctl_tcp_max_reordering,
1064 },
1065 {
1066 .procname = "tcp_retries1",
1067 .data = &init_net.ipv4.sysctl_tcp_retries1,
1068 .maxlen = sizeof(u8),
1069 .mode = 0644,
1070 .proc_handler = proc_dou8vec_minmax,
1071 .extra2 = &tcp_retr1_max
1072 },
1073 {
1074 .procname = "tcp_retries2",
1075 .data = &init_net.ipv4.sysctl_tcp_retries2,
1076 .maxlen = sizeof(u8),
1077 .mode = 0644,
1078 .proc_handler = proc_dou8vec_minmax,
1079 },
1080 {
1081 .procname = "tcp_orphan_retries",
1082 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
1083 .maxlen = sizeof(u8),
1084 .mode = 0644,
1085 .proc_handler = proc_dou8vec_minmax,
1086 },
1087 {
1088 .procname = "tcp_fin_timeout",
1089 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
1090 .maxlen = sizeof(int),
1091 .mode = 0644,
1092 .proc_handler = proc_dointvec_jiffies,
1093 },
1094 {
1095 .procname = "tcp_notsent_lowat",
1096 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
1097 .maxlen = sizeof(unsigned int),
1098 .mode = 0644,
1099 .proc_handler = proc_douintvec,
1100 },
1101 {
1102 .procname = "tcp_tw_reuse",
1103 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
1104 .maxlen = sizeof(u8),
1105 .mode = 0644,
1106 .proc_handler = proc_dou8vec_minmax,
1107 .extra1 = SYSCTL_ZERO,
1108 .extra2 = SYSCTL_TWO,
1109 },
1110 {
1111 .procname = "tcp_tw_reuse_delay",
1112 .data = &init_net.ipv4.sysctl_tcp_tw_reuse_delay,
1113 .maxlen = sizeof(unsigned int),
1114 .mode = 0644,
1115 .proc_handler = proc_douintvec_minmax,
1116 .extra1 = SYSCTL_ONE,
1117 .extra2 = &tcp_tw_reuse_delay_max,
1118 },
1119 {
1120 .procname = "tcp_max_syn_backlog",
1121 .data = &init_net.ipv4.sysctl_max_syn_backlog,
1122 .maxlen = sizeof(int),
1123 .mode = 0644,
1124 .proc_handler = proc_dointvec
1125 },
1126 {
1127 .procname = "tcp_fastopen",
1128 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1129 .maxlen = sizeof(int),
1130 .mode = 0644,
1131 .proc_handler = proc_dointvec,
1132 },
1133 {
1134 .procname = "tcp_fastopen_key",
1135 .mode = 0600,
1136 .data = &init_net.ipv4.sysctl_tcp_fastopen,
1137 /* maxlen to print the list of keys in hex (*2), with dashes
1138 * separating doublewords and a comma in between keys.
1139 */
1140 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
1141 2 * TCP_FASTOPEN_KEY_MAX) +
1142 (TCP_FASTOPEN_KEY_MAX * 5)),
1143 .proc_handler = proc_tcp_fastopen_key,
1144 },
1145 {
1146 .procname = "tcp_fastopen_blackhole_timeout_sec",
1147 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
1148 .maxlen = sizeof(int),
1149 .mode = 0644,
1150 .proc_handler = proc_tfo_blackhole_detect_timeout,
1151 .extra1 = SYSCTL_ZERO,
1152 },
1153 #ifdef CONFIG_IP_ROUTE_MULTIPATH
1154 {
1155 .procname = "fib_multipath_use_neigh",
1156 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
1157 .maxlen = sizeof(u8),
1158 .mode = 0644,
1159 .proc_handler = proc_dou8vec_minmax,
1160 .extra1 = SYSCTL_ZERO,
1161 .extra2 = SYSCTL_ONE,
1162 },
1163 {
1164 .procname = "fib_multipath_hash_policy",
1165 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
1166 .maxlen = sizeof(u8),
1167 .mode = 0644,
1168 .proc_handler = proc_fib_multipath_hash_policy,
1169 .extra1 = SYSCTL_ZERO,
1170 .extra2 = SYSCTL_THREE,
1171 },
1172 {
1173 .procname = "fib_multipath_hash_fields",
1174 .data = &init_net.ipv4.sysctl_fib_multipath_hash_fields,
1175 .maxlen = sizeof(u32),
1176 .mode = 0644,
1177 .proc_handler = proc_fib_multipath_hash_fields,
1178 .extra1 = SYSCTL_ONE,
1179 .extra2 = &fib_multipath_hash_fields_all_mask,
1180 },
1181 {
1182 .procname = "fib_multipath_hash_seed",
1183 .data = &init_net,
1184 .maxlen = sizeof(u32),
1185 .mode = 0644,
1186 .proc_handler = proc_fib_multipath_hash_seed,
1187 },
1188 #endif
1189 {
1190 .procname = "ip_unprivileged_port_start",
1191 .maxlen = sizeof(int),
1192 .data = &init_net.ipv4.sysctl_ip_prot_sock,
1193 .mode = 0644,
1194 .proc_handler = ipv4_privileged_ports,
1195 },
1196 #ifdef CONFIG_NET_L3_MASTER_DEV
1197 {
1198 .procname = "udp_l3mdev_accept",
1199 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
1200 .maxlen = sizeof(u8),
1201 .mode = 0644,
1202 .proc_handler = proc_dou8vec_minmax,
1203 .extra1 = SYSCTL_ZERO,
1204 .extra2 = SYSCTL_ONE,
1205 },
1206 #endif
1207 {
1208 .procname = "tcp_sack",
1209 .data = &init_net.ipv4.sysctl_tcp_sack,
1210 .maxlen = sizeof(u8),
1211 .mode = 0644,
1212 .proc_handler = proc_dou8vec_minmax,
1213 },
1214 {
1215 .procname = "tcp_window_scaling",
1216 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
1217 .maxlen = sizeof(u8),
1218 .mode = 0644,
1219 .proc_handler = proc_dou8vec_minmax,
1220 },
1221 {
1222 .procname = "tcp_timestamps",
1223 .data = &init_net.ipv4.sysctl_tcp_timestamps,
1224 .maxlen = sizeof(u8),
1225 .mode = 0644,
1226 .proc_handler = proc_dou8vec_minmax,
1227 },
1228 {
1229 .procname = "tcp_early_retrans",
1230 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
1231 .maxlen = sizeof(u8),
1232 .mode = 0644,
1233 .proc_handler = proc_dou8vec_minmax,
1234 .extra1 = SYSCTL_ZERO,
1235 .extra2 = SYSCTL_FOUR,
1236 },
1237 {
1238 .procname = "tcp_recovery",
1239 .data = &init_net.ipv4.sysctl_tcp_recovery,
1240 .maxlen = sizeof(u8),
1241 .mode = 0644,
1242 .proc_handler = proc_dou8vec_minmax,
1243 },
1244 {
1245 .procname = "tcp_thin_linear_timeouts",
1246 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1247 .maxlen = sizeof(u8),
1248 .mode = 0644,
1249 .proc_handler = proc_dou8vec_minmax,
1250 },
1251 {
1252 .procname = "tcp_slow_start_after_idle",
1253 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1254 .maxlen = sizeof(u8),
1255 .mode = 0644,
1256 .proc_handler = proc_dou8vec_minmax,
1257 },
1258 {
1259 .procname = "tcp_retrans_collapse",
1260 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
1261 .maxlen = sizeof(u8),
1262 .mode = 0644,
1263 .proc_handler = proc_dou8vec_minmax,
1264 },
1265 {
1266 .procname = "tcp_stdurg",
1267 .data = &init_net.ipv4.sysctl_tcp_stdurg,
1268 .maxlen = sizeof(u8),
1269 .mode = 0644,
1270 .proc_handler = proc_dou8vec_minmax,
1271 },
1272 {
1273 .procname = "tcp_rfc1337",
1274 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1275 .maxlen = sizeof(u8),
1276 .mode = 0644,
1277 .proc_handler = proc_dou8vec_minmax,
1278 },
1279 {
1280 .procname = "tcp_abort_on_overflow",
1281 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1282 .maxlen = sizeof(u8),
1283 .mode = 0644,
1284 .proc_handler = proc_dou8vec_minmax,
1285 },
1286 {
1287 .procname = "tcp_fack",
1288 .data = &init_net.ipv4.sysctl_tcp_fack,
1289 .maxlen = sizeof(u8),
1290 .mode = 0644,
1291 .proc_handler = proc_dou8vec_minmax,
1292 },
1293 {
1294 .procname = "tcp_max_reordering",
1295 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1296 .maxlen = sizeof(int),
1297 .mode = 0644,
1298 .proc_handler = proc_dointvec_minmax,
1299 .extra1 = SYSCTL_ONE,
1300 },
1301 {
1302 .procname = "tcp_dsack",
1303 .data = &init_net.ipv4.sysctl_tcp_dsack,
1304 .maxlen = sizeof(u8),
1305 .mode = 0644,
1306 .proc_handler = proc_dou8vec_minmax,
1307 },
1308 {
1309 .procname = "tcp_app_win",
1310 .data = &init_net.ipv4.sysctl_tcp_app_win,
1311 .maxlen = sizeof(u8),
1312 .mode = 0644,
1313 .proc_handler = proc_dou8vec_minmax,
1314 .extra1 = SYSCTL_ZERO,
1315 .extra2 = &tcp_app_win_max,
1316 },
1317 {
1318 .procname = "tcp_adv_win_scale",
1319 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1320 .maxlen = sizeof(int),
1321 .mode = 0644,
1322 .proc_handler = proc_dointvec_minmax,
1323 .extra1 = &tcp_adv_win_scale_min,
1324 .extra2 = &tcp_adv_win_scale_max,
1325 },
1326 {
1327 .procname = "tcp_frto",
1328 .data = &init_net.ipv4.sysctl_tcp_frto,
1329 .maxlen = sizeof(u8),
1330 .mode = 0644,
1331 .proc_handler = proc_dou8vec_minmax,
1332 },
1333 {
1334 .procname = "tcp_no_metrics_save",
1335 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1336 .maxlen = sizeof(u8),
1337 .mode = 0644,
1338 .proc_handler = proc_dou8vec_minmax,
1339 },
1340 {
1341 .procname = "tcp_no_ssthresh_metrics_save",
1342 .data = &init_net.ipv4.sysctl_tcp_no_ssthresh_metrics_save,
1343 .maxlen = sizeof(u8),
1344 .mode = 0644,
1345 .proc_handler = proc_dou8vec_minmax,
1346 .extra1 = SYSCTL_ZERO,
1347 .extra2 = SYSCTL_ONE,
1348 },
1349 {
1350 .procname = "tcp_moderate_rcvbuf",
1351 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1352 .maxlen = sizeof(u8),
1353 .mode = 0644,
1354 .proc_handler = proc_dou8vec_minmax,
1355 },
1356 {
1357 .procname = "tcp_rcvbuf_low_rtt",
1358 .data = &init_net.ipv4.sysctl_tcp_rcvbuf_low_rtt,
1359 .maxlen = sizeof(int),
1360 .mode = 0644,
1361 .proc_handler = proc_dointvec_minmax,
1362 .extra1 = SYSCTL_ZERO,
1363 .extra2 = SYSCTL_INT_MAX,
1364 },
1365 {
1366 .procname = "tcp_tso_win_divisor",
1367 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1368 .maxlen = sizeof(u8),
1369 .mode = 0644,
1370 .proc_handler = proc_dou8vec_minmax,
1371 },
1372 {
1373 .procname = "tcp_workaround_signed_windows",
1374 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1375 .maxlen = sizeof(u8),
1376 .mode = 0644,
1377 .proc_handler = proc_dou8vec_minmax,
1378 },
1379 {
1380 .procname = "tcp_limit_output_bytes",
1381 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1382 .maxlen = sizeof(int),
1383 .mode = 0644,
1384 .proc_handler = proc_dointvec
1385 },
1386 {
1387 .procname = "tcp_challenge_ack_limit",
1388 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1389 .maxlen = sizeof(int),
1390 .mode = 0644,
1391 .proc_handler = proc_dointvec
1392 },
1393 {
1394 .procname = "tcp_min_tso_segs",
1395 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1396 .maxlen = sizeof(u8),
1397 .mode = 0644,
1398 .proc_handler = proc_dou8vec_minmax,
1399 .extra1 = SYSCTL_ONE,
1400 },
1401 {
1402 .procname = "tcp_tso_rtt_log",
1403 .data = &init_net.ipv4.sysctl_tcp_tso_rtt_log,
1404 .maxlen = sizeof(u8),
1405 .mode = 0644,
1406 .proc_handler = proc_dou8vec_minmax,
1407 },
1408 {
1409 .procname = "tcp_min_rtt_wlen",
1410 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1411 .maxlen = sizeof(int),
1412 .mode = 0644,
1413 .proc_handler = proc_dointvec_minmax,
1414 .extra1 = SYSCTL_ZERO,
1415 .extra2 = &one_day_secs
1416 },
1417 {
1418 .procname = "tcp_autocorking",
1419 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1420 .maxlen = sizeof(u8),
1421 .mode = 0644,
1422 .proc_handler = proc_dou8vec_minmax,
1423 .extra1 = SYSCTL_ZERO,
1424 .extra2 = SYSCTL_ONE,
1425 },
1426 {
1427 .procname = "tcp_invalid_ratelimit",
1428 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1429 .maxlen = sizeof(int),
1430 .mode = 0644,
1431 .proc_handler = proc_dointvec_ms_jiffies,
1432 },
1433 {
1434 .procname = "tcp_pacing_ss_ratio",
1435 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1436 .maxlen = sizeof(int),
1437 .mode = 0644,
1438 .proc_handler = proc_dointvec_minmax,
1439 .extra1 = SYSCTL_ZERO,
1440 .extra2 = SYSCTL_ONE_THOUSAND,
1441 },
1442 {
1443 .procname = "tcp_pacing_ca_ratio",
1444 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1445 .maxlen = sizeof(int),
1446 .mode = 0644,
1447 .proc_handler = proc_dointvec_minmax,
1448 .extra1 = SYSCTL_ZERO,
1449 .extra2 = SYSCTL_ONE_THOUSAND,
1450 },
1451 {
1452 .procname = "tcp_wmem",
1453 .data = &init_net.ipv4.sysctl_tcp_wmem,
1454 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1455 .mode = 0644,
1456 .proc_handler = proc_dointvec_minmax,
1457 .extra1 = SYSCTL_ONE,
1458 },
1459 {
1460 .procname = "tcp_rmem",
1461 .data = &init_net.ipv4.sysctl_tcp_rmem,
1462 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1463 .mode = 0644,
1464 .proc_handler = proc_dointvec_minmax,
1465 .extra1 = SYSCTL_ONE,
1466 },
1467 {
1468 .procname = "tcp_comp_sack_delay_ns",
1469 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1470 .maxlen = sizeof(unsigned long),
1471 .mode = 0644,
1472 .proc_handler = proc_doulongvec_minmax,
1473 },
1474 {
1475 .procname = "tcp_comp_sack_rtt_percent",
1476 .data = &init_net.ipv4.sysctl_tcp_comp_sack_rtt_percent,
1477 .maxlen = sizeof(int),
1478 .mode = 0644,
1479 .proc_handler = proc_dointvec_minmax,
1480 .extra1 = SYSCTL_ONE,
1481 .extra2 = SYSCTL_ONE_THOUSAND,
1482 },
1483 {
1484 .procname = "tcp_comp_sack_slack_ns",
1485 .data = &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
1486 .maxlen = sizeof(unsigned long),
1487 .mode = 0644,
1488 .proc_handler = proc_doulongvec_minmax,
1489 },
1490 {
1491 .procname = "tcp_comp_sack_nr",
1492 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1493 .maxlen = sizeof(u8),
1494 .mode = 0644,
1495 .proc_handler = proc_dou8vec_minmax,
1496 .extra1 = SYSCTL_ZERO,
1497 },
1498 {
1499 .procname = "tcp_backlog_ack_defer",
1500 .data = &init_net.ipv4.sysctl_tcp_backlog_ack_defer,
1501 .maxlen = sizeof(u8),
1502 .mode = 0644,
1503 .proc_handler = proc_dou8vec_minmax,
1504 .extra1 = SYSCTL_ZERO,
1505 .extra2 = SYSCTL_ONE,
1506 },
1507 {
1508 .procname = "tcp_reflect_tos",
1509 .data = &init_net.ipv4.sysctl_tcp_reflect_tos,
1510 .maxlen = sizeof(u8),
1511 .mode = 0644,
1512 .proc_handler = proc_dou8vec_minmax,
1513 .extra1 = SYSCTL_ZERO,
1514 .extra2 = SYSCTL_ONE,
1515 },
1516 {
1517 .procname = "tcp_ehash_entries",
1518 .data = &init_net.ipv4.sysctl_tcp_child_ehash_entries,
1519 .mode = 0444,
1520 .proc_handler = proc_tcp_ehash_entries,
1521 },
1522 {
1523 .procname = "tcp_child_ehash_entries",
1524 .data = &init_net.ipv4.sysctl_tcp_child_ehash_entries,
1525 .maxlen = sizeof(unsigned int),
1526 .mode = 0644,
1527 .proc_handler = proc_douintvec_minmax,
1528 .extra1 = SYSCTL_ZERO,
1529 .extra2 = &tcp_child_ehash_entries_max,
1530 },
1531 {
1532 .procname = "udp_hash_entries",
1533 .data = &init_net.ipv4.sysctl_udp_child_hash_entries,
1534 .mode = 0444,
1535 .proc_handler = proc_udp_hash_entries,
1536 },
1537 {
1538 .procname = "udp_child_hash_entries",
1539 .data = &init_net.ipv4.sysctl_udp_child_hash_entries,
1540 .maxlen = sizeof(unsigned int),
1541 .mode = 0644,
1542 .proc_handler = proc_douintvec_minmax,
1543 .extra1 = SYSCTL_ZERO,
1544 .extra2 = &udp_child_hash_entries_max,
1545 },
1546 {
1547 .procname = "udp_rmem_min",
1548 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1549 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1550 .mode = 0644,
1551 .proc_handler = proc_dointvec_minmax,
1552 .extra1 = SYSCTL_ONE
1553 },
1554 {
1555 .procname = "udp_wmem_min",
1556 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1557 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1558 .mode = 0644,
1559 .proc_handler = proc_dointvec_minmax,
1560 .extra1 = SYSCTL_ONE
1561 },
1562 {
1563 .procname = "fib_notify_on_flag_change",
1564 .data = &init_net.ipv4.sysctl_fib_notify_on_flag_change,
1565 .maxlen = sizeof(u8),
1566 .mode = 0644,
1567 .proc_handler = proc_dou8vec_minmax,
1568 .extra1 = SYSCTL_ZERO,
1569 .extra2 = SYSCTL_TWO,
1570 },
1571 {
1572 .procname = "tcp_plb_enabled",
1573 .data = &init_net.ipv4.sysctl_tcp_plb_enabled,
1574 .maxlen = sizeof(u8),
1575 .mode = 0644,
1576 .proc_handler = proc_dou8vec_minmax,
1577 .extra1 = SYSCTL_ZERO,
1578 .extra2 = SYSCTL_ONE,
1579 },
1580 {
1581 .procname = "tcp_plb_idle_rehash_rounds",
1582 .data = &init_net.ipv4.sysctl_tcp_plb_idle_rehash_rounds,
1583 .maxlen = sizeof(u8),
1584 .mode = 0644,
1585 .proc_handler = proc_dou8vec_minmax,
1586 .extra2 = &tcp_plb_max_rounds,
1587 },
1588 {
1589 .procname = "tcp_plb_rehash_rounds",
1590 .data = &init_net.ipv4.sysctl_tcp_plb_rehash_rounds,
1591 .maxlen = sizeof(u8),
1592 .mode = 0644,
1593 .proc_handler = proc_dou8vec_minmax,
1594 .extra2 = &tcp_plb_max_rounds,
1595 },
1596 {
1597 .procname = "tcp_plb_suspend_rto_sec",
1598 .data = &init_net.ipv4.sysctl_tcp_plb_suspend_rto_sec,
1599 .maxlen = sizeof(u8),
1600 .mode = 0644,
1601 .proc_handler = proc_dou8vec_minmax,
1602 },
1603 {
1604 .procname = "tcp_plb_cong_thresh",
1605 .data = &init_net.ipv4.sysctl_tcp_plb_cong_thresh,
1606 .maxlen = sizeof(int),
1607 .mode = 0644,
1608 .proc_handler = proc_dointvec_minmax,
1609 .extra1 = SYSCTL_ZERO,
1610 .extra2 = &tcp_plb_max_cong_thresh,
1611 },
1612 {
1613 .procname = "tcp_syn_linear_timeouts",
1614 .data = &init_net.ipv4.sysctl_tcp_syn_linear_timeouts,
1615 .maxlen = sizeof(u8),
1616 .mode = 0644,
1617 .proc_handler = proc_dou8vec_minmax,
1618 .extra1 = SYSCTL_ZERO,
1619 .extra2 = &tcp_syn_linear_timeouts_max,
1620 },
1621 {
1622 .procname = "tcp_shrink_window",
1623 .data = &init_net.ipv4.sysctl_tcp_shrink_window,
1624 .maxlen = sizeof(u8),
1625 .mode = 0644,
1626 .proc_handler = proc_dou8vec_minmax,
1627 .extra1 = SYSCTL_ZERO,
1628 .extra2 = SYSCTL_ONE,
1629 },
1630 {
1631 .procname = "tcp_pingpong_thresh",
1632 .data = &init_net.ipv4.sysctl_tcp_pingpong_thresh,
1633 .maxlen = sizeof(u8),
1634 .mode = 0644,
1635 .proc_handler = proc_dou8vec_minmax,
1636 .extra1 = SYSCTL_ONE,
1637 },
1638 {
1639 .procname = "tcp_rto_min_us",
1640 .data = &init_net.ipv4.sysctl_tcp_rto_min_us,
1641 .maxlen = sizeof(int),
1642 .mode = 0644,
1643 .proc_handler = proc_dointvec_minmax,
1644 .extra1 = SYSCTL_ONE,
1645 },
1646 {
1647 .procname = "tcp_rto_max_ms",
1648 .data = &init_net.ipv4.sysctl_tcp_rto_max_ms,
1649 .maxlen = sizeof(int),
1650 .mode = 0644,
1651 .proc_handler = proc_dointvec_minmax,
1652 .extra1 = SYSCTL_ONE_THOUSAND,
1653 .extra2 = &tcp_rto_max_max,
1654 },
1655 };
1656
ipv4_net_table_dup(struct net * net)1657 static const struct ctl_table *ipv4_net_table_dup(struct net *net)
1658 {
1659 size_t table_size = ARRAY_SIZE(ipv4_net_table);
1660 struct ctl_table *table;
1661 int i;
1662
1663 table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
1664 if (!table)
1665 return NULL;
1666
1667 for (i = 0; i < table_size; i++) {
1668 if (table[i].data) {
1669 /* Update the variables to point into
1670 * the current struct net
1671 */
1672 table[i].data += (void *)net - (void *)&init_net;
1673 } else {
1674 /* Entries without data pointer are global;
1675 * Make them read-only in non-init_net ns
1676 */
1677 table[i].mode &= ~0222;
1678 }
1679 if (table[i].extra2 >= (void *)&init_net.ipv4 &&
1680 table[i].extra2 < (void *)(&init_net.ipv4 + 1))
1681 table[i].extra2 += (void *)net - (void *)&init_net;
1682 }
1683 return table;
1684 }
1685
ipv4_sysctl_init_net(struct net * net)1686 static __net_init int ipv4_sysctl_init_net(struct net *net)
1687 {
1688 size_t table_size = ARRAY_SIZE(ipv4_net_table);
1689 const struct ctl_table *table;
1690
1691 table = ipv4_net_table;
1692 if (!net_eq(net, &init_net)) {
1693 table = ipv4_net_table_dup(net);
1694 if (!table)
1695 goto err_alloc;
1696 }
1697
1698 net->ipv4.ipv4_hdr = register_net_sysctl_sz(net, "net/ipv4", table,
1699 table_size);
1700 if (!net->ipv4.ipv4_hdr)
1701 goto err_reg;
1702
1703 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1704 if (!net->ipv4.sysctl_local_reserved_ports)
1705 goto err_ports;
1706
1707 proc_fib_multipath_hash_set_seed(net, 0);
1708
1709 return 0;
1710
1711 err_ports:
1712 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1713 err_reg:
1714 if (!net_eq(net, &init_net))
1715 kfree(table);
1716 err_alloc:
1717 return -ENOMEM;
1718 }
1719
ipv4_sysctl_exit_net(struct net * net)1720 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1721 {
1722 const struct ctl_table *table;
1723
1724 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1725 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1726 kfree(table);
1727 kfree(net->ipv4.sysctl_local_reserved_ports);
1728 }
1729
1730 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1731 .init = ipv4_sysctl_init_net,
1732 .exit = ipv4_sysctl_exit_net,
1733 };
1734
sysctl_ipv4_init(void)1735 static __init int sysctl_ipv4_init(void)
1736 {
1737 struct ctl_table_header *hdr;
1738
1739 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1740 if (!hdr)
1741 return -ENOMEM;
1742
1743 proc_fib_multipath_hash_init_rand_seed();
1744
1745 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1746 unregister_net_sysctl_table(hdr);
1747 return -ENOMEM;
1748 }
1749
1750 return 0;
1751 }
1752
1753 __initcall(sysctl_ipv4_init);
1754