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