]> git.openfabrics.org - ~shefty/rdma-dev.git/blob - net/ipv4/sysctl_net_ipv4.c
tcp: restrict net.ipv4.tcp_adv_win_scale (#20312)
[~shefty/rdma-dev.git] / net / ipv4 / sysctl_net_ipv4.c
1 /*
2  * sysctl_net_ipv4.c: sysctl interface to net IPV4 subsystem.
3  *
4  * Begun April 1, 1996, Mike Shaver.
5  * Added /proc/sys/net/ipv4 directory entry (empty =) ). [MS]
6  */
7
8 #include <linux/mm.h>
9 #include <linux/module.h>
10 #include <linux/sysctl.h>
11 #include <linux/igmp.h>
12 #include <linux/inetdevice.h>
13 #include <linux/seqlock.h>
14 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <net/snmp.h>
17 #include <net/icmp.h>
18 #include <net/ip.h>
19 #include <net/route.h>
20 #include <net/tcp.h>
21 #include <net/udp.h>
22 #include <net/cipso_ipv4.h>
23 #include <net/inet_frag.h>
24
25 static int zero;
26 static int tcp_retr1_max = 255;
27 static int ip_local_port_range_min[] = { 1, 1 };
28 static int ip_local_port_range_max[] = { 65535, 65535 };
29 static int tcp_adv_win_scale_min = -31;
30 static int tcp_adv_win_scale_max = 31;
31
32 /* Update system visible IP port range */
33 static void set_local_port_range(int range[2])
34 {
35         write_seqlock(&sysctl_local_ports.lock);
36         sysctl_local_ports.range[0] = range[0];
37         sysctl_local_ports.range[1] = range[1];
38         write_sequnlock(&sysctl_local_ports.lock);
39 }
40
41 /* Validate changes from /proc interface. */
42 static int ipv4_local_port_range(ctl_table *table, int write,
43                                  void __user *buffer,
44                                  size_t *lenp, loff_t *ppos)
45 {
46         int ret;
47         int range[2];
48         ctl_table tmp = {
49                 .data = &range,
50                 .maxlen = sizeof(range),
51                 .mode = table->mode,
52                 .extra1 = &ip_local_port_range_min,
53                 .extra2 = &ip_local_port_range_max,
54         };
55
56         inet_get_local_port_range(range, range + 1);
57         ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
58
59         if (write && ret == 0) {
60                 if (range[1] < range[0])
61                         ret = -EINVAL;
62                 else
63                         set_local_port_range(range);
64         }
65
66         return ret;
67 }
68
69 static int proc_tcp_congestion_control(ctl_table *ctl, int write,
70                                        void __user *buffer, size_t *lenp, loff_t *ppos)
71 {
72         char val[TCP_CA_NAME_MAX];
73         ctl_table tbl = {
74                 .data = val,
75                 .maxlen = TCP_CA_NAME_MAX,
76         };
77         int ret;
78
79         tcp_get_default_congestion_control(val);
80
81         ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
82         if (write && ret == 0)
83                 ret = tcp_set_default_congestion_control(val);
84         return ret;
85 }
86
87 static int proc_tcp_available_congestion_control(ctl_table *ctl,
88                                                  int write,
89                                                  void __user *buffer, size_t *lenp,
90                                                  loff_t *ppos)
91 {
92         ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
93         int ret;
94
95         tbl.data = kmalloc(tbl.maxlen, GFP_USER);
96         if (!tbl.data)
97                 return -ENOMEM;
98         tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
99         ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
100         kfree(tbl.data);
101         return ret;
102 }
103
104 static int proc_allowed_congestion_control(ctl_table *ctl,
105                                            int write,
106                                            void __user *buffer, size_t *lenp,
107                                            loff_t *ppos)
108 {
109         ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
110         int ret;
111
112         tbl.data = kmalloc(tbl.maxlen, GFP_USER);
113         if (!tbl.data)
114                 return -ENOMEM;
115
116         tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
117         ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
118         if (write && ret == 0)
119                 ret = tcp_set_allowed_congestion_control(tbl.data);
120         kfree(tbl.data);
121         return ret;
122 }
123
124 static struct ctl_table ipv4_table[] = {
125         {
126                 .procname       = "tcp_timestamps",
127                 .data           = &sysctl_tcp_timestamps,
128                 .maxlen         = sizeof(int),
129                 .mode           = 0644,
130                 .proc_handler   = proc_dointvec
131         },
132         {
133                 .procname       = "tcp_window_scaling",
134                 .data           = &sysctl_tcp_window_scaling,
135                 .maxlen         = sizeof(int),
136                 .mode           = 0644,
137                 .proc_handler   = proc_dointvec
138         },
139         {
140                 .procname       = "tcp_sack",
141                 .data           = &sysctl_tcp_sack,
142                 .maxlen         = sizeof(int),
143                 .mode           = 0644,
144                 .proc_handler   = proc_dointvec
145         },
146         {
147                 .procname       = "tcp_retrans_collapse",
148                 .data           = &sysctl_tcp_retrans_collapse,
149                 .maxlen         = sizeof(int),
150                 .mode           = 0644,
151                 .proc_handler   = proc_dointvec
152         },
153         {
154                 .procname       = "ip_default_ttl",
155                 .data           = &sysctl_ip_default_ttl,
156                 .maxlen         = sizeof(int),
157                 .mode           = 0644,
158                 .proc_handler   = ipv4_doint_and_flush,
159                 .extra2         = &init_net,
160         },
161         {
162                 .procname       = "ip_no_pmtu_disc",
163                 .data           = &ipv4_config.no_pmtu_disc,
164                 .maxlen         = sizeof(int),
165                 .mode           = 0644,
166                 .proc_handler   = proc_dointvec
167         },
168         {
169                 .procname       = "ip_nonlocal_bind",
170                 .data           = &sysctl_ip_nonlocal_bind,
171                 .maxlen         = sizeof(int),
172                 .mode           = 0644,
173                 .proc_handler   = proc_dointvec
174         },
175         {
176                 .procname       = "tcp_syn_retries",
177                 .data           = &sysctl_tcp_syn_retries,
178                 .maxlen         = sizeof(int),
179                 .mode           = 0644,
180                 .proc_handler   = proc_dointvec
181         },
182         {
183                 .procname       = "tcp_synack_retries",
184                 .data           = &sysctl_tcp_synack_retries,
185                 .maxlen         = sizeof(int),
186                 .mode           = 0644,
187                 .proc_handler   = proc_dointvec
188         },
189         {
190                 .procname       = "tcp_max_orphans",
191                 .data           = &sysctl_tcp_max_orphans,
192                 .maxlen         = sizeof(int),
193                 .mode           = 0644,
194                 .proc_handler   = proc_dointvec
195         },
196         {
197                 .procname       = "tcp_max_tw_buckets",
198                 .data           = &tcp_death_row.sysctl_max_tw_buckets,
199                 .maxlen         = sizeof(int),
200                 .mode           = 0644,
201                 .proc_handler   = proc_dointvec
202         },
203         {
204                 .procname       = "ip_dynaddr",
205                 .data           = &sysctl_ip_dynaddr,
206                 .maxlen         = sizeof(int),
207                 .mode           = 0644,
208                 .proc_handler   = proc_dointvec
209         },
210         {
211                 .procname       = "tcp_keepalive_time",
212                 .data           = &sysctl_tcp_keepalive_time,
213                 .maxlen         = sizeof(int),
214                 .mode           = 0644,
215                 .proc_handler   = proc_dointvec_jiffies,
216         },
217         {
218                 .procname       = "tcp_keepalive_probes",
219                 .data           = &sysctl_tcp_keepalive_probes,
220                 .maxlen         = sizeof(int),
221                 .mode           = 0644,
222                 .proc_handler   = proc_dointvec
223         },
224         {
225                 .procname       = "tcp_keepalive_intvl",
226                 .data           = &sysctl_tcp_keepalive_intvl,
227                 .maxlen         = sizeof(int),
228                 .mode           = 0644,
229                 .proc_handler   = proc_dointvec_jiffies,
230         },
231         {
232                 .procname       = "tcp_retries1",
233                 .data           = &sysctl_tcp_retries1,
234                 .maxlen         = sizeof(int),
235                 .mode           = 0644,
236                 .proc_handler   = proc_dointvec_minmax,
237                 .extra2         = &tcp_retr1_max
238         },
239         {
240                 .procname       = "tcp_retries2",
241                 .data           = &sysctl_tcp_retries2,
242                 .maxlen         = sizeof(int),
243                 .mode           = 0644,
244                 .proc_handler   = proc_dointvec
245         },
246         {
247                 .procname       = "tcp_fin_timeout",
248                 .data           = &sysctl_tcp_fin_timeout,
249                 .maxlen         = sizeof(int),
250                 .mode           = 0644,
251                 .proc_handler   = proc_dointvec_jiffies,
252         },
253 #ifdef CONFIG_SYN_COOKIES
254         {
255                 .procname       = "tcp_syncookies",
256                 .data           = &sysctl_tcp_syncookies,
257                 .maxlen         = sizeof(int),
258                 .mode           = 0644,
259                 .proc_handler   = proc_dointvec
260         },
261 #endif
262         {
263                 .procname       = "tcp_tw_recycle",
264                 .data           = &tcp_death_row.sysctl_tw_recycle,
265                 .maxlen         = sizeof(int),
266                 .mode           = 0644,
267                 .proc_handler   = proc_dointvec
268         },
269         {
270                 .procname       = "tcp_abort_on_overflow",
271                 .data           = &sysctl_tcp_abort_on_overflow,
272                 .maxlen         = sizeof(int),
273                 .mode           = 0644,
274                 .proc_handler   = proc_dointvec
275         },
276         {
277                 .procname       = "tcp_stdurg",
278                 .data           = &sysctl_tcp_stdurg,
279                 .maxlen         = sizeof(int),
280                 .mode           = 0644,
281                 .proc_handler   = proc_dointvec
282         },
283         {
284                 .procname       = "tcp_rfc1337",
285                 .data           = &sysctl_tcp_rfc1337,
286                 .maxlen         = sizeof(int),
287                 .mode           = 0644,
288                 .proc_handler   = proc_dointvec
289         },
290         {
291                 .procname       = "tcp_max_syn_backlog",
292                 .data           = &sysctl_max_syn_backlog,
293                 .maxlen         = sizeof(int),
294                 .mode           = 0644,
295                 .proc_handler   = proc_dointvec
296         },
297         {
298                 .procname       = "ip_local_port_range",
299                 .data           = &sysctl_local_ports.range,
300                 .maxlen         = sizeof(sysctl_local_ports.range),
301                 .mode           = 0644,
302                 .proc_handler   = ipv4_local_port_range,
303         },
304         {
305                 .procname       = "ip_local_reserved_ports",
306                 .data           = NULL, /* initialized in sysctl_ipv4_init */
307                 .maxlen         = 65536,
308                 .mode           = 0644,
309                 .proc_handler   = proc_do_large_bitmap,
310         },
311 #ifdef CONFIG_IP_MULTICAST
312         {
313                 .procname       = "igmp_max_memberships",
314                 .data           = &sysctl_igmp_max_memberships,
315                 .maxlen         = sizeof(int),
316                 .mode           = 0644,
317                 .proc_handler   = proc_dointvec
318         },
319
320 #endif
321         {
322                 .procname       = "igmp_max_msf",
323                 .data           = &sysctl_igmp_max_msf,
324                 .maxlen         = sizeof(int),
325                 .mode           = 0644,
326                 .proc_handler   = proc_dointvec
327         },
328         {
329                 .procname       = "inet_peer_threshold",
330                 .data           = &inet_peer_threshold,
331                 .maxlen         = sizeof(int),
332                 .mode           = 0644,
333                 .proc_handler   = proc_dointvec
334         },
335         {
336                 .procname       = "inet_peer_minttl",
337                 .data           = &inet_peer_minttl,
338                 .maxlen         = sizeof(int),
339                 .mode           = 0644,
340                 .proc_handler   = proc_dointvec_jiffies,
341         },
342         {
343                 .procname       = "inet_peer_maxttl",
344                 .data           = &inet_peer_maxttl,
345                 .maxlen         = sizeof(int),
346                 .mode           = 0644,
347                 .proc_handler   = proc_dointvec_jiffies,
348         },
349         {
350                 .procname       = "inet_peer_gc_mintime",
351                 .data           = &inet_peer_gc_mintime,
352                 .maxlen         = sizeof(int),
353                 .mode           = 0644,
354                 .proc_handler   = proc_dointvec_jiffies,
355         },
356         {
357                 .procname       = "inet_peer_gc_maxtime",
358                 .data           = &inet_peer_gc_maxtime,
359                 .maxlen         = sizeof(int),
360                 .mode           = 0644,
361                 .proc_handler   = proc_dointvec_jiffies,
362         },
363         {
364                 .procname       = "tcp_orphan_retries",
365                 .data           = &sysctl_tcp_orphan_retries,
366                 .maxlen         = sizeof(int),
367                 .mode           = 0644,
368                 .proc_handler   = proc_dointvec
369         },
370         {
371                 .procname       = "tcp_fack",
372                 .data           = &sysctl_tcp_fack,
373                 .maxlen         = sizeof(int),
374                 .mode           = 0644,
375                 .proc_handler   = proc_dointvec
376         },
377         {
378                 .procname       = "tcp_reordering",
379                 .data           = &sysctl_tcp_reordering,
380                 .maxlen         = sizeof(int),
381                 .mode           = 0644,
382                 .proc_handler   = proc_dointvec
383         },
384         {
385                 .procname       = "tcp_ecn",
386                 .data           = &sysctl_tcp_ecn,
387                 .maxlen         = sizeof(int),
388                 .mode           = 0644,
389                 .proc_handler   = proc_dointvec
390         },
391         {
392                 .procname       = "tcp_dsack",
393                 .data           = &sysctl_tcp_dsack,
394                 .maxlen         = sizeof(int),
395                 .mode           = 0644,
396                 .proc_handler   = proc_dointvec
397         },
398         {
399                 .procname       = "tcp_mem",
400                 .data           = &sysctl_tcp_mem,
401                 .maxlen         = sizeof(sysctl_tcp_mem),
402                 .mode           = 0644,
403                 .proc_handler   = proc_doulongvec_minmax
404         },
405         {
406                 .procname       = "tcp_wmem",
407                 .data           = &sysctl_tcp_wmem,
408                 .maxlen         = sizeof(sysctl_tcp_wmem),
409                 .mode           = 0644,
410                 .proc_handler   = proc_dointvec
411         },
412         {
413                 .procname       = "tcp_rmem",
414                 .data           = &sysctl_tcp_rmem,
415                 .maxlen         = sizeof(sysctl_tcp_rmem),
416                 .mode           = 0644,
417                 .proc_handler   = proc_dointvec
418         },
419         {
420                 .procname       = "tcp_app_win",
421                 .data           = &sysctl_tcp_app_win,
422                 .maxlen         = sizeof(int),
423                 .mode           = 0644,
424                 .proc_handler   = proc_dointvec
425         },
426         {
427                 .procname       = "tcp_adv_win_scale",
428                 .data           = &sysctl_tcp_adv_win_scale,
429                 .maxlen         = sizeof(int),
430                 .mode           = 0644,
431                 .proc_handler   = proc_dointvec_minmax,
432                 .extra1         = &tcp_adv_win_scale_min,
433                 .extra2         = &tcp_adv_win_scale_max,
434         },
435         {
436                 .procname       = "tcp_tw_reuse",
437                 .data           = &sysctl_tcp_tw_reuse,
438                 .maxlen         = sizeof(int),
439                 .mode           = 0644,
440                 .proc_handler   = proc_dointvec
441         },
442         {
443                 .procname       = "tcp_frto",
444                 .data           = &sysctl_tcp_frto,
445                 .maxlen         = sizeof(int),
446                 .mode           = 0644,
447                 .proc_handler   = proc_dointvec
448         },
449         {
450                 .procname       = "tcp_frto_response",
451                 .data           = &sysctl_tcp_frto_response,
452                 .maxlen         = sizeof(int),
453                 .mode           = 0644,
454                 .proc_handler   = proc_dointvec
455         },
456         {
457                 .procname       = "tcp_low_latency",
458                 .data           = &sysctl_tcp_low_latency,
459                 .maxlen         = sizeof(int),
460                 .mode           = 0644,
461                 .proc_handler   = proc_dointvec
462         },
463         {
464                 .procname       = "tcp_no_metrics_save",
465                 .data           = &sysctl_tcp_nometrics_save,
466                 .maxlen         = sizeof(int),
467                 .mode           = 0644,
468                 .proc_handler   = proc_dointvec,
469         },
470         {
471                 .procname       = "tcp_moderate_rcvbuf",
472                 .data           = &sysctl_tcp_moderate_rcvbuf,
473                 .maxlen         = sizeof(int),
474                 .mode           = 0644,
475                 .proc_handler   = proc_dointvec,
476         },
477         {
478                 .procname       = "tcp_tso_win_divisor",
479                 .data           = &sysctl_tcp_tso_win_divisor,
480                 .maxlen         = sizeof(int),
481                 .mode           = 0644,
482                 .proc_handler   = proc_dointvec,
483         },
484         {
485                 .procname       = "tcp_congestion_control",
486                 .mode           = 0644,
487                 .maxlen         = TCP_CA_NAME_MAX,
488                 .proc_handler   = proc_tcp_congestion_control,
489         },
490         {
491                 .procname       = "tcp_abc",
492                 .data           = &sysctl_tcp_abc,
493                 .maxlen         = sizeof(int),
494                 .mode           = 0644,
495                 .proc_handler   = proc_dointvec,
496         },
497         {
498                 .procname       = "tcp_mtu_probing",
499                 .data           = &sysctl_tcp_mtu_probing,
500                 .maxlen         = sizeof(int),
501                 .mode           = 0644,
502                 .proc_handler   = proc_dointvec,
503         },
504         {
505                 .procname       = "tcp_base_mss",
506                 .data           = &sysctl_tcp_base_mss,
507                 .maxlen         = sizeof(int),
508                 .mode           = 0644,
509                 .proc_handler   = proc_dointvec,
510         },
511         {
512                 .procname       = "tcp_workaround_signed_windows",
513                 .data           = &sysctl_tcp_workaround_signed_windows,
514                 .maxlen         = sizeof(int),
515                 .mode           = 0644,
516                 .proc_handler   = proc_dointvec
517         },
518 #ifdef CONFIG_NET_DMA
519         {
520                 .procname       = "tcp_dma_copybreak",
521                 .data           = &sysctl_tcp_dma_copybreak,
522                 .maxlen         = sizeof(int),
523                 .mode           = 0644,
524                 .proc_handler   = proc_dointvec
525         },
526 #endif
527         {
528                 .procname       = "tcp_slow_start_after_idle",
529                 .data           = &sysctl_tcp_slow_start_after_idle,
530                 .maxlen         = sizeof(int),
531                 .mode           = 0644,
532                 .proc_handler   = proc_dointvec
533         },
534 #ifdef CONFIG_NETLABEL
535         {
536                 .procname       = "cipso_cache_enable",
537                 .data           = &cipso_v4_cache_enabled,
538                 .maxlen         = sizeof(int),
539                 .mode           = 0644,
540                 .proc_handler   = proc_dointvec,
541         },
542         {
543                 .procname       = "cipso_cache_bucket_size",
544                 .data           = &cipso_v4_cache_bucketsize,
545                 .maxlen         = sizeof(int),
546                 .mode           = 0644,
547                 .proc_handler   = proc_dointvec,
548         },
549         {
550                 .procname       = "cipso_rbm_optfmt",
551                 .data           = &cipso_v4_rbm_optfmt,
552                 .maxlen         = sizeof(int),
553                 .mode           = 0644,
554                 .proc_handler   = proc_dointvec,
555         },
556         {
557                 .procname       = "cipso_rbm_strictvalid",
558                 .data           = &cipso_v4_rbm_strictvalid,
559                 .maxlen         = sizeof(int),
560                 .mode           = 0644,
561                 .proc_handler   = proc_dointvec,
562         },
563 #endif /* CONFIG_NETLABEL */
564         {
565                 .procname       = "tcp_available_congestion_control",
566                 .maxlen         = TCP_CA_BUF_MAX,
567                 .mode           = 0444,
568                 .proc_handler   = proc_tcp_available_congestion_control,
569         },
570         {
571                 .procname       = "tcp_allowed_congestion_control",
572                 .maxlen         = TCP_CA_BUF_MAX,
573                 .mode           = 0644,
574                 .proc_handler   = proc_allowed_congestion_control,
575         },
576         {
577                 .procname       = "tcp_max_ssthresh",
578                 .data           = &sysctl_tcp_max_ssthresh,
579                 .maxlen         = sizeof(int),
580                 .mode           = 0644,
581                 .proc_handler   = proc_dointvec,
582         },
583         {
584                 .procname       = "tcp_cookie_size",
585                 .data           = &sysctl_tcp_cookie_size,
586                 .maxlen         = sizeof(int),
587                 .mode           = 0644,
588                 .proc_handler   = proc_dointvec
589         },
590         {
591                 .procname       = "tcp_thin_linear_timeouts",
592                 .data           = &sysctl_tcp_thin_linear_timeouts,
593                 .maxlen         = sizeof(int),
594                 .mode           = 0644,
595                 .proc_handler   = proc_dointvec
596         },
597         {
598                 .procname       = "tcp_thin_dupack",
599                 .data           = &sysctl_tcp_thin_dupack,
600                 .maxlen         = sizeof(int),
601                 .mode           = 0644,
602                 .proc_handler   = proc_dointvec
603         },
604         {
605                 .procname       = "udp_mem",
606                 .data           = &sysctl_udp_mem,
607                 .maxlen         = sizeof(sysctl_udp_mem),
608                 .mode           = 0644,
609                 .proc_handler   = proc_doulongvec_minmax,
610         },
611         {
612                 .procname       = "udp_rmem_min",
613                 .data           = &sysctl_udp_rmem_min,
614                 .maxlen         = sizeof(sysctl_udp_rmem_min),
615                 .mode           = 0644,
616                 .proc_handler   = proc_dointvec_minmax,
617                 .extra1         = &zero
618         },
619         {
620                 .procname       = "udp_wmem_min",
621                 .data           = &sysctl_udp_wmem_min,
622                 .maxlen         = sizeof(sysctl_udp_wmem_min),
623                 .mode           = 0644,
624                 .proc_handler   = proc_dointvec_minmax,
625                 .extra1         = &zero
626         },
627         { }
628 };
629
630 static struct ctl_table ipv4_net_table[] = {
631         {
632                 .procname       = "icmp_echo_ignore_all",
633                 .data           = &init_net.ipv4.sysctl_icmp_echo_ignore_all,
634                 .maxlen         = sizeof(int),
635                 .mode           = 0644,
636                 .proc_handler   = proc_dointvec
637         },
638         {
639                 .procname       = "icmp_echo_ignore_broadcasts",
640                 .data           = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
641                 .maxlen         = sizeof(int),
642                 .mode           = 0644,
643                 .proc_handler   = proc_dointvec
644         },
645         {
646                 .procname       = "icmp_ignore_bogus_error_responses",
647                 .data           = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
648                 .maxlen         = sizeof(int),
649                 .mode           = 0644,
650                 .proc_handler   = proc_dointvec
651         },
652         {
653                 .procname       = "icmp_errors_use_inbound_ifaddr",
654                 .data           = &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
655                 .maxlen         = sizeof(int),
656                 .mode           = 0644,
657                 .proc_handler   = proc_dointvec
658         },
659         {
660                 .procname       = "icmp_ratelimit",
661                 .data           = &init_net.ipv4.sysctl_icmp_ratelimit,
662                 .maxlen         = sizeof(int),
663                 .mode           = 0644,
664                 .proc_handler   = proc_dointvec_ms_jiffies,
665         },
666         {
667                 .procname       = "icmp_ratemask",
668                 .data           = &init_net.ipv4.sysctl_icmp_ratemask,
669                 .maxlen         = sizeof(int),
670                 .mode           = 0644,
671                 .proc_handler   = proc_dointvec
672         },
673         {
674                 .procname       = "rt_cache_rebuild_count",
675                 .data           = &init_net.ipv4.sysctl_rt_cache_rebuild_count,
676                 .maxlen         = sizeof(int),
677                 .mode           = 0644,
678                 .proc_handler   = proc_dointvec
679         },
680         { }
681 };
682
683 struct ctl_path net_ipv4_ctl_path[] = {
684         { .procname = "net", },
685         { .procname = "ipv4", },
686         { },
687 };
688 EXPORT_SYMBOL_GPL(net_ipv4_ctl_path);
689
690 static __net_init int ipv4_sysctl_init_net(struct net *net)
691 {
692         struct ctl_table *table;
693
694         table = ipv4_net_table;
695         if (!net_eq(net, &init_net)) {
696                 table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
697                 if (table == NULL)
698                         goto err_alloc;
699
700                 table[0].data =
701                         &net->ipv4.sysctl_icmp_echo_ignore_all;
702                 table[1].data =
703                         &net->ipv4.sysctl_icmp_echo_ignore_broadcasts;
704                 table[2].data =
705                         &net->ipv4.sysctl_icmp_ignore_bogus_error_responses;
706                 table[3].data =
707                         &net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr;
708                 table[4].data =
709                         &net->ipv4.sysctl_icmp_ratelimit;
710                 table[5].data =
711                         &net->ipv4.sysctl_icmp_ratemask;
712                 table[6].data =
713                         &net->ipv4.sysctl_rt_cache_rebuild_count;
714         }
715
716         net->ipv4.sysctl_rt_cache_rebuild_count = 4;
717
718         net->ipv4.ipv4_hdr = register_net_sysctl_table(net,
719                         net_ipv4_ctl_path, table);
720         if (net->ipv4.ipv4_hdr == NULL)
721                 goto err_reg;
722
723         return 0;
724
725 err_reg:
726         if (!net_eq(net, &init_net))
727                 kfree(table);
728 err_alloc:
729         return -ENOMEM;
730 }
731
732 static __net_exit void ipv4_sysctl_exit_net(struct net *net)
733 {
734         struct ctl_table *table;
735
736         table = net->ipv4.ipv4_hdr->ctl_table_arg;
737         unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
738         kfree(table);
739 }
740
741 static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
742         .init = ipv4_sysctl_init_net,
743         .exit = ipv4_sysctl_exit_net,
744 };
745
746 static __init int sysctl_ipv4_init(void)
747 {
748         struct ctl_table_header *hdr;
749         struct ctl_table *i;
750
751         for (i = ipv4_table; i->procname; i++) {
752                 if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
753                         i->data = sysctl_local_reserved_ports;
754                         break;
755                 }
756         }
757         if (!i->procname)
758                 return -EINVAL;
759
760         hdr = register_sysctl_paths(net_ipv4_ctl_path, ipv4_table);
761         if (hdr == NULL)
762                 return -ENOMEM;
763
764         if (register_pernet_subsys(&ipv4_sysctl_ops)) {
765                 unregister_sysctl_table(hdr);
766                 return -ENOMEM;
767         }
768
769         return 0;
770 }
771
772 __initcall(sysctl_ipv4_init);