Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Pavel Emelyanov | 04128f2 | 2007-10-15 02:33:45 -0700 | [diff] [blame] | 15 | #include <net/inet_frag.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 17 | extern struct ctl_table *ipv6_route_sysctl_init(struct net *net); |
| 18 | extern struct ctl_table *ipv6_icmp_sysctl_init(struct net *net); |
| 19 | |
| 20 | static ctl_table ipv6_table_template[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | { |
| 22 | .ctl_name = NET_IPV6_ROUTE, |
| 23 | .procname = "route", |
| 24 | .maxlen = 0, |
| 25 | .mode = 0555, |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 26 | .child = ipv6_route_table_template |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | }, |
| 28 | { |
| 29 | .ctl_name = NET_IPV6_ICMP, |
| 30 | .procname = "icmp", |
| 31 | .maxlen = 0, |
| 32 | .mode = 0555, |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 33 | .child = ipv6_icmp_table_template |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | }, |
| 35 | { |
| 36 | .ctl_name = NET_IPV6_BINDV6ONLY, |
| 37 | .procname = "bindv6only", |
Daniel Lezcano | 99bc9c4 | 2008-01-10 02:54:53 -0800 | [diff] [blame] | 38 | .data = &init_net.ipv6.sysctl.bindv6only, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | .maxlen = sizeof(int), |
| 40 | .mode = 0644, |
| 41 | .proc_handler = &proc_dointvec |
| 42 | }, |
| 43 | { |
| 44 | .ctl_name = NET_IPV6_IP6FRAG_HIGH_THRESH, |
| 45 | .procname = "ip6frag_high_thresh", |
Daniel Lezcano | e71e034 | 2008-01-10 02:56:03 -0800 | [diff] [blame] | 46 | .data = &init_net.ipv6.sysctl.frags.high_thresh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | .maxlen = sizeof(int), |
| 48 | .mode = 0644, |
| 49 | .proc_handler = &proc_dointvec |
| 50 | }, |
| 51 | { |
| 52 | .ctl_name = NET_IPV6_IP6FRAG_LOW_THRESH, |
| 53 | .procname = "ip6frag_low_thresh", |
Daniel Lezcano | e71e034 | 2008-01-10 02:56:03 -0800 | [diff] [blame] | 54 | .data = &init_net.ipv6.sysctl.frags.low_thresh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | .maxlen = sizeof(int), |
| 56 | .mode = 0644, |
| 57 | .proc_handler = &proc_dointvec |
| 58 | }, |
| 59 | { |
| 60 | .ctl_name = NET_IPV6_IP6FRAG_TIME, |
| 61 | .procname = "ip6frag_time", |
Daniel Lezcano | e71e034 | 2008-01-10 02:56:03 -0800 | [diff] [blame] | 62 | .data = &init_net.ipv6.sysctl.frags.timeout, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | .maxlen = sizeof(int), |
| 64 | .mode = 0644, |
| 65 | .proc_handler = &proc_dointvec_jiffies, |
| 66 | .strategy = &sysctl_jiffies, |
| 67 | }, |
| 68 | { |
| 69 | .ctl_name = NET_IPV6_IP6FRAG_SECRET_INTERVAL, |
| 70 | .procname = "ip6frag_secret_interval", |
Daniel Lezcano | e71e034 | 2008-01-10 02:56:03 -0800 | [diff] [blame] | 71 | .data = &init_net.ipv6.sysctl.frags.secret_interval, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | .maxlen = sizeof(int), |
| 73 | .mode = 0644, |
| 74 | .proc_handler = &proc_dointvec_jiffies, |
| 75 | .strategy = &sysctl_jiffies |
| 76 | }, |
| 77 | { |
| 78 | .ctl_name = NET_IPV6_MLD_MAX_MSF, |
| 79 | .procname = "mld_max_msf", |
| 80 | .data = &sysctl_mld_max_msf, |
| 81 | .maxlen = sizeof(int), |
| 82 | .mode = 0644, |
| 83 | .proc_handler = &proc_dointvec |
| 84 | }, |
| 85 | { .ctl_name = 0 } |
| 86 | }; |
| 87 | |
Pavel Emelyanov | 3d7cc2b | 2008-01-09 00:33:11 -0800 | [diff] [blame] | 88 | struct ctl_path net_ipv6_ctl_path[] = { |
Pavel Emelyanov | 4d43b78 | 2007-12-05 01:44:02 -0800 | [diff] [blame] | 89 | { .procname = "net", .ctl_name = CTL_NET, }, |
| 90 | { .procname = "ipv6", .ctl_name = NET_IPV6, }, |
| 91 | { }, |
| 92 | }; |
Pavel Emelyanov | 3d7cc2b | 2008-01-09 00:33:11 -0800 | [diff] [blame] | 93 | EXPORT_SYMBOL_GPL(net_ipv6_ctl_path); |
Pavel Emelyanov | 4d43b78 | 2007-12-05 01:44:02 -0800 | [diff] [blame] | 94 | |
Daniel Lezcano | 89918fc | 2008-01-10 02:49:34 -0800 | [diff] [blame] | 95 | static int ipv6_sysctl_net_init(struct net *net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 97 | struct ctl_table *ipv6_table; |
| 98 | struct ctl_table *ipv6_route_table; |
| 99 | struct ctl_table *ipv6_icmp_table; |
| 100 | int err; |
| 101 | |
| 102 | err = -ENOMEM; |
| 103 | ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template), |
| 104 | GFP_KERNEL); |
| 105 | if (!ipv6_table) |
| 106 | goto out; |
| 107 | |
| 108 | ipv6_route_table = ipv6_route_sysctl_init(net); |
| 109 | if (!ipv6_route_table) |
| 110 | goto out_ipv6_table; |
| 111 | |
| 112 | ipv6_icmp_table = ipv6_icmp_sysctl_init(net); |
| 113 | if (!ipv6_icmp_table) |
| 114 | goto out_ipv6_route_table; |
| 115 | |
| 116 | ipv6_table[0].child = ipv6_route_table; |
| 117 | ipv6_table[1].child = ipv6_icmp_table; |
| 118 | |
Daniel Lezcano | 99bc9c4 | 2008-01-10 02:54:53 -0800 | [diff] [blame] | 119 | ipv6_table[2].data = &net->ipv6.sysctl.bindv6only; |
Daniel Lezcano | e71e034 | 2008-01-10 02:56:03 -0800 | [diff] [blame] | 120 | ipv6_table[3].data = &net->ipv6.sysctl.frags.high_thresh; |
| 121 | ipv6_table[4].data = &net->ipv6.sysctl.frags.low_thresh; |
| 122 | ipv6_table[5].data = &net->ipv6.sysctl.frags.timeout; |
| 123 | ipv6_table[6].data = &net->ipv6.sysctl.frags.secret_interval; |
Daniel Lezcano | 99bc9c4 | 2008-01-10 02:54:53 -0800 | [diff] [blame] | 124 | |
Daniel Lezcano | 7c76509 | 2008-01-10 02:57:43 -0800 | [diff] [blame^] | 125 | /* We don't want this value to be per namespace, it should be global |
| 126 | to all namespaces, so make it read-only when we are not in the |
| 127 | init network namespace */ |
| 128 | if (net != &init_net) |
| 129 | ipv6_table[7].mode = 0444; |
| 130 | |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 131 | net->ipv6.sysctl.table = register_net_sysctl_table(net, net_ipv6_ctl_path, |
| 132 | ipv6_table); |
| 133 | if (!net->ipv6.sysctl.table) |
Daniel Lezcano | 291480c | 2008-01-10 02:47:55 -0800 | [diff] [blame] | 134 | return -ENOMEM; |
| 135 | |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 136 | if (!net->ipv6.sysctl.table) |
| 137 | goto out_ipv6_icmp_table; |
Daniel Lezcano | 291480c | 2008-01-10 02:47:55 -0800 | [diff] [blame] | 138 | |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 139 | err = 0; |
| 140 | out: |
| 141 | return err; |
| 142 | |
| 143 | out_ipv6_icmp_table: |
| 144 | kfree(ipv6_icmp_table); |
| 145 | out_ipv6_route_table: |
| 146 | kfree(ipv6_route_table); |
| 147 | out_ipv6_table: |
| 148 | kfree(ipv6_table); |
| 149 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Daniel Lezcano | 89918fc | 2008-01-10 02:49:34 -0800 | [diff] [blame] | 152 | static void ipv6_sysctl_net_exit(struct net *net) |
| 153 | { |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 154 | struct ctl_table *ipv6_table; |
| 155 | struct ctl_table *ipv6_route_table; |
| 156 | struct ctl_table *ipv6_icmp_table; |
| 157 | |
| 158 | ipv6_table = net->ipv6.sysctl.table->ctl_table_arg; |
| 159 | ipv6_route_table = ipv6_table[0].child; |
| 160 | ipv6_icmp_table = ipv6_table[1].child; |
| 161 | |
| 162 | unregister_net_sysctl_table(net->ipv6.sysctl.table); |
| 163 | |
| 164 | kfree(ipv6_table); |
| 165 | kfree(ipv6_route_table); |
| 166 | kfree(ipv6_icmp_table); |
Daniel Lezcano | 89918fc | 2008-01-10 02:49:34 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | static struct pernet_operations ipv6_sysctl_net_ops = { |
| 170 | .init = ipv6_sysctl_net_init, |
| 171 | .exit = ipv6_sysctl_net_exit, |
| 172 | }; |
| 173 | |
| 174 | int ipv6_sysctl_register(void) |
| 175 | { |
| 176 | return register_pernet_subsys(&ipv6_sysctl_net_ops); |
| 177 | } |
| 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | void ipv6_sysctl_unregister(void) |
| 180 | { |
Daniel Lezcano | 89918fc | 2008-01-10 02:49:34 -0800 | [diff] [blame] | 181 | unregister_pernet_subsys(&ipv6_sysctl_net_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |