Rtos API example

Embed: (wiki syntax)

« Back to documentation index

lwip_inet_chksum.c File Reference

lwip_inet_chksum.c File Reference

Incluse internet checksum functions. More...

Go to the source code of this file.

Functions

u16_t lwip_standard_chksum (const void *dataptr, int len)
 lwip checksum
static u16_t inet_cksum_pseudo_base (struct pbuf *p, u8_t proto, u16_t proto_len, u32_t acc)
 Parts of the pseudo checksum which are common to IPv4 and IPv6.
u16_t ip6_chksum_pseudo (struct pbuf *p, u8_t proto, u16_t proto_len, const ip6_addr_t *src, const ip6_addr_t *dest)
 Calculates the checksum with IPv6 pseudo header used by TCP and UDP for a pbuf chain.
static u16_t inet_cksum_pseudo_partial_base (struct pbuf *p, u8_t proto, u16_t proto_len, u16_t chksum_len, u32_t acc)
 Parts of the pseudo checksum which are common to IPv4 and IPv6.
u16_t ip6_chksum_pseudo_partial (struct pbuf *p, u8_t proto, u16_t proto_len, u16_t chksum_len, const ip6_addr_t *src, const ip6_addr_t *dest)
 Calculates the checksum with IPv6 pseudo header used by TCP and UDP for a pbuf chain.
u16_t inet_chksum_pbuf (struct pbuf *p)
 Calculate a checksum over a chain of pbufs (without pseudo-header, much like inet_chksum only pbufs are used).
u16_t lwip_chksum_copy (void *dst, const void *src, u16_t len)
 Safe but slow: first call MEMCPY, then call LWIP_CHKSUM.

Detailed Description

Incluse internet checksum functions.


These are some reference implementations of the checksum algorithm, with the aim of being simple, correct and fully portable. Checksumming is the first thing you would want to optimize for your platform. If you create your own version, link it in and in your cc.h put:

#define LWIP_CHKSUM your_checksum_routine

Or you can select from the implementations below by defining LWIP_CHKSUM_ALGORITHM to 1, 2 or 3.

Definition in file lwip_inet_chksum.c.


Function Documentation

u16_t inet_chksum_pbuf ( struct pbuf p )

Calculate a checksum over a chain of pbufs (without pseudo-header, much like inet_chksum only pbufs are used).

Parameters:
ppbuf chain over that the checksum should be calculated
Returns:
checksum (as u16_t) to be saved directly in the protocol header

Definition at line 568 of file lwip_inet_chksum.c.

static u16_t inet_cksum_pseudo_base ( struct pbuf p,
u8_t  proto,
u16_t  proto_len,
u32_t  acc 
) [static]

Parts of the pseudo checksum which are common to IPv4 and IPv6.

Definition at line 260 of file lwip_inet_chksum.c.

static u16_t inet_cksum_pseudo_partial_base ( struct pbuf p,
u8_t  proto,
u16_t  proto_len,
u16_t  chksum_len,
u32_t  acc 
) [static]

Parts of the pseudo checksum which are common to IPv4 and IPv6.

Definition at line 399 of file lwip_inet_chksum.c.

u16_t ip6_chksum_pseudo ( struct pbuf p,
u8_t  proto,
u16_t  proto_len,
const ip6_addr_t src,
const ip6_addr_t dest 
)

Calculates the checksum with IPv6 pseudo header used by TCP and UDP for a pbuf chain.

IPv6 addresses are expected to be in network byte order.

Parameters:
pchain of pbufs over that a checksum should be calculated (ip data part)
protoipv6 protocol/next header (used for checksum of pseudo header)
proto_lenlength of the ipv6 payload (used for checksum of pseudo header)
srcsource ipv6 address (used for checksum of pseudo header)
destdestination ipv6 address (used for checksum of pseudo header)
Returns:
checksum (as u16_t) to be saved directly in the protocol header

Definition at line 343 of file lwip_inet_chksum.c.

u16_t ip6_chksum_pseudo_partial ( struct pbuf p,
u8_t  proto,
u16_t  proto_len,
u16_t  chksum_len,
const ip6_addr_t src,
const ip6_addr_t dest 
)

Calculates the checksum with IPv6 pseudo header used by TCP and UDP for a pbuf chain.

IPv6 addresses are expected to be in network byte order. Will only compute for a portion of the payload.

Parameters:
pchain of pbufs over that a checksum should be calculated (ip data part)
protoipv6 protocol/next header (used for checksum of pseudo header)
proto_lenlength of the ipv6 payload (used for checksum of pseudo header)
chksum_lennumber of payload bytes used to compute chksum
srcsource ipv6 address (used for checksum of pseudo header)
destdestination ipv6 address (used for checksum of pseudo header)
Returns:
checksum (as u16_t) to be saved directly in the protocol header

Definition at line 491 of file lwip_inet_chksum.c.

u16_t lwip_chksum_copy ( void *  dst,
const void *  src,
u16_t  len 
)

Safe but slow: first call MEMCPY, then call LWIP_CHKSUM.

For architectures with big caches, data might still be in cache when generating the checksum after copying.

Definition at line 604 of file lwip_inet_chksum.c.

u16_t lwip_standard_chksum ( const void *  dataptr,
int  len 
)

lwip checksum

An optimized checksum routine.

Parameters:
dataptrpoints to start of data to be summed at any boundary
lenlength of data to be summed
Returns:
host order (!) lwip checksum (non-inverted Internet sum)
Note:
accumulator size limits summable length to 64k
host endianess is irrelevant (p3 RFC1071)

Basically, it uses loop-unrolling on the checksum loop, treating the head and tail bytes specially, whereas the inner loop acts on 8 bytes at a time.

  • start of buffer to be checksummed. May be an odd byte address. number of bytes in the buffer to be checksummed.
    Returns:
    host order (!) lwip checksum (non-inverted Internet sum)
    by Curt McDowell, Broadcom Corp. December 8th, 2005

Definition at line 80 of file lwip_inet_chksum.c.