blob: 3804dcbbfab0f46cc0cfcfd852482e4eb529e312 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/in6.h>
11#include <linux/ipv6.h>
12#include <net/ndisc.h>
13#include <net/ipv6.h>
14#include <net/addrconf.h>
Pavel Emelyanov04128f22007-10-15 02:33:45 -070015#include <net/inet_frag.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Daniel Lezcano760f2d02008-01-10 02:53:43 -080017static ctl_table ipv6_table_template[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 {
19 .ctl_name = NET_IPV6_ROUTE,
20 .procname = "route",
21 .maxlen = 0,
22 .mode = 0555,
Daniel Lezcano760f2d02008-01-10 02:53:43 -080023 .child = ipv6_route_table_template
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 },
25 {
26 .ctl_name = NET_IPV6_ICMP,
27 .procname = "icmp",
28 .maxlen = 0,
29 .mode = 0555,
Daniel Lezcano760f2d02008-01-10 02:53:43 -080030 .child = ipv6_icmp_table_template
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 },
32 {
33 .ctl_name = NET_IPV6_BINDV6ONLY,
34 .procname = "bindv6only",
Daniel Lezcano99bc9c42008-01-10 02:54:53 -080035 .data = &init_net.ipv6.sysctl.bindv6only,
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 .maxlen = sizeof(int),
37 .mode = 0644,
38 .proc_handler = &proc_dointvec
39 },
40 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 .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
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -080051struct ctl_path net_ipv6_ctl_path[] = {
Pavel Emelyanov4d43b782007-12-05 01:44:02 -080052 { .procname = "net", .ctl_name = CTL_NET, },
53 { .procname = "ipv6", .ctl_name = NET_IPV6, },
54 { },
55};
Pavel Emelyanov3d7cc2b2008-01-09 00:33:11 -080056EXPORT_SYMBOL_GPL(net_ipv6_ctl_path);
Pavel Emelyanov4d43b782007-12-05 01:44:02 -080057
Daniel Lezcano89918fc2008-01-10 02:49:34 -080058static int ipv6_sysctl_net_init(struct net *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
Daniel Lezcano760f2d02008-01-10 02:53:43 -080060 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;
YOSHIFUJI Hideaki5ee09102008-02-28 00:24:28 +090074 ipv6_table[0].child = ipv6_route_table;
Daniel Lezcano760f2d02008-01-10 02:53:43 -080075
76 ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
77 if (!ipv6_icmp_table)
78 goto out_ipv6_route_table;
Daniel Lezcano760f2d02008-01-10 02:53:43 -080079 ipv6_table[1].child = ipv6_icmp_table;
80
Daniel Lezcano99bc9c42008-01-10 02:54:53 -080081 ipv6_table[2].data = &net->ipv6.sysctl.bindv6only;
82
Daniel Lezcano7c765092008-01-10 02:57:43 -080083 /* We don't want this value to be per namespace, it should be global
84 to all namespaces, so make it read-only when we are not in the
85 init network namespace */
86 if (net != &init_net)
Pavel Emelyanov8d8354d2008-01-22 05:58:31 -080087 ipv6_table[3].mode = 0444;
Daniel Lezcano7c765092008-01-10 02:57:43 -080088
Daniel Lezcano760f2d02008-01-10 02:53:43 -080089 net->ipv6.sysctl.table = register_net_sysctl_table(net, net_ipv6_ctl_path,
90 ipv6_table);
91 if (!net->ipv6.sysctl.table)
Daniel Lezcano760f2d02008-01-10 02:53:43 -080092 goto out_ipv6_icmp_table;
Daniel Lezcano291480c2008-01-10 02:47:55 -080093
Daniel Lezcano760f2d02008-01-10 02:53:43 -080094 err = 0;
95out:
96 return err;
97
98out_ipv6_icmp_table:
99 kfree(ipv6_icmp_table);
100out_ipv6_route_table:
101 kfree(ipv6_route_table);
102out_ipv6_table:
103 kfree(ipv6_table);
104 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
Daniel Lezcano89918fc2008-01-10 02:49:34 -0800107static void ipv6_sysctl_net_exit(struct net *net)
108{
Daniel Lezcano760f2d02008-01-10 02:53:43 -0800109 struct ctl_table *ipv6_table;
110 struct ctl_table *ipv6_route_table;
111 struct ctl_table *ipv6_icmp_table;
112
113 ipv6_table = net->ipv6.sysctl.table->ctl_table_arg;
114 ipv6_route_table = ipv6_table[0].child;
115 ipv6_icmp_table = ipv6_table[1].child;
116
117 unregister_net_sysctl_table(net->ipv6.sysctl.table);
118
119 kfree(ipv6_table);
120 kfree(ipv6_route_table);
121 kfree(ipv6_icmp_table);
Daniel Lezcano89918fc2008-01-10 02:49:34 -0800122}
123
124static struct pernet_operations ipv6_sysctl_net_ops = {
125 .init = ipv6_sysctl_net_init,
126 .exit = ipv6_sysctl_net_exit,
127};
128
129int ipv6_sysctl_register(void)
130{
131 return register_pernet_subsys(&ipv6_sysctl_net_ops);
132}
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134void ipv6_sysctl_unregister(void)
135{
Daniel Lezcano89918fc2008-01-10 02:49:34 -0800136 unregister_pernet_subsys(&ipv6_sysctl_net_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}