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:26 UTC

[incubator-nuttx] branch master updated (773f540 -> bd398138)

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.


    from 773f540  tools/checkpatch.sh: enhance added files judgement with +++ at the line beginning
     new 85dce03  netlink/route: remove domain check
     new 16c0c61  netlink/route: reuse response terminator
     new bd4bccb  netlink: add netlink multicast group define
     new 7552655  netlink: replace the operation handle to connection
     new bd398138 netlink: Add netlink_add_broadcast function

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 include/netpacket/netlink.h  |  55 ++++++++
 include/nuttx/net/netlink.h  |  21 ++-
 net/netlink/netlink.h        |   8 +-
 net/netlink/netlink_conn.c   | 102 ++++++++++++---
 net/netlink/netlink_route.c  | 295 ++++++++++---------------------------------
 net/netlink/netlink_sockif.c |   8 +-
 6 files changed, 234 insertions(+), 255 deletions(-)


[incubator-nuttx] 02/05: netlink/route: reuse response terminator

Posted by xi...@apache.org.
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 16c0c61e3e829a797bce279abc6908081dcc7a57
Author: chao.an <an...@xiaomi.com>
AuthorDate: Mon Apr 13 15:40:01 2020 +0800

    netlink/route: reuse response terminator
    
    Change-Id: I19c3d97b088231d96909d415d286c728ffe83881
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 net/netlink/netlink_route.c | 117 +++++++++++++++-----------------------------
 1 file changed, 40 insertions(+), 77 deletions(-)

diff --git a/net/netlink/netlink_route.c b/net/netlink/netlink_route.c
index 6f356d7..741b6ba 100644
--- a/net/netlink/netlink_route.c
+++ b/net/netlink/netlink_route.c
@@ -83,14 +83,6 @@
  * Private Types
  ****************************************************************************/
 
-/* Used to send message done */
-
-struct nlroute_msgdone_rsplist_s
-{
-  sq_entry_t flink;
-  struct nlmsghdr payload;
-};
-
 /* RTM_GETLINK:  Enumerate network devices */
 
 struct getlink_recvfrom_response_s
@@ -262,32 +254,58 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
 #endif
 
 /****************************************************************************
- * Name: netlink_get_devlist
+ * Name: netlink_response_terminator
  *
  * Description:
  *   Dump a list of all network devices of the specified type.
  *
  ****************************************************************************/
 
-#ifndef CONFIG_NETLINK_DISABLE_GETLINK
-static int netlink_get_devlist(FAR struct socket *psock,
+static int netlink_response_terminator(FAR struct socket *psock,
                               FAR const struct nlroute_sendto_request_s *req)
 {
-  struct nlroute_info_s info;
-  FAR struct nlroute_msgdone_rsplist_s *alloc;
-  FAR struct nlmsghdr *resp;
-  int ret;
+  FAR struct netlink_response_s *resp;
+  FAR struct nlmsghdr *hdr;
 
-  /* Pre-allocate the list terminator */
+  /* Allocate the list terminator */
 
-  alloc = (FAR struct nlroute_msgdone_rsplist_s *)
-    kmm_zalloc(sizeof(struct nlroute_msgdone_rsplist_s));
-  if (alloc == NULL)
+  resp = kmm_zalloc(sizeof(struct netlink_response_s));
+  if (resp == NULL)
     {
       nerr("ERROR: Failed to allocate response terminator.\n");
       return -ENOMEM;
     }
 
+  /* Initialize and send the list terminator */
+
+  hdr              = &resp->msg;
+  hdr->nlmsg_len   = sizeof(struct nlmsghdr);
+  hdr->nlmsg_type  = NLMSG_DONE;
+  hdr->nlmsg_flags = req->hdr.nlmsg_flags;
+  hdr->nlmsg_seq   = req->hdr.nlmsg_seq;
+  hdr->nlmsg_pid   = req->hdr.nlmsg_pid;
+
+  /* Finally, add the response to the list of pending responses */
+
+  netlink_add_response(psock, resp);
+  return OK;
+}
+
+/****************************************************************************
+ * Name: netlink_get_devlist
+ *
+ * Description:
+ *   Dump a list of all network devices of the specified type.
+ *
+ ****************************************************************************/
+
+#ifndef CONFIG_NETLINK_DISABLE_GETLINK
+static int netlink_get_devlist(FAR struct socket *psock,
+                              FAR const struct nlroute_sendto_request_s *req)
+{
+  struct nlroute_info_s info;
+  int ret;
+
   /* Visit each device */
 
   info.psock = psock;
@@ -298,23 +316,10 @@ static int netlink_get_devlist(FAR struct socket *psock,
   net_unlock();
   if (ret < 0)
     {
-      kmm_free(alloc);
       return ret;
     }
 
-  /* Initialize and send the list terminator */
-
-  resp               = &alloc->payload;
-  resp->nlmsg_len    = sizeof(struct nlmsghdr);
-  resp->nlmsg_type   = NLMSG_DONE;
-  resp->nlmsg_flags  = req->hdr.nlmsg_flags;
-  resp->nlmsg_seq    = req->hdr.nlmsg_seq;
-  resp->nlmsg_pid    = req->hdr.nlmsg_pid;
-
-  /* Finally, add the data to the list of pending responses */
-
-  netlink_add_response(psock, (FAR struct netlink_response_s *)alloc);
-  return OK;
+  return netlink_response_terminator(psock, req);
 }
 #endif
 
@@ -485,48 +490,6 @@ static int netlink_get_nbtable(FAR struct socket *psock,
 #endif
 
 /****************************************************************************
- * Name: netlink_route_terminator
- *
- * Description:
- *   Dump a list of all network devices of the specified type.
- *
- ****************************************************************************/
-
-#ifndef CONFIG_NETLINK_DISABLE_GETROUTE
-static int
-netlink_route_terminator(FAR struct socket *psock,
-                         FAR const struct nlroute_sendto_request_s *req)
-{
-  FAR struct nlroute_msgdone_rsplist_s *alloc;
-  FAR struct nlmsghdr *resp;
-
-  /* Allocate the list terminator */
-
-  alloc = (FAR struct nlroute_msgdone_rsplist_s *)
-    kmm_zalloc(sizeof(struct nlroute_msgdone_rsplist_s));
-  if (alloc == NULL)
-    {
-      nerr("ERROR: Failed to allocate response terminator.\n");
-      return -ENOMEM;
-    }
-
-  /* Initialize and send the list terminator */
-
-  resp              = &alloc->payload;
-  resp->nlmsg_len   = sizeof(struct nlmsghdr);
-  resp->nlmsg_type  = NLMSG_DONE;
-  resp->nlmsg_flags = req->hdr.nlmsg_flags;
-  resp->nlmsg_seq   = req->hdr.nlmsg_seq;
-  resp->nlmsg_pid   = req->hdr.nlmsg_pid;
-
-  /* Finally, add the response to the list of pending responses */
-
-  netlink_add_response(psock, (FAR struct netlink_response_s *)alloc);
-  return OK;
-}
-#endif
-
-/****************************************************************************
  * Name: netlink_ipv4_route
  *
  * Description:
@@ -615,7 +578,7 @@ static int netlink_get_ipv4route(FAR struct socket *psock,
 
   /* Terminate the routing table */
 
-  return netlink_route_terminator(psock, req);
+  return netlink_response_terminator(psock, req);
 }
 #endif
 
@@ -708,7 +671,7 @@ static int netlink_get_ip6vroute(FAR struct socket *psock,
 
   /* Terminate the routing table */
 
-  return netlink_route_terminator(psock, req);
+  return netlink_response_terminator(psock, req);
 }
 #endif
 


[incubator-nuttx] 04/05: netlink: replace the operation handle to connection

Posted by xi...@apache.org.
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 755265506cf26288bf35b2d018de5caebdc9aa10
Author: chao.an <an...@xiaomi.com>
AuthorDate: Mon Apr 13 20:49:52 2020 +0800

    netlink: replace the operation handle to connection
    
    Change-Id: Ie55d65823fe7eb7e917349c095cf8fd4f6326e8f
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 net/netlink/netlink.h        |  8 ++---
 net/netlink/netlink_conn.c   | 30 ++++++------------
 net/netlink/netlink_route.c  | 74 +++++++++++++++++++++-----------------------
 net/netlink/netlink_sockif.c |  8 ++---
 4 files changed, 53 insertions(+), 67 deletions(-)

diff --git a/net/netlink/netlink.h b/net/netlink/netlink.h
index 9e04f0a..19381dc 100644
--- a/net/netlink/netlink.h
+++ b/net/netlink/netlink.h
@@ -227,7 +227,7 @@ void netlink_notifier_signal(FAR struct netlink_conn_s *conn);
  ****************************************************************************/
 
 FAR struct netlink_response_s *
-netlink_tryget_response(FAR struct socket *psock);
+netlink_tryget_response(FAR struct netlink_conn_s *conn);
 
 /****************************************************************************
  * Name: netlink_get_response
@@ -248,7 +248,7 @@ netlink_tryget_response(FAR struct socket *psock);
  ****************************************************************************/
 
 FAR struct netlink_response_s *
-netlink_get_response(FAR struct socket *psock);
+netlink_get_response(FAR struct netlink_conn_s *conn);
 
 /****************************************************************************
  * Name: netlink_check_response
@@ -261,7 +261,7 @@ netlink_get_response(FAR struct socket *psock);
  *
  ****************************************************************************/
 
-bool netlink_check_response(FAR struct socket *psock);
+bool netlink_check_response(FAR struct netlink_conn_s *conn);
 
 /****************************************************************************
  * Name: netlink_route_sendto()
@@ -272,7 +272,7 @@ bool netlink_check_response(FAR struct socket *psock);
  ****************************************************************************/
 
 #ifdef CONFIG_NETLINK_ROUTE
-ssize_t netlink_route_sendto(FAR struct socket *psock,
+ssize_t netlink_route_sendto(NETLINK_HANDLE handle,
                              FAR const struct nlmsghdr *nlmsg,
                              size_t len, int flags,
                              FAR const struct sockaddr_nl *to,
diff --git a/net/netlink/netlink_conn.c b/net/netlink/netlink_conn.c
index 331beec..fc25ad0 100644
--- a/net/netlink/netlink_conn.c
+++ b/net/netlink/netlink_conn.c
@@ -273,13 +273,10 @@ FAR struct netlink_conn_s *netlink_nextconn(FAR struct netlink_conn_s *conn)
 void netlink_add_response(NETLINK_HANDLE handle,
                           FAR struct netlink_response_s *resp)
 {
-  FAR struct socket *psock;
   FAR struct netlink_conn_s *conn;
 
-  psock = (FAR struct socket *)handle;
-  DEBUGASSERT(psock != NULL && psock->s_conn != NULL && resp != NULL);
-
-  conn = (FAR struct netlink_conn_s *)psock->s_conn;
+  conn = handle;
+  DEBUGASSERT(conn != NULL && resp != NULL);
 
   /* Add the response to the end of the FIFO list */
 
@@ -310,14 +307,11 @@ void netlink_add_response(NETLINK_HANDLE handle,
  ****************************************************************************/
 
 FAR struct netlink_response_s *
-netlink_tryget_response(FAR struct socket *psock)
+netlink_tryget_response(FAR struct netlink_conn_s *conn)
 {
   FAR struct netlink_response_s *resp;
-  FAR struct netlink_conn_s *conn;
 
-  DEBUGASSERT(psock != NULL && psock->s_conn != NULL);
-
-  conn = (FAR struct netlink_conn_s *)psock->s_conn;
+  DEBUGASSERT(conn != NULL);
 
   /* Return the response at the head of the pending response list (may be
    * NULL).
@@ -349,15 +343,12 @@ netlink_tryget_response(FAR struct socket *psock)
  ****************************************************************************/
 
 FAR struct netlink_response_s *
-netlink_get_response(FAR struct socket *psock)
+netlink_get_response(FAR struct netlink_conn_s *conn)
 {
   FAR struct netlink_response_s *resp;
-  FAR struct netlink_conn_s *conn;
   int ret;
 
-  DEBUGASSERT(psock != NULL && psock->s_conn != NULL);
-
-  conn = (FAR struct netlink_conn_s *)psock->s_conn;
+  DEBUGASSERT(conn != NULL);
 
   /* Loop, until a response is received.  A loop is used because in the case
    * of multiple waiters, all waiters will be awakened, but only the highest
@@ -365,7 +356,7 @@ netlink_get_response(FAR struct socket *psock)
    */
 
   net_lock();
-  while ((resp = netlink_tryget_response(psock)) == NULL)
+  while ((resp = netlink_tryget_response(conn)) == NULL)
     {
       sem_t waitsem;
 
@@ -419,12 +410,9 @@ netlink_get_response(FAR struct socket *psock)
  *
  ****************************************************************************/
 
-bool netlink_check_response(FAR struct socket *psock)
+bool netlink_check_response(FAR struct netlink_conn_s *conn)
 {
-  FAR struct netlink_conn_s *conn;
-
-  DEBUGASSERT(psock != NULL && psock->s_conn != NULL);
-  conn = (FAR struct netlink_conn_s *)psock->s_conn;
+  DEBUGASSERT(conn != NULL);
 
   /* Check if the response is available.  It is not necessary to lock the
    * network because the sq_peek() is an atomic operation.
diff --git a/net/netlink/netlink_route.c b/net/netlink/netlink_route.c
index 741b6ba..955e3da 100644
--- a/net/netlink/netlink_route.c
+++ b/net/netlink/netlink_route.c
@@ -175,7 +175,7 @@ struct nlroute_sendto_request_s
 
 struct nlroute_info_s
 {
-  FAR struct socket *psock;
+  NETLINK_HANDLE handle;
   FAR const struct nlroute_sendto_request_s *req;
 };
 
@@ -195,14 +195,12 @@ struct nlroute_info_s
 static int netlink_device_callback(FAR struct net_driver_s *dev,
                                    FAR void *arg)
 {
-  FAR struct nlroute_info_s *info;
   FAR struct getlink_recvfrom_rsplist_s *alloc;
   FAR struct getlink_recvfrom_response_s *resp;
+  FAR struct nlroute_info_s *info = arg;
 
   DEBUGASSERT(dev != NULL && arg != NULL);
-
-  info = (FAR struct nlroute_info_s *)arg;
-  DEBUGASSERT(info->psock != NULL && info->req != NULL);
+  DEBUGASSERT(info->handle != NULL && info->req != NULL);
 
   /* Check if the link is in the UP state */
 
@@ -248,8 +246,8 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
 
   /* Finally, add the data to the list of pending responses */
 
-  netlink_add_response(info->psock, (FAR struct netlink_response_s *)alloc);
-  return 0;
+  netlink_add_response(info->handle, (FAR struct netlink_response_s *)alloc);
+  return OK;
 }
 #endif
 
@@ -261,7 +259,7 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
  *
  ****************************************************************************/
 
-static int netlink_response_terminator(FAR struct socket *psock,
+static int netlink_response_terminator(NETLINK_HANDLE handle,
                               FAR const struct nlroute_sendto_request_s *req)
 {
   FAR struct netlink_response_s *resp;
@@ -287,7 +285,7 @@ static int netlink_response_terminator(FAR struct socket *psock,
 
   /* Finally, add the response to the list of pending responses */
 
-  netlink_add_response(psock, resp);
+  netlink_add_response(handle, resp);
   return OK;
 }
 
@@ -300,7 +298,7 @@ static int netlink_response_terminator(FAR struct socket *psock,
  ****************************************************************************/
 
 #ifndef CONFIG_NETLINK_DISABLE_GETLINK
-static int netlink_get_devlist(FAR struct socket *psock,
+static int netlink_get_devlist(NETLINK_HANDLE handle,
                               FAR const struct nlroute_sendto_request_s *req)
 {
   struct nlroute_info_s info;
@@ -308,8 +306,8 @@ static int netlink_get_devlist(FAR struct socket *psock,
 
   /* Visit each device */
 
-  info.psock = psock;
-  info.req   = req;
+  info.handle = handle;
+  info.req    = req;
 
   net_lock();
   ret = netdev_foreach(netlink_device_callback, &info);
@@ -319,7 +317,7 @@ static int netlink_get_devlist(FAR struct socket *psock,
       return ret;
     }
 
-  return netlink_response_terminator(psock, req);
+  return netlink_response_terminator(handle, req);
 }
 #endif
 
@@ -332,14 +330,14 @@ static int netlink_get_devlist(FAR struct socket *psock,
  ****************************************************************************/
 
 #if defined(CONFIG_NET_ARP) && !defined(CONFIG_NETLINK_DISABLE_GETNEIGH)
-static int netlink_get_arptable(FAR struct socket *psock,
+static int netlink_get_arptable(NETLINK_HANDLE handle,
                               FAR const struct nlroute_sendto_request_s *req)
 {
   FAR struct getneigh_recvfrom_rsplist_s *entry;
   unsigned int ncopied;
+  size_t allocsize;
   size_t tabsize;
   size_t rspsize;
-  size_t allocsize;
 
   /* Preallocate memory to hold the maximum sized ARP table
    * REVISIT:  This is probably excessively large and could cause false
@@ -400,7 +398,7 @@ static int netlink_get_arptable(FAR struct socket *psock,
 
   /* Finally, add the data to the list of pending responses */
 
-  netlink_add_response(psock, (FAR struct netlink_response_s *)entry);
+  netlink_add_response(handle, (FAR struct netlink_response_s *)entry);
   return OK;
 }
 #endif
@@ -414,14 +412,14 @@ static int netlink_get_arptable(FAR struct socket *psock,
  ****************************************************************************/
 
 #if defined(CONFIG_NET_IPv6) && !defined(CONFIG_NETLINK_DISABLE_GETNEIGH)
-static int netlink_get_nbtable(FAR struct socket *psock,
+static int netlink_get_nbtable(NETLINK_HANDLE handle,
                               FAR const struct nlroute_sendto_request_s *req)
 {
   FAR struct getneigh_recvfrom_rsplist_s *entry;
   unsigned int ncopied;
+  size_t allocsize;
   size_t tabsize;
   size_t rspsize;
-  size_t allocsize;
 
   /* Preallocate memory to hold the maximum sized Neighbor table
    * REVISIT:  This is probably excessively large and could cause false
@@ -484,7 +482,7 @@ static int netlink_get_nbtable(FAR struct socket *psock,
 
   /* Finally, add the response to the list of pending responses */
 
-  netlink_add_response(psock, (FAR struct netlink_response_s *)entry);
+  netlink_add_response(handle, (FAR struct netlink_response_s *)entry);
   return OK;
 }
 #endif
@@ -501,9 +499,9 @@ static int netlink_get_nbtable(FAR struct socket *psock,
 static int netlink_ipv4_route(FAR struct net_route_ipv4_s *route,
                               FAR void *arg)
 {
-  FAR struct nlroute_info_s *info;
   FAR struct getroute_recvfrom_ipv4resplist_s *alloc;
   FAR struct getroute_recvfrom_ipv4response_s *resp;
+  FAR struct nlroute_info_s *info;
 
   DEBUGASSERT(route != NULL && arg != NULL);
   info = (FAR struct nlroute_info_s *)arg;
@@ -545,7 +543,7 @@ static int netlink_ipv4_route(FAR struct net_route_ipv4_s *route,
 
   /* Finally, add the response to the list of pending responses */
 
-  netlink_add_response(info->psock, (FAR struct netlink_response_s *)alloc);
+  netlink_add_response(info->handle, (FAR struct netlink_response_s *)alloc);
   return OK;
 }
 #endif
@@ -559,7 +557,7 @@ static int netlink_ipv4_route(FAR struct net_route_ipv4_s *route,
  ****************************************************************************/
 
 #if defined(CONFIG_NET_IPv4) && !defined(CONFIG_NETLINK_DISABLE_GETROUTE)
-static int netlink_get_ipv4route(FAR struct socket *psock,
+static int netlink_get_ipv4route(NETLINK_HANDLE handle,
                               FAR const struct nlroute_sendto_request_s *req)
 {
   struct nlroute_info_s info;
@@ -567,8 +565,8 @@ static int netlink_get_ipv4route(FAR struct socket *psock,
 
   /* Visit each routing table entry */
 
-  info.psock = psock;
-  info.req   = req;
+  info.handle = handle;
+  info.req    = req;
 
   ret = net_foreachroute_ipv4(netlink_ipv4_route, &info);
   if (ret < 0)
@@ -578,7 +576,7 @@ static int netlink_get_ipv4route(FAR struct socket *psock,
 
   /* Terminate the routing table */
 
-  return netlink_response_terminator(psock, req);
+  return netlink_response_terminator(handle, req);
 }
 #endif
 
@@ -594,9 +592,9 @@ static int netlink_get_ipv4route(FAR struct socket *psock,
 static int netlink_ipv6_route(FAR struct net_route_ipv6_s *route,
                               FAR void *arg)
 {
-  FAR struct nlroute_info_s *info;
   FAR struct getroute_recvfrom_ipv6resplist_s *alloc;
   FAR struct getroute_recvfrom_ipv6response_s *resp;
+  FAR struct nlroute_info_s *info;
 
   DEBUGASSERT(route != NULL && arg != NULL);
   info = (FAR struct nlroute_info_s *)arg;
@@ -638,7 +636,7 @@ static int netlink_ipv6_route(FAR struct net_route_ipv6_s *route,
 
   /* Finally, add the response to the list of pending responses */
 
-  netlink_add_response(info->psock, (FAR struct netlink_response_s *)alloc);
+  netlink_add_response(info->handle, (FAR struct netlink_response_s *)alloc);
   return OK;
 }
 #endif
@@ -652,7 +650,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(FAR struct socket *psock,
+static int netlink_get_ip6vroute(NETLINK_HANDLE handle,
                               FAR const struct nlroute_sendto_request_s *req)
 {
   struct nlroute_info_s info;
@@ -660,8 +658,8 @@ static int netlink_get_ip6vroute(FAR struct socket *psock,
 
   /* Visit each routing table entry */
 
-  info.psock = psock;
-  info.req   = req;
+  info.handle = handle;
+  info.req    = req;
 
   ret = net_foreachroute_ipv6(netlink_ipv6_route, &info);
   if (ret < 0)
@@ -671,7 +669,7 @@ static int netlink_get_ip6vroute(FAR struct socket *psock,
 
   /* Terminate the routing table */
 
-  return netlink_response_terminator(psock, req);
+  return netlink_response_terminator(handle, req);
 }
 #endif
 
@@ -687,7 +685,7 @@ static int netlink_get_ip6vroute(FAR struct socket *psock,
  *
  ****************************************************************************/
 
-ssize_t netlink_route_sendto(FAR struct socket *psock,
+ssize_t netlink_route_sendto(NETLINK_HANDLE handle,
                              FAR const struct nlmsghdr *nlmsg,
                              size_t len, int flags,
                              FAR const struct sockaddr_nl *to,
@@ -697,7 +695,7 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
     (FAR const struct nlroute_sendto_request_s *)nlmsg;
   int ret;
 
-  DEBUGASSERT(psock != NULL && nlmsg != NULL &&
+  DEBUGASSERT(handle != NULL && nlmsg != NULL &&
               nlmsg->nlmsg_len >= sizeof(struct nlmsghdr) &&
               len >= sizeof(struct nlmsghdr) &&
               len >= nlmsg->nlmsg_len && to != NULL &&
@@ -714,7 +712,7 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
 
         /* Generate the response */
 
-        ret = netlink_get_devlist(psock, req);
+        ret = netlink_get_devlist(handle, req);
         break;
 #endif
 
@@ -727,7 +725,7 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
 
         if (req->gen.rtgen_family == AF_INET)
           {
-            ret = netlink_get_arptable(psock, req);
+            ret = netlink_get_arptable(handle, req);
           }
         else
 #endif
@@ -737,7 +735,7 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
 
         if (req->gen.rtgen_family == AF_INET6)
           {
-             ret = netlink_get_nbtable(psock, req);
+             ret = netlink_get_nbtable(handle, req);
           }
         else
 #endif
@@ -754,14 +752,14 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
 #ifdef CONFIG_NET_IPv4
         if (req->gen.rtgen_family == AF_INET)
           {
-            ret = netlink_get_ipv4route(psock, req);
+            ret = netlink_get_ipv4route(handle, req);
           }
         else
 #endif
 #ifdef CONFIG_NET_IPv6
         if (req->gen.rtgen_family == AF_INET6)
           {
-            ret = netlink_get_ip6vroute(psock, req);
+            ret = netlink_get_ip6vroute(handle, req);
           }
         else
 #endif
diff --git a/net/netlink/netlink_sockif.c b/net/netlink/netlink_sockif.c
index 9295901..577d520 100644
--- a/net/netlink/netlink_sockif.c
+++ b/net/netlink/netlink_sockif.c
@@ -605,7 +605,7 @@ static int netlink_poll(FAR struct socket *psock, FAR struct pollfd *fds,
        */
 
       net_lock();
-      if (netlink_check_response(psock))
+      if (netlink_check_response(conn))
         {
           revents |= POLLIN;
         }
@@ -761,7 +761,7 @@ static ssize_t netlink_sendto(FAR struct socket *psock, FAR const void *buf,
     {
 #ifdef CONFIG_NETLINK_ROUTE
       case NETLINK_ROUTE:
-        ret = netlink_route_sendto(psock, nlmsg, len, flags,
+        ret = netlink_route_sendto(conn, nlmsg, len, flags,
                                    (FAR struct sockaddr_nl *)to,
                                    tolen);
         break;
@@ -810,7 +810,7 @@ static ssize_t netlink_recvfrom(FAR struct socket *psock, FAR void *buf,
 
   /* Find the response to this message.  The return value */
 
-  entry = (FAR struct netlink_response_s *)netlink_tryget_response(psock);
+  entry = netlink_tryget_response(psock->s_conn);
   if (entry == NULL)
     {
       /* No response is variable, but presumably, one is expected.  Check
@@ -824,7 +824,7 @@ static ssize_t netlink_recvfrom(FAR struct socket *psock, FAR void *buf,
 
       /* Wait for the response.  This should always succeed. */
 
-      entry = (FAR struct netlink_response_s *)netlink_get_response(psock);
+      entry = netlink_get_response(psock->s_conn);
       DEBUGASSERT(entry != NULL);
       if (entry == NULL)
         {


[incubator-nuttx] 01/05: netlink/route: remove domain check

Posted by xi...@apache.org.
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 85dce03d22cc91cd49577cc0f1449e36ce2a7226
Author: chao.an <an...@xiaomi.com>
AuthorDate: Mon Apr 13 15:32:13 2020 +0800

    netlink/route: remove domain check
    
    Change-Id: I965788c3bd2e6bfa41048b87d8c26f111f61c48e
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 net/netlink/netlink_route.c | 116 --------------------------------------------
 1 file changed, 116 deletions(-)

diff --git a/net/netlink/netlink_route.c b/net/netlink/netlink_route.c
index f42b95d..6f356d7 100644
--- a/net/netlink/netlink_route.c
+++ b/net/netlink/netlink_route.c
@@ -221,122 +221,6 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
       return 0;
     }
 
-  /* Filter only the requested address families */
-
-  switch (info->req->gen.rtgen_family)
-    {
-#ifdef CONFIG_NET_LOCAL
-      case AF_LOCAL:
-        /* Should have info->psock->s_domain == PF_LOCAL and d_lltype ==
-         * NET_LL_LOOPBACK.
-         */
-
-        if (info->psock->s_domain == PF_LOCAL)
-          {
-            DEBUGASSERT(dev->d_lltype == NET_LL_LOOPBACK);
-            break;
-          }
-        else
-          {
-            return 0;
-          }
-#endif
-
-#ifdef CONFIG_NET_IPv4
-        /* Should have info->psock->s_domain == PF_INET but d_lltype could be
-         * several things.
-         */
-
-      case AF_INET:
-
-        if (info->psock->s_domain == PF_INET)
-          {
-            break;
-          }
-        else
-          {
-            return 0;
-          }
-#endif
-
-#ifdef CONFIG_NET_IPv6
-        /* Should have info->psock->s_domain == PF_INET6 but d_lltype could
-         * be several things.
-         */
-
-      case AF_INET6:
-
-        if (info->psock->s_domain == PF_INET6)
-          {
-            break;
-          }
-        else
-          {
-            return 0;
-          }
-#endif
-
-#ifdef CONFIG_NET_BLUETOOTH
-        /* Should have info->psock->s_domain == PF_PACKET and d_lltype should
-         * be NET_LL_BLUETOOTH.
-         */
-
-      case AF_BLUETOOTH:
-        if (info->psock->s_domain == PF_PACKET)
-          {
-            DEBUGASSERT(dev->d_lltype == NET_LL_BLUETOOTH);
-            break;
-          }
-        else
-          {
-            return 0;
-          }
-#endif
-
-#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154)
-      /* psock_domain could be PF_PACKET or PF_INET6 but d_lltype should
-       * be AF_IEEE802154.
-       */
-
-      case AF_IEEE802154:
-        if (dev->d_lltype == NET_LL_IEEE802154)
-          {
-            DEBUGASSERT(info->psock->s_domain == PF_PACKET ||
-                        info->psock->s_domain == PF_INET6);
-            break;
-          }
-        else
-          {
-            return 0;
-          }
-#endif
-
-#ifdef CONFIG_NET_6LOWPAN
-      /* psock_domain should be PF_INET6 and d_lltype should be
-       * NET_LL_PKTRADIO.
-       */
-
-        if (dev->d_lltype == NET_LL_PKTRADIO)
-          {
-            DEBUGASSERT(info->psock->s_domain == PF_INET6);
-            break;
-          }
-        else
-          {
-            return 0;
-          }
-#endif
-
-      case AF_PACKET:     /* Take all address families */
-        break;
-
-      case AF_UNSPEC:
-      case AF_PKTRADIO:
-      default:
-        nerr("ERROR: Unsupported address family: %u\n", info->req->gen);
-        return 0;
-    }
-
   /* Allocate the response buffer */
 
   alloc = (FAR struct getlink_recvfrom_rsplist_s *)


[incubator-nuttx] 03/05: netlink: add netlink multicast group define

Posted by xi...@apache.org.
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 bd4bccbe2738e04ad4b153300c23f1a7182862d4
Author: chao.an <an...@xiaomi.com>
AuthorDate: Mon Apr 13 16:04:13 2020 +0800

    netlink: add netlink multicast group define
    
    Change-Id: I0cedbee311f83320ba396a1004e12075e835cccf
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 include/netpacket/netlink.h | 55 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/include/netpacket/netlink.h b/include/netpacket/netlink.h
index 336414c..f0afa9f 100644
--- a/include/netpacket/netlink.h
+++ b/include/netpacket/netlink.h
@@ -361,6 +361,61 @@
 #define  RT_SCOPE_HOST        254  /* Route on local host */
 #define  RT_SCOPE_NOWHERE     255  /* Destination does not exist */
 
+/* RTnetlink multicast groups (userspace) */
+
+#define RTMGRP_LINK           1
+#define RTMGRP_NOTIFY         2
+#define RTMGRP_NEIGH          4
+#define RTMGRP_TC             8
+
+#define RTMGRP_IPV4_IFADDR    0x10
+#define RTMGRP_IPV4_MROUTE    0x20
+#define RTMGRP_IPV4_ROUTE     0x40
+#define RTMGRP_IPV4_RULE      0x80
+
+#define RTMGRP_IPV6_IFADDR    0x100
+#define RTMGRP_IPV6_MROUTE    0x200
+#define RTMGRP_IPV6_ROUTE     0x400
+#define RTMGRP_IPV6_IFINFO    0x800
+
+#define RTMGRP_DECnet_IFADDR  0x1000
+#define RTMGRP_DECnet_ROUTE   0x4000
+
+#define RTMGRP_IPV6_PREFIX    0x20000
+
+/* RTnetlink multicast groups */
+
+#define RTNLGRP_NONE          0
+#define RTNLGRP_LINK          1
+#define RTNLGRP_NOTIFY        2
+#define RTNLGRP_NEIGH         3
+#define RTNLGRP_TC            4
+#define RTNLGRP_IPV4_IFADDR   5
+#define RTNLGRP_IPV4_MROUTE   6
+#define RTNLGRP_IPV4_ROUTE    7
+#define RTNLGRP_IPV4_RULE     8
+#define RTNLGRP_IPV6_IFADDR   9
+#define RTNLGRP_IPV6_MROUTE   10
+#define RTNLGRP_IPV6_ROUTE    11
+#define RTNLGRP_IPV6_IFINFO   12
+#define RTNLGRP_DECnet_IFADDR 13
+#define RTNLGRP_NOP2          14
+#define RTNLGRP_DECnet_ROUTE  15
+#define RTNLGRP_DECnet_RULE   16
+#define RTNLGRP_NOP4          17
+#define RTNLGRP_IPV6_PREFIX   18
+#define RTNLGRP_IPV6_RULE     19
+#define RTNLGRP_ND_USEROPT    20
+#define RTNLGRP_PHONET_IFADDR 21
+#define RTNLGRP_PHONET_ROUTE  22
+#define RTNLGRP_DCB           23
+#define RTNLGRP_IPV4_NETCONF  24
+#define RTNLGRP_IPV6_NETCONF  25
+#define RTNLGRP_MDB           26
+#define RTNLGRP_MPLS_ROUTE    27
+#define RTNLGRP_NSID          28
+#define RTNLGRP_MAX           29
+
 /****************************************************************************
  * Public Type Definitions
  ****************************************************************************/


[incubator-nuttx] 05/05: netlink: Add netlink_add_broadcast function

Posted by xi...@apache.org.
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: