Skip to content

Commit 906d1ca

Browse files
authored
[component][sal]add netgetdev api
1 parent c9a1245 commit 906d1ca

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

components/net/netdev/include/netdev.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ struct netdev *netdev_get_by_name(const char *name);
155155
struct netdev *netdev_get_by_family(int family);
156156
int netdev_family_get(struct netdev *netdev);
157157
#endif /* RT_USING_SAL */
158+
#if defined(SAL_USING_AF_NETLINK)
159+
int netdev_getnetdev(struct msg_buf *msg, int (*cb)(struct msg_buf *m_buf, struct netdev *nd, int nd_num, int index, int ipvx));
160+
#endif
158161

159162
/* Set default network interface device in list */
160163
void netdev_set_default(struct netdev *netdev);

components/net/netdev/src/netdev.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,44 @@ int netdev_family_get(struct netdev *netdev)
392392

393393
#endif /* RT_USING_SAL */
394394

395+
#if defined(SAL_USING_AF_NETLINK)
396+
int netdev_getnetdev(struct msg_buf *msg, int (*cb)(struct msg_buf *m_buf, struct netdev *nd, int nd_num, int index, int ipvx))
397+
{
398+
struct netdev *cur_nd_list = netdev_list;
399+
struct netdev *nd_node;
400+
int nd_num = 0;
401+
int err = 0;
402+
403+
if (cur_nd_list == RT_NULL)
404+
return 0;
405+
406+
rt_spin_lock(&_spinlock);
407+
nd_num = rt_slist_len(&cur_nd_list->list) + 1;
408+
rt_spin_unlock(&_spinlock);
409+
410+
err = cb(msg, cur_nd_list, nd_num, nd.ifindex, ROUTE_IPV4_TRUE);
411+
if (err < 0)
412+
return err;
413+
414+
415+
rt_spin_lock(&_spinlock);
416+
rt_slist_for_each_entry(nd_node, &(cur_nd_list->list), list)
417+
{
418+
rt_spin_unlock(&_spinlock);
419+
err = cb(msg, nd_node, nd_num, nd.ifindex, ROUTE_IPV4_TRUE);
420+
if (err < 0)
421+
{
422+
return err;
423+
}
424+
425+
rt_spin_lock(&_spinlock);
426+
}
427+
rt_spin_unlock(&_spinlock);
428+
429+
return 0;
430+
}
431+
#endif
432+
395433
/**
396434
* This function will set default network interface device.
397435
*

0 commit comments

Comments
 (0)