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/ratelimit.h>
14
#include <linux/init.h>
15

16
#include <net/ip.h>
17
#include <net/sock.h>
L
Linus Torvalds 已提交
18

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

114 115 116 117 118 119 120
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 已提交
121
		.proc_handler	= proc_dointvec
122 123 124 125
	},
	{ .ctl_name = 0 }
};

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

132
static __net_init int sysctl_core_net_init(struct net *net)
133
{
134
	struct ctl_table *tbl;
135

136
	net->core.sysctl_somaxconn = SOMAXCONN;
137

138
	tbl = netns_core_table;
139
	if (net != &init_net) {
140
		tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
141 142 143
		if (tbl == NULL)
			goto err_dup;

144
		tbl[0].data = &net->core.sysctl_somaxconn;
145 146
	}

147
	net->core.sysctl_hdr = register_net_sysctl_table(net,
148
			net_core_path, tbl);
149
	if (net->core.sysctl_hdr == NULL)
150
		goto err_reg;
151

152 153 154
	return 0;

err_reg:
155
	if (tbl != netns_core_table)
156 157 158 159 160 161 162 163 164
		kfree(tbl);
err_dup:
	return -ENOMEM;
}

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

165 166
	tbl = net->core.sysctl_hdr->ctl_table_arg;
	unregister_net_sysctl_table(net->core.sysctl_hdr);
167
	BUG_ON(tbl == netns_core_table);
168 169 170 171 172 173 174 175 176 177
	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 已提交
178 179 180
	static struct ctl_table empty[1];

	register_sysctl_paths(net_core_path, empty);
181
	register_net_sysctl_rotable(net_core_path, net_core_table);
182
	return register_pernet_subsys(&sysctl_core_ops);
183 184
}

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