ReactOS 0.4.15-dev-7953-g1f49173
inet_chksum.h File Reference
#include "lwip/opt.h"
#include "lwip/pbuf.h"
#include "lwip/ip_addr.h"
Include dependency graph for inet_chksum.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SWAP_BYTES_IN_WORD(w)   (((w) & 0xff) << 8) | (((w) & 0xff00) >> 8)
 
#define FOLD_U32T(u)   (((u) >> 16) + ((u) & 0x0000ffffUL))
 
#define LWIP_CHKSUM_COPY_ALGORITHM   0
 

Functions

u16_t inet_chksum (void *dataptr, u16_t len)
 
u16_t inet_chksum_pbuf (struct pbuf *p)
 
u16_t inet_chksum_pseudo (struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, u8_t proto, u16_t proto_len)
 
u16_t inet_chksum_pseudo_partial (struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, u8_t proto, u16_t proto_len, u16_t chksum_len)
 

Macro Definition Documentation

◆ FOLD_U32T

#define FOLD_U32T (   u)    (((u) >> 16) + ((u) & 0x0000ffffUL))

Split an u32_t in two u16_ts and add them up

Definition at line 53 of file inet_chksum.h.

◆ LWIP_CHKSUM_COPY_ALGORITHM

#define LWIP_CHKSUM_COPY_ALGORITHM   0

Definition at line 66 of file inet_chksum.h.

◆ SWAP_BYTES_IN_WORD

#define SWAP_BYTES_IN_WORD (   w)    (((w) & 0xff) << 8) | (((w) & 0xff00) >> 8)

Swap the bytes in an u16_t: much like htons() for little-endian

Definition at line 47 of file inet_chksum.h.

Function Documentation

◆ inet_chksum()

u16_t inet_chksum ( void dataptr,
u16_t  len 
)

Definition at line 396 of file inet_chksum.c.

397{
398 return ~LWIP_CHKSUM(dataptr, len);
399}
GLenum GLsizei len
Definition: glext.h:6722
int const JOCTET * dataptr
Definition: jpeglib.h:1031

◆ inet_chksum_pbuf()

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 409 of file inet_chksum.c.

410{
411 u32_t acc;
412 struct pbuf *q;
413 u8_t swapped;
414
415 acc = 0;
416 swapped = 0;
417 for(q = p; q != NULL; q = q->next) {
418 acc += LWIP_CHKSUM(q->payload, q->len);
419 acc = FOLD_U32T(acc);
420 if (q->len % 2 != 0) {
421 swapped = 1 - swapped;
422 acc = SWAP_BYTES_IN_WORD(acc);
423 }
424 }
425
426 if (swapped) {
427 acc = SWAP_BYTES_IN_WORD(acc);
428 }
429 return (u16_t)~(acc & 0xffffUL);
430}
#define NULL
Definition: types.h:112
unsigned long u32_t
Definition: cc.h:25
unsigned char u8_t
Definition: cc.h:23
unsigned short u16_t
Definition: cc.h:24
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902
#define LWIP_CHKSUM
Definition: inet_chksum.c:59
#define SWAP_BYTES_IN_WORD(w)
Definition: inet_chksum.h:47
#define FOLD_U32T(u)
Definition: inet_chksum.h:53
struct define * next
Definition: compiler.c:65
Definition: pbuf.h:79

◆ inet_chksum_pseudo()

u16_t inet_chksum_pseudo ( struct pbuf p,
ip_addr_t src,
ip_addr_t dest,
u8_t  proto,
u16_t  proto_len 
)

Definition at line 272 of file inet_chksum.c.

275{
276 u32_t acc;
277 u32_t addr;
278 struct pbuf *q;
279 u8_t swapped;
280
281 acc = 0;
282 swapped = 0;
283 /* iterate through all pbuf in chain */
284 for(q = p; q != NULL; q = q->next) {
285 LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): checksumming pbuf %p (has next %p) \n",
286 (void *)q, (void *)q->next));
287 acc += LWIP_CHKSUM(q->payload, q->len);
288 /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%"X32_F" \n", acc));*/
289 /* just executing this next line is probably faster that the if statement needed
290 to check whether we really need to execute it, and does no harm */
291 acc = FOLD_U32T(acc);
292 if (q->len % 2 != 0) {
293 swapped = 1 - swapped;
294 acc = SWAP_BYTES_IN_WORD(acc);
295 }
296 /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): wrapped lwip_chksum()=%"X32_F" \n", acc));*/
297 }
298
299 if (swapped) {
300 acc = SWAP_BYTES_IN_WORD(acc);
301 }
303 acc += (addr & 0xffffUL);
304 acc += ((addr >> 16) & 0xffffUL);
306 acc += (addr & 0xffffUL);
307 acc += ((addr >> 16) & 0xffffUL);
308 acc += (u32_t)htons((u16_t)proto);
309 acc += (u32_t)htons(proto_len);
310
311 /* Fold 32-bit sum to 16 bits
312 calling this twice is propably faster than if statements... */
313 acc = FOLD_U32T(acc);
314 acc = FOLD_U32T(acc);
315 LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain lwip_chksum()=%"X32_F"\n", acc));
316 return (u16_t)~(acc & 0xffffUL);
317}
#define X32_F
Definition: cc.h:41
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:95
GLenum src
Definition: glext.h:6340
GLenum const GLvoid * addr
Definition: glext.h:9621
#define INET_DEBUG
Definition: lwipopts.h:130
#define ip4_addr_get_u32(src_ipaddr)
Definition: ip_addr.h:181
#define htons(x)
Definition: module.h:215
static char * dest
Definition: rtl.c:135

Referenced by tcp_create_segment_wnd().

◆ inet_chksum_pseudo_partial()

u16_t inet_chksum_pseudo_partial ( struct pbuf p,
ip_addr_t src,
ip_addr_t dest,
u8_t  proto,
u16_t  proto_len,
u16_t  chksum_len 
)

Definition at line 332 of file inet_chksum.c.

335{
336 u32_t acc;
337 u32_t addr;
338 struct pbuf *q;
339 u8_t swapped;
340 u16_t chklen;
341
342 acc = 0;
343 swapped = 0;
344 /* iterate through all pbuf in chain */
345 for(q = p; (q != NULL) && (chksum_len > 0); q = q->next) {
346 LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): checksumming pbuf %p (has next %p) \n",
347 (void *)q, (void *)q->next));
348 chklen = q->len;
349 if (chklen > chksum_len) {
350 chklen = chksum_len;
351 }
352 acc += LWIP_CHKSUM(q->payload, chklen);
353 chksum_len -= chklen;
354 LWIP_ASSERT("delete me", chksum_len < 0x7fff);
355 /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%"X32_F" \n", acc));*/
356 /* fold the upper bit down */
357 acc = FOLD_U32T(acc);
358 if (q->len % 2 != 0) {
359 swapped = 1 - swapped;
360 acc = SWAP_BYTES_IN_WORD(acc);
361 }
362 /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): wrapped lwip_chksum()=%"X32_F" \n", acc));*/
363 }
364
365 if (swapped) {
366 acc = SWAP_BYTES_IN_WORD(acc);
367 }
369 acc += (addr & 0xffffUL);
370 acc += ((addr >> 16) & 0xffffUL);
372 acc += (addr & 0xffffUL);
373 acc += ((addr >> 16) & 0xffffUL);
374 acc += (u32_t)htons((u16_t)proto);
375 acc += (u32_t)htons(proto_len);
376
377 /* Fold 32-bit sum to 16 bits
378 calling this twice is propably faster than if statements... */
379 acc = FOLD_U32T(acc);
380 acc = FOLD_U32T(acc);
381 LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain lwip_chksum()=%"X32_F"\n", acc));
382 return (u16_t)~(acc & 0xffffUL);
383}
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:66