Rev 3555 | Rev 3626 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3555 | Rev 3589 | ||
---|---|---|---|
Line 110... | Line 110... | ||
110 | dec ecx |
110 | dec ecx |
111 | jnz .loop |
111 | jnz .loop |
112 | jmp .done |
112 | jmp .done |
Line 113... | Line 113... | ||
113 | 113 | ||
114 | .died: |
114 | .died: |
115 | DEBUGF 2,"IPv4 Fragment slot timed-out!\n" |
115 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4 Fragment slot timed-out!\n" |
116 | ;;; TODO: clear all entry's of timed-out slot |
116 | ;;; TODO: clear all entry's of timed-out slot |
Line 117... | Line 117... | ||
117 | jmp .next |
117 | jmp .next |
118 | 118 | ||
Line 203... | Line 203... | ||
203 | ; |
203 | ; |
204 | ;----------------------------------------------------------------- |
204 | ;----------------------------------------------------------------- |
205 | align 4 |
205 | align 4 |
206 | IPv4_input: ; TODO: add IPv4 raw sockets support |
206 | IPv4_input: ; TODO: add IPv4 raw sockets support |
Line 207... | Line 207... | ||
207 | 207 | ||
208 | DEBUGF 2,"IPv4_input, packet from: %u.%u.%u.%u ",\ |
208 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input, packet from: %u.%u.%u.%u ",\ |
209 | [edx + IPv4_header.SourceAddress + 0]:1,[edx + IPv4_header.SourceAddress + 1]:1,\ |
209 | [edx + IPv4_header.SourceAddress + 0]:1,[edx + IPv4_header.SourceAddress + 1]:1,\ |
210 | [edx + IPv4_header.SourceAddress + 2]:1,[edx + IPv4_header.SourceAddress + 3]:1 |
210 | [edx + IPv4_header.SourceAddress + 2]:1,[edx + IPv4_header.SourceAddress + 3]:1 |
211 | DEBUGF 2,"to: %u.%u.%u.%u\n",\ |
211 | DEBUGF DEBUG_NETWORK_VERBOSE, "to: %u.%u.%u.%u\n",\ |
212 | [edx + IPv4_header.DestinationAddress + 0]:1,[edx + IPv4_header.DestinationAddress + 1]:1,\ |
212 | [edx + IPv4_header.DestinationAddress + 0]:1,[edx + IPv4_header.DestinationAddress + 1]:1,\ |
Line 213... | Line 213... | ||
213 | [edx + IPv4_header.DestinationAddress + 2]:1,[edx + IPv4_header.DestinationAddress + 3]:1 |
213 | [edx + IPv4_header.DestinationAddress + 2]:1,[edx + IPv4_header.DestinationAddress + 3]:1 |
214 | 214 | ||
Line 215... | Line 215... | ||
215 | ;------------------------------- |
215 | ;------------------------------- |
216 | ; re-calculate the checksum |
216 | ; re-calculate the checksum |
Line 217... | Line 217... | ||
217 | 217 | ||
Line 218... | Line 218... | ||
218 | IPv4_checksum edx |
218 | IPv4_checksum edx |
219 | jnz .dump ; if checksum isn't valid then dump packet |
219 | jnz .dump ; if checksum isn't valid then dump packet |
Line 220... | Line 220... | ||
220 | 220 | ||
Line 254... | Line 254... | ||
254 | cmp eax, 127 |
254 | cmp eax, 127 |
255 | je .ip_ok |
255 | je .ip_ok |
Line 256... | Line 256... | ||
256 | 256 | ||
Line 257... | Line 257... | ||
257 | ; or it's just not meant for us.. :( |
257 | ; or it's just not meant for us.. :( |
258 | 258 | ||
Line 259... | Line 259... | ||
259 | DEBUGF 2,"IPv4_input: Destination address does not match!\n" |
259 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: Destination address does not match!\n" |
260 | jmp .dump |
260 | jmp .dump |
Line 298... | Line 298... | ||
298 | je UDP_input |
298 | je UDP_input |
Line 299... | Line 299... | ||
299 | 299 | ||
300 | cmp al, IP_PROTO_ICMP |
300 | cmp al, IP_PROTO_ICMP |
Line 301... | Line 301... | ||
301 | je ICMP_input |
301 | je ICMP_input |
Line 302... | Line 302... | ||
302 | 302 | ||
303 | DEBUGF 2,"IPv4_input: unknown protocol %u\n", al |
303 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: unknown protocol %u\n", al |
304 | 304 | ||
305 | .dump: |
305 | .dump: |
306 | DEBUGF 1,"IPv4_input: dumping\n" |
306 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: dumping\n" |
307 | inc [IP_packets_dumped] ; FIXME: use correct interface |
307 | inc [IP_packets_dumped] ; FIXME: use correct interface |
Line 317... | Line 317... | ||
317 | .has_fragments: |
317 | .has_fragments: |
318 | movzx eax, [edx + IPv4_header.FlagsAndFragmentOffset] |
318 | movzx eax, [edx + IPv4_header.FlagsAndFragmentOffset] |
319 | xchg al, ah |
319 | xchg al, ah |
320 | shl ax, 3 |
320 | shl ax, 3 |
Line 321... | Line 321... | ||
321 | 321 | ||
Line 322... | Line 322... | ||
322 | DEBUGF 1,"IPv4_input: fragmented packet offset=%u id=%x\n", ax, [edx + IPv4_header.Identification]:4 |
322 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: fragmented packet offset=%u id=%x\n", ax, [edx + IPv4_header.Identification]:4 |
323 | 323 | ||
Line 324... | Line 324... | ||
324 | test ax, ax ; Is this the first packet of the fragment? |
324 | test ax, ax ; Is this the first packet of the fragment? |
325 | jz .is_first_fragment |
325 | jz .is_first_fragment |
Line 326... | Line 326... | ||
326 | 326 | ||
Line 327... | Line 327... | ||
327 | 327 | ||
328 | ;------------------------------------------------------- |
328 | ;------------------------------------------------------- |
329 | ; We have a fragmented IP packet, but it's not the first |
329 | ; We have a fragmented IP packet, but it's not the first |
Line 359... | Line 359... | ||
359 | 359 | ||
360 | ;------------------------------------ |
360 | ;------------------------------------ |
Line 361... | Line 361... | ||
361 | ; We have received the first fragment |
361 | ; We have received the first fragment |
362 | 362 | ||
363 | .is_first_fragment: |
363 | .is_first_fragment: |
364 | DEBUGF 1,"IPv4_input: First fragment packet received!\n" |
364 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: First fragment packet received!\n" |
365 | ; try to locate a free slot.. |
365 | ; try to locate a free slot.. |
366 | mov ecx, MAX_FRAGMENTS |
366 | mov ecx, MAX_FRAGMENTS |
367 | mov esi, FRAGMENT_LIST |
367 | mov esi, FRAGMENT_LIST |
Line 393... | Line 393... | ||
393 | 393 | ||
394 | ;----------------------------------- |
394 | ;----------------------------------- |
Line 395... | Line 395... | ||
395 | ; We have received the last fragment |
395 | ; We have received the last fragment |
396 | 396 | ||
Line 397... | Line 397... | ||
397 | .is_last_fragment: |
397 | .is_last_fragment: |
398 | DEBUGF 1,"IPv4_input: Last fragment packet received!\n" |
398 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: Last fragment packet received!\n" |
399 | 399 | ||
Line 409... | Line 409... | ||
409 | .count_bytes: |
409 | .count_bytes: |
410 | cmp [esi + FRAGMENT_entry.PrevPtr], edi |
410 | cmp [esi + FRAGMENT_entry.PrevPtr], edi |
411 | jne .destroy_slot_pop ; Damn, something screwed up, remove the whole slot (and free buffers too if possible!) |
411 | jne .destroy_slot_pop ; Damn, something screwed up, remove the whole slot (and free buffers too if possible!) |
412 | mov cx, [esi + sizeof.FRAGMENT_entry + IPv4_header.TotalLength] ; Add total length |
412 | mov cx, [esi + sizeof.FRAGMENT_entry + IPv4_header.TotalLength] ; Add total length |
413 | xchg cl, ch |
413 | xchg cl, ch |
414 | DEBUGF 1,"IPv4_input: Packet size=%u\n", cx |
414 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: Packet size=%u\n", cx |
415 | add ax, cx |
415 | add ax, cx |
416 | movzx cx, [esi + sizeof.FRAGMENT_entry + IPv4_header.VersionAndIHL] ; Sub Header length |
416 | movzx cx, [esi + sizeof.FRAGMENT_entry + IPv4_header.VersionAndIHL] ; Sub Header length |
417 | and cx, 0x000F |
417 | and cx, 0x000F |
418 | shl cx, 2 |
418 | shl cx, 2 |
419 | DEBUGF 1,"IPv4_input: Header size=%u\n", cx |
419 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: Header size=%u\n", cx |
420 | sub ax, cx |
420 | sub ax, cx |
421 | mov edi, esi |
421 | mov edi, esi |
422 | mov esi, [esi + FRAGMENT_entry.NextPtr] |
422 | mov esi, [esi + FRAGMENT_entry.NextPtr] |
423 | cmp esi, -1 |
423 | cmp esi, -1 |
424 | jne .count_bytes |
424 | jne .count_bytes |
Line 429... | Line 429... | ||
429 | mov [esi + FRAGMENT_entry.PrevPtr], edi |
429 | mov [esi + FRAGMENT_entry.PrevPtr], edi |
430 | mov [esi + FRAGMENT_entry.Owner], ebx |
430 | mov [esi + FRAGMENT_entry.Owner], ebx |
Line 431... | Line 431... | ||
431 | 431 | ||
432 | mov cx, [edx + IPv4_header.TotalLength] ; Note: This time we dont substract Header length |
432 | mov cx, [edx + IPv4_header.TotalLength] ; Note: This time we dont substract Header length |
433 | xchg cl, ch |
433 | xchg cl, ch |
434 | DEBUGF 1,"IPv4_input: Packet size=%u\n", cx |
434 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: Packet size=%u\n", cx |
435 | add ax, cx |
435 | add ax, cx |
Line 436... | Line 436... | ||
436 | DEBUGF 1,"IPv4_input: Total Received data size=%u\n", eax |
436 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: Total Received data size=%u\n", eax |
437 | 437 | ||
438 | push eax |
438 | push eax |
439 | mov ax, [edx + IPv4_header.FlagsAndFragmentOffset] |
439 | mov ax, [edx + IPv4_header.FlagsAndFragmentOffset] |
440 | xchg al, ah |
440 | xchg al, ah |
441 | shl ax, 3 |
441 | shl ax, 3 |
442 | add cx, ax |
442 | add cx, ax |
Line 443... | Line 443... | ||
443 | pop eax |
443 | pop eax |
444 | DEBUGF 1,"IPv4_input: Total Fragment size=%u\n", ecx |
444 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: Total Fragment size=%u\n", ecx |
Line 445... | Line 445... | ||
445 | 445 | ||
Line 455... | Line 455... | ||
455 | 455 | ||
456 | .rebuild_packet_loop: |
456 | .rebuild_packet_loop: |
457 | movzx ecx, [edx + sizeof.FRAGMENT_entry + IPv4_header.FlagsAndFragmentOffset] ; Calculate the fragment offset |
457 | movzx ecx, [edx + sizeof.FRAGMENT_entry + IPv4_header.FlagsAndFragmentOffset] ; Calculate the fragment offset |
458 | xchg cl, ch ; intel byte order |
458 | xchg cl, ch ; intel byte order |
459 | shl cx, 3 ; multiply by 8 and clear first 3 bits |
459 | shl cx, 3 ; multiply by 8 and clear first 3 bits |
Line 460... | Line 460... | ||
460 | DEBUGF 1,"IPv4_input: Fragment offset=%u\n", cx |
460 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: Fragment offset=%u\n", cx |
461 | 461 | ||
462 | lea edi, [eax + ecx] ; Notice that edi will be equal to eax for first fragment |
462 | lea edi, [eax + ecx] ; Notice that edi will be equal to eax for first fragment |
463 | movzx ebx, [edx + sizeof.FRAGMENT_entry + IPv4_header.VersionAndIHL] ; Find header size (in ebx) of fragment |
463 | movzx ebx, [edx + sizeof.FRAGMENT_entry + IPv4_header.VersionAndIHL] ; Find header size (in ebx) of fragment |
Line 502... | Line 502... | ||
502 | jmp .handle_it ; edx = buf ptr, ecx = size, [esp] buf ptr, [esp+4], total size, ebx=device ptr |
502 | jmp .handle_it ; edx = buf ptr, ecx = size, [esp] buf ptr, [esp+4], total size, ebx=device ptr |
Line 503... | Line 503... | ||
503 | 503 | ||
504 | .destroy_slot_pop: |
504 | .destroy_slot_pop: |
505 | add esp, 4 |
505 | add esp, 4 |
506 | .destroy_slot: |
506 | .destroy_slot: |
507 | DEBUGF 1,"IPv4_input: Destroy fragment slot!\n" |
507 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: Destroy fragment slot!\n" |
508 | ; TODO! |
508 | ; TODO! |
Line 566... | Line 566... | ||
566 | ; |
566 | ; |
567 | ;------------------------------------------------------------------ |
567 | ;------------------------------------------------------------------ |
568 | align 4 |
568 | align 4 |
569 | IPv4_output: |
569 | IPv4_output: |
Line 570... | Line 570... | ||
570 | 570 | ||
Line 571... | Line 571... | ||
571 | DEBUGF 1,"IPv4_output: size=%u\n", ecx |
571 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_output: size=%u\n", ecx |
572 | 572 | ||
Line 573... | Line 573... | ||
573 | cmp ecx, 65500 ; Max IPv4 packet size |
573 | cmp ecx, 65500 ; Max IPv4 packet size |
Line 612... | Line 612... | ||
612 | 612 | ||
Line 613... | Line 613... | ||
613 | pop ecx |
613 | pop ecx |
614 | 614 | ||
615 | IPv4_checksum edi |
615 | IPv4_checksum edi |
616 | add edi, sizeof.IPv4_header |
616 | add edi, sizeof.IPv4_header |
Line 617... | Line 617... | ||
617 | DEBUGF 2,"IPv4_output: success!\n" |
617 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_output: success!\n" |
618 | ret |
618 | ret |
619 | 619 | ||
620 | .eth_error: |
620 | .eth_error: |
621 | DEBUGF 2,"IPv4_output: ethernet error\n" |
621 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_output: ethernet error\n" |
Line 622... | Line 622... | ||
622 | add esp, 3*4+2+6 |
622 | add esp, 3*4+2+6 |
623 | xor edi, edi |
623 | xor edi, edi |
624 | ret |
624 | ret |
625 | 625 | ||
626 | .arp_error: |
626 | .arp_error: |
Line 627... | Line 627... | ||
627 | DEBUGF 2,"IPv4_output: ARP error=%x\n", eax |
627 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_output: ARP error=%x\n", eax |
628 | add esp, 3*4+2 |
628 | add esp, 3*4+2 |
629 | xor edi, edi |
629 | xor edi, edi |
630 | ret |
630 | ret |
Line 631... | Line 631... | ||
631 | 631 | ||
632 | .too_large: |
632 | .too_large: |
Line 711... | Line 711... | ||
711 | ; [edi + IPv4_header.SourceAddress] |
711 | ; [edi + IPv4_header.SourceAddress] |
712 | ; [edi + IPv4_header.DestinationAddress] |
712 | ; [edi + IPv4_header.DestinationAddress] |
Line 713... | Line 713... | ||
713 | 713 | ||
714 | IPv4_checksum edi ;;;; todo: checksum for IP packet with options! |
714 | IPv4_checksum edi ;;;; todo: checksum for IP packet with options! |
715 | add edi, sizeof.IPv4_header |
715 | add edi, sizeof.IPv4_header |
716 | DEBUGF 2,"IPv4_output_raw: device=%x\n", ebx |
716 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_output_raw: device=%x\n", ebx |
717 | call [ebx + NET_DEVICE.transmit] |
717 | call [ebx + NET_DEVICE.transmit] |
Line 718... | Line 718... | ||
718 | ret |
718 | ret |
719 | 719 | ||
720 | .error: |
720 | .error: |
721 | add esp, 6 |
721 | add esp, 6 |
722 | .arp_error: |
722 | .arp_error: |
723 | add esp, 8+4+4 |
723 | add esp, 8+4+4 |
724 | .too_large: |
724 | .too_large: |
725 | DEBUGF 2,"IPv4_output_raw: Failed\n" |
725 | DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output_raw: Failed\n" |
Line 726... | Line 726... | ||
726 | sub edi, edi |
726 | sub edi, edi |
Line 740... | Line 740... | ||
740 | ;-------------------------------------------------------- |
740 | ;-------------------------------------------------------- |
Line 741... | Line 741... | ||
741 | 741 | ||
742 | align 4 |
742 | align 4 |
Line 743... | Line 743... | ||
743 | IPv4_fragment: |
743 | IPv4_fragment: |
Line 744... | Line 744... | ||
744 | 744 | ||
Line 745... | Line 745... | ||
745 | DEBUGF 1,"IPv4_fragment\n" |
745 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_fragment\n" |
746 | 746 | ||
Line 768... | Line 768... | ||
768 | sub ecx, sizeof.IPv4_header ; substract header size |
768 | sub ecx, sizeof.IPv4_header ; substract header size |
769 | push ecx ; max data size |
769 | push ecx ; max data size |
770 | push dword 0 ; offset |
770 | push dword 0 ; offset |
Line 771... | Line 771... | ||
771 | 771 | ||
772 | .new_fragment: |
772 | .new_fragment: |
Line 773... | Line 773... | ||
773 | DEBUGF 1,"Ipv4_fragment: new fragment" |
773 | DEBUGF DEBUG_NETWORK_VERBOSE, "Ipv4_fragment: new fragment" |
774 | 774 | ||
775 | 775 | ||
Line 790... | Line 790... | ||
790 | mov esi, [esp + 2*4] |
790 | mov esi, [esp + 2*4] |
791 | add esi, sizeof.IPv4_header |
791 | add esi, sizeof.IPv4_header |
792 | add esi, [esp] ; offset |
792 | add esi, [esp] ; offset |
Line 793... | Line 793... | ||
793 | 793 | ||
794 | mov ecx, [esp + 1*4] |
794 | mov ecx, [esp + 1*4] |
795 | DEBUGF 1,"IPv4_fragment: copying %u bytes\n", ecx |
795 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_fragment: copying %u bytes\n", ecx |
Line 796... | Line 796... | ||
796 | rep movsb |
796 | rep movsb |
797 | 797 | ||
798 | ; now, correct header |
798 | ; now, correct header |
Line 827... | Line 827... | ||
827 | mov ecx, [esp+3*4+6+4] ; ptr to begin of buff |
827 | mov ecx, [esp+3*4+6+4] ; ptr to begin of buff |
828 | add ecx, [esp+3*4+6+4+4] ; buff size |
828 | add ecx, [esp+3*4+6+4+4] ; buff size |
829 | sub ecx, [esp+2*4] ; ptr to ip header |
829 | sub ecx, [esp+2*4] ; ptr to ip header |
830 | add ecx, [esp] ; offset |
830 | add ecx, [esp] ; offset |
Line 831... | Line 831... | ||
831 | 831 | ||
Line 832... | Line 832... | ||
832 | DEBUGF 1,"Ipv4_fragment: %u bytes remaining\n", ecx |
832 | DEBUGF DEBUG_NETWORK_VERBOSE, "Ipv4_fragment: %u bytes remaining\n", ecx |
833 | 833 | ||
Line 834... | Line 834... | ||
834 | cmp ecx, [esp+1*4] |
834 | cmp ecx, [esp+1*4] |
835 | jae .new_fragment |
835 | jae .new_fragment |
Line 836... | Line 836... | ||
836 | 836 | ||
837 | mov [esp+4], ecx ; set fragment size to remaining packet size |
837 | mov [esp+4], ecx ; set fragment size to remaining packet size |
838 | jmp .new_fragment |
838 | jmp .new_fragment |
839 | 839 | ||
840 | .err: |
840 | .err: |
841 | DEBUGF 1,"Ipv4_fragment: failed\n" |
841 | DEBUGF DEBUG_NETWORK_ERROR, "Ipv4_fragment: failed\n" |
842 | .done: |
842 | .done: |
843 | add esp, 12 + 4 + 6 |
843 | add esp, 12 + 4 + 6 |
Line 844... | Line 844... | ||
844 | .err2: |
844 | .err2: |
Line 884... | Line 884... | ||
884 | .invalid: |
884 | .invalid: |
885 | xor edi, edi ; if none found, use device 0 as default |
885 | xor edi, edi ; if none found, use device 0 as default |
886 | mov eax, [GATEWAY_LIST] |
886 | mov eax, [GATEWAY_LIST] |
Line 887... | Line 887... | ||
887 | 887 | ||
888 | .found_it: |
888 | .found_it: |
889 | DEBUGF 1,"IPv4_dest_to_dev: %u\n", edi |
889 | DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_route: %u\n", edi |
Line 890... | Line 890... | ||
890 | ret |
890 | ret |
891 | 891 | ||
892 | .broadcast: |
892 | .broadcast: |