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