Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * sysctl_net_ipv6.c: sysctl interface to net IPV6 subsystem. |
| 4 | * |
| 5 | * Changes: |
| 6 | * YOSHIFUJI Hideaki @USAGI: added icmp sysctl table. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/mm.h> |
| 10 | #include <linux/sysctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/in6.h> |
| 12 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 13 | #include <linux/slab.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 14 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <net/ndisc.h> |
| 16 | #include <net/ipv6.h> |
| 17 | #include <net/addrconf.h> |
Pavel Emelyanov | 04128f2 | 2007-10-15 02:33:45 -0700 | [diff] [blame] | 18 | #include <net/inet_frag.h> |
David Ahern | b4bac17 | 2018-03-02 08:32:18 -0800 | [diff] [blame] | 19 | #include <net/netevent.h> |
Ido Schimmel | ed13923 | 2021-05-17 21:15:22 +0300 | [diff] [blame] | 20 | #include <net/ip_fib.h> |
Huw Davies | 4fee524 | 2016-06-27 15:06:17 -0400 | [diff] [blame] | 21 | #ifdef CONFIG_NETLABEL |
| 22 | #include <net/calipso.h> |
| 23 | #endif |
Justin Iurman | 9ee11f0 | 2021-07-20 21:42:57 +0200 | [diff] [blame] | 24 | #include <linux/ioam6.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Ido Schimmel | 05d4487 | 2020-09-02 16:16:59 +0300 | [diff] [blame] | 26 | static int two = 2; |
Ido Schimmel | 73c2c5c | 2021-05-17 21:15:23 +0300 | [diff] [blame] | 27 | static int three = 3; |
Eric Dumazet | a346abe | 2019-07-01 06:39:36 -0700 | [diff] [blame] | 28 | static int flowlabel_reflect_max = 0x7; |
Tom Herbert | 4224090 | 2015-07-31 16:52:12 -0700 | [diff] [blame] | 29 | static int auto_flowlabels_max = IP6_AUTO_FLOW_LABEL_MAX; |
Ido Schimmel | ed13923 | 2021-05-17 21:15:22 +0300 | [diff] [blame] | 30 | static u32 rt6_multipath_hash_fields_all_mask = |
| 31 | FIB_MULTIPATH_HASH_FIELD_ALL_MASK; |
Justin Iurman | 9ee11f0 | 2021-07-20 21:42:57 +0200 | [diff] [blame] | 32 | static u32 ioam6_id_max = IOAM6_DEFAULT_ID; |
| 33 | static u64 ioam6_id_wide_max = IOAM6_DEFAULT_ID_WIDE; |
Tom Herbert | 4224090 | 2015-07-31 16:52:12 -0700 | [diff] [blame] | 34 | |
David Ahern | b4bac17 | 2018-03-02 08:32:18 -0800 | [diff] [blame] | 35 | static int proc_rt6_multipath_hash_policy(struct ctl_table *table, int write, |
Christoph Hellwig | 3292739 | 2020-04-24 08:43:38 +0200 | [diff] [blame] | 36 | void *buffer, size_t *lenp, loff_t *ppos) |
David Ahern | b4bac17 | 2018-03-02 08:32:18 -0800 | [diff] [blame] | 37 | { |
| 38 | struct net *net; |
| 39 | int ret; |
| 40 | |
| 41 | net = container_of(table->data, struct net, |
| 42 | ipv6.sysctl.multipath_hash_policy); |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 43 | ret = proc_dou8vec_minmax(table, write, buffer, lenp, ppos); |
David Ahern | b4bac17 | 2018-03-02 08:32:18 -0800 | [diff] [blame] | 44 | if (write && ret == 0) |
| 45 | call_netevent_notifiers(NETEVENT_IPV6_MPATH_HASH_UPDATE, net); |
| 46 | |
| 47 | return ret; |
| 48 | } |
Hannes Frederic Sowa | 2f71193 | 2014-09-02 15:49:25 +0200 | [diff] [blame] | 49 | |
Ido Schimmel | eb0e4d59 | 2021-05-19 15:08:18 +0300 | [diff] [blame] | 50 | static int |
| 51 | proc_rt6_multipath_hash_fields(struct ctl_table *table, int write, void *buffer, |
| 52 | size_t *lenp, loff_t *ppos) |
| 53 | { |
| 54 | struct net *net; |
| 55 | int ret; |
| 56 | |
| 57 | net = container_of(table->data, struct net, |
| 58 | ipv6.sysctl.multipath_hash_fields); |
| 59 | ret = proc_douintvec_minmax(table, write, buffer, lenp, ppos); |
| 60 | if (write && ret == 0) |
| 61 | call_netevent_notifiers(NETEVENT_IPV6_MPATH_HASH_UPDATE, net); |
| 62 | |
| 63 | return ret; |
| 64 | } |
| 65 | |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 66 | static struct ctl_table ipv6_table_template[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | .procname = "bindv6only", |
Daniel Lezcano | 99bc9c4 | 2008-01-10 02:54:53 -0800 | [diff] [blame] | 69 | .data = &init_net.ipv6.sysctl.bindv6only, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 70 | .maxlen = sizeof(u8), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | .mode = 0644, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 72 | .proc_handler = proc_dou8vec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | }, |
FX Le Bail | 509aba3 | 2014-01-07 14:57:27 +0100 | [diff] [blame] | 74 | { |
| 75 | .procname = "anycast_src_echo_reply", |
FX Le Bail | ec35b61 | 2014-01-13 15:59:01 +0100 | [diff] [blame] | 76 | .data = &init_net.ipv6.sysctl.anycast_src_echo_reply, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 77 | .maxlen = sizeof(u8), |
FX Le Bail | 509aba3 | 2014-01-07 14:57:27 +0100 | [diff] [blame] | 78 | .mode = 0644, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 79 | .proc_handler = proc_dou8vec_minmax, |
FX Le Bail | 509aba3 | 2014-01-07 14:57:27 +0100 | [diff] [blame] | 80 | }, |
Florent Fourcot | 6444f72 | 2014-01-17 17:15:05 +0100 | [diff] [blame] | 81 | { |
| 82 | .procname = "flowlabel_consistency", |
| 83 | .data = &init_net.ipv6.sysctl.flowlabel_consistency, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 84 | .maxlen = sizeof(u8), |
Florent Fourcot | 6444f72 | 2014-01-17 17:15:05 +0100 | [diff] [blame] | 85 | .mode = 0644, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 86 | .proc_handler = proc_dou8vec_minmax, |
Florent Fourcot | 6444f72 | 2014-01-17 17:15:05 +0100 | [diff] [blame] | 87 | }, |
Lorenzo Colitti | e110861 | 2014-05-13 10:17:33 -0700 | [diff] [blame] | 88 | { |
Tom Herbert | cb1ce2e | 2014-07-01 21:33:10 -0700 | [diff] [blame] | 89 | .procname = "auto_flowlabels", |
| 90 | .data = &init_net.ipv6.sysctl.auto_flowlabels, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 91 | .maxlen = sizeof(u8), |
Tom Herbert | cb1ce2e | 2014-07-01 21:33:10 -0700 | [diff] [blame] | 92 | .mode = 0644, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 93 | .proc_handler = proc_dou8vec_minmax, |
Tom Herbert | 4224090 | 2015-07-31 16:52:12 -0700 | [diff] [blame] | 94 | .extra2 = &auto_flowlabels_max |
Tom Herbert | cb1ce2e | 2014-07-01 21:33:10 -0700 | [diff] [blame] | 95 | }, |
| 96 | { |
Lorenzo Colitti | e110861 | 2014-05-13 10:17:33 -0700 | [diff] [blame] | 97 | .procname = "fwmark_reflect", |
| 98 | .data = &init_net.ipv6.sysctl.fwmark_reflect, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 99 | .maxlen = sizeof(u8), |
Lorenzo Colitti | e110861 | 2014-05-13 10:17:33 -0700 | [diff] [blame] | 100 | .mode = 0644, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 101 | .proc_handler = proc_dou8vec_minmax, |
Lorenzo Colitti | e110861 | 2014-05-13 10:17:33 -0700 | [diff] [blame] | 102 | }, |
Hannes Frederic Sowa | 1855b7c | 2015-03-23 23:36:05 +0100 | [diff] [blame] | 103 | { |
| 104 | .procname = "idgen_retries", |
| 105 | .data = &init_net.ipv6.sysctl.idgen_retries, |
| 106 | .maxlen = sizeof(int), |
| 107 | .mode = 0644, |
| 108 | .proc_handler = proc_dointvec, |
| 109 | }, |
| 110 | { |
| 111 | .procname = "idgen_delay", |
| 112 | .data = &init_net.ipv6.sysctl.idgen_delay, |
| 113 | .maxlen = sizeof(int), |
| 114 | .mode = 0644, |
| 115 | .proc_handler = proc_dointvec_jiffies, |
| 116 | }, |
Tom Herbert | 82a584b | 2015-04-29 15:33:21 -0700 | [diff] [blame] | 117 | { |
| 118 | .procname = "flowlabel_state_ranges", |
| 119 | .data = &init_net.ipv6.sysctl.flowlabel_state_ranges, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 120 | .maxlen = sizeof(u8), |
Tom Herbert | 82a584b | 2015-04-29 15:33:21 -0700 | [diff] [blame] | 121 | .mode = 0644, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 122 | .proc_handler = proc_dou8vec_minmax, |
Tom Herbert | 82a584b | 2015-04-29 15:33:21 -0700 | [diff] [blame] | 123 | }, |
Tom Herbert | 35a256f | 2015-07-08 16:58:22 -0700 | [diff] [blame] | 124 | { |
| 125 | .procname = "ip_nonlocal_bind", |
| 126 | .data = &init_net.ipv6.sysctl.ip_nonlocal_bind, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 127 | .maxlen = sizeof(u8), |
Tom Herbert | 35a256f | 2015-07-08 16:58:22 -0700 | [diff] [blame] | 128 | .mode = 0644, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 129 | .proc_handler = proc_dou8vec_minmax, |
Tom Herbert | 35a256f | 2015-07-08 16:58:22 -0700 | [diff] [blame] | 130 | }, |
Jakub Sitnicki | 22b6722 | 2017-08-23 09:55:41 +0200 | [diff] [blame] | 131 | { |
| 132 | .procname = "flowlabel_reflect", |
| 133 | .data = &init_net.ipv6.sysctl.flowlabel_reflect, |
| 134 | .maxlen = sizeof(int), |
| 135 | .mode = 0644, |
Eiichi Tsukata | 00dc330 | 2019-06-28 11:37:14 +0900 | [diff] [blame] | 136 | .proc_handler = proc_dointvec_minmax, |
Matteo Croce | eec4844 | 2019-07-18 15:58:50 -0700 | [diff] [blame] | 137 | .extra1 = SYSCTL_ZERO, |
Eric Dumazet | a346abe | 2019-07-01 06:39:36 -0700 | [diff] [blame] | 138 | .extra2 = &flowlabel_reflect_max, |
Jakub Sitnicki | 22b6722 | 2017-08-23 09:55:41 +0200 | [diff] [blame] | 139 | }, |
Tom Herbert | 47d3d7a | 2017-10-30 14:16:00 -0700 | [diff] [blame] | 140 | { |
| 141 | .procname = "max_dst_opts_number", |
| 142 | .data = &init_net.ipv6.sysctl.max_dst_opts_cnt, |
| 143 | .maxlen = sizeof(int), |
| 144 | .mode = 0644, |
| 145 | .proc_handler = proc_dointvec |
| 146 | }, |
| 147 | { |
| 148 | .procname = "max_hbh_opts_number", |
| 149 | .data = &init_net.ipv6.sysctl.max_hbh_opts_cnt, |
| 150 | .maxlen = sizeof(int), |
| 151 | .mode = 0644, |
| 152 | .proc_handler = proc_dointvec |
| 153 | }, |
| 154 | { |
| 155 | .procname = "max_dst_opts_length", |
| 156 | .data = &init_net.ipv6.sysctl.max_dst_opts_len, |
| 157 | .maxlen = sizeof(int), |
| 158 | .mode = 0644, |
| 159 | .proc_handler = proc_dointvec |
| 160 | }, |
| 161 | { |
| 162 | .procname = "max_hbh_length", |
| 163 | .data = &init_net.ipv6.sysctl.max_hbh_opts_len, |
| 164 | .maxlen = sizeof(int), |
| 165 | .mode = 0644, |
| 166 | .proc_handler = proc_dointvec |
| 167 | }, |
David Ahern | b4bac17 | 2018-03-02 08:32:18 -0800 | [diff] [blame] | 168 | { |
| 169 | .procname = "fib_multipath_hash_policy", |
| 170 | .data = &init_net.ipv6.sysctl.multipath_hash_policy, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 171 | .maxlen = sizeof(u8), |
David Ahern | b4bac17 | 2018-03-02 08:32:18 -0800 | [diff] [blame] | 172 | .mode = 0644, |
| 173 | .proc_handler = proc_rt6_multipath_hash_policy, |
Matteo Croce | eec4844 | 2019-07-18 15:58:50 -0700 | [diff] [blame] | 174 | .extra1 = SYSCTL_ZERO, |
Ido Schimmel | 73c2c5c | 2021-05-17 21:15:23 +0300 | [diff] [blame] | 175 | .extra2 = &three, |
David Ahern | b4bac17 | 2018-03-02 08:32:18 -0800 | [diff] [blame] | 176 | }, |
Ahmed Abdelsalam | b5facfd | 2018-04-24 20:23:16 +0200 | [diff] [blame] | 177 | { |
Ido Schimmel | ed13923 | 2021-05-17 21:15:22 +0300 | [diff] [blame] | 178 | .procname = "fib_multipath_hash_fields", |
| 179 | .data = &init_net.ipv6.sysctl.multipath_hash_fields, |
| 180 | .maxlen = sizeof(u32), |
| 181 | .mode = 0644, |
Ido Schimmel | eb0e4d59 | 2021-05-19 15:08:18 +0300 | [diff] [blame] | 182 | .proc_handler = proc_rt6_multipath_hash_fields, |
Ido Schimmel | ed13923 | 2021-05-17 21:15:22 +0300 | [diff] [blame] | 183 | .extra1 = SYSCTL_ONE, |
| 184 | .extra2 = &rt6_multipath_hash_fields_all_mask, |
| 185 | }, |
| 186 | { |
Ahmed Abdelsalam | b5facfd | 2018-04-24 20:23:16 +0200 | [diff] [blame] | 187 | .procname = "seg6_flowlabel", |
| 188 | .data = &init_net.ipv6.sysctl.seg6_flowlabel, |
| 189 | .maxlen = sizeof(int), |
| 190 | .mode = 0644, |
| 191 | .proc_handler = proc_dointvec |
| 192 | }, |
Amit Cohen | 907eea4 | 2021-02-01 21:47:55 +0200 | [diff] [blame] | 193 | { |
| 194 | .procname = "fib_notify_on_flag_change", |
| 195 | .data = &init_net.ipv6.sysctl.fib_notify_on_flag_change, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 196 | .maxlen = sizeof(u8), |
Amit Cohen | 907eea4 | 2021-02-01 21:47:55 +0200 | [diff] [blame] | 197 | .mode = 0644, |
Eric Dumazet | a617563 | 2021-03-31 10:52:12 -0700 | [diff] [blame] | 198 | .proc_handler = proc_dou8vec_minmax, |
Amit Cohen | 907eea4 | 2021-02-01 21:47:55 +0200 | [diff] [blame] | 199 | .extra1 = SYSCTL_ZERO, |
Amit Cohen | 6fad361 | 2021-02-07 10:22:53 +0200 | [diff] [blame] | 200 | .extra2 = &two, |
Amit Cohen | 907eea4 | 2021-02-01 21:47:55 +0200 | [diff] [blame] | 201 | }, |
Justin Iurman | 9ee11f0 | 2021-07-20 21:42:57 +0200 | [diff] [blame] | 202 | { |
| 203 | .procname = "ioam6_id", |
| 204 | .data = &init_net.ipv6.sysctl.ioam6_id, |
| 205 | .maxlen = sizeof(u32), |
| 206 | .mode = 0644, |
| 207 | .proc_handler = proc_douintvec_minmax, |
| 208 | .extra2 = &ioam6_id_max, |
| 209 | }, |
| 210 | { |
| 211 | .procname = "ioam6_id_wide", |
| 212 | .data = &init_net.ipv6.sysctl.ioam6_id_wide, |
| 213 | .maxlen = sizeof(u64), |
| 214 | .mode = 0644, |
| 215 | .proc_handler = proc_doulongvec_minmax, |
| 216 | .extra2 = &ioam6_id_wide_max, |
| 217 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 218 | { } |
Pavel Emelyanov | 34ac257 | 2008-05-19 13:53:30 -0700 | [diff] [blame] | 219 | }; |
| 220 | |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 221 | static struct ctl_table ipv6_rotable[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | .procname = "mld_max_msf", |
| 224 | .data = &sysctl_mld_max_msf, |
| 225 | .maxlen = sizeof(int), |
| 226 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 227 | .proc_handler = proc_dointvec |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | }, |
Hannes Frederic Sowa | 2f71193 | 2014-09-02 15:49:25 +0200 | [diff] [blame] | 229 | { |
| 230 | .procname = "mld_qrv", |
| 231 | .data = &sysctl_mld_qrv, |
| 232 | .maxlen = sizeof(int), |
| 233 | .mode = 0644, |
| 234 | .proc_handler = proc_dointvec_minmax, |
Matteo Croce | eec4844 | 2019-07-18 15:58:50 -0700 | [diff] [blame] | 235 | .extra1 = SYSCTL_ONE |
Hannes Frederic Sowa | 2f71193 | 2014-09-02 15:49:25 +0200 | [diff] [blame] | 236 | }, |
Huw Davies | 4fee524 | 2016-06-27 15:06:17 -0400 | [diff] [blame] | 237 | #ifdef CONFIG_NETLABEL |
| 238 | { |
| 239 | .procname = "calipso_cache_enable", |
| 240 | .data = &calipso_cache_enabled, |
| 241 | .maxlen = sizeof(int), |
| 242 | .mode = 0644, |
| 243 | .proc_handler = proc_dointvec, |
| 244 | }, |
| 245 | { |
| 246 | .procname = "calipso_cache_bucket_size", |
| 247 | .data = &calipso_cache_bucketsize, |
| 248 | .maxlen = sizeof(int), |
| 249 | .mode = 0644, |
| 250 | .proc_handler = proc_dointvec, |
| 251 | }, |
| 252 | #endif /* CONFIG_NETLABEL */ |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 253 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | }; |
| 255 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 256 | static int __net_init ipv6_sysctl_net_init(struct net *net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | { |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 258 | struct ctl_table *ipv6_table; |
| 259 | struct ctl_table *ipv6_route_table; |
| 260 | struct ctl_table *ipv6_icmp_table; |
Cambda Zhu | d2f7e56 | 2020-03-03 14:54:34 +0800 | [diff] [blame] | 261 | int err, i; |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 262 | |
| 263 | err = -ENOMEM; |
| 264 | ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template), |
| 265 | GFP_KERNEL); |
| 266 | if (!ipv6_table) |
| 267 | goto out; |
Cambda Zhu | d2f7e56 | 2020-03-03 14:54:34 +0800 | [diff] [blame] | 268 | /* Update the variables to point into the current struct net */ |
| 269 | for (i = 0; i < ARRAY_SIZE(ipv6_table_template) - 1; i++) |
| 270 | ipv6_table[i].data += (void *)net - (void *)&init_net; |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 271 | |
| 272 | ipv6_route_table = ipv6_route_sysctl_init(net); |
| 273 | if (!ipv6_route_table) |
| 274 | goto out_ipv6_table; |
| 275 | |
| 276 | ipv6_icmp_table = ipv6_icmp_sysctl_init(net); |
| 277 | if (!ipv6_icmp_table) |
| 278 | goto out_ipv6_route_table; |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 279 | |
Eric W. Biederman | 6dceb03 | 2012-04-19 13:37:09 +0000 | [diff] [blame] | 280 | net->ipv6.sysctl.hdr = register_net_sysctl(net, "net/ipv6", ipv6_table); |
| 281 | if (!net->ipv6.sysctl.hdr) |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 282 | goto out_ipv6_icmp_table; |
Daniel Lezcano | 291480c | 2008-01-10 02:47:55 -0800 | [diff] [blame] | 283 | |
Eric W. Biederman | 6dceb03 | 2012-04-19 13:37:09 +0000 | [diff] [blame] | 284 | net->ipv6.sysctl.route_hdr = |
| 285 | register_net_sysctl(net, "net/ipv6/route", ipv6_route_table); |
| 286 | if (!net->ipv6.sysctl.route_hdr) |
| 287 | goto out_unregister_ipv6_table; |
| 288 | |
| 289 | net->ipv6.sysctl.icmp_hdr = |
| 290 | register_net_sysctl(net, "net/ipv6/icmp", ipv6_icmp_table); |
| 291 | if (!net->ipv6.sysctl.icmp_hdr) |
| 292 | goto out_unregister_route_table; |
| 293 | |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 294 | err = 0; |
| 295 | out: |
| 296 | return err; |
Eric W. Biederman | 6dceb03 | 2012-04-19 13:37:09 +0000 | [diff] [blame] | 297 | out_unregister_route_table: |
| 298 | unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr); |
| 299 | out_unregister_ipv6_table: |
| 300 | unregister_net_sysctl_table(net->ipv6.sysctl.hdr); |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 301 | out_ipv6_icmp_table: |
| 302 | kfree(ipv6_icmp_table); |
| 303 | out_ipv6_route_table: |
| 304 | kfree(ipv6_route_table); |
| 305 | out_ipv6_table: |
| 306 | kfree(ipv6_table); |
| 307 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 310 | static void __net_exit ipv6_sysctl_net_exit(struct net *net) |
Daniel Lezcano | 89918fc | 2008-01-10 02:49:34 -0800 | [diff] [blame] | 311 | { |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 312 | struct ctl_table *ipv6_table; |
| 313 | struct ctl_table *ipv6_route_table; |
| 314 | struct ctl_table *ipv6_icmp_table; |
| 315 | |
Eric W. Biederman | 6dceb03 | 2012-04-19 13:37:09 +0000 | [diff] [blame] | 316 | ipv6_table = net->ipv6.sysctl.hdr->ctl_table_arg; |
| 317 | ipv6_route_table = net->ipv6.sysctl.route_hdr->ctl_table_arg; |
| 318 | ipv6_icmp_table = net->ipv6.sysctl.icmp_hdr->ctl_table_arg; |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 319 | |
Eric W. Biederman | 6dceb03 | 2012-04-19 13:37:09 +0000 | [diff] [blame] | 320 | unregister_net_sysctl_table(net->ipv6.sysctl.icmp_hdr); |
| 321 | unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr); |
| 322 | unregister_net_sysctl_table(net->ipv6.sysctl.hdr); |
Daniel Lezcano | 760f2d0 | 2008-01-10 02:53:43 -0800 | [diff] [blame] | 323 | |
| 324 | kfree(ipv6_table); |
| 325 | kfree(ipv6_route_table); |
| 326 | kfree(ipv6_icmp_table); |
Daniel Lezcano | 89918fc | 2008-01-10 02:49:34 -0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | static struct pernet_operations ipv6_sysctl_net_ops = { |
| 330 | .init = ipv6_sysctl_net_init, |
| 331 | .exit = ipv6_sysctl_net_exit, |
| 332 | }; |
| 333 | |
Pavel Emelyanov | 34ac257 | 2008-05-19 13:53:30 -0700 | [diff] [blame] | 334 | static struct ctl_table_header *ip6_header; |
| 335 | |
Daniel Lezcano | 89918fc | 2008-01-10 02:49:34 -0800 | [diff] [blame] | 336 | int ipv6_sysctl_register(void) |
| 337 | { |
Fernando Carrijo | c19a28e | 2009-01-07 18:09:08 -0800 | [diff] [blame] | 338 | int err = -ENOMEM; |
Pavel Emelyanov | 34ac257 | 2008-05-19 13:53:30 -0700 | [diff] [blame] | 339 | |
Eric W. Biederman | 4344475 | 2012-04-19 13:22:55 +0000 | [diff] [blame] | 340 | ip6_header = register_net_sysctl(&init_net, "net/ipv6", ipv6_rotable); |
Ian Morris | 63159f2 | 2015-03-29 14:00:04 +0100 | [diff] [blame] | 341 | if (!ip6_header) |
Pavel Emelyanov | 34ac257 | 2008-05-19 13:53:30 -0700 | [diff] [blame] | 342 | goto out; |
| 343 | |
| 344 | err = register_pernet_subsys(&ipv6_sysctl_net_ops); |
| 345 | if (err) |
| 346 | goto err_pernet; |
| 347 | out: |
| 348 | return err; |
| 349 | |
| 350 | err_pernet: |
| 351 | unregister_net_sysctl_table(ip6_header); |
| 352 | goto out; |
Daniel Lezcano | 89918fc | 2008-01-10 02:49:34 -0800 | [diff] [blame] | 353 | } |
| 354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | void ipv6_sysctl_unregister(void) |
| 356 | { |
Pavel Emelyanov | 34ac257 | 2008-05-19 13:53:30 -0700 | [diff] [blame] | 357 | unregister_net_sysctl_table(ip6_header); |
Daniel Lezcano | 89918fc | 2008-01-10 02:49:34 -0800 | [diff] [blame] | 358 | unregister_pernet_subsys(&ipv6_sysctl_net_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |