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> | |
5a0e3ad6 | 12 | #include <linux/slab.h> |
1da177e4 LT |
13 | #include <net/ndisc.h> |
14 | #include <net/ipv6.h> | |
15 | #include <net/addrconf.h> | |
04128f23 | 16 | #include <net/inet_frag.h> |
1da177e4 | 17 | |
bf36076a EB |
18 | static struct ctl_table empty[1]; |
19 | ||
760f2d01 | 20 | static ctl_table ipv6_table_template[] = { |
1da177e4 | 21 | { |
1da177e4 LT |
22 | .procname = "route", |
23 | .maxlen = 0, | |
24 | .mode = 0555, | |
760f2d01 | 25 | .child = ipv6_route_table_template |
1da177e4 LT |
26 | }, |
27 | { | |
1da177e4 LT |
28 | .procname = "icmp", |
29 | .maxlen = 0, | |
30 | .mode = 0555, | |
760f2d01 | 31 | .child = ipv6_icmp_table_template |
1da177e4 LT |
32 | }, |
33 | { | |
1da177e4 | 34 | .procname = "bindv6only", |
99bc9c4e | 35 | .data = &init_net.ipv6.sysctl.bindv6only, |
1da177e4 LT |
36 | .maxlen = sizeof(int), |
37 | .mode = 0644, | |
6d9f239a | 38 | .proc_handler = proc_dointvec |
1da177e4 | 39 | }, |
bf36076a EB |
40 | { |
41 | .procname = "neigh", | |
42 | .maxlen = 0, | |
43 | .mode = 0555, | |
44 | .child = empty, | |
45 | }, | |
f8572d8f | 46 | { } |
34ac2573 PE |
47 | }; |
48 | ||
81e43213 | 49 | static ctl_table ipv6_rotable[] = { |
1da177e4 | 50 | { |
1da177e4 LT |
51 | .procname = "mld_max_msf", |
52 | .data = &sysctl_mld_max_msf, | |
53 | .maxlen = sizeof(int), | |
54 | .mode = 0644, | |
6d9f239a | 55 | .proc_handler = proc_dointvec |
1da177e4 | 56 | }, |
f8572d8f | 57 | { } |
1da177e4 LT |
58 | }; |
59 | ||
3d7cc2ba | 60 | struct ctl_path net_ipv6_ctl_path[] = { |
f8572d8f EB |
61 | { .procname = "net", }, |
62 | { .procname = "ipv6", }, | |
4d43b78a | 63 | { }, |
1da177e4 | 64 | }; |
3d7cc2ba | 65 | EXPORT_SYMBOL_GPL(net_ipv6_ctl_path); |
1da177e4 | 66 | |
2c8c1e72 | 67 | static int __net_init ipv6_sysctl_net_init(struct net *net) |
1da177e4 | 68 | { |
760f2d01 DL |
69 | struct ctl_table *ipv6_table; |
70 | struct ctl_table *ipv6_route_table; | |
71 | struct ctl_table *ipv6_icmp_table; | |
72 | int err; | |
73 | ||
74 | err = -ENOMEM; | |
75 | ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template), | |
76 | GFP_KERNEL); | |
77 | if (!ipv6_table) | |
78 | goto out; | |
79 | ||
80 | ipv6_route_table = ipv6_route_sysctl_init(net); | |
81 | if (!ipv6_route_table) | |
82 | goto out_ipv6_table; | |
5ee09105 | 83 | ipv6_table[0].child = ipv6_route_table; |
760f2d01 DL |
84 | |
85 | ipv6_icmp_table = ipv6_icmp_sysctl_init(net); | |
86 | if (!ipv6_icmp_table) | |
87 | goto out_ipv6_route_table; | |
760f2d01 DL |
88 | ipv6_table[1].child = ipv6_icmp_table; |
89 | ||
99bc9c4e DL |
90 | ipv6_table[2].data = &net->ipv6.sysctl.bindv6only; |
91 | ||
760f2d01 DL |
92 | net->ipv6.sysctl.table = register_net_sysctl_table(net, net_ipv6_ctl_path, |
93 | ipv6_table); | |
760f2d01 DL |
94 | if (!net->ipv6.sysctl.table) |
95 | goto out_ipv6_icmp_table; | |
96 | ||
97 | err = 0; | |
98 | out: | |
99 | return err; | |
291480c0 | 100 | |
760f2d01 DL |
101 | out_ipv6_icmp_table: |
102 | kfree(ipv6_icmp_table); | |
103 | out_ipv6_route_table: | |
104 | kfree(ipv6_route_table); | |
105 | out_ipv6_table: | |
106 | kfree(ipv6_table); | |
107 | goto out; | |
1da177e4 LT |
108 | } |
109 | ||
2c8c1e72 | 110 | static void __net_exit ipv6_sysctl_net_exit(struct net *net) |
89918fc2 | 111 | { |
760f2d01 DL |
112 | struct ctl_table *ipv6_table; |
113 | struct ctl_table *ipv6_route_table; | |
114 | struct ctl_table *ipv6_icmp_table; | |
115 | ||
116 | ipv6_table = net->ipv6.sysctl.table->ctl_table_arg; | |
117 | ipv6_route_table = ipv6_table[0].child; | |
118 | ipv6_icmp_table = ipv6_table[1].child; | |
119 | ||
120 | unregister_net_sysctl_table(net->ipv6.sysctl.table); | |
121 | ||
122 | kfree(ipv6_table); | |
123 | kfree(ipv6_route_table); | |
124 | kfree(ipv6_icmp_table); | |
89918fc2 DL |
125 | } |
126 | ||
127 | static struct pernet_operations ipv6_sysctl_net_ops = { | |
128 | .init = ipv6_sysctl_net_init, | |
129 | .exit = ipv6_sysctl_net_exit, | |
130 | }; | |
131 | ||
34ac2573 PE |
132 | static struct ctl_table_header *ip6_header; |
133 | ||
89918fc2 DL |
134 | int ipv6_sysctl_register(void) |
135 | { | |
c19a28e1 | 136 | int err = -ENOMEM; |
34ac2573 | 137 | |
81e43213 | 138 | ip6_header = register_net_sysctl_rotable(net_ipv6_ctl_path, ipv6_rotable); |
34ac2573 PE |
139 | if (ip6_header == NULL) |
140 | goto out; | |
141 | ||
142 | err = register_pernet_subsys(&ipv6_sysctl_net_ops); | |
143 | if (err) | |
144 | goto err_pernet; | |
145 | out: | |
146 | return err; | |
147 | ||
148 | err_pernet: | |
149 | unregister_net_sysctl_table(ip6_header); | |
150 | goto out; | |
89918fc2 DL |
151 | } |
152 | ||
1da177e4 LT |
153 | void ipv6_sysctl_unregister(void) |
154 | { | |
34ac2573 | 155 | unregister_net_sysctl_table(ip6_header); |
89918fc2 | 156 | unregister_pernet_subsys(&ipv6_sysctl_net_ops); |
1da177e4 | 157 | } |
eeb61f71 AV |
158 | |
159 | static struct ctl_table_header *ip6_base; | |
160 | ||
161 | int ipv6_static_sysctl_register(void) | |
162 | { | |
ce3113ec | 163 | ip6_base = register_sysctl_paths(net_ipv6_ctl_path, empty); |
eeb61f71 AV |
164 | if (ip6_base == NULL) |
165 | return -ENOMEM; | |
166 | return 0; | |
167 | } | |
168 | ||
169 | void ipv6_static_sysctl_unregister(void) | |
170 | { | |
171 | unregister_net_sysctl_table(ip6_base); | |
172 | } |