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 |
|