forked from KolibriOS/kolibrios
small updates and fixes in net branch
git-svn-id: svn://kolibrios.org@2308 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
df1f1777ac
commit
63bc53c598
@ -290,20 +290,18 @@ IPv4_input: ; TODO: implement handler for IP options
|
||||
; 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
|
||||
|
@ -134,8 +134,8 @@ macro ICMP_init {
|
||||
; 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 @@ ICMP_input:
|
||||
|
||||
; 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,14 +155,14 @@ ICMP_input:
|
||||
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?
|
||||
jne .check_sockets
|
||||
|
||||
; We well re-use the packet so we 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 @@ ICMP_input:
|
||||
|
||||
.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]
|
||||
|
@ -25,9 +25,7 @@ $Revision$
|
||||
; ebx = ptr to device struct
|
||||
; ecx = segment size
|
||||
; edx = ptr to TCP segment
|
||||
;
|
||||
; esi = ipv4 source address
|
||||
; edi = ipv4 dest address
|
||||
; edi = ptr to ipv4 source address, followed by ipv4 dest address
|
||||
;
|
||||
; OUT: /
|
||||
;
|
||||
@ -54,10 +52,8 @@ TCP_input:
|
||||
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 @@ TCP_input:
|
||||
|
||||
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 @@ TCP_input:
|
||||
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 @@ TCP_input:
|
||||
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 @@ TCP_input:
|
||||
;--------------------
|
||||
; 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 @@ TCP_input:
|
||||
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 @@ TCP_input:
|
||||
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 @@ TCP_input:
|
||||
|
||||
|
||||
.opt_window:
|
||||
cmp byte [edi+1], 3
|
||||
cmp byte [esi+1], 3
|
||||
jne .no_options
|
||||
|
||||
test [edx + TCP_header.Flags], TH_SYN
|
||||
@ -283,14 +279,14 @@ TCP_input:
|
||||
|
||||
|
||||
.opt_timestamp:
|
||||
cmp byte [edi+1], 10
|
||||
cmp byte [esi+1], 10
|
||||
jne .no_options
|
||||
|
||||
DEBUGF 1,"Got timestamp option\n"
|
||||
|
||||
;;;;;
|
||||
|
||||
add edi, 10
|
||||
add esi, 10
|
||||
jmp .opt_loop
|
||||
|
||||
.no_options:
|
||||
@ -416,6 +412,9 @@ TCP_input:
|
||||
|
||||
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 @@ align 4
|
||||
|
||||
;;; 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 @@ align 4
|
||||
@@:
|
||||
|
||||
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,11 +1352,10 @@ align 4
|
||||
|
||||
;; TODO: check if data is in sequence !
|
||||
|
||||
movzx eax, [edx + TCP_header.DataOffset] ;;; todo: remember this in.. edi ?
|
||||
and eax, 0xf0
|
||||
shr al, 2
|
||||
|
||||
lea esi, [edx + eax]
|
||||
movzx esi, [edx + TCP_header.DataOffset]
|
||||
and esi, 0xf0
|
||||
shr esi, 2
|
||||
add esi, edx
|
||||
|
||||
or [ebx + TCP_SOCKET.t_flags], TF_DELACK
|
||||
add [ebx + TCP_SOCKET.RCV_NXT], ecx
|
||||
|
@ -311,7 +311,9 @@ TCP_respond_socket:
|
||||
;-------------------------
|
||||
; 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 @@ TCP_respond_segment:
|
||||
;---------------------
|
||||
; 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
|
||||
|
||||
|
@ -108,9 +108,7 @@ macro UDP_checksum IP1, IP2 { ; esi = ptr to udp packet, ecx = packet size, des
|
||||
; ebx = ptr to device struct
|
||||
; ecx = UDP Packet size
|
||||
; edx = ptr to UDP header
|
||||
;
|
||||
; esi = ipv4 source address
|
||||
; edi = ipv4 dest address
|
||||
; edi = ptr to ipv4 source and dest address
|
||||
;
|
||||
; OUT: /
|
||||
;
|
||||
@ -129,7 +127,7 @@ UDP_input:
|
||||
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 @@ UDP_input:
|
||||
|
||||
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
|
||||
@@:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user