|
@@ -39,6 +39,7 @@ struct netdev *netdev_default = RT_NULL;
|
|
|
static netdev_callback_fn g_netdev_register_callback = RT_NULL;
|
|
|
static netdev_callback_fn g_netdev_default_change_callback = RT_NULL;
|
|
|
static RT_DEFINE_SPINLOCK(_spinlock);
|
|
|
+static int netdev_num;
|
|
|
|
|
|
/**
|
|
|
* This function will register network interface device and
|
|
@@ -112,6 +113,9 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
|
|
|
rt_slist_append(&(netdev_list->list), &(netdev->list));
|
|
|
}
|
|
|
|
|
|
+ netdev_num++;
|
|
|
+ netdev->ifindex = netdev_num;
|
|
|
+
|
|
|
rt_spin_unlock(&_spinlock);
|
|
|
|
|
|
if (netdev_default == RT_NULL)
|
|
@@ -326,6 +330,42 @@ struct netdev *netdev_get_by_name(const char *name)
|
|
|
return RT_NULL;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * This function will get network interface device
|
|
|
+ * in network interface device list by netdev ifindex.
|
|
|
+ *
|
|
|
+ * @param ifindex the ifindex of network interface device
|
|
|
+ *
|
|
|
+ * @return != NULL: network interface device object
|
|
|
+ * NULL: get failed
|
|
|
+ */
|
|
|
+struct netdev *netdev_get_by_ifindex(int ifindex)
|
|
|
+{
|
|
|
+ rt_slist_t *node = RT_NULL;
|
|
|
+ struct netdev *netdev = RT_NULL;
|
|
|
+
|
|
|
+ if (netdev_list == RT_NULL)
|
|
|
+ {
|
|
|
+ return RT_NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ rt_spin_lock(&_spinlock);
|
|
|
+
|
|
|
+ for (node = &(netdev_list->list); node; node = rt_slist_next(node))
|
|
|
+ {
|
|
|
+ netdev = rt_slist_entry(node, struct netdev, list);
|
|
|
+ if (netdev && (netdev->ifindex == ifindex))
|
|
|
+ {
|
|
|
+ rt_spin_unlock(&_spinlock);
|
|
|
+ return netdev;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ rt_spin_unlock(&_spinlock);
|
|
|
+
|
|
|
+ return RT_NULL;
|
|
|
+}
|
|
|
+
|
|
|
#ifdef RT_USING_SAL
|
|
|
/**
|
|
|
* This function will get the first network interface device
|