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_discard_srv.c 388 2019-05-22 11:25:18Z coas-nagasima $
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * DISCARD ãµã¼ã
|
---|
48 | *
|
---|
49 | * ã»çã³ãã¼ API
|
---|
50 | * ã»IPv4
|
---|
51 | * ã»IPv6
|
---|
52 | */
|
---|
53 |
|
---|
54 | #include <string.h>
|
---|
55 |
|
---|
56 | #ifdef TARGET_KERNEL_ASP
|
---|
57 |
|
---|
58 | #include <kernel.h>
|
---|
59 | #include <sil.h>
|
---|
60 | #include <t_syslog.h>
|
---|
61 | #include "tinet_cfg.h"
|
---|
62 |
|
---|
63 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
64 |
|
---|
65 | #ifdef TARGET_KERNEL_JSP
|
---|
66 |
|
---|
67 | #include <t_services.h>
|
---|
68 | #include "tinet_id.h"
|
---|
69 |
|
---|
70 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
71 |
|
---|
72 | #include <netinet/in.h>
|
---|
73 | #include <netinet/in_itron.h>
|
---|
74 |
|
---|
75 | #include <netapp/netapp.h>
|
---|
76 | #include <netapp/netapp_var.h>
|
---|
77 | #include <netapp/tcp_discard_srv.h>
|
---|
78 |
|
---|
79 | #ifdef USE_TCP_DISCARD_SRV
|
---|
80 |
|
---|
81 | /*
|
---|
82 | * 表示
|
---|
83 | */
|
---|
84 |
|
---|
85 | //#define SHOW_RCV_RANGE
|
---|
86 | //#define SHOW_RCV_DATA
|
---|
87 |
|
---|
88 | /*
|
---|
89 | * å
|
---|
90 | ¨åå¤æ°
|
---|
91 | */
|
---|
92 |
|
---|
93 | /* TCP éåä¿¡ã¦ã£ã³ããããã¡ */
|
---|
94 |
|
---|
95 | #ifndef TCP_CFG_RWBUF_CSAVE_ONLY
|
---|
96 | uint8_t tcp_discard_srv_rwbuf[TCP_DISCARD_SRV_RWBUF_SIZE];
|
---|
97 | #endif
|
---|
98 |
|
---|
99 | /*
|
---|
100 | * TCP DISCARD ãµã¼ãã¿ã¹ã¯
|
---|
101 | */
|
---|
102 |
|
---|
103 | #define BUF_SIZE TCP_DISCARD_SRV_RWBUF_SIZE
|
---|
104 |
|
---|
105 | #ifdef USE_COPYSAVE_API
|
---|
106 |
|
---|
107 | static ER
|
---|
108 | tcp_discard_srv (ID cepid, ID repid)
|
---|
109 | {
|
---|
110 | T_IPEP dst;
|
---|
111 | ER_UINT rlen;
|
---|
112 | ER error;
|
---|
113 | SYSTIM time;
|
---|
114 | uint32_t total;
|
---|
115 | uint16_t count;
|
---|
116 | uint8_t *buf;
|
---|
117 |
|
---|
118 | #ifdef SHOW_RCV_DATA
|
---|
119 | uint_t ix;
|
---|
120 | #endif /* of #ifdef SHOW_RCV_DATA */
|
---|
121 |
|
---|
122 | if ((error = TCP_ACP_CEP(cepid, repid, &dst, TMO_FEVR)) != E_OK) {
|
---|
123 | syslog(LOG_NOTICE, "[TDSn:%02u ACP] accept error: %s", cepid, itron_strerror(error));
|
---|
124 | return error;
|
---|
125 | }
|
---|
126 |
|
---|
127 | #ifdef USE_TCP_EXTENTIONS
|
---|
128 | if ((error = FREE_TCP_REP(repid, true)) != E_OK) {
|
---|
129 | syslog(LOG_NOTICE, "[TDSn:%02u DEL] REP delete error: %s", cepid, itron_strerror(error));
|
---|
130 | return error;
|
---|
131 | }
|
---|
132 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
133 |
|
---|
134 | count = total = 0;
|
---|
135 | get_tim(&time);
|
---|
136 | syslog(LOG_NOTICE, "[TDSn:%02u RCV] conct: %7lu, from: %s.%d",
|
---|
137 | cepid, time / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
|
---|
138 | while ((rlen = tcp_rcv_buf(cepid, (void*)&buf, TMO_FEVR)) > 0) {
|
---|
139 | count ++;
|
---|
140 |
|
---|
141 | #ifdef SHOW_RCV_RANGE
|
---|
142 | syslog(LOG_NOTICE, "[TDSn:%02u RCV] count: %6lu, len: %4u, data: %02x -> %02x",
|
---|
143 | cepid, count, (uint16_t)rlen, *buf, *(buf + rlen - 1));
|
---|
144 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
145 |
|
---|
146 | #ifdef SHOW_RCV_DATA
|
---|
147 | for (ix = 0; ix < rlen; ix ++)
|
---|
148 | cons_putchar(CONSOLE_PORTID, *(buf + ix));
|
---|
149 | #endif /* of #ifdef SHOW_RCV_DATA */
|
---|
150 |
|
---|
151 | if ((error = tcp_rel_buf(cepid, rlen)) != E_OK) {
|
---|
152 | syslog(LOG_NOTICE, "[TDSn:%02u RCV] rel buf error: %s",
|
---|
153 | cepid, itron_strerror(error));
|
---|
154 | rlen = 0;
|
---|
155 | break;
|
---|
156 | }
|
---|
157 | total += rlen;
|
---|
158 | }
|
---|
159 |
|
---|
160 | if (rlen != 0)
|
---|
161 | syslog(LOG_NOTICE, "[TDSn:%02u RCV] recv buf error: %s", cepid, itron_strerror(rlen));
|
---|
162 |
|
---|
163 | if ((error = tcp_sht_cep(cepid)) != E_OK)
|
---|
164 | syslog(LOG_NOTICE, "[TDSn:%02u RCV] shutdown error: %s", cepid, itron_strerror(error));
|
---|
165 |
|
---|
166 | if ((error = tcp_cls_cep(cepid, TMO_FEVR)) != E_OK)
|
---|
167 | syslog(LOG_NOTICE, "[TDSn:%02u RCV] close error: %s", cepid, itron_strerror(error));
|
---|
168 |
|
---|
169 | get_tim(&time);
|
---|
170 | syslog(LOG_NOTICE, "[TDSn:%02u RCV] finsh: %7lu, ttl: %lu",
|
---|
171 | cepid, time / SYSTIM_HZ, count, total);
|
---|
172 |
|
---|
173 | return error;
|
---|
174 | }
|
---|
175 |
|
---|
176 | #else /* of #ifdef USE_COPYSAVE_API */
|
---|
177 |
|
---|
178 | static ER
|
---|
179 | tcp_discard_srv (ID cepid, ID repid)
|
---|
180 | {
|
---|
181 | static char buffer[BUF_SIZE];
|
---|
182 |
|
---|
183 | T_IPEP dst;
|
---|
184 | ER_UINT rlen;
|
---|
185 | ER error;
|
---|
186 | SYSTIM time;
|
---|
187 | uint32_t total;
|
---|
188 | uint16_t count;
|
---|
189 | uint8_t *buf = buffer;
|
---|
190 |
|
---|
191 | if ((error = TCP_ACP_CEP(cepid, repid, &dst, TMO_FEVR)) != E_OK) {
|
---|
192 | syslog(LOG_NOTICE, "[TDSn:%02u RCV] accept error: %s", cepid, itron_strerror(error));
|
---|
193 | return error;
|
---|
194 | }
|
---|
195 |
|
---|
196 | #ifdef USE_TCP_EXTENTIONS
|
---|
197 | if ((error = FREE_TCP_REP(repid, true)) != E_OK) {
|
---|
198 | syslog(LOG_NOTICE, "[TDSn:%02u DEL] REP delete error: %s", cepid, itron_strerror(error));
|
---|
199 | return error;
|
---|
200 | }
|
---|
201 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
202 |
|
---|
203 | count = total = 0;
|
---|
204 | get_tim(&time);
|
---|
205 | syslog(LOG_NOTICE, "[TDSn:%02u RCV] conct: %7lu, from: %s.%d",
|
---|
206 | cepid, time / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
|
---|
207 | while ((rlen = tcp_rcv_dat(cepid, buf, BUF_SIZE - 1, TMO_FEVR)) > 0) {
|
---|
208 | count ++;
|
---|
209 |
|
---|
210 | #ifdef SHOW_RCV_RANGE
|
---|
211 | syslog(LOG_NOTICE, "[TDSn:%02u RCV] count: %6lu, len: %4u, data: %02x -> %02x",
|
---|
212 | cepid, count, (uint16_t)rlen, *buf, *(buf + rlen - 1));
|
---|
213 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
214 |
|
---|
215 | total += rlen;
|
---|
216 | }
|
---|
217 | if (rlen != 0)
|
---|
218 | syslog(LOG_NOTICE, "[TDSn:%02u RCV] recv error: %s", cepid, itron_strerror(rlen));
|
---|
219 |
|
---|
220 | if ((error = tcp_sht_cep(cepid)) != E_OK)
|
---|
221 | syslog(LOG_NOTICE, "[TDSn:%02u RCV] shutdown error: %s", cepid, itron_strerror(error));
|
---|
222 |
|
---|
223 | if ((error = tcp_cls_cep(cepid, TMO_FEVR)) != E_OK)
|
---|
224 | syslog(LOG_NOTICE, "[TDSn:%02u RCV] close error: %s", cepid, itron_strerror(error));
|
---|
225 |
|
---|
226 | get_tim(&time);
|
---|
227 | syslog(LOG_NOTICE, "[TDSn:%02u RCV] finsh: %7lu, ttl: %lu",
|
---|
228 | cepid, time / SYSTIM_HZ, count, total);
|
---|
229 |
|
---|
230 | return error;
|
---|
231 | }
|
---|
232 |
|
---|
233 | #endif /* of #ifdef USE_COPYSAVE_API */
|
---|
234 |
|
---|
235 | #ifdef USE_TCP_EXTENTIONS
|
---|
236 |
|
---|
237 | /*
|
---|
238 | * get_tcp_rep -- TCP åä»å£ãç²å¾ããã
|
---|
239 | */
|
---|
240 |
|
---|
241 | static ER
|
---|
242 | get_tcp_rep (ID *repid)
|
---|
243 | {
|
---|
244 | ID tskid;
|
---|
245 | T_TCPN_CREP crep;
|
---|
246 |
|
---|
247 | get_tid(&tskid);
|
---|
248 |
|
---|
249 | crep.repatr = UINT_C(0);
|
---|
250 | crep.myaddr.portno = UINT_C(9);
|
---|
251 |
|
---|
252 | #if defined(SUPPORT_INET6)
|
---|
253 |
|
---|
254 | memcpy(&crep.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
|
---|
255 |
|
---|
256 | #else /* #if defined(SUPPORT_INET6) */
|
---|
257 |
|
---|
258 | #if defined(SUPPORT_INET4)
|
---|
259 | crep.myaddr.ipaddr = IPV4_ADDRANY;
|
---|
260 | #endif
|
---|
261 |
|
---|
262 | #endif /* #if defined(SUPPORT_INET6) */
|
---|
263 |
|
---|
264 | return ALLOC_TCP_REP(repid, tskid, &crep);
|
---|
265 | }
|
---|
266 |
|
---|
267 | /*
|
---|
268 | * get_tcp_cep -- TCP é信端ç¹ã¨ãç²å¾ããã
|
---|
269 | */
|
---|
270 |
|
---|
271 | static ER
|
---|
272 | get_tcp_cep (ID *cepid)
|
---|
273 | {
|
---|
274 | ID tskid;
|
---|
275 | T_TCP_CCEP ccep;
|
---|
276 |
|
---|
277 | get_tid(&tskid);
|
---|
278 |
|
---|
279 | ccep.cepatr = UINT_C(0);
|
---|
280 | ccep.sbuf = NADR;
|
---|
281 | ccep.sbufsz = 0;
|
---|
282 | ccep.rbufsz = TCP_DISCARD_SRV_RWBUF_SIZE;
|
---|
283 | ccep.callback = NULL;
|
---|
284 |
|
---|
285 | #ifdef TCP_CFG_RWBUF_CSAVE
|
---|
286 | ccep.rbuf = NADR;
|
---|
287 | #else
|
---|
288 | ccep.rbuf = tcp_discard_srv_rwbuf;
|
---|
289 | #endif
|
---|
290 |
|
---|
291 | return ALLOC_TCP_CEP(cepid, tskid, &ccep);
|
---|
292 | }
|
---|
293 |
|
---|
294 | /*
|
---|
295 | * tcp_discard_srv_task -- TCP ã¨ã³ã¼ãµã¼ãã¿ã¹ã¯
|
---|
296 | */
|
---|
297 |
|
---|
298 | void
|
---|
299 | tcp_discard_srv_task (intptr_t exinf)
|
---|
300 | {
|
---|
301 | ID tskid, cepid, repid;
|
---|
302 | ER error = E_OK;
|
---|
303 |
|
---|
304 | syscall(get_tid(&tskid));
|
---|
305 |
|
---|
306 | #if defined(SUPPORT_INET6)
|
---|
307 | #if defined(SUPPORT_INET4)
|
---|
308 | syslog(LOG_NOTICE, "[TCPn DISCARD SRV:%d] started.", tskid);
|
---|
309 | #else
|
---|
310 | syslog(LOG_NOTICE, "[TCP6 DISCARD SRV:%d] started.", tskid);
|
---|
311 | #endif
|
---|
312 | #else
|
---|
313 | syslog(LOG_NOTICE, "[TCP4 DISCARD SRV:%d] started.", tskid);
|
---|
314 | #endif
|
---|
315 |
|
---|
316 | while (true) {
|
---|
317 |
|
---|
318 | syscall(slp_tsk());
|
---|
319 | if ((error = get_tcp_cep (&cepid)) != E_OK) {
|
---|
320 | syslog(LOG_NOTICE, "[TDSn:00 EXT] CEP create error: %s", itron_strerror(error));
|
---|
321 | continue;
|
---|
322 | }
|
---|
323 |
|
---|
324 | while (true) {
|
---|
325 |
|
---|
326 | if ((error = get_tcp_rep (&repid)) != E_OK) {
|
---|
327 | syslog(LOG_NOTICE, "[TDSn:00 EXT] REP create error: %s", itron_strerror(error));
|
---|
328 | break;
|
---|
329 | }
|
---|
330 | else if ((error = tcp_discard_srv(cepid, repid)) != E_OK) {
|
---|
331 | error = FREE_TCP_REP(repid, error != E_DLT);
|
---|
332 | break;
|
---|
333 | }
|
---|
334 | }
|
---|
335 |
|
---|
336 | if ((error = FREE_TCP_CEP(cepid)) != E_OK)
|
---|
337 | syslog(LOG_NOTICE, "[TDSn:%02u EXT] CEP delete error: %s", cepid, itron_strerror(error));
|
---|
338 |
|
---|
339 | }
|
---|
340 | }
|
---|
341 |
|
---|
342 | #else /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
343 |
|
---|
344 | void
|
---|
345 | tcp_discard_srv_task(intptr_t exinf)
|
---|
346 | {
|
---|
347 | ID tskid;
|
---|
348 |
|
---|
349 | get_tid(&tskid);
|
---|
350 |
|
---|
351 | #if defined(SUPPORT_INET6)
|
---|
352 | #if defined(SUPPORT_INET4)
|
---|
353 | syslog(LOG_NOTICE, "[TCPn DISCARD SRV:%d,%d] started.", tskid, (ID)exinf);
|
---|
354 | #else
|
---|
355 | syslog(LOG_NOTICE, "[TCP6 DISCARD SRV:%d,%d] started.", tskid, (ID)exinf);
|
---|
356 | #endif
|
---|
357 | #else
|
---|
358 | syslog(LOG_NOTICE, "[TCP4 DISCARD SRV:%d,%d] started.", tskid, (ID)exinf);
|
---|
359 | #endif
|
---|
360 |
|
---|
361 | while (true) {
|
---|
362 | while (tcp_discard_srv((ID)exinf, TCP_DISCARD_SRV_REPID) == E_OK)
|
---|
363 | ;
|
---|
364 | }
|
---|
365 | }
|
---|
366 |
|
---|
367 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
368 |
|
---|
369 | #endif /* of #ifdef USE_TCP_DISCARD_SRV */
|
---|