Use the current MIPS in_cksum for in4_cksum too.
This commit is contained in:
parent
937b671271
commit
d75c18b050
@ -1,4 +1,4 @@
|
||||
# $NetBSD: files.mips,v 1.40 2002/04/03 13:16:13 simonb Exp $
|
||||
# $NetBSD: files.mips,v 1.41 2002/06/01 11:41:33 simonb Exp $
|
||||
#
|
||||
|
||||
defflag opt_cputype.h NOFPU # and the rest...
|
||||
@ -45,7 +45,6 @@ file arch/mips/mips/cache_r5900.c mips3 & mips3_5900
|
||||
file arch/mips/mips/cache_mipsNN.c mips32 | mips64
|
||||
|
||||
file arch/mips/mips/in_cksum.c inet
|
||||
file netinet/in4_cksum.c inet
|
||||
file netns/ns_cksum.c ns
|
||||
|
||||
file arch/mips/mips/fpemu.c softfloat
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: in_cksum.c,v 1.7 2002/03/05 14:15:31 simonb Exp $ */
|
||||
/* $NetBSD: in_cksum.c,v 1.8 2002/06/01 11:41:33 simonb Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993 Regents of the University of California.
|
||||
@ -45,7 +45,12 @@
|
||||
#include <sys/systm.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_var.h>
|
||||
|
||||
#include <machine/endian.h>
|
||||
|
||||
union memptr {
|
||||
@ -56,8 +61,7 @@ union memptr {
|
||||
unsigned char *c;
|
||||
};
|
||||
|
||||
static __inline u_int32_t fastsum(union memptr, int, u_int, int);
|
||||
|
||||
static inline uint32_t fastsum(union memptr, int, unsigned int, int);
|
||||
|
||||
/*
|
||||
* Compute 1's complement sum over a contiguous block at 'buf' for 'n' bytes.
|
||||
@ -68,7 +72,7 @@ static __inline u_int32_t fastsum(union memptr, int, u_int, int);
|
||||
* and so we must byteswap the memory-aligned 1's-complement sum
|
||||
* over the data before adding it to `oldsum'.
|
||||
*/
|
||||
u_int32_t
|
||||
static inline uint32_t
|
||||
fastsum(union memptr buf, int n, unsigned int oldsum, int odd_aligned)
|
||||
{
|
||||
unsigned long hilo = 0, high = 0;
|
||||
@ -236,33 +240,71 @@ fastsum(union memptr buf, int n, unsigned int oldsum, int odd_aligned)
|
||||
return(sum);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Checksum routine for Internet Protocol family headers (mips r3000 Version).
|
||||
* Checksum routine for Internet Protocol family headers.
|
||||
*
|
||||
*/
|
||||
int
|
||||
in_cksum(struct mbuf *m, int len)
|
||||
static inline int
|
||||
in_cksum_internal(struct mbuf *m, int off, int len, uint32_t sum)
|
||||
{
|
||||
/*u_short **/ union memptr w;
|
||||
u_int32_t sum = 0;
|
||||
int mlen;
|
||||
int odd_aligned = 0;
|
||||
|
||||
for ( ; m && len; m = m->m_next) {
|
||||
|
||||
mlen = m->m_len;
|
||||
if (mlen == 0)
|
||||
for (; m && len; m = m->m_next) {
|
||||
if (m->m_len == 0)
|
||||
continue;
|
||||
if (mlen > len)
|
||||
w.c = mtod(m, u_char *) + off;
|
||||
mlen = m->m_len - off;
|
||||
off = 0;
|
||||
if (len < mlen)
|
||||
mlen = len;
|
||||
w.c = mtod(m, u_char *);
|
||||
sum = fastsum(w, mlen, sum, odd_aligned);
|
||||
len -= mlen;
|
||||
|
||||
sum = fastsum(w, mlen, sum, odd_aligned);
|
||||
odd_aligned = (odd_aligned + mlen) & 0x01;
|
||||
}
|
||||
if (len != 0) {
|
||||
printf("in_cksum: out of data, %d\n", len);
|
||||
printf("cksum: out of data, %d\n", len);
|
||||
}
|
||||
return (~sum & 0xffff);
|
||||
}
|
||||
|
||||
int
|
||||
in_cksum(struct mbuf *m, int len)
|
||||
{
|
||||
|
||||
return (in_cksum_internal(m, 0, len, 0));
|
||||
}
|
||||
|
||||
int
|
||||
in4_cksum(struct mbuf *m, uint8_t nxt, int off, int len)
|
||||
{
|
||||
uint sum = 0;
|
||||
|
||||
if (nxt != 0) {
|
||||
uint16_t *w;
|
||||
struct ipovly ipov;
|
||||
|
||||
/* pseudo header */
|
||||
memset(&ipov, 0, sizeof(ipov));
|
||||
ipov.ih_len = htons(len);
|
||||
ipov.ih_pr = nxt;
|
||||
ipov.ih_src = mtod(m, struct ip *)->ip_src;
|
||||
ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
|
||||
w = (uint16_t *)&ipov;
|
||||
/* assumes sizeof(ipov) == 20 */
|
||||
sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3]; sum += w[4];
|
||||
sum += w[5]; sum += w[6]; sum += w[7]; sum += w[8]; sum += w[9];
|
||||
}
|
||||
|
||||
/* skip unnecessary part */
|
||||
while (m && off > 0) {
|
||||
if (m->m_len > off)
|
||||
break;
|
||||
off -= m->m_len;
|
||||
m = m->m_next;
|
||||
}
|
||||
|
||||
return (in_cksum_internal(m, off, len, sum));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user