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