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