-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add an API to get the netdev list #8860
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -398,6 +398,51 @@ int netdev_family_get(struct netdev *netdev) | |
return ((struct sal_proto_family *)netdev->sal_user_data)->family; | ||
} | ||
|
||
#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; | ||
struct netdev nd; | ||
rt_base_t level; | ||
int index = 0; | ||
int nd_num = 0; | ||
int err = 0; | ||
|
||
if (cur_nd_list == RT_NULL) | ||
return 0; | ||
|
||
level = rt_spin_lock_irqsave(&_spinlock); | ||
nd_num = rt_slist_len(&cur_nd_list->list) + 1; | ||
rt_spin_unlock_irqrestore(&_spinlock, level); | ||
|
||
rt_memcpy(&nd, cur_nd_list, sizeof(struct netdev)); | ||
err = cb(msg, &nd, nd_num, index, ROUTE_IPV4_TRUE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 没开 NETLINK 的时应该没有这个宏定义,这么处理会编译失败。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个函数加了宏控,不会编译失败的,并且cb是传过来的回调函数,即使没有宏控,编译也不应该会失败的才对 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 是指 |
||
if (err < 0) | ||
return err; | ||
|
||
index ++; | ||
|
||
level = rt_spin_lock_irqsave(&_spinlock); | ||
rt_slist_for_each_entry(nd_node, &(cur_nd_list->list), list) | ||
{ | ||
rt_memcpy(&nd, nd_node, sizeof(struct netdev)); | ||
rt_spin_unlock_irqrestore(&_spinlock, level); | ||
err = cb(msg, &nd, nd_num, index, ROUTE_IPV4_TRUE); | ||
if (err < 0) | ||
{ | ||
return err; | ||
} | ||
|
||
index ++; | ||
level = rt_spin_lock_irqsave(&_spinlock); | ||
} | ||
rt_spin_unlock_irqrestore(&_spinlock, level); | ||
|
||
return 0; | ||
} | ||
#endif | ||
|
||
#endif /* RT_USING_SAL */ | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以想想,怎么来降低spin_lock_irqsave的时间吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果只是计算netdev_list的长度,可以的,只需要定义一个原子类型的变量,在每次注册或者删除netdev的时候进行原子操作+1或者-1就可以了