blob: 0c6c5ef65f9dac4342f9d21775568653dfc1bec1 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Alexey Dobriyanb27aead2008-11-25 18:00:48 -08002#include <linux/sysctl.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09003#include <linux/slab.h>
Alexey Dobriyanb27aead2008-11-25 18:00:48 -08004#include <net/net_namespace.h>
5#include <net/xfrm.h>
6
Alexey Dobriyan2c8c1e72010-01-17 03:35:32 +00007static void __net_init __xfrm_sysctl_init(struct net *net)
Alexey Dobriyanb27aead2008-11-25 18:00:48 -08008{
9 net->xfrm.sysctl_aevent_etime = XFRM_AE_ETIME;
10 net->xfrm.sysctl_aevent_rseqth = XFRM_AE_SEQT_SIZE;
11 net->xfrm.sysctl_larval_drop = 1;
12 net->xfrm.sysctl_acq_expires = 30;
13}
14
15#ifdef CONFIG_SYSCTL
16static struct ctl_table xfrm_table[] = {
17 {
Alexey Dobriyanb27aead2008-11-25 18:00:48 -080018 .procname = "xfrm_aevent_etime",
19 .maxlen = sizeof(u32),
20 .mode = 0644,
subashab@codeaurora.org0f76d252016-09-06 18:09:31 -060021 .proc_handler = proc_douintvec
Alexey Dobriyanb27aead2008-11-25 18:00:48 -080022 },
23 {
Alexey Dobriyanb27aead2008-11-25 18:00:48 -080024 .procname = "xfrm_aevent_rseqth",
25 .maxlen = sizeof(u32),
26 .mode = 0644,
subashab@codeaurora.org0f76d252016-09-06 18:09:31 -060027 .proc_handler = proc_douintvec
Alexey Dobriyanb27aead2008-11-25 18:00:48 -080028 },
29 {
Alexey Dobriyanb27aead2008-11-25 18:00:48 -080030 .procname = "xfrm_larval_drop",
31 .maxlen = sizeof(int),
32 .mode = 0644,
33 .proc_handler = proc_dointvec
34 },
35 {
Alexey Dobriyanb27aead2008-11-25 18:00:48 -080036 .procname = "xfrm_acq_expires",
37 .maxlen = sizeof(int),
38 .mode = 0644,
39 .proc_handler = proc_dointvec
40 },
41 {}
42};
43
44int __net_init xfrm_sysctl_init(struct net *net)
45{
46 struct ctl_table *table;
47
48 __xfrm_sysctl_init(net);
49
50 table = kmemdup(xfrm_table, sizeof(xfrm_table), GFP_KERNEL);
51 if (!table)
52 goto out_kmemdup;
53 table[0].data = &net->xfrm.sysctl_aevent_etime;
54 table[1].data = &net->xfrm.sysctl_aevent_rseqth;
55 table[2].data = &net->xfrm.sysctl_larval_drop;
56 table[3].data = &net->xfrm.sysctl_acq_expires;
57
Eric W. Biederman464dc802012-11-16 03:02:59 +000058 /* Don't export sysctls to unprivileged users */
59 if (net->user_ns != &init_user_ns)
60 table[0].procname = NULL;
61
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +000062 net->xfrm.sysctl_hdr = register_net_sysctl(net, "net/core", table);
Alexey Dobriyanb27aead2008-11-25 18:00:48 -080063 if (!net->xfrm.sysctl_hdr)
64 goto out_register;
65 return 0;
66
67out_register:
68 kfree(table);
69out_kmemdup:
70 return -ENOMEM;
71}
72
Alexey Dobriyan2c8c1e72010-01-17 03:35:32 +000073void __net_exit xfrm_sysctl_fini(struct net *net)
Alexey Dobriyanb27aead2008-11-25 18:00:48 -080074{
75 struct ctl_table *table;
76
77 table = net->xfrm.sysctl_hdr->ctl_table_arg;
78 unregister_net_sysctl_table(net->xfrm.sysctl_hdr);
79 kfree(table);
80}
81#else
82int __net_init xfrm_sysctl_init(struct net *net)
83{
84 __xfrm_sysctl_init(net);
85 return 0;
86}
87#endif