Rev 2302 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2302 | Rev 2305 | ||
---|---|---|---|
Line 15... | Line 15... | ||
15 | ;; Version 2, June 1991 ;; |
15 | ;; Version 2, June 1991 ;; |
16 | ;; ;; |
16 | ;; ;; |
17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 18... | Line 18... | ||
18 | 18 | ||
Line 19... | Line 19... | ||
19 | 19 | ||
Line 20... | Line 20... | ||
20 | $Revision: 2302 $ |
20 | $Revision: 2305 $ |
Line 85... | Line 85... | ||
85 | ICMP_PHOTURIS_AUTH_FAILED equ 2 ; auth failed |
85 | ICMP_PHOTURIS_AUTH_FAILED equ 2 ; auth failed |
86 | ICMP_PHOTURIS_DECRYPT_FAILED equ 3 ; decrypt failed |
86 | ICMP_PHOTURIS_DECRYPT_FAILED equ 3 ; decrypt failed |
Line 87... | Line 87... | ||
87 | 87 | ||
- | 88 | ||
88 | 89 | ||
89 | 90 | struct ICMP_header |
|
90 | struct ICMP_Packet |
91 | |
91 | .Type db ? |
92 | Type db ? |
92 | .Code db ? |
93 | Code db ? |
93 | .Checksum dw ? |
94 | Checksum dw ? |
94 | .Identifier dw ? |
95 | Identifier dw ? |
Line 95... | Line 96... | ||
95 | .SequenceNumber dw ? |
96 | SequenceNumber dw ? |
96 | .Data: |
97 | |
Line 144... | Line 145... | ||
144 | DEBUGF 1,"ICMP_input - start\n" |
145 | DEBUGF 1,"ICMP_input - start\n" |
Line 145... | Line 146... | ||
145 | 146 | ||
Line 146... | Line 147... | ||
146 | ; First, check the checksum (altough some implementations ignore it) |
147 | ; First, check the checksum (altough some implementations ignore it) |
147 | 148 | ||
148 | push edx esi ecx |
149 | push edx esi ecx |
149 | push [edx + ICMP_Packet.Checksum] |
150 | push [edx + ICMP_header.Checksum] |
150 | mov [edx + ICMP_Packet.Checksum], 0 |
151 | mov [edx + ICMP_header.Checksum], 0 |
151 | mov esi, edx |
152 | mov esi, edx |
152 | xor edx, edx |
153 | xor edx, edx |
153 | call checksum_1 |
154 | call checksum_1 |
154 | call checksum_2 |
155 | call checksum_2 |
155 | pop si |
156 | pop si |
156 | cmp dx, si |
157 | cmp dx, si |
Line 157... | Line 158... | ||
157 | pop ecx esi edx |
158 | pop ecx esi edx |
158 | jne .checksum_mismatch |
159 | jne .checksum_mismatch |
Line 159... | Line 160... | ||
159 | 160 | ||
160 | cmp byte [edx + ICMP_Packet.Type], ICMP_ECHO ; Is this an echo request? |
161 | cmp [edx + ICMP_header.Type], ICMP_ECHO ; Is this an echo request? |
Line 161... | Line 162... | ||
161 | jne .check_sockets |
162 | jne .check_sockets |
162 | 163 | ||
Line 163... | Line 164... | ||
163 | ; We well re-use the packet sow e can create the response as fast as possible |
164 | ; We well re-use the packet sow e can create the response as fast as possible |
164 | ; Notice: this only works on pure ethernet (however, IP packet options are not a problem this time :) |
165 | ; Notice: this only works on pure ethernet (however, IP packet options are not a problem this time :) |
165 | 166 | ||
166 | DEBUGF 1,"ICMP_input - echo request\n" |
167 | DEBUGF 1,"ICMP_input - echo request\n" |
Line 174... | Line 175... | ||
174 | inc [ICMP_PACKETS_TX+4*edi] |
175 | inc [ICMP_PACKETS_TX+4*edi] |
Line 175... | Line 176... | ||
175 | 176 | ||
176 | ; exchange dest and source address in IP header |
177 | ; exchange dest and source address in IP header |
177 | ; exchange dest and source MAC in ETH header |
178 | ; exchange dest and source MAC in ETH header |
178 | mov esi, [esp] ; Start of buffer |
179 | mov esi, [esp] ; Start of buffer |
179 | push dword [esi + ETH_FRAME.DstMAC] |
180 | push dword [esi + ETH_header.DstMAC] |
180 | push dword [esi + ETH_FRAME.SrcMAC] |
181 | push dword [esi + ETH_header.SrcMAC] |
181 | pop dword [esi + ETH_FRAME.DstMAC] |
182 | pop dword [esi + ETH_header.DstMAC] |
182 | pop dword [esi + ETH_FRAME.SrcMAC] |
183 | pop dword [esi + ETH_header.SrcMAC] |
183 | push word [esi + ETH_FRAME.DstMAC + 4] |
184 | push word [esi + ETH_header.DstMAC + 4] |
184 | push word [esi + ETH_FRAME.SrcMAC + 4] |
185 | push word [esi + ETH_header.SrcMAC + 4] |
185 | pop word [esi + ETH_FRAME.DstMAC + 4] |
186 | pop word [esi + ETH_header.DstMAC + 4] |
186 | pop word [esi + ETH_FRAME.SrcMAC + 4] |
187 | pop word [esi + ETH_header.SrcMAC + 4] |
187 | 188 | ||
188 | add esi, ETH_FRAME.Data |
189 | add esi, sizeof.ETH_header |
189 | push [esi + IPv4_Packet.SourceAddress] |
190 | push [esi + IPv4_header.SourceAddress] |
190 | push [esi + IPv4_Packet.DestinationAddress] |
191 | push [esi + IPv4_header.DestinationAddress] |
191 | pop [esi + IPv4_Packet.SourceAddress] |
192 | pop [esi + IPv4_header.SourceAddress] |
Line 192... | Line 193... | ||
192 | pop [esi + IPv4_Packet.DestinationAddress] |
193 | pop [esi + IPv4_header.DestinationAddress] |
193 | 194 | ||
194 | ; Recalculate ip header checksum |
195 | ; Recalculate ip header checksum |
195 | movzx ecx, [esi + IPv4_Packet.VersionAndIHL] ; Calculate IP Header length by using IHL field |
196 | movzx ecx, [esi + IPv4_header.VersionAndIHL] ; Calculate IP Header length by using IHL field |
196 | and ecx, 0x0f |
197 | and ecx, 0x0f |
197 | shl cx, 2 |
198 | shl cx, 2 |
Line 198... | Line 199... | ||
198 | mov edi, ecx ; IP header length |
199 | mov edi, ecx ; IP header length |
199 | mov eax, edx ; ICMP packet start addr |
200 | mov eax, edx ; ICMP packet start addr |
200 | 201 | ||
201 | push esi ; Calculate the IP checksum |
202 | push esi ; Calculate the IP checksum |
202 | xor edx, edx ; |
203 | xor edx, edx ; |
203 | call checksum_1 ; |
204 | call checksum_1 ; |
Line 204... | Line 205... | ||
204 | call checksum_2 ; |
205 | call checksum_2 ; |
205 | pop esi ; |
206 | pop esi ; |
206 | mov [esi + IPv4_Packet.HeaderChecksum], dx ; |
207 | mov [esi + IPv4_header.HeaderChecksum], dx ; |
207 | 208 | ||
Line 208... | Line 209... | ||
208 | ; Recalculate ICMP CheckSum |
209 | ; Recalculate ICMP CheckSum |
209 | movzx ecx, [esi + IPv4_Packet.TotalLength] ; Find length of IP Packet |
210 | movzx ecx, [esi + IPv4_header.TotalLength] ; Find length of IP Packet |
210 | xchg ch, cl ; |
211 | xchg ch, cl ; |
211 | sub ecx, edi ; IP packet length - IP header length = ICMP packet length |
212 | sub ecx, edi ; IP packet length - IP header length = ICMP packet length |
212 | 213 | ||
Line 213... | Line 214... | ||
213 | mov esi, eax ; Calculate ICMP checksum |
214 | mov esi, eax ; Calculate ICMP checksum |
214 | xor edx, edx ; |
215 | xor edx, edx ; |
215 | call checksum_1 ; |
216 | call checksum_1 ; |
Line 227... | Line 228... | ||
227 | ; Look for an open ICMP socket |
228 | ; Look for an open ICMP socket |
228 | ; esi = sender ip |
229 | ; esi = sender ip |
Line 229... | Line 230... | ||
229 | 230 | ||
230 | mov ebx, net_sockets |
231 | mov ebx, net_sockets |
231 | .try_more: |
232 | .try_more: |
232 | ; mov ax , [edx + ICMP_Packet.Identifier] |
233 | ; mov ax , [edx + ICMP_header.Identifier] |
233 | .next_socket: |
234 | .next_socket: |
234 | mov ebx, [ebx + SOCKET.NextPtr] |
235 | mov ebx, [ebx + SOCKET.NextPtr] |
235 | or ebx, ebx |
236 | or ebx, ebx |
Line 295... | Line 296... | ||
295 | 296 | ||
Line 296... | Line 297... | ||
296 | push esi edi edx |
297 | push esi edi edx |
297 | 298 | ||
298 | mov ebx, [eax + IP_SOCKET.LocalIP] |
299 | mov ebx, [eax + IP_SOCKET.LocalIP] |
299 | mov eax, [eax + IP_SOCKET.RemoteIP] |
300 | mov eax, [eax + IP_SOCKET.RemoteIP] |
300 | add ecx, ICMP_Packet.Data |
301 | add ecx, sizeof.ICMP_header |
Line 301... | Line 302... | ||
301 | mov di , IP_PROTO_ICMP SHL 8 + 128 ; TTL |
302 | mov di , IP_PROTO_ICMP SHL 8 + 128 ; TTL |
302 | shr edx, 16 |
303 | shr edx, 16 |
Line 303... | Line 304... | ||
303 | 304 | ||
Line 304... | Line 305... | ||
304 | call IPv4_output |
305 | call IPv4_output |
305 | jz .exit |
306 | jz .exit |
306 | 307 | ||
307 | DEBUGF 1,"full icmp packet size: %u\n", edx |
308 | DEBUGF 1,"full icmp packet size: %u\n", edx |
308 | 309 | ||
309 | pop eax |
310 | pop eax |
310 | mov word [edi + ICMP_Packet.Type], ax ; Write both type and code bytes at once |
311 | mov word [edi + ICMP_header.Type], ax ; Write both type and code bytes at once |
Line 311... | Line 312... | ||
311 | pop eax |
312 | pop eax |
312 | mov [edi + ICMP_Packet.SequenceNumber], ax |
313 | mov [edi + ICMP_header.SequenceNumber], ax |
313 | shr eax, 16 |
314 | shr eax, 16 |
314 | mov [edi + ICMP_Packet.Identifier], ax |
315 | mov [edi + ICMP_header.Identifier], ax |
315 | mov [edi + ICMP_Packet.Checksum], 0 |
316 | mov [edi + ICMP_header.Checksum], 0 |
316 | 317 | ||
317 | push eax ebx ecx edx |
318 | push eax ebx ecx edx |
Line 318... | Line 319... | ||
318 | mov esi, edi |
319 | mov esi, edi |
319 | xor edx, edx |
320 | xor edx, edx |
320 | call checksum_1 |
321 | call checksum_1 |
321 | call checksum_2 |
322 | call checksum_2 |
322 | mov [edi + ICMP_Packet.Checksum], dx |
323 | mov [edi + ICMP_header.Checksum], dx |
323 | pop edx ecx ebx eax esi |
324 | pop edx ecx ebx eax esi |
324 | 325 | ||
Line 374... | Line 375... | ||
374 | push edi ecx |
375 | push edi ecx |
375 | DEBUGF 1,"copying %u bytes from %x to %x\n", ecx, esi, edi |
376 | DEBUGF 1,"copying %u bytes from %x to %x\n", ecx, esi, edi |
376 | rep movsb |
377 | rep movsb |
377 | pop ecx edi |
378 | pop ecx edi |
Line 378... | Line 379... | ||
378 | 379 | ||
Line 379... | Line 380... | ||
379 | mov [edi + ICMP_Packet.Checksum], 0 |
380 | mov [edi + ICMP_header.Checksum], 0 |
380 | 381 | ||
381 | mov esi, edi |
382 | mov esi, edi |
382 | xor edx, edx |
383 | xor edx, edx |
383 | call checksum_1 |
384 | call checksum_1 |
Line 384... | Line 385... | ||
384 | call checksum_2 |
385 | call checksum_2 |
385 | mov [edi + ICMP_Packet.Checksum], dx |
386 | mov [edi + ICMP_header.Checksum], dx |
386 | 387 | ||
387 | DEBUGF 1,"Sending ICMP Packet\n" |
388 | DEBUGF 1,"Sending ICMP Packet\n" |