Merge in4_cksum().

This commit is contained in:
pk 2001-03-21 00:38:47 +00:00
parent 71bd2bfc03
commit b54ea24924
2 changed files with 63 additions and 13 deletions

View File

@ -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 # @(#)files.sparc 8.1 (Berkeley) 7/19/93
# sparc-specific configuration info # sparc-specific configuration info
@ -220,7 +220,6 @@ file arch/sparc/sparc/cache.c
file arch/sparc/sparc/conf.c file arch/sparc/sparc/conf.c
file arch/sparc/sparc/emul.c file arch/sparc/sparc/emul.c
file arch/sparc/sparc/in_cksum.c file arch/sparc/sparc/in_cksum.c
file netinet/in4_cksum.c inet
file arch/sparc/sparc/intr.c file arch/sparc/sparc/intr.c
file arch/sparc/sparc/kgdb_machdep.c kgdb file arch/sparc/sparc/kgdb_machdep.c kgdb
# sparc/sparc/locore.s is handled specially in the makefile, # sparc/sparc/locore.s is handled specially in the makefile,

View File

@ -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. * Copyright (c) 1995 Zubin Dittia.
@ -44,8 +44,12 @@
*/ */
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h> #include <sys/mbuf.h>
#include <netinet/in.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. * Checksum routine for Internet Protocol family headers.
@ -134,14 +138,11 @@
#define ADDSHORT {sum += *(u_short *)w;} #define ADDSHORT {sum += *(u_short *)w;}
#define ADVANCE(n) {w += n; mlen -= n;} #define ADVANCE(n) {w += n; mlen -= n;}
int static __inline__ int
in_cksum(m, len) in_cksum_internal(struct mbuf *m, int off, int len, u_int sum)
register struct mbuf *m;
register int len;
{ {
register u_char *w; u_char *w;
register u_int sum = 0; int mlen = 0;
register int mlen = 0;
int byte_swapped = 0; int byte_swapped = 0;
/* /*
@ -149,13 +150,14 @@ in_cksum(m, len)
* allow the compiler to pick which specific machine registers to * allow the compiler to pick which specific machine registers to
* use, instead of hard-coding this in the asm code above. * 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) { for (; m && len; m = m->m_next) {
if (m->m_len == 0) if (m->m_len == 0)
continue; continue;
w = mtod(m, u_char *); w = mtod(m, u_char *) + off;
mlen = m->m_len; mlen = m->m_len - off;
off = 0;
if (len < mlen) if (len < mlen)
mlen = len; mlen = len;
len -= mlen; len -= mlen;
@ -222,3 +224,52 @@ in_cksum(m, len)
return (0xffff ^ sum); 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));
}