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