• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*- linux-c -*-
2  * sysctl_net_core.c: sysctl interface to net core subsystem.
3  *
4  * Begun April 1, 1996, Mike Shaver.
5  * Added /proc/sys/net/core directory entry (empty =) ). [MS]
6  */
7 
8 #include <linux/mm.h>
9 #include <linux/sysctl.h>
10 #include <linux/module.h>
11 #include <linux/socket.h>
12 #include <linux/netdevice.h>
13 #include <linux/init.h>
14 #include <net/sock.h>
15 
16 static struct ctl_table net_core_table[] = {
17 #ifdef CONFIG_NET
18 	{
19 		.ctl_name	= NET_CORE_WMEM_MAX,
20 		.procname	= "wmem_max",
21 		.data		= &sysctl_wmem_max,
22 		.maxlen		= sizeof(int),
23 		.mode		= 0644,
24 		.proc_handler	= proc_dointvec
25 	},
26 	{
27 		.ctl_name	= NET_CORE_RMEM_MAX,
28 		.procname	= "rmem_max",
29 		.data		= &sysctl_rmem_max,
30 		.maxlen		= sizeof(int),
31 		.mode		= 0644,
32 		.proc_handler	= proc_dointvec
33 	},
34 	{
35 		.ctl_name	= NET_CORE_WMEM_DEFAULT,
36 		.procname	= "wmem_default",
37 		.data		= &sysctl_wmem_default,
38 		.maxlen		= sizeof(int),
39 		.mode		= 0644,
40 		.proc_handler	= proc_dointvec
41 	},
42 	{
43 		.ctl_name	= NET_CORE_RMEM_DEFAULT,
44 		.procname	= "rmem_default",
45 		.data		= &sysctl_rmem_default,
46 		.maxlen		= sizeof(int),
47 		.mode		= 0644,
48 		.proc_handler	= proc_dointvec
49 	},
50 	{
51 		.ctl_name	= NET_CORE_DEV_WEIGHT,
52 		.procname	= "dev_weight",
53 		.data		= &weight_p,
54 		.maxlen		= sizeof(int),
55 		.mode		= 0644,
56 		.proc_handler	= proc_dointvec
57 	},
58 	{
59 		.ctl_name	= NET_CORE_MAX_BACKLOG,
60 		.procname	= "netdev_max_backlog",
61 		.data		= &netdev_max_backlog,
62 		.maxlen		= sizeof(int),
63 		.mode		= 0644,
64 		.proc_handler	= proc_dointvec
65 	},
66 	{
67 		.ctl_name	= NET_CORE_MSG_COST,
68 		.procname	= "message_cost",
69 		.data		= &net_ratelimit_state.interval,
70 		.maxlen		= sizeof(int),
71 		.mode		= 0644,
72 		.proc_handler	= proc_dointvec_jiffies,
73 		.strategy	= sysctl_jiffies,
74 	},
75 	{
76 		.ctl_name	= NET_CORE_MSG_BURST,
77 		.procname	= "message_burst",
78 		.data		= &net_ratelimit_state.burst,
79 		.maxlen		= sizeof(int),
80 		.mode		= 0644,
81 		.proc_handler	= proc_dointvec,
82 	},
83 	{
84 		.ctl_name	= NET_CORE_OPTMEM_MAX,
85 		.procname	= "optmem_max",
86 		.data		= &sysctl_optmem_max,
87 		.maxlen		= sizeof(int),
88 		.mode		= 0644,
89 		.proc_handler	= proc_dointvec
90 	},
91 #endif /* CONFIG_NET */
92 	{
93 		.ctl_name	= NET_CORE_BUDGET,
94 		.procname	= "netdev_budget",
95 		.data		= &netdev_budget,
96 		.maxlen		= sizeof(int),
97 		.mode		= 0644,
98 		.proc_handler	= proc_dointvec
99 	},
100 	{
101 		.ctl_name	= NET_CORE_WARNINGS,
102 		.procname	= "warnings",
103 		.data		= &net_msg_warn,
104 		.maxlen		= sizeof(int),
105 		.mode		= 0644,
106 		.proc_handler	= proc_dointvec
107 	},
108 	{ .ctl_name = 0 }
109 };
110 
111 static struct ctl_table netns_core_table[] = {
112 	{
113 		.ctl_name	= NET_CORE_SOMAXCONN,
114 		.procname	= "somaxconn",
115 		.data		= &init_net.core.sysctl_somaxconn,
116 		.maxlen		= sizeof(int),
117 		.mode		= 0644,
118 		.proc_handler	= proc_dointvec
119 	},
120 	{ .ctl_name = 0 }
121 };
122 
123 __net_initdata struct ctl_path net_core_path[] = {
124 	{ .procname = "net", .ctl_name = CTL_NET, },
125 	{ .procname = "core", .ctl_name = NET_CORE, },
126 	{ },
127 };
128 
sysctl_core_net_init(struct net * net)129 static __net_init int sysctl_core_net_init(struct net *net)
130 {
131 	struct ctl_table *tbl;
132 
133 	net->core.sysctl_somaxconn = SOMAXCONN;
134 
135 	tbl = netns_core_table;
136 	if (net != &init_net) {
137 		tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
138 		if (tbl == NULL)
139 			goto err_dup;
140 
141 		tbl[0].data = &net->core.sysctl_somaxconn;
142 	}
143 
144 	net->core.sysctl_hdr = register_net_sysctl_table(net,
145 			net_core_path, tbl);
146 	if (net->core.sysctl_hdr == NULL)
147 		goto err_reg;
148 
149 	return 0;
150 
151 err_reg:
152 	if (tbl != netns_core_table)
153 		kfree(tbl);
154 err_dup:
155 	return -ENOMEM;
156 }
157 
sysctl_core_net_exit(struct net * net)158 static __net_exit void sysctl_core_net_exit(struct net *net)
159 {
160 	struct ctl_table *tbl;
161 
162 	tbl = net->core.sysctl_hdr->ctl_table_arg;
163 	unregister_net_sysctl_table(net->core.sysctl_hdr);
164 	BUG_ON(tbl == netns_core_table);
165 	kfree(tbl);
166 }
167 
168 static __net_initdata struct pernet_operations sysctl_core_ops = {
169 	.init = sysctl_core_net_init,
170 	.exit = sysctl_core_net_exit,
171 };
172 
sysctl_core_init(void)173 static __init int sysctl_core_init(void)
174 {
175 	static struct ctl_table empty[1];
176 
177 	register_sysctl_paths(net_core_path, empty);
178 	register_net_sysctl_rotable(net_core_path, net_core_table);
179 	return register_pernet_subsys(&sysctl_core_ops);
180 }
181 
182 fs_initcall(sysctl_core_init);
183