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/16 17:47:03 UTC

[incubator-nuttx] branch pr807 updated (9ac3a0d -> b635a5c)

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

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


    from 9ac3a0d  Fix sixlowpan_framer.c build warnings under macos
     new 0c630d7  netlink: Fix the compiler warning in netlink_add_broadcast
     new f49bba8  netlink: add netlink route notify support
     new f6cbda4  netdev/carrier: monitor the driver status
     new b635a5c  Fix nxstyle warning

The 4 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:
 net/netdev/netdev_carrier.c |   3 +
 net/netdev/netdev_ioctl.c   |  46 ++++++++++------
 net/netlink/netlink.h       |  18 ++++++
 net/netlink/netlink_conn.c  |   2 +-
 net/netlink/netlink_route.c | 131 +++++++++++++++++++++++++++++++-------------
 5 files changed, 144 insertions(+), 56 deletions(-)


[incubator-nuttx] 03/04: netdev/carrier: monitor the driver status

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

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

commit f6cbda424a32254f847cb6b9ee87415b8f9cb8a6
Author: chao.an <an...@xiaomi.com>
AuthorDate: Mon Apr 13 21:36:14 2020 +0800

    netdev/carrier: monitor the driver status
    
    Change-Id: Ieae06eae724ad4d5894e725c56a5bd493d2849fe
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 net/netdev/netdev_carrier.c | 3 +++
 net/netdev/netdev_ioctl.c   | 9 +++++++++
 2 files changed, 12 insertions(+)

diff --git a/net/netdev/netdev_carrier.c b/net/netdev/netdev_carrier.c
index ffccd8a..1c882f5 100644
--- a/net/netdev/netdev_carrier.c
+++ b/net/netdev/netdev_carrier.c
@@ -51,6 +51,7 @@
 #include <nuttx/net/netdev.h>
 
 #include "netdev/netdev.h"
+#include "netlink/netlink.h"
 
 /****************************************************************************
  * Public Functions
@@ -76,6 +77,7 @@ int netdev_carrier_on(FAR struct net_driver_s *dev)
   if (dev)
     {
       dev->d_flags |= IFF_RUNNING;
+      netlink_device_notify(dev);
       return OK;
     }
 
@@ -102,6 +104,7 @@ int netdev_carrier_off(FAR struct net_driver_s *dev)
   if (dev)
     {
       dev->d_flags &= ~IFF_RUNNING;
+      netlink_device_notify(dev);
       return OK;
     }
 
diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c
index f18980c..bf1ea5e 100644
--- a/net/netdev/netdev_ioctl.c
+++ b/net/netdev/netdev_ioctl.c
@@ -89,6 +89,7 @@
 #include "igmp/igmp.h"
 #include "icmpv6/icmpv6.h"
 #include "route/route.h"
+#include "netlink/netlink.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -1761,6 +1762,10 @@ void netdev_ifup(FAR struct net_driver_s *dev)
               /* Mark the interface as up */
 
               dev->d_flags |= IFF_UP;
+
+              /* Update the driver status */
+
+              netlink_device_notify(dev);
             }
         }
     }
@@ -1783,6 +1788,10 @@ void netdev_ifdown(FAR struct net_driver_s *dev)
               /* Mark the interface as down */
 
               dev->d_flags &= ~IFF_UP;
+
+              /* Update the driver status */
+
+              netlink_device_notify(dev);
             }
         }
 


[incubator-nuttx] 01/04: netlink: Fix the compiler warning in netlink_add_broadcast

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

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

commit 0c630d79f9d3e2630983ff40c0da98c7d7fef9a4
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Thu Apr 16 13:50:20 2020 +0800

    netlink: Fix the compiler warning in netlink_add_broadcast
    
    netlink/netlink_conn.c: In function 'netlink_add_broadcast':
    netlink/netlink_conn.c:319:45: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
      319 |       if (conn->groups & (1 << (group - 1)) == 0)
          |                          ~~~~~~~~~~~~~~~~~~~^~~~
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
    Change-Id: I1bee7933dca1bdd118d0034a564b4306e1ae5684
---
 net/netlink/netlink_conn.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netlink/netlink_conn.c b/net/netlink/netlink_conn.c
index 9145ef2..96aed71 100644
--- a/net/netlink/netlink_conn.c
+++ b/net/netlink/netlink_conn.c
@@ -317,7 +317,7 @@ void netlink_add_broadcast(int group, FAR struct netlink_response_s *data)
 
   while ((conn = netlink_nextconn(conn)) != NULL)
     {
-      if (conn->groups & (1 << (group - 1)) == 0)
+      if ((conn->groups & (1 << (group - 1))) == 0)
         {
           continue;
         }


[incubator-nuttx] 04/04: Fix nxstyle warning

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

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

commit b635a5c2b63bc584c644ce4cb4448374b1d9139e
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Thu Apr 16 22:02:11 2020 +0800

    Fix nxstyle warning
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 net/netdev/netdev_ioctl.c | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c
index bf1ea5e..4e27251 100644
--- a/net/netdev/netdev_ioctl.c
+++ b/net/netdev/netdev_ioctl.c
@@ -305,8 +305,8 @@ static void ioctl_get_ipv4addr(FAR struct sockaddr *outaddr,
  ****************************************************************************/
 
 #ifdef CONFIG_NET_IPv4
-static void inline ioctl_get_ipv4broadcast(FAR struct sockaddr *outaddr,
-                                           in_addr_t inaddr, in_addr_t netmask)
+static void ioctl_get_ipv4broadcast(FAR struct sockaddr *outaddr,
+                                    in_addr_t inaddr, in_addr_t netmask)
 {
   FAR struct sockaddr_in *dest  = (FAR struct sockaddr_in *)outaddr;
   dest->sin_family              = AF_INET;
@@ -378,7 +378,8 @@ static void ioctl_set_ipv4addr(FAR in_addr_t *outaddr,
 static void ioctl_set_ipv6addr(FAR net_ipv6addr_t outaddr,
                                FAR const struct sockaddr_storage *inaddr)
 {
-  FAR const struct sockaddr_in6 *src = (FAR const struct sockaddr_in6 *)inaddr;
+  FAR const struct sockaddr_in6 *src =
+    (FAR const struct sockaddr_in6 *)inaddr;
   memcpy(outaddr, src->sin6_addr.in6_u.u6_addr8, 16);
 }
 #endif
@@ -511,7 +512,7 @@ static int netdev_iee802154_ioctl(FAR struct socket *psock, int cmd,
  * Name: netdev_pktradio_ioctl
  *
  * Description:
- *   Perform non-IEEE802.15.4 packet radio network device specific operations.
+ *   Perform non-IEEE802.15.4 packet radio network device specific operation.
  *
  * Input Parameters:
  *   psock  - Socket structure
@@ -605,7 +606,7 @@ static int netdev_wifr_ioctl(FAR struct socket *psock, int cmd,
         {
           /* Just forward the IOCTL to the wireless driver */
 
-          ret = dev->d_ioctl(dev, cmd, ((unsigned long)(uintptr_t)req));
+          ret = dev->d_ioctl(dev, cmd, (unsigned long)(uintptr_t)req);
         }
     }
 
@@ -1065,8 +1066,9 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
           dev = netdev_ifr_dev(req);
           if (dev && dev->d_ioctl)
             {
-              struct mii_ioctl_notify_s *notify = &req->ifr_ifru.ifru_mii_notify;
-              ret = dev->d_ioctl(dev, cmd, ((unsigned long)(uintptr_t)notify));
+              struct mii_ioctl_notify_s *notify =
+                &req->ifr_ifru.ifru_mii_notify;
+              ret = dev->d_ioctl(dev, cmd, (unsigned long)(uintptr_t)notify);
             }
         }
         break;
@@ -1079,8 +1081,10 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
           dev = netdev_ifr_dev(req);
           if (dev && dev->d_ioctl)
             {
-              struct mii_ioctl_data_s *mii_data = &req->ifr_ifru.ifru_mii_data;
-              ret = dev->d_ioctl(dev, cmd, ((unsigned long)(uintptr_t)mii_data));
+              struct mii_ioctl_data_s *mii_data =
+                &req->ifr_ifru.ifru_mii_data;
+              ret = dev->d_ioctl(dev, cmd,
+                                 (unsigned long)(uintptr_t)mii_data);
             }
         }
         break;
@@ -1243,9 +1247,10 @@ static int netdev_arp_ioctl(FAR struct socket *psock, int cmd,
               FAR struct sockaddr_in *addr =
                 (FAR struct sockaddr_in *)&req->arp_pa;
 
-              /* Find the existing ARP table entry for this protocol address. */
+              /* Find the existing ARP entry for this protocol address. */
 
-              FAR struct arp_entry_s *entry = arp_lookup(addr->sin_addr.s_addr);
+              FAR struct arp_entry_s *entry =
+                arp_lookup(addr->sin_addr.s_addr);
               if (entry != NULL)
                 {
                   /* The ARP table is fixed size; an entry is deleted
@@ -1613,8 +1618,6 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
       return -EBADF;
     }
 
-  /* Execute the command.  First check for a standard network IOCTL command. */
-
 #ifdef CONFIG_NET_USRSOCK
   /* Check for a USRSOCK ioctl command */
 
@@ -1624,7 +1627,7 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
     {
       /* Check for a standard network IOCTL command. */
 
-      ret = netdev_ifr_ioctl(psock, cmd, (FAR struct ifreq *)((uintptr_t)arg));
+      ret = netdev_ifr_ioctl(psock, cmd, (FAR struct ifreq *)(uintptr_t)arg);
     }
 
 #if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NETDEV_WIRELESS_IOCTL)
@@ -1672,7 +1675,7 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
   if (ret == -ENOTTY)
     {
       ret = netdev_imsf_ioctl(psock, cmd,
-                              (FAR struct ip_msfilter *)((uintptr_t)arg));
+                              (FAR struct ip_msfilter *)(uintptr_t)arg);
     }
 #endif
 
@@ -1682,7 +1685,7 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
   if (ret == -ENOTTY)
     {
       ret = netdev_arp_ioctl(psock, cmd,
-                             (FAR struct arpreq *)((uintptr_t)arg));
+                             (FAR struct arpreq *)(uintptr_t)arg);
     }
 #endif
 
@@ -1692,7 +1695,7 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
   if (ret == -ENOTTY)
     {
       ret = netdev_rt_ioctl(psock, cmd,
-                            (FAR struct rtentry *)((uintptr_t)arg));
+                            (FAR struct rtentry *)(uintptr_t)arg);
     }
 #endif
 


[incubator-nuttx] 02/04: netlink: add netlink route notify support

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

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

commit f49bba8678a65ff42998d81f68e29efed40902a4
Author: chao.an <an...@xiaomi.com>
AuthorDate: Mon Apr 13 16:10:30 2020 +0800

    netlink: add netlink route notify support
    
    Change-Id: I9b7585ce5c9b67c606b118ccd72d496ecb219eeb
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 net/netlink/netlink.h       |  18 ++++++
 net/netlink/netlink_route.c | 131 +++++++++++++++++++++++++++++++-------------
 2 files changed, 111 insertions(+), 38 deletions(-)

diff --git a/net/netlink/netlink.h b/net/netlink/netlink.h
index 19381dc..d11d8a8 100644
--- a/net/netlink/netlink.h
+++ b/net/netlink/netlink.h
@@ -53,6 +53,14 @@
 #include "devif/devif.h"
 #include "socket/socket.h"
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef CONFIG_NETLINK_ROUTE
+  #define netlink_device_notify(dev)
+#endif
+
 #ifdef CONFIG_NET_NETLINK
 
 /****************************************************************************
@@ -277,6 +285,16 @@ ssize_t netlink_route_sendto(NETLINK_HANDLE handle,
                              size_t len, int flags,
                              FAR const struct sockaddr_nl *to,
                              socklen_t tolen);
+
+/****************************************************************************
+ * Name: netlink_device_notify()
+ *
+ * Description:
+ *   Perform the route broadcast for the NETLINK_ROUTE protocol.
+ *
+ ****************************************************************************/
+
+void netlink_device_notify(FAR struct net_driver_s *dev);
 #endif
 
 #undef EXTERN
diff --git a/net/netlink/netlink_route.c b/net/netlink/netlink_route.c
index 955e3da..3a46391 100644
--- a/net/netlink/netlink_route.c
+++ b/net/netlink/netlink_route.c
@@ -184,32 +184,21 @@ struct nlroute_info_s
  ****************************************************************************/
 
 /****************************************************************************
- * Name: netlink_device_callback
+ * Name: netlink_get_device
  *
  * Description:
- *   Handle one device.
+ *   Generate one device response.
  *
  ****************************************************************************/
 
 #ifndef CONFIG_NETLINK_DISABLE_GETLINK
-static int netlink_device_callback(FAR struct net_driver_s *dev,
-                                   FAR void *arg)
+static FAR struct netlink_response_s *
+netlink_get_device(FAR struct net_driver_s *dev,
+                   FAR const struct nlroute_sendto_request_s *req)
 {
   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);
-  DEBUGASSERT(info->handle != NULL && info->req != NULL);
-
-  /* Check if the link is in the UP state */
-
-  if ((dev->d_flags & IFF_UP) == 0)
-    {
-      /* No.. skip this device */
-
-      return 0;
-    }
+  int up = IFF_IS_UP(dev->d_flags);
 
   /* Allocate the response buffer */
 
@@ -218,7 +207,7 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
   if (alloc == NULL)
     {
       nerr("ERROR: Failed to allocate response buffer.\n");
-      return -ENOMEM;
+      return NULL;
     }
 
   /* Initialize the response buffer */
@@ -226,12 +215,12 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
   resp                   = &alloc->payload;
 
   resp->hdr.nlmsg_len    = sizeof(struct getlink_recvfrom_response_s);
-  resp->hdr.nlmsg_type   = RTM_NEWLINK;
-  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->hdr.nlmsg_type   = up ? RTM_NEWLINK : RTM_DELLINK;
+  resp->hdr.nlmsg_flags  = req ? req->hdr.nlmsg_flags : 0;
+  resp->hdr.nlmsg_seq    = req ? req->hdr.nlmsg_seq : 0;
+  resp->hdr.nlmsg_pid    = req ? req->hdr.nlmsg_pid : 0;
 
-  resp->iface.ifi_family = info->req->gen.rtgen_family;
+  resp->iface.ifi_family = req ? req->gen.rtgen_family : AF_PACKET;
   resp->iface.ifi_type   = dev->d_lltype;
 #ifdef CONFIG_NETDEV_IFINDEX
   resp->iface.ifi_index  = dev->d_ifindex;
@@ -244,23 +233,22 @@ static int netlink_device_callback(FAR struct net_driver_s *dev,
 
   strncpy((FAR char *)resp->data, dev->d_ifname, IFNAMSIZ);
 
-  /* Finally, add the data to the list of pending responses */
+  /* Finally, return the response */
 
-  netlink_add_response(info->handle, (FAR struct netlink_response_s *)alloc);
-  return OK;
+  return (FAR struct netlink_response_s *)alloc;
 }
 #endif
 
 /****************************************************************************
- * Name: netlink_response_terminator
+ * Name: netlink_get_terminator
  *
  * Description:
- *   Dump a list of all network devices of the specified type.
+ *   Generate one NLMSG_DONE response.
  *
  ****************************************************************************/
 
-static int netlink_response_terminator(NETLINK_HANDLE handle,
-                              FAR const struct nlroute_sendto_request_s *req)
+static FAR struct netlink_response_s *
+netlink_get_terminator(FAR const struct nlroute_sendto_request_s *req)
 {
   FAR struct netlink_response_s *resp;
   FAR struct nlmsghdr *hdr;
@@ -271,7 +259,7 @@ static int netlink_response_terminator(NETLINK_HANDLE handle,
   if (resp == NULL)
     {
       nerr("ERROR: Failed to allocate response terminator.\n");
-      return -ENOMEM;
+      return NULL;
     }
 
   /* Initialize and send the list terminator */
@@ -279,11 +267,33 @@ static int netlink_response_terminator(NETLINK_HANDLE handle,
   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;
+  hdr->nlmsg_flags = req ? req->hdr.nlmsg_flags : 0;
+  hdr->nlmsg_seq   = req ? req->hdr.nlmsg_seq : 0;
+  hdr->nlmsg_pid   = req ? req->hdr.nlmsg_pid : 0;
 
-  /* Finally, add the response to the list of pending responses */
+  /* Finally, return the response */
+
+  return resp;
+}
+
+/****************************************************************************
+ * Name: netlink_add_terminator
+ *
+ * Description:
+ *   Add one NLMSG_DONE response to handle.
+ *
+ ****************************************************************************/
+
+static int netlink_add_terminator(NETLINK_HANDLE handle,
+                              FAR const struct nlroute_sendto_request_s *req)
+{
+  FAR struct netlink_response_s * resp;
+
+  resp = netlink_get_terminator(req);
+  if (resp == NULL)
+    {
+      return -ENOMEM;
+    }
 
   netlink_add_response(handle, resp);
   return OK;
@@ -298,6 +308,22 @@ static int netlink_response_terminator(NETLINK_HANDLE handle,
  ****************************************************************************/
 
 #ifndef CONFIG_NETLINK_DISABLE_GETLINK
+static int netlink_device_callback(FAR struct net_driver_s *dev,
+                                   FAR void *arg)
+{
+  FAR struct nlroute_info_s *info = arg;
+  FAR struct netlink_response_s * resp;
+
+  resp = netlink_get_device(dev, info->req);
+  if (resp == NULL)
+    {
+      return -ENOMEM;
+    }
+
+  netlink_add_response(info->handle, resp);
+  return OK;
+}
+
 static int netlink_get_devlist(NETLINK_HANDLE handle,
                               FAR const struct nlroute_sendto_request_s *req)
 {
@@ -317,7 +343,7 @@ static int netlink_get_devlist(NETLINK_HANDLE handle,
       return ret;
     }
 
-  return netlink_response_terminator(handle, req);
+  return netlink_add_terminator(handle, req);
 }
 #endif
 
@@ -576,7 +602,7 @@ static int netlink_get_ipv4route(NETLINK_HANDLE handle,
 
   /* Terminate the routing table */
 
-  return netlink_response_terminator(handle, req);
+  return netlink_add_terminator(handle, req);
 }
 #endif
 
@@ -669,7 +695,7 @@ static int netlink_get_ip6vroute(NETLINK_HANDLE handle,
 
   /* Terminate the routing table */
 
-  return netlink_response_terminator(handle, req);
+  return netlink_add_terminator(handle, req);
 }
 #endif
 
@@ -784,4 +810,33 @@ ssize_t netlink_route_sendto(NETLINK_HANDLE handle,
   return ret;
 }
 
+/****************************************************************************
+ * Name: netlink_device_notify()
+ *
+ * Description:
+ *   Perform the route broadcast for the NETLINK_ROUTE protocol.
+ *
+ ****************************************************************************/
+
+#ifndef CONFIG_NETLINK_DISABLE_GETLINK
+void netlink_device_notify(FAR struct net_driver_s *dev)
+{
+  FAR struct netlink_response_s *resp;
+
+  DEBUGASSERT(dev != NULL);
+
+  resp = netlink_get_device(dev, NULL);
+  if (resp != NULL)
+    {
+      netlink_add_broadcast(RTNLGRP_LINK, resp);
+
+      resp = netlink_get_terminator(NULL);
+      if (resp != NULL)
+        {
+          netlink_add_broadcast(RTNLGRP_LINK, resp);
+        }
+    }
+}
+#endif
+
 #endif /* CONFIG_NETLINK_ROUTE */