[component][sal]add netgetdev api

This commit is contained in:
zms123456 2024-10-11 10:40:24 +08:00 committed by GitHub
parent c9a1245977
commit 906d1caea6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 0 deletions

View File

@ -155,6 +155,9 @@ struct netdev *netdev_get_by_name(const char *name);
struct netdev *netdev_get_by_family(int family); struct netdev *netdev_get_by_family(int family);
int netdev_family_get(struct netdev *netdev); int netdev_family_get(struct netdev *netdev);
#endif /* RT_USING_SAL */ #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 */ /* Set default network interface device in list */
void netdev_set_default(struct netdev *netdev); void netdev_set_default(struct netdev *netdev);

View File

@ -392,6 +392,44 @@ int netdev_family_get(struct netdev *netdev)
#endif /* RT_USING_SAL */ #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. * This function will set default network interface device.
* *