643-bridge_remove_ipv6_dependency.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. From: Jonas Gorski <[email protected]>
  2. Subject: [PATCH] bridge: remove IPv6 depependency of bridge in 2.6.38+
  3. Since 2.6.38 the bridge module has a dependency to IPv6 if IPv6 is
  4. enabled. Since the IPv6 module isn't exactly lightweight and bridge also
  5. only needs a single function from IPv6, it's rather easy to create a
  6. common "lib" module with a RCU pointer to the actual implementation, if
  7. the IPv6 module is loaded (although slightly hackish).
  8. The codepath seems to be only taken when using IPv6, so there should be
  9. no negative side effects when IPv6 isn't loaded. I did not measure how
  10. big the performance impact is.
  11. ---
  12. --- a/include/net/addrconf.h
  13. +++ b/include/net/addrconf.h
  14. @@ -122,6 +122,12 @@ static inline int addrconf_ifid_eui48(u8
  15. return 0;
  16. }
  17. +extern int (*ipv6_dev_get_saddr_hook)(struct net *net,
  18. + const struct net_device *dev,
  19. + const struct in6_addr *daddr,
  20. + unsigned int prefs,
  21. + struct in6_addr *saddr);
  22. +
  23. static inline unsigned long addrconf_timeout_fixup(u32 timeout,
  24. unsigned int unit)
  25. {
  26. --- a/net/bridge/Kconfig
  27. +++ b/net/bridge/Kconfig
  28. @@ -6,7 +6,6 @@ config BRIDGE
  29. tristate "802.1d Ethernet Bridging"
  30. select LLC
  31. select STP
  32. - depends on IPV6 || IPV6=n
  33. ---help---
  34. If you say Y here, then your Linux box will be able to act as an
  35. Ethernet bridge, which means that the different Ethernet segments it
  36. --- a/net/ipv6/Makefile
  37. +++ b/net/ipv6/Makefile
  38. @@ -46,6 +46,7 @@ obj-y += addrconf_core.o exthdrs_core.o
  39. obj-$(CONFIG_INET) += output_core.o protocol.o $(ipv6-offload)
  40. obj-$(subst m,y,$(CONFIG_IPV6)) += inet6_hashtables.o
  41. +obj-$(subst m,y,$(CONFIG_IPV6)) += inet6_stubs.o
  42. ifneq ($(CONFIG_IPV6),)
  43. obj-$(CONFIG_NET_UDP_TUNNEL) += ip6_udp_tunnel.o
  44. --- a/net/ipv6/addrconf.c
  45. +++ b/net/ipv6/addrconf.c
  46. @@ -1509,7 +1509,7 @@ out:
  47. return hiscore_idx;
  48. }
  49. -int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
  50. +static int ___ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
  51. const struct in6_addr *daddr, unsigned int prefs,
  52. struct in6_addr *saddr)
  53. {
  54. @@ -1579,7 +1579,6 @@ int ipv6_dev_get_saddr(struct net *net,
  55. in6_ifa_put(hiscore->ifa);
  56. return 0;
  57. }
  58. -EXPORT_SYMBOL(ipv6_dev_get_saddr);
  59. int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
  60. u32 banned_flags)
  61. @@ -5941,6 +5940,9 @@ int __init addrconf_init(void)
  62. ipv6_addr_label_rtnl_register();
  63. + BUG_ON(ipv6_dev_get_saddr_hook != NULL);
  64. + rcu_assign_pointer(ipv6_dev_get_saddr_hook, ___ipv6_dev_get_saddr);
  65. +
  66. return 0;
  67. errout:
  68. rtnl_af_unregister(&inet6_ops);
  69. @@ -5960,6 +5962,9 @@ void addrconf_cleanup(void)
  70. struct net_device *dev;
  71. int i;
  72. + rcu_assign_pointer(ipv6_dev_get_saddr_hook, NULL);
  73. + synchronize_rcu();
  74. +
  75. unregister_netdevice_notifier(&ipv6_dev_notf);
  76. unregister_pernet_subsys(&addrconf_ops);
  77. ipv6_addr_label_cleanup();
  78. --- /dev/null
  79. +++ b/net/ipv6/inet6_stubs.c
  80. @@ -0,0 +1,33 @@
  81. +/*
  82. + * This program is free software; you can redistribute it and/or
  83. + * modify it under the terms of the GNU General Public License
  84. + * as published by the Free Software Foundation; either version
  85. + * 2 of the License, or (at your option) any later version.
  86. + */
  87. +#include <linux/export.h>
  88. +#include <net/ipv6.h>
  89. +
  90. +int (*ipv6_dev_get_saddr_hook)(struct net *net, const struct net_device *dev,
  91. + const struct in6_addr *daddr, unsigned int prefs,
  92. + struct in6_addr *saddr);
  93. +
  94. +EXPORT_SYMBOL(ipv6_dev_get_saddr_hook);
  95. +
  96. +int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
  97. + const struct in6_addr *daddr, unsigned int prefs,
  98. + struct in6_addr *saddr)
  99. +{
  100. + int ret = -EADDRNOTAVAIL;
  101. + typeof(ipv6_dev_get_saddr_hook) dev_get_saddr;
  102. +
  103. + rcu_read_lock();
  104. + dev_get_saddr = rcu_dereference(ipv6_dev_get_saddr_hook);
  105. +
  106. + if (dev_get_saddr)
  107. + ret = dev_get_saddr(net, dst_dev, daddr, prefs, saddr);
  108. +
  109. + rcu_read_unlock();
  110. + return ret;
  111. +}
  112. +EXPORT_SYMBOL(ipv6_dev_get_saddr);
  113. +