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/01/30 13:47:46 UTC

[incubator-nuttx] 01/03: net/: Fix net checksum related issue

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 affc32c9d13950b1b50250d02556cdbce8f7060d
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Thu Jan 30 15:45:15 2020 +0800

    net/:  Fix net checksum related issue
    
    1. Remove the unused and unimplemented ipv6_chksum declaration
    2. Update NET_ARCH_CHKSUM description to align with the implementation
    3. Declare all checksum function prototype regardless CONFIG_NET_ARCH_CHKSUM
    4. Remove the CONFIG_NET_ARCH_CHKSUM guard for tcp_ipv[4|6]_chksum
---
 include/nuttx/net/netdev.h | 21 ---------------------
 net/utils/Kconfig          |  7 +++----
 net/utils/net_chksum.c     | 15 ---------------
 net/utils/net_icmpchksum.c |  5 -----
 net/utils/net_incr32.c     |  9 ---------
 net/utils/net_ipchksum.c   |  2 --
 net/utils/net_tcpchksum.c  |  6 ------
 net/utils/net_udpchksum.c  |  4 ----
 net/utils/utils.h          | 10 ++--------
 9 files changed, 5 insertions(+), 74 deletions(-)

diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h
index 6c67c56..3ab2fc9 100644
--- a/include/nuttx/net/netdev.h
+++ b/include/nuttx/net/netdev.h
@@ -697,27 +697,6 @@ uint16_t ipv4_chksum(FAR struct net_driver_s *dev);
 #endif
 
 /****************************************************************************
- * Name: ipv6_chksum
- *
- * Description:
- *   Calculate the IPv6 header checksum of the packet header in d_buf.
- *
- *   The IPv6 header checksum is the Internet checksum of the 40 bytes of
- *   the IPv6 header.
- *
- *   If CONFIG_NET_ARCH_CHKSUM is defined, then this function must be
- *   provided by architecture-specific logic.
- *
- * Returned Value:
- *   The IPv6 header checksum of the IPv6 header in the d_buf buffer.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_NET_IPv6
-uint16_t ipv6_chksum(FAR struct net_driver_s *dev);
-#endif
-
-/****************************************************************************
  * Name: netdev_ipv4_hdrlen
  *
  * Description:
diff --git a/net/utils/Kconfig b/net/utils/Kconfig
index 771bb2b..7eeb537 100644
--- a/net/utils/Kconfig
+++ b/net/utils/Kconfig
@@ -19,9 +19,8 @@ config NET_ARCH_CHKSUM
 		Define if you architecture provided an optimized version of
 		functions with the following prototypes:
 
+			uint16_t chksum(uint16_t sum, FAR const uint8_t *data, uint16_t len)
 			uint16_t net_chksum(FAR uint16_t *data, uint16_t len)
 			uint16_t ipv4_chksum(FAR struct net_driver_s *dev)
-			uint16_t tcp_ipv4_chksum(FAR struct net_driver_s *dev);
-			uint16_t tcp_ipv6_chksum(FAR struct net_driver_s *dev);
-			uint16_t udp_ipv4_chksum(FAR struct net_driver_s *dev);
-			uint16_t udp_ipv6_chksum(FAR struct net_driver_s *dev);
+			uint16_t ipv4_upperlayer_chksum(FAR struct net_driver_s *dev, uint8_t proto)
+			uint16_t ipv6_upperlayer_chksum(FAR struct net_driver_s *dev, uint8_t proto, unsigned int iplen)
diff --git a/net/utils/net_chksum.c b/net/utils/net_chksum.c
index ac5095f..0242159 100644
--- a/net/utils/net_chksum.c
+++ b/net/utils/net_chksum.c
@@ -41,24 +41,9 @@
 #include <nuttx/config.h>
 #ifdef CONFIG_NET
 
-#include <stdint.h>
-#include <debug.h>
-
-#include <nuttx/net/netconfig.h>
-#include <nuttx/net/netdev.h>
-#include <nuttx/net/ip.h>
-#include <nuttx/net/icmp.h>
-
 #include "utils/utils.h"
 
 /****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define IPv4BUF   ((struct ipv4_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
-#define IPv6BUF   ((struct ipv6_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
-
-/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
diff --git a/net/utils/net_icmpchksum.c b/net/utils/net_icmpchksum.c
index b17f532..dc9d84f 100644
--- a/net/utils/net_icmpchksum.c
+++ b/net/utils/net_icmpchksum.c
@@ -40,10 +40,6 @@
 #include <nuttx/config.h>
 #ifdef CONFIG_NET
 
-#include <stdint.h>
-#include <debug.h>
-
-#include <nuttx/net/netconfig.h>
 #include <nuttx/net/netdev.h>
 #include <nuttx/net/icmp.h>
 
@@ -55,7 +51,6 @@
 
 #define IPv4BUF     ((FAR struct ipv4_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
 #define ICMPBUF(hl) ((FAR struct icmp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + (hl)])
-#define ICMPv6BUF   ((struct icmp_ipv6hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
 
 /****************************************************************************
  * Public Functions
diff --git a/net/utils/net_incr32.c b/net/utils/net_incr32.c
index c50695e..841de1d 100644
--- a/net/utils/net_incr32.c
+++ b/net/utils/net_incr32.c
@@ -39,16 +39,7 @@
  ****************************************************************************/
 
 #include <nuttx/config.h>
-
-#include <stdint.h>
-#include <debug.h>
-
-#include <nuttx/net/netconfig.h>
 #include <nuttx/net/netdev.h>
-#include <nuttx/net/ip.h>
-#include <nuttx/net/icmp.h>
-
-#include "utils/utils.h"
 
 #ifndef CONFIG_NET_ARCH_INCR32
 
diff --git a/net/utils/net_ipchksum.c b/net/utils/net_ipchksum.c
index 1ec2951..d3e4057 100644
--- a/net/utils/net_ipchksum.c
+++ b/net/utils/net_ipchksum.c
@@ -40,10 +40,8 @@
 
 #include <nuttx/config.h>
 
-#include <stdint.h>
 #include <assert.h>
 
-#include <nuttx/net/netconfig.h>
 #include <nuttx/net/netdev.h>
 #include <nuttx/net/ip.h>
 
diff --git a/net/utils/net_tcpchksum.c b/net/utils/net_tcpchksum.c
index 2f96f2a..3c53890 100644
--- a/net/utils/net_tcpchksum.c
+++ b/net/utils/net_tcpchksum.c
@@ -39,10 +39,6 @@
  ****************************************************************************/
 
 #include <nuttx/config.h>
-
-#include <stdint.h>
-
-#include <nuttx/net/netconfig.h>
 #include <nuttx/net/netdev.h>
 
 #include "utils/utils.h"
@@ -72,7 +68,6 @@
  *
  ****************************************************************************/
 
-#ifndef CONFIG_NET_ARCH_CHKSUM
 #ifdef CONFIG_NET_IPv4
 uint16_t tcp_ipv4_chksum(FAR struct net_driver_s *dev)
 {
@@ -86,7 +81,6 @@ uint16_t tcp_ipv6_chksum(FAR struct net_driver_s *dev)
   return ipv6_upperlayer_chksum(dev, IP_PROTO_TCP, IPv6_HDRLEN);
 }
 #endif /* CONFIG_NET_IPv6 */
-#endif /* !CONFIG_NET_ARCH_CHKSUM */
 
 #if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
 uint16_t tcp_chksum(FAR struct net_driver_s *dev)
diff --git a/net/utils/net_udpchksum.c b/net/utils/net_udpchksum.c
index 533475b..462ba1a 100644
--- a/net/utils/net_udpchksum.c
+++ b/net/utils/net_udpchksum.c
@@ -39,10 +39,6 @@
  ****************************************************************************/
 
 #include <nuttx/config.h>
-
-#include <stdint.h>
-
-#include <nuttx/net/netconfig.h>
 #include <nuttx/net/netdev.h>
 
 #include "utils/utils.h"
diff --git a/net/utils/utils.h b/net/utils/utils.h
index a09b905..e47ded9 100644
--- a/net/utils/utils.h
+++ b/net/utils/utils.h
@@ -234,9 +234,7 @@ void net_ipv6_pref2mask(uint8_t preflen, net_ipv6addr_t mask);
  *
  ****************************************************************************/
 
-#ifndef CONFIG_NET_ARCH_CHKSUM
 uint16_t chksum(uint16_t sum, FAR const uint8_t *data, uint16_t len);
-#endif
 
 /****************************************************************************
  * Name: net_chksum
@@ -263,9 +261,7 @@ uint16_t chksum(uint16_t sum, FAR const uint8_t *data, uint16_t len);
  *
  ****************************************************************************/
 
-#ifndef CONFIG_NET_ARCH_CHKSUM
 uint16_t net_chksum(FAR uint16_t *data, uint16_t len);
-#endif
 
 /****************************************************************************
  * Name: ipv4_upperlayer_chksum
@@ -284,7 +280,7 @@ uint16_t net_chksum(FAR uint16_t *data, uint16_t len);
  *
  ****************************************************************************/
 
-#if !defined(CONFIG_NET_ARCH_CHKSUM) && defined(CONFIG_NET_IPv4)
+#ifdef CONFIG_NET_IPv4
 uint16_t ipv4_upperlayer_chksum(FAR struct net_driver_s *dev, uint8_t proto);
 #endif
 
@@ -308,7 +304,7 @@ uint16_t ipv4_upperlayer_chksum(FAR struct net_driver_s *dev, uint8_t proto);
  *
  ****************************************************************************/
 
-#if !defined(CONFIG_NET_ARCH_CHKSUM) && defined(CONFIG_NET_IPv6)
+#ifdef CONFIG_NET_IPv6
 uint16_t ipv6_upperlayer_chksum(FAR struct net_driver_s *dev,
                                 uint8_t proto, unsigned int iplen);
 #endif
@@ -337,8 +333,6 @@ uint16_t tcp_ipv4_chksum(FAR struct net_driver_s *dev);
 #endif
 
 #ifdef CONFIG_NET_IPv6
-/* REVIST: Is this used? */
-
 uint16_t tcp_ipv6_chksum(FAR struct net_driver_s *dev);
 #endif