Rev 3600 | Rev 5013 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3600 | Rev 4850 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2013. 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: 3143 $ |
17 | $Revision: 4850 $ |
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 | ;---------------------- |
26 | ;---------------------- |
27 | ; 160 ms timer |
27 | ; 160 ms timer |
28 | ;---------------------- |
28 | ;---------------------- |
29 | macro TCP_timer_160ms { |
29 | macro TCP_timer_160ms { |
30 | 30 | ||
31 | local .loop |
31 | local .loop |
32 | local .exit |
32 | local .exit |
33 | 33 | ||
34 | mov ebx, net_sockets |
34 | mov ebx, net_sockets |
35 | .loop: |
35 | .loop: |
36 | mov ebx, [ebx + SOCKET.NextPtr] |
36 | mov ebx, [ebx + SOCKET.NextPtr] |
37 | test ebx, ebx |
37 | test ebx, ebx |
38 | jz .exit |
38 | jz .exit |
39 | 39 | ||
40 | cmp [ebx + SOCKET.Domain], AF_INET4 |
40 | cmp [ebx + SOCKET.Domain], AF_INET4 |
41 | jne .loop |
41 | jne .loop |
42 | cmp [ebx + SOCKET.Protocol], IP_PROTO_TCP |
42 | cmp [ebx + SOCKET.Protocol], IP_PROTO_TCP |
43 | jne .loop |
43 | jne .loop |
44 | test [ebx + TCP_SOCKET.t_flags], TF_DELACK |
44 | test [ebx + TCP_SOCKET.t_flags], TF_DELACK |
45 | jz .loop |
45 | jz .loop |
46 | 46 | ||
47 | and [ebx + TCP_SOCKET.t_flags], not (TF_DELACK) |
47 | and [ebx + TCP_SOCKET.t_flags], not (TF_DELACK) |
48 | 48 | ||
49 | push ebx |
49 | push ebx |
50 | mov cl, TH_ACK |
50 | mov cl, TH_ACK |
51 | call TCP_respond |
51 | call TCP_respond |
52 | ; and [ebx + TCP_SOCKET.t_flags], TF_ACKNOW ;; |
52 | ; and [ebx + TCP_SOCKET.t_flags], TF_ACKNOW ;; |
53 | ; mov eax, ebx ;; |
53 | ; mov eax, ebx ;; |
54 | ; call TCP_output ;; |
54 | ; call TCP_output ;; |
55 | pop ebx |
55 | pop ebx |
56 | 56 | ||
57 | jmp .loop |
57 | jmp .loop |
58 | 58 | ||
59 | .exit: |
59 | .exit: |
60 | 60 | ||
61 | } |
61 | } |
62 | 62 | ||
63 | 63 | ||
64 | ;---------------------- |
64 | ;---------------------- |
65 | ; 640 ms timer |
65 | ; 640 ms timer |
66 | ;---------------------- |
66 | ;---------------------- |
67 | macro TCP_timer_640ms { ; TODO: implement timed wait timer! |
67 | macro TCP_timer_640ms { ; TODO: implement timed wait timer! |
68 | 68 | ||
69 | local .loop |
69 | local .loop |
70 | local .exit |
70 | local .exit |
71 | 71 | ||
72 | ; Update TCP sequence number |
72 | ; Update TCP sequence number |
73 | 73 | ||
74 | add [TCP_sequence_num], 64000 |
74 | add [TCP_sequence_num], 64000 |
75 | 75 | ||
76 | ; scan through all the active TCP sockets, decrementing ALL timers |
76 | ; scan through all the active TCP sockets, decrementing ALL timers |
77 | ; When a timer reaches zero, we'll check wheter it was active or not |
77 | ; When a timer reaches zero, we'll check wheter it was active or not |
78 | 78 | ||
79 | mov eax, net_sockets |
79 | mov eax, net_sockets |
80 | .loop: |
80 | .loop: |
81 | mov eax, [eax + SOCKET.NextPtr] |
81 | mov eax, [eax + SOCKET.NextPtr] |
82 | .check_only: |
82 | .check_only: |
83 | or eax, eax |
83 | or eax, eax |
84 | jz .exit |
84 | jz .exit |
85 | 85 | ||
86 | cmp [eax + SOCKET.Domain], AF_INET4 |
86 | cmp [eax + SOCKET.Domain], AF_INET4 |
87 | jne .loop |
87 | jne .loop |
88 | 88 | ||
89 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
89 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
90 | jne .loop |
90 | jne .loop |
91 | 91 | ||
92 | inc [eax + TCP_SOCKET.t_idle] |
92 | inc [eax + TCP_SOCKET.t_idle] |
93 | 93 | ||
94 | dec [eax + TCP_SOCKET.timer_retransmission] |
94 | dec [eax + TCP_SOCKET.timer_retransmission] |
95 | jnz .check_more2 |
95 | jnz .check_more2 |
96 | test [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission |
96 | test [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission |
97 | jz .check_more2 |
97 | jz .check_more2 |
98 | 98 | ||
99 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Retransmission timer expired\n", eax |
99 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Retransmission timer expired\n", eax |
100 | 100 | ||
101 | push eax |
101 | push eax |
102 | call TCP_output |
102 | call TCP_output |
103 | pop eax |
103 | pop eax |
104 | 104 | ||
105 | .check_more2: |
105 | .check_more2: |
106 | dec [eax + TCP_SOCKET.timer_keepalive] |
106 | dec [eax + TCP_SOCKET.timer_keepalive] |
107 | jnz .check_more3 |
107 | jnz .check_more3 |
108 | test [eax + TCP_SOCKET.timer_flags], timer_flag_keepalive |
108 | test [eax + TCP_SOCKET.timer_flags], timer_flag_keepalive |
109 | jz .check_more3 |
109 | jz .check_more3 |
110 | 110 | ||
111 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Keepalive expired\n", eax |
111 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Keepalive expired\n", eax |
112 | 112 | ||
113 | cmp [eax + TCP_SOCKET.state], TCPS_ESTABLISHED |
113 | cmp [eax + TCP_SOCKET.state], TCPS_ESTABLISHED |
114 | ja .dont_kill |
114 | ja .dont_kill |
115 | 115 | ||
116 | push eax |
116 | push eax |
117 | call TCP_disconnect |
117 | call TCP_disconnect |
118 | pop eax |
118 | pop eax |
119 | jmp .loop |
119 | jmp .loop |
120 | 120 | ||
121 | .dont_kill: |
121 | .dont_kill: |
122 | test [eax + SOCKET.options], SO_KEEPALIVE |
122 | test [eax + SOCKET.options], SO_KEEPALIVE |
123 | jz .reset_keepalive |
123 | jz .reset_keepalive |
124 | 124 | ||
125 | push eax |
125 | push eax |
126 | mov ebx, eax |
126 | mov ebx, eax |
127 | xor cl, cl |
127 | xor cl, cl |
128 | call TCP_respond ; send keepalive |
128 | call TCP_respond ; send keepalive |
129 | pop eax |
129 | pop eax |
130 | mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval |
130 | mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval |
131 | jmp .check_more3 |
131 | jmp .check_more3 |
132 | 132 | ||
133 | .reset_keepalive: |
133 | .reset_keepalive: |
134 | mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_idle |
134 | mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_idle |
135 | 135 | ||
136 | .check_more3: |
136 | .check_more3: |
137 | dec [eax + TCP_SOCKET.timer_timed_wait] |
137 | dec [eax + TCP_SOCKET.timer_timed_wait] |
138 | jnz .check_more5 |
138 | jnz .check_more5 |
139 | test [eax + TCP_SOCKET.timer_flags], timer_flag_2msl |
139 | test [eax + TCP_SOCKET.timer_flags], timer_flag_2msl |
140 | jz .check_more5 |
140 | jz .check_more5 |
141 | 141 | ||
142 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: 2MSL timer expired\n", eax |
142 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: 2MSL timer expired\n", eax |
143 | 143 | ||
144 | .check_more5: |
144 | .check_more5: |
145 | dec [eax + TCP_SOCKET.timer_persist] |
145 | dec [eax + TCP_SOCKET.timer_persist] |
146 | jnz .loop |
146 | jnz .loop |
147 | test [eax + TCP_SOCKET.timer_flags], timer_flag_persist |
147 | test [eax + TCP_SOCKET.timer_flags], timer_flag_persist |
148 | jz .loop |
148 | jz .loop |
149 | 149 | ||
150 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: persist timer expired\n", eax |
150 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: persist timer expired\n", eax |
151 | 151 | ||
152 | call TCP_set_persist |
152 | call TCP_set_persist |
153 | mov [eax + TCP_SOCKET.t_force], 1 |
153 | mov [eax + TCP_SOCKET.t_force], 1 |
154 | push eax |
154 | push eax |
155 | call TCP_output |
155 | call TCP_output |
156 | pop eax |
156 | pop eax |
157 | mov [eax + TCP_SOCKET.t_force], 0 |
157 | mov [eax + TCP_SOCKET.t_force], 0 |
158 | 158 | ||
159 | jmp .loop |
159 | jmp .loop |
160 | .exit: |
160 | .exit: |
161 | 161 | ||
162 | } |
162 | } |
163 | 163 | ||
164 | 164 | ||
165 | 165 | ||
166 | ; eax = socket |
166 | ; eax = socket |
167 | 167 | ||
168 | TCP_cancel_timers: |
168 | TCP_cancel_timers: |
169 | 169 | ||
170 | mov [eax + TCP_SOCKET.timer_flags], 0 |
170 | mov [eax + TCP_SOCKET.timer_flags], 0 |
171 | 171 | ||
172 | ret |
172 | ret |