sysctl_net_core.c 4.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10
/* -*- linux-c -*-
 * sysctl_net_core.c: sysctl interface to net core subsystem.
 *
 * Begun April 1, 1996, Mike Shaver.
 * Added /proc/sys/net/core directory entry (empty =) ). [MS]
 */

#include <linux/mm.h>
#include <linux/sysctl.h>
#include <linux/module.h>
11
#include <linux/socket.h>
12
#include <linux/netdevice.h>
13
#include <linux/init.h>
14
#include <net/sock.h>
L
Linus Torvalds 已提交
15

16
static struct ctl_table net_core_table[] = {
L
Linus Torvalds 已提交
17 18 19 20 21 22 23
#ifdef CONFIG_NET
	{
		.ctl_name	= NET_CORE_WMEM_MAX,
		.procname	= "wmem_max",
		.data		= &sysctl_wmem_max,
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
24
		.proc_handler	= proc_dointvec
L
Linus Torvalds 已提交
25 26 27 28 29 30 31
	},
	{
		.ctl_name	= NET_CORE_RMEM_MAX,
		.procname	= "rmem_max",
		.data		= &sysctl_rmem_max,
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
32
		.proc_handler	= proc_dointvec
L
Linus Torvalds 已提交
33 34 35 36 37 38 39
	},
	{
		.ctl_name	= NET_CORE_WMEM_DEFAULT,
		.procname	= "wmem_default",
		.data		= &sysctl_wmem_default,
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
40
		.proc_handler	= proc_dointvec
L
Linus Torvalds 已提交
41 42 43 44 45 46 47
	},
	{
		.ctl_name	= NET_CORE_RMEM_DEFAULT,
		.procname	= "rmem_default",
		.data		= &sysctl_rmem_default,
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
48
		.proc_handler	= proc_dointvec
L
Linus Torvalds 已提交
49 50 51 52 53 54 55
	},
	{
		.ctl_name	= NET_CORE_DEV_WEIGHT,
		.procname	= "dev_weight",
		.data		= &weight_p,
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
56
		.proc_handler	= proc_dointvec
L
Linus Torvalds 已提交
57 58 59 60 61 62 63
	},
	{
		.ctl_name	= NET_CORE_MAX_BACKLOG,
		.procname	= "netdev_max_backlog",
		.data		= &netdev_max_backlog,
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
64
		.proc_handler	= proc_dointvec
L
Linus Torvalds 已提交
65 66 67 68
	},
	{
		.ctl_name	= NET_CORE_MSG_COST,
		.procname	= "message_cost",
D
Dave Young 已提交
69
		.data		= &net_ratelimit_state.interval,
L
Linus Torvalds 已提交
70 71
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
72 73
		.proc_handler	= proc_dointvec_jiffies,
		.strategy	= sysctl_jiffies,
L
Linus Torvalds 已提交
74 75 76 77
	},
	{
		.ctl_name	= NET_CORE_MSG_BURST,
		.procname	= "message_burst",
D
Dave Young 已提交
78
		.data		= &net_ratelimit_state.burst,
L
Linus Torvalds 已提交
79 80
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
81
		.proc_handler	= proc_dointvec,
L
Linus Torvalds 已提交
82 83 84 85 86 87 88
	},
	{
		.ctl_name	= NET_CORE_OPTMEM_MAX,
		.procname	= "optmem_max",
		.data		= &sysctl_optmem_max,
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
89
		.proc_handler	= proc_dointvec
L
Linus Torvalds 已提交
90 91
	},
#endif /* CONFIG_NET */
92 93 94 95 96 97
	{
		.ctl_name	= NET_CORE_BUDGET,
		.procname	= "netdev_budget",
		.data		= &netdev_budget,
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
98
		.proc_handler	= proc_dointvec
99
	},
100 101 102 103 104 105
	{
		.ctl_name	= NET_CORE_WARNINGS,
		.procname	= "warnings",
		.data		= &net_msg_warn,
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
106
		.proc_handler	= proc_dointvec
107
	},
L
Linus Torvalds 已提交
108 109
	{ .ctl_name = 0 }
};
110

111 112 113 114 115 116 117
static struct ctl_table netns_core_table[] = {
	{
		.ctl_name	= NET_CORE_SOMAXCONN,
		.procname	= "somaxconn",
		.data		= &init_net.core.sysctl_somaxconn,
		.maxlen		= sizeof(int),
		.mode		= 0644,
A
Alexey Dobriyan 已提交
118
		.proc_handler	= proc_dointvec
119 120 121 122
	},
	{ .ctl_name = 0 }
};

A
Alexey Dobriyan 已提交
123
__net_initdata struct ctl_path net_core_path[] = {
124 125 126 127 128
	{ .procname = "net", .ctl_name = CTL_NET, },
	{ .procname = "core", .ctl_name = NET_CORE, },
	{ },
};

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 139 140
		if (tbl == NULL)
			goto err_dup;

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 150 151
	return 0;

err_reg:
152
	if (tbl != netns_core_table)
153 154 155 156 157 158 159 160 161
		kfree(tbl);
err_dup:
	return -ENOMEM;
}

static __net_exit void sysctl_core_net_exit(struct net *net)
{
	struct ctl_table *tbl;

162 163
	tbl = net->core.sysctl_hdr->ctl_table_arg;
	unregister_net_sysctl_table(net->core.sysctl_hdr);
164
	BUG_ON(tbl == netns_core_table);
165 166 167 168 169 170 171 172 173 174
	kfree(tbl);
}

static __net_initdata struct pernet_operations sysctl_core_ops = {
	.init = sysctl_core_net_init,
	.exit = sysctl_core_net_exit,
};

static __init int sysctl_core_init(void)
{
A
Alexey Dobriyan 已提交
175 176 177
	static struct ctl_table empty[1];

	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
}

A
Alexey Dobriyan 已提交
182
fs_initcall(sysctl_core_init);