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