Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 2309 → Rev 2310

/kernel/branches/net/network/IPv4.inc
301,7 → 301,7
 
lea edi, [edx + IPv4_header.SourceAddress] ; make edi ptr to source and dest IPv4 address
mov al , [edx + IPv4_header.Protocol]
add edx, esi ; make edi ptr to data
add esi, edx ; make esi ptr to data
 
cmp al , IP_PROTO_TCP
je TCP_input
/kernel/branches/net/network/icmp.inc
133,7 → 133,7
; size of buffer in [esp+4]
; ebx = pointer to device struct
; ecx = ICMP Packet size
; edx = ptr to ICMP Packet data
; esi = ptr to ICMP Packet data
; edi = ptr to ipv4 source and dest address
;
; OUT: /
146,10 → 146,9
 
; First, check the checksum (altough some implementations ignore it)
 
push edx ecx
push esi ecx
push [edx + ICMP_header.Checksum]
mov [edx + ICMP_header.Checksum], 0
mov esi, edx
xor edx, edx
call checksum_1
call checksum_2
/kernel/branches/net/network/socket.inc
108,11 → 108,12
 
 
;---------
; RFC 1323
SND_SCALE db ? ; Scale factor
; RFC 1323 ; the order of next 4 elements may not change
 
SND_SCALE db ?
RCV_SCALE db ?
requested_s_scale db ?
request_r_scale db ?
requested_s_scale dd ?
 
ts_recent dd ?
ts_recent_age dd ?
/kernel/branches/net/network/tcp_input.inc
24,7 → 24,7
; [esp+4] = buffer size
; ebx = ptr to device struct
; ecx = segment size
; edx = ptr to TCP segment
; esi = ptr to TCP segment
; edi = ptr to ipv4 source address, followed by ipv4 dest address
;
; OUT: /
36,18 → 36,17
 
DEBUGF 1,"TCP_input size=%u\n", ecx
 
and [edx + TCP_header.DataOffset], 0xf0 ; Calculate TCP segment header size (throwing away unused reserved bits in TCP header)
shr [edx + TCP_header.DataOffset], 2
cmp [edx + TCP_header.DataOffset], sizeof.TCP_header ; Now see if it's at least the size of a standard TCP header
and [esi + TCP_header.DataOffset], 0xf0 ; Calculate TCP segment header size (throwing away unused reserved bits in TCP header)
shr [esi + TCP_header.DataOffset], 2
cmp [esi + TCP_header.DataOffset], sizeof.TCP_header ; Now see if it's at least the size of a standard TCP header
jb .drop_not_locked ; If not, drop the packet
 
;-------------------------------
; Now, re-calculate the checksum
 
push ecx edx
pushw [edx + TCP_header.Checksum]
mov [edx + TCP_header.Checksum], 0
mov esi, edx
push ecx esi
pushw [esi + TCP_header.Checksum]
mov [esi + TCP_header.Checksum], 0
TCP_checksum (edi), (edi+4)
pop cx ; previous checksum
cmp cx, dx
56,7 → 55,8
 
DEBUGF 1,"Checksum ok\n"
 
sub ecx, [edx + TCP_header.DataOffset] ; substract TCP header size from total segment size
movzx eax, [edx + TCP_header.DataOffset]
sub ecx, eax ; substract TCP header size from total segment size
jb .drop_not_locked ; If total segment size is less then the advertised header size, drop packet
DEBUGF 1,"we got %u bytes of data\n", ecx
 
63,7 → 63,7
;-----------------------------------------------------------------------------------------
; Check if this packet has a timestamp option (We do it here so we can process it quickly)
 
cmp [edx + TCP_header.DataOffset], sizeof.TCP_header + 12 ; Timestamp option is 12 bytes
cmp eax, sizeof.TCP_header + 12 ; Timestamp option is 12 bytes
jb .no_timestamp
je .is_ok
 
202,8 → 202,8
;--------------------
; Process TCP options
 
mov eax, [edx + TCP_header.DataOffset]
cmp eax, TCP_header.DataOffset ; Does header contain any options?
movzx eax, [edx + TCP_header.DataOffset]
cmp eax, sizeof.TCP_header ; Does header contain any options?
je .no_options
 
DEBUGF 1,"Segment has options\n"
/kernel/branches/net/network/udp.inc
17,7 → 17,7
$Revision$
 
 
struct UDP_Packet
struct UDP_header
 
SourcePort dw ?
DestinationPort dw ?
65,33 → 65,33
adc dl, [IP2+3]
adc dh, [IP2+2]
 
adc dl, cl ; byte[esi+UDP_Packet.Length+1]
adc dh, ch ; byte[esi+UDP_Packet.Length+0]
adc dl, cl ; byte[esi+UDP_header.Length+1]
adc dh, ch ; byte[esi+UDP_header.Length+0]
 
; Done with pseudoheader, now do real header
adc dl, byte[esi+UDP_Packet.SourcePort+1]
adc dh, byte[esi+UDP_Packet.SourcePort+0]
adc dl, byte[esi+UDP_header.SourcePort+1]
adc dh, byte[esi+UDP_header.SourcePort+0]
 
adc dl, byte[esi+UDP_Packet.DestinationPort+1]
adc dh, byte[esi+UDP_Packet.DestinationPort+0]
adc dl, byte[esi+UDP_header.DestinationPort+1]
adc dh, byte[esi+UDP_header.DestinationPort+0]
 
adc dl, byte[esi+UDP_Packet.Length+1]
adc dh, byte[esi+UDP_Packet.Length+0]
adc dl, byte[esi+UDP_header.Length+1]
adc dh, byte[esi+UDP_header.Length+0]
 
adc edx, 0
 
; Done with header, now do data
push esi
movzx ecx, [esi+UDP_Packet.Length]
movzx ecx, [esi+UDP_header.Length]
rol cx , 8
sub cx , sizeof.UDP_Packet
add esi, sizeof.UDP_Packet
sub cx , sizeof.UDP_header
add esi, sizeof.UDP_header
 
call checksum_1
call checksum_2
pop esi
 
add [esi+UDP_Packet.Checksum], dx ; this final instruction will set or clear ZF :)
add [esi+UDP_header.Checksum], dx ; this final instruction will set or clear ZF :)
 
}
 
107,7 → 107,7
; [esp+4] = size of buffer
; ebx = ptr to device struct
; ecx = UDP Packet size
; edx = ptr to UDP header
; esi = ptr to UDP header
; edi = ptr to ipv4 source and dest address
;
; OUT: /
118,18 → 118,14
 
DEBUGF 1,"UDP_input, size:%u\n", ecx
 
; First validate, checksum:
neg [edx+UDP_Packet.Checksum] ; substract chechksum from 0
; First validate, checksum
 
neg [esi + UDP_header.Checksum] ; substract checksum from 0
jz .no_checksum ; if checksum is zero, it is considered valid and we continue processing
; otherwise, we will re-calculate the checksum and add it to this value, thus creating 0 when it is correct
 
push edx
push edi
push esi
mov esi, edx
UDP_checksum (edi), (edi+4)
pop edi
pop esi ; we dont need it, but it is smaller then add esp, 4
pop edx
jnz .checksum_mismatch
 
136,22 → 132,32
.no_checksum:
DEBUGF 1,"UDP Checksum is correct\n"
 
; Convert port numbers to intel format
 
rol [edx + UDP_header.DestinationPort], 8
rol [edx + UDP_header.SourcePort], 8
rol [edx + UDP_header.Length], 8
 
; Look for a socket where
; IP Packet UDP Destination Port = local Port
; IP Packet SA = Remote IP
 
mov si, [edx + UDP_header.DestinationPort]
mov cx, [edx + UDP_header.SourcePort]
mov edi, [edi + 4] ; ipv4 source address
mov eax, net_sockets
.try_more:
mov si , [edx + UDP_Packet.DestinationPort] ; get the local port from the IP Packet's UDP header
rol si , 8
 
.next_socket:
mov eax, [eax + SOCKET.NextPtr]
or eax, eax
jz .dump
 
cmp [eax + SOCKET.Domain], AF_INET4
jne .next_socket
 
cmp [eax + SOCKET.Protocol], IP_PROTO_UDP
jne .next_socket
 
cmp [eax + UDP_SOCKET.LocalPort], si
jne .next_socket
 
161,17 → 167,14
 
cmp [eax + IP_SOCKET.RemoteIP], 0xffffffff
je @f
mov edi, [edi + 4] ; ipv4 source address
cmp [eax + IP_SOCKET.RemoteIP], edi
jne .try_more
jne .next_socket
@@:
 
cmp [eax + UDP_SOCKET.firstpacket], 0
jz .updateport
 
mov si, [edx + UDP_Packet.SourcePort]
rol si, 8
cmp [eax + UDP_SOCKET.RemotePort], si
cmp [eax + UDP_SOCKET.RemotePort], cx
jne .dump
 
push ebx
182,10 → 185,9
.updatesock:
inc [UDP_PACKETS_RX]
DEBUGF 1,"Found valid UDP packet for socket %x\n", eax
lea esi, [edx + sizeof.UDP_Packet]
movzx ecx, [edx + UDP_Packet.Length]
rol cx , 8
sub cx , sizeof.UDP_Packet
lea esi, [edx + sizeof.UDP_header]
movzx ecx, [edx + UDP_header.Length]
sub ecx, sizeof.UDP_header
 
jmp SOCKET_input
 
195,8 → 197,7
call wait_mutex
pop ebx
 
mov si, [edx + UDP_Packet.SourcePort]
rol si, 8
mov si, [edx + UDP_header.SourcePort]
DEBUGF 1,"Changing remote port to: %u\n", si
mov [eax + UDP_SOCKET.RemotePort], si
inc [eax + UDP_SOCKET.firstpacket]
246,7 → 247,7
 
mov di, IP_PROTO_UDP shl 8 + 128
sub esp, 8 ; Data ptr and data size will be placed here
add ecx, sizeof.UDP_Packet
add ecx, sizeof.UDP_header
 
;;; TODO: fragment id
push edx esi
256,13 → 257,13
mov [esp + 8], eax ; pointer to buffer start
mov [esp + 8 + 4], edx ; buffer size
 
mov [edi + UDP_Packet.Length], cx
rol [edi + UDP_Packet.Length], 8
mov [edi + UDP_header.Length], cx
rol [edi + UDP_header.Length], 8
 
pop esi
push edi ecx
sub ecx, sizeof.UDP_Packet
add edi, sizeof.UDP_Packet
sub ecx, sizeof.UDP_header
add edi, sizeof.UDP_header
shr ecx, 2
rep movsd
mov ecx, [esp]
270,11 → 271,11
rep movsb
pop ecx edi
 
pop dword [edi + UDP_Packet.SourcePort]
pop dword [edi + UDP_header.SourcePort]
 
; Checksum
mov esi, edi
mov [edi + UDP_Packet.Checksum], 0
mov [edi + UDP_header.Checksum], 0
UDP_checksum (edi-4), (edi-8) ; TODO: fix this, IPv4 packet could have options..
 
inc [UDP_PACKETS_TX]