sysctl_net_ipv4.c 25 KB

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