[313] | 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_cli.c 313 2017-07-23 04:50:32Z coas-nagasima $
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 | /*
|
---|
| 47 | * TCP DISCARD ã¯ã©ã¤ã¢ã³ã
|
---|
| 48 | *
|
---|
| 49 | * ã»ãã³ããããã³ã°ã³ã¼ã«
|
---|
| 50 | * ã»IPv4
|
---|
| 51 | * ã»IPv6
|
---|
| 52 | */
|
---|
| 53 |
|
---|
| 54 | #include <stdlib.h>
|
---|
| 55 |
|
---|
| 56 | #ifdef TARGET_KERNEL_ASP
|
---|
| 57 |
|
---|
| 58 | #include <kernel.h>
|
---|
| 59 | #include <sil.h>
|
---|
| 60 | #include <t_syslog.h>
|
---|
| 61 | #include "kernel_cfg.h"
|
---|
| 62 |
|
---|
| 63 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 64 |
|
---|
| 65 | #ifdef TARGET_KERNEL_JSP
|
---|
| 66 |
|
---|
| 67 | #include <t_services.h>
|
---|
| 68 | #include "kernel_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_cli.h>
|
---|
| 78 |
|
---|
| 79 | #ifdef USE_TCP_DISCARD_CLI
|
---|
| 80 |
|
---|
| 81 | /* discard ãµã¼ãã®ãã¼ãçªå· */
|
---|
| 82 |
|
---|
| 83 | #define DISCARD_SRV_PORTNO UINT_C(9)
|
---|
| 84 |
|
---|
| 85 | /* 表示 */
|
---|
| 86 |
|
---|
| 87 | /*#define SHOW_RCV_RANGE*/
|
---|
| 88 |
|
---|
| 89 | /* éä¿¡éé */
|
---|
| 90 |
|
---|
| 91 | #ifdef TOPPERS_S810_CLG3_85
|
---|
| 92 |
|
---|
| 93 | #define START_DLY (10*SYSTIM_HZ)
|
---|
| 94 | #define SND_ITV (5*SYSTIM_HZ)
|
---|
| 95 | #define SLP_ITV (30*SYSTIM_HZ)
|
---|
| 96 |
|
---|
| 97 | #else /* of #ifdef TOPPERS_S810_CLG3_85 */
|
---|
| 98 |
|
---|
| 99 | #define START_DLY (10*SYSTIM_HZ)
|
---|
| 100 | #define SND_ITV (5*SYSTIM_HZ)
|
---|
| 101 | #define SLP_ITV (60*SYSTIM_HZ)
|
---|
| 102 |
|
---|
| 103 | #endif /* of #ifdef TOPPERS_S810_CLG3_85 */
|
---|
| 104 |
|
---|
| 105 | /* èªåå®è¡ */
|
---|
| 106 |
|
---|
| 107 | #if defined(TCP_DISCARD_CLI_AUTO_RUN_STR)
|
---|
| 108 | #else
|
---|
| 109 | #if 0
|
---|
| 110 | #if defined(SUPPORT_INET6)
|
---|
| 111 | #define TCP_DISCARD_CLI_AUTO_RUN_STR "fd90:cce5:25f6:ff81:201:2ff:fe81:e7c9 - 0"
|
---|
| 112 | #else
|
---|
| 113 | #define TCP_DISCARD_CLI_AUTO_RUN_STR "172.25.129.142 - 0"
|
---|
| 114 | #endif
|
---|
| 115 | #endif
|
---|
| 116 | #endif
|
---|
| 117 |
|
---|
| 118 | /*
|
---|
| 119 | * ãããã¡ãµã¤ãºã®å®ç¾©
|
---|
| 120 | */
|
---|
| 121 |
|
---|
| 122 | #define NUM_DISCARD 5
|
---|
| 123 | #define NUM_REP_PAT 40
|
---|
| 124 | #define PAT_BEGIN ' '
|
---|
| 125 | #define PAT_END '~'
|
---|
| 126 | #define SND_BUF_SIZE ((PAT_END - PAT_BEGIN + 1) * NUM_REP_PAT)
|
---|
| 127 |
|
---|
| 128 | /*
|
---|
| 129 | * å
|
---|
| 130 | ¨åå¤æ°
|
---|
| 131 | */
|
---|
| 132 |
|
---|
| 133 | bool_t tcp_discard_cli_valid;
|
---|
| 134 |
|
---|
| 135 | /* TCP éåä¿¡ã¦ã£ã³ããããã¡ */
|
---|
| 136 |
|
---|
| 137 | #ifndef TCP_CFG_SWBUF_CSAVE_ONLY
|
---|
| 138 | uint8_t tcp_discard_cli_swbuf[TCP_DISCARD_CLI_SWBUF_SIZE];
|
---|
| 139 | #endif
|
---|
| 140 |
|
---|
| 141 | #ifdef USE_TCP_NON_BLOCKING
|
---|
| 142 |
|
---|
| 143 | /*
|
---|
| 144 | * å¤æ°
|
---|
| 145 | */
|
---|
| 146 |
|
---|
| 147 | static T_IPEP nblk_src = {
|
---|
| 148 | IP_ADDRANY,
|
---|
| 149 | TCP_PORTANY,
|
---|
| 150 | };
|
---|
| 151 | static T_IPEP nblk_dst;
|
---|
| 152 | static ER_UINT nblk_error;
|
---|
| 153 |
|
---|
| 154 | /*
|
---|
| 155 | * ãã³ããããã³ã°ã³ã¼ã«ã®ã³ã¼ã«ããã¯é¢æ°
|
---|
| 156 | */
|
---|
| 157 |
|
---|
| 158 | ER
|
---|
| 159 | callback_nblk_tcp_discard_cli (ID cepid, FN fncd, void *p_parblk)
|
---|
| 160 | {
|
---|
| 161 | ER error = E_OK;
|
---|
| 162 |
|
---|
| 163 | nblk_error = *(ER*)p_parblk;
|
---|
| 164 |
|
---|
| 165 | switch (fncd) {
|
---|
| 166 |
|
---|
| 167 | case TFN_TCP_CON_CEP:
|
---|
| 168 | syscall(sig_sem(SEM_TCP_DISCARD_CLI_NBLK_READY));
|
---|
| 169 | break;
|
---|
| 170 |
|
---|
| 171 | case TFN_TCP_CLS_CEP:
|
---|
| 172 | if (nblk_error < 0)
|
---|
| 173 | syslog(LOG_NOTICE, "[TDCn:%02u CBN] close error: %s", cepid, itron_strerror(nblk_error));
|
---|
| 174 | syscall(sig_sem(SEM_TCP_DISCARD_CLI_NBLK_READY));
|
---|
| 175 | break;
|
---|
| 176 |
|
---|
| 177 | case TFN_TCP_ACP_CEP:
|
---|
| 178 | case TFN_TCP_SND_DAT:
|
---|
| 179 | case TFN_TCP_GET_BUF:
|
---|
| 180 | case TFN_TCP_SND_OOB:
|
---|
| 181 | default:
|
---|
| 182 | error = E_PAR;
|
---|
| 183 | break;
|
---|
| 184 | }
|
---|
| 185 | return error;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | /*
|
---|
| 189 | * send_tcp_discard -- DISCARD/TCP ãµã¼ãã«ã¡ãã»ã¼ã¸ãéä¿¡ããã
|
---|
| 190 | */
|
---|
| 191 |
|
---|
| 192 | static ER
|
---|
| 193 | send_tcp_discard (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno)
|
---|
| 194 | {
|
---|
| 195 | static char smsg[SND_BUF_SIZE];
|
---|
| 196 |
|
---|
| 197 | ER_UINT slen;
|
---|
| 198 | ER error;
|
---|
| 199 | SYSTIM time;
|
---|
| 200 | uint32_t total;
|
---|
| 201 | uint16_t soff, discard, rep, scount;
|
---|
| 202 | uint8_t pat, *p;
|
---|
| 203 |
|
---|
| 204 | nblk_dst.ipaddr = *ipaddr;
|
---|
| 205 | nblk_dst.portno = portno;
|
---|
| 206 |
|
---|
| 207 | p = smsg;
|
---|
| 208 | for (rep = NUM_REP_PAT; rep -- > 0; )
|
---|
| 209 | for (pat = PAT_BEGIN; pat <= PAT_END; pat ++)
|
---|
| 210 | *p ++ = pat;
|
---|
| 211 |
|
---|
| 212 | if ((error = TCP_CON_CEP(cepid, &nblk_src, &nblk_dst, TMO_NBLK)) != E_WBLK) {
|
---|
| 213 | syslog(LOG_NOTICE, "[TDCn:%02u SND] connect error: %s", cepid, itron_strerror(error));
|
---|
| 214 | return error;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | /* æ¥ç¶ãå®äºããã¾ã§å¾
|
---|
| 218 | ã¤ã*/
|
---|
| 219 | syscall(wai_sem(SEM_TCP_DISCARD_CLI_NBLK_READY));
|
---|
| 220 |
|
---|
| 221 | if (nblk_error != E_OK)
|
---|
| 222 | syslog(LOG_NOTICE, "[TDCn:%02u SND] connect error: %s", cepid, itron_strerror(nblk_error));
|
---|
| 223 | else {
|
---|
| 224 | get_tim(&time);
|
---|
| 225 | syslog(LOG_NOTICE, "[TDCn:%02u SND] conct: %7lu, to: %s.%d",
|
---|
| 226 | cepid, time / SYSTIM_HZ, IP2STR(NULL, ipaddr), nblk_dst.portno);
|
---|
| 227 |
|
---|
| 228 | scount = total = 0;
|
---|
| 229 | for (discard = NUM_DISCARD; discard -- > 0; ) {
|
---|
| 230 | soff = 0;
|
---|
| 231 | while (soff < SND_BUF_SIZE) {
|
---|
| 232 | if ((slen = tcp_snd_dat(cepid, smsg + soff, sizeof(smsg) - soff, TMO_FEVR)) < 0) {
|
---|
| 233 | syslog(LOG_NOTICE, "[TDCn:%02u SND] send error: %s",
|
---|
| 234 | cepid, itron_strerror(slen));
|
---|
| 235 | goto cls_ret;
|
---|
| 236 | }
|
---|
| 237 | soff += (uint16_t)slen;
|
---|
| 238 | total += slen;
|
---|
| 239 | scount ++;
|
---|
| 240 |
|
---|
| 241 | #ifdef SHOW_RCV_RANGE
|
---|
| 242 | syslog(LOG_NOTICE, "[TDCn:%02u SND] send: %7lu, len: %4u, off: %4u",
|
---|
| 243 | cepid, scount, (uint16_t)slen, soff);
|
---|
| 244 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
| 245 |
|
---|
| 246 | syscall(dly_tsk(500 + netapp_rand() % SYSTIM_HZ));
|
---|
| 247 | }
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | cls_ret:
|
---|
| 251 | get_tim(&time);
|
---|
| 252 | syslog(LOG_NOTICE, "[TDCn:%02u SND] finsh: %7lu, ttl: %lu",
|
---|
| 253 | cepid, time / SYSTIM_HZ, scount, total);
|
---|
| 254 |
|
---|
| 255 | if ((error = tcp_sht_cep(cepid)) < 0)
|
---|
| 256 | syslog(LOG_NOTICE, "[TDCn:%02u SND] shutdown error: %s", cepid, itron_strerror(error));
|
---|
| 257 |
|
---|
| 258 | if ((error = tcp_cls_cep(cepid, TMO_NBLK)) != E_WBLK)
|
---|
| 259 | syslog(LOG_NOTICE, "[TDCn:%02u SND] close error: %s", cepid, itron_strerror(error));
|
---|
| 260 |
|
---|
| 261 | /* éæ¾ãå®äºããã¾ã§å¾
|
---|
| 262 | ã¤ã*/
|
---|
| 263 | syscall(wai_sem(SEM_TCP_DISCARD_CLI_NBLK_READY));
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | return E_OK;
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | #else /* of #ifdef USE_TCP_NON_BLOCKING */
|
---|
| 270 |
|
---|
| 271 | /*
|
---|
| 272 | * send_tcp_discard -- DISCARD/TCP ãµã¼ãã«ã¡ãã»ã¼ã¸ãéä¿¡ããã
|
---|
| 273 | */
|
---|
| 274 |
|
---|
| 275 | static ER
|
---|
| 276 | send_tcp_discard (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno)
|
---|
| 277 | {
|
---|
| 278 | static char smsg[SND_BUF_SIZE];
|
---|
| 279 | static T_IPEP src = {
|
---|
| 280 | IP_ADDRANY,
|
---|
| 281 | TCP_PORTANY,
|
---|
| 282 | };
|
---|
| 283 |
|
---|
| 284 | T_IPEP dst;
|
---|
| 285 | ER_UINT slen;
|
---|
| 286 | ER error;
|
---|
| 287 | SYSTIM time;
|
---|
| 288 | uint16_t pat, soff, discard, rep, scount, total;
|
---|
| 289 | uint8_t *p;
|
---|
| 290 |
|
---|
| 291 | dst.ipaddr = *ipaddr;
|
---|
| 292 | dst.portno = portno;
|
---|
| 293 |
|
---|
| 294 | p = smsg;
|
---|
| 295 | for (rep = NUM_REP_PAT; rep -- > 0; )
|
---|
| 296 | for (pat = PAT_BEGIN; pat <= PAT_END; pat ++)
|
---|
| 297 | *p ++ = pat;
|
---|
| 298 |
|
---|
| 299 | if ((error = TCP_CON_CEP(cepid, &src, &dst, 60 * 1000)) != E_OK) {
|
---|
| 300 | syslog(LOG_NOTICE, "[TDCn:%02u SND] connect error: %s", cepid, itron_strerror(error));
|
---|
| 301 | return error;
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 | get_tim(&time);
|
---|
| 305 | syslog(LOG_NOTICE, "[TDCn:%02u SND] conct: %7lu, to: %s.%d",
|
---|
| 306 | cepid, time / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
|
---|
| 307 |
|
---|
| 308 | scount = total = 0;
|
---|
| 309 | for (discard = NUM_DISCARD; discard -- > 0; ) {
|
---|
| 310 | soff = 0;
|
---|
| 311 | while (soff < SND_BUF_SIZE) {
|
---|
| 312 | if ((slen = tcp_snd_dat(cepid, smsg + soff, sizeof(smsg) - soff, TMO_FEVR)) < 0) {
|
---|
| 313 | syslog(LOG_NOTICE, "[TDCn:%02u SND] send error: %s", cepid, itron_strerror(slen));
|
---|
| 314 | goto cls_ret;
|
---|
| 315 | }
|
---|
| 316 | soff += (uint16_t)slen;
|
---|
| 317 | total += slen;
|
---|
| 318 | scount ++;
|
---|
| 319 |
|
---|
| 320 | #ifdef SHOW_RCV_RANGE
|
---|
| 321 | syslog(LOG_NOTICE, "[TDCn:%02u SND] send: %7lu, len: %4u, off: %4u",
|
---|
| 322 | cepid, scount, (uint16_t)slen, soff);
|
---|
| 323 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
| 324 |
|
---|
| 325 | syscall(dly_tsk(500 + netapp_rand() % SYSTIM_HZ));
|
---|
| 326 | }
|
---|
| 327 | }
|
---|
| 328 |
|
---|
| 329 | cls_ret:
|
---|
| 330 | get_tim(&time);
|
---|
| 331 | syslog(LOG_NOTICE, "[TDCn:%02u SND] finsh: %7lu, ttl: %lu",
|
---|
| 332 | cepid, time / SYSTIM_HZ, scount, total);
|
---|
| 333 |
|
---|
| 334 | if ((error = tcp_sht_cep(cepid)) < 0)
|
---|
| 335 | syslog(LOG_NOTICE, "[TDCn:%02u SND] shutdown error: %s", cepid, itron_strerror(error));
|
---|
| 336 |
|
---|
| 337 | if ((error = tcp_cls_cep(cepid, TMO_FEVR)) < 0)
|
---|
| 338 | syslog(LOG_NOTICE, "[TDCn:%02u SND] close error: %s", cepid, itron_strerror(error));
|
---|
| 339 |
|
---|
| 340 | return E_OK;
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | #endif /* of #ifdef USE_TCP_NON_BLOCKING */
|
---|
| 344 |
|
---|
| 345 | /*
|
---|
| 346 | * getcomd -- ã³ãã³ããå¾ãã
|
---|
| 347 | */
|
---|
| 348 |
|
---|
| 349 | #ifdef TCP_DISCARD_CLI_AUTO_RUN_STR
|
---|
| 350 |
|
---|
| 351 | static char *
|
---|
| 352 | getcomd (ID cepid, bool_t retry)
|
---|
| 353 | {
|
---|
| 354 | ER error;
|
---|
| 355 | char *line = NULL;
|
---|
| 356 | static char auto_run_str[] = TCP_DISCARD_CLI_AUTO_RUN_STR;
|
---|
| 357 | static int_t count = 0;
|
---|
| 358 |
|
---|
| 359 | if (retry || (count == 0)) {
|
---|
| 360 | line = auto_run_str;
|
---|
| 361 | dly_tsk(3 * 1000);
|
---|
| 362 | }
|
---|
| 363 | else {
|
---|
| 364 | while ((error = rcv_dtq(DTQ_TCP_DISCARD_CLI, (intptr_t*)&line)) != E_OK) {
|
---|
| 365 | syslog(LOG_NOTICE, "[TDCn:%02u TSK] error: %s", cepid, itron_strerror(error));
|
---|
| 366 | dly_tsk(SLP_ITV);
|
---|
| 367 | }
|
---|
| 368 | }
|
---|
| 369 |
|
---|
| 370 | count ++;
|
---|
| 371 | return line;
|
---|
| 372 | }
|
---|
| 373 |
|
---|
| 374 | #else /* of #ifdef TCP_DISCARD_CLI_AUTO_RUN_STR */
|
---|
| 375 |
|
---|
| 376 | static char *
|
---|
| 377 | getcomd (ID cepid, bool_t retry)
|
---|
| 378 | {
|
---|
| 379 | ER error;
|
---|
| 380 | char *line = NULL;
|
---|
| 381 |
|
---|
| 382 | while ((error = rcv_dtq(DTQ_TCP_DISCARD_CLI, (intptr_t*)&line)) != E_OK) {
|
---|
| 383 | syslog(LOG_NOTICE, "[TDCn:%02u TSK] error: %s", cepid, itron_strerror(error));
|
---|
| 384 | dly_tsk(SLP_ITV);
|
---|
| 385 | }
|
---|
| 386 | return line;
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 | #endif /* of #ifdef TCP_DISCARD_CLI_AUTO_RUN_STR */
|
---|
| 390 |
|
---|
| 391 | void
|
---|
| 392 | tcp_discard_cli_task (intptr_t exinf)
|
---|
| 393 | {
|
---|
| 394 | ID tskid, cepid;
|
---|
| 395 | T_IN_ADDR addr;
|
---|
| 396 | ER error;
|
---|
| 397 | uint8_t *line;
|
---|
| 398 | int_t rep, count;
|
---|
| 399 | bool_t retry = false;
|
---|
| 400 | uint16_t portno;
|
---|
| 401 | char apip;
|
---|
| 402 |
|
---|
| 403 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 404 |
|
---|
| 405 | T_TCP_CCEP ccep;
|
---|
| 406 |
|
---|
| 407 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 408 |
|
---|
| 409 | #ifdef TCP_ECHO_CLI_AUTO_RUN_STR
|
---|
| 410 | dly_tsk(START_DLY);
|
---|
| 411 | #endif
|
---|
| 412 | get_tid(&tskid);
|
---|
| 413 |
|
---|
| 414 | #if defined(SUPPORT_INET6)
|
---|
| 415 | apip = API_PROTO_IPV6;
|
---|
| 416 | #if defined(SUPPORT_INET4)
|
---|
| 417 | syslog(LOG_NOTICE, "[TCPn DISCARD CLI:%d,%d] started.", tskid, (ID)exinf);
|
---|
| 418 | #else
|
---|
| 419 | syslog(LOG_NOTICE, "[TCP6 DISCARD CLI:%d,%d] started.", tskid, (ID)exinf);
|
---|
| 420 | #endif
|
---|
| 421 | #else
|
---|
| 422 | apip = API_PROTO_IPV4;
|
---|
| 423 | syslog(LOG_NOTICE, "[TCP4 DISCARD CLI:%d,%d] started.", tskid, (ID)exinf);
|
---|
| 424 | #endif
|
---|
| 425 |
|
---|
| 426 | while (true) {
|
---|
| 427 | line = skip_blanks(getcomd((ID)exinf, retry));
|
---|
| 428 |
|
---|
| 429 | if ((line = lookup_ipaddr(&addr, line, apip)) == NULL) {
|
---|
| 430 | syslog(LOG_NOTICE, "[TDCn:%02u TSK] sleep %d.%03u[s], unknown host.",
|
---|
| 431 | (ID)exinf, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
|
---|
| 432 | dly_tsk(SLP_ITV);
|
---|
| 433 | syslog(LOG_NOTICE, "[TDCn:%02u TSK] resume.", (ID)exinf);
|
---|
| 434 | retry = true;
|
---|
| 435 | continue;
|
---|
| 436 | }
|
---|
| 437 | else
|
---|
| 438 | retry = false;
|
---|
| 439 |
|
---|
| 440 | line = skip_blanks(line);
|
---|
| 441 | if ('0' <= *line && *line <= '9') { /* Port No */
|
---|
| 442 | line = get_int(&rep, line);
|
---|
| 443 | portno = (uint16_t)rep;
|
---|
| 444 | }
|
---|
| 445 | else {
|
---|
| 446 | line ++;
|
---|
| 447 | portno = DISCARD_SRV_PORTNO;
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 | line = skip_blanks(line);
|
---|
| 451 | if ('0' <= *line && *line <= '9') /* Repeat */
|
---|
| 452 | line = get_int(&rep, line);
|
---|
| 453 | else
|
---|
| 454 | rep = 1;
|
---|
| 455 |
|
---|
| 456 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 457 |
|
---|
| 458 | ccep.cepatr = 0;
|
---|
| 459 | ccep.sbufsz = TCP_DISCARD_CLI_SWBUF_SIZE;
|
---|
| 460 | ccep.rbufsz = 0;
|
---|
| 461 | ccep.rbuf = NADR;
|
---|
| 462 |
|
---|
| 463 | #ifdef TCP_CFG_SWBUF_CSAVE
|
---|
| 464 | ccep.sbuf = NADR;
|
---|
| 465 | #else
|
---|
| 466 | ccep.sbuf = tcp_discard_cli_swbuf;
|
---|
| 467 | #endif
|
---|
| 468 | #ifdef USE_TCP_NON_BLOCKING
|
---|
| 469 | ccep.callback = (FP)callback_nblk_tcp_discard_cli;
|
---|
| 470 | #else
|
---|
| 471 | ccep.callback = NULL;
|
---|
| 472 | #endif
|
---|
| 473 |
|
---|
| 474 | if ((error = ALLOC_TCP_CEP(&cepid, tskid, &ccep)) != E_OK) {
|
---|
| 475 | syslog(LOG_NOTICE, "[TDCn:%02u TSK] CEP create error: %s", cepid, itron_strerror(error));
|
---|
| 476 | continue;
|
---|
| 477 | }
|
---|
| 478 |
|
---|
| 479 | #else /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 480 |
|
---|
| 481 | cepid = (ID)exinf;
|
---|
| 482 |
|
---|
| 483 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 484 |
|
---|
| 485 | tcp_discard_cli_valid = true;
|
---|
| 486 | count = 0;
|
---|
| 487 | while (rep == 0 || count < rep) {
|
---|
| 488 | if (!tcp_discard_cli_valid) {
|
---|
| 489 | syslog(LOG_NOTICE, "[TDCn:%02u TSK] canceled.", cepid);
|
---|
| 490 | break;
|
---|
| 491 | }
|
---|
| 492 |
|
---|
| 493 | count ++;
|
---|
| 494 | if (rep == 0) {
|
---|
| 495 | syslog(LOG_NOTICE, "[TDCn:%02u TSK] start: repeat: %d", cepid, count);
|
---|
| 496 | error = send_tcp_discard(cepid, &addr, portno);
|
---|
| 497 | syslog(LOG_NOTICE, "[TDCn:%02u TSK] finsh: repeat: %d", cepid, count);
|
---|
| 498 | }
|
---|
| 499 | else {
|
---|
| 500 | syslog(LOG_NOTICE, "[TDCn:%02u TSK] start: repeat: %d/%d", cepid, count, rep);
|
---|
| 501 | error = send_tcp_discard(cepid, &addr, portno);
|
---|
| 502 | syslog(LOG_NOTICE, "[TDCn:%02u TSK] finsh: repeat: %d/%d", cepid, count, rep);
|
---|
| 503 | }
|
---|
| 504 |
|
---|
| 505 | if (error != E_OK) {
|
---|
| 506 | syslog(LOG_NOTICE, "[TDCn:%02u TSK] sleep %d.%03u[s], error: %s",
|
---|
| 507 | cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ, itron_strerror(error));
|
---|
| 508 | tslp_tsk(SLP_ITV);
|
---|
| 509 | syslog(LOG_NOTICE, "[TDCn:%02u TSK] resume.", cepid);
|
---|
| 510 | }
|
---|
| 511 |
|
---|
| 512 | #if defined(SND_ITV)
|
---|
| 513 | #if SND_ITV > 0
|
---|
| 514 | if (count < rep) {
|
---|
| 515 | uint_t itv;
|
---|
| 516 |
|
---|
| 517 | itv = SND_ITV;
|
---|
| 518 | syslog(LOG_NOTICE, "[TDCn:%02u TSK] interval: %d[s].", cepid, itv / SYSTIM_HZ);
|
---|
| 519 | syscall(dly_tsk(SND_ITV));
|
---|
| 520 | }
|
---|
| 521 | #endif
|
---|
| 522 | #endif
|
---|
| 523 | }
|
---|
| 524 |
|
---|
| 525 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 526 |
|
---|
| 527 | if ((error = FREE_TCP_CEP(cepid)) != E_OK)
|
---|
| 528 | syslog(LOG_NOTICE, "[TDCn:%02u TSK] CEP delete error: %s", cepid, itron_strerror(error));
|
---|
| 529 |
|
---|
| 530 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 531 |
|
---|
| 532 | }
|
---|
| 533 | }
|
---|
| 534 |
|
---|
| 535 | #endif /* of #ifdef USE_TCP_DISCARD_CLI */
|
---|