You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/04/10 14:18:17 UTC

[incubator-nuttx] branch master updated (ef36039 -> 581dbb2)

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

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


    from ef36039  mm/mm_heap: fix mm_heap not support BUILD_FLAT
     new 9fb6eee  netlink: Remove the unused netlink_active
     new 3421ec9  netlink: Shouldn't call netlink_notify_response in netlink_poll
     new e6c3062  netlink: Return -EBUSY if some notifier was setup in netlink_notifier_setup
     new 5708015  netlink: Sync the macro with Linux definition
     new 16dbe37  netlink: Implement netlink_connect and netlink_getpeername
     new 70012bc  netlink: Remove netlink_route_recvfrom
     new 369a0fa  netlink: all request to NETLINK_ROUTE should use rtgenmsg
     new 581dbb2  netlink: Fix nxstyle issue

The 8 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    | 153 ++++++-----
 include/nuttx/net/netlink.h    |   6 +-
 net/netlink/Make.defs          |   2 +-
 net/netlink/netlink.h          |  76 +-----
 net/netlink/netlink_conn.c     | 101 +------
 net/netlink/netlink_notifier.c |   7 +-
 net/netlink/netlink_route.c    | 585 +++++++++++------------------------------
 net/netlink/netlink_sockif.c   | 224 ++++++++--------
 8 files changed, 372 insertions(+), 782 deletions(-)


[incubator-nuttx] 03/08: netlink: Return -EBUSY if some notifier was setup in netlink_notifier_setup

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e6c30629a1ef9f0f09894678a055b4b9444fb0f2
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Apr 8 01:52:32 2020 +0800

    netlink: Return -EBUSY if some notifier was setup in netlink_notifier_setup
    
    Change-Id: I62d036bb43420934efbf0e9b990ca2cf3dd0b2e5
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 net/netlink/netlink_notifier.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/netlink/netlink_notifier.c b/net/netlink/netlink_notifier.c
index c9f37db..e48c7ce 100644
--- a/net/netlink/netlink_notifier.c
+++ b/net/netlink/netlink_notifier.c
@@ -79,6 +79,11 @@ int netlink_notifier_setup(worker_t worker, FAR struct netlink_conn_s *conn,
 
   DEBUGASSERT(worker != NULL && conn != NULL);
 
+  if (conn->key > 0)
+    {
+      return -EBUSY;
+    }
+
   /* This is just a simple wrapper around work_notifer_setup(). */
 
   info.evtype    = WORK_NETLINK_RESPONSE;
@@ -88,7 +93,7 @@ int netlink_notifier_setup(worker_t worker, FAR struct netlink_conn_s *conn,
   info.worker    = worker;
 
   conn->key      =  work_notifier_setup(&info);
-  return OK;
+  return conn->key;
 }
 
 /****************************************************************************


[incubator-nuttx] 01/08: netlink: Remove the unused netlink_active

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9fb6eee5feae7cfe68a5ae043261ab1a5347c7f7
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Apr 8 01:44:23 2020 +0800

    netlink: Remove the unused netlink_active
    
    Change-Id: I976b3fbab033baa4eaec35f8f443d4eb971db142
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 net/netlink/Make.defs        |  2 +-
 net/netlink/netlink.h        | 36 +++---------------------------------
 net/netlink/netlink_conn.c   | 32 +++++---------------------------
 net/netlink/netlink_sockif.c |  6 +++---
 4 files changed, 12 insertions(+), 64 deletions(-)

diff --git a/net/netlink/Make.defs b/net/netlink/Make.defs
index 5e1a58a..ce5aa9a 100644
--- a/net/netlink/Make.defs
+++ b/net/netlink/Make.defs
@@ -33,7 +33,7 @@
 #
 ############################################################################
 
-# Logic specific to IPv6 Neighbor Discovery Protocol
+# Logic specific to NETLINK
 
 ifeq ($(CONFIG_NET_NETLINK),y)
 
diff --git a/net/netlink/netlink.h b/net/netlink/netlink.h
index f7012c1..e1e7c7d 100644
--- a/net/netlink/netlink.h
+++ b/net/netlink/netlink.h
@@ -56,12 +56,6 @@
 #ifdef CONFIG_NET_NETLINK
 
 /****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define NETLINK_NO_WAITER ((pid_t)-1)
-
-/****************************************************************************
  * Public Type Definitions
  ****************************************************************************/
 
@@ -73,13 +67,6 @@ struct netlink_conn_s
 
   dq_entry_t node;                   /* Supports a doubly linked list */
 
-  /* This is a list of NetLink connection callbacks.  Each callback
-   * represents a thread that is stalled, waiting for a device-specific
-   * event.
-   */
-
-  FAR struct devif_callback_s *list; /* NetLink callbacks */
-
   /* NetLink-specific content follows */
 
   uint32_t pid;                      /* Port ID (if bound) */
@@ -95,7 +82,7 @@ struct netlink_conn_s
 
   /* Queued response data */
 
-  sq_queue_t resplist;               /* Singly linked list of responses*/
+  sq_queue_t resplist;               /* Singly linked list of responses */
 };
 
 /****************************************************************************
@@ -113,12 +100,6 @@ extern "C"
 EXTERN const struct sock_intf_s g_netlink_sockif;
 
 /****************************************************************************
- * Public Function Prototypes
- ****************************************************************************/
-
-struct sockaddr_nl;  /* Forward reference */
-
-/****************************************************************************
  * Name: netlink_initialize()
  *
  * Description:
@@ -165,17 +146,6 @@ void netlink_free(FAR struct netlink_conn_s *conn);
 FAR struct netlink_conn_s *netlink_nextconn(FAR struct netlink_conn_s *conn);
 
 /****************************************************************************
- * Name: netlink_active()
- *
- * Description:
- *   Find a connection structure that is the appropriate connection for the
- *   provided NetLink address
- *
- ****************************************************************************/
-
-FAR struct netlink_conn_s *netlink_active(FAR struct sockaddr_nl *addr);
-
-/****************************************************************************
  * Name: netlink_notifier_setup
  *
  * Description:
@@ -255,7 +225,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 socket *psock);
 
 /****************************************************************************
  * Name: netlink_get_response
@@ -276,7 +246,7 @@ FAR struct netlink_response_s *
  ****************************************************************************/
 
 FAR struct netlink_response_s *
-  netlink_get_response(FAR struct socket *psock);
+netlink_get_response(FAR struct socket *psock);
 
 /****************************************************************************
  * Name: netlink_check_response
diff --git a/net/netlink/netlink_conn.c b/net/netlink/netlink_conn.c
index 8935d0e..f72876a 100644
--- a/net/netlink/netlink_conn.c
+++ b/net/netlink/netlink_conn.c
@@ -129,7 +129,7 @@ static void netlink_response_available(FAR void *arg)
  * Name: netlink_initialize()
  *
  * Description:
- *   Initialize the User Socket connection structures.  Called once and only
+ *   Initialize the NetLink connection structures.  Called once and only
  *   from the networking layer.
  *
  ****************************************************************************/
@@ -251,27 +251,6 @@ FAR struct netlink_conn_s *netlink_nextconn(FAR struct netlink_conn_s *conn)
 }
 
 /****************************************************************************
- * Name: netlink_active
- *
- * Description:
- *   Find a connection structure that is the appropriate connection for the
- *   provided NetLink address
- *
- * Assumptions:
- *
- ****************************************************************************/
-
-FAR struct netlink_conn_s *netlink_active(FAR struct sockaddr_nl *addr)
-{
-  /* This function is used to handle routing of incoming messages to sockets
-   * connected to the address.  There is no such use case for NetLink
-   * sockets.
-   */
-
-  return NULL;
-}
-
-/****************************************************************************
  * Name: netlink_add_response
  *
  * Description:
@@ -330,7 +309,7 @@ void netlink_add_response(NETLINK_HANDLE handle,
  ****************************************************************************/
 
 FAR struct netlink_response_s *
-  netlink_tryget_response(FAR struct socket *psock)
+netlink_tryget_response(FAR struct socket *psock)
 {
   FAR struct netlink_response_s *resp;
   FAR struct netlink_conn_s *conn;
@@ -369,7 +348,7 @@ FAR struct netlink_response_s *
  ****************************************************************************/
 
 FAR struct netlink_response_s *
-  netlink_get_response(FAR struct socket *psock)
+netlink_get_response(FAR struct socket *psock)
 {
   FAR struct netlink_response_s *resp;
   FAR struct netlink_conn_s *conn;
@@ -391,8 +370,8 @@ FAR struct netlink_response_s *
 
       /* Set up a semaphore to notify us when a response is queued. */
 
-      (void)sem_init(&waitsem, 0, 0);
-      (void)nxsem_setprotocol(&waitsem, SEM_PRIO_NONE);
+      sem_init(&waitsem, 0, 0);
+      nxsem_setprotocol(&waitsem, SEM_PRIO_NONE);
 
       /* Set up a notifier to post the semaphore when a response is
        * received.
@@ -420,7 +399,6 @@ FAR struct netlink_response_s *
 
       if (ret < 0)
         {
-          resp = NULL;
           break;
         }
     }
diff --git a/net/netlink/netlink_sockif.c b/net/netlink/netlink_sockif.c
index cff507a..3b8e498 100644
--- a/net/netlink/netlink_sockif.c
+++ b/net/netlink/netlink_sockif.c
@@ -118,7 +118,7 @@ const struct sock_intf_s g_netlink_sockif =
  ****************************************************************************/
 
 /****************************************************************************
- * Name: inet_setup
+ * Name: netlink_setup
  *
  * Description:
  *   Called for socket() to verify that the provided socket type and
@@ -458,7 +458,7 @@ static int netlink_connect(FAR struct socket *psock,
  *   actual length of the address returned.
  *
  *   If no pending connections are present on the queue, and the socket is
- *   not marked as non-blocking, inet_accept blocks the caller until a
+ *   not marked as non-blocking, accept blocks the caller until a
  *   connection is present. If the socket is marked non-blocking and no
  *   pending connections are present on the queue, inet_accept returns
  *   EAGAIN.
@@ -518,7 +518,7 @@ static void netlink_response_available(FAR void *arg)
       /* Wake up the poll() with POLLIN */
 
        *conn->pollevent |= POLLIN;
-       (void)nxsem_post(conn->pollsem);
+       nxsem_post(conn->pollsem);
     }
   else
     {


[incubator-nuttx] 05/08: netlink: Implement netlink_connect and netlink_getpeername

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 16dbe373c0f5120023310334b4e7ed1a9ec682d8
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Apr 8 02:31:57 2020 +0800

    netlink: Implement netlink_connect and netlink_getpeername
    
    and refine netlink_bind and netlink_send implmentation
    
    Change-Id: I2b3e7980eac01dc42927cfaa0a64874df52d6bf5
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 net/netlink/netlink.h        |   2 +
 net/netlink/netlink_sockif.c | 107 +++++++++++++++++++++++--------------------
 2 files changed, 60 insertions(+), 49 deletions(-)

diff --git a/net/netlink/netlink.h b/net/netlink/netlink.h
index ff745b5..f1f204c 100644
--- a/net/netlink/netlink.h
+++ b/net/netlink/netlink.h
@@ -71,6 +71,8 @@ struct netlink_conn_s
 
   uint32_t pid;                      /* Port ID (if bound) */
   uint32_t groups;                   /* Multicast groups mask (if bound) */
+  uint32_t dst_pid;                  /* Destination port ID */
+  uint32_t dst_groups;               /* Destination multicast groups mask */
   uint8_t crefs;                     /* Reference counts on this instance */
   uint8_t protocol;                  /* See NETLINK_* definitions */
 
diff --git a/net/netlink/netlink_sockif.c b/net/netlink/netlink_sockif.c
index 45fc04e..63c9bd5 100644
--- a/net/netlink/netlink_sockif.c
+++ b/net/netlink/netlink_sockif.c
@@ -281,11 +281,11 @@ static int netlink_bind(FAR struct socket *psock,
 
   /* Save the address information in the connection structure */
 
-  nladdr          = (FAR struct sockaddr_nl *)addr;
-  conn            = (FAR struct netlink_conn_s *)psock->s_conn;
+  nladdr = (FAR struct sockaddr_nl *)addr;
+  conn   = (FAR struct netlink_conn_s *)psock->s_conn;
 
-  conn->pid       = nladdr->nl_pid;
-  conn->groups    = nladdr->nl_groups;
+  conn->pid    = nladdr->nl_pid ? nladdr->nl_pid : getpid();
+  conn->groups = nladdr->nl_groups;
 
   return OK;
 }
@@ -317,25 +317,21 @@ static int netlink_getsockname(FAR struct socket *psock,
                                FAR socklen_t *addrlen)
 {
   FAR struct sockaddr_nl *nladdr;
+  FAR struct netlink_conn_s *conn;
 
   DEBUGASSERT(psock != NULL && psock->s_conn != NULL && addr != NULL &&
               addrlen != NULL && *addrlen >= sizeof(struct sockaddr_nl));
 
+  conn = (FAR struct netlink_conn_s *)psock->s_conn;
+
   /* Return the address information in the address structure */
 
   nladdr = (FAR struct sockaddr_nl *)addr;
   memset(nladdr, 0, sizeof(struct sockaddr_nl));
 
-  nladdr->nl_family     = AF_NETLINK;
-
-  if (_SS_ISBOUND(psock->s_flags))
-    {
-      FAR struct netlink_conn_s *conn;
-
-      conn              = (FAR struct netlink_conn_s *)psock->s_conn;
-      nladdr->nl_pid    = conn->pid;
-      nladdr->nl_groups = conn->groups;
-    }
+  nladdr->nl_family = AF_NETLINK;
+  nladdr->nl_pid    = conn->pid;
+  nladdr->nl_groups = conn->groups;
 
   *addrlen = sizeof(struct sockaddr_nl);
   return OK;
@@ -373,8 +369,25 @@ static int netlink_getpeername(FAR struct socket *psock,
                                FAR struct sockaddr *addr,
                                FAR socklen_t *addrlen)
 {
-#warning Missing logic for NETLINK getsockname
-  return -EOPNOTSUPP;  /* Or maybe return -EAFNOSUPPORT; */
+  FAR struct sockaddr_nl *nladdr;
+  FAR struct netlink_conn_s *conn;
+
+  DEBUGASSERT(psock != NULL && psock->s_conn != NULL && addr != NULL &&
+              addrlen != NULL && *addrlen >= sizeof(struct sockaddr_nl));
+
+  conn = (FAR struct netlink_conn_s *)psock->s_conn;
+
+  /* Return the address information in the address structure */
+
+  nladdr = (FAR struct sockaddr_nl *)addr;
+  memset(nladdr, 0, sizeof(struct sockaddr_nl));
+
+  nladdr->nl_family = AF_NETLINK;
+  nladdr->nl_pid    = conn->dst_pid;
+  nladdr->nl_groups = conn->dst_groups;
+
+  *addrlen = sizeof(struct sockaddr_nl);
+  return OK;
 }
 
 /****************************************************************************
@@ -405,7 +418,6 @@ static int netlink_getpeername(FAR struct socket *psock,
 
 static int netlink_listen(FAR struct socket *psock, int backlog)
 {
-#warning Missing logic for NETLINK listen
   return -EOPNOTSUPP;
 }
 
@@ -431,8 +443,21 @@ static int netlink_connect(FAR struct socket *psock,
                            FAR const struct sockaddr *addr,
                            socklen_t addrlen)
 {
-#warning Missing logic for NETLINK connect
-  return -EOPNOTSUPP;
+  FAR struct sockaddr_nl *nladdr;
+  FAR struct netlink_conn_s *conn;
+
+  DEBUGASSERT(psock != NULL && psock->s_conn != NULL && addr != NULL &&
+              addrlen >= sizeof(struct sockaddr_nl));
+
+  /* Save the address information in the connection structure */
+
+  nladdr = (FAR struct sockaddr_nl *)addr;
+  conn   = (FAR struct netlink_conn_s *)psock->s_conn;
+
+  conn->dst_pid    = nladdr->nl_pid;
+  conn->dst_groups = nladdr->nl_groups;
+
+  return OK;
 }
 
 /****************************************************************************
@@ -482,7 +507,6 @@ static int netlink_connect(FAR struct socket *psock,
 static int netlink_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
                           FAR socklen_t *addrlen, FAR struct socket *newsock)
 {
-#warning Missing logic for NETLINK accept
   return -EOPNOTSUPP;
 }
 
@@ -665,38 +689,27 @@ static int netlink_poll(FAR struct socket *psock, FAR struct pollfd *fds,
 static ssize_t netlink_send(FAR struct socket *psock, FAR const void *buf,
                             size_t len, int flags)
 {
-  DEBUGASSERT(psock != NULL && psock->s_conn != NULL && buf != NULL);
-
-  /* The socket must be connected in order to use send */
-
-  if (_SS_ISBOUND(psock->s_flags))
-    {
-      FAR struct netlink_conn_s *conn;
-      struct sockaddr_nl nladdr;
-
-      /* Get the underlying connection structure */
+  FAR struct netlink_conn_s *conn;
+  struct sockaddr_nl nladdr;
 
-      conn             = (FAR struct netlink_conn_s *)psock->s_conn;
+  DEBUGASSERT(psock != NULL && psock->s_conn != NULL && buf != NULL);
 
-      /* Format the address */
+  /* Get the underlying connection structure */
 
-      nladdr.nl_family = AF_NETLINK;
-      nladdr.nl_pad    = 0;
-      nladdr.nl_pid    = conn->pid;
-      nladdr.nl_groups = conn->groups;
+  conn = (FAR struct netlink_conn_s *)psock->s_conn;
 
-      /* Then let sendto() perform the actual send operation */
+  /* Format the address */
 
-      return netlink_sendto(psock, buf, len, flags,
-                            (FAR const struct sockaddr *)&nladdr,
-                            sizeof(struct sockaddr_nl));
-    }
+  nladdr.nl_family = AF_NETLINK;
+  nladdr.nl_pad    = 0;
+  nladdr.nl_pid    = conn->dst_pid;
+  nladdr.nl_groups = conn->dst_groups;
 
-  /* EDESTADDRREQ.  Signifies that the socket is not connection-mode and no
-   * peer address is set.
-   */
+  /* Then let sendto() perform the actual send operation */
 
-  return -EDESTADDRREQ;
+  return netlink_sendto(psock, buf, len, flags,
+                        (FAR const struct sockaddr *)&nladdr,
+                        sizeof(struct sockaddr_nl));
 }
 
 /****************************************************************************
@@ -851,10 +864,6 @@ static int netlink_close(FAR struct socket *psock)
 
   if (conn->crefs <= 1)
     {
-      /* Yes... inform user-space daemon of socket close. */
-
-#warning Missing logic in NETLINK close()
-
       /* Free the connection structure */
 
       conn->crefs = 0;


[incubator-nuttx] 04/08: netlink: Sync the macro with Linux definition

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 570801567429d6496bbdcb1e31c0862d84fe147a
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Apr 8 02:01:03 2020 +0800

    netlink: Sync the macro with Linux definition
    
    Change-Id: I0c0895fa17e167c67fb12acfdfc6dc3a7fb63b3b
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 include/netpacket/netlink.h | 153 +++++++++++++++++++++++---------------------
 include/nuttx/net/netlink.h |   2 +-
 net/netlink/netlink_route.c |  16 +----
 3 files changed, 82 insertions(+), 89 deletions(-)

diff --git a/include/netpacket/netlink.h b/include/netpacket/netlink.h
index 940c69a..336414c 100644
--- a/include/netpacket/netlink.h
+++ b/include/netpacket/netlink.h
@@ -65,30 +65,32 @@
 
 #define NETLINK_ROUTE          0       /* Routing/device hook for user-space
                                         * routing daemons (default) */
-#define NETLINK_USERSOCK       1       /* Reserved for user mode socket protocols */
-#define NETLINK_FIREWALL       2       /* Interface to receive packets from
+#define NETLINK_UNUSED         1       /* Unused number */
+#define NETLINK_USERSOCK       2       /* Reserved for user mode socket protocols */
+#define NETLINK_FIREWALL       3       /* Interface to receive packets from
                                         * the firewall */
-#define NETLINK_SOCK_DIAG      3       /* Socket monitoring */
-#define NETLINK_NFLOG          4       /* netfilter/iptables ULOG */
-#define NETLINK_XFRM           5       /* Interface to IPsec security databases
+#define NETLINK_SOCK_DIAG      4       /* Socket monitoring */
+#define NETLINK_NFLOG          5       /* netfilter/iptables ULOG */
+#define NETLINK_XFRM           6       /* Interface to IPsec security databases
                                         * for key-manager daemons using the
                                         * Internet Key Exchange protocol. */
-#define NETLINK_ISCSI          6       /* Open-iSCSI */
-#define NETLINK_AUDIT          7       /* Interface to auditing sub-system */
-#define NETLINK_FIB_LOOKUP     8
-#define NETLINK_CONNECTOR      9
-#define NETLINK_NETFILTER      10      /* netfilter subsystem */
-#define NETLINK_IP6_FW         11      /* Interface to transport packets from
+#define NETLINK_SELINUX        7       /* SELinux event notifications */
+#define NETLINK_ISCSI          8       /* Open-iSCSI */
+#define NETLINK_AUDIT          9       /* Interface to auditing sub-system */
+#define NETLINK_FIB_LOOKUP     10
+#define NETLINK_CONNECTOR      11
+#define NETLINK_NETFILTER      12      /* netfilter subsystem */
+#define NETLINK_IP6_FW         13      /* Interface to transport packets from
                                         * netfilter to user-space. */
-#define NETLINK_DNRTMSG        12      /* DECnet routing messages */
-#define NETLINK_KOBJECT_UEVENT 13      /* Kernel messages to userspace */
-#define NETLINK_GENERIC        14
+#define NETLINK_DNRTMSG        14      /* DECnet routing messages */
+#define NETLINK_KOBJECT_UEVENT 15      /* Kernel messages to userspace */
+#define NETLINK_GENERIC        16
                                        /* NETLINK_DM (DM Events) */
-#define NETLINK_SCSITRANSPORT  16      /* SCSI Transports */
-#define NETLINK_ECRYPTFS       17
-#define NETLINK_RDMA           18
-#define NETLINK_CRYPTO         19      /* Crypto layer */
-#define NETLINK_SMC            20      /* SMC monitoring */
+#define NETLINK_SCSITRANSPORT  18      /* SCSI Transports */
+#define NETLINK_ECRYPTFS       19
+#define NETLINK_RDMA           20
+#define NETLINK_CRYPTO         21      /* Crypto layer */
+#define NETLINK_SMC            22      /* SMC monitoring */
 
 /* Definitions associated with struct sockaddr_nl ***************************/
 
@@ -131,16 +133,17 @@
 #define NLMSG_HDRLEN          sizeof(struct nlmsghdr)
 #define NLMSG_LENGTH(n)       (NLMSG_HDRLEN + (n))
 #define NLMSG_SPACE(len)      NLMSG_ALIGN(NLMSG_LENGTH(len))
-#define NLMSG_DATA(hdr)       ((FAR void*)(((FAR char*)hdr) + NLMSG_HDRLEN))
-#define NLMSG_NEXT(hdr,n) \
+#define NLMSG_DATA(hdr)       ((FAR void *)(((FAR char *)hdr) + NLMSG_HDRLEN))
+#define NLMSG_NEXT(hdr, n) \
   ((n) -= NLMSG_ALIGN((hdr)->nlmsg_len), \
-   (FAR struct nlmsghdr*) \
-   (((FAR char*)(hdr)) + NLMSG_ALIGN((hdr)->nlmsg_len)))
-#define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
+   (FAR struct nlmsghdr *) \
+   (((FAR char *)(hdr)) + NLMSG_ALIGN((hdr)->nlmsg_len)))
+#define NLMSG_OK(nlh, len) \
+  ((len) >= (int)sizeof(struct nlmsghdr) && \
     (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
     (nlh)->nlmsg_len <= (len))
 #define NLMSG_PAYLOAD(hdr, len) \
-  ((hdr)->nlmsg_len - NLMSG_SPACE((len)))
+  ((hdr)->nlmsg_len - NLMSG_SPACE(len))
 
 #define NLMSG_NOOP            1    /* Nothing */
 #define NLMSG_ERROR           2    /* Error */
@@ -154,14 +157,14 @@
 
 #define RTA_MASK              (sizeof(uint32_t) - 1)
 #define RTA_ALIGN(n)          (((n) + RTA_MASK) & ~RTA_MASK)
-#define RTA_OK(rta,n) \
+#define RTA_OK(rta, n) \
   ((n) >= (int)sizeof(struct rtattr) && \
    (rta)->rta_len >= sizeof(struct rtattr) && \
    (rta)->rta_len <= (n))
 #define RTA_NEXT(rta, attrlen) \
   ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
-   (FAR struct rtattr*)(((FAR char*)(rta)) + RTA_ALIGN((rta)->rta_len)))
-#define RTA_LENGTH(n)         (RTA_ALIGN(sizeof(struct rtattr)) + (n))
+   (FAR struct rtattr *)(((FAR char *)(rta)) + RTA_ALIGN((rta)->rta_len)))
+#define RTA_LENGTH(n)         (sizeof(struct rtattr) + (n))
 #define RTA_SPACE(n)          RTA_ALIGN(RTA_LENGTH(n))
 #define RTA_DATA(rta)         ((FAR void *)(((FAR char *)(rta)) + RTA_LENGTH(0)))
 #define RTA_PAYLOAD(rta)      ((int)((rta)->rta_len) - RTA_LENGTH(0))
@@ -173,8 +176,8 @@
 #define RTA_SRC               2    /* Argument:  Route source address */
 #define RTA_IIF               3    /* Argument:  Input interface index */
 #define RTA_OIF               4    /* Argument:  Output interface index */
-#define RTA_GENMASK           5    /* Argument:  Network address mask of sub-net */
-#define RTA_GATEWAY           6    /* Argument:  Gateway address of the route */
+#define RTA_GATEWAY           5    /* Argument:  Gateway address of the route */
+#define RTA_GENMASK           6    /* Argument:  Network address mask of sub-net */
 
 /* NETLINK_ROUTE protocol message types *************************************/
 
@@ -186,10 +189,10 @@
  *   of rtattr structures.
  */
 
-#define RTM_NEWLINK           0
-#define RTM_DELLINK           1
-#define RTM_GETLINK           2
-#define RTM_SETLINK           3
+#define RTM_NEWLINK           16
+#define RTM_DELLINK           17
+#define RTM_GETLINK           18
+#define RTM_SETLINK           19
 
 /* Address settings:
  *
@@ -199,9 +202,9 @@
  *   followed by rtattr routing attributes.
  */
 
-#define RTM_NEWADDR           4
-#define RTM_DELADDR           5
-#define RTM_GETADDR           6
+#define RTM_NEWADDR           20
+#define RTM_DELADDR           21
+#define RTM_GETADDR           22
 
 /* Routing tables:
  *
@@ -215,9 +218,9 @@
  *   except rtm_table and rtm_protocol, 0 is the wildcard.
  */
 
-#define RTM_NEWROUTE         7
-#define RTM_DELROUTE         8
-#define RTM_GETROUTE         9
+#define RTM_NEWROUTE         24
+#define RTM_DELROUTE         25
+#define RTM_GETROUTE         26
 
 /* Neighbor cache:
  *
@@ -226,9 +229,9 @@
  *   an ARP entry).  The message contains an ndmsg structure.
  */
 
-#define RTM_NEWNEIGH         10
-#define RTM_DELNEIGH         11
-#define RTM_GETNEIGH         12
+#define RTM_NEWNEIGH         28
+#define RTM_DELNEIGH         29
+#define RTM_GETNEIGH         30
 
 /* Routing rules:
  *
@@ -236,9 +239,9 @@
  *   Add, delete or retrieve a routing rule.  Carries a struct rtmsg
  */
 
-#define RTM_NEWRULE          13
-#define RTM_DELRULE          14
-#define RTM_GETRULE          15
+#define RTM_NEWRULE          32
+#define RTM_DELRULE          33
+#define RTM_GETRULE          34
 
 /* Queuing discipline settings:
  *
@@ -247,9 +250,9 @@
  *   struct tcmsg and may be followed by a series of attributes.
  */
 
-#define RTM_NEWQDISC         16
-#define RTM_DELQDISC         17
-#define RTM_GETQDISC         18
+#define RTM_NEWQDISC         36
+#define RTM_DELQDISC         37
+#define RTM_GETQDISC         38
 
 /* Traffic classes used with queues:
  *
@@ -258,9 +261,9 @@
  *   tcmsg as described above.
  */
 
-#define RTM_NEWTCLASS        19
-#define RTM_DELTCLASS        20
-#define RTM_GETTCLASS        21
+#define RTM_NEWTCLASS        40
+#define RTM_DELTCLASS        41
+#define RTM_GETTCLASS        42
 
 /* Traffic filters:
  *
@@ -269,35 +272,39 @@
  *   messages contain a struct tcmsg as described above.
  */
 
-#define RTM_NEWTFILTER       22
-#define RTM_DELTFILTER       23
-#define RTM_GETTFILTER       24
+#define RTM_NEWTFILTER       44
+#define RTM_DELTFILTER       45
+#define RTM_GETTFILTER       46
 
 /* Others: */
 
-#define RTM_NEWACTION        25
-#define RTM_DELACTION        26
-#define RTM_GETACTION        27
-#define RTM_NEWPREFIX        28
-#define RTM_GETPREFIX        29
-#define RTM_GETMULTICAST     30
-#define RTM_GETANYCAST       31
-#define RTM_NEWNEIGHTBL      32
-#define RTM_GETNEIGHTBL      33
-#define RTM_SETNEIGHTBL      34
+#define RTM_NEWACTION        48
+#define RTM_DELACTION        49
+#define RTM_GETACTION        50
+#define RTM_NEWPREFIX        52
+#define RTM_GETMULTICAST     58
+#define RTM_GETANYCAST       62
+#define RTM_NEWNEIGHTBL      64
+#define RTM_GETNEIGHTBL      66
+#define RTM_SETNEIGHTBL      67
 
-#define RTM_FIRSTMSG          0
-#define RTM_LASTMSG          34
+#define RTM_BASE             16
+#define RTM_MAX              67
 
 /* Definitions for struct ifaddrmsg  ****************************************/
 
+#define IFA_RTA(r)          ((FAR struct rtattr *) \
+                             (((FAR char *)(r)) + \
+                              NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
+#define IFA_PAYLOAD(n)      NLMSG_PAYLOAD(n, sizeof(struct ifaddrmsg))
+
 /* ifa_flags definitions:  ifa_flags is a flag word of IFA_F_SECONDARY for
  * secondary address (old alias interface), IFA_F_PERMANENT for a permanent
  * address set by the user and other undocumented flags.
  */
 
 #define IFA_F_SECONDARY      0x01
-#define IFA_F_PERMANENT      0x02
+#define IFA_F_PERMANENT      0x80
 
 /* Definitions for struct ifinfomsg *****************************************/
 
@@ -342,8 +349,8 @@
 #define RTPROT_KERNEL         2    /* Route installed by kernel */
 #define RTPROT_BOOT           3    /* Route installed during boot */
 #define RTPROT_STATIC         4    /* Route installed by administrator */
-#define RTPROT_RA             5    /* RDISC/ND router advertisements */
-#define RTPROT_DHCP           6    /* DHCP client */
+#define RTPROT_RA             9    /* RDISC/ND router advertisements */
+#define RTPROT_DHCP           16   /* DHCP client */
 
 /* rtm_scope */
 
@@ -407,9 +414,9 @@ struct rtattr
 struct ifinfomsg
 {
   uint8_t  ifi_family;    /* AF_UNSPEC */
-  uint8_t  ifi_pid;
+  uint8_t  ifi_pad;
   uint16_t ifi_type;      /* Device type (ARPHRD) */
-  int16_t  ifi_index;     /* Unique interface index */
+  int32_t  ifi_index;     /* Unique interface index */
   uint32_t ifi_flags;     /* Device IFF_* flags  */
   uint32_t ifi_change;    /* Change mask, must always be 0xffffffff */
 };
@@ -434,7 +441,7 @@ struct ifaddrmsg
   uint8_t  ifa_prefixlen; /* Prefix length of address */
   uint8_t  ifa_flags;     /* Address flags.  See IFA_F_* definitions */
   uint8_t  ifa_scope;     /* Address scope */
-  int16_t  ifa_index;     /* Unique interface index */
+  int32_t  ifa_index;     /* Unique interface index */
 };
 
 /* RTM_NEWNEIGH, RTM_DELNEIGH, RTM_GETNEIGH
diff --git a/include/nuttx/net/netlink.h b/include/nuttx/net/netlink.h
index cbf9910..cf1655b 100644
--- a/include/nuttx/net/netlink.h
+++ b/include/nuttx/net/netlink.h
@@ -77,7 +77,7 @@ struct netlink_response_s
   /* Message-specific data may follow */
 };
 
-#define SIZEOF_NETLINK_RESPONSE_S(n) (sizeof(struct netlink_response_s) + (n) - 1)
+#define SIZEOF_NETLINK_RESPONSE_S(n) (sizeof(struct netlink_response_s) + (n))
 
 /****************************************************************************
  * Public Function Prototypes
diff --git a/net/netlink/netlink_route.c b/net/netlink/netlink_route.c
index 68b3ec0..6c51ea7 100644
--- a/net/netlink/netlink_route.c
+++ b/net/netlink/netlink_route.c
@@ -79,20 +79,6 @@
 #  define CONFIG_NETLINK_DISABLE_GETROUTE 1
 #endif
 
-#undef NETLINK_DISABLE_NLMSGDONE
-#if defined(CONFIG_NETLINK_DISABLE_GETLINK) && \
-    defined(CONFIG_NETLINK_DISABLE_GETROUTE)
-#  define NETLINK_DISABLE_NLMSGDONE 1
-#endif
-
-/* Helpers ******************************************************************/
-
-#define IFA_RTA(r)  \
-  ((FAR struct rtattr *)(((FAR char *)(r)) + \
-   NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
-#define IFA_PAYLOAD(n) \
-  NLMSG_PAYLOAD(n, sizeof(struct ifaddrmsg))
-
 /****************************************************************************
  * Private Types
  ****************************************************************************/
@@ -416,7 +402,7 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
   resp->hdr.nlmsg_pid    = devinfo->req->hdr.nlmsg_pid;
 
   resp->iface.ifi_family = devinfo->req->gen.rtgen_family;
-  resp->iface.ifi_pid    = devinfo->req->hdr.nlmsg_pid;
+  resp->iface.ifi_pad    = 0;
   resp->iface.ifi_type   = devinfo->req->hdr.nlmsg_type;
 #ifdef CONFIG_NETDEV_IFINDEX
   resp->iface.ifi_index  = dev->d_ifindex;


[incubator-nuttx] 02/08: netlink: Shouldn't call netlink_notify_response in netlink_poll

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3421ec90b4c0aaae4831f97567d2e1efd9a277ba
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Apr 8 01:50:01 2020 +0800

    netlink: Shouldn't call netlink_notify_response in netlink_poll
    
    to avoid sleep inside netlink_poll
    
    Change-Id: Id801c2dae805455a9b91f2e091d001679f0b3d4b
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 net/netlink/netlink.h        | 17 ------------
 net/netlink/netlink_conn.c   | 62 --------------------------------------------
 net/netlink/netlink_sockif.c | 40 +---------------------------
 3 files changed, 1 insertion(+), 118 deletions(-)

diff --git a/net/netlink/netlink.h b/net/netlink/netlink.h
index e1e7c7d..ff745b5 100644
--- a/net/netlink/netlink.h
+++ b/net/netlink/netlink.h
@@ -262,23 +262,6 @@ netlink_get_response(FAR struct socket *psock);
 bool netlink_check_response(FAR struct socket *psock);
 
 /****************************************************************************
- * Name: netlink_notify_response
- *
- * Description:
- *   Notify a thread when a response is available.  The thread will be
- *   notified via work queue notifier when the response becomes available.
- *
- * Returned Value:
- *   Zero (OK) is returned if the response is already available.  No
- *     notification will be sent.
- *   One is returned if the notification was successfully setup.
- *   A negated errno value is returned on any failure.
- *
- ****************************************************************************/
-
-int netlink_notify_response(FAR struct socket *psock);
-
-/****************************************************************************
  * Name: netlink_route_sendto()
  *
  * Description:
diff --git a/net/netlink/netlink_conn.c b/net/netlink/netlink_conn.c
index f72876a..cbd18c5 100644
--- a/net/netlink/netlink_conn.c
+++ b/net/netlink/netlink_conn.c
@@ -432,66 +432,4 @@ bool netlink_check_response(FAR struct socket *psock)
   return (sq_peek(&conn->resplist) != NULL);
 }
 
-/****************************************************************************
- * Name: netlink_notify_response
- *
- * Description:
- *   Notify a thread when a response is available.  The thread will be
- *   notified via work queue notifier when the response becomes available.
- *
- * Returned Value:
- *   Zero (OK) is returned if the response is already available.  No
- *     notification will be sent.
- *   One is returned if the notification was successfully setup.
- *   A negated errno value is returned on any failure.
- *
- ****************************************************************************/
-
-int netlink_notify_response(FAR struct socket *psock)
-{
-  FAR struct netlink_conn_s *conn;
-  int ret = 0;
-
-  DEBUGASSERT(psock != NULL && psock->s_conn != NULL);
-  conn = (FAR struct netlink_conn_s *)psock->s_conn;
-
-  /* Check if the response is available */
-
-  net_lock();
-  if (((FAR struct netlink_response_s *)sq_peek(&conn->resplist)) == NULL)
-    {
-      sem_t waitsem;
-
-      /* No.. Set up a semaphore to notify us when a response is queued. */
-
-      (void)sem_init(&waitsem, 0, 0);
-      (void)nxsem_setprotocol(&waitsem, SEM_PRIO_NONE);
-
-      /* Set up a notifier to post the semaphore when a response is
-       * received.
-       */
-
-      ret = netlink_notifier_setup(netlink_response_available, conn,
-                                   &waitsem);
-      if (ret < 0)
-        {
-          nerr("ERROR: netlink_notifier_setup() failed: %d\n", ret);
-        }
-      else
-        {
-          /* Wait for a response to be queued */
-
-          _netlink_semtake(&waitsem);
-        }
-
-      /* Tear-down the notifier and the semaphore */
-
-      netlink_notifier_teardown(conn);
-      sem_destroy(&waitsem);
-    }
-
-  net_unlock();
-  return ret < 0 ? ret : OK;
-}
-
 #endif /* CONFIG_NET_NETLINK */
diff --git a/net/netlink/netlink_sockif.c b/net/netlink/netlink_sockif.c
index 3b8e498..45fc04e 100644
--- a/net/netlink/netlink_sockif.c
+++ b/net/netlink/netlink_sockif.c
@@ -561,7 +561,7 @@ static int netlink_poll(FAR struct socket *psock, FAR struct pollfd *fds,
                         bool setup)
 {
   FAR struct netlink_conn_s *conn;
-  int ret;
+  int ret = OK;
 
   DEBUGASSERT(psock != NULL && psock->s_conn != NULL);
   conn = (FAR struct netlink_conn_s *)psock->s_conn;
@@ -626,44 +626,6 @@ static int netlink_poll(FAR struct socket *psock, FAR struct pollfd *fds,
               conn->pollsem   = NULL;
               conn->pollevent = NULL;
             }
-          else
-            {
-              /* Call netlink_notify_response() to receive a notification
-               * when a response has been queued.
-               */
-
-              ret = netlink_notify_response(psock);
-              if (ret < 0)
-                {
-                  nerr("ERROR: netlink_notify_response() failed: %d\n", ret);
-                  netlink_notifier_teardown(conn);
-                  conn->pollsem   = NULL;
-                  conn->pollevent = NULL;
-                }
-              else if (ret == 0)
-                {
-                  /* The return value of zero means that a response is
-                   * already available and that no notification is
-                   * forthcoming.
-                   */
-
-                  netlink_notifier_teardown(conn);
-                  conn->pollsem   = NULL;
-                  conn->pollevent = NULL;
-                  fds->revents    = POLLIN;
-                  nxsem_post(fds->sem);
-                }
-              else
-                {
-                  ret = OK;
-                }
-            }
-        }
-      else
-        {
-          /* There will not be any wakeups coming?  Probably an error? */
-
-          ret = OK;
         }
 
       net_unlock();


[incubator-nuttx] 08/08: netlink: Fix nxstyle issue

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 581dbb22fe5da600a1cc0e74c9ae9c4c3deaa72e
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Apr 10 21:03:34 2020 +0800

    netlink: Fix nxstyle issue
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 include/nuttx/net/netlink.h  |  4 +--
 net/netlink/netlink.h        |  6 ++--
 net/netlink/netlink_conn.c   |  7 ++--
 net/netlink/netlink_route.c  | 78 +++++++++++++++++++++++---------------------
 net/netlink/netlink_sockif.c | 17 ++++++----
 5 files changed, 59 insertions(+), 53 deletions(-)

diff --git a/include/nuttx/net/netlink.h b/include/nuttx/net/netlink.h
index cf1655b..04f9eaa 100644
--- a/include/nuttx/net/netlink.h
+++ b/include/nuttx/net/netlink.h
@@ -54,8 +54,8 @@
  * Public Types
  ****************************************************************************/
 
-/* This is the form of the obfuscated state structure passed to modules outside of the
- * networking layer.
+/* This is the form of the obfuscated state structure passed to modules
+ * outside of the networking layer.
  */
 
 typedef FAR void *NETLINK_HANDLE;
diff --git a/net/netlink/netlink.h b/net/netlink/netlink.h
index fc58cf8..9e04f0a 100644
--- a/net/netlink/netlink.h
+++ b/net/netlink/netlink.h
@@ -59,7 +59,7 @@
  * Public Type Definitions
  ****************************************************************************/
 
-/* This "connection" structure describes the underlying state of the socket. */
+/* This connection structure describes the underlying state of the socket. */
 
 struct netlink_conn_s
 {
@@ -127,8 +127,8 @@ FAR struct netlink_conn_s *netlink_alloc(void);
  * Name: netlink_free()
  *
  * Description:
- *   Free a NetLink connection structure that is no longer in use. This should
- *   be done by the implementation of close().
+ *   Free a NetLink connection structure that is no longer in use. This
+ *   should be done by the implementation of close().
  *
  ****************************************************************************/
 
diff --git a/net/netlink/netlink_conn.c b/net/netlink/netlink_conn.c
index cbd18c5..331beec 100644
--- a/net/netlink/netlink_conn.c
+++ b/net/netlink/netlink_conn.c
@@ -171,7 +171,8 @@ FAR struct netlink_conn_s *netlink_alloc(void)
   /* The free list is protected by a semaphore (that behaves like a mutex). */
 
   _netlink_semtake(&g_free_sem);
-  conn = (FAR struct netlink_conn_s *)dq_remfirst(&g_free_netlink_connections);
+  conn = (FAR struct netlink_conn_s *)
+           dq_remfirst(&g_free_netlink_connections);
   if (conn != NULL)
     {
       /* Make sure that the connection is marked as uninitialized */
@@ -191,8 +192,8 @@ FAR struct netlink_conn_s *netlink_alloc(void)
  * Name: netlink_free()
  *
  * Description:
- *   Free a NetLink connection structure that is no longer in use. This should
- *   be done by the implementation of close().
+ *   Free a NetLink connection structure that is no longer in use. This
+ *   should be done by the implementation of close().
  *
  ****************************************************************************/
 
diff --git a/net/netlink/netlink_route.c b/net/netlink/netlink_route.c
index 46fd844..f42b95d 100644
--- a/net/netlink/netlink_route.c
+++ b/net/netlink/netlink_route.c
@@ -260,8 +260,8 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
 #endif
 
 #ifdef CONFIG_NET_IPv6
-        /* Should have info->psock->s_domain == PF_INET6 but d_lltype could be
-         * several things.
+        /* Should have info->psock->s_domain == PF_INET6 but d_lltype could
+         * be several things.
          */
 
       case AF_INET6:
@@ -277,8 +277,8 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
 #endif
 
 #ifdef CONFIG_NET_BLUETOOTH
-        /* Should have info->psock->s_domain == PF_PACKET and d_lltype should be
-         * NET_LL_BLUETOOTH.
+        /* Should have info->psock->s_domain == PF_PACKET and d_lltype should
+         * be NET_LL_BLUETOOTH.
          */
 
       case AF_BLUETOOTH:
@@ -387,7 +387,7 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
 
 #ifndef CONFIG_NETLINK_DISABLE_GETLINK
 static int netlink_get_devlist(FAR struct socket *psock,
-                               FAR const struct nlroute_sendto_request_s *req)
+                              FAR const struct nlroute_sendto_request_s *req)
 {
   struct nlroute_info_s info;
   FAR struct nlroute_msgdone_rsplist_s *alloc;
@@ -444,7 +444,7 @@ 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,
-                                FAR const struct nlroute_sendto_request_s *req)
+                              FAR const struct nlroute_sendto_request_s *req)
 {
   FAR struct getneigh_recvfrom_rsplist_s *entry;
   unsigned int ncopied;
@@ -462,7 +462,7 @@ static int netlink_get_arptable(FAR struct socket *psock,
   rspsize   = SIZEOF_NLROUTE_RECVFROM_RESPONSE_S(tabsize);
   allocsize = SIZEOF_NLROUTE_RECVFROM_RSPLIST_S(tabsize);
 
-  entry     = (FAR struct getneigh_recvfrom_rsplist_s *)kmm_zalloc(allocsize);
+  entry = (FAR struct getneigh_recvfrom_rsplist_s *)kmm_zalloc(allocsize);
   if (entry == NULL)
     {
       nerr("ERROR: Failed to allocate response buffer.\n");
@@ -526,7 +526,7 @@ 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,
-                               FAR const struct nlroute_sendto_request_s *req)
+                              FAR const struct nlroute_sendto_request_s *req)
 {
   FAR struct getneigh_recvfrom_rsplist_s *entry;
   unsigned int ncopied;
@@ -545,7 +545,7 @@ static int netlink_get_nbtable(FAR struct socket *psock,
   rspsize   = SIZEOF_NLROUTE_RECVFROM_RESPONSE_S(tabsize);
   allocsize = SIZEOF_NLROUTE_RECVFROM_RSPLIST_S(tabsize);
 
-  entry     = (FAR struct getneigh_recvfrom_rsplist_s *)kmm_zalloc(allocsize);
+  entry = (FAR struct getneigh_recvfrom_rsplist_s *)kmm_zalloc(allocsize);
   if (entry == NULL)
     {
       nerr("ERROR: Failed to allocate response buffer.\n");
@@ -564,8 +564,9 @@ static int netlink_get_nbtable(FAR struct socket *psock,
    */
 
   net_lock();
-  ncopied = neighbor_snapshot((FAR struct neighbor_entry_s *)entry->payload.data,
-                              CONFIG_NET_IPv6_NCONF_ENTRIES);
+  ncopied = neighbor_snapshot(
+    (FAR struct neighbor_entry_s *)entry->payload.data,
+    CONFIG_NET_IPv6_NCONF_ENTRIES);
   net_unlock();
 
   /* Now we have the real number of valid entries in the Neighbor table
@@ -671,21 +672,21 @@ static int netlink_ipv4_route(FAR struct net_route_ipv4_s *route,
 
   /* Format the response */
 
-  resp                        = &alloc->payload;
-  resp->hdr.nlmsg_len         = sizeof(struct getroute_recvfrom_ipv4response_s);
-  resp->hdr.nlmsg_type        = RTM_NEWROUTE;
-  resp->hdr.nlmsg_flags       = info->req->hdr.nlmsg_flags;
-  resp->hdr.nlmsg_seq         = info->req->hdr.nlmsg_seq;
-  resp->hdr.nlmsg_pid         = info->req->hdr.nlmsg_pid;
+  resp                  = &alloc->payload;
+  resp->hdr.nlmsg_len   = sizeof(struct getroute_recvfrom_ipv4response_s);
+  resp->hdr.nlmsg_type  = RTM_NEWROUTE;
+  resp->hdr.nlmsg_flags = info->req->hdr.nlmsg_flags;
+  resp->hdr.nlmsg_seq   = info->req->hdr.nlmsg_seq;
+  resp->hdr.nlmsg_pid   = info->req->hdr.nlmsg_pid;
 
-  resp->rte.rtm_family        = info->req->gen.rtgen_family;
-  resp->rte.rtm_table         = RT_TABLE_MAIN;
-  resp->rte.rtm_protocol      = RTPROT_STATIC;
-  resp->rte.rtm_scope         = RT_SCOPE_SITE;
+  resp->rte.rtm_family   = info->req->gen.rtgen_family;
+  resp->rte.rtm_table    = RT_TABLE_MAIN;
+  resp->rte.rtm_protocol = RTPROT_STATIC;
+  resp->rte.rtm_scope    = RT_SCOPE_SITE;
 
-  resp->dst.attr.rta_len      = RTA_LENGTH(sizeof(in_addr_t));
-  resp->dst.attr.rta_type     = RTA_DST;
-  resp->dst.addr              = route->target;
+  resp->dst.attr.rta_len  = RTA_LENGTH(sizeof(in_addr_t));
+  resp->dst.attr.rta_type = RTA_DST;
+  resp->dst.addr          = route->target;
 
   resp->genmask.attr.rta_len  = RTA_LENGTH(sizeof(in_addr_t));
   resp->genmask.attr.rta_type = RTA_GENMASK;
@@ -712,7 +713,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,
-                                 FAR const struct nlroute_sendto_request_s *req)
+                              FAR const struct nlroute_sendto_request_s *req)
 {
   struct nlroute_info_s info;
   int ret;
@@ -764,20 +765,20 @@ static int netlink_ipv6_route(FAR struct net_route_ipv6_s *route,
 
   /* Format the response */
 
-  resp                        = &alloc->payload;
-  resp->hdr.nlmsg_len         = sizeof(struct getroute_recvfrom_ipv6response_s);
-  resp->hdr.nlmsg_type        = RTM_NEWROUTE;
-  resp->hdr.nlmsg_flags       = info->req->hdr.nlmsg_flags;
-  resp->hdr.nlmsg_seq         = info->req->hdr.nlmsg_seq;
-  resp->hdr.nlmsg_pid         = info->req->hdr.nlmsg_pid;
+  resp                  = &alloc->payload;
+  resp->hdr.nlmsg_len   = sizeof(struct getroute_recvfrom_ipv6response_s);
+  resp->hdr.nlmsg_type  = RTM_NEWROUTE;
+  resp->hdr.nlmsg_flags = info->req->hdr.nlmsg_flags;
+  resp->hdr.nlmsg_seq   = info->req->hdr.nlmsg_seq;
+  resp->hdr.nlmsg_pid   = info->req->hdr.nlmsg_pid;
 
-  resp->rte.rtm_family        = info->req->gen.rtgen_family;
-  resp->rte.rtm_table         = RT_TABLE_MAIN;
-  resp->rte.rtm_protocol      = RTPROT_STATIC;
-  resp->rte.rtm_scope         = RT_SCOPE_SITE;
+  resp->rte.rtm_family   = info->req->gen.rtgen_family;
+  resp->rte.rtm_table    = RT_TABLE_MAIN;
+  resp->rte.rtm_protocol = RTPROT_STATIC;
+  resp->rte.rtm_scope    = RT_SCOPE_SITE;
 
-  resp->dst.attr.rta_len      = RTA_LENGTH(sizeof(net_ipv6addr_t));
-  resp->dst.attr.rta_type     = RTA_DST;
+  resp->dst.attr.rta_len  = RTA_LENGTH(sizeof(net_ipv6addr_t));
+  resp->dst.attr.rta_type = RTA_DST;
   net_ipv6addr_copy(resp->dst.addr, route->target);
 
   resp->genmask.attr.rta_len  = RTA_LENGTH(sizeof(net_ipv6addr_t));
@@ -805,7 +806,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,
-                                 FAR const struct nlroute_sendto_request_s *req)
+                              FAR const struct nlroute_sendto_request_s *req)
 {
   struct nlroute_info_s info;
   int ret;
@@ -863,6 +864,7 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
       /* Dump a list of all devices */
 
       case RTM_GETLINK:
+
         /* Generate the response */
 
         ret = netlink_get_devlist(psock, req);
diff --git a/net/netlink/netlink_sockif.c b/net/netlink/netlink_sockif.c
index 8d981c4..9295901 100644
--- a/net/netlink/netlink_sockif.c
+++ b/net/netlink/netlink_sockif.c
@@ -74,8 +74,9 @@ static int  netlink_getpeername(FAR struct socket *psock,
 static int  netlink_listen(FAR struct socket *psock, int backlog);
 static int  netlink_connect(FAR struct socket *psock,
               FAR const struct sockaddr *addr, socklen_t addrlen);
-static int  netlink_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
-              FAR socklen_t *addrlen, FAR struct socket *newsock);
+static int  netlink_accept(FAR struct socket *psock,
+              FAR struct sockaddr *addr, FAR socklen_t *addrlen,
+              FAR struct socket *newsock);
 static int  netlink_poll(FAR struct socket *psock, FAR struct pollfd *fds,
               bool setup);
 static ssize_t netlink_send(FAR struct socket *psock,
@@ -428,7 +429,7 @@ static int netlink_listen(FAR struct socket *psock, int backlog)
  *   Perform a netlink connection
  *
  * Input Parameters:
- *   psock   A reference to the socket structure of the socket to be connected
+ *   psock   A reference to the structure of the socket to be connected
  *   addr    The address of the remote server to connect to
  *   addrlen Length of address buffer
  *
@@ -504,8 +505,9 @@ static int netlink_connect(FAR struct socket *psock,
  *
  ****************************************************************************/
 
-static int netlink_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
-                          FAR socklen_t *addrlen, FAR struct socket *newsock)
+static int netlink_accept(FAR struct socket *psock,
+                          FAR struct sockaddr *addr, FAR socklen_t *addrlen,
+                          FAR struct socket *newsock)
 {
   return -EOPNOTSUPP;
 }
@@ -643,7 +645,8 @@ static int netlink_poll(FAR struct socket *psock, FAR struct pollfd *fds,
           conn->pollsem    = fds->sem;
           conn->pollevent  = &fds->revents;
 
-          ret = netlink_notifier_setup(netlink_response_available, conn, conn);
+          ret = netlink_notifier_setup(netlink_response_available,
+                                       conn, conn);
           if (ret < 0)
             {
               nerr("ERROR: netlink_notifier_setup() failed: %d\n", ret);
@@ -722,7 +725,7 @@ static ssize_t netlink_send(FAR struct socket *psock, FAR const void *buf,
  *   returned when the socket was not actually connected.
  *
  * Input Parameters:
- *   psock    A reference to the socket structure of the socket to be connected
+ *   psock    A reference to the structure of the socket to be connected
  *   buf      Data to send
  *   len      Length of data to send
  *   flags    Send flags (ignored)


[incubator-nuttx] 06/08: netlink: Remove netlink_route_recvfrom

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 70012bc4a276fd2e2e5c1eedf53d9da9fe19887b
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Apr 8 18:30:28 2020 +0800

    netlink: Remove netlink_route_recvfrom
    
    The same functionality could be implemented in the common place(netlink_recvfrom)
    
    Change-Id: I8aedb29c4f0572f020ca5c0775f06c5e1e17ae4a
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 net/netlink/netlink.h        |  15 ----
 net/netlink/netlink_route.c  | 175 -------------------------------------------
 net/netlink/netlink_sockif.c |  54 +++++++------
 3 files changed, 33 insertions(+), 211 deletions(-)

diff --git a/net/netlink/netlink.h b/net/netlink/netlink.h
index f1f204c..fc58cf8 100644
--- a/net/netlink/netlink.h
+++ b/net/netlink/netlink.h
@@ -279,21 +279,6 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
                              socklen_t tolen);
 #endif
 
-/****************************************************************************
- * Name: netlink_route_recvfrom()
- *
- * Description:
- *   Perform the recvfrom() operation for the NETLINK_ROUTE protocol.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_NETLINK_ROUTE
-ssize_t netlink_route_recvfrom(FAR struct socket *psock,
-                               FAR struct nlmsghdr *nlmsg,
-                               size_t len, int flags,
-                               FAR struct sockaddr_nl *from);
-#endif
-
 #undef EXTERN
 #ifdef __cplusplus
 }
diff --git a/net/netlink/netlink_route.c b/net/netlink/netlink_route.c
index 6c51ea7..e5873e7 100644
--- a/net/netlink/netlink_route.c
+++ b/net/netlink/netlink_route.c
@@ -1015,179 +1015,4 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
   return ret;
 }
 
-/****************************************************************************
- * Name: netlink_route_recvfrom()
- *
- * Description:
- *   Perform the recvfrom() operation for the NETLINK_ROUTE protocol.
- *
- ****************************************************************************/
-
-ssize_t netlink_route_recvfrom(FAR struct socket *psock,
-                               FAR struct nlmsghdr *nlmsg,
-                               size_t len, int flags,
-                               FAR struct sockaddr_nl *from)
-{
-  FAR struct netlink_response_s *entry;
-  ssize_t ret;
-
-  DEBUGASSERT(psock != NULL && nlmsg != NULL &&
-              len >= sizeof(struct nlmsghdr));
-
-  /* Find the response to this message.  The return value */
-
-  entry = (FAR struct netlink_response_s *)netlink_tryget_response(psock);
-  if (entry == NULL)
-    {
-      /* No response is variable, but presumably, one is expected.  Check
-       * if the socket has been configured for non-blocking operation.
-       * REVISIT:  I think there needs to be some higher level logic to
-       * select Netlink non-blocking sockets.
-       */
-
-      if (_SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0)
-        {
-          return -EAGAIN;
-        }
-
-      /* Wait for the response.  This should always succeed. */
-
-      entry = (FAR struct netlink_response_s *)netlink_get_response(psock);
-      DEBUGASSERT(entry != NULL);
-      if (entry == NULL)
-        {
-          return -EPIPE;
-        }
-    }
-
-  if (len < entry->msg.nlmsg_len)
-    {
-      kmm_free(entry);
-      return -EMSGSIZE;
-    }
-
-  /* Handle the response according to the message type */
-
-  switch (entry->msg.nlmsg_type)
-    {
-#ifndef CONFIG_NETLINK_DISABLE_GETLINK
-      case RTM_NEWLINK:
-        {
-          FAR struct getlink_recvfrom_rsplist_s *resp =
-            (FAR struct getlink_recvfrom_rsplist_s *)entry;
-
-          /* Copy the payload to the user buffer */
-
-          memcpy(nlmsg, &resp->payload, resp->payload.hdr.nlmsg_len);
-
-          /* Return address.  REVISIT... this is just a guess. */
-
-          if (from != NULL)
-            {
-              from->nl_family = resp->payload.iface.ifi_family;
-              from->nl_pad    = 0;
-              from->nl_pid    = resp->payload.hdr.nlmsg_pid;
-              from->nl_groups = resp->payload.hdr.nlmsg_type;
-            }
-
-          /* The return value is the payload size */
-
-          ret = resp->payload.hdr.nlmsg_len;
-        }
-        break;
-#endif
-
-#ifndef CONFIG_NETLINK_DISABLE_GETNEIGH
-      case RTM_GETNEIGH:
-        {
-          FAR struct getneigh_recvfrom_rsplist_s *resp =
-            (FAR struct getneigh_recvfrom_rsplist_s *)entry;
-
-          /* Copy the payload to the user buffer */
-
-          memcpy(nlmsg, &resp->payload, resp->payload.hdr.nlmsg_len);
-
-          /* Return address.  REVISIT... this is just a guess. */
-
-          if (from != NULL)
-            {
-              from->nl_family = resp->payload.msg.ndm_family;
-              from->nl_pad    = 0;
-              from->nl_pid    = resp->payload.hdr.nlmsg_pid;
-              from->nl_groups = resp->payload.hdr.nlmsg_type;
-            }
-
-          /* The return value is the payload size */
-
-          ret = resp->payload.hdr.nlmsg_len;
-        }
-        break;
-#endif
-
-#ifndef CONFIG_NETLINK_DISABLE_GETROUTE
-      case RTM_NEWROUTE:
-        {
-          FAR struct getroute_recvfrom_resplist_s *resp =
-            (FAR struct getroute_recvfrom_resplist_s *)entry;
-
-          /* Copy the payload to the user buffer */
-
-          memcpy(nlmsg, &resp->payload, resp->payload.hdr.nlmsg_len);
-
-          /* Return address.  REVISIT... this is just a guess. */
-
-          if (from != NULL)
-            {
-              from->nl_family = resp->payload.rte.rtm_family;
-              from->nl_pad    = 0;
-              from->nl_pid    = resp->payload.hdr.nlmsg_pid;
-              from->nl_groups = resp->payload.hdr.nlmsg_type;
-            }
-
-          /* The return value is the payload size */
-
-          ret = resp->payload.hdr.nlmsg_len;
-        }
-        break;
-#endif
-
-#ifndef NETLINK_DISABLE_NLMSGDONE
-      case NLMSG_DONE:
-        {
-          FAR struct nlroute_msgdone_rsplist_s *resp =
-            (FAR struct nlroute_msgdone_rsplist_s *)entry;
-
-          /* Copy the payload to the user buffer */
-
-          resp->payload.hdr.nlmsg_len = sizeof(struct nlmsghdr);
-          memcpy(nlmsg, &resp->payload, sizeof(struct nlmsghdr));
-
-          /* Return address.  REVISIT... this is just a guess. */
-
-          if (from != NULL)
-            {
-              from->nl_family = resp->payload.gen.rtgen_family;
-              from->nl_pad    = 0;
-              from->nl_pid    = resp->payload.hdr.nlmsg_pid;
-              from->nl_groups = 0;
-            }
-
-          /* The return value is the payload size */
-
-          ret = sizeof(struct nlmsghdr);
-        }
-        break;
-#endif
-
-      default:
-        nerr("ERROR: Unrecognized message type: %u\n",
-             entry->msg.nlmsg_type);
-        ret = -EIO;
-        break;
-    }
-
-  kmm_free(entry);
-  return ret;
-}
-
 #endif /* CONFIG_NETLINK_ROUTE */
diff --git a/net/netlink/netlink_sockif.c b/net/netlink/netlink_sockif.c
index 63c9bd5..8d981c4 100644
--- a/net/netlink/netlink_sockif.c
+++ b/net/netlink/netlink_sockif.c
@@ -799,40 +799,52 @@ static ssize_t netlink_recvfrom(FAR struct socket *psock, FAR void *buf,
                                 FAR struct sockaddr *from,
                                 FAR socklen_t *fromlen)
 {
-  FAR struct netlink_conn_s *conn;
-  FAR struct nlmsghdr *nlmsg;
-  int ret;
+  FAR struct netlink_response_s *entry;
 
   DEBUGASSERT(psock != NULL && psock->s_conn != NULL && buf != NULL);
   DEBUGASSERT(from == NULL ||
               (fromlen != NULL && *fromlen >= sizeof(struct sockaddr_nl)));
 
-  conn = (FAR struct netlink_conn_s *)psock->s_conn;
+  /* Find the response to this message.  The return value */
 
-  /* Get a reference to the NetLink message */
+  entry = (FAR struct netlink_response_s *)netlink_tryget_response(psock);
+  if (entry == NULL)
+    {
+      /* No response is variable, but presumably, one is expected.  Check
+       * if the socket has been configured for non-blocking operation.
+       */
 
-  nlmsg = (FAR struct nlmsghdr *)buf;
+      if (_SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0)
+        {
+          return -EAGAIN;
+        }
 
-  switch (conn->protocol)
+      /* Wait for the response.  This should always succeed. */
+
+      entry = (FAR struct netlink_response_s *)netlink_get_response(psock);
+      DEBUGASSERT(entry != NULL);
+      if (entry == NULL)
+        {
+          return -EPIPE;
+        }
+    }
+
+  if (len > entry->msg.nlmsg_len)
     {
-#ifdef CONFIG_NETLINK_ROUTE
-      case NETLINK_ROUTE:
-        ret = netlink_route_recvfrom(psock, nlmsg, len, flags,
-                                     (FAR struct sockaddr_nl *)from);
-        if (ret >= 0 && fromlen != NULL)
-          {
-            *fromlen = sizeof(struct sockaddr_nl);
-          }
+      len = entry->msg.nlmsg_len;
+    }
 
-        break;
-#endif
+  /* Copy the payload to the user buffer */
 
-      default:
-       ret = -EOPNOTSUPP;
-       break;
+  memcpy(buf, &entry->msg, len);
+  kmm_free(entry);
+
+  if (from != NULL)
+    {
+      netlink_getpeername(psock, from, fromlen);
     }
 
-  return ret;
+  return len;
 }
 
 /****************************************************************************


[incubator-nuttx] 07/08: netlink: all request to NETLINK_ROUTE should use rtgenmsg

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 369a0fa4fba2d61302495e341caae488c300c894
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Apr 10 01:54:18 2020 -0400

    netlink: all request to NETLINK_ROUTE should use rtgenmsg
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
    Change-Id: Ib7a05dbf08277f56882e19a886a12a153889ca38
---
 net/netlink/netlink_route.c | 354 +++++++++++++++++---------------------------
 1 file changed, 138 insertions(+), 216 deletions(-)

diff --git a/net/netlink/netlink_route.c b/net/netlink/netlink_route.c
index e5873e7..46fd844 100644
--- a/net/netlink/netlink_route.c
+++ b/net/netlink/netlink_route.c
@@ -83,31 +83,15 @@
  * Private Types
  ****************************************************************************/
 
-/* Used to send message done.  gen is tacked on to provide the address
- * family.  It is discarded before returning the struct nlmsghdr payload.
- */
-
-struct nlroute_msgdone_response_s
-{
-  struct nlmsghdr  hdr;
-  struct rtgenmsg  gen;
-};
+/* Used to send message done */
 
 struct nlroute_msgdone_rsplist_s
 {
   sq_entry_t flink;
-  struct nlroute_msgdone_response_s payload;
+  struct nlmsghdr payload;
 };
 
-/* RTM_GETLINK:  Enumerate network devices .  The message contains the
- * 'rtgenmsg' structure.
- */
-
-struct getlink_sendto_request_s
-{
-  struct nlmsghdr  hdr;
-  struct rtgenmsg  gen;
-};
+/* RTM_GETLINK:  Enumerate network devices */
 
 struct getlink_recvfrom_response_s
 {
@@ -123,15 +107,7 @@ struct getlink_recvfrom_rsplist_s
   struct getlink_recvfrom_response_s payload;
 };
 
-/* RTM_GETNEIGH:  Get neighbor table entry.  The message contains an 'ndmsg'
- * structure.
- */
-
-struct getneigh_sendto_request_s
-{
-  struct nlmsghdr hdr;
-  struct ndmsg    msg;
-};
+/* RTM_GETNEIGH:  Get neighbor table entry */
 
 struct getneigh_recvfrom_response_s
 {
@@ -155,36 +131,16 @@ struct getneigh_recvfrom_rsplist_s
 
 /* RTM_GETROUTE.  Get routing tables */
 
-struct getroute_sendto_request_s
-{
-  struct nlmsghdr  hdr;
-  struct rtgenmsg  gen;
-};
-
-struct getroute_recvfrom_response_s
-{
-  struct nlmsghdr  hdr;
-  struct rtmsg     rte;
-
-  /* Addresses follow */
-};
-
-struct getroute_recvfrom_resplist_s
-{
-  sq_entry_t flink;
-  struct getroute_recvfrom_response_s payload;
-};
-
 struct getroute_recvfrom_ipv4addr_s
 {
-  struct rtattr    attr;
-  in_addr_t        addr;
+  struct rtattr attr;
+  in_addr_t     addr;
 };
 
 struct getroute_recvfrom_ipv4response_s
 {
-  struct nlmsghdr  hdr;
-  struct rtmsg     rte;
+  struct nlmsghdr hdr;
+  struct rtmsg    rte;
   struct getroute_recvfrom_ipv4addr_s dst;
   struct getroute_recvfrom_ipv4addr_s genmask;
   struct getroute_recvfrom_ipv4addr_s gateway;
@@ -198,14 +154,14 @@ struct getroute_recvfrom_ipv4resplist_s
 
 struct getroute_recvfrom_ipv6addr_s
 {
-  struct rtattr    attr;
-  net_ipv6addr_t   addr;
+  struct rtattr  attr;
+  net_ipv6addr_t addr;
 };
 
 struct getroute_recvfrom_ipv6response_s
 {
-  struct nlmsghdr  hdr;
-  struct rtmsg     rte;
+  struct nlmsghdr hdr;
+  struct rtmsg    rte;
   struct getroute_recvfrom_ipv6addr_s dst;
   struct getroute_recvfrom_ipv6addr_s genmask;
   struct getroute_recvfrom_ipv6addr_s gateway;
@@ -219,16 +175,16 @@ struct getroute_recvfrom_ipv6resplist_s
 
 /* netdev_foreach() callback */
 
-struct nlroute_devinfo_s
+struct nlroute_sendto_request_s
 {
-  FAR struct socket *psock;
-  FAR const struct getlink_sendto_request_s *req;
+  struct nlmsghdr hdr;
+  struct rtgenmsg gen;
 };
 
-struct nlroute_routeinfo_s
+struct nlroute_info_s
 {
   FAR struct socket *psock;
-  FAR const struct getroute_sendto_request_s *req;
+  FAR const struct nlroute_sendto_request_s *req;
 };
 
 /****************************************************************************
@@ -247,14 +203,14 @@ struct nlroute_routeinfo_s
 static int netlink_device_callback(FAR struct net_driver_s *dev,
                                    FAR void *arg)
 {
-  FAR struct nlroute_devinfo_s *devinfo;
+  FAR struct nlroute_info_s *info;
   FAR struct getlink_recvfrom_rsplist_s *alloc;
   FAR struct getlink_recvfrom_response_s *resp;
 
   DEBUGASSERT(dev != NULL && arg != NULL);
 
-  devinfo = (FAR struct nlroute_devinfo_s *)arg;
-  DEBUGASSERT(devinfo->psock != NULL && devinfo->req != NULL);
+  info = (FAR struct nlroute_info_s *)arg;
+  DEBUGASSERT(info->psock != NULL && info->req != NULL);
 
   /* Check if the link is in the UP state */
 
@@ -267,15 +223,15 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
 
   /* Filter only the requested address families */
 
-  switch (devinfo->req->gen.rtgen_family)
+  switch (info->req->gen.rtgen_family)
     {
 #ifdef CONFIG_NET_LOCAL
       case AF_LOCAL:
-        /* Should have devinfo->psock->s_domain == PF_LOCAL and d_lltype ==
+        /* Should have info->psock->s_domain == PF_LOCAL and d_lltype ==
          * NET_LL_LOOPBACK.
          */
 
-        if (devinfo->psock->s_domain == PF_LOCAL)
+        if (info->psock->s_domain == PF_LOCAL)
           {
             DEBUGASSERT(dev->d_lltype == NET_LL_LOOPBACK);
             break;
@@ -287,13 +243,13 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
 #endif
 
 #ifdef CONFIG_NET_IPv4
-        /* Should have devinfo->psock->s_domain == PF_INET but d_lltype could be
+        /* Should have info->psock->s_domain == PF_INET but d_lltype could be
          * several things.
          */
 
       case AF_INET:
 
-        if (devinfo->psock->s_domain == PF_INET)
+        if (info->psock->s_domain == PF_INET)
           {
             break;
           }
@@ -304,13 +260,13 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
 #endif
 
 #ifdef CONFIG_NET_IPv6
-        /* Should have devinfo->psock->s_domain == PF_INET6 but d_lltype
-         * could be several things.
+        /* Should have info->psock->s_domain == PF_INET6 but d_lltype could be
+         * several things.
          */
 
       case AF_INET6:
 
-        if (devinfo->psock->s_domain == PF_INET6)
+        if (info->psock->s_domain == PF_INET6)
           {
             break;
           }
@@ -321,12 +277,12 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
 #endif
 
 #ifdef CONFIG_NET_BLUETOOTH
-        /* Should have devinfo->psock->s_domain == PF_PACKET and d_lltype
-         * should be NET_LL_BLUETOOTH.
+        /* Should have info->psock->s_domain == PF_PACKET and d_lltype should be
+         * NET_LL_BLUETOOTH.
          */
 
       case AF_BLUETOOTH:
-        if (devinfo->psock->s_domain == PF_PACKET)
+        if (info->psock->s_domain == PF_PACKET)
           {
             DEBUGASSERT(dev->d_lltype == NET_LL_BLUETOOTH);
             break;
@@ -345,8 +301,8 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
       case AF_IEEE802154:
         if (dev->d_lltype == NET_LL_IEEE802154)
           {
-            DEBUGASSERT(devinfo->psock->s_domain == PF_PACKET ||
-                        devinfo->psock->s_domain == PF_INET6);
+            DEBUGASSERT(info->psock->s_domain == PF_PACKET ||
+                        info->psock->s_domain == PF_INET6);
             break;
           }
         else
@@ -362,7 +318,7 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
 
         if (dev->d_lltype == NET_LL_PKTRADIO)
           {
-            DEBUGASSERT(devinfo->psock->s_domain == PF_INET6);
+            DEBUGASSERT(info->psock->s_domain == PF_INET6);
             break;
           }
         else
@@ -377,14 +333,14 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
       case AF_UNSPEC:
       case AF_PKTRADIO:
       default:
-        nerr("ERROR: Unsupported address family: %u\n", devinfo->req->gen);
+        nerr("ERROR: Unsupported address family: %u\n", info->req->gen);
         return 0;
     }
 
   /* Allocate the response buffer */
 
   alloc = (FAR struct getlink_recvfrom_rsplist_s *)
-    kmm_malloc(sizeof(struct getlink_recvfrom_rsplist_s));
+    kmm_zalloc(sizeof(struct getlink_recvfrom_rsplist_s));
   if (alloc == NULL)
     {
       nerr("ERROR: Failed to allocate response buffer.\n");
@@ -397,17 +353,14 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
 
   resp->hdr.nlmsg_len    = sizeof(struct getlink_recvfrom_response_s);
   resp->hdr.nlmsg_type   = RTM_NEWLINK;
-  resp->hdr.nlmsg_flags  = devinfo->req->hdr.nlmsg_flags;
-  resp->hdr.nlmsg_seq    = devinfo->req->hdr.nlmsg_seq;
-  resp->hdr.nlmsg_pid    = devinfo->req->hdr.nlmsg_pid;
+  resp->hdr.nlmsg_flags  = info->req->hdr.nlmsg_flags;
+  resp->hdr.nlmsg_seq    = info->req->hdr.nlmsg_seq;
+  resp->hdr.nlmsg_pid    = info->req->hdr.nlmsg_pid;
 
-  resp->iface.ifi_family = devinfo->req->gen.rtgen_family;
-  resp->iface.ifi_pad    = 0;
-  resp->iface.ifi_type   = devinfo->req->hdr.nlmsg_type;
+  resp->iface.ifi_family = info->req->gen.rtgen_family;
+  resp->iface.ifi_type   = dev->d_lltype;
 #ifdef CONFIG_NETDEV_IFINDEX
   resp->iface.ifi_index  = dev->d_ifindex;
-#else
-  resp->iface.ifi_index  = 0;
 #endif
   resp->iface.ifi_flags  = dev->d_flags;
   resp->iface.ifi_change = 0xffffffff;
@@ -417,16 +370,9 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
 
   strncpy((FAR char *)resp->data, dev->d_ifname, IFNAMSIZ);
 
-  /* REVISIT:  Another response should be provided with nlmsg_type =
-   * RTM_NEWROUTE.  That response should include struct rtmsg followed by a
-   * number of attributes.  This response provides routing information for
-   * the device including address (RTA_DST) and gateway (RTA_GATEWAY)
-   * attributes.
-   */
-
   /* Finally, add the data to the list of pending responses */
 
-  netlink_add_response(devinfo->psock, (FAR struct netlink_response_s *)alloc);
+  netlink_add_response(info->psock, (FAR struct netlink_response_s *)alloc);
   return 0;
 }
 #endif
@@ -441,17 +387,17 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
 
 #ifndef CONFIG_NETLINK_DISABLE_GETLINK
 static int netlink_get_devlist(FAR struct socket *psock,
-                               FAR const struct getlink_sendto_request_s *req)
+                               FAR const struct nlroute_sendto_request_s *req)
 {
-  struct nlroute_devinfo_s devinfo;
+  struct nlroute_info_s info;
   FAR struct nlroute_msgdone_rsplist_s *alloc;
-  FAR struct nlroute_msgdone_response_s *resp;
+  FAR struct nlmsghdr *resp;
   int ret;
 
   /* Pre-allocate the list terminator */
 
   alloc = (FAR struct nlroute_msgdone_rsplist_s *)
-    kmm_malloc(sizeof(struct nlroute_msgdone_rsplist_s));
+    kmm_zalloc(sizeof(struct nlroute_msgdone_rsplist_s));
   if (alloc == NULL)
     {
       nerr("ERROR: Failed to allocate response terminator.\n");
@@ -460,31 +406,30 @@ static int netlink_get_devlist(FAR struct socket *psock,
 
   /* Visit each device */
 
-  devinfo.psock = psock;
-  devinfo.req   = req;
+  info.psock = psock;
+  info.req   = req;
 
   net_lock();
-  ret = netdev_foreach(netlink_device_callback, &devinfo);
+  ret = netdev_foreach(netlink_device_callback, &info);
+  net_unlock();
   if (ret < 0)
     {
-      net_unlock();
+      kmm_free(alloc);
       return ret;
     }
 
   /* Initialize and send the list terminator */
 
-  resp                   = &alloc->payload;
-  resp->hdr.nlmsg_len    = sizeof(struct nlroute_msgdone_response_s);
-  resp->hdr.nlmsg_type   = NLMSG_DONE;
-  resp->hdr.nlmsg_flags  = req->hdr.nlmsg_flags;
-  resp->hdr.nlmsg_seq    = req->hdr.nlmsg_seq;
-  resp->hdr.nlmsg_pid    = req->hdr.nlmsg_pid;
-  resp->gen.rtgen_family = req->gen.rtgen_family;
+  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);
-  net_unlock();
   return OK;
 }
 #endif
@@ -499,7 +444,7 @@ 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,
-                                FAR const struct getneigh_sendto_request_s *req)
+                                FAR const struct nlroute_sendto_request_s *req)
 {
   FAR struct getneigh_recvfrom_rsplist_s *entry;
   unsigned int ncopied;
@@ -517,7 +462,7 @@ static int netlink_get_arptable(FAR struct socket *psock,
   rspsize   = SIZEOF_NLROUTE_RECVFROM_RESPONSE_S(tabsize);
   allocsize = SIZEOF_NLROUTE_RECVFROM_RSPLIST_S(tabsize);
 
-  entry     = (FAR struct getneigh_recvfrom_rsplist_s *)kmm_malloc(allocsize);
+  entry     = (FAR struct getneigh_recvfrom_rsplist_s *)kmm_zalloc(allocsize);
   if (entry == NULL)
     {
       nerr("ERROR: Failed to allocate response buffer.\n");
@@ -527,10 +472,9 @@ static int netlink_get_arptable(FAR struct socket *psock,
   /* Populate the entry */
 
   memcpy(&entry->payload.hdr, &req->hdr, sizeof(struct nlmsghdr));
-  entry->payload.hdr.nlmsg_len = rspsize;
-  memcpy(&entry->payload.msg, &req->msg, sizeof(struct ndmsg));
-  entry->payload.attr.rta_len  = RTA_LENGTH(tabsize);
-  entry->payload.attr.rta_type = 0;
+  entry->payload.hdr.nlmsg_len  = rspsize;
+  entry->payload.msg.ndm_family = req->gen.rtgen_family;
+  entry->payload.attr.rta_len   = RTA_LENGTH(tabsize);
 
   /* Lock the network so that the ARP table will be stable, then copy
    * the ARP table into the allocated memory.
@@ -582,7 +526,7 @@ 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,
-                               FAR const struct getneigh_sendto_request_s *req)
+                               FAR const struct nlroute_sendto_request_s *req)
 {
   FAR struct getneigh_recvfrom_rsplist_s *entry;
   unsigned int ncopied;
@@ -601,7 +545,7 @@ static int netlink_get_nbtable(FAR struct socket *psock,
   rspsize   = SIZEOF_NLROUTE_RECVFROM_RESPONSE_S(tabsize);
   allocsize = SIZEOF_NLROUTE_RECVFROM_RSPLIST_S(tabsize);
 
-  entry     = (FAR struct getneigh_recvfrom_rsplist_s *)kmm_malloc(allocsize);
+  entry     = (FAR struct getneigh_recvfrom_rsplist_s *)kmm_zalloc(allocsize);
   if (entry == NULL)
     {
       nerr("ERROR: Failed to allocate response buffer.\n");
@@ -611,10 +555,9 @@ static int netlink_get_nbtable(FAR struct socket *psock,
   /* Populate the entry */
 
   memcpy(&entry->payload.hdr, &req->hdr, sizeof(struct nlmsghdr));
-  entry->payload.hdr.nlmsg_len = rspsize;
-  memcpy(&entry->payload.msg, &req->msg, sizeof(struct ndmsg));
-  entry->payload.attr.rta_len  = RTA_LENGTH(tabsize);
-  entry->payload.attr.rta_type = 0;
+  entry->payload.hdr.nlmsg_len  = rspsize;
+  entry->payload.msg.ndm_family = req->gen.rtgen_family;
+  entry->payload.attr.rta_len   = RTA_LENGTH(tabsize);
 
   /* Lock the network so that the Neighbor table will be stable, then
    * copy the Neighbor table into the allocated memory.
@@ -666,16 +609,16 @@ static int netlink_get_nbtable(FAR struct socket *psock,
 
 #ifndef CONFIG_NETLINK_DISABLE_GETROUTE
 static int
-  netlink_route_terminator(FAR struct socket *psock,
-                           FAR const struct getroute_sendto_request_s *req)
+netlink_route_terminator(FAR struct socket *psock,
+                         FAR const struct nlroute_sendto_request_s *req)
 {
   FAR struct nlroute_msgdone_rsplist_s *alloc;
-  FAR struct nlroute_msgdone_response_s *resp;
+  FAR struct nlmsghdr *resp;
 
   /* Allocate the list terminator */
 
   alloc = (FAR struct nlroute_msgdone_rsplist_s *)
-    kmm_malloc(sizeof(struct nlroute_msgdone_rsplist_s));
+    kmm_zalloc(sizeof(struct nlroute_msgdone_rsplist_s));
   if (alloc == NULL)
     {
       nerr("ERROR: Failed to allocate response terminator.\n");
@@ -684,13 +627,12 @@ static int
 
   /* Initialize and send the list terminator */
 
-  resp                   = &alloc->payload;
-  resp->hdr.nlmsg_len    = sizeof(struct nlroute_msgdone_response_s);
-  resp->hdr.nlmsg_type   = NLMSG_DONE;
-  resp->hdr.nlmsg_flags  = req->hdr.nlmsg_flags;
-  resp->hdr.nlmsg_seq    = req->hdr.nlmsg_seq;
-  resp->hdr.nlmsg_pid    = req->hdr.nlmsg_pid;
-  resp->gen.rtgen_family = req->gen.rtgen_family;
+  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 */
 
@@ -711,17 +653,17 @@ static int
 static int netlink_ipv4_route(FAR struct net_route_ipv4_s *route,
                               FAR void *arg)
 {
-  FAR struct nlroute_routeinfo_s *routeinfo;
+  FAR struct nlroute_info_s *info;
   FAR struct getroute_recvfrom_ipv4resplist_s *alloc;
   FAR struct getroute_recvfrom_ipv4response_s *resp;
 
   DEBUGASSERT(route != NULL && arg != NULL);
-  routeinfo = (FAR struct nlroute_routeinfo_s *)arg;
+  info = (FAR struct nlroute_info_s *)arg;
 
   /* Allocate the response */
 
   alloc = (FAR struct getroute_recvfrom_ipv4resplist_s *)
-    kmm_malloc(sizeof(struct getroute_recvfrom_ipv4resplist_s));
+    kmm_zalloc(sizeof(struct getroute_recvfrom_ipv4resplist_s));
   if (alloc == NULL)
     {
       return -ENOMEM;
@@ -732,12 +674,11 @@ static int netlink_ipv4_route(FAR struct net_route_ipv4_s *route,
   resp                        = &alloc->payload;
   resp->hdr.nlmsg_len         = sizeof(struct getroute_recvfrom_ipv4response_s);
   resp->hdr.nlmsg_type        = RTM_NEWROUTE;
-  resp->hdr.nlmsg_flags       = routeinfo->req->hdr.nlmsg_flags;
-  resp->hdr.nlmsg_seq         = routeinfo->req->hdr.nlmsg_seq;
-  resp->hdr.nlmsg_pid         = routeinfo->req->hdr.nlmsg_pid;
+  resp->hdr.nlmsg_flags       = info->req->hdr.nlmsg_flags;
+  resp->hdr.nlmsg_seq         = info->req->hdr.nlmsg_seq;
+  resp->hdr.nlmsg_pid         = info->req->hdr.nlmsg_pid;
 
-  memset(&resp->rte, 0, sizeof(struct rtmsg));  /* REVISIT:  Uninitialize fields */
-  resp->rte.rtm_family        = routeinfo->req->gen.rtgen_family;
+  resp->rte.rtm_family        = info->req->gen.rtgen_family;
   resp->rte.rtm_table         = RT_TABLE_MAIN;
   resp->rte.rtm_protocol      = RTPROT_STATIC;
   resp->rte.rtm_scope         = RT_SCOPE_SITE;
@@ -756,7 +697,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(routeinfo->psock, (FAR struct netlink_response_s *)alloc);
+  netlink_add_response(info->psock, (FAR struct netlink_response_s *)alloc);
   return OK;
 }
 #endif
@@ -771,18 +712,17 @@ 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,
-                                 FAR const struct getroute_sendto_request_s *req)
+                                 FAR const struct nlroute_sendto_request_s *req)
 {
-  struct nlroute_routeinfo_s routeinfo;
+  struct nlroute_info_s info;
   int ret;
 
   /* Visit each routing table entry */
 
-  routeinfo.psock = psock;
-  routeinfo.req   = req;
+  info.psock = psock;
+  info.req   = req;
 
-  net_lock();
-  ret = net_foreachroute_ipv4(netlink_ipv4_route, &routeinfo);
+  ret = net_foreachroute_ipv4(netlink_ipv4_route, &info);
   if (ret < 0)
     {
       return ret;
@@ -790,9 +730,7 @@ static int netlink_get_ipv4route(FAR struct socket *psock,
 
   /* Terminate the routing table */
 
-  ret = netlink_route_terminator(psock, req);
-  net_unlock();
-  return ret;
+  return netlink_route_terminator(psock, req);
 }
 #endif
 
@@ -808,17 +746,17 @@ 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_routeinfo_s *routeinfo;
+  FAR struct nlroute_info_s *info;
   FAR struct getroute_recvfrom_ipv6resplist_s *alloc;
   FAR struct getroute_recvfrom_ipv6response_s *resp;
 
   DEBUGASSERT(route != NULL && arg != NULL);
-  routeinfo = (FAR struct nlroute_routeinfo_s *)arg;
+  info = (FAR struct nlroute_info_s *)arg;
 
   /* Allocate the response */
 
   alloc = (FAR struct getroute_recvfrom_ipv6resplist_s *)
-    kmm_malloc(sizeof(struct getroute_recvfrom_ipv6resplist_s));
+    kmm_zalloc(sizeof(struct getroute_recvfrom_ipv6resplist_s));
   if (alloc == NULL)
     {
       return -ENOMEM;
@@ -829,12 +767,11 @@ static int netlink_ipv6_route(FAR struct net_route_ipv6_s *route,
   resp                        = &alloc->payload;
   resp->hdr.nlmsg_len         = sizeof(struct getroute_recvfrom_ipv6response_s);
   resp->hdr.nlmsg_type        = RTM_NEWROUTE;
-  resp->hdr.nlmsg_flags       = routeinfo->req->hdr.nlmsg_flags;
-  resp->hdr.nlmsg_seq         = routeinfo->req->hdr.nlmsg_seq;
-  resp->hdr.nlmsg_pid         = routeinfo->req->hdr.nlmsg_pid;
+  resp->hdr.nlmsg_flags       = info->req->hdr.nlmsg_flags;
+  resp->hdr.nlmsg_seq         = info->req->hdr.nlmsg_seq;
+  resp->hdr.nlmsg_pid         = info->req->hdr.nlmsg_pid;
 
-  memset(&resp->rte, 0, sizeof(struct rtmsg));  /* REVISIT:  Uninitialize fields */
-  resp->rte.rtm_family        = routeinfo->req->gen.rtgen_family;
+  resp->rte.rtm_family        = info->req->gen.rtgen_family;
   resp->rte.rtm_table         = RT_TABLE_MAIN;
   resp->rte.rtm_protocol      = RTPROT_STATIC;
   resp->rte.rtm_scope         = RT_SCOPE_SITE;
@@ -853,7 +790,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(routeinfo->psock, (FAR struct netlink_response_s *)alloc);
+  netlink_add_response(info->psock, (FAR struct netlink_response_s *)alloc);
   return OK;
 }
 #endif
@@ -868,18 +805,17 @@ 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,
-                                 FAR const struct getroute_sendto_request_s *req)
+                                 FAR const struct nlroute_sendto_request_s *req)
 {
-  struct nlroute_routeinfo_s routeinfo;
+  struct nlroute_info_s info;
   int ret;
 
   /* Visit each routing table entry */
 
-  routeinfo.psock = psock;
-  routeinfo.req   = req;
+  info.psock = psock;
+  info.req   = req;
 
-  net_lock();
-  ret = net_foreachroute_ipv6(netlink_ipv6_route, &routeinfo);
+  ret = net_foreachroute_ipv6(netlink_ipv6_route, &info);
   if (ret < 0)
     {
       return ret;
@@ -887,9 +823,7 @@ static int netlink_get_ip6vroute(FAR struct socket *psock,
 
   /* Terminate the routing table */
 
-  ret = netlink_route_terminator(psock, req);
-  net_unlock();
-  return ret;
+  return netlink_route_terminator(psock, req);
 }
 #endif
 
@@ -911,8 +845,8 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
                              FAR const struct sockaddr_nl *to,
                              socklen_t tolen)
 {
-  FAR const struct getneigh_sendto_request_s *gnreq =
-    (FAR const struct getneigh_sendto_request_s *)nlmsg;
+  FAR const struct nlroute_sendto_request_s *req =
+    (FAR const struct nlroute_sendto_request_s *)nlmsg;
   int ret;
 
   DEBUGASSERT(psock != NULL && nlmsg != NULL &&
@@ -923,20 +857,15 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
 
   /* Handle according to the message type */
 
-  switch (gnreq->hdr.nlmsg_type)
+  switch (nlmsg->nlmsg_type)
     {
 #ifndef CONFIG_NETLINK_DISABLE_GETLINK
       /* Dump a list of all devices */
 
       case RTM_GETLINK:
-        {
-          FAR const struct getlink_sendto_request_s *glreq =
-            (FAR const struct getlink_sendto_request_s *)nlmsg;
+        /* Generate the response */
 
-          /* Generate the response */
-
-          ret = netlink_get_devlist(psock, glreq);
-        }
+        ret = netlink_get_devlist(psock, req);
         break;
 #endif
 
@@ -944,30 +873,28 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
       /* Retrieve ARP/Neighbor Tables */
 
       case RTM_GETNEIGH:
-        {
 #ifdef CONFIG_NET_ARP
-          /* Retrieve the ARP table in its entirety. */
+        /* Retrieve the ARP table in its entirety. */
 
-          if (gnreq->msg.ndm_family == AF_INET)
-            {
-              ret = netlink_get_arptable(psock, gnreq);
-            }
-          else
+        if (req->gen.rtgen_family == AF_INET)
+          {
+            ret = netlink_get_arptable(psock, req);
+          }
+        else
 #endif
 
 #ifdef CONFIG_NET_IPv6
-          /* Retrieve the IPv6 neighbor table in its entirety. */
+        /* Retrieve the IPv6 neighbor table in its entirety. */
 
-          if (gnreq->msg.ndm_family == AF_INET6)
-            {
-               ret = netlink_get_nbtable(psock, gnreq);
-            }
-          else
+        if (req->gen.rtgen_family == AF_INET6)
+          {
+             ret = netlink_get_nbtable(psock, req);
+          }
+        else
 #endif
-            {
-              ret = -EAFNOSUPPORT;
-            }
-        }
+          {
+            ret = -EAFNOSUPPORT;
+          }
         break;
 #endif /* !CONFIG_NETLINK_DISABLE_GETNEIGH */
 
@@ -975,28 +902,23 @@ ssize_t netlink_route_sendto(FAR struct socket *psock,
       /* Retrieve the IPv4 or IPv6 routing table */
 
       case RTM_GETROUTE:
-        {
-          FAR const struct getroute_sendto_request_s *grreq =
-            (FAR const struct getroute_sendto_request_s *)nlmsg;
-
 #ifdef CONFIG_NET_IPv4
-          if (grreq->gen.rtgen_family == AF_INET)
-            {
-              ret = netlink_get_ipv4route(psock, grreq);
-            }
-          else
+        if (req->gen.rtgen_family == AF_INET)
+          {
+            ret = netlink_get_ipv4route(psock, req);
+          }
+        else
 #endif
 #ifdef CONFIG_NET_IPv6
-          if (grreq->gen.rtgen_family == AF_INET6)
-            {
-              ret = netlink_get_ip6vroute(psock, grreq);
-            }
-          else
+        if (req->gen.rtgen_family == AF_INET6)
+          {
+            ret = netlink_get_ip6vroute(psock, req);
+          }
+        else
 #endif
-            {
-              ret = -EAFNOSUPPORT;
-            }
-        }
+          {
+            ret = -EAFNOSUPPORT;
+          }
         break;
 #endif