You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/11/26 05:47:17 UTC

[GitHub] [incubator-nuttx] anchao commented on a change in pull request #4895: Optimize arp table

anchao commented on a change in pull request #4895:
URL: https://github.com/apache/incubator-nuttx/pull/4895#discussion_r757239744



##########
File path: net/arp/arp_table.c
##########
@@ -393,6 +398,32 @@ void arp_delete(in_addr_t ipaddr)
     }
 }
 
+/****************************************************************************
+ * Name: arp_cleanup
+ *
+ * Description:
+ *   Clear the ARP table on the network device
+ *
+ * Input Parameters:
+ *   dev  - The device driver structure
+ *
+ * Assumptions
+ *   The network is locked to assure exclusive access to the ARP table.
+ *
+ ****************************************************************************/
+
+void arp_cleanup(FAR struct net_driver_s *dev)
+{
+  int i;

Review comment:
       add a blank line after the variable definition

##########
File path: include/nuttx/net/arp.h
##########
@@ -85,6 +85,7 @@ struct arp_entry_s
   in_addr_t         at_ipaddr;   /* IP address */
   struct ether_addr at_ethaddr;  /* Hardware address */
   clock_t           at_time;     /* Time of last usage */
+  FAR struct net_driver_s *at_dev;

Review comment:
       align with other member

##########
File path: net/netdev/netdev_ioctl.c
##########
@@ -1256,15 +1289,11 @@ static int netdev_arp_ioctl(FAR struct socket *psock, int cmd,
               req->arp_pa.sa_family == AF_INET &&
               req->arp_ha.sa_family == ARPHRD_ETHER)
             {
-              FAR struct sockaddr_in *addr =
-                (FAR struct sockaddr_in *)&req->arp_pa;
-
               /* Update any existing ARP table entry for this protocol
                * address -OR- add a new ARP table entry if there is not.
                */
 
-              ret = arp_update(addr->sin_addr.s_addr,
-                               (FAR uint8_t *)req->arp_ha.sa_data);
+              ret = netdev_foreach(netdev_arp_callback, req)? OK : -EINVAL;

Review comment:
       space before ?

##########
File path: net/netdev/netdev_ioctl.c
##########
@@ -1222,6 +1222,39 @@ static int netdev_imsf_ioctl(FAR struct socket *psock, int cmd,
 }
 #endif
 
+/****************************************************************************
+ * Name: netdev_arp_callback
+ *
+ * Description:
+ *   This is a callback that checks if the Ethernet network device has the
+ *   indicated name
+ *
+ * Input Parameters:
+ *   dev    Ethernet driver device structure
+ *   req    The argument of the ioctl cmd
+ *
+ * Returned Value:
+ *   1 on success
+ *   0 on error
+ ****************************************************************************/
+
+#ifdef CONFIG_NET_ARP
+static int netdev_arp_callback(FAR struct net_driver_s *dev, FAR void *arg)
+{
+  FAR struct arpreq *req = arg;
+  FAR struct sockaddr_in *addr = (FAR struct sockaddr_in *)&req->arp_pa;
+  if (strncmp(dev->d_ifname, (FAR const char *)req->arp_dev,
+       sizeof(dev->d_ifname)))
+    {
+      return 0;
+    }
+
+  arp_update(dev, addr->sin_addr.s_addr,
+              (FAR uint8_t *)req->arp_ha.sa_data);

Review comment:
       align with first input parameter

##########
File path: net/netdev/netdev_ioctl.c
##########
@@ -1222,6 +1222,39 @@ static int netdev_imsf_ioctl(FAR struct socket *psock, int cmd,
 }
 #endif
 
+/****************************************************************************
+ * Name: netdev_arp_callback
+ *
+ * Description:
+ *   This is a callback that checks if the Ethernet network device has the
+ *   indicated name
+ *
+ * Input Parameters:
+ *   dev    Ethernet driver device structure
+ *   req    The argument of the ioctl cmd
+ *
+ * Returned Value:
+ *   1 on success
+ *   0 on error
+ ****************************************************************************/
+
+#ifdef CONFIG_NET_ARP
+static int netdev_arp_callback(FAR struct net_driver_s *dev, FAR void *arg)
+{
+  FAR struct arpreq *req = arg;
+  FAR struct sockaddr_in *addr = (FAR struct sockaddr_in *)&req->arp_pa;

Review comment:
       add a blank line after the variable definition

##########
File path: net/netdev/netdev_ioctl.c
##########
@@ -1222,6 +1222,39 @@ static int netdev_imsf_ioctl(FAR struct socket *psock, int cmd,
 }
 #endif
 
+/****************************************************************************
+ * Name: netdev_arp_callback
+ *
+ * Description:
+ *   This is a callback that checks if the Ethernet network device has the
+ *   indicated name
+ *
+ * Input Parameters:
+ *   dev    Ethernet driver device structure
+ *   req    The argument of the ioctl cmd
+ *
+ * Returned Value:
+ *   1 on success
+ *   0 on error
+ ****************************************************************************/
+
+#ifdef CONFIG_NET_ARP
+static int netdev_arp_callback(FAR struct net_driver_s *dev, FAR void *arg)
+{
+  FAR struct arpreq *req = arg;
+  FAR struct sockaddr_in *addr = (FAR struct sockaddr_in *)&req->arp_pa;
+  if (strncmp(dev->d_ifname, (FAR const char *)req->arp_dev,
+       sizeof(dev->d_ifname)))

Review comment:
       align with first input parameter




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org