sysctl_net_ipv4.c 20 KB

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