Rev 4423 | Rev 5565 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4423 | Rev 5201 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2014. 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 | ;; IPv4.INC ;; |
6 | ;; IPv4.INC ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; Part of the TCP/IP network stack for KolibriOS ;; |
8 | ;; Part of the TCP/IP network stack for KolibriOS ;; |
Line 265... | Line 265... | ||
265 | 265 | ||
266 | and eax, 0x0fffffff |
266 | and eax, 0x0fffffff |
267 | cmp eax, 224 |
267 | cmp eax, 224 |
Line 268... | Line 268... | ||
268 | je .ip_ok |
268 | je .ip_ok |
Line 269... | Line -... | ||
269 | - | ||
270 | ; or a loopback address (127.0.0.0/8) |
269 | |
271 | 270 | ; maybe we just dont have an IP yet and should accept everything on the IP level |
|
Line 272... | Line 271... | ||
272 | and eax, 0x00ffffff |
271 | |
Line 273... | Line 272... | ||
273 | cmp eax, 127 |
272 | cmp [IP_LIST + edi], 0 |
Line 575... | Line 574... | ||
575 | ; IN: eax = Destination IP |
574 | ; IN: eax = Destination IP |
576 | ; ecx = data length |
575 | ; ecx = data length |
577 | ; edx = Source IP |
576 | ; edx = Source IP |
578 | ; di = TTL shl 8 + protocol |
577 | ; di = TTL shl 8 + protocol |
579 | ; |
578 | ; |
580 | ; OUT: eax = pointer to buffer start |
579 | ; OUT: eax = pointer to buffer start / 0 on error |
581 | ; ebx = pointer to device struct (needed for sending procedure) |
580 | ; ebx = device ptr (send packet through this device) |
582 | ; ecx = unchanged (packet size of embedded data) |
581 | ; ecx = data length |
583 | ; edx = size of complete buffer |
582 | ; edx = size of complete frame |
584 | ; edi = pointer to start of data (0 on error) |
583 | ; edi = start of IPv4 payload |
585 | ; |
584 | ; |
586 | ;------------------------------------------------------------------ |
585 | ;------------------------------------------------------------------ |
587 | align 4 |
586 | align 4 |
588 | IPv4_output: |
587 | IPv4_output: |
Line 593... | Line 592... | ||
593 | ja .too_large |
592 | ja .too_large |
Line 594... | Line 593... | ||
594 | 593 | ||
595 | push ecx di eax |
594 | push ecx di eax |
596 | call IPv4_route ; outputs device number in edi, dest ip in eax, source IP in edx |
595 | call IPv4_route ; outputs device number in edi, dest ip in eax, source IP in edx |
597 | push edx |
- | |
598 | 596 | push edx |
|
599 | test edi, edi |
597 | test edi, edi |
Line 600... | Line 598... | ||
600 | jz .loopback |
598 | jz .loopback |
601 | 599 | ||
Line 605... | Line 603... | ||
605 | push ebx ; push the mac onto the stack |
603 | push ebx ; push the mac onto the stack |
606 | push ax |
604 | push ax |
Line 607... | Line 605... | ||
607 | 605 | ||
Line -... | Line 606... | ||
- | 606 | inc [IPv4_packets_tx + edi] ; update stats |
|
608 | inc [IPv4_packets_tx + edi] ; update stats |
607 | |
609 | - | ||
610 | mov ebx, [NET_DRV_LIST + edi] |
- | |
611 | lea eax, [ebx + ETH_DEVICE.mac] |
608 | mov ax, ETHER_PROTO_IPv4 |
612 | mov edx, esp |
609 | mov ebx, [NET_DRV_LIST + edi] |
613 | mov ecx, [esp + 6 + 8 + 2] |
610 | mov ecx, [esp + 6 + 8 + 2] |
614 | add ecx, sizeof.IPv4_header |
611 | add ecx, sizeof.IPv4_header |
615 | mov di, ETHER_PROTO_IPv4 |
612 | mov edx, esp |
616 | call ETH_output |
613 | call ETH_output |
Line 617... | Line 614... | ||
617 | jz .eth_error |
614 | jz .eth_error |
Line 640... | Line 637... | ||
640 | ret |
637 | ret |
Line 641... | Line 638... | ||
641 | 638 | ||
642 | .eth_error: |
639 | .eth_error: |
643 | DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output: ethernet error\n" |
640 | DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output: ethernet error\n" |
644 | add esp, 3*4+2+6 |
641 | add esp, 3*4+2+6 |
645 | xor edi, edi |
642 | xor eax, eax |
Line 646... | Line 643... | ||
646 | ret |
643 | ret |
647 | 644 | ||
648 | .arp_error: |
645 | .arp_error: |
649 | DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output: ARP error=%x\n", eax |
646 | DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output: ARP error=%x\n", eax |
650 | add esp, 3*4+2 |
647 | add esp, 3*4+2 |
Line 651... | Line 648... | ||
651 | xor edi, edi |
648 | xor eax, eax |
652 | ret |
649 | ret |
653 | 650 | ||
654 | .too_large: |
651 | .too_large: |
Line 655... | Line 652... | ||
655 | DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output: Packet too large!\n" |
652 | DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output: Packet too large!\n" |
656 | xor edi, edi |
653 | xor eax, eax |
657 | ret |
654 | ret |
Line 673... | Line 670... | ||
673 | ; |
670 | ; |
674 | ; IN: eax = socket ptr |
671 | ; IN: eax = socket ptr |
675 | ; ecx = data length |
672 | ; ecx = data length |
676 | ; esi = data ptr |
673 | ; esi = data ptr |
677 | ; |
674 | ; |
678 | ; OUT: / |
675 | ; OUT: eax = -1 on error |
679 | ; |
676 | ; |
680 | ;------------------------------------------------------------------ |
677 | ;------------------------------------------------------------------ |
681 | align 4 |
678 | align 4 |
682 | IPv4_output_raw: |
679 | IPv4_output_raw: |
Line 697... | Line 694... | ||
697 | 694 | ||
698 | push ebx ; push the mac |
695 | push ebx ; push the mac |
Line 699... | Line 696... | ||
699 | push ax |
696 | push ax |
- | 697 | ||
700 | 698 | inc [IPv4_packets_tx + 4*edi] |
|
701 | inc [IPv4_packets_tx + 4*edi] |
- | |
702 | mov ebx, [NET_DRV_LIST + 4*edi] |
- | |
703 | lea eax, [ebx + ETH_DEVICE.mac] |
699 | mov ax, ETHER_PROTO_IPv4 |
704 | mov edx, esp |
700 | mov ebx, [NET_DRV_LIST + 4*edi] |
705 | mov ecx, [esp + 6 + 4] |
701 | mov ecx, [esp + 6 + 4] |
706 | add ecx, sizeof.IPv4_header |
702 | add ecx, sizeof.IPv4_header |
707 | mov di, ETHER_PROTO_IPv4 |
703 | mov edx, esp |
708 | call ETH_output |
- | |
709 | jz .error |
704 | call ETH_output |
Line 710... | Line 705... | ||
710 | 705 | jz .error |
|
711 | add esp, 6 ; pop the mac |
706 | add esp, 6 ; pop the mac |
Line 744... | Line 739... | ||
744 | add esp, 6 |
739 | add esp, 6 |
745 | .arp_error: |
740 | .arp_error: |
746 | add esp, 8+4+4 |
741 | add esp, 8+4+4 |
747 | .too_large: |
742 | .too_large: |
748 | DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output_raw: Failed\n" |
743 | DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output_raw: Failed\n" |
749 | sub edi, edi |
744 | or eax, -1 |
750 | ret |
745 | ret |
Line 751... | Line 746... | ||
751 | 746 | ||
752 | 747 | ||
Line 793... | Line 788... | ||
793 | push dword 0 ; offset |
788 | push dword 0 ; offset |
Line 794... | Line 789... | ||
794 | 789 | ||
795 | .new_fragment: |
790 | .new_fragment: |
Line 796... | Line -... | ||
796 | DEBUGF DEBUG_NETWORK_VERBOSE, "Ipv4_fragment: new fragment" |
- | |
797 | 791 | DEBUGF DEBUG_NETWORK_VERBOSE, "Ipv4_fragment: new fragment" |
|
798 | 792 | ||
799 | mov eax, [esp + 3*4] |
- | |
800 | lea ebx, [esp + 4*4] |
793 | mov ax, ETHER_PROTO_IPv4 |
801 | mov di , ETHER_PROTO_IPv4 |
- | |
802 | call ETH_output |
- | |
803 | 794 | lea ebx, [esp + 4*4] |
|
Line 804... | Line 795... | ||
804 | cmp edi, -1 |
795 | call ETH_output |
805 | jz .err |
796 | jz .err |
806 | 797 |