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