Linux Audio

Check our new training course

Loading...
v3.1
  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 <net/snmp.h>
 18#include <net/icmp.h>
 19#include <net/ip.h>
 20#include <net/route.h>
 21#include <net/tcp.h>
 22#include <net/udp.h>
 23#include <net/cipso_ipv4.h>
 24#include <net/inet_frag.h>
 25#include <net/ping.h>
 26
 27static int zero;
 
 
 
 
 28static int tcp_retr1_max = 255;
 29static int ip_local_port_range_min[] = { 1, 1 };
 30static int ip_local_port_range_max[] = { 65535, 65535 };
 31static int tcp_adv_win_scale_min = -31;
 32static int tcp_adv_win_scale_max = 31;
 33static int ip_ttl_min = 1;
 34static int ip_ttl_max = 255;
 
 
 35static int ip_ping_group_range_min[] = { 0, 0 };
 36static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
 37
 38/* Update system visible IP port range */
 39static void set_local_port_range(int range[2])
 40{
 41	write_seqlock(&sysctl_local_ports.lock);
 42	sysctl_local_ports.range[0] = range[0];
 43	sysctl_local_ports.range[1] = range[1];
 44	write_sequnlock(&sysctl_local_ports.lock);
 
 
 
 
 
 
 45}
 46
 47/* Validate changes from /proc interface. */
 48static int ipv4_local_port_range(ctl_table *table, int write,
 49				 void __user *buffer,
 50				 size_t *lenp, loff_t *ppos)
 51{
 
 
 52	int ret;
 53	int range[2];
 54	ctl_table tmp = {
 55		.data = &range,
 56		.maxlen = sizeof(range),
 57		.mode = table->mode,
 58		.extra1 = &ip_local_port_range_min,
 59		.extra2 = &ip_local_port_range_max,
 60	};
 61
 62	inet_get_local_port_range(range, range + 1);
 
 63	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
 64
 65	if (write && ret == 0) {
 66		if (range[1] < range[0])
 67			ret = -EINVAL;
 68		else
 69			set_local_port_range(range);
 70	}
 71
 72	return ret;
 73}
 74
 75
 76void inet_get_ping_group_range_table(struct ctl_table *table, gid_t *low, gid_t *high)
 77{
 78	gid_t *data = table->data;
 79	unsigned seq;
 
 
 80	do {
 81		seq = read_seqbegin(&sysctl_local_ports.lock);
 82
 83		*low = data[0];
 84		*high = data[1];
 85	} while (read_seqretry(&sysctl_local_ports.lock, seq));
 86}
 87
 88/* Update system visible IP port range */
 89static void set_ping_group_range(struct ctl_table *table, int range[2])
 90{
 91	gid_t *data = table->data;
 92	write_seqlock(&sysctl_local_ports.lock);
 93	data[0] = range[0];
 94	data[1] = range[1];
 95	write_sequnlock(&sysctl_local_ports.lock);
 
 
 96}
 97
 98/* Validate changes from /proc interface. */
 99static int ipv4_ping_group_range(ctl_table *table, int write,
100				 void __user *buffer,
101				 size_t *lenp, loff_t *ppos)
102{
 
103	int ret;
104	gid_t range[2];
105	ctl_table tmp = {
106		.data = &range,
107		.maxlen = sizeof(range),
 
108		.mode = table->mode,
109		.extra1 = &ip_ping_group_range_min,
110		.extra2 = &ip_ping_group_range_max,
111	};
112
113	inet_get_ping_group_range_table(table, range, range + 1);
 
 
114	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
115
116	if (write && ret == 0)
117		set_ping_group_range(table, range);
 
 
 
 
 
 
 
 
118
119	return ret;
120}
121
122static int proc_tcp_congestion_control(ctl_table *ctl, int write,
123				       void __user *buffer, size_t *lenp, loff_t *ppos)
124{
125	char val[TCP_CA_NAME_MAX];
126	ctl_table tbl = {
127		.data = val,
128		.maxlen = TCP_CA_NAME_MAX,
129	};
130	int ret;
131
132	tcp_get_default_congestion_control(val);
133
134	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
135	if (write && ret == 0)
136		ret = tcp_set_default_congestion_control(val);
137	return ret;
138}
139
140static int proc_tcp_available_congestion_control(ctl_table *ctl,
141						 int write,
142						 void __user *buffer, size_t *lenp,
143						 loff_t *ppos)
144{
145	ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
146	int ret;
147
148	tbl.data = kmalloc(tbl.maxlen, GFP_USER);
149	if (!tbl.data)
150		return -ENOMEM;
151	tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
152	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
153	kfree(tbl.data);
154	return ret;
155}
156
157static int proc_allowed_congestion_control(ctl_table *ctl,
158					   int write,
159					   void __user *buffer, size_t *lenp,
160					   loff_t *ppos)
161{
162	ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
163	int ret;
164
165	tbl.data = kmalloc(tbl.maxlen, GFP_USER);
166	if (!tbl.data)
167		return -ENOMEM;
168
169	tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
170	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
171	if (write && ret == 0)
172		ret = tcp_set_allowed_congestion_control(tbl.data);
173	kfree(tbl.data);
174	return ret;
175}
176
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177static struct ctl_table ipv4_table[] = {
178	{
179		.procname	= "tcp_timestamps",
180		.data		= &sysctl_tcp_timestamps,
181		.maxlen		= sizeof(int),
182		.mode		= 0644,
183		.proc_handler	= proc_dointvec
184	},
185	{
186		.procname	= "tcp_window_scaling",
187		.data		= &sysctl_tcp_window_scaling,
188		.maxlen		= sizeof(int),
189		.mode		= 0644,
190		.proc_handler	= proc_dointvec
191	},
192	{
193		.procname	= "tcp_sack",
194		.data		= &sysctl_tcp_sack,
195		.maxlen		= sizeof(int),
196		.mode		= 0644,
197		.proc_handler	= proc_dointvec
198	},
199	{
200		.procname	= "tcp_retrans_collapse",
201		.data		= &sysctl_tcp_retrans_collapse,
202		.maxlen		= sizeof(int),
203		.mode		= 0644,
204		.proc_handler	= proc_dointvec
205	},
206	{
207		.procname	= "ip_default_ttl",
208		.data		= &sysctl_ip_default_ttl,
209		.maxlen		= sizeof(int),
210		.mode		= 0644,
211		.proc_handler	= proc_dointvec_minmax,
212		.extra1		= &ip_ttl_min,
213		.extra2		= &ip_ttl_max,
214	},
215	{
216		.procname	= "ip_no_pmtu_disc",
217		.data		= &ipv4_config.no_pmtu_disc,
218		.maxlen		= sizeof(int),
219		.mode		= 0644,
220		.proc_handler	= proc_dointvec
221	},
222	{
223		.procname	= "ip_nonlocal_bind",
224		.data		= &sysctl_ip_nonlocal_bind,
225		.maxlen		= sizeof(int),
226		.mode		= 0644,
227		.proc_handler	= proc_dointvec
228	},
229	{
230		.procname	= "tcp_syn_retries",
231		.data		= &sysctl_tcp_syn_retries,
232		.maxlen		= sizeof(int),
233		.mode		= 0644,
234		.proc_handler	= proc_dointvec
235	},
236	{
237		.procname	= "tcp_synack_retries",
238		.data		= &sysctl_tcp_synack_retries,
239		.maxlen		= sizeof(int),
240		.mode		= 0644,
241		.proc_handler	= proc_dointvec
242	},
243	{
244		.procname	= "tcp_max_orphans",
245		.data		= &sysctl_tcp_max_orphans,
246		.maxlen		= sizeof(int),
247		.mode		= 0644,
248		.proc_handler	= proc_dointvec
249	},
250	{
251		.procname	= "tcp_max_tw_buckets",
252		.data		= &tcp_death_row.sysctl_max_tw_buckets,
253		.maxlen		= sizeof(int),
254		.mode		= 0644,
255		.proc_handler	= proc_dointvec
256	},
257	{
258		.procname	= "ip_dynaddr",
259		.data		= &sysctl_ip_dynaddr,
260		.maxlen		= sizeof(int),
261		.mode		= 0644,
262		.proc_handler	= proc_dointvec
263	},
264	{
265		.procname	= "tcp_keepalive_time",
266		.data		= &sysctl_tcp_keepalive_time,
267		.maxlen		= sizeof(int),
268		.mode		= 0644,
269		.proc_handler	= proc_dointvec_jiffies,
270	},
271	{
272		.procname	= "tcp_keepalive_probes",
273		.data		= &sysctl_tcp_keepalive_probes,
274		.maxlen		= sizeof(int),
275		.mode		= 0644,
276		.proc_handler	= proc_dointvec
277	},
278	{
279		.procname	= "tcp_keepalive_intvl",
280		.data		= &sysctl_tcp_keepalive_intvl,
281		.maxlen		= sizeof(int),
282		.mode		= 0644,
283		.proc_handler	= proc_dointvec_jiffies,
284	},
285	{
286		.procname	= "tcp_retries1",
287		.data		= &sysctl_tcp_retries1,
288		.maxlen		= sizeof(int),
289		.mode		= 0644,
290		.proc_handler	= proc_dointvec_minmax,
291		.extra2		= &tcp_retr1_max
292	},
293	{
294		.procname	= "tcp_retries2",
295		.data		= &sysctl_tcp_retries2,
296		.maxlen		= sizeof(int),
297		.mode		= 0644,
298		.proc_handler	= proc_dointvec
299	},
300	{
301		.procname	= "tcp_fin_timeout",
302		.data		= &sysctl_tcp_fin_timeout,
303		.maxlen		= sizeof(int),
304		.mode		= 0644,
305		.proc_handler	= proc_dointvec_jiffies,
306	},
307#ifdef CONFIG_SYN_COOKIES
308	{
309		.procname	= "tcp_syncookies",
310		.data		= &sysctl_tcp_syncookies,
311		.maxlen		= sizeof(int),
312		.mode		= 0644,
313		.proc_handler	= proc_dointvec
314	},
315#endif
316	{
317		.procname	= "tcp_tw_recycle",
318		.data		= &tcp_death_row.sysctl_tw_recycle,
319		.maxlen		= sizeof(int),
320		.mode		= 0644,
321		.proc_handler	= proc_dointvec
322	},
323	{
324		.procname	= "tcp_abort_on_overflow",
325		.data		= &sysctl_tcp_abort_on_overflow,
326		.maxlen		= sizeof(int),
327		.mode		= 0644,
328		.proc_handler	= proc_dointvec
329	},
330	{
331		.procname	= "tcp_stdurg",
332		.data		= &sysctl_tcp_stdurg,
333		.maxlen		= sizeof(int),
334		.mode		= 0644,
335		.proc_handler	= proc_dointvec
336	},
337	{
338		.procname	= "tcp_rfc1337",
339		.data		= &sysctl_tcp_rfc1337,
340		.maxlen		= sizeof(int),
341		.mode		= 0644,
342		.proc_handler	= proc_dointvec
343	},
344	{
345		.procname	= "tcp_max_syn_backlog",
346		.data		= &sysctl_max_syn_backlog,
347		.maxlen		= sizeof(int),
348		.mode		= 0644,
349		.proc_handler	= proc_dointvec
350	},
351	{
352		.procname	= "ip_local_port_range",
353		.data		= &sysctl_local_ports.range,
354		.maxlen		= sizeof(sysctl_local_ports.range),
355		.mode		= 0644,
356		.proc_handler	= ipv4_local_port_range,
357	},
358	{
359		.procname	= "ip_local_reserved_ports",
360		.data		= NULL, /* initialized in sysctl_ipv4_init */
361		.maxlen		= 65536,
362		.mode		= 0644,
363		.proc_handler	= proc_do_large_bitmap,
364	},
365	{
366		.procname	= "igmp_max_memberships",
367		.data		= &sysctl_igmp_max_memberships,
368		.maxlen		= sizeof(int),
369		.mode		= 0644,
370		.proc_handler	= proc_dointvec
371	},
372	{
373		.procname	= "igmp_max_msf",
374		.data		= &sysctl_igmp_max_msf,
375		.maxlen		= sizeof(int),
376		.mode		= 0644,
377		.proc_handler	= proc_dointvec
378	},
379	{
380		.procname	= "inet_peer_threshold",
381		.data		= &inet_peer_threshold,
382		.maxlen		= sizeof(int),
383		.mode		= 0644,
384		.proc_handler	= proc_dointvec
385	},
386	{
387		.procname	= "inet_peer_minttl",
388		.data		= &inet_peer_minttl,
389		.maxlen		= sizeof(int),
390		.mode		= 0644,
391		.proc_handler	= proc_dointvec_jiffies,
392	},
393	{
394		.procname	= "inet_peer_maxttl",
395		.data		= &inet_peer_maxttl,
396		.maxlen		= sizeof(int),
397		.mode		= 0644,
398		.proc_handler	= proc_dointvec_jiffies,
399	},
400	{
401		.procname	= "tcp_orphan_retries",
402		.data		= &sysctl_tcp_orphan_retries,
403		.maxlen		= sizeof(int),
404		.mode		= 0644,
405		.proc_handler	= proc_dointvec
406	},
407	{
408		.procname	= "tcp_fack",
409		.data		= &sysctl_tcp_fack,
410		.maxlen		= sizeof(int),
411		.mode		= 0644,
412		.proc_handler	= proc_dointvec
413	},
414	{
415		.procname	= "tcp_reordering",
416		.data		= &sysctl_tcp_reordering,
417		.maxlen		= sizeof(int),
418		.mode		= 0644,
419		.proc_handler	= proc_dointvec
420	},
421	{
422		.procname	= "tcp_ecn",
423		.data		= &sysctl_tcp_ecn,
424		.maxlen		= sizeof(int),
425		.mode		= 0644,
426		.proc_handler	= proc_dointvec
427	},
428	{
429		.procname	= "tcp_dsack",
430		.data		= &sysctl_tcp_dsack,
431		.maxlen		= sizeof(int),
432		.mode		= 0644,
433		.proc_handler	= proc_dointvec
434	},
435	{
436		.procname	= "tcp_mem",
437		.data		= &sysctl_tcp_mem,
438		.maxlen		= sizeof(sysctl_tcp_mem),
 
439		.mode		= 0644,
440		.proc_handler	= proc_doulongvec_minmax
441	},
442	{
443		.procname	= "tcp_wmem",
444		.data		= &sysctl_tcp_wmem,
445		.maxlen		= sizeof(sysctl_tcp_wmem),
446		.mode		= 0644,
447		.proc_handler	= proc_dointvec
 
448	},
449	{
450		.procname	= "tcp_rmem",
451		.data		= &sysctl_tcp_rmem,
452		.maxlen		= sizeof(sysctl_tcp_rmem),
453		.mode		= 0644,
454		.proc_handler	= proc_dointvec
 
455	},
456	{
457		.procname	= "tcp_app_win",
458		.data		= &sysctl_tcp_app_win,
459		.maxlen		= sizeof(int),
460		.mode		= 0644,
461		.proc_handler	= proc_dointvec
462	},
463	{
464		.procname	= "tcp_adv_win_scale",
465		.data		= &sysctl_tcp_adv_win_scale,
466		.maxlen		= sizeof(int),
467		.mode		= 0644,
468		.proc_handler	= proc_dointvec_minmax,
469		.extra1		= &tcp_adv_win_scale_min,
470		.extra2		= &tcp_adv_win_scale_max,
471	},
472	{
473		.procname	= "tcp_tw_reuse",
474		.data		= &sysctl_tcp_tw_reuse,
475		.maxlen		= sizeof(int),
476		.mode		= 0644,
477		.proc_handler	= proc_dointvec
478	},
479	{
480		.procname	= "tcp_frto",
481		.data		= &sysctl_tcp_frto,
482		.maxlen		= sizeof(int),
483		.mode		= 0644,
484		.proc_handler	= proc_dointvec
485	},
486	{
487		.procname	= "tcp_frto_response",
488		.data		= &sysctl_tcp_frto_response,
489		.maxlen		= sizeof(int),
490		.mode		= 0644,
491		.proc_handler	= proc_dointvec
492	},
493	{
494		.procname	= "tcp_low_latency",
495		.data		= &sysctl_tcp_low_latency,
496		.maxlen		= sizeof(int),
497		.mode		= 0644,
498		.proc_handler	= proc_dointvec
499	},
500	{
501		.procname	= "tcp_no_metrics_save",
502		.data		= &sysctl_tcp_nometrics_save,
503		.maxlen		= sizeof(int),
504		.mode		= 0644,
505		.proc_handler	= proc_dointvec,
506	},
507	{
508		.procname	= "tcp_moderate_rcvbuf",
509		.data		= &sysctl_tcp_moderate_rcvbuf,
510		.maxlen		= sizeof(int),
511		.mode		= 0644,
512		.proc_handler	= proc_dointvec,
513	},
514	{
515		.procname	= "tcp_tso_win_divisor",
516		.data		= &sysctl_tcp_tso_win_divisor,
517		.maxlen		= sizeof(int),
518		.mode		= 0644,
519		.proc_handler	= proc_dointvec,
520	},
521	{
522		.procname	= "tcp_congestion_control",
523		.mode		= 0644,
524		.maxlen		= TCP_CA_NAME_MAX,
525		.proc_handler	= proc_tcp_congestion_control,
526	},
527	{
528		.procname	= "tcp_abc",
529		.data		= &sysctl_tcp_abc,
530		.maxlen		= sizeof(int),
531		.mode		= 0644,
532		.proc_handler	= proc_dointvec,
533	},
534	{
535		.procname	= "tcp_mtu_probing",
536		.data		= &sysctl_tcp_mtu_probing,
537		.maxlen		= sizeof(int),
538		.mode		= 0644,
539		.proc_handler	= proc_dointvec,
540	},
541	{
542		.procname	= "tcp_base_mss",
543		.data		= &sysctl_tcp_base_mss,
544		.maxlen		= sizeof(int),
545		.mode		= 0644,
546		.proc_handler	= proc_dointvec,
547	},
548	{
549		.procname	= "tcp_workaround_signed_windows",
550		.data		= &sysctl_tcp_workaround_signed_windows,
551		.maxlen		= sizeof(int),
552		.mode		= 0644,
553		.proc_handler	= proc_dointvec
554	},
555#ifdef CONFIG_NET_DMA
556	{
557		.procname	= "tcp_dma_copybreak",
558		.data		= &sysctl_tcp_dma_copybreak,
559		.maxlen		= sizeof(int),
560		.mode		= 0644,
561		.proc_handler	= proc_dointvec
562	},
563#endif
564	{
565		.procname	= "tcp_slow_start_after_idle",
566		.data		= &sysctl_tcp_slow_start_after_idle,
567		.maxlen		= sizeof(int),
568		.mode		= 0644,
569		.proc_handler	= proc_dointvec
570	},
571#ifdef CONFIG_NETLABEL
572	{
573		.procname	= "cipso_cache_enable",
574		.data		= &cipso_v4_cache_enabled,
575		.maxlen		= sizeof(int),
576		.mode		= 0644,
577		.proc_handler	= proc_dointvec,
578	},
579	{
580		.procname	= "cipso_cache_bucket_size",
581		.data		= &cipso_v4_cache_bucketsize,
582		.maxlen		= sizeof(int),
583		.mode		= 0644,
584		.proc_handler	= proc_dointvec,
585	},
586	{
587		.procname	= "cipso_rbm_optfmt",
588		.data		= &cipso_v4_rbm_optfmt,
589		.maxlen		= sizeof(int),
590		.mode		= 0644,
591		.proc_handler	= proc_dointvec,
592	},
593	{
594		.procname	= "cipso_rbm_strictvalid",
595		.data		= &cipso_v4_rbm_strictvalid,
596		.maxlen		= sizeof(int),
597		.mode		= 0644,
598		.proc_handler	= proc_dointvec,
599	},
600#endif /* CONFIG_NETLABEL */
601	{
602		.procname	= "tcp_available_congestion_control",
603		.maxlen		= TCP_CA_BUF_MAX,
604		.mode		= 0444,
605		.proc_handler   = proc_tcp_available_congestion_control,
606	},
607	{
608		.procname	= "tcp_allowed_congestion_control",
609		.maxlen		= TCP_CA_BUF_MAX,
610		.mode		= 0644,
611		.proc_handler   = proc_allowed_congestion_control,
612	},
613	{
614		.procname	= "tcp_max_ssthresh",
615		.data		= &sysctl_tcp_max_ssthresh,
616		.maxlen		= sizeof(int),
617		.mode		= 0644,
618		.proc_handler	= proc_dointvec,
619	},
620	{
621		.procname	= "tcp_cookie_size",
622		.data		= &sysctl_tcp_cookie_size,
623		.maxlen		= sizeof(int),
624		.mode		= 0644,
625		.proc_handler	= proc_dointvec
626	},
627	{
628		.procname       = "tcp_thin_linear_timeouts",
629		.data           = &sysctl_tcp_thin_linear_timeouts,
630		.maxlen         = sizeof(int),
631		.mode           = 0644,
632		.proc_handler   = proc_dointvec
633	},
634        {
635		.procname       = "tcp_thin_dupack",
636		.data           = &sysctl_tcp_thin_dupack,
637		.maxlen         = sizeof(int),
638		.mode           = 0644,
639		.proc_handler   = proc_dointvec
640	},
641	{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
642		.procname	= "udp_mem",
643		.data		= &sysctl_udp_mem,
644		.maxlen		= sizeof(sysctl_udp_mem),
645		.mode		= 0644,
646		.proc_handler	= proc_doulongvec_minmax,
647	},
648	{
649		.procname	= "udp_rmem_min",
650		.data		= &sysctl_udp_rmem_min,
651		.maxlen		= sizeof(sysctl_udp_rmem_min),
652		.mode		= 0644,
653		.proc_handler	= proc_dointvec_minmax,
654		.extra1		= &zero
655	},
656	{
657		.procname	= "udp_wmem_min",
658		.data		= &sysctl_udp_wmem_min,
659		.maxlen		= sizeof(sysctl_udp_wmem_min),
660		.mode		= 0644,
661		.proc_handler	= proc_dointvec_minmax,
662		.extra1		= &zero
663	},
664	{ }
665};
666
667static struct ctl_table ipv4_net_table[] = {
668	{
669		.procname	= "icmp_echo_ignore_all",
670		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_all,
671		.maxlen		= sizeof(int),
672		.mode		= 0644,
673		.proc_handler	= proc_dointvec
674	},
675	{
676		.procname	= "icmp_echo_ignore_broadcasts",
677		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
678		.maxlen		= sizeof(int),
679		.mode		= 0644,
680		.proc_handler	= proc_dointvec
681	},
682	{
683		.procname	= "icmp_ignore_bogus_error_responses",
684		.data		= &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
685		.maxlen		= sizeof(int),
686		.mode		= 0644,
687		.proc_handler	= proc_dointvec
688	},
689	{
690		.procname	= "icmp_errors_use_inbound_ifaddr",
691		.data		= &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
692		.maxlen		= sizeof(int),
693		.mode		= 0644,
694		.proc_handler	= proc_dointvec
695	},
696	{
697		.procname	= "icmp_ratelimit",
698		.data		= &init_net.ipv4.sysctl_icmp_ratelimit,
699		.maxlen		= sizeof(int),
700		.mode		= 0644,
701		.proc_handler	= proc_dointvec_ms_jiffies,
702	},
703	{
704		.procname	= "icmp_ratemask",
705		.data		= &init_net.ipv4.sysctl_icmp_ratemask,
706		.maxlen		= sizeof(int),
707		.mode		= 0644,
708		.proc_handler	= proc_dointvec
709	},
710	{
711		.procname	= "rt_cache_rebuild_count",
712		.data		= &init_net.ipv4.sysctl_rt_cache_rebuild_count,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
713		.maxlen		= sizeof(int),
714		.mode		= 0644,
715		.proc_handler	= proc_dointvec
716	},
717	{
718		.procname	= "ping_group_range",
719		.data		= &init_net.ipv4.sysctl_ping_group_range,
720		.maxlen		= sizeof(init_net.ipv4.sysctl_ping_group_range),
721		.mode		= 0644,
722		.proc_handler	= ipv4_ping_group_range,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
723	},
724	{ }
725};
726
727struct ctl_path net_ipv4_ctl_path[] = {
728	{ .procname = "net", },
729	{ .procname = "ipv4", },
730	{ },
731};
732EXPORT_SYMBOL_GPL(net_ipv4_ctl_path);
733
734static __net_init int ipv4_sysctl_init_net(struct net *net)
735{
736	struct ctl_table *table;
737
738	table = ipv4_net_table;
739	if (!net_eq(net, &init_net)) {
 
 
740		table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
741		if (table == NULL)
742			goto err_alloc;
743
744		table[0].data =
745			&net->ipv4.sysctl_icmp_echo_ignore_all;
746		table[1].data =
747			&net->ipv4.sysctl_icmp_echo_ignore_broadcasts;
748		table[2].data =
749			&net->ipv4.sysctl_icmp_ignore_bogus_error_responses;
750		table[3].data =
751			&net->ipv4.sysctl_icmp_errors_use_inbound_ifaddr;
752		table[4].data =
753			&net->ipv4.sysctl_icmp_ratelimit;
754		table[5].data =
755			&net->ipv4.sysctl_icmp_ratemask;
756		table[6].data =
757			&net->ipv4.sysctl_rt_cache_rebuild_count;
758		table[7].data =
759			&net->ipv4.sysctl_ping_group_range;
760
761	}
762
763	/*
764	 * Sane defaults - nobody may create ping sockets.
765	 * Boot scripts should set this to distro-specific group.
766	 */
767	net->ipv4.sysctl_ping_group_range[0] = 1;
768	net->ipv4.sysctl_ping_group_range[1] = 0;
769
770	net->ipv4.sysctl_rt_cache_rebuild_count = 4;
771
772	net->ipv4.ipv4_hdr = register_net_sysctl_table(net,
773			net_ipv4_ctl_path, table);
774	if (net->ipv4.ipv4_hdr == NULL)
775		goto err_reg;
776
 
 
 
 
 
 
 
 
777	return 0;
778
 
 
779err_reg:
780	if (!net_eq(net, &init_net))
781		kfree(table);
782err_alloc:
783	return -ENOMEM;
784}
785
786static __net_exit void ipv4_sysctl_exit_net(struct net *net)
787{
788	struct ctl_table *table;
789
 
790	table = net->ipv4.ipv4_hdr->ctl_table_arg;
791	unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
792	kfree(table);
793}
794
795static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
796	.init = ipv4_sysctl_init_net,
797	.exit = ipv4_sysctl_exit_net,
798};
799
800static __init int sysctl_ipv4_init(void)
801{
802	struct ctl_table_header *hdr;
803	struct ctl_table *i;
804
805	for (i = ipv4_table; i->procname; i++) {
806		if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
807			i->data = sysctl_local_reserved_ports;
808			break;
809		}
810	}
811	if (!i->procname)
812		return -EINVAL;
813
814	hdr = register_sysctl_paths(net_ipv4_ctl_path, ipv4_table);
815	if (hdr == NULL)
816		return -ENOMEM;
817
818	if (register_pernet_subsys(&ipv4_sysctl_ops)) {
819		unregister_sysctl_table(hdr);
820		return -ENOMEM;
821	}
822
823	return 0;
824}
825
826__initcall(sysctl_ipv4_init);
v4.6
   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
  28static int zero;
  29static int one = 1;
  30static int four = 4;
  31static int thousand = 1000;
  32static int gso_max_segs = GSO_MAX_SEGS;
  33static int tcp_retr1_max = 255;
  34static int ip_local_port_range_min[] = { 1, 1 };
  35static int ip_local_port_range_max[] = { 65535, 65535 };
  36static int tcp_adv_win_scale_min = -31;
  37static int tcp_adv_win_scale_max = 31;
  38static int ip_ttl_min = 1;
  39static int ip_ttl_max = 255;
  40static int tcp_syn_retries_min = 1;
  41static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
  42static int ip_ping_group_range_min[] = { 0, 0 };
  43static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
  44
  45/* Update system visible IP port range */
  46static void set_local_port_range(struct net *net, int range[2])
  47{
  48	bool same_parity = !((range[0] ^ range[1]) & 1);
  49
  50	write_seqlock_bh(&net->ipv4.ip_local_ports.lock);
  51	if (same_parity && !net->ipv4.ip_local_ports.warned) {
  52		net->ipv4.ip_local_ports.warned = true;
  53		pr_err_ratelimited("ip_local_port_range: prefer different parity for start/end values.\n");
  54	}
  55	net->ipv4.ip_local_ports.range[0] = range[0];
  56	net->ipv4.ip_local_ports.range[1] = range[1];
  57	write_sequnlock_bh(&net->ipv4.ip_local_ports.lock);
  58}
  59
  60/* Validate changes from /proc interface. */
  61static int ipv4_local_port_range(struct ctl_table *table, int write,
  62				 void __user *buffer,
  63				 size_t *lenp, loff_t *ppos)
  64{
  65	struct net *net =
  66		container_of(table->data, struct net, ipv4.ip_local_ports.range);
  67	int ret;
  68	int range[2];
  69	struct ctl_table tmp = {
  70		.data = &range,
  71		.maxlen = sizeof(range),
  72		.mode = table->mode,
  73		.extra1 = &ip_local_port_range_min,
  74		.extra2 = &ip_local_port_range_max,
  75	};
  76
  77	inet_get_local_port_range(net, &range[0], &range[1]);
  78
  79	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
  80
  81	if (write && ret == 0) {
  82		if (range[1] < range[0])
  83			ret = -EINVAL;
  84		else
  85			set_local_port_range(net, range);
  86	}
  87
  88	return ret;
  89}
  90
  91
  92static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low, kgid_t *high)
  93{
  94	kgid_t *data = table->data;
  95	struct net *net =
  96		container_of(table->data, struct net, ipv4.ping_group_range.range);
  97	unsigned int seq;
  98	do {
  99		seq = read_seqbegin(&net->ipv4.ip_local_ports.lock);
 100
 101		*low = data[0];
 102		*high = data[1];
 103	} while (read_seqretry(&net->ipv4.ip_local_ports.lock, seq));
 104}
 105
 106/* Update system visible IP port range */
 107static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t high)
 108{
 109	kgid_t *data = table->data;
 110	struct net *net =
 111		container_of(table->data, struct net, ipv4.ping_group_range.range);
 112	write_seqlock(&net->ipv4.ip_local_ports.lock);
 113	data[0] = low;
 114	data[1] = high;
 115	write_sequnlock(&net->ipv4.ip_local_ports.lock);
 116}
 117
 118/* Validate changes from /proc interface. */
 119static int ipv4_ping_group_range(struct ctl_table *table, int write,
 120				 void __user *buffer,
 121				 size_t *lenp, loff_t *ppos)
 122{
 123	struct user_namespace *user_ns = current_user_ns();
 124	int ret;
 125	gid_t urange[2];
 126	kgid_t low, high;
 127	struct ctl_table tmp = {
 128		.data = &urange,
 129		.maxlen = sizeof(urange),
 130		.mode = table->mode,
 131		.extra1 = &ip_ping_group_range_min,
 132		.extra2 = &ip_ping_group_range_max,
 133	};
 134
 135	inet_get_ping_group_range_table(table, &low, &high);
 136	urange[0] = from_kgid_munged(user_ns, low);
 137	urange[1] = from_kgid_munged(user_ns, high);
 138	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
 139
 140	if (write && ret == 0) {
 141		low = make_kgid(user_ns, urange[0]);
 142		high = make_kgid(user_ns, urange[1]);
 143		if (!gid_valid(low) || !gid_valid(high) ||
 144		    (urange[1] < urange[0]) || gid_lt(high, low)) {
 145			low = make_kgid(&init_user_ns, 1);
 146			high = make_kgid(&init_user_ns, 0);
 147		}
 148		set_ping_group_range(table, low, high);
 149	}
 150
 151	return ret;
 152}
 153
 154static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
 155				       void __user *buffer, size_t *lenp, loff_t *ppos)
 156{
 157	char val[TCP_CA_NAME_MAX];
 158	struct ctl_table tbl = {
 159		.data = val,
 160		.maxlen = TCP_CA_NAME_MAX,
 161	};
 162	int ret;
 163
 164	tcp_get_default_congestion_control(val);
 165
 166	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
 167	if (write && ret == 0)
 168		ret = tcp_set_default_congestion_control(val);
 169	return ret;
 170}
 171
 172static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
 173						 int write,
 174						 void __user *buffer, size_t *lenp,
 175						 loff_t *ppos)
 176{
 177	struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
 178	int ret;
 179
 180	tbl.data = kmalloc(tbl.maxlen, GFP_USER);
 181	if (!tbl.data)
 182		return -ENOMEM;
 183	tcp_get_available_congestion_control(tbl.data, TCP_CA_BUF_MAX);
 184	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
 185	kfree(tbl.data);
 186	return ret;
 187}
 188
 189static int proc_allowed_congestion_control(struct ctl_table *ctl,
 190					   int write,
 191					   void __user *buffer, size_t *lenp,
 192					   loff_t *ppos)
 193{
 194	struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
 195	int ret;
 196
 197	tbl.data = kmalloc(tbl.maxlen, GFP_USER);
 198	if (!tbl.data)
 199		return -ENOMEM;
 200
 201	tcp_get_allowed_congestion_control(tbl.data, tbl.maxlen);
 202	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
 203	if (write && ret == 0)
 204		ret = tcp_set_allowed_congestion_control(tbl.data);
 205	kfree(tbl.data);
 206	return ret;
 207}
 208
 209static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
 210				 void __user *buffer, size_t *lenp,
 211				 loff_t *ppos)
 212{
 213	struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
 214	struct tcp_fastopen_context *ctxt;
 215	int ret;
 216	u32  user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
 217
 218	tbl.data = kmalloc(tbl.maxlen, GFP_KERNEL);
 219	if (!tbl.data)
 220		return -ENOMEM;
 221
 222	rcu_read_lock();
 223	ctxt = rcu_dereference(tcp_fastopen_ctx);
 224	if (ctxt)
 225		memcpy(user_key, ctxt->key, TCP_FASTOPEN_KEY_LENGTH);
 226	else
 227		memset(user_key, 0, sizeof(user_key));
 228	rcu_read_unlock();
 229
 230	snprintf(tbl.data, tbl.maxlen, "%08x-%08x-%08x-%08x",
 231		user_key[0], user_key[1], user_key[2], user_key[3]);
 232	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
 233
 234	if (write && ret == 0) {
 235		if (sscanf(tbl.data, "%x-%x-%x-%x", user_key, user_key + 1,
 236			   user_key + 2, user_key + 3) != 4) {
 237			ret = -EINVAL;
 238			goto bad_key;
 239		}
 240		/* Generate a dummy secret but don't publish it. This
 241		 * is needed so we don't regenerate a new key on the
 242		 * first invocation of tcp_fastopen_cookie_gen
 243		 */
 244		tcp_fastopen_init_key_once(false);
 245		tcp_fastopen_reset_cipher(user_key, TCP_FASTOPEN_KEY_LENGTH);
 246	}
 247
 248bad_key:
 249	pr_debug("proc FO key set 0x%x-%x-%x-%x <- 0x%s: %u\n",
 250	       user_key[0], user_key[1], user_key[2], user_key[3],
 251	       (char *)tbl.data, ret);
 252	kfree(tbl.data);
 253	return ret;
 254}
 255
 256static struct ctl_table ipv4_table[] = {
 257	{
 258		.procname	= "tcp_timestamps",
 259		.data		= &sysctl_tcp_timestamps,
 260		.maxlen		= sizeof(int),
 261		.mode		= 0644,
 262		.proc_handler	= proc_dointvec
 263	},
 264	{
 265		.procname	= "tcp_window_scaling",
 266		.data		= &sysctl_tcp_window_scaling,
 267		.maxlen		= sizeof(int),
 268		.mode		= 0644,
 269		.proc_handler	= proc_dointvec
 270	},
 271	{
 272		.procname	= "tcp_sack",
 273		.data		= &sysctl_tcp_sack,
 274		.maxlen		= sizeof(int),
 275		.mode		= 0644,
 276		.proc_handler	= proc_dointvec
 277	},
 278	{
 279		.procname	= "tcp_retrans_collapse",
 280		.data		= &sysctl_tcp_retrans_collapse,
 281		.maxlen		= sizeof(int),
 282		.mode		= 0644,
 283		.proc_handler	= proc_dointvec
 284	},
 285	{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 286		.procname	= "tcp_max_orphans",
 287		.data		= &sysctl_tcp_max_orphans,
 288		.maxlen		= sizeof(int),
 289		.mode		= 0644,
 290		.proc_handler	= proc_dointvec
 291	},
 292	{
 293		.procname	= "tcp_max_tw_buckets",
 294		.data		= &tcp_death_row.sysctl_max_tw_buckets,
 295		.maxlen		= sizeof(int),
 296		.mode		= 0644,
 297		.proc_handler	= proc_dointvec
 298	},
 299	{
 300		.procname	= "tcp_fastopen",
 301		.data		= &sysctl_tcp_fastopen,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 302		.maxlen		= sizeof(int),
 303		.mode		= 0644,
 304		.proc_handler	= proc_dointvec,
 305	},
 
 306	{
 307		.procname	= "tcp_fastopen_key",
 308		.mode		= 0600,
 309		.maxlen		= ((TCP_FASTOPEN_KEY_LENGTH * 2) + 10),
 310		.proc_handler	= proc_tcp_fastopen_key,
 
 311	},
 
 312	{
 313		.procname	= "tcp_tw_recycle",
 314		.data		= &tcp_death_row.sysctl_tw_recycle,
 315		.maxlen		= sizeof(int),
 316		.mode		= 0644,
 317		.proc_handler	= proc_dointvec
 318	},
 319	{
 320		.procname	= "tcp_abort_on_overflow",
 321		.data		= &sysctl_tcp_abort_on_overflow,
 322		.maxlen		= sizeof(int),
 323		.mode		= 0644,
 324		.proc_handler	= proc_dointvec
 325	},
 326	{
 327		.procname	= "tcp_stdurg",
 328		.data		= &sysctl_tcp_stdurg,
 329		.maxlen		= sizeof(int),
 330		.mode		= 0644,
 331		.proc_handler	= proc_dointvec
 332	},
 333	{
 334		.procname	= "tcp_rfc1337",
 335		.data		= &sysctl_tcp_rfc1337,
 336		.maxlen		= sizeof(int),
 337		.mode		= 0644,
 338		.proc_handler	= proc_dointvec
 339	},
 340	{
 341		.procname	= "tcp_max_syn_backlog",
 342		.data		= &sysctl_max_syn_backlog,
 343		.maxlen		= sizeof(int),
 344		.mode		= 0644,
 345		.proc_handler	= proc_dointvec
 346	},
 347	{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 348		.procname	= "inet_peer_threshold",
 349		.data		= &inet_peer_threshold,
 350		.maxlen		= sizeof(int),
 351		.mode		= 0644,
 352		.proc_handler	= proc_dointvec
 353	},
 354	{
 355		.procname	= "inet_peer_minttl",
 356		.data		= &inet_peer_minttl,
 357		.maxlen		= sizeof(int),
 358		.mode		= 0644,
 359		.proc_handler	= proc_dointvec_jiffies,
 360	},
 361	{
 362		.procname	= "inet_peer_maxttl",
 363		.data		= &inet_peer_maxttl,
 364		.maxlen		= sizeof(int),
 365		.mode		= 0644,
 366		.proc_handler	= proc_dointvec_jiffies,
 367	},
 368	{
 
 
 
 
 
 
 
 369		.procname	= "tcp_fack",
 370		.data		= &sysctl_tcp_fack,
 371		.maxlen		= sizeof(int),
 372		.mode		= 0644,
 373		.proc_handler	= proc_dointvec
 374	},
 375	{
 376		.procname	= "tcp_recovery",
 377		.data		= &sysctl_tcp_recovery,
 378		.maxlen		= sizeof(int),
 379		.mode		= 0644,
 380		.proc_handler	= proc_dointvec,
 381	},
 382	{
 383		.procname	= "tcp_max_reordering",
 384		.data		= &sysctl_tcp_max_reordering,
 385		.maxlen		= sizeof(int),
 386		.mode		= 0644,
 387		.proc_handler	= proc_dointvec
 388	},
 389	{
 390		.procname	= "tcp_dsack",
 391		.data		= &sysctl_tcp_dsack,
 392		.maxlen		= sizeof(int),
 393		.mode		= 0644,
 394		.proc_handler	= proc_dointvec
 395	},
 396	{
 397		.procname	= "tcp_mem",
 
 398		.maxlen		= sizeof(sysctl_tcp_mem),
 399		.data		= &sysctl_tcp_mem,
 400		.mode		= 0644,
 401		.proc_handler	= proc_doulongvec_minmax,
 402	},
 403	{
 404		.procname	= "tcp_wmem",
 405		.data		= &sysctl_tcp_wmem,
 406		.maxlen		= sizeof(sysctl_tcp_wmem),
 407		.mode		= 0644,
 408		.proc_handler	= proc_dointvec_minmax,
 409		.extra1		= &one,
 410	},
 411	{
 412		.procname	= "tcp_rmem",
 413		.data		= &sysctl_tcp_rmem,
 414		.maxlen		= sizeof(sysctl_tcp_rmem),
 415		.mode		= 0644,
 416		.proc_handler	= proc_dointvec_minmax,
 417		.extra1		= &one,
 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_min_rtt_wlen",
 451		.data		= &sysctl_tcp_min_rtt_wlen,
 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_workaround_signed_windows",
 492		.data		= &sysctl_tcp_workaround_signed_windows,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 493		.maxlen		= sizeof(int),
 494		.mode		= 0644,
 495		.proc_handler	= proc_dointvec
 496	},
 497	{
 498		.procname	= "tcp_limit_output_bytes",
 499		.data		= &sysctl_tcp_limit_output_bytes,
 500		.maxlen		= sizeof(int),
 501		.mode		= 0644,
 502		.proc_handler	= proc_dointvec
 503	},
 
 504	{
 505		.procname	= "tcp_challenge_ack_limit",
 506		.data		= &sysctl_tcp_challenge_ack_limit,
 507		.maxlen		= sizeof(int),
 508		.mode		= 0644,
 509		.proc_handler	= proc_dointvec
 510	},
 
 511	{
 512		.procname	= "tcp_slow_start_after_idle",
 513		.data		= &sysctl_tcp_slow_start_after_idle,
 514		.maxlen		= sizeof(int),
 515		.mode		= 0644,
 516		.proc_handler	= proc_dointvec
 517	},
 518#ifdef CONFIG_NETLABEL
 519	{
 520		.procname	= "cipso_cache_enable",
 521		.data		= &cipso_v4_cache_enabled,
 522		.maxlen		= sizeof(int),
 523		.mode		= 0644,
 524		.proc_handler	= proc_dointvec,
 525	},
 526	{
 527		.procname	= "cipso_cache_bucket_size",
 528		.data		= &cipso_v4_cache_bucketsize,
 529		.maxlen		= sizeof(int),
 530		.mode		= 0644,
 531		.proc_handler	= proc_dointvec,
 532	},
 533	{
 534		.procname	= "cipso_rbm_optfmt",
 535		.data		= &cipso_v4_rbm_optfmt,
 536		.maxlen		= sizeof(int),
 537		.mode		= 0644,
 538		.proc_handler	= proc_dointvec,
 539	},
 540	{
 541		.procname	= "cipso_rbm_strictvalid",
 542		.data		= &cipso_v4_rbm_strictvalid,
 543		.maxlen		= sizeof(int),
 544		.mode		= 0644,
 545		.proc_handler	= proc_dointvec,
 546	},
 547#endif /* CONFIG_NETLABEL */
 548	{
 549		.procname	= "tcp_available_congestion_control",
 550		.maxlen		= TCP_CA_BUF_MAX,
 551		.mode		= 0444,
 552		.proc_handler   = proc_tcp_available_congestion_control,
 553	},
 554	{
 555		.procname	= "tcp_allowed_congestion_control",
 556		.maxlen		= TCP_CA_BUF_MAX,
 557		.mode		= 0644,
 558		.proc_handler   = proc_allowed_congestion_control,
 559	},
 560	{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 561		.procname       = "tcp_thin_linear_timeouts",
 562		.data           = &sysctl_tcp_thin_linear_timeouts,
 563		.maxlen         = sizeof(int),
 564		.mode           = 0644,
 565		.proc_handler   = proc_dointvec
 566	},
 567	{
 568		.procname       = "tcp_thin_dupack",
 569		.data           = &sysctl_tcp_thin_dupack,
 570		.maxlen         = sizeof(int),
 571		.mode           = 0644,
 572		.proc_handler   = proc_dointvec
 573	},
 574	{
 575		.procname	= "tcp_early_retrans",
 576		.data		= &sysctl_tcp_early_retrans,
 577		.maxlen		= sizeof(int),
 578		.mode		= 0644,
 579		.proc_handler	= proc_dointvec_minmax,
 580		.extra1		= &zero,
 581		.extra2		= &four,
 582	},
 583	{
 584		.procname	= "tcp_min_tso_segs",
 585		.data		= &sysctl_tcp_min_tso_segs,
 586		.maxlen		= sizeof(int),
 587		.mode		= 0644,
 588		.proc_handler	= proc_dointvec_minmax,
 589		.extra1		= &one,
 590		.extra2		= &gso_max_segs,
 591	},
 592	{
 593		.procname	= "tcp_pacing_ss_ratio",
 594		.data		= &sysctl_tcp_pacing_ss_ratio,
 595		.maxlen		= sizeof(int),
 596		.mode		= 0644,
 597		.proc_handler	= proc_dointvec_minmax,
 598		.extra1		= &zero,
 599		.extra2		= &thousand,
 600	},
 601	{
 602		.procname	= "tcp_pacing_ca_ratio",
 603		.data		= &sysctl_tcp_pacing_ca_ratio,
 604		.maxlen		= sizeof(int),
 605		.mode		= 0644,
 606		.proc_handler	= proc_dointvec_minmax,
 607		.extra1		= &zero,
 608		.extra2		= &thousand,
 609	},
 610	{
 611		.procname	= "tcp_autocorking",
 612		.data		= &sysctl_tcp_autocorking,
 613		.maxlen		= sizeof(int),
 614		.mode		= 0644,
 615		.proc_handler	= proc_dointvec_minmax,
 616		.extra1		= &zero,
 617		.extra2		= &one,
 618	},
 619	{
 620		.procname	= "tcp_invalid_ratelimit",
 621		.data		= &sysctl_tcp_invalid_ratelimit,
 622		.maxlen		= sizeof(int),
 623		.mode		= 0644,
 624		.proc_handler	= proc_dointvec_ms_jiffies,
 625	},
 626	{
 627		.procname	= "icmp_msgs_per_sec",
 628		.data		= &sysctl_icmp_msgs_per_sec,
 629		.maxlen		= sizeof(int),
 630		.mode		= 0644,
 631		.proc_handler	= proc_dointvec_minmax,
 632		.extra1		= &zero,
 633	},
 634	{
 635		.procname	= "icmp_msgs_burst",
 636		.data		= &sysctl_icmp_msgs_burst,
 637		.maxlen		= sizeof(int),
 638		.mode		= 0644,
 639		.proc_handler	= proc_dointvec_minmax,
 640		.extra1		= &zero,
 641	},
 642	{
 643		.procname	= "udp_mem",
 644		.data		= &sysctl_udp_mem,
 645		.maxlen		= sizeof(sysctl_udp_mem),
 646		.mode		= 0644,
 647		.proc_handler	= proc_doulongvec_minmax,
 648	},
 649	{
 650		.procname	= "udp_rmem_min",
 651		.data		= &sysctl_udp_rmem_min,
 652		.maxlen		= sizeof(sysctl_udp_rmem_min),
 653		.mode		= 0644,
 654		.proc_handler	= proc_dointvec_minmax,
 655		.extra1		= &one
 656	},
 657	{
 658		.procname	= "udp_wmem_min",
 659		.data		= &sysctl_udp_wmem_min,
 660		.maxlen		= sizeof(sysctl_udp_wmem_min),
 661		.mode		= 0644,
 662		.proc_handler	= proc_dointvec_minmax,
 663		.extra1		= &one
 664	},
 665	{ }
 666};
 667
 668static struct ctl_table ipv4_net_table[] = {
 669	{
 670		.procname	= "icmp_echo_ignore_all",
 671		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_all,
 672		.maxlen		= sizeof(int),
 673		.mode		= 0644,
 674		.proc_handler	= proc_dointvec
 675	},
 676	{
 677		.procname	= "icmp_echo_ignore_broadcasts",
 678		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
 679		.maxlen		= sizeof(int),
 680		.mode		= 0644,
 681		.proc_handler	= proc_dointvec
 682	},
 683	{
 684		.procname	= "icmp_ignore_bogus_error_responses",
 685		.data		= &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
 686		.maxlen		= sizeof(int),
 687		.mode		= 0644,
 688		.proc_handler	= proc_dointvec
 689	},
 690	{
 691		.procname	= "icmp_errors_use_inbound_ifaddr",
 692		.data		= &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
 693		.maxlen		= sizeof(int),
 694		.mode		= 0644,
 695		.proc_handler	= proc_dointvec
 696	},
 697	{
 698		.procname	= "icmp_ratelimit",
 699		.data		= &init_net.ipv4.sysctl_icmp_ratelimit,
 700		.maxlen		= sizeof(int),
 701		.mode		= 0644,
 702		.proc_handler	= proc_dointvec_ms_jiffies,
 703	},
 704	{
 705		.procname	= "icmp_ratemask",
 706		.data		= &init_net.ipv4.sysctl_icmp_ratemask,
 707		.maxlen		= sizeof(int),
 708		.mode		= 0644,
 709		.proc_handler	= proc_dointvec
 710	},
 711	{
 712		.procname	= "ping_group_range",
 713		.data		= &init_net.ipv4.ping_group_range.range,
 714		.maxlen		= sizeof(gid_t)*2,
 715		.mode		= 0644,
 716		.proc_handler	= ipv4_ping_group_range,
 717	},
 718	{
 719		.procname	= "tcp_ecn",
 720		.data		= &init_net.ipv4.sysctl_tcp_ecn,
 721		.maxlen		= sizeof(int),
 722		.mode		= 0644,
 723		.proc_handler	= proc_dointvec
 724	},
 725	{
 726		.procname	= "tcp_ecn_fallback",
 727		.data		= &init_net.ipv4.sysctl_tcp_ecn_fallback,
 728		.maxlen		= sizeof(int),
 729		.mode		= 0644,
 730		.proc_handler	= proc_dointvec
 731	},
 732	{
 733		.procname	= "ip_dynaddr",
 734		.data		= &init_net.ipv4.sysctl_ip_dynaddr,
 735		.maxlen		= sizeof(int),
 736		.mode		= 0644,
 737		.proc_handler	= proc_dointvec
 738	},
 739	{
 740		.procname	= "ip_early_demux",
 741		.data		= &init_net.ipv4.sysctl_ip_early_demux,
 742		.maxlen		= sizeof(int),
 743		.mode		= 0644,
 744		.proc_handler	= proc_dointvec
 745	},
 746	{
 747		.procname	= "ip_default_ttl",
 748		.data		= &init_net.ipv4.sysctl_ip_default_ttl,
 749		.maxlen		= sizeof(int),
 750		.mode		= 0644,
 751		.proc_handler	= proc_dointvec_minmax,
 752		.extra1		= &ip_ttl_min,
 753		.extra2		= &ip_ttl_max,
 754	},
 755	{
 756		.procname	= "ip_local_port_range",
 757		.maxlen		= sizeof(init_net.ipv4.ip_local_ports.range),
 758		.data		= &init_net.ipv4.ip_local_ports.range,
 759		.mode		= 0644,
 760		.proc_handler	= ipv4_local_port_range,
 761	},
 762	{
 763		.procname	= "ip_local_reserved_ports",
 764		.data		= &init_net.ipv4.sysctl_local_reserved_ports,
 765		.maxlen		= 65536,
 766		.mode		= 0644,
 767		.proc_handler	= proc_do_large_bitmap,
 768	},
 769	{
 770		.procname	= "ip_no_pmtu_disc",
 771		.data		= &init_net.ipv4.sysctl_ip_no_pmtu_disc,
 772		.maxlen		= sizeof(int),
 773		.mode		= 0644,
 774		.proc_handler	= proc_dointvec
 775	},
 776	{
 777		.procname	= "ip_forward_use_pmtu",
 778		.data		= &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
 779		.maxlen		= sizeof(int),
 780		.mode		= 0644,
 781		.proc_handler	= proc_dointvec,
 782	},
 783	{
 784		.procname	= "ip_nonlocal_bind",
 785		.data		= &init_net.ipv4.sysctl_ip_nonlocal_bind,
 786		.maxlen		= sizeof(int),
 787		.mode		= 0644,
 788		.proc_handler	= proc_dointvec
 789	},
 790	{
 791		.procname	= "fwmark_reflect",
 792		.data		= &init_net.ipv4.sysctl_fwmark_reflect,
 793		.maxlen		= sizeof(int),
 794		.mode		= 0644,
 795		.proc_handler	= proc_dointvec,
 796	},
 797	{
 798		.procname	= "tcp_fwmark_accept",
 799		.data		= &init_net.ipv4.sysctl_tcp_fwmark_accept,
 800		.maxlen		= sizeof(int),
 801		.mode		= 0644,
 802		.proc_handler	= proc_dointvec,
 803	},
 804#ifdef CONFIG_NET_L3_MASTER_DEV
 805	{
 806		.procname	= "tcp_l3mdev_accept",
 807		.data		= &init_net.ipv4.sysctl_tcp_l3mdev_accept,
 808		.maxlen		= sizeof(int),
 809		.mode		= 0644,
 810		.proc_handler	= proc_dointvec_minmax,
 811		.extra1		= &zero,
 812		.extra2		= &one,
 813	},
 814#endif
 815	{
 816		.procname	= "tcp_mtu_probing",
 817		.data		= &init_net.ipv4.sysctl_tcp_mtu_probing,
 818		.maxlen		= sizeof(int),
 819		.mode		= 0644,
 820		.proc_handler	= proc_dointvec,
 821	},
 822	{
 823		.procname	= "tcp_base_mss",
 824		.data		= &init_net.ipv4.sysctl_tcp_base_mss,
 825		.maxlen		= sizeof(int),
 826		.mode		= 0644,
 827		.proc_handler	= proc_dointvec,
 828	},
 829	{
 830		.procname	= "tcp_probe_threshold",
 831		.data		= &init_net.ipv4.sysctl_tcp_probe_threshold,
 832		.maxlen		= sizeof(int),
 833		.mode		= 0644,
 834		.proc_handler	= proc_dointvec,
 835	},
 836	{
 837		.procname	= "tcp_probe_interval",
 838		.data		= &init_net.ipv4.sysctl_tcp_probe_interval,
 839		.maxlen		= sizeof(int),
 840		.mode		= 0644,
 841		.proc_handler	= proc_dointvec,
 842	},
 843	{
 844		.procname	= "igmp_link_local_mcast_reports",
 845		.data		= &init_net.ipv4.sysctl_igmp_llm_reports,
 846		.maxlen		= sizeof(int),
 847		.mode		= 0644,
 848		.proc_handler	= proc_dointvec
 849	},
 850	{
 851		.procname	= "igmp_max_memberships",
 852		.data		= &init_net.ipv4.sysctl_igmp_max_memberships,
 853		.maxlen		= sizeof(int),
 854		.mode		= 0644,
 855		.proc_handler	= proc_dointvec
 856	},
 857	{
 858		.procname	= "igmp_max_msf",
 859		.data		= &init_net.ipv4.sysctl_igmp_max_msf,
 860		.maxlen		= sizeof(int),
 861		.mode		= 0644,
 862		.proc_handler	= proc_dointvec
 863	},
 864#ifdef CONFIG_IP_MULTICAST
 865	{
 866		.procname	= "igmp_qrv",
 867		.data		= &init_net.ipv4.sysctl_igmp_qrv,
 868		.maxlen		= sizeof(int),
 869		.mode		= 0644,
 870		.proc_handler	= proc_dointvec_minmax,
 871		.extra1		= &one
 872	},
 873#endif
 874	{
 875		.procname	= "tcp_keepalive_time",
 876		.data		= &init_net.ipv4.sysctl_tcp_keepalive_time,
 877		.maxlen		= sizeof(int),
 878		.mode		= 0644,
 879		.proc_handler	= proc_dointvec_jiffies,
 880	},
 881	{
 882		.procname	= "tcp_keepalive_probes",
 883		.data		= &init_net.ipv4.sysctl_tcp_keepalive_probes,
 884		.maxlen		= sizeof(int),
 885		.mode		= 0644,
 886		.proc_handler	= proc_dointvec
 887	},
 888	{
 889		.procname	= "tcp_keepalive_intvl",
 890		.data		= &init_net.ipv4.sysctl_tcp_keepalive_intvl,
 891		.maxlen		= sizeof(int),
 892		.mode		= 0644,
 893		.proc_handler	= proc_dointvec_jiffies,
 894	},
 895	{
 896		.procname	= "tcp_syn_retries",
 897		.data		= &init_net.ipv4.sysctl_tcp_syn_retries,
 898		.maxlen		= sizeof(int),
 899		.mode		= 0644,
 900		.proc_handler	= proc_dointvec_minmax,
 901		.extra1		= &tcp_syn_retries_min,
 902		.extra2		= &tcp_syn_retries_max
 903	},
 904	{
 905		.procname	= "tcp_synack_retries",
 906		.data		= &init_net.ipv4.sysctl_tcp_synack_retries,
 907		.maxlen		= sizeof(int),
 908		.mode		= 0644,
 909		.proc_handler	= proc_dointvec
 910	},
 911#ifdef CONFIG_SYN_COOKIES
 912	{
 913		.procname	= "tcp_syncookies",
 914		.data		= &init_net.ipv4.sysctl_tcp_syncookies,
 915		.maxlen		= sizeof(int),
 916		.mode		= 0644,
 917		.proc_handler	= proc_dointvec
 918	},
 919#endif
 920	{
 921		.procname	= "tcp_reordering",
 922		.data		= &init_net.ipv4.sysctl_tcp_reordering,
 923		.maxlen		= sizeof(int),
 924		.mode		= 0644,
 925		.proc_handler	= proc_dointvec
 926	},
 927	{
 928		.procname	= "tcp_retries1",
 929		.data		= &init_net.ipv4.sysctl_tcp_retries1,
 930		.maxlen		= sizeof(int),
 931		.mode		= 0644,
 932		.proc_handler	= proc_dointvec_minmax,
 933		.extra2		= &tcp_retr1_max
 934	},
 935	{
 936		.procname	= "tcp_retries2",
 937		.data		= &init_net.ipv4.sysctl_tcp_retries2,
 938		.maxlen		= sizeof(int),
 939		.mode		= 0644,
 940		.proc_handler	= proc_dointvec
 941	},
 942	{
 943		.procname	= "tcp_orphan_retries",
 944		.data		= &init_net.ipv4.sysctl_tcp_orphan_retries,
 945		.maxlen		= sizeof(int),
 946		.mode		= 0644,
 947		.proc_handler	= proc_dointvec
 948	},
 949	{
 950		.procname	= "tcp_fin_timeout",
 951		.data		= &init_net.ipv4.sysctl_tcp_fin_timeout,
 952		.maxlen		= sizeof(int),
 953		.mode		= 0644,
 954		.proc_handler	= proc_dointvec_jiffies,
 955	},
 956	{
 957		.procname	= "tcp_notsent_lowat",
 958		.data		= &init_net.ipv4.sysctl_tcp_notsent_lowat,
 959		.maxlen		= sizeof(unsigned int),
 960		.mode		= 0644,
 961		.proc_handler	= proc_dointvec,
 962	},
 963	{ }
 964};
 965
 
 
 
 
 
 
 
 966static __net_init int ipv4_sysctl_init_net(struct net *net)
 967{
 968	struct ctl_table *table;
 969
 970	table = ipv4_net_table;
 971	if (!net_eq(net, &init_net)) {
 972		int i;
 973
 974		table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
 975		if (!table)
 976			goto err_alloc;
 977
 978		/* Update the variables to point into the current struct net */
 979		for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++)
 980			table[i].data += (void *)net - (void *)&init_net;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 981	}
 982
 983	net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
 984	if (!net->ipv4.ipv4_hdr)
 
 
 
 
 
 
 
 
 
 
 985		goto err_reg;
 986
 987	net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
 988	if (!net->ipv4.sysctl_local_reserved_ports)
 989		goto err_ports;
 990
 991	net->ipv4.sysctl_ip_default_ttl = IPDEFTTL;
 992	net->ipv4.sysctl_ip_dynaddr = 0;
 993	net->ipv4.sysctl_ip_early_demux = 1;
 994
 995	return 0;
 996
 997err_ports:
 998	unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
 999err_reg:
1000	if (!net_eq(net, &init_net))
1001		kfree(table);
1002err_alloc:
1003	return -ENOMEM;
1004}
1005
1006static __net_exit void ipv4_sysctl_exit_net(struct net *net)
1007{
1008	struct ctl_table *table;
1009
1010	kfree(net->ipv4.sysctl_local_reserved_ports);
1011	table = net->ipv4.ipv4_hdr->ctl_table_arg;
1012	unregister_net_sysctl_table(net->ipv4.ipv4_hdr);
1013	kfree(table);
1014}
1015
1016static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
1017	.init = ipv4_sysctl_init_net,
1018	.exit = ipv4_sysctl_exit_net,
1019};
1020
1021static __init int sysctl_ipv4_init(void)
1022{
1023	struct ctl_table_header *hdr;
 
 
 
 
 
 
 
 
 
 
1024
1025	hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
1026	if (!hdr)
1027		return -ENOMEM;
1028
1029	if (register_pernet_subsys(&ipv4_sysctl_ops)) {
1030		unregister_net_sysctl_table(hdr);
1031		return -ENOMEM;
1032	}
1033
1034	return 0;
1035}
1036
1037__initcall(sysctl_ipv4_init);