Rev 2434 | Rev 3555 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2434 | Rev 2465 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;; ICMP.INC ;; |
6 | ;; ICMP.INC ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; Internet Control Message Protocol ( RFC 792 ) ;; |
8 | ;; Internet Control Message Protocol ( RFC 792 ) ;; |
9 | ;; ;; |
9 | ;; ;; |
10 | ;; Last revision: 11.11.2006 ;; |
10 | ;; Last revision: 11.11.2006 ;; |
11 | ;; ;; |
11 | ;; ;; |
12 | ;; This file contains the following: ;; |
12 | ;; This file contains the following: ;; |
13 | ;; icmp_rx - processes ICMP-packets received by the IP layer ;; |
13 | ;; icmp_rx - processes ICMP-packets received by the IP layer ;; |
14 | ;; ;; |
14 | ;; ;; |
15 | ;; Changes history: ;; |
15 | ;; Changes history: ;; |
16 | ;; 22.09.2003 - [Mike Hibbett] : mikeh@oceanfree.net ;; |
16 | ;; 22.09.2003 - [Mike Hibbett] : mikeh@oceanfree.net ;; |
17 | ;; 11.11.2006 - [Johnny_B] and [smb] ;; |
17 | ;; 11.11.2006 - [Johnny_B] and [smb] ;; |
18 | ;; ;; |
18 | ;; ;; |
19 | ;; Current status: ;; |
19 | ;; Current status: ;; |
20 | ;; This implemetation of ICMP proto supports message of ECHO type. |
20 | ;; This implemetation of ICMP proto supports message of ECHO type. |
21 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
21 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
22 | 22 | ||
23 | $Revision: 2434 $ |
23 | $Revision: 2465 $ |
24 | 24 | ||
25 | 25 | ||
26 | struc ICMP_PACKET |
26 | struc ICMP_PACKET |
27 | { .Type db ? ;+00 |
27 | { .Type db ? ;+00 |
28 | .Code db ? ;+01 |
28 | .Code db ? ;+01 |
29 | .Checksum dw ? ;+02 |
29 | .Checksum dw ? ;+02 |
30 | .Identifier dw ? ;+04 |
30 | .Identifier dw ? ;+04 |
31 | .SequenceNumber dw ? ;+06 |
31 | .SequenceNumber dw ? ;+06 |
32 | .Data db ? ;+08 |
32 | .Data db ? ;+08 |
33 | } |
33 | } |
34 | 34 | ||
35 | virtual at 0 |
35 | virtual at 0 |
36 | ICMP_PACKET ICMP_PACKET |
36 | ICMP_PACKET ICMP_PACKET |
37 | end virtual |
37 | end virtual |
38 | 38 | ||
39 | 39 | ||
40 | ; Example: |
40 | ; Example: |
41 | ; ECHO message format |
41 | ; ECHO message format |
42 | ; |
42 | ; |
43 | ; |
43 | ; |
44 | ; 0 1 2 3 |
44 | ; 0 1 2 3 |
45 | ; 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 |
45 | ; 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 |
46 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
46 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
47 | ; | Type | Code | Checksum | |
47 | ; | Type | Code | Checksum | |
48 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
48 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
49 | ; | Identifier | Sequence Number | |
49 | ; | Identifier | Sequence Number | |
50 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
50 | ; +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
51 | ; | Data ... |
51 | ; | Data ... |
52 | ; +-+-+-+-+- |
52 | ; +-+-+-+-+- |
53 | ; |
53 | ; |
54 | 54 | ||
55 | ; |
55 | ; |
56 | ; ICMP types & codes, RFC 792 and FreeBSD's ICMP sources |
56 | ; ICMP types & codes, RFC 792 and FreeBSD's ICMP sources |
57 | ; |
57 | ; |
58 | 58 | ||
59 | ICMP_ECHOREPLY equ 0 ; echo reply message |
59 | ICMP_ECHOREPLY equ 0 ; echo reply message |
60 | 60 | ||
61 | ICMP_UNREACH equ 3 |
61 | ICMP_UNREACH equ 3 |
62 | ICMP_UNREACH_NET equ 0 ; bad net |
62 | ICMP_UNREACH_NET equ 0 ; bad net |
63 | ICMP_UNREACH_HOST equ 1 ; bad host |
63 | ICMP_UNREACH_HOST equ 1 ; bad host |
64 | ICMP_UNREACH_PROTOCOL equ 2 ; bad protocol |
64 | ICMP_UNREACH_PROTOCOL equ 2 ; bad protocol |
65 | ICMP_UNREACH_PORT equ 3 ; bad port |
65 | ICMP_UNREACH_PORT equ 3 ; bad port |
66 | ICMP_UNREACH_NEEDFRAG equ 4 ; IP_DF caused drop |
66 | ICMP_UNREACH_NEEDFRAG equ 4 ; IP_DF caused drop |
67 | ICMP_UNREACH_SRCFAIL equ 5 ; src route failed |
67 | ICMP_UNREACH_SRCFAIL equ 5 ; src route failed |
68 | ICMP_UNREACH_NET_UNKNOWN equ 6 ; unknown net |
68 | ICMP_UNREACH_NET_UNKNOWN equ 6 ; unknown net |
69 | ICMP_UNREACH_HOST_UNKNOWN equ 7 ; unknown host |
69 | ICMP_UNREACH_HOST_UNKNOWN equ 7 ; unknown host |
70 | ICMP_UNREACH_ISOLATED equ 8 ; src host isolated |
70 | ICMP_UNREACH_ISOLATED equ 8 ; src host isolated |
71 | ICMP_UNREACH_NET_PROHIB equ 9 ; prohibited access |
71 | ICMP_UNREACH_NET_PROHIB equ 9 ; prohibited access |
72 | ICMP_UNREACH_HOST_PROHIB equ 10 ; ditto |
72 | ICMP_UNREACH_HOST_PROHIB equ 10 ; ditto |
73 | ICMP_UNREACH_TOSNET equ 11 ; bad tos for net |
73 | ICMP_UNREACH_TOSNET equ 11 ; bad tos for net |
74 | ICMP_UNREACH_TOSHOST equ 12 ; bad tos for host |
74 | ICMP_UNREACH_TOSHOST equ 12 ; bad tos for host |
75 | ICMP_UNREACH_FILTER_PROHIB equ 13 ; admin prohib |
75 | ICMP_UNREACH_FILTER_PROHIB equ 13 ; admin prohib |
76 | ICMP_UNREACH_HOST_PRECEDENCE equ 14 ; host prec vio. |
76 | ICMP_UNREACH_HOST_PRECEDENCE equ 14 ; host prec vio. |
77 | ICMP_UNREACH_PRECEDENCE_CUTOFF equ 15 ; prec cutoff |
77 | ICMP_UNREACH_PRECEDENCE_CUTOFF equ 15 ; prec cutoff |
78 | 78 | ||
79 | ICMP_SOURCEQUENCH equ 4 ; packet lost, slow down |
79 | ICMP_SOURCEQUENCH equ 4 ; packet lost, slow down |
80 | 80 | ||
81 | ICMP_REDIRECT equ 5 ; shorter route, codes: |
81 | ICMP_REDIRECT equ 5 ; shorter route, codes: |
82 | ICMP_REDIRECT_NET equ 0 ; for network |
82 | ICMP_REDIRECT_NET equ 0 ; for network |
83 | ICMP_REDIRECT_HOST equ 1 ; for host |
83 | ICMP_REDIRECT_HOST equ 1 ; for host |
84 | ICMP_REDIRECT_TOSNET equ 2 ; for tos and net |
84 | ICMP_REDIRECT_TOSNET equ 2 ; for tos and net |
85 | ICMP_REDIRECT_TOSHOST equ 3 ; for tos and host |
85 | ICMP_REDIRECT_TOSHOST equ 3 ; for tos and host |
86 | 86 | ||
87 | ICMP_ALTHOSTADDR equ 6 ; alternate host address |
87 | ICMP_ALTHOSTADDR equ 6 ; alternate host address |
88 | ICMP_ECHO equ 8 ; echo service |
88 | ICMP_ECHO equ 8 ; echo service |
89 | ICMP_ROUTERADVERT equ 9 ; router advertisement |
89 | ICMP_ROUTERADVERT equ 9 ; router advertisement |
90 | ICMP_ROUTERADVERT_NORMAL equ 0 ; normal advertisement |
90 | ICMP_ROUTERADVERT_NORMAL equ 0 ; normal advertisement |
91 | ICMP_ROUTERADVERT_NOROUTE_COMMON equ 16 ; selective routing |
91 | ICMP_ROUTERADVERT_NOROUTE_COMMON equ 16 ; selective routing |
92 | 92 | ||
93 | ICMP_ROUTERSOLICIT equ 10 ; router solicitation |
93 | ICMP_ROUTERSOLICIT equ 10 ; router solicitation |
94 | ICMP_TIMXCEED equ 11 ; time exceeded, code: |
94 | ICMP_TIMXCEED equ 11 ; time exceeded, code: |
95 | ICMP_TIMXCEED_INTRANS equ 0 ; ttl==0 in transit |
95 | ICMP_TIMXCEED_INTRANS equ 0 ; ttl==0 in transit |
96 | ICMP_TIMXCEED_REASS equ 1 ; ttl==0 in reass |
96 | ICMP_TIMXCEED_REASS equ 1 ; ttl==0 in reass |
97 | 97 | ||
98 | ICMP_PARAMPROB equ 12 ; ip header bad |
98 | ICMP_PARAMPROB equ 12 ; ip header bad |
99 | ICMP_PARAMPROB_ERRATPTR equ 0 ; error at param ptr |
99 | ICMP_PARAMPROB_ERRATPTR equ 0 ; error at param ptr |
100 | ICMP_PARAMPROB_OPTABSENT equ 1 ; req. opt. absent |
100 | ICMP_PARAMPROB_OPTABSENT equ 1 ; req. opt. absent |
101 | ICMP_PARAMPROB_LENGTH equ 2 ; bad length |
101 | ICMP_PARAMPROB_LENGTH equ 2 ; bad length |
102 | 102 | ||
103 | ICMP_TSTAMP equ 13 ; timestamp request |
103 | ICMP_TSTAMP equ 13 ; timestamp request |
104 | ICMP_TSTAMPREPLY equ 14 ; timestamp reply |
104 | ICMP_TSTAMPREPLY equ 14 ; timestamp reply |
105 | ICMP_IREQ equ 15 ; information request |
105 | ICMP_IREQ equ 15 ; information request |
106 | ICMP_IREQREPLY equ 16 ; information reply |
106 | ICMP_IREQREPLY equ 16 ; information reply |
107 | ICMP_MASKREQ equ 17 ; address mask request |
107 | ICMP_MASKREQ equ 17 ; address mask request |
108 | ICMP_MASKREPLY equ 18 ; address mask reply |
108 | ICMP_MASKREPLY equ 18 ; address mask reply |
109 | ICMP_TRACEROUTE equ 30 ; traceroute |
109 | ICMP_TRACEROUTE equ 30 ; traceroute |
110 | ICMP_DATACONVERR equ 31 ; data conversion error |
110 | ICMP_DATACONVERR equ 31 ; data conversion error |
111 | ICMP_MOBILE_REDIRECT equ 32 ; mobile host redirect |
111 | ICMP_MOBILE_REDIRECT equ 32 ; mobile host redirect |
112 | ICMP_IPV6_WHEREAREYOU equ 33 ; IPv6 where-are-you |
112 | ICMP_IPV6_WHEREAREYOU equ 33 ; IPv6 where-are-you |
113 | ICMP_IPV6_IAMHERE equ 34 ; IPv6 i-am-here |
113 | ICMP_IPV6_IAMHERE equ 34 ; IPv6 i-am-here |
114 | ICMP_MOBILE_REGREQUEST equ 35 ; mobile registration req |
114 | ICMP_MOBILE_REGREQUEST equ 35 ; mobile registration req |
115 | ICMP_MOBILE_REGREPLY equ 36 ; mobile registreation reply |
115 | ICMP_MOBILE_REGREPLY equ 36 ; mobile registreation reply |
116 | ICMP_SKIP equ 39 ; SKIP |
116 | ICMP_SKIP equ 39 ; SKIP |
117 | 117 | ||
118 | ICMP_PHOTURIS equ 40 ; Photuris |
118 | ICMP_PHOTURIS equ 40 ; Photuris |
119 | ICMP_PHOTURIS_UNKNOWN_INDEX equ 1 ; unknown sec index |
119 | ICMP_PHOTURIS_UNKNOWN_INDEX equ 1 ; unknown sec index |
120 | ICMP_PHOTURIS_AUTH_FAILED equ 2 ; auth failed |
120 | ICMP_PHOTURIS_AUTH_FAILED equ 2 ; auth failed |
121 | ICMP_PHOTURIS_DECRYPT_FAILED equ 3 ; decrypt failed |
121 | ICMP_PHOTURIS_DECRYPT_FAILED equ 3 ; decrypt failed |
122 | 122 | ||
123 | 123 | ||
124 | ;*************************************************************************** |
124 | ;*************************************************************************** |
125 | ; Function |
125 | ; Function |
126 | ; icmp_rx [by Johnny_B] |
126 | ; icmp_rx [by Johnny_B] |
127 | ; |
127 | ; |
128 | ; Description |
128 | ; Description |
129 | ; ICMP protocol handler |
129 | ; ICMP protocol handler |
130 | ; This is a kernel function, called by ip_rx |
130 | ; This is a kernel function, called by ip_rx |
131 | ; |
131 | ; |
132 | ; IN: |
132 | ; IN: |
133 | ; buffer_number - # of IP-buffer. This buffer must be reused or marked as empty afterwards |
133 | ; buffer_number - # of IP-buffer. This buffer must be reused or marked as empty afterwards |
134 | ; IPPacketBase - IP_PACKET base address |
134 | ; IPPacketBase - IP_PACKET base address |
135 | ; IPHeaderLength - Header length of IP_PACKET |
135 | ; IPHeaderLength - Header length of IP_PACKET |
136 | ; |
136 | ; |
137 | ; OUT: |
137 | ; OUT: |
138 | ; EAX=not defined |
138 | ; EAX=not defined |
139 | ; |
139 | ; |
140 | ; All used registers will be saved |
140 | ; All used registers will be saved |
141 | ; |
141 | ; |
142 | ;*************************************************************************** |
142 | ;*************************************************************************** |
143 | proc icmp_rx stdcall uses ebx esi edi,\ |
143 | proc icmp_rx stdcall uses ebx esi edi,\ |
144 | buffer_number:DWORD,IPPacketBase:DWORD,IPHeaderLength:DWORD |
144 | buffer_number:DWORD,IPPacketBase:DWORD,IPHeaderLength:DWORD |
145 | 145 | ||
146 | mov esi, [IPPacketBase];esi=IP_PACKET base address |
146 | mov esi, [IPPacketBase];esi=IP_PACKET base address |
147 | mov edi, esi |
147 | mov edi, esi |
148 | add edi, [IPHeaderLength];edi=ICMP_PACKET base address |
148 | add edi, [IPHeaderLength];edi=ICMP_PACKET base address |
149 | 149 | ||
150 | cmp byte[edi + ICMP_PACKET.Type], ICMP_ECHO; Is this an echo request? discard if not |
150 | cmp byte[edi + ICMP_PACKET.Type], ICMP_ECHO; Is this an echo request? discard if not |
151 | jz .icmp_echo |
151 | jz .icmp_echo |
152 | 152 | ||
153 | mov eax, [buffer_number] |
153 | mov eax, [buffer_number] |
154 | call freeBuff |
154 | call freeBuff |
155 | jmp .exit |
155 | jmp .exit |
156 | 156 | ||
157 | .icmp_echo: |
157 | .icmp_echo: |
158 | 158 | ||
159 | ; swap the source and destination addresses |
159 | ; swap the source and destination addresses |
160 | mov ecx, [esi + IP_PACKET.DestinationAddress] |
160 | mov ecx, [esi + IP_PACKET.DestinationAddress] |
161 | mov ebx, [esi + IP_PACKET.SourceAddress] |
161 | mov ebx, [esi + IP_PACKET.SourceAddress] |
162 | mov [esi + IP_PACKET.DestinationAddress], ebx |
162 | mov [esi + IP_PACKET.DestinationAddress], ebx |
163 | mov [esi + IP_PACKET.SourceAddress], ecx |
163 | mov [esi + IP_PACKET.SourceAddress], ecx |
164 | 164 | ||
165 | ; recalculate the IP header checksum |
165 | ; recalculate the IP header checksum |
166 | mov eax, [IPHeaderLength] |
166 | mov eax, [IPHeaderLength] |
167 | stdcall checksum_jb, esi, eax;buf_ptr,buf_size |
167 | stdcall checksum_jb, esi, eax;buf_ptr,buf_size |
168 | 168 | ||
169 | mov byte[esi + IP_PACKET.HeaderChecksum], ah |
169 | mov byte[esi + IP_PACKET.HeaderChecksum], ah |
170 | mov byte[esi + IP_PACKET.HeaderChecksum + 1], al ; ?? correct byte order? |
170 | mov byte[esi + IP_PACKET.HeaderChecksum + 1], al ; ?? correct byte order? |
171 | 171 | ||
172 | mov byte[edi + ICMP_PACKET.Type], ICMP_ECHOREPLY; change the request to a response |
172 | mov byte[edi + ICMP_PACKET.Type], ICMP_ECHOREPLY; change the request to a response |
173 | mov word[edi + ICMP_PACKET.Checksum], 0; clear ICMP checksum prior to re-calc |
173 | mov word[edi + ICMP_PACKET.Checksum], 0; clear ICMP checksum prior to re-calc |
174 | 174 | ||
175 | ; Calculate the length of the ICMP data ( IP payload) |
175 | ; Calculate the length of the ICMP data ( IP payload) |
176 | xor eax, eax |
176 | xor eax, eax |
177 | mov ah, byte[esi + IP_PACKET.TotalLength] |
177 | mov ah, byte[esi + IP_PACKET.TotalLength] |
178 | mov al, byte[esi + IP_PACKET.TotalLength + 1] |
178 | mov al, byte[esi + IP_PACKET.TotalLength + 1] |
179 | sub ax, word[IPHeaderLength];ax=ICMP-packet length |
179 | sub ax, word[IPHeaderLength];ax=ICMP-packet length |
180 | 180 | ||
181 | stdcall checksum_jb, edi, eax;buf_ptr,buf_size |
181 | stdcall checksum_jb, edi, eax;buf_ptr,buf_size |
182 | 182 | ||
183 | mov byte[edi + ICMP_PACKET.Checksum], ah |
183 | mov byte[edi + ICMP_PACKET.Checksum], ah |
184 | mov byte[edi + ICMP_PACKET.Checksum + 1], al |
184 | mov byte[edi + ICMP_PACKET.Checksum + 1], al |
185 | 185 | ||
186 | ; Queue packet for transmission |
186 | ; Queue packet for transmission |
187 | mov ebx, [buffer_number] |
187 | mov ebx, [buffer_number] |
188 | mov eax, NET1OUT_QUEUE |
188 | mov eax, NET1OUT_QUEUE |
189 | call queue |
189 | call queue |
190 | 190 | ||
191 | .exit: |
191 | .exit: |
192 | ret |
192 | ret |
193 | endp |
193 | endp |