Subversion Repositories Kolibri OS

Rev

Rev 1337 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1337 Rev 1473
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: 1337 $
17
$Revision: 1473 $
18
 
18
 
19
 
19
 
Line 73... Line 73...
73
;-----------------------------------------------------------------
73
;-----------------------------------------------------------------
74
align 4
74
align 4
75
UDP_handler:
75
UDP_handler:
Line 76... Line 76...
76
 
76
 
-
 
77
	DEBUGF	1,"UDP_Handler\n"
-
 
78
 
-
 
79
	cmp	[edx + UDP_Packet.Checksum], 0
77
	DEBUGF 1,"UDP_Handler\n"
80
	jz	.no_checksum
Line 78... Line 81...
78
	; First validate, checksum:
81
	; First validate, checksum:
Line 79... Line -...
79
 
-
 
80
	pusha
82
 
81
 
83
	pusha
82
	rol	cx, 8
84
 
83
	push	cx
85
	push	cx
84
	rol	cx, 8
86
	rol	word [esp], 8
Line 85... Line 87...
85
	push	word IP_PROTO_UDP shl 8
87
	push	word IP_PROTO_UDP shl 8
86
	push	edi
88
	push	edi
Line 87... Line 89...
87
	push	esi
89
	push	esi
88
 
90
 
89
	mov	di, [edx + UDP_Packet.Checksum]
91
	mov	di, [edx + UDP_Packet.Checksum]
90
	mov    [edx + UDP_Packet.Checksum], 0
-
 
91
 
-
 
92
	mov	esi, edx
92
	mov	[edx + UDP_Packet.Checksum], 0
93
	xor	edx, edx
-
 
94
	call	checksum_1
93
 
Line 95... Line 94...
95
	mov	ecx, 12
94
	mov	esi, edx
96
	mov	esi, esp
95
	xor	edx, edx
-
 
96
	call	checksum_1
-
 
97
	call	checksum_pseudoheader
-
 
98
	call	checksum_2
97
	call	checksum_1
99
 
Line 98... Line 100...
98
	add	esp, 12
100
	cmp	di, dx
Line 99... Line 101...
99
	call	checksum_2
101
	popa
100
 
102
	jne	.checksum_mismatch ;dump
101
	cmp	di, dx
103
 
Line 102... Line 104...
102
	popa
104
 
103
	jne	.dump
105
  .no_checksum:
104
 
106
 
105
	DEBUGF 1,"UDP Checksum is correct\n"
107
	DEBUGF	1,"UDP Checksum is correct\n"
106
 
108
 
107
	; Look for a socket where
109
	; Look for a socket where
108
	; IP Packet UDP Destination Port = local Port
110
	; IP Packet UDP Destination Port = local Port
109
	; IP Packet SA = Remote IP
111
	; IP Packet SA = Remote IP
110
 
112
 
111
	mov	eax, net_sockets
113
	mov	eax, net_sockets
112
  .try_more:
114
  .try_more:
113
	mov	bx , [edx + UDP_Packet.DestinationPort]   ; get the local port from the IP Packet's UDP header
115
	mov	si , [edx + UDP_Packet.DestinationPort]   ; get the local port from the IP Packet's UDP header
114
  .next_socket:
116
  .next_socket:
Line 115... Line 117...
115
	mov	eax, [eax + SOCKET_head.NextPtr]
117
	mov	eax, [eax + SOCKET_head.NextPtr]
Line 116... Line 118...
116
	or	eax, eax
118
	or	eax, eax
Line 129... Line 131...
129
	; I bind to, if the socket is opened with a destination IP address of
131
	; I bind to, if the socket is opened with a destination IP address of
130
	; 255.255.255.255
132
	; 255.255.255.255
131
	cmp	[eax + SOCKET_head.end + IPv4_SOCKET.RemoteIP], 0xffffffff
133
	cmp	[eax + SOCKET_head.end + IPv4_SOCKET.RemoteIP], 0xffffffff
132
	je	.ok1
134
	je	.ok1
Line 133... Line 135...
133
 
135
 
134
	mov	ebx, [esp]
136
	mov	esi, [esp]
135
	mov	ebx, [ebx + ETH_FRAME.Data + IPv4_Packet.SourceAddress] ; get the Source address from the IP Packet   FIXME
137
	mov	esi, [ebx + ETH_FRAME.Data + IPv4_Packet.SourceAddress] ; get the Source address from the IP Packet   FIXME
136
	cmp	[eax + SOCKET_head.end + IPv4_SOCKET.RemoteIP], ebx
138
	cmp	[eax + SOCKET_head.end + IPv4_SOCKET.RemoteIP], esi
Line 137... Line 139...
137
	jne	.try_more					      ; Quit if the source IP is not valid, check for more sockets with this IP/PORT combination
139
	jne	.try_more					      ; Quit if the source IP is not valid, check for more sockets with this IP/PORT combination
138
 
140
 
Line 139... Line 141...
139
 
141
 
140
	DEBUGF 1,"Remote Ip matches\n"
142
	DEBUGF	1,"Remote Ip matches\n"
Line 141... Line 143...
141
  .ok1:
143
  .ok1:
142
 
144
 
143
	cmp	[eax + SOCKET_head.end + IPv4_SOCKET.end + UDP_SOCKET.firstpacket], 0
145
	cmp	[eax + SOCKET_head.end + IPv4_SOCKET.end + UDP_SOCKET.firstpacket], 0
Line -... Line 146...
-
 
146
	jz	.updateport
144
	jz	.updateport
147
 
145
 
148
	mov	si, [edx + UDP_Packet.SourcePort]
-
 
149
	cmp	[eax + SOCKET_head.end + IPv4_SOCKET.end + UDP_SOCKET.RemotePort], si
Line 146... Line 150...
146
	mov	bx, [edx + UDP_Packet.SourcePort]
150
	jne	.dump
Line 147... Line 151...
147
	cmp	[eax + SOCKET_head.end + IPv4_SOCKET.end + UDP_SOCKET.RemotePort], bx
151
 
148
	jne	.dump
152
	push	ebx
Line 168... Line 172...
168
	jmp	socket_internal_receiver
172
	jmp	socket_internal_receiver
Line 169... Line 173...
169
 
173
 
Line -... Line 174...
-
 
174
 
170
 
175
  .updateport:
171
  .updateport:
176
 
-
 
177
	push	ebx
Line 172... Line 178...
172
 
178
	lea	ebx, [eax + SOCKET_head.lock]
173
	lea	ebx, [eax + SOCKET_head.lock]
179
	call	wait_mutex
174
	call	wait_mutex
180
	pop	ebx
175
 
181
 
Line 176... Line 182...
176
	mov	bx, [edx + UDP_Packet.SourcePort]
182
	mov	si, [edx + UDP_Packet.SourcePort]
Line -... Line 183...
-
 
183
	DEBUGF	1,"Changing remote port to: %x\n", si
-
 
184
	mov	[eax + SOCKET_head.end + IPv4_SOCKET.end + UDP_SOCKET.RemotePort], si
-
 
185
	inc	[eax + SOCKET_head.end + IPv4_SOCKET.end + UDP_SOCKET.firstpacket]
-
 
186
 
-
 
187
	jmp	.ok2
-
 
188
 
-
 
189
  .checksum_mismatch:
-
 
190
 
-
 
191
	DEBUGF	2,"UDP_Handler - checksum mismatch\n"
-
 
192
 
-
 
193
	mov	esi, [esp]
177
	DEBUGF 1,"Changing remote port to: %x\n", bx
194
	mov	ecx, [esp + 4]
178
	mov	[eax + SOCKET_head.end + IPv4_SOCKET.end + UDP_SOCKET.RemotePort], bx
-
 
179
	inc	[eax + SOCKET_head.end + IPv4_SOCKET.end + UDP_SOCKET.firstpacket]
195
       @@:			   ;
180
 
196
	lodsb			   ;
-
 
197
	DEBUGF	2,"%x ", eax:2	   ;
Line 181... Line 198...
181
	jmp	.ok2
198
	loop	@r		   ;
Line 211... Line 228...
211
	mov	eax, [eax + SOCKET_head.end + IPv4_SOCKET.RemoteIP]
228
	mov	eax, [eax + SOCKET_head.end + IPv4_SOCKET.RemoteIP]
Line 212... Line 229...
212
 
229
 
Line 213... Line 230...
213
	DEBUGF 1,"Create UDP Packet (size=%u)\n",ecx
230
	DEBUGF	1,"Create UDP Packet (size=%u)\n",ecx
214
 
-
 
215
	mov	di , IP_PROTO_UDP
231
 
216
 
-
 
217
	sub	esp, 8						; reserve some place in stack for later
232
	mov	di , IP_PROTO_UDP
218
 
233
	sub	esp, 8						; reserve some place in stack for later
219
; Create a part pseudoheader in stack,
-
 
220
	push	dword IP_PROTO_UDP shl 8
234
								; Create a part of the pseudoheader in stack,
Line 221... Line 235...
221
 
235
	push	dword IP_PROTO_UDP shl 8
Line 222... Line 236...
222
	add	ecx, UDP_Packet.Data
236
	add	ecx, UDP_Packet.Data
Line 255... Line 269...
255
	mov	esi, edi
269
	mov	esi, edi
256
	call	checksum_1
270
	call	checksum_1
257
; Checksum for pseudoheader
271
; Checksum for pseudoheader
258
	pushd	[edi-4] ; destination address           ; TODO: fix this, IPv4 packet could have options..
272
	pushd	[edi-4] ; destination address           ; TODO: fix this, IPv4 packet could have options..
259
	pushd	[edi-8] ; source address
273
	pushd	[edi-8] ; source address
260
	mov	ecx, 12
-
 
261
	mov	esi, esp
-
 
262
	call	checksum_1
274
	call	checksum_pseudoheader
263
	add	esp, 12 					; remove the pseudoheader from stack
-
 
264
; Now create the final checksum and store it in UDP header
275
; Now create the final checksum and store it in UDP header
265
	call	checksum_2
276
	call	checksum_2
266
	mov	[edi + UDP_Packet.Checksum], dx
277
	mov	[edi + UDP_Packet.Checksum], dx
Line 267... Line 278...
267
 
278