hdmi: reconfigure audio when enable/disable 3D Frame packing mode.
[firefly-linux-kernel-4.4.55.git] / net / core / sysctl_net_core.c
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
23 static int zero = 0;
24 static int one = 1;
25 static int ushort_max = USHRT_MAX;
26 static int min_sndbuf = SOCK_MIN_SNDBUF;
27 static int min_rcvbuf = SOCK_MIN_RCVBUF;
28
29 #ifdef CONFIG_RPS
30 static int rps_sock_flow_sysctl(ctl_table *table, int write,
31                                 void __user *buffer, size_t *lenp, loff_t *ppos)
32 {
33         unsigned int orig_size, size;
34         int ret, i;
35         ctl_table tmp = {
36                 .data = &size,
37                 .maxlen = sizeof(size),
38                 .mode = table->mode
39         };
40         struct rps_sock_flow_table *orig_sock_table, *sock_table;
41         static DEFINE_MUTEX(sock_flow_mutex);
42
43         mutex_lock(&sock_flow_mutex);
44
45         orig_sock_table = rcu_dereference_protected(rps_sock_flow_table,
46                                         lockdep_is_held(&sock_flow_mutex));
47         size = orig_size = orig_sock_table ? orig_sock_table->mask + 1 : 0;
48
49         ret = proc_dointvec(&tmp, write, buffer, lenp, ppos);
50
51         if (write) {
52                 if (size) {
53                         if (size > 1<<30) {
54                                 /* Enforce limit to prevent overflow */
55                                 mutex_unlock(&sock_flow_mutex);
56                                 return -EINVAL;
57                         }
58                         size = roundup_pow_of_two(size);
59                         if (size != orig_size) {
60                                 sock_table =
61                                     vmalloc(RPS_SOCK_FLOW_TABLE_SIZE(size));
62                                 if (!sock_table) {
63                                         mutex_unlock(&sock_flow_mutex);
64                                         return -ENOMEM;
65                                 }
66
67                                 sock_table->mask = size - 1;
68                         } else
69                                 sock_table = orig_sock_table;
70
71                         for (i = 0; i < size; i++)
72                                 sock_table->ents[i] = RPS_NO_CPU;
73                 } else
74                         sock_table = NULL;
75
76                 if (sock_table != orig_sock_table) {
77                         rcu_assign_pointer(rps_sock_flow_table, sock_table);
78                         if (sock_table)
79                                 static_key_slow_inc(&rps_needed);
80                         if (orig_sock_table) {
81                                 static_key_slow_dec(&rps_needed);
82                                 synchronize_rcu();
83                                 vfree(orig_sock_table);
84                         }
85                 }
86         }
87
88         mutex_unlock(&sock_flow_mutex);
89
90         return ret;
91 }
92 #endif /* CONFIG_RPS */
93
94 static struct ctl_table net_core_table[] = {
95 #ifdef CONFIG_NET
96         {
97                 .procname       = "wmem_max",
98                 .data           = &sysctl_wmem_max,
99                 .maxlen         = sizeof(int),
100                 .mode           = 0644,
101                 .proc_handler   = proc_dointvec_minmax,
102                 .extra1         = &min_sndbuf,
103         },
104         {
105                 .procname       = "rmem_max",
106                 .data           = &sysctl_rmem_max,
107                 .maxlen         = sizeof(int),
108                 .mode           = 0644,
109                 .proc_handler   = proc_dointvec_minmax,
110                 .extra1         = &min_rcvbuf,
111         },
112         {
113                 .procname       = "wmem_default",
114                 .data           = &sysctl_wmem_default,
115                 .maxlen         = sizeof(int),
116                 .mode           = 0644,
117                 .proc_handler   = proc_dointvec_minmax,
118                 .extra1         = &min_sndbuf,
119         },
120         {
121                 .procname       = "rmem_default",
122                 .data           = &sysctl_rmem_default,
123                 .maxlen         = sizeof(int),
124                 .mode           = 0644,
125                 .proc_handler   = proc_dointvec_minmax,
126                 .extra1         = &min_rcvbuf,
127         },
128         {
129                 .procname       = "dev_weight",
130                 .data           = &weight_p,
131                 .maxlen         = sizeof(int),
132                 .mode           = 0644,
133                 .proc_handler   = proc_dointvec
134         },
135         {
136                 .procname       = "netdev_max_backlog",
137                 .data           = &netdev_max_backlog,
138                 .maxlen         = sizeof(int),
139                 .mode           = 0644,
140                 .proc_handler   = proc_dointvec
141         },
142 #ifdef CONFIG_BPF_JIT
143         {
144                 .procname       = "bpf_jit_enable",
145                 .data           = &bpf_jit_enable,
146                 .maxlen         = sizeof(int),
147                 .mode           = 0644,
148                 .proc_handler   = proc_dointvec
149         },
150 #endif
151         {
152                 .procname       = "netdev_tstamp_prequeue",
153                 .data           = &netdev_tstamp_prequeue,
154                 .maxlen         = sizeof(int),
155                 .mode           = 0644,
156                 .proc_handler   = proc_dointvec
157         },
158         {
159                 .procname       = "message_cost",
160                 .data           = &net_ratelimit_state.interval,
161                 .maxlen         = sizeof(int),
162                 .mode           = 0644,
163                 .proc_handler   = proc_dointvec_jiffies,
164         },
165         {
166                 .procname       = "message_burst",
167                 .data           = &net_ratelimit_state.burst,
168                 .maxlen         = sizeof(int),
169                 .mode           = 0644,
170                 .proc_handler   = proc_dointvec,
171         },
172         {
173                 .procname       = "optmem_max",
174                 .data           = &sysctl_optmem_max,
175                 .maxlen         = sizeof(int),
176                 .mode           = 0644,
177                 .proc_handler   = proc_dointvec
178         },
179 #ifdef CONFIG_RPS
180         {
181                 .procname       = "rps_sock_flow_entries",
182                 .maxlen         = sizeof(int),
183                 .mode           = 0644,
184                 .proc_handler   = rps_sock_flow_sysctl
185         },
186 #endif
187 #endif /* CONFIG_NET */
188         {
189                 .procname       = "netdev_budget",
190                 .data           = &netdev_budget,
191                 .maxlen         = sizeof(int),
192                 .mode           = 0644,
193                 .proc_handler   = proc_dointvec
194         },
195         {
196                 .procname       = "warnings",
197                 .data           = &net_msg_warn,
198                 .maxlen         = sizeof(int),
199                 .mode           = 0644,
200                 .proc_handler   = proc_dointvec
201         },
202         { }
203 };
204
205 static struct ctl_table netns_core_table[] = {
206         {
207                 .procname       = "somaxconn",
208                 .data           = &init_net.core.sysctl_somaxconn,
209                 .maxlen         = sizeof(int),
210                 .mode           = 0644,
211                 .extra1         = &zero,
212                 .extra2         = &ushort_max,
213                 .proc_handler   = proc_dointvec_minmax
214         },
215         { }
216 };
217
218 static __net_init int sysctl_core_net_init(struct net *net)
219 {
220         struct ctl_table *tbl;
221
222         net->core.sysctl_somaxconn = SOMAXCONN;
223
224         tbl = netns_core_table;
225         if (!net_eq(net, &init_net)) {
226                 tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
227                 if (tbl == NULL)
228                         goto err_dup;
229
230                 tbl[0].data = &net->core.sysctl_somaxconn;
231
232                 /* Don't export any sysctls to unprivileged users */
233                 if (net->user_ns != &init_user_ns) {
234                         tbl[0].procname = NULL;
235                 }
236         }
237
238         net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
239         if (net->core.sysctl_hdr == NULL)
240                 goto err_reg;
241
242         return 0;
243
244 err_reg:
245         if (tbl != netns_core_table)
246                 kfree(tbl);
247 err_dup:
248         return -ENOMEM;
249 }
250
251 static __net_exit void sysctl_core_net_exit(struct net *net)
252 {
253         struct ctl_table *tbl;
254
255         tbl = net->core.sysctl_hdr->ctl_table_arg;
256         unregister_net_sysctl_table(net->core.sysctl_hdr);
257         BUG_ON(tbl == netns_core_table);
258         kfree(tbl);
259 }
260
261 static __net_initdata struct pernet_operations sysctl_core_ops = {
262         .init = sysctl_core_net_init,
263         .exit = sysctl_core_net_exit,
264 };
265
266 static __init int sysctl_core_init(void)
267 {
268         register_net_sysctl(&init_net, "net/core", net_core_table);
269         return register_pernet_subsys(&sysctl_core_ops);
270 }
271
272 fs_initcall(sysctl_core_init);