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 },
616 {
617 .procname = "ip_dynaddr",
618 .data = &init_net.ipv4.sysctl_ip_dynaddr,
619 .maxlen = sizeof(u8),
620 .mode = 0644,
621 .proc_handler = proc_dou8vec_minmax,
622 },
623 {
624 .procname = "ip_early_demux",
625 .data = &init_net.ipv4.sysctl_ip_early_demux,
626 .maxlen = sizeof(u8),
627 .mode = 0644,
628 .proc_handler = proc_dou8vec_minmax,
629 },
630 {
631 .procname = "udp_early_demux",
632 .data = &init_net.ipv4.sysctl_udp_early_demux,
633 .maxlen = sizeof(int),
634 .mode = 0644,
635 .proc_handler = proc_douintvec_minmax,
636 },
637 {
638 .procname = "tcp_early_demux",
639 .data = &init_net.ipv4.sysctl_tcp_early_demux,
640 .maxlen = sizeof(int),
641 .mode = 0644,
642 .proc_handler = proc_douintvec_minmax,
643 },
644 {
645 .procname = "nexthop_compat_mode",
646 .data = &init_net.ipv4.sysctl_nexthop_compat_mode,
647 .maxlen = sizeof(u8),
648 .mode = 0644,
649 .proc_handler = proc_dou8vec_minmax,
650 .extra1 = SYSCTL_ZERO,
651 .extra2 = SYSCTL_ONE,
652 },
653 {
654 .procname = "ip_default_ttl",
655 .data = &init_net.ipv4.sysctl_ip_default_ttl,
656 .maxlen = sizeof(u8),
657 .mode = 0644,
658 .proc_handler = proc_dou8vec_minmax,
659 .extra1 = &ip_ttl_min,
660 .extra2 = &ip_ttl_max,
661 },
662 {
663 .procname = "ip_local_port_range",
664 .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
665 .data = &init_net.ipv4.ip_local_ports.range,
666 .mode = 0644,
667 .proc_handler = ipv4_local_port_range,
668 },
669 {
670 .procname = "ip_local_reserved_ports",
671 .data = &init_net.ipv4.sysctl_local_reserved_ports,
672 .maxlen = 65536,
673 .mode = 0644,
674 .proc_handler = proc_do_large_bitmap,
675 },
676 {
677 .procname = "ip_no_pmtu_disc",
678 .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
679 .maxlen = sizeof(u8),
680 .mode = 0644,
681 .proc_handler = proc_dou8vec_minmax,
682 },
683 {
684 .procname = "ip_forward_use_pmtu",
685 .data = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
686 .maxlen = sizeof(u8),
687 .mode = 0644,
688 .proc_handler = proc_dou8vec_minmax,
689 },
690 {
691 .procname = "ip_forward_update_priority",
692 .data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
693 .maxlen = sizeof(int),
694 .mode = 0644,
695 .proc_handler = ipv4_fwd_update_priority,
696 .extra1 = SYSCTL_ZERO,
697 .extra2 = SYSCTL_ONE,
698 },
699 {
700 .procname = "ip_nonlocal_bind",
701 .data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
702 .maxlen = sizeof(u8),
703 .mode = 0644,
704 .proc_handler = proc_dou8vec_minmax,
705 },
706 {
707 .procname = "ip_autobind_reuse",
708 .data = &init_net.ipv4.sysctl_ip_autobind_reuse,
709 .maxlen = sizeof(u8),
710 .mode = 0644,
711 .proc_handler = proc_dou8vec_minmax,
712 .extra1 = SYSCTL_ZERO,
713 .extra2 = SYSCTL_ONE,
714 },
715 {
716 .procname = "fwmark_reflect",
717 .data = &init_net.ipv4.sysctl_fwmark_reflect,
718 .maxlen = sizeof(u8),
719 .mode = 0644,
720 .proc_handler = proc_dou8vec_minmax,
721 },
722 {
723 .procname = "tcp_fwmark_accept",
724 .data = &init_net.ipv4.sysctl_tcp_fwmark_accept,
725 .maxlen = sizeof(u8),
726 .mode = 0644,
727 .proc_handler = proc_dou8vec_minmax,
728 },
729 #ifdef CONFIG_NET_L3_MASTER_DEV
730 {
731 .procname = "tcp_l3mdev_accept",
732 .data = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
733 .maxlen = sizeof(u8),
734 .mode = 0644,
735 .proc_handler = proc_dou8vec_minmax,
736 .extra1 = SYSCTL_ZERO,
737 .extra2 = SYSCTL_ONE,
738 },
739 #endif
740 {
741 .procname = "tcp_mtu_probing",
742 .data = &init_net.ipv4.sysctl_tcp_mtu_probing,
743 .maxlen = sizeof(u8),
744 .mode = 0644,
745 .proc_handler = proc_dou8vec_minmax,
746 },
747 {
748 .procname = "tcp_base_mss",
749 .data = &init_net.ipv4.sysctl_tcp_base_mss,
750 .maxlen = sizeof(int),
751 .mode = 0644,
752 .proc_handler = proc_dointvec,
753 },
754 {
755 .procname = "tcp_min_snd_mss",
756 .data = &init_net.ipv4.sysctl_tcp_min_snd_mss,
757 .maxlen = sizeof(int),
758 .mode = 0644,
759 .proc_handler = proc_dointvec_minmax,
760 .extra1 = &tcp_min_snd_mss_min,
761 .extra2 = &tcp_min_snd_mss_max,
762 },
763 {
764 .procname = "tcp_mtu_probe_floor",
765 .data = &init_net.ipv4.sysctl_tcp_mtu_probe_floor,
766 .maxlen = sizeof(int),
767 .mode = 0644,
768 .proc_handler = proc_dointvec_minmax,
769 .extra1 = &tcp_min_snd_mss_min,
770 .extra2 = &tcp_min_snd_mss_max,
771 },
772 {
773 .procname = "tcp_probe_threshold",
774 .data = &init_net.ipv4.sysctl_tcp_probe_threshold,
775 .maxlen = sizeof(int),
776 .mode = 0644,
777 .proc_handler = proc_dointvec,
778 },
779 {
780 .procname = "tcp_probe_interval",
781 .data = &init_net.ipv4.sysctl_tcp_probe_interval,
782 .maxlen = sizeof(u32),
783 .mode = 0644,
784 .proc_handler = proc_douintvec_minmax,
785 .extra2 = &u32_max_div_HZ,
786 },
787 {
788 .procname = "igmp_link_local_mcast_reports",
789 .data = &init_net.ipv4.sysctl_igmp_llm_reports,
790 .maxlen = sizeof(int),
791 .mode = 0644,
792 .proc_handler = proc_dointvec
793 },
794 {
795 .procname = "igmp_max_memberships",
796 .data = &init_net.ipv4.sysctl_igmp_max_memberships,
797 .maxlen = sizeof(int),
798 .mode = 0644,
799 .proc_handler = proc_dointvec
800 },
801 {
802 .procname = "igmp_max_msf",
803 .data = &init_net.ipv4.sysctl_igmp_max_msf,
804 .maxlen = sizeof(int),
805 .mode = 0644,
806 .proc_handler = proc_dointvec
807 },
808 #ifdef CONFIG_IP_MULTICAST
809 {
810 .procname = "igmp_qrv",
811 .data = &init_net.ipv4.sysctl_igmp_qrv,
812 .maxlen = sizeof(int),
813 .mode = 0644,
814 .proc_handler = proc_dointvec_minmax,
815 .extra1 = SYSCTL_ONE
816 },
817 #endif
818 {
819 .procname = "tcp_congestion_control",
820 .data = &init_net.ipv4.tcp_congestion_control,
821 .mode = 0644,
822 .maxlen = TCP_CA_NAME_MAX,
823 .proc_handler = proc_tcp_congestion_control,
824 },
825 {
826 .procname = "tcp_available_congestion_control",
827 .maxlen = TCP_CA_BUF_MAX,
828 .mode = 0444,
829 .proc_handler = proc_tcp_available_congestion_control,
830 },
831 {
832 .procname = "tcp_allowed_congestion_control",
833 .maxlen = TCP_CA_BUF_MAX,
834 .mode = 0644,
835 .proc_handler = proc_allowed_congestion_control,
836 },
837 {
838 .procname = "tcp_keepalive_time",
839 .data = &init_net.ipv4.sysctl_tcp_keepalive_time,
840 .maxlen = sizeof(int),
841 .mode = 0644,
842 .proc_handler = proc_dointvec_jiffies,
843 },
844 {
845 .procname = "tcp_keepalive_probes",
846 .data = &init_net.ipv4.sysctl_tcp_keepalive_probes,
847 .maxlen = sizeof(u8),
848 .mode = 0644,
849 .proc_handler = proc_dou8vec_minmax,
850 },
851 {
852 .procname = "tcp_keepalive_intvl",
853 .data = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
854 .maxlen = sizeof(int),
855 .mode = 0644,
856 .proc_handler = proc_dointvec_jiffies,
857 },
858 {
859 .procname = "tcp_syn_retries",
860 .data = &init_net.ipv4.sysctl_tcp_syn_retries,
861 .maxlen = sizeof(u8),
862 .mode = 0644,
863 .proc_handler = proc_dou8vec_minmax,
864 .extra1 = &tcp_syn_retries_min,
865 .extra2 = &tcp_syn_retries_max
866 },
867 {
868 .procname = "tcp_synack_retries",
869 .data = &init_net.ipv4.sysctl_tcp_synack_retries,
870 .maxlen = sizeof(u8),
871 .mode = 0644,
872 .proc_handler = proc_dou8vec_minmax,
873 },
874 #ifdef CONFIG_SYN_COOKIES
875 {
876 .procname = "tcp_syncookies",
877 .data = &init_net.ipv4.sysctl_tcp_syncookies,
878 .maxlen = sizeof(u8),
879 .mode = 0644,
880 .proc_handler = proc_dou8vec_minmax,
881 },
882 #endif
883 {
884 .procname = "tcp_migrate_req",
885 .data = &init_net.ipv4.sysctl_tcp_migrate_req,
886 .maxlen = sizeof(u8),
887 .mode = 0644,
888 .proc_handler = proc_dou8vec_minmax,
889 .extra1 = SYSCTL_ZERO,
890 .extra2 = SYSCTL_ONE
891 },
892 {
893 .procname = "tcp_reordering",
894 .data = &init_net.ipv4.sysctl_tcp_reordering,
895 .maxlen = sizeof(int),
896 .mode = 0644,
897 .proc_handler = proc_dointvec
898 },
899 {
900 .procname = "tcp_retries1",
901 .data = &init_net.ipv4.sysctl_tcp_retries1,
902 .maxlen = sizeof(u8),
903 .mode = 0644,
904 .proc_handler = proc_dou8vec_minmax,
905 .extra2 = &tcp_retr1_max
906 },
907 {
908 .procname = "tcp_retries2",
909 .data = &init_net.ipv4.sysctl_tcp_retries2,
910 .maxlen = sizeof(u8),
911 .mode = 0644,
912 .proc_handler = proc_dou8vec_minmax,
913 },
914 {
915 .procname = "tcp_orphan_retries",
916 .data = &init_net.ipv4.sysctl_tcp_orphan_retries,
917 .maxlen = sizeof(u8),
918 .mode = 0644,
919 .proc_handler = proc_dou8vec_minmax,
920 },
921 {
922 .procname = "tcp_fin_timeout",
923 .data = &init_net.ipv4.sysctl_tcp_fin_timeout,
924 .maxlen = sizeof(int),
925 .mode = 0644,
926 .proc_handler = proc_dointvec_jiffies,
927 },
928 {
929 .procname = "tcp_notsent_lowat",
930 .data = &init_net.ipv4.sysctl_tcp_notsent_lowat,
931 .maxlen = sizeof(unsigned int),
932 .mode = 0644,
933 .proc_handler = proc_douintvec,
934 },
935 {
936 .procname = "tcp_tw_reuse",
937 .data = &init_net.ipv4.sysctl_tcp_tw_reuse,
938 .maxlen = sizeof(u8),
939 .mode = 0644,
940 .proc_handler = proc_dou8vec_minmax,
941 .extra1 = SYSCTL_ZERO,
942 .extra2 = &two,
943 },
944 {
945 .procname = "tcp_max_tw_buckets",
946 .data = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
947 .maxlen = sizeof(int),
948 .mode = 0644,
949 .proc_handler = proc_dointvec
950 },
951 {
952 .procname = "tcp_max_syn_backlog",
953 .data = &init_net.ipv4.sysctl_max_syn_backlog,
954 .maxlen = sizeof(int),
955 .mode = 0644,
956 .proc_handler = proc_dointvec
957 },
958 {
959 .procname = "tcp_fastopen",
960 .data = &init_net.ipv4.sysctl_tcp_fastopen,
961 .maxlen = sizeof(int),
962 .mode = 0644,
963 .proc_handler = proc_dointvec,
964 },
965 {
966 .procname = "tcp_fastopen_key",
967 .mode = 0600,
968 .data = &init_net.ipv4.sysctl_tcp_fastopen,
969 /* maxlen to print the list of keys in hex (*2), with dashes
970 * separating doublewords and a comma in between keys.
971 */
972 .maxlen = ((TCP_FASTOPEN_KEY_LENGTH *
973 2 * TCP_FASTOPEN_KEY_MAX) +
974 (TCP_FASTOPEN_KEY_MAX * 5)),
975 .proc_handler = proc_tcp_fastopen_key,
976 },
977 {
978 .procname = "tcp_fastopen_blackhole_timeout_sec",
979 .data = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
980 .maxlen = sizeof(int),
981 .mode = 0644,
982 .proc_handler = proc_tfo_blackhole_detect_timeout,
983 .extra1 = SYSCTL_ZERO,
984 },
985 #ifdef CONFIG_IP_ROUTE_MULTIPATH
986 {
987 .procname = "fib_multipath_use_neigh",
988 .data = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
989 .maxlen = sizeof(int),
990 .mode = 0644,
991 .proc_handler = proc_dointvec_minmax,
992 .extra1 = SYSCTL_ZERO,
993 .extra2 = SYSCTL_ONE,
994 },
995 {
996 .procname = "fib_multipath_hash_policy",
997 .data = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
998 .maxlen = sizeof(int),
999 .mode = 0644,
1000 .proc_handler = proc_fib_multipath_hash_policy,
1001 .extra1 = SYSCTL_ZERO,
1002 .extra2 = &two,
1003 },
1004 #endif
1005 {
1006 .procname = "ip_unprivileged_port_start",
1007 .maxlen = sizeof(int),
1008 .data = &init_net.ipv4.sysctl_ip_prot_sock,
1009 .mode = 0644,
1010 .proc_handler = ipv4_privileged_ports,
1011 },
1012 #ifdef CONFIG_NET_L3_MASTER_DEV
1013 {
1014 .procname = "udp_l3mdev_accept",
1015 .data = &init_net.ipv4.sysctl_udp_l3mdev_accept,
1016 .maxlen = sizeof(int),
1017 .mode = 0644,
1018 .proc_handler = proc_dointvec_minmax,
1019 .extra1 = SYSCTL_ZERO,
1020 .extra2 = SYSCTL_ONE,
1021 },
1022 #endif
1023 {
1024 .procname = "tcp_sack",
1025 .data = &init_net.ipv4.sysctl_tcp_sack,
1026 .maxlen = sizeof(u8),
1027 .mode = 0644,
1028 .proc_handler = proc_dou8vec_minmax,
1029 },
1030 {
1031 .procname = "tcp_window_scaling",
1032 .data = &init_net.ipv4.sysctl_tcp_window_scaling,
1033 .maxlen = sizeof(u8),
1034 .mode = 0644,
1035 .proc_handler = proc_dou8vec_minmax,
1036 },
1037 {
1038 .procname = "tcp_timestamps",
1039 .data = &init_net.ipv4.sysctl_tcp_timestamps,
1040 .maxlen = sizeof(u8),
1041 .mode = 0644,
1042 .proc_handler = proc_dou8vec_minmax,
1043 },
1044 {
1045 .procname = "tcp_early_retrans",
1046 .data = &init_net.ipv4.sysctl_tcp_early_retrans,
1047 .maxlen = sizeof(u8),
1048 .mode = 0644,
1049 .proc_handler = proc_dou8vec_minmax,
1050 .extra1 = SYSCTL_ZERO,
1051 .extra2 = &four,
1052 },
1053 {
1054 .procname = "tcp_recovery",
1055 .data = &init_net.ipv4.sysctl_tcp_recovery,
1056 .maxlen = sizeof(u8),
1057 .mode = 0644,
1058 .proc_handler = proc_dou8vec_minmax,
1059 },
1060 {
1061 .procname = "tcp_thin_linear_timeouts",
1062 .data = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1063 .maxlen = sizeof(u8),
1064 .mode = 0644,
1065 .proc_handler = proc_dou8vec_minmax,
1066 },
1067 {
1068 .procname = "tcp_slow_start_after_idle",
1069 .data = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1070 .maxlen = sizeof(u8),
1071 .mode = 0644,
1072 .proc_handler = proc_dou8vec_minmax,
1073 },
1074 {
1075 .procname = "tcp_retrans_collapse",
1076 .data = &init_net.ipv4.sysctl_tcp_retrans_collapse,
1077 .maxlen = sizeof(u8),
1078 .mode = 0644,
1079 .proc_handler = proc_dou8vec_minmax,
1080 },
1081 {
1082 .procname = "tcp_stdurg",
1083 .data = &init_net.ipv4.sysctl_tcp_stdurg,
1084 .maxlen = sizeof(u8),
1085 .mode = 0644,
1086 .proc_handler = proc_dou8vec_minmax,
1087 },
1088 {
1089 .procname = "tcp_rfc1337",
1090 .data = &init_net.ipv4.sysctl_tcp_rfc1337,
1091 .maxlen = sizeof(u8),
1092 .mode = 0644,
1093 .proc_handler = proc_dou8vec_minmax,
1094 },
1095 {
1096 .procname = "tcp_abort_on_overflow",
1097 .data = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1098 .maxlen = sizeof(u8),
1099 .mode = 0644,
1100 .proc_handler = proc_dou8vec_minmax,
1101 },
1102 {
1103 .procname = "tcp_fack",
1104 .data = &init_net.ipv4.sysctl_tcp_fack,
1105 .maxlen = sizeof(u8),
1106 .mode = 0644,
1107 .proc_handler = proc_dou8vec_minmax,
1108 },
1109 {
1110 .procname = "tcp_max_reordering",
1111 .data = &init_net.ipv4.sysctl_tcp_max_reordering,
1112 .maxlen = sizeof(int),
1113 .mode = 0644,
1114 .proc_handler = proc_dointvec
1115 },
1116 {
1117 .procname = "tcp_dsack",
1118 .data = &init_net.ipv4.sysctl_tcp_dsack,
1119 .maxlen = sizeof(u8),
1120 .mode = 0644,
1121 .proc_handler = proc_dou8vec_minmax,
1122 },
1123 {
1124 .procname = "tcp_app_win",
1125 .data = &init_net.ipv4.sysctl_tcp_app_win,
1126 .maxlen = sizeof(u8),
1127 .mode = 0644,
1128 .proc_handler = proc_dou8vec_minmax,
1129 .extra1 = SYSCTL_ZERO,
1130 .extra2 = &tcp_app_win_max,
1131 },
1132 {
1133 .procname = "tcp_adv_win_scale",
1134 .data = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1135 .maxlen = sizeof(int),
1136 .mode = 0644,
1137 .proc_handler = proc_dointvec_minmax,
1138 .extra1 = &tcp_adv_win_scale_min,
1139 .extra2 = &tcp_adv_win_scale_max,
1140 },
1141 {
1142 .procname = "tcp_frto",
1143 .data = &init_net.ipv4.sysctl_tcp_frto,
1144 .maxlen = sizeof(u8),
1145 .mode = 0644,
1146 .proc_handler = proc_dou8vec_minmax,
1147 },
1148 {
1149 .procname = "tcp_no_metrics_save",
1150 .data = &init_net.ipv4.sysctl_tcp_nometrics_save,
1151 .maxlen = sizeof(u8),
1152 .mode = 0644,
1153 .proc_handler = proc_dou8vec_minmax,
1154 },
1155 {
1156 .procname = "tcp_no_ssthresh_metrics_save",
1157 .data = &init_net.ipv4.sysctl_tcp_no_ssthresh_metrics_save,
1158 .maxlen = sizeof(u8),
1159 .mode = 0644,
1160 .proc_handler = proc_dou8vec_minmax,
1161 .extra1 = SYSCTL_ZERO,
1162 .extra2 = SYSCTL_ONE,
1163 },
1164 {
1165 .procname = "tcp_moderate_rcvbuf",
1166 .data = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1167 .maxlen = sizeof(u8),
1168 .mode = 0644,
1169 .proc_handler = proc_dou8vec_minmax,
1170 },
1171 {
1172 .procname = "tcp_tso_win_divisor",
1173 .data = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1174 .maxlen = sizeof(u8),
1175 .mode = 0644,
1176 .proc_handler = proc_dou8vec_minmax,
1177 },
1178 {
1179 .procname = "tcp_workaround_signed_windows",
1180 .data = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1181 .maxlen = sizeof(u8),
1182 .mode = 0644,
1183 .proc_handler = proc_dou8vec_minmax,
1184 },
1185 {
1186 .procname = "tcp_limit_output_bytes",
1187 .data = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1188 .maxlen = sizeof(int),
1189 .mode = 0644,
1190 .proc_handler = proc_dointvec
1191 },
1192 {
1193 .procname = "tcp_challenge_ack_limit",
1194 .data = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1195 .maxlen = sizeof(int),
1196 .mode = 0644,
1197 .proc_handler = proc_dointvec
1198 },
1199 {
1200 .procname = "tcp_min_tso_segs",
1201 .data = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1202 .maxlen = sizeof(u8),
1203 .mode = 0644,
1204 .proc_handler = proc_dou8vec_minmax,
1205 .extra1 = SYSCTL_ONE,
1206 },
1207 {
1208 .procname = "tcp_min_rtt_wlen",
1209 .data = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1210 .maxlen = sizeof(int),
1211 .mode = 0644,
1212 .proc_handler = proc_dointvec_minmax,
1213 .extra1 = SYSCTL_ZERO,
1214 .extra2 = &one_day_secs
1215 },
1216 {
1217 .procname = "tcp_autocorking",
1218 .data = &init_net.ipv4.sysctl_tcp_autocorking,
1219 .maxlen = sizeof(u8),
1220 .mode = 0644,
1221 .proc_handler = proc_dou8vec_minmax,
1222 .extra1 = SYSCTL_ZERO,
1223 .extra2 = SYSCTL_ONE,
1224 },
1225 {
1226 .procname = "tcp_invalid_ratelimit",
1227 .data = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1228 .maxlen = sizeof(int),
1229 .mode = 0644,
1230 .proc_handler = proc_dointvec_ms_jiffies,
1231 },
1232 {
1233 .procname = "tcp_pacing_ss_ratio",
1234 .data = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1235 .maxlen = sizeof(int),
1236 .mode = 0644,
1237 .proc_handler = proc_dointvec_minmax,
1238 .extra1 = SYSCTL_ZERO,
1239 .extra2 = &thousand,
1240 },
1241 {
1242 .procname = "tcp_pacing_ca_ratio",
1243 .data = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1244 .maxlen = sizeof(int),
1245 .mode = 0644,
1246 .proc_handler = proc_dointvec_minmax,
1247 .extra1 = SYSCTL_ZERO,
1248 .extra2 = &thousand,
1249 },
1250 {
1251 .procname = "tcp_wmem",
1252 .data = &init_net.ipv4.sysctl_tcp_wmem,
1253 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1254 .mode = 0644,
1255 .proc_handler = proc_dointvec_minmax,
1256 .extra1 = SYSCTL_ONE,
1257 },
1258 {
1259 .procname = "tcp_rmem",
1260 .data = &init_net.ipv4.sysctl_tcp_rmem,
1261 .maxlen = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1262 .mode = 0644,
1263 .proc_handler = proc_dointvec_minmax,
1264 .extra1 = SYSCTL_ONE,
1265 },
1266 {
1267 .procname = "tcp_comp_sack_delay_ns",
1268 .data = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1269 .maxlen = sizeof(unsigned long),
1270 .mode = 0644,
1271 .proc_handler = proc_doulongvec_minmax,
1272 },
1273 {
1274 .procname = "tcp_comp_sack_slack_ns",
1275 .data = &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
1276 .maxlen = sizeof(unsigned long),
1277 .mode = 0644,
1278 .proc_handler = proc_doulongvec_minmax,
1279 },
1280 {
1281 .procname = "tcp_comp_sack_nr",
1282 .data = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1283 .maxlen = sizeof(int),
1284 .mode = 0644,
1285 .proc_handler = proc_dointvec_minmax,
1286 .extra1 = SYSCTL_ZERO,
1287 .extra2 = &comp_sack_nr_max,
1288 },
1289 {
1290 .procname = "tcp_reflect_tos",
1291 .data = &init_net.ipv4.sysctl_tcp_reflect_tos,
1292 .maxlen = sizeof(u8),
1293 .mode = 0644,
1294 .proc_handler = proc_dou8vec_minmax,
1295 .extra1 = SYSCTL_ZERO,
1296 .extra2 = SYSCTL_ONE,
1297 },
1298 {
1299 .procname = "udp_rmem_min",
1300 .data = &init_net.ipv4.sysctl_udp_rmem_min,
1301 .maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1302 .mode = 0644,
1303 .proc_handler = proc_dointvec_minmax,
1304 .extra1 = SYSCTL_ONE
1305 },
1306 {
1307 .procname = "udp_wmem_min",
1308 .data = &init_net.ipv4.sysctl_udp_wmem_min,
1309 .maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1310 .mode = 0644,
1311 .proc_handler = proc_dointvec_minmax,
1312 .extra1 = SYSCTL_ONE
1313 },
1314 { }
1315 };
1316
ipv4_sysctl_init_net(struct net * net)1317 static __net_init int ipv4_sysctl_init_net(struct net *net)
1318 {
1319 struct ctl_table *table;
1320
1321 table = ipv4_net_table;
1322 if (!net_eq(net, &init_net)) {
1323 int i;
1324
1325 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
1326 if (!table)
1327 goto err_alloc;
1328
1329 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) {
1330 if (table[i].data) {
1331 /* Update the variables to point into
1332 * the current struct net
1333 */
1334 table[i].data += (void *)net - (void *)&init_net;
1335 } else {
1336 /* Entries without data pointer are global;
1337 * Make them read-only in non-init_net ns
1338 */
1339 table[i].mode &= ~0222;
1340 }
1341 }
1342 }
1343
1344 net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
1345 if (!net->ipv4.ipv4_hdr)
1346 goto err_reg;
1347
1348 net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1349 if (!net->ipv4.sysctl_local_reserved_ports)
1350 goto err_ports;
1351
1352 return 0;
1353
1354 err_ports:
1355 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1356 err_reg:
1357 if (!net_eq(net, &init_net))
1358 kfree(table);
1359 err_alloc:
1360 return -ENOMEM;
1361 }
1362
ipv4_sysctl_exit_net(struct net * net)1363 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1364 {
1365 struct ctl_table *table;
1366
1367 kfree(net->ipv4.sysctl_local_reserved_ports);
1368 table = net->ipv4.ipv4_hdr->ctl_table_arg;
1369 unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1370 kfree(table);
1371 }
1372
1373 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1374 .init = ipv4_sysctl_init_net,
1375 .exit = ipv4_sysctl_exit_net,
1376 };
1377
sysctl_ipv4_init(void)1378 static __init int sysctl_ipv4_init(void)
1379 {
1380 struct ctl_table_header *hdr;
1381
1382 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1383 if (!hdr)
1384 return -ENOMEM;
1385
1386 if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1387 unregister_net_sysctl_table(hdr);
1388 return -ENOMEM;
1389 }
1390
1391 return 0;
1392 }
1393
1394 __initcall(sysctl_ipv4_init);
1395