summaryrefslogtreecommitdiffstats
path: root/net/ipv4/devinet.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2011-02-18 12:43:09 -0800
committerDavid S. Miller <davem@davemloft.net>2011-02-18 12:43:09 -0800
commit9435eb1cf0b76b323019cebf8d16762a50a12a19 (patch)
treeb8396802efe005380366a59c58ce85267a460af1 /net/ipv4/devinet.c
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>
Diffstat (limited to 'net/ipv4/devinet.c')
-rw-r--r--net/ipv4/devinet.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 2fe50765a67..ee144a4fca4 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -125,6 +125,39 @@ static void inet_hash_remove(struct in_ifaddr *ifa)
spin_unlock(&inet_addr_hash_lock);
}
+/**
+ * __ip_dev_find - find the first device with a given source address.
+ * @net: the net namespace
+ * @addr: the source address
+ * @devref: if true, take a reference on the found device
+ *
+ * If a caller uses devref=false, it should be protected by RCU, or RTNL
+ */
+struct net_device *__ip_dev_find(struct net *net, __be32 addr, bool devref)
+{
+ unsigned int hash = inet_addr_hash(net, addr);
+ struct net_device *result = NULL;
+ struct in_ifaddr *ifa;
+ struct hlist_node *node;
+
+ rcu_read_lock();
+ hlist_for_each_entry_rcu(ifa, node, &inet_addr_lst[hash], hash) {
+ struct net_device *dev = ifa->ifa_dev->dev;
+
+ if (!net_eq(dev_net(dev), net))
+ continue;
+ if (ifa->ifa_address == addr) {
+ result = dev;
+ break;
+ }
+ }
+ if (result && devref)
+ dev_hold(result);
+ rcu_read_unlock();
+ return result;
+}
+EXPORT_SYMBOL(__ip_dev_find);
+
static void rtmsg_ifa(int event, struct in_ifaddr *, struct nlmsghdr *, u32);
static BLOCKING_NOTIFIER_HEAD(inetaddr_chain);