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