This should fix a checksum test failure observed on Alpha in Debian's
buildds.
- * Copyright (c) 2008, 2009 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <config.h>
#include "csum.h"
#include <config.h>
#include "csum.h"
/* Returns the IP checksum of the 'n' bytes in 'data'.
*
/* Returns the IP checksum of the 'n' bytes in 'data'.
*
{
const uint16_t *data = data_;
{
const uint16_t *data = data_;
- for (; n > 1; n -= 2) {
- partial = csum_add16(partial, *data++);
+ for (; n > 1; n -= 2, data++) {
+ partial = csum_add16(partial, get_unaligned_u16(data));
}
if (n) {
partial += *(uint8_t *) data;
}
if (n) {
partial += *(uint8_t *) data;
#include <stdlib.h>
#include <string.h>
#include "random.h"
#include <stdlib.h>
#include <string.h>
#include "random.h"
#include "util.h"
#undef NDEBUG
#include "util.h"
#undef NDEBUG
/* Test csum_add16(). */
partial = 0;
for (i = 0; i < tc->size / 2; i++) {
/* Test csum_add16(). */
partial = 0;
for (i = 0; i < tc->size / 2; i++) {
- partial = csum_add16(partial, data16[i]);
+ partial = csum_add16(partial, get_unaligned_u16(&data16[i]));
}
assert(ntohs(csum_finish(partial)) == tc->csum);
mark('.');
}
assert(ntohs(csum_finish(partial)) == tc->csum);
mark('.');
/* Test csum_add32(). */
partial = 0;
for (i = 0; i < tc->size / 4; i++) {
/* Test csum_add32(). */
partial = 0;
for (i = 0; i < tc->size / 4; i++) {
- partial = csum_add32(partial, data32[i]);
+ partial = csum_add32(partial, get_unaligned_u32(&data32[i]));
}
assert(ntohs(csum_finish(partial)) == tc->csum);
mark('.');
}
assert(ntohs(csum_finish(partial)) == tc->csum);
mark('.');
partial = 0;
for (i = 0; i < tc->size / 4; i++) {
if (i % 2) {
partial = 0;
for (i = 0; i < tc->size / 4; i++) {
if (i % 2) {
- partial = csum_add32(partial, data32[i]);
+ partial = csum_add32(partial, get_unaligned_u32(&data32[i]));
- partial = csum_add16(partial, data16[i * 2]);
- partial = csum_add16(partial, data16[i * 2 + 1]);
+ uint16_t u0 = get_unaligned_u16(&data16[i * 2]);
+ uint16_t u1 = get_unaligned_u16(&data16[i * 2 + 1]);
+ partial = csum_add16(partial, u0);
+ partial = csum_add16(partial, u1);
}
}
assert(ntohs(csum_finish(partial)) == tc->csum);
}
}
assert(ntohs(csum_finish(partial)) == tc->csum);