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
|
||||
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
|
||||
|
@ -133,7 +133,7 @@ macro ICMP_init {
|
||||
; 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 @@ ICMP_input:
|
||||
|
||||
; 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
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -24,7 +24,7 @@ $Revision$
|
||||
; [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 @@ TCP_input:
|
||||
|
||||
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,14 +55,15 @@ TCP_input:
|
||||
|
||||
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
|
||||
|
||||
;-----------------------------------------------------------------------------------------
|
||||
; 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 @@ TCP_input:
|
||||
;--------------------
|
||||
; 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"
|
||||
|
@ -17,7 +17,7 @@
|
||||
$Revision$
|
||||
|
||||
|
||||
struct UDP_Packet
|
||||
struct UDP_header
|
||||
|
||||
SourcePort 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 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 @@ macro UDP_checksum IP1, IP2 { ; esi = ptr to udp packet, ecx = packet size
|
||||
; [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,40 +118,46 @@ UDP_input:
|
||||
|
||||
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
|
||||
|
||||
.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 @@ UDP_input:
|
||||
|
||||
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 @@ UDP_input:
|
||||
.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 @@ UDP_input:
|
||||
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 @@ UDP_output:
|
||||
|
||||
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 @@ UDP_output:
|
||||
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 @@ UDP_output:
|
||||
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]
|
||||
|
Loading…
Reference in New Issue
Block a user