Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[component][sal]add netgetdev api #9442

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions components/net/netdev/include/netdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,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);
Expand Down
38 changes: 38 additions & 0 deletions components/net/netdev/src/netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,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.
*
Expand Down
Loading