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