forked from KolibriOS/kolibrios
more small updates and fixes in net branch
git-svn-id: svn://kolibrios.org@2310 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
29c0d093db
commit
3ce07b4be0
@ -301,7 +301,7 @@ IPv4_input: ; TODO: implement handler for IP options
|
|||||||
|
|
||||||
lea edi, [edx + IPv4_header.SourceAddress] ; make edi ptr to source and dest IPv4 address
|
lea edi, [edx + IPv4_header.SourceAddress] ; make edi ptr to source and dest IPv4 address
|
||||||
mov al , [edx + IPv4_header.Protocol]
|
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
|
cmp al , IP_PROTO_TCP
|
||||||
je TCP_input
|
je TCP_input
|
||||||
|
@ -133,7 +133,7 @@ macro ICMP_init {
|
|||||||
; size of buffer in [esp+4]
|
; size of buffer in [esp+4]
|
||||||
; ebx = pointer to device struct
|
; ebx = pointer to device struct
|
||||||
; ecx = ICMP Packet size
|
; ecx = ICMP Packet size
|
||||||
; edx = ptr to ICMP Packet data
|
; esi = ptr to ICMP Packet data
|
||||||
; edi = ptr to ipv4 source and dest address
|
; edi = ptr to ipv4 source and dest address
|
||||||
;
|
;
|
||||||
; OUT: /
|
; OUT: /
|
||||||
@ -146,10 +146,9 @@ ICMP_input:
|
|||||||
|
|
||||||
; First, check the checksum (altough some implementations ignore it)
|
; First, check the checksum (altough some implementations ignore it)
|
||||||
|
|
||||||
push edx ecx
|
push esi ecx
|
||||||
push [edx + ICMP_header.Checksum]
|
push [edx + ICMP_header.Checksum]
|
||||||
mov [edx + ICMP_header.Checksum], 0
|
mov [edx + ICMP_header.Checksum], 0
|
||||||
mov esi, edx
|
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
call checksum_1
|
call checksum_1
|
||||||
call checksum_2
|
call checksum_2
|
||||||
|
@ -108,11 +108,12 @@ struct TCP_SOCKET IP_SOCKET
|
|||||||
|
|
||||||
|
|
||||||
;---------
|
;---------
|
||||||
; RFC 1323
|
; RFC 1323 ; the order of next 4 elements may not change
|
||||||
SND_SCALE db ? ; Scale factor
|
|
||||||
|
SND_SCALE db ?
|
||||||
RCV_SCALE db ?
|
RCV_SCALE db ?
|
||||||
|
requested_s_scale db ?
|
||||||
request_r_scale db ?
|
request_r_scale db ?
|
||||||
requested_s_scale dd ?
|
|
||||||
|
|
||||||
ts_recent dd ?
|
ts_recent dd ?
|
||||||
ts_recent_age dd ?
|
ts_recent_age dd ?
|
||||||
|
@ -24,7 +24,7 @@ $Revision$
|
|||||||
; [esp+4] = buffer size
|
; [esp+4] = buffer size
|
||||||
; ebx = ptr to device struct
|
; ebx = ptr to device struct
|
||||||
; ecx = segment size
|
; ecx = segment size
|
||||||
; edx = ptr to TCP segment
|
; esi = ptr to TCP segment
|
||||||
; edi = ptr to ipv4 source address, followed by ipv4 dest address
|
; edi = ptr to ipv4 source address, followed by ipv4 dest address
|
||||||
;
|
;
|
||||||
; OUT: /
|
; OUT: /
|
||||||
@ -36,18 +36,17 @@ TCP_input:
|
|||||||
|
|
||||||
DEBUGF 1,"TCP_input size=%u\n", ecx
|
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)
|
and [esi + TCP_header.DataOffset], 0xf0 ; Calculate TCP segment header size (throwing away unused reserved bits in TCP header)
|
||||||
shr [edx + TCP_header.DataOffset], 2
|
shr [esi + 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
|
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
|
jb .drop_not_locked ; If not, drop the packet
|
||||||
|
|
||||||
;-------------------------------
|
;-------------------------------
|
||||||
; Now, re-calculate the checksum
|
; Now, re-calculate the checksum
|
||||||
|
|
||||||
push ecx edx
|
push ecx esi
|
||||||
pushw [edx + TCP_header.Checksum]
|
pushw [esi + TCP_header.Checksum]
|
||||||
mov [edx + TCP_header.Checksum], 0
|
mov [esi + TCP_header.Checksum], 0
|
||||||
mov esi, edx
|
|
||||||
TCP_checksum (edi), (edi+4)
|
TCP_checksum (edi), (edi+4)
|
||||||
pop cx ; previous checksum
|
pop cx ; previous checksum
|
||||||
cmp cx, dx
|
cmp cx, dx
|
||||||
@ -56,14 +55,15 @@ TCP_input:
|
|||||||
|
|
||||||
DEBUGF 1,"Checksum ok\n"
|
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
|
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
|
DEBUGF 1,"we got %u bytes of data\n", ecx
|
||||||
|
|
||||||
;-----------------------------------------------------------------------------------------
|
;-----------------------------------------------------------------------------------------
|
||||||
; Check if this packet has a timestamp option (We do it here so we can process it quickly)
|
; 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
|
jb .no_timestamp
|
||||||
je .is_ok
|
je .is_ok
|
||||||
|
|
||||||
@ -202,8 +202,8 @@ TCP_input:
|
|||||||
;--------------------
|
;--------------------
|
||||||
; Process TCP options
|
; Process TCP options
|
||||||
|
|
||||||
mov eax, [edx + TCP_header.DataOffset]
|
movzx eax, [edx + TCP_header.DataOffset]
|
||||||
cmp eax, TCP_header.DataOffset ; Does header contain any options?
|
cmp eax, sizeof.TCP_header ; Does header contain any options?
|
||||||
je .no_options
|
je .no_options
|
||||||
|
|
||||||
DEBUGF 1,"Segment has options\n"
|
DEBUGF 1,"Segment has options\n"
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
$Revision$
|
$Revision$
|
||||||
|
|
||||||
|
|
||||||
struct UDP_Packet
|
struct UDP_header
|
||||||
|
|
||||||
SourcePort dw ?
|
SourcePort dw ?
|
||||||
DestinationPort dw ?
|
DestinationPort dw ?
|
||||||
@ -65,33 +65,33 @@ macro UDP_checksum IP1, IP2 { ; esi = ptr to udp packet, ecx = packet size
|
|||||||
adc dl, [IP2+3]
|
adc dl, [IP2+3]
|
||||||
adc dh, [IP2+2]
|
adc dh, [IP2+2]
|
||||||
|
|
||||||
adc dl, cl ; byte[esi+UDP_Packet.Length+1]
|
adc dl, cl ; byte[esi+UDP_header.Length+1]
|
||||||
adc dh, ch ; byte[esi+UDP_Packet.Length+0]
|
adc dh, ch ; byte[esi+UDP_header.Length+0]
|
||||||
|
|
||||||
; Done with pseudoheader, now do real header
|
; Done with pseudoheader, now do real header
|
||||||
adc dl, byte[esi+UDP_Packet.SourcePort+1]
|
adc dl, byte[esi+UDP_header.SourcePort+1]
|
||||||
adc dh, byte[esi+UDP_Packet.SourcePort+0]
|
adc dh, byte[esi+UDP_header.SourcePort+0]
|
||||||
|
|
||||||
adc dl, byte[esi+UDP_Packet.DestinationPort+1]
|
adc dl, byte[esi+UDP_header.DestinationPort+1]
|
||||||
adc dh, byte[esi+UDP_Packet.DestinationPort+0]
|
adc dh, byte[esi+UDP_header.DestinationPort+0]
|
||||||
|
|
||||||
adc dl, byte[esi+UDP_Packet.Length+1]
|
adc dl, byte[esi+UDP_header.Length+1]
|
||||||
adc dh, byte[esi+UDP_Packet.Length+0]
|
adc dh, byte[esi+UDP_header.Length+0]
|
||||||
|
|
||||||
adc edx, 0
|
adc edx, 0
|
||||||
|
|
||||||
; Done with header, now do data
|
; Done with header, now do data
|
||||||
push esi
|
push esi
|
||||||
movzx ecx, [esi+UDP_Packet.Length]
|
movzx ecx, [esi+UDP_header.Length]
|
||||||
rol cx , 8
|
rol cx , 8
|
||||||
sub cx , sizeof.UDP_Packet
|
sub cx , sizeof.UDP_header
|
||||||
add esi, sizeof.UDP_Packet
|
add esi, sizeof.UDP_header
|
||||||
|
|
||||||
call checksum_1
|
call checksum_1
|
||||||
call checksum_2
|
call checksum_2
|
||||||
pop esi
|
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 @@ macro UDP_checksum IP1, IP2 { ; esi = ptr to udp packet, ecx = packet size
|
|||||||
; [esp+4] = size of buffer
|
; [esp+4] = size of buffer
|
||||||
; ebx = ptr to device struct
|
; ebx = ptr to device struct
|
||||||
; ecx = UDP Packet size
|
; ecx = UDP Packet size
|
||||||
; edx = ptr to UDP header
|
; esi = ptr to UDP header
|
||||||
; edi = ptr to ipv4 source and dest address
|
; edi = ptr to ipv4 source and dest address
|
||||||
;
|
;
|
||||||
; OUT: /
|
; OUT: /
|
||||||
@ -118,40 +118,46 @@ UDP_input:
|
|||||||
|
|
||||||
DEBUGF 1,"UDP_input, size:%u\n", ecx
|
DEBUGF 1,"UDP_input, size:%u\n", ecx
|
||||||
|
|
||||||
; First validate, checksum:
|
; First validate, checksum
|
||||||
neg [edx+UDP_Packet.Checksum] ; substract chechksum from 0
|
|
||||||
|
neg [esi + UDP_header.Checksum] ; substract checksum from 0
|
||||||
jz .no_checksum ; if checksum is zero, it is considered valid and we continue processing
|
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
|
; 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
|
push esi
|
||||||
mov esi, edx
|
|
||||||
UDP_checksum (edi), (edi+4)
|
UDP_checksum (edi), (edi+4)
|
||||||
pop edi
|
|
||||||
pop esi ; we dont need it, but it is smaller then add esp, 4
|
|
||||||
pop edx
|
pop edx
|
||||||
jnz .checksum_mismatch
|
jnz .checksum_mismatch
|
||||||
|
|
||||||
.no_checksum:
|
.no_checksum:
|
||||||
DEBUGF 1,"UDP Checksum is correct\n"
|
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
|
; Look for a socket where
|
||||||
; IP Packet UDP Destination Port = local Port
|
; IP Packet UDP Destination Port = local Port
|
||||||
; IP Packet SA = Remote IP
|
; 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
|
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:
|
.next_socket:
|
||||||
mov eax, [eax + SOCKET.NextPtr]
|
mov eax, [eax + SOCKET.NextPtr]
|
||||||
or eax, eax
|
or eax, eax
|
||||||
jz .dump
|
jz .dump
|
||||||
|
|
||||||
cmp [eax + SOCKET.Domain], AF_INET4
|
cmp [eax + SOCKET.Domain], AF_INET4
|
||||||
jne .next_socket
|
jne .next_socket
|
||||||
|
|
||||||
cmp [eax + SOCKET.Protocol], IP_PROTO_UDP
|
cmp [eax + SOCKET.Protocol], IP_PROTO_UDP
|
||||||
jne .next_socket
|
jne .next_socket
|
||||||
|
|
||||||
cmp [eax + UDP_SOCKET.LocalPort], si
|
cmp [eax + UDP_SOCKET.LocalPort], si
|
||||||
jne .next_socket
|
jne .next_socket
|
||||||
|
|
||||||
@ -161,17 +167,14 @@ UDP_input:
|
|||||||
|
|
||||||
cmp [eax + IP_SOCKET.RemoteIP], 0xffffffff
|
cmp [eax + IP_SOCKET.RemoteIP], 0xffffffff
|
||||||
je @f
|
je @f
|
||||||
mov edi, [edi + 4] ; ipv4 source address
|
|
||||||
cmp [eax + IP_SOCKET.RemoteIP], edi
|
cmp [eax + IP_SOCKET.RemoteIP], edi
|
||||||
jne .try_more
|
jne .next_socket
|
||||||
@@:
|
@@:
|
||||||
|
|
||||||
cmp [eax + UDP_SOCKET.firstpacket], 0
|
cmp [eax + UDP_SOCKET.firstpacket], 0
|
||||||
jz .updateport
|
jz .updateport
|
||||||
|
|
||||||
mov si, [edx + UDP_Packet.SourcePort]
|
cmp [eax + UDP_SOCKET.RemotePort], cx
|
||||||
rol si, 8
|
|
||||||
cmp [eax + UDP_SOCKET.RemotePort], si
|
|
||||||
jne .dump
|
jne .dump
|
||||||
|
|
||||||
push ebx
|
push ebx
|
||||||
@ -182,10 +185,9 @@ UDP_input:
|
|||||||
.updatesock:
|
.updatesock:
|
||||||
inc [UDP_PACKETS_RX]
|
inc [UDP_PACKETS_RX]
|
||||||
DEBUGF 1,"Found valid UDP packet for socket %x\n", eax
|
DEBUGF 1,"Found valid UDP packet for socket %x\n", eax
|
||||||
lea esi, [edx + sizeof.UDP_Packet]
|
lea esi, [edx + sizeof.UDP_header]
|
||||||
movzx ecx, [edx + UDP_Packet.Length]
|
movzx ecx, [edx + UDP_header.Length]
|
||||||
rol cx , 8
|
sub ecx, sizeof.UDP_header
|
||||||
sub cx , sizeof.UDP_Packet
|
|
||||||
|
|
||||||
jmp SOCKET_input
|
jmp SOCKET_input
|
||||||
|
|
||||||
@ -195,8 +197,7 @@ UDP_input:
|
|||||||
call wait_mutex
|
call wait_mutex
|
||||||
pop ebx
|
pop ebx
|
||||||
|
|
||||||
mov si, [edx + UDP_Packet.SourcePort]
|
mov si, [edx + UDP_header.SourcePort]
|
||||||
rol si, 8
|
|
||||||
DEBUGF 1,"Changing remote port to: %u\n", si
|
DEBUGF 1,"Changing remote port to: %u\n", si
|
||||||
mov [eax + UDP_SOCKET.RemotePort], si
|
mov [eax + UDP_SOCKET.RemotePort], si
|
||||||
inc [eax + UDP_SOCKET.firstpacket]
|
inc [eax + UDP_SOCKET.firstpacket]
|
||||||
@ -246,7 +247,7 @@ UDP_output:
|
|||||||
|
|
||||||
mov di, IP_PROTO_UDP shl 8 + 128
|
mov di, IP_PROTO_UDP shl 8 + 128
|
||||||
sub esp, 8 ; Data ptr and data size will be placed here
|
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
|
;;; TODO: fragment id
|
||||||
push edx esi
|
push edx esi
|
||||||
@ -256,13 +257,13 @@ UDP_output:
|
|||||||
mov [esp + 8], eax ; pointer to buffer start
|
mov [esp + 8], eax ; pointer to buffer start
|
||||||
mov [esp + 8 + 4], edx ; buffer size
|
mov [esp + 8 + 4], edx ; buffer size
|
||||||
|
|
||||||
mov [edi + UDP_Packet.Length], cx
|
mov [edi + UDP_header.Length], cx
|
||||||
rol [edi + UDP_Packet.Length], 8
|
rol [edi + UDP_header.Length], 8
|
||||||
|
|
||||||
pop esi
|
pop esi
|
||||||
push edi ecx
|
push edi ecx
|
||||||
sub ecx, sizeof.UDP_Packet
|
sub ecx, sizeof.UDP_header
|
||||||
add edi, sizeof.UDP_Packet
|
add edi, sizeof.UDP_header
|
||||||
shr ecx, 2
|
shr ecx, 2
|
||||||
rep movsd
|
rep movsd
|
||||||
mov ecx, [esp]
|
mov ecx, [esp]
|
||||||
@ -270,11 +271,11 @@ UDP_output:
|
|||||||
rep movsb
|
rep movsb
|
||||||
pop ecx edi
|
pop ecx edi
|
||||||
|
|
||||||
pop dword [edi + UDP_Packet.SourcePort]
|
pop dword [edi + UDP_header.SourcePort]
|
||||||
|
|
||||||
; Checksum
|
; Checksum
|
||||||
mov esi, edi
|
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..
|
UDP_checksum (edi-4), (edi-8) ; TODO: fix this, IPv4 packet could have options..
|
||||||
|
|
||||||
inc [UDP_PACKETS_TX]
|
inc [UDP_PACKETS_TX]
|
||||||
|
Loading…
Reference in New Issue
Block a user