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