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/nuttx.git

commit 9b77bb16c9a1d6b6a172af8b0906281e0f0f0c4e
Author: Zhe Weng <[email protected]>
AuthorDate: Thu Mar 21 12:14:29 2024 +0800

    net/netlink: Move netlink_add_terminator as public
    
    Prepare for other netlink dumps.
    
    Signed-off-by: Zhe Weng <[email protected]>
---
 net/netlink/netlink.h       | 23 ++++++++++++
 net/netlink/netlink_conn.c  | 80 +++++++++++++++++++++++++++++++++++++++++
 net/netlink/netlink_route.c | 88 +++++----------------------------------------
 3 files changed, 112 insertions(+), 79 deletions(-)

diff --git a/net/netlink/netlink.h b/net/netlink/netlink.h
index c2b83ed0fa..320f792438 100644
--- a/net/netlink/netlink.h
+++ b/net/netlink/netlink.h
@@ -398,6 +398,29 @@ void netlink_notifier_teardown(FAR struct netlink_conn_s 
*conn);
 
 void netlink_notifier_signal(FAR struct netlink_conn_s *conn);
 
+/****************************************************************************
+ * Name: netlink_add_terminator
+ *
+ * Description:
+ *   Add one NLMSG_DONE response to handle.
+ *
+ * Input Parameters:
+ *   handle - The handle previously provided to the sendto() implementation
+ *            for the protocol.  This is an opaque reference to the Netlink
+ *            socket state structure.
+ *   req    - The request message header.
+ *   group  - The broadcast group index, 0 for normal response.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned if the terminator was successfully added to the
+ *   response list.
+ *   A negated error value is returned if an unexpected error occurred.
+ *
+ ****************************************************************************/
+
+int netlink_add_terminator(NETLINK_HANDLE handle,
+                           FAR const struct nlmsghdr *req, int group);
+
 /****************************************************************************
  * Name: netlink_tryget_response
  *
diff --git a/net/netlink/netlink_conn.c b/net/netlink/netlink_conn.c
index 39f7fcc861..8f7673850c 100644
--- a/net/netlink/netlink_conn.c
+++ b/net/netlink/netlink_conn.c
@@ -92,6 +92,43 @@ static void netlink_response_available(FAR void *arg)
   nxsem_post(arg);
 }
 
+/****************************************************************************
+ * Name: netlink_get_terminator
+ *
+ * Description:
+ *   Generate one NLMSG_DONE response.
+ *
+ ****************************************************************************/
+
+static FAR struct netlink_response_s *
+netlink_get_terminator(FAR const struct nlmsghdr *req)
+{
+  FAR struct netlink_response_s *resp;
+  FAR struct nlmsghdr *hdr;
+
+  /* Allocate the list terminator */
+
+  resp = kmm_zalloc(sizeof(struct netlink_response_s));
+  if (resp == NULL)
+    {
+      nerr("ERROR: Failed to allocate response terminator.\n");
+      return NULL;
+    }
+
+  /* Initialize and send the list terminator */
+
+  hdr              = &resp->msg;
+  hdr->nlmsg_len   = sizeof(struct nlmsghdr);
+  hdr->nlmsg_type  = NLMSG_DONE;
+  hdr->nlmsg_flags = req ? req->nlmsg_flags : 0;
+  hdr->nlmsg_seq   = req ? req->nlmsg_seq : 0;
+  hdr->nlmsg_pid   = req ? req->nlmsg_pid : 0;
+
+  /* Finally, return the response */
+
+  return resp;
+}
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -286,6 +323,49 @@ void netlink_add_response(NETLINK_HANDLE handle,
   net_unlock();
 }
 
+/****************************************************************************
+ * Name: netlink_add_terminator
+ *
+ * Description:
+ *   Add one NLMSG_DONE response to handle.
+ *
+ * Input Parameters:
+ *   handle - The handle previously provided to the sendto() implementation
+ *            for the protocol.  This is an opaque reference to the Netlink
+ *            socket state structure.
+ *   req    - The request message header.
+ *   group  - The broadcast group index, 0 for normal response.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned if the terminator was successfully added to the
+ *   response list.
+ *   A negated error value is returned if an unexpected error occurred.
+ *
+ ****************************************************************************/
+
+int netlink_add_terminator(NETLINK_HANDLE handle,
+                           FAR const struct nlmsghdr *req, int group)
+{
+  FAR struct netlink_response_s *resp;
+
+  resp = netlink_get_terminator(req);
+  if (resp == NULL)
+    {
+      return -ENOMEM;
+    }
+
+  if (group > 0)
+    {
+      netlink_add_broadcast(group, resp);
+    }
+  else
+    {
+      netlink_add_response(handle, resp);
+    }
+
+  return OK;
+}
+
 /****************************************************************************
  * Name: netlink_add_broadcast
  *
diff --git a/net/netlink/netlink_route.c b/net/netlink/netlink_route.c
index 82192203ef..0f4bdc2e18 100644
--- a/net/netlink/netlink_route.c
+++ b/net/netlink/netlink_route.c
@@ -440,66 +440,6 @@ netlink_get_ifaddr(FAR struct net_driver_s *dev, int 
domain, int type,
 }
 #endif
 
-/****************************************************************************
- * Name: netlink_get_terminator
- *
- * Description:
- *   Generate one NLMSG_DONE response.
- *
- ****************************************************************************/
-
-static FAR struct netlink_response_s *
-netlink_get_terminator(FAR const struct nlroute_sendto_request_s *req)
-{
-  FAR struct netlink_response_s *resp;
-  FAR struct nlmsghdr *hdr;
-
-  /* Allocate the list terminator */
-
-  resp = kmm_zalloc(sizeof(struct netlink_response_s));
-  if (resp == NULL)
-    {
-      nerr("ERROR: Failed to allocate response terminator.\n");
-      return NULL;
-    }
-
-  /* Initialize and send the list terminator */
-
-  hdr              = &resp->msg;
-  hdr->nlmsg_len   = sizeof(struct nlmsghdr);
-  hdr->nlmsg_type  = NLMSG_DONE;
-  hdr->nlmsg_flags = req ? req->hdr.nlmsg_flags : 0;
-  hdr->nlmsg_seq   = req ? req->hdr.nlmsg_seq : 0;
-  hdr->nlmsg_pid   = req ? req->hdr.nlmsg_pid : 0;
-
-  /* Finally, return the response */
-
-  return resp;
-}
-
-/****************************************************************************
- * Name: netlink_add_terminator
- *
- * Description:
- *   Add one NLMSG_DONE response to handle.
- *
- ****************************************************************************/
-
-static int netlink_add_terminator(NETLINK_HANDLE handle,
-                              FAR const struct nlroute_sendto_request_s *req)
-{
-  FAR struct netlink_response_s * resp;
-
-  resp = netlink_get_terminator(req);
-  if (resp == NULL)
-    {
-      return -ENOMEM;
-    }
-
-  netlink_add_response(handle, resp);
-  return OK;
-}
-
 /****************************************************************************
  * Name: netlink_get_devlist
  *
@@ -544,7 +484,7 @@ static int netlink_get_devlist(NETLINK_HANDLE handle,
       return ret;
     }
 
-  return netlink_add_terminator(handle, req);
+  return netlink_add_terminator(handle, &req->hdr, 0);
 }
 #endif
 
@@ -803,7 +743,7 @@ static int netlink_get_ipv4route(NETLINK_HANDLE handle,
 
   /* Terminate the routing table */
 
-  return netlink_add_terminator(handle, req);
+  return netlink_add_terminator(handle, &req->hdr, 0);
 }
 #endif
 
@@ -869,7 +809,7 @@ static int netlink_ipv6_route(FAR struct net_route_ipv6_s 
*route,
 #endif
 
 /****************************************************************************
- * Name: netlink_get_ip6vroute
+ * Name: netlink_get_ipv6route
  *
  * Description:
  *   Dump a list of all network devices of the specified type.
@@ -877,7 +817,7 @@ static int netlink_ipv6_route(FAR struct net_route_ipv6_s 
*route,
  ****************************************************************************/
 
 #if defined(CONFIG_NET_IPv6) && !defined(CONFIG_NETLINK_DISABLE_GETROUTE)
-static int netlink_get_ip6vroute(NETLINK_HANDLE handle,
+static int netlink_get_ipv6route(NETLINK_HANDLE handle,
                               FAR const struct nlroute_sendto_request_s *req)
 {
   struct nlroute_info_s info;
@@ -896,7 +836,7 @@ static int netlink_get_ip6vroute(NETLINK_HANDLE handle,
 
   /* Terminate the routing table */
 
-  return netlink_add_terminator(handle, req);
+  return netlink_add_terminator(handle, &req->hdr, 0);
 }
 #endif
 
@@ -1188,7 +1128,7 @@ static int netlink_get_addr(NETLINK_HANDLE handle,
       return ret;
     }
 
-  return netlink_add_terminator(handle, req);
+  return netlink_add_terminator(handle, &req->hdr, 0);
 }
 #endif
 
@@ -1278,7 +1218,7 @@ ssize_t netlink_route_sendto(NETLINK_HANDLE handle,
 #ifdef CONFIG_NET_IPv6
         if (req->gen.rtgen_family == AF_INET6)
           {
-            ret = netlink_get_ip6vroute(handle, req);
+            ret = netlink_get_ipv6route(handle, req);
           }
         else
 #endif
@@ -1394,12 +1334,7 @@ void netlink_device_notify(FAR struct net_driver_s *dev)
   if (resp != NULL)
     {
       netlink_add_broadcast(RTNLGRP_LINK, resp);
-
-      resp = netlink_get_terminator(NULL);
-      if (resp != NULL)
-        {
-          netlink_add_broadcast(RTNLGRP_LINK, resp);
-        }
+      netlink_add_terminator(NULL, NULL, RTNLGRP_LINK);
     }
 }
 #endif
@@ -1448,12 +1383,7 @@ void netlink_device_notify_ipaddr(FAR struct 
net_driver_s *dev,
         }
 
       netlink_add_broadcast(group, resp);
-
-      resp = netlink_get_terminator(NULL);
-      if (resp != NULL)
-        {
-          netlink_add_broadcast(group, resp);
-        }
+      netlink_add_terminator(NULL, NULL, group);
     }
 }
 #endif

Reply via email to