//
// dev_2.0.c
//
//
// Created by Mac User on 13/02/11.
//
//
#include <stdio.h>
/**
* __xev_get_by_name - find a device by its name
* @name: name to find
*
* Find an interface by name. Must be called under RTNL semaphore
* or @dev_base_lock. If the name is found a pointer to the device
* is returned. If the name is not found then %NULL is returned. The
* reference counters are not incremented so the caller must be
* careful with locks.
*/
struct net_xevice *__xev_get_by_name(const char *name)
{
struct hlist_node *p;
hlist_for_each(p, xev_name_hash(name)) {
struct net_device *xev
= hlist_entry(p, struct net_device, name_hlist);
if (!strncmp(dev->name, name, IFNAMSIZ))
return xev;
}
return NULL;
}
/**
* xev_get_by_name - find a device by its name
* @name: name to find
*
* Find an interface by name. This can be called from any
* context and does its own locking. The returned handle has
* the usage count incremented and the caller must use dev_put() to
* release it when it is no longer needed. %NULL is returned if no
* matching device is found.
*/
struct net_device *xev_get_by_name(const char *name)
{
struct net_device *xev;
read_lock(&xev_base_lock);
xev = __xev_get_by_name(name);
if (xev)
xev_hold(xev);
read_unlock(&xev_base_lock);
return xev;
}
/**
* __xev_get_by_index - find a device by its ifindex
* @ifindex: index of device
*
* Search for an interface by index. Returns %NULL if the device
* is not found or a pointer to the device. The device has not
* had its reference counter increased so the caller must be careful
* about locking. The caller must hold either the RTNL semaphore
* or @dev_base_lock.
*/
struct net_device *__xev_get_by_index(int ifindex)
{
struct hlist_node *p;
hlist_for_each(p, xev_index_hash(ifindex)) {
struct net_device *xev
= hlist_entry(p, struct net_device, index_hlist);
if (dev->ifindex == ifindex)
return xev;
}
return NULL;
}