sysctl_net_ipv4.c 22 KB

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