Subject: Re: [PATCH net-next] ipv6: sr: restruct ifdefines

From: Sabrina Dubroca <[email-masked]>
Date: Tue, 28 May 2024 12:05:12 +0200

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 <[email-masked]>

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;

-- 
Sabrina