提交 ed7865a4 编写于 作者: E Eric Dumazet 提交者: David S. Miller

ipv4: avoid two atomic ops in ip_rt_redirect()

in_dev_get() -> __in_dev_get_rcu() in a rcu protected function.

[ Fix build with CONFIG_IP_ROUTE_VERBOSE disabled. -DaveM ]
Signed-off-by: NEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 9a57a9d2
...@@ -1343,11 +1343,12 @@ static void rt_del(unsigned hash, struct rtable *rt) ...@@ -1343,11 +1343,12 @@ static void rt_del(unsigned hash, struct rtable *rt)
spin_unlock_bh(rt_hash_lock_addr(hash)); spin_unlock_bh(rt_hash_lock_addr(hash));
} }
/* called in rcu_read_lock() section */
void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw, void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
__be32 saddr, struct net_device *dev) __be32 saddr, struct net_device *dev)
{ {
int i, k; int i, k;
struct in_device *in_dev = in_dev_get(dev); struct in_device *in_dev = __in_dev_get_rcu(dev);
struct rtable *rth, **rthp; struct rtable *rth, **rthp;
__be32 skeys[2] = { saddr, 0 }; __be32 skeys[2] = { saddr, 0 };
int ikeys[2] = { dev->ifindex, 0 }; int ikeys[2] = { dev->ifindex, 0 };
...@@ -1383,7 +1384,6 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw, ...@@ -1383,7 +1384,6 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
rthp=&rt_hash_table[hash].chain; rthp=&rt_hash_table[hash].chain;
rcu_read_lock();
while ((rth = rcu_dereference(*rthp)) != NULL) { while ((rth = rcu_dereference(*rthp)) != NULL) {
struct rtable *rt; struct rtable *rt;
...@@ -1405,12 +1405,10 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw, ...@@ -1405,12 +1405,10 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
break; break;
dst_hold(&rth->u.dst); dst_hold(&rth->u.dst);
rcu_read_unlock();
rt = dst_alloc(&ipv4_dst_ops); rt = dst_alloc(&ipv4_dst_ops);
if (rt == NULL) { if (rt == NULL) {
ip_rt_put(rth); ip_rt_put(rth);
in_dev_put(in_dev);
return; return;
} }
...@@ -1463,12 +1461,10 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw, ...@@ -1463,12 +1461,10 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
ip_rt_put(rt); ip_rt_put(rt);
goto do_next; goto do_next;
} }
rcu_read_unlock();
do_next: do_next:
; ;
} }
} }
in_dev_put(in_dev);
return; return;
reject_redirect: reject_redirect:
...@@ -1479,7 +1475,7 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw, ...@@ -1479,7 +1475,7 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw,
&old_gw, dev->name, &new_gw, &old_gw, dev->name, &new_gw,
&saddr, &daddr); &saddr, &daddr);
#endif #endif
in_dev_put(in_dev); ;
} }
static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst) static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册