Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * sysctl_net_ipv6.c: sysctl interface to net IPV6 subsystem. | |
3 | * | |
4 | * Changes: | |
5 | * YOSHIFUJI Hideaki @USAGI: added icmp sysctl table. | |
6 | */ | |
7 | ||
8 | #include <linux/mm.h> | |
9 | #include <linux/sysctl.h> | |
1da177e4 LT |
10 | #include <linux/in6.h> |
11 | #include <linux/ipv6.h> | |
12 | #include <net/ndisc.h> | |
13 | #include <net/ipv6.h> | |
14 | #include <net/addrconf.h> | |
04128f23 | 15 | #include <net/inet_frag.h> |
1da177e4 | 16 | |
760f2d01 DL |
17 | extern struct ctl_table *ipv6_route_sysctl_init(struct net *net); |
18 | extern struct ctl_table *ipv6_icmp_sysctl_init(struct net *net); | |
19 | ||
20 | static ctl_table ipv6_table_template[] = { | |
1da177e4 LT |
21 | { |
22 | .ctl_name = NET_IPV6_ROUTE, | |
23 | .procname = "route", | |
24 | .maxlen = 0, | |
25 | .mode = 0555, | |
760f2d01 | 26 | .child = ipv6_route_table_template |
1da177e4 LT |
27 | }, |
28 | { | |
29 | .ctl_name = NET_IPV6_ICMP, | |
30 | .procname = "icmp", | |
31 | .maxlen = 0, | |
32 | .mode = 0555, | |
760f2d01 | 33 | .child = ipv6_icmp_table_template |
1da177e4 LT |
34 | }, |
35 | { | |
36 | .ctl_name = NET_IPV6_BINDV6ONLY, | |
37 | .procname = "bindv6only", | |
38 | .data = &sysctl_ipv6_bindv6only, | |
39 | .maxlen = sizeof(int), | |
40 | .mode = 0644, | |
41 | .proc_handler = &proc_dointvec | |
42 | }, | |
43 | { | |
44 | .ctl_name = NET_IPV6_IP6FRAG_HIGH_THRESH, | |
45 | .procname = "ip6frag_high_thresh", | |
04128f23 | 46 | .data = &ip6_frags_ctl.high_thresh, |
1da177e4 LT |
47 | .maxlen = sizeof(int), |
48 | .mode = 0644, | |
49 | .proc_handler = &proc_dointvec | |
50 | }, | |
51 | { | |
52 | .ctl_name = NET_IPV6_IP6FRAG_LOW_THRESH, | |
53 | .procname = "ip6frag_low_thresh", | |
04128f23 | 54 | .data = &ip6_frags_ctl.low_thresh, |
1da177e4 LT |
55 | .maxlen = sizeof(int), |
56 | .mode = 0644, | |
57 | .proc_handler = &proc_dointvec | |
58 | }, | |
59 | { | |
60 | .ctl_name = NET_IPV6_IP6FRAG_TIME, | |
61 | .procname = "ip6frag_time", | |
04128f23 | 62 | .data = &ip6_frags_ctl.timeout, |
1da177e4 LT |
63 | .maxlen = sizeof(int), |
64 | .mode = 0644, | |
65 | .proc_handler = &proc_dointvec_jiffies, | |
66 | .strategy = &sysctl_jiffies, | |
67 | }, | |
68 | { | |
69 | .ctl_name = NET_IPV6_IP6FRAG_SECRET_INTERVAL, | |
70 | .procname = "ip6frag_secret_interval", | |
04128f23 | 71 | .data = &ip6_frags_ctl.secret_interval, |
1da177e4 LT |
72 | .maxlen = sizeof(int), |
73 | .mode = 0644, | |
74 | .proc_handler = &proc_dointvec_jiffies, | |
75 | .strategy = &sysctl_jiffies | |
76 | }, | |
77 | { | |
78 | .ctl_name = NET_IPV6_MLD_MAX_MSF, | |
79 | .procname = "mld_max_msf", | |
80 | .data = &sysctl_mld_max_msf, | |
81 | .maxlen = sizeof(int), | |
82 | .mode = 0644, | |
83 | .proc_handler = &proc_dointvec | |
84 | }, | |
85 | { .ctl_name = 0 } | |
86 | }; | |
87 | ||
3d7cc2ba | 88 | struct ctl_path net_ipv6_ctl_path[] = { |
4d43b78a PE |
89 | { .procname = "net", .ctl_name = CTL_NET, }, |
90 | { .procname = "ipv6", .ctl_name = NET_IPV6, }, | |
91 | { }, | |
1da177e4 | 92 | }; |
3d7cc2ba | 93 | EXPORT_SYMBOL_GPL(net_ipv6_ctl_path); |
1da177e4 | 94 | |
89918fc2 | 95 | static int ipv6_sysctl_net_init(struct net *net) |
1da177e4 | 96 | { |
760f2d01 DL |
97 | struct ctl_table *ipv6_table; |
98 | struct ctl_table *ipv6_route_table; | |
99 | struct ctl_table *ipv6_icmp_table; | |
100 | int err; | |
101 | ||
102 | err = -ENOMEM; | |
103 | ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template), | |
104 | GFP_KERNEL); | |
105 | if (!ipv6_table) | |
106 | goto out; | |
107 | ||
108 | ipv6_route_table = ipv6_route_sysctl_init(net); | |
109 | if (!ipv6_route_table) | |
110 | goto out_ipv6_table; | |
111 | ||
112 | ipv6_icmp_table = ipv6_icmp_sysctl_init(net); | |
113 | if (!ipv6_icmp_table) | |
114 | goto out_ipv6_route_table; | |
115 | ||
116 | ipv6_table[0].child = ipv6_route_table; | |
117 | ipv6_table[1].child = ipv6_icmp_table; | |
118 | ||
119 | net->ipv6.sysctl.table = register_net_sysctl_table(net, net_ipv6_ctl_path, | |
120 | ipv6_table); | |
121 | if (!net->ipv6.sysctl.table) | |
291480c0 DL |
122 | return -ENOMEM; |
123 | ||
760f2d01 DL |
124 | if (!net->ipv6.sysctl.table) |
125 | goto out_ipv6_icmp_table; | |
126 | ||
127 | err = 0; | |
128 | out: | |
129 | return err; | |
291480c0 | 130 | |
760f2d01 DL |
131 | out_ipv6_icmp_table: |
132 | kfree(ipv6_icmp_table); | |
133 | out_ipv6_route_table: | |
134 | kfree(ipv6_route_table); | |
135 | out_ipv6_table: | |
136 | kfree(ipv6_table); | |
137 | goto out; | |
1da177e4 LT |
138 | } |
139 | ||
89918fc2 DL |
140 | static void ipv6_sysctl_net_exit(struct net *net) |
141 | { | |
760f2d01 DL |
142 | struct ctl_table *ipv6_table; |
143 | struct ctl_table *ipv6_route_table; | |
144 | struct ctl_table *ipv6_icmp_table; | |
145 | ||
146 | ipv6_table = net->ipv6.sysctl.table->ctl_table_arg; | |
147 | ipv6_route_table = ipv6_table[0].child; | |
148 | ipv6_icmp_table = ipv6_table[1].child; | |
149 | ||
150 | unregister_net_sysctl_table(net->ipv6.sysctl.table); | |
151 | ||
152 | kfree(ipv6_table); | |
153 | kfree(ipv6_route_table); | |
154 | kfree(ipv6_icmp_table); | |
89918fc2 DL |
155 | } |
156 | ||
157 | static struct pernet_operations ipv6_sysctl_net_ops = { | |
158 | .init = ipv6_sysctl_net_init, | |
159 | .exit = ipv6_sysctl_net_exit, | |
160 | }; | |
161 | ||
162 | int ipv6_sysctl_register(void) | |
163 | { | |
164 | return register_pernet_subsys(&ipv6_sysctl_net_ops); | |
165 | } | |
166 | ||
1da177e4 LT |
167 | void ipv6_sysctl_unregister(void) |
168 | { | |
89918fc2 | 169 | unregister_pernet_subsys(&ipv6_sysctl_net_ops); |
1da177e4 | 170 | } |