1 // SPDX-License-Identifier: GPL-2.0
3 * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
5 * Begun April 1, 1996, Mike Shaver.
6 * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
9 #include <linux/sysctl.h>
10 #include <linux/seqlock.h>
11 #include <linux/init.h>
12 #include <linux/slab.h>
15 #include <net/ip_fib.h>
18 #include <net/cipso_ipv4.h>
20 #include <net/protocol.h>
21 #include <net/netevent.h>
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_min_snd_mss_min = TCP_MIN_SND_MSS;
29 static int tcp_min_snd_mss_max = 65535;
30 static int ip_privileged_port_min;
31 static int ip_privileged_port_max = 65535;
32 static int ip_ttl_min = 1;
33 static int ip_ttl_max = 255;
34 static int tcp_syn_retries_min = 1;
35 static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
36 static int ip_ping_group_range_min[] = { 0, 0 };
37 static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
38 static u32 u32_max_div_HZ = UINT_MAX / HZ;
39 static int one_day_secs = 24 * 3600;
40 static u32 fib_multipath_hash_fields_all_mask __maybe_unused =
41 FIB_MULTIPATH_HASH_FIELD_ALL_MASK;
44 static int sysctl_tcp_low_latency __read_mostly;
46 /* Update system visible IP port range */
47 static void set_local_port_range(struct net *net, int range[2])
49 bool same_parity = !((range[0] ^ range[1]) & 1);
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");
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);
61 /* Validate changes from /proc interface. */
62 static int ipv4_local_port_range(struct ctl_table *table, int write,
63 void *buffer, size_t *lenp, loff_t *ppos)
66 container_of(table->data, struct net, ipv4.ip_local_ports.range);
69 struct ctl_table tmp = {
71 .maxlen = sizeof(range),
73 .extra1 = &ip_local_port_range_min,
74 .extra2 = &ip_local_port_range_max,
77 inet_get_local_port_range(net, &range[0], &range[1]);
79 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
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
86 if ((range[1] < range[0]) ||
87 (range[0] < READ_ONCE(net->ipv4.sysctl_ip_prot_sock)))
90 set_local_port_range(net, range);
96 /* Validate changes from /proc interface. */
97 static int ipv4_privileged_ports(struct ctl_table *table, int write,
98 void *buffer, size_t *lenp, loff_t *ppos)
100 struct net *net = container_of(table->data, struct net,
101 ipv4.sysctl_ip_prot_sock);
105 struct ctl_table tmp = {
107 .maxlen = sizeof(pports),
109 .extra1 = &ip_privileged_port_min,
110 .extra2 = &ip_privileged_port_max,
113 pports = READ_ONCE(net->ipv4.sysctl_ip_prot_sock);
115 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
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.
122 if (range[0] < pports)
125 WRITE_ONCE(net->ipv4.sysctl_ip_prot_sock, pports);
131 static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
133 kgid_t *data = table->data;
135 container_of(table->data, struct net, ipv4.ping_group_range.range);
138 seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
142 } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
145 /* Update system visible IP port range */
146 static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
148 kgid_t *data = table->data;
150 container_of(table->data, struct net, ipv4.ping_group_range.range);
151 write_seqlock(&net->ipv4.ping_group_range.lock);
154 write_sequnlock(&net->ipv4.ping_group_range.lock);
157 /* Validate changes from /proc interface. */
158 static int ipv4_ping_group_range(struct ctl_table *table, int write,
159 void *buffer, size_t *lenp, loff_t *ppos)
161 struct user_namespace *user_ns = current_user_ns();
165 struct ctl_table tmp = {
167 .maxlen = sizeof(urange),
169 .extra1 = &ip_ping_group_range_min,
170 .extra2 = &ip_ping_group_range_max,
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);
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))
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);
187 set_ping_group_range(table, low, high);
193 static int ipv4_fwd_update_priority(struct ctl_table *table, int write,
194 void *buffer, size_t *lenp, loff_t *ppos)
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,
209 static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
210 void *buffer, size_t *lenp, loff_t *ppos)
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 = {
217 .maxlen = TCP_CA_NAME_MAX,
221 tcp_get_default_congestion_control(net, val);
223 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
224 if (write && ret == 0)
225 ret = tcp_set_default_congestion_control(net, val);
229 static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
230 int write, void *buffer,
231 size_t *lenp, loff_t *ppos)
233 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
236 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
239 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
240 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
245 static int proc_allowed_congestion_control(struct ctl_table *ctl,
246 int write, void *buffer,
247 size_t *lenp, loff_t *ppos)
249 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
252 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
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);
264 static int sscanf_key(char *buf, __le32 *key)
269 if (sscanf(buf, "%x-%x-%x-%x", user_key, user_key + 1,
270 user_key + 2, user_key + 3) != 4) {
273 for (i = 0; i < ARRAY_SIZE(user_key); i++)
274 key[i] = cpu_to_le32(user_key[i]);
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);
282 static int proc_tcp_fastopen_key(struct ctl_table *table, int write,
283 void *buffer, size_t *lenp, loff_t *ppos)
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.
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)];
296 int ret, i = 0, off = 0, n_keys;
298 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
302 n_keys = tcp_fastopen_get_cipher(net, NULL, (u64 *)key);
304 memset(&key[0], 0, TCP_FASTOPEN_KEY_LENGTH);
308 for (i = 0; i < n_keys * 4; i++)
309 user_key[i] = le32_to_cpu(key[i]);
311 for (i = 0; i < n_keys; i++) {
312 off += snprintf(tbl.data + off, tbl.maxlen - off,
313 "%08x-%08x-%08x-%08x",
317 user_key[i * 4 + 3]);
319 if (WARN_ON_ONCE(off >= tbl.maxlen - 1))
323 off += snprintf(tbl.data + off, tbl.maxlen - off, ",");
326 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
328 if (write && ret == 0) {
329 backup_data = strchr(tbl.data, ',');
334 if (sscanf_key(tbl.data, key)) {
339 if (sscanf_key(backup_data, key + 4)) {
344 tcp_fastopen_reset_cipher(net, NULL, key,
345 backup_data ? key + 4 : NULL);
353 static int proc_tfo_blackhole_detect_timeout(struct ctl_table *table,
354 int write, void *buffer,
355 size_t *lenp, loff_t *ppos)
357 struct net *net = container_of(table->data, struct net,
358 ipv4.sysctl_tcp_fastopen_blackhole_timeout);
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);
368 static int proc_tcp_available_ulp(struct ctl_table *ctl,
369 int write, void *buffer, size_t *lenp,
372 struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
375 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
378 tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
379 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
385 #ifdef CONFIG_IP_ROUTE_MULTIPATH
386 static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
387 void *buffer, size_t *lenp,
390 struct net *net = container_of(table->data, struct net,
391 ipv4.sysctl_fib_multipath_hash_policy);
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);
401 static int proc_fib_multipath_hash_fields(struct ctl_table *table, int write,
402 void *buffer, size_t *lenp,
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);
418 static struct ctl_table ipv4_table[] = {
420 .procname = "tcp_max_orphans",
421 .data = &sysctl_tcp_max_orphans,
422 .maxlen = sizeof(int),
424 .proc_handler = proc_dointvec
427 .procname = "inet_peer_threshold",
428 .data = &inet_peer_threshold,
429 .maxlen = sizeof(int),
431 .proc_handler = proc_dointvec
434 .procname = "inet_peer_minttl",
435 .data = &inet_peer_minttl,
436 .maxlen = sizeof(int),
438 .proc_handler = proc_dointvec_jiffies,
441 .procname = "inet_peer_maxttl",
442 .data = &inet_peer_maxttl,
443 .maxlen = sizeof(int),
445 .proc_handler = proc_dointvec_jiffies,
448 .procname = "tcp_mem",
449 .maxlen = sizeof(sysctl_tcp_mem),
450 .data = &sysctl_tcp_mem,
452 .proc_handler = proc_doulongvec_minmax,
455 .procname = "tcp_low_latency",
456 .data = &sysctl_tcp_low_latency,
457 .maxlen = sizeof(int),
459 .proc_handler = proc_dointvec
461 #ifdef CONFIG_NETLABEL
463 .procname = "cipso_cache_enable",
464 .data = &cipso_v4_cache_enabled,
465 .maxlen = sizeof(int),
467 .proc_handler = proc_dointvec,
470 .procname = "cipso_cache_bucket_size",
471 .data = &cipso_v4_cache_bucketsize,
472 .maxlen = sizeof(int),
474 .proc_handler = proc_dointvec,
477 .procname = "cipso_rbm_optfmt",
478 .data = &cipso_v4_rbm_optfmt,
479 .maxlen = sizeof(int),
481 .proc_handler = proc_dointvec,
484 .procname = "cipso_rbm_strictvalid",
485 .data = &cipso_v4_rbm_strictvalid,
486 .maxlen = sizeof(int),
488 .proc_handler = proc_dointvec,
490 #endif /* CONFIG_NETLABEL */
492 .procname = "tcp_available_ulp",
493 .maxlen = TCP_ULP_BUF_MAX,
495 .proc_handler = proc_tcp_available_ulp,
498 .procname = "icmp_msgs_per_sec",
499 .data = &sysctl_icmp_msgs_per_sec,
500 .maxlen = sizeof(int),
502 .proc_handler = proc_dointvec_minmax,
503 .extra1 = SYSCTL_ZERO,
506 .procname = "icmp_msgs_burst",
507 .data = &sysctl_icmp_msgs_burst,
508 .maxlen = sizeof(int),
510 .proc_handler = proc_dointvec_minmax,
511 .extra1 = SYSCTL_ZERO,
514 .procname = "udp_mem",
515 .data = &sysctl_udp_mem,
516 .maxlen = sizeof(sysctl_udp_mem),
518 .proc_handler = proc_doulongvec_minmax,
521 .procname = "fib_sync_mem",
522 .data = &sysctl_fib_sync_mem,
523 .maxlen = sizeof(sysctl_fib_sync_mem),
525 .proc_handler = proc_douintvec_minmax,
526 .extra1 = &sysctl_fib_sync_mem_min,
527 .extra2 = &sysctl_fib_sync_mem_max,
532 static struct ctl_table ipv4_net_table[] = {
533 /* tcp_max_tw_buckets must be first in this table. */
535 .procname = "tcp_max_tw_buckets",
536 /* .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets, */
537 .maxlen = sizeof(int),
539 .proc_handler = proc_dointvec
542 .procname = "icmp_echo_ignore_all",
543 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
544 .maxlen = sizeof(u8),
546 .proc_handler = proc_dou8vec_minmax,
547 .extra1 = SYSCTL_ZERO,
551 .procname = "icmp_echo_enable_probe",
552 .data = &init_net.ipv4.sysctl_icmp_echo_enable_probe,
553 .maxlen = sizeof(u8),
555 .proc_handler = proc_dou8vec_minmax,
556 .extra1 = SYSCTL_ZERO,
560 .procname = "icmp_echo_ignore_broadcasts",
561 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
562 .maxlen = sizeof(u8),
564 .proc_handler = proc_dou8vec_minmax,
565 .extra1 = SYSCTL_ZERO,
569 .procname = "icmp_ignore_bogus_error_responses",
570 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
571 .maxlen = sizeof(u8),
573 .proc_handler = proc_dou8vec_minmax,
574 .extra1 = SYSCTL_ZERO,
578 .procname = "icmp_errors_use_inbound_ifaddr",
579 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
580 .maxlen = sizeof(u8),
582 .proc_handler = proc_dou8vec_minmax,
583 .extra1 = SYSCTL_ZERO,
587 .procname = "icmp_ratelimit",
588 .data = &init_net.ipv4.sysctl_icmp_ratelimit,
589 .maxlen = sizeof(int),
591 .proc_handler = proc_dointvec_ms_jiffies,
594 .procname = "icmp_ratemask",
595 .data = &init_net.ipv4.sysctl_icmp_ratemask,
596 .maxlen = sizeof(int),
598 .proc_handler = proc_dointvec
601 .procname = "ping_group_range",
602 .data = &init_net.ipv4.ping_group_range.range,
603 .maxlen = sizeof(gid_t)*2,
605 .proc_handler = ipv4_ping_group_range,
607 #ifdef CONFIG_NET_L3_MASTER_DEV
609 .procname = "raw_l3mdev_accept",
610 .data = &init_net.ipv4.sysctl_raw_l3mdev_accept,
611 .maxlen = sizeof(u8),
613 .proc_handler = proc_dou8vec_minmax,
614 .extra1 = SYSCTL_ZERO,
615 .extra2 = SYSCTL_ONE,
619 .procname = "tcp_ecn",
620 .data = &init_net.ipv4.sysctl_tcp_ecn,
621 .maxlen = sizeof(u8),
623 .proc_handler = proc_dou8vec_minmax,
624 .extra1 = SYSCTL_ZERO,
625 .extra2 = SYSCTL_TWO,
628 .procname = "tcp_ecn_fallback",
629 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
630 .maxlen = sizeof(u8),
632 .proc_handler = proc_dou8vec_minmax,
633 .extra1 = SYSCTL_ZERO,
634 .extra2 = SYSCTL_ONE,
637 .procname = "ip_dynaddr",
638 .data = &init_net.ipv4.sysctl_ip_dynaddr,
639 .maxlen = sizeof(u8),
641 .proc_handler = proc_dou8vec_minmax,
644 .procname = "ip_early_demux",
645 .data = &init_net.ipv4.sysctl_ip_early_demux,
646 .maxlen = sizeof(u8),
648 .proc_handler = proc_dou8vec_minmax,
651 .procname = "udp_early_demux",
652 .data = &init_net.ipv4.sysctl_udp_early_demux,
653 .maxlen = sizeof(u8),
655 .proc_handler = proc_dou8vec_minmax,
658 .procname = "tcp_early_demux",
659 .data = &init_net.ipv4.sysctl_tcp_early_demux,
660 .maxlen = sizeof(u8),
662 .proc_handler = proc_dou8vec_minmax,
665 .procname = "nexthop_compat_mode",
666 .data = &init_net.ipv4.sysctl_nexthop_compat_mode,
667 .maxlen = sizeof(u8),
669 .proc_handler = proc_dou8vec_minmax,
670 .extra1 = SYSCTL_ZERO,
671 .extra2 = SYSCTL_ONE,
674 .procname = "ip_default_ttl",
675 .data = &init_net.ipv4.sysctl_ip_default_ttl,
676 .maxlen = sizeof(u8),
678 .proc_handler = proc_dou8vec_minmax,
679 .extra1 = &ip_ttl_min,
680 .extra2 = &ip_ttl_max,
683 .procname = "ip_local_port_range",
684 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
685 .data = &init_net.ipv4.ip_local_ports.range,
687 .proc_handler = ipv4_local_port_range,
690 .procname = "ip_local_reserved_ports",
691 .data = &init_net.ipv4.sysctl_local_reserved_ports,
694 .proc_handler = proc_do_large_bitmap,
697 .procname = "ip_no_pmtu_disc",
698 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
699 .maxlen = sizeof(u8),
701 .proc_handler = proc_dou8vec_minmax,
704 .procname = "ip_forward_use_pmtu",
705 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
706 .maxlen = sizeof(u8),
708 .proc_handler = proc_dou8vec_minmax,
711 .procname = "ip_forward_update_priority",
712 .data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
713 .maxlen = sizeof(u8),
715 .proc_handler = ipv4_fwd_update_priority,
716 .extra1 = SYSCTL_ZERO,
717 .extra2 = SYSCTL_ONE,
720 .procname = "ip_nonlocal_bind",
721 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
722 .maxlen = sizeof(u8),
724 .proc_handler = proc_dou8vec_minmax,
727 .procname = "ip_autobind_reuse",
728 .data = &init_net.ipv4.sysctl_ip_autobind_reuse,
729 .maxlen = sizeof(u8),
731 .proc_handler = proc_dou8vec_minmax,
732 .extra1 = SYSCTL_ZERO,
733 .extra2 = SYSCTL_ONE,
736 .procname = "fwmark_reflect",
737 .data = &init_net.ipv4.sysctl_fwmark_reflect,
738 .maxlen = sizeof(u8),
740 .proc_handler = proc_dou8vec_minmax,
743 .procname = "tcp_fwmark_accept",
744 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
745 .maxlen = sizeof(u8),
747 .proc_handler = proc_dou8vec_minmax,
749 #ifdef CONFIG_NET_L3_MASTER_DEV
751 .procname = "tcp_l3mdev_accept",
752 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
753 .maxlen = sizeof(u8),
755 .proc_handler = proc_dou8vec_minmax,
756 .extra1 = SYSCTL_ZERO,
757 .extra2 = SYSCTL_ONE,
761 .procname = "tcp_mtu_probing",
762 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
763 .maxlen = sizeof(u8),
765 .proc_handler = proc_dou8vec_minmax,
768 .procname = "tcp_base_mss",
769 .data = &init_net.ipv4.sysctl_tcp_base_mss,
770 .maxlen = sizeof(int),
772 .proc_handler = proc_dointvec,
775 .procname = "tcp_min_snd_mss",
776 .data = &init_net.ipv4.sysctl_tcp_min_snd_mss,
777 .maxlen = sizeof(int),
779 .proc_handler = proc_dointvec_minmax,
780 .extra1 = &tcp_min_snd_mss_min,
781 .extra2 = &tcp_min_snd_mss_max,
784 .procname = "tcp_mtu_probe_floor",
785 .data = &init_net.ipv4.sysctl_tcp_mtu_probe_floor,
786 .maxlen = sizeof(int),
788 .proc_handler = proc_dointvec_minmax,
789 .extra1 = &tcp_min_snd_mss_min,
790 .extra2 = &tcp_min_snd_mss_max,
793 .procname = "tcp_probe_threshold",
794 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
795 .maxlen = sizeof(int),
797 .proc_handler = proc_dointvec,
800 .procname = "tcp_probe_interval",
801 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
802 .maxlen = sizeof(u32),
804 .proc_handler = proc_douintvec_minmax,
805 .extra2 = &u32_max_div_HZ,
808 .procname = "igmp_link_local_mcast_reports",
809 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
810 .maxlen = sizeof(u8),
812 .proc_handler = proc_dou8vec_minmax,
815 .procname = "igmp_max_memberships",
816 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
817 .maxlen = sizeof(int),
819 .proc_handler = proc_dointvec
822 .procname = "igmp_max_msf",
823 .data = &init_net.ipv4.sysctl_igmp_max_msf,
824 .maxlen = sizeof(int),
826 .proc_handler = proc_dointvec
828 #ifdef CONFIG_IP_MULTICAST
830 .procname = "igmp_qrv",
831 .data = &init_net.ipv4.sysctl_igmp_qrv,
832 .maxlen = sizeof(int),
834 .proc_handler = proc_dointvec_minmax,
839 .procname = "tcp_congestion_control",
840 .data = &init_net.ipv4.tcp_congestion_control,
842 .maxlen = TCP_CA_NAME_MAX,
843 .proc_handler = proc_tcp_congestion_control,
846 .procname = "tcp_available_congestion_control",
847 .maxlen = TCP_CA_BUF_MAX,
849 .proc_handler = proc_tcp_available_congestion_control,
852 .procname = "tcp_allowed_congestion_control",
853 .maxlen = TCP_CA_BUF_MAX,
855 .proc_handler = proc_allowed_congestion_control,
858 .procname = "tcp_keepalive_time",
859 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
860 .maxlen = sizeof(int),
862 .proc_handler = proc_dointvec_jiffies,
865 .procname = "tcp_keepalive_probes",
866 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
867 .maxlen = sizeof(u8),
869 .proc_handler = proc_dou8vec_minmax,
872 .procname = "tcp_keepalive_intvl",
873 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
874 .maxlen = sizeof(int),
876 .proc_handler = proc_dointvec_jiffies,
879 .procname = "tcp_syn_retries",
880 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
881 .maxlen = sizeof(u8),
883 .proc_handler = proc_dou8vec_minmax,
884 .extra1 = &tcp_syn_retries_min,
885 .extra2 = &tcp_syn_retries_max
888 .procname = "tcp_synack_retries",
889 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
890 .maxlen = sizeof(u8),
892 .proc_handler = proc_dou8vec_minmax,
894 #ifdef CONFIG_SYN_COOKIES
896 .procname = "tcp_syncookies",
897 .data = &init_net.ipv4.sysctl_tcp_syncookies,
898 .maxlen = sizeof(u8),
900 .proc_handler = proc_dou8vec_minmax,
904 .procname = "tcp_migrate_req",
905 .data = &init_net.ipv4.sysctl_tcp_migrate_req,
906 .maxlen = sizeof(u8),
908 .proc_handler = proc_dou8vec_minmax,
909 .extra1 = SYSCTL_ZERO,
913 .procname = "tcp_reordering",
914 .data = &init_net.ipv4.sysctl_tcp_reordering,
915 .maxlen = sizeof(int),
917 .proc_handler = proc_dointvec
920 .procname = "tcp_retries1",
921 .data = &init_net.ipv4.sysctl_tcp_retries1,
922 .maxlen = sizeof(u8),
924 .proc_handler = proc_dou8vec_minmax,
925 .extra2 = &tcp_retr1_max
928 .procname = "tcp_retries2",
929 .data = &init_net.ipv4.sysctl_tcp_retries2,
930 .maxlen = sizeof(u8),
932 .proc_handler = proc_dou8vec_minmax,
935 .procname = "tcp_orphan_retries",
936 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
937 .maxlen = sizeof(u8),
939 .proc_handler = proc_dou8vec_minmax,
942 .procname = "tcp_fin_timeout",
943 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
944 .maxlen = sizeof(int),
946 .proc_handler = proc_dointvec_jiffies,
949 .procname = "tcp_notsent_lowat",
950 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
951 .maxlen = sizeof(unsigned int),
953 .proc_handler = proc_douintvec,
956 .procname = "tcp_tw_reuse",
957 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
958 .maxlen = sizeof(u8),
960 .proc_handler = proc_dou8vec_minmax,
961 .extra1 = SYSCTL_ZERO,
962 .extra2 = SYSCTL_TWO,
965 .procname = "tcp_max_syn_backlog",
966 .data = &init_net.ipv4.sysctl_max_syn_backlog,
967 .maxlen = sizeof(int),
969 .proc_handler = proc_dointvec
972 .procname = "tcp_fastopen",
973 .data = &init_net.ipv4.sysctl_tcp_fastopen,
974 .maxlen = sizeof(int),
976 .proc_handler = proc_dointvec,
979 .procname = "tcp_fastopen_key",
981 .data = &init_net.ipv4.sysctl_tcp_fastopen,
982 /* maxlen to print the list of keys in hex (*2), with dashes
983 * separating doublewords and a comma in between keys.
985 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
986 2 * TCP_FASTOPEN_KEY_MAX) +
987 (TCP_FASTOPEN_KEY_MAX * 5)),
988 .proc_handler = proc_tcp_fastopen_key,
991 .procname = "tcp_fastopen_blackhole_timeout_sec",
992 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
993 .maxlen = sizeof(int),
995 .proc_handler = proc_tfo_blackhole_detect_timeout,
996 .extra1 = SYSCTL_ZERO,
998 #ifdef CONFIG_IP_ROUTE_MULTIPATH
1000 .procname = "fib_multipath_use_neigh",
1001 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
1002 .maxlen = sizeof(u8),
1004 .proc_handler = proc_dou8vec_minmax,
1005 .extra1 = SYSCTL_ZERO,
1006 .extra2 = SYSCTL_ONE,
1009 .procname = "fib_multipath_hash_policy",
1010 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
1011 .maxlen = sizeof(u8),
1013 .proc_handler = proc_fib_multipath_hash_policy,
1014 .extra1 = SYSCTL_ZERO,
1015 .extra2 = SYSCTL_THREE,
1018 .procname = "fib_multipath_hash_fields",
1019 .data = &init_net.ipv4.sysctl_fib_multipath_hash_fields,
1020 .maxlen = sizeof(u32),
1022 .proc_handler = proc_fib_multipath_hash_fields,
1023 .extra1 = SYSCTL_ONE,
1024 .extra2 = &fib_multipath_hash_fields_all_mask,
1028 .procname = "ip_unprivileged_port_start",
1029 .maxlen = sizeof(int),
1030 .data = &init_net.ipv4.sysctl_ip_prot_sock,
1032 .proc_handler = ipv4_privileged_ports,
1034 #ifdef CONFIG_NET_L3_MASTER_DEV
1036 .procname = "udp_l3mdev_accept",
1037 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
1038 .maxlen = sizeof(u8),
1040 .proc_handler = proc_dou8vec_minmax,
1041 .extra1 = SYSCTL_ZERO,
1042 .extra2 = SYSCTL_ONE,
1046 .procname = "tcp_sack",
1047 .data = &init_net.ipv4.sysctl_tcp_sack,
1048 .maxlen = sizeof(u8),
1050 .proc_handler = proc_dou8vec_minmax,
1053 .procname = "tcp_window_scaling",
1054 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
1055 .maxlen = sizeof(u8),
1057 .proc_handler = proc_dou8vec_minmax,
1060 .procname = "tcp_timestamps",
1061 .data = &init_net.ipv4.sysctl_tcp_timestamps,
1062 .maxlen = sizeof(u8),
1064 .proc_handler = proc_dou8vec_minmax,
1067 .procname = "tcp_early_retrans",
1068 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
1069 .maxlen = sizeof(u8),
1071 .proc_handler = proc_dou8vec_minmax,
1072 .extra1 = SYSCTL_ZERO,
1073 .extra2 = SYSCTL_FOUR,
1076 .procname = "tcp_recovery",
1077 .data = &init_net.ipv4.sysctl_tcp_recovery,
1078 .maxlen = sizeof(u8),
1080 .proc_handler = proc_dou8vec_minmax,
1083 .procname = "tcp_thin_linear_timeouts",
1084 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1085 .maxlen = sizeof(u8),
1087 .proc_handler = proc_dou8vec_minmax,
1090 .procname = "tcp_slow_start_after_idle",
1091 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1092 .maxlen = sizeof(u8),
1094 .proc_handler = proc_dou8vec_minmax,
1097 .procname = "tcp_retrans_collapse",
1098 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
1099 .maxlen = sizeof(u8),
1101 .proc_handler = proc_dou8vec_minmax,
1104 .procname = "tcp_stdurg",
1105 .data = &init_net.ipv4.sysctl_tcp_stdurg,
1106 .maxlen = sizeof(u8),
1108 .proc_handler = proc_dou8vec_minmax,
1111 .procname = "tcp_rfc1337",
1112 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1113 .maxlen = sizeof(u8),
1115 .proc_handler = proc_dou8vec_minmax,
1118 .procname = "tcp_abort_on_overflow",
1119 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1120 .maxlen = sizeof(u8),
1122 .proc_handler = proc_dou8vec_minmax,
1125 .procname = "tcp_fack",
1126 .data = &init_net.ipv4.sysctl_tcp_fack,
1127 .maxlen = sizeof(u8),
1129 .proc_handler = proc_dou8vec_minmax,
1132 .procname = "tcp_max_reordering",
1133 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1134 .maxlen = sizeof(int),
1136 .proc_handler = proc_dointvec
1139 .procname = "tcp_dsack",
1140 .data = &init_net.ipv4.sysctl_tcp_dsack,
1141 .maxlen = sizeof(u8),
1143 .proc_handler = proc_dou8vec_minmax,
1146 .procname = "tcp_app_win",
1147 .data = &init_net.ipv4.sysctl_tcp_app_win,
1148 .maxlen = sizeof(u8),
1150 .proc_handler = proc_dou8vec_minmax,
1153 .procname = "tcp_adv_win_scale",
1154 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1155 .maxlen = sizeof(int),
1157 .proc_handler = proc_dointvec_minmax,
1158 .extra1 = &tcp_adv_win_scale_min,
1159 .extra2 = &tcp_adv_win_scale_max,
1162 .procname = "tcp_frto",
1163 .data = &init_net.ipv4.sysctl_tcp_frto,
1164 .maxlen = sizeof(u8),
1166 .proc_handler = proc_dou8vec_minmax,
1169 .procname = "tcp_no_metrics_save",
1170 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1171 .maxlen = sizeof(u8),
1173 .proc_handler = proc_dou8vec_minmax,
1176 .procname = "tcp_no_ssthresh_metrics_save",
1177 .data = &init_net.ipv4.sysctl_tcp_no_ssthresh_metrics_save,
1178 .maxlen = sizeof(u8),
1180 .proc_handler = proc_dou8vec_minmax,
1181 .extra1 = SYSCTL_ZERO,
1182 .extra2 = SYSCTL_ONE,
1185 .procname = "tcp_moderate_rcvbuf",
1186 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1187 .maxlen = sizeof(u8),
1189 .proc_handler = proc_dou8vec_minmax,
1192 .procname = "tcp_tso_win_divisor",
1193 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1194 .maxlen = sizeof(u8),
1196 .proc_handler = proc_dou8vec_minmax,
1199 .procname = "tcp_workaround_signed_windows",
1200 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1201 .maxlen = sizeof(u8),
1203 .proc_handler = proc_dou8vec_minmax,
1206 .procname = "tcp_limit_output_bytes",
1207 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1208 .maxlen = sizeof(int),
1210 .proc_handler = proc_dointvec
1213 .procname = "tcp_challenge_ack_limit",
1214 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1215 .maxlen = sizeof(int),
1217 .proc_handler = proc_dointvec
1220 .procname = "tcp_min_tso_segs",
1221 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1222 .maxlen = sizeof(u8),
1224 .proc_handler = proc_dou8vec_minmax,
1225 .extra1 = SYSCTL_ONE,
1228 .procname = "tcp_tso_rtt_log",
1229 .data = &init_net.ipv4.sysctl_tcp_tso_rtt_log,
1230 .maxlen = sizeof(u8),
1232 .proc_handler = proc_dou8vec_minmax,
1235 .procname = "tcp_min_rtt_wlen",
1236 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1237 .maxlen = sizeof(int),
1239 .proc_handler = proc_dointvec_minmax,
1240 .extra1 = SYSCTL_ZERO,
1241 .extra2 = &one_day_secs
1244 .procname = "tcp_autocorking",
1245 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1246 .maxlen = sizeof(u8),
1248 .proc_handler = proc_dou8vec_minmax,
1249 .extra1 = SYSCTL_ZERO,
1250 .extra2 = SYSCTL_ONE,
1253 .procname = "tcp_invalid_ratelimit",
1254 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1255 .maxlen = sizeof(int),
1257 .proc_handler = proc_dointvec_ms_jiffies,
1260 .procname = "tcp_pacing_ss_ratio",
1261 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1262 .maxlen = sizeof(int),
1264 .proc_handler = proc_dointvec_minmax,
1265 .extra1 = SYSCTL_ZERO,
1266 .extra2 = SYSCTL_ONE_THOUSAND,
1269 .procname = "tcp_pacing_ca_ratio",
1270 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1271 .maxlen = sizeof(int),
1273 .proc_handler = proc_dointvec_minmax,
1274 .extra1 = SYSCTL_ZERO,
1275 .extra2 = SYSCTL_ONE_THOUSAND,
1278 .procname = "tcp_wmem",
1279 .data = &init_net.ipv4.sysctl_tcp_wmem,
1280 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1282 .proc_handler = proc_dointvec_minmax,
1283 .extra1 = SYSCTL_ONE,
1286 .procname = "tcp_rmem",
1287 .data = &init_net.ipv4.sysctl_tcp_rmem,
1288 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1290 .proc_handler = proc_dointvec_minmax,
1291 .extra1 = SYSCTL_ONE,
1294 .procname = "tcp_comp_sack_delay_ns",
1295 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1296 .maxlen = sizeof(unsigned long),
1298 .proc_handler = proc_doulongvec_minmax,
1301 .procname = "tcp_comp_sack_slack_ns",
1302 .data = &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
1303 .maxlen = sizeof(unsigned long),
1305 .proc_handler = proc_doulongvec_minmax,
1308 .procname = "tcp_comp_sack_nr",
1309 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1310 .maxlen = sizeof(u8),
1312 .proc_handler = proc_dou8vec_minmax,
1313 .extra1 = SYSCTL_ZERO,
1316 .procname = "tcp_reflect_tos",
1317 .data = &init_net.ipv4.sysctl_tcp_reflect_tos,
1318 .maxlen = sizeof(u8),
1320 .proc_handler = proc_dou8vec_minmax,
1321 .extra1 = SYSCTL_ZERO,
1322 .extra2 = SYSCTL_ONE,
1325 .procname = "udp_rmem_min",
1326 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1327 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1329 .proc_handler = proc_dointvec_minmax,
1330 .extra1 = SYSCTL_ONE
1333 .procname = "udp_wmem_min",
1334 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1335 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1337 .proc_handler = proc_dointvec_minmax,
1338 .extra1 = SYSCTL_ONE
1341 .procname = "fib_notify_on_flag_change",
1342 .data = &init_net.ipv4.sysctl_fib_notify_on_flag_change,
1343 .maxlen = sizeof(u8),
1345 .proc_handler = proc_dou8vec_minmax,
1346 .extra1 = SYSCTL_ZERO,
1347 .extra2 = SYSCTL_TWO,
1352 static __net_init int ipv4_sysctl_init_net(struct net *net)
1354 struct ctl_table *table;
1356 table = ipv4_net_table;
1357 if (!net_eq(net, &init_net)) {
1360 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
1364 /* skip first entry (sysctl_max_tw_buckets) */
1365 for (i = 1; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) {
1366 if (table[i].data) {
1367 /* Update the variables to point into
1368 * the current struct net
1370 table[i].data += (void *)net - (void *)&init_net;
1372 /* Entries without data pointer are global;
1373 * Make them read-only in non-init_net ns
1375 table[i].mode &= ~0222;
1380 table[0].data = &net->ipv4.tcp_death_row->sysctl_max_tw_buckets;
1382 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
1383 if (!net->ipv4.ipv4_hdr)
1386 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1387 if (!net->ipv4.sysctl_local_reserved_ports)
1393 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1395 if (!net_eq(net, &init_net))
1401 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1403 struct ctl_table *table;
1405 kfree(net->ipv4.sysctl_local_reserved_ports);
1406 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1407 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1411 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1412 .init = ipv4_sysctl_init_net,
1413 .exit = ipv4_sysctl_exit_net,
1416 static __init int sysctl_ipv4_init(void)
1418 struct ctl_table_header *hdr;
1420 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1424 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1425 unregister_net_sysctl_table(hdr);
1432 __initcall(sysctl_ipv4_init);