Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ipv6: Use math to point per net sysctls into the appropriate struct net

The data pointers of ipv6 sysctl are set one by one which is hard to
maintain, especially with kconfig. This patch simplifies it by using
math to point the per net sysctls into the appropriate struct net,
just like what we did for ipv4.

Signed-off-by: Cambda Zhu <cambda@linux.alibaba.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Cambda Zhu and committed by
David S. Miller
d2f7e56d 15070919

+4 -17
+4 -17
net/ipv6/sysctl_net_ipv6.c
··· 203 203 struct ctl_table *ipv6_table; 204 204 struct ctl_table *ipv6_route_table; 205 205 struct ctl_table *ipv6_icmp_table; 206 - int err; 206 + int err, i; 207 207 208 208 err = -ENOMEM; 209 209 ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template), 210 210 GFP_KERNEL); 211 211 if (!ipv6_table) 212 212 goto out; 213 - ipv6_table[0].data = &net->ipv6.sysctl.bindv6only; 214 - ipv6_table[1].data = &net->ipv6.sysctl.anycast_src_echo_reply; 215 - ipv6_table[2].data = &net->ipv6.sysctl.flowlabel_consistency; 216 - ipv6_table[3].data = &net->ipv6.sysctl.auto_flowlabels; 217 - ipv6_table[4].data = &net->ipv6.sysctl.fwmark_reflect; 218 - ipv6_table[5].data = &net->ipv6.sysctl.idgen_retries; 219 - ipv6_table[6].data = &net->ipv6.sysctl.idgen_delay; 220 - ipv6_table[7].data = &net->ipv6.sysctl.flowlabel_state_ranges; 221 - ipv6_table[8].data = &net->ipv6.sysctl.ip_nonlocal_bind; 222 - ipv6_table[9].data = &net->ipv6.sysctl.flowlabel_reflect; 223 - ipv6_table[10].data = &net->ipv6.sysctl.max_dst_opts_cnt; 224 - ipv6_table[11].data = &net->ipv6.sysctl.max_hbh_opts_cnt; 225 - ipv6_table[12].data = &net->ipv6.sysctl.max_dst_opts_len; 226 - ipv6_table[13].data = &net->ipv6.sysctl.max_hbh_opts_len; 227 - ipv6_table[14].data = &net->ipv6.sysctl.multipath_hash_policy, 228 - ipv6_table[15].data = &net->ipv6.sysctl.seg6_flowlabel; 213 + /* Update the variables to point into the current struct net */ 214 + for (i = 0; i < ARRAY_SIZE(ipv6_table_template) - 1; i++) 215 + ipv6_table[i].data += (void *)net - (void *)&init_net; 229 216 230 217 ipv6_route_table = ipv6_route_sysctl_init(net); 231 218 if (!ipv6_route_table)