Skip to content

Commit

Permalink
Clean-up naming associated with network checksums
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory-nutt committed Jun 27, 2014
1 parent fce2a79 commit 50b749a
Show file tree
Hide file tree
Showing 15 changed files with 296 additions and 111 deletions.
93 changes: 48 additions & 45 deletions include/nuttx/net/netdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_off(FAR struct net_driver_s *dev);

/* By defining UIP_ARCH_CHKSUM, the architecture can replace up_incr32
* with hardware assisted solutions.
*/

/* Carry out a 32-bit addition.
/****************************************************************************
* Name: net_chksum
*
* 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
* Description:
* Calculate the Internet checksum over a buffer.
*
* op16 - A 16-bit integer in host byte order.
*/

void uip_incr32(uint8_t *op32, uint16_t op16);

/* 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.
*
* The Internet checksum is the one's complement of the one's
* complement sum of all 16-bit words in the buffer.
* See RFC1071.
*
* See RFC1071.
* If CONFIG_NET_ARCH_CHKSUM is defined, then this function must be
* provided by architecture-specific logic.
*
* Note: This function is not called in the current version of uIP,
* but future versions might make use of it.
* Input Parameters:
*
* buf A pointer to the buffer over which the checksum is to be
* computed.
* 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.
* len - The length of the buffer over which the checksum is to be computed.
*
* Return: The Internet checksum of the buffer.
*/
* Returned Value:
* The Internet checksum of the buffer.
*
****************************************************************************/

uint16_t uip_chksum(uint16_t *buf, uint16_t len);
uint16_t net_chksum(FAR uint16_t *data, uint16_t len);

/* Calculate the IP header checksum of the packet header in d_buf.
/****************************************************************************
* Name: net_incr32
*
* The IP header checksum is the Internet checksum of the 20 bytes of
* the IP header.
* Description:
*
* Return: The IP header checksum of the IP header in the d_buf
* buffer.
*/
* 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.
*
****************************************************************************/

uint16_t uip_ipchksum(struct net_driver_s *dev);
void net_incr32(FAR uint8_t *op32, uint16_t op16);

/* Calculate the TCP checksum of the packet in d_buf and d_appdata.
/****************************************************************************
* Name: ip_chksum
*
* The TCP checksum is the Internet checksum of data contents of the
* TCP segment, and a pseudo-header as defined in RFC793.
* Description:
* Calculate the IP header checksum of the packet header in d_buf.
*
* 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.
* The IP header checksum is the Internet checksum of the 20 bytes of
* the IP header.
*
* Return: The TCP checksum of the TCP segment in d_buf and pointed
* to by d_appdata.
*/
* 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.
*
****************************************************************************/

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);
uint16_t ip_chksum(FAR struct net_driver_s *dev);

#endif /* __INCLUDE_NUTTX_NET_NETDEV_H */
2 changes: 1 addition & 1 deletion include/nuttx/net/uip.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ typedef uip_ip4addr_t uip_ipaddr_t;

/* The IP header */

struct uip_ip_hdr
struct net_iphdr_s
{
#ifdef CONFIG_NET_IPv6

Expand Down
31 changes: 16 additions & 15 deletions net/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Directory Structure
+- devif - Stack/device interface layer
+- icmp - Internet Control Message Protocol
+- iob - I/O buffering logic
+- ipv6 - Logic unique to IPv6
+- netdev - Socket network device interface
+- pkt - "Raw" packet socket support
+- socket - BSD socket interface
Expand All @@ -21,18 +22,18 @@ Directory Structure
`- utils - Miscellaneous utility functions


+-------------------------------------------------------------+
| Application layer |
+-------------------------------------------------------------+
+-------------------------------------------------------------+
| Socket layer (socket/) |
+-------------------------------------------------------------+
+------------++-----------------------------------------------+
| Network || Protocol stacks (arp, icmp, pkt, tcp, udp) |
| Device |+-----------------------------------------------+
| Interface |+---------------------------------++------------+
| (netdev/) ||Network Device Interface (devif/)|| Utilities |
+------------++---------------------------------++------------+
+-------------------------------------------------------------+
| Network Device Drivers |
+-------------------------------------------------------------+
+----------------------------------------------------------------+
| Application layer |
+----------------------------------------------------------------+
+----------------------------------------------------------------+
| Socket layer (socket/) |
+----------------------------------------------------------------+
+------------++--------------------------------------------------+
| Network || Protocol stacks (arp, ipv6, icmp, pkt, tcp, udp) |
| Device |+--------------------------------------------------+
| Interface |+------------------------------------++------------+
| (netdev/) || Network Device Interface (devif/) || Utilities |
+------------++------------------------------------++------------+
+----------------------------------------------------------------+
| Network Device Drivers |
+----------------------------------------------------------------+
1 change: 1 addition & 0 deletions net/icmp/icmp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

#include "uip/uip.h"
#include "icmp/icmp.h"
#include "utils/utils.h"

#ifdef CONFIG_NET_ICMP

Expand Down
3 changes: 2 additions & 1 deletion net/icmp/icmp_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <nuttx/net/netstats.h>

#include "uip/uip.h"
#include "utils/utils.h"
#include "icmp/icmp.h"

/****************************************************************************
Expand Down Expand Up @@ -144,7 +145,7 @@ void icmp_send(FAR struct net_driver_s *dev, FAR uip_ipaddr_t *destaddr)
/* Calculate IP checksum. */

picmp->ipchksum = 0;
picmp->ipchksum = ~(uip_ipchksum(dev));
picmp->ipchksum = ~(ip_chksum(dev));

#endif /* CONFIG_NET_IPv6 */

Expand Down
2 changes: 1 addition & 1 deletion net/igmp/igmp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void igmp_input(struct net_driver_s *dev)

/* 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);
nlldbg("Checksum error\n");
Expand Down
2 changes: 1 addition & 1 deletion net/igmp/igmp_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@

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;
}

Expand Down
21 changes: 11 additions & 10 deletions net/tcp/tcp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include <nuttx/net/netstats.h>

#include "uip/uip.h"
#include "utils/utils.h"
#include "tcp/tcp.h"

/****************************************************************************
Expand Down Expand Up @@ -210,7 +211,7 @@ void tcp_input(struct net_driver_s *dev)
goto drop;
}

uip_incr32(conn->rcvseq, 1);
net_incr32(conn->rcvseq, 1);

/* Parse the TCP MSS option, if present. */

Expand Down Expand Up @@ -474,7 +475,7 @@ void tcp_input(struct net_driver_s *dev)
if (dev->d_len > 0)
{
flags |= UIP_NEWDATA;
uip_incr32(conn->rcvseq, dev->d_len);
net_incr32(conn->rcvseq, dev->d_len);
}

dev->d_sndlen = 0;
Expand Down Expand Up @@ -557,7 +558,7 @@ void tcp_input(struct net_driver_s *dev)
conn->tcpstateflags = UIP_ESTABLISHED;
memcpy(conn->rcvseq, pbuf->seqno, 4);

uip_incr32(conn->rcvseq, 1);
net_incr32(conn->rcvseq, 1);
conn->unacked = 0;

#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
Expand Down Expand Up @@ -623,7 +624,7 @@ void tcp_input(struct net_driver_s *dev)
* been closed.
*/

uip_incr32(conn->rcvseq, dev->d_len + 1);
net_incr32(conn->rcvseq, dev->d_len + 1);
flags |= UIP_CLOSE;

if (dev->d_len > 0)
Expand Down Expand Up @@ -657,7 +658,7 @@ void tcp_input(struct net_driver_s *dev)
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_urgdata = dev->d_appdata;
dev->d_appdata += dev->d_urglen;
Expand Down Expand Up @@ -724,7 +725,7 @@ void tcp_input(struct net_driver_s *dev)
{
/* 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 */
Expand Down Expand Up @@ -757,7 +758,7 @@ void tcp_input(struct net_driver_s *dev)

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)
Expand All @@ -775,7 +776,7 @@ void tcp_input(struct net_driver_s *dev)
nllvdbg("TCP state: UIP_CLOSING\n");
}

uip_incr32(conn->rcvseq, 1);
net_incr32(conn->rcvseq, 1);
(void)tcp_callback(dev, conn, UIP_CLOSE);
tcp_send(dev, conn, TCP_ACK, UIP_IPTCPH_LEN);
return;
Expand All @@ -799,7 +800,7 @@ void tcp_input(struct net_driver_s *dev)
case UIP_FIN_WAIT_2:
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)
Expand All @@ -808,7 +809,7 @@ void tcp_input(struct net_driver_s *dev)
conn->timer = 0;
nllvdbg("TCP state: UIP_TIME_WAIT\n");

uip_incr32(conn->rcvseq, 1);
net_incr32(conn->rcvseq, 1);
(void)tcp_callback(dev, conn, UIP_CLOSE);
tcp_send(dev, conn, TCP_ACK, UIP_IPTCPH_LEN);
return;
Expand Down
3 changes: 2 additions & 1 deletion net/tcp/tcp_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <nuttx/net/netstats.h>

#include "uip/uip.h"
#include "utils/utils.h"

/****************************************************************************
* Pre-processor Definitions
Expand Down Expand Up @@ -139,7 +140,7 @@ static void tcp_sendcomplete(FAR struct net_driver_s *dev)
/* Calculate IP checksum. */

pbuf->ipchksum = 0;
pbuf->ipchksum = ~(uip_ipchksum(dev));
pbuf->ipchksum = ~(ip_chksum(dev));

#endif /* CONFIG_NET_IPv6 */

Expand Down
1 change: 1 addition & 0 deletions net/udp/udp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <nuttx/net/netstats.h>

#include "uip/uip.h"
#include "utils/utils.h"
#include "udp/udp.h"

/****************************************************************************
Expand Down
3 changes: 2 additions & 1 deletion net/udp/udp_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <nuttx/net/netstats.h>

#include "uip/uip.h"
#include "utils/utils.h"
#include "udp/udp.h"

/****************************************************************************
Expand Down Expand Up @@ -144,7 +145,7 @@ void udp_send(struct net_driver_s *dev, struct udp_conn_s *conn)
/* Calculate IP checksum. */

pudpbuf->ipchksum = 0;
pudpbuf->ipchksum = ~(uip_ipchksum(dev));
pudpbuf->ipchksum = ~(ip_chksum(dev));

#endif /* CONFIG_NET_IPv6 */

Expand Down
Loading

0 comments on commit 50b749a

Please sign in to comment.