2 * sysctl_net_core.c: sysctl interface to net core subsystem.
4 * Begun April 1, 1996, Mike Shaver.
5 * Added /proc/sys/net/core directory entry (empty =) ). [MS]
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>
22 static int rps_sock_flow_sysctl(ctl_table
*table
, int write
,
23 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
25 unsigned int orig_size
, size
;
29 .maxlen
= sizeof(size
),
32 struct rps_sock_flow_table
*orig_sock_table
, *sock_table
;
33 static DEFINE_MUTEX(sock_flow_mutex
);
35 mutex_lock(&sock_flow_mutex
);
37 orig_sock_table
= rps_sock_flow_table
;
38 size
= orig_size
= orig_sock_table
? orig_sock_table
->mask
+ 1 : 0;
40 ret
= proc_dointvec(&tmp
, write
, buffer
, lenp
, ppos
);
45 /* Enforce limit to prevent overflow */
46 mutex_unlock(&sock_flow_mutex
);
49 size
= roundup_pow_of_two(size
);
50 if (size
!= orig_size
) {
52 vmalloc(RPS_SOCK_FLOW_TABLE_SIZE(size
));
54 mutex_unlock(&sock_flow_mutex
);
58 sock_table
->mask
= size
- 1;
60 sock_table
= orig_sock_table
;
62 for (i
= 0; i
< size
; i
++)
63 sock_table
->ents
[i
] = RPS_NO_CPU
;
67 if (sock_table
!= orig_sock_table
) {
68 rcu_assign_pointer(rps_sock_flow_table
, sock_table
);
70 vfree(orig_sock_table
);
74 mutex_unlock(&sock_flow_mutex
);
78 #endif /* CONFIG_RPS */
80 static struct ctl_table net_core_table
[] = {
83 .procname
= "wmem_max",
84 .data
= &sysctl_wmem_max
,
85 .maxlen
= sizeof(int),
87 .proc_handler
= proc_dointvec
90 .procname
= "rmem_max",
91 .data
= &sysctl_rmem_max
,
92 .maxlen
= sizeof(int),
94 .proc_handler
= proc_dointvec
97 .procname
= "wmem_default",
98 .data
= &sysctl_wmem_default
,
99 .maxlen
= sizeof(int),
101 .proc_handler
= proc_dointvec
104 .procname
= "rmem_default",
105 .data
= &sysctl_rmem_default
,
106 .maxlen
= sizeof(int),
108 .proc_handler
= proc_dointvec
111 .procname
= "dev_weight",
113 .maxlen
= sizeof(int),
115 .proc_handler
= proc_dointvec
118 .procname
= "netdev_max_backlog",
119 .data
= &netdev_max_backlog
,
120 .maxlen
= sizeof(int),
122 .proc_handler
= proc_dointvec
125 .procname
= "netdev_tstamp_prequeue",
126 .data
= &netdev_tstamp_prequeue
,
127 .maxlen
= sizeof(int),
129 .proc_handler
= proc_dointvec
132 .procname
= "message_cost",
133 .data
= &net_ratelimit_state
.interval
,
134 .maxlen
= sizeof(int),
136 .proc_handler
= proc_dointvec_jiffies
,
139 .procname
= "message_burst",
140 .data
= &net_ratelimit_state
.burst
,
141 .maxlen
= sizeof(int),
143 .proc_handler
= proc_dointvec
,
146 .procname
= "optmem_max",
147 .data
= &sysctl_optmem_max
,
148 .maxlen
= sizeof(int),
150 .proc_handler
= proc_dointvec
154 .procname
= "rps_sock_flow_entries",
155 .maxlen
= sizeof(int),
157 .proc_handler
= rps_sock_flow_sysctl
160 #endif /* CONFIG_NET */
162 .procname
= "netdev_budget",
163 .data
= &netdev_budget
,
164 .maxlen
= sizeof(int),
166 .proc_handler
= proc_dointvec
169 .procname
= "warnings",
170 .data
= &net_msg_warn
,
171 .maxlen
= sizeof(int),
173 .proc_handler
= proc_dointvec
178 static struct ctl_table netns_core_table
[] = {
180 .procname
= "somaxconn",
181 .data
= &init_net
.core
.sysctl_somaxconn
,
182 .maxlen
= sizeof(int),
184 .proc_handler
= proc_dointvec
189 __net_initdata
struct ctl_path net_core_path
[] = {
190 { .procname
= "net", },
191 { .procname
= "core", },
195 static __net_init
int sysctl_core_net_init(struct net
*net
)
197 struct ctl_table
*tbl
;
199 net
->core
.sysctl_somaxconn
= SOMAXCONN
;
201 tbl
= netns_core_table
;
202 if (!net_eq(net
, &init_net
)) {
203 tbl
= kmemdup(tbl
, sizeof(netns_core_table
), GFP_KERNEL
);
207 tbl
[0].data
= &net
->core
.sysctl_somaxconn
;
210 net
->core
.sysctl_hdr
= register_net_sysctl_table(net
,
212 if (net
->core
.sysctl_hdr
== NULL
)
218 if (tbl
!= netns_core_table
)
224 static __net_exit
void sysctl_core_net_exit(struct net
*net
)
226 struct ctl_table
*tbl
;
228 tbl
= net
->core
.sysctl_hdr
->ctl_table_arg
;
229 unregister_net_sysctl_table(net
->core
.sysctl_hdr
);
230 BUG_ON(tbl
== netns_core_table
);
234 static __net_initdata
struct pernet_operations sysctl_core_ops
= {
235 .init
= sysctl_core_net_init
,
236 .exit
= sysctl_core_net_exit
,
239 static __init
int sysctl_core_init(void)
241 static struct ctl_table empty
[1];
243 register_sysctl_paths(net_core_path
, empty
);
244 register_net_sysctl_rotable(net_core_path
, net_core_table
);
245 return register_pernet_subsys(&sysctl_core_ops
);
248 fs_initcall(sysctl_core_init
);