aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/if_tunnel.h7
-rw-r--r--net/ipv4/ip_gre.c14
-rw-r--r--net/ipv4/ip_vti.c13
-rw-r--r--net/ipv4/ipip.c13
-rw-r--r--net/ipv6/ip6_gre.c14
-rw-r--r--net/ipv6/sit.c13
6 files changed, 25 insertions, 49 deletions
diff --git a/include/linux/if_tunnel.h b/include/linux/if_tunnel.h
index 06d1d5badd36..f4e56ecd0b1a 100644
--- a/include/linux/if_tunnel.h
+++ b/include/linux/if_tunnel.h
@@ -6,6 +6,13 @@
6#include <uapi/linux/if_tunnel.h> 6#include <uapi/linux/if_tunnel.h>
7#include <linux/u64_stats_sync.h> 7#include <linux/u64_stats_sync.h>
8 8
9/*
10 * Locking : hash tables are protected by RCU and RTNL
11 */
12
13#define for_each_ip_tunnel_rcu(pos, start) \
14 for (pos = rcu_dereference(start); pos; pos = rcu_dereference(pos->next))
15
9/* often modified stats are per cpu, other are shared (netdev->stats) */ 16/* often modified stats are per cpu, other are shared (netdev->stats) */
10struct pcpu_tstats { 17struct pcpu_tstats {
11 u64 rx_packets; 18 u64 rx_packets;
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 37000ae24c55..127f2a1e67f5 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -164,12 +164,6 @@ struct ipgre_net {
164#define tunnels_r tunnels[2] 164#define tunnels_r tunnels[2]
165#define tunnels_l tunnels[1] 165#define tunnels_l tunnels[1]
166#define tunnels_wc tunnels[0] 166#define tunnels_wc tunnels[0]
167/*
168 * Locking : hash tables are protected by RCU and RTNL
169 */
170
171#define for_each_ip_tunnel_rcu(start) \
172 for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
173 167
174static struct rtnl_link_stats64 *ipgre_get_stats64(struct net_device *dev, 168static struct rtnl_link_stats64 *ipgre_get_stats64(struct net_device *dev,
175 struct rtnl_link_stats64 *tot) 169 struct rtnl_link_stats64 *tot)
@@ -241,7 +235,7 @@ static struct ip_tunnel *ipgre_tunnel_lookup(struct net_device *dev,
241 ARPHRD_ETHER : ARPHRD_IPGRE; 235 ARPHRD_ETHER : ARPHRD_IPGRE;
242 int score, cand_score = 4; 236 int score, cand_score = 4;
243 237
244 for_each_ip_tunnel_rcu(ign->tunnels_r_l[h0 ^ h1]) { 238 for_each_ip_tunnel_rcu(t, ign->tunnels_r_l[h0 ^ h1]) {
245 if (local != t->parms.iph.saddr || 239 if (local != t->parms.iph.saddr ||
246 remote != t->parms.iph.daddr || 240 remote != t->parms.iph.daddr ||
247 !(t->dev->flags & IFF_UP)) 241 !(t->dev->flags & IFF_UP))
@@ -268,7 +262,7 @@ static struct ip_tunnel *ipgre_tunnel_lookup(struct net_device *dev,
268 } 262 }
269 } 263 }
270 264
271 for_each_ip_tunnel_rcu(ign->tunnels_r[h0 ^ h1]) { 265 for_each_ip_tunnel_rcu(t, ign->tunnels_r[h0 ^ h1]) {
272 if (remote != t->parms.iph.daddr || 266 if (remote != t->parms.iph.daddr ||
273 !(t->dev->flags & IFF_UP)) 267 !(t->dev->flags & IFF_UP))
274 continue; 268 continue;
@@ -294,7 +288,7 @@ static struct ip_tunnel *ipgre_tunnel_lookup(struct net_device *dev,
294 } 288 }
295 } 289 }
296 290
297 for_each_ip_tunnel_rcu(ign->tunnels_l[h1]) { 291 for_each_ip_tunnel_rcu(t, ign->tunnels_l[h1]) {
298 if ((local != t->parms.iph.saddr && 292 if ((local != t->parms.iph.saddr &&
299 (local != t->parms.iph.daddr || 293 (local != t->parms.iph.daddr ||
300 !ipv4_is_multicast(local))) || 294 !ipv4_is_multicast(local))) ||
@@ -322,7 +316,7 @@ static struct ip_tunnel *ipgre_tunnel_lookup(struct net_device *dev,
322 } 316 }
323 } 317 }
324 318
325 for_each_ip_tunnel_rcu(ign->tunnels_wc[h1]) { 319 for_each_ip_tunnel_rcu(t, ign->tunnels_wc[h1]) {
326 if (t->parms.i_key != key || 320 if (t->parms.i_key != key ||
327 !(t->dev->flags & IFF_UP)) 321 !(t->dev->flags & IFF_UP))
328 continue; 322 continue;
diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
index e0f2c88f03c1..516188b0dc1e 100644
--- a/net/ipv4/ip_vti.c
+++ b/net/ipv4/ip_vti.c
@@ -66,11 +66,6 @@ static void vti_tunnel_setup(struct net_device *dev);
66static void vti_dev_free(struct net_device *dev); 66static void vti_dev_free(struct net_device *dev);
67static int vti_tunnel_bind_dev(struct net_device *dev); 67static int vti_tunnel_bind_dev(struct net_device *dev);
68 68
69/* Locking : hash tables are protected by RCU and RTNL */
70
71#define for_each_ip_tunnel_rcu(start) \
72 for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
73
74#define VTI_XMIT(stats1, stats2) do { \ 69#define VTI_XMIT(stats1, stats2) do { \
75 int err; \ 70 int err; \
76 int pkt_len = skb->len; \ 71 int pkt_len = skb->len; \
@@ -133,19 +128,19 @@ static struct ip_tunnel *vti_tunnel_lookup(struct net *net,
133 struct ip_tunnel *t; 128 struct ip_tunnel *t;
134 struct vti_net *ipn = net_generic(net, vti_net_id); 129 struct vti_net *ipn = net_generic(net, vti_net_id);
135 130
136 for_each_ip_tunnel_rcu(ipn->tunnels_r_l[h0 ^ h1]) 131 for_each_ip_tunnel_rcu(t, ipn->tunnels_r_l[h0 ^ h1])
137 if (local == t->parms.iph.saddr && 132 if (local == t->parms.iph.saddr &&
138 remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP)) 133 remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP))
139 return t; 134 return t;
140 for_each_ip_tunnel_rcu(ipn->tunnels_r[h0]) 135 for_each_ip_tunnel_rcu(t, ipn->tunnels_r[h0])
141 if (remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP)) 136 if (remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP))
142 return t; 137 return t;
143 138
144 for_each_ip_tunnel_rcu(ipn->tunnels_l[h1]) 139 for_each_ip_tunnel_rcu(t, ipn->tunnels_l[h1])
145 if (local == t->parms.iph.saddr && (t->dev->flags&IFF_UP)) 140 if (local == t->parms.iph.saddr && (t->dev->flags&IFF_UP))
146 return t; 141 return t;
147 142
148 for_each_ip_tunnel_rcu(ipn->tunnels_wc[0]) 143 for_each_ip_tunnel_rcu(t, ipn->tunnels_wc[0])
149 if (t && (t->dev->flags&IFF_UP)) 144 if (t && (t->dev->flags&IFF_UP))
150 return t; 145 return t;
151 return NULL; 146 return NULL;
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
index 3a4ad7d82f67..099fc1c428b4 100644
--- a/net/ipv4/ipip.c
+++ b/net/ipv4/ipip.c
@@ -140,13 +140,6 @@ static void ipip_tunnel_setup(struct net_device *dev);
140static void ipip_dev_free(struct net_device *dev); 140static void ipip_dev_free(struct net_device *dev);
141static struct rtnl_link_ops ipip_link_ops __read_mostly; 141static struct rtnl_link_ops ipip_link_ops __read_mostly;
142 142
143/*
144 * Locking : hash tables are protected by RCU and RTNL
145 */
146
147#define for_each_ip_tunnel_rcu(start) \
148 for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
149
150static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev, 143static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
151 struct rtnl_link_stats64 *tot) 144 struct rtnl_link_stats64 *tot)
152{ 145{
@@ -189,16 +182,16 @@ static struct ip_tunnel *ipip_tunnel_lookup(struct net *net,
189 struct ip_tunnel *t; 182 struct ip_tunnel *t;
190 struct ipip_net *ipn = net_generic(net, ipip_net_id); 183 struct ipip_net *ipn = net_generic(net, ipip_net_id);
191 184
192 for_each_ip_tunnel_rcu(ipn->tunnels_r_l[h0 ^ h1]) 185 for_each_ip_tunnel_rcu(t, ipn->tunnels_r_l[h0 ^ h1])
193 if (local == t->parms.iph.saddr && 186 if (local == t->parms.iph.saddr &&
194 remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP)) 187 remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP))
195 return t; 188 return t;
196 189
197 for_each_ip_tunnel_rcu(ipn->tunnels_r[h0]) 190 for_each_ip_tunnel_rcu(t, ipn->tunnels_r[h0])
198 if (remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP)) 191 if (remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP))
199 return t; 192 return t;
200 193
201 for_each_ip_tunnel_rcu(ipn->tunnels_l[h1]) 194 for_each_ip_tunnel_rcu(t, ipn->tunnels_l[h1])
202 if (local == t->parms.iph.saddr && (t->dev->flags&IFF_UP)) 195 if (local == t->parms.iph.saddr && (t->dev->flags&IFF_UP))
203 return t; 196 return t;
204 197
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 672101db71ee..823fd64d0136 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -109,12 +109,6 @@ static u32 HASH_ADDR(const struct in6_addr *addr)
109#define tunnels_r tunnels[2] 109#define tunnels_r tunnels[2]
110#define tunnels_l tunnels[1] 110#define tunnels_l tunnels[1]
111#define tunnels_wc tunnels[0] 111#define tunnels_wc tunnels[0]
112/*
113 * Locking : hash tables are protected by RCU and RTNL
114 */
115
116#define for_each_ip_tunnel_rcu(start) \
117 for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
118 112
119static struct rtnl_link_stats64 *ip6gre_get_stats64(struct net_device *dev, 113static struct rtnl_link_stats64 *ip6gre_get_stats64(struct net_device *dev,
120 struct rtnl_link_stats64 *tot) 114 struct rtnl_link_stats64 *tot)
@@ -172,7 +166,7 @@ static struct ip6_tnl *ip6gre_tunnel_lookup(struct net_device *dev,
172 ARPHRD_ETHER : ARPHRD_IP6GRE; 166 ARPHRD_ETHER : ARPHRD_IP6GRE;
173 int score, cand_score = 4; 167 int score, cand_score = 4;
174 168
175 for_each_ip_tunnel_rcu(ign->tunnels_r_l[h0 ^ h1]) { 169 for_each_ip_tunnel_rcu(t, ign->tunnels_r_l[h0 ^ h1]) {
176 if (!ipv6_addr_equal(local, &t->parms.laddr) || 170 if (!ipv6_addr_equal(local, &t->parms.laddr) ||
177 !ipv6_addr_equal(remote, &t->parms.raddr) || 171 !ipv6_addr_equal(remote, &t->parms.raddr) ||
178 key != t->parms.i_key || 172 key != t->parms.i_key ||
@@ -197,7 +191,7 @@ static struct ip6_tnl *ip6gre_tunnel_lookup(struct net_device *dev,
197 } 191 }
198 } 192 }
199 193
200 for_each_ip_tunnel_rcu(ign->tunnels_r[h0 ^ h1]) { 194 for_each_ip_tunnel_rcu(t, ign->tunnels_r[h0 ^ h1]) {
201 if (!ipv6_addr_equal(remote, &t->parms.raddr) || 195 if (!ipv6_addr_equal(remote, &t->parms.raddr) ||
202 key != t->parms.i_key || 196 key != t->parms.i_key ||
203 !(t->dev->flags & IFF_UP)) 197 !(t->dev->flags & IFF_UP))
@@ -221,7 +215,7 @@ static struct ip6_tnl *ip6gre_tunnel_lookup(struct net_device *dev,
221 } 215 }
222 } 216 }
223 217
224 for_each_ip_tunnel_rcu(ign->tunnels_l[h1]) { 218 for_each_ip_tunnel_rcu(t, ign->tunnels_l[h1]) {
225 if ((!ipv6_addr_equal(local, &t->parms.laddr) && 219 if ((!ipv6_addr_equal(local, &t->parms.laddr) &&
226 (!ipv6_addr_equal(local, &t->parms.raddr) || 220 (!ipv6_addr_equal(local, &t->parms.raddr) ||
227 !ipv6_addr_is_multicast(local))) || 221 !ipv6_addr_is_multicast(local))) ||
@@ -247,7 +241,7 @@ static struct ip6_tnl *ip6gre_tunnel_lookup(struct net_device *dev,
247 } 241 }
248 } 242 }
249 243
250 for_each_ip_tunnel_rcu(ign->tunnels_wc[h1]) { 244 for_each_ip_tunnel_rcu(t, ign->tunnels_wc[h1]) {
251 if (t->parms.i_key != key || 245 if (t->parms.i_key != key ||
252 !(t->dev->flags & IFF_UP)) 246 !(t->dev->flags & IFF_UP))
253 continue; 247 continue;
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index ffe83ef70cf7..5bce2f698044 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -81,13 +81,6 @@ struct sit_net {
81 struct net_device *fb_tunnel_dev; 81 struct net_device *fb_tunnel_dev;
82}; 82};
83 83
84/*
85 * Locking : hash tables are protected by RCU and RTNL
86 */
87
88#define for_each_ip_tunnel_rcu(start) \
89 for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
90
91static struct rtnl_link_stats64 *ipip6_get_stats64(struct net_device *dev, 84static struct rtnl_link_stats64 *ipip6_get_stats64(struct net_device *dev,
92 struct rtnl_link_stats64 *tot) 85 struct rtnl_link_stats64 *tot)
93{ 86{
@@ -133,20 +126,20 @@ static struct ip_tunnel *ipip6_tunnel_lookup(struct net *net,
133 struct ip_tunnel *t; 126 struct ip_tunnel *t;
134 struct sit_net *sitn = net_generic(net, sit_net_id); 127 struct sit_net *sitn = net_generic(net, sit_net_id);
135 128
136 for_each_ip_tunnel_rcu(sitn->tunnels_r_l[h0 ^ h1]) { 129 for_each_ip_tunnel_rcu(t, sitn->tunnels_r_l[h0 ^ h1]) {
137 if (local == t->parms.iph.saddr && 130 if (local == t->parms.iph.saddr &&
138 remote == t->parms.iph.daddr && 131 remote == t->parms.iph.daddr &&
139 (!dev || !t->parms.link || dev->iflink == t->parms.link) && 132 (!dev || !t->parms.link || dev->iflink == t->parms.link) &&
140 (t->dev->flags & IFF_UP)) 133 (t->dev->flags & IFF_UP))
141 return t; 134 return t;
142 } 135 }
143 for_each_ip_tunnel_rcu(sitn->tunnels_r[h0]) { 136 for_each_ip_tunnel_rcu(t, sitn->tunnels_r[h0]) {
144 if (remote == t->parms.iph.daddr && 137 if (remote == t->parms.iph.daddr &&
145 (!dev || !t->parms.link || dev->iflink == t->parms.link) && 138 (!dev || !t->parms.link || dev->iflink == t->parms.link) &&
146 (t->dev->flags & IFF_UP)) 139 (t->dev->flags & IFF_UP))
147 return t; 140 return t;
148 } 141 }
149 for_each_ip_tunnel_rcu(sitn->tunnels_l[h1]) { 142 for_each_ip_tunnel_rcu(t, sitn->tunnels_l[h1]) {
150 if (local == t->parms.iph.saddr && 143 if (local == t->parms.iph.saddr &&
151 (!dev || !t->parms.link || dev->iflink == t->parms.link) && 144 (!dev || !t->parms.link || dev->iflink == t->parms.link) &&
152 (t->dev->flags & IFF_UP)) 145 (t->dev->flags & IFF_UP))