Rev 5584 | Rev 5976 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5584 | Rev 5842 | ||
---|---|---|---|
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: 5584 $ |
17 | $Revision: 5842 $ |
Line 18... | Line 18... | ||
18 | 18 | ||
Line 55... | Line 55... | ||
55 | macro UDP_checksum IP1, IP2 { ; esi = ptr to udp packet, ecx = packet size, destroys: ecx, edx |
55 | macro UDP_checksum IP1, IP2 { ; esi = ptr to udp packet, ecx = packet size, destroys: ecx, edx |
Line 56... | Line 56... | ||
56 | 56 | ||
57 | ; Pseudoheader |
57 | ; Pseudoheader |
Line 58... | Line 58... | ||
58 | mov edx, IP_PROTO_UDP |
58 | mov edx, IP_PROTO_UDP |
59 | 59 | ||
60 | add dl, [IP1+1] |
60 | add dl, byte[IP1+1] |
61 | adc dh, [IP1+0] |
61 | adc dh, byte[IP1+0] |
62 | adc dl, [IP1+3] |
62 | adc dl, byte[IP1+3] |
63 | adc dh, [IP1+2] |
63 | adc dh, byte[IP1+2] |
64 | 64 | ||
65 | adc dl, [IP2+1] |
65 | adc dl, byte[IP2+1] |
66 | adc dh, [IP2+0] |
66 | adc dh, byte[IP2+0] |
Line 67... | Line 67... | ||
67 | adc dl, [IP2+3] |
67 | adc dl, byte[IP2+3] |
68 | adc dh, [IP2+2] |
68 | adc dh, byte[IP2+2] |
Line 69... | Line 69... | ||
69 | 69 | ||
Line 101... | Line 101... | ||
101 | ;----------------------------------------------------------------- |
101 | ;----------------------------------------------------------------- |
102 | ; |
102 | ; |
103 | ; UDP_input: |
103 | ; UDP_input: |
104 | ; |
104 | ; |
105 | ; Called by IPv4_input, |
105 | ; Called by IPv4_input, |
106 | ; this procedure will inject the udp data diagrams in the application sockets. |
106 | ; this procedure will inject the UDP data in the application sockets. |
107 | ; |
107 | ; |
108 | ; IN: [esp] = Pointer to buffer |
108 | ; IN: [esp] = ptr to buffer |
109 | ; [esp+4] = size of buffer |
- | |
110 | ; ebx = ptr to device struct |
109 | ; ebx = ptr to device struct |
111 | ; ecx = UDP Packet size |
110 | ; ecx = UDP packet size |
112 | ; esi = ptr to UDP header |
111 | ; edx = ptr to IPv4 header |
113 | ; edi = ptr to ipv4 source and dest address |
112 | ; esi = ptr to UDP packet data |
- | 113 | ; edi = interface number*4 |
|
114 | ; |
114 | ; |
115 | ; OUT: / |
115 | ; OUT: / |
116 | ; |
116 | ; |
117 | ;----------------------------------------------------------------- |
117 | ;----------------------------------------------------------------- |
118 | align 4 |
118 | align 4 |
Line 125... | Line 125... | ||
125 | neg [esi + UDP_header.Checksum] ; substract checksum from 0 |
125 | neg [esi + UDP_header.Checksum] ; substract checksum from 0 |
126 | jz .no_checksum ; if checksum is zero, it is considered valid |
126 | jz .no_checksum ; if checksum is zero, it is considered valid |
Line 127... | Line 127... | ||
127 | 127 | ||
Line 128... | Line 128... | ||
128 | ; otherwise, we will re-calculate the checksum and add it to this value, thus creating 0 when it is correct |
128 | ; otherwise, we will re-calculate the checksum and add it to this value, thus creating 0 when it is correct |
- | 129 | ||
129 | 130 | mov eax, edx |
|
Line 130... | Line 131... | ||
130 | UDP_checksum (edi), (edi+4) |
131 | UDP_checksum (eax+IPv4_header.SourceAddress), (eax+IPv4_header.DestinationAddress) |
131 | jnz .checksum_mismatch |
132 | jnz .checksum_mismatch |
Line 146... | Line 147... | ||
146 | call mutex_lock |
147 | call mutex_lock |
147 | popa |
148 | popa |
Line 148... | Line 149... | ||
148 | 149 | ||
149 | mov cx, [esi + UDP_header.SourcePort] |
150 | mov cx, [esi + UDP_header.SourcePort] |
150 | mov dx, [esi + UDP_header.DestinationPort] |
- | |
151 | mov edi, [edi + 4] ; ipv4 source address |
151 | mov dx, [esi + UDP_header.DestinationPort] |
152 | mov eax, net_sockets |
- | |
153 | 152 | mov eax, net_sockets |
|
154 | .next_socket: |
153 | .next_socket: |
155 | mov eax, [eax + SOCKET.NextPtr] |
154 | mov eax, [eax + SOCKET.NextPtr] |
156 | or eax, eax |
155 | or eax, eax |
Line 170... | Line 169... | ||
170 | pusha |
169 | pusha |
171 | mov ecx, socket_mutex |
170 | mov ecx, socket_mutex |
172 | call mutex_unlock |
171 | call mutex_unlock |
173 | popa |
172 | popa |
Line 174... | Line 173... | ||
174 | 173 | ||
Line -... | Line 174... | ||
- | 174 | ;;; TODO: when packet is processed, check more sockets?! |
|
- | 175 | ||
175 | ;;; TODO: when packet is processed, check more sockets! |
176 | ; FIXME: check remote IP if possible |
176 | 177 | ; |
|
177 | ; cmp [eax + IP_SOCKET.RemoteIP], 0xffffffff |
178 | ; cmp [eax + IP_SOCKET.RemoteIP], 0xffffffff |
178 | ; je @f |
179 | ; je @f |
179 | ; cmp [eax + IP_SOCKET.RemoteIP], edi |
180 | ; cmp [eax + IP_SOCKET.RemoteIP], |
180 | ; jne .next_socket |
- | |
181 | ; @@: |
- | |
Line 182... | Line 181... | ||
182 | ; |
181 | ; jne .next_socket |
183 | ; FIXME: UDP should check remote IP, but not under all circumstances! |
182 | ; @@: |
Line 184... | Line 183... | ||
184 | 183 | ||
Line 192... | Line 191... | ||
192 | lea ecx, [eax + SOCKET.mutex] |
191 | lea ecx, [eax + SOCKET.mutex] |
193 | call mutex_lock |
192 | call mutex_lock |
194 | popa |
193 | popa |
Line 195... | Line 194... | ||
195 | 194 | ||
196 | .updatesock: |
- | |
197 | call NET_ptr_to_num4 |
195 | .updatesock: |
Line 198... | Line 196... | ||
198 | inc [UDP_PACKETS_RX + edi] |
196 | inc [UDP_PACKETS_RX + edi] |
199 | 197 | ||
200 | movzx ecx, [esi + UDP_header.Length] |
198 | movzx ecx, [esi + UDP_header.Length] |
Line 255... | Line 253... | ||
255 | mov dx, [eax + UDP_SOCKET.LocalPort] |
253 | mov dx, [eax + UDP_SOCKET.LocalPort] |
256 | DEBUGF DEBUG_NETWORK_VERBOSE, "local port=%x\n", dx |
254 | DEBUGF DEBUG_NETWORK_VERBOSE, "local port=%x\n", dx |
Line 257... | Line 255... | ||
257 | 255 | ||
258 | sub esp, 4 ; Data ptr will be placed here |
256 | sub esp, 4 ; Data ptr will be placed here |
259 | push edx esi |
- | |
260 | mov edx, [eax + IP_SOCKET.LocalIP] |
257 | push edx esi |
- | 258 | mov ebx, [eax + IP_SOCKET.device] |
|
261 | mov ebx, [eax + IP_SOCKET.device] |
259 | mov edx, [eax + IP_SOCKET.LocalIP] |
- | 260 | mov edi, [eax + IP_SOCKET.RemoteIP] |
|
262 | mov eax, [eax + IP_SOCKET.RemoteIP] |
261 | mov al, [eax + IP_SOCKET.ttl] |
263 | mov di, IP_PROTO_UDP shl 8 + 128 |
262 | mov ah, IP_PROTO_UDP |
264 | add ecx, sizeof.UDP_header |
263 | add ecx, sizeof.UDP_header |
265 | call IPv4_output |
264 | call IPv4_output |
266 | jz .fail |
265 | jz .fail |
Line 346... | Line 345... | ||
346 | jne @f |
345 | jne @f |
347 | call SOCKET_find_port |
346 | call SOCKET_find_port |
348 | @@: |
347 | @@: |
Line 349... | Line 348... | ||
349 | 348 | ||
350 | push eax |
- | |
351 | init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue |
- | |
352 | pop eax |
- | |
353 | - | ||
354 | push eax |
349 | push eax |
355 | lea ecx, [eax + SOCKET.mutex] |
350 | lea ecx, [eax + SOCKET.mutex] |
356 | call mutex_unlock |
351 | call mutex_unlock |
Line 357... | Line 352... | ||
357 | pop eax |
352 | pop eax |