Linux Audio

Check our new training course

Loading...
v3.1
  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/ratelimit.h>
 14#include <linux/vmalloc.h>
 15#include <linux/init.h>
 16#include <linux/slab.h>
 
 17
 18#include <net/ip.h>
 19#include <net/sock.h>
 20#include <net/net_ratelimit.h>
 
 
 
 
 
 
 
 
 
 
 21
 22#ifdef CONFIG_RPS
 23static int rps_sock_flow_sysctl(ctl_table *table, int write,
 24				void __user *buffer, size_t *lenp, loff_t *ppos)
 25{
 26	unsigned int orig_size, size;
 27	int ret, i;
 28	ctl_table tmp = {
 29		.data = &size,
 30		.maxlen = sizeof(size),
 31		.mode = table->mode
 32	};
 33	struct rps_sock_flow_table *orig_sock_table, *sock_table;
 34	static DEFINE_MUTEX(sock_flow_mutex);
 35
 36	mutex_lock(&sock_flow_mutex);
 37
 38	orig_sock_table = rcu_dereference_protected(rps_sock_flow_table,
 39					lockdep_is_held(&sock_flow_mutex));
 40	size = orig_size = orig_sock_table ? orig_sock_table->mask + 1 : 0;
 41
 42	ret = proc_dointvec(&tmp, write, buffer, lenp, ppos);
 43
 44	if (write) {
 45		if (size) {
 46			if (size > 1<<30) {
 47				/* Enforce limit to prevent overflow */
 48				mutex_unlock(&sock_flow_mutex);
 49				return -EINVAL;
 50			}
 51			size = roundup_pow_of_two(size);
 52			if (size != orig_size) {
 53				sock_table =
 54				    vmalloc(RPS_SOCK_FLOW_TABLE_SIZE(size));
 55				if (!sock_table) {
 56					mutex_unlock(&sock_flow_mutex);
 57					return -ENOMEM;
 58				}
 59
 60				sock_table->mask = size - 1;
 61			} else
 62				sock_table = orig_sock_table;
 63
 64			for (i = 0; i < size; i++)
 65				sock_table->ents[i] = RPS_NO_CPU;
 66		} else
 67			sock_table = NULL;
 68
 69		if (sock_table != orig_sock_table) {
 70			rcu_assign_pointer(rps_sock_flow_table, sock_table);
 71			synchronize_rcu();
 72			vfree(orig_sock_table);
 
 
 
 
 
 
 
 
 73		}
 74	}
 75
 76	mutex_unlock(&sock_flow_mutex);
 77
 78	return ret;
 79}
 80#endif /* CONFIG_RPS */
 81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 82static struct ctl_table net_core_table[] = {
 83#ifdef CONFIG_NET
 84	{
 85		.procname	= "wmem_max",
 86		.data		= &sysctl_wmem_max,
 87		.maxlen		= sizeof(int),
 88		.mode		= 0644,
 89		.proc_handler	= proc_dointvec
 
 90	},
 91	{
 92		.procname	= "rmem_max",
 93		.data		= &sysctl_rmem_max,
 94		.maxlen		= sizeof(int),
 95		.mode		= 0644,
 96		.proc_handler	= proc_dointvec
 
 97	},
 98	{
 99		.procname	= "wmem_default",
100		.data		= &sysctl_wmem_default,
101		.maxlen		= sizeof(int),
102		.mode		= 0644,
103		.proc_handler	= proc_dointvec
 
104	},
105	{
106		.procname	= "rmem_default",
107		.data		= &sysctl_rmem_default,
108		.maxlen		= sizeof(int),
109		.mode		= 0644,
110		.proc_handler	= proc_dointvec
 
111	},
112	{
113		.procname	= "dev_weight",
114		.data		= &weight_p,
115		.maxlen		= sizeof(int),
116		.mode		= 0644,
117		.proc_handler	= proc_dointvec
118	},
119	{
120		.procname	= "netdev_max_backlog",
121		.data		= &netdev_max_backlog,
122		.maxlen		= sizeof(int),
123		.mode		= 0644,
124		.proc_handler	= proc_dointvec
125	},
 
 
 
 
 
 
 
126#ifdef CONFIG_BPF_JIT
127	{
128		.procname	= "bpf_jit_enable",
129		.data		= &bpf_jit_enable,
130		.maxlen		= sizeof(int),
131		.mode		= 0644,
132		.proc_handler	= proc_dointvec
133	},
 
 
 
 
 
 
 
 
 
134#endif
135	{
136		.procname	= "netdev_tstamp_prequeue",
137		.data		= &netdev_tstamp_prequeue,
138		.maxlen		= sizeof(int),
139		.mode		= 0644,
140		.proc_handler	= proc_dointvec
141	},
142	{
143		.procname	= "message_cost",
144		.data		= &net_ratelimit_state.interval,
145		.maxlen		= sizeof(int),
146		.mode		= 0644,
147		.proc_handler	= proc_dointvec_jiffies,
148	},
149	{
150		.procname	= "message_burst",
151		.data		= &net_ratelimit_state.burst,
152		.maxlen		= sizeof(int),
153		.mode		= 0644,
154		.proc_handler	= proc_dointvec,
155	},
156	{
157		.procname	= "optmem_max",
158		.data		= &sysctl_optmem_max,
159		.maxlen		= sizeof(int),
160		.mode		= 0644,
161		.proc_handler	= proc_dointvec
162	},
 
 
 
 
 
 
 
 
 
163#ifdef CONFIG_RPS
164	{
165		.procname	= "rps_sock_flow_entries",
166		.maxlen		= sizeof(int),
167		.mode		= 0644,
168		.proc_handler	= rps_sock_flow_sysctl
169	},
170#endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171#endif /* CONFIG_NET */
172	{
173		.procname	= "netdev_budget",
174		.data		= &netdev_budget,
175		.maxlen		= sizeof(int),
176		.mode		= 0644,
177		.proc_handler	= proc_dointvec
178	},
179	{
180		.procname	= "warnings",
181		.data		= &net_msg_warn,
182		.maxlen		= sizeof(int),
183		.mode		= 0644,
184		.proc_handler	= proc_dointvec
185	},
 
 
 
 
 
 
 
 
 
186	{ }
187};
188
189static struct ctl_table netns_core_table[] = {
190	{
191		.procname	= "somaxconn",
192		.data		= &init_net.core.sysctl_somaxconn,
193		.maxlen		= sizeof(int),
194		.mode		= 0644,
195		.proc_handler	= proc_dointvec
 
196	},
197	{ }
198};
199
200__net_initdata struct ctl_path net_core_path[] = {
201	{ .procname = "net", },
202	{ .procname = "core", },
203	{ },
204};
205
206static __net_init int sysctl_core_net_init(struct net *net)
207{
208	struct ctl_table *tbl;
209
210	net->core.sysctl_somaxconn = SOMAXCONN;
211
212	tbl = netns_core_table;
213	if (!net_eq(net, &init_net)) {
214		tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
215		if (tbl == NULL)
216			goto err_dup;
217
218		tbl[0].data = &net->core.sysctl_somaxconn;
 
 
 
 
 
219	}
220
221	net->core.sysctl_hdr = register_net_sysctl_table(net,
222			net_core_path, tbl);
223	if (net->core.sysctl_hdr == NULL)
224		goto err_reg;
225
226	return 0;
227
228err_reg:
229	if (tbl != netns_core_table)
230		kfree(tbl);
231err_dup:
232	return -ENOMEM;
233}
234
235static __net_exit void sysctl_core_net_exit(struct net *net)
236{
237	struct ctl_table *tbl;
238
239	tbl = net->core.sysctl_hdr->ctl_table_arg;
240	unregister_net_sysctl_table(net->core.sysctl_hdr);
241	BUG_ON(tbl == netns_core_table);
242	kfree(tbl);
243}
244
245static __net_initdata struct pernet_operations sysctl_core_ops = {
246	.init = sysctl_core_net_init,
247	.exit = sysctl_core_net_exit,
248};
249
250static __init int sysctl_core_init(void)
251{
252	static struct ctl_table empty[1];
253
254	register_sysctl_paths(net_core_path, empty);
255	register_net_sysctl_rotable(net_core_path, net_core_table);
256	return register_pernet_subsys(&sysctl_core_ops);
257}
258
259fs_initcall(sysctl_core_init);
v4.10.11
  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/ratelimit.h>
 14#include <linux/vmalloc.h>
 15#include <linux/init.h>
 16#include <linux/slab.h>
 17#include <linux/kmemleak.h>
 18
 19#include <net/ip.h>
 20#include <net/sock.h>
 21#include <net/net_ratelimit.h>
 22#include <net/busy_poll.h>
 23#include <net/pkt_sched.h>
 24
 25static int zero = 0;
 26static int one = 1;
 27static int min_sndbuf = SOCK_MIN_SNDBUF;
 28static int min_rcvbuf = SOCK_MIN_RCVBUF;
 29static int max_skb_frags = MAX_SKB_FRAGS;
 30
 31static int net_msg_warn;	/* Unused, but still a sysctl */
 32
 33#ifdef CONFIG_RPS
 34static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
 35				void __user *buffer, size_t *lenp, loff_t *ppos)
 36{
 37	unsigned int orig_size, size;
 38	int ret, i;
 39	struct ctl_table tmp = {
 40		.data = &size,
 41		.maxlen = sizeof(size),
 42		.mode = table->mode
 43	};
 44	struct rps_sock_flow_table *orig_sock_table, *sock_table;
 45	static DEFINE_MUTEX(sock_flow_mutex);
 46
 47	mutex_lock(&sock_flow_mutex);
 48
 49	orig_sock_table = rcu_dereference_protected(rps_sock_flow_table,
 50					lockdep_is_held(&sock_flow_mutex));
 51	size = orig_size = orig_sock_table ? orig_sock_table->mask + 1 : 0;
 52
 53	ret = proc_dointvec(&tmp, write, buffer, lenp, ppos);
 54
 55	if (write) {
 56		if (size) {
 57			if (size > 1<<29) {
 58				/* Enforce limit to prevent overflow */
 59				mutex_unlock(&sock_flow_mutex);
 60				return -EINVAL;
 61			}
 62			size = roundup_pow_of_two(size);
 63			if (size != orig_size) {
 64				sock_table =
 65				    vmalloc(RPS_SOCK_FLOW_TABLE_SIZE(size));
 66				if (!sock_table) {
 67					mutex_unlock(&sock_flow_mutex);
 68					return -ENOMEM;
 69				}
 70				rps_cpu_mask = roundup_pow_of_two(nr_cpu_ids) - 1;
 71				sock_table->mask = size - 1;
 72			} else
 73				sock_table = orig_sock_table;
 74
 75			for (i = 0; i < size; i++)
 76				sock_table->ents[i] = RPS_NO_CPU;
 77		} else
 78			sock_table = NULL;
 79
 80		if (sock_table != orig_sock_table) {
 81			rcu_assign_pointer(rps_sock_flow_table, sock_table);
 82			if (sock_table) {
 83				static_key_slow_inc(&rps_needed);
 84				static_key_slow_inc(&rfs_needed);
 85			}
 86			if (orig_sock_table) {
 87				static_key_slow_dec(&rps_needed);
 88				static_key_slow_dec(&rfs_needed);
 89				synchronize_rcu();
 90				vfree(orig_sock_table);
 91			}
 92		}
 93	}
 94
 95	mutex_unlock(&sock_flow_mutex);
 96
 97	return ret;
 98}
 99#endif /* CONFIG_RPS */
100
101#ifdef CONFIG_NET_FLOW_LIMIT
102static DEFINE_MUTEX(flow_limit_update_mutex);
103
104static int flow_limit_cpu_sysctl(struct ctl_table *table, int write,
105				 void __user *buffer, size_t *lenp,
106				 loff_t *ppos)
107{
108	struct sd_flow_limit *cur;
109	struct softnet_data *sd;
110	cpumask_var_t mask;
111	int i, len, ret = 0;
112
113	if (!alloc_cpumask_var(&mask, GFP_KERNEL))
114		return -ENOMEM;
115
116	if (write) {
117		ret = cpumask_parse_user(buffer, *lenp, mask);
118		if (ret)
119			goto done;
120
121		mutex_lock(&flow_limit_update_mutex);
122		len = sizeof(*cur) + netdev_flow_limit_table_len;
123		for_each_possible_cpu(i) {
124			sd = &per_cpu(softnet_data, i);
125			cur = rcu_dereference_protected(sd->flow_limit,
126				     lockdep_is_held(&flow_limit_update_mutex));
127			if (cur && !cpumask_test_cpu(i, mask)) {
128				RCU_INIT_POINTER(sd->flow_limit, NULL);
129				synchronize_rcu();
130				kfree(cur);
131			} else if (!cur && cpumask_test_cpu(i, mask)) {
132				cur = kzalloc_node(len, GFP_KERNEL,
133						   cpu_to_node(i));
134				if (!cur) {
135					/* not unwinding previous changes */
136					ret = -ENOMEM;
137					goto write_unlock;
138				}
139				cur->num_buckets = netdev_flow_limit_table_len;
140				rcu_assign_pointer(sd->flow_limit, cur);
141			}
142		}
143write_unlock:
144		mutex_unlock(&flow_limit_update_mutex);
145	} else {
146		char kbuf[128];
147
148		if (*ppos || !*lenp) {
149			*lenp = 0;
150			goto done;
151		}
152
153		cpumask_clear(mask);
154		rcu_read_lock();
155		for_each_possible_cpu(i) {
156			sd = &per_cpu(softnet_data, i);
157			if (rcu_dereference(sd->flow_limit))
158				cpumask_set_cpu(i, mask);
159		}
160		rcu_read_unlock();
161
162		len = min(sizeof(kbuf) - 1, *lenp);
163		len = scnprintf(kbuf, len, "%*pb", cpumask_pr_args(mask));
164		if (!len) {
165			*lenp = 0;
166			goto done;
167		}
168		if (len < *lenp)
169			kbuf[len++] = '\n';
170		if (copy_to_user(buffer, kbuf, len)) {
171			ret = -EFAULT;
172			goto done;
173		}
174		*lenp = len;
175		*ppos += len;
176	}
177
178done:
179	free_cpumask_var(mask);
180	return ret;
181}
182
183static int flow_limit_table_len_sysctl(struct ctl_table *table, int write,
184				       void __user *buffer, size_t *lenp,
185				       loff_t *ppos)
186{
187	unsigned int old, *ptr;
188	int ret;
189
190	mutex_lock(&flow_limit_update_mutex);
191
192	ptr = table->data;
193	old = *ptr;
194	ret = proc_dointvec(table, write, buffer, lenp, ppos);
195	if (!ret && write && !is_power_of_2(*ptr)) {
196		*ptr = old;
197		ret = -EINVAL;
198	}
199
200	mutex_unlock(&flow_limit_update_mutex);
201	return ret;
202}
203#endif /* CONFIG_NET_FLOW_LIMIT */
204
205#ifdef CONFIG_NET_SCHED
206static int set_default_qdisc(struct ctl_table *table, int write,
207			     void __user *buffer, size_t *lenp, loff_t *ppos)
208{
209	char id[IFNAMSIZ];
210	struct ctl_table tbl = {
211		.data = id,
212		.maxlen = IFNAMSIZ,
213	};
214	int ret;
215
216	qdisc_get_default(id, IFNAMSIZ);
217
218	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
219	if (write && ret == 0)
220		ret = qdisc_set_default(id);
221	return ret;
222}
223#endif
224
225static int proc_do_rss_key(struct ctl_table *table, int write,
226			   void __user *buffer, size_t *lenp, loff_t *ppos)
227{
228	struct ctl_table fake_table;
229	char buf[NETDEV_RSS_KEY_LEN * 3];
230
231	snprintf(buf, sizeof(buf), "%*phC", NETDEV_RSS_KEY_LEN, netdev_rss_key);
232	fake_table.data = buf;
233	fake_table.maxlen = sizeof(buf);
234	return proc_dostring(&fake_table, write, buffer, lenp, ppos);
235}
236
237static struct ctl_table net_core_table[] = {
238#ifdef CONFIG_NET
239	{
240		.procname	= "wmem_max",
241		.data		= &sysctl_wmem_max,
242		.maxlen		= sizeof(int),
243		.mode		= 0644,
244		.proc_handler	= proc_dointvec_minmax,
245		.extra1		= &min_sndbuf,
246	},
247	{
248		.procname	= "rmem_max",
249		.data		= &sysctl_rmem_max,
250		.maxlen		= sizeof(int),
251		.mode		= 0644,
252		.proc_handler	= proc_dointvec_minmax,
253		.extra1		= &min_rcvbuf,
254	},
255	{
256		.procname	= "wmem_default",
257		.data		= &sysctl_wmem_default,
258		.maxlen		= sizeof(int),
259		.mode		= 0644,
260		.proc_handler	= proc_dointvec_minmax,
261		.extra1		= &min_sndbuf,
262	},
263	{
264		.procname	= "rmem_default",
265		.data		= &sysctl_rmem_default,
266		.maxlen		= sizeof(int),
267		.mode		= 0644,
268		.proc_handler	= proc_dointvec_minmax,
269		.extra1		= &min_rcvbuf,
270	},
271	{
272		.procname	= "dev_weight",
273		.data		= &weight_p,
274		.maxlen		= sizeof(int),
275		.mode		= 0644,
276		.proc_handler	= proc_dointvec
277	},
278	{
279		.procname	= "netdev_max_backlog",
280		.data		= &netdev_max_backlog,
281		.maxlen		= sizeof(int),
282		.mode		= 0644,
283		.proc_handler	= proc_dointvec
284	},
285	{
286		.procname	= "netdev_rss_key",
287		.data		= &netdev_rss_key,
288		.maxlen		= sizeof(int),
289		.mode		= 0444,
290		.proc_handler	= proc_do_rss_key,
291	},
292#ifdef CONFIG_BPF_JIT
293	{
294		.procname	= "bpf_jit_enable",
295		.data		= &bpf_jit_enable,
296		.maxlen		= sizeof(int),
297		.mode		= 0644,
298		.proc_handler	= proc_dointvec
299	},
300# ifdef CONFIG_HAVE_EBPF_JIT
301	{
302		.procname	= "bpf_jit_harden",
303		.data		= &bpf_jit_harden,
304		.maxlen		= sizeof(int),
305		.mode		= 0600,
306		.proc_handler	= proc_dointvec,
307	},
308# endif
309#endif
310	{
311		.procname	= "netdev_tstamp_prequeue",
312		.data		= &netdev_tstamp_prequeue,
313		.maxlen		= sizeof(int),
314		.mode		= 0644,
315		.proc_handler	= proc_dointvec
316	},
317	{
318		.procname	= "message_cost",
319		.data		= &net_ratelimit_state.interval,
320		.maxlen		= sizeof(int),
321		.mode		= 0644,
322		.proc_handler	= proc_dointvec_jiffies,
323	},
324	{
325		.procname	= "message_burst",
326		.data		= &net_ratelimit_state.burst,
327		.maxlen		= sizeof(int),
328		.mode		= 0644,
329		.proc_handler	= proc_dointvec,
330	},
331	{
332		.procname	= "optmem_max",
333		.data		= &sysctl_optmem_max,
334		.maxlen		= sizeof(int),
335		.mode		= 0644,
336		.proc_handler	= proc_dointvec
337	},
338	{
339		.procname	= "tstamp_allow_data",
340		.data		= &sysctl_tstamp_allow_data,
341		.maxlen		= sizeof(int),
342		.mode		= 0644,
343		.proc_handler	= proc_dointvec_minmax,
344		.extra1		= &zero,
345		.extra2		= &one
346	},
347#ifdef CONFIG_RPS
348	{
349		.procname	= "rps_sock_flow_entries",
350		.maxlen		= sizeof(int),
351		.mode		= 0644,
352		.proc_handler	= rps_sock_flow_sysctl
353	},
354#endif
355#ifdef CONFIG_NET_FLOW_LIMIT
356	{
357		.procname	= "flow_limit_cpu_bitmap",
358		.mode		= 0644,
359		.proc_handler	= flow_limit_cpu_sysctl
360	},
361	{
362		.procname	= "flow_limit_table_len",
363		.data		= &netdev_flow_limit_table_len,
364		.maxlen		= sizeof(int),
365		.mode		= 0644,
366		.proc_handler	= flow_limit_table_len_sysctl
367	},
368#endif /* CONFIG_NET_FLOW_LIMIT */
369#ifdef CONFIG_NET_RX_BUSY_POLL
370	{
371		.procname	= "busy_poll",
372		.data		= &sysctl_net_busy_poll,
373		.maxlen		= sizeof(unsigned int),
374		.mode		= 0644,
375		.proc_handler	= proc_dointvec
376	},
377	{
378		.procname	= "busy_read",
379		.data		= &sysctl_net_busy_read,
380		.maxlen		= sizeof(unsigned int),
381		.mode		= 0644,
382		.proc_handler	= proc_dointvec
383	},
384#endif
385#ifdef CONFIG_NET_SCHED
386	{
387		.procname	= "default_qdisc",
388		.mode		= 0644,
389		.maxlen		= IFNAMSIZ,
390		.proc_handler	= set_default_qdisc
391	},
392#endif
393#endif /* CONFIG_NET */
394	{
395		.procname	= "netdev_budget",
396		.data		= &netdev_budget,
397		.maxlen		= sizeof(int),
398		.mode		= 0644,
399		.proc_handler	= proc_dointvec
400	},
401	{
402		.procname	= "warnings",
403		.data		= &net_msg_warn,
404		.maxlen		= sizeof(int),
405		.mode		= 0644,
406		.proc_handler	= proc_dointvec
407	},
408	{
409		.procname	= "max_skb_frags",
410		.data		= &sysctl_max_skb_frags,
411		.maxlen		= sizeof(int),
412		.mode		= 0644,
413		.proc_handler	= proc_dointvec_minmax,
414		.extra1		= &one,
415		.extra2		= &max_skb_frags,
416	},
417	{ }
418};
419
420static struct ctl_table netns_core_table[] = {
421	{
422		.procname	= "somaxconn",
423		.data		= &init_net.core.sysctl_somaxconn,
424		.maxlen		= sizeof(int),
425		.mode		= 0644,
426		.extra1		= &zero,
427		.proc_handler	= proc_dointvec_minmax
428	},
429	{ }
430};
431
 
 
 
 
 
 
432static __net_init int sysctl_core_net_init(struct net *net)
433{
434	struct ctl_table *tbl;
435
436	net->core.sysctl_somaxconn = SOMAXCONN;
437
438	tbl = netns_core_table;
439	if (!net_eq(net, &init_net)) {
440		tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
441		if (tbl == NULL)
442			goto err_dup;
443
444		tbl[0].data = &net->core.sysctl_somaxconn;
445
446		/* Don't export any sysctls to unprivileged users */
447		if (net->user_ns != &init_user_ns) {
448			tbl[0].procname = NULL;
449		}
450	}
451
452	net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
 
453	if (net->core.sysctl_hdr == NULL)
454		goto err_reg;
455
456	return 0;
457
458err_reg:
459	if (tbl != netns_core_table)
460		kfree(tbl);
461err_dup:
462	return -ENOMEM;
463}
464
465static __net_exit void sysctl_core_net_exit(struct net *net)
466{
467	struct ctl_table *tbl;
468
469	tbl = net->core.sysctl_hdr->ctl_table_arg;
470	unregister_net_sysctl_table(net->core.sysctl_hdr);
471	BUG_ON(tbl == netns_core_table);
472	kfree(tbl);
473}
474
475static __net_initdata struct pernet_operations sysctl_core_ops = {
476	.init = sysctl_core_net_init,
477	.exit = sysctl_core_net_exit,
478};
479
480static __init int sysctl_core_init(void)
481{
482	register_net_sysctl(&init_net, "net/core", net_core_table);
 
 
 
483	return register_pernet_subsys(&sysctl_core_ops);
484}
485
486fs_initcall(sysctl_core_init);