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 LT |
18 | { |
19 | .ctl_name = NET_IPV6_ROUTE, | |
20 | .procname = "route", | |
21 | .maxlen = 0, | |
22 | .mode = 0555, | |
760f2d01 | 23 | .child = ipv6_route_table_template |
1da177e4 LT |
24 | }, |
25 | { | |
26 | .ctl_name = NET_IPV6_ICMP, | |
27 | .procname = "icmp", | |
28 | .maxlen = 0, | |
29 | .mode = 0555, | |
760f2d01 | 30 | .child = ipv6_icmp_table_template |
1da177e4 LT |
31 | }, |
32 | { | |
33 | .ctl_name = NET_IPV6_BINDV6ONLY, | |
34 | .procname = "bindv6only", | |
99bc9c4e | 35 | .data = &init_net.ipv6.sysctl.bindv6only, |
1da177e4 LT |
36 | .maxlen = sizeof(int), |
37 | .mode = 0644, | |
38 | .proc_handler = &proc_dointvec | |
39 | }, | |
1da177e4 LT |
40 | { |
41 | .ctl_name = NET_IPV6_MLD_MAX_MSF, | |
42 | .procname = "mld_max_msf", | |
43 | .data = &sysctl_mld_max_msf, | |
44 | .maxlen = sizeof(int), | |
45 | .mode = 0644, | |
46 | .proc_handler = &proc_dointvec | |
47 | }, | |
48 | { .ctl_name = 0 } | |
49 | }; | |
50 | ||
3d7cc2ba | 51 | struct ctl_path net_ipv6_ctl_path[] = { |
4d43b78a PE |
52 | { .procname = "net", .ctl_name = CTL_NET, }, |
53 | { .procname = "ipv6", .ctl_name = NET_IPV6, }, | |
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; | |
74 | ||
75 | ipv6_icmp_table = ipv6_icmp_sysctl_init(net); | |
76 | if (!ipv6_icmp_table) | |
77 | goto out_ipv6_route_table; | |
78 | ||
4990509f DL |
79 | ipv6_route_table[0].data = &net->ipv6.sysctl.flush_delay; |
80 | /* ipv6_route_table[1].data will be handled when we have | |
81 | routes per namespace */ | |
82 | ipv6_route_table[2].data = &net->ipv6.sysctl.ip6_rt_max_size; | |
83 | ipv6_route_table[3].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval; | |
84 | ipv6_route_table[4].data = &net->ipv6.sysctl.ip6_rt_gc_timeout; | |
85 | ipv6_route_table[5].data = &net->ipv6.sysctl.ip6_rt_gc_interval; | |
86 | ipv6_route_table[6].data = &net->ipv6.sysctl.ip6_rt_gc_elasticity; | |
87 | ipv6_route_table[7].data = &net->ipv6.sysctl.ip6_rt_mtu_expires; | |
88 | ipv6_route_table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss; | |
760f2d01 | 89 | ipv6_table[0].child = ipv6_route_table; |
4990509f | 90 | |
41a76906 | 91 | ipv6_icmp_table[0].data = &net->ipv6.sysctl.icmpv6_time; |
760f2d01 DL |
92 | ipv6_table[1].child = ipv6_icmp_table; |
93 | ||
99bc9c4e DL |
94 | ipv6_table[2].data = &net->ipv6.sysctl.bindv6only; |
95 | ||
7c76509d DL |
96 | /* We don't want this value to be per namespace, it should be global |
97 | to all namespaces, so make it read-only when we are not in the | |
98 | init network namespace */ | |
99 | if (net != &init_net) | |
8d8354d2 | 100 | ipv6_table[3].mode = 0444; |
7c76509d | 101 | |
760f2d01 DL |
102 | net->ipv6.sysctl.table = register_net_sysctl_table(net, net_ipv6_ctl_path, |
103 | ipv6_table); | |
760f2d01 DL |
104 | if (!net->ipv6.sysctl.table) |
105 | goto out_ipv6_icmp_table; | |
106 | ||
107 | err = 0; | |
108 | out: | |
109 | return err; | |
291480c0 | 110 | |
760f2d01 DL |
111 | out_ipv6_icmp_table: |
112 | kfree(ipv6_icmp_table); | |
113 | out_ipv6_route_table: | |
114 | kfree(ipv6_route_table); | |
115 | out_ipv6_table: | |
116 | kfree(ipv6_table); | |
117 | goto out; | |
1da177e4 LT |
118 | } |
119 | ||
89918fc2 DL |
120 | static void ipv6_sysctl_net_exit(struct net *net) |
121 | { | |
760f2d01 DL |
122 | struct ctl_table *ipv6_table; |
123 | struct ctl_table *ipv6_route_table; | |
124 | struct ctl_table *ipv6_icmp_table; | |
125 | ||
126 | ipv6_table = net->ipv6.sysctl.table->ctl_table_arg; | |
127 | ipv6_route_table = ipv6_table[0].child; | |
128 | ipv6_icmp_table = ipv6_table[1].child; | |
129 | ||
130 | unregister_net_sysctl_table(net->ipv6.sysctl.table); | |
131 | ||
132 | kfree(ipv6_table); | |
133 | kfree(ipv6_route_table); | |
134 | kfree(ipv6_icmp_table); | |
89918fc2 DL |
135 | } |
136 | ||
137 | static struct pernet_operations ipv6_sysctl_net_ops = { | |
138 | .init = ipv6_sysctl_net_init, | |
139 | .exit = ipv6_sysctl_net_exit, | |
140 | }; | |
141 | ||
142 | int ipv6_sysctl_register(void) | |
143 | { | |
144 | return register_pernet_subsys(&ipv6_sysctl_net_ops); | |
145 | } | |
146 | ||
1da177e4 LT |
147 | void ipv6_sysctl_unregister(void) |
148 | { | |
89918fc2 | 149 | unregister_pernet_subsys(&ipv6_sysctl_net_ops); |
1da177e4 | 150 | } |