Merge in4_cksum().
This commit is contained in:
parent
71bd2bfc03
commit
b54ea24924
@ -1,4 +1,4 @@
|
||||
# $NetBSD: files.sparc,v 1.100 2001/01/17 00:07:37 fvdl Exp $
|
||||
# $NetBSD: files.sparc,v 1.101 2001/03/21 00:38:47 pk Exp $
|
||||
|
||||
# @(#)files.sparc 8.1 (Berkeley) 7/19/93
|
||||
# sparc-specific configuration info
|
||||
@ -220,7 +220,6 @@ file arch/sparc/sparc/cache.c
|
||||
file arch/sparc/sparc/conf.c
|
||||
file arch/sparc/sparc/emul.c
|
||||
file arch/sparc/sparc/in_cksum.c
|
||||
file netinet/in4_cksum.c inet
|
||||
file arch/sparc/sparc/intr.c
|
||||
file arch/sparc/sparc/kgdb_machdep.c kgdb
|
||||
# sparc/sparc/locore.s is handled specially in the makefile,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: in_cksum.c,v 1.9 1998/11/29 10:37:08 mycroft Exp $ */
|
||||
/* $NetBSD: in_cksum.c,v 1.10 2001/03/21 00:38:47 pk Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995 Zubin Dittia.
|
||||
@ -44,8 +44,12 @@
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_var.h>
|
||||
|
||||
/*
|
||||
* Checksum routine for Internet Protocol family headers.
|
||||
@ -134,14 +138,11 @@
|
||||
#define ADDSHORT {sum += *(u_short *)w;}
|
||||
#define ADVANCE(n) {w += n; mlen -= n;}
|
||||
|
||||
int
|
||||
in_cksum(m, len)
|
||||
register struct mbuf *m;
|
||||
register int len;
|
||||
static __inline__ int
|
||||
in_cksum_internal(struct mbuf *m, int off, int len, u_int sum)
|
||||
{
|
||||
register u_char *w;
|
||||
register u_int sum = 0;
|
||||
register int mlen = 0;
|
||||
u_char *w;
|
||||
int mlen = 0;
|
||||
int byte_swapped = 0;
|
||||
|
||||
/*
|
||||
@ -149,13 +150,14 @@ in_cksum(m, len)
|
||||
* allow the compiler to pick which specific machine registers to
|
||||
* use, instead of hard-coding this in the asm code above.
|
||||
*/
|
||||
register u_int tmp1, tmp2;
|
||||
u_int tmp1, tmp2;
|
||||
|
||||
for (; m && len; m = m->m_next) {
|
||||
if (m->m_len == 0)
|
||||
continue;
|
||||
w = mtod(m, u_char *);
|
||||
mlen = m->m_len;
|
||||
w = mtod(m, u_char *) + off;
|
||||
mlen = m->m_len - off;
|
||||
off = 0;
|
||||
if (len < mlen)
|
||||
mlen = len;
|
||||
len -= mlen;
|
||||
@ -222,3 +224,52 @@ in_cksum(m, len)
|
||||
|
||||
return (0xffff ^ sum);
|
||||
}
|
||||
|
||||
int
|
||||
in_cksum(m, len)
|
||||
struct mbuf *m;
|
||||
int len;
|
||||
{
|
||||
|
||||
return (in_cksum_internal(m, 0, len, 0));
|
||||
}
|
||||
|
||||
int
|
||||
in4_cksum(m, nxt, off, len)
|
||||
struct mbuf *m;
|
||||
u_int8_t nxt;
|
||||
int off, len;
|
||||
{
|
||||
u_char *w;
|
||||
u_int sum = 0;
|
||||
struct ipovly ipov;
|
||||
|
||||
/*
|
||||
* Declare two temporary registers for use by the asm code. We
|
||||
* allow the compiler to pick which specific machine registers to
|
||||
* use, instead of hard-coding this in the asm code above.
|
||||
*/
|
||||
u_int tmp1, tmp2;
|
||||
|
||||
/* 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 = (u_char *)&ipov;
|
||||
/* assumes sizeof(ipov) == 20 */
|
||||
ADD16;
|
||||
w += 16;
|
||||
ADD4;
|
||||
|
||||
/* 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