Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2731 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2012. All rights reserved.         ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
6
;;  IPv6.INC                                                       ;;
7
;;                                                                 ;;
8
;;  Part of the tcp/ip network stack for KolibriOS                 ;;
9
;;                                                                 ;;
10
;;    Written by hidnplayr@kolibrios.org                           ;;
11
;;                                                                 ;;
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
13
;;             Version 2, June 1991                                ;;
14
;;                                                                 ;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16
 
17
$Revision: 2731 $
18
 
19
 
20
struct  IPv6_header
21
 
22
        VersionTrafficFlow      dd ?    ; Version[0-3], Traffic class[4-11], Flow Label [12-31]
23
        PayloadLength           dw ?    ; 16 bits, unsigned length of payload (extension headers are part of this)
24
        NextHeader              db ?    ; Values are same as in IPv4 'Protocol' field
25
        HopLimit                db ?    ; Decremented by every node, packet is discarded when it reaches 0
26
        SourceAddress           rd 4    ; 128-bit addresses
27
        DestinationAddress      rd 4    ;
28
 
29
ends
30
 
31
 
32
 
33
 
34
 
35
;-----------------------------------------------------------------
36
;
37
; IPv6_input:
38
;
39
;  Will check if IPv6 Packet isnt damaged
40
;  and call appropriate handler. (TCP/UDP/ICMP/..)
41
;
42
;  It will also re-construct fragmented packets
43
;
44
;  IN:  Pointer to buffer in [esp]
45
;       size of buffer in [esp+4]
46
;       pointer to device struct in ebx
47
;       pointer to IPv6 header in edx
48
;       size of IPv6 packet in ecx
49
;  OUT: /
50
;
51
;-----------------------------------------------------------------
52
align 4
53
IPv6_input:
54
 
55
        DEBUGF  1,"IPv6_input\nfrom: %x:%x:%x:%x:%x:%x:%x:%x\n",\
56
        [edx + IPv6_header.SourceAddress + 0]:4,[edx + IPv6_header.SourceAddress + 2]:4,\
57
        [edx + IPv6_header.SourceAddress + 4]:4,[edx + IPv6_header.SourceAddress + 6]:4,\
58
        [edx + IPv6_header.SourceAddress + 8]:4,[edx + IPv6_header.SourceAddress + 10]:4,\
59
        [edx + IPv6_header.SourceAddress + 12]:4,[edx + IPv6_header.SourceAddress + 14]:4
60
        DEBUGF  1,"to: %x:%x:%x:%x:%x:%x:%x:%x\n",\
61
        [edx + IPv6_header.DestinationAddress + 0]:4,[edx + IPv6_header.DestinationAddress + 2]:4,\
62
        [edx + IPv6_header.DestinationAddress + 4]:4,[edx + IPv6_header.DestinationAddress + 6]:4,\
63
        [edx + IPv6_header.DestinationAddress + 8]:4,[edx + IPv6_header.DestinationAddress + 10]:4,\
64
        [edx + IPv6_header.DestinationAddress + 12]:4,[edx + IPv6_header.DestinationAddress + 14]:4
65
 
66
        sub     ecx, sizeof.IPv6_header
67
        jb      .dump
68
 
69
        movzx   eax, [edx + IPv6.PayloadLength]
70
        xchg    al, ah
71
        cmp     eax, ecx
72
        jb      .dump
73
 
74
 
75
 
76
;-------------------------------------------------------------------
77
; No, it's just a regular IP packet, pass it to the higher protocols
78
 
79
  .handle_it:
80
 
81
        movzx   esi, [edx + IPv6_header.VersionAndIHL]          ; Calculate Header length by using IHL field
82
        and     esi, 0x0000000f                                 ;
83
        shl     esi, 2                                          ;
84
 
85
        movzx   ecx, [edx + IPv6_header.TotalLength]            ; Calculate length of encapsulated Packet
86
        xchg    cl, ch                                          ;
87
        sub     ecx, esi                                        ;
88
 
89
        lea     edi, [edx + IPv6_header.SourceAddress]          ; make edi ptr to source and dest IPv6 address
90
        mov     al, [edx + IPv6_header.Protocol]
91
        add     esi, edx                                        ; make esi ptr to data
92
 
93
;        cmp     al, IP_PROTO_TCP
94
;        je      TCP_input
95
 
96
;        cmp     al, IP_PROTO_UDP
97
;        je      UDP_input
98
 
99
;        cmp     al, IP_PROTO_ICMP
100
;        je      ICMP_input
101
 
102
        DEBUGF  2,"IPv6_input - unknown protocol: %u\n", al
103
 
104
  .dump:
105
        DEBUGF  2,"IPv6_input - dumping\n"
106
 
107
        add     esp, 4
108
        call    KernelFree
109
        ret