sysctl_net_ipv4.c 24 KB

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