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