1 /* 2 * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem. 3 * 4 * Begun April 1, 1996, Mike Shaver. 5 * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS] 6 */ 7 8 #include <linux/mm.h> 9 #include <linux/module.h> 10 #include <linux/sysctl.h> 11 #include <linux/igmp.h> 12 #include <linux/inetdevice.h> 13 #include <linux/seqlock.h> 14 #include <linux/init.h> 15 #include <linux/slab.h> 16 #include <linux/nsproxy.h> 17 #include <linux/swap.h> 18 #include <net/snmp.h> 19 #include <net/icmp.h> 20 #include <net/ip.h> 21 #include <net/route.h> 22 #include <net/tcp.h> 23 #include <net/udp.h> 24 #include <net/cipso_ipv4.h> 25 #include <net/inet_frag.h> 26 #include <net/ping.h> 27 #include <net/tcp_memcontrol.h> 28 29 static int zero; 30 static int one = 1; 31 static int four = 4; 32 static int gso_max_segs = GSO_MAX_SEGS; 33 static int tcp_retr1_max = 255; 34 static int ip_local_port_range_min[] = { 1, 1 }; 35 static int ip_local_port_range_max[] = { 65535, 65535 }; 36 static int tcp_adv_win_scale_min = -31; 37 static int tcp_adv_win_scale_max = 31; 38 static int ip_ttl_min = 1; 39 static int ip_ttl_max = 255; 40 static int tcp_syn_retries_min = 1; 41 static int tcp_syn_retries_max = MAX_TCP_SYNCNT; 42 static int ip_ping_group_range_min[] = { 0, 0 }; 43 static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX }; 44 static int min_sndbuf = SOCK_MIN_SNDBUF; 45 static int min_rcvbuf = SOCK_MIN_RCVBUF; 46 47 /* Update system visible IP port range */ 48 static void set_local_port_range(struct net *net, int range[2]) 49 { 50 bool same_parity = !((range[0] ^ range[1]) & 1); 51 52 write_seqlock(&net->ipv4.ip_local_ports.lock); 53 if (same_parity && !net->ipv4.ip_local_ports.warned) { 54 net->ipv4.ip_local_ports.warned = true; 55 pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n"); 56 } 57 net->ipv4.ip_local_ports.range[0] = range[0]; 58 net->ipv4.ip_local_ports.range[1] = range[1]; 59 write_sequnlock(&net->ipv4.ip_local_ports.lock); 60 } 61 62 /* Validate changes from /proc interface. */ 63 static int ipv4_local_port_range(struct ctl_table *table, int write, 64 void __user *buffer, 65 size_t *lenp, loff_t *ppos) 66 { 67 struct net *net = 68 container_of(table->data, struct net, ipv4.ip_local_ports.range); 69 int ret; 70 int range[2]; 71 struct ctl_table tmp = { 72 .data = &range, 73 .maxlen = sizeof(range), 74 .mode = table->mode, 75 .extra1 = &ip_local_port_range_min, 76 .extra2 = &ip_local_port_range_max, 77 }; 78 79 inet_get_local_port_range(net, &range[0], &range[1]); 80 81 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); 82 83 if (write && ret == 0) { 84 if (range[1] < range[0]) 85 ret = -EINVAL; 86 else 87 set_local_port_range(net, range); 88 } 89 90 return ret; 91 } 92 93 94 static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high) 95 { 96 kgid_t *data = table->data; 97 struct net *net = 98 container_of(table->data, struct net, ipv4.ping_group_range.range); 99 unsigned int seq; 100 do { 101 seq = read_seqbegin(&net->ipv4.ip_local_ports.lock); 102 103 *low = data[0]; 104 *high = data[1]; 105 } while (read_seqretry(&net->ipv4.ip_local_ports.lock, seq)); 106 } 107 108 /* Update system visible IP port range */ 109 static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high) 110 { 111 kgid_t *data = table->data; 112 struct net *net = 113 container_of(table->data, struct net, ipv4.ping_group_range.range); 114 write_seqlock(&net->ipv4.ip_local_ports.lock); 115 data[0] = low; 116 data[1] = high; 117 write_sequnlock(&net->ipv4.ip_local_ports.lock); 118 } 119 120 /* Validate changes from /proc interface. */ 121 static int ipv4_ping_group_range(struct ctl_table *table, int write, 122 void __user *buffer, 123 size_t *lenp, loff_t *ppos) 124 { 125 struct user_namespace *user_ns = current_user_ns(); 126 int ret; 127 gid_t urange[2]; 128 kgid_t low, high; 129 struct ctl_table tmp = { 130 .data = &urange, 131 .maxlen = sizeof(urange), 132 .mode = table->mode, 133 .extra1 = &ip_ping_group_range_min, 134 .extra2 = &ip_ping_group_range_max, 135 }; 136 137 inet_get_ping_group_range_table(table, &low, &high); 138 urange[0] = from_kgid_munged(user_ns, low); 139 urange[1] = from_kgid_munged(user_ns, high); 140 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); 141 142 if (write && ret == 0) { 143 low = make_kgid(user_ns, urange[0]); 144 high = make_kgid(user_ns, urange[1]); 145 if (!gid_valid(low) || !gid_valid(high) || 146 (urange[1] < urange[0]) || gid_lt(high, low)) { 147 low = make_kgid(&init_user_ns, 1); 148 high = make_kgid(&init_user_ns, 0); 149 } 150 set_ping_group_range(table, low, high); 151 } 152 153 return ret; 154 } 155 156 static int proc_tcp_congestion_control(struct ctl_table *ctl, int write, 157 void __user *buffer, size_t *lenp, loff_t *ppos) 158 { 159 char val[TCP_CA_NAME_MAX]; 160 struct ctl_table tbl = { 161 .data = val, 162 .maxlen = TCP_CA_NAME_MAX, 163 }; 164 int ret; 165 166 tcp_get_default_congestion_control(val); 167 168 ret = proc_dostring(&tbl, write, buffer, lenp, ppos); 169 if (write && ret == 0) 170 ret = tcp_set_default_congestion_control(val); 171 return ret; 172 } 173 174 static int proc_tcp_available_congestion_control(struct ctl_table *ctl, 175 int write, 176 void __user *buffer, size_t *lenp, 177 loff_t *ppos) 178 { 179 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, }; 180 int ret; 181 182 tbl.data = kmalloc(tbl.maxlen, GFP_USER); 183 if (!tbl.data) 184 return -ENOMEM; 185 tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX); 186 ret = proc_dostring(&tbl, write, buffer, lenp, ppos); 187 kfree(tbl.data); 188 return ret; 189 } 190 191 static int proc_allowed_congestion_control(struct ctl_table *ctl, 192 int write, 193 void __user *buffer, size_t *lenp, 194 loff_t *ppos) 195 { 196 struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX }; 197 int ret; 198 199 tbl.data = kmalloc(tbl.maxlen, GFP_USER); 200 if (!tbl.data) 201 return -ENOMEM; 202 203 tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen); 204 ret = proc_dostring(&tbl, write, buffer, lenp, ppos); 205 if (write && ret == 0) 206 ret = tcp_set_allowed_congestion_control(tbl.data); 207 kfree(tbl.data); 208 return ret; 209 } 210 211 static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write, 212 void __user *buffer, size_t *lenp, 213 loff_t *ppos) 214 { 215 struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) }; 216 struct tcp_fastopen_context *ctxt; 217 int ret; 218 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */ 219 220 tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL); 221 if (!tbl.data) 222 return -ENOMEM; 223 224 rcu_read_lock(); 225 ctxt = rcu_dereference(tcp_fastopen_ctx); 226 if (ctxt) 227 memcpy(user_key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH); 228 else 229 memset(user_key, 0, sizeof(user_key)); 230 rcu_read_unlock(); 231 232 snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x", 233 user_key[0], user_key[1], user_key[2], user_key[3]); 234 ret = proc_dostring(&tbl, write, buffer, lenp, ppos); 235 236 if (write && ret == 0) { 237 if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1, 238 user_key + 2, user_key + 3) != 4) { 239 ret = -EINVAL; 240 goto bad_key; 241 } 242 /* Generate a dummy secret but don't publish it. This 243 * is needed so we don't regenerate a new key on the 244 * first invocation of tcp_fastopen_cookie_gen 245 */ 246 tcp_fastopen_init_key_once(false); 247 tcp_fastopen_reset_cipher(user_key, TCP_FASTOPEN_KEY_LENGTH); 248 } 249 250 bad_key: 251 pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n", 252 user_key[0], user_key[1], user_key[2], user_key[3], 253 (char *)tbl.data, ret); 254 kfree(tbl.data); 255 return ret; 256 } 257 258 static struct ctl_table ipv4_table[] = { 259 { 260 .procname = "tcp_timestamps", 261 .data = &sysctl_tcp_timestamps, 262 .maxlen = sizeof(int), 263 .mode = 0644, 264 .proc_handler = proc_dointvec 265 }, 266 { 267 .procname = "tcp_window_scaling", 268 .data = &sysctl_tcp_window_scaling, 269 .maxlen = sizeof(int), 270 .mode = 0644, 271 .proc_handler = proc_dointvec 272 }, 273 { 274 .procname = "tcp_sack", 275 .data = &sysctl_tcp_sack, 276 .maxlen = sizeof(int), 277 .mode = 0644, 278 .proc_handler = proc_dointvec 279 }, 280 { 281 .procname = "tcp_retrans_collapse", 282 .data = &sysctl_tcp_retrans_collapse, 283 .maxlen = sizeof(int), 284 .mode = 0644, 285 .proc_handler = proc_dointvec 286 }, 287 { 288 .procname = "ip_default_ttl", 289 .data = &sysctl_ip_default_ttl, 290 .maxlen = sizeof(int), 291 .mode = 0644, 292 .proc_handler = proc_dointvec_minmax, 293 .extra1 = &ip_ttl_min, 294 .extra2 = &ip_ttl_max, 295 }, 296 { 297 .procname = "tcp_syn_retries", 298 .data = &sysctl_tcp_syn_retries, 299 .maxlen = sizeof(int), 300 .mode = 0644, 301 .proc_handler = proc_dointvec_minmax, 302 .extra1 = &tcp_syn_retries_min, 303 .extra2 = &tcp_syn_retries_max 304 }, 305 { 306 .procname = "tcp_synack_retries", 307 .data = &sysctl_tcp_synack_retries, 308 .maxlen = sizeof(int), 309 .mode = 0644, 310 .proc_handler = proc_dointvec 311 }, 312 { 313 .procname = "tcp_max_orphans", 314 .data = &sysctl_tcp_max_orphans, 315 .maxlen = sizeof(int), 316 .mode = 0644, 317 .proc_handler = proc_dointvec 318 }, 319 { 320 .procname = "tcp_max_tw_buckets", 321 .data = &tcp_death_row.sysctl_max_tw_buckets, 322 .maxlen = sizeof(int), 323 .mode = 0644, 324 .proc_handler = proc_dointvec 325 }, 326 { 327 .procname = "ip_early_demux", 328 .data = &sysctl_ip_early_demux, 329 .maxlen = sizeof(int), 330 .mode = 0644, 331 .proc_handler = proc_dointvec 332 }, 333 { 334 .procname = "ip_dynaddr", 335 .data = &sysctl_ip_dynaddr, 336 .maxlen = sizeof(int), 337 .mode = 0644, 338 .proc_handler = proc_dointvec 339 }, 340 { 341 .procname = "tcp_keepalive_time", 342 .data = &sysctl_tcp_keepalive_time, 343 .maxlen = sizeof(int), 344 .mode = 0644, 345 .proc_handler = proc_dointvec_jiffies, 346 }, 347 { 348 .procname = "tcp_keepalive_probes", 349 .data = &sysctl_tcp_keepalive_probes, 350 .maxlen = sizeof(int), 351 .mode = 0644, 352 .proc_handler = proc_dointvec 353 }, 354 { 355 .procname = "tcp_keepalive_intvl", 356 .data = &sysctl_tcp_keepalive_intvl, 357 .maxlen = sizeof(int), 358 .mode = 0644, 359 .proc_handler = proc_dointvec_jiffies, 360 }, 361 { 362 .procname = "tcp_retries1", 363 .data = &sysctl_tcp_retries1, 364 .maxlen = sizeof(int), 365 .mode = 0644, 366 .proc_handler = proc_dointvec_minmax, 367 .extra2 = &tcp_retr1_max 368 }, 369 { 370 .procname = "tcp_retries2", 371 .data = &sysctl_tcp_retries2, 372 .maxlen = sizeof(int), 373 .mode = 0644, 374 .proc_handler = proc_dointvec 375 }, 376 { 377 .procname = "tcp_fin_timeout", 378 .data = &sysctl_tcp_fin_timeout, 379 .maxlen = sizeof(int), 380 .mode = 0644, 381 .proc_handler = proc_dointvec_jiffies, 382 }, 383 #ifdef CONFIG_SYN_COOKIES 384 { 385 .procname = "tcp_syncookies", 386 .data = &sysctl_tcp_syncookies, 387 .maxlen = sizeof(int), 388 .mode = 0644, 389 .proc_handler = proc_dointvec 390 }, 391 #endif 392 { 393 .procname = "tcp_fastopen", 394 .data = &sysctl_tcp_fastopen, 395 .maxlen = sizeof(int), 396 .mode = 0644, 397 .proc_handler = proc_dointvec, 398 }, 399 { 400 .procname = "tcp_fastopen_key", 401 .mode = 0600, 402 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10), 403 .proc_handler = proc_tcp_fastopen_key, 404 }, 405 { 406 .procname = "tcp_tw_recycle", 407 .data = &tcp_death_row.sysctl_tw_recycle, 408 .maxlen = sizeof(int), 409 .mode = 0644, 410 .proc_handler = proc_dointvec 411 }, 412 { 413 .procname = "tcp_abort_on_overflow", 414 .data = &sysctl_tcp_abort_on_overflow, 415 .maxlen = sizeof(int), 416 .mode = 0644, 417 .proc_handler = proc_dointvec 418 }, 419 { 420 .procname = "tcp_stdurg", 421 .data = &sysctl_tcp_stdurg, 422 .maxlen = sizeof(int), 423 .mode = 0644, 424 .proc_handler = proc_dointvec 425 }, 426 { 427 .procname = "tcp_rfc1337", 428 .data = &sysctl_tcp_rfc1337, 429 .maxlen = sizeof(int), 430 .mode = 0644, 431 .proc_handler = proc_dointvec 432 }, 433 { 434 .procname = "tcp_max_syn_backlog", 435 .data = &sysctl_max_syn_backlog, 436 .maxlen = sizeof(int), 437 .mode = 0644, 438 .proc_handler = proc_dointvec 439 }, 440 { 441 .procname = "igmp_max_memberships", 442 .data = &sysctl_igmp_max_memberships, 443 .maxlen = sizeof(int), 444 .mode = 0644, 445 .proc_handler = proc_dointvec 446 }, 447 { 448 .procname = "igmp_max_msf", 449 .data = &sysctl_igmp_max_msf, 450 .maxlen = sizeof(int), 451 .mode = 0644, 452 .proc_handler = proc_dointvec 453 }, 454 #ifdef CONFIG_IP_MULTICAST 455 { 456 .procname = "igmp_qrv", 457 .data = &sysctl_igmp_qrv, 458 .maxlen = sizeof(int), 459 .mode = 0644, 460 .proc_handler = proc_dointvec_minmax, 461 .extra1 = &one 462 }, 463 #endif 464 { 465 .procname = "inet_peer_threshold", 466 .data = &inet_peer_threshold, 467 .maxlen = sizeof(int), 468 .mode = 0644, 469 .proc_handler = proc_dointvec 470 }, 471 { 472 .procname = "inet_peer_minttl", 473 .data = &inet_peer_minttl, 474 .maxlen = sizeof(int), 475 .mode = 0644, 476 .proc_handler = proc_dointvec_jiffies, 477 }, 478 { 479 .procname = "inet_peer_maxttl", 480 .data = &inet_peer_maxttl, 481 .maxlen = sizeof(int), 482 .mode = 0644, 483 .proc_handler = proc_dointvec_jiffies, 484 }, 485 { 486 .procname = "tcp_orphan_retries", 487 .data = &sysctl_tcp_orphan_retries, 488 .maxlen = sizeof(int), 489 .mode = 0644, 490 .proc_handler = proc_dointvec 491 }, 492 { 493 .procname = "tcp_fack", 494 .data = &sysctl_tcp_fack, 495 .maxlen = sizeof(int), 496 .mode = 0644, 497 .proc_handler = proc_dointvec 498 }, 499 { 500 .procname = "tcp_reordering", 501 .data = &sysctl_tcp_reordering, 502 .maxlen = sizeof(int), 503 .mode = 0644, 504 .proc_handler = proc_dointvec 505 }, 506 { 507 .procname = "tcp_max_reordering", 508 .data = &sysctl_tcp_max_reordering, 509 .maxlen = sizeof(int), 510 .mode = 0644, 511 .proc_handler = proc_dointvec 512 }, 513 { 514 .procname = "tcp_dsack", 515 .data = &sysctl_tcp_dsack, 516 .maxlen = sizeof(int), 517 .mode = 0644, 518 .proc_handler = proc_dointvec 519 }, 520 { 521 .procname = "tcp_mem", 522 .maxlen = sizeof(sysctl_tcp_mem), 523 .data = &sysctl_tcp_mem, 524 .mode = 0644, 525 .proc_handler = proc_doulongvec_minmax, 526 }, 527 { 528 .procname = "tcp_wmem", 529 .data = &sysctl_tcp_wmem, 530 .maxlen = sizeof(sysctl_tcp_wmem), 531 .mode = 0644, 532 .proc_handler = proc_dointvec_minmax, 533 .extra1 = &min_sndbuf, 534 }, 535 { 536 .procname = "tcp_notsent_lowat", 537 .data = &sysctl_tcp_notsent_lowat, 538 .maxlen = sizeof(sysctl_tcp_notsent_lowat), 539 .mode = 0644, 540 .proc_handler = proc_dointvec, 541 }, 542 { 543 .procname = "tcp_rmem", 544 .data = &sysctl_tcp_rmem, 545 .maxlen = sizeof(sysctl_tcp_rmem), 546 .mode = 0644, 547 .proc_handler = proc_dointvec_minmax, 548 .extra1 = &min_rcvbuf, 549 }, 550 { 551 .procname = "tcp_app_win", 552 .data = &sysctl_tcp_app_win, 553 .maxlen = sizeof(int), 554 .mode = 0644, 555 .proc_handler = proc_dointvec 556 }, 557 { 558 .procname = "tcp_adv_win_scale", 559 .data = &sysctl_tcp_adv_win_scale, 560 .maxlen = sizeof(int), 561 .mode = 0644, 562 .proc_handler = proc_dointvec_minmax, 563 .extra1 = &tcp_adv_win_scale_min, 564 .extra2 = &tcp_adv_win_scale_max, 565 }, 566 { 567 .procname = "tcp_tw_reuse", 568 .data = &sysctl_tcp_tw_reuse, 569 .maxlen = sizeof(int), 570 .mode = 0644, 571 .proc_handler = proc_dointvec 572 }, 573 { 574 .procname = "tcp_frto", 575 .data = &sysctl_tcp_frto, 576 .maxlen = sizeof(int), 577 .mode = 0644, 578 .proc_handler = proc_dointvec 579 }, 580 { 581 .procname = "tcp_low_latency", 582 .data = &sysctl_tcp_low_latency, 583 .maxlen = sizeof(int), 584 .mode = 0644, 585 .proc_handler = proc_dointvec 586 }, 587 { 588 .procname = "tcp_no_metrics_save", 589 .data = &sysctl_tcp_nometrics_save, 590 .maxlen = sizeof(int), 591 .mode = 0644, 592 .proc_handler = proc_dointvec, 593 }, 594 { 595 .procname = "tcp_moderate_rcvbuf", 596 .data = &sysctl_tcp_moderate_rcvbuf, 597 .maxlen = sizeof(int), 598 .mode = 0644, 599 .proc_handler = proc_dointvec, 600 }, 601 { 602 .procname = "tcp_tso_win_divisor", 603 .data = &sysctl_tcp_tso_win_divisor, 604 .maxlen = sizeof(int), 605 .mode = 0644, 606 .proc_handler = proc_dointvec, 607 }, 608 { 609 .procname = "tcp_congestion_control", 610 .mode = 0644, 611 .maxlen = TCP_CA_NAME_MAX, 612 .proc_handler = proc_tcp_congestion_control, 613 }, 614 { 615 .procname = "tcp_workaround_signed_windows", 616 .data = &sysctl_tcp_workaround_signed_windows, 617 .maxlen = sizeof(int), 618 .mode = 0644, 619 .proc_handler = proc_dointvec 620 }, 621 { 622 .procname = "tcp_limit_output_bytes", 623 .data = &sysctl_tcp_limit_output_bytes, 624 .maxlen = sizeof(int), 625 .mode = 0644, 626 .proc_handler = proc_dointvec 627 }, 628 { 629 .procname = "tcp_challenge_ack_limit", 630 .data = &sysctl_tcp_challenge_ack_limit, 631 .maxlen = sizeof(int), 632 .mode = 0644, 633 .proc_handler = proc_dointvec 634 }, 635 { 636 .procname = "tcp_slow_start_after_idle", 637 .data = &sysctl_tcp_slow_start_after_idle, 638 .maxlen = sizeof(int), 639 .mode = 0644, 640 .proc_handler = proc_dointvec 641 }, 642 #ifdef CONFIG_NETLABEL 643 { 644 .procname = "cipso_cache_enable", 645 .data = &cipso_v4_cache_enabled, 646 .maxlen = sizeof(int), 647 .mode = 0644, 648 .proc_handler = proc_dointvec, 649 }, 650 { 651 .procname = "cipso_cache_bucket_size", 652 .data = &cipso_v4_cache_bucketsize, 653 .maxlen = sizeof(int), 654 .mode = 0644, 655 .proc_handler = proc_dointvec, 656 }, 657 { 658 .procname = "cipso_rbm_optfmt", 659 .data = &cipso_v4_rbm_optfmt, 660 .maxlen = sizeof(int), 661 .mode = 0644, 662 .proc_handler = proc_dointvec, 663 }, 664 { 665 .procname = "cipso_rbm_strictvalid", 666 .data = &cipso_v4_rbm_strictvalid, 667 .maxlen = sizeof(int), 668 .mode = 0644, 669 .proc_handler = proc_dointvec, 670 }, 671 #endif /* CONFIG_NETLABEL */ 672 { 673 .procname = "tcp_available_congestion_control", 674 .maxlen = TCP_CA_BUF_MAX, 675 .mode = 0444, 676 .proc_handler = proc_tcp_available_congestion_control, 677 }, 678 { 679 .procname = "tcp_allowed_congestion_control", 680 .maxlen = TCP_CA_BUF_MAX, 681 .mode = 0644, 682 .proc_handler = proc_allowed_congestion_control, 683 }, 684 { 685 .procname = "tcp_thin_linear_timeouts", 686 .data = &sysctl_tcp_thin_linear_timeouts, 687 .maxlen = sizeof(int), 688 .mode = 0644, 689 .proc_handler = proc_dointvec 690 }, 691 { 692 .procname = "tcp_thin_dupack", 693 .data = &sysctl_tcp_thin_dupack, 694 .maxlen = sizeof(int), 695 .mode = 0644, 696 .proc_handler = proc_dointvec 697 }, 698 { 699 .procname = "tcp_early_retrans", 700 .data = &sysctl_tcp_early_retrans, 701 .maxlen = sizeof(int), 702 .mode = 0644, 703 .proc_handler = proc_dointvec_minmax, 704 .extra1 = &zero, 705 .extra2 = &four, 706 }, 707 { 708 .procname = "tcp_min_tso_segs", 709 .data = &sysctl_tcp_min_tso_segs, 710 .maxlen = sizeof(int), 711 .mode = 0644, 712 .proc_handler = proc_dointvec_minmax, 713 .extra1 = &one, 714 .extra2 = &gso_max_segs, 715 }, 716 { 717 .procname = "tcp_autocorking", 718 .data = &sysctl_tcp_autocorking, 719 .maxlen = sizeof(int), 720 .mode = 0644, 721 .proc_handler = proc_dointvec_minmax, 722 .extra1 = &zero, 723 .extra2 = &one, 724 }, 725 { 726 .procname = "tcp_invalid_ratelimit", 727 .data = &sysctl_tcp_invalid_ratelimit, 728 .maxlen = sizeof(int), 729 .mode = 0644, 730 .proc_handler = proc_dointvec_ms_jiffies, 731 }, 732 { 733 .procname = "icmp_msgs_per_sec", 734 .data = &sysctl_icmp_msgs_per_sec, 735 .maxlen = sizeof(int), 736 .mode = 0644, 737 .proc_handler = proc_dointvec_minmax, 738 .extra1 = &zero, 739 }, 740 { 741 .procname = "icmp_msgs_burst", 742 .data = &sysctl_icmp_msgs_burst, 743 .maxlen = sizeof(int), 744 .mode = 0644, 745 .proc_handler = proc_dointvec_minmax, 746 .extra1 = &zero, 747 }, 748 { 749 .procname = "udp_mem", 750 .data = &sysctl_udp_mem, 751 .maxlen = sizeof(sysctl_udp_mem), 752 .mode = 0644, 753 .proc_handler = proc_doulongvec_minmax, 754 }, 755 { 756 .procname = "udp_rmem_min", 757 .data = &sysctl_udp_rmem_min, 758 .maxlen = sizeof(sysctl_udp_rmem_min), 759 .mode = 0644, 760 .proc_handler = proc_dointvec_minmax, 761 .extra1 = &min_rcvbuf, 762 }, 763 { 764 .procname = "udp_wmem_min", 765 .data = &sysctl_udp_wmem_min, 766 .maxlen = sizeof(sysctl_udp_wmem_min), 767 .mode = 0644, 768 .proc_handler = proc_dointvec_minmax, 769 .extra1 = &min_sndbuf, 770 }, 771 { } 772 }; 773 774 static struct ctl_table ipv4_net_table[] = { 775 { 776 .procname = "icmp_echo_ignore_all", 777 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all, 778 .maxlen = sizeof(int), 779 .mode = 0644, 780 .proc_handler = proc_dointvec 781 }, 782 { 783 .procname = "icmp_echo_ignore_broadcasts", 784 .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts, 785 .maxlen = sizeof(int), 786 .mode = 0644, 787 .proc_handler = proc_dointvec 788 }, 789 { 790 .procname = "icmp_ignore_bogus_error_responses", 791 .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses, 792 .maxlen = sizeof(int), 793 .mode = 0644, 794 .proc_handler = proc_dointvec 795 }, 796 { 797 .procname = "icmp_errors_use_inbound_ifaddr", 798 .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr, 799 .maxlen = sizeof(int), 800 .mode = 0644, 801 .proc_handler = proc_dointvec 802 }, 803 { 804 .procname = "icmp_ratelimit", 805 .data = &init_net.ipv4.sysctl_icmp_ratelimit, 806 .maxlen = sizeof(int), 807 .mode = 0644, 808 .proc_handler = proc_dointvec_ms_jiffies, 809 }, 810 { 811 .procname = "icmp_ratemask", 812 .data = &init_net.ipv4.sysctl_icmp_ratemask, 813 .maxlen = sizeof(int), 814 .mode = 0644, 815 .proc_handler = proc_dointvec 816 }, 817 { 818 .procname = "ping_group_range", 819 .data = &init_net.ipv4.ping_group_range.range, 820 .maxlen = sizeof(gid_t)*2, 821 .mode = 0644, 822 .proc_handler = ipv4_ping_group_range, 823 }, 824 { 825 .procname = "tcp_ecn", 826 .data = &init_net.ipv4.sysctl_tcp_ecn, 827 .maxlen = sizeof(int), 828 .mode = 0644, 829 .proc_handler = proc_dointvec 830 }, 831 { 832 .procname = "tcp_ecn_fallback", 833 .data = &init_net.ipv4.sysctl_tcp_ecn_fallback, 834 .maxlen = sizeof(int), 835 .mode = 0644, 836 .proc_handler = proc_dointvec 837 }, 838 { 839 .procname = "ip_local_port_range", 840 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range), 841 .data = &init_net.ipv4.ip_local_ports.range, 842 .mode = 0644, 843 .proc_handler = ipv4_local_port_range, 844 }, 845 { 846 .procname = "ip_local_reserved_ports", 847 .data = &init_net.ipv4.sysctl_local_reserved_ports, 848 .maxlen = 65536, 849 .mode = 0644, 850 .proc_handler = proc_do_large_bitmap, 851 }, 852 { 853 .procname = "ip_no_pmtu_disc", 854 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc, 855 .maxlen = sizeof(int), 856 .mode = 0644, 857 .proc_handler = proc_dointvec 858 }, 859 { 860 .procname = "ip_forward_use_pmtu", 861 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu, 862 .maxlen = sizeof(int), 863 .mode = 0644, 864 .proc_handler = proc_dointvec, 865 }, 866 { 867 .procname = "ip_nonlocal_bind", 868 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind, 869 .maxlen = sizeof(int), 870 .mode = 0644, 871 .proc_handler = proc_dointvec 872 }, 873 { 874 .procname = "fwmark_reflect", 875 .data = &init_net.ipv4.sysctl_fwmark_reflect, 876 .maxlen = sizeof(int), 877 .mode = 0644, 878 .proc_handler = proc_dointvec, 879 }, 880 { 881 .procname = "tcp_fwmark_accept", 882 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept, 883 .maxlen = sizeof(int), 884 .mode = 0644, 885 .proc_handler = proc_dointvec, 886 }, 887 { 888 .procname = "tcp_mtu_probing", 889 .data = &init_net.ipv4.sysctl_tcp_mtu_probing, 890 .maxlen = sizeof(int), 891 .mode = 0644, 892 .proc_handler = proc_dointvec, 893 }, 894 { 895 .procname = "tcp_base_mss", 896 .data = &init_net.ipv4.sysctl_tcp_base_mss, 897 .maxlen = sizeof(int), 898 .mode = 0644, 899 .proc_handler = proc_dointvec, 900 }, 901 { 902 .procname = "tcp_probe_threshold", 903 .data = &init_net.ipv4.sysctl_tcp_probe_threshold, 904 .maxlen = sizeof(int), 905 .mode = 0644, 906 .proc_handler = proc_dointvec, 907 }, 908 { 909 .procname = "tcp_probe_interval", 910 .data = &init_net.ipv4.sysctl_tcp_probe_interval, 911 .maxlen = sizeof(int), 912 .mode = 0644, 913 .proc_handler = proc_dointvec, 914 }, 915 { } 916 }; 917 918 static __net_init int ipv4_sysctl_init_net(struct net *net) 919 { 920 struct ctl_table *table; 921 922 table = ipv4_net_table; 923 if (!net_eq(net, &init_net)) { 924 int i; 925 926 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL); 927 if (!table) 928 goto err_alloc; 929 930 /* Update the variables to point into the current struct net */ 931 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) 932 table[i].data += (void *)net - (void *)&init_net; 933 } 934 935 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table); 936 if (!net->ipv4.ipv4_hdr) 937 goto err_reg; 938 939 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL); 940 if (!net->ipv4.sysctl_local_reserved_ports) 941 goto err_ports; 942 943 return 0; 944 945 err_ports: 946 unregister_net_sysctl_table(net->ipv4.ipv4_hdr); 947 err_reg: 948 if (!net_eq(net, &init_net)) 949 kfree(table); 950 err_alloc: 951 return -ENOMEM; 952 } 953 954 static __net_exit void ipv4_sysctl_exit_net(struct net *net) 955 { 956 struct ctl_table *table; 957 958 kfree(net->ipv4.sysctl_local_reserved_ports); 959 table = net->ipv4.ipv4_hdr->ctl_table_arg; 960 unregister_net_sysctl_table(net->ipv4.ipv4_hdr); 961 kfree(table); 962 } 963 964 static __net_initdata struct pernet_operations ipv4_sysctl_ops = { 965 .init = ipv4_sysctl_init_net, 966 .exit = ipv4_sysctl_exit_net, 967 }; 968 969 static __init int sysctl_ipv4_init(void) 970 { 971 struct ctl_table_header *hdr; 972 973 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table); 974 if (!hdr) 975 return -ENOMEM; 976 977 if (register_pernet_subsys(&ipv4_sysctl_ops)) { 978 unregister_net_sysctl_table(hdr); 979 return -ENOMEM; 980 } 981 982 return 0; 983 } 984 985 __initcall(sysctl_ipv4_init); 986