| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: in4_cksum.c,v 1.17 2008/02/12 13:05:55 joerg Exp $ */ | | 1 | /* $NetBSD: in4_cksum.c,v 1.18 2011/04/25 22:04:32 yamt Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>. | | 4 | * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * | | 10 | * |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in | | 14 | * notice, this list of conditions and the following disclaimer in |
| @@ -20,54 +20,54 @@ | | | @@ -20,54 +20,54 @@ |
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | | 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | | 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | | 22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, | | 23 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, |
24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
26 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | | 26 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | | 27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
28 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 28 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | | 29 | * SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __KERNEL_RCSID(0, "$NetBSD: in4_cksum.c,v 1.17 2008/02/12 13:05:55 joerg Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: in4_cksum.c,v 1.18 2011/04/25 22:04:32 yamt Exp $"); |
34 | | | 34 | |
35 | #include <sys/param.h> | | 35 | #include <sys/param.h> |
36 | #include <sys/mbuf.h> | | 36 | #include <sys/mbuf.h> |
37 | #include <netinet/in.h> | | 37 | #include <netinet/in.h> |
38 | #include <netinet/in_systm.h> | | 38 | #include <netinet/in_systm.h> |
39 | #include <netinet/ip.h> | | 39 | #include <netinet/ip.h> |
40 | | | 40 | |
41 | /* | | 41 | /* |
42 | * Checksum of the IPv4 pseudo header. | | 42 | * Checksum of the IPv4 pseudo header. |
43 | * | | 43 | * |
44 | * off is supposed to be the skipped IPv4 header, len is the payload size. | | 44 | * off is supposed to be the skipped IPv4 header, len is the payload size. |
45 | */ | | 45 | */ |
46 | | | 46 | |
47 | int | | 47 | int |
48 | in4_cksum(struct mbuf *m, u_int8_t nxt, int off, int len) | | 48 | in4_cksum(struct mbuf *m, u_int8_t nxt, int off, int len) |
49 | { | | 49 | { |
50 | uint32_t sum; | | 50 | uint32_t sum; |
51 | uint16_t *w; | | 51 | uint16_t *w; |
52 | | | 52 | |
| | | 53 | if (nxt == 0) |
| | | 54 | return cpu_in_cksum(m, len, off, 0); |
| | | 55 | |
53 | if (__predict_false(off < sizeof(struct ip))) | | 56 | if (__predict_false(off < sizeof(struct ip))) |
54 | panic("in4_cksum: offset too short for IP header"); | | 57 | panic("in4_cksum: offset too short for IP header"); |
55 | if (__predict_false(m->m_len < sizeof(struct ip))) | | 58 | if (__predict_false(m->m_len < sizeof(struct ip))) |
56 | panic("in4_cksum: mbuf too short for IP header"); | | 59 | panic("in4_cksum: mbuf too short for IP header"); |
57 | | | 60 | |
58 | if (nxt == 0) | | | |
59 | return cpu_in_cksum(m, len, off, 0); | | | |
60 | | | | |
61 | /* | | 61 | /* |
62 | * Compute the equivalent of: | | 62 | * Compute the equivalent of: |
63 | * struct ipovly ip; | | 63 | * struct ipovly ip; |
64 | * | | 64 | * |
65 | * bzero(sizeof(*ip)); | | 65 | * bzero(sizeof(*ip)); |
66 | * ip.ih_pr = nxt; | | 66 | * ip.ih_pr = nxt; |
67 | * ip.ip_len = htons(len); | | 67 | * ip.ip_len = htons(len); |
68 | * ip.ih_src = mtod(m, struct ip *)->ip_src; | | 68 | * ip.ih_src = mtod(m, struct ip *)->ip_src; |
69 | * ip.ih_dst = mtod(m, struct ip *)->ip_dst; | | 69 | * ip.ih_dst = mtod(m, struct ip *)->ip_dst; |
70 | * sum = one_add(&ip); | | 70 | * sum = one_add(&ip); |
71 | */ | | 71 | */ |
72 | | | 72 | |
73 | #if BYTE_ORDER == LITTLE_ENDIAN | | 73 | #if BYTE_ORDER == LITTLE_ENDIAN |