diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2006-11-15 00:19:22 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-12-03 00:23:12 -0500 |
commit | abf419b809bed2333267e4b23dd2b3b4f10da88c (patch) | |
tree | 69f47b8df85bac6cc2d158035932c9eee5a30625 | |
parent | c459dd90f0de00db1ca1328482214019f6ca292f (diff) |
[NET]: UML checksum annotations and cleanups.
* sanitize prototypes, annotate
* kill csum_partial_copy_fromuser
* kill shift-by-16 in checksum calculations
* ntohs->shift in checksum calculations
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | arch/um/include/sysdep-i386/checksum.h | 74 | ||||
-rw-r--r-- | arch/um/include/sysdep-x86_64/checksum.h | 47 |
2 files changed, 53 insertions, 68 deletions
diff --git a/arch/um/include/sysdep-i386/checksum.h b/arch/um/include/sysdep-i386/checksum.h index 052bb061a978..0cb4645cbeb8 100644 --- a/arch/um/include/sysdep-i386/checksum.h +++ b/arch/um/include/sysdep-i386/checksum.h | |||
@@ -20,8 +20,7 @@ | |||
20 | * | 20 | * |
21 | * it's best to have buff aligned on a 32-bit boundary | 21 | * it's best to have buff aligned on a 32-bit boundary |
22 | */ | 22 | */ |
23 | unsigned int csum_partial(const unsigned char * buff, int len, | 23 | __wsum csum_partial(const void *buff, int len, __wsum sum); |
24 | unsigned int sum); | ||
25 | 24 | ||
26 | /* | 25 | /* |
27 | * Note: when you get a NULL pointer exception here this means someone | 26 | * Note: when you get a NULL pointer exception here this means someone |
@@ -32,8 +31,8 @@ unsigned int csum_partial(const unsigned char * buff, int len, | |||
32 | */ | 31 | */ |
33 | 32 | ||
34 | static __inline__ | 33 | static __inline__ |
35 | unsigned int csum_partial_copy_nocheck(const unsigned char *src, unsigned char *dst, | 34 | __wsum csum_partial_copy_nocheck(const void *src, void *dst, |
36 | int len, int sum) | 35 | int len, __wsum sum) |
37 | { | 36 | { |
38 | memcpy(dst, src, len); | 37 | memcpy(dst, src, len); |
39 | return csum_partial(dst, len, sum); | 38 | return csum_partial(dst, len, sum); |
@@ -48,36 +47,25 @@ unsigned int csum_partial_copy_nocheck(const unsigned char *src, unsigned char * | |||
48 | */ | 47 | */ |
49 | 48 | ||
50 | static __inline__ | 49 | static __inline__ |
51 | unsigned int csum_partial_copy_from_user(const unsigned char __user *src, | 50 | __wsum csum_partial_copy_from_user(const void __user *src, void *dst, |
52 | unsigned char *dst, | 51 | int len, __wsum sum, int *err_ptr) |
53 | int len, int sum, int *err_ptr) | ||
54 | { | 52 | { |
55 | if(copy_from_user(dst, src, len)){ | 53 | if (copy_from_user(dst, src, len)) { |
56 | *err_ptr = -EFAULT; | 54 | *err_ptr = -EFAULT; |
57 | return(-1); | 55 | return (__force __wsum)-1; |
58 | } | 56 | } |
59 | 57 | ||
60 | return csum_partial(dst, len, sum); | 58 | return csum_partial(dst, len, sum); |
61 | } | 59 | } |
62 | 60 | ||
63 | /* | 61 | /* |
64 | * These are the old (and unsafe) way of doing checksums, a warning message | ||
65 | * will be printed if they are used and an exception occurs. | ||
66 | * | ||
67 | * these functions should go away after some time. | ||
68 | */ | ||
69 | |||
70 | #define csum_partial_copy_fromuser csum_partial_copy_from_user | ||
71 | |||
72 | /* | ||
73 | * This is a version of ip_compute_csum() optimized for IP headers, | 62 | * This is a version of ip_compute_csum() optimized for IP headers, |
74 | * which always checksum on 4 octet boundaries. | 63 | * which always checksum on 4 octet boundaries. |
75 | * | 64 | * |
76 | * By Jorge Cwik <jorge@laser.satlink.net>, adapted for linux by | 65 | * By Jorge Cwik <jorge@laser.satlink.net>, adapted for linux by |
77 | * Arnt Gulbrandsen. | 66 | * Arnt Gulbrandsen. |
78 | */ | 67 | */ |
79 | static inline unsigned short ip_fast_csum(unsigned char * iph, | 68 | static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl) |
80 | unsigned int ihl) | ||
81 | { | 69 | { |
82 | unsigned int sum; | 70 | unsigned int sum; |
83 | 71 | ||
@@ -105,29 +93,29 @@ static inline unsigned short ip_fast_csum(unsigned char * iph, | |||
105 | : "=r" (sum), "=r" (iph), "=r" (ihl) | 93 | : "=r" (sum), "=r" (iph), "=r" (ihl) |
106 | : "1" (iph), "2" (ihl) | 94 | : "1" (iph), "2" (ihl) |
107 | : "memory"); | 95 | : "memory"); |
108 | return sum; | 96 | return (__force __sum16)sum; |
109 | } | 97 | } |
110 | 98 | ||
111 | /* | 99 | /* |
112 | * Fold a partial checksum | 100 | * Fold a partial checksum |
113 | */ | 101 | */ |
114 | 102 | ||
115 | static inline unsigned int csum_fold(unsigned int sum) | 103 | static inline __sum16 csum_fold(__wsum sum) |
116 | { | 104 | { |
117 | __asm__( | 105 | __asm__( |
118 | "addl %1, %0 ;\n" | 106 | "addl %1, %0 ;\n" |
119 | "adcl $0xffff, %0 ;\n" | 107 | "adcl $0xffff, %0 ;\n" |
120 | : "=r" (sum) | 108 | : "=r" (sum) |
121 | : "r" (sum << 16), "0" (sum & 0xffff0000) | 109 | : "r" ((__force u32)sum << 16), |
110 | "0" ((__force u32)sum & 0xffff0000) | ||
122 | ); | 111 | ); |
123 | return (~sum) >> 16; | 112 | return (__force __sum16)(~(__force u32)sum >> 16); |
124 | } | 113 | } |
125 | 114 | ||
126 | static inline unsigned long csum_tcpudp_nofold(unsigned long saddr, | 115 | static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, |
127 | unsigned long daddr, | ||
128 | unsigned short len, | 116 | unsigned short len, |
129 | unsigned short proto, | 117 | unsigned short proto, |
130 | unsigned int sum) | 118 | __wsum sum) |
131 | { | 119 | { |
132 | __asm__( | 120 | __asm__( |
133 | "addl %1, %0 ;\n" | 121 | "addl %1, %0 ;\n" |
@@ -135,7 +123,7 @@ static inline unsigned long csum_tcpudp_nofold(unsigned long saddr, | |||
135 | "adcl %3, %0 ;\n" | 123 | "adcl %3, %0 ;\n" |
136 | "adcl $0, %0 ;\n" | 124 | "adcl $0, %0 ;\n" |
137 | : "=r" (sum) | 125 | : "=r" (sum) |
138 | : "g" (daddr), "g"(saddr), "g"((ntohs(len)<<16)+proto*256), "0"(sum)); | 126 | : "g" (daddr), "g"(saddr), "g"((len + proto) << 8), "0"(sum)); |
139 | return sum; | 127 | return sum; |
140 | } | 128 | } |
141 | 129 | ||
@@ -143,11 +131,10 @@ static inline unsigned long csum_tcpudp_nofold(unsigned long saddr, | |||
143 | * computes the checksum of the TCP/UDP pseudo-header | 131 | * computes the checksum of the TCP/UDP pseudo-header |
144 | * returns a 16-bit checksum, already complemented | 132 | * returns a 16-bit checksum, already complemented |
145 | */ | 133 | */ |
146 | static inline unsigned short int csum_tcpudp_magic(unsigned long saddr, | 134 | static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, |
147 | unsigned long daddr, | ||
148 | unsigned short len, | 135 | unsigned short len, |
149 | unsigned short proto, | 136 | unsigned short proto, |
150 | unsigned int sum) | 137 | __wsum sum) |
151 | { | 138 | { |
152 | return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); | 139 | return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); |
153 | } | 140 | } |
@@ -157,17 +144,16 @@ static inline unsigned short int csum_tcpudp_magic(unsigned long saddr, | |||
157 | * in icmp.c | 144 | * in icmp.c |
158 | */ | 145 | */ |
159 | 146 | ||
160 | static inline unsigned short ip_compute_csum(unsigned char * buff, int len) | 147 | static inline __sum16 ip_compute_csum(const void *buff, int len) |
161 | { | 148 | { |
162 | return csum_fold (csum_partial(buff, len, 0)); | 149 | return csum_fold (csum_partial(buff, len, 0)); |
163 | } | 150 | } |
164 | 151 | ||
165 | #define _HAVE_ARCH_IPV6_CSUM | 152 | #define _HAVE_ARCH_IPV6_CSUM |
166 | static __inline__ unsigned short int csum_ipv6_magic(struct in6_addr *saddr, | 153 | static __inline__ __sum16 csum_ipv6_magic(const struct in6_addr *saddr, |
167 | struct in6_addr *daddr, | 154 | const struct in6_addr *daddr, |
168 | __u32 len, | 155 | __u32 len, unsigned short proto, |
169 | unsigned short proto, | 156 | __wsum sum) |
170 | unsigned int sum) | ||
171 | { | 157 | { |
172 | __asm__( | 158 | __asm__( |
173 | "addl 0(%1), %0 ;\n" | 159 | "addl 0(%1), %0 ;\n" |
@@ -192,14 +178,14 @@ static __inline__ unsigned short int csum_ipv6_magic(struct in6_addr *saddr, | |||
192 | * Copy and checksum to user | 178 | * Copy and checksum to user |
193 | */ | 179 | */ |
194 | #define HAVE_CSUM_COPY_USER | 180 | #define HAVE_CSUM_COPY_USER |
195 | static __inline__ unsigned int csum_and_copy_to_user(const unsigned char *src, | 181 | static __inline__ __wsum csum_and_copy_to_user(const void *src, |
196 | unsigned char __user *dst, | 182 | void __user *dst, |
197 | int len, int sum, int *err_ptr) | 183 | int len, __wsum sum, int *err_ptr) |
198 | { | 184 | { |
199 | if (access_ok(VERIFY_WRITE, dst, len)){ | 185 | if (access_ok(VERIFY_WRITE, dst, len)) { |
200 | if(copy_to_user(dst, src, len)){ | 186 | if (copy_to_user(dst, src, len)) { |
201 | *err_ptr = -EFAULT; | 187 | *err_ptr = -EFAULT; |
202 | return(-1); | 188 | return (__force __wsum)-1; |
203 | } | 189 | } |
204 | 190 | ||
205 | return csum_partial(src, len, sum); | 191 | return csum_partial(src, len, sum); |
@@ -208,7 +194,7 @@ static __inline__ unsigned int csum_and_copy_to_user(const unsigned char *src, | |||
208 | if (len) | 194 | if (len) |
209 | *err_ptr = -EFAULT; | 195 | *err_ptr = -EFAULT; |
210 | 196 | ||
211 | return -1; /* invalid checksum */ | 197 | return (__force __wsum)-1; /* invalid checksum */ |
212 | } | 198 | } |
213 | 199 | ||
214 | #endif | 200 | #endif |
diff --git a/arch/um/include/sysdep-x86_64/checksum.h b/arch/um/include/sysdep-x86_64/checksum.h index ea97005af694..a5be9031ea85 100644 --- a/arch/um/include/sysdep-x86_64/checksum.h +++ b/arch/um/include/sysdep-x86_64/checksum.h | |||
@@ -9,8 +9,7 @@ | |||
9 | #include "linux/in6.h" | 9 | #include "linux/in6.h" |
10 | #include "asm/uaccess.h" | 10 | #include "asm/uaccess.h" |
11 | 11 | ||
12 | extern unsigned csum_partial(const unsigned char *buff, unsigned len, | 12 | extern __wsum csum_partial(const void *buff, int len, __wsum sum); |
13 | unsigned sum); | ||
14 | 13 | ||
15 | /* | 14 | /* |
16 | * Note: when you get a NULL pointer exception here this means someone | 15 | * Note: when you get a NULL pointer exception here this means someone |
@@ -21,21 +20,21 @@ extern unsigned csum_partial(const unsigned char *buff, unsigned len, | |||
21 | */ | 20 | */ |
22 | 21 | ||
23 | static __inline__ | 22 | static __inline__ |
24 | unsigned int csum_partial_copy_nocheck(const unsigned char *src, unsigned char *dst, | 23 | __wsum csum_partial_copy_nocheck(const void *src, void *dst, |
25 | int len, int sum) | 24 | int len, __wsum sum) |
26 | { | 25 | { |
27 | memcpy(dst, src, len); | 26 | memcpy(dst, src, len); |
28 | return(csum_partial(dst, len, sum)); | 27 | return(csum_partial(dst, len, sum)); |
29 | } | 28 | } |
30 | 29 | ||
31 | static __inline__ | 30 | static __inline__ |
32 | unsigned int csum_partial_copy_from_user(const unsigned char *src, | 31 | __wsum csum_partial_copy_from_user(const void __user *src, |
33 | unsigned char *dst, int len, int sum, | 32 | void *dst, int len, __wsum sum, |
34 | int *err_ptr) | 33 | int *err_ptr) |
35 | { | 34 | { |
36 | if(copy_from_user(dst, src, len)){ | 35 | if (copy_from_user(dst, src, len)) { |
37 | *err_ptr = -EFAULT; | 36 | *err_ptr = -EFAULT; |
38 | return(-1); | 37 | return (__force __wsum)-1; |
39 | } | 38 | } |
40 | return csum_partial(dst, len, sum); | 39 | return csum_partial(dst, len, sum); |
41 | } | 40 | } |
@@ -48,15 +47,16 @@ unsigned int csum_partial_copy_from_user(const unsigned char *src, | |||
48 | * the last step before putting a checksum into a packet. | 47 | * the last step before putting a checksum into a packet. |
49 | * Make sure not to mix with 64bit checksums. | 48 | * Make sure not to mix with 64bit checksums. |
50 | */ | 49 | */ |
51 | static inline unsigned int csum_fold(unsigned int sum) | 50 | static inline __sum16 csum_fold(__wsum sum) |
52 | { | 51 | { |
53 | __asm__( | 52 | __asm__( |
54 | " addl %1,%0\n" | 53 | " addl %1,%0\n" |
55 | " adcl $0xffff,%0" | 54 | " adcl $0xffff,%0" |
56 | : "=r" (sum) | 55 | : "=r" (sum) |
57 | : "r" (sum << 16), "0" (sum & 0xffff0000) | 56 | : "r" ((__force u32)sum << 16), |
57 | "0" ((__force u32)sum & 0xffff0000) | ||
58 | ); | 58 | ); |
59 | return (~sum) >> 16; | 59 | return (__force __sum16)(~(__force u32)sum >> 16); |
60 | } | 60 | } |
61 | 61 | ||
62 | /** | 62 | /** |
@@ -70,28 +70,27 @@ static inline unsigned int csum_fold(unsigned int sum) | |||
70 | * Returns the pseudo header checksum the input data. Result is | 70 | * Returns the pseudo header checksum the input data. Result is |
71 | * 32bit unfolded. | 71 | * 32bit unfolded. |
72 | */ | 72 | */ |
73 | static inline unsigned long | 73 | static inline __wsum |
74 | csum_tcpudp_nofold(unsigned saddr, unsigned daddr, unsigned short len, | 74 | csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len, |
75 | unsigned short proto, unsigned int sum) | 75 | unsigned short proto, __wsum sum) |
76 | { | 76 | { |
77 | asm(" addl %1, %0\n" | 77 | asm(" addl %1, %0\n" |
78 | " adcl %2, %0\n" | 78 | " adcl %2, %0\n" |
79 | " adcl %3, %0\n" | 79 | " adcl %3, %0\n" |
80 | " adcl $0, %0\n" | 80 | " adcl $0, %0\n" |
81 | : "=r" (sum) | 81 | : "=r" (sum) |
82 | : "g" (daddr), "g" (saddr), "g" ((ntohs(len)<<16)+proto*256), "0" (sum)); | 82 | : "g" (daddr), "g" (saddr), "g" ((len + proto) << 8), "0" (sum)); |
83 | return sum; | 83 | return sum; |
84 | } | 84 | } |
85 | 85 | ||
86 | /* | 86 | /* |
87 | * computes the checksum of the TCP/UDP pseudo-header | 87 | * computes the checksum of the TCP/UDP pseudo-header |
88 | * returns a 16-bit checksum, already complemented | 88 | * returns a 16-bit checksum, already complemented |
89 | */ | 89 | */ |
90 | static inline unsigned short int csum_tcpudp_magic(unsigned long saddr, | 90 | static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, |
91 | unsigned long daddr, | 91 | unsigned short len, |
92 | unsigned short len, | 92 | unsigned short proto, |
93 | unsigned short proto, | 93 | __wsum sum) |
94 | unsigned int sum) | ||
95 | { | 94 | { |
96 | return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); | 95 | return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); |
97 | } | 96 | } |
@@ -101,7 +100,7 @@ static inline unsigned short int csum_tcpudp_magic(unsigned long saddr, | |||
101 | * iph: ipv4 header | 100 | * iph: ipv4 header |
102 | * ihl: length of header / 4 | 101 | * ihl: length of header / 4 |
103 | */ | 102 | */ |
104 | static inline unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl) | 103 | static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl) |
105 | { | 104 | { |
106 | unsigned int sum; | 105 | unsigned int sum; |
107 | 106 | ||
@@ -128,7 +127,7 @@ static inline unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl) | |||
128 | : "=r" (sum), "=r" (iph), "=r" (ihl) | 127 | : "=r" (sum), "=r" (iph), "=r" (ihl) |
129 | : "1" (iph), "2" (ihl) | 128 | : "1" (iph), "2" (ihl) |
130 | : "memory"); | 129 | : "memory"); |
131 | return(sum); | 130 | return (__force __sum16)sum; |
132 | } | 131 | } |
133 | 132 | ||
134 | static inline unsigned add32_with_carry(unsigned a, unsigned b) | 133 | static inline unsigned add32_with_carry(unsigned a, unsigned b) |
@@ -140,6 +139,6 @@ static inline unsigned add32_with_carry(unsigned a, unsigned b) | |||
140 | return a; | 139 | return a; |
141 | } | 140 | } |
142 | 141 | ||
143 | extern unsigned short ip_compute_csum(unsigned char * buff, int len); | 142 | extern __sum16 ip_compute_csum(const void *buff, int len); |
144 | 143 | ||
145 | #endif | 144 | #endif |