Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 2307 → Rev 2308

/kernel/branches/net/network/IPv4.inc
290,20 → 290,18
; No, it's just a regular IP packet, pass it to the higher protocols
 
.handle_it: ; We reach here if packet hasnt been fragmented, or when it already has been re-constructed
movzx eax, [edx + IPv4_header.VersionAndIHL] ; Calculate Header length by using IHL field
and eax, 0x0000000f ;
shl eax, 2 ;
 
movzx esi, [edx + IPv4_header.VersionAndIHL] ; Calculate Header length by using IHL field
and esi, 0x0000000f ;
shl esi, 2 ;
 
movzx ecx, [edx + IPv4_header.TotalLength] ; Calculate length of encapsulated Packet
xchg cl , ch ;
sub ecx, eax ;
sub ecx, esi ;
 
add eax, edx
push eax
 
mov esi, [edx + IPv4_header.SourceAddress] ; These values might be of interest to the higher protocols
mov edi, [edx + IPv4_header.DestinationAddress] ;
lea edi, [edx + IPv4_header.SourceAddress] ; make edi ptr to source and dest IPv4 address
mov al , [edx + IPv4_header.Protocol]
pop edx ; Offset to data (tcp/udp/icmp/.. Packet)
add edx, esi ; make edi ptr to data
 
cmp al , IP_PROTO_TCP
je TCP_input
/kernel/branches/net/network/icmp.inc
134,8 → 134,8
; ebx = pointer to device struct
; ecx = ICMP Packet size
; edx = ptr to ICMP Packet data
; esi = ipv4 source address
; edi = ipv4 dest address
; edi = ptr to ipv4 source and dest address
;
; OUT: /
;
;-----------------------------------------------------------------
146,7 → 146,7
 
; First, check the checksum (altough some implementations ignore it)
 
push edx esi ecx
push edx ecx
push [edx + ICMP_header.Checksum]
mov [edx + ICMP_header.Checksum], 0
mov esi, edx
155,7 → 155,7
call checksum_2
pop si
cmp dx, si
pop ecx esi edx
pop ecx edx
jne .checksum_mismatch
 
cmp [edx + ICMP_header.Type], ICMP_ECHO ; Is this an echo request?
162,7 → 162,7
jne .check_sockets
 
; We well re-use the packet sow e can create the response as fast as possible
; Notice: this only works on pure ethernet (however, IP packet options are not a problem this time :)
; Notice: this only works on pure ethernet
 
DEBUGF 1,"ICMP_input - echo request\n"
mov [edx + ICMP_header.Type], ICMP_ECHOREPLY ; Change Packet type to reply
226,8 → 226,8
 
.check_sockets:
; Look for an open ICMP socket
; esi = sender ip
 
mov esi, [edi] ; ipv4 source address
mov ebx, net_sockets
.try_more:
; mov ax , [edx + ICMP_header.Identifier]
/kernel/branches/net/network/tcp_input.inc
25,10 → 25,8
; ebx = ptr to device struct
; ecx = segment size
; edx = ptr to TCP segment
; edi = ptr to ipv4 source address, followed by ipv4 dest address
;
; esi = ipv4 source address
; edi = ipv4 dest address
;
; OUT: /
;
;-----------------------------------------------------------------
54,10 → 52,8
push eax ecx edx
pushw [edx + TCP_header.Checksum]
mov [edx + TCP_header.Checksum], 0
push esi edi
mov esi, edx
TCP_checksum (esp), (esp+4)
pop esi edi ; yes, swap them (we dont need dest addr)
TCP_checksum (edi), (edi+4)
pop cx ; previous checksum
cmp cx, dx
pop edx ecx esi
65,7 → 61,7
 
DEBUGF 1,"Checksum is correct\n"
 
sub ecx, esi ; update packet size
sub ecx, esi ; substract TCP header size from total segment size
jb .drop_not_locked
DEBUGF 1,"we got %u bytes of data\n", ecx
 
129,7 → 125,7
jne .socket_loop
 
mov eax, [ebx + IP_SOCKET.RemoteIP]
cmp eax, edi ; edi is source ip from packet
cmp eax, [edi] ; Ipv4 source addres
je @f
test eax, eax
jnz .socket_loop
189,7 → 185,7
test eax, eax
jz .drop
 
push [edx - sizeof.IPv4_header + IPv4_header.DestinationAddress] ;;; FIXME
push dword [edi + 4] ; Ipv4 destination addres
pop [eax + IP_SOCKET.LocalIP]
 
push [edx + TCP_header.DestinationPort]
213,7 → 209,7
;--------------------
; Process TCP options
 
cmp esi, TCP_header.DataOffset ; esi is headersize
cmp esi, TCP_header.DataOffset ; Does header contain any options?
je .no_options
 
DEBUGF 1,"Segment has options\n"
221,26 → 217,26
cmp [ebx + TCP_SOCKET.t_state], TCPS_LISTEN ; no options when in listen state
jz .not_uni_xfer ; also no header prediction
 
lea edi, [edx + sizeof.TCP_header]
lea eax, [edx + esi]
lea esi, [edx + sizeof.TCP_header]
 
.opt_loop:
cmp edi, eax
cmp esi, eax ; are we scanning outside of header?
jae .no_options
 
cmp byte [edi], TCP_OPT_EOL ; end of option list?
cmp byte [esi], TCP_OPT_EOL ; end of option list?
jz .no_options
 
cmp byte [edi], TCP_OPT_NOP ; nop ?
cmp byte [esi], TCP_OPT_NOP ; nop ?
jz .opt_nop
 
cmp byte [edi], TCP_OPT_MAXSEG
cmp byte [esi], TCP_OPT_MAXSEG
je .opt_maxseg
 
cmp byte [edi], TCP_OPT_WINDOW
cmp byte [esi], TCP_OPT_WINDOW
je .opt_window
 
cmp byte [edi], TCP_OPT_TIMESTAMP
cmp byte [esi], TCP_OPT_TIMESTAMP
je .opt_timestamp
 
jmp .no_options ; If we reach here, some unknown options were received, skip them all!
250,13 → 246,13
jmp .opt_loop
 
.opt_maxseg:
cmp byte [edi+1], 4
cmp byte [esi+1], 4
jne .no_options ; error occured, ignore all options!
 
test [edx + TCP_header.Flags], TH_SYN
jz @f
 
movzx eax, word[edi+2]
movzx eax, word[esi+2]
rol ax, 8
DEBUGF 1,"Maxseg: %u\n", ax
 
268,7 → 264,7
 
 
.opt_window:
cmp byte [edi+1], 3
cmp byte [esi+1], 3
jne .no_options
 
test [edx + TCP_header.Flags], TH_SYN
283,7 → 279,7
 
 
.opt_timestamp:
cmp byte [edi+1], 10
cmp byte [esi+1], 10
jne .no_options
 
DEBUGF 1,"Got timestamp option\n"
290,7 → 286,7
 
;;;;;
 
add edi, 10
add esi, 10
jmp .opt_loop
 
.no_options:
416,6 → 412,9
 
add [ebx + TCP_SOCKET.RCV_NXT], ecx ; Update sequence number with number of bytes we have copied
 
movzx esi, [edx + TCP_header.DataOffset]
and esi, 0xf0
shr esi, 2
add esi, edx
lea eax, [ebx + STREAM_SOCKET.rcv]
call SOCKET_ring_write ; Add the data to the socket buffer
480,7 → 479,7
 
;;; TODO: check if it's a broadcast or multicast, and drop if so
 
push [edx - sizeof.IPv4_header + IPv4_header.SourceAddress] ;;; FIXME
push dword [edi + 4] ; Ipv4 destination addres
pop [ebx + IP_SOCKET.RemoteIP]
 
push [edx + TCP_header.SourcePort]
1054,7 → 1053,7
@@:
 
mov edi, [edx + TCP_header.AckNumber]
sub edi, [ebx + TCP_SOCKET.SND_UNA] ; now we got the number of acked bytes in esi
sub edi, [ebx + TCP_SOCKET.SND_UNA] ; now we got the number of acked bytes in edi
 
;;; TODO: update stats
 
1353,12 → 1352,11
 
;; TODO: check if data is in sequence !
 
movzx eax, [edx + TCP_header.DataOffset] ;;; todo: remember this in.. edi ?
and eax, 0xf0
shr al, 2
movzx esi, [edx + TCP_header.DataOffset]
and esi, 0xf0
shr esi, 2
add esi, edx
 
lea esi, [edx + eax]
 
or [ebx + TCP_SOCKET.t_flags], TF_DELACK
add [ebx + TCP_SOCKET.RCV_NXT], ecx
 
/kernel/branches/net/network/tcp_subr.inc
311,7 → 311,9
;-------------------------
; TCP_respond.segment:
;
; IN: edx = segment ptr (a previously received segment)
; IN: ebx = ptr to driver
; edx = segment ptr (a previously received segment)
; edi = ptr to dest and src IPv4 addresses
; cl = flags
 
align 4
322,14 → 324,14
;---------------------
; Create the IP packet
 
push cx edx
mov ebx, [edx - sizeof.IPv4_header + IPv4_header.SourceAddress] ;;;; FIXME: and what if ip packet had options?!
mov eax, [edx - sizeof.IPv4_header + IPv4_header.DestinationAddress] ;;;
push cx edx ebx
mov ebx, [edi + 4]
mov eax, [edi]
mov ecx, sizeof.TCP_header
mov di , IP_PROTO_TCP shl 8 + 128
call IPv4_output
jz .error
pop esi cx
pop ebx esi cx
 
push edx eax
 
/kernel/branches/net/network/udp.inc
108,10 → 108,8
; ebx = ptr to device struct
; ecx = UDP Packet size
; edx = ptr to UDP header
; edi = ptr to ipv4 source and dest address
;
; esi = ipv4 source address
; edi = ipv4 dest address
;
; OUT: /
;
;-----------------------------------------------------------------
129,7 → 127,7
push edi
push esi
mov esi, edx
UDP_checksum (esp), (esp+4)
UDP_checksum (edi), (edi+4)
pop edi
pop esi ; we dont need it, but it is smaller then add esp, 4
pop edx
163,7 → 161,8
 
cmp [eax + IP_SOCKET.RemoteIP], 0xffffffff
je @f
cmp [eax + IP_SOCKET.RemoteIP], edi ; edi is the packets source address
mov edi, [edi + 4] ; ipv4 source address
cmp [eax + IP_SOCKET.RemoteIP], edi
jne .try_more
@@: