Clean-up naming associated with network checksums
This commit is contained in:
parent
fce2a79abd
commit
50b749a636
15 changed files with 309 additions and 124 deletions
|
|
@ -330,68 +330,71 @@ int uip_timer(struct net_driver_s *dev, uip_poll_callback_t callback, int hsec);
|
||||||
int netdev_carrier_on(FAR struct net_driver_s *dev);
|
int netdev_carrier_on(FAR struct net_driver_s *dev);
|
||||||
int netdev_carrier_off(FAR struct net_driver_s *dev);
|
int netdev_carrier_off(FAR struct net_driver_s *dev);
|
||||||
|
|
||||||
/* By defining UIP_ARCH_CHKSUM, the architecture can replace up_incr32
|
/****************************************************************************
|
||||||
* with hardware assisted solutions.
|
* Name: net_chksum
|
||||||
*/
|
*
|
||||||
|
* Description:
|
||||||
|
* Calculate the Internet checksum over a buffer.
|
||||||
|
*
|
||||||
|
* The Internet checksum is the one's complement of the one's complement
|
||||||
|
* sum of all 16-bit words in the buffer.
|
||||||
|
*
|
||||||
|
* See RFC1071.
|
||||||
|
*
|
||||||
|
* If CONFIG_NET_ARCH_CHKSUM is defined, then this function must be
|
||||||
|
* provided by architecture-specific logic.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
*
|
||||||
|
* buf - A pointer to the buffer over which the checksum is to be computed.
|
||||||
|
*
|
||||||
|
* len - The length of the buffer over which the checksum is to be computed.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* The Internet checksum of the buffer.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
/* Carry out a 32-bit addition.
|
uint16_t net_chksum(FAR uint16_t *data, uint16_t len);
|
||||||
*
|
|
||||||
* op32 - A pointer to a 4-byte array representing a 32-bit
|
|
||||||
* integer in network byte order (big endian). This value may not
|
|
||||||
* be word aligned. The value pointed to by op32 is modified in place
|
|
||||||
*
|
|
||||||
* op16 - A 16-bit integer in host byte order.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void uip_incr32(uint8_t *op32, uint16_t op16);
|
/****************************************************************************
|
||||||
|
* Name: net_incr32
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
*
|
||||||
|
* Carry out a 32-bit addition.
|
||||||
|
*
|
||||||
|
* By defining CONFIG_NET_ARCH_INCR32, the architecture can replace
|
||||||
|
* net_incr32 with hardware assisted solutions.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* op32 - A pointer to a 4-byte array representing a 32-bit integer in
|
||||||
|
* network byte order (big endian). This value may not be word
|
||||||
|
* aligned. The value pointed to by op32 is modified in place
|
||||||
|
*
|
||||||
|
* op16 - A 16-bit integer in host byte order.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
/* Calculate the Internet checksum over a buffer.
|
void net_incr32(FAR uint8_t *op32, uint16_t op16);
|
||||||
*
|
|
||||||
* The Internet checksum is the one's complement of the one's
|
|
||||||
* complement sum of all 16-bit words in the buffer.
|
|
||||||
*
|
|
||||||
* See RFC1071.
|
|
||||||
*
|
|
||||||
* Note: This function is not called in the current version of uIP,
|
|
||||||
* but future versions might make use of it.
|
|
||||||
*
|
|
||||||
* buf A pointer to the buffer over which the checksum is to be
|
|
||||||
* computed.
|
|
||||||
*
|
|
||||||
* len The length of the buffer over which the checksum is to
|
|
||||||
* be computed.
|
|
||||||
*
|
|
||||||
* Return: The Internet checksum of the buffer.
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint16_t uip_chksum(uint16_t *buf, uint16_t len);
|
/****************************************************************************
|
||||||
|
* Name: ip_chksum
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Calculate the IP header checksum of the packet header in d_buf.
|
||||||
|
*
|
||||||
|
* The IP header checksum is the Internet checksum of the 20 bytes of
|
||||||
|
* the IP header.
|
||||||
|
*
|
||||||
|
* If CONFIG_NET_ARCH_CHKSUM is defined, then this function must be
|
||||||
|
* provided by architecture-specific logic.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* The IP header checksum of the IP header in the d_buf buffer.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
/* Calculate the IP header checksum of the packet header in d_buf.
|
uint16_t ip_chksum(FAR struct net_driver_s *dev);
|
||||||
*
|
|
||||||
* The IP header checksum is the Internet checksum of the 20 bytes of
|
|
||||||
* the IP header.
|
|
||||||
*
|
|
||||||
* Return: The IP header checksum of the IP header in the d_buf
|
|
||||||
* buffer.
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint16_t uip_ipchksum(struct net_driver_s *dev);
|
|
||||||
|
|
||||||
/* Calculate the TCP checksum of the packet in d_buf and d_appdata.
|
|
||||||
*
|
|
||||||
* The TCP checksum is the Internet checksum of data contents of the
|
|
||||||
* TCP segment, and a pseudo-header as defined in RFC793.
|
|
||||||
*
|
|
||||||
* Note: The d_appdata pointer that points to the packet data may
|
|
||||||
* point anywhere in memory, so it is not possible to simply calculate
|
|
||||||
* the Internet checksum of the contents of the d_buf buffer.
|
|
||||||
*
|
|
||||||
* Return: The TCP checksum of the TCP segment in d_buf and pointed
|
|
||||||
* to by d_appdata.
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint16_t tcp_chksum(struct net_driver_s *dev);
|
|
||||||
uint16_t udp_chksum(struct net_driver_s *dev);
|
|
||||||
uint16_t icmp_chksum(struct net_driver_s *dev, int len);
|
|
||||||
|
|
||||||
#endif /* __INCLUDE_NUTTX_NET_NETDEV_H */
|
#endif /* __INCLUDE_NUTTX_NET_NETDEV_H */
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ typedef uip_ip4addr_t uip_ipaddr_t;
|
||||||
|
|
||||||
/* The IP header */
|
/* The IP header */
|
||||||
|
|
||||||
struct uip_ip_hdr
|
struct net_iphdr_s
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ Directory Structure
|
||||||
+- devif - Stack/device interface layer
|
+- devif - Stack/device interface layer
|
||||||
+- icmp - Internet Control Message Protocol
|
+- icmp - Internet Control Message Protocol
|
||||||
+- iob - I/O buffering logic
|
+- iob - I/O buffering logic
|
||||||
|
+- ipv6 - Logic unique to IPv6
|
||||||
+- netdev - Socket network device interface
|
+- netdev - Socket network device interface
|
||||||
+- pkt - "Raw" packet socket support
|
+- pkt - "Raw" packet socket support
|
||||||
+- socket - BSD socket interface
|
+- socket - BSD socket interface
|
||||||
|
|
@ -21,18 +22,18 @@ Directory Structure
|
||||||
`- utils - Miscellaneous utility functions
|
`- utils - Miscellaneous utility functions
|
||||||
|
|
||||||
|
|
||||||
+-------------------------------------------------------------+
|
+----------------------------------------------------------------+
|
||||||
| Application layer |
|
| Application layer |
|
||||||
+-------------------------------------------------------------+
|
+----------------------------------------------------------------+
|
||||||
+-------------------------------------------------------------+
|
+----------------------------------------------------------------+
|
||||||
| Socket layer (socket/) |
|
| Socket layer (socket/) |
|
||||||
+-------------------------------------------------------------+
|
+----------------------------------------------------------------+
|
||||||
+------------++-----------------------------------------------+
|
+------------++--------------------------------------------------+
|
||||||
| Network || Protocol stacks (arp, icmp, pkt, tcp, udp) |
|
| Network || Protocol stacks (arp, ipv6, icmp, pkt, tcp, udp) |
|
||||||
| Device |+-----------------------------------------------+
|
| Device |+--------------------------------------------------+
|
||||||
| Interface |+---------------------------------++------------+
|
| Interface |+------------------------------------++------------+
|
||||||
| (netdev/) ||Network Device Interface (devif/)|| Utilities |
|
| (netdev/) || Network Device Interface (devif/) || Utilities |
|
||||||
+------------++---------------------------------++------------+
|
+------------++------------------------------------++------------+
|
||||||
+-------------------------------------------------------------+
|
+----------------------------------------------------------------+
|
||||||
| Network Device Drivers |
|
| Network Device Drivers |
|
||||||
+-------------------------------------------------------------+
|
+----------------------------------------------------------------+
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@
|
||||||
|
|
||||||
#include "uip/uip.h"
|
#include "uip/uip.h"
|
||||||
#include "icmp/icmp.h"
|
#include "icmp/icmp.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
#ifdef CONFIG_NET_ICMP
|
#ifdef CONFIG_NET_ICMP
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@
|
||||||
#include <nuttx/net/netstats.h>
|
#include <nuttx/net/netstats.h>
|
||||||
|
|
||||||
#include "uip/uip.h"
|
#include "uip/uip.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
#include "icmp/icmp.h"
|
#include "icmp/icmp.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
@ -144,7 +145,7 @@ void icmp_send(FAR struct net_driver_s *dev, FAR uip_ipaddr_t *destaddr)
|
||||||
/* Calculate IP checksum. */
|
/* Calculate IP checksum. */
|
||||||
|
|
||||||
picmp->ipchksum = 0;
|
picmp->ipchksum = 0;
|
||||||
picmp->ipchksum = ~(uip_ipchksum(dev));
|
picmp->ipchksum = ~(ip_chksum(dev));
|
||||||
|
|
||||||
#endif /* CONFIG_NET_IPv6 */
|
#endif /* CONFIG_NET_IPv6 */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ void igmp_input(struct net_driver_s *dev)
|
||||||
|
|
||||||
/* Calculate and check the IGMP checksum */
|
/* Calculate and check the IGMP checksum */
|
||||||
|
|
||||||
if (uip_chksum((uint16_t*)&IGMPBUF->type, UIP_IGMPH_LEN) != 0)
|
if (net_chksum((uint16_t*)&IGMPBUF->type, UIP_IGMPH_LEN) != 0)
|
||||||
{
|
{
|
||||||
IGMP_STATINCR(g_netstats.igmp.chksum_errors);
|
IGMP_STATINCR(g_netstats.igmp.chksum_errors);
|
||||||
nlldbg("Checksum error\n");
|
nlldbg("Checksum error\n");
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@
|
||||||
|
|
||||||
static uint16_t igmp_chksum(FAR uint8_t *buffer, int buflen)
|
static uint16_t igmp_chksum(FAR uint8_t *buffer, int buflen)
|
||||||
{
|
{
|
||||||
uint16_t sum = uip_chksum((FAR uint16_t*)buffer, buflen);
|
uint16_t sum = net_chksum((FAR uint16_t*)buffer, buflen);
|
||||||
return sum ? sum : 0xffff;
|
return sum ? sum : 0xffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@
|
||||||
#include <nuttx/net/netstats.h>
|
#include <nuttx/net/netstats.h>
|
||||||
|
|
||||||
#include "uip/uip.h"
|
#include "uip/uip.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
#include "tcp/tcp.h"
|
#include "tcp/tcp.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
@ -210,7 +211,7 @@ void tcp_input(struct net_driver_s *dev)
|
||||||
goto drop;
|
goto drop;
|
||||||
}
|
}
|
||||||
|
|
||||||
uip_incr32(conn->rcvseq, 1);
|
net_incr32(conn->rcvseq, 1);
|
||||||
|
|
||||||
/* Parse the TCP MSS option, if present. */
|
/* Parse the TCP MSS option, if present. */
|
||||||
|
|
||||||
|
|
@ -474,7 +475,7 @@ found:
|
||||||
if (dev->d_len > 0)
|
if (dev->d_len > 0)
|
||||||
{
|
{
|
||||||
flags |= UIP_NEWDATA;
|
flags |= UIP_NEWDATA;
|
||||||
uip_incr32(conn->rcvseq, dev->d_len);
|
net_incr32(conn->rcvseq, dev->d_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
dev->d_sndlen = 0;
|
dev->d_sndlen = 0;
|
||||||
|
|
@ -557,7 +558,7 @@ found:
|
||||||
conn->tcpstateflags = UIP_ESTABLISHED;
|
conn->tcpstateflags = UIP_ESTABLISHED;
|
||||||
memcpy(conn->rcvseq, pbuf->seqno, 4);
|
memcpy(conn->rcvseq, pbuf->seqno, 4);
|
||||||
|
|
||||||
uip_incr32(conn->rcvseq, 1);
|
net_incr32(conn->rcvseq, 1);
|
||||||
conn->unacked = 0;
|
conn->unacked = 0;
|
||||||
|
|
||||||
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
|
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
|
||||||
|
|
@ -623,7 +624,7 @@ found:
|
||||||
* been closed.
|
* been closed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uip_incr32(conn->rcvseq, dev->d_len + 1);
|
net_incr32(conn->rcvseq, dev->d_len + 1);
|
||||||
flags |= UIP_CLOSE;
|
flags |= UIP_CLOSE;
|
||||||
|
|
||||||
if (dev->d_len > 0)
|
if (dev->d_len > 0)
|
||||||
|
|
@ -657,7 +658,7 @@ found:
|
||||||
dev->d_urglen = dev->d_len;
|
dev->d_urglen = dev->d_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
uip_incr32(conn->rcvseq, dev->d_urglen);
|
net_incr32(conn->rcvseq, dev->d_urglen);
|
||||||
dev->d_len -= dev->d_urglen;
|
dev->d_len -= dev->d_urglen;
|
||||||
dev->d_urgdata = dev->d_appdata;
|
dev->d_urgdata = dev->d_appdata;
|
||||||
dev->d_appdata += dev->d_urglen;
|
dev->d_appdata += dev->d_urglen;
|
||||||
|
|
@ -724,7 +725,7 @@ found:
|
||||||
{
|
{
|
||||||
/* Update the sequence number using the saved length */
|
/* Update the sequence number using the saved length */
|
||||||
|
|
||||||
uip_incr32(conn->rcvseq, len);
|
net_incr32(conn->rcvseq, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send the response, ACKing the data or not, as appropriate */
|
/* Send the response, ACKing the data or not, as appropriate */
|
||||||
|
|
@ -757,7 +758,7 @@ found:
|
||||||
|
|
||||||
if (dev->d_len > 0)
|
if (dev->d_len > 0)
|
||||||
{
|
{
|
||||||
uip_incr32(conn->rcvseq, dev->d_len);
|
net_incr32(conn->rcvseq, dev->d_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pbuf->flags & TCP_FIN) != 0)
|
if ((pbuf->flags & TCP_FIN) != 0)
|
||||||
|
|
@ -775,7 +776,7 @@ found:
|
||||||
nllvdbg("TCP state: UIP_CLOSING\n");
|
nllvdbg("TCP state: UIP_CLOSING\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
uip_incr32(conn->rcvseq, 1);
|
net_incr32(conn->rcvseq, 1);
|
||||||
(void)tcp_callback(dev, conn, UIP_CLOSE);
|
(void)tcp_callback(dev, conn, UIP_CLOSE);
|
||||||
tcp_send(dev, conn, TCP_ACK, UIP_IPTCPH_LEN);
|
tcp_send(dev, conn, TCP_ACK, UIP_IPTCPH_LEN);
|
||||||
return;
|
return;
|
||||||
|
|
@ -799,7 +800,7 @@ found:
|
||||||
case UIP_FIN_WAIT_2:
|
case UIP_FIN_WAIT_2:
|
||||||
if (dev->d_len > 0)
|
if (dev->d_len > 0)
|
||||||
{
|
{
|
||||||
uip_incr32(conn->rcvseq, dev->d_len);
|
net_incr32(conn->rcvseq, dev->d_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pbuf->flags & TCP_FIN) != 0)
|
if ((pbuf->flags & TCP_FIN) != 0)
|
||||||
|
|
@ -808,7 +809,7 @@ found:
|
||||||
conn->timer = 0;
|
conn->timer = 0;
|
||||||
nllvdbg("TCP state: UIP_TIME_WAIT\n");
|
nllvdbg("TCP state: UIP_TIME_WAIT\n");
|
||||||
|
|
||||||
uip_incr32(conn->rcvseq, 1);
|
net_incr32(conn->rcvseq, 1);
|
||||||
(void)tcp_callback(dev, conn, UIP_CLOSE);
|
(void)tcp_callback(dev, conn, UIP_CLOSE);
|
||||||
tcp_send(dev, conn, TCP_ACK, UIP_IPTCPH_LEN);
|
tcp_send(dev, conn, TCP_ACK, UIP_IPTCPH_LEN);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@
|
||||||
#include <nuttx/net/netstats.h>
|
#include <nuttx/net/netstats.h>
|
||||||
|
|
||||||
#include "uip/uip.h"
|
#include "uip/uip.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
|
|
@ -139,7 +140,7 @@ static void tcp_sendcomplete(FAR struct net_driver_s *dev)
|
||||||
/* Calculate IP checksum. */
|
/* Calculate IP checksum. */
|
||||||
|
|
||||||
pbuf->ipchksum = 0;
|
pbuf->ipchksum = 0;
|
||||||
pbuf->ipchksum = ~(uip_ipchksum(dev));
|
pbuf->ipchksum = ~(ip_chksum(dev));
|
||||||
|
|
||||||
#endif /* CONFIG_NET_IPv6 */
|
#endif /* CONFIG_NET_IPv6 */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@
|
||||||
#include <nuttx/net/netstats.h>
|
#include <nuttx/net/netstats.h>
|
||||||
|
|
||||||
#include "uip/uip.h"
|
#include "uip/uip.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
#include "udp/udp.h"
|
#include "udp/udp.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@
|
||||||
#include <nuttx/net/netstats.h>
|
#include <nuttx/net/netstats.h>
|
||||||
|
|
||||||
#include "uip/uip.h"
|
#include "uip/uip.h"
|
||||||
|
#include "utils/utils.h"
|
||||||
#include "udp/udp.h"
|
#include "udp/udp.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
@ -144,7 +145,7 @@ void udp_send(struct net_driver_s *dev, struct udp_conn_s *conn)
|
||||||
/* Calculate IP checksum. */
|
/* Calculate IP checksum. */
|
||||||
|
|
||||||
pudpbuf->ipchksum = 0;
|
pudpbuf->ipchksum = 0;
|
||||||
pudpbuf->ipchksum = ~(uip_ipchksum(dev));
|
pudpbuf->ipchksum = ~(ip_chksum(dev));
|
||||||
|
|
||||||
#endif /* CONFIG_NET_IPv6 */
|
#endif /* CONFIG_NET_IPv6 */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,8 +107,8 @@
|
||||||
|
|
||||||
/* Macros. */
|
/* Macros. */
|
||||||
|
|
||||||
#define BUF ((struct uip_ip_hdr *)&dev->d_buf[UIP_LLH_LEN])
|
#define BUF ((FAR struct net_iphdr_s *)&dev->d_buf[UIP_LLH_LEN])
|
||||||
#define FBUF ((struct uip_ip_hdr *)&uip_reassbuf[0])
|
#define FBUF ((FAR struct net_iphdr_s *)&uip_reassbuf[0])
|
||||||
|
|
||||||
/* IP fragment re-assembly */
|
/* IP fragment re-assembly */
|
||||||
|
|
||||||
|
|
@ -149,8 +149,8 @@ static uint8_t uip_reassflags;
|
||||||
#if UIP_REASSEMBLY && !defined(CONFIG_NET_IPv6)
|
#if UIP_REASSEMBLY && !defined(CONFIG_NET_IPv6)
|
||||||
static uint8_t uip_reass(void)
|
static uint8_t uip_reass(void)
|
||||||
{
|
{
|
||||||
struct uip_ip_hdr *pbuf = BUF;
|
FAR struct net_iphdr_s *pbuf = BUF;
|
||||||
struct uip_ip_hdr *pfbuf = FBUF;
|
FAR struct net_iphdr_s *pfbuf = FBUF;
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
|
|
@ -277,7 +277,7 @@ static uint8_t uip_reass(void)
|
||||||
pbuf->len[0] = uip_reasslen >> 8;
|
pbuf->len[0] = uip_reasslen >> 8;
|
||||||
pbuf->len[1] = uip_reasslen & 0xff;
|
pbuf->len[1] = uip_reasslen & 0xff;
|
||||||
pbuf->ipchksum = 0;
|
pbuf->ipchksum = 0;
|
||||||
pbuf->ipchksum = ~(uip_ipchksum(dev));
|
pbuf->ipchksum = ~(ip_chksum(dev));
|
||||||
|
|
||||||
return uip_reasslen;
|
return uip_reasslen;
|
||||||
}
|
}
|
||||||
|
|
@ -307,9 +307,9 @@ nullreturn:
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int uip_input(struct net_driver_s *dev)
|
int uip_input(FAR struct net_driver_s *dev)
|
||||||
{
|
{
|
||||||
struct uip_ip_hdr *pbuf = BUF;
|
FAR struct net_iphdr_s *pbuf = BUF;
|
||||||
uint16_t iplen;
|
uint16_t iplen;
|
||||||
|
|
||||||
/* This is where the input processing starts. */
|
/* This is where the input processing starts. */
|
||||||
|
|
@ -491,7 +491,7 @@ int uip_input(struct net_driver_s *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CONFIG_NET_IPv6
|
#ifndef CONFIG_NET_IPv6
|
||||||
if (uip_ipchksum(dev) != 0xffff)
|
if (ip_chksum(dev) != 0xffff)
|
||||||
{
|
{
|
||||||
/* Compute and check the IP header checksum. */
|
/* Compute and check the IP header checksum. */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,24 @@
|
||||||
# For a description of the syntax of this configuration file,
|
# For a description of the syntax of this configuration file,
|
||||||
# see misc/tools/kconfig-language.txt.
|
# see misc/tools/kconfig-language.txt.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
config NET_ARCH_INCR32
|
||||||
|
bool "Architecture-specific net_incr32()"
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
Define if you architecture provided an optimized version of
|
||||||
|
net_incr32() with prototype:
|
||||||
|
|
||||||
|
void net_incr32(FAR uint8_t *op32, uint16_t op16)
|
||||||
|
|
||||||
|
config NET_ARCH_CHKSUM
|
||||||
|
bool "Architecture-specific net_chksum()"
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
Define if you architecture provided an optimized version of
|
||||||
|
functions with the following prototypes:
|
||||||
|
|
||||||
|
uint16_t net_chksum(FAR uint16_t *data, uint16_t len)
|
||||||
|
uint16_t ip_chksum(FAR struct net_driver_s *dev)
|
||||||
|
uint16_t tcp_chksum(FAR struct net_driver_s *dev);
|
||||||
|
uint16_t udp_chksum(FAR struct net_driver_s *dev);
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#define BUF ((struct uip_ip_hdr *)&dev->d_buf[UIP_LLH_LEN])
|
#define BUF ((struct net_iphdr_s *)&dev->d_buf[UIP_LLH_LEN])
|
||||||
#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[UIP_LLH_LEN])
|
#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[UIP_LLH_LEN])
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
@ -65,7 +65,11 @@
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if !UIP_ARCH_CHKSUM
|
/****************************************************************************
|
||||||
|
* Name: chksum
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if !CONFIG_NET_ARCH_CHKSUM
|
||||||
static uint16_t chksum(uint16_t sum, FAR const uint8_t *data, uint16_t len)
|
static uint16_t chksum(uint16_t sum, FAR const uint8_t *data, uint16_t len)
|
||||||
{
|
{
|
||||||
uint16_t t;
|
uint16_t t;
|
||||||
|
|
@ -103,10 +107,16 @@ static uint16_t chksum(uint16_t sum, FAR const uint8_t *data, uint16_t len)
|
||||||
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
#endif /* CONFIG_NET_ARCH_CHKSUM */
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: upper_layer_chksum
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if !CONFIG_NET_ARCH_CHKSUM
|
||||||
static uint16_t upper_layer_chksum(FAR struct net_driver_s *dev, uint8_t proto)
|
static uint16_t upper_layer_chksum(FAR struct net_driver_s *dev, uint8_t proto)
|
||||||
{
|
{
|
||||||
struct uip_ip_hdr *pbuf = BUF;
|
FAR struct net_iphdr_s *pbuf = BUF;
|
||||||
uint16_t upper_layer_len;
|
uint16_t upper_layer_len;
|
||||||
uint16_t sum;
|
uint16_t sum;
|
||||||
|
|
||||||
|
|
@ -132,20 +142,31 @@ static uint16_t upper_layer_chksum(FAR struct net_driver_s *dev, uint8_t proto)
|
||||||
|
|
||||||
return (sum == 0) ? 0xffff : htons(sum);
|
return (sum == 0) ? 0xffff : htons(sum);
|
||||||
}
|
}
|
||||||
|
#endif /* CONFIG_NET_ARCH_CHKSUM */
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: icmp_6chksum
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if !CONFIG_NET_ARCH_CHKSUM
|
||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
static uint16_t icmp_6chksum(FAR struct net_driver_s *dev)
|
static uint16_t icmp_6chksum(FAR struct net_driver_s *dev)
|
||||||
{
|
{
|
||||||
return upper_layer_chksum(dev, UIP_PROTO_ICMP6);
|
return upper_layer_chksum(dev, UIP_PROTO_ICMP6);
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_NET_IPv6 */
|
#endif /* CONFIG_NET_IPv6 */
|
||||||
|
#endif /* CONFIG_NET_ARCH_CHKSUM */
|
||||||
|
|
||||||
#endif /* UIP_ARCH_CHKSUM */
|
/****************************************************************************
|
||||||
|
* Name: net_carry32
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Calculate the Internet checksum over a buffer.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
/* Calculate the Internet checksum over a buffer. */
|
#if !CONFIG_NET_ARCH_INCR32
|
||||||
|
static inline void net_carry32(FAR uint8_t *sum, uint16_t op16)
|
||||||
#if !UIP_ARCH_ADD32
|
|
||||||
static inline void uip_carry32(FAR uint8_t *sum, uint16_t op16)
|
|
||||||
{
|
{
|
||||||
if (sum[2] < (op16 >> 8))
|
if (sum[2] < (op16 >> 8))
|
||||||
{
|
{
|
||||||
|
|
@ -169,64 +190,154 @@ static inline void uip_carry32(FAR uint8_t *sum, uint16_t op16)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* UIP_ARCH_ADD32 */
|
#endif /* CONFIG_NET_ARCH_INCR32 */
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if !UIP_ARCH_ADD32
|
/****************************************************************************
|
||||||
void uip_incr32(FAR uint8_t *op32, uint16_t op16)
|
* Name: net_incr32
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
*
|
||||||
|
* Carry out a 32-bit addition.
|
||||||
|
*
|
||||||
|
* By defining CONFIG_NET_ARCH_INCR32, the architecture can replace
|
||||||
|
* net_incr32 with hardware assisted solutions.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* op32 - A pointer to a 4-byte array representing a 32-bit integer in
|
||||||
|
* network byte order (big endian). This value may not be word
|
||||||
|
* aligned. The value pointed to by op32 is modified in place
|
||||||
|
*
|
||||||
|
* op16 - A 16-bit integer in host byte order.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if !CONFIG_NET_ARCH_INCR32
|
||||||
|
void net_incr32(FAR uint8_t *op32, uint16_t op16)
|
||||||
{
|
{
|
||||||
op32[3] += (op16 & 0xff);
|
op32[3] += (op16 & 0xff);
|
||||||
op32[2] += (op16 >> 8);
|
op32[2] += (op16 >> 8);
|
||||||
uip_carry32(op32, op16);
|
net_carry32(op32, op16);
|
||||||
}
|
}
|
||||||
#endif /* UIP_ARCH_ADD32 */
|
#endif /* CONFIG_NET_ARCH_INCR32 */
|
||||||
|
|
||||||
#if !UIP_ARCH_CHKSUM
|
/****************************************************************************
|
||||||
uint16_t uip_chksum(FAR uint16_t *data, uint16_t len)
|
* Name: net_chksum
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Calculate the Internet checksum over a buffer.
|
||||||
|
*
|
||||||
|
* The Internet checksum is the one's complement of the one's complement
|
||||||
|
* sum of all 16-bit words in the buffer.
|
||||||
|
*
|
||||||
|
* See RFC1071.
|
||||||
|
*
|
||||||
|
* If CONFIG_NET_ARCH_CHKSUM is defined, then this function must be
|
||||||
|
* provided by architecture-specific logic.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
*
|
||||||
|
* buf - A pointer to the buffer over which the checksum is to be computed.
|
||||||
|
*
|
||||||
|
* len - The length of the buffer over which the checksum is to be computed.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* The Internet checksum of the buffer.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if !CONFIG_NET_ARCH_CHKSUM
|
||||||
|
uint16_t net_chksum(FAR uint16_t *data, uint16_t len)
|
||||||
{
|
{
|
||||||
return htons(chksum(0, (uint8_t *)data, len));
|
return htons(chksum(0, (uint8_t *)data, len));
|
||||||
}
|
}
|
||||||
|
#endif /* CONFIG_NET_ARCH_CHKSUM */
|
||||||
|
|
||||||
/* Calculate the IP header checksum of the packet header in d_buf. */
|
/****************************************************************************
|
||||||
|
* Name: ip_chksum
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Calculate the IP header checksum of the packet header in d_buf.
|
||||||
|
*
|
||||||
|
* The IP header checksum is the Internet checksum of the 20 bytes of
|
||||||
|
* the IP header.
|
||||||
|
*
|
||||||
|
* If CONFIG_NET_ARCH_CHKSUM is defined, then this function must be
|
||||||
|
* provided by architecture-specific logic.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* The IP header checksum of the IP header in the d_buf buffer.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef UIP_ARCH_IPCHKSUM
|
#if !CONFIG_NET_ARCH_CHKSUM
|
||||||
uint16_t uip_ipchksum(FAR struct net_driver_s *dev)
|
uint16_t ip_chksum(FAR struct net_driver_s *dev)
|
||||||
{
|
{
|
||||||
uint16_t sum;
|
uint16_t sum;
|
||||||
|
|
||||||
sum = chksum(0, &dev->d_buf[UIP_LLH_LEN], UIP_IPH_LEN);
|
sum = chksum(0, &dev->d_buf[UIP_LLH_LEN], UIP_IPH_LEN);
|
||||||
return (sum == 0) ? 0xffff : htons(sum);
|
return (sum == 0) ? 0xffff : htons(sum);
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* CONFIG_NET_ARCH_CHKSUM */
|
||||||
|
|
||||||
/* Calculate the TCP checksum of the packet in d_buf and d_appdata. */
|
/****************************************************************************
|
||||||
|
* Name: tcp_chksum
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Calculate the TCP checksum of the packet in d_buf and d_appdata.
|
||||||
|
*
|
||||||
|
* The TCP checksum is the Internet checksum of data contents of the
|
||||||
|
* TCP segment, and a pseudo-header as defined in RFC793.
|
||||||
|
*
|
||||||
|
* Note: The d_appdata pointer that points to the packet data may
|
||||||
|
* point anywhere in memory, so it is not possible to simply calculate
|
||||||
|
* the Internet checksum of the contents of the d_buf buffer.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* The TCP checksum of the TCP segment in d_buf and pointed to by
|
||||||
|
* d_appdata.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if !CONFIG_NET_ARCH_CHKSUM
|
||||||
uint16_t tcp_chksum(FAR struct net_driver_s *dev)
|
uint16_t tcp_chksum(FAR struct net_driver_s *dev)
|
||||||
{
|
{
|
||||||
return upper_layer_chksum(dev, UIP_PROTO_TCP);
|
return upper_layer_chksum(dev, UIP_PROTO_TCP);
|
||||||
}
|
}
|
||||||
|
#endif /* CONFIG_NET_ARCH_CHKSUM */
|
||||||
|
|
||||||
/* Calculate the UDP checksum of the packet in d_buf and d_appdata. */
|
/****************************************************************************
|
||||||
|
* Name: udp_chksum
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Calculate the UDP checksum of the packet in d_buf and d_appdata.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_NET_UDP_CHECKSUMS
|
#if defined(CONFIG_NET_UDP_CHECKSUMS) && !defined(CONFIG_NET_ARCH_CHKSUM)
|
||||||
uint16_t udp_chksum(FAR struct net_driver_s *dev)
|
uint16_t udp_chksum(FAR struct net_driver_s *dev)
|
||||||
{
|
{
|
||||||
return upper_layer_chksum(dev, UIP_PROTO_UDP);
|
return upper_layer_chksum(dev, UIP_PROTO_UDP);
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* CONFIG_NET_UDP_CHECKSUMS && !CONFIG_NET_ARCH_CHKSUM */
|
||||||
|
|
||||||
/* Calculate the checksum of the ICMP message */
|
/****************************************************************************
|
||||||
|
* Name: icmp_chksum
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Calculate the checksum of the ICMP message
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING)
|
#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING)
|
||||||
uint16_t icmp_chksum(FAR struct net_driver_s *dev, int len)
|
uint16_t icmp_chksum(FAR struct net_driver_s *dev, int len)
|
||||||
{
|
{
|
||||||
FAR struct icmp_iphdr_s *picmp = ICMPBUF;
|
FAR struct icmp_iphdr_s *picmp = ICMPBUF;
|
||||||
return uip_chksum((uint16_t*)&picmp->type, len);
|
return net_chksum((uint16_t*)&picmp->type, len);
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* CONFIG_NET_ICMP && CONFIG_NET_ICMP_PING */
|
||||||
|
|
||||||
#endif /* UIP_ARCH_CHKSUM */
|
|
||||||
#endif /* CONFIG_NET */
|
#endif /* CONFIG_NET */
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,49 @@ extern "C"
|
||||||
struct timeval;
|
struct timeval;
|
||||||
void net_dsec2timeval(uint16_t dsec, FAR struct timeval *tv);
|
void net_dsec2timeval(uint16_t dsec, FAR struct timeval *tv);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: tcp_chksum
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Calculate the TCP checksum of the packet in d_buf and d_appdata.
|
||||||
|
*
|
||||||
|
* The TCP checksum is the Internet checksum of data contents of the
|
||||||
|
* TCP segment, and a pseudo-header as defined in RFC793.
|
||||||
|
*
|
||||||
|
* Note: The d_appdata pointer that points to the packet data may
|
||||||
|
* point anywhere in memory, so it is not possible to simply calculate
|
||||||
|
* the Internet checksum of the contents of the d_buf buffer.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* The TCP checksum of the TCP segment in d_buf and pointed to by
|
||||||
|
* d_appdata.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
uint16_t tcp_chksum(FAR struct net_driver_s *dev);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: udp_chksum
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Calculate the UDP checksum of the packet in d_buf and d_appdata.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_NET_UDP_CHECKSUMS
|
||||||
|
uint16_t udp_chksum(FAR struct net_driver_s *dev);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: icmp_chksum
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Calculate the checksum of the ICMP message
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
uint16_t icmp_chksum(FAR struct net_driver_s *dev, int len);
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue