You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2020/04/16 09:47:31 UTC
[incubator-nuttx] 05/05: netlink: Add netlink_add_broadcast function
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit bd39813883e172767d59100339bb51e47a24d3b7
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Thu Apr 16 13:50:20 2020 +0800
netlink: Add netlink_add_broadcast function
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
Change-Id: I1bee7933dca1bdd118d0034a564b4306e1ae5684
---
include/nuttx/net/netlink.h | 21 ++++++++++++-
net/netlink/netlink_conn.c | 72 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 92 insertions(+), 1 deletion(-)
diff --git a/include/nuttx/net/netlink.h b/include/nuttx/net/netlink.h
index 04f9eaa..3796271 100644
--- a/include/nuttx/net/netlink.h
+++ b/include/nuttx/net/netlink.h
@@ -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
}
diff --git a/net/netlink/netlink_conn.c b/net/netlink/netlink_conn.c
index fc25ad0..9145ef2 100644
--- a/net/netlink/netlink_conn.c
+++ b/net/netlink/netlink_conn.c
@@ -290,6 +290,78 @@ void netlink_add_response(NETLINK_HANDLE handle,
}
/****************************************************************************
+ * 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
*
* Description: