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

Configure Feed

Select the types of activity you want to include in your feed.

ipv6: sr: restruct ifdefines

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.

Suggested-by: Simon Horman <horms@kernel.org>
Suggested-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
Reviewed-by: David Ahern <dsahern@kernel.org>
Link: https://lore.kernel.org/r/20240529040908.3472952-1-liuhangbin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Hangbin Liu and committed by
Jakub Kicinski
a79d8fe2 57e3c5af

+20 -29
+7
include/net/seg6.h
··· 52 52 53 53 extern int seg6_init(void); 54 54 extern void seg6_exit(void); 55 + #ifdef CONFIG_IPV6_SEG6_LWTUNNEL 55 56 extern int seg6_iptunnel_init(void); 56 57 extern void seg6_iptunnel_exit(void); 57 58 extern int seg6_local_init(void); 58 59 extern void seg6_local_exit(void); 60 + #else 61 + static inline int seg6_iptunnel_init(void) { return 0; } 62 + static inline void seg6_iptunnel_exit(void) {} 63 + static inline int seg6_local_init(void) { return 0; } 64 + static inline void seg6_local_exit(void) {} 65 + #endif 59 66 60 67 extern bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len, bool reduced); 61 68 extern struct ipv6_sr_hdr *seg6_get_srh(struct sk_buff *skb, int flags);
+7
include/net/seg6_hmac.h
··· 49 49 extern int seg6_push_hmac(struct net *net, struct in6_addr *saddr, 50 50 struct ipv6_sr_hdr *srh); 51 51 extern bool seg6_hmac_validate_skb(struct sk_buff *skb); 52 + #ifdef CONFIG_IPV6_SEG6_HMAC 52 53 extern int seg6_hmac_init(void); 53 54 extern void seg6_hmac_exit(void); 54 55 extern int seg6_hmac_net_init(struct net *net); 55 56 extern void seg6_hmac_net_exit(struct net *net); 57 + #else 58 + static inline int seg6_hmac_init(void) { return 0; } 59 + static inline void seg6_hmac_exit(void) {} 60 + static inline int seg6_hmac_net_init(struct net *net) { return 0; } 61 + static inline void seg6_hmac_net_exit(struct net *net) {} 62 + #endif 56 63 57 64 #endif
+6 -29
net/ipv6/seg6.c
··· 21 21 #include <net/genetlink.h> 22 22 #include <linux/seg6.h> 23 23 #include <linux/seg6_genl.h> 24 - #ifdef CONFIG_IPV6_SEG6_HMAC 25 24 #include <net/seg6_hmac.h> 26 - #endif 27 25 28 26 bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len, bool reduced) 29 27 { ··· 435 437 436 438 net->ipv6.seg6_data = sdata; 437 439 438 - #ifdef CONFIG_IPV6_SEG6_HMAC 439 440 if (seg6_hmac_net_init(net)) { 440 441 kfree(rcu_dereference_raw(sdata->tun_src)); 441 442 kfree(sdata); 442 443 return -ENOMEM; 443 444 } 444 - #endif 445 445 446 446 return 0; 447 447 } ··· 448 452 { 449 453 struct seg6_pernet_data *sdata = seg6_pernet(net); 450 454 451 - #ifdef CONFIG_IPV6_SEG6_HMAC 452 455 seg6_hmac_net_exit(net); 453 - #endif 454 456 455 457 kfree(rcu_dereference_raw(sdata->tun_src)); 456 458 kfree(sdata); ··· 514 520 if (err) 515 521 goto out_unregister_pernet; 516 522 517 - #ifdef CONFIG_IPV6_SEG6_LWTUNNEL 518 523 err = seg6_iptunnel_init(); 519 524 if (err) 520 525 goto out_unregister_genl; 521 526 522 527 err = seg6_local_init(); 523 - if (err) { 524 - seg6_iptunnel_exit(); 525 - goto out_unregister_genl; 526 - } 527 - #endif 528 - 529 - #ifdef CONFIG_IPV6_SEG6_HMAC 530 - err = seg6_hmac_init(); 531 528 if (err) 532 529 goto out_unregister_iptun; 533 - #endif 530 + 531 + err = seg6_hmac_init(); 532 + if (err) 533 + goto out_unregister_seg6; 534 534 535 535 pr_info("Segment Routing with IPv6\n"); 536 536 537 537 out: 538 538 return err; 539 - #ifdef CONFIG_IPV6_SEG6_HMAC 540 - out_unregister_iptun: 541 - #ifdef CONFIG_IPV6_SEG6_LWTUNNEL 539 + out_unregister_seg6: 542 540 seg6_local_exit(); 541 + out_unregister_iptun: 543 542 seg6_iptunnel_exit(); 544 - #endif 545 - #endif 546 - #ifdef CONFIG_IPV6_SEG6_LWTUNNEL 547 543 out_unregister_genl: 548 - #endif 549 - #if IS_ENABLED(CONFIG_IPV6_SEG6_LWTUNNEL) || IS_ENABLED(CONFIG_IPV6_SEG6_HMAC) 550 544 genl_unregister_family(&seg6_genl_family); 551 - #endif 552 545 out_unregister_pernet: 553 546 unregister_pernet_subsys(&ip6_segments_ops); 554 547 goto out; ··· 543 562 544 563 void seg6_exit(void) 545 564 { 546 - #ifdef CONFIG_IPV6_SEG6_HMAC 547 565 seg6_hmac_exit(); 548 - #endif 549 - #ifdef CONFIG_IPV6_SEG6_LWTUNNEL 550 566 seg6_local_exit(); 551 567 seg6_iptunnel_exit(); 552 - #endif 553 568 genl_unregister_family(&seg6_genl_family); 554 569 unregister_pernet_subsys(&ip6_segments_ops); 555 570 }