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: udp_discard_cli.c 317 2017-08-03 13:14:26Z coas-nagasima $
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * UDP DISCARD ã¯ã©ã¤ã¢ã³ã
|
---|
48 | */
|
---|
49 |
|
---|
50 | #include <stdlib.h>
|
---|
51 | #include <string.h>
|
---|
52 |
|
---|
53 | #ifdef TARGET_KERNEL_ASP
|
---|
54 |
|
---|
55 | #include <kernel.h>
|
---|
56 | #include <sil.h>
|
---|
57 | #include <t_syslog.h>
|
---|
58 | #include "kernel_cfg.h"
|
---|
59 |
|
---|
60 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
61 |
|
---|
62 | #ifdef TARGET_KERNEL_JSP
|
---|
63 |
|
---|
64 | #include <t_services.h>
|
---|
65 | #include "kernel_id.h"
|
---|
66 | #include "tinet_id.h"
|
---|
67 |
|
---|
68 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
69 |
|
---|
70 | #include <netinet/in.h>
|
---|
71 | #include <netinet/in_itron.h>
|
---|
72 | #include <netinet/ip.h>
|
---|
73 | #include <netinet/udp.h>
|
---|
74 |
|
---|
75 | #include <netapp/netapp.h>
|
---|
76 | #include <netapp/netapp_var.h>
|
---|
77 | #include <netapp/udp_discard_cli.h>
|
---|
78 |
|
---|
79 | #ifdef USE_UDP_DISCARD_CLI
|
---|
80 |
|
---|
81 | /* discard ãµã¼ãã®ãã¼ãçªå· */
|
---|
82 |
|
---|
83 | #define DISCARD_SRV_PORTNO UINT_C(9)
|
---|
84 |
|
---|
85 | /*
|
---|
86 | * å¤æ°
|
---|
87 | */
|
---|
88 |
|
---|
89 | #define PAT_BEGIN ' '
|
---|
90 | #define PAT_END '~'
|
---|
91 |
|
---|
92 | #if defined(SUPPORT_INET6)
|
---|
93 | #define API_PROTO '6'
|
---|
94 | #else
|
---|
95 | #define API_PROTO '4'
|
---|
96 | #endif
|
---|
97 |
|
---|
98 | /*
|
---|
99 | * å
|
---|
100 | ¨åå¤æ°
|
---|
101 | */
|
---|
102 |
|
---|
103 | bool_t udp_discard_cli_valid;
|
---|
104 |
|
---|
105 | /*
|
---|
106 | * send_udp_discard -- DISCARD/UDP ãµã¼ãã«ã¡ãã»ã¼ã¸ãéä¿¡ããã
|
---|
107 | */
|
---|
108 |
|
---|
109 | static ER
|
---|
110 | send_udp_discard (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno)
|
---|
111 | {
|
---|
112 | #if defined(SUPPORT_INET6)
|
---|
113 | static char smsg[IPV6_MMTU - (IP6_HDR_SIZE + UDP_HDR_SIZE)];
|
---|
114 | #else
|
---|
115 | static char smsg[IP4_MSS - (IP4_HDR_SIZE + UDP_HDR_SIZE)];
|
---|
116 | #endif
|
---|
117 |
|
---|
118 | T_IPEP dst;
|
---|
119 | ER_UINT len;
|
---|
120 | SYSTIM time;
|
---|
121 | char *p;
|
---|
122 | uint32_t total;
|
---|
123 | uint16_t pat, slen, scount;
|
---|
124 |
|
---|
125 | dst.ipaddr = *ipaddr;
|
---|
126 | dst.portno = portno;
|
---|
127 |
|
---|
128 | p = smsg;
|
---|
129 | for (slen = sizeof(smsg); slen > 0; )
|
---|
130 | for (pat = PAT_BEGIN; slen > 0 && pat <= PAT_END; pat ++, slen --)
|
---|
131 | *p ++ = pat;
|
---|
132 |
|
---|
133 | get_tim(&time);
|
---|
134 | syslog(LOG_NOTICE, "[UDC%c:%02u SND] send: %7lu, to: %s.%d",
|
---|
135 | API_PROTO, cepid, time / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
|
---|
136 |
|
---|
137 | scount = total = 0;
|
---|
138 | udp_discard_cli_valid = true;
|
---|
139 | for (slen = sizeof(smsg); udp_discard_cli_valid && slen > 0; slen --) {
|
---|
140 | scount ++;
|
---|
141 | if ((len = UDP_SND_DAT(cepid, &dst, smsg, slen, TMO_FEVR)) < 0) {
|
---|
142 | syslog(LOG_NOTICE, "[UDC%c:%02u SND] error: %s", API_PROTO, cepid, itron_strerror(len));
|
---|
143 | return len;
|
---|
144 | }
|
---|
145 | else
|
---|
146 | syslog(LOG_NOTICE, "[UDC%c:%02u SND] send: %7lu, %4u", API_PROTO, cepid, scount, slen);
|
---|
147 | total += len;
|
---|
148 | dly_tsk(10 * SYSTIM_HZ + netapp_rand() % (10 * SYSTIM_HZ));
|
---|
149 | }
|
---|
150 |
|
---|
151 | get_tim(&time);
|
---|
152 | syslog(LOG_NOTICE, "[UDC%c:%02u SND] finsh: %7lu, snd: %4u, len: %ld",
|
---|
153 | API_PROTO, cepid, time / SYSTIM_HZ, scount, total);
|
---|
154 | return E_OK;
|
---|
155 | }
|
---|
156 |
|
---|
157 | /*
|
---|
158 | * UDP DISCARD ã¯ã©ã¤ã¢ã³ãéä¿¡ã¿ã¹ã¯
|
---|
159 | */
|
---|
160 |
|
---|
161 | void
|
---|
162 | udp_discard_cli_task (intptr_t exinf)
|
---|
163 | {
|
---|
164 | T_IN_ADDR addr;
|
---|
165 | ID tskid, cepid;
|
---|
166 | ER error;
|
---|
167 | char *line;
|
---|
168 | int_t no;
|
---|
169 | uint16_t portno;
|
---|
170 | char apip;
|
---|
171 |
|
---|
172 | #ifdef USE_UDP_EXTENTIONS
|
---|
173 |
|
---|
174 | #if defined(SUPPORT_INET6)
|
---|
175 | T_UDP6_CCEP ccep;
|
---|
176 | #else
|
---|
177 | T_UDP_CCEP ccep;
|
---|
178 | #endif
|
---|
179 |
|
---|
180 | #endif /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
181 |
|
---|
182 | #if defined(SUPPORT_INET6)
|
---|
183 | apip = API_PROTO_IPV6;
|
---|
184 | #else
|
---|
185 | apip = API_PROTO_IPV4;
|
---|
186 | #endif
|
---|
187 |
|
---|
188 | get_tid(&tskid);
|
---|
189 | syslog(LOG_NOTICE, "[UDP DISCARD CLI:%d,%d] started.", tskid, (ID)exinf);
|
---|
190 | while (true) {
|
---|
191 | if (rcv_dtq(DTQ_UDP_DISCARD_CLI, (intptr_t*)&line) == E_OK) {
|
---|
192 | line = skip_blanks(GET_IPADDR(&addr, skip_blanks(line))); /* IP Address */
|
---|
193 |
|
---|
194 | if ((line = lookup_ipaddr(&addr, line, apip)) == NULL) {
|
---|
195 | syslog(LOG_NOTICE, "[UDC%c:%02u TSK] unknown host.", (ID)exinf);
|
---|
196 | continue;
|
---|
197 | }
|
---|
198 |
|
---|
199 | if ('0' <= *line && *line <= '9') { /* Port No */
|
---|
200 | line = get_int(&no, line);
|
---|
201 | portno = (uint16_t)no;
|
---|
202 | }
|
---|
203 | else {
|
---|
204 | line ++;
|
---|
205 | portno = DISCARD_SRV_PORTNO;
|
---|
206 | }
|
---|
207 |
|
---|
208 | #ifdef USE_UDP_EXTENTIONS
|
---|
209 |
|
---|
210 | ccep.cepatr = UINT_C(0);
|
---|
211 | ccep.callback = NULL;
|
---|
212 | ccep.myaddr.portno = UDP_PORTANY;
|
---|
213 |
|
---|
214 | #if defined(SUPPORT_INET6)
|
---|
215 |
|
---|
216 | memcpy(&ccep.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
|
---|
217 |
|
---|
218 | #else /* #if defined(SUPPORT_INET6) */
|
---|
219 |
|
---|
220 | #if defined(SUPPORT_INET4)
|
---|
221 | ccep.myaddr.ipaddr = IPV4_ADDRANY;
|
---|
222 | #endif
|
---|
223 |
|
---|
224 | #endif /* #if defined(SUPPORT_INET6) */
|
---|
225 |
|
---|
226 | if ((error = ALLOC_UDP_CEP(&cepid, tskid, &ccep)) != E_OK) {
|
---|
227 | syslog(LOG_NOTICE, "[UDC%c:%02u TSK] CEP create error: %s", API_PROTO, cepid, itron_strerror(error));
|
---|
228 | continue;
|
---|
229 | }
|
---|
230 |
|
---|
231 | #else /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
232 |
|
---|
233 | cepid = (ID)exinf;
|
---|
234 |
|
---|
235 | #endif /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
236 |
|
---|
237 | if ((error = send_udp_discard(cepid, &addr, portno)) != E_OK)
|
---|
238 | syslog(LOG_NOTICE, "[UDC%c:%02u TSK] error: %s", API_PROTO, cepid, itron_strerror(error));
|
---|
239 |
|
---|
240 | #ifdef USE_UDP_EXTENTIONS
|
---|
241 |
|
---|
242 | if ((error = FREE_UDP_CEP(cepid, !(error == E_NOEXS || error == E_DLT))) != E_OK)
|
---|
243 | syslog(LOG_NOTICE, "[UDC%c:%02u TSK] CEP delete error: %s", API_PROTO, cepid, itron_strerror(error));
|
---|
244 |
|
---|
245 | #endif /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
246 |
|
---|
247 | }
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|
251 | #endif /* of #ifdef USE_UDP_DISCARD_CLI */
|
---|