summaryrefslogtreecommitdiff
path: root/target/linux/generic/patches-4.3/643-bridge_remove_ipv6_dependency.patch
blob: ee5c2443ac15f266bbb586b48cfdbe8021c25432 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
From: Jonas Gorski <jonas.gorski+openwrt@gmail.com>
Subject: [PATCH] bridge: remove IPv6 depependency of bridge in 2.6.38+

Since 2.6.38 the bridge module has a dependency to IPv6 if IPv6 is
enabled. Since the IPv6 module isn't exactly lightweight and bridge also
only needs a single function from IPv6, it's rather easy to create a
common "lib" module with a RCU pointer to the actual implementation, if
the IPv6 module is loaded (although slightly hackish).

The codepath seems to be only taken when using IPv6, so there should be
no negative side effects when IPv6 isn't loaded. I did not measure how
big the performance impact is.
---
--- a/include/net/addrconf.h
+++ b/include/net/addrconf.h
@@ -122,6 +122,12 @@ static inline int addrconf_ifid_eui48(u8
 	return 0;
 }
 
+extern int			(*ipv6_dev_get_saddr_hook)(struct net *net,
+						const struct net_device *dev,
+						const struct in6_addr *daddr,
+						unsigned int prefs,
+						struct in6_addr *saddr);
+
 static inline unsigned long addrconf_timeout_fixup(u32 timeout,
 						   unsigned int unit)
 {
--- a/net/bridge/Kconfig
+++ b/net/bridge/Kconfig
@@ -6,7 +6,6 @@ config BRIDGE
 	tristate "802.1d Ethernet Bridging"
 	select LLC
 	select STP
-	depends on IPV6 || IPV6=n
 	---help---
 	  If you say Y here, then your Linux box will be able to act as an
 	  Ethernet bridge, which means that the different Ethernet segments it
--- a/net/ipv6/Makefile
+++ b/net/ipv6/Makefile
@@ -46,6 +46,7 @@ obj-y += addrconf_core.o exthdrs_core.o
 obj-$(CONFIG_INET) += output_core.o protocol.o $(ipv6-offload)
 
 obj-$(subst m,y,$(CONFIG_IPV6)) += inet6_hashtables.o
+obj-$(subst m,y,$(CONFIG_IPV6)) += inet6_stubs.o
 
 ifneq ($(CONFIG_IPV6),)
 obj-$(CONFIG_NET_UDP_TUNNEL) += ip6_udp_tunnel.o
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -1509,7 +1509,7 @@ out:
 	return hiscore_idx;
 }
 
-int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
+static int ___ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
 		       const struct in6_addr *daddr, unsigned int prefs,
 		       struct in6_addr *saddr)
 {
@@ -1579,7 +1579,6 @@ int ipv6_dev_get_saddr(struct net *net,
 	in6_ifa_put(hiscore->ifa);
 	return 0;
 }
-EXPORT_SYMBOL(ipv6_dev_get_saddr);
 
 int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
 		      u32 banned_flags)
@@ -5941,6 +5940,9 @@ int __init addrconf_init(void)
 
 	ipv6_addr_label_rtnl_register();
 
+	BUG_ON(ipv6_dev_get_saddr_hook != NULL);
+	rcu_assign_pointer(ipv6_dev_get_saddr_hook, ___ipv6_dev_get_saddr);
+
 	return 0;
 errout:
 	rtnl_af_unregister(&inet6_ops);
@@ -5960,6 +5962,9 @@ void addrconf_cleanup(void)
 	struct net_device *dev;
 	int i;
 
+	rcu_assign_pointer(ipv6_dev_get_saddr_hook, NULL);
+	synchronize_rcu();
+
 	unregister_netdevice_notifier(&ipv6_dev_notf);
 	unregister_pernet_subsys(&addrconf_ops);
 	ipv6_addr_label_cleanup();
--- /dev/null
+++ b/net/ipv6/inet6_stubs.c
@@ -0,0 +1,33 @@
+/*
+ *      This program is free software; you can redistribute it and/or
+ *      modify it under the terms of the GNU General Public License
+ *      as published by the Free Software Foundation; either version
+ *      2 of the License, or (at your option) any later version.
+ */
+#include <linux/export.h>
+#include <net/ipv6.h>
+
+int (*ipv6_dev_get_saddr_hook)(struct net *net, const struct net_device *dev,
+			const struct in6_addr *daddr, unsigned int prefs,
+			struct in6_addr *saddr);
+
+EXPORT_SYMBOL(ipv6_dev_get_saddr_hook);
+
+int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
+			const struct in6_addr *daddr, unsigned int prefs,
+			struct in6_addr *saddr)
+{
+	int ret = -EADDRNOTAVAIL;
+	typeof(ipv6_dev_get_saddr_hook) dev_get_saddr;
+
+	rcu_read_lock();
+	dev_get_saddr = rcu_dereference(ipv6_dev_get_saddr_hook);
+
+	if (dev_get_saddr)
+		ret = dev_get_saddr(net, dst_dev, daddr, prefs, saddr);
+
+	rcu_read_unlock();
+	return ret;
+}
+EXPORT_SYMBOL(ipv6_dev_get_saddr);
+