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 | * TCP ECHO ãµã¼ã #1
|
---|
48 | *
|
---|
49 | * ã»éåä¿¡ã¿ã¹ã¯åä¸å
|
---|
50 | * ã»ãã³ããããã³ã°ã³ã¼ã«
|
---|
51 | * ã»çã³ãã¼ API
|
---|
52 | * ã»IPv4/IPv6
|
---|
53 | * ã»ç·æ¥ãã¼ã¿ã®åä¿¡
|
---|
54 | */
|
---|
55 |
|
---|
56 | #include <string.h>
|
---|
57 |
|
---|
58 | #ifdef TARGET_KERNEL_ASP
|
---|
59 |
|
---|
60 | #include <kernel.h>
|
---|
61 | #include <sil.h>
|
---|
62 | #include <t_syslog.h>
|
---|
63 | #include "kernel_cfg.h"
|
---|
64 | #include "tinet_cfg.h"
|
---|
65 |
|
---|
66 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
67 |
|
---|
68 | #ifdef TARGET_KERNEL_JSP
|
---|
69 |
|
---|
70 | #include <t_services.h>
|
---|
71 | #include "kernel_id.h"
|
---|
72 | #include "tinet_id.h"
|
---|
73 |
|
---|
74 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
75 |
|
---|
76 | #include <netinet/in.h>
|
---|
77 | #include <netinet/in_itron.h>
|
---|
78 |
|
---|
79 | #include <netapp/netapp.h>
|
---|
80 | #include <netapp/netapp_var.h>
|
---|
81 | #include <netapp/tcp_echo_srv1.h>
|
---|
82 | #include <netapp/tcp_echo_srv1_var.h>
|
---|
83 |
|
---|
84 | #ifdef USE_TCP_ECHO_SRV1
|
---|
85 |
|
---|
86 | /*
|
---|
87 | * 表示
|
---|
88 | */
|
---|
89 |
|
---|
90 | //#define SHOW_RCV_RANGE
|
---|
91 |
|
---|
92 | /*
|
---|
93 | * ã³ãã¯ã·ã§ã³åææ¹æ³ã®æå®
|
---|
94 | */
|
---|
95 |
|
---|
96 | #define USE_TCP_SHT_CEP
|
---|
97 |
|
---|
98 | /*
|
---|
99 | * ã¿ã¤ã ã¢ã¦ã
|
---|
100 | */
|
---|
101 |
|
---|
102 | #ifdef TOPPERS_S810_CLG3_85
|
---|
103 |
|
---|
104 | #define CLS_TMO TMO_FEVR /* Close Wait ã¯æ¨æºã§ 60ç§ */
|
---|
105 | //#define RCV_TMO TMO_FEVR
|
---|
106 | #define RCV_TMO (30*SYSTIM_HZ)
|
---|
107 | //#define SND_TMO TMO_FEVR
|
---|
108 | #define SND_TMO (30*SYSTIM_HZ)
|
---|
109 |
|
---|
110 | #else /* of #ifdef TOPPERS_S810_CLG3_85 */
|
---|
111 |
|
---|
112 | //#define CLS_TMO TMO_FEVR /* Close Wait ã¯æ¨æºã§ 60ç§ */
|
---|
113 | #define CLS_TMO (70*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*10)
|
---|
114 | //#define RCV_TMO TMO_FEVR
|
---|
115 | #define RCV_TMO (30*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*30)
|
---|
116 | //#define SND_TMO TMO_FEVR
|
---|
117 | #define SND_TMO (40*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*20)
|
---|
118 |
|
---|
119 | #endif /* of #ifdef TOPPERS_S810_CLG3_85 */
|
---|
120 |
|
---|
121 | #ifdef USE_TCP_EXTENTIONS
|
---|
122 |
|
---|
123 | /*
|
---|
124 | * å¤æ°
|
---|
125 | */
|
---|
126 |
|
---|
127 | typedef struct t_tcp_echo_srv_task_info {
|
---|
128 | ID taskid; /* ã¿ã¹ã¯ ID */
|
---|
129 | bool_t active; /* åä½ç¶æ
|
---|
130 | */
|
---|
131 | char apip; /* API IPãããã³ã« */
|
---|
132 | } T_TCP_ECHO_SRV_TASK_INFO;
|
---|
133 |
|
---|
134 | static T_TCP_ECHO_SRV_TASK_INFO tcp_echo_srv_task_info[NUM_TCP_ECHO_SRV_TASKS] = {
|
---|
135 |
|
---|
136 | { TCP_ECHO_SRV_TASK1, false },
|
---|
137 |
|
---|
138 | #if NUM_TCP_ECHO_SRV_TASKS >= 2
|
---|
139 | { TCP_ECHO_SRV_TASK2, false },
|
---|
140 | #endif
|
---|
141 | #if NUM_TCP_ECHO_SRV_TASKS >= 3
|
---|
142 | { TCP_ECHO_SRV_TASK3, false },
|
---|
143 | #endif
|
---|
144 | #if NUM_TCP_ECHO_SRV_TASKS >= 4
|
---|
145 | { TCP_ECHO_SRV_TASK4, false },
|
---|
146 | #endif
|
---|
147 | #if NUM_TCP_ECHO_SRV_TASKS >= 5
|
---|
148 | { TCP_ECHO_SRV_TASK5, false },
|
---|
149 | #endif
|
---|
150 | #if NUM_TCP_ECHO_SRV_TASKS >= 6
|
---|
151 | { TCP_ECHO_SRV_TASK6, false },
|
---|
152 | #endif
|
---|
153 | #if NUM_TCP_ECHO_SRV_TASKS >= 7
|
---|
154 | { TCP_ECHO_SRV_TASK7, false },
|
---|
155 | #endif
|
---|
156 | #if NUM_TCP_ECHO_SRV_TASKS >= 8
|
---|
157 | { TCP_ECHO_SRV_TASK8, false },
|
---|
158 | #endif
|
---|
159 |
|
---|
160 | };
|
---|
161 |
|
---|
162 | /*
|
---|
163 | * get_tcp_rep -- TCP åä»å£ãç²å¾ããã
|
---|
164 | */
|
---|
165 |
|
---|
166 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
167 |
|
---|
168 | static ER
|
---|
169 | get_tcp_rep (ID *repid, char apip)
|
---|
170 | {
|
---|
171 | ID tskid;
|
---|
172 | T_TCP6_CREP crep6;
|
---|
173 | T_TCP_CREP crep4;
|
---|
174 |
|
---|
175 | get_tid(&tskid);
|
---|
176 | if (apip == API_PROTO_IPV6) {
|
---|
177 | crep6.repatr = UINT_C(0);
|
---|
178 | crep6.myaddr.portno = UINT_C(7);
|
---|
179 | memcpy(&crep6.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
|
---|
180 | return alloc_tcp6_rep(repid, tskid, &crep6);
|
---|
181 | }
|
---|
182 | else {
|
---|
183 | crep4.repatr = UINT_C(0);
|
---|
184 | crep4.myaddr.portno = UINT_C(7);
|
---|
185 | crep4.myaddr.ipaddr = IPV4_ADDRANY;
|
---|
186 | return alloc_tcp4_rep(repid, tskid, &crep4);
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|
190 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
191 |
|
---|
192 | static ER
|
---|
193 | get_tcp_rep (ID *repid, char apip)
|
---|
194 | {
|
---|
195 | ID tskid;
|
---|
196 | T_TCPN_CREP crep;
|
---|
197 |
|
---|
198 | get_tid(&tskid);
|
---|
199 |
|
---|
200 | crep.repatr = UINT_C(0);
|
---|
201 | crep.myaddr.portno = UINT_C(7);
|
---|
202 |
|
---|
203 | #if defined(SUPPORT_INET6)
|
---|
204 |
|
---|
205 | memcpy(&crep.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
|
---|
206 |
|
---|
207 | #else /* #if defined(SUPPORT_INET6) */
|
---|
208 |
|
---|
209 | #if defined(SUPPORT_INET4)
|
---|
210 | crep.myaddr.ipaddr = IPV4_ADDRANY;
|
---|
211 | #endif
|
---|
212 |
|
---|
213 | #endif /* #if defined(SUPPORT_INET6) */
|
---|
214 |
|
---|
215 | return ALLOC_TCP_REP(repid, tskid, &crep);
|
---|
216 | }
|
---|
217 |
|
---|
218 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
219 |
|
---|
220 | /*
|
---|
221 | * get_tcp_cep -- TCP é信端ç¹ãç²å¾ããã
|
---|
222 | */
|
---|
223 |
|
---|
224 | static ER
|
---|
225 | get_tcp_cep (ID *cepid, char apip)
|
---|
226 | {
|
---|
227 | ID tskid;
|
---|
228 | T_TCP_CCEP ccep;
|
---|
229 |
|
---|
230 | get_tid(&tskid);
|
---|
231 |
|
---|
232 | ccep.cepatr = UINT_C(0);
|
---|
233 | ccep.sbufsz = TCP_ECHO_SRV_SWBUF_SIZE;
|
---|
234 | ccep.rbufsz = TCP_ECHO_SRV_RWBUF_SIZE;
|
---|
235 |
|
---|
236 | #ifdef TCP_CFG_SWBUF_CSAVE
|
---|
237 | ccep.sbuf = NADR;
|
---|
238 | #else
|
---|
239 | ccep.sbuf = tcp_echo_srv_swbuf;
|
---|
240 | #endif
|
---|
241 | #ifdef TCP_CFG_RWBUF_CSAVE
|
---|
242 | ccep.rbuf = NADR;
|
---|
243 | #else
|
---|
244 | ccep.rbuf = tcp_echo_srv_rwbuf;
|
---|
245 | #endif
|
---|
246 | #ifdef USE_TCP_NON_BLOCKING
|
---|
247 | ccep.callback = (FP)callback_nblk_tcp_echo_srv;
|
---|
248 | #else
|
---|
249 | ccep.callback = NULL;
|
---|
250 | #endif
|
---|
251 |
|
---|
252 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
253 |
|
---|
254 | if (apip == API_PROTO_IPV6)
|
---|
255 | return alloc_tcp6_cep(cepid, tskid, &ccep);
|
---|
256 | else
|
---|
257 | return alloc_tcp4_cep(cepid, tskid, &ccep);
|
---|
258 |
|
---|
259 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
260 |
|
---|
261 | return ALLOC_TCP_CEP(cepid, tskid, &ccep);
|
---|
262 |
|
---|
263 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
264 |
|
---|
265 | }
|
---|
266 |
|
---|
267 | /*
|
---|
268 | * wakeup_tcp_echo_srv -- TCP ã¨ã³ã¼ãµã¼ãã¿ã¹ã¯ã®ä¼æ¢è§£é¤
|
---|
269 | */
|
---|
270 |
|
---|
271 | ER
|
---|
272 | wakeup_tcp_echo_srv (char apip)
|
---|
273 | {
|
---|
274 | int ix;
|
---|
275 |
|
---|
276 | for (ix = NUM_TCP_ECHO_SRV_TASKS; -- ix >= 0; )
|
---|
277 | if (!tcp_echo_srv_task_info[ix].active) {
|
---|
278 | syslog(LOG_NOTICE, "[TCP%c ECHO SRV(EXT):%d] wake up.",
|
---|
279 | apip, tcp_echo_srv_task_info[ix].taskid);
|
---|
280 | tcp_echo_srv_task_info[ix].apip = apip;
|
---|
281 | tcp_echo_srv_task_info[ix].active = true;
|
---|
282 | return syscall(wup_tsk(tcp_echo_srv_task_info[ix].taskid));
|
---|
283 | }
|
---|
284 | syslog(LOG_NOTICE, "[TCP%c ECHO SRV(EXT):%d] wake up error: %s.",
|
---|
285 | apip, tcp_echo_srv_task_info[ix].taskid, itron_strerror(E_ID));
|
---|
286 | return E_ID;
|
---|
287 | }
|
---|
288 |
|
---|
289 | /*
|
---|
290 | * tcp_echo_srv_task -- TCP ã¨ã³ã¼ãµã¼ãã¿ã¹ã¯
|
---|
291 | */
|
---|
292 |
|
---|
293 | void
|
---|
294 | tcp_echo_srv_task (intptr_t exinf)
|
---|
295 | {
|
---|
296 | ID tskid;
|
---|
297 | ER error = E_OK;
|
---|
298 | int ix;
|
---|
299 | char apip;
|
---|
300 |
|
---|
301 | syscall(get_tid(&tskid));
|
---|
302 | syslog(LOG_NOTICE, "[TCPn ECHO SRV(EXT):%d] started.", tskid);
|
---|
303 | while (true) {
|
---|
304 | syslog(LOG_NOTICE, "[TCPn ECHO SRV(EXT):%d] goto sleep.", tskid);
|
---|
305 | syscall(slp_tsk());
|
---|
306 |
|
---|
307 | for (ix = NUM_TCP_ECHO_SRV_TASKS; -- ix >= 0; ) {
|
---|
308 | if (tcp_echo_srv_task_info[ix].taskid == tskid) {
|
---|
309 | break;
|
---|
310 | }
|
---|
311 | }
|
---|
312 |
|
---|
313 | apip = tcp_echo_srv_task_info[ix].apip;
|
---|
314 | if ((error = get_tcp_cep(&tcp_echo_srv_info[ix].cepid, apip)) != E_OK) {
|
---|
315 | syslog(LOG_NOTICE, "[TCP%c ECHO SRV(EXT):%d] create CEP error: %s",
|
---|
316 | apip, tskid, itron_strerror(error));
|
---|
317 | continue;
|
---|
318 | }
|
---|
319 |
|
---|
320 | while (true) {
|
---|
321 |
|
---|
322 | if ((error = get_tcp_rep(&tcp_echo_srv_info[ix].repid, apip)) != E_OK) {
|
---|
323 | syslog(LOG_NOTICE, "[TCP%c ECHO SRV(EXT):%d] create REP error: %s",
|
---|
324 | apip, tskid, itron_strerror(error));
|
---|
325 | break;
|
---|
326 | }
|
---|
327 | else if ((error = tcp_echo_srv(ix, apip)) != E_OK) {
|
---|
328 |
|
---|
329 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
330 |
|
---|
331 | if (apip == API_PROTO_IPV6)
|
---|
332 | error = free_tcp6_rep(tcp_echo_srv_info[ix].repid, error != E_DLT);
|
---|
333 | else
|
---|
334 | error = free_tcp4_rep(tcp_echo_srv_info[ix].repid, error != E_DLT);
|
---|
335 |
|
---|
336 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
337 |
|
---|
338 | error = FREE_TCP_REP(tcp_echo_srv_info[ix].repid, error != E_DLT);
|
---|
339 |
|
---|
340 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
341 |
|
---|
342 | if (error != E_OK) {
|
---|
343 | syslog(LOG_NOTICE, "[TCP%c ECHO SRV(EXT):%d] delete REP error: %s",
|
---|
344 | apip, tskid, itron_strerror(error));
|
---|
345 | }
|
---|
346 |
|
---|
347 | break;
|
---|
348 | }
|
---|
349 | }
|
---|
350 |
|
---|
351 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
352 |
|
---|
353 | if (apip == API_PROTO_IPV6)
|
---|
354 | error = free_tcp6_cep(tcp_echo_srv_info[ix].cepid);
|
---|
355 | else
|
---|
356 | error = free_tcp4_cep(tcp_echo_srv_info[ix].cepid);
|
---|
357 |
|
---|
358 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
359 |
|
---|
360 | error = FREE_TCP_CEP(tcp_echo_srv_info[ix].cepid);
|
---|
361 |
|
---|
362 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
363 |
|
---|
364 | if (error != E_OK) {
|
---|
365 | syslog(LOG_NOTICE, "[TCP%c ECHO SRV(EXT):%d] delete CEP error: %s",
|
---|
366 | apip, tskid, itron_strerror(error));
|
---|
367 | }
|
---|
368 |
|
---|
369 | for (ix = NUM_TCP_ECHO_SRV_TASKS; -- ix >= 0; ) {
|
---|
370 | if (tcp_echo_srv_task_info[ix].taskid == tskid) {
|
---|
371 | tcp_echo_srv_task_info[ix].active = false;
|
---|
372 | break;
|
---|
373 | }
|
---|
374 | }
|
---|
375 |
|
---|
376 | }
|
---|
377 | }
|
---|
378 |
|
---|
379 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
380 |
|
---|
381 | #endif /* of #ifdef USE_TCP_ECHO_SRV1 */
|
---|