sysctl_net_ipv4.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  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. #include <linux/mm.h>
  8. #include <linux/module.h>
  9. #include <linux/sysctl.h>
  10. #include <linux/igmp.h>
  11. #include <linux/inetdevice.h>
  12. #include <linux/seqlock.h>
  13. #include <linux/init.h>
  14. #include <linux/slab.h>
  15. #include <linux/nsproxy.h>
  16. #include <net/snmp.h>
  17. #include <net/icmp.h>
  18. #include <net/ip.h>
  19. #include <net/route.h>
  20. #include <net/tcp.h>
  21. #include <net/udp.h>
  22. #include <net/cipso_ipv4.h>
  23. #include <net/inet_frag.h>
  24. #include <net/ping.h>
  25. static int zero;
  26. static int tcp_retr1_max = 255;
  27. static int ip_local_port_range_min[] = { 1, 1 };
  28. static int ip_local_port_range_max[] = { 65535, 65535 };
  29. static int tcp_adv_win_scale_min = -31;
  30. static int tcp_adv_win_scale_max = 31;
  31. static int ip_ttl_min = 1;
  32. static int ip_ttl_max = 255;
  33. static int ip_ping_group_range_min[] = { 0, 0 };
  34. static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
  35. /* Update system visible IP port range */
  36. static void set_local_port_range(int range[2])
  37. {
  38. write_seqlock(&sysctl_local_ports.lock);
  39. sysctl_local_ports.range[0] = range[0];
  40. sysctl_local_ports.range[1] = range[1];
  41. write_sequnlock(&sysctl_local_ports.lock);
  42. }
  43. /* Validate changes from /proc interface. */
  44. static int ipv4_local_port_range(ctl_table *table, int write,
  45. void __user *buffer,
  46. size_t *lenp, loff_t *ppos)
  47. {
  48. int ret;
  49. int range[2];
  50. ctl_table tmp = {
  51. .data = &range,
  52. .maxlen = sizeof(range),
  53. .mode = table->mode,
  54. .extra1 = &ip_local_port_range_min,
  55. .extra2 = &ip_local_port_range_max,
  56. };
  57. inet_get_local_port_range(range, range + 1);
  58. ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
  59. if (write && ret == 0) {
  60. if (range[1] < range[0])
  61. ret = -EINVAL;
  62. else
  63. set_local_port_range(range);
  64. }
  65. return ret;
  66. }
  67. void inet_get_ping_group_range_table(struct ctl_table *table, gid_t *low, gid_t *high)
  68. {
  69. gid_t *data = table->data;
  70. unsigned seq;
  71. do {
  72. seq = read_seqbegin(&sysctl_local_ports.lock);
  73. *low = data[0];
  74. *high = data[1];
  75. } while (read_seqretry(&sysctl_local_ports.lock, seq));
  76. }
  77. /* Update system visible IP port range */
  78. static void set_ping_group_range(struct ctl_table *table, int range[2])
  79. {
  80. gid_t *data = table->data;
  81. write_seqlock(&sysctl_local_ports.lock);
  82. data[0] = range[0];
  83. data[1] = range[1];
  84. write_sequnlock(&sysctl_local_ports.lock);
  85. }
  86. /* Validate changes from /proc interface. */
  87. static int ipv4_ping_group_range(ctl_table *table, int write,
  88. void __user *buffer,
  89. size_t *lenp, loff_t *ppos)
  90. {
  91. int ret;
  92. gid_t range[2];
  93. ctl_table tmp = {
  94. .data = &range,
  95. .maxlen = sizeof(range),
  96. .mode = table->mode,
  97. .extra1 = &ip_ping_group_range_min,
  98. .extra2 = &ip_ping_group_range_max,
  99. };
  100. inet_get_ping_group_range_table(table, range, range + 1);
  101. ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
  102. if (write && ret == 0)
  103. set_ping_group_range(table, range);
  104. return ret;
  105. }
  106. static int proc_tcp_congestion_control(ctl_table *ctl, int write,
  107. void __user *buffer, size_t *lenp, loff_t *ppos)
  108. {
  109. char val[TCP_CA_NAME_MAX];
  110. ctl_table tbl = {
  111. .data = val,
  112. .maxlen = TCP_CA_NAME_MAX,
  113. };
  114. int ret;
  115. tcp_get_default_congestion_control(val);
  116. ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
  117. if (write && ret == 0)
  118. ret = tcp_set_default_congestion_control(val);
  119. return ret;
  120. }
  121. static int proc_tcp_available_congestion_control(ctl_table *ctl,
  122. int write,
  123. void __user *buffer, size_t *lenp,
  124. loff_t *ppos)
  125. {
  126. ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
  127. int ret;
  128. tbl.data = kmalloc(tbl.maxlen, GFP_USER);
  129. if (!tbl.data)
  130. return -ENOMEM;
  131. tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
  132. ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
  133. kfree(tbl.data);
  134. return ret;
  135. }
  136. static int proc_allowed_congestion_control(ctl_table *ctl,
  137. int write,
  138. void __user *buffer, size_t *lenp,
  139. loff_t *ppos)
  140. {
  141. ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
  142. int ret;
  143. tbl.data = kmalloc(tbl.maxlen, GFP_USER);
  144. if (!tbl.data)
  145. return -ENOMEM;
  146. tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
  147. ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
  148. if (write && ret == 0)
  149. ret = tcp_set_allowed_congestion_control(tbl.data);
  150. kfree(tbl.data);
  151. return ret;
  152. }
  153. static struct ctl_table ipv4_table[] = {
  154. {
  155. .procname = "tcp_timestamps",
  156. .data = &sysctl_tcp_timestamps,
  157. .maxlen = sizeof(int),
  158. .mode = 0644,
  159. .proc_handler = proc_dointvec
  160. },
  161. {
  162. .procname = "tcp_window_scaling",
  163. .data = &sysctl_tcp_window_scaling,
  164. .maxlen = sizeof(int),
  165. .mode = 0644,
  166. .proc_handler = proc_dointvec
  167. },
  168. {
  169. .procname = "tcp_sack",
  170. .data = &sysctl_tcp_sack,
  171. .maxlen = sizeof(int),
  172. .mode = 0644,
  173. .proc_handler = proc_dointvec
  174. },
  175. {
  176. .procname = "tcp_retrans_collapse",
  177. .data = &sysctl_tcp_retrans_collapse,
  178. .maxlen = sizeof(int),
  179. .mode = 0644,
  180. .proc_handler = proc_dointvec
  181. },
  182. {
  183. .procname = "ip_default_ttl",
  184. .data = &sysctl_ip_default_ttl,
  185. .maxlen = sizeof(int),
  186. .mode = 0644,
  187. .proc_handler = proc_dointvec_minmax,
  188. .extra1 = &ip_ttl_min,
  189. .extra2 = &ip_ttl_max,
  190. },
  191. {
  192. .procname = "ip_no_pmtu_disc",
  193. .data = &ipv4_config.no_pmtu_disc,
  194. .maxlen = sizeof(int),
  195. .mode = 0644,
  196. .proc_handler = proc_dointvec
  197. },
  198. {
  199. .procname = "ip_nonlocal_bind",
  200. .data = &sysctl_ip_nonlocal_bind,
  201. .maxlen = sizeof(int),
  202. .mode = 0644,
  203. .proc_handler = proc_dointvec
  204. },
  205. {
  206. .procname = "tcp_syn_retries",
  207. .data = &sysctl_tcp_syn_retries,
  208. .maxlen = sizeof(int),
  209. .mode = 0644,
  210. .proc_handler = proc_dointvec
  211. },
  212. {
  213. .procname = "tcp_synack_retries",
  214. .data = &sysctl_tcp_synack_retries,
  215. .maxlen = sizeof(int),
  216. .mode = 0644,
  217. .proc_handler = proc_dointvec
  218. },
  219. {
  220. .procname = "tcp_max_orphans",
  221. .data = &sysctl_tcp_max_orphans,
  222. .maxlen = sizeof(int),
  223. .mode = 0644,
  224. .proc_handler = proc_dointvec
  225. },
  226. {
  227. .procname = "tcp_max_tw_buckets",
  228. .data = &tcp_death_row.sysctl_max_tw_buckets,
  229. .maxlen = sizeof(int),
  230. .mode = 0644,
  231. .proc_handler = proc_dointvec
  232. },
  233. {
  234. .procname = "ip_dynaddr",
  235. .data = &sysctl_ip_dynaddr,
  236. .maxlen = sizeof(int),
  237. .mode = 0644,
  238. .proc_handler = proc_dointvec
  239. },
  240. {
  241. .procname = "tcp_keepalive_time",
  242. .data = &sysctl_tcp_keepalive_time,
  243. .maxlen = sizeof(int),
  244. .mode = 0644,
  245. .proc_handler = proc_dointvec_jiffies,
  246. },
  247. {
  248. .procname = "tcp_keepalive_probes",
  249. .data = &sysctl_tcp_keepalive_probes,
  250. .maxlen = sizeof(int),
  251. .mode = 0644,
  252. .proc_handler = proc_dointvec
  253. },
  254. {
  255. .procname = "tcp_keepalive_intvl",
  256. .data = &sysctl_tcp_keepalive_intvl,
  257. .maxlen = sizeof(int),
  258. .mode = 0644,
  259. .proc_handler = proc_dointvec_jiffies,
  260. },
  261. {
  262. .procname = "tcp_retries1",
  263. .data = &sysctl_tcp_retries1,
  264. .maxlen = sizeof(int),
  265. .mode = 0644,
  266. .proc_handler = proc_dointvec_minmax,
  267. .extra2 = &tcp_retr1_max
  268. },
  269. {
  270. .procname = "tcp_retries2",
  271. .data = &sysctl_tcp_retries2,
  272. .maxlen = sizeof(int),
  273. .mode = 0644,
  274. .proc_handler = proc_dointvec
  275. },
  276. {
  277. .procname = "tcp_fin_timeout",
  278. .data = &sysctl_tcp_fin_timeout,
  279. .maxlen = sizeof(int),
  280. .mode = 0644,
  281. .proc_handler = proc_dointvec_jiffies,
  282. },
  283. #ifdef CONFIG_SYN_COOKIES
  284. {
  285. .procname = "tcp_syncookies",
  286. .data = &sysctl_tcp_syncookies,
  287. .maxlen = sizeof(int),
  288. .mode = 0644,
  289. .proc_handler = proc_dointvec
  290. },
  291. #endif
  292. {
  293. .procname = "tcp_tw_recycle",
  294. .data = &tcp_death_row.sysctl_tw_recycle,
  295. .maxlen = sizeof(int),
  296. .mode = 0644,
  297. .proc_handler = proc_dointvec
  298. },
  299. {
  300. .procname = "tcp_abort_on_overflow",
  301. .data = &sysctl_tcp_abort_on_overflow,
  302. .maxlen = sizeof(int),
  303. .mode = 0644,
  304. .proc_handler = proc_dointvec
  305. },
  306. {
  307. .procname = "tcp_stdurg",
  308. .data = &sysctl_tcp_stdurg,
  309. .maxlen = sizeof(int),
  310. .mode = 0644,
  311. .proc_handler = proc_dointvec
  312. },
  313. {
  314. .procname = "tcp_rfc1337",
  315. .data = &sysctl_tcp_rfc1337,
  316. .maxlen = sizeof(int),
  317. .mode = 0644,
  318. .proc_handler = proc_dointvec
  319. },
  320. {
  321. .procname = "tcp_max_syn_backlog",
  322. .data = &sysctl_max_syn_backlog,
  323. .maxlen = sizeof(int),
  324. .mode = 0644,
  325. .proc_handler = proc_dointvec
  326. },
  327. {
  328. .procname = "ip_local_port_range",
  329. .data = &sysctl_local_ports.range,
  330. .maxlen = sizeof(sysctl_local_ports.range),
  331. .mode = 0644,
  332. .proc_handler = ipv4_local_port_range,
  333. },
  334. {
  335. .procname = "ip_local_reserved_ports",
  336. .data = NULL, /* initialized in sysctl_ipv4_init */
  337. .maxlen = 65536,
  338. .mode = 0644,
  339. .proc_handler = proc_do_large_bitmap,
  340. },
  341. {
  342. .procname = "igmp_max_memberships",
  343. .data = &sysctl_igmp_max_memberships,
  344. .maxlen = sizeof(int),
  345. .mode = 0644,
  346. .proc_handler = proc_dointvec
  347. },
  348. {
  349. .procname = "igmp_max_msf",
  350. .data = &sysctl_igmp_max_msf,
  351. .maxlen = sizeof(int),
  352. .mode = 0644,
  353. .proc_handler = proc_dointvec
  354. },
  355. {
  356. .procname = "inet_peer_threshold",
  357. .data = &inet_peer_threshold,
  358. .maxlen = sizeof(int),
  359. .mode = 0644,
  360. .proc_handler = proc_dointvec
  361. },
  362. {
  363. .procname = "inet_peer_minttl",
  364. .data = &inet_peer_minttl,
  365. .maxlen = sizeof(int),
  366. .mode = 0644,
  367. .proc_handler = proc_dointvec_jiffies,
  368. },
  369. {
  370. .procname = "inet_peer_maxttl",
  371. .data = &inet_peer_maxttl,
  372. .maxlen = sizeof(int),
  373. .mode = 0644,
  374. .proc_handler = proc_dointvec_jiffies,
  375. },
  376. {
  377. .procname = "inet_peer_gc_mintime",
  378. .data = &inet_peer_gc_mintime,
  379. .maxlen = sizeof(int),
  380. .mode = 0644,
  381. .proc_handler = proc_dointvec_jiffies,
  382. },
  383. {
  384. .procname = "inet_peer_gc_maxtime",
  385. .data = &inet_peer_gc_maxtime,
  386. .maxlen = sizeof(int),
  387. .mode = 0644,
  388. .proc_handler = proc_dointvec_jiffies,
  389. },
  390. {
  391. .procname = "tcp_orphan_retries",
  392. .data = &sysctl_tcp_orphan_retries,
  393. .maxlen = sizeof(int),
  394. .mode = 0644,
  395. .proc_handler = proc_dointvec
  396. },
  397. {
  398. .procname = "tcp_fack",
  399. .data = &sysctl_tcp_fack,
  400. .maxlen = sizeof(int),
  401. .mode = 0644,
  402. .proc_handler = proc_dointvec
  403. },
  404. {
  405. .procname = "tcp_reordering",
  406. .data = &sysctl_tcp_reordering,
  407. .maxlen = sizeof(int),
  408. .mode = 0644,
  409. .proc_handler = proc_dointvec
  410. },
  411. {
  412. .procname = "tcp_ecn",
  413. .data = &sysctl_tcp_ecn,
  414. .maxlen = sizeof(int),
  415. .mode = 0644,
  416. .proc_handler = proc_dointvec
  417. },
  418. {
  419. .procname = "tcp_dsack",
  420. .data = &sysctl_tcp_dsack,
  421. .maxlen = sizeof(int),
  422. .mode = 0644,
  423. .proc_handler = proc_dointvec
  424. },
  425. {
  426. .procname = "tcp_mem",
  427. .data = &sysctl_tcp_mem,
  428. .maxlen = sizeof(sysctl_tcp_mem),
  429. .mode = 0644,
  430. .proc_handler = proc_doulongvec_minmax
  431. },
  432. {
  433. .procname = "tcp_wmem",
  434. .data = &sysctl_tcp_wmem,
  435. .maxlen = sizeof(sysctl_tcp_wmem),
  436. .mode = 0644,
  437. .proc_handler = proc_dointvec
  438. },
  439. {
  440. .procname = "tcp_rmem",
  441. .data = &sysctl_tcp_rmem,
  442. .maxlen = sizeof(sysctl_tcp_rmem),
  443. .mode = 0644,
  444. .proc_handler = proc_dointvec
  445. },
  446. {
  447. .procname = "tcp_app_win",
  448. .data = &sysctl_tcp_app_win,
  449. .maxlen = sizeof(int),
  450. .mode = 0644,
  451. .proc_handler = proc_dointvec
  452. },
  453. {
  454. .procname = "tcp_adv_win_scale",
  455. .data = &sysctl_tcp_adv_win_scale,
  456. .maxlen = sizeof(int),
  457. .mode = 0644,
  458. .proc_handler = proc_dointvec_minmax,
  459. .extra1 = &tcp_adv_win_scale_min,
  460. .extra2 = &tcp_adv_win_scale_max,
  461. },
  462. {
  463. .procname = "tcp_tw_reuse",
  464. .data = &sysctl_tcp_tw_reuse,
  465. .maxlen = sizeof(int),
  466. .mode = 0644,
  467. .proc_handler = proc_dointvec
  468. },
  469. {
  470. .procname = "tcp_frto",
  471. .data = &sysctl_tcp_frto,
  472. .maxlen = sizeof(int),
  473. .mode = 0644,
  474. .proc_handler = proc_dointvec
  475. },
  476. {
  477. .procname = "tcp_frto_response",
  478. .data = &sysctl_tcp_frto_response,
  479. .maxlen = sizeof(int),
  480. .mode = 0644,
  481. .proc_handler = proc_dointvec
  482. },
  483. {
  484. .procname = "tcp_low_latency",
  485. .data = &sysctl_tcp_low_latency,
  486. .maxlen = sizeof(int),
  487. .mode = 0644,
  488. .proc_handler = proc_dointvec
  489. },
  490. {
  491. .procname = "tcp_no_metrics_save",
  492. .data = &sysctl_tcp_nometrics_save,
  493. .maxlen = sizeof(int),
  494. .mode = 0644,
  495. .proc_handler = proc_dointvec,
  496. },
  497. {
  498. .procname = "tcp_moderate_rcvbuf",
  499. .data = &sysctl_tcp_moderate_rcvbuf,
  500. .maxlen = sizeof(int),
  501. .mode = 0644,
  502. .proc_handler = proc_dointvec,
  503. },
  504. {
  505. .procname = "tcp_tso_win_divisor",
  506. .data = &sysctl_tcp_tso_win_divisor,
  507. .maxlen = sizeof(int),
  508. .mode = 0644,
  509. .proc_handler = proc_dointvec,
  510. },
  511. {
  512. .procname = "tcp_congestion_control",
  513. .mode = 0644,
  514. .maxlen = TCP_CA_NAME_MAX,
  515. .proc_handler = proc_tcp_congestion_control,
  516. },
  517. {
  518. .procname = "tcp_abc",
  519. .data = &sysctl_tcp_abc,
  520. .maxlen = sizeof(int),
  521. .mode = 0644,
  522. .proc_handler = proc_dointvec,
  523. },
  524. {
  525. .procname = "tcp_mtu_probing",
  526. .data = &sysctl_tcp_mtu_probing,
  527. .maxlen = sizeof(int),
  528. .mode = 0644,
  529. .proc_handler = proc_dointvec,
  530. },
  531. {
  532. .procname = "tcp_base_mss",
  533. .data = &sysctl_tcp_base_mss,
  534. .maxlen = sizeof(int),
  535. .mode = 0644,
  536. .proc_handler = proc_dointvec,
  537. },
  538. {
  539. .procname = "tcp_workaround_signed_windows",
  540. .data = &sysctl_tcp_workaround_signed_windows,
  541. .maxlen = sizeof(int),
  542. .mode = 0644,
  543. .proc_handler = proc_dointvec
  544. },
  545. #ifdef CONFIG_NET_DMA
  546. {
  547. .procname = "tcp_dma_copybreak",
  548. .data = &sysctl_tcp_dma_copybreak,
  549. .maxlen = sizeof(int),
  550. .mode = 0644,
  551. .proc_handler = proc_dointvec
  552. },
  553. #endif
  554. {
  555. .procname = "tcp_slow_start_after_idle",
  556. .data = &sysctl_tcp_slow_start_after_idle,
  557. .maxlen = sizeof(int),
  558. .mode = 0644,
  559. .proc_handler = proc_dointvec
  560. },
  561. #ifdef CONFIG_NETLABEL
  562. {
  563. .procname = "cipso_cache_enable",
  564. .data = &cipso_v4_cache_enabled,
  565. .maxlen = sizeof(int),
  566. .mode = 0644,
  567. .proc_handler = proc_dointvec,
  568. },
  569. {
  570. .procname = "cipso_cache_bucket_size",
  571. .data = &cipso_v4_cache_bucketsize,
  572. .maxlen = sizeof(int),
  573. .mode = 0644,
  574. .proc_handler = proc_dointvec,
  575. },
  576. {
  577. .procname = "cipso_rbm_optfmt",
  578. .data = &cipso_v4_rbm_optfmt,
  579. .maxlen = sizeof(int),
  580. .mode = 0644,
  581. .proc_handler = proc_dointvec,
  582. },
  583. {
  584. .procname = "cipso_rbm_strictvalid",
  585. .data = &cipso_v4_rbm_strictvalid,
  586. .maxlen = sizeof(int),
  587. .mode = 0644,
  588. .proc_handler = proc_dointvec,
  589. },
  590. #endif /* CONFIG_NETLABEL */
  591. {
  592. .procname = "tcp_available_congestion_control",
  593. .maxlen = TCP_CA_BUF_MAX,
  594. .mode = 0444,
  595. .proc_handler = proc_tcp_available_congestion_control,
  596. },
  597. {
  598. .procname = "tcp_allowed_congestion_control",
  599. .maxlen = TCP_CA_BUF_MAX,
  600. .mode = 0644,
  601. .proc_handler = proc_allowed_congestion_control,
  602. },
  603. {
  604. .procname = "tcp_max_ssthresh",
  605. .data = &sysctl_tcp_max_ssthresh,
  606. .maxlen = sizeof(int),
  607. .mode = 0644,
  608. .proc_handler = proc_dointvec,
  609. },
  610. {
  611. .procname = "tcp_cookie_size",
  612. .data = &sysctl_tcp_cookie_size,
  613. .maxlen = sizeof(int),
  614. .mode = 0644,
  615. .proc_handler = proc_dointvec
  616. },
  617. {
  618. .procname = "tcp_thin_linear_timeouts",
  619. .data = &sysctl_tcp_thin_linear_timeouts,
  620. .maxlen = sizeof(int),
  621. .mode = 0644,
  622. .proc_handler = proc_dointvec
  623. },
  624. {
  625. .procname = "tcp_thin_dupack",
  626. .data = &sysctl_tcp_thin_dupack,
  627. .maxlen = sizeof(int),
  628. .mode = 0644,
  629. .proc_handler = proc_dointvec
  630. },
  631. {
  632. .procname = "udp_mem",
  633. .data = &sysctl_udp_mem,
  634. .maxlen = sizeof(sysctl_udp_mem),
  635. .mode = 0644,
  636. .proc_handler = proc_doulongvec_minmax,
  637. },
  638. {
  639. .procname = "udp_rmem_min",
  640. .data = &sysctl_udp_rmem_min,
  641. .maxlen = sizeof(sysctl_udp_rmem_min),
  642. .mode = 0644,
  643. .proc_handler = proc_dointvec_minmax,
  644. .extra1 = &zero
  645. },
  646. {
  647. .procname = "udp_wmem_min",
  648. .data = &sysctl_udp_wmem_min,
  649. .maxlen = sizeof(sysctl_udp_wmem_min),
  650. .mode = 0644,
  651. .proc_handler = proc_dointvec_minmax,
  652. .extra1 = &zero
  653. },
  654. { }
  655. };
  656. static struct ctl_table ipv4_net_table[] = {
  657. {
  658. .procname = "icmp_echo_ignore_all",
  659. .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
  660. .maxlen = sizeof(int),
  661. .mode = 0644,
  662. .proc_handler = proc_dointvec
  663. },
  664. {
  665. .procname = "icmp_echo_ignore_broadcasts",
  666. .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
  667. .maxlen = sizeof(int),
  668. .mode = 0644,
  669. .proc_handler = proc_dointvec
  670. },
  671. {
  672. .procname = "icmp_ignore_bogus_error_responses",
  673. .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
  674. .maxlen = sizeof(int),
  675. .mode = 0644,
  676. .proc_handler = proc_dointvec
  677. },
  678. {
  679. .procname = "icmp_errors_use_inbound_ifaddr",
  680. .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
  681. .maxlen = sizeof(int),
  682. .mode = 0644,
  683. .proc_handler = proc_dointvec
  684. },
  685. {
  686. .procname = "icmp_ratelimit",
  687. .data = &init_net.ipv4.sysctl_icmp_ratelimit,
  688. .maxlen = sizeof(int),
  689. .mode = 0644,
  690. .proc_handler = proc_dointvec_ms_jiffies,
  691. },
  692. {
  693. .procname = "icmp_ratemask",
  694. .data = &init_net.ipv4.sysctl_icmp_ratemask,
  695. .maxlen = sizeof(int),
  696. .mode = 0644,
  697. .proc_handler = proc_dointvec
  698. },
  699. {
  700. .procname = "rt_cache_rebuild_count",
  701. .data = &init_net.ipv4.sysctl_rt_cache_rebuild_count,
  702. .maxlen = sizeof(int),
  703. .mode = 0644,
  704. .proc_handler = proc_dointvec
  705. },
  706. {
  707. .procname = "ping_group_range",
  708. .data = &init_net.ipv4.sysctl_ping_group_range,
  709. .maxlen = sizeof(init_net.ipv4.sysctl_ping_group_range),
  710. .mode = 0644,
  711. .proc_handler = ipv4_ping_group_range,
  712. },
  713. { }
  714. };
  715. struct ctl_path net_ipv4_ctl_path[] = {
  716. { .procname = "net", },
  717. { .procname = "ipv4", },
  718. { },
  719. };
  720. EXPORT_SYMBOL_GPL(net_ipv4_ctl_path);
  721. static __net_init int ipv4_sysctl_init_net(struct net *net)
  722. {
  723. struct ctl_table *table;
  724. table = ipv4_net_table;
  725. if (!net_eq(net, &init_net)) {
  726. table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
  727. if (table == NULL)
  728. goto err_alloc;
  729. table[0].data =
  730. &net->ipv4.sysctl_icmp_echo_ignore_all;
  731. table[1].data =
  732. &net->ipv4.sysctl_icmp_echo_ignore_broadcasts;
  733. table[2].data =
  734. &net->ipv4.sysctl_icmp_ignore_bogus_error_responses;
  735. table[3].data =
  736. &net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr;
  737. table[4].data =
  738. &net->ipv4.sysctl_icmp_ratelimit;
  739. table[5].data =
  740. &net->ipv4.sysctl_icmp_ratemask;
  741. table[6].data =
  742. &net->ipv4.sysctl_rt_cache_rebuild_count;
  743. table[7].data =
  744. &net->ipv4.sysctl_ping_group_range;
  745. }
  746. /*
  747. * Sane defaults - nobody may create ping sockets.
  748. * Boot scripts should set this to distro-specific group.
  749. */
  750. net->ipv4.sysctl_ping_group_range[0] = 1;
  751. net->ipv4.sysctl_ping_group_range[1] = 0;
  752. net->ipv4.sysctl_rt_cache_rebuild_count = 4;
  753. net->ipv4.ipv4_hdr = register_net_sysctl_table(net,
  754. net_ipv4_ctl_path, table);
  755. if (net->ipv4.ipv4_hdr == NULL)
  756. goto err_reg;
  757. return 0;
  758. err_reg:
  759. if (!net_eq(net, &init_net))
  760. kfree(table);
  761. err_alloc:
  762. return -ENOMEM;
  763. }
  764. static __net_exit void ipv4_sysctl_exit_net(struct net *net)
  765. {
  766. struct ctl_table *table;
  767. table = net->ipv4.ipv4_hdr->ctl_table_arg;
  768. unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
  769. kfree(table);
  770. }
  771. static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
  772. .init = ipv4_sysctl_init_net,
  773. .exit = ipv4_sysctl_exit_net,
  774. };
  775. static __init int sysctl_ipv4_init(void)
  776. {
  777. struct ctl_table_header *hdr;
  778. struct ctl_table *i;
  779. for (i = ipv4_table; i->procname; i++) {
  780. if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
  781. i->data = sysctl_local_reserved_ports;
  782. break;
  783. }
  784. }
  785. if (!i->procname)
  786. return -EINVAL;
  787. hdr = register_sysctl_paths(net_ipv4_ctl_path, ipv4_table);
  788. if (hdr == NULL)
  789. return -ENOMEM;
  790. if (register_pernet_subsys(&ipv4_sysctl_ops)) {
  791. unregister_sysctl_table(hdr);
  792. return -ENOMEM;
  793. }
  794. return 0;
  795. }
  796. __initcall(sysctl_ipv4_init);