aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2011-02-18 15:43:09 -0500
committerDavid S. Miller <davem@davemloft.net>2011-02-18 15:43:09 -0500
commit9435eb1cf0b76b323019cebf8d16762a50a12a19 (patch)
treeb8396802efe005380366a59c58ce85267a460af1
parentfd23c3b31107e2fc483301ee923d8a1db14e53f4 (diff)
ipv4: Implement __ip_dev_find using new interface address hash.
Much quicker than going through the FIB tables. Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/ipv4/devinet.c33
-rw-r--r--net/ipv4/fib_frontend.c40
2 files changed, 33 insertions, 40 deletions
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 2fe50765a672..ee144a4fca41 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -125,6 +125,39 @@ static void inet_hash_remove(struct in_ifaddr *ifa)
125 spin_unlock(&inet_addr_hash_lock); 125 spin_unlock(&inet_addr_hash_lock);
126} 126}
127 127
128/**
129 * __ip_dev_find - find the first device with a given source address.
130 * @net: the net namespace
131 * @addr: the source address
132 * @devref: if true, take a reference on the found device
133 *
134 * If a caller uses devref=false, it should be protected by RCU, or RTNL
135 */
136struct net_device *__ip_dev_find(struct net *net, __be32 addr, bool devref)
137{
138 unsigned int hash = inet_addr_hash(net, addr);
139 struct net_device *result = NULL;
140 struct in_ifaddr *ifa;
141 struct hlist_node *node;
142
143 rcu_read_lock();
144 hlist_for_each_entry_rcu(ifa, node, &inet_addr_lst[hash], hash) {
145 struct net_device *dev = ifa->ifa_dev->dev;
146
147 if (!net_eq(dev_net(dev), net))
148 continue;
149 if (ifa->ifa_address == addr) {
150 result = dev;
151 break;
152 }
153 }
154 if (result && devref)
155 dev_hold(result);
156 rcu_read_unlock();
157 return result;
158}
159EXPORT_SYMBOL(__ip_dev_find);
160
128static void rtmsg_ifa(int event, struct in_ifaddr *, struct nlmsghdr *, u32); 161static void rtmsg_ifa(int event, struct in_ifaddr *, struct nlmsghdr *, u32);
129 162
130static BLOCKING_NOTIFIER_HEAD(inetaddr_chain); 163static BLOCKING_NOTIFIER_HEAD(inetaddr_chain);
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index 2a49c061b34c..ad0778a3fa53 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -132,46 +132,6 @@ static void fib_flush(struct net *net)
132 rt_cache_flush(net, -1); 132 rt_cache_flush(net, -1);
133} 133}
134 134
135/**
136 * __ip_dev_find - find the first device with a given source address.
137 * @net: the net namespace
138 * @addr: the source address
139 * @devref: if true, take a reference on the found device
140 *
141 * If a caller uses devref=false, it should be protected by RCU, or RTNL
142 */
143struct net_device *__ip_dev_find(struct net *net, __be32 addr, bool devref)
144{
145 struct flowi fl = {
146 .fl4_dst = addr,
147 };
148 struct fib_result res = { 0 };
149 struct net_device *dev = NULL;
150 struct fib_table *local_table;
151
152#ifdef CONFIG_IP_MULTIPLE_TABLES
153 res.r = NULL;
154#endif
155
156 rcu_read_lock();
157 local_table = fib_get_table(net, RT_TABLE_LOCAL);
158 if (!local_table ||
159 fib_table_lookup(local_table, &fl, &res, FIB_LOOKUP_NOREF)) {
160 rcu_read_unlock();
161 return NULL;
162 }
163 if (res.type != RTN_LOCAL)
164 goto out;
165 dev = FIB_RES_DEV(res);
166
167 if (dev && devref)
168 dev_hold(dev);
169out:
170 rcu_read_unlock();
171 return dev;
172}
173EXPORT_SYMBOL(__ip_dev_find);
174
175/* 135/*
176 * Find address type as if only "dev" was present in the system. If 136 * Find address type as if only "dev" was present in the system. If
177 * on_dev is NULL then all interfaces are taken into consideration. 137 * on_dev is NULL then all interfaces are taken into consideration.