2 * sysctl_net_ipv6.c: sysctl interface to net IPV6 subsystem.
5 * YOSHIFUJI Hideaki @USAGI: added icmp sysctl table.
9 #include <linux/sysctl.h>
10 #include <linux/in6.h>
11 #include <linux/ipv6.h>
12 #include <linux/slab.h>
13 #include <linux/export.h>
14 #include <net/ndisc.h>
16 #include <net/addrconf.h>
17 #include <net/inet_frag.h>
19 static ctl_table ipv6_table_template[] = {
21 .procname = "bindv6only",
22 .data = &init_net.ipv6.sysctl.bindv6only,
23 .maxlen = sizeof(int),
25 .proc_handler = proc_dointvec
30 static ctl_table ipv6_rotable[] = {
32 .procname = "mld_max_msf",
33 .data = &sysctl_mld_max_msf,
34 .maxlen = sizeof(int),
36 .proc_handler = proc_dointvec
41 static int __net_init ipv6_sysctl_net_init(struct net *net)
43 struct ctl_table *ipv6_table;
44 struct ctl_table *ipv6_route_table;
45 struct ctl_table *ipv6_icmp_table;
49 ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template),
53 ipv6_table[0].data = &net->ipv6.sysctl.bindv6only;
55 /* Don't export sysctls to unprivileged users */
56 if (net->user_ns != &init_user_ns)
57 ipv6_table[0].procname = NULL;
59 ipv6_route_table = ipv6_route_sysctl_init(net);
60 if (!ipv6_route_table)
63 ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
65 goto out_ipv6_route_table;
67 net->ipv6.sysctl.hdr = register_net_sysctl(net, "net/ipv6", ipv6_table);
68 if (!net->ipv6.sysctl.hdr)
69 goto out_ipv6_icmp_table;
71 net->ipv6.sysctl.route_hdr =
72 register_net_sysctl(net, "net/ipv6/route", ipv6_route_table);
73 if (!net->ipv6.sysctl.route_hdr)
74 goto out_unregister_ipv6_table;
76 net->ipv6.sysctl.icmp_hdr =
77 register_net_sysctl(net, "net/ipv6/icmp", ipv6_icmp_table);
78 if (!net->ipv6.sysctl.icmp_hdr)
79 goto out_unregister_route_table;
84 out_unregister_route_table:
85 unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
86 out_unregister_ipv6_table:
87 unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
89 kfree(ipv6_icmp_table);
91 kfree(ipv6_route_table);
97 static void __net_exit ipv6_sysctl_net_exit(struct net *net)
99 struct ctl_table *ipv6_table;
100 struct ctl_table *ipv6_route_table;
101 struct ctl_table *ipv6_icmp_table;
103 ipv6_table = net->ipv6.sysctl.hdr->ctl_table_arg;
104 ipv6_route_table = net->ipv6.sysctl.route_hdr->ctl_table_arg;
105 ipv6_icmp_table = net->ipv6.sysctl.icmp_hdr->ctl_table_arg;
107 unregister_net_sysctl_table(net->ipv6.sysctl.icmp_hdr);
108 unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
109 unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
112 kfree(ipv6_route_table);
113 kfree(ipv6_icmp_table);
116 static struct pernet_operations ipv6_sysctl_net_ops = {
117 .init = ipv6_sysctl_net_init,
118 .exit = ipv6_sysctl_net_exit,
121 static struct ctl_table_header *ip6_header;
123 int ipv6_sysctl_register(void)
127 ip6_header = register_net_sysctl(&init_net, "net/ipv6", ipv6_rotable);
128 if (ip6_header == NULL)
131 err = register_pernet_subsys(&ipv6_sysctl_net_ops);
138 unregister_net_sysctl_table(ip6_header);
142 void ipv6_sysctl_unregister(void)
144 unregister_net_sysctl_table(ip6_header);
145 unregister_pernet_subsys(&ipv6_sysctl_net_ops);