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