All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ipv6: Use math to point per net sysctls into the appropriate struct net
@ 2020-03-03  6:54 Cambda Zhu
  2020-03-03  7:34 ` Eric Dumazet
  2020-03-03 22:50 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Cambda Zhu @ 2020-03-03  6:54 UTC (permalink / raw)
  To: netdev; +Cc: Dust Li, Tony Lu, Cambda Zhu

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>
---
 net/ipv6/sysctl_net_ipv6.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
index ec8fcfc60a27..cfc82cbe8e1f 100644
--- a/net/ipv6/sysctl_net_ipv6.c
+++ b/net/ipv6/sysctl_net_ipv6.c
@@ -203,6 +203,7 @@ static int __net_init ipv6_sysctl_net_init(struct net *net)
 	struct ctl_table *ipv6_table;
 	struct ctl_table *ipv6_route_table;
 	struct ctl_table *ipv6_icmp_table;
+	int i;
 	int err;
 
 	err = -ENOMEM;
@@ -210,22 +211,9 @@ static int __net_init ipv6_sysctl_net_init(struct net *net)
 			     GFP_KERNEL);
 	if (!ipv6_table)
 		goto out;
-	ipv6_table[0].data = &net->ipv6.sysctl.bindv6only;
-	ipv6_table[1].data = &net->ipv6.sysctl.anycast_src_echo_reply;
-	ipv6_table[2].data = &net->ipv6.sysctl.flowlabel_consistency;
-	ipv6_table[3].data = &net->ipv6.sysctl.auto_flowlabels;
-	ipv6_table[4].data = &net->ipv6.sysctl.fwmark_reflect;
-	ipv6_table[5].data = &net->ipv6.sysctl.idgen_retries;
-	ipv6_table[6].data = &net->ipv6.sysctl.idgen_delay;
-	ipv6_table[7].data = &net->ipv6.sysctl.flowlabel_state_ranges;
-	ipv6_table[8].data = &net->ipv6.sysctl.ip_nonlocal_bind;
-	ipv6_table[9].data = &net->ipv6.sysctl.flowlabel_reflect;
-	ipv6_table[10].data = &net->ipv6.sysctl.max_dst_opts_cnt;
-	ipv6_table[11].data = &net->ipv6.sysctl.max_hbh_opts_cnt;
-	ipv6_table[12].data = &net->ipv6.sysctl.max_dst_opts_len;
-	ipv6_table[13].data = &net->ipv6.sysctl.max_hbh_opts_len;
-	ipv6_table[14].data = &net->ipv6.sysctl.multipath_hash_policy,
-	ipv6_table[15].data = &net->ipv6.sysctl.seg6_flowlabel;
+	/* Update the variables to point into the current struct net */
+	for (i = 0; i < ARRAY_SIZE(ipv6_table_template) - 1; i++)
+		ipv6_table[i].data += (void *)net - (void *)&init_net;
 
 	ipv6_route_table = ipv6_route_sysctl_init(net);
 	if (!ipv6_route_table)
-- 
2.16.6


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ipv6: Use math to point per net sysctls into the appropriate struct net
  2020-03-03  6:54 [PATCH] ipv6: Use math to point per net sysctls into the appropriate struct net Cambda Zhu
@ 2020-03-03  7:34 ` Eric Dumazet
  2020-03-03 22:50 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2020-03-03  7:34 UTC (permalink / raw)
  To: Cambda Zhu, netdev; +Cc: Dust Li, Tony Lu



On 3/2/20 10:54 PM, Cambda Zhu wrote:
> 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>
> ---
>  net/ipv6/sysctl_net_ipv6.c | 20 ++++----------------
>  1 file changed, 4 insertions(+), 16 deletions(-)
>


Reviewed-by: Eric Dumazet <edumazet@google.com>

Please add the intended tree (net-next in this case) for your next patches.

Documentation/networking/netdev-FAQ.rst


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ipv6: Use math to point per net sysctls into the appropriate struct net
  2020-03-03  6:54 [PATCH] ipv6: Use math to point per net sysctls into the appropriate struct net Cambda Zhu
  2020-03-03  7:34 ` Eric Dumazet
@ 2020-03-03 22:50 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2020-03-03 22:50 UTC (permalink / raw)
  To: cambda; +Cc: netdev, dust.li, tonylu

From: Cambda Zhu <cambda@linux.alibaba.com>
Date: Tue,  3 Mar 2020 14:54:34 +0800

> 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>

Applied, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-03 22:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-03  6:54 [PATCH] ipv6: Use math to point per net sysctls into the appropriate struct net Cambda Zhu
2020-03-03  7:34 ` Eric Dumazet
2020-03-03 22:50 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.