Rev 1529 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1529 | Rev 1541 | ||
---|---|---|---|
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: 1529 $ |
20 | $Revision: 1541 $ |
Line 130... | Line 130... | ||
130 | ; This procedure will send reply's to ICMP echo's |
130 | ; This procedure will send reply's to ICMP echo's |
131 | ; and insert packets into sockets when needed |
131 | ; and insert packets into sockets when needed |
132 | ; |
132 | ; |
133 | ; IN: Pointer to buffer in [esp] |
133 | ; IN: Pointer to buffer in [esp] |
134 | ; size of buffer in [esp+4] |
134 | ; size of buffer in [esp+4] |
135 | ; pointer to device struct in ebx |
135 | ; ebx = pointer to device struct |
136 | ; ICMP Packet size in ecx |
136 | ; ecx = ICMP Packet size |
137 | ; pointer to ICMP Packet data in edx |
137 | ; edx = ptr to ICMP Packet data |
- | 138 | ; esi = ipv4 source address |
|
- | 139 | ; edi = ipv4 dest address |
|
138 | ; OUT: / |
140 | ; OUT: / |
139 | ; |
141 | ; |
140 | ;----------------------------------------------------------------- |
142 | ;----------------------------------------------------------------- |
141 | align 4 |
143 | align 4 |
142 | ICMP_input: |
144 | ICMP_input: |
Line 143... | Line 145... | ||
143 | 145 | ||
Line 144... | Line 146... | ||
144 | ;;; TODO: works only on pure ethernet right now ! |
146 | ;;; TODO: check checksum! |
145 | 147 | ||
146 | DEBUGF 1,"ICMP_Handler - start\n" |
148 | DEBUGF 1,"ICMP_input - start\n" |
Line 147... | Line -... | ||
147 | cmp byte [edx + ICMP_Packet.Type], ICMP_ECHO ; Is this an echo request? |
- | |
148 | jne .check_sockets |
- | |
149 | 149 | cmp byte [edx + ICMP_Packet.Type], ICMP_ECHO ; Is this an echo request? |
|
Line 150... | Line 150... | ||
150 | ;;; TODO: check checksum! |
150 | jne .check_sockets |
151 | 151 | ||
Line 152... | Line 152... | ||
152 | DEBUGF 1,"ICMP_Handler - echo request\n" |
152 | DEBUGF 1,"ICMP_input - echo request\n" |
Line 209... | Line 209... | ||
209 | 209 | ||
210 | - | ||
211 | - | ||
212 | 210 | ||
- | 211 | ||
Line 213... | Line 212... | ||
213 | .check_sockets: |
212 | |
214 | ; TODO: validate the header & checksum. |
213 | .check_sockets: |
215 | 214 | ; Look for an open ICMP socket |
|
216 | ; Look for an open ICMP socket |
215 | ; esi = sender ip |
217 | 216 | ||
218 | mov esi, net_sockets |
217 | mov ebx, net_sockets |
219 | .try_more: |
218 | .try_more: |
- | 219 | ; mov ax , [edx + ICMP_Packet.Identifier] |
|
220 | mov ax , [edx + ICMP_Packet.Identifier] |
220 | .next_socket: |
221 | .next_socket: |
221 | mov ebx, [ebx + SOCKET.NextPtr] |
- | 222 | or ebx, ebx |
|
222 | mov esi, [esi + SOCKET.NextPtr] |
223 | jz .dump |
223 | or esi, esi |
224 | |
Line 224... | Line 225... | ||
224 | jz .dump |
225 | cmp [ebx + SOCKET.Domain], AF_INET4 |
225 | cmp [esi + SOCKET.Type], IP_PROTO_ICMP |
- | |
226 | jne .next_socket |
226 | jne .next_socket |
227 | cmp [esi + ICMP_SOCKET.Identifier], ax |
- | |
Line 228... | Line 227... | ||
228 | jne .next_socket |
227 | |
- | 228 | cmp [ebx + SOCKET.Type], SOCK_RAW |
|
Line 229... | Line 229... | ||
229 | 229 | jne .next_socket |
|
230 | call IPv4_dest_to_dev |
230 | |
Line 231... | Line 231... | ||
231 | cmp edi,-1 |
231 | cmp [ebx + SOCKET.Protocol], IP_PROTO_ICMP |
232 | je .dump |
232 | jne .next_socket |
233 | inc [ICMP_PACKETS_RX+edi] |
233 | |
- | 234 | cmp [ebx + IP_SOCKET.RemoteIP], esi |
|
Line -... | Line 235... | ||
- | 235 | jne .next_socket |
|
- | 236 | ||
234 | 237 | ; cmp [esi + ICMP_SOCKET.Identifier], ax |
|
235 | DEBUGF 1,"Found valid ICMP packet for socket %x\n", esi |
- | |
236 | 238 | ; jne .next_socket |
|
237 | lea ebx, [esi + SOCKET.lock] |
239 | |
- | 240 | ; call IPv4_dest_to_dev |
|
238 | call wait_mutex |
241 | ; cmp edi,-1 |
239 | 242 | ; je .dump |
|
Line -... | Line 243... | ||
- | 243 | ; inc [ICMP_PACKETS_RX+edi] |
|
240 | ; Now, assign data to socket. We have socket address in esi. |
244 | |
241 | ; We have ICMP Packet in edx |
245 | DEBUGF 1,"Found valid ICMP packet for socket %x\n", ebx |
Line 242... | Line 246... | ||
242 | ; number of bytes in ecx |
246 | |
243 | 247 | mov eax, ebx |
|
Line 276... | Line 280... | ||
276 | 280 | ||
Line 277... | Line 281... | ||
277 | DEBUGF 1,"Creating ICMP Packet\n" |
281 | DEBUGF 1,"Creating ICMP Packet\n" |
Line -... | Line 282... | ||
- | 282 | ||
- | 283 | push esi edi edx |
|
278 | 284 | ||
279 | push esi edi edx |
285 | mov ebx, [eax + IP_SOCKET.LocalIP] |
280 | 286 | mov eax, [eax + IP_SOCKET.RemoteIP] |
|
Line 281... | Line 287... | ||
281 | add ecx, ICMP_Packet.Data |
287 | add ecx, ICMP_Packet.Data |
Line 323... | Line 329... | ||
323 | ret |
329 | ret |
Line -... | Line 330... | ||
- | 330 | ||
- | 331 | ||
- | 332 | ||
- | 333 | ||
- | 334 | ;----------------------------------------------------------------- |
|
- | 335 | ; |
|
- | 336 | ; ICMP_output |
|
- | 337 | ; |
|
- | 338 | ; IN: eax = socket ptr |
|
- | 339 | ; ecx = data length |
|
- | 340 | ; esi = data offset |
|
- | 341 | ; |
|
- | 342 | ;----------------------------------------------------------------- |
|
- | 343 | align 4 |
|
- | 344 | ICMP_output_raw: |
|
- | 345 | ||
- | 346 | DEBUGF 1,"Creating ICMP Packet for socket %x, data ptr=%x\n", eax, edx |
|
- | 347 | ||
- | 348 | push edx |
|
- | 349 | ||
- | 350 | mov di, IP_PROTO_ICMP SHL 8 + 128 ; TTL |
|
- | 351 | shr edx, 16 |
|
- | 352 | mov ebx, [eax + IP_SOCKET.LocalIP] |
|
- | 353 | mov eax, [eax + IP_SOCKET.RemoteIP] |
|
- | 354 | call IPv4_output |
|
- | 355 | jz .exit |
|
- | 356 | ||
- | 357 | pop esi |
|
- | 358 | push edx |
|
- | 359 | push eax |
|
- | 360 | ||
- | 361 | push edi ecx |
|
- | 362 | DEBUGF 1,"copying %u bytes from %x to %x\n", ecx, esi, edi |
|
- | 363 | rep movsb |
|
- | 364 | pop ecx edi |
|
- | 365 | ||
- | 366 | mov [edi + ICMP_Packet.Checksum], 0 |
|
- | 367 | ||
- | 368 | mov esi, edi |
|
- | 369 | xor edx, edx |
|
- | 370 | call checksum_1 |
|
- | 371 | call checksum_2 |
|
- | 372 | mov [edi + ICMP_Packet.Checksum], dx |
|
- | 373 | ||
- | 374 | DEBUGF 1,"Sending ICMP Packet\n" |
|
- | 375 | call [ebx + NET_DEVICE.transmit] |
|
- | 376 | ret |
|
- | 377 | .exit: |
|
- | 378 | DEBUGF 1,"Creating ICMP Packet failed\n" |
|
- | 379 | add esp, 4 |
|
- | 380 | ret |
|
324 | 381 | ||
325 | 382 | ||
326 | 383 | ||
327 | 384 | ||
328 | ;----------------------------------------------------------------- |
385 | ;----------------------------------------------------------------- |