sysctl_net_ipv4.c 27 KB

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