1 | /*
|
---|
2 | * TINET (TCP/IP Protocol Stack)
|
---|
3 | *
|
---|
4 | * Copyright (C) 2001-2009 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_output.c 270 2017-02-09 04:03:47Z 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_output.c 8.4 (Berkeley) 5/24/95
|
---|
79 | * $FreeBSD: src/sys/netinet/tcp_output.c,v 1.32.2.2 1999/08/29 16:29:55 peter Exp $
|
---|
80 | */
|
---|
81 |
|
---|
82 | #ifdef TARGET_KERNEL_ASP
|
---|
83 |
|
---|
84 | #include <kernel.h>
|
---|
85 | #include <sil.h>
|
---|
86 | #include <t_syslog.h>
|
---|
87 | #include "kernel_cfg.h"
|
---|
88 |
|
---|
89 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
90 |
|
---|
91 | #ifdef TARGET_KERNEL_JSP
|
---|
92 |
|
---|
93 | #include <s_services.h>
|
---|
94 | #include <t_services.h>
|
---|
95 | #include "kernel_id.h"
|
---|
96 |
|
---|
97 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
98 |
|
---|
99 | #include <tinet_defs.h>
|
---|
100 | #include <tinet_config.h>
|
---|
101 |
|
---|
102 | #include <net/if.h>
|
---|
103 | #include <net/if_ppp.h>
|
---|
104 | #include <net/if_loop.h>
|
---|
105 | #include <net/ethernet.h>
|
---|
106 | #include <net/net.h>
|
---|
107 | #include <net/net_buf.h>
|
---|
108 | #include <net/net_timer.h>
|
---|
109 | #include <net/net_count.h>
|
---|
110 |
|
---|
111 | #include <netinet/in.h>
|
---|
112 | #include <netinet6/in6.h>
|
---|
113 | #include <netinet/in_var.h>
|
---|
114 | #include <netinet/in_itron.h>
|
---|
115 | #include <netinet/ip.h>
|
---|
116 | #include <netinet/ip_var.h>
|
---|
117 | #include <netinet6/in6_var.h>
|
---|
118 | #include <netinet/ip6.h>
|
---|
119 | #include <netinet6/ip6_var.h>
|
---|
120 | #include <netinet/tcp.h>
|
---|
121 | #include <netinet/tcp_timer.h>
|
---|
122 | #include <netinet/tcp_var.h>
|
---|
123 | #include <netinet/tcp_fsm.h>
|
---|
124 | #include <netinet/tcp_seq.h>
|
---|
125 |
|
---|
126 | #ifdef SUPPORT_TCP
|
---|
127 |
|
---|
128 | /*
|
---|
129 | * é¢æ°
|
---|
130 | */
|
---|
131 |
|
---|
132 | static ER send_segment (bool_t *sendalot, T_TCP_CEP *cep, uint_t doff, uint_t win, uint_t len, uint8_t flags);
|
---|
133 | static void tcp_output (T_TCP_CEP *cep);
|
---|
134 |
|
---|
135 | /*
|
---|
136 | * å¤æ°
|
---|
137 | */
|
---|
138 |
|
---|
139 | /* åºåæã®ãã©ã°ã FSM ç¶æ
|
---|
140 | ã«ããé¸æããããã®è¡¨ */
|
---|
141 |
|
---|
142 | const static uint8_t tcp_outflags[] = {
|
---|
143 | TCP_FLG_RST | TCP_FLG_ACK, /* 0, ã¯ãã¼ãº */
|
---|
144 | 0, /* 1, ååãªã¼ãã³ */
|
---|
145 | TCP_FLG_SYN, /* 2, è½åãªã¼ãã³ãSYN éä¿¡æ¸ã¿ */
|
---|
146 | TCP_FLG_SYN | TCP_FLG_ACK, /* 3, SYM ãåä¿¡ããSYN éä¿¡æ¸ã¿ */
|
---|
147 | TCP_FLG_ACK, /* 4, ã³ãã¯ã·ã§ã³éè¨å®äº */
|
---|
148 | TCP_FLG_ACK, /* 5, FIN åä¿¡ãã¯ãã¼ãºå¾
|
---|
149 | ã¡ */
|
---|
150 | TCP_FLG_FIN | TCP_FLG_ACK, /* 6, çµäºãã¦ãFIN éä¿¡æ¸ã¿ */
|
---|
151 | TCP_FLG_FIN | TCP_FLG_ACK, /* 7, çµäºãFIN 交ææ¸ã¿ãACK å¾
|
---|
152 | ã¡ */
|
---|
153 | TCP_FLG_FIN | TCP_FLG_ACK, /* 8, FIN åä¿¡ãçµäºãACK å¾
|
---|
154 | ã¡ */
|
---|
155 | TCP_FLG_ACK, /* 9, çµäºãFIN ä¼é確èªåä¿¡ãFINå¾
|
---|
156 | ã¡ */
|
---|
157 | TCP_FLG_ACK, /* 10, çµäºãæéå¾
|
---|
158 | ã¡ */
|
---|
159 | };
|
---|
160 |
|
---|
161 | /*
|
---|
162 | * send_segment -- TCP åºåå¦ç
|
---|
163 | */
|
---|
164 |
|
---|
165 | static ER
|
---|
166 | send_segment (bool_t *sendalot, T_TCP_CEP *cep, uint_t doff, uint_t win, uint_t len, uint8_t flags)
|
---|
167 | {
|
---|
168 | T_NET_BUF *output;
|
---|
169 | T_TCP_HDR *tcph;
|
---|
170 | uint_t optlen;
|
---|
171 | ER error;
|
---|
172 |
|
---|
173 | #ifdef TCP_CFG_OPT_MSS
|
---|
174 |
|
---|
175 | uint8_t *optp;
|
---|
176 |
|
---|
177 | if (flags & TCP_FLG_SYN)
|
---|
178 | optlen = TCP_OPT_LEN_MAXSEG;
|
---|
179 | else
|
---|
180 | optlen = 0;
|
---|
181 |
|
---|
182 | #else/* of #ifdef TCP_CFG_OPT_MSS */
|
---|
183 |
|
---|
184 | optlen = 0;
|
---|
185 |
|
---|
186 | #endif/* of #ifdef TCP_CFG_OPT_MSS */
|
---|
187 |
|
---|
188 | NET_COUNT_TCP(net_count_tcp[NC_TCP_SEND_SEGS], 1);
|
---|
189 | NET_COUNT_MIB(tcp_stats.tcpOutSegs, 1);
|
---|
190 |
|
---|
191 | /*
|
---|
192 | * ã»ã°ã¡ã³ãé·ããç¸æã®æ大åä¿¡ã»ã°ã¡ã³ãé·ã«èª¿æ´ããã
|
---|
193 | * ãããè¶
|
---|
194 | ãã¦ããå ´åã¯ãè¶
|
---|
195 | ããåãå¾ã§éä¿¡ããã
|
---|
196 | * ãã®ãããFIN ããããã¯ãªã¢ããã
|
---|
197 | *
|
---|
198 | * ãªãªã¸ãã«ã§ã¯ãt_maxopd ãå¶éé·ã«ãã¦ãããã
|
---|
199 | * æ¬å®è£
|
---|
200 | ã§ã¯ãç¸æã®æ大åä¿¡ã»ã°ã¡ã³ãã«ããã
|
---|
201 | */
|
---|
202 | if (len + optlen > cep->maxseg) {
|
---|
203 | flags &= ~TCP_FLG_FIN;
|
---|
204 | len = cep->maxseg - optlen;
|
---|
205 | *sendalot = true;
|
---|
206 | }
|
---|
207 |
|
---|
208 | /*
|
---|
209 | * éä¿¡ãããã¡ã空ã«ãªãã¨ã㯠PUSH ãã©ã°ãè¨å®ããã
|
---|
210 | */
|
---|
211 | if (len && doff + len >= cep->swbuf_count)
|
---|
212 | flags |= TCP_FLG_PUSH;
|
---|
213 |
|
---|
214 | #if defined(TCP_CFG_SWBUF_CSAVE_ONLY)
|
---|
215 |
|
---|
216 | if (len > 0 && ((cep->flags & TCP_CEP_FLG_WBCS_MASK) == TCP_CEP_FLG_WBCS_SEND_READY ||
|
---|
217 | (cep->flags & TCP_CEP_FLG_WBCS_MASK) == TCP_CEP_FLG_WBCS_SENT)) {
|
---|
218 |
|
---|
219 | /*
|
---|
220 | * éä¿¡ã¦ã¤ã³ããããã¡ãéæ¾ãããªãããã«ãã¦ã
|
---|
221 | * ãããã¯ã¼ã¯ãããã¡ãåºåã«ç§»ãã
|
---|
222 | */
|
---|
223 | cep->swbufq->flags |= NB_FLG_NOREL_IFOUT;
|
---|
224 | output = cep->swbufq;
|
---|
225 | }
|
---|
226 | else {
|
---|
227 |
|
---|
228 | /*
|
---|
229 | * ACK å®äºç¶æ
|
---|
230 | ã§ããã®é¢æ°ãå¼ã³åºããããã¨ãããã
|
---|
231 | * ãã®æã¯ãlen ã 0 ã«ãã¦ãå¦çãç¶ç¶ããã
|
---|
232 | */
|
---|
233 | len = 0;
|
---|
234 | if ((error = tcp_get_segment(&output, cep, optlen,
|
---|
235 | len, (uint_t)(net_buf_max_siz() - IF_IP_TCP_HDR_SIZE),
|
---|
236 | NBA_SEARCH_ASCENT, TMO_TCP_GET_NET_BUF)) != E_OK) {
|
---|
237 | if (cep->timer[TCP_TIM_REXMT] == 0)
|
---|
238 | cep->timer[TCP_TIM_REXMT] = cep->rxtcur;
|
---|
239 | goto err_ret;
|
---|
240 | }
|
---|
241 | }
|
---|
242 |
|
---|
243 | #elif defined(TCP_CFG_SWBUF_CSAVE) /* of #if defined(TCP_CFG_SWBUF_CSAVE_ONLY) */
|
---|
244 |
|
---|
245 | if (IS_PTR_DEFINED(cep->sbuf)) {
|
---|
246 | if ((error = tcp_get_segment(&output, cep, optlen,
|
---|
247 | len, (uint_t)(net_buf_max_siz() - IF_IP_TCP_HDR_SIZE),
|
---|
248 | NBA_SEARCH_ASCENT, TMO_TCP_GET_NET_BUF)) != E_OK) {
|
---|
249 | if (cep->timer[TCP_TIM_REXMT] == 0)
|
---|
250 | cep->timer[TCP_TIM_REXMT] = cep->rxtcur;
|
---|
251 | goto err_ret;
|
---|
252 | }
|
---|
253 | }
|
---|
254 | else if (len > 0 && ((cep->flags & TCP_CEP_FLG_WBCS_MASK) == TCP_CEP_FLG_WBCS_SEND_READY ||
|
---|
255 | (cep->flags & TCP_CEP_FLG_WBCS_MASK) == TCP_CEP_FLG_WBCS_SENT)) {
|
---|
256 |
|
---|
257 | /*
|
---|
258 | * éä¿¡ã¦ã¤ã³ããããã¡ãéæ¾ãããªãããã«ãã¦ã
|
---|
259 | * ãããã¯ã¼ã¯ãããã¡ãåºåã«ç§»ãã
|
---|
260 | */
|
---|
261 | cep->swbufq->flags |= NB_FLG_NOREL_IFOUT;
|
---|
262 | output = cep->swbufq;
|
---|
263 | }
|
---|
264 | else {
|
---|
265 |
|
---|
266 | /*
|
---|
267 | * ACK å®äºç¶æ
|
---|
268 | ã§ããã®é¢æ°ãå¼ã³åºããããã¨ãããã
|
---|
269 | * ãã®æã¯ãlen ã 0 ã«ãã¦ãå¦çãç¶ç¶ããã
|
---|
270 | */
|
---|
271 | len = 0;
|
---|
272 | if ((error = tcp_get_segment(&output, cep, optlen,
|
---|
273 | len, (uint_t)(net_buf_max_siz() - IF_IP_TCP_HDR_SIZE),
|
---|
274 | NBA_SEARCH_ASCENT, TMO_TCP_GET_NET_BUF)) != E_OK) {
|
---|
275 | if (cep->timer[TCP_TIM_REXMT] == 0)
|
---|
276 | cep->timer[TCP_TIM_REXMT] = cep->rxtcur;
|
---|
277 | goto err_ret;
|
---|
278 | }
|
---|
279 | }
|
---|
280 |
|
---|
281 | #else /* of #if defined(TCP_CFG_SWBUF_CSAVE_ONLY) */
|
---|
282 |
|
---|
283 | if ((error = tcp_get_segment(&output, cep, optlen,
|
---|
284 | len, (uint_t)(net_buf_max_siz() - IF_IP_TCP_HDR_SIZE),
|
---|
285 | NBA_SEARCH_ASCENT, TMO_TCP_GET_NET_BUF)) != E_OK) {
|
---|
286 | if (cep->timer[TCP_TIM_REXMT] == 0)
|
---|
287 | cep->timer[TCP_TIM_REXMT] = cep->rxtcur;
|
---|
288 | goto err_ret;
|
---|
289 | }
|
---|
290 |
|
---|
291 | #endif /* of #if defined(TCP_CFG_SWBUF_CSAVE_ONLY) */
|
---|
292 |
|
---|
293 | /*
|
---|
294 | * TCP ãªãã·ã§ã³ã®è¨å®ãè¡ãã
|
---|
295 | * æ¬å®è£
|
---|
296 | ã§ã¯ãæ大ã»ã°ã¡ã³ããµã¤ãºã®ã¿è¨å®ããã
|
---|
297 | */
|
---|
298 | if (flags & TCP_FLG_SYN) {
|
---|
299 | cep->snd_nxt = cep->iss;
|
---|
300 |
|
---|
301 | #ifdef TCP_CFG_OPT_MSS
|
---|
302 |
|
---|
303 | optp = GET_TCP_OPT(output, IF_IP_TCP_HDR_OFFSET);
|
---|
304 | *optp ++ = TCP_OPT_MAXSEG;
|
---|
305 | *optp ++ = TCP_OPT_LEN_MAXSEG;
|
---|
306 | *(uint16_t*)optp = htons(DEF_TCP_RCV_SEG);
|
---|
307 |
|
---|
308 | #endif/* of #ifdef TCP_CFG_OPT_MSS */
|
---|
309 |
|
---|
310 | }
|
---|
311 |
|
---|
312 | /* TCP SDU ã«éä¿¡ãã¼ã¿ãã³ãã¼ããã*/
|
---|
313 |
|
---|
314 | if (len > 0) {
|
---|
315 | if (SEQ_LT(cep->snd_nxt, cep->snd_max)) {
|
---|
316 | NET_COUNT_TCP(net_count_tcp[NC_TCP_SEND_REXMIT_SEGS], 1);
|
---|
317 | NET_COUNT_MIB(tcp_stats.tcpRetransSegs, 1);
|
---|
318 | }
|
---|
319 | TCP_READ_SWBUF(cep, output, len, doff);
|
---|
320 | }
|
---|
321 | else {
|
---|
322 | if (cep->flags & TCP_CEP_FLG_ACK_NOW)
|
---|
323 | NET_COUNT_TCP(net_count_tcp[NC_TCP_SEND_ACKS], 1);
|
---|
324 | if (flags & (TCP_FLG_FIN | TCP_FLG_SYN | TCP_FLG_RST))
|
---|
325 | NET_COUNT_TCP(net_count_tcp[NC_TCP_SEND_CNTL_SEGS], 1);
|
---|
326 |
|
---|
327 |
|
---|
328 | #ifdef TCP_CFG_EXTENTIONS
|
---|
329 |
|
---|
330 | if (SEQ_LT(cep->snd_up, cep->snd_una))
|
---|
331 | NET_COUNT_TCP(net_count_tcp[NC_TCP_SEND_URG_SEGS], 1);
|
---|
332 |
|
---|
333 | #endif /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
334 |
|
---|
335 | }
|
---|
336 |
|
---|
337 | /*
|
---|
338 | * snd_max: éä¿¡ããæ大 SEQ
|
---|
339 | * snd_nxt: 次ã«éä¿¡ãã SEQ
|
---|
340 | *
|
---|
341 | * ç¸æãã FIN ãåä¿¡ããã¾ã FIN ãéä¿¡ãã¦ããªããã
|
---|
342 | * éããã¼ã¿ããªãã¨ãã¯ãFIN ãç¸æã«å±ããããã
|
---|
343 | * ã»ã°ã¡ã³ããéä¿¡ããããSEQ ã¯é²ããªãã
|
---|
344 | */
|
---|
345 | if ((flags & TCP_FLG_FIN) && (cep->flags & TCP_CEP_FLG_SENT_FIN) &&
|
---|
346 | cep->snd_nxt == cep->snd_max) {
|
---|
347 | cep->snd_nxt --;
|
---|
348 | }
|
---|
349 |
|
---|
350 | tcph = GET_TCP_HDR(output, IF_IP_TCP_HDR_OFFSET);
|
---|
351 |
|
---|
352 | /*
|
---|
353 | * SEQãACKããã©ã°ã®è¨å®ã
|
---|
354 | */
|
---|
355 | if (len > 0 || (flags & (TCP_FLG_SYN | TCP_FLG_FIN)) || cep->timer[TCP_TIM_PERSIST] != 0)
|
---|
356 | tcph->seq = htonl(cep->snd_nxt);
|
---|
357 | else
|
---|
358 | tcph->seq = htonl(cep->snd_max);
|
---|
359 |
|
---|
360 | /*
|
---|
361 | * rcv_nxt: åä¿¡ãæå¾
|
---|
362 | ãã¦ããæå°ã® SEQ
|
---|
363 | */
|
---|
364 | tcph->ack = htonl(cep->rcv_nxt);
|
---|
365 | tcph->flags = flags;
|
---|
366 |
|
---|
367 | /*
|
---|
368 | * åä¿¡ã¦ã£ã³ãã®è¨ç®
|
---|
369 | *
|
---|
370 | * rbufsz: åä¿¡ç¨ãããã¡ãµã¤ãº
|
---|
371 | * maxseg: ç¸æã®æ大åä¿¡ã»ã°ã¡ã³ããµã¤ãº
|
---|
372 | */
|
---|
373 | if (win < (cep->rbufsz / 4) && win < cep->maxseg)
|
---|
374 | win = 0;
|
---|
375 |
|
---|
376 | /*
|
---|
377 | * rcv_nxt: åä¿¡ãæå¾
|
---|
378 | ãã¦ããæå°ã® SEQ
|
---|
379 | * rcv_adv: åä¿¡ãæå¾
|
---|
380 | ãã¦ããæ大㮠SEQ
|
---|
381 | */
|
---|
382 | if ((int32_t)win < (int32_t)(cep->rcv_adv - cep->rcv_nxt))
|
---|
383 | win = (uint_t)(cep->rcv_adv - cep->rcv_nxt);
|
---|
384 |
|
---|
385 | tcph->win = htons(win);
|
---|
386 |
|
---|
387 | #ifdef TCP_CFG_EXTENTIONS
|
---|
388 |
|
---|
389 | /*
|
---|
390 | * ç·æ¥ãã¤ã³ã¿ã®è¨å®
|
---|
391 | */
|
---|
392 | if (SEQ_GT(cep->snd_up, cep->snd_nxt)) {
|
---|
393 | if (TCP_CFG_URG_OFFSET)
|
---|
394 | tcph->urp = htons((uint16_t)(cep->snd_up - cep->snd_nxt));
|
---|
395 | else
|
---|
396 | tcph->urp = htons((uint16_t)(cep->snd_up - cep->snd_nxt - 1));
|
---|
397 | tcph->flags |= TCP_FLG_URG;
|
---|
398 | }
|
---|
399 | else
|
---|
400 | cep->snd_up = cep->snd_una;
|
---|
401 |
|
---|
402 | #endif /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
403 |
|
---|
404 | /*
|
---|
405 | * ãã§ãã¯ãµã ãè¨å®ããã
|
---|
406 | */
|
---|
407 | tcph->sum = 0;
|
---|
408 | tcph->sum = IN_CKSUM(output, IPPROTO_TCP, (uint_t)GET_TCP_HDR_OFFSET(output),
|
---|
409 | GET_TCP_HDR_SIZE2(output, IF_IP_TCP_HDR_OFFSET) + len);
|
---|
410 |
|
---|
411 | /* ãããã¯ã¼ã¯ãããã¡é·ã調æ´ããã*/
|
---|
412 | output->len = (uint16_t)(GET_IF_IP_TCP_HDR_SIZE2(output, IF_IP_TCP_HDR_OFFSET) + len);
|
---|
413 |
|
---|
414 | /*
|
---|
415 | * ã¿ã¤ãã®èª¿æ´
|
---|
416 | */
|
---|
417 | if ((cep->flags & TCP_CEP_FLG_FORCE) == 0 || cep->timer[TCP_TIM_PERSIST] == 0) {
|
---|
418 | T_TCP_SEQ startseq = cep->snd_nxt;
|
---|
419 |
|
---|
420 | /*
|
---|
421 | * 次ã«éä¿¡ãã SEQ (snd_nxt) ãä»åéä¿¡ãããã¼ã¿æ°åé²ããã
|
---|
422 | */
|
---|
423 | if (flags & TCP_FLG_SYN)
|
---|
424 | cep->snd_nxt ++;
|
---|
425 | if (flags & TCP_FLG_FIN) {
|
---|
426 | cep->flags |= TCP_CEP_FLG_SENT_FIN;
|
---|
427 | cep->snd_nxt ++;
|
---|
428 | }
|
---|
429 |
|
---|
430 | cep->snd_nxt += len;
|
---|
431 |
|
---|
432 | /*
|
---|
433 | * 次ã«éä¿¡ãã SEQ (snd_nxt) ã
|
---|
434 | * éä¿¡ããæ大 SEQ (snd_max) ããé²ãã§ããã°ã
|
---|
435 | * éä¿¡ããæ大 SEQ (snd_max) ãæ´æ°ããã
|
---|
436 | */
|
---|
437 | if (SEQ_GT(cep->snd_nxt, cep->snd_max)) {
|
---|
438 | cep->snd_max = cep->snd_nxt;
|
---|
439 | /*
|
---|
440 | * ãããå¾å¾©æéè¨æ¸¬ãè¡ã£ã¦ããªããã°ã
|
---|
441 | * ãã®éä¿¡ã«æéãåãããã
|
---|
442 | */
|
---|
443 | if (cep->rtt == 0) {
|
---|
444 | cep->rtt = 1;
|
---|
445 | cep->rtseq = startseq; /* æ´æ°åã® cep->snd_nxt */
|
---|
446 | }
|
---|
447 | }
|
---|
448 |
|
---|
449 | /*
|
---|
450 | * ããè¨å®ããã¦ããªãããACK ã¾ãã¯ä¿çãçºçãã¦ããªããã°ã
|
---|
451 | * åéã¿ã¤ããè¨å®ãããè¨å®ããåæå¤ã¯ã
|
---|
452 | * ãæ»ãããªå¾å¾©æé + 2 à å¾å¾©æéå¤åãã§ããã
|
---|
453 | * åéæéã®ããã¯ãªãã«ä½¿ãããã·ããã«ã¦ã³ããåæåããã
|
---|
454 | */
|
---|
455 | if (cep->timer[TCP_TIM_REXMT] == 0 && cep->snd_nxt != cep->snd_una) {
|
---|
456 | cep->timer[TCP_TIM_REXMT] = cep->rxtcur;
|
---|
457 | if (cep->timer[TCP_TIM_PERSIST] != 0) {
|
---|
458 | cep->timer[TCP_TIM_PERSIST] = 0;
|
---|
459 | cep->rxtshift = 0;
|
---|
460 | }
|
---|
461 | }
|
---|
462 | }
|
---|
463 |
|
---|
464 | /*
|
---|
465 | * 次ã«éä¿¡ãã SEQ (snd_nxt) + ä»åéä¿¡ãããã¼ã¿æ° (len) ã
|
---|
466 | * éä¿¡ããæ大 SEQ (snd_max) ããé²ãã§ããã°ã
|
---|
467 | * éä¿¡ããæ大 SEQ (snd_max) ãæ´æ°ããã
|
---|
468 | */
|
---|
469 | else if (SEQ_GT(cep->snd_nxt + len, cep->snd_max))
|
---|
470 | cep->snd_max = cep->snd_nxt + len;
|
---|
471 |
|
---|
472 | #ifdef TCP_CFG_SWBUF_CSAVE
|
---|
473 |
|
---|
474 | if ((cep->flags & TCP_CEP_FLG_WBCS_MASK) == TCP_CEP_FLG_WBCS_SEND_READY)
|
---|
475 | cep->flags = (cep->flags & ~TCP_CEP_FLG_WBCS_MASK) | TCP_CEP_FLG_WBCS_SENT;
|
---|
476 |
|
---|
477 | #endif /* of #ifdef TCP_CFG_SWBUF_CSAVE */
|
---|
478 |
|
---|
479 | #ifdef TCP_CFG_TRACE
|
---|
480 |
|
---|
481 | tcp_output_trace(output, cep);
|
---|
482 |
|
---|
483 | #endif /* of #ifdef TCP_CFG_TRACE */
|
---|
484 |
|
---|
485 | /* ãããã¯ã¼ã¯å±¤ (IP) ã®åºåé¢æ°ãå¼ã³åºãã*/
|
---|
486 | if ((error = IP_OUTPUT(output, TMO_TCP_OUTPUT)) != E_OK)
|
---|
487 | goto err_ret;
|
---|
488 |
|
---|
489 | /*
|
---|
490 | * ç¸æã«ä¼ããã¦ã£ã³ãã¦ãµã¤ãº (win) ã 0 以ä¸ã§ã
|
---|
491 | * åä¿¡ãæå¾
|
---|
492 | ãã¦ããæå°ã® SEQ (rcv_nxt) + win ã
|
---|
493 | * åä¿¡ãæå¾
|
---|
494 | ãã¦ããæ大㮠SEQ (rcv_adv) ããé²ãã§ããã°
|
---|
495 | * åä¿¡ãæå¾
|
---|
496 | ãã¦ããæ大㮠SEQ ãæ´æ°ããã
|
---|
497 | */
|
---|
498 | if (win > 0 && SEQ_GT(cep->rcv_nxt + win, cep->rcv_adv)) {
|
---|
499 | cep->rcv_adv = cep->rcv_nxt + win;
|
---|
500 | }
|
---|
501 |
|
---|
502 | /*
|
---|
503 | * æå¾ã«éä¿¡ãã ACK (last_ack_sent) ãæ´æ°ããã
|
---|
504 | */
|
---|
505 | cep->last_ack_sent = cep->rcv_nxt;
|
---|
506 |
|
---|
507 | /*
|
---|
508 | * ãã©ã°ã®è¨å®ãè¡ãã
|
---|
509 | */
|
---|
510 | cep->flags &= ~(TCP_CEP_FLG_ACK_NOW | TCP_CEP_FLG_DEL_ACK);
|
---|
511 | if (cep->flags & TCP_CEP_FLG_FORCE_CLEAR)
|
---|
512 | cep->flags &= ~(TCP_CEP_FLG_FORCE | TCP_CEP_FLG_FORCE_CLEAR);
|
---|
513 |
|
---|
514 | return E_OK;
|
---|
515 |
|
---|
516 | err_ret:
|
---|
517 | /*
|
---|
518 | * 以ä¸ã«é¢ä¿ããªããã©ã°ãã¯ãªã¢ã¼ããã
|
---|
519 | * ã»éåä¿¡ã¦ã£ã³ããããã¡ã®çã³ãã¼æ©è½
|
---|
520 | * ã»åçãªé信端ç¹ã®çæã»åé¤æ©è½
|
---|
521 | */
|
---|
522 | cep->flags &= (TCP_CEP_FLG_WBCS_NBUF_REQ | TCP_CEP_FLG_WBCS_MASK |
|
---|
523 | TCP_CEP_FLG_DYNAMIC | TCP_CEP_FLG_VALID);
|
---|
524 |
|
---|
525 | return error;
|
---|
526 | }
|
---|
527 |
|
---|
528 | /*
|
---|
529 | * tcp_output -- TCP åºåå¦ç
|
---|
530 | */
|
---|
531 |
|
---|
532 | void
|
---|
533 | tcp_output (T_TCP_CEP *cep)
|
---|
534 | {
|
---|
535 | bool_t sendalot = true, idle;
|
---|
536 | ER error = E_OK;
|
---|
537 | int32_t len;
|
---|
538 | uint_t doff, win;
|
---|
539 | uint8_t flags;
|
---|
540 |
|
---|
541 | /*
|
---|
542 | * snd_una: æªç¢ºèªã®æå°éä¿¡ SEQ ã¾ãã¯ã確èªãããæ大éä¿¡ SEQ
|
---|
543 | * snd_max: éä¿¡ããæ大 SEQ
|
---|
544 | */
|
---|
545 | idle = (cep->snd_max == cep->snd_una);
|
---|
546 |
|
---|
547 | /*
|
---|
548 | * idle: ã¢ã¤ãã«æé
|
---|
549 | * rxtcur: ç¾å¨ã®åéã¿ã¤ã ã¢ã¦ã
|
---|
550 | */
|
---|
551 | if (idle && cep->idle >= cep->rxtcur)
|
---|
552 |
|
---|
553 | /*
|
---|
554 | * snd_cwnd: 輻輳ã¦ã£ã³ããµã¤ãº
|
---|
555 | * maxseg : ç¸æã®æ大åä¿¡ã»ã°ã¡ã³ããµã¤ãº
|
---|
556 | *
|
---|
557 | * é·æéã¢ã¤ãã«ã ã£ãã®ã§ã¹ãã¼ã¹ã¿ã¼ãå¶å¾¡ã«è¨å®ããã
|
---|
558 | */
|
---|
559 | cep->snd_cwnd = cep->maxseg;
|
---|
560 |
|
---|
561 | while (error == E_OK && sendalot) {
|
---|
562 | sendalot = false;
|
---|
563 |
|
---|
564 | /*
|
---|
565 | * snd_nxt: 次ã«éä¿¡ãã SEQããã®æç¹ã§ã¯ãååéä¿¡ãã SEQ
|
---|
566 | * snd_una: æªç¢ºèªã®æå°éä¿¡ SEQãã¾ãã¯ç¢ºèªãããæ大éä¿¡ SEQ
|
---|
567 | *
|
---|
568 | * doff: éä¿¡ãéå§ãããªãã»ããã
|
---|
569 | * swbuf_count (éä¿¡ãããã¡ã«ãããªã¯ãããæ°)
|
---|
570 | * 0 V
|
---|
571 | * +-------------------------------------------+
|
---|
572 | * | sbuf |
|
---|
573 | * +-------------------------------------------+
|
---|
574 | * ^ ^
|
---|
575 | * |<------------->snd_nxt (ååéä¿¡ãã SEQ)
|
---|
576 | * | doff
|
---|
577 | * snd_una (ã¾ã 確èªããã¦ããªã)
|
---|
578 | */
|
---|
579 | doff = (uint_t)(cep->snd_nxt - cep->snd_una);
|
---|
580 |
|
---|
581 | /*
|
---|
582 | * snd_wnd: ç¸æã®åä¿¡å¯è½ã¦ã£ã³ããµã¤ãº
|
---|
583 | * snd_cwnd: 輻輳ã¦ã£ã³ããµã¤ãº
|
---|
584 | *
|
---|
585 | * win: ã©ã¡ããå°ããã¦ã£ã³ããµã¤ãºã«è¨å®ããã
|
---|
586 | */
|
---|
587 | win = cep->snd_wnd < cep->snd_cwnd ? cep->snd_wnd : cep->snd_cwnd;
|
---|
588 |
|
---|
589 | /* åºåãã©ã°ã®è¨å® */
|
---|
590 | flags = tcp_outflags[cep->fsm_state];
|
---|
591 | if (cep->flags & TCP_CEP_FLG_NEED_FIN)
|
---|
592 | flags |= TCP_FLG_FIN;
|
---|
593 | if (cep->flags & TCP_CEP_FLG_NEED_SYN)
|
---|
594 | flags |= TCP_FLG_SYN;
|
---|
595 | if (cep->flags & TCP_CEP_FLG_FORCE) {
|
---|
596 |
|
---|
597 | /*
|
---|
598 | * ãããéä¿¡ã¦ã¤ã³ããµã¤ãº (win) ã 0 ãªã 1 ãªã¯ãããéä¿¡ããã
|
---|
599 | * ããã§ãªããã°ãæç¶ã¿ã¤ã ã¢ã¦ãããã£ã³ã»ã«ãã
|
---|
600 | * åéä¿¡åæ° (rxtshift) ã 0 ã«ããã
|
---|
601 | */
|
---|
602 | if (win == 0) {
|
---|
603 |
|
---|
604 | /*
|
---|
605 | * doff: éä¿¡ãããªã¯ãããæ°ã
|
---|
606 | * swbuf_count: éä¿¡ãããã¡ã®ä½¿ç¨ä¸ãµã¤ãº
|
---|
607 | *
|
---|
608 | * éä¿¡ãããã¡ã«æ®ã£ã¦ãããªã¯ããããããããã
|
---|
609 | * éä¿¡ãããã¨ãã¦ãããªã¯ãããæ°ããå¤ããã°
|
---|
610 | * FIN ãã©ã°ãã¯ãªã¢ããã
|
---|
611 | */
|
---|
612 | if (doff < cep->swbuf_count)
|
---|
613 | flags &=~TCP_FLG_FIN;
|
---|
614 | win = 1;
|
---|
615 | }
|
---|
616 | else {
|
---|
617 | /*
|
---|
618 | * TCP_TIM_PERSIST: æç¶ã¿ã¤ã
|
---|
619 | * rxtshift: åéä¿¡åæ°ã® log(2)
|
---|
620 | */
|
---|
621 | cep->timer[TCP_TIM_PERSIST] = 0;
|
---|
622 | cep->rxtshift = 0;
|
---|
623 | }
|
---|
624 | }
|
---|
625 |
|
---|
626 | /*
|
---|
627 | * len: ä»åéä¿¡ãããªã¯ãããæ°
|
---|
628 | * swbuf_count (éä¿¡ãããã¡ã«ãããªã¯ãããæ°)
|
---|
629 | * |
|
---|
630 | * 0 V
|
---|
631 | * +-------------------------------------------+
|
---|
632 | * | sbuf | |
|
---|
633 | * +-------------------------------------------+
|
---|
634 | * ^ ^<------------->
|
---|
635 | * | | len
|
---|
636 | * |<------------->snd_nxt (ååéä¿¡ãã SEQ)
|
---|
637 | * | doff
|
---|
638 | * snd_una (ã¾ã 確èªããã¦ããªã)
|
---|
639 | */
|
---|
640 | if (cep->swbuf_count < win)
|
---|
641 | len = (int32_t)cep->swbuf_count - doff;
|
---|
642 | else
|
---|
643 | len = (int32_t)win - doff;
|
---|
644 |
|
---|
645 | /*
|
---|
646 | * ãã§ã«éä¿¡ããã¦ããã°ãSYN ãããããªãããã
|
---|
647 | * ãããã以ä¸ã®æ¡ä»¶ã§ã¯éä¿¡ãæ§ããã
|
---|
648 | *
|
---|
649 | * ã»ç¶æ
|
---|
650 | ã SYN éä¿¡ã
|
---|
651 | * ã»ã»ã°ã¡ã³ãããã¼ã¿ãå«ãã§ããã
|
---|
652 | */
|
---|
653 | if ((flags & TCP_FLG_SYN) && SEQ_GT(cep->snd_nxt, cep->snd_una)) {
|
---|
654 | flags &= ~TCP_FLG_SYN;
|
---|
655 | doff --; /* -1 㯠SYN ãã©ã°å */
|
---|
656 | len ++; /* +1 㯠SYN ãã©ã°å */
|
---|
657 | if (len > 0 && cep->fsm_state == TCP_FSM_SYN_SENT)
|
---|
658 | break;
|
---|
659 | }
|
---|
660 |
|
---|
661 | if (flags & TCP_FLG_SYN) {
|
---|
662 | len = 0;
|
---|
663 | flags &= ~TCP_FLG_FIN;
|
---|
664 | }
|
---|
665 |
|
---|
666 | if (len < 0) {
|
---|
667 |
|
---|
668 | /*
|
---|
669 | * len ã 0 以ä¸ãªãã0 ã«è¨å®ããã
|
---|
670 | * ãããéä¿¡ã¦ã£ã³ãã¦ãµã¤ãºã 0 ãªãã
|
---|
671 | * åéä¿¡ã¿ã¤ãããã£ã³ã»ã«ãã
|
---|
672 | * ååéä¿¡ãã SEQ (snd_nxt) ã
|
---|
673 | * 確èªãããæ大éä¿¡ SEQ (snd_una) ã«æ»ãã
|
---|
674 | * ããã¦ãæç¶ã¿ã¤ãã¼ãæ¢ã¾ã£ã¦ããã°ãåè¨å®ããã
|
---|
675 | */
|
---|
676 | len = 0;
|
---|
677 | if (win == 0) {
|
---|
678 | cep->timer[TCP_TIM_REXMT] = 0;
|
---|
679 | cep->rxtshift = 0;
|
---|
680 | cep->snd_nxt = cep->snd_una;
|
---|
681 | if (cep->timer[TCP_TIM_PERSIST] == 0)
|
---|
682 | tcp_set_persist_timer(cep);
|
---|
683 | }
|
---|
684 | }
|
---|
685 |
|
---|
686 |
|
---|
687 | /*
|
---|
688 | * ä»åéä¿¡ãããªã¯ãããæ° (len) ã¯ã
|
---|
689 | * ç¸æã®æ大åä¿¡ã»ã°ã¡ã³ããµã¤ãº (maxseg) ãè¶
|
---|
690 | ããªãããã«ããã
|
---|
691 | */
|
---|
692 | if (len > cep->maxseg) {
|
---|
693 | len = cep->maxseg;
|
---|
694 | sendalot = true;
|
---|
695 | }
|
---|
696 |
|
---|
697 | /*
|
---|
698 | * swbuf_count (éä¿¡ãããã¡ã«ãããªã¯ãããæ°)
|
---|
699 | * |
|
---|
700 | * 0 V
|
---|
701 | * +-------------------------------------------+
|
---|
702 | * | sbuf | |
|
---|
703 | * +-------------------------------------------+
|
---|
704 | * ^ ^<------------->
|
---|
705 | * | | len
|
---|
706 | * |<------------->snd_nxt (ååéä¿¡ãã SEQ)
|
---|
707 | * | doff
|
---|
708 | * snd_una (ã¾ã 確èªããã¦ããªã)
|
---|
709 | *
|
---|
710 | * ä»åéä¿¡å¾ããéä¿¡ãããã¡ã«ãã¼ã¿ãæ®ã£ã¦ããã°
|
---|
711 | * FIN ãã©ã°ãã¯ãªã¢ããã
|
---|
712 | */
|
---|
713 | if (SEQ_LT(cep->snd_nxt + len, cep->snd_una + cep->swbuf_count))
|
---|
714 | flags &= ~TCP_FLG_FIN;
|
---|
715 |
|
---|
716 | /*
|
---|
717 | * ãããã win ã¯ãåä¿¡ã¦ã£ã³ãã¦ãµã¤ãºã
|
---|
718 | * åä¿¡ãããã¡ã®ç©ºã容é
|
---|
719 | */
|
---|
720 | win = cep->rbufsz - cep->rwbuf_count;
|
---|
721 |
|
---|
722 | /*
|
---|
723 | * æããªã¦ã£ã³ãã¦ã»ã·ã³ããã¼ã ã®åé¿å¦ç (éä¿¡å´)
|
---|
724 | *
|
---|
725 | * 以ä¸ã®æ¡ä»¶ã§ãéä¿¡ãè¡ãã
|
---|
726 | *
|
---|
727 | * ã»ãã«ãµã¤ãº (maxseg) ã®ã»ã°ã¡ã³ããéããã¨ãã§ããã
|
---|
728 | * ã»ç¸æã®æ大ã®åä¿¡ã¦ã£ã³ãã¦ãµã¤ãºã® 1/2 ã®ãã¼ã¿ã
|
---|
729 | * éããã¨ãã§ããã
|
---|
730 | * ã»éä¿¡ãããã¡ã空ã«ã§ããã¢ã¤ãã«ãéé
|
---|
731 | 延ãªãã·ã§ã³ãæå¹ãªã¨ãã
|
---|
732 | */
|
---|
733 | if (len) {
|
---|
734 |
|
---|
735 | /*
|
---|
736 | * ä»åéä¿¡ãããªã¯ãããæ° (len) ã
|
---|
737 | * ç¸æã®æ大åä¿¡ã»ã°ã¡ã³ããµã¤ãº (maxseg) ã«
|
---|
738 | * ä¸è´ããã¨ãã¯éä¿¡ããã
|
---|
739 | */
|
---|
740 | if (len == cep->maxseg) {
|
---|
741 | error = send_segment(&sendalot, cep, doff, win, (uint_t)len, flags);
|
---|
742 | continue;
|
---|
743 | }
|
---|
744 |
|
---|
745 | /*
|
---|
746 | * ä»åã®éä¿¡ã§ãéä¿¡ãããã¡ã空ã«ã§ãã
|
---|
747 | * ã¢ã¤ãã«ãé PUSH ãªãã·ã§ã³ãæå¹ãªã¨ãã
|
---|
748 | */
|
---|
749 | if ((idle || (cep->flags & TCP_CEP_FLG_NO_DELAY)) &&
|
---|
750 | (cep->flags & TCP_CEP_FLG_NO_PUSH) == 0 &&
|
---|
751 | len + doff >= cep->swbuf_count) {
|
---|
752 | error = send_segment(&sendalot, cep, doff, win, (uint_t)len, flags);
|
---|
753 | continue;
|
---|
754 | }
|
---|
755 |
|
---|
756 | /*
|
---|
757 | * max_sndwnd: ä»ã¾ã§ã®æ大éä¿¡ã¦ã£ã³ããµã¤ãº
|
---|
758 | * snd_nxt: 次ã«éä¿¡ãã SEQ
|
---|
759 | * snd_max: éä¿¡ããæ大 SEQ
|
---|
760 | *
|
---|
761 | * 次ã®æ¡ä»¶ã§ã¯éä¿¡ãè¡ãã
|
---|
762 | *
|
---|
763 | * ã»å¼·å¶éä¿¡ãã©ã°ãã»ããããã¦ããã
|
---|
764 | * ã»ãã¼ã¿é·ãç¸æã®æ大ã®åä¿¡ã¦ã£ã³ãã¦ãµã¤ãºã® 1/2 以ä¸ã§ã
|
---|
765 | * ç¸æã®æ大ã®åä¿¡ã¦ã£ã³ãã¦ãµã¤ãºã 0 ãã大ããã
|
---|
766 | * ã»æ¬¡ã«éä¿¡ãã SEQ ãéä¿¡ããæ大 SEQ ããå°ããã
|
---|
767 | * ã¤ã¾ããåéããã¨ãã
|
---|
768 | */
|
---|
769 | if ((cep->flags & TCP_CEP_FLG_FORCE) ||
|
---|
770 | (len >= cep->max_sndwnd / 2 && cep->max_sndwnd > 0) ||
|
---|
771 | SEQ_LT(cep->snd_nxt, cep->snd_max)) {
|
---|
772 | error = send_segment(&sendalot, cep, doff, win, (uint_t)len, flags);
|
---|
773 | continue;
|
---|
774 | }
|
---|
775 | }
|
---|
776 |
|
---|
777 |
|
---|
778 | /*
|
---|
779 | * æããªã¦ã£ã³ãã¦ã»ã·ã³ããã¼ã ã®åé¿å¦ç (åä¿¡å´)
|
---|
780 | *
|
---|
781 | * ã¦ã£ã³ãã¦ãµã¤ãºããã«ãµã¤ãºã® 2 åã®ã»ã°ã¡ã³ãããããã¯
|
---|
782 | * åä¿¡ãããã¡å®¹éã® 1/2 ã®ãããããå°ããã»ãã®
|
---|
783 | * ãµã¤ãºã§å¢å ãããå ´åã¯ãã¦ã£ã³ãã¦ãµã¤ãºã®æ´æ°ãè¡ãã
|
---|
784 | */
|
---|
785 | if (win > 0) {
|
---|
786 | long adv;
|
---|
787 |
|
---|
788 | /*
|
---|
789 | * win: åä¿¡ãããã¡ã®ç©ºã容é
|
---|
790 | * MAX_TCP_WIN_SIZE: TCP ãããã® win ãã£ã¼ã«ãã«è¨å®ã§ããæ大å¤
|
---|
791 | * rcv_adv: åä¿¡ãæå¾
|
---|
792 | ãã¦ããæ大㮠SEQ
|
---|
793 | * rcv_nxt: åä¿¡ãæå¾
|
---|
794 | ãã¦ããæå°ã® SEQ
|
---|
795 | */
|
---|
796 | if (win < MAX_TCP_WIN_SIZE)
|
---|
797 | adv = win - (cep->rcv_adv - cep->rcv_nxt);
|
---|
798 | else
|
---|
799 | adv = MAX_TCP_WIN_SIZE - (cep->rcv_adv - cep->rcv_nxt);
|
---|
800 |
|
---|
801 | if (adv >= (long)(cep->maxseg * 2) ||
|
---|
802 | adv * 2 >= (long) cep->rbufsz) {
|
---|
803 | error = send_segment(&sendalot, cep, doff, win, (uint_t)len, flags);
|
---|
804 | continue;
|
---|
805 | }
|
---|
806 | }
|
---|
807 |
|
---|
808 | /*
|
---|
809 | * ACK ãéä¿¡ããã
|
---|
810 | */
|
---|
811 | if (cep->flags & TCP_CEP_FLG_ACK_NOW) {
|
---|
812 | error = send_segment(&sendalot, cep, doff, win, (uint_t)len, flags);
|
---|
813 | continue;
|
---|
814 | }
|
---|
815 |
|
---|
816 | if ( (flags & TCP_FLG_RST) ||
|
---|
817 | ((flags & TCP_FLG_SYN) && (cep->flags & TCP_CEP_FLG_NEED_SYN) == 0)) {
|
---|
818 | error = send_segment(&sendalot, cep, doff, win, (uint_t)len, flags);
|
---|
819 | continue;
|
---|
820 | }
|
---|
821 |
|
---|
822 | #ifdef TCP_CFG_EXTENTIONS
|
---|
823 |
|
---|
824 | if (SEQ_GT(cep->snd_up, cep->snd_una)) {
|
---|
825 | error = send_segment(&sendalot, cep, doff, win, (uint_t)len, flags);
|
---|
826 | continue;
|
---|
827 | }
|
---|
828 |
|
---|
829 | #endif /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
830 |
|
---|
831 | /*
|
---|
832 | * snd_nxt: 次ã«éä¿¡ãã SEQ
|
---|
833 | * snd_una: æªç¢ºèªã®æå°éä¿¡ SEQãã¾ãã¯ç¢ºèªãããæ大éä¿¡ SEQ
|
---|
834 | *
|
---|
835 | * ç¸æãã FIN ãåä¿¡ããã¾ã FIN ãéä¿¡ãã¦ããªããã
|
---|
836 | * éããã¼ã¿ããªãã¨ãã¯ãFIN ãç¸æã«å±ããããã
|
---|
837 | * ã»ã°ã¡ã³ããéä¿¡ããã
|
---|
838 | */
|
---|
839 | if ((flags & TCP_FLG_FIN) &&
|
---|
840 | ((cep->flags & TCP_CEP_FLG_SENT_FIN) == 0 || cep->snd_nxt == cep->snd_una)) {
|
---|
841 | error = send_segment(&sendalot, cep, doff, win, (uint_t)len, flags);
|
---|
842 | continue;
|
---|
843 | }
|
---|
844 |
|
---|
845 | /*
|
---|
846 | * éä¿¡ãã¹ããã¼ã¿ããããåéã¿ã¤ãã¨æç¶ã¿ã¤ããåãã¦ããã¨ãã¯
|
---|
847 | * æç¶ã¿ã¤ããè¨å®ããã
|
---|
848 | */
|
---|
849 | if (cep->swbuf_count && cep->timer[TCP_TIM_REXMT ] == 0 &&
|
---|
850 | cep->timer[TCP_TIM_PERSIST] == 0) {
|
---|
851 | cep->rxtshift = 0;
|
---|
852 | tcp_set_persist_timer(cep);
|
---|
853 | break;
|
---|
854 | }
|
---|
855 |
|
---|
856 | }
|
---|
857 | }
|
---|
858 |
|
---|
859 | #ifdef TCP_CFG_SWBUF_CSAVE
|
---|
860 |
|
---|
861 | /*
|
---|
862 | * tcptsk_alloc_swbufq -- éä¿¡ã¦ã£ã³ããããã¡å²ãå½ã¦
|
---|
863 | */
|
---|
864 |
|
---|
865 | static void
|
---|
866 | tcptsk_alloc_swbufq (T_TCP_CEP *cep)
|
---|
867 | {
|
---|
868 | ER error;
|
---|
869 | uint_t win;
|
---|
870 |
|
---|
871 | /*
|
---|
872 | * snd_wnd: ç¸æã®åä¿¡å¯è½ã¦ã£ã³ããµã¤ãº
|
---|
873 | * snd_cwnd: 輻輳ã¦ã£ã³ããµã¤ãº
|
---|
874 | *
|
---|
875 | * win: ã©ã¡ããå°ããã¦ã£ã³ããµã¤ãºã«è¨å®ããã
|
---|
876 | */
|
---|
877 | win = cep->snd_wnd < cep->snd_cwnd ? cep->snd_wnd : cep->snd_cwnd;
|
---|
878 |
|
---|
879 | /*
|
---|
880 | * ç¸æã®åä¿¡ã¦ã£ã³ããéãã¦ããå ´åã¯ãéãã¾ã§å¾
|
---|
881 | æ©ããã
|
---|
882 | */
|
---|
883 | if (win == 0) {
|
---|
884 | cep->flags = (cep->flags & ~TCP_CEP_FLG_WBCS_MASK) | TCP_CEP_FLG_WBCS_WOPEN_PEND;
|
---|
885 | }
|
---|
886 | else {
|
---|
887 |
|
---|
888 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
889 |
|
---|
890 | /* ãã³ããããã³ã°ã³ã¼ã« */
|
---|
891 | if (!IS_PTR_DEFINED(cep->callback)) {
|
---|
892 | syslog(LOG_WARNING, "[TCP] no call back, CEP: %d.", GET_TCP_CEPID(cep));
|
---|
893 |
|
---|
894 | /* è¨æ¶ããã¦ããã¿ã¹ã¯ ID 㨠API æ©è½ã³ã¼ããã¯ãªã¢ã¼ããã*/
|
---|
895 | cep->snd_tskid = TA_NULL;
|
---|
896 | cep->snd_tfn = cep->snd_nblk_tfn = TFN_TCP_UNDEF;
|
---|
897 | return;
|
---|
898 | }
|
---|
899 |
|
---|
900 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
901 |
|
---|
902 | if ((error = tcp_get_segment(&cep->swbufq, cep, 0,
|
---|
903 | (uint_t) TCP_CFG_SWBUF_CSAVE_MIN_SIZE,
|
---|
904 | (uint_t)(TCP_CFG_SWBUF_CSAVE_MAX_SIZE - IF_IP_TCP_HDR_SIZE),
|
---|
905 | (ATR)(NBA_SEARCH_DESCENT |
|
---|
906 | NBA_RESERVE_TCP |
|
---|
907 | (GET_TCP_CEPID(cep) & NBA_ID_MASK)), TMO_POL)) != E_OK) {
|
---|
908 |
|
---|
909 | /* ãããã¯ã¼ã¯ãããã¡ãäºç´ããã*/
|
---|
910 | cep->flags = (cep->flags & ~TCP_CEP_FLG_WBCS_MASK) | TCP_CEP_FLG_WBCS_NBUF_PEND;
|
---|
911 | }
|
---|
912 | else {
|
---|
913 |
|
---|
914 | /* éä¿¡ã¦ã£ã³ããããã¡ãåæåããã*/
|
---|
915 | tcp_init_swbuf(cep);
|
---|
916 |
|
---|
917 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
918 |
|
---|
919 | if (cep->snd_nblk_tfn == TFN_TCP_GET_BUF) {
|
---|
920 |
|
---|
921 | uint_t len;
|
---|
922 |
|
---|
923 | /* éä¿¡ã¦ã£ã³ããããã¡ã®æ¸ãè¾¼ã¿ã¢ãã¬ã¹ãè¨å®ããã*/
|
---|
924 | len = TCP_GET_SWBUF_ADDR(cep, cep->snd_p_buf);
|
---|
925 |
|
---|
926 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
927 |
|
---|
928 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
929 | (*cep->callback)(GET_TCP_CEPID(cep), cep->snd_nblk_tfn, (void*)(uint32_t)len);
|
---|
930 |
|
---|
931 | #else /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
932 |
|
---|
933 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
934 | (*cep->callback)(GET_TCP_CEPID(cep), cep->snd_nblk_tfn, (void*)&len);
|
---|
935 |
|
---|
936 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
937 |
|
---|
938 |
|
---|
939 | /* è¨æ¶ããã¦ããã¿ã¹ã¯ ID 㨠API æ©è½ã³ã¼ããã¯ãªã¢ã¼ããã*/
|
---|
940 | cep->snd_tskid = TA_NULL;
|
---|
941 | cep->snd_tfn = cep->snd_nblk_tfn = TFN_TCP_UNDEF;
|
---|
942 | }
|
---|
943 |
|
---|
944 | else { /* cep->snd_nblk_tfn == TFN_TCP_SND_DAT || */
|
---|
945 | /* cep->snd_nblk_tfn == TFN_TCP_SND_OOB */
|
---|
946 |
|
---|
947 | uint_t len;
|
---|
948 |
|
---|
949 | /* éä¿¡ã¦ã£ã³ããããã¡ã«ãã¼ã¿ãæ¸ãè¾¼ãã*/
|
---|
950 | len = TCP_WRITE_SWBUF(cep, cep->snd_data, (uint_t)cep->snd_len);
|
---|
951 |
|
---|
952 | #ifdef TCP_CFG_EXTENTIONS
|
---|
953 |
|
---|
954 | /* éä¿¡ç·æ¥ãã¤ã³ã¿ãè¨å®ããã*/
|
---|
955 | if (cep->snd_nblk_tfn == TFN_TCP_SND_OOB)
|
---|
956 | cep->snd_up = cep->snd_una + len;
|
---|
957 |
|
---|
958 | #endif /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
959 |
|
---|
960 | /* ãã©ã°ããéä¿¡å¯è½ã«è¨å®ããå¼·å¶çã«éä¿¡ããã*/
|
---|
961 | cep->flags |= TCP_CEP_FLG_FORCE | TCP_CEP_FLG_FORCE_CLEAR | TCP_CEP_FLG_POST_OUTPUT;
|
---|
962 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
963 |
|
---|
964 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
965 | (*cep->callback)(GET_TCP_CEPID(cep), cep->snd_nblk_tfn, (void*)(uint32_t)len);
|
---|
966 |
|
---|
967 | #else /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
968 |
|
---|
969 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
970 | (*cep->callback)(GET_TCP_CEPID(cep), cep->snd_nblk_tfn, (void*)&len);
|
---|
971 |
|
---|
972 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
973 |
|
---|
974 |
|
---|
975 | /* è¨æ¶ããã¦ããã¿ã¹ã¯ ID 㨠API æ©è½ã³ã¼ããã¯ãªã¢ã¼ããã*/
|
---|
976 | cep->snd_tskid = TA_NULL;
|
---|
977 | cep->snd_tfn = cep->snd_nblk_tfn = TFN_TCP_UNDEF;
|
---|
978 | }
|
---|
979 |
|
---|
980 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
981 |
|
---|
982 | }
|
---|
983 | }
|
---|
984 | }
|
---|
985 |
|
---|
986 | /*
|
---|
987 | * tcptsk_free_swbufq -- éä¿¡ã¦ã£ã³ããããã¡éæ¾
|
---|
988 | */
|
---|
989 |
|
---|
990 | static void
|
---|
991 | tcptsk_free_swbufq (T_TCP_CEP *cep)
|
---|
992 | {
|
---|
993 | /*
|
---|
994 | * å信確èªãå®äºãããããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ããã®
|
---|
995 | * åºåãå®äºããã¨ãã¯ãéä¿¡ã¦ã£ã³ããããã¡ãã¥ã¼ã解æ¾ããã
|
---|
996 | */
|
---|
997 |
|
---|
998 | /* éä¿¡ã¦ã£ã³ããããã¡ã®ä½¿ç¨ä¸ãµã¤ãºããªã»ããããã*/
|
---|
999 | cep->swbuf_count = 0;
|
---|
1000 |
|
---|
1001 | /* éä¿¡ã¦ã£ã³ããããã¡ãã¥ã¼ã®ãããã¯ã¼ã¯ãããã¡ã解æ¾ããã*/
|
---|
1002 | syscall(rel_net_buf(cep->swbufq));
|
---|
1003 | cep->swbufq = NULL;
|
---|
1004 |
|
---|
1005 | /* ãã©ã°ã空ãã«è¨å®ããã*/
|
---|
1006 | cep->flags = (cep->flags & ~TCP_CEP_FLG_WBCS_MASK) | TCP_CEP_FLG_WBCS_FREE;
|
---|
1007 |
|
---|
1008 | /* éä¿¡ã¦ã£ã³ããããã¡ã«ç©ºããã§ãããã¨ãç¥ãããã*/
|
---|
1009 | syscall(set_flg(cep->snd_flgid, TCP_CEP_EVT_SWBUF_READY));
|
---|
1010 |
|
---|
1011 | /* éä¿¡ã¦ã£ã³ããããã¡ã®ç©ºãå¾
|
---|
1012 | ã¡ã®ã¨ãã¯ãTCP åºåã¿ã¹ã¯ãèµ·åããã*/
|
---|
1013 | if ((cep->flags & TCP_CEP_FLG_WBCS_NBUF_REQ) != 0) {
|
---|
1014 | sig_sem(SEM_TCP_POST_OUTPUT);
|
---|
1015 | }
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | #endif /* of #ifdef TCP_CFG_SWBUF_CSAVE */
|
---|
1019 |
|
---|
1020 | /*
|
---|
1021 | * TCP åºåã¿ã¹ã¯
|
---|
1022 | */
|
---|
1023 |
|
---|
1024 | void
|
---|
1025 | tcp_output_task (intptr_t exinf)
|
---|
1026 | {
|
---|
1027 | static int_t last_ix = 0;
|
---|
1028 |
|
---|
1029 | T_TCP_CEP *cep;
|
---|
1030 | ID tskid;
|
---|
1031 | int_t ix, sel_ix;
|
---|
1032 |
|
---|
1033 | get_tid(&tskid);
|
---|
1034 | syslog(LOG_NOTICE, "[TCP OUTPUT:%d] started.", tskid);
|
---|
1035 |
|
---|
1036 | tcp_init();
|
---|
1037 |
|
---|
1038 | #ifdef SUPPORT_INET6
|
---|
1039 |
|
---|
1040 | /* IPv6 ã®ã¹ãã¼ãã¬ã¹ã»ã¢ãã¬ã¹èªåè¨å®ãå®è¡ããã*/
|
---|
1041 | in6_if_up(IF_GET_IFNET());
|
---|
1042 |
|
---|
1043 | #endif /* of #ifdef SUPPORT_INET6 */
|
---|
1044 |
|
---|
1045 | while (true) {
|
---|
1046 |
|
---|
1047 | /* åºåããã¹ããããã¾ã§å¾
|
---|
1048 | ã¤ã*/
|
---|
1049 | syscall(wai_sem(SEM_TCP_POST_OUTPUT));
|
---|
1050 |
|
---|
1051 | if (++ last_ix == tmax_tcp_cepid)
|
---|
1052 | last_ix = 0;
|
---|
1053 | sel_ix = ix = last_ix;
|
---|
1054 | do {
|
---|
1055 | cep = &tcp_cep[ix];
|
---|
1056 |
|
---|
1057 | #ifdef TCP_CFG_SWBUF_CSAVE
|
---|
1058 |
|
---|
1059 | if ((cep->flags & TCP_CEP_FLG_WBCS_NBUF_REQ) != 0 &&
|
---|
1060 | ((cep->flags & TCP_CEP_FLG_WBCS_MASK) == TCP_CEP_FLG_WBCS_FREE ||
|
---|
1061 | (cep->flags & TCP_CEP_FLG_WBCS_MASK) == TCP_CEP_FLG_WBCS_NBUF_RSVD)) {
|
---|
1062 | tcptsk_alloc_swbufq(cep);
|
---|
1063 | sel_ix = ix;
|
---|
1064 | }
|
---|
1065 |
|
---|
1066 | if ((cep->flags & TCP_CEP_FLG_WBCS_MASK) == TCP_CEP_FLG_WBCS_ACKED &&
|
---|
1067 | (cep->swbufq->flags & NB_FLG_NOREL_IFOUT) == 0) {
|
---|
1068 | tcptsk_free_swbufq(cep);
|
---|
1069 | sel_ix = ix;
|
---|
1070 | }
|
---|
1071 |
|
---|
1072 | /*
|
---|
1073 | * ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ããéä¿¡ãçµãã£ã¦ããªãã¨ãã¯ã
|
---|
1074 | * éä¿¡ãäºç´ããã
|
---|
1075 | */
|
---|
1076 | if (cep->flags & TCP_CEP_FLG_POST_OUTPUT &&
|
---|
1077 | (cep->flags & TCP_CEP_FLG_WBCS_MASK) >= TCP_CEP_FLG_WBCS_SENT) {
|
---|
1078 | syscall(wai_sem(cep->semid_lock));
|
---|
1079 | if (cep->swbufq == NULL)
|
---|
1080 | cep->flags &= ~TCP_CEP_FLG_POST_OUTPUT;
|
---|
1081 | else if (cep->swbufq->flags & NB_FLG_NOREL_IFOUT) {
|
---|
1082 | cep->flags &= ~TCP_CEP_FLG_POST_OUTPUT;
|
---|
1083 | cep->flags |= TCP_CEP_FLG_RESERVE_OUTPUT;
|
---|
1084 | }
|
---|
1085 | syscall(sig_sem(cep->semid_lock));
|
---|
1086 | }
|
---|
1087 |
|
---|
1088 | /*
|
---|
1089 | * éä¿¡äºç´ä¸ã«ããããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ããéä¿¡ãçµäºãããã
|
---|
1090 | * éä¿¡ãéå§ããããã ããå®å
|
---|
1091 | ¨ã«éä¿¡ãçµäºããã¨ãã¯ä½ãããªãã
|
---|
1092 | */
|
---|
1093 | if (cep->flags & TCP_CEP_FLG_RESERVE_OUTPUT) {
|
---|
1094 | syscall(wai_sem(cep->semid_lock));
|
---|
1095 | if (cep->swbufq != NULL && (cep->swbufq->flags & NB_FLG_NOREL_IFOUT) == 0) {
|
---|
1096 | cep->flags |= TCP_CEP_FLG_POST_OUTPUT;
|
---|
1097 | }
|
---|
1098 | syscall(sig_sem(cep->semid_lock));
|
---|
1099 | cep->flags &= ~TCP_CEP_FLG_RESERVE_OUTPUT;
|
---|
1100 | }
|
---|
1101 |
|
---|
1102 | #endif /* of #ifdef TCP_CFG_SWBUF_CSAVE */
|
---|
1103 |
|
---|
1104 | if (cep->flags & TCP_CEP_FLG_POST_OUTPUT) {
|
---|
1105 |
|
---|
1106 | cep->flags &= ~TCP_CEP_FLG_POST_OUTPUT;
|
---|
1107 |
|
---|
1108 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
1109 |
|
---|
1110 | if (cep->snd_nblk_tfn == TFN_TCP_CON_CEP && cep->myaddr.portno == TCP_PORTANY) {
|
---|
1111 | ER error;
|
---|
1112 |
|
---|
1113 | /*
|
---|
1114 | * tcp_con_cep ã®ãã³ããããã³ã°ã³ã¼ã«ã§ã
|
---|
1115 | * æªå²å½ã®ã®å ´åã¯ããã¼ãçªå·ãå²ãå½ã¦ãã
|
---|
1116 | * p_myaddr ã NADR (-1) ãã
|
---|
1117 | * èªãã¼ãçªå·ã TCP_PORTANY ãªããèªåã§å²ãå½ã¦ãã
|
---|
1118 | */
|
---|
1119 | if (cep->p_myaddr == NADR || cep->p_myaddr->portno == TCP_PORTANY)
|
---|
1120 | tcp_alloc_auto_port(cep);
|
---|
1121 | else if ((error = tcp_alloc_port(cep, cep->p_myaddr->portno)) != E_OK) {
|
---|
1122 |
|
---|
1123 | if (IS_PTR_DEFINED(cep->callback))
|
---|
1124 |
|
---|
1125 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
1126 |
|
---|
1127 | (*cep->callback)(GET_TCP_CEPID(cep), cep->snd_nblk_tfn, (void*)error);
|
---|
1128 |
|
---|
1129 | #else /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
1130 |
|
---|
1131 | (*cep->callback)(GET_TCP_CEPID(cep), cep->snd_nblk_tfn, (void*)&error);
|
---|
1132 |
|
---|
1133 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
1134 |
|
---|
1135 | else
|
---|
1136 | syslog(LOG_WARNING, "[TCP] no call back, CEP: %d.", GET_TCP_CEPID(cep));
|
---|
1137 |
|
---|
1138 | /* è¨æ¶ããã¦ããã¿ã¹ã¯ ID 㨠API æ©è½ã³ã¼ããã¯ãªã¢ã¼ããã*/
|
---|
1139 | cep->snd_tfn = cep->snd_nblk_tfn = TFN_TCP_UNDEF;
|
---|
1140 | cep->snd_tskid = TA_NULL;
|
---|
1141 | continue;
|
---|
1142 | }
|
---|
1143 | }
|
---|
1144 |
|
---|
1145 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
1146 |
|
---|
1147 | tcp_output(cep);
|
---|
1148 |
|
---|
1149 | if (cep->flags & TCP_CEP_FLG_CLOSE_AFTER_OUTPUT) {
|
---|
1150 | /* ã³ãã¯ã·ã§ã³ãéããã*/
|
---|
1151 | tcp_close(cep);
|
---|
1152 | cep->flags &= ~TCP_CEP_FLG_CLOSE_AFTER_OUTPUT;
|
---|
1153 | }
|
---|
1154 |
|
---|
1155 | if (cep->flags & TCP_CEP_FLG_RESTORE_NEXT_OUTPUT) {
|
---|
1156 | /* snd_nxt ãå
|
---|
1157 | ã«æ»ãã*/
|
---|
1158 | if (SEQ_GT(cep->snd_old_nxt, cep->snd_nxt))
|
---|
1159 | cep->snd_nxt = cep->snd_old_nxt;
|
---|
1160 | cep->flags &= ~TCP_CEP_FLG_RESTORE_NEXT_OUTPUT;
|
---|
1161 | }
|
---|
1162 |
|
---|
1163 | sel_ix = ix;
|
---|
1164 | }
|
---|
1165 |
|
---|
1166 | if (++ ix == tmax_tcp_cepid)
|
---|
1167 | ix = 0;
|
---|
1168 | } while (ix != last_ix);
|
---|
1169 |
|
---|
1170 | /* 次åã¯ãå¦çããé信端ç¹ãå¾åãã«ããã*/
|
---|
1171 | last_ix = sel_ix;
|
---|
1172 | }
|
---|
1173 | }
|
---|
1174 |
|
---|
1175 | #endif /* of #ifdef SUPPORT_TCP */
|
---|