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: udp_echo_cli.c 270 2017-02-09 04:03:47Z coas-nagasima $
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * UDP ECHO ã¯ã©ã¤ã¢ã³ã
|
---|
48 | */
|
---|
49 |
|
---|
50 | #include <string.h>
|
---|
51 |
|
---|
52 | #ifdef TARGET_KERNEL_ASP
|
---|
53 |
|
---|
54 | #include <kernel.h>
|
---|
55 | #include <sil.h>
|
---|
56 | #include <t_syslog.h>
|
---|
57 | #include "kernel_cfg.h"
|
---|
58 |
|
---|
59 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
60 |
|
---|
61 | #ifdef TARGET_KERNEL_JSP
|
---|
62 |
|
---|
63 | #include <t_services.h>
|
---|
64 | #include "kernel_id.h"
|
---|
65 | #include "tinet_id.h"
|
---|
66 |
|
---|
67 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
68 |
|
---|
69 | #include <tinet_defs.h>
|
---|
70 | #include <tinet_config.h>
|
---|
71 |
|
---|
72 | #include <net/net.h>
|
---|
73 | #include <net/net_var.h>
|
---|
74 | #include <net/net_timer.h>
|
---|
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/echo.h>
|
---|
82 |
|
---|
83 | #ifdef USE_UDP_ECHO_CLI
|
---|
84 |
|
---|
85 | /* echo ãµã¼ãã®ãã¼ãçªå· */
|
---|
86 |
|
---|
87 | #define ECHO_SRV_PORTNO UINT_C(7)
|
---|
88 |
|
---|
89 | /*
|
---|
90 | * å
|
---|
91 | ¨åå¤æ°
|
---|
92 | */
|
---|
93 |
|
---|
94 | bool_t udp_echo_cli_valid;
|
---|
95 |
|
---|
96 | /*
|
---|
97 | * å¤æ°
|
---|
98 | */
|
---|
99 |
|
---|
100 | #define BUF_SIZE 2048
|
---|
101 |
|
---|
102 | static char udp_buf[BUF_SIZE];
|
---|
103 | static T_IPEP dst;
|
---|
104 |
|
---|
105 | #ifdef USE_UDP_NON_BLOCKING
|
---|
106 |
|
---|
107 | static ER_UINT nblk_len;
|
---|
108 |
|
---|
109 | /*
|
---|
110 | * ãã³ããããã³ã°ã³ã¼ã«ã®ã³ã¼ã«ããã¯é¢æ°
|
---|
111 | */
|
---|
112 |
|
---|
113 | ER
|
---|
114 | callback_nblk_udp_echo_cli (ID cepid, FN fncd, void *p_parblk)
|
---|
115 | {
|
---|
116 | nblk_len = *(ER_UINT*)p_parblk;
|
---|
117 | syscall(wup_tsk(UDP_ECHO_CLI_TASK));
|
---|
118 | return E_OK;
|
---|
119 | }
|
---|
120 |
|
---|
121 | /*
|
---|
122 | * send_udp_echo -- ECHO/UDP ãµã¼ãã«ã¡ãã»ã¼ã¸ãéä¿¡ãã (ãã³ããããã³ã°ã³ã¼ã«ä½¿ç¨)ã
|
---|
123 | */
|
---|
124 |
|
---|
125 | static ER
|
---|
126 | send_udp_echo (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno, char *line)
|
---|
127 | {
|
---|
128 | ER_UINT error;
|
---|
129 | uint_t len;
|
---|
130 |
|
---|
131 | dst.ipaddr = *ipaddr;
|
---|
132 | dst.portno = portno;
|
---|
133 | len = strlen(line);
|
---|
134 | if ((error = UDP_SND_DAT(cepid, &dst, line, len, TMO_NBLK)) != E_WBLK) {
|
---|
135 | syslog(LOG_NOTICE, "[UEC:%02d SND] error: %s", cepid, itron_strerror(error));
|
---|
136 | return error;
|
---|
137 | }
|
---|
138 | else
|
---|
139 | syslog(LOG_NOTICE, "[UEC:%02d SND] sending: to: %s.%d: %s",
|
---|
140 | cepid, IP2STR(NULL, &dst.ipaddr), dst.portno, line);
|
---|
141 |
|
---|
142 | syscall(slp_tsk());
|
---|
143 | if (nblk_len < 0) { /* 0 以ä¸ã®å ´åã¯ãã¨ã©ã¼ã³ã¼ã */
|
---|
144 | syslog(LOG_NOTICE, "[UEC:%02d CBR] error: %s", cepid, itron_strerror(nblk_len));
|
---|
145 | return nblk_len;
|
---|
146 | }
|
---|
147 |
|
---|
148 | if ((error = UDP_RCV_DAT(cepid, &dst, udp_buf, sizeof(udp_buf), TMO_NBLK)) != E_WBLK) {
|
---|
149 | syslog(LOG_NOTICE, "[UEC:%02d RCV] error: %s", cepid, itron_strerror(error));
|
---|
150 | return error;
|
---|
151 | }
|
---|
152 |
|
---|
153 | syscall(slp_tsk());
|
---|
154 | if (nblk_len < 0) { /* 0 以ä¸ã®å ´åã¯ãã¨ã©ã¼ã³ã¼ã */
|
---|
155 | syslog(LOG_NOTICE, "[UEC:%02d RCV] error: %s", cepid, itron_strerror(nblk_len));
|
---|
156 | return nblk_len;
|
---|
157 | }
|
---|
158 | else {
|
---|
159 | udp_buf[nblk_len] = '\0';
|
---|
160 | syslog(LOG_NOTICE, "[UEC:%02d RCV] received: from: %s.%d: %s",
|
---|
161 | cepid, IP2STR(NULL, &dst.ipaddr), dst.portno, udp_buf);
|
---|
162 | nblk_len = E_OK;
|
---|
163 | }
|
---|
164 |
|
---|
165 | return nblk_len;
|
---|
166 | }
|
---|
167 |
|
---|
168 | #else /* of #ifdef USE_UDP_NON_BLOCKING */
|
---|
169 |
|
---|
170 | #ifdef USE_UDP_CALL_BACK
|
---|
171 |
|
---|
172 | /*
|
---|
173 | * ã³ã¼ã«ããã¯é¢æ°
|
---|
174 | */
|
---|
175 |
|
---|
176 | ER
|
---|
177 | callback_udp_echo_cli (ID cepid, FN fncd, void *p_parblk)
|
---|
178 | {
|
---|
179 | ER_UINT len;
|
---|
180 |
|
---|
181 | if ((len = UDP_RCV_DAT(cepid, &dst, udp_buf, sizeof(udp_buf), TMO_FEVR)) >= 0) {
|
---|
182 | *(udp_buf + len) = '\0';
|
---|
183 | syslog(LOG_NOTICE, "[UEC:%02d RCV] recv: addr: %s.%d: %s",
|
---|
184 | cepid, IP2STR(NULL, &dst.ipaddr), dst.portno, udp_buf);
|
---|
185 | }
|
---|
186 | else
|
---|
187 | syslog(LOG_NOTICE, "[UEC:%02d RCV] recv: error: %s", cepid, itron_strerror(len));
|
---|
188 |
|
---|
189 | return E_OK;
|
---|
190 | }
|
---|
191 |
|
---|
192 | /*
|
---|
193 | * send_udp_echo -- ECHO/UDP ãµã¼ãã«ã¡ãã»ã¼ã¸ãéä¿¡ãã (ã³ã¼ã«ããã¯é¢æ°ä½¿ç¨)ã
|
---|
194 | */
|
---|
195 |
|
---|
196 | static ER
|
---|
197 | send_udp_echo (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno, char *line)
|
---|
198 | {
|
---|
199 | ER_UINT len;
|
---|
200 |
|
---|
201 | dst.ipaddr = *ipaddr;
|
---|
202 | dst.portno = portno;
|
---|
203 | len = strlen(line);
|
---|
204 | syslog(LOG_NOTICE, "[UEC:%02d SND] sending: to: %s.%d: %s",
|
---|
205 | cepid, IP2STR(NULL, &dst.ipaddr), dst.portno, line);
|
---|
206 | if ((len = UDP_SND_DAT(cepid, &dst, line, len, TMO_FEVR)) < 0)
|
---|
207 | syslog(LOG_NOTICE, "[UEC:%02d SND] error: %s", cepid, itron_strerror(len));
|
---|
208 |
|
---|
209 | return E_OK;
|
---|
210 | }
|
---|
211 |
|
---|
212 | #else /* of #ifdef USE_UDP_CALL_BACK */
|
---|
213 |
|
---|
214 | /*
|
---|
215 | * send_udp_echo -- ECHO/UDP ãµã¼ãã«ã¡ãã»ã¼ã¸ãéä¿¡ãã (ã³ã¼ã«ããã¯é¢æ°æªä½¿ç¨)ã
|
---|
216 | */
|
---|
217 |
|
---|
218 | static ER
|
---|
219 | send_udp_echo (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno, char *line)
|
---|
220 | {
|
---|
221 | ER_UINT len;
|
---|
222 |
|
---|
223 | dst.ipaddr = *ipaddr;
|
---|
224 | dst.portno = portno;
|
---|
225 | len = strlen(line);
|
---|
226 | syslog(LOG_NOTICE, "[UEC:%02d SND] sending: to: %s.%d: %s",
|
---|
227 | cepid, IP2STR(NULL, &dst.ipaddr), dst.portno, line);
|
---|
228 | if ((len = UDP_SND_DAT(cepid, &dst, line, len, TMO_FEVR)) < 0) {
|
---|
229 | syslog(LOG_NOTICE, "[UEC:%02d SND] error: %s", cepid, itron_strerror(len));
|
---|
230 | return len;
|
---|
231 | }
|
---|
232 |
|
---|
233 | if ((len = UDP_RCV_DAT(cepid, &dst, udp_buf, sizeof(udp_buf), 10*1000)) >= 0) {
|
---|
234 | *(udp_buf + len) = '\0';
|
---|
235 | syslog(LOG_NOTICE, "[UEC:%02d RCV] received: from: %s.%d: %s",
|
---|
236 | cepid, IP2STR(NULL, &dst.ipaddr), dst.portno, line);
|
---|
237 | return E_OK;
|
---|
238 | }
|
---|
239 | else {
|
---|
240 | syslog(LOG_NOTICE, "[UEC:%02d RCV] error: %s", cepid, itron_strerror(len));
|
---|
241 | return len;
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | #endif /* of #ifdef USE_UDP_CALL_BACK */
|
---|
246 |
|
---|
247 | #endif /* of #ifdef USE_UDP_NON_BLOCKING */
|
---|
248 |
|
---|
249 | #define MESSAGE_FORMAT "MSG 1000000"
|
---|
250 |
|
---|
251 | /*
|
---|
252 | * UDP ECHO ã¯ã©ã¤ã¢ã³ãéä¿¡ã¿ã¹ã¯
|
---|
253 | */
|
---|
254 |
|
---|
255 | void
|
---|
256 | udp_echo_cli_task (intptr_t exinf)
|
---|
257 | {
|
---|
258 | static char msg[sizeof(MESSAGE_FORMAT)] = MESSAGE_FORMAT;
|
---|
259 |
|
---|
260 | T_IN_ADDR addr;
|
---|
261 | ID tskid, cepid;
|
---|
262 | ER error = E_OK;
|
---|
263 | char *line, *p;
|
---|
264 | int_t rep;
|
---|
265 | uint32_t count, msgno;
|
---|
266 | uint16_t portno;
|
---|
267 |
|
---|
268 | #ifdef USE_UDP_EXTENTIONS
|
---|
269 |
|
---|
270 | T_UDP_CCEP ccep;
|
---|
271 |
|
---|
272 | #endif /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
273 |
|
---|
274 | get_tid(&tskid);
|
---|
275 | syslog(LOG_NOTICE, "[UDP ECHO CLI:%d,%d] started.", tskid, (ID)exinf);
|
---|
276 | while (true) {
|
---|
277 | if (rcv_dtq(DTQ_UDP_ECHO_CLI, (intptr_t*)&line) == E_OK) {
|
---|
278 |
|
---|
279 | #ifdef USE_UDP_EXTENTIONS
|
---|
280 |
|
---|
281 | ccep.cepatr = UINT_C(0);
|
---|
282 | ccep.myaddr.portno = UDP_PORTANY;
|
---|
283 |
|
---|
284 | #if defined(SUPPORT_INET4)
|
---|
285 | ccep.myaddr.ipaddr = IPV4_ADDRANY;
|
---|
286 | #endif
|
---|
287 |
|
---|
288 | #if defined(SUPPORT_INET6)
|
---|
289 | memcpy(&ccep.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
|
---|
290 | #endif
|
---|
291 |
|
---|
292 | #ifdef USE_UDP_NON_BLOCKING
|
---|
293 | ccep.callback = (FP)callback_nblk_udp_echo_cli;
|
---|
294 | #else
|
---|
295 | ccep.callback = NULL;
|
---|
296 | #endif
|
---|
297 |
|
---|
298 | if ((error = alloc_udp_cep(&cepid, tskid, &ccep)) != E_OK) {
|
---|
299 | syslog(LOG_NOTICE, "[UEC:%02d TSK] CEP create error: %s", cepid, itron_strerror(error));
|
---|
300 | continue;
|
---|
301 | }
|
---|
302 |
|
---|
303 | #else /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
304 |
|
---|
305 | cepid = (ID)exinf;
|
---|
306 |
|
---|
307 | #endif /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
308 |
|
---|
309 | line = skip_blanks(GET_IPADDR(&addr, skip_blanks(line))); /* IP Address */
|
---|
310 |
|
---|
311 | if ('0' <= *line && *line <= '9') { /* Port No */
|
---|
312 | line = get_int(&rep, line);
|
---|
313 | portno = (uint16_t)rep;
|
---|
314 | }
|
---|
315 | else {
|
---|
316 | line ++;
|
---|
317 | portno = ECHO_SRV_PORTNO;
|
---|
318 | }
|
---|
319 |
|
---|
320 | line = skip_blanks(line);
|
---|
321 | if ('0' <= *line && *line <= '9') { /* Repeat */
|
---|
322 | line = get_int(&rep, line);
|
---|
323 | if (rep > 1000000)
|
---|
324 | rep = 1000000;
|
---|
325 | udp_echo_cli_valid = true;
|
---|
326 | for (count = 0; count ++ < rep; ) {
|
---|
327 | if (!udp_echo_cli_valid) {
|
---|
328 | syslog(LOG_NOTICE, "[UEC:%02d TSK] canceled.", cepid);
|
---|
329 | break;
|
---|
330 | }
|
---|
331 |
|
---|
332 | p = &msg[sizeof(MESSAGE_FORMAT)] - 1;
|
---|
333 | for (msgno = count; msgno > 0; msgno /= 10)
|
---|
334 | *(-- p) = msgno % 10 + '0';
|
---|
335 | while (*(p - 2) != 'G')
|
---|
336 | *(-- p) = ' ';
|
---|
337 |
|
---|
338 | if ((error = send_udp_echo(cepid, &addr, portno, msg)) != E_OK)
|
---|
339 | break;
|
---|
340 |
|
---|
341 | dly_tsk(10 * SYSTIM_HZ + net_rand() % (10 * SYSTIM_HZ));
|
---|
342 | }
|
---|
343 | }
|
---|
344 |
|
---|
345 | else /* Single Message */
|
---|
346 | error = send_udp_echo(cepid, &addr, portno, line);
|
---|
347 |
|
---|
348 | if (error != E_OK)
|
---|
349 | syslog(LOG_NOTICE, "[UEC:%02d TSK] error: %s", cepid, itron_strerror(error));
|
---|
350 |
|
---|
351 | #ifdef USE_UDP_EXTENTIONS
|
---|
352 |
|
---|
353 | if ((error = free_udp_cep(cepid, !(error == E_NOEXS || error == E_DLT))) != E_OK)
|
---|
354 | syslog(LOG_NOTICE, "[UEC:%02d TSK] CEP delete error: %s", cepid, itron_strerror(error));
|
---|
355 |
|
---|
356 | #endif /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
357 |
|
---|
358 | }
|
---|
359 | }
|
---|
360 | }
|
---|
361 |
|
---|
362 | #endif /* of #ifdef USE_UDP_ECHO_CLI */
|
---|