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