Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 1513 → Rev 1514

/kernel/branches/net/network/icmp.inc
1,6 → 1,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; ICMP.INC ;;
130,10 → 130,10
 
;-----------------------------------------------------------------
;
; ICMP_Handler:
; ICMP_input:
;
; this procedure will send reply's to ICMP echo's
; and insert packets into sockets when needed ;;; TODO: update this to work with fragmented packets too!
; This procedure will send reply's to ICMP echo's
; and insert packets into sockets when needed
;
; IN: Pointer to buffer in [esp]
; size of buffer in [esp+4]
144,20 → 144,22
;
;-----------------------------------------------------------------
align 4
ICMP_handler: ;TODO: works only on pure ethernet right now !
ICMP_input:
 
DEBUGF 1,"ICMP_Handler - buf:%x size:%x dev:%x, size:%x, buf:%x\n", [esp], [esp+4], ebx, ecx, edx
;;; TODO: works only on pure ethernet right now !
 
DEBUGF 1,"ICMP_Handler - start\n"
cmp byte [edx + ICMP_Packet.Type], ICMP_ECHO ; Is this an echo request?
jne .check_sockets
 
;;; TODO: check checksum!
 
DEBUGF 1,"ICMP_Handler - is echo request, through device:%x\n", ebx
DEBUGF 1,"ICMP_Handler - echo request\n"
 
mov byte [edx + ICMP_Packet.Type], ICMP_ECHOREPLY ; Change Packet type to reply
mov word [edx + ICMP_Packet.Checksum], 0 ; Set checksum to 0, needed to calculate new checksum
 
call ETH_struc2dev
call NET_ptr_to_num
cmp edi,-1
je .dump
inc [ICMP_PACKETS_RX+4*edi]
207,12 → 209,12
pop ecx edx ebx
mov word [edx + ICMP_Packet.Checksum], ax
 
jmp ETH_sender ; Send the reply
jmp NET_send ; Send the reply
; and return to caller of this proc
 
 
 
 
 
.check_sockets:
; TODO: validate the header & checksum.
 
222,12 → 224,12
.try_more:
mov ax , [edx + ICMP_Packet.Identifier]
.next_socket:
mov esi, [esi + SOCKET_head.NextPtr]
mov esi, [esi + SOCKET.NextPtr]
or esi, esi
jz .dump
cmp [esi + SOCKET_head.Type], IP_PROTO_ICMP
cmp [esi + SOCKET.Type], IP_PROTO_ICMP
jne .next_socket
cmp [esi + SOCKET_head.end + IPv4_SOCKET.end + ICMP_SOCKET.Identifier], ax
cmp [esi + ICMP_SOCKET.Identifier], ax
jne .next_socket
 
call IPv4_dest_to_dev
237,7 → 239,7
 
DEBUGF 1,"Found valid ICMP packet for socket %x\n", esi
 
lea ebx, [esi + SOCKET_head.lock]
lea ebx, [esi + SOCKET.lock]
call wait_mutex
 
; Now, assign data to socket. We have socket address in esi.
249,7 → 251,7
add esp, 4
sub edx, esi
mov edi, edx
jmp socket_internal_receiver
;;; jmp SOCKET_input
 
.dump:
DEBUGF 1,"ICMP_Handler - dumping\n"
262,59 → 264,6
 
;-----------------------------------------------------------------
;
; ICMP_Handler_fragments:
;
; Called by IP_handler,
; this procedure will send reply's to ICMP echo's etc
;
; IN: Pointer to buffer in [esp]
; size of buffer in [esp+4]
; pointer to device struct in ebx
; ICMP Packet size in ecx
; pointer to ICMP Packet data in edx
; OUT: /
;
;-----------------------------------------------------------------
align 4
ICMP_handler_fragments: ; works only on pure ethernet right now !
 
DEBUGF 1,"ICMP_Handler_fragments - start\n"
 
cmp ecx, 65500
jg .dump
 
cmp byte [edx + ICMP_Packet.Type], ICMP_ECHO ; Is this an echo request? discard if not
jne .dump
 
mov esi, [esp]
 
sub ecx, ICMP_Packet.Data
mov eax, [esi + IPv4_Packet.SourceAddress]
mov ebx, [esi + IPv4_Packet.DestinationAddress]
push word [esi + IPv4_Packet.Identification]
 
mov di , [edx + ICMP_Packet.Identifier]
shl edi, 16
mov di , [edx + ICMP_Packet.SequenceNumber]
 
mov esi, edx
add esi, ICMP_Packet.Data
pop dx
shl edx, 16
mov dx , ICMP_ECHOREPLY shl 8 + 0 ; Type + Code
 
call ICMP_create_packet
 
.dump:
DEBUGF 1,"ICMP_Handler_fragments - end\n"
 
call kernel_free
add esp, 4 ; pop (balance stack)
ret
 
 
;-----------------------------------------------------------------
;
; Note: ICMP only works on top of IP protocol :)
;
; inputs:
330,7 → 279,7
;
;-----------------------------------------------------------------
align 4
ICMP_create_packet:
ICMP_output:
 
DEBUGF 1,"Create ICMP Packet\n"
 
341,10 → 290,8
shr edx, 16
 
call IPv4_create_packet
jz .exit
 
cmp edi, -1
je .exit
 
DEBUGF 1,"full icmp packet size: %u\n", edx
 
pop eax
372,7 → 319,7
and cx , 3
rep movsb
 
sub edi, edx ;; TODO: find a better way to remember start of packet
sub edi, edx ;;; TODO: find a better way to remember start of packet
mov ecx, [ebx + ETH_DEVICE.transmit]
push edx edi ecx
DEBUGF 1,"Sending ICMP Packet\n"