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