This source file includes following definitions.
- ip_fast_csum
- csum_tcpudp_magic
- ip_compute_csum
1 #ifndef _I386_CHECKSUM_H
2 #define _I386_CHECKSUM_H
3
4
5
6
7
8
9
10
11
12
13
14
15
16 unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum);
17
18
19
20
21
22
23
24
25
26 unsigned int csum_partial_copy( const char *src, char *dst, int len, int sum);
27
28
29
30
31
32
33
34
35
36 unsigned int csum_partial_copy_fromuser(const char *src, char *dst, int len, int sum);
37
38
39
40
41
42
43
44
45 static inline unsigned short ip_fast_csum(unsigned char * iph,
46 unsigned int ihl) {
47 unsigned int sum;
48
49 __asm__("
50 movl (%1), %0
51 subl $4, %2
52 jbe 2f
53 addl 4(%1), %0
54 adcl 8(%1), %0
55 adcl 12(%1), %0
56 1: adcl 16(%1), %0
57 lea 4(%1), %1
58 decl %2
59 jne 1b
60 adcl $0, %0
61 movl %0, %2
62 shrl $16, %0
63 addw %w2, %w0
64 adcl $0, %0
65 notl %0
66 2:
67 "
68 : "=&r" (sum), "=&r" (iph), "=&r" (ihl)
69 : "1" (iph), "2" (ihl));
70 return(sum);
71 }
72
73
74
75
76
77
78
79
80
81 static inline unsigned short int csum_tcpudp_magic(unsigned long saddr,
82 unsigned long daddr,
83 unsigned short len,
84 unsigned short proto,
85 unsigned int sum) {
86 __asm__("
87 addl %1, %0
88 adcl %4, %0
89 adcl %5, %0
90 adcl $0, %0
91 movl %0, %1
92 shrl $16, %1
93 addw %w1, %w0
94 adcl $0, %0
95 notl %0
96 "
97 : "=&r" (sum), "=&r" (saddr)
98 : "0" (daddr), "1"(saddr), "r"((ntohs(len)<<16)+proto*256), "r"(sum));
99 return((unsigned short)sum);
100 }
101
102
103
104
105
106
107 static inline unsigned short ip_compute_csum(unsigned char * buff, int len) {
108 unsigned int sum;
109
110 unsigned int scratch;
111 __asm__("
112 movl %0, %1
113 shrl $16, %1
114 addw %w1, %w0
115 adcl $0, %0
116 notl %0
117 "
118 : "=a"(sum), "=r" (scratch)
119 : "0" (csum_partial(buff, len, 0)));
120 return(sum);
121 }
122
123 #endif