diff mbox series

[net-next] ipv6: sr: restruct ifdefines

Message ID 20240528032530.2182346-1-liuhangbin@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] ipv6: sr: restruct ifdefines | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 936 this patch: 936
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 906 this patch: 906
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 940 this patch: 940
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 115 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-05-28--15-00 (tests: 1037)

Commit Message

Hangbin Liu May 28, 2024, 3:25 a.m. UTC
There are too many ifdef in IPv6 segment routing code that may cause logic
problems. like commit 160e9d275218 ("ipv6: sr: fix invalid unregister error
path"). To avoid this, the init functions are redefined for both cases. The
code could be more clear after all fidefs are removed.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 include/net/seg6.h      |  7 +++++++
 include/net/seg6_hmac.h |  7 +++++++
 net/ipv6/seg6.c         | 22 ----------------------
 3 files changed, 14 insertions(+), 22 deletions(-)

Comments

Sabrina Dubroca May 28, 2024, 10:05 a.m. UTC | #1
Hi Hangbin,

2024-05-28, 11:25:30 +0800, Hangbin Liu wrote:
> There are too many ifdef in IPv6 segment routing code that may cause logic
> problems. like commit 160e9d275218 ("ipv6: sr: fix invalid unregister error
> path"). To avoid this, the init functions are redefined for both cases. The
> code could be more clear after all fidefs are removed.
> 
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>

I think this was suggested by Simon?


> @@ -520,7 +514,6 @@ int __init seg6_init(void)
>  	if (err)
>  		goto out_unregister_pernet;
>  

(With a bit more context around this:)

> -#ifdef CONFIG_IPV6_SEG6_LWTUNNEL
>  	err = seg6_iptunnel_init();
>  	if (err)
>  		goto out_unregister_genl;
>  
>  	err = seg6_local_init();
>  	if (err) {
>  		seg6_iptunnel_exit();

With those changes, we don't need this weird partial uninit anymore,
we can just create a new label above the other seg6_iptunnel_exit()
call and jump there directly.

>  		goto out_unregister_genl;
>  	}
> -#endif
>  
> -#ifdef CONFIG_IPV6_SEG6_HMAC
>  	err = seg6_hmac_init();
>  	if (err)
>  		goto out_unregister_iptun;
> -#endif
>  
>  	pr_info("Segment Routing with IPv6\n");
>  
>  out:
>  	return err;
> -#ifdef CONFIG_IPV6_SEG6_HMAC
>  out_unregister_iptun:
> -#ifdef CONFIG_IPV6_SEG6_LWTUNNEL
>  	seg6_local_exit();

[jump here]

>  	seg6_iptunnel_exit();
> -#endif
> -#endif
> -#ifdef CONFIG_IPV6_SEG6_LWTUNNEL
>  out_unregister_genl:
> -#endif
> -#if IS_ENABLED(CONFIG_IPV6_SEG6_LWTUNNEL) || IS_ENABLED(CONFIG_IPV6_SEG6_HMAC)
>  	genl_unregister_family(&seg6_genl_family);
> -#endif
>  out_unregister_pernet:
>  	unregister_pernet_subsys(&ip6_segments_ops);
>  	goto out;
Hangbin Liu May 28, 2024, 1 p.m. UTC | #2
On Tue, May 28, 2024 at 12:05:12PM +0200, Sabrina Dubroca wrote:
> Hi Hangbin,
> 
> 2024-05-28, 11:25:30 +0800, Hangbin Liu wrote:
> > There are too many ifdef in IPv6 segment routing code that may cause logic
> > problems. like commit 160e9d275218 ("ipv6: sr: fix invalid unregister error
> > path"). To avoid this, the init functions are redefined for both cases. The
> > code could be more clear after all fidefs are removed.
> > 
> > Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> 
> I think this was suggested by Simon?

Yes, and David Ahern also suggested this. And I thought you also mentioned it?
I was afraid there are too many suggested-by tags here :) I can add them
in next version patch.

> 
> 
> > @@ -520,7 +514,6 @@ int __init seg6_init(void)
> >  	if (err)
> >  		goto out_unregister_pernet;
> >  
> 
> (With a bit more context around this:)
> 
> > -#ifdef CONFIG_IPV6_SEG6_LWTUNNEL
> >  	err = seg6_iptunnel_init();
> >  	if (err)
> >  		goto out_unregister_genl;
> >  
> >  	err = seg6_local_init();
> >  	if (err) {
> >  		seg6_iptunnel_exit();
> 
> With those changes, we don't need this weird partial uninit anymore,
> we can just create a new label above the other seg6_iptunnel_exit()
> call and jump there directly.

Yes.

Thanks
Hangbin
Sabrina Dubroca May 28, 2024, 3:29 p.m. UTC | #3
2024-05-28, 21:00:13 +0800, Hangbin Liu wrote:
> On Tue, May 28, 2024 at 12:05:12PM +0200, Sabrina Dubroca wrote:
> > Hi Hangbin,
> > 
> > 2024-05-28, 11:25:30 +0800, Hangbin Liu wrote:
> > > There are too many ifdef in IPv6 segment routing code that may cause logic
> > > problems. like commit 160e9d275218 ("ipv6: sr: fix invalid unregister error
> > > path"). To avoid this, the init functions are redefined for both cases. The
> > > code could be more clear after all fidefs are removed.
> > > 
> > > Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> > 
> > I think this was suggested by Simon?
> 
> Yes, and David Ahern also suggested this. And I thought you also mentioned it?

I don't think I did.

> I was afraid there are too many suggested-by tags here :) I can add them
> in next version patch.

Yes, please add tags for David and Simon.

Thanks!
diff mbox series

Patch

diff --git a/include/net/seg6.h b/include/net/seg6.h
index af668f17b398..82b3fbbcbb93 100644
--- a/include/net/seg6.h
+++ b/include/net/seg6.h
@@ -52,10 +52,17 @@  static inline struct seg6_pernet_data *seg6_pernet(struct net *net)
 
 extern int seg6_init(void);
 extern void seg6_exit(void);
+#ifdef CONFIG_IPV6_SEG6_LWTUNNEL
 extern int seg6_iptunnel_init(void);
 extern void seg6_iptunnel_exit(void);
 extern int seg6_local_init(void);
 extern void seg6_local_exit(void);
+#else
+static inline int seg6_iptunnel_init(void) { return 0; }
+static inline void seg6_iptunnel_exit(void) {}
+static inline int seg6_local_init(void) { return 0; }
+static inline void seg6_local_exit(void) {}
+#endif
 
 extern bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len, bool reduced);
 extern struct ipv6_sr_hdr *seg6_get_srh(struct sk_buff *skb, int flags);
diff --git a/include/net/seg6_hmac.h b/include/net/seg6_hmac.h
index 2b5d2ee5613e..24f733b3e3fe 100644
--- a/include/net/seg6_hmac.h
+++ b/include/net/seg6_hmac.h
@@ -49,9 +49,16 @@  extern int seg6_hmac_info_del(struct net *net, u32 key);
 extern int seg6_push_hmac(struct net *net, struct in6_addr *saddr,
 			  struct ipv6_sr_hdr *srh);
 extern bool seg6_hmac_validate_skb(struct sk_buff *skb);
+#ifdef CONFIG_IPV6_SEG6_HMAC
 extern int seg6_hmac_init(void);
 extern void seg6_hmac_exit(void);
 extern int seg6_hmac_net_init(struct net *net);
 extern void seg6_hmac_net_exit(struct net *net);
+#else
+static inline int seg6_hmac_init(void) { return 0; }
+static inline void seg6_hmac_exit(void) {}
+static inline int seg6_hmac_net_init(struct net *net) { return 0; }
+static inline void seg6_hmac_net_exit(struct net *net) {}
+#endif
 
 #endif
diff --git a/net/ipv6/seg6.c b/net/ipv6/seg6.c
index a31521e270f7..671aa1706d04 100644
--- a/net/ipv6/seg6.c
+++ b/net/ipv6/seg6.c
@@ -21,9 +21,7 @@ 
 #include <net/genetlink.h>
 #include <linux/seg6.h>
 #include <linux/seg6_genl.h>
-#ifdef CONFIG_IPV6_SEG6_HMAC
 #include <net/seg6_hmac.h>
-#endif
 
 bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len, bool reduced)
 {
@@ -437,13 +435,11 @@  static int __net_init seg6_net_init(struct net *net)
 
 	net->ipv6.seg6_data = sdata;
 
-#ifdef CONFIG_IPV6_SEG6_HMAC
 	if (seg6_hmac_net_init(net)) {
 		kfree(rcu_dereference_raw(sdata->tun_src));
 		kfree(sdata);
 		return -ENOMEM;
 	}
-#endif
 
 	return 0;
 }
@@ -452,9 +448,7 @@  static void __net_exit seg6_net_exit(struct net *net)
 {
 	struct seg6_pernet_data *sdata = seg6_pernet(net);
 
-#ifdef CONFIG_IPV6_SEG6_HMAC
 	seg6_hmac_net_exit(net);
-#endif
 
 	kfree(rcu_dereference_raw(sdata->tun_src));
 	kfree(sdata);
@@ -520,7 +514,6 @@  int __init seg6_init(void)
 	if (err)
 		goto out_unregister_pernet;
 
-#ifdef CONFIG_IPV6_SEG6_LWTUNNEL
 	err = seg6_iptunnel_init();
 	if (err)
 		goto out_unregister_genl;
@@ -530,31 +523,20 @@  int __init seg6_init(void)
 		seg6_iptunnel_exit();
 		goto out_unregister_genl;
 	}
-#endif
 
-#ifdef CONFIG_IPV6_SEG6_HMAC
 	err = seg6_hmac_init();
 	if (err)
 		goto out_unregister_iptun;
-#endif
 
 	pr_info("Segment Routing with IPv6\n");
 
 out:
 	return err;
-#ifdef CONFIG_IPV6_SEG6_HMAC
 out_unregister_iptun:
-#ifdef CONFIG_IPV6_SEG6_LWTUNNEL
 	seg6_local_exit();
 	seg6_iptunnel_exit();
-#endif
-#endif
-#ifdef CONFIG_IPV6_SEG6_LWTUNNEL
 out_unregister_genl:
-#endif
-#if IS_ENABLED(CONFIG_IPV6_SEG6_LWTUNNEL) || IS_ENABLED(CONFIG_IPV6_SEG6_HMAC)
 	genl_unregister_family(&seg6_genl_family);
-#endif
 out_unregister_pernet:
 	unregister_pernet_subsys(&ip6_segments_ops);
 	goto out;
@@ -562,13 +544,9 @@  int __init seg6_init(void)
 
 void seg6_exit(void)
 {
-#ifdef CONFIG_IPV6_SEG6_HMAC
 	seg6_hmac_exit();
-#endif
-#ifdef CONFIG_IPV6_SEG6_LWTUNNEL
 	seg6_local_exit();
 	seg6_iptunnel_exit();
-#endif
 	genl_unregister_family(&seg6_genl_family);
 	unregister_pernet_subsys(&ip6_segments_ops);
 }