sysctl_net_ipv4.c 24 KB

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