Subversion Repositories Kolibri OS

Rev

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

Rev 1473 Rev 1514
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2010. 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
;;  ICMP.INC                                                       ;;
6
;;  ICMP.INC                                                       ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;  Part of the tcp/ip network stack for KolibriOS                 ;;
8
;;  Part of the tcp/ip network stack for KolibriOS                 ;;
Line 15... Line 15...
15
;;             Version 2, June 1991                                ;;
15
;;             Version 2, June 1991                                ;;
16
;;                                                                 ;;
16
;;                                                                 ;;
17
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 18... Line 18...
18
 
18
 
Line 19... Line 19...
19
 
19
 
Line 20... Line 20...
20
$Revision: 1473 $
20
$Revision: 1514 $
Line 128... Line 128...
128
													     
128
													     
129
 
129
 
130
 
130
 
131
;-----------------------------------------------------------------
131
;-----------------------------------------------------------------
132
;
132
;
133
; ICMP_Handler:
133
; ICMP_input:
134
;
134
;
135
;  this procedure will send reply's to ICMP echo's
135
;  This procedure will send reply's to ICMP echo's
136
;  and insert packets into sockets when needed                         ;;; TODO: update this to work with fragmented packets too!
136
;   and insert packets into sockets when needed
137
;
137
;
138
;  IN:  Pointer to buffer in [esp]
138
;  IN:  Pointer to buffer in [esp]
139
;       size of buffer in [esp+4]
139
;       size of buffer in [esp+4]
140
;       pointer to device struct in ebx
140
;       pointer to device struct in ebx
141
;       ICMP Packet size in ecx
141
;       ICMP Packet size in ecx
142
;       pointer to ICMP Packet data in edx
142
;       pointer to ICMP Packet data in edx
143
;  OUT: /
143
;  OUT: /
144
;
144
;
Line -... Line 145...
-
 
145
;-----------------------------------------------------------------
-
 
146
align 4
145
;-----------------------------------------------------------------
147
ICMP_input:
146
align 4
148
 
147
ICMP_handler:	;TODO: works only on pure ethernet right now !
149
;;; TODO: works only on pure ethernet right now !
Line 148... Line 150...
148
 
150
 
Line 149... Line 151...
149
	DEBUGF	1,"ICMP_Handler - buf:%x size:%x dev:%x, size:%x, buf:%x\n", [esp], [esp+4], ebx, ecx, edx
151
	DEBUGF	1,"ICMP_Handler - start\n"
Line 150... Line 152...
150
	cmp	byte [edx + ICMP_Packet.Type], ICMP_ECHO		    ; Is this an echo request?
152
	cmp	byte [edx + ICMP_Packet.Type], ICMP_ECHO		    ; Is this an echo request?
151
	jne	.check_sockets
153
	jne	.check_sockets
Line 152... Line 154...
152
 
154
 
153
;;; TODO: check checksum!
155
;;; TODO: check checksum!
154
 
156
 
155
	DEBUGF	1,"ICMP_Handler - is echo request, through device:%x\n", ebx
157
	DEBUGF	1,"ICMP_Handler - echo request\n"
156
 
158
 
Line 205... Line 207...
205
	call	checksum_2
207
	call	checksum_2
206
	mov	ax , dx
208
	mov	ax , dx
207
	pop	ecx edx ebx
209
	pop	ecx edx ebx
208
	mov	word [edx + ICMP_Packet.Checksum], ax
210
	mov	word [edx + ICMP_Packet.Checksum], ax
Line 209... Line 211...
209
 
211
 
210
	jmp	ETH_sender						    ; Send the reply
-
 
-
 
212
	jmp	NET_send						  ; Send the reply
Line 211... Line 213...
211
 
213
									    ; and return to caller of this proc
Line 220... Line 222...
220
 
222
 
221
	mov	esi, net_sockets
223
	mov	esi, net_sockets
222
  .try_more:
224
  .try_more:
223
	mov	ax , [edx + ICMP_Packet.Identifier]
225
	mov	ax , [edx + ICMP_Packet.Identifier]
224
  .next_socket:
226
  .next_socket:
225
	mov	esi, [esi + SOCKET_head.NextPtr]
227
	mov	esi, [esi + SOCKET.NextPtr]
226
	or	esi, esi
228
	or	esi, esi
227
	jz	.dump
229
	jz	.dump
228
	cmp	[esi + SOCKET_head.Type], IP_PROTO_ICMP
230
	cmp	[esi + SOCKET.Type], IP_PROTO_ICMP
229
	jne	.next_socket
231
	jne	.next_socket
230
	cmp	[esi + SOCKET_head.end + IPv4_SOCKET.end + ICMP_SOCKET.Identifier], ax
232
	cmp	[esi + ICMP_SOCKET.Identifier], ax
Line 231... Line 233...
231
	jne	.next_socket
233
	jne	.next_socket
232
 
234
 
233
	call	IPv4_dest_to_dev
235
	call	IPv4_dest_to_dev
234
	cmp	edi,-1
236
	cmp	edi,-1
Line 235... Line 237...
235
	je	.dump
237
	je	.dump
Line 236... Line 238...
236
	inc	[ICMP_PACKETS_RX+4*edi]
238
	inc	[ICMP_PACKETS_RX+4*edi]
237
 
239
 
Line 238... Line 240...
238
	DEBUGF 1,"Found valid ICMP packet for socket %x\n", esi
240
	DEBUGF 1,"Found valid ICMP packet for socket %x\n", esi
239
 
241
 
240
	lea	ebx, [esi + SOCKET_head.lock]
242
	lea	ebx, [esi + SOCKET.lock]
Line 247... Line 249...
247
	mov	eax, esi
249
	mov	eax, esi
248
	pop	esi
250
	pop	esi
249
	add	esp, 4
251
	add	esp, 4
250
	sub	edx, esi
252
	sub	edx, esi
251
	mov	edi, edx
253
	mov	edi, edx
252
	jmp	socket_internal_receiver
254
;;;        jmp     SOCKET_input
Line 253... Line 255...
253
 
255
 
254
       .dump:
256
       .dump:
Line 255... Line 257...
255
	DEBUGF	1,"ICMP_Handler - dumping\n"
257
	DEBUGF	1,"ICMP_Handler - dumping\n"
Line 260... Line 262...
260
	ret
262
	ret
Line 261... Line 263...
261
 
263
 
262
 
264
 
263
;-----------------------------------------------------------------
-
 
264
;
-
 
265
; ICMP_Handler_fragments:
-
 
266
;
-
 
267
;  Called by IP_handler,
-
 
268
;  this procedure will send reply's to ICMP echo's etc
-
 
269
;
-
 
270
;  IN:  Pointer to buffer in [esp]
-
 
271
;       size of buffer in [esp+4]
-
 
272
;       pointer to device struct in ebx
-
 
273
;       ICMP Packet size in ecx
-
 
274
;       pointer to ICMP Packet data in edx
-
 
275
;  OUT: /
-
 
276
;
-
 
277
;-----------------------------------------------------------------
-
 
278
align 4
-
 
279
ICMP_handler_fragments:   ; works only on pure ethernet right now !
-
 
280
 
-
 
281
	DEBUGF	1,"ICMP_Handler_fragments - start\n"
-
 
282
 
-
 
283
	cmp	ecx, 65500
-
 
284
	jg	.dump
-
 
285
 
-
 
286
	cmp	byte [edx + ICMP_Packet.Type], ICMP_ECHO		    ; Is this an echo request? discard if not
-
 
287
	jne	.dump
-
 
288
 
-
 
289
	mov	esi, [esp]
-
 
290
 
-
 
291
	sub	ecx, ICMP_Packet.Data
-
 
292
	mov	eax, [esi + IPv4_Packet.SourceAddress]
-
 
293
	mov	ebx, [esi + IPv4_Packet.DestinationAddress]
-
 
294
	push	word [esi + IPv4_Packet.Identification]
-
 
295
 
-
 
296
	mov	di , [edx + ICMP_Packet.Identifier]
-
 
297
	shl	edi, 16
-
 
298
	mov	di , [edx + ICMP_Packet.SequenceNumber]
-
 
299
 
-
 
300
	mov	esi, edx
-
 
301
	add	esi, ICMP_Packet.Data
-
 
302
	pop	dx
-
 
303
	shl	edx, 16
-
 
304
	mov	dx , ICMP_ECHOREPLY shl 8 + 0				    ; Type + Code
-
 
305
 
-
 
306
	call	ICMP_create_packet
-
 
307
 
-
 
308
       .dump:
-
 
309
	DEBUGF	1,"ICMP_Handler_fragments - end\n"
-
 
310
 
-
 
311
	call	kernel_free
-
 
312
	add	esp, 4 ; pop (balance stack)
-
 
313
	ret
-
 
314
 
-
 
315
 
-
 
316
;-----------------------------------------------------------------
265
;-----------------------------------------------------------------
317
;
266
;
318
; Note: ICMP only works on top of IP protocol :)
267
; Note: ICMP only works on top of IP protocol :)
319
;
268
;
320
; inputs:
269
; inputs:
Line 328... Line 277...
328
; esi = data offset
277
; esi = data offset
329
; edi = identifier shl 16 + sequence number
278
; edi = identifier shl 16 + sequence number
330
;
279
;
331
;-----------------------------------------------------------------
280
;-----------------------------------------------------------------
332
align 4
281
align 4
333
ICMP_create_packet:
282
ICMP_output:
Line 334... Line 283...
334
 
283
 
Line 335... Line 284...
335
	DEBUGF 1,"Create ICMP Packet\n"
284
	DEBUGF 1,"Create ICMP Packet\n"
Line 336... Line 285...
336
 
285
 
337
	push	esi edi edx
286
	push	esi edi edx
338
 
287
 
Line 339... Line 288...
339
	add	ecx, ICMP_Packet.Data
288
	add	ecx, ICMP_Packet.Data
340
	mov	di , IP_PROTO_ICMP
-
 
341
	shr	edx, 16
-
 
342
 
289
	mov	di , IP_PROTO_ICMP
Line 343... Line 290...
343
	call	IPv4_create_packet
290
	shr	edx, 16
Line 344... Line 291...
344
 
291
 
345
	cmp	edi, -1
292
	call	IPv4_create_packet
Line 370... Line 317...
370
	rep	movsd
317
	rep	movsd
371
	pop	cx
318
	pop	cx
372
	and	cx , 3
319
	and	cx , 3
373
	rep	movsb
320
	rep	movsb
Line 374... Line 321...
374
 
321
 
375
	sub	edi, edx  ;; TODO: find a better way to remember start of packet
322
	sub	edi, edx				;;; TODO: find a better way to remember start of packet
376
	mov	ecx, [ebx + ETH_DEVICE.transmit]
323
	mov	ecx, [ebx + ETH_DEVICE.transmit]
377
	push	edx edi ecx
324
	push	edx edi ecx
378
	DEBUGF 1,"Sending ICMP Packet\n"
325
	DEBUGF 1,"Sending ICMP Packet\n"