Blame view

net/ipv6/sysctl_net_ipv6.c 3.55 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
  /*
   * sysctl_net_ipv6.c: sysctl interface to net IPV6 subsystem.
   *
   * Changes:
   * YOSHIFUJI Hideaki @USAGI:	added icmp sysctl table.
   */
  
  #include <linux/mm.h>
  #include <linux/sysctl.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
11
  #include <linux/in6.h>
  #include <linux/ipv6.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
12
  #include <linux/slab.h>
bc3b2d7fb   Paul Gortmaker   net: Add export.h...
13
  #include <linux/export.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14
15
16
  #include <net/ndisc.h>
  #include <net/ipv6.h>
  #include <net/addrconf.h>
04128f233   Pavel Emelyanov   [INET]: Collect c...
17
  #include <net/inet_frag.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18

bf36076a6   Eric W. Biederman   net: Fix ipv6 nei...
19
  static struct ctl_table empty[1];
9d2a8fa96   Eric W. Biederman   net ipv6: Fix dup...
20
21
22
23
24
25
26
27
28
  static ctl_table ipv6_static_skeleton[] = {
  	{
  		.procname	= "neigh",
  		.maxlen		= 0,
  		.mode		= 0555,
  		.child		= empty,
  	},
  	{ }
  };
760f2d018   Daniel Lezcano   [NETNS][IPV6]: Ma...
29
  static ctl_table ipv6_table_template[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
  	{
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
32
33
  		.procname	= "route",
  		.maxlen		= 0,
  		.mode		= 0555,
760f2d018   Daniel Lezcano   [NETNS][IPV6]: Ma...
34
  		.child		= ipv6_route_table_template
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
36
  	},
  	{
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
39
  		.procname	= "icmp",
  		.maxlen		= 0,
  		.mode		= 0555,
760f2d018   Daniel Lezcano   [NETNS][IPV6]: Ma...
40
  		.child		= ipv6_icmp_table_template
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
42
  	},
  	{
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
  		.procname	= "bindv6only",
99bc9c4e4   Daniel Lezcano   [NETNS][IPV6]: Ma...
44
  		.data		= &init_net.ipv6.sysctl.bindv6only,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
45
46
  		.maxlen		= sizeof(int),
  		.mode		= 0644,
6d9f239a1   Alexey Dobriyan   net: '&' redux
47
  		.proc_handler	= proc_dointvec
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
48
  	},
f8572d8f2   Eric W. Biederman   sysctl net: Remov...
49
  	{ }
34ac2573e   Pavel Emelyanov   ipv6: Register so...
50
  };
81e432138   Gerrit Renker   inet6: functions ...
51
  static ctl_table ipv6_rotable[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52
  	{
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
54
55
56
  		.procname	= "mld_max_msf",
  		.data		= &sysctl_mld_max_msf,
  		.maxlen		= sizeof(int),
  		.mode		= 0644,
6d9f239a1   Alexey Dobriyan   net: '&' redux
57
  		.proc_handler	= proc_dointvec
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
58
  	},
f8572d8f2   Eric W. Biederman   sysctl net: Remov...
59
  	{ }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60
  };
3d7cc2ba6   Pavel Emelyanov   [NETFILTER]: Swit...
61
  struct ctl_path net_ipv6_ctl_path[] = {
f8572d8f2   Eric W. Biederman   sysctl net: Remov...
62
63
  	{ .procname = "net", },
  	{ .procname = "ipv6", },
4d43b78ac   Pavel Emelyanov   [IPV6]: Use sysct...
64
  	{ },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
65
  };
3d7cc2ba6   Pavel Emelyanov   [NETFILTER]: Swit...
66
  EXPORT_SYMBOL_GPL(net_ipv6_ctl_path);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
67

2c8c1e729   Alexey Dobriyan   net: spread __net...
68
  static int __net_init ipv6_sysctl_net_init(struct net *net)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69
  {
760f2d018   Daniel Lezcano   [NETNS][IPV6]: Ma...
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  	struct ctl_table *ipv6_table;
  	struct ctl_table *ipv6_route_table;
  	struct ctl_table *ipv6_icmp_table;
  	int err;
  
  	err = -ENOMEM;
  	ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template),
  			     GFP_KERNEL);
  	if (!ipv6_table)
  		goto out;
  
  	ipv6_route_table = ipv6_route_sysctl_init(net);
  	if (!ipv6_route_table)
  		goto out_ipv6_table;
5ee091050   YOSHIFUJI Hideaki   [IPV6] SYSCTL: co...
84
  	ipv6_table[0].child = ipv6_route_table;
760f2d018   Daniel Lezcano   [NETNS][IPV6]: Ma...
85
86
87
88
  
  	ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
  	if (!ipv6_icmp_table)
  		goto out_ipv6_route_table;
760f2d018   Daniel Lezcano   [NETNS][IPV6]: Ma...
89
  	ipv6_table[1].child = ipv6_icmp_table;
99bc9c4e4   Daniel Lezcano   [NETNS][IPV6]: Ma...
90
  	ipv6_table[2].data = &net->ipv6.sysctl.bindv6only;
760f2d018   Daniel Lezcano   [NETNS][IPV6]: Ma...
91
92
93
  	net->ipv6.sysctl.table = register_net_sysctl_table(net, net_ipv6_ctl_path,
  							   ipv6_table);
  	if (!net->ipv6.sysctl.table)
760f2d018   Daniel Lezcano   [NETNS][IPV6]: Ma...
94
95
96
97
98
  		goto out_ipv6_icmp_table;
  
  	err = 0;
  out:
  	return err;
291480c09   Daniel Lezcano   [NETNS][IPV6]: Ma...
99

760f2d018   Daniel Lezcano   [NETNS][IPV6]: Ma...
100
101
102
103
104
105
106
  out_ipv6_icmp_table:
  	kfree(ipv6_icmp_table);
  out_ipv6_route_table:
  	kfree(ipv6_route_table);
  out_ipv6_table:
  	kfree(ipv6_table);
  	goto out;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107
  }
2c8c1e729   Alexey Dobriyan   net: spread __net...
108
  static void __net_exit ipv6_sysctl_net_exit(struct net *net)
89918fc27   Daniel Lezcano   [NETNS][IPV6]: Ma...
109
  {
760f2d018   Daniel Lezcano   [NETNS][IPV6]: Ma...
110
111
112
113
114
115
116
117
118
119
120
121
122
  	struct ctl_table *ipv6_table;
  	struct ctl_table *ipv6_route_table;
  	struct ctl_table *ipv6_icmp_table;
  
  	ipv6_table = net->ipv6.sysctl.table->ctl_table_arg;
  	ipv6_route_table = ipv6_table[0].child;
  	ipv6_icmp_table = ipv6_table[1].child;
  
  	unregister_net_sysctl_table(net->ipv6.sysctl.table);
  
  	kfree(ipv6_table);
  	kfree(ipv6_route_table);
  	kfree(ipv6_icmp_table);
89918fc27   Daniel Lezcano   [NETNS][IPV6]: Ma...
123
124
125
126
127
128
  }
  
  static struct pernet_operations ipv6_sysctl_net_ops = {
  	.init = ipv6_sysctl_net_init,
  	.exit = ipv6_sysctl_net_exit,
  };
34ac2573e   Pavel Emelyanov   ipv6: Register so...
129
  static struct ctl_table_header *ip6_header;
89918fc27   Daniel Lezcano   [NETNS][IPV6]: Ma...
130
131
  int ipv6_sysctl_register(void)
  {
c19a28e11   Fernando Carrijo   remove lots of do...
132
  	int err = -ENOMEM;
34ac2573e   Pavel Emelyanov   ipv6: Register so...
133

81e432138   Gerrit Renker   inet6: functions ...
134
  	ip6_header = register_net_sysctl_rotable(net_ipv6_ctl_path, ipv6_rotable);
34ac2573e   Pavel Emelyanov   ipv6: Register so...
135
136
137
138
139
140
141
142
143
144
145
146
  	if (ip6_header == NULL)
  		goto out;
  
  	err = register_pernet_subsys(&ipv6_sysctl_net_ops);
  	if (err)
  		goto err_pernet;
  out:
  	return err;
  
  err_pernet:
  	unregister_net_sysctl_table(ip6_header);
  	goto out;
89918fc27   Daniel Lezcano   [NETNS][IPV6]: Ma...
147
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
148
149
  void ipv6_sysctl_unregister(void)
  {
34ac2573e   Pavel Emelyanov   ipv6: Register so...
150
  	unregister_net_sysctl_table(ip6_header);
89918fc27   Daniel Lezcano   [NETNS][IPV6]: Ma...
151
  	unregister_pernet_subsys(&ipv6_sysctl_net_ops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
152
  }
eeb61f719   Al Viro   missing bits of n...
153
154
155
156
157
  
  static struct ctl_table_header *ip6_base;
  
  int ipv6_static_sysctl_register(void)
  {
9d2a8fa96   Eric W. Biederman   net ipv6: Fix dup...
158
  	ip6_base = register_sysctl_paths(net_ipv6_ctl_path, ipv6_static_skeleton);
eeb61f719   Al Viro   missing bits of n...
159
160
161
162
163
164
165
166
167
  	if (ip6_base == NULL)
  		return -ENOMEM;
  	return 0;
  }
  
  void ipv6_static_sysctl_unregister(void)
  {
  	unregister_net_sysctl_table(ip6_base);
  }