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