Rev 2308 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2308 | Rev 2309 | ||
---|---|---|---|
Line 12... | Line 12... | ||
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
13 | ;; Version 2, June 1991 ;; |
13 | ;; Version 2, June 1991 ;; |
14 | ;; ;; |
14 | ;; ;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 16... | Line 16... | ||
16 | 16 | ||
Line 17... | Line 17... | ||
17 | $Revision: 2308 $ |
17 | $Revision: 2309 $ |
18 | 18 | ||
19 | ;----------------------------------------------------------------- |
19 | ;----------------------------------------------------------------- |
20 | ; |
20 | ; |
Line 32... | Line 32... | ||
32 | ;----------------------------------------------------------------- |
32 | ;----------------------------------------------------------------- |
Line 33... | Line 33... | ||
33 | 33 | ||
34 | align 4 |
34 | align 4 |
Line 35... | Line 35... | ||
35 | TCP_input: |
35 | TCP_input: |
36 | - | ||
Line -... | Line 36... | ||
- | 36 | ||
37 | DEBUGF 1,"TCP_input size=%u ", ecx |
37 | DEBUGF 1,"TCP_input size=%u\n", ecx |
38 | ; Offset must be greater than or equal to the size of the standard TCP header (20) and less than or equal to the TCP length. |
- | |
39 | - | ||
40 | movzx eax, [edx + TCP_header.DataOffset] |
- | |
41 | and eax, 0xf0 |
- | |
42 | shr al, 2 |
- | |
43 | 38 | ||
44 | DEBUGF 1,"headersize=%u\n", eax |
39 | and [edx + TCP_header.DataOffset], 0xf0 ; Calculate TCP segment header size (throwing away unused reserved bits in TCP header) |
Line 45... | Line 40... | ||
45 | 40 | shr [edx + TCP_header.DataOffset], 2 |
|
46 | cmp eax, TCP_header.DataOffset |
41 | cmp [edx + TCP_header.DataOffset], sizeof.TCP_header ; Now see if it's at least the size of a standard TCP header |
Line 47... | Line 42... | ||
47 | jb .drop_not_locked |
42 | jb .drop_not_locked ; If not, drop the packet |
48 | 43 | ||
49 | ;------------------------------- |
44 | ;------------------------------- |
50 | ; Now, re-calculate the checksum |
45 | ; Now, re-calculate the checksum |
51 | 46 | ||
52 | push eax ecx edx |
47 | push ecx edx |
53 | pushw [edx + TCP_header.Checksum] |
48 | pushw [edx + TCP_header.Checksum] |
54 | mov [edx + TCP_header.Checksum], 0 |
49 | mov [edx + TCP_header.Checksum], 0 |
55 | mov esi, edx |
50 | mov esi, edx |
Line 56... | Line 51... | ||
56 | TCP_checksum (edi), (edi+4) |
51 | TCP_checksum (edi), (edi+4) |
Line 57... | Line 52... | ||
57 | pop cx ; previous checksum |
52 | pop cx ; previous checksum |
58 | cmp cx, dx |
53 | cmp cx, dx |
59 | pop edx ecx esi |
54 | pop edx ecx |
Line 60... | Line 55... | ||
60 | jnz .drop_not_locked |
55 | jnz .drop_not_locked |
61 | 56 | ||
Line 62... | Line 57... | ||
62 | DEBUGF 1,"Checksum is correct\n" |
57 | DEBUGF 1,"Checksum ok\n" |
63 | 58 | ||
64 | sub ecx, esi ; substract TCP header size from total segment size |
59 | sub ecx, [edx + TCP_header.DataOffset] ; substract TCP header size from total segment size |
Line 65... | Line 60... | ||
65 | jb .drop_not_locked |
60 | jb .drop_not_locked ; If total segment size is less then the advertised header size, drop packet |
66 | DEBUGF 1,"we got %u bytes of data\n", ecx |
61 | DEBUGF 1,"we got %u bytes of data\n", ecx |
Line 106... | Line 101... | ||
106 | ; IP Packet TCP Destination Port = local Port |
101 | ; IP Packet TCP Destination Port = local Port |
107 | ; (IP Packet SenderAddress = Remote IP) OR (Remote IP = 0) |
102 | ; (IP Packet SenderAddress = Remote IP) OR (Remote IP = 0) |
108 | ; (IP Packet TCP Source Port = remote Port) OR (remote Port = 0) |
103 | ; (IP Packet TCP Source Port = remote Port) OR (remote Port = 0) |
Line 109... | Line 104... | ||
109 | 104 | ||
- | 105 | mov ebx, net_sockets |
|
Line 110... | Line 106... | ||
110 | mov ebx, net_sockets |
106 | mov si, [edx + TCP_header.DestinationPort] |
111 | 107 | ||
112 | .socket_loop: |
108 | .socket_loop: |
113 | mov ebx, [ebx + SOCKET.NextPtr] |
109 | mov ebx, [ebx + SOCKET.NextPtr] |
Line 118... | Line 114... | ||
118 | jne .socket_loop |
114 | jne .socket_loop |
Line 119... | Line 115... | ||
119 | 115 | ||
120 | cmp [ebx + SOCKET.Protocol], IP_PROTO_TCP |
116 | cmp [ebx + SOCKET.Protocol], IP_PROTO_TCP |
Line 121... | Line -... | ||
121 | jne .socket_loop |
- | |
122 | 117 | jne .socket_loop |
|
123 | mov ax, [edx + TCP_header.DestinationPort] |
118 | |
Line 124... | Line 119... | ||
124 | cmp [ebx + TCP_SOCKET.LocalPort], ax |
119 | cmp [ebx + TCP_SOCKET.LocalPort], si |
125 | jne .socket_loop |
120 | jne .socket_loop |
126 | 121 | ||
Line 134... | Line 129... | ||
134 | mov ax, [ebx + TCP_SOCKET.RemotePort] |
129 | mov ax, [ebx + TCP_SOCKET.RemotePort] |
135 | cmp [edx + TCP_header.SourcePort] , ax |
130 | cmp [edx + TCP_header.SourcePort] , ax |
136 | je .found_socket |
131 | je .found_socket |
137 | test ax, ax |
132 | test ax, ax |
138 | jnz .socket_loop |
133 | jnz .socket_loop |
139 | .found_socket: |
134 | .found_socket: ; ebx now contains the socketpointer |
140 | DEBUGF 1,"Socket ptr: %x\n", ebx |
135 | DEBUGF 1,"Socket ptr: %x\n", ebx |
Line 141... | Line -... | ||
141 | - | ||
Line 142... | Line 136... | ||
142 | ; ebx now contains the pointer to the socket |
136 | |
143 | 137 | ||
Line 144... | Line 138... | ||
144 | ;---------------------------- |
138 | ;---------------------------- |
Line 156... | Line 150... | ||
156 | add ebx, SOCKET.lock |
150 | add ebx, SOCKET.lock |
157 | DEBUGF 1,"lock: %x\n", [ebx] |
151 | DEBUGF 1,"lock: %x\n", [ebx] |
158 | call wait_mutex |
152 | call wait_mutex |
159 | sub ebx, SOCKET.lock |
153 | sub ebx, SOCKET.lock |
Line 160... | Line -... | ||
160 | - | ||
161 | 154 | ||
Line 162... | Line 155... | ||
162 | DEBUGF 1,"Socket locked\n" |
155 | DEBUGF 1,"Socket locked\n" |
163 | 156 | ||
Line 207... | Line 200... | ||
207 | mov [ebx + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval |
200 | mov [ebx + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval |
Line 208... | Line 201... | ||
208 | 201 | ||
209 | ;-------------------- |
202 | ;-------------------- |
Line -... | Line 203... | ||
- | 203 | ; Process TCP options |
|
210 | ; Process TCP options |
204 | |
211 | 205 | mov eax, [edx + TCP_header.DataOffset] |
|
Line 212... | Line 206... | ||
212 | cmp esi, TCP_header.DataOffset ; Does header contain any options? |
206 | cmp eax, TCP_header.DataOffset ; Does header contain any options? |
Line 213... | Line 207... | ||
213 | je .no_options |
207 | je .no_options |
214 | 208 | ||
Line 215... | Line 209... | ||
215 | DEBUGF 1,"Segment has options\n" |
209 | DEBUGF 1,"Segment has options\n" |
216 | 210 | ||
Line 217... | Line 211... | ||
217 | cmp [ebx + TCP_SOCKET.t_state], TCPS_LISTEN ; no options when in listen state |
211 | cmp [ebx + TCP_SOCKET.t_state], TCPS_LISTEN ; no options when in listen state |
218 | jz .not_uni_xfer ; also no header prediction |
212 | jz .not_uni_xfer ; also no header prediction |
219 | 213 | ||
Line 411... | Line 405... | ||
411 | DEBUGF 1,"header prediction: we are receiver\nreceiving %u bytes of data\n", ecx |
405 | DEBUGF 1,"header prediction: we are receiver\nreceiving %u bytes of data\n", ecx |
Line 412... | Line 406... | ||
412 | 406 | ||
Line 413... | Line 407... | ||
413 | add [ebx + TCP_SOCKET.RCV_NXT], ecx ; Update sequence number with number of bytes we have copied |
407 | add [ebx + TCP_SOCKET.RCV_NXT], ecx ; Update sequence number with number of bytes we have copied |
414 | - | ||
415 | movzx esi, [edx + TCP_header.DataOffset] |
- | |
416 | and esi, 0xf0 |
408 | |
417 | shr esi, 2 |
409 | movzx esi, [edx + TCP_header.DataOffset] |
418 | add esi, edx |
410 | add esi, edx |
Line 419... | Line 411... | ||
419 | lea eax, [ebx + STREAM_SOCKET.rcv] |
411 | lea eax, [ebx + STREAM_SOCKET.rcv] |
Line 907... | Line 899... | ||
907 | cmp [ebx + TCP_SOCKET.SND_UNA], eax |
899 | cmp [ebx + TCP_SOCKET.SND_UNA], eax |
908 | ja .drop_with_reset |
900 | ja .drop_with_reset |
909 | cmp eax, [ebx + TCP_SOCKET.SND_MAX] |
901 | cmp eax, [ebx + TCP_SOCKET.SND_MAX] |
910 | ja .drop_with_reset |
902 | ja .drop_with_reset |
Line 911... | Line 903... | ||
911 | 903 | ||
- | 904 | ;;; TODO: update stats |
|
912 | ;;; update stats |
905 | |
913 | mov eax, ebx |
906 | mov eax, ebx |
914 | call SOCKET_is_connected |
907 | call SOCKET_is_connected |
Line 915... | Line 908... | ||
915 | mov [ebx + TCP_SOCKET.t_state], TCPS_ESTABLISHED |
908 | mov [ebx + TCP_SOCKET.t_state], TCPS_ESTABLISHED |
Line 919... | Line 912... | ||
919 | test [ebx + TCP_SOCKET.t_flags], TF_RCVD_SCALE |
912 | test [ebx + TCP_SOCKET.t_flags], TF_RCVD_SCALE |
920 | jz @f |
913 | jz @f |
921 | test [ebx + TCP_SOCKET.t_flags], TF_REQ_SCALE |
914 | test [ebx + TCP_SOCKET.t_flags], TF_REQ_SCALE |
922 | jz @f |
915 | jz @f |
Line -... | Line 916... | ||
- | 916 | ||
923 | 917 | push word [ebx + TCP_SOCKET.requested_s_scale] ; Set send and receive scale factors to the received values |
|
924 | ;;; 810-811 |
- | |
925 | 918 | pop word [ebx + TCP_SOCKET.SND_SCALE] |
|
Line 926... | Line 919... | ||
926 | @@: |
919 | @@: |
Line 927... | Line 920... | ||
927 | 920 | ||
928 | ;;; 813 ? |
921 | ;;; TODO: copy the data (if any) into the socket |
929 | 922 | ||
930 | mov eax, [edx + TCP_header.SequenceNumber] |
923 | mov eax, [edx + TCP_header.SequenceNumber] |
Line 947... | Line 940... | ||
947 | cmp eax, [ebx + TCP_SOCKET.SND_WND] |
940 | cmp eax, [ebx + TCP_SOCKET.SND_WND] |
948 | jne .reset_dupacks |
941 | jne .reset_dupacks |
Line 949... | Line 942... | ||
949 | 942 | ||
Line 950... | Line 943... | ||
950 | DEBUGF 1,"Processing a duplicate ACK..\n" |
943 | DEBUGF 1,"Processing a duplicate ACK..\n" |
951 | 944 | ||
Line 952... | Line 945... | ||
952 | cmp [ebx + TCP_SOCKET.timer_retransmission], 10000 ;;;; |
945 | cmp [ebx + TCP_SOCKET.timer_retransmission], 10000 ;;;; FIXME |
953 | ja @f |
946 | ja @f |
954 | 947 | ||
Line 1244... | Line 1237... | ||
1244 | 1237 | ||
1245 | mov eax, [ebx + TCP_SOCKET.SND_WL2] |
1238 | mov eax, [ebx + TCP_SOCKET.SND_WL2] |
1246 | cmp eax, [edx + TCP_header.AckNumber] |
1239 | cmp eax, [edx + TCP_header.AckNumber] |
Line 1247... | Line 1240... | ||
1247 | jne .no_window_update |
1240 | jne .no_window_update |
1248 | 1241 | ||
1249 | movzx eax, [edx + TCP_header.Window] |
1242 | mov eax, dword [edx + TCP_header.Window] |
Line 1250... | Line 1243... | ||
1250 | cmp eax, [ebx + TCP_SOCKET.SND_WND] |
1243 | cmp eax, [ebx + TCP_SOCKET.SND_WND] |
Line 1351... | Line 1344... | ||
1351 | DEBUGF 1,"Processing data in segment\n" |
1344 | DEBUGF 1,"Processing data in segment\n" |
Line 1352... | Line 1345... | ||
1352 | 1345 | ||
Line 1353... | Line 1346... | ||
1353 | ;; TODO: check if data is in sequence ! |
1346 | ;; TODO: check if data is in sequence ! |
1354 | - | ||
1355 | movzx esi, [edx + TCP_header.DataOffset] |
- | |
1356 | and esi, 0xf0 |
1347 | |
Line 1357... | Line 1348... | ||
1357 | shr esi, 2 |
1348 | movzx esi, [edx + TCP_header.DataOffset] |
1358 | add esi, edx |
1349 | add esi, edx |