1 | /*
|
---|
2 | * TINET (TCP/IP Protocol Stack)
|
---|
3 | *
|
---|
4 | * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
|
---|
5 | * Tomakomai National College of Technology, JAPAN
|
---|
6 | *
|
---|
7 | * ä¸è¨èä½æ¨©è
|
---|
8 | ã¯ï¼ä»¥ä¸ã® (1)ï½(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
9 | * ã«ãã£ã¦å
|
---|
10 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
11 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
12 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
13 | å¸ï¼ä»¥ä¸ï¼
|
---|
14 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
15 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
16 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
17 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
18 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
19 | * ç¨ã§ããå½¢ã§åé
|
---|
20 | å¸ããå ´åã«ã¯ï¼åé
|
---|
21 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
22 | * è
|
---|
23 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
24 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
25 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
26 | * ç¨ã§ããªãå½¢ã§åé
|
---|
27 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®æ¡ä»¶ãæºãããã¨ï¼
|
---|
28 | * (a) åé
|
---|
29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
31 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
32 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
33 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
34 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
35 | 責ãããã¨ï¼
|
---|
36 | *
|
---|
37 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
38 | ã
|
---|
39 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
40 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
41 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
42 | *
|
---|
43 | * @(#) $Id: tcp_subr.c 313 2017-07-23 04:50:32Z coas-nagasima $
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
|
---|
48 | * The Regents of the University of California. All rights reserved.
|
---|
49 | *
|
---|
50 | * Redistribution and use in source and binary forms, with or without
|
---|
51 | * modification, are permitted provided that the following conditions
|
---|
52 | * are met:
|
---|
53 | * 1. Redistributions of source code must retain the above copyright
|
---|
54 | * notice, this list of conditions and the following disclaimer.
|
---|
55 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
56 | * notice, this list of conditions and the following disclaimer in the
|
---|
57 | * documentation and/or other materials provided with the distribution.
|
---|
58 | * 3. All advertising materials mentioning features or use of this software
|
---|
59 | * must display the following acknowledgement:
|
---|
60 | * This product includes software developed by the University of
|
---|
61 | * California, Berkeley and its contributors.
|
---|
62 | * 4. Neither the name of the University nor the names of its contributors
|
---|
63 | * may be used to endorse or promote products derived from this software
|
---|
64 | * without specific prior written permission.
|
---|
65 | *
|
---|
66 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
---|
67 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
68 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
69 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
70 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
71 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
72 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
73 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
74 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
75 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
76 | * SUCH DAMAGE.
|
---|
77 | *
|
---|
78 | * @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95
|
---|
79 | * $FreeBSD: src/sys/netinet/tcp_subr.c,v 1.49.2.4 1999/08/29 16:29:55 peter Exp $
|
---|
80 | */
|
---|
81 |
|
---|
82 | #include <stdarg.h>
|
---|
83 | #include <string.h>
|
---|
84 |
|
---|
85 | #ifdef TARGET_KERNEL_ASP
|
---|
86 |
|
---|
87 | #include <kernel.h>
|
---|
88 | #include <sil.h>
|
---|
89 | #include <syssvc/serial.h>
|
---|
90 | #include <syssvc/logtask.h>
|
---|
91 | #include <t_syslog.h>
|
---|
92 | #include "kernel_cfg.h"
|
---|
93 |
|
---|
94 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
95 |
|
---|
96 | #ifdef TARGET_KERNEL_JSP
|
---|
97 |
|
---|
98 | #include <s_services.h>
|
---|
99 | #include <t_services.h>
|
---|
100 | #include "kernel_id.h"
|
---|
101 |
|
---|
102 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
103 |
|
---|
104 | #include <tinet_defs.h>
|
---|
105 | #include <tinet_config.h>
|
---|
106 |
|
---|
107 | #include <net/if.h>
|
---|
108 | #include <net/if_ppp.h>
|
---|
109 | #include <net/if_loop.h>
|
---|
110 | #include <net/ethernet.h>
|
---|
111 | #include <net/net.h>
|
---|
112 | #include <net/net_endian.h>
|
---|
113 | #include <net/net_var.h>
|
---|
114 | #include <net/net_buf.h>
|
---|
115 | #include <net/net_timer.h>
|
---|
116 | #include <net/net_count.h>
|
---|
117 |
|
---|
118 | #include <netinet/in.h>
|
---|
119 | #include <netinet/in_var.h>
|
---|
120 | #include <netinet/in_itron.h>
|
---|
121 | #include <netinet/ip.h>
|
---|
122 | #include <netinet/ip_var.h>
|
---|
123 | #include <netinet/tcp.h>
|
---|
124 | #include <netinet/tcp_var.h>
|
---|
125 | #include <netinet/tcp_fsm.h>
|
---|
126 | #include <netinet/tcp_seq.h>
|
---|
127 | #include <netinet/tcp_timer.h>
|
---|
128 |
|
---|
129 | #ifdef SUPPORT_TCP
|
---|
130 |
|
---|
131 | /*
|
---|
132 | * å
|
---|
133 | ¨åå¤æ°
|
---|
134 | */
|
---|
135 |
|
---|
136 | /*
|
---|
137 | * TCP ã® SEQ ã®åæå¤ãããã°ã©ã ãèµ·åãã¦ãæåã« TCP ã»ã°ã¡ã³ãã
|
---|
138 | * éåä¿¡ããã¨ãã«ãget_tim() ã«ããåæåããã
|
---|
139 | */
|
---|
140 | T_TCP_SEQ tcp_iss = 0;
|
---|
141 |
|
---|
142 | #ifdef SUPPORT_MIB
|
---|
143 |
|
---|
144 | /*
|
---|
145 | * SNMP 㮠管çæ
|
---|
146 | å ±ãã¼ã¹ (MIB)
|
---|
147 | */
|
---|
148 |
|
---|
149 | T_TCP_STATS tcp_stats;
|
---|
150 |
|
---|
151 | #endif /* of #ifdef SUPPORT_MIB */
|
---|
152 |
|
---|
153 | /*
|
---|
154 | * å±æå¤æ°
|
---|
155 | */
|
---|
156 |
|
---|
157 | static uint16_t tcp_port_auto = TCP_PORT_FIRST_AUTO; /* èªåå²ãå½ã¦çªå· */
|
---|
158 |
|
---|
159 | #if defined(NUM_TCP_TW_CEP_ENTRY) && NUM_TCP_TW_CEP_ENTRY > 0
|
---|
160 |
|
---|
161 | /*
|
---|
162 | * ã¿ã¹ã¯ããã® Time Wait ç¶æ
|
---|
163 | CEP åé¢æ©è½
|
---|
164 | */
|
---|
165 |
|
---|
166 | /*
|
---|
167 | * å¤æ°
|
---|
168 | */
|
---|
169 |
|
---|
170 | T_TCP_TWCEP tcp_twcep[NUM_TCP_TW_CEP_ENTRY];
|
---|
171 |
|
---|
172 | /*
|
---|
173 | * tcp_move_twcep -- å¿
|
---|
174 | è¦ãªæ
|
---|
175 | å ±ã Time Wait ç¨ TCP é信端ç¹ã«ç§»ãã¦ã
|
---|
176 | * æ¨æºã® TCP é信端ç¹ãéæ¾ããã
|
---|
177 | */
|
---|
178 |
|
---|
179 | void
|
---|
180 | tcp_move_twcep (T_TCP_CEP *cep)
|
---|
181 | {
|
---|
182 | T_TCP_TWCEP* twcep;
|
---|
183 |
|
---|
184 | /* 空ãã® Time Wait ç¨ TCP é信端ç¹ãæ¢ç´¢ããã*/
|
---|
185 | for (twcep = &tcp_twcep[NUM_TCP_TW_CEP_ENTRY]; twcep -- != tcp_twcep; ) {
|
---|
186 | if (twcep->fsm_state != TCP_FSM_TIME_WAIT) {
|
---|
187 |
|
---|
188 | /*
|
---|
189 | * é信端ç¹ãããã¯ãã
|
---|
190 | * å¿
|
---|
191 | è¦ãªæ
|
---|
192 | å ±ã Time Wait ç¨ TCP é信端ç¹ã«ç§»ãã
|
---|
193 | */
|
---|
194 | syscall(wai_sem(cep->semid_lock));
|
---|
195 | twcep->flags = (uint8_t)cep->flags;
|
---|
196 | twcep->rbufsz = cep->rbufsz;
|
---|
197 | twcep->dstaddr = cep->dstaddr;
|
---|
198 | twcep->myaddr = cep->myaddr;
|
---|
199 | twcep->snd_una = cep->snd_una;
|
---|
200 | twcep->rcv_nxt = cep->rcv_nxt;
|
---|
201 | twcep->rwbuf_count = cep->rwbuf_count;
|
---|
202 | twcep->fsm_state = cep->fsm_state;
|
---|
203 | twcep->timer_2msl = cep->timer[TCP_TIM_2MSL];
|
---|
204 |
|
---|
205 | /* é信端ç¹ãããã¯ã解é¤ããã*/
|
---|
206 | syscall(sig_sem(cep->semid_lock));
|
---|
207 |
|
---|
208 | /* æ¨æº TCP é信端ç¹ãéæ¾ããã*/
|
---|
209 | tcp_close(cep);
|
---|
210 |
|
---|
211 | break;
|
---|
212 | }
|
---|
213 | }
|
---|
214 | }
|
---|
215 |
|
---|
216 | /*
|
---|
217 | * tcp_find_twcep -- ãã¼ãçªå·ãã Time Wait ç¨ TCP é信端ç¹ãå¾ãã
|
---|
218 | */
|
---|
219 |
|
---|
220 | T_TCP_TWCEP*
|
---|
221 | tcp_find_twcep (T_NET_BUF *input, uint_t off)
|
---|
222 | {
|
---|
223 | T_TCP_TWCEP* twcep;
|
---|
224 | T_TCP_HDR *tcph;
|
---|
225 |
|
---|
226 | tcph = GET_TCP_HDR(input, off);
|
---|
227 |
|
---|
228 | /*
|
---|
229 | * ç¶æ
|
---|
230 | ã TIME WAIT ã§ã
|
---|
231 | * IP ã¢ãã¬ã¹ã¨ãã¼ãçªå·ãä¸è´ããé信端ç¹ãæ¢ç´¢ããã
|
---|
232 | */
|
---|
233 | for (twcep = &tcp_twcep[NUM_TCP_TW_CEP_ENTRY]; twcep -- != tcp_twcep; ) {
|
---|
234 | if (twcep->fsm_state == TCP_FSM_TIME_WAIT &&
|
---|
235 | IN_IS_DSTADDR_ACCEPT (&twcep->myaddr.ipaddr, input) &&
|
---|
236 | IN_ARE_NET_SRCADDR_EQUAL(&twcep->dstaddr.ipaddr, input) &&
|
---|
237 | tcph->dport == twcep->myaddr.portno &&
|
---|
238 | tcph->sport == twcep->dstaddr.portno)
|
---|
239 | return twcep;
|
---|
240 | }
|
---|
241 |
|
---|
242 | return NULL;
|
---|
243 | }
|
---|
244 |
|
---|
245 | #endif /* of #if defined(NUM_TCP_TW_CEP_ENTRY) && NUM_TCP_TW_CEP_ENTRY > 0 */
|
---|
246 |
|
---|
247 | /*
|
---|
248 | * tcp_find_cep -- ãã¼ãçªå·ãã TCP é信端ç¹ãå¾ãã
|
---|
249 | */
|
---|
250 |
|
---|
251 | T_TCP_CEP*
|
---|
252 | tcp_find_cep (T_NET_BUF *input, uint_t off)
|
---|
253 | {
|
---|
254 | T_TCP_CEP* cep;
|
---|
255 | T_TCP_HDR *tcph;
|
---|
256 |
|
---|
257 | tcph = GET_TCP_HDR(input, off);
|
---|
258 |
|
---|
259 | /*
|
---|
260 | * ç¶æ
|
---|
261 | ã SYN éä¿¡æ¸ã¿ä»¥å¾ã¯ã
|
---|
262 | * IP ã¢ãã¬ã¹ã¨ãã¼ãçªå·ãä¸è´ãã TCP é信端ç¹ãæ¢ç´¢ããã
|
---|
263 | */
|
---|
264 | for (cep = &tcp_cep[tmax_tcp_cepid]; cep -- != tcp_cep; ) {
|
---|
265 | if (cep->fsm_state >= TCP_FSM_SYN_SENT &&
|
---|
266 | IN_IS_DSTADDR_ACCEPT (&cep->myaddr.ipaddr, input) &&
|
---|
267 | IN_ARE_NET_SRCADDR_EQUAL(&cep->dstaddr.ipaddr, input) &&
|
---|
268 | tcph->dport == cep->myaddr.portno &&
|
---|
269 | tcph->sport == cep->dstaddr.portno)
|
---|
270 | return cep;
|
---|
271 | }
|
---|
272 |
|
---|
273 | /* IPv4 ã§ååãªã¼ãã³ä¸ã® TCP é信端ç¹ãå
|
---|
274 | ã«æ¢ç´¢ããã*/
|
---|
275 | for (cep = &tcp_cep[tmax_tcp_cepid]; cep -- != tcp_cep; ) {
|
---|
276 | if ((cep->flags & TCP_CEP_FLG_IPV4) &&
|
---|
277 | cep->fsm_state == TCP_FSM_LISTEN &&
|
---|
278 | GET_IP_VER(input) == IPV4_VERSION &&
|
---|
279 | IN_IS_DSTADDR_ACCEPT(&cep->myaddr.ipaddr, input) &&
|
---|
280 | tcph->dport == cep->myaddr.portno)
|
---|
281 | return cep;
|
---|
282 | }
|
---|
283 |
|
---|
284 | /* ååãªã¼ãã³ä¸ã® TCP é信端ç¹ãæ¢ç´¢ããã*/
|
---|
285 | for (cep = &tcp_cep[tmax_tcp_cepid]; cep -- != tcp_cep; ) {
|
---|
286 |
|
---|
287 | #if defined(_IP6_CFG) && defined(_IP4_CFG)
|
---|
288 |
|
---|
289 | if (cep->flags & TCP_CEP_FLG_IPV4) {
|
---|
290 | if (cep->fsm_state == TCP_FSM_LISTEN &&
|
---|
291 | GET_IP_VER(input) == IPV4_VERSION &&
|
---|
292 | IN_IS_DSTADDR_ACCEPT(&cep->myaddr.ipaddr, input) &&
|
---|
293 | tcph->dport == cep->myaddr.portno)
|
---|
294 | return cep;
|
---|
295 | }
|
---|
296 | else {
|
---|
297 |
|
---|
298 | #if defined(API_CFG_IP4MAPPED_ADDR)
|
---|
299 |
|
---|
300 | if (cep->fsm_state == TCP_FSM_LISTEN &&
|
---|
301 | IN_IS_DSTADDR_ACCEPT(&cep->myaddr.ipaddr, input) &&
|
---|
302 | tcph->dport == cep->myaddr.portno)
|
---|
303 | return cep;
|
---|
304 |
|
---|
305 | #else /* of #if defined(API_CFG_IP4MAPPED_ADDR) */
|
---|
306 |
|
---|
307 | if (cep->fsm_state == TCP_FSM_LISTEN &&
|
---|
308 | INN6_IS_DSTADDR_ACCEPT(&cep->myaddr.ipaddr, input) &&
|
---|
309 | tcph->dport == cep->myaddr.portno)
|
---|
310 | return cep;
|
---|
311 |
|
---|
312 | #endif /* of #if defined(API_CFG_IP4MAPPED_ADDR) */
|
---|
313 |
|
---|
314 | }
|
---|
315 |
|
---|
316 | #else /* of #if defined(_IP6_CFG) && defined(_IP4_CFG) */
|
---|
317 |
|
---|
318 | if (cep->fsm_state == TCP_FSM_LISTEN &&
|
---|
319 | IN_IS_DSTADDR_ACCEPT(&cep->myaddr.ipaddr, input) &&
|
---|
320 | tcph->dport == cep->myaddr.portno)
|
---|
321 | return cep;
|
---|
322 |
|
---|
323 | #endif /* of #if defined(_IP6_CFG) && defined(_IP4_CFG) */
|
---|
324 | }
|
---|
325 |
|
---|
326 | return NULL;
|
---|
327 | }
|
---|
328 |
|
---|
329 | /*
|
---|
330 | * tcp_is_addr_accept -- åä¿¡å¯è½ãª IP ã¢ãã¬ã¹ã¨ãã¼ãçªå·ã§ãããã¨ã確èªããã
|
---|
331 | */
|
---|
332 |
|
---|
333 | bool_t
|
---|
334 | tcp_is_addr_accept (T_NET_BUF *input, uint_t off)
|
---|
335 | {
|
---|
336 | T_TCP_HDR *tcph;
|
---|
337 |
|
---|
338 | tcph = GET_TCP_HDR(input, off);
|
---|
339 |
|
---|
340 | #if !defined(_IP6_CFG) && defined(_IP4_CFG) && defined(SUPPORT_LOOP)
|
---|
341 |
|
---|
342 | /*
|
---|
343 | * 次ã®ã¨ãã¯ç ´æ£ããã
|
---|
344 | * ã»ãã¼ãçªå·ãåä¸ã§ãéåä¿¡ IP ã¢ãã¬ã¹ ãåä¸ã
|
---|
345 | * ãã ããéä¿¡å
|
---|
346 | IP ã¢ãã¬ã¹ããã¼ã«ã«ã«ã¼ãããã¯ãªãè¯ãã
|
---|
347 | * ã»ãã«ããã£ã¹ãã¢ãã¬ã¹
|
---|
348 | */
|
---|
349 |
|
---|
350 | if (tcph->dport == tcph->sport &&
|
---|
351 | (IN4_ARE_HDR_ADDR_EQUAL(input) && !IN4_ARE_NET_ADDR_EQUAL(&GET_IP4_HDR(input)->dst, &IPV4_ADDR_LOOPBACK)))
|
---|
352 | return RET_DROP;
|
---|
353 |
|
---|
354 | #else /* of #if !defined(_IP6_CFG) && defined(_IP4_CFG) && defined(SUPPORT_LOOP) */
|
---|
355 |
|
---|
356 | /*
|
---|
357 | * 次ã®ã¨ãã¯ãåä¿¡å¯è½ã§ã¯ãªãã
|
---|
358 | * ã»ãã¼ãçªå·ãåä¸ã§ãéåä¿¡ IP ã¢ãã¬ã¹ ãåä¸ã
|
---|
359 | * ã»ãã«ããã£ã¹ãã¢ãã¬ã¹
|
---|
360 | */
|
---|
361 | if (tcph->dport == tcph->sport && IN_ARE_HDR_ADDR_EQUAL(input))
|
---|
362 | return false;
|
---|
363 |
|
---|
364 | #endif /* of #if !defined(_IP6_CFG) && defined(_IP4_CFG) && defined(SUPPORT_LOOP) */
|
---|
365 |
|
---|
366 | if (IN_IS_NET_ADDR_MULTICAST(input))
|
---|
367 | return false;
|
---|
368 | else
|
---|
369 | return true;
|
---|
370 | }
|
---|
371 |
|
---|
372 | /*
|
---|
373 | * tcp_free_reassq -- åä¿¡åæ§æãã¥ã¼ã®ãããã¯ã¼ã¯ãããã¡ã解æ¾ããã
|
---|
374 | *
|
---|
375 | * 注æ:
|
---|
376 | * å¿
|
---|
377 | è¦ã§ããã°ããã®é¢æ°ãå¼ã³åºãåã«ãé信端ç¹ãããã¯ãã
|
---|
378 | * æ»ã£ãå¾ã解é¤ããå¿
|
---|
379 | è¦ãããã
|
---|
380 | */
|
---|
381 |
|
---|
382 | void
|
---|
383 | tcp_free_reassq (T_TCP_CEP *cep)
|
---|
384 | {
|
---|
385 | T_NET_BUF *q, *nq;
|
---|
386 |
|
---|
387 | for (q = cep->reassq; q != NULL; q = nq) {
|
---|
388 | nq = GET_TCP_Q_HDR(q, GET_IP_TCP_Q_HDR_OFFSET(q))->next;
|
---|
389 | syscall(rel_net_buf(q));
|
---|
390 | }
|
---|
391 | cep->reassq = NULL;
|
---|
392 | NET_COUNT_TCP(net_count_tcp[NC_TCP_FREE_RCV_QUEUE], 1);
|
---|
393 | }
|
---|
394 |
|
---|
395 | /*
|
---|
396 | * tcp_alloc_auto_port -- èªåå²ãå½ã¦ãã¼ãçªå·ãè¨å®ããã
|
---|
397 | */
|
---|
398 |
|
---|
399 | void
|
---|
400 | tcp_alloc_auto_port (T_TCP_CEP *cep)
|
---|
401 | {
|
---|
402 | int_t ix;
|
---|
403 | uint16_t portno;
|
---|
404 |
|
---|
405 | while (true) {
|
---|
406 | portno = tcp_port_auto ++;
|
---|
407 | if (tcp_port_auto > TCP_PORT_LAST_AUTO)
|
---|
408 | tcp_port_auto = TCP_PORT_FIRST_AUTO;
|
---|
409 |
|
---|
410 | #if defined(TNUM_TCP6_REPID)
|
---|
411 | #if TNUM_TCP6_REPID > 0
|
---|
412 |
|
---|
413 | for (ix = tmax_tcp6_repid; ix -- > 0; ) {
|
---|
414 |
|
---|
415 | #ifdef TCP_CFG_EXTENTIONS
|
---|
416 |
|
---|
417 | if (VALID_TCP_REP(&tcp6_rep[ix]) && tcp6_rep[ix].myaddr.portno == portno) {
|
---|
418 | portno = TCP_PORTANY;
|
---|
419 | break;
|
---|
420 | }
|
---|
421 |
|
---|
422 | #else /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
423 |
|
---|
424 | if (tcp6_rep[ix].myaddr.portno == portno) {
|
---|
425 | portno = TCP_PORTANY;
|
---|
426 | break;
|
---|
427 | }
|
---|
428 |
|
---|
429 | #endif /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
430 |
|
---|
431 | }
|
---|
432 |
|
---|
433 | #endif /* of #if TNUM_TCP6_REPID > 0 */
|
---|
434 | #endif /* of #if defined(TNUM_TCP6_REPID) */
|
---|
435 |
|
---|
436 | #if defined(TNUM_TCP4_REPID)
|
---|
437 | #if TNUM_TCP4_REPID > 0
|
---|
438 |
|
---|
439 | for (ix = tmax_tcp4_repid; ix -- > 0; ) {
|
---|
440 |
|
---|
441 | #ifdef TCP_CFG_EXTENTIONS
|
---|
442 |
|
---|
443 | if (VALID_TCP_REP(&tcp4_rep[ix]) && tcp4_rep[ix].myaddr.portno == portno) {
|
---|
444 | portno = TCP_PORTANY;
|
---|
445 | break;
|
---|
446 | }
|
---|
447 |
|
---|
448 | #else /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
449 |
|
---|
450 | if (tcp4_rep[ix].myaddr.portno == portno) {
|
---|
451 | portno = TCP_PORTANY;
|
---|
452 | break;
|
---|
453 | }
|
---|
454 |
|
---|
455 | #endif /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
456 |
|
---|
457 | }
|
---|
458 |
|
---|
459 | #endif /* of #if TNUM_TCP4_REPID > 0 */
|
---|
460 | #endif /* of #if defined(TNUM_TCP4_REPID) */
|
---|
461 |
|
---|
462 | if (portno != TCP_PORTANY) {
|
---|
463 |
|
---|
464 | syscall(wai_sem(SEM_TCP_CEP));
|
---|
465 | for (ix = tmax_tcp_cepid; ix -- > 0; ) {
|
---|
466 | if (VALID_TCP_CEP(&tcp_cep[ix]) && tcp_cep[ix].myaddr.portno == portno) {
|
---|
467 | portno = TCP_PORTANY;
|
---|
468 | break;
|
---|
469 | }
|
---|
470 | }
|
---|
471 |
|
---|
472 | if (portno != TCP_PORTANY) {
|
---|
473 | cep->myaddr.portno = portno;
|
---|
474 | syscall(sig_sem(SEM_TCP_CEP));
|
---|
475 | return;
|
---|
476 | }
|
---|
477 | syscall(sig_sem(SEM_TCP_CEP));
|
---|
478 | }
|
---|
479 | }
|
---|
480 | }
|
---|
481 |
|
---|
482 | /*
|
---|
483 | * tcp_alloc_port -- æå®ããããã¼ãçªå·ãè¨å®ããã
|
---|
484 | */
|
---|
485 |
|
---|
486 | ER
|
---|
487 | tcp_alloc_port (T_TCP_CEP *cep, uint16_t portno)
|
---|
488 | {
|
---|
489 | int_t ix;
|
---|
490 |
|
---|
491 | syscall(wai_sem(SEM_TCP_CEP));
|
---|
492 | for (ix = tmax_tcp_cepid; ix -- > 0; )
|
---|
493 | if (VALID_TCP_CEP(cep) && tcp_cep[ix].myaddr.portno == portno) {
|
---|
494 | syscall(sig_sem(SEM_TCP_CEP));
|
---|
495 | return E_PAR;
|
---|
496 | }
|
---|
497 | cep->myaddr.portno = portno;
|
---|
498 | syscall(sig_sem(SEM_TCP_CEP));
|
---|
499 | return E_OK;
|
---|
500 | }
|
---|
501 |
|
---|
502 | /*
|
---|
503 | * tcp_init -- TCP ã¢ã¸ã¥ã¼ã«ã®åæå
|
---|
504 | */
|
---|
505 |
|
---|
506 | void
|
---|
507 | tcp_init (void)
|
---|
508 | {
|
---|
509 | timeout(tcp_slow_timo, NULL, TCP_SLOW_TMO);
|
---|
510 |
|
---|
511 | #ifdef TCP_CFG_DELAY_ACK
|
---|
512 |
|
---|
513 | timeout(tcp_fast_timo, NULL, TCP_FAST_TMO);
|
---|
514 |
|
---|
515 | #endif/* of #ifdef TCP_CFG_DELAY_ACK */
|
---|
516 | }
|
---|
517 |
|
---|
518 | /*
|
---|
519 | * tcp_init_iss ã·ã¼ã±ã³ã¹çªå·ãåæåããã
|
---|
520 | */
|
---|
521 |
|
---|
522 | void
|
---|
523 | tcp_init_iss (void)
|
---|
524 | {
|
---|
525 | SYSTIM now;
|
---|
526 |
|
---|
527 | syscall(get_tim(&now));
|
---|
528 | net_srand(now);
|
---|
529 | tcp_iss = net_rand();
|
---|
530 | }
|
---|
531 |
|
---|
532 | /*
|
---|
533 | * tcp_close -- ã³ãã¯ã·ã§ã³ãéæ¾ããã
|
---|
534 | */
|
---|
535 |
|
---|
536 | T_TCP_CEP *
|
---|
537 | tcp_close (T_TCP_CEP *cep)
|
---|
538 | {
|
---|
539 | /* ã¿ã¤ãã¼ãåæ¢ããã*/
|
---|
540 | tcp_cancel_timers(cep);
|
---|
541 |
|
---|
542 | /*
|
---|
543 | * é信端ç¹ãããã¯ãã
|
---|
544 | * åä¿¡åæ§æãã¥ã¼ã®ãããã¯ã¼ã¯ãããã¡ã解æ¾ããã
|
---|
545 | */
|
---|
546 | syscall(wai_sem(cep->semid_lock));
|
---|
547 | tcp_free_reassq(cep);
|
---|
548 | syscall(sig_sem(cep->semid_lock));
|
---|
549 |
|
---|
550 | /* ç¶æ
|
---|
551 | ãæªä½¿ç¨ã«ããã*/
|
---|
552 | cep->fsm_state = TCP_FSM_CLOSED;
|
---|
553 |
|
---|
554 | /*
|
---|
555 | * 以ä¸ã«é¢ä¿ããªããã©ã°ãã¯ãªã¢ã¼ããã
|
---|
556 | * ã»éåä¿¡ã¦ã£ã³ããããã¡ã®çã³ãã¼æ©è½
|
---|
557 | * ã»åçãªé信端ç¹ã®çæã»åé¤æ©è½
|
---|
558 | * ã»é信端ç¹ã®ãããã¯ã¼ã¯å±¤ãããã³ã«
|
---|
559 | */
|
---|
560 | cep->flags &= TCP_CEP_FLG_NOT_CLEAR;
|
---|
561 |
|
---|
562 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
563 |
|
---|
564 | if (cep->snd_nblk_tfn != TFN_TCP_UNDEF || cep->rcv_nblk_tfn != TFN_TCP_UNDEF) {
|
---|
565 | /* ãã³ããããã³ã°ã³ã¼ã« */
|
---|
566 |
|
---|
567 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
568 |
|
---|
569 | if (!IS_PTR_DEFINED(cep->callback))
|
---|
570 | syslog(LOG_WARNING, "[TCP] no call back, CEP: %d.", GET_TCP_CEPID(cep));
|
---|
571 | else {
|
---|
572 | if (cep->rcv_nblk_tfn != TFN_TCP_UNDEF) {
|
---|
573 | ER_UINT len;
|
---|
574 |
|
---|
575 | switch (cep->rcv_nblk_tfn) {
|
---|
576 |
|
---|
577 | case TFN_TCP_ACP_CEP:
|
---|
578 | /* TCP é信端ç¹ããTCP åä»å£ã解æ¾ããã*/
|
---|
579 | cep->rep = NULL;
|
---|
580 |
|
---|
581 | #if defined(_IP6_CFG) && defined(_IP4_CFG)
|
---|
582 | cep->rep4 = NULL;
|
---|
583 | #endif
|
---|
584 |
|
---|
585 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)E_CLS);
|
---|
586 | break;
|
---|
587 |
|
---|
588 | case TFN_TCP_RCV_BUF:
|
---|
589 |
|
---|
590 | /* åä¿¡ã¦ã£ã³ããããã¡ã®ç©ºã¢ãã¬ã¹ãç²å¾ããã*/
|
---|
591 | len = TCP_GET_RWBUF_ADDR(cep, cep->rcv_p_buf);
|
---|
592 |
|
---|
593 | /* ç°å¸¸åæçã®ã¨ã©ã¼ãè¨å®ããã*/
|
---|
594 | if (cep->error == E_TMOUT)
|
---|
595 | len = E_CLS;
|
---|
596 | else if (cep->error < 0)
|
---|
597 | len = cep->error;
|
---|
598 |
|
---|
599 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)(uint32_t)len);
|
---|
600 | break;
|
---|
601 |
|
---|
602 | case TFN_TCP_RCV_DAT:
|
---|
603 |
|
---|
604 | /* åä¿¡ã¦ã£ã³ããããã¡ãããã¼ã¿ãåãåºãã*/
|
---|
605 | len = TCP_READ_RWBUF(cep, cep->rcv_data, (uint_t)cep->rcv_len);
|
---|
606 |
|
---|
607 | /* ç°å¸¸åæçã®ã¨ã©ã¼ãè¨å®ããã*/
|
---|
608 | if (cep->error == E_TMOUT)
|
---|
609 | len = E_CLS;
|
---|
610 | else if (cep->error != E_OK)
|
---|
611 | len = cep->error;
|
---|
612 |
|
---|
613 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)(uint32_t)len);
|
---|
614 | break;
|
---|
615 |
|
---|
616 | case TFN_TCP_CLS_CEP:
|
---|
617 |
|
---|
618 | if (cep->error == E_TMOUT)
|
---|
619 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)E_CLS);
|
---|
620 | else
|
---|
621 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)cep->error);
|
---|
622 | break;
|
---|
623 |
|
---|
624 | default:
|
---|
625 | syslog(LOG_WARNING, "[TCP] unexp TFN: %s.", in_strtfn((FN)cep->rcv_nblk_tfn));
|
---|
626 | break;
|
---|
627 | }
|
---|
628 |
|
---|
629 | /* è¨æ¶ããã¦ããã¿ã¹ã¯ ID 㨠API æ©è½ã³ã¼ããã¯ãªã¢ã¼ããã*/
|
---|
630 | cep->rcv_tskid = TA_NULL;
|
---|
631 | cep->rcv_tfn = cep->rcv_nblk_tfn = TFN_TCP_UNDEF;
|
---|
632 | }
|
---|
633 |
|
---|
634 | if (cep->snd_nblk_tfn != TFN_TCP_UNDEF) {
|
---|
635 |
|
---|
636 | switch (cep->snd_nblk_tfn) {
|
---|
637 |
|
---|
638 | case TFN_TCP_CON_CEP:
|
---|
639 | /* TCP é信端ç¹ãã TCP åä»å£ã解æ¾ããã*/
|
---|
640 | cep->rep = NULL;
|
---|
641 |
|
---|
642 | #if defined(_IP6_CFG) && defined(_IP4_CFG)
|
---|
643 | cep->rep4 = NULL;
|
---|
644 | #endif
|
---|
645 |
|
---|
646 | (*cep->callback)(GET_TCP_CEPID(cep), cep->snd_nblk_tfn, (void*)E_CLS);
|
---|
647 | break;
|
---|
648 |
|
---|
649 | case TFN_TCP_SND_DAT:
|
---|
650 | case TFN_TCP_GET_BUF:
|
---|
651 | if (cep->error == E_TMOUT)
|
---|
652 | (*cep->callback)(GET_TCP_CEPID(cep), cep->snd_nblk_tfn, (void*)E_CLS);
|
---|
653 | else
|
---|
654 | (*cep->callback)(GET_TCP_CEPID(cep), cep->snd_nblk_tfn, (void*)cep->error);
|
---|
655 | break;
|
---|
656 |
|
---|
657 | default:
|
---|
658 | syslog(LOG_WARNING, "[TCP] unexp TFN: %s.", in_strtfn((FN)cep->snd_nblk_tfn));
|
---|
659 | break;
|
---|
660 | }
|
---|
661 |
|
---|
662 | /* è¨æ¶ããã¦ããã¿ã¹ã¯ ID 㨠API æ©è½ã³ã¼ããã¯ãªã¢ã¼ããã*/
|
---|
663 | cep->snd_tskid = TA_NULL;
|
---|
664 | cep->snd_tfn = cep->snd_nblk_tfn = TFN_TCP_UNDEF;
|
---|
665 | }
|
---|
666 |
|
---|
667 | }
|
---|
668 |
|
---|
669 | #else /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
670 |
|
---|
671 | if (!IS_PTR_DEFINED(cep->callback))
|
---|
672 | syslog(LOG_WARNING, "[TCP] no call back, CEP: %d.", GET_TCP_CEPID(cep));
|
---|
673 | else {
|
---|
674 | if (cep->rcv_nblk_tfn != TFN_TCP_UNDEF) {
|
---|
675 | ER_UINT len;
|
---|
676 |
|
---|
677 | switch (cep->rcv_nblk_tfn) {
|
---|
678 |
|
---|
679 | case TFN_TCP_ACP_CEP:
|
---|
680 |
|
---|
681 | /* TCP é信端ç¹ããTCP åä»å£ã解æ¾ããã*/
|
---|
682 | cep->rep = NULL;
|
---|
683 |
|
---|
684 | #if defined(_IP6_CFG) && defined(_IP4_CFG)
|
---|
685 | cep->rep4 = NULL;
|
---|
686 | #endif
|
---|
687 |
|
---|
688 | /* æ¥ç¶ã¨ã©ã¼ãè¨å®ããã*/
|
---|
689 | len = E_CLS;
|
---|
690 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)&len);
|
---|
691 | break;
|
---|
692 |
|
---|
693 | case TFN_TCP_RCV_BUF:
|
---|
694 |
|
---|
695 | /* åä¿¡ã¦ã£ã³ããããã¡ã®ç©ºã¢ãã¬ã¹ãç²å¾ããã*/
|
---|
696 | len = TCP_GET_RWBUF_ADDR(cep, cep->rcv_p_buf);
|
---|
697 |
|
---|
698 | /* ç°å¸¸åæçã®ã¨ã©ã¼ãè¨å®ããã*/
|
---|
699 | if (cep->error == E_TMOUT)
|
---|
700 | len = E_CLS;
|
---|
701 | else if (cep->error < 0)
|
---|
702 | len = cep->error;
|
---|
703 |
|
---|
704 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)&len);
|
---|
705 | break;
|
---|
706 |
|
---|
707 | case TFN_TCP_RCV_DAT:
|
---|
708 |
|
---|
709 | /* åä¿¡ã¦ã£ã³ããããã¡ãããã¼ã¿ãåãåºãã*/
|
---|
710 | len = TCP_READ_RWBUF(cep, cep->rcv_data, (uint_t)cep->rcv_len);
|
---|
711 |
|
---|
712 | /* ç°å¸¸åæçã®ã¨ã©ã¼ãè¨å®ããã*/
|
---|
713 | if (cep->error == E_TMOUT)
|
---|
714 | len = E_CLS;
|
---|
715 | else if (cep->error != E_OK)
|
---|
716 | len = cep->error;
|
---|
717 |
|
---|
718 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)&len);
|
---|
719 | break;
|
---|
720 |
|
---|
721 | case TFN_TCP_CLS_CEP:
|
---|
722 | if (cep->error == E_TMOUT)
|
---|
723 | len = E_CLS;
|
---|
724 | else
|
---|
725 | len = cep->error;
|
---|
726 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)&len);
|
---|
727 | break;
|
---|
728 |
|
---|
729 | default:
|
---|
730 | syslog(LOG_WARNING, "[TCP] unexp TFN: %s.", in_strtfn((FN)cep->rcv_nblk_tfn));
|
---|
731 | break;
|
---|
732 | }
|
---|
733 |
|
---|
734 | /* è¨æ¶ããã¦ããã¿ã¹ã¯ ID 㨠API æ©è½ã³ã¼ããã¯ãªã¢ã¼ããã*/
|
---|
735 | cep->rcv_tskid = TA_NULL;
|
---|
736 | cep->rcv_tfn = cep->rcv_nblk_tfn = TFN_TCP_UNDEF;
|
---|
737 | }
|
---|
738 |
|
---|
739 | if (cep->snd_nblk_tfn != TFN_TCP_UNDEF) {
|
---|
740 | ER_UINT len;
|
---|
741 |
|
---|
742 | switch (cep->snd_nblk_tfn) {
|
---|
743 |
|
---|
744 | case TFN_TCP_CON_CEP:
|
---|
745 |
|
---|
746 | /* TCP é信端ç¹ããTCP åä»å£ã解æ¾ããã*/
|
---|
747 | cep->rep = NULL;
|
---|
748 |
|
---|
749 | #if defined(_IP6_CFG) && defined(_IP4_CFG)
|
---|
750 | cep->rep4 = NULL;
|
---|
751 | #endif
|
---|
752 |
|
---|
753 | /* æ¥ç¶ã¨ã©ã¼ãè¨å®ããã*/
|
---|
754 | len = E_CLS;
|
---|
755 | (*cep->callback)(GET_TCP_CEPID(cep), cep->snd_nblk_tfn, (void*)&len);
|
---|
756 | break;
|
---|
757 |
|
---|
758 | case TFN_TCP_SND_DAT:
|
---|
759 | case TFN_TCP_GET_BUF:
|
---|
760 | if (cep->error == E_TMOUT)
|
---|
761 | len = E_CLS;
|
---|
762 | else
|
---|
763 | len = cep->error;
|
---|
764 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)&len);
|
---|
765 | break;
|
---|
766 |
|
---|
767 | default:
|
---|
768 | syslog(LOG_WARNING, "[TCP] unexp TFN: %s.", in_strtfn((FN)cep->snd_nblk_tfn));
|
---|
769 | break;
|
---|
770 | }
|
---|
771 |
|
---|
772 | /* è¨æ¶ããã¦ããã¿ã¹ã¯ ID 㨠API æ©è½ã³ã¼ããã¯ãªã¢ã¼ããã*/
|
---|
773 | cep->snd_tskid = TA_NULL;
|
---|
774 | cep->snd_tfn = cep->snd_nblk_tfn = TFN_TCP_UNDEF;
|
---|
775 | }
|
---|
776 |
|
---|
777 | }
|
---|
778 |
|
---|
779 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
780 |
|
---|
781 | /*
|
---|
782 | * é信端ç¹ãããã¯ãã
|
---|
783 | * éåä¿¡ã¦ã£ã³ããããã¡ãã¥ã¼ã®ãããã¯ã¼ã¯ãããã¡ã解æ¾ããã
|
---|
784 | */
|
---|
785 | syscall(wai_sem(cep->semid_lock));
|
---|
786 | TCP_FREE_RWBUFQ(cep);
|
---|
787 | TCP_FREE_SWBUFQ(cep);
|
---|
788 | syscall(sig_sem(cep->semid_lock));
|
---|
789 |
|
---|
790 | /* æªä½¿ç¨ã«ãªã£ããã¨ãç¥ãããã*/
|
---|
791 | syscall(set_flg(cep->est_flgid, TCP_CEP_EVT_CLOSED));
|
---|
792 | }
|
---|
793 | else { /* éãã³ããããã³ã°ã³ã¼ã« */
|
---|
794 |
|
---|
795 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
796 |
|
---|
797 | /* è¨æ¶ããã¦ããã¿ã¹ã¯ ID 㨠API æ©è½ã³ã¼ããã¯ãªã¢ã¼ããã*/
|
---|
798 | cep->snd_tskid = cep->rcv_tskid = TA_NULL;
|
---|
799 | cep->snd_tfn = cep->rcv_tfn = TFN_TCP_UNDEF;
|
---|
800 |
|
---|
801 | /*
|
---|
802 | * é信端ç¹ãããã¯ãã
|
---|
803 | * éåä¿¡ã¦ã£ã³ããããã¡ãã¥ã¼ã®ãããã¯ã¼ã¯ãããã¡ã解æ¾ããã
|
---|
804 | */
|
---|
805 | syscall(wai_sem(cep->semid_lock));
|
---|
806 | TCP_FREE_RWBUFQ(cep);
|
---|
807 | TCP_FREE_SWBUFQ(cep);
|
---|
808 | syscall(sig_sem(cep->semid_lock));
|
---|
809 |
|
---|
810 | /* æªä½¿ç¨ã«ãªã£ããã¨ãç¥ãããã*/
|
---|
811 | syscall(set_flg(cep->est_flgid, TCP_CEP_EVT_CLOSED));
|
---|
812 |
|
---|
813 | /*
|
---|
814 | * å
|
---|
815 | ¥åºåã¿ã¹ã¯ãèµ·åºãã¦ã
|
---|
816 | * éåä¿¡ä¸å¯ã«ãªã£ããã¨ãç¥ãããã
|
---|
817 | */
|
---|
818 | syscall(set_flg(cep->snd_flgid, TCP_CEP_EVT_SWBUF_READY));
|
---|
819 | syscall(set_flg(cep->rcv_flgid, TCP_CEP_EVT_RWBUF_READY));
|
---|
820 |
|
---|
821 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
822 |
|
---|
823 | }
|
---|
824 |
|
---|
825 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
826 |
|
---|
827 | return NULL;
|
---|
828 | }
|
---|
829 |
|
---|
830 | /*
|
---|
831 | * tcp_drop -- TCP æ¥ç¶ãç ´æ£ããã
|
---|
832 | */
|
---|
833 |
|
---|
834 | T_TCP_CEP *
|
---|
835 | tcp_drop (T_TCP_CEP *cep, ER errno)
|
---|
836 | {
|
---|
837 | #ifdef SUPPORT_MIB
|
---|
838 |
|
---|
839 | if ((cep->fsm_state == TCP_FSM_SYN_SENT) || (cep->fsm_state == TCP_FSM_SYN_RECVD)) {
|
---|
840 | NET_COUNT_MIB(tcp_stats.tcpAttemptFails, 1);
|
---|
841 | }
|
---|
842 |
|
---|
843 | #endif /* of #ifdef SUPPORT_MIB */
|
---|
844 |
|
---|
845 | cep->error = errno;
|
---|
846 | if (TCP_FSM_HAVE_RCVD_SYN(cep->fsm_state)) {
|
---|
847 | cep->fsm_state = TCP_FSM_CLOSED;
|
---|
848 |
|
---|
849 | /* éä¿¡ã¨ãéä¿¡å¾ã³ãã¯ã·ã§ã³ã®åæãæ示ããã*/
|
---|
850 | cep->flags |= TCP_CEP_FLG_POST_OUTPUT | TCP_CEP_FLG_CLOSE_AFTER_OUTPUT;
|
---|
851 | sig_sem(SEM_TCP_POST_OUTPUT);
|
---|
852 | }
|
---|
853 | else {
|
---|
854 | cep = tcp_close(cep);
|
---|
855 | }
|
---|
856 | return cep;
|
---|
857 | }
|
---|
858 |
|
---|
859 | /*
|
---|
860 | * tcp_respond -- TCP ã®åä¸ã¡ãã»ã¼ã¸ãéä¿¡ããã
|
---|
861 | */
|
---|
862 |
|
---|
863 | void
|
---|
864 | tcp_respond (T_NET_BUF *output, T_TCP_CEP *cep,
|
---|
865 | T_TCP_SEQ ack, T_TCP_SEQ seq, uint_t rbfree, uint8_t flags)
|
---|
866 | {
|
---|
867 | T_TCP_HDR *tcph;
|
---|
868 | uint_t win = 0;
|
---|
869 | uint_t hdr_offset;
|
---|
870 |
|
---|
871 | if ((flags & TCP_FLG_RST) == 0)
|
---|
872 | win = rbfree;
|
---|
873 |
|
---|
874 | /*
|
---|
875 | * output ã NULL ã§ãªããã°ãããã¯å
|
---|
876 | ¥åããã»ã°ã¡ã³ãã®
|
---|
877 | * net_buf ã§ããã®ã¾ã¾åå©ç¨ããã
|
---|
878 | */
|
---|
879 | if (output != NULL) {
|
---|
880 | uint16_t portno;
|
---|
881 |
|
---|
882 | /*
|
---|
883 | * IPv4 ã§ã¯ãIP ãããã®ãªãã·ã§ã³ãåé¤ããã
|
---|
884 | * IPv6 ã§ã¯ãæ¡å¼µããããåé¤ããã
|
---|
885 | */
|
---|
886 | if (IP_REMOVE_OPTIONS(output) != E_OK) {
|
---|
887 | syscall(rel_net_buf(output));
|
---|
888 | return;
|
---|
889 | }
|
---|
890 |
|
---|
891 | ip_exchg_addr(output);
|
---|
892 |
|
---|
893 | #if defined(_IP6_CFG)
|
---|
894 |
|
---|
895 | /* ãã©ããã¯ã¯ã©ã¹ã¨ããã¼ã©ãã«ãã¯ãªã¢ããã*/
|
---|
896 | SET_IP_CF(output, 0);
|
---|
897 |
|
---|
898 | #endif /* of #if defined(_IP6_CFG) */
|
---|
899 |
|
---|
900 | /* TCP SDU é·ã 0 ã«ããã*/
|
---|
901 | SET_IP_SDU_SIZE(output, TCP_HDR_SIZE);
|
---|
902 |
|
---|
903 | tcph = GET_TCP_HDR(output, IF_IP_TCP_HDR_OFFSET(output));
|
---|
904 |
|
---|
905 | /* ãã¼ãçªå·ã交æããã*/
|
---|
906 | portno = tcph->sport;
|
---|
907 | tcph->sport = tcph->dport;
|
---|
908 | tcph->dport = portno;
|
---|
909 |
|
---|
910 | /* TCP ãããã«æ
|
---|
911 | å ±ãè¨å®ããã*/
|
---|
912 | tcph->doff = TCP_MAKE_DATA_OFF(TCP_HDR_SIZE);
|
---|
913 | }
|
---|
914 |
|
---|
915 | /* cep ã NULL ã§ããã°ãä½ãããªãã§çµäºããã*/
|
---|
916 | else if (cep == NULL)
|
---|
917 | return;
|
---|
918 | else {
|
---|
919 | if (tcpn_get_segment(&output, cep, 0,
|
---|
920 | 0, (uint_t)net_buf_max_siz(),
|
---|
921 | NBA_SEARCH_ASCENT, TMO_TCP_GET_NET_BUF) != E_OK)
|
---|
922 | return;
|
---|
923 | tcph = GET_TCP_HDR(output, IF_IP_TCP_HDR_OFFSET(output));
|
---|
924 | flags |= TCP_FLG_ACK;
|
---|
925 | }
|
---|
926 |
|
---|
927 | tcph->seq = htonl(seq);
|
---|
928 | tcph->ack = htonl(ack);
|
---|
929 | tcph->win = htons(win);
|
---|
930 | tcph->flags = flags;
|
---|
931 | tcph->urp = tcph->sum = 0;
|
---|
932 |
|
---|
933 | /*
|
---|
934 | * ãã§ãã¯ãµã ãè¨å®ããã
|
---|
935 | */
|
---|
936 | hdr_offset = IF_IP_TCP_HDR_OFFSET(output);
|
---|
937 | tcph->sum = IN_CKSUM(output, IPPROTO_TCP, hdr_offset,
|
---|
938 | (uint_t)GET_TCP_HDR_SIZE(output, hdr_offset));
|
---|
939 |
|
---|
940 | /* ãããã¯ã¼ã¯ãããã¡é·ã調æ´ããã*/
|
---|
941 | output->len = (uint16_t)GET_IF_IP_TCP_HDR_SIZE(output, hdr_offset);
|
---|
942 |
|
---|
943 | #ifdef TCP_CFG_TRACE
|
---|
944 |
|
---|
945 | tcp_output_trace(output, cep);
|
---|
946 |
|
---|
947 | #endif /* of #ifdef TCP_CFG_TRACE */
|
---|
948 |
|
---|
949 | /* ãããã¯ã¼ã¯å±¤ (IP) ã®åºåé¢æ°ãå¼ã³åºãã*/
|
---|
950 | IP_OUTPUT(output, TMO_TCP_OUTPUT);
|
---|
951 | }
|
---|
952 | #if 0
|
---|
953 | /*
|
---|
954 | * tcp_get_segment -- TCP ã»ã°ã¡ã³ããç²å¾ããããããè¨å®ããã
|
---|
955 | *
|
---|
956 | * æ»ãå¤ ã¨ã©ã¼ã³ã¼ã
|
---|
957 | * optlen ãªãã·ã§ã³ãµã¤ãºã4 ãªã¯ãããåä½
|
---|
958 | * maxlen æ大ã»ã°ã¡ã³ããµã¤ãºï¼IF/IP/TCP ããããµã¤ãºãå«ã¾ãªãï¼
|
---|
959 | * len TCP SDU ãµã¤ãº
|
---|
960 | */
|
---|
961 |
|
---|
962 | ER
|
---|
963 | tcp_get_segment (T_NET_BUF **nbuf, T_TCP_CEP *cep,
|
---|
964 | uint_t optlen, uint_t len, uint_t maxlen, ATR nbatr, TMO tmout)
|
---|
965 | {
|
---|
966 | T_TCP_HDR *tcph;
|
---|
967 | ER error;
|
---|
968 |
|
---|
969 | /* IP ãã¼ã¿ã°ã©ã ãç²å¾ããã*/
|
---|
970 | if ((error = IN_GET_DATAGRAM(nbuf,
|
---|
971 | (uint_t)(TCP_HDR_SIZE + optlen + len),
|
---|
972 | (uint_t)(TCP_HDR_SIZE + maxlen),
|
---|
973 | &cep->dstaddr.ipaddr,
|
---|
974 | &cep->myaddr.ipaddr,
|
---|
975 | IPPROTO_TCP, IP_DEFTTL, nbatr, tmout)) != E_OK) {
|
---|
976 | syslog(LOG_WARNING, "[TCP] NET BUF busy, len: %d, CEP: %d.",
|
---|
977 | (uint16_t)(TCP_HDR_SIZE + optlen + len), GET_TCP_CEPID(cep));
|
---|
978 | return error;
|
---|
979 | }
|
---|
980 |
|
---|
981 | /* TCP ãããã«æ
|
---|
982 | å ±ãè¨å®ããã*/
|
---|
983 |
|
---|
984 | /* TCP ãããã«æ
|
---|
985 | å ±ãè¨å®ããã*/
|
---|
986 | tcph = GET_TCP_HDR(*nbuf, IF_IP_TCP_HDR_OFFSET(*nbuf));
|
---|
987 | tcph->sport = htons(cep->myaddr.portno);
|
---|
988 | tcph->dport = htons(cep->dstaddr.portno);
|
---|
989 | tcph->doff = TCP_MAKE_DATA_OFF(TCP_HDR_SIZE + optlen);
|
---|
990 | tcph->sum = tcph->flags = 0;
|
---|
991 |
|
---|
992 | return E_OK;
|
---|
993 | }
|
---|
994 | #endif
|
---|
995 | /*
|
---|
996 | * tcpn_get_segment -- TCP ã»ã°ã¡ã³ããç²å¾ããããããè¨å®ããã
|
---|
997 | *
|
---|
998 | * æ»ãå¤ ã¨ã©ã¼ã³ã¼ã
|
---|
999 | * optlen ãªãã·ã§ã³ãµã¤ãºã4 ãªã¯ãããåä½
|
---|
1000 | * maxlen æ大ã»ã°ã¡ã³ããµã¤ãºï¼IF/IP/TCP ããããµã¤ãºãå«ãï¼
|
---|
1001 | * len TCP SDU ãµã¤ãº
|
---|
1002 | */
|
---|
1003 |
|
---|
1004 | ER
|
---|
1005 | tcpn_get_segment (T_NET_BUF **nbuf, T_TCP_CEP *cep,
|
---|
1006 | uint_t optlen, uint_t len, uint_t maxlen, ATR nbatr, TMO tmout)
|
---|
1007 | {
|
---|
1008 | T_TCP_HDR *tcph;
|
---|
1009 | ER error;
|
---|
1010 |
|
---|
1011 | /* IP ãã¼ã¿ã°ã©ã ãç²å¾ããã*/
|
---|
1012 | if ((error = IN_GET_DATAGRAM(nbuf,
|
---|
1013 | (uint_t)(TCP_HDR_SIZE + optlen + len),
|
---|
1014 | (uint_t)(maxlen - IF_IP_NET_HDR_SIZE(&cep->dstaddr.ipaddr)),
|
---|
1015 | &cep->dstaddr.ipaddr,
|
---|
1016 | &cep->myaddr.ipaddr,
|
---|
1017 | IPPROTO_TCP, IP_DEFTTL, nbatr, tmout)) != E_OK) {
|
---|
1018 | syslog(LOG_WARNING, "[TCP] NET BUF busy, len:%4d, CEP: %d.",
|
---|
1019 | (uint16_t)(TCP_HDR_SIZE + optlen + len), GET_TCP_CEPID(cep));
|
---|
1020 | return error;
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | /* TCP ãããã«æ
|
---|
1024 | å ±ãè¨å®ããã*/
|
---|
1025 |
|
---|
1026 | /* TCP ãããã«æ
|
---|
1027 | å ±ãè¨å®ããã*/
|
---|
1028 | tcph = GET_TCP_HDR(*nbuf, IF_IP_TCP_HDR_OFFSET(*nbuf));
|
---|
1029 | tcph->sport = htons(cep->myaddr.portno);
|
---|
1030 | tcph->dport = htons(cep->dstaddr.portno);
|
---|
1031 | tcph->doff = TCP_MAKE_DATA_OFF(TCP_HDR_SIZE + optlen);
|
---|
1032 | tcph->sum = tcph->flags = 0;
|
---|
1033 |
|
---|
1034 | return E_OK;
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | /*
|
---|
1038 | * tcp_can_send_more -- éä¿¡ã§ããããé信端ç¹ã®ç¶æ
|
---|
1039 | ãè¦ãã
|
---|
1040 | */
|
---|
1041 |
|
---|
1042 | ER
|
---|
1043 | tcp_can_send_more (T_TCP_CEP *cep, FN fncd, TMO tmout)
|
---|
1044 | {
|
---|
1045 | ER error;
|
---|
1046 |
|
---|
1047 | /* éä¿¡ã§ããããCEP ã® FSM ç¶æ
|
---|
1048 | ãè¦ãã*/
|
---|
1049 | if (!TCP_FSM_CAN_SEND_MORE(cep->fsm_state)) {
|
---|
1050 | if ((error = cep->error) == E_OK)
|
---|
1051 | error = E_OBJ;
|
---|
1052 |
|
---|
1053 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
1054 |
|
---|
1055 | /* ã¿ã¤ã ã¢ã¦ãããã§ãã¯ããã*/
|
---|
1056 | if (tmout == TMO_NBLK) { /* ãã³ããããã³ã°ã³ã¼ã« */
|
---|
1057 |
|
---|
1058 | if (!IS_PTR_DEFINED(cep->callback))
|
---|
1059 | error = E_OBJ;
|
---|
1060 | else {
|
---|
1061 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
1062 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
1063 | (*cep->callback)(GET_TCP_CEPID(cep), fncd, (void*)error);
|
---|
1064 | #else
|
---|
1065 | (*cep->callback)(GET_TCP_CEPID(cep), fncd, (void*)&error);
|
---|
1066 | #endif
|
---|
1067 | error = E_WBLK;
|
---|
1068 | }
|
---|
1069 | }
|
---|
1070 |
|
---|
1071 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
1072 |
|
---|
1073 | }
|
---|
1074 | else {
|
---|
1075 |
|
---|
1076 | #ifdef TCP_CFG_SWBUF_CSAVE
|
---|
1077 |
|
---|
1078 | error = E_OK;
|
---|
1079 |
|
---|
1080 | #else /* of #ifdef TCP_CFG_SWBUF_CSAVE */
|
---|
1081 |
|
---|
1082 | if (!IS_PTR_DEFINED(cep->sbuf)) {
|
---|
1083 |
|
---|
1084 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
1085 |
|
---|
1086 | /* ã¿ã¤ã ã¢ã¦ãããã§ãã¯ããã*/
|
---|
1087 | if (tmout == TMO_NBLK) { /* ãã³ããããã³ã°ã³ã¼ã« */
|
---|
1088 | if (!IS_PTR_DEFINED(cep->callback))
|
---|
1089 | error = E_OBJ;
|
---|
1090 | else {
|
---|
1091 | error = E_OBJ;
|
---|
1092 |
|
---|
1093 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
1094 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
1095 | (*cep->callback)(GET_TCP_CEPID(cep), fncd, (void*)error);
|
---|
1096 | #else
|
---|
1097 | (*cep->callback)(GET_TCP_CEPID(cep), fncd, (void*)&error);
|
---|
1098 | #endif
|
---|
1099 | error = E_WBLK;
|
---|
1100 | }
|
---|
1101 | }
|
---|
1102 | else
|
---|
1103 |
|
---|
1104 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
1105 |
|
---|
1106 | error = E_OBJ;
|
---|
1107 | }
|
---|
1108 | else
|
---|
1109 | error = E_OK;
|
---|
1110 |
|
---|
1111 | #endif /* of #ifdef TCP_CFG_SWBUF_CSAVE */
|
---|
1112 |
|
---|
1113 | }
|
---|
1114 |
|
---|
1115 | return error;
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 | /*
|
---|
1119 | * tcp_can_recv_more -- åä¿¡ã§ããããé信端ç¹ã®ç¶æ
|
---|
1120 | ãè¦ãã
|
---|
1121 | *
|
---|
1122 | * 注æ: æ»ãå¤
|
---|
1123 | *
|
---|
1124 | * E_OK åä¿¡å¯è½
|
---|
1125 | * E_OBJ ç¸æããåæãããããã¨ã©ã¼ãçºçããã
|
---|
1126 | */
|
---|
1127 |
|
---|
1128 | ER
|
---|
1129 | tcp_can_recv_more (ER *error, T_TCP_CEP *cep, FN fncd, TMO tmout)
|
---|
1130 | {
|
---|
1131 | /*
|
---|
1132 | * åä¿¡ã§ããããfsm_state ãè¦ããåä¿¡ã§ããªãå ´åã¯
|
---|
1133 | * é·ã 0ãã¾ãã¯ã¨ã©ã¼ãè¿ãã
|
---|
1134 | */
|
---|
1135 | if (!TCP_FSM_CAN_RECV_MORE(cep->fsm_state) &&
|
---|
1136 | cep->rwbuf_count == 0 && cep->reassq == NULL) {
|
---|
1137 | *error = cep->error;
|
---|
1138 |
|
---|
1139 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
1140 |
|
---|
1141 | /* ã¿ã¤ã ã¢ã¦ãããã§ãã¯ããã*/
|
---|
1142 | if (tmout == TMO_NBLK) { /* ãã³ããããã³ã°ã³ã¼ã« */
|
---|
1143 |
|
---|
1144 | if (!IS_PTR_DEFINED(cep->callback))
|
---|
1145 | *error = E_OBJ;
|
---|
1146 | else {
|
---|
1147 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
1148 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
1149 | (*cep->callback)(GET_TCP_CEPID(cep), fncd, (void*)*error);
|
---|
1150 | #else
|
---|
1151 | (*cep->callback)(GET_TCP_CEPID(cep), fncd, (void*)error);
|
---|
1152 | #endif
|
---|
1153 | *error = E_WBLK;
|
---|
1154 | }
|
---|
1155 | }
|
---|
1156 |
|
---|
1157 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
1158 |
|
---|
1159 | /*
|
---|
1160 | * é信端ç¹ãããã¯ãã¦ã
|
---|
1161 | * åä¿¡ã¦ã£ã³ããããã¡ãã¥ã¼ã®ãããã¯ã¼ã¯ãããã¡ã解æ¾ããã
|
---|
1162 | */
|
---|
1163 | syscall(wai_sem(cep->semid_lock));
|
---|
1164 | TCP_FREE_RWBUFQ(cep);
|
---|
1165 | syscall(sig_sem(cep->semid_lock));
|
---|
1166 |
|
---|
1167 | return E_OBJ;
|
---|
1168 | }
|
---|
1169 | else {
|
---|
1170 |
|
---|
1171 | #ifndef TCP_CFG_RWBUF_CSAVE
|
---|
1172 |
|
---|
1173 | if (!IS_PTR_DEFINED(cep->rbuf)) {
|
---|
1174 |
|
---|
1175 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
1176 |
|
---|
1177 | /* ã¿ã¤ã ã¢ã¦ãããã§ãã¯ããã*/
|
---|
1178 | if (tmout == TMO_NBLK) { /* ãã³ããããã³ã°ã³ã¼ã« */
|
---|
1179 | if (!IS_PTR_DEFINED(cep->callback))
|
---|
1180 | *error = E_OBJ;
|
---|
1181 | else {
|
---|
1182 | *error = E_OBJ;
|
---|
1183 |
|
---|
1184 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
1185 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
1186 | (*cep->callback)(GET_TCP_CEPID(cep), fncd, (void*)*error);
|
---|
1187 | #else
|
---|
1188 | (*cep->callback)(GET_TCP_CEPID(cep), fncd, (void*)error);
|
---|
1189 | #endif
|
---|
1190 | *error = E_WBLK;
|
---|
1191 | }
|
---|
1192 | }
|
---|
1193 | else
|
---|
1194 |
|
---|
1195 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
1196 |
|
---|
1197 | *error = E_OBJ;
|
---|
1198 |
|
---|
1199 | return E_OBJ;
|
---|
1200 | }
|
---|
1201 |
|
---|
1202 | #endif /* of #ifndef TCP_CFG_RWBUF_CSAVE */
|
---|
1203 |
|
---|
1204 | return E_OK;
|
---|
1205 | }
|
---|
1206 | }
|
---|
1207 |
|
---|
1208 | /*
|
---|
1209 | * tcp_wait_rwbuf -- åä¿¡ã¦ã£ã³ããããã¡ã«ãã¼ã¿ãå
|
---|
1210 | ¥ãã®ãå¾
|
---|
1211 | ã¤ã
|
---|
1212 | */
|
---|
1213 |
|
---|
1214 | ER
|
---|
1215 | tcp_wait_rwbuf (T_TCP_CEP *cep, TMO tmout)
|
---|
1216 | {
|
---|
1217 | ER error;
|
---|
1218 | FLGPTN flag;
|
---|
1219 |
|
---|
1220 | if (cep->rwbuf_count == 0) {
|
---|
1221 | /* åä¿¡ã¦ã£ã³ããããã¡ã«ãã¼ã¿ããªããã°ãå
|
---|
1222 | ¥åãããã¾ã§å¾
|
---|
1223 | ã¤ã*/
|
---|
1224 | while (cep->rwbuf_count == 0) {
|
---|
1225 | if ((error = twai_flg(cep->rcv_flgid, TCP_CEP_EVT_RWBUF_READY, TWF_ORW, &flag, tmout)) != E_OK) {
|
---|
1226 | return error;
|
---|
1227 | }
|
---|
1228 | syscall(clr_flg(cep->rcv_flgid, (FLGPTN)(~TCP_CEP_EVT_RWBUF_READY)));
|
---|
1229 |
|
---|
1230 | /*
|
---|
1231 | * åä¿¡ã§ããããfsm_state ãè¦ããåä¿¡ã§ããªãç¶æ
|
---|
1232 | ã§ã
|
---|
1233 | * åä¿¡ã¦ã£ã³ããããã¡ã«æåããªãå ´åã¯çµäºããã
|
---|
1234 | */
|
---|
1235 | if (!TCP_FSM_CAN_RECV_MORE(cep->fsm_state) &&
|
---|
1236 | cep->rwbuf_count == 0 && cep->reassq == NULL) {
|
---|
1237 |
|
---|
1238 | /*
|
---|
1239 | * é信端ç¹ãããã¯ãã¦ã
|
---|
1240 | * åä¿¡ã¦ã£ã³ããããã¡ãã¥ã¼ã®ãããã¯ã¼ã¯ãããã¡ã解æ¾ããã
|
---|
1241 | */
|
---|
1242 | syscall(wai_sem(cep->semid_lock));
|
---|
1243 | TCP_FREE_RWBUFQ(cep);
|
---|
1244 | syscall(sig_sem(cep->semid_lock));
|
---|
1245 |
|
---|
1246 | return cep->error;
|
---|
1247 | }
|
---|
1248 | }
|
---|
1249 | }
|
---|
1250 | else {
|
---|
1251 | syscall(clr_flg(cep->rcv_flgid, (FLGPTN)(~TCP_CEP_EVT_RWBUF_READY)));
|
---|
1252 | }
|
---|
1253 |
|
---|
1254 | return E_OK;
|
---|
1255 | }
|
---|
1256 |
|
---|
1257 | /*
|
---|
1258 | * tcp_move_ra2rw -- åä¿¡åæ§æãã¥ã¼ã§åæ§æããã»ã°ã¡ã³ããåä¿¡ã¦ã£ã³ããããã¡ã«æ¸ãè¾¼ãã
|
---|
1259 | */
|
---|
1260 |
|
---|
1261 | uint8_t
|
---|
1262 | tcp_move_ra2rw (T_TCP_CEP *cep, uint8_t flags)
|
---|
1263 | {
|
---|
1264 | T_NET_BUF *q;
|
---|
1265 | T_TCP_Q_HDR *qhdr;
|
---|
1266 |
|
---|
1267 | /*
|
---|
1268 | * åä¿¡ãã¼ã¿ãåä¿¡ã¦ã£ã³ããããã¡ã«æ¸ãè¾¼ã¿ã
|
---|
1269 | * rcv_nxt ãå®äºãã SEQ ã ãé²ããã
|
---|
1270 | */
|
---|
1271 | if (TCP_FSM_HAVE_ESTABLISHED(cep->fsm_state)) {
|
---|
1272 | while (cep->reassq != NULL) {
|
---|
1273 | q = cep->reassq;
|
---|
1274 | qhdr = GET_TCP_Q_HDR(q, GET_IP_TCP_Q_HDR_OFFSET(q));
|
---|
1275 | if (qhdr->seq != cep->rcv_nxt)
|
---|
1276 | break;
|
---|
1277 |
|
---|
1278 | /* 次ã®ã»ã°ã¡ã³ãã«é²ãã*/
|
---|
1279 | cep->reassq = qhdr->next;
|
---|
1280 |
|
---|
1281 | /* FIN ãã©ã°ã®ã¿æ®ãã*/
|
---|
1282 | flags &= TCP_FLG_FIN;
|
---|
1283 |
|
---|
1284 | /* ãã¼ã¿ãåä¿¡ã¦ã£ã³ããããã¡ã«æ¸ãè¾¼ãã*/
|
---|
1285 | TCP_WRITE_RWBUF(cep, q, (uint_t)(GET_IP_TCP_Q_HDR_OFFSET(q)));
|
---|
1286 | }
|
---|
1287 | }
|
---|
1288 | if (cep->reassq != NULL) {
|
---|
1289 | cep->flags |= TCP_CEP_FLG_ACK_NOW;
|
---|
1290 | flags &= ~TCP_FLG_FIN;
|
---|
1291 | }
|
---|
1292 | return flags;
|
---|
1293 | }
|
---|
1294 |
|
---|
1295 | /*
|
---|
1296 | * tcp_write_raque -- åä¿¡ã»ã°ã¡ã³ããåæ§æãã¦ãåä¿¡åæ§æãã¥ã¼ã«ç¹ãã
|
---|
1297 | */
|
---|
1298 |
|
---|
1299 | uint8_t
|
---|
1300 | tcp_write_raque (T_NET_BUF *input, T_TCP_CEP *cep, uint_t thoff, uint8_t flags)
|
---|
1301 | {
|
---|
1302 | T_NET_BUF *new;
|
---|
1303 | T_NET_BUF *p, *q, *nq;
|
---|
1304 | T_TCP_Q_HDR *qhdr, *inqhdr = GET_TCP_Q_HDR(input, thoff);
|
---|
1305 | int32_t len;
|
---|
1306 |
|
---|
1307 | /* TCP ãããã®ä½ç½®ãä¿åããã*/
|
---|
1308 | SET_IP_TCP_Q_HDR_OFFSET(input, thoff);
|
---|
1309 |
|
---|
1310 | /*
|
---|
1311 | * MAX_TCP_REALLOC_SIZE 以ä¸ã®å ´åã¯ãæ°ãã«ãããã¯ã¼ã¯ãããã¡ã
|
---|
1312 | * å²å½ã¦ã¦ããã¼ã¿ãã³ãã¼ããã
|
---|
1313 | * ãã®ã¨ããIP ã®ãªãã·ã§ã³ï¼æ¡å¼µãããï¼ã¨ TCP ã®ãªãã·ã§ã³ã¯åé¤ããã
|
---|
1314 | */
|
---|
1315 | len = IF_IP_TCP_HDR_SIZE(input) + inqhdr->slen;
|
---|
1316 |
|
---|
1317 | if (len <= MAX_TCP_REALLOC_SIZE) {
|
---|
1318 |
|
---|
1319 | /*
|
---|
1320 | * ãããã¯ã¼ã¯ãããã¡ã確ä¿ã§ããªãã¨ãã¯å²å½ã¦ãªãã
|
---|
1321 | */
|
---|
1322 | if (tget_net_buf(&new, (uint_t)len, TMO_TCP_GET_NET_BUF) != E_OK)
|
---|
1323 | new = NULL;
|
---|
1324 | }
|
---|
1325 | else
|
---|
1326 | new = NULL;
|
---|
1327 |
|
---|
1328 | /*
|
---|
1329 | * inqhdr->seq
|
---|
1330 | * |
|
---|
1331 | * |<------- inqhdr->slen ------->|
|
---|
1332 | * v v
|
---|
1333 | * +------------------------------+
|
---|
1334 | * | input |
|
---|
1335 | * +------------------------------+
|
---|
1336 | * ^ ^
|
---|
1337 | * |<----- slen ----->|
|
---|
1338 | * |
|
---|
1339 | * soff
|
---|
1340 | *
|
---|
1341 | */
|
---|
1342 | inqhdr->soff = 0;
|
---|
1343 |
|
---|
1344 | /*
|
---|
1345 | * ä»å追å ããã»ã°ã¡ã³ãããå(p)ã¨å¾(q)ã®ã»ã°ã¡ã³ããæ¢ãã
|
---|
1346 | *
|
---|
1347 | * +-------------------------+
|
---|
1348 | * | p |
|
---|
1349 | * +-------------------------+
|
---|
1350 | * ^ +---------------------------+
|
---|
1351 | * p->seq | input |
|
---|
1352 | * +---------------------------+
|
---|
1353 | * ^ +-------------------------+
|
---|
1354 | * inqhdr->seq | q |
|
---|
1355 | * +-------------------------+
|
---|
1356 | * ^
|
---|
1357 | * q->seq
|
---|
1358 | */
|
---|
1359 | for (q = cep->reassq, p = NULL; q != NULL; ) {
|
---|
1360 | qhdr = GET_TCP_Q_HDR(q, GET_IP_TCP_Q_HDR_OFFSET(q));
|
---|
1361 | if (SEQ_GT(qhdr->seq, inqhdr->seq))
|
---|
1362 | break;
|
---|
1363 | p = q;
|
---|
1364 | q = qhdr->next;
|
---|
1365 | }
|
---|
1366 |
|
---|
1367 | /*
|
---|
1368 | * å(p)ã®ã»ã°ã¡ã³ããããã°ãæ¢ã«ãä»åã¨åãã»ã°ã¡ã³ãã
|
---|
1369 | * ãããã¨ãããããã®å ´åã¯ããã®é¨åã¾ãã¯å
|
---|
1370 | ¨ã¦ãç ´æ£ããã
|
---|
1371 | *
|
---|
1372 | * qhdr->seq
|
---|
1373 | * |
|
---|
1374 | * |<----- qhdr->slen ------>|
|
---|
1375 | * v v
|
---|
1376 | * +-------------------------+
|
---|
1377 | * | p |
|
---|
1378 | * +-------------------------+
|
---|
1379 | * <--len -->
|
---|
1380 | * +---------------------------+
|
---|
1381 | * | input |
|
---|
1382 | * +---------------------------+
|
---|
1383 | * ^
|
---|
1384 | * inqhdr->seq
|
---|
1385 | */
|
---|
1386 | if (p != NULL) {
|
---|
1387 | qhdr = GET_TCP_Q_HDR(p, GET_IP_TCP_Q_HDR_OFFSET(p));
|
---|
1388 | len = qhdr->seq + qhdr->slen - inqhdr->seq;
|
---|
1389 | if (len > 0) {
|
---|
1390 |
|
---|
1391 | /*
|
---|
1392 | * len ãæ£ã§ããã°ãå(p) ã®ã»ã°ã¡ã³ãã¨ä»åã®
|
---|
1393 | * ã»ã°ã¡ã³ããéãªã£ã¦ããã
|
---|
1394 | */
|
---|
1395 | if (len >= inqhdr->slen) {
|
---|
1396 |
|
---|
1397 | /*
|
---|
1398 | * len ãä»åã®ã»ã°ã¡ã³ãã¨åããªã
|
---|
1399 | * ã¾ã£ããåãã»ã°ã¡ã³ããªã®ã§ä½ãããªãã
|
---|
1400 | */
|
---|
1401 | if (new != NULL) {
|
---|
1402 | syscall(rel_net_buf(new));
|
---|
1403 | }
|
---|
1404 |
|
---|
1405 | syscall(rel_net_buf(input));
|
---|
1406 | return flags;
|
---|
1407 | }
|
---|
1408 |
|
---|
1409 | /*
|
---|
1410 | * 追å ããã»ã°ã¡ã³ãã® SDU ã len ååã«è©°ããã
|
---|
1411 | */
|
---|
1412 | inqhdr->seq += len;
|
---|
1413 | inqhdr->soff += (uint16_t)len;
|
---|
1414 | inqhdr->slen -= (uint16_t)len;
|
---|
1415 | }
|
---|
1416 | }
|
---|
1417 |
|
---|
1418 | /*
|
---|
1419 | * ãã¥ã¼ã«ã¤ãªãåã«ãæ°ãããããã¯ã¼ã¯ãããã¡ã«ãã¼ã¿ã移ãã
|
---|
1420 | * TCP ã®ãªãã·ã§ã³ã¯åé¤ããã
|
---|
1421 | */
|
---|
1422 | if (new != NULL) {
|
---|
1423 | memcpy(new->buf, input->buf, (size_t)(thoff + TCP_HDR_SIZE));
|
---|
1424 | memcpy((uint8_t*)GET_TCP_HDR(new, thoff) + TCP_HDR_SIZE,
|
---|
1425 | GET_TCP_SDU(input, thoff), (size_t)(inqhdr->slen));
|
---|
1426 | syscall(rel_net_buf(input));
|
---|
1427 | input = new;
|
---|
1428 | inqhdr = GET_TCP_Q_HDR(input, thoff);
|
---|
1429 | inqhdr->doff = (uint8_t)TCP_MAKE_DATA_OFF(TCP_HDR_SIZE);
|
---|
1430 | }
|
---|
1431 |
|
---|
1432 | /*
|
---|
1433 | * éãªãå¾(q)ã®ã»ã°ã¡ã³ãã調æ´ããã
|
---|
1434 | *
|
---|
1435 | * inqhdr->seq
|
---|
1436 | * |
|
---|
1437 | * |<----- inqhdr->slen ---->|
|
---|
1438 | * v v
|
---|
1439 | * +-------------------------+
|
---|
1440 | * | input |
|
---|
1441 | * +-------------------------+
|
---|
1442 | * <--len -->
|
---|
1443 | * +---------------------------+
|
---|
1444 | * | q |
|
---|
1445 | * +---------------------------+
|
---|
1446 | * ^
|
---|
1447 | * qhdr->seq
|
---|
1448 | */
|
---|
1449 | while (q != NULL) {
|
---|
1450 | qhdr = GET_TCP_Q_HDR(q, GET_IP_TCP_Q_HDR_OFFSET(q));
|
---|
1451 | len = inqhdr->seq + inqhdr->slen - qhdr->seq;
|
---|
1452 | if (len <= 0)
|
---|
1453 | /* len ãè² ãªãéãªã£ã¦ããªãã*/
|
---|
1454 | break;
|
---|
1455 | else if (len < qhdr->slen) {
|
---|
1456 |
|
---|
1457 | /*
|
---|
1458 | * å¾ãã§éãªã£ã¦ããã»ã°ã¡ã³ãã® SDU ã len ååã«è©°ããã
|
---|
1459 | *
|
---|
1460 | * inqhdr->seq
|
---|
1461 | * |
|
---|
1462 | * |<----- inqhdr->slen ---->|
|
---|
1463 | * v v
|
---|
1464 | * +-------------------------+
|
---|
1465 | * | input |
|
---|
1466 | * +-------------------------+
|
---|
1467 | * <--len -->
|
---|
1468 | * +------+---------------------------+
|
---|
1469 | * | | q |
|
---|
1470 | * +------+---------------------------+
|
---|
1471 | * ^--------->
|
---|
1472 | * qhdr->seq
|
---|
1473 | * qhdr->soff
|
---|
1474 | */
|
---|
1475 | qhdr->seq += len;
|
---|
1476 | qhdr->soff += (uint16_t)len;
|
---|
1477 | qhdr->slen -= (uint16_t)len;
|
---|
1478 | break;
|
---|
1479 | }
|
---|
1480 | nq = qhdr->next;
|
---|
1481 | if (p)
|
---|
1482 | GET_TCP_Q_HDR(p, GET_IP_TCP_Q_HDR_OFFSET(p))->next = nq;
|
---|
1483 | else
|
---|
1484 | cep->reassq = nq;
|
---|
1485 | syscall(rel_net_buf(q));
|
---|
1486 | q = nq;
|
---|
1487 | }
|
---|
1488 |
|
---|
1489 | if (p == NULL) {
|
---|
1490 | inqhdr->next = cep->reassq;
|
---|
1491 | cep->reassq = input;
|
---|
1492 | }
|
---|
1493 | else {
|
---|
1494 | inqhdr->next = GET_TCP_Q_HDR(p, GET_IP_TCP_Q_HDR_OFFSET(p))->next;
|
---|
1495 | GET_TCP_Q_HDR(p, GET_IP_TCP_Q_HDR_OFFSET(p))->next = input;
|
---|
1496 | }
|
---|
1497 |
|
---|
1498 | return tcp_move_ra2rw(cep, flags);
|
---|
1499 | }
|
---|
1500 |
|
---|
1501 | /*
|
---|
1502 | * tcp_rexmt_val -- åéã¿ã¤ã ã¢ã¦ãå¤ãè¿ãã
|
---|
1503 | */
|
---|
1504 |
|
---|
1505 | T_TCP_TIME
|
---|
1506 | tcp_rexmt_val (T_TCP_CEP *cep)
|
---|
1507 | {
|
---|
1508 | T_TCP_TIME val;
|
---|
1509 |
|
---|
1510 | val = ((cep->srtt >> (TCP_SRTT_SHIFT - TCP_DELTA_SHIFT)) + cep->rttvar) >> TCP_DELTA_SHIFT;
|
---|
1511 | if (val < TCP_TVAL_MIN)
|
---|
1512 | return TCP_TVAL_MIN;
|
---|
1513 | else
|
---|
1514 | return val;
|
---|
1515 | }
|
---|
1516 |
|
---|
1517 | /*
|
---|
1518 | * tcp_init_cep -- é信端ç¹ãåæåããã
|
---|
1519 | */
|
---|
1520 |
|
---|
1521 | void
|
---|
1522 | tcp_init_cep (T_TCP_CEP *cep)
|
---|
1523 | {
|
---|
1524 |
|
---|
1525 | #ifdef TCP_CFG_RWBUF_CSAVE
|
---|
1526 | /*
|
---|
1527 | * åä¿¡ã¦ã£ã³ããããã¡ã®çã³ãã¼æ©è½ãæå¹ã«ããå ´åã
|
---|
1528 | * åä¿¡ã¦ã£ã³ããããã¡ãå
|
---|
1529 | ¨ã¦è§£æ¾ãããªããã¨ãããã®ã§ã
|
---|
1530 | * ããã§è§£æ¾ããã
|
---|
1531 | */
|
---|
1532 | if (cep->rwbufq != NULL) {
|
---|
1533 | cep->rwbuf_count = 0;
|
---|
1534 | TCP_FREE_RWBUFQ(cep);
|
---|
1535 | }
|
---|
1536 | #endif /* of #ifdef TCP_CFG_RWBUF_CSAVE */
|
---|
1537 |
|
---|
1538 |
|
---|
1539 | memset((uint8_t*)cep + offsetof(T_TCP_CEP, timer), 0,
|
---|
1540 | sizeof(T_TCP_CEP) - offsetof(T_TCP_CEP, timer));
|
---|
1541 |
|
---|
1542 | cep->sbuf_rptr = cep->sbuf_wptr = cep->sbuf;
|
---|
1543 | cep->rbuf_rptr = cep->rbuf_wptr = cep->rbuf;
|
---|
1544 |
|
---|
1545 | cep->maxseg = DEF_TCP_SND_SEG; /* éä¿¡æ大ã»ã°ã¡ã³ããµã¤ãº */
|
---|
1546 | cep->srtt = TCP_TVAL_SRTT_BASE; /* æ»ãããªç§»åå¹³å */
|
---|
1547 | cep->rttvar = ((TCP_TVAL_RTO_BASE - TCP_TVAL_SRTT_BASE) << TCP_RTTVAR_SHIFT) / 4;
|
---|
1548 | /* æ»ãããªåæ£ */
|
---|
1549 | cep->rxtcur = TCP_TVAL_RTO_BASE; /* ç¾å¨ã®åéå¤ */
|
---|
1550 | cep->snd_cwnd = MAX_TCP_WIN_SIZE; /* 輻輳ã¦ã£ã³ããµã¤ãº */
|
---|
1551 | cep->snd_ssthresh= MAX_TCP_WIN_SIZE; /* 輻輳ã¦ã£ã³ããµã¤ãº(snd_cwnd)ã® å¶éå¤ */
|
---|
1552 |
|
---|
1553 | /*
|
---|
1554 | * 以ä¸ã«é¢ä¿ããªããã©ã°ãã¯ãªã¢ã¼ããã
|
---|
1555 | * ã»éåä¿¡ã¦ã£ã³ããããã¡ã®çã³ãã¼æ©è½
|
---|
1556 | * ã»åçãªé信端ç¹ã®çæã»åé¤æ©è½
|
---|
1557 | * ã»é信端ç¹ã®ãããã¯ã¼ã¯å±¤ãããã³ã«
|
---|
1558 | */
|
---|
1559 | cep->flags &= TCP_CEP_FLG_NOT_CLEAR;
|
---|
1560 |
|
---|
1561 | /* ã»ããã©ãåæåããã*/
|
---|
1562 | sig_sem(cep->semid_lock);
|
---|
1563 |
|
---|
1564 | /* ãã©ã°ãåæåããã*/
|
---|
1565 | syscall(set_flg(cep->snd_flgid, TCP_CEP_EVT_SWBUF_READY));
|
---|
1566 | syscall(clr_flg(cep->rcv_flgid, TCP_CEP_EVT_RWBUF_READY));
|
---|
1567 | }
|
---|
1568 |
|
---|
1569 | /*
|
---|
1570 | * tcp_notify -- ICMP ã¨ã©ã¼ã®å¦ç
|
---|
1571 | */
|
---|
1572 |
|
---|
1573 | void
|
---|
1574 | tcp_notify (T_NET_BUF *input, ER error)
|
---|
1575 | {
|
---|
1576 | T_TCP_CEP *cep;
|
---|
1577 |
|
---|
1578 | if ((cep = tcp_find_cep(input, GET_TCP_HDR_OFFSET(input))) != NULL) {
|
---|
1579 |
|
---|
1580 | /*
|
---|
1581 | * ã³ãã¯ã·ã§ã³éè¨æ¸ã§ããã¹ãå°éä¸è½ã¨ã©ã¼ã®å ´åã¯ã
|
---|
1582 | * åéã«ããå¦çããã
|
---|
1583 | */
|
---|
1584 | if (cep->fsm_state == TCP_FSM_ESTABLISHED &&
|
---|
1585 | (error == EV_NURCH || error == EV_HURCH || error == EV_HDOWN))
|
---|
1586 | return;
|
---|
1587 |
|
---|
1588 | /*
|
---|
1589 | * ã³ãã¯ã·ã§ã³éè¨ä¸ãåãã¨ã©ã¼ãä½åº¦ãåä¿¡ããå ´åã¯ã
|
---|
1590 | * å¾
|
---|
1591 | ã¡ç¶æ
|
---|
1592 | ã解é¤ãã対å¿ããé¢æ°ã«ã¨ã©ã¼ãè¿ãããã
|
---|
1593 | */
|
---|
1594 | if (cep->fsm_state < TCP_FSM_ESTABLISHED && cep->rxtshift > 3 && cep->net_error != E_OK) {
|
---|
1595 | cep->error = E_CLS;
|
---|
1596 | tcp_close(cep);
|
---|
1597 | }
|
---|
1598 | else {
|
---|
1599 | cep->net_error = error;
|
---|
1600 |
|
---|
1601 | /* éä¿¡ãæ示ããã*/
|
---|
1602 | cep->flags |= TCP_CEP_FLG_POST_OUTPUT;
|
---|
1603 | sig_sem(SEM_TCP_POST_OUTPUT);
|
---|
1604 | }
|
---|
1605 | }
|
---|
1606 | }
|
---|
1607 |
|
---|
1608 | /*
|
---|
1609 | * tcp_lock_cep -- TCP é信端ç¹ãããã¯ããã
|
---|
1610 | */
|
---|
1611 |
|
---|
1612 | ER
|
---|
1613 | tcp_lock_cep (ID cepid, T_TCP_CEP **p_cep, FN tfn)
|
---|
1614 | {
|
---|
1615 | T_TCP_CEP *cep;
|
---|
1616 | ER error = E_OK;
|
---|
1617 |
|
---|
1618 | *p_cep = NULL;
|
---|
1619 |
|
---|
1620 | /* TCP éä¿¡ç«¯ç¹ ID ããã§ãã¯ããã*/
|
---|
1621 | if (!VALID_TCP_CEPID(cepid))
|
---|
1622 | return E_ID;
|
---|
1623 |
|
---|
1624 | /* TCP é信端ç¹ãå¾ãã*/
|
---|
1625 | cep = GET_TCP_CEP(cepid);
|
---|
1626 |
|
---|
1627 | /* TCP é信端ç¹ãããã¯ããã*/
|
---|
1628 | syscall(wai_sem(cep->semid_lock));
|
---|
1629 |
|
---|
1630 | /* TCP é信端ç¹ããã§ãã¯ããã*/
|
---|
1631 | if (!VALID_TCP_CEP(cep)) {
|
---|
1632 | syscall(sig_sem(cep->semid_lock));
|
---|
1633 | return E_NOEXS;
|
---|
1634 | }
|
---|
1635 |
|
---|
1636 | /*
|
---|
1637 | * API æ©è½ã³ã¼ãã¨ã¿ã¹ã¯èå¥åãè¨é²ããã
|
---|
1638 | * ãã§ã«è¨é²ããã¦ããã°ããã³ãã£ã³ã°ä¸ãªã®ã§ã¨ã©ã¼
|
---|
1639 | */
|
---|
1640 | if (IS_TFN_TCP_RCV(tfn)) {
|
---|
1641 | if (cep->rcv_tfn != TFN_TCP_UNDEF ||
|
---|
1642 | (tfn == TFN_TCP_ACP_CEP && cep->snd_tfn == TFN_TCP_CON_CEP))
|
---|
1643 | error = E_OBJ;
|
---|
1644 | else {
|
---|
1645 | get_tid(&(cep->rcv_tskid));
|
---|
1646 | cep->rcv_tfn = tfn;
|
---|
1647 | }
|
---|
1648 | }
|
---|
1649 | else {
|
---|
1650 | if (cep->snd_tfn != TFN_TCP_UNDEF ||
|
---|
1651 | (tfn == TFN_TCP_CON_CEP && cep->rcv_tfn == TFN_TCP_ACP_CEP) ||
|
---|
1652 | (tfn == TFN_TCP_CON_CEP && cep->rcv_tfn == TFN_TCP_CLS_CEP))
|
---|
1653 | error = E_OBJ;
|
---|
1654 | else {
|
---|
1655 | get_tid(&(cep->snd_tskid));
|
---|
1656 | cep->snd_tfn = tfn;
|
---|
1657 | }
|
---|
1658 | }
|
---|
1659 |
|
---|
1660 | /* é信端ç¹ã®ããã¯ã解é¤ããã*/
|
---|
1661 | syscall(sig_sem(cep->semid_lock));
|
---|
1662 |
|
---|
1663 | *p_cep = cep;
|
---|
1664 | return error;
|
---|
1665 | }
|
---|
1666 |
|
---|
1667 | #ifdef TCP_CFG_TRACE
|
---|
1668 |
|
---|
1669 | /*
|
---|
1670 | * ãã¬ã¼ã¹åºåã«ç¨ããã·ãªã¢ã«ãã¼ãçªå·
|
---|
1671 | */
|
---|
1672 |
|
---|
1673 | #ifndef CONSOLE_PORTID
|
---|
1674 | #define CONSOLE_PORTID LOGTASK_PORTID
|
---|
1675 | #endif
|
---|
1676 |
|
---|
1677 | /*
|
---|
1678 | * ã³ãã¯ã·ã§ã³ã®ç¶æ
|
---|
1679 |
|
---|
1680 | */
|
---|
1681 |
|
---|
1682 | static const char tcp_strfsm[][3] = {
|
---|
1683 | { 'C', 'D', '\0' },
|
---|
1684 | { 'L', 'I', '\0' },
|
---|
1685 | { 'S', 'S', '\0' },
|
---|
1686 | { 'S', 'R', '\0' },
|
---|
1687 | { 'E', 'S', '\0' },
|
---|
1688 | { 'C', 'W', '\0' },
|
---|
1689 | { 'F', '1', '\0' },
|
---|
1690 | { 'C', 'G', '\0' },
|
---|
1691 | { 'L', 'A', '\0' },
|
---|
1692 | { 'F', '2', '\0' },
|
---|
1693 | { 'T', 'W', '\0' },
|
---|
1694 | };
|
---|
1695 |
|
---|
1696 | /*
|
---|
1697 | * trace_putchar -- ã·ãªã¢ã«ãã¼ãã¸ã®æååºå
|
---|
1698 | */
|
---|
1699 |
|
---|
1700 | static void
|
---|
1701 | trace_putchar (ID portid, char ch)
|
---|
1702 | {
|
---|
1703 | serial_wri_dat(portid, &ch, 1);
|
---|
1704 | /*cpu_putc(ch);*/
|
---|
1705 | }
|
---|
1706 |
|
---|
1707 | /*
|
---|
1708 | * ã·ãªã¢ã«ãã¼ãã¸ã®æ¸å¼ä»æåååºåã©ã¤ãã©ãª
|
---|
1709 | */
|
---|
1710 |
|
---|
1711 | /*
|
---|
1712 | * æ°å¤å¤æã®ããã®å¤æ表
|
---|
1713 | */
|
---|
1714 |
|
---|
1715 | static const char radhex[] = "0123456789abcdef";
|
---|
1716 | static const char radHEX[] = "0123456789ABCDEF";
|
---|
1717 |
|
---|
1718 | /*
|
---|
1719 | * convert -- trace_printf ã®æ°å¤å¤æ
|
---|
1720 | */
|
---|
1721 |
|
---|
1722 | static int_t
|
---|
1723 | convert (ID portid, long_t val, int_t radix,
|
---|
1724 | const char *radchar, int_t width, bool_t minus, char padchar)
|
---|
1725 | {
|
---|
1726 | char digits[24];
|
---|
1727 | int_t ix, pad, pchars;
|
---|
1728 |
|
---|
1729 | ix = 0;
|
---|
1730 | do {
|
---|
1731 | if (minus)
|
---|
1732 | digits[ix ++] = radchar[val % radix];
|
---|
1733 | else
|
---|
1734 | digits[ix ++] = radchar[(ulong_t)val % radix];
|
---|
1735 | val /= radix;
|
---|
1736 | } while (val != 0);
|
---|
1737 |
|
---|
1738 | if (minus)
|
---|
1739 | digits[ix ++] = '-';
|
---|
1740 |
|
---|
1741 | if (width > ix)
|
---|
1742 | pchars = width;
|
---|
1743 | else
|
---|
1744 | pchars = ix;
|
---|
1745 |
|
---|
1746 | for (pad = ix; pad < width; pad ++)
|
---|
1747 | trace_putchar(portid, padchar);
|
---|
1748 |
|
---|
1749 | while (ix -- > 0)
|
---|
1750 | trace_putchar(portid, digits[ix]);
|
---|
1751 |
|
---|
1752 | return pchars;
|
---|
1753 | }
|
---|
1754 |
|
---|
1755 | /*
|
---|
1756 | * trace_printf -- ã·ãªã¢ã«ãã¼ãã¸ã®æ¸å¼ä»æåååºå
|
---|
1757 | */
|
---|
1758 |
|
---|
1759 | static void
|
---|
1760 | trace_printf (ID portid, const char *fmt, ...)
|
---|
1761 | {
|
---|
1762 | va_list ap;
|
---|
1763 | ulong_t val;
|
---|
1764 | char padchar, *str;
|
---|
1765 | int_t ch, width, longflag;
|
---|
1766 |
|
---|
1767 | va_start(ap, fmt);
|
---|
1768 | while ((ch = *fmt ++) != '\0') {
|
---|
1769 | if (ch != '%') { /* æ¸å¼æå®ä»¥å¤ */
|
---|
1770 | trace_putchar(portid, (char)ch);
|
---|
1771 | continue;
|
---|
1772 | }
|
---|
1773 |
|
---|
1774 | width = longflag = 0;
|
---|
1775 | padchar = ' ';
|
---|
1776 | if ((ch = *fmt ++) == '0') { /* ä¸ä½æ¡ã® 0 */
|
---|
1777 | padchar = '0';
|
---|
1778 | ch = *fmt ++;
|
---|
1779 | }
|
---|
1780 |
|
---|
1781 | while ('0' <= ch && ch <= '9') { /* åºåå¹
|
---|
1782 | */
|
---|
1783 | width = width * 10 + ch - '0';
|
---|
1784 | ch = *fmt ++;
|
---|
1785 | }
|
---|
1786 |
|
---|
1787 | while (ch == 'l') { /* long (long) ã®æå® */
|
---|
1788 | longflag ++;
|
---|
1789 | ch = *fmt ++;
|
---|
1790 | }
|
---|
1791 |
|
---|
1792 | switch (ch) {
|
---|
1793 | case 'd':
|
---|
1794 | val = longflag ? (ulong_t)va_arg(ap, long_t)
|
---|
1795 | : (ulong_t)va_arg(ap, int_t);
|
---|
1796 | if (val >= 0)
|
---|
1797 | convert(portid, val, 10, radhex, width, false, padchar);
|
---|
1798 | else
|
---|
1799 | convert(portid, -val, 10, radhex, width, true, padchar);
|
---|
1800 | break;
|
---|
1801 |
|
---|
1802 | case 'u':
|
---|
1803 | val = longflag ? (ulong_t)va_arg(ap, ulong_t)
|
---|
1804 | : (ulong_t)va_arg(ap, uint_t);
|
---|
1805 | convert(portid, val, 10, radhex, width, false, padchar);
|
---|
1806 | break;
|
---|
1807 |
|
---|
1808 | case 'x':
|
---|
1809 | val = longflag ? (ulong_t)va_arg(ap, ulong_t)
|
---|
1810 | : (ulong_t)va_arg(ap, uint_t);
|
---|
1811 | convert(portid, val, 16, radhex, width, false, padchar);
|
---|
1812 | break;
|
---|
1813 |
|
---|
1814 | case 'X':
|
---|
1815 | val = longflag ? (ulong_t)va_arg(ap, ulong_t)
|
---|
1816 | : (ulong_t)va_arg(ap, uint_t);
|
---|
1817 | convert(portid, val, 16, radHEX, width, false, padchar);
|
---|
1818 | break;
|
---|
1819 |
|
---|
1820 | case 'c':
|
---|
1821 | ch = va_arg(ap, int_t);
|
---|
1822 | trace_putchar(portid, (char)ch);
|
---|
1823 | break;
|
---|
1824 |
|
---|
1825 | case 's':
|
---|
1826 | str = va_arg(ap, char*);
|
---|
1827 | while ((ch = *str ++) != '\0')
|
---|
1828 | trace_putchar(portid, (char)ch);
|
---|
1829 | break;
|
---|
1830 |
|
---|
1831 | case '%':
|
---|
1832 | trace_putchar(portid, '%');
|
---|
1833 | break;
|
---|
1834 |
|
---|
1835 | case '0':
|
---|
1836 | fmt --;
|
---|
1837 | break;
|
---|
1838 |
|
---|
1839 | default:
|
---|
1840 | break;
|
---|
1841 | }
|
---|
1842 |
|
---|
1843 | }
|
---|
1844 | va_end(ap);
|
---|
1845 | }
|
---|
1846 |
|
---|
1847 | /*
|
---|
1848 | * TCP ãã©ã°æåå
|
---|
1849 | */
|
---|
1850 |
|
---|
1851 | static char *
|
---|
1852 | get_tcp_flag_str (char *buf, uint8_t flags)
|
---|
1853 | {
|
---|
1854 | static char tcp_flag_str[] = "FSRPAU";
|
---|
1855 |
|
---|
1856 | int_t bit, mask = 1;
|
---|
1857 |
|
---|
1858 | for (bit = 0; bit < sizeof(tcp_flag_str); bit ++) {
|
---|
1859 | buf[sizeof(tcp_flag_str) - bit - 1] = (char)((flags & mask) ? tcp_flag_str[bit] : '-');
|
---|
1860 | mask <<= 1;
|
---|
1861 | }
|
---|
1862 | buf[sizeof(tcp_flag_str)] = '\0';
|
---|
1863 | return buf;
|
---|
1864 | }
|
---|
1865 |
|
---|
1866 | /*
|
---|
1867 | * éä¿¡ TCP ãããã®ãã¬ã¼ã¹åºå
|
---|
1868 | */
|
---|
1869 |
|
---|
1870 | void
|
---|
1871 | tcp_output_trace (T_NET_BUF *output, T_TCP_CEP *cep)
|
---|
1872 | {
|
---|
1873 | SYSTIM time;
|
---|
1874 | T_TCP_HDR *tcph;
|
---|
1875 | char buf[9];
|
---|
1876 |
|
---|
1877 | if (!(TCP_CFG_TRACE_LPORTNO == TCP_PORTANY || cep->myaddr.portno == TCP_CFG_TRACE_LPORTNO) ||
|
---|
1878 | !(TCP_CFG_TRACE_RPORTNO == TCP_PORTANY || cep->dstaddr.portno == TCP_CFG_TRACE_RPORTNO))
|
---|
1879 | return;
|
---|
1880 |
|
---|
1881 | #if defined(_IP4_CFG)
|
---|
1882 |
|
---|
1883 | #if defined(_IP6_CFG)
|
---|
1884 |
|
---|
1885 | if (!((TCP_CFG_TRACE_IPV4_RADDR == IPV4_ADDRANY) ||
|
---|
1886 | ((cep->flags & TCP_CEP_FLG_IPV4) &&
|
---|
1887 | IN6_IS_ADDR_V4MAPPED(&cep->dstaddr.ipaddr) &&
|
---|
1888 | (ntohl(cep->dstaddr.ipaddr.s6_addr32[3]) == TCP_CFG_TRACE_IPV4_RADDR))))
|
---|
1889 | return;
|
---|
1890 |
|
---|
1891 | #else /* of #if defined(_IP6_CFG) */
|
---|
1892 |
|
---|
1893 | if (!(TCP_CFG_TRACE_IPV4_RADDR == IPV4_ADDRANY || cep->dstaddr.ipaddr == TCP_CFG_TRACE_IPV4_RADDR))
|
---|
1894 | return;
|
---|
1895 |
|
---|
1896 | #endif /* of #if defined(_IP6_CFG) */
|
---|
1897 |
|
---|
1898 | #endif /* of #if defined(_IP4_CFG) */
|
---|
1899 |
|
---|
1900 | syscall(wai_sem(SEM_TCP_TRACE));
|
---|
1901 | syscall(get_tim(&time));
|
---|
1902 | tcph = GET_TCP_HDR(output, GET_TCP_HDR_OFFSET(output));
|
---|
1903 | if (time > 99999999)
|
---|
1904 | trace_printf(CONSOLE_PORTID, "=O%10d", time / 1000);
|
---|
1905 | else
|
---|
1906 | trace_printf(CONSOLE_PORTID, "=O%6d.%03d", time / 1000, time % 1000);
|
---|
1907 | if (cep == NULL)
|
---|
1908 | trace_printf(CONSOLE_PORTID, "=c:-- s:-- f:--------");
|
---|
1909 | else
|
---|
1910 | trace_printf(CONSOLE_PORTID, "=c:%2d s:%s f:%08x",
|
---|
1911 | GET_TCP_CEPID(cep),
|
---|
1912 | tcp_strfsm[cep->fsm_state], cep->flags);
|
---|
1913 | trace_printf(CONSOLE_PORTID, ":%s", get_tcp_flag_str(buf, tcph->flags));
|
---|
1914 | if (cep->fsm_state >= TCP_FSM_ESTABLISHED)
|
---|
1915 | trace_printf(CONSOLE_PORTID, " s:%10u a:%10u",
|
---|
1916 | ntohl(tcph->seq) - cep->iss,
|
---|
1917 | ntohl(tcph->ack) - cep->irs);
|
---|
1918 | else
|
---|
1919 | trace_printf(CONSOLE_PORTID, " s:%10u a:%10u",
|
---|
1920 | ntohl(tcph->seq), ntohl(tcph->ack));
|
---|
1921 | trace_printf(CONSOLE_PORTID, " w:%5d l:%4d>\n",
|
---|
1922 | ntohs(tcph->win),
|
---|
1923 | GET_IP_SDU_SIZE(output) - TCP_HDR_LEN(tcph->doff));
|
---|
1924 | syscall(sig_sem(SEM_TCP_TRACE));
|
---|
1925 | }
|
---|
1926 |
|
---|
1927 | /*
|
---|
1928 | * åä¿¡ TCP ãããã®ãã¬ã¼ã¹åºå
|
---|
1929 | *
|
---|
1930 | * 注æ: TCP ãããå
|
---|
1931 | ã¯ããã§ã«ãã¹ããã¤ããªã¼ã
|
---|
1932 | */
|
---|
1933 |
|
---|
1934 | void
|
---|
1935 | tcp_input_trace (T_NET_BUF *input, T_TCP_CEP *cep)
|
---|
1936 | {
|
---|
1937 | SYSTIM time;
|
---|
1938 | T_TCP_HDR *tcph;
|
---|
1939 | char buf[9];
|
---|
1940 |
|
---|
1941 | if (!(TCP_CFG_TRACE_LPORTNO == TCP_PORTANY || cep->myaddr.portno == TCP_CFG_TRACE_LPORTNO) ||
|
---|
1942 | !(TCP_CFG_TRACE_RPORTNO == TCP_PORTANY || cep->dstaddr.portno == TCP_CFG_TRACE_RPORTNO))
|
---|
1943 | return;
|
---|
1944 |
|
---|
1945 | #if defined(_IP4_CFG)
|
---|
1946 |
|
---|
1947 | #if defined(_IP6_CFG)
|
---|
1948 |
|
---|
1949 | if (!((TCP_CFG_TRACE_IPV4_RADDR == IPV4_ADDRANY) ||
|
---|
1950 | ((cep->flags & TCP_CEP_FLG_IPV4) &&
|
---|
1951 | IN6_IS_ADDR_V4MAPPED(&cep->dstaddr.ipaddr) &&
|
---|
1952 | (ntohl(cep->dstaddr.ipaddr.s6_addr32[3]) == TCP_CFG_TRACE_IPV4_RADDR))))
|
---|
1953 | return;
|
---|
1954 |
|
---|
1955 | #else /* of #if defined(_IP6_CFG) */
|
---|
1956 |
|
---|
1957 | if (!(TCP_CFG_TRACE_IPV4_RADDR == IPV4_ADDRANY || cep->dstaddr.ipaddr == TCP_CFG_TRACE_IPV4_RADDR))
|
---|
1958 | return;
|
---|
1959 |
|
---|
1960 | #endif /* of #if defined(_IP6_CFG) */
|
---|
1961 |
|
---|
1962 | #endif /* of #if defined(_IP4_CFG) */
|
---|
1963 |
|
---|
1964 | syscall(wai_sem(SEM_TCP_TRACE));
|
---|
1965 | syscall(get_tim(&time));
|
---|
1966 | tcph = GET_TCP_HDR(input, GET_TCP_HDR_OFFSET(input));
|
---|
1967 | if (time > 99999999)
|
---|
1968 | trace_printf(CONSOLE_PORTID, "<I%10d", time / 1000);
|
---|
1969 | else
|
---|
1970 | trace_printf(CONSOLE_PORTID, "<I%6d.%03d", time / 1000, time % 1000);
|
---|
1971 | if (cep == NULL)
|
---|
1972 | trace_printf(CONSOLE_PORTID, "=c:-- s:-- f:--------");
|
---|
1973 | else
|
---|
1974 | trace_printf(CONSOLE_PORTID, "=c:%2d s:%s f:%08x",
|
---|
1975 | GET_TCP_CEPID(cep),
|
---|
1976 | tcp_strfsm[cep->fsm_state], cep->flags);
|
---|
1977 | trace_printf(CONSOLE_PORTID, ":%s", get_tcp_flag_str(buf, tcph->flags));
|
---|
1978 | if (cep->fsm_state >= TCP_FSM_SYN_RECVD)
|
---|
1979 | trace_printf(CONSOLE_PORTID, " a:%10u s:%10u", tcph->ack - cep->iss, tcph->seq - cep->irs);
|
---|
1980 | else
|
---|
1981 | trace_printf(CONSOLE_PORTID, " a:%10u s:%10u", tcph->ack, tcph->seq);
|
---|
1982 | trace_printf(CONSOLE_PORTID, " w:%5d l:%4d=\n",
|
---|
1983 | tcph->win, GET_IP_SDU_SIZE(input) - TCP_HDR_LEN(tcph->doff));
|
---|
1984 | syscall(sig_sem(SEM_TCP_TRACE));
|
---|
1985 | }
|
---|
1986 |
|
---|
1987 | #endif /* of #ifdef TCP_CFG_TRACE */
|
---|
1988 |
|
---|
1989 | #endif /* of #ifdef SUPPORT_TCP */
|
---|