ipv4: Add custom multipath hash policy
[linux-2.6-microblaze.git] / net / ipv4 / sysctl_net_ipv4.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
4  *
5  * Begun April 1, 1996, Mike Shaver.
6  * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
7  */
8
9 #include <linux/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] < 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 = 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                         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 #endif
469
470 static struct ctl_table ipv4_table[] = {
471         {
472                 .procname       = "tcp_max_orphans",
473                 .data           = &sysctl_tcp_max_orphans,
474                 .maxlen         = sizeof(int),
475                 .mode           = 0644,
476                 .proc_handler   = proc_dointvec
477         },
478         {
479                 .procname       = "inet_peer_threshold",
480                 .data           = &inet_peer_threshold,
481                 .maxlen         = sizeof(int),
482                 .mode           = 0644,
483                 .proc_handler   = proc_dointvec
484         },
485         {
486                 .procname       = "inet_peer_minttl",
487                 .data           = &inet_peer_minttl,
488                 .maxlen         = sizeof(int),
489                 .mode           = 0644,
490                 .proc_handler   = proc_dointvec_jiffies,
491         },
492         {
493                 .procname       = "inet_peer_maxttl",
494                 .data           = &inet_peer_maxttl,
495                 .maxlen         = sizeof(int),
496                 .mode           = 0644,
497                 .proc_handler   = proc_dointvec_jiffies,
498         },
499         {
500                 .procname       = "tcp_mem",
501                 .maxlen         = sizeof(sysctl_tcp_mem),
502                 .data           = &sysctl_tcp_mem,
503                 .mode           = 0644,
504                 .proc_handler   = proc_doulongvec_minmax,
505         },
506         {
507                 .procname       = "tcp_low_latency",
508                 .data           = &sysctl_tcp_low_latency,
509                 .maxlen         = sizeof(int),
510                 .mode           = 0644,
511                 .proc_handler   = proc_dointvec
512         },
513 #ifdef CONFIG_NETLABEL
514         {
515                 .procname       = "cipso_cache_enable",
516                 .data           = &cipso_v4_cache_enabled,
517                 .maxlen         = sizeof(int),
518                 .mode           = 0644,
519                 .proc_handler   = proc_dointvec,
520         },
521         {
522                 .procname       = "cipso_cache_bucket_size",
523                 .data           = &cipso_v4_cache_bucketsize,
524                 .maxlen         = sizeof(int),
525                 .mode           = 0644,
526                 .proc_handler   = proc_dointvec,
527         },
528         {
529                 .procname       = "cipso_rbm_optfmt",
530                 .data           = &cipso_v4_rbm_optfmt,
531                 .maxlen         = sizeof(int),
532                 .mode           = 0644,
533                 .proc_handler   = proc_dointvec,
534         },
535         {
536                 .procname       = "cipso_rbm_strictvalid",
537                 .data           = &cipso_v4_rbm_strictvalid,
538                 .maxlen         = sizeof(int),
539                 .mode           = 0644,
540                 .proc_handler   = proc_dointvec,
541         },
542 #endif /* CONFIG_NETLABEL */
543         {
544                 .procname       = "tcp_available_ulp",
545                 .maxlen         = TCP_ULP_BUF_MAX,
546                 .mode           = 0444,
547                 .proc_handler   = proc_tcp_available_ulp,
548         },
549         {
550                 .procname       = "icmp_msgs_per_sec",
551                 .data           = &sysctl_icmp_msgs_per_sec,
552                 .maxlen         = sizeof(int),
553                 .mode           = 0644,
554                 .proc_handler   = proc_dointvec_minmax,
555                 .extra1         = SYSCTL_ZERO,
556         },
557         {
558                 .procname       = "icmp_msgs_burst",
559                 .data           = &sysctl_icmp_msgs_burst,
560                 .maxlen         = sizeof(int),
561                 .mode           = 0644,
562                 .proc_handler   = proc_dointvec_minmax,
563                 .extra1         = SYSCTL_ZERO,
564         },
565         {
566                 .procname       = "udp_mem",
567                 .data           = &sysctl_udp_mem,
568                 .maxlen         = sizeof(sysctl_udp_mem),
569                 .mode           = 0644,
570                 .proc_handler   = proc_doulongvec_minmax,
571         },
572         {
573                 .procname       = "fib_sync_mem",
574                 .data           = &sysctl_fib_sync_mem,
575                 .maxlen         = sizeof(sysctl_fib_sync_mem),
576                 .mode           = 0644,
577                 .proc_handler   = proc_douintvec_minmax,
578                 .extra1         = &sysctl_fib_sync_mem_min,
579                 .extra2         = &sysctl_fib_sync_mem_max,
580         },
581         {
582                 .procname       = "tcp_rx_skb_cache",
583                 .data           = &tcp_rx_skb_cache_key.key,
584                 .mode           = 0644,
585                 .proc_handler   = proc_do_static_key,
586         },
587         {
588                 .procname       = "tcp_tx_skb_cache",
589                 .data           = &tcp_tx_skb_cache_key.key,
590                 .mode           = 0644,
591                 .proc_handler   = proc_do_static_key,
592         },
593         { }
594 };
595
596 static struct ctl_table ipv4_net_table[] = {
597         {
598                 .procname       = "icmp_echo_ignore_all",
599                 .data           = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
600                 .maxlen         = sizeof(u8),
601                 .mode           = 0644,
602                 .proc_handler   = proc_dou8vec_minmax,
603         },
604         {
605                 .procname       = "icmp_echo_enable_probe",
606                 .data           = &init_net.ipv4.sysctl_icmp_echo_enable_probe,
607                 .maxlen         = sizeof(u8),
608                 .mode           = 0644,
609                 .proc_handler   = proc_dou8vec_minmax,
610                 .extra1         = SYSCTL_ZERO,
611                 .extra2         = SYSCTL_ONE
612         },
613         {
614                 .procname       = "icmp_echo_ignore_broadcasts",
615                 .data           = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
616                 .maxlen         = sizeof(u8),
617                 .mode           = 0644,
618                 .proc_handler   = proc_dou8vec_minmax,
619         },
620         {
621                 .procname       = "icmp_ignore_bogus_error_responses",
622                 .data           = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
623                 .maxlen         = sizeof(u8),
624                 .mode           = 0644,
625                 .proc_handler   = proc_dou8vec_minmax,
626         },
627         {
628                 .procname       = "icmp_errors_use_inbound_ifaddr",
629                 .data           = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
630                 .maxlen         = sizeof(u8),
631                 .mode           = 0644,
632                 .proc_handler   = proc_dou8vec_minmax,
633         },
634         {
635                 .procname       = "icmp_ratelimit",
636                 .data           = &init_net.ipv4.sysctl_icmp_ratelimit,
637                 .maxlen         = sizeof(int),
638                 .mode           = 0644,
639                 .proc_handler   = proc_dointvec_ms_jiffies,
640         },
641         {
642                 .procname       = "icmp_ratemask",
643                 .data           = &init_net.ipv4.sysctl_icmp_ratemask,
644                 .maxlen         = sizeof(int),
645                 .mode           = 0644,
646                 .proc_handler   = proc_dointvec
647         },
648         {
649                 .procname       = "ping_group_range",
650                 .data           = &init_net.ipv4.ping_group_range.range,
651                 .maxlen         = sizeof(gid_t)*2,
652                 .mode           = 0644,
653                 .proc_handler   = ipv4_ping_group_range,
654         },
655 #ifdef CONFIG_NET_L3_MASTER_DEV
656         {
657                 .procname       = "raw_l3mdev_accept",
658                 .data           = &init_net.ipv4.sysctl_raw_l3mdev_accept,
659                 .maxlen         = sizeof(u8),
660                 .mode           = 0644,
661                 .proc_handler   = proc_dou8vec_minmax,
662                 .extra1         = SYSCTL_ZERO,
663                 .extra2         = SYSCTL_ONE,
664         },
665 #endif
666         {
667                 .procname       = "tcp_ecn",
668                 .data           = &init_net.ipv4.sysctl_tcp_ecn,
669                 .maxlen         = sizeof(u8),
670                 .mode           = 0644,
671                 .proc_handler   = proc_dou8vec_minmax,
672         },
673         {
674                 .procname       = "tcp_ecn_fallback",
675                 .data           = &init_net.ipv4.sysctl_tcp_ecn_fallback,
676                 .maxlen         = sizeof(u8),
677                 .mode           = 0644,
678                 .proc_handler   = proc_dou8vec_minmax,
679         },
680         {
681                 .procname       = "ip_dynaddr",
682                 .data           = &init_net.ipv4.sysctl_ip_dynaddr,
683                 .maxlen         = sizeof(u8),
684                 .mode           = 0644,
685                 .proc_handler   = proc_dou8vec_minmax,
686         },
687         {
688                 .procname       = "ip_early_demux",
689                 .data           = &init_net.ipv4.sysctl_ip_early_demux,
690                 .maxlen         = sizeof(u8),
691                 .mode           = 0644,
692                 .proc_handler   = proc_dou8vec_minmax,
693         },
694         {
695                 .procname       = "udp_early_demux",
696                 .data           = &init_net.ipv4.sysctl_udp_early_demux,
697                 .maxlen         = sizeof(u8),
698                 .mode           = 0644,
699                 .proc_handler   = proc_udp_early_demux
700         },
701         {
702                 .procname       = "tcp_early_demux",
703                 .data           = &init_net.ipv4.sysctl_tcp_early_demux,
704                 .maxlen         = sizeof(u8),
705                 .mode           = 0644,
706                 .proc_handler   = proc_tcp_early_demux
707         },
708         {
709                 .procname       = "nexthop_compat_mode",
710                 .data           = &init_net.ipv4.sysctl_nexthop_compat_mode,
711                 .maxlen         = sizeof(u8),
712                 .mode           = 0644,
713                 .proc_handler   = proc_dou8vec_minmax,
714                 .extra1         = SYSCTL_ZERO,
715                 .extra2         = SYSCTL_ONE,
716         },
717         {
718                 .procname       = "ip_default_ttl",
719                 .data           = &init_net.ipv4.sysctl_ip_default_ttl,
720                 .maxlen         = sizeof(u8),
721                 .mode           = 0644,
722                 .proc_handler   = proc_dou8vec_minmax,
723                 .extra1         = &ip_ttl_min,
724                 .extra2         = &ip_ttl_max,
725         },
726         {
727                 .procname       = "ip_local_port_range",
728                 .maxlen         = sizeof(init_net.ipv4.ip_local_ports.range),
729                 .data           = &init_net.ipv4.ip_local_ports.range,
730                 .mode           = 0644,
731                 .proc_handler   = ipv4_local_port_range,
732         },
733         {
734                 .procname       = "ip_local_reserved_ports",
735                 .data           = &init_net.ipv4.sysctl_local_reserved_ports,
736                 .maxlen         = 65536,
737                 .mode           = 0644,
738                 .proc_handler   = proc_do_large_bitmap,
739         },
740         {
741                 .procname       = "ip_no_pmtu_disc",
742                 .data           = &init_net.ipv4.sysctl_ip_no_pmtu_disc,
743                 .maxlen         = sizeof(u8),
744                 .mode           = 0644,
745                 .proc_handler   = proc_dou8vec_minmax,
746         },
747         {
748                 .procname       = "ip_forward_use_pmtu",
749                 .data           = &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
750                 .maxlen         = sizeof(u8),
751                 .mode           = 0644,
752                 .proc_handler   = proc_dou8vec_minmax,
753         },
754         {
755                 .procname       = "ip_forward_update_priority",
756                 .data           = &init_net.ipv4.sysctl_ip_fwd_update_priority,
757                 .maxlen         = sizeof(u8),
758                 .mode           = 0644,
759                 .proc_handler   = ipv4_fwd_update_priority,
760                 .extra1         = SYSCTL_ZERO,
761                 .extra2         = SYSCTL_ONE,
762         },
763         {
764                 .procname       = "ip_nonlocal_bind",
765                 .data           = &init_net.ipv4.sysctl_ip_nonlocal_bind,
766                 .maxlen         = sizeof(u8),
767                 .mode           = 0644,
768                 .proc_handler   = proc_dou8vec_minmax,
769         },
770         {
771                 .procname       = "ip_autobind_reuse",
772                 .data           = &init_net.ipv4.sysctl_ip_autobind_reuse,
773                 .maxlen         = sizeof(u8),
774                 .mode           = 0644,
775                 .proc_handler   = proc_dou8vec_minmax,
776                 .extra1         = SYSCTL_ZERO,
777                 .extra2         = SYSCTL_ONE,
778         },
779         {
780                 .procname       = "fwmark_reflect",
781                 .data           = &init_net.ipv4.sysctl_fwmark_reflect,
782                 .maxlen         = sizeof(u8),
783                 .mode           = 0644,
784                 .proc_handler   = proc_dou8vec_minmax,
785         },
786         {
787                 .procname       = "tcp_fwmark_accept",
788                 .data           = &init_net.ipv4.sysctl_tcp_fwmark_accept,
789                 .maxlen         = sizeof(u8),
790                 .mode           = 0644,
791                 .proc_handler   = proc_dou8vec_minmax,
792         },
793 #ifdef CONFIG_NET_L3_MASTER_DEV
794         {
795                 .procname       = "tcp_l3mdev_accept",
796                 .data           = &init_net.ipv4.sysctl_tcp_l3mdev_accept,
797                 .maxlen         = sizeof(u8),
798                 .mode           = 0644,
799                 .proc_handler   = proc_dou8vec_minmax,
800                 .extra1         = SYSCTL_ZERO,
801                 .extra2         = SYSCTL_ONE,
802         },
803 #endif
804         {
805                 .procname       = "tcp_mtu_probing",
806                 .data           = &init_net.ipv4.sysctl_tcp_mtu_probing,
807                 .maxlen         = sizeof(u8),
808                 .mode           = 0644,
809                 .proc_handler   = proc_dou8vec_minmax,
810         },
811         {
812                 .procname       = "tcp_base_mss",
813                 .data           = &init_net.ipv4.sysctl_tcp_base_mss,
814                 .maxlen         = sizeof(int),
815                 .mode           = 0644,
816                 .proc_handler   = proc_dointvec,
817         },
818         {
819                 .procname       = "tcp_min_snd_mss",
820                 .data           = &init_net.ipv4.sysctl_tcp_min_snd_mss,
821                 .maxlen         = sizeof(int),
822                 .mode           = 0644,
823                 .proc_handler   = proc_dointvec_minmax,
824                 .extra1         = &tcp_min_snd_mss_min,
825                 .extra2         = &tcp_min_snd_mss_max,
826         },
827         {
828                 .procname       = "tcp_mtu_probe_floor",
829                 .data           = &init_net.ipv4.sysctl_tcp_mtu_probe_floor,
830                 .maxlen         = sizeof(int),
831                 .mode           = 0644,
832                 .proc_handler   = proc_dointvec_minmax,
833                 .extra1         = &tcp_min_snd_mss_min,
834                 .extra2         = &tcp_min_snd_mss_max,
835         },
836         {
837                 .procname       = "tcp_probe_threshold",
838                 .data           = &init_net.ipv4.sysctl_tcp_probe_threshold,
839                 .maxlen         = sizeof(int),
840                 .mode           = 0644,
841                 .proc_handler   = proc_dointvec,
842         },
843         {
844                 .procname       = "tcp_probe_interval",
845                 .data           = &init_net.ipv4.sysctl_tcp_probe_interval,
846                 .maxlen         = sizeof(u32),
847                 .mode           = 0644,
848                 .proc_handler   = proc_douintvec_minmax,
849                 .extra2         = &u32_max_div_HZ,
850         },
851         {
852                 .procname       = "igmp_link_local_mcast_reports",
853                 .data           = &init_net.ipv4.sysctl_igmp_llm_reports,
854                 .maxlen         = sizeof(u8),
855                 .mode           = 0644,
856                 .proc_handler   = proc_dou8vec_minmax,
857         },
858         {
859                 .procname       = "igmp_max_memberships",
860                 .data           = &init_net.ipv4.sysctl_igmp_max_memberships,
861                 .maxlen         = sizeof(int),
862                 .mode           = 0644,
863                 .proc_handler   = proc_dointvec
864         },
865         {
866                 .procname       = "igmp_max_msf",
867                 .data           = &init_net.ipv4.sysctl_igmp_max_msf,
868                 .maxlen         = sizeof(int),
869                 .mode           = 0644,
870                 .proc_handler   = proc_dointvec
871         },
872 #ifdef CONFIG_IP_MULTICAST
873         {
874                 .procname       = "igmp_qrv",
875                 .data           = &init_net.ipv4.sysctl_igmp_qrv,
876                 .maxlen         = sizeof(int),
877                 .mode           = 0644,
878                 .proc_handler   = proc_dointvec_minmax,
879                 .extra1         = SYSCTL_ONE
880         },
881 #endif
882         {
883                 .procname       = "tcp_congestion_control",
884                 .data           = &init_net.ipv4.tcp_congestion_control,
885                 .mode           = 0644,
886                 .maxlen         = TCP_CA_NAME_MAX,
887                 .proc_handler   = proc_tcp_congestion_control,
888         },
889         {
890                 .procname       = "tcp_available_congestion_control",
891                 .maxlen         = TCP_CA_BUF_MAX,
892                 .mode           = 0444,
893                 .proc_handler   = proc_tcp_available_congestion_control,
894         },
895         {
896                 .procname       = "tcp_allowed_congestion_control",
897                 .maxlen         = TCP_CA_BUF_MAX,
898                 .mode           = 0644,
899                 .proc_handler   = proc_allowed_congestion_control,
900         },
901         {
902                 .procname       = "tcp_keepalive_time",
903                 .data           = &init_net.ipv4.sysctl_tcp_keepalive_time,
904                 .maxlen         = sizeof(int),
905                 .mode           = 0644,
906                 .proc_handler   = proc_dointvec_jiffies,
907         },
908         {
909                 .procname       = "tcp_keepalive_probes",
910                 .data           = &init_net.ipv4.sysctl_tcp_keepalive_probes,
911                 .maxlen         = sizeof(u8),
912                 .mode           = 0644,
913                 .proc_handler   = proc_dou8vec_minmax,
914         },
915         {
916                 .procname       = "tcp_keepalive_intvl",
917                 .data           = &init_net.ipv4.sysctl_tcp_keepalive_intvl,
918                 .maxlen         = sizeof(int),
919                 .mode           = 0644,
920                 .proc_handler   = proc_dointvec_jiffies,
921         },
922         {
923                 .procname       = "tcp_syn_retries",
924                 .data           = &init_net.ipv4.sysctl_tcp_syn_retries,
925                 .maxlen         = sizeof(u8),
926                 .mode           = 0644,
927                 .proc_handler   = proc_dou8vec_minmax,
928                 .extra1         = &tcp_syn_retries_min,
929                 .extra2         = &tcp_syn_retries_max
930         },
931         {
932                 .procname       = "tcp_synack_retries",
933                 .data           = &init_net.ipv4.sysctl_tcp_synack_retries,
934                 .maxlen         = sizeof(u8),
935                 .mode           = 0644,
936                 .proc_handler   = proc_dou8vec_minmax,
937         },
938 #ifdef CONFIG_SYN_COOKIES
939         {
940                 .procname       = "tcp_syncookies",
941                 .data           = &init_net.ipv4.sysctl_tcp_syncookies,
942                 .maxlen         = sizeof(u8),
943                 .mode           = 0644,
944                 .proc_handler   = proc_dou8vec_minmax,
945         },
946 #endif
947         {
948                 .procname       = "tcp_reordering",
949                 .data           = &init_net.ipv4.sysctl_tcp_reordering,
950                 .maxlen         = sizeof(int),
951                 .mode           = 0644,
952                 .proc_handler   = proc_dointvec
953         },
954         {
955                 .procname       = "tcp_retries1",
956                 .data           = &init_net.ipv4.sysctl_tcp_retries1,
957                 .maxlen         = sizeof(u8),
958                 .mode           = 0644,
959                 .proc_handler   = proc_dou8vec_minmax,
960                 .extra2         = &tcp_retr1_max
961         },
962         {
963                 .procname       = "tcp_retries2",
964                 .data           = &init_net.ipv4.sysctl_tcp_retries2,
965                 .maxlen         = sizeof(u8),
966                 .mode           = 0644,
967                 .proc_handler   = proc_dou8vec_minmax,
968         },
969         {
970                 .procname       = "tcp_orphan_retries",
971                 .data           = &init_net.ipv4.sysctl_tcp_orphan_retries,
972                 .maxlen         = sizeof(u8),
973                 .mode           = 0644,
974                 .proc_handler   = proc_dou8vec_minmax,
975         },
976         {
977                 .procname       = "tcp_fin_timeout",
978                 .data           = &init_net.ipv4.sysctl_tcp_fin_timeout,
979                 .maxlen         = sizeof(int),
980                 .mode           = 0644,
981                 .proc_handler   = proc_dointvec_jiffies,
982         },
983         {
984                 .procname       = "tcp_notsent_lowat",
985                 .data           = &init_net.ipv4.sysctl_tcp_notsent_lowat,
986                 .maxlen         = sizeof(unsigned int),
987                 .mode           = 0644,
988                 .proc_handler   = proc_douintvec,
989         },
990         {
991                 .procname       = "tcp_tw_reuse",
992                 .data           = &init_net.ipv4.sysctl_tcp_tw_reuse,
993                 .maxlen         = sizeof(u8),
994                 .mode           = 0644,
995                 .proc_handler   = proc_dou8vec_minmax,
996                 .extra1         = SYSCTL_ZERO,
997                 .extra2         = &two,
998         },
999         {
1000                 .procname       = "tcp_max_tw_buckets",
1001                 .data           = &init_net.ipv4.tcp_death_row.sysctl_max_tw_buckets,
1002                 .maxlen         = sizeof(int),
1003                 .mode           = 0644,
1004                 .proc_handler   = proc_dointvec
1005         },
1006         {
1007                 .procname       = "tcp_max_syn_backlog",
1008                 .data           = &init_net.ipv4.sysctl_max_syn_backlog,
1009                 .maxlen         = sizeof(int),
1010                 .mode           = 0644,
1011                 .proc_handler   = proc_dointvec
1012         },
1013         {
1014                 .procname       = "tcp_fastopen",
1015                 .data           = &init_net.ipv4.sysctl_tcp_fastopen,
1016                 .maxlen         = sizeof(int),
1017                 .mode           = 0644,
1018                 .proc_handler   = proc_dointvec,
1019         },
1020         {
1021                 .procname       = "tcp_fastopen_key",
1022                 .mode           = 0600,
1023                 .data           = &init_net.ipv4.sysctl_tcp_fastopen,
1024                 /* maxlen to print the list of keys in hex (*2), with dashes
1025                  * separating doublewords and a comma in between keys.
1026                  */
1027                 .maxlen         = ((TCP_FASTOPEN_KEY_LENGTH *
1028                                    2 * TCP_FASTOPEN_KEY_MAX) +
1029                                    (TCP_FASTOPEN_KEY_MAX * 5)),
1030                 .proc_handler   = proc_tcp_fastopen_key,
1031         },
1032         {
1033                 .procname       = "tcp_fastopen_blackhole_timeout_sec",
1034                 .data           = &init_net.ipv4.sysctl_tcp_fastopen_blackhole_timeout,
1035                 .maxlen         = sizeof(int),
1036                 .mode           = 0644,
1037                 .proc_handler   = proc_tfo_blackhole_detect_timeout,
1038                 .extra1         = SYSCTL_ZERO,
1039         },
1040 #ifdef CONFIG_IP_ROUTE_MULTIPATH
1041         {
1042                 .procname       = "fib_multipath_use_neigh",
1043                 .data           = &init_net.ipv4.sysctl_fib_multipath_use_neigh,
1044                 .maxlen         = sizeof(u8),
1045                 .mode           = 0644,
1046                 .proc_handler   = proc_dou8vec_minmax,
1047                 .extra1         = SYSCTL_ZERO,
1048                 .extra2         = SYSCTL_ONE,
1049         },
1050         {
1051                 .procname       = "fib_multipath_hash_policy",
1052                 .data           = &init_net.ipv4.sysctl_fib_multipath_hash_policy,
1053                 .maxlen         = sizeof(u8),
1054                 .mode           = 0644,
1055                 .proc_handler   = proc_fib_multipath_hash_policy,
1056                 .extra1         = SYSCTL_ZERO,
1057                 .extra2         = &three,
1058         },
1059         {
1060                 .procname       = "fib_multipath_hash_fields",
1061                 .data           = &init_net.ipv4.sysctl_fib_multipath_hash_fields,
1062                 .maxlen         = sizeof(u32),
1063                 .mode           = 0644,
1064                 .proc_handler   = proc_douintvec_minmax,
1065                 .extra1         = SYSCTL_ONE,
1066                 .extra2         = &fib_multipath_hash_fields_all_mask,
1067         },
1068 #endif
1069         {
1070                 .procname       = "ip_unprivileged_port_start",
1071                 .maxlen         = sizeof(int),
1072                 .data           = &init_net.ipv4.sysctl_ip_prot_sock,
1073                 .mode           = 0644,
1074                 .proc_handler   = ipv4_privileged_ports,
1075         },
1076 #ifdef CONFIG_NET_L3_MASTER_DEV
1077         {
1078                 .procname       = "udp_l3mdev_accept",
1079                 .data           = &init_net.ipv4.sysctl_udp_l3mdev_accept,
1080                 .maxlen         = sizeof(u8),
1081                 .mode           = 0644,
1082                 .proc_handler   = proc_dou8vec_minmax,
1083                 .extra1         = SYSCTL_ZERO,
1084                 .extra2         = SYSCTL_ONE,
1085         },
1086 #endif
1087         {
1088                 .procname       = "tcp_sack",
1089                 .data           = &init_net.ipv4.sysctl_tcp_sack,
1090                 .maxlen         = sizeof(u8),
1091                 .mode           = 0644,
1092                 .proc_handler   = proc_dou8vec_minmax,
1093         },
1094         {
1095                 .procname       = "tcp_window_scaling",
1096                 .data           = &init_net.ipv4.sysctl_tcp_window_scaling,
1097                 .maxlen         = sizeof(u8),
1098                 .mode           = 0644,
1099                 .proc_handler   = proc_dou8vec_minmax,
1100         },
1101         {
1102                 .procname       = "tcp_timestamps",
1103                 .data           = &init_net.ipv4.sysctl_tcp_timestamps,
1104                 .maxlen         = sizeof(u8),
1105                 .mode           = 0644,
1106                 .proc_handler   = proc_dou8vec_minmax,
1107         },
1108         {
1109                 .procname       = "tcp_early_retrans",
1110                 .data           = &init_net.ipv4.sysctl_tcp_early_retrans,
1111                 .maxlen         = sizeof(u8),
1112                 .mode           = 0644,
1113                 .proc_handler   = proc_dou8vec_minmax,
1114                 .extra1         = SYSCTL_ZERO,
1115                 .extra2         = &four,
1116         },
1117         {
1118                 .procname       = "tcp_recovery",
1119                 .data           = &init_net.ipv4.sysctl_tcp_recovery,
1120                 .maxlen         = sizeof(u8),
1121                 .mode           = 0644,
1122                 .proc_handler   = proc_dou8vec_minmax,
1123         },
1124         {
1125                 .procname       = "tcp_thin_linear_timeouts",
1126                 .data           = &init_net.ipv4.sysctl_tcp_thin_linear_timeouts,
1127                 .maxlen         = sizeof(u8),
1128                 .mode           = 0644,
1129                 .proc_handler   = proc_dou8vec_minmax,
1130         },
1131         {
1132                 .procname       = "tcp_slow_start_after_idle",
1133                 .data           = &init_net.ipv4.sysctl_tcp_slow_start_after_idle,
1134                 .maxlen         = sizeof(u8),
1135                 .mode           = 0644,
1136                 .proc_handler   = proc_dou8vec_minmax,
1137         },
1138         {
1139                 .procname       = "tcp_retrans_collapse",
1140                 .data           = &init_net.ipv4.sysctl_tcp_retrans_collapse,
1141                 .maxlen         = sizeof(u8),
1142                 .mode           = 0644,
1143                 .proc_handler   = proc_dou8vec_minmax,
1144         },
1145         {
1146                 .procname       = "tcp_stdurg",
1147                 .data           = &init_net.ipv4.sysctl_tcp_stdurg,
1148                 .maxlen         = sizeof(u8),
1149                 .mode           = 0644,
1150                 .proc_handler   = proc_dou8vec_minmax,
1151         },
1152         {
1153                 .procname       = "tcp_rfc1337",
1154                 .data           = &init_net.ipv4.sysctl_tcp_rfc1337,
1155                 .maxlen         = sizeof(u8),
1156                 .mode           = 0644,
1157                 .proc_handler   = proc_dou8vec_minmax,
1158         },
1159         {
1160                 .procname       = "tcp_abort_on_overflow",
1161                 .data           = &init_net.ipv4.sysctl_tcp_abort_on_overflow,
1162                 .maxlen         = sizeof(u8),
1163                 .mode           = 0644,
1164                 .proc_handler   = proc_dou8vec_minmax,
1165         },
1166         {
1167                 .procname       = "tcp_fack",
1168                 .data           = &init_net.ipv4.sysctl_tcp_fack,
1169                 .maxlen         = sizeof(u8),
1170                 .mode           = 0644,
1171                 .proc_handler   = proc_dou8vec_minmax,
1172         },
1173         {
1174                 .procname       = "tcp_max_reordering",
1175                 .data           = &init_net.ipv4.sysctl_tcp_max_reordering,
1176                 .maxlen         = sizeof(int),
1177                 .mode           = 0644,
1178                 .proc_handler   = proc_dointvec
1179         },
1180         {
1181                 .procname       = "tcp_dsack",
1182                 .data           = &init_net.ipv4.sysctl_tcp_dsack,
1183                 .maxlen         = sizeof(u8),
1184                 .mode           = 0644,
1185                 .proc_handler   = proc_dou8vec_minmax,
1186         },
1187         {
1188                 .procname       = "tcp_app_win",
1189                 .data           = &init_net.ipv4.sysctl_tcp_app_win,
1190                 .maxlen         = sizeof(u8),
1191                 .mode           = 0644,
1192                 .proc_handler   = proc_dou8vec_minmax,
1193         },
1194         {
1195                 .procname       = "tcp_adv_win_scale",
1196                 .data           = &init_net.ipv4.sysctl_tcp_adv_win_scale,
1197                 .maxlen         = sizeof(int),
1198                 .mode           = 0644,
1199                 .proc_handler   = proc_dointvec_minmax,
1200                 .extra1         = &tcp_adv_win_scale_min,
1201                 .extra2         = &tcp_adv_win_scale_max,
1202         },
1203         {
1204                 .procname       = "tcp_frto",
1205                 .data           = &init_net.ipv4.sysctl_tcp_frto,
1206                 .maxlen         = sizeof(u8),
1207                 .mode           = 0644,
1208                 .proc_handler   = proc_dou8vec_minmax,
1209         },
1210         {
1211                 .procname       = "tcp_no_metrics_save",
1212                 .data           = &init_net.ipv4.sysctl_tcp_nometrics_save,
1213                 .maxlen         = sizeof(u8),
1214                 .mode           = 0644,
1215                 .proc_handler   = proc_dou8vec_minmax,
1216         },
1217         {
1218                 .procname       = "tcp_no_ssthresh_metrics_save",
1219                 .data           = &init_net.ipv4.sysctl_tcp_no_ssthresh_metrics_save,
1220                 .maxlen         = sizeof(u8),
1221                 .mode           = 0644,
1222                 .proc_handler   = proc_dou8vec_minmax,
1223                 .extra1         = SYSCTL_ZERO,
1224                 .extra2         = SYSCTL_ONE,
1225         },
1226         {
1227                 .procname       = "tcp_moderate_rcvbuf",
1228                 .data           = &init_net.ipv4.sysctl_tcp_moderate_rcvbuf,
1229                 .maxlen         = sizeof(u8),
1230                 .mode           = 0644,
1231                 .proc_handler   = proc_dou8vec_minmax,
1232         },
1233         {
1234                 .procname       = "tcp_tso_win_divisor",
1235                 .data           = &init_net.ipv4.sysctl_tcp_tso_win_divisor,
1236                 .maxlen         = sizeof(u8),
1237                 .mode           = 0644,
1238                 .proc_handler   = proc_dou8vec_minmax,
1239         },
1240         {
1241                 .procname       = "tcp_workaround_signed_windows",
1242                 .data           = &init_net.ipv4.sysctl_tcp_workaround_signed_windows,
1243                 .maxlen         = sizeof(u8),
1244                 .mode           = 0644,
1245                 .proc_handler   = proc_dou8vec_minmax,
1246         },
1247         {
1248                 .procname       = "tcp_limit_output_bytes",
1249                 .data           = &init_net.ipv4.sysctl_tcp_limit_output_bytes,
1250                 .maxlen         = sizeof(int),
1251                 .mode           = 0644,
1252                 .proc_handler   = proc_dointvec
1253         },
1254         {
1255                 .procname       = "tcp_challenge_ack_limit",
1256                 .data           = &init_net.ipv4.sysctl_tcp_challenge_ack_limit,
1257                 .maxlen         = sizeof(int),
1258                 .mode           = 0644,
1259                 .proc_handler   = proc_dointvec
1260         },
1261         {
1262                 .procname       = "tcp_min_tso_segs",
1263                 .data           = &init_net.ipv4.sysctl_tcp_min_tso_segs,
1264                 .maxlen         = sizeof(u8),
1265                 .mode           = 0644,
1266                 .proc_handler   = proc_dou8vec_minmax,
1267                 .extra1         = SYSCTL_ONE,
1268         },
1269         {
1270                 .procname       = "tcp_min_rtt_wlen",
1271                 .data           = &init_net.ipv4.sysctl_tcp_min_rtt_wlen,
1272                 .maxlen         = sizeof(int),
1273                 .mode           = 0644,
1274                 .proc_handler   = proc_dointvec_minmax,
1275                 .extra1         = SYSCTL_ZERO,
1276                 .extra2         = &one_day_secs
1277         },
1278         {
1279                 .procname       = "tcp_autocorking",
1280                 .data           = &init_net.ipv4.sysctl_tcp_autocorking,
1281                 .maxlen         = sizeof(u8),
1282                 .mode           = 0644,
1283                 .proc_handler   = proc_dou8vec_minmax,
1284                 .extra1         = SYSCTL_ZERO,
1285                 .extra2         = SYSCTL_ONE,
1286         },
1287         {
1288                 .procname       = "tcp_invalid_ratelimit",
1289                 .data           = &init_net.ipv4.sysctl_tcp_invalid_ratelimit,
1290                 .maxlen         = sizeof(int),
1291                 .mode           = 0644,
1292                 .proc_handler   = proc_dointvec_ms_jiffies,
1293         },
1294         {
1295                 .procname       = "tcp_pacing_ss_ratio",
1296                 .data           = &init_net.ipv4.sysctl_tcp_pacing_ss_ratio,
1297                 .maxlen         = sizeof(int),
1298                 .mode           = 0644,
1299                 .proc_handler   = proc_dointvec_minmax,
1300                 .extra1         = SYSCTL_ZERO,
1301                 .extra2         = &thousand,
1302         },
1303         {
1304                 .procname       = "tcp_pacing_ca_ratio",
1305                 .data           = &init_net.ipv4.sysctl_tcp_pacing_ca_ratio,
1306                 .maxlen         = sizeof(int),
1307                 .mode           = 0644,
1308                 .proc_handler   = proc_dointvec_minmax,
1309                 .extra1         = SYSCTL_ZERO,
1310                 .extra2         = &thousand,
1311         },
1312         {
1313                 .procname       = "tcp_wmem",
1314                 .data           = &init_net.ipv4.sysctl_tcp_wmem,
1315                 .maxlen         = sizeof(init_net.ipv4.sysctl_tcp_wmem),
1316                 .mode           = 0644,
1317                 .proc_handler   = proc_dointvec_minmax,
1318                 .extra1         = SYSCTL_ONE,
1319         },
1320         {
1321                 .procname       = "tcp_rmem",
1322                 .data           = &init_net.ipv4.sysctl_tcp_rmem,
1323                 .maxlen         = sizeof(init_net.ipv4.sysctl_tcp_rmem),
1324                 .mode           = 0644,
1325                 .proc_handler   = proc_dointvec_minmax,
1326                 .extra1         = SYSCTL_ONE,
1327         },
1328         {
1329                 .procname       = "tcp_comp_sack_delay_ns",
1330                 .data           = &init_net.ipv4.sysctl_tcp_comp_sack_delay_ns,
1331                 .maxlen         = sizeof(unsigned long),
1332                 .mode           = 0644,
1333                 .proc_handler   = proc_doulongvec_minmax,
1334         },
1335         {
1336                 .procname       = "tcp_comp_sack_slack_ns",
1337                 .data           = &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
1338                 .maxlen         = sizeof(unsigned long),
1339                 .mode           = 0644,
1340                 .proc_handler   = proc_doulongvec_minmax,
1341         },
1342         {
1343                 .procname       = "tcp_comp_sack_nr",
1344                 .data           = &init_net.ipv4.sysctl_tcp_comp_sack_nr,
1345                 .maxlen         = sizeof(u8),
1346                 .mode           = 0644,
1347                 .proc_handler   = proc_dou8vec_minmax,
1348                 .extra1         = SYSCTL_ZERO,
1349         },
1350         {
1351                 .procname       = "tcp_reflect_tos",
1352                 .data           = &init_net.ipv4.sysctl_tcp_reflect_tos,
1353                 .maxlen         = sizeof(u8),
1354                 .mode           = 0644,
1355                 .proc_handler   = proc_dou8vec_minmax,
1356                 .extra1         = SYSCTL_ZERO,
1357                 .extra2         = SYSCTL_ONE,
1358         },
1359         {
1360                 .procname       = "udp_rmem_min",
1361                 .data           = &init_net.ipv4.sysctl_udp_rmem_min,
1362                 .maxlen         = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1363                 .mode           = 0644,
1364                 .proc_handler   = proc_dointvec_minmax,
1365                 .extra1         = SYSCTL_ONE
1366         },
1367         {
1368                 .procname       = "udp_wmem_min",
1369                 .data           = &init_net.ipv4.sysctl_udp_wmem_min,
1370                 .maxlen         = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1371                 .mode           = 0644,
1372                 .proc_handler   = proc_dointvec_minmax,
1373                 .extra1         = SYSCTL_ONE
1374         },
1375         {
1376                 .procname       = "fib_notify_on_flag_change",
1377                 .data           = &init_net.ipv4.sysctl_fib_notify_on_flag_change,
1378                 .maxlen         = sizeof(u8),
1379                 .mode           = 0644,
1380                 .proc_handler   = proc_dou8vec_minmax,
1381                 .extra1         = SYSCTL_ZERO,
1382                 .extra2         = &two,
1383         },
1384         { }
1385 };
1386
1387 static __net_init int ipv4_sysctl_init_net(struct net *net)
1388 {
1389         struct ctl_table *table;
1390
1391         table = ipv4_net_table;
1392         if (!net_eq(net, &init_net)) {
1393                 int i;
1394
1395                 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
1396                 if (!table)
1397                         goto err_alloc;
1398
1399                 for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) {
1400                         if (table[i].data) {
1401                                 /* Update the variables to point into
1402                                  * the current struct net
1403                                  */
1404                                 table[i].data += (void *)net - (void *)&init_net;
1405                         } else {
1406                                 /* Entries without data pointer are global;
1407                                  * Make them read-only in non-init_net ns
1408                                  */
1409                                 table[i].mode &= ~0222;
1410                         }
1411                 }
1412         }
1413
1414         net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
1415         if (!net->ipv4.ipv4_hdr)
1416                 goto err_reg;
1417
1418         net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
1419         if (!net->ipv4.sysctl_local_reserved_ports)
1420                 goto err_ports;
1421
1422         return 0;
1423
1424 err_ports:
1425         unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1426 err_reg:
1427         if (!net_eq(net, &init_net))
1428                 kfree(table);
1429 err_alloc:
1430         return -ENOMEM;
1431 }
1432
1433 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1434 {
1435         struct ctl_table *table;
1436
1437         kfree(net->ipv4.sysctl_local_reserved_ports);
1438         table = net->ipv4.ipv4_hdr->ctl_table_arg;
1439         unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1440         kfree(table);
1441 }
1442
1443 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1444         .init = ipv4_sysctl_init_net,
1445         .exit = ipv4_sysctl_exit_net,
1446 };
1447
1448 static __init int sysctl_ipv4_init(void)
1449 {
1450         struct ctl_table_header *hdr;
1451
1452         hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1453         if (!hdr)
1454                 return -ENOMEM;
1455
1456         if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1457                 unregister_net_sysctl_table(hdr);
1458                 return -ENOMEM;
1459         }
1460
1461         return 0;
1462 }
1463
1464 __initcall(sysctl_ipv4_init);