Rev 2308 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2308 | Rev 2310 | ||
---|---|---|---|
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: 2308 $ |
17 | $Revision: 2310 $ |
Line 18... | Line 18... | ||
18 | 18 | ||
19 | 19 | ||
20 | struct UDP_Packet |
20 | struct UDP_header |
21 | 21 | ||
Line 63... | Line 63... | ||
63 | adc dl, [IP2+1] |
63 | adc dl, [IP2+1] |
64 | adc dh, [IP2+0] |
64 | adc dh, [IP2+0] |
65 | adc dl, [IP2+3] |
65 | adc dl, [IP2+3] |
66 | adc dh, [IP2+2] |
66 | adc dh, [IP2+2] |
Line 67... | Line 67... | ||
67 | 67 | ||
68 | adc dl, cl ; byte[esi+UDP_Packet.Length+1] |
68 | adc dl, cl ; byte[esi+UDP_header.Length+1] |
Line 69... | Line 69... | ||
69 | adc dh, ch ; byte[esi+UDP_Packet.Length+0] |
69 | adc dh, ch ; byte[esi+UDP_header.Length+0] |
70 | 70 | ||
71 | ; Done with pseudoheader, now do real header |
71 | ; Done with pseudoheader, now do real header |
Line 72... | Line 72... | ||
72 | adc dl, byte[esi+UDP_Packet.SourcePort+1] |
72 | adc dl, byte[esi+UDP_header.SourcePort+1] |
73 | adc dh, byte[esi+UDP_Packet.SourcePort+0] |
73 | adc dh, byte[esi+UDP_header.SourcePort+0] |
Line 74... | Line 74... | ||
74 | 74 | ||
75 | adc dl, byte[esi+UDP_Packet.DestinationPort+1] |
75 | adc dl, byte[esi+UDP_header.DestinationPort+1] |
Line 76... | Line 76... | ||
76 | adc dh, byte[esi+UDP_Packet.DestinationPort+0] |
76 | adc dh, byte[esi+UDP_header.DestinationPort+0] |
Line 77... | Line 77... | ||
77 | 77 | ||
78 | adc dl, byte[esi+UDP_Packet.Length+1] |
78 | adc dl, byte[esi+UDP_header.Length+1] |
79 | adc dh, byte[esi+UDP_Packet.Length+0] |
79 | adc dh, byte[esi+UDP_header.Length+0] |
80 | 80 | ||
81 | adc edx, 0 |
81 | adc edx, 0 |
82 | 82 | ||
Line 83... | Line 83... | ||
83 | ; Done with header, now do data |
83 | ; Done with header, now do data |
84 | push esi |
84 | push esi |
85 | movzx ecx, [esi+UDP_Packet.Length] |
85 | movzx ecx, [esi+UDP_header.Length] |
Line 86... | Line 86... | ||
86 | rol cx , 8 |
86 | rol cx , 8 |
Line 87... | Line 87... | ||
87 | sub cx , sizeof.UDP_Packet |
87 | sub cx , sizeof.UDP_header |
Line 88... | Line 88... | ||
88 | add esi, sizeof.UDP_Packet |
88 | add esi, sizeof.UDP_header |
Line 105... | Line 105... | ||
105 | ; |
105 | ; |
106 | ; IN: [esp] = Pointer to buffer |
106 | ; IN: [esp] = Pointer to buffer |
107 | ; [esp+4] = size of buffer |
107 | ; [esp+4] = size of buffer |
108 | ; ebx = ptr to device struct |
108 | ; ebx = ptr to device struct |
109 | ; ecx = UDP Packet size |
109 | ; ecx = UDP Packet size |
110 | ; edx = ptr to UDP header |
110 | ; esi = ptr to UDP header |
111 | ; edi = ptr to ipv4 source and dest address |
111 | ; edi = ptr to ipv4 source and dest address |
112 | ; |
112 | ; |
113 | ; OUT: / |
113 | ; OUT: / |
114 | ; |
114 | ; |
115 | ;----------------------------------------------------------------- |
115 | ;----------------------------------------------------------------- |
116 | align 4 |
116 | align 4 |
117 | UDP_input: |
117 | UDP_input: |
Line 118... | Line 118... | ||
118 | 118 | ||
Line 119... | Line 119... | ||
119 | DEBUGF 1,"UDP_input, size:%u\n", ecx |
119 | DEBUGF 1,"UDP_input, size:%u\n", ecx |
- | 120 | ||
120 | 121 | ; First validate, checksum |
|
121 | ; First validate, checksum: |
122 | |
122 | neg [edx+UDP_Packet.Checksum] ; substract chechksum from 0 |
123 | neg [esi + UDP_header.Checksum] ; substract checksum from 0 |
Line 123... | Line -... | ||
123 | jz .no_checksum ; if checksum is zero, it is considered valid and we continue processing |
- | |
124 | ; otherwise, we will re-calculate the checksum and add it to this value, thus creating 0 when it is correct |
- | |
125 | 124 | jz .no_checksum ; if checksum is zero, it is considered valid and we continue processing |
|
126 | push edx |
- | |
127 | push edi |
125 | ; otherwise, we will re-calculate the checksum and add it to this value, thus creating 0 when it is correct |
128 | push esi |
- | |
129 | mov esi, edx |
- | |
130 | UDP_checksum (edi), (edi+4) |
126 | |
131 | pop edi |
127 | push esi |
Line 132... | Line 128... | ||
132 | pop esi ; we dont need it, but it is smaller then add esp, 4 |
128 | UDP_checksum (edi), (edi+4) |
133 | pop edx |
129 | pop edx |
Line -... | Line 130... | ||
- | 130 | jnz .checksum_mismatch |
|
- | 131 | ||
- | 132 | .no_checksum: |
|
- | 133 | DEBUGF 1,"UDP Checksum is correct\n" |
|
- | 134 | ||
- | 135 | ; Convert port numbers to intel format |
|
134 | jnz .checksum_mismatch |
136 | |
135 | 137 | rol [edx + UDP_header.DestinationPort], 8 |
|
136 | .no_checksum: |
138 | rol [edx + UDP_header.SourcePort], 8 |
Line -... | Line 139... | ||
- | 139 | rol [edx + UDP_header.Length], 8 |
|
- | 140 | ||
- | 141 | ; Look for a socket where |
|
137 | DEBUGF 1,"UDP Checksum is correct\n" |
142 | ; IP Packet UDP Destination Port = local Port |
138 | 143 | ; IP Packet SA = Remote IP |
|
139 | ; Look for a socket where |
- | |
140 | ; IP Packet UDP Destination Port = local Port |
- | |
141 | ; IP Packet SA = Remote IP |
144 | |
142 | 145 | mov si, [edx + UDP_header.DestinationPort] |
|
143 | mov eax, net_sockets |
146 | mov cx, [edx + UDP_header.SourcePort] |
144 | .try_more: |
147 | mov edi, [edi + 4] ; ipv4 source address |
- | 148 | mov eax, net_sockets |
|
145 | mov si , [edx + UDP_Packet.DestinationPort] ; get the local port from the IP Packet's UDP header |
149 | |
146 | rol si , 8 |
150 | .next_socket: |
- | 151 | mov eax, [eax + SOCKET.NextPtr] |
|
147 | .next_socket: |
152 | or eax, eax |
148 | mov eax, [eax + SOCKET.NextPtr] |
153 | jz .dump |
- | 154 | ||
149 | or eax, eax |
155 | cmp [eax + SOCKET.Domain], AF_INET4 |
150 | jz .dump |
156 | jne .next_socket |
Line 151... | Line 157... | ||
151 | cmp [eax + SOCKET.Domain], AF_INET4 |
157 | |
Line 152... | Line 158... | ||
152 | jne .next_socket |
158 | cmp [eax + SOCKET.Protocol], IP_PROTO_UDP |
Line 153... | Line 159... | ||
153 | cmp [eax + SOCKET.Protocol], IP_PROTO_UDP |
159 | jne .next_socket |
154 | jne .next_socket |
160 | |
155 | cmp [eax + UDP_SOCKET.LocalPort], si |
- | |
156 | jne .next_socket |
161 | cmp [eax + UDP_SOCKET.LocalPort], si |
157 | 162 | jne .next_socket |
|
158 | DEBUGF 1,"using socket: %x\n", eax |
163 | |
Line 159... | Line 164... | ||
159 | 164 | DEBUGF 1,"using socket: %x\n", eax |
|
160 | ;;; TODO: when packet is processed, check more sockets! |
165 | |
Line 161... | Line -... | ||
161 | - | ||
162 | cmp [eax + IP_SOCKET.RemoteIP], 0xffffffff |
- | |
163 | je @f |
166 | ;;; TODO: when packet is processed, check more sockets! |
164 | mov edi, [edi + 4] ; ipv4 source address |
167 | |
Line 165... | Line 168... | ||
165 | cmp [eax + IP_SOCKET.RemoteIP], edi |
168 | cmp [eax + IP_SOCKET.RemoteIP], 0xffffffff |
166 | jne .try_more |
169 | je @f |
167 | @@: |
170 | cmp [eax + IP_SOCKET.RemoteIP], edi |
168 | 171 | jne .next_socket |
|
Line 169... | Line 172... | ||
169 | cmp [eax + UDP_SOCKET.firstpacket], 0 |
172 | @@: |
170 | jz .updateport |
173 | |
171 | 174 | cmp [eax + UDP_SOCKET.firstpacket], 0 |
|
172 | mov si, [edx + UDP_Packet.SourcePort] |
175 | jz .updateport |
173 | rol si, 8 |
176 | |
174 | cmp [eax + UDP_SOCKET.RemotePort], si |
- | |
175 | jne .dump |
177 | cmp [eax + UDP_SOCKET.RemotePort], cx |
Line 176... | Line 178... | ||
176 | 178 | jne .dump |
|
Line 177... | Line 179... | ||
177 | push ebx |
179 | |
178 | lea ebx, [eax + SOCKET.lock] |
180 | push ebx |
179 | call wait_mutex |
181 | lea ebx, [eax + SOCKET.lock] |
180 | pop ebx |
182 | call wait_mutex |
181 | 183 | pop ebx |
|
Line 182... | Line 184... | ||
182 | .updatesock: |
184 | |
183 | inc [UDP_PACKETS_RX] |
- | |
184 | DEBUGF 1,"Found valid UDP packet for socket %x\n", eax |
185 | .updatesock: |
185 | lea esi, [edx + sizeof.UDP_Packet] |
186 | inc [UDP_PACKETS_RX] |
186 | movzx ecx, [edx + UDP_Packet.Length] |
187 | DEBUGF 1,"Found valid UDP packet for socket %x\n", eax |
Line 187... | Line 188... | ||
187 | rol cx , 8 |
188 | lea esi, [edx + sizeof.UDP_header] |
Line 244... | Line 245... | ||
244 | mov ebx, [eax + IP_SOCKET.LocalIP] |
245 | mov ebx, [eax + IP_SOCKET.LocalIP] |
245 | mov eax, [eax + IP_SOCKET.RemoteIP] |
246 | mov eax, [eax + IP_SOCKET.RemoteIP] |
Line 246... | Line 247... | ||
246 | 247 | ||
247 | mov di, IP_PROTO_UDP shl 8 + 128 |
248 | mov di, IP_PROTO_UDP shl 8 + 128 |
248 | sub esp, 8 ; Data ptr and data size will be placed here |
249 | sub esp, 8 ; Data ptr and data size will be placed here |
Line 249... | Line 250... | ||
249 | add ecx, sizeof.UDP_Packet |
250 | add ecx, sizeof.UDP_header |
250 | 251 | ||
251 | ;;; TODO: fragment id |
252 | ;;; TODO: fragment id |
252 | push edx esi |
253 | push edx esi |
Line 253... | Line 254... | ||
253 | call IPv4_output |
254 | call IPv4_output |
254 | jz .fail |
255 | jz .fail |
Line 255... | Line 256... | ||
255 | 256 | ||
256 | mov [esp + 8], eax ; pointer to buffer start |
257 | mov [esp + 8], eax ; pointer to buffer start |
Line 257... | Line 258... | ||
257 | mov [esp + 8 + 4], edx ; buffer size |
258 | mov [esp + 8 + 4], edx ; buffer size |
258 | 259 | ||
259 | mov [edi + UDP_Packet.Length], cx |
260 | mov [edi + UDP_header.Length], cx |
260 | rol [edi + UDP_Packet.Length], 8 |
261 | rol [edi + UDP_header.Length], 8 |
261 | 262 | ||
262 | pop esi |
263 | pop esi |
263 | push edi ecx |
264 | push edi ecx |
264 | sub ecx, sizeof.UDP_Packet |
265 | sub ecx, sizeof.UDP_header |
265 | add edi, sizeof.UDP_Packet |
266 | add edi, sizeof.UDP_header |
266 | shr ecx, 2 |
267 | shr ecx, 2 |
Line 267... | Line 268... | ||
267 | rep movsd |
268 | rep movsd |
Line 268... | Line 269... | ||
268 | mov ecx, [esp] |
269 | mov ecx, [esp] |
269 | and ecx, 3 |
270 | and ecx, 3 |
270 | rep movsb |
271 | rep movsb |
271 | pop ecx edi |
272 | pop ecx edi |
Line 272... | Line 273... | ||
272 | 273 | ||
Line 273... | Line 274... | ||
273 | pop dword [edi + UDP_Packet.SourcePort] |
274 | pop dword [edi + UDP_header.SourcePort] |