diff options
author | Brad Smith <brad@cvs.openbsd.org> | 2005-05-09 21:54:59 +0000 |
---|---|---|
committer | Brad Smith <brad@cvs.openbsd.org> | 2005-05-09 21:54:59 +0000 |
commit | 6bfc8041f8bed2c0b102f16274ae576676e2df62 (patch) | |
tree | c1ed6247fd53ef5c1527b619f5686d2fe55ba1dc /sys/arch/alpha | |
parent | c88e123cb76a0a53f9debd6e97aa7c91cb009182 (diff) |
- add alpha optimized in4_cksum
- de register and use ANSI prototypes
From NetBSD
ok miod@ martin@
Diffstat (limited to 'sys/arch/alpha')
-rw-r--r-- | sys/arch/alpha/alpha/in_cksum.c | 83 | ||||
-rw-r--r-- | sys/arch/alpha/conf/files.alpha | 3 |
2 files changed, 68 insertions, 18 deletions
diff --git a/sys/arch/alpha/alpha/in_cksum.c b/sys/arch/alpha/alpha/in_cksum.c index 8e33ffa2fc7..8897226b7c8 100644 --- a/sys/arch/alpha/alpha/in_cksum.c +++ b/sys/arch/alpha/alpha/in_cksum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_cksum.c,v 1.6 2003/06/02 23:27:43 millert Exp $ */ +/* $OpenBSD: in_cksum.c,v 1.7 2005/05/09 21:54:58 brad Exp $ */ /* $NetBSD: in_cksum.c,v 1.4 1996/11/13 21:13:06 cgd Exp $ */ /* @@ -37,9 +37,11 @@ #include <sys/param.h> #include <sys/mbuf.h> #include <sys/systm.h> +#include <sys/socketvar.h> #include <netinet/in.h> - -u_int64_t in_cksumdata(caddr_t, int); +#include <netinet/in_systm.h> +#include <netinet/ip.h> +#include <netinet/ip_var.h> /* * Checksum routine for Internet Protocol family headers @@ -81,12 +83,8 @@ union q_util { u_int64_t q; }; -u_int64_t in_cksumdata(caddr_t buf, int len); - -u_int64_t -in_cksumdata(buf, len) - register caddr_t buf; - register int len; +static u_int64_t +in_cksumdata(caddr_t buf, int len) { const u_int32_t *lw = (u_int32_t *) buf; u_int64_t sum = 0; @@ -167,14 +165,12 @@ in_cksumdata(buf, len) } int -in_cksum(m, len) - register struct mbuf *m; - register int len; +in_cksum(struct mbuf *m, int len) { - register u_int64_t sum = 0; - register int mlen = 0; - register int clen = 0; - register caddr_t addr; + u_int64_t sum = 0; + int mlen = 0; + int clen = 0; + caddr_t addr; union l_util l_util; union q_util q_util; @@ -196,3 +192,58 @@ in_cksum(m, len) REDUCE16; return (~sum & 0xffff); } + +int +in4_cksum(struct mbuf *m, u_int8_t nxt, int off, int len) +{ + u_int64_t sum = 0; + int mlen = 0; + int clen = 0; + caddr_t addr; + union q_util q_util; + union l_util l_util; + struct ipovly ipov; + + if (nxt != 0) { + /* pseudo header */ + if (off < sizeof(struct ipovly)) + panic("in4_cksum: offset too short"); + if (m->m_len < sizeof(struct ip)) + panic("in4_cksum: bad mbuf chain"); + + 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; + + sum += in_cksumdata((caddr_t) &ipov, sizeof(ipov)); + } + + /* skip over unnecessary part */ + while (m != NULL && off > 0) { + if (m->m_len > off) + break; + off -= m->m_len; + m = m->m_next; + } + + for (; m && len; m = m->m_next, off = 0) { + if (m->m_len == 0) + continue; + mlen = m->m_len - off; + if (len < mlen) + mlen = len; + addr = mtod(m, caddr_t) + off; + if ((clen ^ (long) addr) & 1) + sum += in_cksumdata(addr, mlen) << 8; + else + sum += in_cksumdata(addr, mlen); + + clen += mlen; + len -= mlen; + } + REDUCE16; + return (~sum & 0xffff); +} diff --git a/sys/arch/alpha/conf/files.alpha b/sys/arch/alpha/conf/files.alpha index 5f7e2038d60..867b870c4c3 100644 --- a/sys/arch/alpha/conf/files.alpha +++ b/sys/arch/alpha/conf/files.alpha @@ -1,4 +1,4 @@ -# $OpenBSD: files.alpha,v 1.66 2005/05/01 21:36:55 brad Exp $ +# $OpenBSD: files.alpha,v 1.67 2005/05/09 21:54:58 brad Exp $ # $NetBSD: files.alpha,v 1.32 1996/11/25 04:03:21 cgd Exp $ # # alpha-specific configuration info @@ -289,7 +289,6 @@ file dev/clock_subr.c # file arch/alpha/alpha/in_cksum.c inet -file netinet/in4_cksum.c inet file netns/ns_cksum.c ns # XXX |