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$
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * Copyright (c) 1982, 1986, 1988, 1993
|
---|
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 | * From: @(#)tcp_usrreq.c 8.2 (Berkeley) 1/3/94
|
---|
79 | * $FreeBSD: src/sys/netinet/tcp_usrreq.c,v 1.40.2.3 1999/08/29 16:29:57 peter Exp $
|
---|
80 | */
|
---|
81 |
|
---|
82 | #ifdef TCP_CFG_EXTENTIONS
|
---|
83 |
|
---|
84 | #if (API_PROTO == API_PROTO_IPV6 && TNUM_TCP6_REPID > 0) || (API_PROTO == API_PROTO_IPV4 && TNUM_TCP4_REPID > 0)
|
---|
85 |
|
---|
86 | /*
|
---|
87 | * tcp_cre_rep -- TCP åä»å£ã®çæãæ¡å¼µæ©è½ã
|
---|
88 | */
|
---|
89 |
|
---|
90 | #ifdef __tcp_cre_rep
|
---|
91 |
|
---|
92 | ER
|
---|
93 | TCP_CRE_REP (ID repid, T_TCPN_CREP *pk_crep)
|
---|
94 | {
|
---|
95 | T_TCP_REP *rep;
|
---|
96 | ER error;
|
---|
97 |
|
---|
98 | /* TCP åä»å£ ID ããã§ãã¯ããã*/
|
---|
99 | if (!VALID_TCP_REPID(repid))
|
---|
100 | return E_ID;
|
---|
101 |
|
---|
102 | /* pk_crep ã NULL ãªãã¨ã©ã¼ */
|
---|
103 | if (pk_crep == NULL)
|
---|
104 | return E_PAR;
|
---|
105 |
|
---|
106 | #if (API_PROTO == API_PROTO_IPV6) && !defined(API_CFG_IP4MAPPED_ADDR)
|
---|
107 |
|
---|
108 | /*
|
---|
109 | * API ã IPv6 㧠IPv4 å°å½±ã¢ãã¬ã¹ãèªãããã¦ããªãã®ã«ããããããã
|
---|
110 | * IPv4 å°å½±ã¢ãã¬ã¹ãæå®ããããã¨ã©ã¼
|
---|
111 | */
|
---|
112 | if (in6_is_addr_ipv4mapped(&pk_crep->myaddr.ipaddr))
|
---|
113 | return E_PAR;
|
---|
114 |
|
---|
115 | #endif /* of #if (API_PROTO == API_PROTO_IPV6) && !defined(DAPI_CFG_IP4MAPPED_ADDR) */
|
---|
116 |
|
---|
117 | /* TCP åä»å£ãå¾ãã*/
|
---|
118 | rep = GET_TCP_REP(repid);
|
---|
119 |
|
---|
120 | /* TCP åä»å£ããåççæç¨ã§ãªããã°ã¨ã©ã¼ */
|
---|
121 | if (!DYNAMIC_TCP_REP(rep))
|
---|
122 | return E_ID;
|
---|
123 |
|
---|
124 | /* åä»å£ãããã¯ããã*/
|
---|
125 | syscall(wai_sem(rep->semid_lock));
|
---|
126 |
|
---|
127 | /*
|
---|
128 | * TCP åä»å£ããã§ãã¯ãããçææ¸ã¿ã§ããã°ã¨ã©ã¼
|
---|
129 | */
|
---|
130 | if (VALID_TCP_REP(rep))
|
---|
131 | error = E_OBJ;
|
---|
132 | else {
|
---|
133 |
|
---|
134 | /* TCP åä»å£çææ
|
---|
135 | å ±ãã³ãã¼ããã*/
|
---|
136 | rep->repatr = pk_crep->repatr; /* åä»å£å±æ§ */
|
---|
137 | rep->myaddr.ipaddr = pk_crep->myaddr.ipaddr; /* èªåã®ã¢ãã¬ã¹ */
|
---|
138 | rep->myaddr.portno = pk_crep->myaddr.portno; /* èªåã®ã¢ãã¬ã¹ */
|
---|
139 |
|
---|
140 | /* TCP åä»å£ãçææ¸ã¿ã«ããã*/
|
---|
141 | rep->flags |= TCP_REP_FLG_VALID;
|
---|
142 | error = E_OK;
|
---|
143 | }
|
---|
144 |
|
---|
145 | /* åä»å£ã®ããã¯ã解é¤ããã*/
|
---|
146 | syscall(sig_sem(rep->semid_lock));
|
---|
147 |
|
---|
148 | return error;
|
---|
149 | }
|
---|
150 |
|
---|
151 | #endif /* of #ifdef __tcp_cre_rep */
|
---|
152 |
|
---|
153 | #ifdef __tcp_del_rep
|
---|
154 |
|
---|
155 | /*
|
---|
156 | * tcp_find_cep_rep -- TCP åä»å£ããªã³ã¯ãã¦ãã TCP é信端ç¹ãå¾ãã
|
---|
157 | */
|
---|
158 |
|
---|
159 | static T_TCP_CEP*
|
---|
160 | TCP_FIND_CEP_REP (T_TCP_REP* rep)
|
---|
161 | {
|
---|
162 | T_TCP_CEP* cep;
|
---|
163 |
|
---|
164 | for (cep = &tcp_cep[tmax_tcp_cepid]; cep -- != tcp_cep; ) {
|
---|
165 |
|
---|
166 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && (API_PROTO == API_PROTO_IPV4)
|
---|
167 | if (cep->rep4 == rep)
|
---|
168 | #else
|
---|
169 | if (cep->rep == rep)
|
---|
170 | #endif
|
---|
171 | return cep;
|
---|
172 | }
|
---|
173 |
|
---|
174 | return NULL;
|
---|
175 | }
|
---|
176 |
|
---|
177 | /*
|
---|
178 | * tcp_del_rep_body -- TCP åä»å£ã®åé¤ãæ¡å¼µæ©è½ãã®æ¬ä½
|
---|
179 | */
|
---|
180 |
|
---|
181 | static ER
|
---|
182 | TCP_DEL_REP_BODY (ID repid)
|
---|
183 | {
|
---|
184 | T_TCP_CEP *cep;
|
---|
185 | T_TCP_REP *rep;
|
---|
186 | ER error = E_OK;
|
---|
187 |
|
---|
188 | /* TCP åä»å£ ID ã®ãã§ãã¯ã¯çµäºãã¦ããã*/
|
---|
189 |
|
---|
190 | /* TCP åä»å£ãå¾ãã*/
|
---|
191 | rep = GET_TCP_REP(repid);
|
---|
192 |
|
---|
193 | /* TCP åä»å£ããåççæç¨ã§ãªããã°ã¨ã©ã¼ */
|
---|
194 | if (!DYNAMIC_TCP_REP(rep))
|
---|
195 | return E_ID;
|
---|
196 |
|
---|
197 | /* åä»å£ãããã¯ããã*/
|
---|
198 | syscall(wai_sem(rep->semid_lock));
|
---|
199 |
|
---|
200 | /* TCP åä»å£ããã§ãã¯ãããæªçæã®å ´åã¯ã¨ã©ã¼ */
|
---|
201 | if (!VALID_TCP_REP(rep))
|
---|
202 | error = E_NOEXS;
|
---|
203 | else {
|
---|
204 | if ((cep = TCP_FIND_CEP_REP(rep)) != NULL) {
|
---|
205 | /*
|
---|
206 | * ãã§ã«ååãªã¼ãã³ãã¦ããã¨ã
|
---|
207 | *ï¼tcp_acp_cep ãå¼ã°ãã¦ããã¨ãï¼ã¯ã
|
---|
208 | * tcp_acp_cep ãçµäºãããã
|
---|
209 | */
|
---|
210 |
|
---|
211 | /* é信端ç¹ãããã¯ããã*/
|
---|
212 | syscall(wai_sem(cep->semid_lock));
|
---|
213 |
|
---|
214 | /*
|
---|
215 | * é信端ç¹ããåä»å£ã解æ¾ãã
|
---|
216 | * ã¤ãã³ããã©ã°ãã¯ãã¼ãºã«è¨å®ããã
|
---|
217 | */
|
---|
218 | cep->rep = NULL;
|
---|
219 |
|
---|
220 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
221 | cep->rep4 = NULL;
|
---|
222 | #endif
|
---|
223 |
|
---|
224 | cep->fsm_state = TCP_FSM_CLOSED;
|
---|
225 | cep->error = E_DLT;
|
---|
226 | syscall(set_flg(cep->est_flgid, TCP_CEP_EVT_CLOSED));
|
---|
227 |
|
---|
228 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
229 |
|
---|
230 | if (cep->rcv_nblk_tfn != TFN_TCP_UNDEF) {
|
---|
231 | if (IS_PTR_DEFINED(cep->callback)) {
|
---|
232 |
|
---|
233 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
234 |
|
---|
235 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)E_DLT);
|
---|
236 |
|
---|
237 | #else /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
238 |
|
---|
239 | ER error = E_DLT;
|
---|
240 |
|
---|
241 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)&error);
|
---|
242 |
|
---|
243 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
244 |
|
---|
245 | }
|
---|
246 | else
|
---|
247 | error = E_OBJ;
|
---|
248 | cep->rcv_nblk_tfn = TFN_TCP_UNDEF;
|
---|
249 | }
|
---|
250 |
|
---|
251 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
252 |
|
---|
253 | cep->rcv_tskid = TA_NULL;
|
---|
254 | cep->rcv_tfn = TFN_TCP_UNDEF;
|
---|
255 |
|
---|
256 | /* é信端ç¹ã®ããã¯ã解é¤ããã*/
|
---|
257 | syscall(sig_sem(cep->semid_lock));
|
---|
258 |
|
---|
259 | }
|
---|
260 | else
|
---|
261 | error = E_OK;
|
---|
262 |
|
---|
263 | /* TCP åä»å£ãæªçæã«ããã*/
|
---|
264 | rep->flags &= ~TCP_REP_FLG_VALID;
|
---|
265 | }
|
---|
266 |
|
---|
267 | /* åä»å£ã®ããã¯ã解é¤ããã*/
|
---|
268 | syscall(sig_sem(rep->semid_lock));
|
---|
269 |
|
---|
270 | return error;
|
---|
271 | }
|
---|
272 |
|
---|
273 | #endif /* of #ifdef __tcp_del_rep */
|
---|
274 |
|
---|
275 | #endif /* of #if (API_PROTO == API_PROTO_IPV6 && TNUM_TCP6_REPID > 0) || (API_PROTO == API_PROTO_IPV4 && TNUM_TCP4_REPID > 0) */
|
---|
276 |
|
---|
277 | #endif /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
278 |
|
---|
279 | #if (API_PROTO == API_PROTO_IPV6 && TNUM_TCP6_REPID > 0) || (API_PROTO == API_PROTO_IPV4 && TNUM_TCP4_REPID > 0)
|
---|
280 |
|
---|
281 | /*
|
---|
282 | * tcp_acp_cep -- æ¥ç¶è¦æ±å¾
|
---|
283 | ã¡ (ååãªã¼ãã³)ãæ¨æºæ©è½ã
|
---|
284 | */
|
---|
285 |
|
---|
286 | #ifdef __tcp_acp_cep
|
---|
287 |
|
---|
288 | ER
|
---|
289 | TCP_ACP_CEP (ID cepid, ID repid, T_IPEP *p_dstaddr, TMO tmout)
|
---|
290 | {
|
---|
291 | T_TCP_REP *rep;
|
---|
292 | T_TCP_CEP *cep;
|
---|
293 | ER error;
|
---|
294 | FLGPTN flag;
|
---|
295 |
|
---|
296 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
297 |
|
---|
298 | /*
|
---|
299 | * API (tcp6_acp_cep 㨠tcp_acp_cep) ã¨ã
|
---|
300 | * TCPé信端ç¹ã®ãããã³ã«ãçç¾ãã¦ããã°ã¨ã©ã¼
|
---|
301 | */
|
---|
302 |
|
---|
303 | #if API_PROTO == API_PROTO_IPV6
|
---|
304 |
|
---|
305 | if (GET_TCP_CEP(cepid)->flags & TCP_CEP_FLG_IPV4)
|
---|
306 | return E_ID;
|
---|
307 |
|
---|
308 | #endif /* of #if API_PROTO == API_PROTO_IPV6 */
|
---|
309 |
|
---|
310 | #if API_PROTO == API_PROTO_IPV4
|
---|
311 |
|
---|
312 | if ((GET_TCP_CEP(cepid)->flags & TCP_CEP_FLG_IPV4) == 0)
|
---|
313 | return E_ID;
|
---|
314 |
|
---|
315 | #endif /* of #if API_PROTO == API_PROTO_IPV4 */
|
---|
316 |
|
---|
317 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
318 |
|
---|
319 | /* TCP åä»å£ããã§ãã¯ããã*/
|
---|
320 | if (!VALID_TCP_REPID(repid))
|
---|
321 | return E_ID;
|
---|
322 |
|
---|
323 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
324 |
|
---|
325 | /* p_dstaddr ã NULL ãªãã¨ã©ã¼ */
|
---|
326 | if (p_dstaddr == NULL)
|
---|
327 | return E_PAR;
|
---|
328 |
|
---|
329 | #else /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
330 |
|
---|
331 | /* p_dstaddr ã NULL ããtmout ã TMO_NBLK ãªãã¨ã©ã¼ */
|
---|
332 | if (p_dstaddr == NULL || tmout == TMO_NBLK)
|
---|
333 | return E_PAR;
|
---|
334 |
|
---|
335 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
336 |
|
---|
337 | #if (API_PROTO == API_PROTO_IPV6) && !defined(API_CFG_IP4MAPPED_ADDR)
|
---|
338 |
|
---|
339 | /*
|
---|
340 | * API ã IPv6 㧠IPv4 å°å½±ã¢ãã¬ã¹ãèªãããã¦ããªãã®ã«ããããããã
|
---|
341 | * IPv4 å°å½±ã¢ãã¬ã¹ãæå®ããããã¨ã©ã¼
|
---|
342 | */
|
---|
343 | if (in6_is_addr_ipv4mapped(&p_dstaddr->ipaddr))
|
---|
344 | return E_PAR;
|
---|
345 |
|
---|
346 | #endif /* of #if (API_PROTO == API_PROTO_IPV6) && !defined(DAPI_CFG_IP4MAPPED_ADDR) */
|
---|
347 |
|
---|
348 | /*
|
---|
349 | * CEP ãããã¯ããAPI æ©è½ã³ã¼ãã¨ã¿ã¹ã¯èå¥åãè¨é²ããã
|
---|
350 | * ãã§ã«è¨é²ããã¦ããã°ããã³ãã£ã³ã°ä¸ãªã®ã§ã¨ã©ã¼
|
---|
351 | */
|
---|
352 | if ((error = tcp_lock_cep(cepid, &cep, TFN_TCP_ACP_CEP)) != E_OK)
|
---|
353 | return error;
|
---|
354 |
|
---|
355 | /* CEP ã® FSM ãã¯ãã¼ãºç¶æ
|
---|
356 | ã§ãªããã°ã¨ã©ã¼ã*/
|
---|
357 | if (cep->fsm_state != TCP_FSM_CLOSED) {
|
---|
358 | error = E_OBJ;
|
---|
359 | goto err_ret;
|
---|
360 | }
|
---|
361 | syscall(clr_flg(cep->est_flgid, (FLGPTN)(~TCP_CEP_EVT_CLOSED)));
|
---|
362 |
|
---|
363 | /* TCP é信端ç¹ãåæåããã*/
|
---|
364 | tcp_init_cep(cep);
|
---|
365 |
|
---|
366 | /* TCP åä»å£ãå¾ãã*/
|
---|
367 |
|
---|
368 | rep = GET_TCP_REP(repid);
|
---|
369 |
|
---|
370 | #ifdef TCP_CFG_EXTENTIONS
|
---|
371 |
|
---|
372 | /* TCP åä»å£ãããã¯ããã*/
|
---|
373 | syscall(wai_sem(rep->semid_lock));
|
---|
374 |
|
---|
375 | /* TCP åä»å£ããã§ãã¯ããã*/
|
---|
376 | if (!VALID_TCP_REP(rep)) {
|
---|
377 | syscall(sig_sem(rep->semid_lock));
|
---|
378 | error = E_NOEXS;
|
---|
379 | goto err_ret;
|
---|
380 | }
|
---|
381 |
|
---|
382 | #endif /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
383 |
|
---|
384 | /* TCP é信端ç¹ã«TCPåä»å£ãè¨é²ããã*/
|
---|
385 |
|
---|
386 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
387 |
|
---|
388 | #if API_PROTO == API_PROTO_IPV6
|
---|
389 |
|
---|
390 | cep->rep = rep;
|
---|
391 |
|
---|
392 | #else /* of #if API_PROTO == API_PROTO_IPV6 */
|
---|
393 |
|
---|
394 | cep->rep4 = rep;
|
---|
395 |
|
---|
396 | #endif /*of #if API_PROTO == API_PROTO_IPV6 */
|
---|
397 |
|
---|
398 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
399 |
|
---|
400 | cep->rep = rep;
|
---|
401 |
|
---|
402 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
403 |
|
---|
404 | #ifdef TCP_CFG_EXTENTIONS
|
---|
405 |
|
---|
406 | /* TCP åä»å£ã®ããã¯ã解é¤ããã*/
|
---|
407 | syscall(sig_sem(rep->semid_lock));
|
---|
408 |
|
---|
409 | #endif /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
410 |
|
---|
411 | /* TCP åä»å£ã®ã¢ãã¬ã¹ãã³ãã¼ããã*/
|
---|
412 |
|
---|
413 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && (API_PROTO == API_PROTO_IPV4)
|
---|
414 |
|
---|
415 | if (rep->myaddr.ipaddr == IPV4_ADDRANY)
|
---|
416 | memcpy(&cep->myaddr.ipaddr, &in6_addr_unspecified,
|
---|
417 | sizeof(in6_addr_unspecified));
|
---|
418 | else
|
---|
419 | in6_make_ipv4mapped(&cep->myaddr.ipaddr, rep->myaddr.ipaddr);
|
---|
420 | cep->myaddr.portno = rep->myaddr.portno;
|
---|
421 |
|
---|
422 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && (API_PROTO == API_PROTO_IPV4) */
|
---|
423 |
|
---|
424 | cep->myaddr = rep->myaddr;
|
---|
425 |
|
---|
426 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && (API_PROTO == API_PROTO_IPV4) */
|
---|
427 |
|
---|
428 | #if API_PROTO == API_PROTO_IPV4
|
---|
429 |
|
---|
430 | /* TCP é信端ç¹ã®ãããã¯ã¼ã¯å±¤ãããã³ã«ãè¨å®ããã*/
|
---|
431 | cep->flags |= TCP_CEP_FLG_IPV4;
|
---|
432 |
|
---|
433 | #endif /* of #if API_PROTO == API_PROTO_IPV4 */
|
---|
434 |
|
---|
435 | /* é信端ç¹ãè¨å®ããã*/
|
---|
436 | cep->fsm_state = TCP_FSM_LISTEN;
|
---|
437 |
|
---|
438 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
439 |
|
---|
440 | /* ã¿ã¤ã ã¢ã¦ãããã§ãã¯ããã*/
|
---|
441 | if (tmout == TMO_NBLK) {
|
---|
442 | /* ãã³ããããã³ã°ã³ã¼ã« */
|
---|
443 |
|
---|
444 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
445 |
|
---|
446 | #if API_PROTO == API_PROTO_IPV4
|
---|
447 |
|
---|
448 | cep->p_dstaddr4 = p_dstaddr;
|
---|
449 | cep->p_dstaddr = NULL;
|
---|
450 |
|
---|
451 | #else /* of #if API_PROTO == API_PROTO_IPV4 */
|
---|
452 |
|
---|
453 | cep->p_dstaddr4 = NULL;
|
---|
454 | cep->p_dstaddr = p_dstaddr;
|
---|
455 |
|
---|
456 | #endif /* of #if API_PROTO == API_PROTO_IPV4 */
|
---|
457 |
|
---|
458 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
459 |
|
---|
460 | cep->p_dstaddr = p_dstaddr;
|
---|
461 |
|
---|
462 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
463 |
|
---|
464 | cep->rcv_nblk_tfn = TFN_TCP_ACP_CEP;
|
---|
465 | return E_WBLK;
|
---|
466 | }
|
---|
467 | else {
|
---|
468 |
|
---|
469 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
470 |
|
---|
471 | /*
|
---|
472 | * FSM ã ESTABLISHED ã«ãªãã¾ã§å¾
|
---|
473 | ã¤ã
|
---|
474 | * FSM ã CLOSED ã«ãªã£ãå ´åã¯ãã¨ã©ã¼ãçºçãããã¨ãæå³ãã¦ããã
|
---|
475 | */
|
---|
476 | error = twai_flg(cep->est_flgid, (TCP_CEP_EVT_CLOSED |
|
---|
477 | TCP_CEP_EVT_ESTABLISHED), TWF_ORW, &flag, tmout);
|
---|
478 | if (error == E_OK) {
|
---|
479 | if (cep->error != E_OK)
|
---|
480 | error = cep->error;
|
---|
481 | else if (cep->fsm_state == TCP_FSM_CLOSED)
|
---|
482 | error = E_TMOUT;
|
---|
483 | }
|
---|
484 |
|
---|
485 | syscall(clr_flg(cep->est_flgid, (FLGPTN)(~TCP_CEP_EVT_ESTABLISHED)));
|
---|
486 |
|
---|
487 | if (error == E_OK) {
|
---|
488 | /* ç¸æã®ã¢ãã¬ã¹ãã³ãã¼ããã*/
|
---|
489 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && (API_PROTO == API_PROTO_IPV4)
|
---|
490 | p_dstaddr->ipaddr = ntohl(cep->dstaddr.ipaddr.s6_addr32[3]);
|
---|
491 | p_dstaddr->portno = cep->dstaddr.portno;
|
---|
492 | #else
|
---|
493 | *p_dstaddr = cep->dstaddr;
|
---|
494 | #endif
|
---|
495 | }
|
---|
496 | else {
|
---|
497 | /*
|
---|
498 | * é信端ç¹ããåä»å£ã解æ¾ãã
|
---|
499 | * ã¤ãã³ããã©ã°ãã¯ãã¼ãºã«è¨å®ããã
|
---|
500 | */
|
---|
501 | cep->rep = NULL;
|
---|
502 |
|
---|
503 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
504 | cep->rep4 = NULL;
|
---|
505 | #endif
|
---|
506 |
|
---|
507 | cep->fsm_state = TCP_FSM_CLOSED;
|
---|
508 | syscall(set_flg(cep->est_flgid, TCP_CEP_EVT_CLOSED));
|
---|
509 | }
|
---|
510 |
|
---|
511 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
512 |
|
---|
513 | }
|
---|
514 |
|
---|
515 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
516 |
|
---|
517 | err_ret:
|
---|
518 | cep->rcv_tskid = TA_NULL;
|
---|
519 | cep->rcv_tfn = TFN_TCP_UNDEF;
|
---|
520 | return error;
|
---|
521 | }
|
---|
522 |
|
---|
523 | #endif /* of #ifdef __tcp_acp_cep */
|
---|
524 |
|
---|
525 | #endif /* of #if (API_PROTO == API_PROTO_IPV6 && TNUM_TCP6_REPID > 0) || (API_PROTO == API_PROTO_IPV4 && TNUM_TCP4_REPID > 0) */
|
---|
526 |
|
---|
527 | /*
|
---|
528 | * tcp_con_cep -- æ¥ç¶è¦æ± (è½åãªã¼ãã³)ãæ¨æºæ©è½ã
|
---|
529 | */
|
---|
530 |
|
---|
531 | #ifdef __tcp_con_cep
|
---|
532 |
|
---|
533 | ER
|
---|
534 | TCP_CON_CEP (ID cepid, T_IPEP *p_myaddr, T_IPEP *p_dstaddr, TMO tmout)
|
---|
535 | {
|
---|
536 | T_TCP_CEP *cep;
|
---|
537 | ER error;
|
---|
538 | FLGPTN flag;
|
---|
539 |
|
---|
540 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
541 |
|
---|
542 | /*
|
---|
543 | * API (tcp6_acp_cep 㨠tcp_acp_cep) ã¨ã
|
---|
544 | * TCPé信端ç¹ã®ãããã³ã«ãçç¾ãã¦ããã°ã¨ã©ã¼
|
---|
545 | */
|
---|
546 |
|
---|
547 | #if API_PROTO == API_PROTO_IPV6
|
---|
548 |
|
---|
549 | if (GET_TCP_CEP(cepid)->flags & TCP_CEP_FLG_IPV4)
|
---|
550 | return E_ID;
|
---|
551 |
|
---|
552 | #endif /* of #if API_PROTO == API_PROTO_IPV6 */
|
---|
553 |
|
---|
554 | #if API_PROTO == API_PROTO_IPV4
|
---|
555 |
|
---|
556 | if ((GET_TCP_CEP(cepid)->flags & TCP_CEP_FLG_IPV4) == 0)
|
---|
557 | return E_ID;
|
---|
558 |
|
---|
559 | #endif /* of #if API_PROTO == API_PROTO_IPV4 */
|
---|
560 |
|
---|
561 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
562 |
|
---|
563 | /*
|
---|
564 | * ãã¦å
|
---|
565 | ããã«ããã£ã¹ãã¢ãã¬ã¹ãªãã¨ã©ã¼
|
---|
566 | */
|
---|
567 |
|
---|
568 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && (API_PROTO == API_PROTO_IPV4)
|
---|
569 |
|
---|
570 | if (IN4_IS_ADDR_MULTICAST(p_dstaddr->ipaddr))
|
---|
571 | return E_PAR;
|
---|
572 |
|
---|
573 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && (API_PROTO == API_PROTO_IPV4) */
|
---|
574 |
|
---|
575 | if (IN_IS_ADDR_MULTICAST(&p_dstaddr->ipaddr))
|
---|
576 | return E_PAR;
|
---|
577 |
|
---|
578 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && (API_PROTO == API_PROTO_IPV4) */
|
---|
579 |
|
---|
580 | #if (API_PROTO == API_PROTO_IPV6) && !defined(API_CFG_IP4MAPPED_ADDR)
|
---|
581 |
|
---|
582 | /*
|
---|
583 | * API ã IPv6 㧠IPv4 å°å½±ã¢ãã¬ã¹ãèªãããã¦ããªãã®ã«ããããããã
|
---|
584 | * IPv4 å°å½±ã¢ãã¬ã¹ãæå®ããããã¨ã©ã¼
|
---|
585 | */
|
---|
586 | if (in6_is_addr_ipv4mapped(&p_dstaddr->ipaddr))
|
---|
587 | return E_PAR;
|
---|
588 |
|
---|
589 | #endif /* of #if (API_PROTO == API_PROTO_IPV6) && !defined(DAPI_CFG_IP4MAPPED_ADDR) */
|
---|
590 |
|
---|
591 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
592 |
|
---|
593 | /*
|
---|
594 | * p_dstaddr ã¾ã㯠p_myaddr ã NULL ãªãã¨ã©ã¼
|
---|
595 | */
|
---|
596 | if (p_myaddr == NULL || p_dstaddr == NULL)
|
---|
597 | return E_PAR;
|
---|
598 |
|
---|
599 | #else /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
600 |
|
---|
601 | /*
|
---|
602 | * p_dstaddr ã¾ã㯠p_myaddr ã NULL ã
|
---|
603 | * tmout ã TMO_NBLK ãªãã¨ã©ã¼
|
---|
604 | */
|
---|
605 | if (p_myaddr == NULL || p_dstaddr == NULL || tmout == TMO_NBLK)
|
---|
606 | return E_PAR;
|
---|
607 |
|
---|
608 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
609 |
|
---|
610 | /*
|
---|
611 | * CEP ãããã¯ããAPI æ©è½ã³ã¼ãã¨ã¿ã¹ã¯èå¥åãè¨é²ããã
|
---|
612 | * ãã§ã«è¨é²ããã¦ããã°ããã³ãã£ã³ã°ä¸ãªã®ã§ã¨ã©ã¼
|
---|
613 | */
|
---|
614 | if ((error = tcp_lock_cep(cepid, &cep, TFN_TCP_CON_CEP)) != E_OK)
|
---|
615 | return error;
|
---|
616 |
|
---|
617 | /* CEP ã® FSM ãã¯ãã¼ãºç¶æ
|
---|
618 | ã§ãªããã°ã¨ã©ã¼ã*/
|
---|
619 | if (cep->fsm_state != TCP_FSM_CLOSED) {
|
---|
620 | error = E_OBJ;
|
---|
621 | goto err_ret;
|
---|
622 | }
|
---|
623 | syscall(clr_flg(cep->est_flgid, (FLGPTN)(~TCP_CEP_EVT_CLOSED)));
|
---|
624 |
|
---|
625 | /* ã·ã¼ã±ã³ã¹çªå·ãåæåããã*/
|
---|
626 | if (tcp_iss == 0)
|
---|
627 | tcp_init_iss();
|
---|
628 |
|
---|
629 | /* é信端ç¹ãåæåããã*/
|
---|
630 | tcp_init_cep(cep);
|
---|
631 |
|
---|
632 | /*
|
---|
633 | * IP ã¢ãã¬ã¹ãè¨å®ããã
|
---|
634 | * p_myaddr ã NADR (-1) ã§ã¯ãªããèª IP ã¢ãã¬ã¹ã ANY ã§ãªããã°ã
|
---|
635 | * æå®ããã IP ã¢ãã¬ã¹ãå²ãå½ã¦ãã
|
---|
636 | */
|
---|
637 |
|
---|
638 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && (API_PROTO == API_PROTO_IPV4)
|
---|
639 |
|
---|
640 | if (p_myaddr != NADR && !IN4_IS_ADDR_ANY(&p_myaddr->ipaddr))
|
---|
641 | in6_make_ipv4mapped(&cep->myaddr.ipaddr, p_myaddr->ipaddr);
|
---|
642 | else
|
---|
643 | in6_make_ipv4mapped(&cep->myaddr.ipaddr, IF_GET_IFNET()->in4_ifaddr.addr);
|
---|
644 |
|
---|
645 | in6_make_ipv4mapped(&cep->dstaddr.ipaddr, p_dstaddr->ipaddr);
|
---|
646 | cep->dstaddr.portno = p_dstaddr->portno;
|
---|
647 |
|
---|
648 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && (API_PROTO == API_PROTO_IPV4) */
|
---|
649 |
|
---|
650 | if (p_myaddr != NADR && !IN_IS_ADDR_ANY(&p_myaddr->ipaddr))
|
---|
651 | cep->myaddr.ipaddr = p_myaddr->ipaddr;
|
---|
652 | else {
|
---|
653 | if (IN_ADDRWITHIFP(IF_GET_IFNET(), &cep->myaddr.ipaddr, &p_dstaddr->ipaddr) == NULL) {
|
---|
654 | error = E_PAR;
|
---|
655 | goto err_ret;
|
---|
656 | }
|
---|
657 | }
|
---|
658 |
|
---|
659 | cep->dstaddr = *p_dstaddr;
|
---|
660 |
|
---|
661 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && (API_PROTO == API_PROTO_IPV4) */
|
---|
662 |
|
---|
663 | #if API_PROTO == API_PROTO_IPV4
|
---|
664 |
|
---|
665 | /* TCP é信端ç¹ã®ãããã¯ã¼ã¯å±¤ãããã³ã«ãè¨å®ããã*/
|
---|
666 | cep->flags |= TCP_CEP_FLG_IPV4;
|
---|
667 |
|
---|
668 | #endif /* of #if API_PROTO == API_PROTO_IPV4 */
|
---|
669 |
|
---|
670 | /* é信端ç¹ãè¨å®ããã*/
|
---|
671 | //NET_DEBUG_TCP5("tcp_con_cep3[c=%d,d=%lI.%d,s=%lI.%d]\n",
|
---|
672 | cep->fsm_state = TCP_FSM_SYN_SENT;
|
---|
673 | cep->iss = tcp_iss;
|
---|
674 | cep->timer[TCP_TIM_KEEP] = TCP_TVAL_KEEP_INIT;
|
---|
675 | tcp_iss += TCP_ISS_INCR() / 2;
|
---|
676 | init_send_seq(cep);
|
---|
677 |
|
---|
678 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
679 |
|
---|
680 | /* ã¿ã¤ã ã¢ã¦ãããã§ãã¯ããã*/
|
---|
681 | if (tmout == TMO_NBLK) {
|
---|
682 | /* ãã³ããããã³ã°ã³ã¼ã« */
|
---|
683 |
|
---|
684 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
685 |
|
---|
686 | #if API_PROTO == API_PROTO_IPV4
|
---|
687 |
|
---|
688 | cep->p_dstaddr4 = p_dstaddr;
|
---|
689 | cep->p_myaddr4 = p_myaddr;
|
---|
690 | cep->p_dstaddr = NULL;
|
---|
691 | cep->p_myaddr = NADR;
|
---|
692 |
|
---|
693 | #else /* of #if API_PROTO == API_PROTO_IPV4 */
|
---|
694 |
|
---|
695 | cep->p_dstaddr4 = NULL;
|
---|
696 | cep->p_myaddr4 = NADR;
|
---|
697 | cep->p_dstaddr = p_dstaddr;
|
---|
698 | cep->p_myaddr = p_myaddr;
|
---|
699 |
|
---|
700 | #endif /* of #if API_PROTO == API_PROTO_IPV4 */
|
---|
701 |
|
---|
702 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
703 |
|
---|
704 | cep->p_dstaddr = p_dstaddr;
|
---|
705 | cep->p_myaddr = p_myaddr;
|
---|
706 |
|
---|
707 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
708 |
|
---|
709 | cep->snd_nblk_tfn = TFN_TCP_CON_CEP;
|
---|
710 |
|
---|
711 | /* ã³ãã¯ã·ã§ã³ã®éè¨ããã¹ãããã*/
|
---|
712 | cep->flags |= TCP_CEP_FLG_POST_OUTPUT;
|
---|
713 | sig_sem(SEM_TCP_POST_OUTPUT);
|
---|
714 | return E_WBLK;
|
---|
715 | }
|
---|
716 | else {
|
---|
717 |
|
---|
718 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
719 |
|
---|
720 | /*
|
---|
721 | * p_myaddr ã NADR (-1) ãã
|
---|
722 | * èªãã¼ãçªå·ã TCP_PORTANY ãªããèªåã§å²ãå½ã¦ãã
|
---|
723 | */
|
---|
724 | if (p_myaddr == NADR || p_myaddr->portno == TCP_PORTANY)
|
---|
725 | tcp_alloc_auto_port(cep);
|
---|
726 | else if ((error = tcp_alloc_port(cep, p_myaddr->portno)) != E_OK)
|
---|
727 | goto err_ret;
|
---|
728 |
|
---|
729 | /* ã³ãã¯ã·ã§ã³ã®éè¨ããã¹ãããã*/
|
---|
730 | cep->flags |= TCP_CEP_FLG_POST_OUTPUT;
|
---|
731 | sig_sem(SEM_TCP_POST_OUTPUT);
|
---|
732 |
|
---|
733 | /*
|
---|
734 | * ã¤ãã³ãã ESTABLISHED ã«ãªãã¾ã§å¾
|
---|
735 | ã¤ã
|
---|
736 | * ã¤ãã³ãã CLOSED ã«ãªã£ãå ´åã¯ãä½ããã®ã¨ã©ã¼ãçºçãããã
|
---|
737 | * æ¥ç¶è¦æ±ãæå¦ããããã¨ãæå³ãã¦ããã
|
---|
738 | */
|
---|
739 | error = twai_flg(cep->est_flgid, (TCP_CEP_EVT_CLOSED |
|
---|
740 | TCP_CEP_EVT_ESTABLISHED), TWF_ORW, &flag, tmout);
|
---|
741 | if (error == E_OK) {
|
---|
742 | if (cep->error != E_OK)
|
---|
743 | error = cep->error;
|
---|
744 | else if (cep->fsm_state == TCP_FSM_CLOSED)
|
---|
745 | error = E_CLS;
|
---|
746 | }
|
---|
747 |
|
---|
748 | syscall(clr_flg(cep->est_flgid, (FLGPTN)(~TCP_CEP_EVT_ESTABLISHED)));
|
---|
749 |
|
---|
750 | if (error != E_OK) {
|
---|
751 | /*
|
---|
752 | * é信端ç¹ããåä»å£ã解æ¾ãã
|
---|
753 | * ã¤ãã³ããã©ã°ãã¯ãã¼ãºã«è¨å®ããã
|
---|
754 | */
|
---|
755 | cep->rep = NULL;
|
---|
756 |
|
---|
757 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
758 | cep->rep4 = NULL;
|
---|
759 | #endif
|
---|
760 |
|
---|
761 | cep->fsm_state = TCP_FSM_CLOSED;
|
---|
762 | syscall(set_flg(cep->est_flgid, TCP_CEP_EVT_CLOSED));
|
---|
763 | }
|
---|
764 |
|
---|
765 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
766 |
|
---|
767 | }
|
---|
768 |
|
---|
769 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
770 |
|
---|
771 | err_ret:
|
---|
772 | cep->snd_tskid = TA_NULL;
|
---|
773 | cep->snd_tfn = TFN_TCP_UNDEF;
|
---|
774 | return error;
|
---|
775 | }
|
---|
776 |
|
---|
777 | #endif /* of #ifdef __tcp_con_cep */
|
---|