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