Rev 2731 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2731 | Rev 2877 | ||
---|---|---|---|
Line 14... | Line 14... | ||
14 | ;; GNU GENERAL PUBLIC LICENSE ;; |
14 | ;; GNU GENERAL PUBLIC LICENSE ;; |
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 | $Revision: 2731 $ |
19 | $Revision: 2877 $ |
20 | 20 | ||
21 | MAX_FRAGMENTS = 64 |
21 | MAX_FRAGMENTS = 64 |
Line 554... | Line 554... | ||
554 | ;------------------------------------------------------------------ |
554 | ;------------------------------------------------------------------ |
555 | ; |
555 | ; |
556 | ; IPv4_output |
556 | ; IPv4_output |
557 | ; |
557 | ; |
558 | ; IN: eax = dest ip |
558 | ; IN: eax = dest ip |
559 | ; ebx = source ip |
559 | ; ebx = output device ptr/0 for automatic choice |
560 | ; ecx = data length |
560 | ; ecx = data length |
561 | ; dx = fragment id |
561 | ; edx = source ip |
562 | ; di = TTL shl 8 + protocol |
562 | ; di = TTL shl 8 + protocol |
563 | ; |
563 | ; |
564 | ; OUT: eax = pointer to buffer start |
564 | ; OUT: eax = pointer to buffer start |
565 | ; ebx = pointer to device struct (needed for sending procedure) |
565 | ; ebx = pointer to device struct (needed for sending procedure) |
566 | ; ecx = unchanged (packet size of embedded data) |
566 | ; ecx = unchanged (packet size of embedded data) |
Line 574... | Line 574... | ||
574 | DEBUGF 1,"IPv4_output: size=%u\n", ecx |
574 | DEBUGF 1,"IPv4_output: size=%u\n", ecx |
Line 575... | Line 575... | ||
575 | 575 | ||
576 | cmp ecx, 65500 ; Max IPv4 packet size |
576 | cmp ecx, 65500 ; Max IPv4 packet size |
Line 577... | Line 577... | ||
577 | ja .too_large |
577 | ja .too_large |
Line -... | Line 578... | ||
- | 578 | ||
578 | 579 | push ecx eax edx di |
|
579 | push ecx eax ebx dx di |
- | |
580 | 580 | ||
581 | call ARP_IP_to_MAC |
581 | call IPv4_dest_to_dev ; outputs device number in edi, dest ip in eax |
582 | - | ||
583 | test eax, 0xffff0000 ; error bits |
582 | call ARP_IP_to_MAC |
584 | jnz .arp_error |
583 | test eax, 0xffff0000 ; error bits |
Line 585... | Line -... | ||
585 | - | ||
586 | push ebx ; push the mac |
584 | jnz .arp_error |
- | 585 | push ebx ; push the mac onto the stack |
|
587 | push ax |
586 | push ax |
588 | 587 | ||
589 | call IPv4_dest_to_dev |
588 | inc [IP_PACKETS_TX + edi] ; update stats |
590 | inc [IP_PACKETS_TX+edi] |
589 | |
591 | mov ebx, [NET_DRV_LIST+edi] |
590 | mov ebx, [NET_DRV_LIST + edi] |
592 | lea eax, [ebx + ETH_DEVICE.mac] |
591 | lea eax, [ebx + ETH_DEVICE.mac] |
593 | mov edx, esp |
592 | mov edx, esp |
594 | mov ecx, [esp + 18] |
593 | mov ecx, [esp + 10 + 6] |
- | 594 | add ecx, sizeof.IPv4_header |
|
Line 595... | Line 595... | ||
595 | add ecx, sizeof.IPv4_header |
595 | mov di, ETHER_IPv4 |
596 | mov di , ETHER_IPv4 |
- | |
597 | call ETH_output |
596 | call ETH_output |
598 | jz .eth_error |
597 | jz .eth_error |
599 | 598 | add esp, 6 ; pop the mac out of the stack |
|
600 | add esp, 6 ; pop the mac |
599 | |
601 | 600 | xchg cl, ch ; internet byte order |
|
602 | mov [edi + IPv4_header.VersionAndIHL], 0x45 ; IPv4, normal length (no Optional header) |
- | |
603 | mov [edi + IPv4_header.TypeOfService], 0 ; nothing special, just plain ip packet |
601 | mov [edi + IPv4_header.VersionAndIHL], 0x45 ; IPv4, normal length (no Optional header) |
604 | mov [edi + IPv4_header.TotalLength], cx |
602 | mov [edi + IPv4_header.TypeOfService], 0 ; nothing special, just plain ip packet |
605 | rol [edi + IPv4_header.TotalLength], 8 ; internet byte order |
603 | mov [edi + IPv4_header.TotalLength], cx |
606 | mov [edi + IPv4_header.FlagsAndFragmentOffset], 0x0000 |
604 | mov [edi + IPv4_header.Identification], 0 ; fragment id: FIXME |
607 | mov [edi + IPv4_header.HeaderChecksum], 0 |
605 | mov [edi + IPv4_header.FlagsAndFragmentOffset], 0 |
Line 608... | Line 606... | ||
608 | pop word [edi + IPv4_header.TimeToLive] ; ttl shl 8 + protocol |
606 | pop word [edi + IPv4_header.TimeToLive] ; ttl shl 8 + protocol |
Line 618... | Line 616... | ||
618 | DEBUGF 1,"IPv4 Packet for device %x created successfully\n", ebx |
616 | DEBUGF 1,"IPv4 Packet for device %x created successfully\n", ebx |
619 | ret |
617 | ret |
Line 620... | Line 618... | ||
620 | 618 | ||
621 | .eth_error: |
619 | .eth_error: |
622 | DEBUGF 1,"IPv4_output: ethernet error\n" |
620 | DEBUGF 1,"IPv4_output: ethernet error\n" |
623 | add esp, 3*4+2*2+6 |
621 | add esp, 3*4+2+6 |
624 | sub edi, edi |
622 | xor edi, edi |
Line 625... | Line 623... | ||
625 | ret |
623 | ret |
626 | 624 | ||
627 | .arp_error: |
625 | .arp_error: |
628 | DEBUGF 1,"IPv4_output: ARP error (0x%x)\n", eax |
626 | DEBUGF 1,"IPv4_output: ARP error (0x%x)\n", eax |
629 | add esp, 4+4+4+2+2 |
627 | add esp, 3*4+2 |
Line 630... | Line 628... | ||
630 | sub edi, edi |
628 | xor edi, edi |
631 | ret |
629 | ret |
632 | 630 | ||
633 | .too_large: |
631 | .too_large: |
Line 659... | Line 657... | ||
659 | ja .too_large |
657 | ja .too_large |
Line 660... | Line 658... | ||
660 | 658 | ||
661 | sub esp, 8 |
659 | sub esp, 8 |
Line -... | Line 660... | ||
- | 660 | push esi eax |
|
662 | push esi eax |
661 | |
Line 663... | Line 662... | ||
663 | 662 | call IPv4_dest_to_dev |
|
664 | call ARP_IP_to_MAC |
663 | call ARP_IP_to_MAC |
Line 665... | Line -... | ||
665 | - | ||
666 | test eax, 0xffff0000 ; error bits |
- | |
667 | jnz .arp_error |
664 | |
668 | 665 | test eax, 0xffff0000 ; error bits |
|
Line 669... | Line -... | ||
669 | .continue: |
- | |
670 | 666 | jnz .arp_error |
|
671 | push ebx ; push the mac |
667 | |
672 | push ax |
668 | push ebx ; push the mac |
673 | 669 | push ax |
|
674 | call IPv4_dest_to_dev |
670 | |
Line 851... | Line 847... | ||
851 | ; |
847 | ; |
852 | ; IPv4_dest_to_dev |
848 | ; IPv4_dest_to_dev |
853 | ; |
849 | ; |
854 | ; IN: eax = Destination IP |
850 | ; IN: eax = Destination IP |
855 | ; OUT: edi = device id * 4 |
851 | ; OUT: edi = device id * 4 |
- | 852 | ; eax = ip of gateway if nescessary, unchanged otherwise |
|
856 | ; |
853 | ; |
857 | ;--------------------------------------------------------------------------- |
854 | ;--------------------------------------------------------------------------- |
858 | align 4 |
855 | align 4 |
859 | IPv4_dest_to_dev: |
856 | IPv4_dest_to_dev: |
Line 860... | Line 857... | ||
860 | 857 | ||
861 | cmp eax, 0xffffffff |
858 | cmp eax, 0xffffffff |
Line 862... | Line 859... | ||
862 | je .invalid |
859 | je .broadcast |
863 | 860 | ||
864 | xor edi, edi |
- | |
865 | mov ecx, MAX_IP |
861 | xor edi, edi |
866 | 862 | mov ecx, MAX_IP |
|
867 | .loop: |
863 | .loop: |
868 | mov ebx, [IP_LIST+edi] |
864 | mov ebx, [IP_LIST+edi] |
869 | and ebx, [SUBNET_LIST+edi] |
- | |
870 | jz .next |
865 | and ebx, [SUBNET_LIST+edi] |
871 | 866 | jz .next |
|
Line 872... | Line 867... | ||
872 | mov edx, eax |
867 | mov edx, eax |
873 | and edx, [SUBNET_LIST+edi] |
868 | and edx, [SUBNET_LIST+edi] |
Line 878... | Line 873... | ||
878 | add edi, 4 |
873 | add edi, 4 |
879 | dec ecx |
874 | dec ecx |
880 | jnz .loop |
875 | jnz .loop |
Line 881... | Line 876... | ||
881 | 876 | ||
882 | .invalid: |
877 | .invalid: |
- | 878 | xor edi, edi ; if none found, use device 0 as default |
|
Line 883... | Line 879... | ||
883 | xor edi, edi ; if none found, use device 0 as default device |
879 | mov eax, [GATEWAY_LIST] |
884 | 880 | ||
- | 881 | .found_it: |
|
Line -... | Line 882... | ||
- | 882 | DEBUGF 1,"IPv4_dest_to_dev: %u\n", edi |
|
- | 883 | ret |
|
885 | .found_it: |
884 | |
Line 886... | Line 885... | ||
886 | DEBUGF 1,"IPv4_dest_to_dev: %u\n", edi |
885 | .broadcast: |