Subversion Repositories Kolibri OS

Rev

Rev 4976 | Rev 5363 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4976 Rev 5015
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 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: 4976 $
19
$Revision: 5015 $
20
 
20
 
Line 21... Line 21...
21
IPv4_MAX_FRAGMENTS              = 64
21
IPv4_MAX_FRAGMENTS              = 64
Line 574... Line 574...
574
; IN:   eax = Destination IP
574
; IN:   eax = Destination IP
575
;       ecx = data length
575
;       ecx = data length
576
;       edx = Source IP
576
;       edx = Source IP
577
;       di  = TTL shl 8 + protocol
577
;        di = TTL shl 8 + protocol
578
;
578
;
579
; OUT:  eax = pointer to buffer start
579
; OUT:  eax = pointer to buffer start / 0 on error
580
;       ebx = pointer to device struct (needed for sending procedure)
580
;       ebx = device ptr (send packet through this device)
581
;       ecx = unchanged (packet size of embedded data)
581
;       ecx = data length
582
;       edx = size of complete buffer
582
;       edx = size of complete frame
583
;       edi = pointer to start of data (0 on error)
583
;       edi = start of IPv4 payload
584
;
584
;
585
;------------------------------------------------------------------
585
;------------------------------------------------------------------
586
align 4
586
align 4
587
IPv4_output:
587
IPv4_output:
Line 592... Line 592...
592
        ja      .too_large
592
        ja      .too_large
Line 593... Line 593...
593
 
593
 
594
        push    ecx di eax
594
        push    ecx di eax
595
        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
596
        push    edx
-
 
597
 
596
        push    edx
598
        test    edi, edi
597
        test    edi, edi
Line 599... Line 598...
599
        jz      .loopback
598
        jz      .loopback
600
 
599
 
Line 604... Line 603...
604
        push    ebx                     ; push the mac onto the stack
603
        push    ebx                     ; push the mac onto the stack
605
        push    ax
604
        push    ax
Line 606... Line 605...
606
 
605
 
Line -... Line 606...
-
 
606
        inc     [IPv4_packets_tx + edi]   ; update stats
607
        inc     [IPv4_packets_tx + edi]   ; update stats
607
 
608
 
-
 
609
        mov     ebx, [NET_DRV_LIST + edi]
-
 
610
        lea     eax, [ebx + ETH_DEVICE.mac]
608
        mov     ax, ETHER_PROTO_IPv4
611
        mov     edx, esp
609
        mov     ebx, [NET_DRV_LIST + edi]
612
        mov     ecx, [esp + 6 + 8 + 2]
610
        mov     ecx, [esp + 6 + 8 + 2]
613
        add     ecx, sizeof.IPv4_header
611
        add     ecx, sizeof.IPv4_header
614
        mov     di, ETHER_PROTO_IPv4
612
        mov     edx, esp
615
        call    ETH_output
613
        call    ETH_output
Line 616... Line 614...
616
        jz      .eth_error
614
        jz      .eth_error
Line 639... Line 637...
639
        ret
637
        ret
Line 640... Line 638...
640
 
638
 
641
  .eth_error:
639
  .eth_error:
642
        DEBUGF  DEBUG_NETWORK_ERROR, "IPv4_output: ethernet error\n"
640
        DEBUGF  DEBUG_NETWORK_ERROR, "IPv4_output: ethernet error\n"
643
        add     esp, 3*4+2+6
641
        add     esp, 3*4+2+6
644
        xor     edi, edi
642
        xor     eax, eax
Line 645... Line 643...
645
        ret
643
        ret
646
 
644
 
647
  .arp_error:
645
  .arp_error:
648
        DEBUGF  DEBUG_NETWORK_ERROR, "IPv4_output: ARP error=%x\n", eax
646
        DEBUGF  DEBUG_NETWORK_ERROR, "IPv4_output: ARP error=%x\n", eax
649
        add     esp, 3*4+2
647
        add     esp, 3*4+2
Line 650... Line 648...
650
        xor     edi, edi
648
        xor     eax, eax
651
        ret
649
        ret
652
 
650
 
653
  .too_large:
651
  .too_large:
Line 654... Line 652...
654
        DEBUGF  DEBUG_NETWORK_ERROR, "IPv4_output: Packet too large!\n"
652
        DEBUGF  DEBUG_NETWORK_ERROR, "IPv4_output: Packet too large!\n"
655
        xor     edi, edi
653
        xor     eax, eax
656
        ret
654
        ret
Line 672... Line 670...
672
;
670
;
673
; IN: eax = socket ptr
671
; IN: eax = socket ptr
674
;     ecx = data length
672
;     ecx = data length
675
;     esi = data ptr
673
;     esi = data ptr
676
;
674
;
677
; OUT: /
675
; OUT: eax = -1 on error
678
;
676
;
679
;------------------------------------------------------------------
677
;------------------------------------------------------------------
680
align 4
678
align 4
681
IPv4_output_raw:
679
IPv4_output_raw:
Line 696... Line 694...
696
 
694
 
697
        push    ebx                     ; push the mac
695
        push    ebx                     ; push the mac
Line 698... Line 696...
698
        push    ax
696
        push    ax
-
 
697
 
699
 
698
        inc     [IPv4_packets_tx + 4*edi]
700
        inc     [IPv4_packets_tx + 4*edi]
-
 
701
        mov     ebx, [NET_DRV_LIST + 4*edi]
-
 
702
        lea     eax, [ebx + ETH_DEVICE.mac]
699
        mov     ax, ETHER_PROTO_IPv4
703
        mov     edx, esp
700
        mov     ebx, [NET_DRV_LIST + 4*edi]
704
        mov     ecx, [esp + 6 + 4]
701
        mov     ecx, [esp + 6 + 4]
705
        add     ecx, sizeof.IPv4_header
702
        add     ecx, sizeof.IPv4_header
706
        mov     di, ETHER_PROTO_IPv4
703
        mov     edx, esp
707
        call    ETH_output
-
 
708
        jz      .error
704
        call    ETH_output
Line 709... Line 705...
709
 
705
        jz      .error
710
        add     esp, 6  ; pop the mac
706
        add     esp, 6  ; pop the mac
Line 743... Line 739...
743
        add     esp, 6
739
        add     esp, 6
744
  .arp_error:
740
  .arp_error:
745
        add     esp, 8+4+4
741
        add     esp, 8+4+4
746
  .too_large:
742
  .too_large:
747
        DEBUGF  DEBUG_NETWORK_ERROR, "IPv4_output_raw: Failed\n"
743
        DEBUGF  DEBUG_NETWORK_ERROR, "IPv4_output_raw: Failed\n"
748
        sub     edi, edi
744
        or      eax, -1
749
        ret
745
        ret
Line 750... Line 746...
750
 
746
 
751
 
747
 
Line 792... Line 788...
792
        push    dword 0                         ; offset
788
        push    dword 0                         ; offset
Line 793... Line 789...
793
 
789
 
794
  .new_fragment:
790
  .new_fragment:
Line 795... Line -...
795
        DEBUGF  DEBUG_NETWORK_VERBOSE, "Ipv4_fragment: new fragment"
-
 
796
 
791
        DEBUGF  DEBUG_NETWORK_VERBOSE, "Ipv4_fragment: new fragment"
797
 
792
 
798
        mov     eax, [esp + 3*4]
-
 
799
        lea     ebx, [esp + 4*4]
793
        mov     ax, ETHER_PROTO_IPv4
800
        mov     di , ETHER_PROTO_IPv4
-
 
801
        call    ETH_output
-
 
802
 
794
        lea     ebx, [esp + 4*4]
Line 803... Line 795...
803
        cmp     edi, -1
795
        call    ETH_output
804
        jz      .err
796
        jz      .err
805
 
797