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