Rev 5984 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5984 | Rev 6078 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;; Part of the TCP/IP network stack for KolibriOS ;; |
6 | ;; Part of the TCP/IP network stack for KolibriOS ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; Written by hidnplayr@kolibrios.org ;; |
8 | ;; Written by hidnplayr@kolibrios.org ;; |
9 | ;; ;; |
9 | ;; ;; |
10 | ;; Based on the code of 4.4BSD ;; |
10 | ;; Based on the code of 4.4BSD ;; |
11 | ;; ;; |
11 | ;; ;; |
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
13 | ;; Version 2, June 1991 ;; |
13 | ;; Version 2, June 1991 ;; |
14 | ;; ;; |
14 | ;; ;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
16 | 16 | ||
17 | $Revision: 5442 $ |
17 | $Revision: 6011 $ |
18 | 18 | ||
19 | timer_flag_retransmission = 1 shl 0 |
19 | timer_flag_retransmission = 1 shl 0 |
20 | timer_flag_keepalive = 1 shl 1 |
20 | timer_flag_keepalive = 1 shl 1 |
21 | timer_flag_2msl = 1 shl 2 |
21 | timer_flag_2msl = 1 shl 2 |
22 | timer_flag_persist = 1 shl 3 |
22 | timer_flag_persist = 1 shl 3 |
23 | timer_flag_wait = 1 shl 4 |
23 | timer_flag_wait = 1 shl 4 |
24 | 24 | ||
25 | 25 | ||
26 | macro TCP_timer_160ms { |
26 | macro tcp_timer_160ms { |
27 | 27 | ||
28 | local .loop |
28 | local .loop |
29 | local .exit |
29 | local .exit |
30 | 30 | ||
31 | mov ebx, net_sockets |
31 | mov ebx, net_sockets |
32 | .loop: |
32 | .loop: |
33 | mov ebx, [ebx + SOCKET.NextPtr] |
33 | mov ebx, [ebx + SOCKET.NextPtr] |
34 | test ebx, ebx |
34 | test ebx, ebx |
35 | jz .exit |
35 | jz .exit |
36 | 36 | ||
37 | cmp [ebx + SOCKET.Domain], AF_INET4 |
37 | cmp [ebx + SOCKET.Domain], AF_INET4 |
38 | jne .loop |
38 | jne .loop |
39 | cmp [ebx + SOCKET.Protocol], IP_PROTO_TCP |
39 | cmp [ebx + SOCKET.Protocol], IP_PROTO_TCP |
40 | jne .loop |
40 | jne .loop |
41 | test [ebx + TCP_SOCKET.t_flags], TF_DELACK |
41 | test [ebx + TCP_SOCKET.t_flags], TF_DELACK |
42 | jz .loop |
42 | jz .loop |
43 | 43 | ||
44 | and [ebx + TCP_SOCKET.t_flags], not (TF_DELACK) |
44 | and [ebx + TCP_SOCKET.t_flags], not (TF_DELACK) |
45 | 45 | ||
46 | push ebx |
46 | push ebx |
47 | mov cl, TH_ACK |
47 | mov cl, TH_ACK |
48 | call TCP_respond |
48 | call tcp_respond |
49 | ; and [ebx + TCP_SOCKET.t_flags], TF_ACKNOW ;; |
- | |
50 | ; mov eax, ebx ;; |
- | |
51 | ; call TCP_output ;; |
- | |
52 | pop ebx |
49 | pop ebx |
53 | 50 | ||
54 | inc [TCPS_delack] ; update stats |
51 | inc [TCPS_delack] ; update stats |
55 | 52 | ||
56 | jmp .loop |
53 | jmp .loop |
57 | 54 | ||
58 | .exit: |
55 | .exit: |
59 | 56 | ||
60 | } |
57 | } |
61 | 58 | ||
62 | 59 | ||
63 | align 4 |
60 | align 4 |
64 | proc TCP_timer_640ms ; TODO: implement timed wait timer! |
61 | proc tcp_timer_640ms |
65 | 62 | ||
66 | xor esi, esi |
63 | xor esi, esi |
67 | mov ecx, MANUAL_DESTROY |
64 | mov ecx, MANUAL_DESTROY |
68 | call create_event |
65 | call create_event |
69 | mov [TCP_timer1_event], eax |
66 | mov [TCP_timer1_event], eax |
70 | 67 | ||
71 | .wait: |
68 | .wait: |
72 | mov eax, [TCP_timer1_event] |
69 | mov eax, [TCP_timer1_event] |
73 | mov ebx, [eax + EVENT.id] |
70 | mov ebx, [eax + EVENT.id] |
74 | call wait_event |
71 | call wait_event |
75 | 72 | ||
76 | ; Update TCP sequence number |
73 | ; Update TCP sequence number |
77 | 74 | ||
78 | add [TCP_sequence_num], 64000 |
75 | add [TCP_sequence_num], 64000 |
79 | 76 | ||
80 | ; scan through all the active TCP sockets, decrementing ALL timers |
77 | ; Scan through all the active TCP sockets, decrementing all active timers |
81 | ; When a timer reaches zero, we'll check wheter it was active or not |
78 | ; When a timer reaches zero, run its handler. |
82 | 79 | ||
83 | mov eax, net_sockets |
80 | mov eax, net_sockets |
84 | .loop: |
81 | .loop: |
85 | mov eax, [eax + SOCKET.NextPtr] |
82 | mov eax, [eax + SOCKET.NextPtr] |
86 | .check_only: |
83 | .check_only: |
87 | or eax, eax |
84 | or eax, eax |
88 | jz .wait |
85 | jz .wait |
89 | 86 | ||
90 | cmp [eax + SOCKET.Domain], AF_INET4 |
87 | cmp [eax + SOCKET.Domain], AF_INET4 |
91 | jne .loop |
88 | jne .loop |
92 | 89 | ||
93 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
90 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
94 | jne .loop |
91 | jne .loop |
95 | 92 | ||
96 | inc [eax + TCP_SOCKET.t_idle] |
93 | inc [eax + TCP_SOCKET.t_idle] |
97 | - | ||
98 | dec [eax + TCP_SOCKET.timer_retransmission] |
- | |
99 | jnz .check_more2 |
94 | |
100 | test [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission |
95 | test [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission |
- | 96 | jz .check_more2 |
|
- | 97 | dec [eax + TCP_SOCKET.timer_retransmission] |
|
101 | jz .check_more2 |
98 | jnz .check_more2 |
102 | 99 | ||
103 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Retransmission timer expired\n", eax |
100 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Retransmission timer expired\n", eax |
104 | 101 | ||
105 | push eax |
102 | push eax |
106 | call TCP_output |
103 | call tcp_output |
107 | pop eax |
104 | pop eax |
108 | 105 | ||
109 | .check_more2: |
106 | .check_more2: |
110 | dec [eax + TCP_SOCKET.timer_keepalive] |
- | |
111 | jnz .check_more3 |
- | |
112 | test [eax + TCP_SOCKET.timer_flags], timer_flag_keepalive |
107 | test [eax + TCP_SOCKET.timer_flags], timer_flag_keepalive |
113 | jz .check_more3 |
108 | jz .check_more3 |
- | 109 | dec [eax + TCP_SOCKET.timer_keepalive] |
|
- | 110 | jnz .check_more3 |
|
114 | 111 | ||
115 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Keepalive expired\n", eax |
112 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Keepalive expired\n", eax |
116 | 113 | ||
117 | cmp [eax + TCP_SOCKET.state], TCPS_ESTABLISHED |
114 | cmp [eax + TCP_SOCKET.state], TCPS_ESTABLISHED |
118 | ja .dont_kill |
115 | ja .dont_kill |
119 | 116 | ||
120 | push eax |
117 | push eax |
121 | call TCP_disconnect |
118 | call tcp_disconnect |
122 | pop eax |
119 | pop eax |
123 | jmp .loop |
120 | jmp .loop |
124 | 121 | ||
125 | .dont_kill: |
122 | .dont_kill: |
126 | test [eax + SOCKET.options], SO_KEEPALIVE |
123 | test [eax + SOCKET.options], SO_KEEPALIVE |
127 | jz .reset_keepalive |
124 | jz .reset_keepalive |
128 | 125 | ||
129 | push eax |
126 | push eax |
130 | mov ebx, eax |
127 | mov ebx, eax |
131 | xor cl, cl |
128 | xor cl, cl |
132 | call TCP_respond ; send keepalive |
129 | call tcp_respond ; send keepalive |
133 | pop eax |
130 | pop eax |
134 | mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval |
131 | mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval |
135 | jmp .check_more3 |
132 | jmp .check_more3 |
136 | 133 | ||
137 | .reset_keepalive: |
134 | .reset_keepalive: |
138 | mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_idle |
135 | mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_idle |
139 | 136 | ||
140 | .check_more3: |
137 | .check_more3: |
141 | dec [eax + TCP_SOCKET.timer_timed_wait] |
- | |
142 | jnz .check_more5 |
- | |
143 | test [eax + TCP_SOCKET.timer_flags], timer_flag_2msl |
138 | test [eax + TCP_SOCKET.timer_flags], timer_flag_2msl |
144 | jz .check_more5 |
139 | jz .check_more5 |
- | 140 | dec [eax + TCP_SOCKET.timer_timed_wait] |
|
- | 141 | jnz .check_more5 |
|
145 | 142 | ||
146 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: 2MSL timer expired\n", eax |
143 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: 2MSL timer expired\n", eax |
147 | 144 | ||
148 | .check_more5: |
145 | .check_more5: |
149 | dec [eax + TCP_SOCKET.timer_persist] |
- | |
150 | jnz .check_more6 |
- | |
151 | test [eax + TCP_SOCKET.timer_flags], timer_flag_persist |
146 | test [eax + TCP_SOCKET.timer_flags], timer_flag_persist |
152 | jz .check_more6 |
147 | jz .check_more6 |
- | 148 | dec [eax + TCP_SOCKET.timer_persist] |
|
- | 149 | jnz .check_more6 |
|
153 | 150 | ||
154 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: persist timer expired\n", eax |
151 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: persist timer expired\n", eax |
155 | 152 | ||
156 | call TCP_set_persist |
153 | call tcp_set_persist |
157 | mov [eax + TCP_SOCKET.t_force], 1 |
154 | mov [eax + TCP_SOCKET.t_force], 1 |
158 | push eax |
155 | push eax |
159 | call TCP_output |
156 | call tcp_output |
160 | pop eax |
157 | pop eax |
161 | mov [eax + TCP_SOCKET.t_force], 0 |
158 | mov [eax + TCP_SOCKET.t_force], 0 |
162 | 159 | ||
163 | .check_more6: |
160 | .check_more6: |
164 | dec [eax + TCP_SOCKET.timer_timed_wait] |
- | |
165 | jnz .loop |
- | |
166 | test [eax + TCP_SOCKET.timer_flags], timer_flag_wait |
161 | test [eax + TCP_SOCKET.timer_flags], timer_flag_wait |
167 | jz .loop |
162 | jz .loop |
- | 163 | dec [eax + TCP_SOCKET.timer_timed_wait] |
|
- | 164 | jnz .loop |
|
168 | 165 | ||
169 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: timed wait timer expired\n", eax |
166 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: timed wait timer expired\n", eax |
170 | 167 | ||
171 | push [eax + SOCKET.NextPtr] |
168 | push [eax + SOCKET.NextPtr] |
172 | call TCP_close |
169 | call tcp_close |
173 | pop eax |
170 | pop eax |
174 | 171 | ||
175 | jmp .check_only |
172 | jmp .check_only |
176 | 173 | ||
177 | endp |
174 | endp |
178 | 175 | ||
179 | 176 | ||
180 | ;-----------------------------------------------------------------; |
177 | ;-----------------------------------------------------------------; |
181 | ; ; |
178 | ; ; |
182 | ; TCP_cancel_timers ; |
179 | ; TCP_cancel_timers ; |
183 | ; ; |
180 | ; ; |
184 | ; IN: eax = socket ; |
181 | ; IN: eax = socket ; |
185 | ; ; |
182 | ; ; |
186 | ; OUT: / ; |
183 | ; OUT: / ; |
187 | ; ; |
184 | ; ; |
188 | ;-----------------------------------------------------------------; |
185 | ;-----------------------------------------------------------------; |
189 | align 4 |
186 | align 4 |
190 | TCP_cancel_timers: |
187 | tcp_cancel_timers: |
191 | 188 | ||
192 | mov [eax + TCP_SOCKET.timer_flags], 0 |
189 | mov [eax + TCP_SOCKET.timer_flags], 0 |
193 | 190 | ||
194 | ret |
191 | ret |