sysctl_net_ipv4.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
  4. *
  5. * Begun April 1, 1996, Mike Shaver.
  6. * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
  7. */
  8. #include <linux/sysctl.h>
  9. #include <linux/seqlock.h>
  10. #include <linux/init.h>
  11. #include <linux/slab.h>
  12. #include <net/icmp.h>
  13. #include <net/ip.h>
  14. #include <net/ip_fib.h>
  15. #include <net/tcp.h>
  16. #include <net/udp.h>
  17. #include <net/cipso_ipv4.h>
  18. #include <net/ping.h>
  19. #include <net/protocol.h>
  20. #include <net/netevent.h>
  21. static int tcp_retr1_max = 255;
  22. static int ip_local_port_range_min[] = { 1, 1 };
  23. static int ip_local_port_range_max[] = { 65535, 65535 };
  24. static int tcp_adv_win_scale_min = -31;
  25. static int tcp_adv_win_scale_max = 31;
  26. static int tcp_app_win_max = 31;
  27. static int tcp_min_snd_mss_min = TCP_MIN_SND_MSS;
  28. static int tcp_min_snd_mss_max = 65535;
  29. static int tcp_rto_max_max = TCP_RTO_MAX_SEC * MSEC_PER_SEC;
  30. static int ip_privileged_port_min;
  31. static int ip_privileged_port_max = 65535;
  32. static int ip_ttl_min = 1;
  33. static int ip_ttl_max = 255;
  34. static int tcp_syn_retries_min = 1;
  35. static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
  36. static int tcp_syn_linear_timeouts_max = MAX_TCP_SYNCNT;
  37. static unsigned long ip_ping_group_range_min[] = { 0, 0 };
  38. static unsigned long ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
  39. static u32 u32_max_div_HZ = UINT_MAX / HZ;
  40. static int one_day_secs = 24 * 3600;
  41. static u32 fib_multipath_hash_fields_all_mask __maybe_unused =
  42. FIB_MULTIPATH_HASH_FIELD_ALL_MASK;
  43. static unsigned int tcp_child_ehash_entries_max = 16 * 1024 * 1024;
  44. static unsigned int udp_child_hash_entries_max = UDP_HTABLE_SIZE_MAX;
  45. static int tcp_plb_max_rounds = 31;
  46. static int tcp_plb_max_cong_thresh = 256;
  47. static unsigned int tcp_tw_reuse_delay_max = TCP_PAWS_MSL * MSEC_PER_SEC;
  48. static int tcp_ecn_mode_max = 5;
  49. static u32 icmp_errors_extension_mask_all =
  50. GENMASK_U8(ICMP_ERR_EXT_COUNT - 1, 0);
  51. /* obsolete */
  52. static int sysctl_tcp_low_latency __read_mostly;
  53. /* Update system visible IP port range */
  54. static void set_local_port_range(struct net *net, unsigned int low, unsigned int high)
  55. {
  56. bool same_parity = !((low ^ high) & 1);
  57. if (same_parity && !net->ipv4.ip_local_ports.warned) {
  58. net->ipv4.ip_local_ports.warned = true;
  59. pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
  60. }
  61. WRITE_ONCE(net->ipv4.ip_local_ports.range, high << 16 | low);
  62. }
  63. /* Validate changes from /proc interface. */
  64. static int ipv4_local_port_range(const struct ctl_table *table, int write,
  65. void *buffer, size_t *lenp, loff_t *ppos)
  66. {
  67. struct net *net = table->data;
  68. int ret;
  69. int range[2];
  70. struct ctl_table tmp = {
  71. .data = &range,
  72. .maxlen = sizeof(range),
  73. .mode = table->mode,
  74. .extra1 = &ip_local_port_range_min,
  75. .extra2 = &ip_local_port_range_max,
  76. };
  77. inet_get_local_port_range(net, &range[0], &range[1]);
  78. ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
  79. if (write && ret == 0) {
  80. /* Ensure that the upper limit is not smaller than the lower,
  81. * and that the lower does not encroach upon the privileged
  82. * port limit.
  83. */
  84. if ((range[1] < range[0]) ||
  85. (range[0] < READ_ONCE(net->ipv4.sysctl_ip_prot_sock)))
  86. ret = -EINVAL;
  87. else
  88. set_local_port_range(net, range[0], range[1]);
  89. }
  90. return ret;
  91. }
  92. /* Validate changes from /proc interface. */
  93. static int ipv4_privileged_ports(const struct ctl_table *table, int write,
  94. void *buffer, size_t *lenp, loff_t *ppos)
  95. {
  96. struct net *net = container_of(table->data, struct net,
  97. ipv4.sysctl_ip_prot_sock);
  98. int ret;
  99. int pports;
  100. int range[2];
  101. struct ctl_table tmp = {
  102. .data = &pports,
  103. .maxlen = sizeof(pports),
  104. .mode = table->mode,
  105. .extra1 = &ip_privileged_port_min,
  106. .extra2 = &ip_privileged_port_max,
  107. };
  108. pports = READ_ONCE(net->ipv4.sysctl_ip_prot_sock);
  109. ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
  110. if (write && ret == 0) {
  111. inet_get_local_port_range(net, &range[0], &range[1]);
  112. /* Ensure that the local port range doesn't overlap with the
  113. * privileged port range.
  114. */
  115. if (range[0] < pports)
  116. ret = -EINVAL;
  117. else
  118. WRITE_ONCE(net->ipv4.sysctl_ip_prot_sock, pports);
  119. }
  120. return ret;
  121. }
  122. static void inet_get_ping_group_range_table(const struct ctl_table *table,
  123. kgid_t *low, kgid_t *high)
  124. {
  125. kgid_t *data = table->data;
  126. struct net *net =
  127. container_of(table->data, struct net, ipv4.ping_group_range.range);
  128. unsigned int seq;
  129. do {
  130. seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
  131. *low = data[0];
  132. *high = data[1];
  133. } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
  134. }
  135. /* Update system visible IP port range */
  136. static void set_ping_group_range(const struct ctl_table *table,
  137. kgid_t low, kgid_t high)
  138. {
  139. kgid_t *data = table->data;
  140. struct net *net =
  141. container_of(table->data, struct net, ipv4.ping_group_range.range);
  142. write_seqlock(&net->ipv4.ping_group_range.lock);
  143. data[0] = low;
  144. data[1] = high;
  145. write_sequnlock(&net->ipv4.ping_group_range.lock);
  146. }
  147. /* Validate changes from /proc interface. */
  148. static int ipv4_ping_group_range(const struct ctl_table *table, int write,
  149. void *buffer, size_t *lenp, loff_t *ppos)
  150. {
  151. struct user_namespace *user_ns = current_user_ns();
  152. int ret;
  153. unsigned long urange[2];
  154. kgid_t low, high;
  155. struct ctl_table tmp = {
  156. .data = &urange,
  157. .maxlen = sizeof(urange),
  158. .mode = table->mode,
  159. .extra1 = &ip_ping_group_range_min,
  160. .extra2 = &ip_ping_group_range_max,
  161. };
  162. inet_get_ping_group_range_table(table, &low, &high);
  163. urange[0] = from_kgid_munged(user_ns, low);
  164. urange[1] = from_kgid_munged(user_ns, high);
  165. ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
  166. if (write && ret == 0) {
  167. low = make_kgid(user_ns, urange[0]);
  168. high = make_kgid(user_ns, urange[1]);
  169. if (!gid_valid(low) || !gid_valid(high))
  170. return -EINVAL;
  171. if (urange[1] < urange[0] || gid_lt(high, low)) {
  172. low = make_kgid(&init_user_ns, 1);
  173. high = make_kgid(&init_user_ns, 0);
  174. }
  175. set_ping_group_range(table, low, high);
  176. }
  177. return ret;
  178. }
  179. static int ipv4_fwd_update_priority(const struct ctl_table *table, int write,
  180. void *buffer, size_t *lenp, loff_t *ppos)
  181. {
  182. struct net *net;
  183. int ret;
  184. net = container_of(table->data, struct net,
  185. ipv4.sysctl_ip_fwd_update_priority);
  186. ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
  187. if (write && ret == 0)
  188. call_netevent_notifiers(NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE,
  189. net);
  190. return ret;
  191. }
  192. static int proc_tcp_congestion_control(const struct ctl_table *ctl, int write,
  193. void *buffer, size_t *lenp, loff_t *ppos)
  194. {
  195. struct net *net = container_of(ctl->data, struct net,
  196. ipv4.tcp_congestion_control);
  197. char val[TCP_CA_NAME_MAX];
  198. struct ctl_table tbl = {
  199. .data = val,
  200. .maxlen = TCP_CA_NAME_MAX,
  201. };
  202. int ret;
  203. tcp_get_default_congestion_control(net, val);
  204. ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
  205. if (write && ret == 0)
  206. ret = tcp_set_default_congestion_control(net, val);
  207. return ret;
  208. }
  209. static int proc_tcp_available_congestion_control(const struct ctl_table *ctl,
  210. int write, void *buffer,
  211. size_t *lenp, loff_t *ppos)
  212. {
  213. struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
  214. int ret;
  215. tbl.data = kmalloc(tbl.maxlen, GFP_USER);
  216. if (!tbl.data)
  217. return -ENOMEM;
  218. tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
  219. ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
  220. kfree(tbl.data);
  221. return ret;
  222. }
  223. static int proc_allowed_congestion_control(const struct ctl_table *ctl,
  224. int write, void *buffer,
  225. size_t *lenp, loff_t *ppos)
  226. {
  227. struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
  228. int ret;
  229. tbl.data = kmalloc(tbl.maxlen, GFP_USER);
  230. if (!tbl.data)
  231. return -ENOMEM;
  232. tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
  233. ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
  234. if (write && ret == 0)
  235. ret = tcp_set_allowed_congestion_control(tbl.data);
  236. kfree(tbl.data);
  237. return ret;
  238. }
  239. static int sscanf_key(char *buf, __le32 *key)
  240. {
  241. u32 user_key[4];
  242. int i, ret = 0;
  243. if (sscanf(buf, "%x-%x-%x-%x", user_key, user_key + 1,
  244. user_key + 2, user_key + 3) != 4) {
  245. ret = -EINVAL;
  246. } else {
  247. for (i = 0; i < ARRAY_SIZE(user_key); i++)
  248. key[i] = cpu_to_le32(user_key[i]);
  249. }
  250. pr_debug("proc TFO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
  251. user_key[0], user_key[1], user_key[2], user_key[3], buf, ret);
  252. return ret;
  253. }
  254. static int proc_tcp_fastopen_key(const struct ctl_table *table, int write,
  255. void *buffer, size_t *lenp, loff_t *ppos)
  256. {
  257. struct net *net = container_of(table->data, struct net,
  258. ipv4.sysctl_tcp_fastopen);
  259. /* maxlen to print the list of keys in hex (*2), with dashes
  260. * separating doublewords and a comma in between keys.
  261. */
  262. struct ctl_table tbl = { .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
  263. 2 * TCP_FASTOPEN_KEY_MAX) +
  264. (TCP_FASTOPEN_KEY_MAX * 5)) };
  265. u32 user_key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(u32)];
  266. __le32 key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(__le32)];
  267. char *backup_data;
  268. int ret, i = 0, off = 0, n_keys;
  269. tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
  270. if (!tbl.data)
  271. return -ENOMEM;
  272. n_keys = tcp_fastopen_get_cipher(net, NULL, (u64 *)key);
  273. if (!n_keys) {
  274. memset(&key[0], 0, TCP_FASTOPEN_KEY_LENGTH);
  275. n_keys = 1;
  276. }
  277. for (i = 0; i < n_keys * 4; i++)
  278. user_key[i] = le32_to_cpu(key[i]);
  279. for (i = 0; i < n_keys; i++) {
  280. off += snprintf(tbl.data + off, tbl.maxlen - off,
  281. "%08x-%08x-%08x-%08x",
  282. user_key[i * 4],
  283. user_key[i * 4 + 1],
  284. user_key[i * 4 + 2],
  285. user_key[i * 4 + 3]);
  286. if (WARN_ON_ONCE(off >= tbl.maxlen - 1))
  287. break;
  288. if (i + 1 < n_keys)
  289. off += snprintf(tbl.data + off, tbl.maxlen - off, ",");
  290. }
  291. ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
  292. if (write && ret == 0) {
  293. backup_data = strchr(tbl.data, ',');
  294. if (backup_data) {
  295. *backup_data = '\0';
  296. backup_data++;
  297. }
  298. if (sscanf_key(tbl.data, key)) {
  299. ret = -EINVAL;
  300. goto bad_key;
  301. }
  302. if (backup_data) {
  303. if (sscanf_key(backup_data, key + 4)) {
  304. ret = -EINVAL;
  305. goto bad_key;
  306. }
  307. }
  308. tcp_fastopen_reset_cipher(net, NULL, key,
  309. backup_data ? key + 4 : NULL);
  310. }
  311. bad_key:
  312. kfree(tbl.data);
  313. return ret;
  314. }
  315. static int proc_tfo_blackhole_detect_timeout(const struct ctl_table *table,
  316. int write, void *buffer,
  317. size_t *lenp, loff_t *ppos)
  318. {
  319. struct net *net = container_of(table->data, struct net,
  320. ipv4.sysctl_tcp_fastopen_blackhole_timeout);
  321. int ret;
  322. ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
  323. if (write && ret == 0)
  324. atomic_set(&net->ipv4.tfo_active_disable_times, 0);
  325. return ret;
  326. }
  327. static int proc_tcp_available_ulp(const struct ctl_table *ctl,
  328. int write, void *buffer, size_t *lenp,
  329. loff_t *ppos)
  330. {
  331. struct ctl_table tbl = { .maxlen = TCP_ULP_BUF_MAX, };
  332. int ret;
  333. tbl.data = kmalloc(tbl.maxlen, GFP_USER);
  334. if (!tbl.data)
  335. return -ENOMEM;
  336. tcp_get_available_ulp(tbl.data, TCP_ULP_BUF_MAX);
  337. ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
  338. kfree(tbl.data);
  339. return ret;
  340. }
  341. static int proc_tcp_ehash_entries(const struct ctl_table *table, int write,
  342. void *buffer, size_t *lenp, loff_t *ppos)
  343. {
  344. struct net *net = container_of(table->data, struct net,
  345. ipv4.sysctl_tcp_child_ehash_entries);
  346. struct inet_hashinfo *hinfo = net->ipv4.tcp_death_row.hashinfo;
  347. int tcp_ehash_entries;
  348. struct ctl_table tbl;
  349. tcp_ehash_entries = hinfo->ehash_mask + 1;
  350. /* A negative number indicates that the child netns
  351. * shares the global ehash.
  352. */
  353. if (!net_eq(net, &init_net) && !hinfo->pernet)
  354. tcp_ehash_entries *= -1;
  355. memset(&tbl, 0, sizeof(tbl));
  356. tbl.data = &tcp_ehash_entries;
  357. tbl.maxlen = sizeof(int);
  358. return proc_dointvec(&tbl, write, buffer, lenp, ppos);
  359. }
  360. static int proc_udp_hash_entries(const struct ctl_table *table, int write,
  361. void *buffer, size_t *lenp, loff_t *ppos)
  362. {
  363. struct net *net = container_of(table->data, struct net,
  364. ipv4.sysctl_udp_child_hash_entries);
  365. int udp_hash_entries;
  366. struct ctl_table tbl;
  367. udp_hash_entries = net->ipv4.udp_table->mask + 1;
  368. /* A negative number indicates that the child netns
  369. * shares the global udp_table.
  370. */
  371. if (!net_eq(net, &init_net) && net->ipv4.udp_table == &udp_table)
  372. udp_hash_entries *= -1;
  373. memset(&tbl, 0, sizeof(tbl));
  374. tbl.data = &udp_hash_entries;
  375. tbl.maxlen = sizeof(int);
  376. return proc_dointvec(&tbl, write, buffer, lenp, ppos);
  377. }
  378. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  379. static int proc_fib_multipath_hash_policy(const struct ctl_table *table, int write,
  380. void *buffer, size_t *lenp,
  381. loff_t *ppos)
  382. {
  383. struct net *net = container_of(table->data, struct net,
  384. ipv4.sysctl_fib_multipath_hash_policy);
  385. int ret;
  386. ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos);
  387. if (write && ret == 0)
  388. call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
  389. return ret;
  390. }
  391. static int proc_fib_multipath_hash_fields(const struct ctl_table *table, int write,
  392. void *buffer, size_t *lenp,
  393. loff_t *ppos)
  394. {
  395. struct net *net;
  396. int ret;
  397. net = container_of(table->data, struct net,
  398. ipv4.sysctl_fib_multipath_hash_fields);
  399. ret = proc_douintvec_minmax(table, write, buffer, lenp, ppos);
  400. if (write && ret == 0)
  401. call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
  402. return ret;
  403. }
  404. static u32 proc_fib_multipath_hash_rand_seed __ro_after_init;
  405. static void proc_fib_multipath_hash_init_rand_seed(void)
  406. {
  407. get_random_bytes(&proc_fib_multipath_hash_rand_seed,
  408. sizeof(proc_fib_multipath_hash_rand_seed));
  409. }
  410. static void proc_fib_multipath_hash_set_seed(struct net *net, u32 user_seed)
  411. {
  412. struct sysctl_fib_multipath_hash_seed new = {
  413. .user_seed = user_seed,
  414. .mp_seed = (user_seed ? user_seed :
  415. proc_fib_multipath_hash_rand_seed),
  416. };
  417. WRITE_ONCE(net->ipv4.sysctl_fib_multipath_hash_seed.user_seed, new.user_seed);
  418. WRITE_ONCE(net->ipv4.sysctl_fib_multipath_hash_seed.mp_seed, new.mp_seed);
  419. }
  420. static int proc_fib_multipath_hash_seed(const struct ctl_table *table, int write,
  421. void *buffer, size_t *lenp,
  422. loff_t *ppos)
  423. {
  424. struct sysctl_fib_multipath_hash_seed *mphs;
  425. struct net *net = table->data;
  426. struct ctl_table tmp;
  427. u32 user_seed;
  428. int ret;
  429. mphs = &net->ipv4.sysctl_fib_multipath_hash_seed;
  430. user_seed = READ_ONCE(mphs->user_seed);
  431. tmp = *table;
  432. tmp.data = &user_seed;
  433. ret = proc_douintvec_minmax(&tmp, write, buffer, lenp, ppos);
  434. if (write && ret == 0) {
  435. proc_fib_multipath_hash_set_seed(net, user_seed);
  436. call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
  437. }
  438. return ret;
  439. }
  440. #else
  441. static void proc_fib_multipath_hash_init_rand_seed(void)
  442. {
  443. }
  444. static void proc_fib_multipath_hash_set_seed(struct net *net, u32 user_seed)
  445. {
  446. }
  447. #endif
  448. static struct ctl_table ipv4_table[] = {
  449. {
  450. .procname = "tcp_max_orphans",
  451. .data = &sysctl_tcp_max_orphans,
  452. .maxlen = sizeof(int),
  453. .mode = 0644,
  454. .proc_handler = proc_dointvec
  455. },
  456. {
  457. .procname = "inet_peer_threshold",
  458. .data = &inet_peer_threshold,
  459. .maxlen = sizeof(int),
  460. .mode = 0644,
  461. .proc_handler = proc_dointvec
  462. },
  463. {
  464. .procname = "inet_peer_minttl",
  465. .data = &inet_peer_minttl,
  466. .maxlen = sizeof(int),
  467. .mode = 0644,
  468. .proc_handler = proc_dointvec_jiffies,
  469. },
  470. {
  471. .procname = "inet_peer_maxttl",
  472. .data = &inet_peer_maxttl,
  473. .maxlen = sizeof(int),
  474. .mode = 0644,
  475. .proc_handler = proc_dointvec_jiffies,
  476. },
  477. {
  478. .procname = "tcp_mem",
  479. .maxlen = sizeof(sysctl_tcp_mem),
  480. .data = &sysctl_tcp_mem,
  481. .mode = 0644,
  482. .proc_handler = proc_doulongvec_minmax,
  483. },
  484. {
  485. .procname = "tcp_low_latency",
  486. .data = &sysctl_tcp_low_latency,
  487. .maxlen = sizeof(int),
  488. .mode = 0644,
  489. .proc_handler = proc_dointvec
  490. },
  491. #ifdef CONFIG_NETLABEL
  492. {
  493. .procname = "cipso_cache_enable",
  494. .data = &cipso_v4_cache_enabled,
  495. .maxlen = sizeof(int),
  496. .mode = 0644,
  497. .proc_handler = proc_dointvec,
  498. },
  499. {
  500. .procname = "cipso_cache_bucket_size",
  501. .data = &cipso_v4_cache_bucketsize,
  502. .maxlen = sizeof(int),
  503. .mode = 0644,
  504. .proc_handler = proc_dointvec,
  505. },
  506. {
  507. .procname = "cipso_rbm_optfmt",
  508. .data = &cipso_v4_rbm_optfmt,
  509. .maxlen = sizeof(int),
  510. .mode = 0644,
  511. .proc_handler = proc_dointvec,
  512. },
  513. {
  514. .procname = "cipso_rbm_strictvalid",
  515. .data = &cipso_v4_rbm_strictvalid,
  516. .maxlen = sizeof(int),
  517. .mode = 0644,
  518. .proc_handler = proc_dointvec,
  519. },
  520. #endif /* CONFIG_NETLABEL */
  521. {
  522. .procname = "tcp_available_ulp",
  523. .maxlen = TCP_ULP_BUF_MAX,
  524. .mode = 0444,
  525. .proc_handler = proc_tcp_available_ulp,
  526. },
  527. {
  528. .procname = "udp_mem",
  529. .data = &sysctl_udp_mem,
  530. .maxlen = sizeof(sysctl_udp_mem),
  531. .mode = 0644,
  532. .proc_handler = proc_doulongvec_minmax,
  533. },
  534. {
  535. .procname = "fib_sync_mem",
  536. .data = &sysctl_fib_sync_mem,
  537. .maxlen = sizeof(sysctl_fib_sync_mem),
  538. .mode = 0644,
  539. .proc_handler = proc_douintvec_minmax,
  540. .extra1 = &sysctl_fib_sync_mem_min,
  541. .extra2 = &sysctl_fib_sync_mem_max,
  542. },
  543. };
  544. static struct ctl_table ipv4_net_table[] = {
  545. {
  546. .procname = "tcp_max_tw_buckets",
  547. .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
  548. .maxlen = sizeof(int),
  549. .mode = 0644,
  550. .proc_handler = proc_dointvec
  551. },
  552. {
  553. .procname = "icmp_echo_ignore_all",
  554. .data = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
  555. .maxlen = sizeof(u8),
  556. .mode = 0644,
  557. .proc_handler = proc_dou8vec_minmax,
  558. .extra1 = SYSCTL_ZERO,
  559. .extra2 = SYSCTL_ONE
  560. },
  561. {
  562. .procname = "icmp_echo_enable_probe",
  563. .data = &init_net.ipv4.sysctl_icmp_echo_enable_probe,
  564. .maxlen = sizeof(u8),
  565. .mode = 0644,
  566. .proc_handler = proc_dou8vec_minmax,
  567. .extra1 = SYSCTL_ZERO,
  568. .extra2 = SYSCTL_ONE
  569. },
  570. {
  571. .procname = "icmp_echo_ignore_broadcasts",
  572. .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
  573. .maxlen = sizeof(u8),
  574. .mode = 0644,
  575. .proc_handler = proc_dou8vec_minmax,
  576. .extra1 = SYSCTL_ZERO,
  577. .extra2 = SYSCTL_ONE
  578. },
  579. {
  580. .procname = "icmp_ignore_bogus_error_responses",
  581. .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
  582. .maxlen = sizeof(u8),
  583. .mode = 0644,
  584. .proc_handler = proc_dou8vec_minmax,
  585. .extra1 = SYSCTL_ZERO,
  586. .extra2 = SYSCTL_ONE
  587. },
  588. {
  589. .procname = "icmp_errors_use_inbound_ifaddr",
  590. .data = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
  591. .maxlen = sizeof(u8),
  592. .mode = 0644,
  593. .proc_handler = proc_dou8vec_minmax,
  594. .extra1 = SYSCTL_ZERO,
  595. .extra2 = SYSCTL_ONE
  596. },
  597. {
  598. .procname = "icmp_errors_extension_mask",
  599. .data = &init_net.ipv4.sysctl_icmp_errors_extension_mask,
  600. .maxlen = sizeof(u8),
  601. .mode = 0644,
  602. .proc_handler = proc_dou8vec_minmax,
  603. .extra1 = SYSCTL_ZERO,
  604. .extra2 = &icmp_errors_extension_mask_all,
  605. },
  606. {
  607. .procname = "icmp_ratelimit",
  608. .data = &init_net.ipv4.sysctl_icmp_ratelimit,
  609. .maxlen = sizeof(int),
  610. .mode = 0644,
  611. .proc_handler = proc_dointvec_ms_jiffies,
  612. },
  613. {
  614. .procname = "icmp_ratemask",
  615. .data = &init_net.ipv4.sysctl_icmp_ratemask,
  616. .maxlen = sizeof(int),
  617. .mode = 0644,
  618. .proc_handler = proc_dointvec
  619. },
  620. {
  621. .procname = "icmp_msgs_per_sec",
  622. .data = &init_net.ipv4.sysctl_icmp_msgs_per_sec,
  623. .maxlen = sizeof(int),
  624. .mode = 0644,
  625. .proc_handler = proc_dointvec_minmax,
  626. .extra1 = SYSCTL_ZERO,
  627. },
  628. {
  629. .procname = "icmp_msgs_burst",
  630. .data = &init_net.ipv4.sysctl_icmp_msgs_burst,
  631. .maxlen = sizeof(int),
  632. .mode = 0644,
  633. .proc_handler = proc_dointvec_minmax,
  634. .extra1 = SYSCTL_ZERO,
  635. },
  636. {
  637. .procname = "ping_group_range",
  638. .data = &init_net.ipv4.ping_group_range.range,
  639. .maxlen = sizeof(gid_t)*2,
  640. .mode = 0644,
  641. .proc_handler = ipv4_ping_group_range,
  642. },
  643. #ifdef CONFIG_NET_L3_MASTER_DEV
  644. {
  645. .procname = "raw_l3mdev_accept",
  646. .data = &init_net.ipv4.sysctl_raw_l3mdev_accept,
  647. .maxlen = sizeof(u8),
  648. .mode = 0644,
  649. .proc_handler = proc_dou8vec_minmax,
  650. .extra1 = SYSCTL_ZERO,
  651. .extra2 = SYSCTL_ONE,
  652. },
  653. #endif
  654. {
  655. .procname = "tcp_ecn",
  656. .data = &init_net.ipv4.sysctl_tcp_ecn,
  657. .maxlen = sizeof(u8),
  658. .mode = 0644,
  659. .proc_handler = proc_dou8vec_minmax,
  660. .extra1 = SYSCTL_ZERO,
  661. .extra2 = &tcp_ecn_mode_max,
  662. },
  663. {
  664. .procname = "tcp_ecn_option",
  665. .data = &init_net.ipv4.sysctl_tcp_ecn_option,
  666. .maxlen = sizeof(u8),
  667. .mode = 0644,
  668. .proc_handler = proc_dou8vec_minmax,
  669. .extra1 = SYSCTL_ZERO,
  670. .extra2 = SYSCTL_THREE,
  671. },
  672. {
  673. .procname = "tcp_ecn_option_beacon",
  674. .data = &init_net.ipv4.sysctl_tcp_ecn_option_beacon,
  675. .maxlen = sizeof(u8),
  676. .mode = 0644,
  677. .proc_handler = proc_dou8vec_minmax,
  678. .extra1 = SYSCTL_ZERO,
  679. .extra2 = SYSCTL_THREE,
  680. },
  681. {
  682. .procname = "tcp_ecn_fallback",
  683. .data = &init_net.ipv4.sysctl_tcp_ecn_fallback,
  684. .maxlen = sizeof(u8),
  685. .mode = 0644,
  686. .proc_handler = proc_dou8vec_minmax,
  687. .extra1 = SYSCTL_ZERO,
  688. .extra2 = SYSCTL_ONE,
  689. },
  690. {
  691. .procname = "ip_dynaddr",
  692. .data = &init_net.ipv4.sysctl_ip_dynaddr,
  693. .maxlen = sizeof(u8),
  694. .mode = 0644,
  695. .proc_handler = proc_dou8vec_minmax,
  696. },
  697. {
  698. .procname = "ip_early_demux",
  699. .data = &init_net.ipv4.sysctl_ip_early_demux,
  700. .maxlen = sizeof(u8),
  701. .mode = 0644,
  702. .proc_handler = proc_dou8vec_minmax,
  703. },
  704. {
  705. .procname = "udp_early_demux",
  706. .data = &init_net.ipv4.sysctl_udp_early_demux,
  707. .maxlen = sizeof(u8),
  708. .mode = 0644,
  709. .proc_handler = proc_dou8vec_minmax,
  710. },
  711. {
  712. .procname = "tcp_early_demux",
  713. .data = &init_net.ipv4.sysctl_tcp_early_demux,
  714. .maxlen = sizeof(u8),
  715. .mode = 0644,
  716. .proc_handler = proc_dou8vec_minmax,
  717. },
  718. {
  719. .procname = "nexthop_compat_mode",
  720. .data = &init_net.ipv4.sysctl_nexthop_compat_mode,
  721. .maxlen = sizeof(u8),
  722. .mode = 0644,
  723. .proc_handler = proc_dou8vec_minmax,
  724. .extra1 = SYSCTL_ZERO,
  725. .extra2 = SYSCTL_ONE,
  726. },
  727. {
  728. .procname = "ip_default_ttl",
  729. .data = &init_net.ipv4.sysctl_ip_default_ttl,
  730. .maxlen = sizeof(u8),
  731. .mode = 0644,
  732. .proc_handler = proc_dou8vec_minmax,
  733. .extra1 = &ip_ttl_min,
  734. .extra2 = &ip_ttl_max,
  735. },
  736. {
  737. .procname = "ip_local_port_range",
  738. .maxlen = 0,
  739. .data = &init_net,
  740. .mode = 0644,
  741. .proc_handler = ipv4_local_port_range,
  742. },
  743. {
  744. .procname = "ip_local_reserved_ports",
  745. .data = &init_net.ipv4.sysctl_local_reserved_ports,
  746. .maxlen = 65536,
  747. .mode = 0644,
  748. .proc_handler = proc_do_large_bitmap,
  749. },
  750. {
  751. .procname = "ip_no_pmtu_disc",
  752. .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
  753. .maxlen = sizeof(u8),
  754. .mode = 0644,
  755. .proc_handler = proc_dou8vec_minmax,
  756. },
  757. {
  758. .procname = "ip_forward_use_pmtu",
  759. .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
  760. .maxlen = sizeof(u8),
  761. .mode = 0644,
  762. .proc_handler = proc_dou8vec_minmax,
  763. },
  764. {
  765. .procname = "ip_forward_update_priority",
  766. .data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
  767. .maxlen = sizeof(u8),
  768. .mode = 0644,
  769. .proc_handler = ipv4_fwd_update_priority,
  770. .extra1 = SYSCTL_ZERO,
  771. .extra2 = SYSCTL_ONE,
  772. },
  773. {
  774. .procname = "ip_nonlocal_bind",
  775. .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
  776. .maxlen = sizeof(u8),
  777. .mode = 0644,
  778. .proc_handler = proc_dou8vec_minmax,
  779. },
  780. {
  781. .procname = "ip_autobind_reuse",
  782. .data = &init_net.ipv4.sysctl_ip_autobind_reuse,
  783. .maxlen = sizeof(u8),
  784. .mode = 0644,
  785. .proc_handler = proc_dou8vec_minmax,
  786. .extra1 = SYSCTL_ZERO,
  787. .extra2 = SYSCTL_ONE,
  788. },
  789. {
  790. .procname = "fwmark_reflect",
  791. .data = &init_net.ipv4.sysctl_fwmark_reflect,
  792. .maxlen = sizeof(u8),
  793. .mode = 0644,
  794. .proc_handler = proc_dou8vec_minmax,
  795. },
  796. {
  797. .procname = "tcp_fwmark_accept",
  798. .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
  799. .maxlen = sizeof(u8),
  800. .mode = 0644,
  801. .proc_handler = proc_dou8vec_minmax,
  802. },
  803. #ifdef CONFIG_NET_L3_MASTER_DEV
  804. {
  805. .procname = "tcp_l3mdev_accept",
  806. .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
  807. .maxlen = sizeof(u8),
  808. .mode = 0644,
  809. .proc_handler = proc_dou8vec_minmax,
  810. .extra1 = SYSCTL_ZERO,
  811. .extra2 = SYSCTL_ONE,
  812. },
  813. #endif
  814. {
  815. .procname = "tcp_mtu_probing",
  816. .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
  817. .maxlen = sizeof(u8),
  818. .mode = 0644,
  819. .proc_handler = proc_dou8vec_minmax,
  820. },
  821. {
  822. .procname = "tcp_base_mss",
  823. .data = &init_net.ipv4.sysctl_tcp_base_mss,
  824. .maxlen = sizeof(int),
  825. .mode = 0644,
  826. .proc_handler = proc_dointvec,
  827. },
  828. {
  829. .procname = "tcp_min_snd_mss",
  830. .data = &init_net.ipv4.sysctl_tcp_min_snd_mss,
  831. .maxlen = sizeof(int),
  832. .mode = 0644,
  833. .proc_handler = proc_dointvec_minmax,
  834. .extra1 = &tcp_min_snd_mss_min,
  835. .extra2 = &tcp_min_snd_mss_max,
  836. },
  837. {
  838. .procname = "tcp_mtu_probe_floor",
  839. .data = &init_net.ipv4.sysctl_tcp_mtu_probe_floor,
  840. .maxlen = sizeof(int),
  841. .mode = 0644,
  842. .proc_handler = proc_dointvec_minmax,
  843. .extra1 = &tcp_min_snd_mss_min,
  844. .extra2 = &tcp_min_snd_mss_max,
  845. },
  846. {
  847. .procname = "tcp_probe_threshold",
  848. .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
  849. .maxlen = sizeof(int),
  850. .mode = 0644,
  851. .proc_handler = proc_dointvec,
  852. },
  853. {
  854. .procname = "tcp_probe_interval",
  855. .data = &init_net.ipv4.sysctl_tcp_probe_interval,
  856. .maxlen = sizeof(u32),
  857. .mode = 0644,
  858. .proc_handler = proc_douintvec_minmax,
  859. .extra2 = &u32_max_div_HZ,
  860. },
  861. {
  862. .procname = "igmp_link_local_mcast_reports",
  863. .data = &init_net.ipv4.sysctl_igmp_llm_reports,
  864. .maxlen = sizeof(u8),
  865. .mode = 0644,
  866. .proc_handler = proc_dou8vec_minmax,
  867. },
  868. {
  869. .procname = "igmp_max_memberships",
  870. .data = &init_net.ipv4.sysctl_igmp_max_memberships,
  871. .maxlen = sizeof(int),
  872. .mode = 0644,
  873. .proc_handler = proc_dointvec
  874. },
  875. {
  876. .procname = "igmp_max_msf",
  877. .data = &init_net.ipv4.sysctl_igmp_max_msf,
  878. .maxlen = sizeof(int),
  879. .mode = 0644,
  880. .proc_handler = proc_dointvec
  881. },
  882. #ifdef CONFIG_IP_MULTICAST
  883. {
  884. .procname = "igmp_qrv",
  885. .data = &init_net.ipv4.sysctl_igmp_qrv,
  886. .maxlen = sizeof(int),
  887. .mode = 0644,
  888. .proc_handler = proc_dointvec_minmax,
  889. .extra1 = SYSCTL_ONE
  890. },
  891. #endif
  892. {
  893. .procname = "tcp_congestion_control",
  894. .data = &init_net.ipv4.tcp_congestion_control,
  895. .mode = 0644,
  896. .maxlen = TCP_CA_NAME_MAX,
  897. .proc_handler = proc_tcp_congestion_control,
  898. },
  899. {
  900. .procname = "tcp_available_congestion_control",
  901. .maxlen = TCP_CA_BUF_MAX,
  902. .mode = 0444,
  903. .proc_handler = proc_tcp_available_congestion_control,
  904. },
  905. {
  906. .procname = "tcp_allowed_congestion_control",
  907. .maxlen = TCP_CA_BUF_MAX,
  908. .mode = 0644,
  909. .proc_handler = proc_allowed_congestion_control,
  910. },
  911. {
  912. .procname = "tcp_keepalive_time",
  913. .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
  914. .maxlen = sizeof(int),
  915. .mode = 0644,
  916. .proc_handler = proc_dointvec_jiffies,
  917. },
  918. {
  919. .procname = "tcp_keepalive_probes",
  920. .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
  921. .maxlen = sizeof(u8),
  922. .mode = 0644,
  923. .proc_handler = proc_dou8vec_minmax,
  924. },
  925. {
  926. .procname = "tcp_keepalive_intvl",
  927. .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
  928. .maxlen = sizeof(int),
  929. .mode = 0644,
  930. .proc_handler = proc_dointvec_jiffies,
  931. },
  932. {
  933. .procname = "tcp_syn_retries",
  934. .data = &init_net.ipv4.sysctl_tcp_syn_retries,
  935. .maxlen = sizeof(u8),
  936. .mode = 0644,
  937. .proc_handler = proc_dou8vec_minmax,
  938. .extra1 = &tcp_syn_retries_min,
  939. .extra2 = &tcp_syn_retries_max
  940. },
  941. {
  942. .procname = "tcp_synack_retries",
  943. .data = &init_net.ipv4.sysctl_tcp_synack_retries,
  944. .maxlen = sizeof(u8),
  945. .mode = 0644,
  946. .proc_handler = proc_dou8vec_minmax,
  947. },
  948. #ifdef CONFIG_SYN_COOKIES
  949. {
  950. .procname = "tcp_syncookies",
  951. .data = &init_net.ipv4.sysctl_tcp_syncookies,
  952. .maxlen = sizeof(u8),
  953. .mode = 0644,
  954. .proc_handler = proc_dou8vec_minmax,
  955. },
  956. #endif
  957. {
  958. .procname = "tcp_migrate_req",
  959. .data = &init_net.ipv4.sysctl_tcp_migrate_req,
  960. .maxlen = sizeof(u8),
  961. .mode = 0644,
  962. .proc_handler = proc_dou8vec_minmax,
  963. .extra1 = SYSCTL_ZERO,
  964. .extra2 = SYSCTL_ONE
  965. },
  966. {
  967. .procname = "tcp_reordering",
  968. .data = &init_net.ipv4.sysctl_tcp_reordering,
  969. .maxlen = sizeof(int),
  970. .mode = 0644,
  971. .proc_handler = proc_dointvec
  972. },
  973. {
  974. .procname = "tcp_retries1",
  975. .data = &init_net.ipv4.sysctl_tcp_retries1,
  976. .maxlen = sizeof(u8),
  977. .mode = 0644,
  978. .proc_handler = proc_dou8vec_minmax,
  979. .extra2 = &tcp_retr1_max
  980. },
  981. {
  982. .procname = "tcp_retries2",
  983. .data = &init_net.ipv4.sysctl_tcp_retries2,
  984. .maxlen = sizeof(u8),
  985. .mode = 0644,
  986. .proc_handler = proc_dou8vec_minmax,
  987. },
  988. {
  989. .procname = "tcp_orphan_retries",
  990. .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
  991. .maxlen = sizeof(u8),
  992. .mode = 0644,
  993. .proc_handler = proc_dou8vec_minmax,
  994. },
  995. {
  996. .procname = "tcp_fin_timeout",
  997. .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
  998. .maxlen = sizeof(int),
  999. .mode = 0644,
  1000. .proc_handler = proc_dointvec_jiffies,
  1001. },
  1002. {
  1003. .procname = "tcp_notsent_lowat",
  1004. .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
  1005. .maxlen = sizeof(unsigned int),
  1006. .mode = 0644,
  1007. .proc_handler = proc_douintvec,
  1008. },
  1009. {
  1010. .procname = "tcp_tw_reuse",
  1011. .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
  1012. .maxlen = sizeof(u8),
  1013. .mode = 0644,
  1014. .proc_handler = proc_dou8vec_minmax,
  1015. .extra1 = SYSCTL_ZERO,
  1016. .extra2 = SYSCTL_TWO,
  1017. },
  1018. {
  1019. .procname = "tcp_tw_reuse_delay",
  1020. .data = &init_net.ipv4.sysctl_tcp_tw_reuse_delay,
  1021. .maxlen = sizeof(unsigned int),
  1022. .mode = 0644,
  1023. .proc_handler = proc_douintvec_minmax,
  1024. .extra1 = SYSCTL_ONE,
  1025. .extra2 = &tcp_tw_reuse_delay_max,
  1026. },
  1027. {
  1028. .procname = "tcp_max_syn_backlog",
  1029. .data = &init_net.ipv4.sysctl_max_syn_backlog,
  1030. .maxlen = sizeof(int),
  1031. .mode = 0644,
  1032. .proc_handler = proc_dointvec
  1033. },
  1034. {
  1035. .procname = "tcp_fastopen",
  1036. .data = &init_net.ipv4.sysctl_tcp_fastopen,
  1037. .maxlen = sizeof(int),
  1038. .mode = 0644,
  1039. .proc_handler = proc_dointvec,
  1040. },
  1041. {
  1042. .procname = "tcp_fastopen_key",
  1043. .mode = 0600,
  1044. .data = &init_net.ipv4.sysctl_tcp_fastopen,
  1045. /* maxlen to print the list of keys in hex (*2), with dashes
  1046. * separating doublewords and a comma in between keys.
  1047. */
  1048. .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
  1049. 2 * TCP_FASTOPEN_KEY_MAX) +
  1050. (TCP_FASTOPEN_KEY_MAX * 5)),
  1051. .proc_handler = proc_tcp_fastopen_key,
  1052. },
  1053. {
  1054. .procname = "tcp_fastopen_blackhole_timeout_sec",
  1055. .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
  1056. .maxlen = sizeof(int),
  1057. .mode = 0644,
  1058. .proc_handler = proc_tfo_blackhole_detect_timeout,
  1059. .extra1 = SYSCTL_ZERO,
  1060. },
  1061. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  1062. {
  1063. .procname = "fib_multipath_use_neigh",
  1064. .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
  1065. .maxlen = sizeof(u8),
  1066. .mode = 0644,
  1067. .proc_handler = proc_dou8vec_minmax,
  1068. .extra1 = SYSCTL_ZERO,
  1069. .extra2 = SYSCTL_ONE,
  1070. },
  1071. {
  1072. .procname = "fib_multipath_hash_policy",
  1073. .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
  1074. .maxlen = sizeof(u8),
  1075. .mode = 0644,
  1076. .proc_handler = proc_fib_multipath_hash_policy,
  1077. .extra1 = SYSCTL_ZERO,
  1078. .extra2 = SYSCTL_THREE,
  1079. },
  1080. {
  1081. .procname = "fib_multipath_hash_fields",
  1082. .data = &init_net.ipv4.sysctl_fib_multipath_hash_fields,
  1083. .maxlen = sizeof(u32),
  1084. .mode = 0644,
  1085. .proc_handler = proc_fib_multipath_hash_fields,
  1086. .extra1 = SYSCTL_ONE,
  1087. .extra2 = &fib_multipath_hash_fields_all_mask,
  1088. },
  1089. {
  1090. .procname = "fib_multipath_hash_seed",
  1091. .data = &init_net,
  1092. .maxlen = sizeof(u32),
  1093. .mode = 0644,
  1094. .proc_handler = proc_fib_multipath_hash_seed,
  1095. },
  1096. #endif
  1097. {
  1098. .procname = "ip_unprivileged_port_start",
  1099. .maxlen = sizeof(int),
  1100. .data = &init_net.ipv4.sysctl_ip_prot_sock,
  1101. .mode = 0644,
  1102. .proc_handler = ipv4_privileged_ports,
  1103. },
  1104. #ifdef CONFIG_NET_L3_MASTER_DEV
  1105. {
  1106. .procname = "udp_l3mdev_accept",
  1107. .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
  1108. .maxlen = sizeof(u8),
  1109. .mode = 0644,
  1110. .proc_handler = proc_dou8vec_minmax,
  1111. .extra1 = SYSCTL_ZERO,
  1112. .extra2 = SYSCTL_ONE,
  1113. },
  1114. #endif
  1115. {
  1116. .procname = "tcp_sack",
  1117. .data = &init_net.ipv4.sysctl_tcp_sack,
  1118. .maxlen = sizeof(u8),
  1119. .mode = 0644,
  1120. .proc_handler = proc_dou8vec_minmax,
  1121. },
  1122. {
  1123. .procname = "tcp_window_scaling",
  1124. .data = &init_net.ipv4.sysctl_tcp_window_scaling,
  1125. .maxlen = sizeof(u8),
  1126. .mode = 0644,
  1127. .proc_handler = proc_dou8vec_minmax,
  1128. },
  1129. {
  1130. .procname = "tcp_timestamps",
  1131. .data = &init_net.ipv4.sysctl_tcp_timestamps,
  1132. .maxlen = sizeof(u8),
  1133. .mode = 0644,
  1134. .proc_handler = proc_dou8vec_minmax,
  1135. },
  1136. {
  1137. .procname = "tcp_early_retrans",
  1138. .data = &init_net.ipv4.sysctl_tcp_early_retrans,
  1139. .maxlen = sizeof(u8),
  1140. .mode = 0644,
  1141. .proc_handler = proc_dou8vec_minmax,
  1142. .extra1 = SYSCTL_ZERO,
  1143. .extra2 = SYSCTL_FOUR,
  1144. },
  1145. {
  1146. .procname = "tcp_recovery",
  1147. .data = &init_net.ipv4.sysctl_tcp_recovery,
  1148. .maxlen = sizeof(u8),
  1149. .mode = 0644,
  1150. .proc_handler = proc_dou8vec_minmax,
  1151. },
  1152. {
  1153. .procname = "tcp_thin_linear_timeouts",
  1154. .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
  1155. .maxlen = sizeof(u8),
  1156. .mode = 0644,
  1157. .proc_handler = proc_dou8vec_minmax,
  1158. },
  1159. {
  1160. .procname = "tcp_slow_start_after_idle",
  1161. .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
  1162. .maxlen = sizeof(u8),
  1163. .mode = 0644,
  1164. .proc_handler = proc_dou8vec_minmax,
  1165. },
  1166. {
  1167. .procname = "tcp_retrans_collapse",
  1168. .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
  1169. .maxlen = sizeof(u8),
  1170. .mode = 0644,
  1171. .proc_handler = proc_dou8vec_minmax,
  1172. },
  1173. {
  1174. .procname = "tcp_stdurg",
  1175. .data = &init_net.ipv4.sysctl_tcp_stdurg,
  1176. .maxlen = sizeof(u8),
  1177. .mode = 0644,
  1178. .proc_handler = proc_dou8vec_minmax,
  1179. },
  1180. {
  1181. .procname = "tcp_rfc1337",
  1182. .data = &init_net.ipv4.sysctl_tcp_rfc1337,
  1183. .maxlen = sizeof(u8),
  1184. .mode = 0644,
  1185. .proc_handler = proc_dou8vec_minmax,
  1186. },
  1187. {
  1188. .procname = "tcp_abort_on_overflow",
  1189. .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
  1190. .maxlen = sizeof(u8),
  1191. .mode = 0644,
  1192. .proc_handler = proc_dou8vec_minmax,
  1193. },
  1194. {
  1195. .procname = "tcp_fack",
  1196. .data = &init_net.ipv4.sysctl_tcp_fack,
  1197. .maxlen = sizeof(u8),
  1198. .mode = 0644,
  1199. .proc_handler = proc_dou8vec_minmax,
  1200. },
  1201. {
  1202. .procname = "tcp_max_reordering",
  1203. .data = &init_net.ipv4.sysctl_tcp_max_reordering,
  1204. .maxlen = sizeof(int),
  1205. .mode = 0644,
  1206. .proc_handler = proc_dointvec
  1207. },
  1208. {
  1209. .procname = "tcp_dsack",
  1210. .data = &init_net.ipv4.sysctl_tcp_dsack,
  1211. .maxlen = sizeof(u8),
  1212. .mode = 0644,
  1213. .proc_handler = proc_dou8vec_minmax,
  1214. },
  1215. {
  1216. .procname = "tcp_app_win",
  1217. .data = &init_net.ipv4.sysctl_tcp_app_win,
  1218. .maxlen = sizeof(u8),
  1219. .mode = 0644,
  1220. .proc_handler = proc_dou8vec_minmax,
  1221. .extra1 = SYSCTL_ZERO,
  1222. .extra2 = &tcp_app_win_max,
  1223. },
  1224. {
  1225. .procname = "tcp_adv_win_scale",
  1226. .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
  1227. .maxlen = sizeof(int),
  1228. .mode = 0644,
  1229. .proc_handler = proc_dointvec_minmax,
  1230. .extra1 = &tcp_adv_win_scale_min,
  1231. .extra2 = &tcp_adv_win_scale_max,
  1232. },
  1233. {
  1234. .procname = "tcp_frto",
  1235. .data = &init_net.ipv4.sysctl_tcp_frto,
  1236. .maxlen = sizeof(u8),
  1237. .mode = 0644,
  1238. .proc_handler = proc_dou8vec_minmax,
  1239. },
  1240. {
  1241. .procname = "tcp_no_metrics_save",
  1242. .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
  1243. .maxlen = sizeof(u8),
  1244. .mode = 0644,
  1245. .proc_handler = proc_dou8vec_minmax,
  1246. },
  1247. {
  1248. .procname = "tcp_no_ssthresh_metrics_save",
  1249. .data = &init_net.ipv4.sysctl_tcp_no_ssthresh_metrics_save,
  1250. .maxlen = sizeof(u8),
  1251. .mode = 0644,
  1252. .proc_handler = proc_dou8vec_minmax,
  1253. .extra1 = SYSCTL_ZERO,
  1254. .extra2 = SYSCTL_ONE,
  1255. },
  1256. {
  1257. .procname = "tcp_moderate_rcvbuf",
  1258. .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
  1259. .maxlen = sizeof(u8),
  1260. .mode = 0644,
  1261. .proc_handler = proc_dou8vec_minmax,
  1262. },
  1263. {
  1264. .procname = "tcp_rcvbuf_low_rtt",
  1265. .data = &init_net.ipv4.sysctl_tcp_rcvbuf_low_rtt,
  1266. .maxlen = sizeof(int),
  1267. .mode = 0644,
  1268. .proc_handler = proc_dointvec_minmax,
  1269. .extra1 = SYSCTL_ZERO,
  1270. .extra2 = SYSCTL_INT_MAX,
  1271. },
  1272. {
  1273. .procname = "tcp_tso_win_divisor",
  1274. .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
  1275. .maxlen = sizeof(u8),
  1276. .mode = 0644,
  1277. .proc_handler = proc_dou8vec_minmax,
  1278. },
  1279. {
  1280. .procname = "tcp_workaround_signed_windows",
  1281. .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
  1282. .maxlen = sizeof(u8),
  1283. .mode = 0644,
  1284. .proc_handler = proc_dou8vec_minmax,
  1285. },
  1286. {
  1287. .procname = "tcp_limit_output_bytes",
  1288. .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
  1289. .maxlen = sizeof(int),
  1290. .mode = 0644,
  1291. .proc_handler = proc_dointvec
  1292. },
  1293. {
  1294. .procname = "tcp_challenge_ack_limit",
  1295. .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
  1296. .maxlen = sizeof(int),
  1297. .mode = 0644,
  1298. .proc_handler = proc_dointvec
  1299. },
  1300. {
  1301. .procname = "tcp_min_tso_segs",
  1302. .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
  1303. .maxlen = sizeof(u8),
  1304. .mode = 0644,
  1305. .proc_handler = proc_dou8vec_minmax,
  1306. .extra1 = SYSCTL_ONE,
  1307. },
  1308. {
  1309. .procname = "tcp_tso_rtt_log",
  1310. .data = &init_net.ipv4.sysctl_tcp_tso_rtt_log,
  1311. .maxlen = sizeof(u8),
  1312. .mode = 0644,
  1313. .proc_handler = proc_dou8vec_minmax,
  1314. },
  1315. {
  1316. .procname = "tcp_min_rtt_wlen",
  1317. .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
  1318. .maxlen = sizeof(int),
  1319. .mode = 0644,
  1320. .proc_handler = proc_dointvec_minmax,
  1321. .extra1 = SYSCTL_ZERO,
  1322. .extra2 = &one_day_secs
  1323. },
  1324. {
  1325. .procname = "tcp_autocorking",
  1326. .data = &init_net.ipv4.sysctl_tcp_autocorking,
  1327. .maxlen = sizeof(u8),
  1328. .mode = 0644,
  1329. .proc_handler = proc_dou8vec_minmax,
  1330. .extra1 = SYSCTL_ZERO,
  1331. .extra2 = SYSCTL_ONE,
  1332. },
  1333. {
  1334. .procname = "tcp_invalid_ratelimit",
  1335. .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
  1336. .maxlen = sizeof(int),
  1337. .mode = 0644,
  1338. .proc_handler = proc_dointvec_ms_jiffies,
  1339. },
  1340. {
  1341. .procname = "tcp_pacing_ss_ratio",
  1342. .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
  1343. .maxlen = sizeof(int),
  1344. .mode = 0644,
  1345. .proc_handler = proc_dointvec_minmax,
  1346. .extra1 = SYSCTL_ZERO,
  1347. .extra2 = SYSCTL_ONE_THOUSAND,
  1348. },
  1349. {
  1350. .procname = "tcp_pacing_ca_ratio",
  1351. .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
  1352. .maxlen = sizeof(int),
  1353. .mode = 0644,
  1354. .proc_handler = proc_dointvec_minmax,
  1355. .extra1 = SYSCTL_ZERO,
  1356. .extra2 = SYSCTL_ONE_THOUSAND,
  1357. },
  1358. {
  1359. .procname = "tcp_wmem",
  1360. .data = &init_net.ipv4.sysctl_tcp_wmem,
  1361. .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
  1362. .mode = 0644,
  1363. .proc_handler = proc_dointvec_minmax,
  1364. .extra1 = SYSCTL_ONE,
  1365. },
  1366. {
  1367. .procname = "tcp_rmem",
  1368. .data = &init_net.ipv4.sysctl_tcp_rmem,
  1369. .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
  1370. .mode = 0644,
  1371. .proc_handler = proc_dointvec_minmax,
  1372. .extra1 = SYSCTL_ONE,
  1373. },
  1374. {
  1375. .procname = "tcp_comp_sack_delay_ns",
  1376. .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
  1377. .maxlen = sizeof(unsigned long),
  1378. .mode = 0644,
  1379. .proc_handler = proc_doulongvec_minmax,
  1380. },
  1381. {
  1382. .procname = "tcp_comp_sack_rtt_percent",
  1383. .data = &init_net.ipv4.sysctl_tcp_comp_sack_rtt_percent,
  1384. .maxlen = sizeof(int),
  1385. .mode = 0644,
  1386. .proc_handler = proc_dointvec_minmax,
  1387. .extra1 = SYSCTL_ONE,
  1388. .extra2 = SYSCTL_ONE_THOUSAND,
  1389. },
  1390. {
  1391. .procname = "tcp_comp_sack_slack_ns",
  1392. .data = &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
  1393. .maxlen = sizeof(unsigned long),
  1394. .mode = 0644,
  1395. .proc_handler = proc_doulongvec_minmax,
  1396. },
  1397. {
  1398. .procname = "tcp_comp_sack_nr",
  1399. .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
  1400. .maxlen = sizeof(u8),
  1401. .mode = 0644,
  1402. .proc_handler = proc_dou8vec_minmax,
  1403. .extra1 = SYSCTL_ZERO,
  1404. },
  1405. {
  1406. .procname = "tcp_backlog_ack_defer",
  1407. .data = &init_net.ipv4.sysctl_tcp_backlog_ack_defer,
  1408. .maxlen = sizeof(u8),
  1409. .mode = 0644,
  1410. .proc_handler = proc_dou8vec_minmax,
  1411. .extra1 = SYSCTL_ZERO,
  1412. .extra2 = SYSCTL_ONE,
  1413. },
  1414. {
  1415. .procname = "tcp_reflect_tos",
  1416. .data = &init_net.ipv4.sysctl_tcp_reflect_tos,
  1417. .maxlen = sizeof(u8),
  1418. .mode = 0644,
  1419. .proc_handler = proc_dou8vec_minmax,
  1420. .extra1 = SYSCTL_ZERO,
  1421. .extra2 = SYSCTL_ONE,
  1422. },
  1423. {
  1424. .procname = "tcp_ehash_entries",
  1425. .data = &init_net.ipv4.sysctl_tcp_child_ehash_entries,
  1426. .mode = 0444,
  1427. .proc_handler = proc_tcp_ehash_entries,
  1428. },
  1429. {
  1430. .procname = "tcp_child_ehash_entries",
  1431. .data = &init_net.ipv4.sysctl_tcp_child_ehash_entries,
  1432. .maxlen = sizeof(unsigned int),
  1433. .mode = 0644,
  1434. .proc_handler = proc_douintvec_minmax,
  1435. .extra1 = SYSCTL_ZERO,
  1436. .extra2 = &tcp_child_ehash_entries_max,
  1437. },
  1438. {
  1439. .procname = "udp_hash_entries",
  1440. .data = &init_net.ipv4.sysctl_udp_child_hash_entries,
  1441. .mode = 0444,
  1442. .proc_handler = proc_udp_hash_entries,
  1443. },
  1444. {
  1445. .procname = "udp_child_hash_entries",
  1446. .data = &init_net.ipv4.sysctl_udp_child_hash_entries,
  1447. .maxlen = sizeof(unsigned int),
  1448. .mode = 0644,
  1449. .proc_handler = proc_douintvec_minmax,
  1450. .extra1 = SYSCTL_ZERO,
  1451. .extra2 = &udp_child_hash_entries_max,
  1452. },
  1453. {
  1454. .procname = "udp_rmem_min",
  1455. .data = &init_net.ipv4.sysctl_udp_rmem_min,
  1456. .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
  1457. .mode = 0644,
  1458. .proc_handler = proc_dointvec_minmax,
  1459. .extra1 = SYSCTL_ONE
  1460. },
  1461. {
  1462. .procname = "udp_wmem_min",
  1463. .data = &init_net.ipv4.sysctl_udp_wmem_min,
  1464. .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
  1465. .mode = 0644,
  1466. .proc_handler = proc_dointvec_minmax,
  1467. .extra1 = SYSCTL_ONE
  1468. },
  1469. {
  1470. .procname = "fib_notify_on_flag_change",
  1471. .data = &init_net.ipv4.sysctl_fib_notify_on_flag_change,
  1472. .maxlen = sizeof(u8),
  1473. .mode = 0644,
  1474. .proc_handler = proc_dou8vec_minmax,
  1475. .extra1 = SYSCTL_ZERO,
  1476. .extra2 = SYSCTL_TWO,
  1477. },
  1478. {
  1479. .procname = "tcp_plb_enabled",
  1480. .data = &init_net.ipv4.sysctl_tcp_plb_enabled,
  1481. .maxlen = sizeof(u8),
  1482. .mode = 0644,
  1483. .proc_handler = proc_dou8vec_minmax,
  1484. .extra1 = SYSCTL_ZERO,
  1485. .extra2 = SYSCTL_ONE,
  1486. },
  1487. {
  1488. .procname = "tcp_plb_idle_rehash_rounds",
  1489. .data = &init_net.ipv4.sysctl_tcp_plb_idle_rehash_rounds,
  1490. .maxlen = sizeof(u8),
  1491. .mode = 0644,
  1492. .proc_handler = proc_dou8vec_minmax,
  1493. .extra2 = &tcp_plb_max_rounds,
  1494. },
  1495. {
  1496. .procname = "tcp_plb_rehash_rounds",
  1497. .data = &init_net.ipv4.sysctl_tcp_plb_rehash_rounds,
  1498. .maxlen = sizeof(u8),
  1499. .mode = 0644,
  1500. .proc_handler = proc_dou8vec_minmax,
  1501. .extra2 = &tcp_plb_max_rounds,
  1502. },
  1503. {
  1504. .procname = "tcp_plb_suspend_rto_sec",
  1505. .data = &init_net.ipv4.sysctl_tcp_plb_suspend_rto_sec,
  1506. .maxlen = sizeof(u8),
  1507. .mode = 0644,
  1508. .proc_handler = proc_dou8vec_minmax,
  1509. },
  1510. {
  1511. .procname = "tcp_plb_cong_thresh",
  1512. .data = &init_net.ipv4.sysctl_tcp_plb_cong_thresh,
  1513. .maxlen = sizeof(int),
  1514. .mode = 0644,
  1515. .proc_handler = proc_dointvec_minmax,
  1516. .extra1 = SYSCTL_ZERO,
  1517. .extra2 = &tcp_plb_max_cong_thresh,
  1518. },
  1519. {
  1520. .procname = "tcp_syn_linear_timeouts",
  1521. .data = &init_net.ipv4.sysctl_tcp_syn_linear_timeouts,
  1522. .maxlen = sizeof(u8),
  1523. .mode = 0644,
  1524. .proc_handler = proc_dou8vec_minmax,
  1525. .extra1 = SYSCTL_ZERO,
  1526. .extra2 = &tcp_syn_linear_timeouts_max,
  1527. },
  1528. {
  1529. .procname = "tcp_shrink_window",
  1530. .data = &init_net.ipv4.sysctl_tcp_shrink_window,
  1531. .maxlen = sizeof(u8),
  1532. .mode = 0644,
  1533. .proc_handler = proc_dou8vec_minmax,
  1534. .extra1 = SYSCTL_ZERO,
  1535. .extra2 = SYSCTL_ONE,
  1536. },
  1537. {
  1538. .procname = "tcp_pingpong_thresh",
  1539. .data = &init_net.ipv4.sysctl_tcp_pingpong_thresh,
  1540. .maxlen = sizeof(u8),
  1541. .mode = 0644,
  1542. .proc_handler = proc_dou8vec_minmax,
  1543. .extra1 = SYSCTL_ONE,
  1544. },
  1545. {
  1546. .procname = "tcp_rto_min_us",
  1547. .data = &init_net.ipv4.sysctl_tcp_rto_min_us,
  1548. .maxlen = sizeof(int),
  1549. .mode = 0644,
  1550. .proc_handler = proc_dointvec_minmax,
  1551. .extra1 = SYSCTL_ONE,
  1552. },
  1553. {
  1554. .procname = "tcp_rto_max_ms",
  1555. .data = &init_net.ipv4.sysctl_tcp_rto_max_ms,
  1556. .maxlen = sizeof(int),
  1557. .mode = 0644,
  1558. .proc_handler = proc_dointvec_minmax,
  1559. .extra1 = SYSCTL_ONE_THOUSAND,
  1560. .extra2 = &tcp_rto_max_max,
  1561. },
  1562. };
  1563. static __net_init int ipv4_sysctl_init_net(struct net *net)
  1564. {
  1565. size_t table_size = ARRAY_SIZE(ipv4_net_table);
  1566. struct ctl_table *table;
  1567. table = ipv4_net_table;
  1568. if (!net_eq(net, &init_net)) {
  1569. int i;
  1570. table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
  1571. if (!table)
  1572. goto err_alloc;
  1573. for (i = 0; i < table_size; i++) {
  1574. if (table[i].data) {
  1575. /* Update the variables to point into
  1576. * the current struct net
  1577. */
  1578. table[i].data += (void *)net - (void *)&init_net;
  1579. } else {
  1580. /* Entries without data pointer are global;
  1581. * Make them read-only in non-init_net ns
  1582. */
  1583. table[i].mode &= ~0222;
  1584. }
  1585. }
  1586. }
  1587. net->ipv4.ipv4_hdr = register_net_sysctl_sz(net, "net/ipv4", table,
  1588. table_size);
  1589. if (!net->ipv4.ipv4_hdr)
  1590. goto err_reg;
  1591. net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
  1592. if (!net->ipv4.sysctl_local_reserved_ports)
  1593. goto err_ports;
  1594. proc_fib_multipath_hash_set_seed(net, 0);
  1595. return 0;
  1596. err_ports:
  1597. unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
  1598. err_reg:
  1599. if (!net_eq(net, &init_net))
  1600. kfree(table);
  1601. err_alloc:
  1602. return -ENOMEM;
  1603. }
  1604. static __net_exit void ipv4_sysctl_exit_net(struct net *net)
  1605. {
  1606. const struct ctl_table *table;
  1607. kfree(net->ipv4.sysctl_local_reserved_ports);
  1608. table = net->ipv4.ipv4_hdr->ctl_table_arg;
  1609. unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
  1610. kfree(table);
  1611. }
  1612. static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
  1613. .init = ipv4_sysctl_init_net,
  1614. .exit = ipv4_sysctl_exit_net,
  1615. };
  1616. static __init int sysctl_ipv4_init(void)
  1617. {
  1618. struct ctl_table_header *hdr;
  1619. hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
  1620. if (!hdr)
  1621. return -ENOMEM;
  1622. proc_fib_multipath_hash_init_rand_seed();
  1623. if (register_pernet_subsys(&ipv4_sysctl_ops)) {
  1624. unregister_net_sysctl_table(hdr);
  1625. return -ENOMEM;
  1626. }
  1627. return 0;
  1628. }
  1629. __initcall(sysctl_ipv4_init);