Subversion Repositories Kolibri OS

Rev

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

Rev 1542 Rev 1544
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: 1542 $
20
$Revision: 1544 $
Line 119... Line 119...
119
	rep	stosd
119
	rep	stosd
Line 120... Line 120...
120
 
120
 
Line 121... Line -...
121
}
-
 
122
												    
-
 
123
													     
121
}
124
 
122
 
125
 
123
 
126
;-----------------------------------------------------------------
124
;-----------------------------------------------------------------
127
;
125
;
Line 141... Line 139...
141
;
139
;
142
;-----------------------------------------------------------------
140
;-----------------------------------------------------------------
143
align 4
141
align 4
144
ICMP_input:
142
ICMP_input:
Line 145... Line -...
145
 
-
 
146
;;; TODO: check checksum!
-
 
147
 
143
 
-
 
144
	DEBUGF	1,"ICMP_input - start\n"
-
 
145
 
-
 
146
; First, check the checksum (altough some implementations ignore it)
-
 
147
 
-
 
148
	push	edx esi ecx
-
 
149
	push	[edx + ICMP_Packet.Checksum]
-
 
150
	mov	[edx + ICMP_Packet.Checksum], 0
-
 
151
	mov	esi, edx
-
 
152
	xor	edx, edx
-
 
153
	call	checksum_1
-
 
154
	call	checksum_2
-
 
155
	pop	si
-
 
156
	cmp	dx, si
-
 
157
	pop	ecx esi edx
-
 
158
	jne	.checksum_mismatch
148
	DEBUGF	1,"ICMP_input - start\n"
159
 
149
	cmp	byte [edx + ICMP_Packet.Type], ICMP_ECHO		    ; Is this an echo request?
160
	cmp	byte [edx + ICMP_Packet.Type], ICMP_ECHO		    ; Is this an echo request?
Line 150... Line 161...
150
	jne	.check_sockets
161
	jne	.check_sockets
-
 
162
 
Line -... Line 163...
-
 
163
; We well re-use the packet sow e can create the response as fast as possible
151
 
164
; Notice: this only works on pure ethernet (however, IP packet options are not a problem this time :)
152
	DEBUGF	1,"ICMP_input - echo request\n"
-
 
Line -... Line 165...
-
 
165
 
153
 
166
	DEBUGF	1,"ICMP_input - echo request\n"
154
	mov	byte [edx + ICMP_Packet.Type], ICMP_ECHOREPLY		    ; Change Packet type to reply
167
	mov	byte [edx + ICMP_Packet.Type], ICMP_ECHOREPLY		    ; Change Packet type to reply
155
	mov	word [edx + ICMP_Packet.Checksum], 0			    ; Set checksum to 0, needed to calculate new checksum
168
 
156
 
169
; Update stats (and validate device ptr)
157
	call	NET_ptr_to_num
170
	call	NET_ptr_to_num
Line 158... Line 171...
158
	cmp	edi,-1
171
	cmp	edi,-1
159
	je	.dump
172
	je	.dump
160
	inc	[ICMP_PACKETS_RX+4*edi]
173
	inc	[ICMP_PACKETS_RX+4*edi]
161
	inc	[ICMP_PACKETS_TX+4*edi]
-
 
162
 
174
	inc	[ICMP_PACKETS_TX+4*edi]
163
; exchange dest and source address in IP header
175
 
164
; exchange dest and source MAC in ETH header
176
; exchange dest and source address in IP header
165
	mov	esi, [esp]
177
; exchange dest and source MAC in ETH header
166
 
-
 
167
	mov	eax, dword [esi + ETH_FRAME.DstMAC]
178
	mov	esi, [esp]						    ; Start of buffer
168
	mov	ecx, dword [esi + ETH_FRAME.SrcMAC]
179
	push	dword [esi + ETH_FRAME.DstMAC]
169
	mov	dword [esi + ETH_FRAME.SrcMAC], eax
180
	push	dword [esi + ETH_FRAME.SrcMAC]
170
	mov	dword [esi + ETH_FRAME.DstMAC], ecx
181
	pop	dword [esi + ETH_FRAME.DstMAC]
171
 
182
	pop	dword [esi + ETH_FRAME.SrcMAC]
-
 
183
	push	word [esi + ETH_FRAME.DstMAC + 4]
172
	mov	ax, word [esi + ETH_FRAME.DstMAC + 4]
184
	push	word [esi + ETH_FRAME.SrcMAC + 4]
173
	mov	cx, word [esi + ETH_FRAME.SrcMAC + 4]
185
	pop	word [esi + ETH_FRAME.DstMAC + 4]
174
	mov	word [esi + ETH_FRAME.SrcMAC + 4], ax
186
	pop	word [esi + ETH_FRAME.SrcMAC + 4]
175
	mov	word [esi + ETH_FRAME.DstMAC + 4], cx
187
 
Line 176... Line 188...
176
 
188
	add	esi, ETH_FRAME.Data
177
	mov	eax, dword [esi + ETH_FRAME.Data + IPv4_Packet.SourceAddress]
-
 
178
	mov	ecx, dword [esi + ETH_FRAME.Data + IPv4_Packet.DestinationAddress]
189
	push	[esi + IPv4_Packet.SourceAddress]
179
	mov	dword [esi + ETH_FRAME.Data + IPv4_Packet.DestinationAddress], eax
190
	push	[esi + IPv4_Packet.DestinationAddress]
180
	mov	dword [esi + ETH_FRAME.Data + IPv4_Packet.SourceAddress], ecx
191
	pop	[esi + IPv4_Packet.SourceAddress]
-
 
192
	pop	[esi + IPv4_Packet.DestinationAddress]
-
 
193
 
-
 
194
; Recalculate ip header checksum
181
 
195
	movzx	ecx, byte [esi + IPv4_Packet.VersionAndIHL]		    ; Calculate IP Header length by using IHL field
182
; Recalculate ip header checksum
196
	and	ecx, 0x0f
183
	add	esi, ETH_FRAME.Data					    ; Point esi to start of IP Packet
197
	shl	cx, 2
184
	movzx	ecx, byte [esi + IPv4_Packet.VersionAndIHL]		    ; Calculate IP Header length by using IHL field
198
	mov	edi, ecx						    ; IP header length
185
	and	ecx, 0x0000000F 					    ;
199
	mov	eax, edx						    ; ICMP packet start addr
186
	shl	cx , 2
200
 
Line 187... Line 201...
187
	push	ebx edx ecx esi
201
	push	esi							    ; Calculate the IP checksum
188
	xor	edx, edx
202
	xor	edx, edx						    ;
189
	call	checksum_1
203
	call	checksum_1						    ;
190
	call	checksum_2
204
	call	checksum_2						    ;
191
	pop	esi
205
	pop	esi							    ;
192
	mov	word [esi + IPv4_Packet.HeaderChecksum], dx		    ; Store it in the IP Packet header
206
	mov	word [esi + IPv4_Packet.HeaderChecksum], dx		    ;
193
 
207
 
194
; Recalculate ICMP CheckSum
208
; Recalculate ICMP CheckSum
195
	movzx	eax, word[esi + IPv4_Packet.TotalLength]		    ; Find length of IP Packet
209
	movzx	ecx, word[esi + IPv4_Packet.TotalLength]		    ; Find length of IP Packet
196
	xchg	ah , al 						    ;
-
 
197
	sub	eax, [esp]						     ; Now we know the length of ICMP data in eax
-
 
198
	mov	ecx, eax
210
	xchg	ch, cl							    ;
Line -... Line 211...
-
 
211
	sub	ecx, edi						    ; IP packet length - IP header length = ICMP packet length
199
	mov	esi, [esp + 4]
212
 
200
	xor	edx, edx
213
	mov	esi, eax						    ; Calculate ICMP checksum
Line 247... Line 260...
247
 
260
 
248
	mov	esi, edx
261
	mov	esi, edx
Line -... Line 262...
-
 
262
	jmp	SOCKET_input
-
 
263
 
-
 
264
 
249
	jmp	SOCKET_input
265
  .checksum_mismatch:
250
 
266
	DEBUGF	1,"ICMP_Handler - checksum mismatch\n"
Line 251... Line 267...
251
 
267
 
252
       .dump:
268
  .dump: