mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
netlink: Add netlink_add_broadcast function
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Change-Id: I1bee7933dca1bdd118d0034a564b4306e1ae5684
This commit is contained in:
@@ -72,7 +72,7 @@ typedef FAR void *NETLINK_HANDLE;
|
|||||||
struct netlink_response_s
|
struct netlink_response_s
|
||||||
{
|
{
|
||||||
sq_entry_t flink;
|
sq_entry_t flink;
|
||||||
FAR struct nlmsghdr msg;
|
struct nlmsghdr msg;
|
||||||
|
|
||||||
/* Message-specific data may follow */
|
/* Message-specific data may follow */
|
||||||
};
|
};
|
||||||
@@ -113,6 +113,25 @@ extern "C"
|
|||||||
void netlink_add_response(NETLINK_HANDLE handle,
|
void netlink_add_response(NETLINK_HANDLE handle,
|
||||||
FAR struct netlink_response_s *resp);
|
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
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -289,6 +289,78 @@ void netlink_add_response(NETLINK_HANDLE handle,
|
|||||||
net_unlock();
|
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
|
* Name: netlink_tryget_response
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user