diff --git a/components/net/netdev/include/netdev.h b/components/net/netdev/include/netdev.h index cafa73d4c2..6b00bc2148 100644 --- a/components/net/netdev/include/netdev.h +++ b/components/net/netdev/include/netdev.h @@ -155,6 +155,9 @@ struct netdev *netdev_get_by_name(const char *name); struct netdev *netdev_get_by_family(int family); int netdev_family_get(struct netdev *netdev); #endif /* RT_USING_SAL */ +#if defined(SAL_USING_AF_NETLINK) +int netdev_getnetdev(struct msg_buf *msg, int (*cb)(struct msg_buf *m_buf, struct netdev *nd, int nd_num, int index, int ipvx)); +#endif /* Set default network interface device in list */ void netdev_set_default(struct netdev *netdev); diff --git a/components/net/netdev/src/netdev.c b/components/net/netdev/src/netdev.c index 2f4cea5120..22b6d3d74c 100644 --- a/components/net/netdev/src/netdev.c +++ b/components/net/netdev/src/netdev.c @@ -392,6 +392,44 @@ int netdev_family_get(struct netdev *netdev) #endif /* RT_USING_SAL */ +#if defined(SAL_USING_AF_NETLINK) +int netdev_getnetdev(struct msg_buf *msg, int (*cb)(struct msg_buf *m_buf, struct netdev *nd, int nd_num, int index, int ipvx)) +{ + struct netdev *cur_nd_list = netdev_list; + struct netdev *nd_node; + int nd_num = 0; + int err = 0; + + if (cur_nd_list == RT_NULL) + return 0; + + rt_spin_lock(&_spinlock); + nd_num = rt_slist_len(&cur_nd_list->list) + 1; + rt_spin_unlock(&_spinlock); + + err = cb(msg, cur_nd_list, nd_num, nd.ifindex, ROUTE_IPV4_TRUE); + if (err < 0) + return err; + + + rt_spin_lock(&_spinlock); + rt_slist_for_each_entry(nd_node, &(cur_nd_list->list), list) + { + rt_spin_unlock(&_spinlock); + err = cb(msg, nd_node, nd_num, nd.ifindex, ROUTE_IPV4_TRUE); + if (err < 0) + { + return err; + } + + rt_spin_lock(&_spinlock); + } + rt_spin_unlock(&_spinlock); + + return 0; +} +#endif + /** * This function will set default network interface device. *