Rev 6916 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6916 | Rev 7099 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2017. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2017. 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: 6916 $ |
17 | $Revision: 7099 $ |
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 | or [ebx + TCP_SOCKET.t_flags], TF_ACKNOW |
|
45 | 46 | ||
46 | push ebx |
47 | push ebx |
47 | mov cl, TH_ACK |
48 | mov eax, ebx |
48 | call tcp_respond |
49 | call tcp_output |
49 | pop ebx |
50 | pop ebx |
50 | 51 | ||
51 | inc [TCPS_delack] ; update stats |
52 | inc [TCPS_delack] ; update stats |
52 | 53 | ||
53 | jmp .loop |
54 | jmp .loop |
54 | 55 | ||
55 | .exit: |
56 | .exit: |
56 | 57 | ||
57 | } |
58 | } |
58 | 59 | ||
59 | 60 | ||
60 | align 4 |
61 | align 4 |
61 | proc tcp_timer_640ms |
62 | proc tcp_timer_640ms |
62 | 63 | ||
63 | xor esi, esi |
64 | xor esi, esi |
64 | mov ecx, MANUAL_DESTROY |
65 | mov ecx, MANUAL_DESTROY |
65 | call create_event |
66 | call create_event |
66 | mov [TCP_timer1_event], eax |
67 | mov [TCP_timer1_event], eax |
67 | 68 | ||
68 | .wait: |
69 | .wait: |
69 | mov eax, [TCP_timer1_event] |
70 | mov eax, [TCP_timer1_event] |
70 | mov ebx, [eax + EVENT.id] |
71 | mov ebx, [eax + EVENT.id] |
71 | call wait_event |
72 | call wait_event |
72 | 73 | ||
73 | ; Update TCP sequence number |
74 | ; Update TCP sequence number |
74 | 75 | ||
75 | add [TCP_sequence_num], 64000 |
76 | add [TCP_sequence_num], 64000 |
76 | 77 | ||
77 | ; Scan through all the active TCP sockets, decrementing all active timers |
78 | ; Scan through all the active TCP sockets, decrementing all active timers |
78 | ; When a timer reaches zero, run its handler. |
79 | ; When a timer reaches zero, run its handler. |
79 | 80 | ||
80 | mov eax, net_sockets |
81 | mov eax, net_sockets |
81 | .loop: |
82 | .loop: |
82 | mov eax, [eax + SOCKET.NextPtr] |
83 | mov eax, [eax + SOCKET.NextPtr] |
83 | .check_only: |
84 | .check_only: |
84 | or eax, eax |
85 | or eax, eax |
85 | jz .wait |
86 | jz .wait |
86 | 87 | ||
87 | cmp [eax + SOCKET.Domain], AF_INET4 |
88 | cmp [eax + SOCKET.Domain], AF_INET4 |
88 | jne .loop |
89 | jne .loop |
89 | 90 | ||
90 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
91 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
91 | jne .loop |
92 | jne .loop |
92 | 93 | ||
93 | inc [eax + TCP_SOCKET.t_idle] |
94 | inc [eax + TCP_SOCKET.t_idle] |
94 | 95 | ||
95 | test [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission |
96 | test [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission |
96 | jz .check_more2 |
97 | jz .check_more2 |
97 | dec [eax + TCP_SOCKET.timer_retransmission] |
98 | dec [eax + TCP_SOCKET.timer_retransmission] |
98 | jnz .check_more2 |
99 | jnz .check_more2 |
99 | 100 | ||
100 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Retransmission timer expired\n", eax |
101 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Retransmission timer expired\n", eax |
101 | 102 | ||
102 | push eax |
103 | push eax |
103 | call tcp_output |
104 | call tcp_output |
104 | pop eax |
105 | pop eax |
105 | 106 | ||
106 | .check_more2: |
107 | .check_more2: |
107 | test [eax + TCP_SOCKET.timer_flags], timer_flag_keepalive |
108 | test [eax + TCP_SOCKET.timer_flags], timer_flag_keepalive |
108 | jz .check_more3 |
109 | jz .check_more3 |
109 | dec [eax + TCP_SOCKET.timer_keepalive] |
110 | dec [eax + TCP_SOCKET.timer_keepalive] |
110 | jnz .check_more3 |
111 | jnz .check_more3 |
111 | 112 | ||
112 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Keepalive expired\n", eax |
113 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Keepalive expired\n", eax |
113 | 114 | ||
114 | cmp [eax + TCP_SOCKET.state], TCPS_ESTABLISHED |
115 | cmp [eax + TCP_SOCKET.state], TCPS_ESTABLISHED |
115 | ja .dont_kill |
116 | ja .dont_kill |
116 | 117 | ||
117 | push eax |
118 | push eax |
118 | call tcp_disconnect |
119 | call tcp_disconnect |
119 | pop eax |
120 | pop eax |
120 | jmp .loop |
121 | jmp .loop |
121 | 122 | ||
122 | .dont_kill: |
123 | .dont_kill: |
123 | test [eax + SOCKET.options], SO_KEEPALIVE |
124 | test [eax + SOCKET.options], SO_KEEPALIVE |
124 | jz .reset_keepalive |
125 | jz .reset_keepalive |
125 | 126 | ||
126 | push eax |
127 | push eax |
127 | mov ebx, eax |
128 | mov ebx, eax |
128 | xor cl, cl |
129 | xor cl, cl |
129 | call tcp_respond ; send keepalive |
130 | call tcp_respond ; send keepalive |
130 | pop eax |
131 | pop eax |
131 | mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval |
132 | mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval |
132 | jmp .check_more3 |
133 | jmp .check_more3 |
133 | 134 | ||
134 | .reset_keepalive: |
135 | .reset_keepalive: |
135 | mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_idle |
136 | mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_idle |
136 | 137 | ||
137 | .check_more3: |
138 | .check_more3: |
138 | test [eax + TCP_SOCKET.timer_flags], timer_flag_2msl |
139 | test [eax + TCP_SOCKET.timer_flags], timer_flag_2msl |
139 | jz .check_more5 |
140 | jz .check_more5 |
140 | dec [eax + TCP_SOCKET.timer_timed_wait] |
141 | dec [eax + TCP_SOCKET.timer_timed_wait] |
141 | jnz .check_more5 |
142 | jnz .check_more5 |
142 | 143 | ||
143 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: 2MSL timer expired\n", eax |
144 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: 2MSL timer expired\n", eax |
144 | 145 | ||
145 | .check_more5: |
146 | .check_more5: |
146 | test [eax + TCP_SOCKET.timer_flags], timer_flag_persist |
147 | test [eax + TCP_SOCKET.timer_flags], timer_flag_persist |
147 | jz .check_more6 |
148 | jz .check_more6 |
148 | dec [eax + TCP_SOCKET.timer_persist] |
149 | dec [eax + TCP_SOCKET.timer_persist] |
149 | jnz .check_more6 |
150 | jnz .check_more6 |
150 | 151 | ||
151 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: persist timer expired\n", eax |
152 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: persist timer expired\n", eax |
152 | 153 | ||
153 | call tcp_set_persist |
154 | call tcp_set_persist |
154 | or [eax + TCP_SOCKET.t_flags], TF_FORCE |
155 | or [eax + TCP_SOCKET.t_flags], TF_FORCE |
155 | push eax |
156 | push eax |
156 | call tcp_output |
157 | call tcp_output |
157 | pop eax |
158 | pop eax |
158 | and [eax + TCP_SOCKET.t_flags], not TF_FORCE |
159 | and [eax + TCP_SOCKET.t_flags], not TF_FORCE |
159 | 160 | ||
160 | .check_more6: |
161 | .check_more6: |
161 | test [eax + TCP_SOCKET.timer_flags], timer_flag_wait |
162 | test [eax + TCP_SOCKET.timer_flags], timer_flag_wait |
162 | jz .loop |
163 | jz .loop |
163 | dec [eax + TCP_SOCKET.timer_timed_wait] |
164 | dec [eax + TCP_SOCKET.timer_timed_wait] |
164 | jnz .loop |
165 | jnz .loop |
165 | 166 | ||
166 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: timed wait timer expired\n", eax |
167 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: timed wait timer expired\n", eax |
167 | 168 | ||
168 | push [eax + SOCKET.NextPtr] |
169 | push [eax + SOCKET.NextPtr] |
169 | call tcp_close |
170 | call tcp_close |
170 | pop eax |
171 | pop eax |
171 | 172 | ||
172 | jmp .check_only |
173 | jmp .check_only |
173 | 174 | ||
174 | endp |
175 | endp |
175 | 176 | ||
176 | 177 | ||
177 | ;-----------------------------------------------------------------; |
178 | ;-----------------------------------------------------------------; |
178 | ; ; |
179 | ; ; |
179 | ; TCP_cancel_timers ; |
180 | ; TCP_cancel_timers ; |
180 | ; ; |
181 | ; ; |
181 | ; IN: eax = socket ; |
182 | ; IN: eax = socket ; |
182 | ; ; |
183 | ; ; |
183 | ; OUT: / ; |
184 | ; OUT: / ; |
184 | ; ; |
185 | ; ; |
185 | ;-----------------------------------------------------------------; |
186 | ;-----------------------------------------------------------------; |
186 | align 4 |
187 | align 4 |
187 | tcp_cancel_timers: |
188 | tcp_cancel_timers: |
188 | 189 | ||
189 | mov [eax + TCP_SOCKET.timer_flags], 0 |
190 | mov [eax + TCP_SOCKET.timer_flags], 0 |
190 | 191 | ||
191 | ret |
192 | ret |