netlink: Add netlink_add_broadcast function
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Change-Id: I1bee7933dca1bdd118d0034a564b4306e1ae5684
This commit is contained in:
parent
755265506c
commit
bd39813883
@ -72,7 +72,7 @@ typedef FAR void *NETLINK_HANDLE;
|
||||
struct netlink_response_s
|
||||
{
|
||||
sq_entry_t flink;
|
||||
FAR struct nlmsghdr msg;
|
||||
struct nlmsghdr msg;
|
||||
|
||||
/* Message-specific data may follow */
|
||||
};
|
||||
@ -113,6 +113,25 @@ extern "C"
|
||||
void netlink_add_response(NETLINK_HANDLE handle,
|
||||
FAR struct netlink_response_s *resp);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netlink_add_broadcast
|
||||
*
|
||||
* Description:
|
||||
* Add broadcast data to all interested netlink connections.
|
||||
*
|
||||
* Note: The network will be momentarily locked to support exclusive
|
||||
* access to the pending response list.
|
||||
*
|
||||
* Input Parameters:
|
||||
* group - The broadcast group index.
|
||||
* data - The broadcast data. The memory referenced by 'data'
|
||||
* must have been allocated via kmm_malloc(). It will be freed
|
||||
* using kmm_free() after it has been consumed.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void netlink_add_broadcast(int group, FAR struct netlink_response_s *data);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -289,6 +289,78 @@ void netlink_add_response(NETLINK_HANDLE handle,
|
||||
net_unlock();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netlink_add_broadcast
|
||||
*
|
||||
* Description:
|
||||
* Add broadcast data to all interested netlink connections.
|
||||
*
|
||||
* Note: The network will be momentarily locked to support exclusive
|
||||
* access to the pending response list.
|
||||
*
|
||||
* Input Parameters:
|
||||
* group - The broadcast group index.
|
||||
* data - The broadcast data. The memory referenced by 'data'
|
||||
* must have been allocated via kmm_malloc(). It will be freed
|
||||
* using kmm_free() after it has been consumed.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void netlink_add_broadcast(int group, FAR struct netlink_response_s *data)
|
||||
{
|
||||
FAR struct netlink_conn_s *conn = NULL;
|
||||
int first = 1;
|
||||
|
||||
DEBUGASSERT(data != NULL);
|
||||
|
||||
net_lock();
|
||||
|
||||
while ((conn = netlink_nextconn(conn)) != NULL)
|
||||
{
|
||||
if (conn->groups & (1 << (group - 1)) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Duplicate the package except the first loop */
|
||||
|
||||
if (!first)
|
||||
{
|
||||
FAR struct netlink_response_s *tmp;
|
||||
size_t len;
|
||||
|
||||
len = sizeof(sq_entry_t) + data->msg.nlmsg_len;
|
||||
tmp = kmm_malloc(len);
|
||||
if (tmp == NULL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(tmp, data, len);
|
||||
data = tmp;
|
||||
}
|
||||
|
||||
first = 0;
|
||||
|
||||
/* Add the response to the end of the FIFO list */
|
||||
|
||||
sq_addlast(&data->flink, &conn->resplist);
|
||||
|
||||
/* Notify any waiters that a response is available */
|
||||
|
||||
netlink_notifier_signal(conn);
|
||||
}
|
||||
|
||||
net_unlock();
|
||||
|
||||
/* Drop the package if nobody is interested in */
|
||||
|
||||
if (first)
|
||||
{
|
||||
kmm_free(data);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: netlink_tryget_response
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user