Subversion Repositories Kolibri OS

Rev

Rev 10051 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3545 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
10051 ace_dent 3
;; Copyright (C) KolibriOS team 2012-2024. All rights reserved.    ;;
3545 hidnplayr 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
 
18
struct  IPv6_header
19
 
20
        VersionTrafficFlow      dd ?    ; Version[0-3], Traffic class[4-11], Flow Label [12-31]
21
        PayloadLength           dw ?    ; 16 bits, unsigned length of payload (extension headers are part of this)
22
        NextHeader              db ?    ; Values are same as in IPv4 'Protocol' field
23
        HopLimit                db ?    ; Decremented by every node, packet is discarded when it reaches 0
24
        SourceAddress           rd 4    ; 128-bit addresses
25
        DestinationAddress      rd 4    ;
26
        Payload                 rb 0
27
 
28
ends
29
 
30
 
3698 hidnplayr 31
uglobal
3545 hidnplayr 32
align 4
33
 
34
        IPv6:
3600 hidnplayr 35
        .addresses      rd 4*NET_DEVICES_MAX
36
        .subnet         rd 4*NET_DEVICES_MAX
37
        .dns            rd 4*NET_DEVICES_MAX
38
        .gateway        rd 4*NET_DEVICES_MAX
3545 hidnplayr 39
 
3600 hidnplayr 40
        .packets_tx     rd NET_DEVICES_MAX
41
        .packets_rx     rd NET_DEVICES_MAX
3545 hidnplayr 42
 
43
endg
44
 
45
 
6011 hidnplayr 46
;-----------------------------------------------------------------;
47
;                                                                 ;
48
; ipv6_init: Resets all IPv6 variables                            ;
49
;                                                                 ;
50
;-----------------------------------------------------------------;
51
macro   ipv6_init {
3545 hidnplayr 52
 
53
        xor     eax, eax
54
        mov     edi, IPv6
55
        mov     ecx, (4*4*4+2*4)MAX_IP
3711 clevermous 56
        rep stosd
3545 hidnplayr 57
 
58
}
59
 
60
 
61
 
6011 hidnplayr 62
;-----------------------------------------------------------------;
63
;                                                                 ;
10058 ace_dent 64
; ipv6_input: Check the IPv6 Packet is not damaged and call       ;
6011 hidnplayr 65
; appropriate handler. (TCP/UDP/ICMP/..)                          ;
66
; We will also re-construct fragmented packets                    ;
67
;                                                                 ;
68
;   IN: [esp] = ptr to buffer                                     ;
69
;       [esp+4] = size of buffer                                  ;
70
;       ebx = ptr to device struct                                ;
71
;       edx = ptr to IPv6 header                                  ;
72
;       ecx = size of IPv6 packet                                 ;
73
;                                                                 ;
74
;  OUT: /                                                         ;
75
;                                                                 ;
76
;-----------------------------------------------------------------;
3545 hidnplayr 77
align 4
6011 hidnplayr 78
ipv6_input:
3545 hidnplayr 79
 
3556 hidnplayr 80
        DEBUGF  DEBUG_NETWORK_VERBOSE, "IPv6_input from: %x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x\n",\
3545 hidnplayr 81
        [edx + IPv6_header.SourceAddress + 0]:2,[edx + IPv6_header.SourceAddress + 1]:2,\
82
        [edx + IPv6_header.SourceAddress + 2]:2,[edx + IPv6_header.SourceAddress + 3]:2,\
83
        [edx + IPv6_header.SourceAddress + 4]:2,[edx + IPv6_header.SourceAddress + 5]:2,\
84
        [edx + IPv6_header.SourceAddress + 6]:2,[edx + IPv6_header.SourceAddress + 7]:2,\
85
        [edx + IPv6_header.SourceAddress + 8]:2,[edx + IPv6_header.SourceAddress + 9]:2,\
86
        [edx + IPv6_header.SourceAddress + 10]:2,[edx + IPv6_header.SourceAddress + 11]:2,\
87
        [edx + IPv6_header.SourceAddress + 12]:2,[edx + IPv6_header.SourceAddress + 13]:2,\
88
        [edx + IPv6_header.SourceAddress + 14]:2,[edx + IPv6_header.SourceAddress + 15]:2
89
 
3556 hidnplayr 90
        DEBUGF  DEBUG_NETWORK_VERBOSE, "IPv6_input to: %x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x\n",\
3545 hidnplayr 91
        [edx + IPv6_header.DestinationAddress + 0]:2,[edx + IPv6_header.DestinationAddress + 1]:2,\
92
        [edx + IPv6_header.DestinationAddress + 2]:2,[edx + IPv6_header.DestinationAddress + 3]:2,\
93
        [edx + IPv6_header.DestinationAddress + 4]:2,[edx + IPv6_header.DestinationAddress + 5]:2,\
94
        [edx + IPv6_header.DestinationAddress + 6]:2,[edx + IPv6_header.DestinationAddress + 7]:2,\
95
        [edx + IPv6_header.DestinationAddress + 8]:2,[edx + IPv6_header.DestinationAddress + 9]:2,\
96
        [edx + IPv6_header.DestinationAddress + 10]:2,[edx + IPv6_header.DestinationAddress + 11]:2,\
97
        [edx + IPv6_header.DestinationAddress + 12]:2,[edx + IPv6_header.DestinationAddress + 13]:2,\
98
        [edx + IPv6_header.DestinationAddress + 14]:2,[edx + IPv6_header.DestinationAddress + 15]:2
99
 
100
        sub     ecx, sizeof.IPv6_header
101
        jb      .dump
102
 
103
        cmp     cx, [edx + IPv6_header.PayloadLength]
104
        jb      .dump
105
 
106
;-------------------------------------------------------------------
107
; No, it's just a regular IP packet, pass it to the higher protocols
108
 
109
  .handle_it:
110
        movzx   ecx, [edx + IPv6_header.PayloadLength]
111
        lea     edi, [edx + IPv6_header.SourceAddress]          ; make edi ptr to source and dest IPv6 address
112
        lea     esi, [edx + IPv6_header.Payload]                ; make esi ptr to data
113
        mov     al, [edx + IPv6_header.NextHeader]
114
 
115
  .scan:
116
        cmp     al, 59  ; no next
117
        je      .dump
118
 
119
        cmp     al, 0
120
        je      .hop_by_hop
121
 
122
        cmp     al, 43
123
        je      .routing
124
 
125
        cmp     al, 44
126
        je      .fragment
127
 
128
        cmp     al, 60
129
        je      .dest_opts
130
 
131
;        cmp     al, IP_PROTO_TCP
132
;        je      TCP_input
133
 
134
;        cmp     al, IP_PROTO_UDP
135
;        je      UDP_input
136
 
137
;        cmp     al, 58
138
;        je      ICMP6_input
139
 
3556 hidnplayr 140
        DEBUGF  DEBUG_NETWORK_VERBOSE, "IPv6_input - unknown protocol: %u\n", al
3545 hidnplayr 141
 
142
  .dump:
3556 hidnplayr 143
        DEBUGF  DEBUG_NETWORK_VERBOSE, "IPv6_input - dumping\n"
6011 hidnplayr 144
        call    net_buff_free
3545 hidnplayr 145
        ret
146
 
147
  .dump_options:
148
        add     esp, 2+4+4
149
        jmp     .dump
150
 
151
  .nextheader:
152
        pop     esi
153
        pop     ecx
154
        pop     ax
155
        jmp     .scan
156
 
157
;-------------------------
158
; Hop-by-Hop
159
 
160
  .hop_by_hop:
3556 hidnplayr 161
        DEBUGF  DEBUG_NETWORK_VERBOSE, "IPv6_input - hop by hop\n"
3545 hidnplayr 162
        pushw   [esi]                   ; 8 bit identifier for option type
163
        movzx   eax, byte[esi + 1]      ; Hdr Ext Len
164
        inc     eax                     ; first 8 octets not counted
165
        shl     eax, 3                  ; * 8
166
        sub     ecx, eax
167
        push    ecx
168
        add     eax, esi
169
        push    eax
170
        inc     esi
171
        inc     esi
172
 
173
        mov     al, [esi]
174
 
175
        cmp     al, 0
176
        je      .pad_1
177
 
178
        cmp     al, 1
179
        je      .pad_n
180
 
181
        ; TODO: check with other known options
182
 
183
; unknown option.. discard packet or not?
184
; check highest two bits
185
        test    al, 0xc0        ; discard packet
186
        jnz     .dump_options
187
 
188
  .pad_n:
189
        movzx   eax, byte[esi + 1]
3556 hidnplayr 190
        DEBUGF  DEBUG_NETWORK_VERBOSE, "IPv6_input - pad %u\n", eax
3545 hidnplayr 191
        inc     esi
192
        inc     esi
193
        add     esi, eax
194
        sub     ecx, eax
195
        jmp     .hop_by_hop
196
 
197
  .pad_1:
3556 hidnplayr 198
        DEBUGF  DEBUG_NETWORK_VERBOSE, "IPv6_input - pad 1\n"
3545 hidnplayr 199
        inc     esi
200
        dec     ecx
201
        jmp     .hop_by_hop
202
 
203
 
204
 
205
  .dest_opts:
3556 hidnplayr 206
        DEBUGF  DEBUG_NETWORK_VERBOSE, "IPv6_input - dest opts\n"
3545 hidnplayr 207
        jmp     .nextheader
208
 
209
  .routing:
3556 hidnplayr 210
        DEBUGF  DEBUG_NETWORK_VERBOSE, "IPv6_input - routing\n"
3545 hidnplayr 211
        pushw   [esi]                   ; 8 bit identifier for option type
212
        movzx   eax, byte[esi + 1]      ; Hdr Ext Len
213
        inc     eax                     ; first 8 octets not counted
214
        shl     eax, 3                  ; * 8
215
        sub     ecx, eax
216
        push    ecx
217
        add     eax, esi
218
        push    eax
219
        inc     esi
220
        inc     esi
221
 
222
        cmp     al, 0
223
        je      .pad_1
224
 
225
        cmp     al, 1
226
        je      .pad_n
227
 
228
        mov     al, [esi]       ; routing type
229
 
230
        jmp     .nextheader
231
 
232
  .fragment:
3556 hidnplayr 233
        DEBUGF  DEBUG_NETWORK_VERBOSE, "IPv6_input - fragment\n"
3545 hidnplayr 234
 
235
        jmp     .nextheader
236
 
237
 
238
 
239
 
240
 
241
 
6011 hidnplayr 242
;-----------------------------------------------------------------;
243
;                                                                 ;
244
; ipv6_api: Part of system function 76                            ;
245
;                                                                 ;
246
;  IN:  bl = subfunction number                                   ;
247
;       bh = device number                                        ;
248
;       ecx, edx, .. depends on subfunction                       ;
249
;                                                                 ;
250
; OUT:  depends on subfunction                                    ;
251
;                                                                 ;
252
;-----------------------------------------------------------------;
3545 hidnplayr 253
align 4
6011 hidnplayr 254
ipv6_api:
3545 hidnplayr 255
 
256
        movzx   eax, bh
257
        shl     eax, 2
258
 
259
        and     ebx, 0x000000ff
260
        cmp     ebx, .number
261
        ja      .error
262
        jmp     dword [.table + 4*ebx]
263
 
264
  .table:
265
        dd      .packets_tx     ; 0
266
        dd      .packets_rx     ; 1
267
;        dd      .read_ip        ; 2
268
;        dd      .write_ip       ; 3
269
;        dd      .read_dns       ; 4
270
;        dd      .write_dns      ; 5
271
;        dd      .read_subnet    ; 6
272
;        dd      .write_subnet   ; 7
273
;        dd      .read_gateway   ; 8
274
;        dd      .write_gateway  ; 9
275
  .number = ($ - .table) / 4 - 1
276
 
277
  .error:
278
        mov     eax, -1
279
        ret
280
 
281
  .packets_tx:
282
        mov     eax, [IPv6.packets_tx + eax]
283
        ret
284
 
285
  .packets_rx:
286
        mov     eax, [IPv6.packets_rx + eax]
287
        ret