[388] | 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_echo_srv1.c 388 2019-05-22 11:25:18Z coas-nagasima $
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 | /*
|
---|
| 47 | * TCP ECHO ãµã¼ã #1
|
---|
| 48 | *
|
---|
| 49 | * ã»éåä¿¡ã¿ã¹ã¯åä¸å
|
---|
| 50 | * ã»ãã³ããããã³ã°ã³ã¼ã«
|
---|
| 51 | * ã»çã³ãã¼ API
|
---|
| 52 | * ã»IPv4/IPv6
|
---|
| 53 | * ã»ç·æ¥ãã¼ã¿ã®åä¿¡
|
---|
| 54 | */
|
---|
| 55 |
|
---|
| 56 | #include <string.h>
|
---|
| 57 |
|
---|
| 58 | #ifdef TARGET_KERNEL_ASP
|
---|
| 59 |
|
---|
| 60 | #include <kernel.h>
|
---|
| 61 | #include <sil.h>
|
---|
| 62 | #include <t_syslog.h>
|
---|
| 63 | #include "kernel_cfg.h"
|
---|
| 64 | #include "tinet_cfg.h"
|
---|
| 65 |
|
---|
| 66 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 67 |
|
---|
| 68 | #ifdef TARGET_KERNEL_JSP
|
---|
| 69 |
|
---|
| 70 | #include <t_services.h>
|
---|
| 71 | #include "kernel_id.h"
|
---|
| 72 | #include "tinet_id.h"
|
---|
| 73 |
|
---|
| 74 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
| 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/tcp_echo_srv1.h>
|
---|
| 82 | #include <netapp/tcp_echo_srv1_var.h>
|
---|
| 83 |
|
---|
| 84 | #if defined(_NET_CFG_BYTE_ORDER)
|
---|
| 85 | #error "net/net.h included."
|
---|
| 86 | #endif
|
---|
| 87 |
|
---|
| 88 | #ifdef USE_TCP_ECHO_SRV1
|
---|
| 89 |
|
---|
| 90 | /*
|
---|
| 91 | * 表示
|
---|
| 92 | */
|
---|
| 93 |
|
---|
| 94 | //#define SHOW_RCV_RANGE
|
---|
| 95 |
|
---|
| 96 | /*
|
---|
| 97 | * ã³ãã¯ã·ã§ã³åææ¹æ³ã®æå®
|
---|
| 98 | */
|
---|
| 99 |
|
---|
| 100 | #define USE_TCP_SHT_CEP
|
---|
| 101 |
|
---|
| 102 | /*
|
---|
| 103 | * ã¿ã¤ã ã¢ã¦ã
|
---|
| 104 | */
|
---|
| 105 |
|
---|
| 106 | #ifdef TOPPERS_S810_CLG3_85
|
---|
| 107 |
|
---|
| 108 | #define CLS_TMO TMO_FEVR /* Close Wait ã¯æ¨æºã§ 60ç§ */
|
---|
| 109 | //#define RCV_TMO TMO_FEVR
|
---|
| 110 | #define RCV_TMO (30*SYSTIM_HZ)
|
---|
| 111 | //#define SND_TMO TMO_FEVR
|
---|
| 112 | #define SND_TMO (30*SYSTIM_HZ)
|
---|
| 113 |
|
---|
| 114 | #else /* of #ifdef TOPPERS_S810_CLG3_85 */
|
---|
| 115 |
|
---|
| 116 | //#define CLS_TMO TMO_FEVR /* Close Wait ã¯æ¨æºã§ 60ç§ */
|
---|
| 117 | #define CLS_TMO (70*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*10)
|
---|
| 118 | //#define RCV_TMO TMO_FEVR
|
---|
| 119 | #define RCV_TMO (30*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*30)
|
---|
| 120 | //#define SND_TMO TMO_FEVR
|
---|
| 121 | #define SND_TMO (40*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*20)
|
---|
| 122 |
|
---|
| 123 | #endif /* of #ifdef TOPPERS_S810_CLG3_85 */
|
---|
| 124 |
|
---|
| 125 | /*
|
---|
| 126 | * å
|
---|
| 127 | ¨åå¤æ°
|
---|
| 128 | */
|
---|
| 129 |
|
---|
| 130 | /* TCP éåä¿¡ã¦ã£ã³ããããã¡ */
|
---|
| 131 |
|
---|
| 132 | #ifndef TCP_CFG_SWBUF_CSAVE
|
---|
| 133 | uint8_t tcp_echo_srv_swbuf[NUM_TCP_ECHO_SRV_TASKS][TCP_ECHO_SRV_SWBUF_SIZE];
|
---|
| 134 | #endif
|
---|
| 135 |
|
---|
| 136 | #ifndef TCP_CFG_RWBUF_CSAVE
|
---|
| 137 | uint8_t tcp_echo_srv_rwbuf[NUM_TCP_ECHO_SRV_TASKS][TCP_ECHO_SRV_RWBUF_SIZE];
|
---|
| 138 | #endif
|
---|
| 139 |
|
---|
| 140 | #ifndef USE_TCP_NON_BLOCKING
|
---|
| 141 |
|
---|
| 142 | /*
|
---|
| 143 | * å¤æ°
|
---|
| 144 | */
|
---|
| 145 |
|
---|
| 146 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 147 |
|
---|
| 148 | T_TCP_ECHO_SRV_INFO tcp_echo_srv_info[NUM_TCP_ECHO_SRV_TASKS];
|
---|
| 149 |
|
---|
| 150 | #else /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 151 |
|
---|
| 152 | T_TCP_ECHO_SRV_INFO tcp_echo_srv_info[] = {
|
---|
| 153 |
|
---|
| 154 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV)
|
---|
| 155 |
|
---|
| 156 | { TCP4_ECHO_SRV_CEPID1, TCP4_ECHO_SRV_REPID },
|
---|
| 157 |
|
---|
| 158 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
|
---|
| 159 |
|
---|
| 160 | { TCP_ECHO_SRV_CEPID1, TCP_ECHO_SRV_REPID },
|
---|
| 161 |
|
---|
| 162 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
|
---|
| 163 |
|
---|
| 164 | #if NUM_TCP_ECHO_SRV_TASKS >= 2
|
---|
| 165 | { TCP_ECHO_SRV_CEPID2, TCP_ECHO_SRV_REPID },
|
---|
| 166 | #endif
|
---|
| 167 | #if NUM_TCP_ECHO_SRV_TASKS >= 3
|
---|
| 168 | { TCP_ECHO_SRV_CEPID3, TCP_ECHO_SRV_REPID },
|
---|
| 169 | #endif
|
---|
| 170 | #if NUM_TCP_ECHO_SRV_TASKS >= 4
|
---|
| 171 | { TCP_ECHO_SRV_CEPID4, TCP_ECHO_SRV_REPID },
|
---|
| 172 | #endif
|
---|
| 173 | #if NUM_TCP_ECHO_SRV_TASKS >= 5
|
---|
| 174 | { TCP_ECHO_SRV_CEPID5, TCP_ECHO_SRV_REPID },
|
---|
| 175 | #endif
|
---|
| 176 | #if NUM_TCP_ECHO_SRV_TASKS >= 6
|
---|
| 177 | { TCP_ECHO_SRV_CEPID6, TCP_ECHO_SRV_REPID },
|
---|
| 178 | #endif
|
---|
| 179 | #if NUM_TCP_ECHO_SRV_TASKS >= 7
|
---|
| 180 | { TCP_ECHO_SRV_CEPID7, TCP_ECHO_SRV_REPID },
|
---|
| 181 | #endif
|
---|
| 182 | #if NUM_TCP_ECHO_SRV_TASKS >= 8
|
---|
| 183 | { TCP_ECHO_SRV_CEPID8, TCP_ECHO_SRV_REPID },
|
---|
| 184 | #endif
|
---|
| 185 |
|
---|
| 186 | };
|
---|
| 187 |
|
---|
| 188 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 189 |
|
---|
| 190 | /*
|
---|
| 191 | * tcp_passive_open -- ååãªã¼ãã³ãå®è¡ããã
|
---|
| 192 | *
|
---|
| 193 | * USE_TCP_NON_BLOCKING OFF
|
---|
| 194 | */
|
---|
| 195 |
|
---|
| 196 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
| 197 |
|
---|
| 198 | static ER
|
---|
| 199 | tcp_passive_open (T_TCP_ECHO_SRV_INFO *info, char apip)
|
---|
| 200 | {
|
---|
| 201 | ER error = E_OK;
|
---|
| 202 |
|
---|
| 203 | #if TNUM_TCP4_REPID > 0
|
---|
| 204 | T_IPV4EP dst4;
|
---|
| 205 | #endif
|
---|
| 206 |
|
---|
| 207 | if (apip == API_PROTO_IPV6) {
|
---|
| 208 |
|
---|
| 209 | #if TNUM_TCP6_REPID > 0
|
---|
| 210 |
|
---|
| 211 | /* åä»å£ã¯ IPv6 */
|
---|
| 212 | if ((error = tcp6_acp_cep(info->cepid, info->repid, &info->dst, TMO_FEVR)) != E_OK)
|
---|
| 213 | return error;
|
---|
| 214 |
|
---|
| 215 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 216 | if ((error = free_tcp6_rep(info->repid, true)) != E_OK)
|
---|
| 217 | return error;
|
---|
| 218 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 219 |
|
---|
| 220 | #endif /* of #if TNUM_TCP6_REPID > 0 */
|
---|
| 221 |
|
---|
| 222 | }
|
---|
| 223 | else {
|
---|
| 224 |
|
---|
| 225 | #if TNUM_TCP4_REPID > 0
|
---|
| 226 |
|
---|
| 227 | /* åä»å£ã¯ IPv4 */
|
---|
| 228 | if ((error = tcp_acp_cep(info->cepid, info->repid, &dst4, TMO_FEVR)) != E_OK)
|
---|
| 229 | return error;
|
---|
| 230 | in6_make_ipv4mapped (&info->dst.ipaddr, dst4.ipaddr);
|
---|
| 231 | info->dst.portno = dst4.portno;
|
---|
| 232 |
|
---|
| 233 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 234 | if ((error = free_tcp4_rep(info->repid, true)) != E_OK)
|
---|
| 235 | return error;
|
---|
| 236 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 237 |
|
---|
| 238 | #endif /* of #if TNUM_TCP4_REPID > 0 */
|
---|
| 239 |
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | return error;
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 246 |
|
---|
| 247 | /*
|
---|
| 248 | * tcp_passive_open -- ååãªã¼ãã³ãå®è¡ããã
|
---|
| 249 | *
|
---|
| 250 | * USE_TCP_NON_BLOCKING OFF
|
---|
| 251 | */
|
---|
| 252 |
|
---|
| 253 | static ER
|
---|
| 254 | tcp_passive_open (T_TCP_ECHO_SRV_INFO *info, char apip)
|
---|
| 255 | {
|
---|
| 256 | ER error = E_OK;
|
---|
| 257 |
|
---|
| 258 | if ((error = TCP_ACP_CEP(info->cepid, info->repid, &info->dst, TMO_FEVR)) != E_OK)
|
---|
| 259 | return error;
|
---|
| 260 |
|
---|
| 261 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 262 | if ((error = FREE_TCP_REP(info->repid, true)) != E_OK)
|
---|
| 263 | return error;
|
---|
| 264 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 265 |
|
---|
| 266 | return error;
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 270 |
|
---|
| 271 | #ifdef USE_COPYSAVE_API
|
---|
| 272 |
|
---|
| 273 | /*
|
---|
| 274 | * tcp_echo_srv -- TCP ã¨ã³ã¼ãµã¼ã
|
---|
| 275 | *
|
---|
| 276 | * USE_TCP_NON_BLOCKING OFF
|
---|
| 277 | * USE_COPYSAVE_API ON
|
---|
| 278 | */
|
---|
| 279 |
|
---|
| 280 | ER
|
---|
| 281 | tcp_echo_srv (uint_t six, char apip)
|
---|
| 282 | {
|
---|
| 283 | ER error = E_OK;
|
---|
| 284 | ER_UINT rblen, sblen;
|
---|
| 285 | SYSTIM now;
|
---|
| 286 | uint32_t total;
|
---|
| 287 | uint16_t rlen, slen, soff, scount, rcount;
|
---|
| 288 | char *rbuf, *sbuf;
|
---|
| 289 |
|
---|
| 290 | #ifdef SHOW_RCV_RANGE
|
---|
| 291 | char head, tail;
|
---|
| 292 | #endif
|
---|
| 293 |
|
---|
| 294 | if ((error = tcp_passive_open(&tcp_echo_srv_info[six], apip)) != E_OK) {
|
---|
| 295 | syslog(LOG_NOTICE, "[TES%c:%02u OPN] error: %s",
|
---|
| 296 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
| 297 | return error;
|
---|
| 298 | }
|
---|
| 299 |
|
---|
| 300 | syscall(get_tim(&now));
|
---|
| 301 |
|
---|
| 302 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
| 303 |
|
---|
| 304 | if (apip == API_PROTO_IPV6)
|
---|
| 305 | syslog(LOG_NOTICE, "[TES6:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
| 306 | tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
| 307 | ipv62str(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
|
---|
| 308 | tcp_echo_srv_info[six].dst.portno);
|
---|
| 309 | else {
|
---|
| 310 | T_IN4_ADDR addr;
|
---|
| 311 |
|
---|
| 312 | addr = ntohl(tcp_echo_srv_info[six].dst.ipaddr.s6_addr32[3]);
|
---|
| 313 | syslog(LOG_NOTICE, "[TES4:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
| 314 | tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
| 315 | ip2str(NULL, &addr), tcp_echo_srv_info[six].dst.portno);
|
---|
| 316 | }
|
---|
| 317 |
|
---|
| 318 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 319 |
|
---|
| 320 | syslog(LOG_NOTICE, "[TES%c:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
| 321 | apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
| 322 | IP2STR(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
|
---|
| 323 | tcp_echo_srv_info[six].dst.portno);
|
---|
| 324 |
|
---|
| 325 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 326 |
|
---|
| 327 | scount = rcount = total = 0;
|
---|
| 328 | while (true) {
|
---|
| 329 | if ((rblen = tcp_rcv_buf(tcp_echo_srv_info[six].cepid, (void**)&rbuf, RCV_TMO)) <= 0) {
|
---|
| 330 | if (rblen != E_OK)
|
---|
| 331 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] error: %s",
|
---|
| 332 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(rblen));
|
---|
| 333 | break;
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 | rcount ++;
|
---|
| 337 |
|
---|
| 338 | #ifdef SHOW_RCV_RANGE
|
---|
| 339 | head = *rbuf;
|
---|
| 340 | tail = *(rbuf + rblen - 1);
|
---|
| 341 |
|
---|
| 342 | //syslog(LOG_NOTICE, "[TES%c:%02u RCV] len: %7lu",
|
---|
| 343 | // apip, tcp_echo_srv_info[six].cepid, (uint16_t)rblen);
|
---|
| 344 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] rcount: %7lu, len: %6lu, data %02x -> %02x",
|
---|
| 345 | apip, tcp_echo_srv_info[six].cepid, rcount, (uint16_t)rblen, head, tail);
|
---|
| 346 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
| 347 |
|
---|
| 348 | rlen = (uint16_t)rblen;
|
---|
| 349 | total += rblen;
|
---|
| 350 | soff = 0;
|
---|
| 351 | while (rlen > 0) {
|
---|
| 352 |
|
---|
| 353 | if ((sblen = tcp_get_buf(tcp_echo_srv_info[six].cepid, (void**)&sbuf, SND_TMO)) < 0) {
|
---|
| 354 | syslog(LOG_NOTICE, "[TES%c:%02u GET] error: %s",
|
---|
| 355 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(sblen));
|
---|
| 356 | goto err_fin;
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 | //syslog(LOG_NOTICE, "[TES%c:%02u SND] len: %7lu",
|
---|
| 360 | // apip, tcp_echo_srv_info[six].cepid, (uint16_t)sblen);
|
---|
| 361 | scount ++;
|
---|
| 362 | slen = rlen < (uint16_t)sblen ? rlen : (uint16_t)sblen;
|
---|
| 363 | memcpy(sbuf, rbuf + soff, slen);
|
---|
| 364 | if ((error = tcp_snd_buf(tcp_echo_srv_info[six].cepid, slen)) != E_OK) {
|
---|
| 365 | syslog(LOG_NOTICE, "[TES%c:%02u SND] error: %s",
|
---|
| 366 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
| 367 | goto err_fin;
|
---|
| 368 | }
|
---|
| 369 | #ifdef SHOW_RCV_RANGE
|
---|
| 370 | syslog(LOG_NOTICE, "[TES%c:%02u SND] scount: %4u, len: %4u",
|
---|
| 371 | apip, tcp_echo_srv_info[six].cepid, scount, slen);
|
---|
| 372 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
| 373 |
|
---|
| 374 | rlen -= slen;
|
---|
| 375 | soff += slen;
|
---|
| 376 | }
|
---|
| 377 |
|
---|
| 378 | if ((error = tcp_rel_buf(tcp_echo_srv_info[six].cepid, rblen)) < 0) {
|
---|
| 379 | syslog(LOG_NOTICE, "[TES%c:%02u REL] error: %s",
|
---|
| 380 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
| 381 | break;
|
---|
| 382 | }
|
---|
| 383 | }
|
---|
| 384 | err_fin:
|
---|
| 385 |
|
---|
| 386 | #ifdef USE_TCP_SHT_CEP
|
---|
| 387 | if ((error = tcp_sht_cep(tcp_echo_srv_info[six].cepid)) != E_OK)
|
---|
| 388 | syslog(LOG_NOTICE, "[TES%c:%02u SHT] error: %s",
|
---|
| 389 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
| 390 | #endif /* of #ifdef USE_TCP_SHT_CEP */
|
---|
| 391 |
|
---|
| 392 | if ((error = tcp_cls_cep(tcp_echo_srv_info[six].cepid, CLS_TMO)) != E_OK)
|
---|
| 393 | syslog(LOG_NOTICE, "[TES%c:%02u CLS] error: %s",
|
---|
| 394 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
| 395 |
|
---|
| 396 | syscall(get_tim(&now));
|
---|
| 397 | #if 1
|
---|
| 398 | syslog(LOG_NOTICE, "[TES%c:%02u FIN] finsh: %7lu, ttl: %lu",
|
---|
| 399 | apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ, total);
|
---|
| 400 | #else
|
---|
| 401 | syslog(LOG_NOTICE, "[TES%c:%02u FIN] finsh: %7lu, ttl: %lu, error: %s",
|
---|
| 402 | apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ, total, itron_strerror(error));
|
---|
| 403 | #endif
|
---|
| 404 |
|
---|
| 405 | return error;
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 | #else /* of #ifdef USE_COPYSAVE_API */
|
---|
| 409 |
|
---|
| 410 | /*
|
---|
| 411 | * tcp_echo_srv -- TCP ã¨ã³ã¼ãµã¼ã
|
---|
| 412 | *
|
---|
| 413 | * USE_TCP_NON_BLOCKING OFF
|
---|
| 414 | * USE_COPYSAVE_API OFF
|
---|
| 415 | */
|
---|
| 416 |
|
---|
| 417 | ER
|
---|
| 418 | tcp_echo_srv (uint_t six, char apip)
|
---|
| 419 | {
|
---|
| 420 | ID cepid;
|
---|
| 421 | ER error = E_OK;
|
---|
| 422 | ER_UINT rlen, slen;
|
---|
| 423 | SYSTIM now;
|
---|
| 424 | uint32_t total;
|
---|
| 425 | uint16_t soff, scount, rcount;
|
---|
| 426 |
|
---|
| 427 | if ((error = tcp_passive_open(&tcp_echo_srv_info[six], apip)) != E_OK) {
|
---|
| 428 | syslog(LOG_NOTICE, "[TES%c:%02u OPN] error: %s",
|
---|
| 429 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
| 430 | return error;
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | syscall(get_tim(&now));
|
---|
| 434 |
|
---|
| 435 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
| 436 |
|
---|
| 437 | if (apip == API_PROTO_IPV6)
|
---|
| 438 | syslog(LOG_NOTICE, "[TES6:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
| 439 | tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
| 440 | ipv62str(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
|
---|
| 441 | tcp_echo_srv_info[six].dst.portno);
|
---|
| 442 | else {
|
---|
| 443 | T_IN4_ADDR addr;
|
---|
| 444 |
|
---|
| 445 | addr = ntohl(tcp_echo_srv_info[six].dst.ipaddr.s6_addr32[3]);
|
---|
| 446 | syslog(LOG_NOTICE, "[TES4:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
| 447 | tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
| 448 | ip2str(NULL, &addr), tcp_echo_srv_info[six].dst.portno);
|
---|
| 449 | }
|
---|
| 450 |
|
---|
| 451 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 452 |
|
---|
| 453 | syslog(LOG_NOTICE, "[TES%c:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
| 454 | apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
| 455 | IP2STR(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
|
---|
| 456 | tcp_echo_srv_info[six].dst.portno);
|
---|
| 457 |
|
---|
| 458 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 459 |
|
---|
| 460 | cepid = tcp_echo_srv_info[six].cepid;
|
---|
| 461 | scount = rcount = total = 0;
|
---|
| 462 | while (true) {
|
---|
| 463 | if ((rlen = tcp_rcv_dat(cepid, tcp_echo_srv_info[six].buffer, BUF_SIZE - 1, RCV_TMO)) <= 0) {
|
---|
| 464 | if (rlen != E_OK)
|
---|
| 465 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] error: %s",
|
---|
| 466 | apip, cepid, itron_strerror(rlen));
|
---|
| 467 | break;
|
---|
| 468 | }
|
---|
| 469 |
|
---|
| 470 | rcount ++;
|
---|
| 471 | #ifdef SHOW_RCV_RANGE
|
---|
| 472 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] rcount: %4u, len: %4u, data %02x -> %02x",
|
---|
| 473 | apip, cepid, rcount,
|
---|
| 474 | (uint16_t)rlen, * tcp_echo_srv_info[six].tcp_echo_srv_info[six].buffer,
|
---|
| 475 | *(tcp_echo_srv_info[six].tcp_echo_srv_info[six].buffer + rlen - 1));
|
---|
| 476 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
| 477 |
|
---|
| 478 | total += rlen;
|
---|
| 479 | soff = 0;
|
---|
| 480 | while (rlen > 0) {
|
---|
| 481 | scount ++;
|
---|
| 482 | if ((slen = tcp_snd_dat(cepid, &tcp_echo_srv_info[six].buffer[soff], rlen, SND_TMO)) < 0) {
|
---|
| 483 | syslog(LOG_NOTICE, "[TES%c:%02u SND] error: %s",
|
---|
| 484 | apip, cepid, itron_strerror(slen));
|
---|
| 485 | goto err_fin;
|
---|
| 486 | }
|
---|
| 487 | #ifdef SHOW_RCV_RANGE
|
---|
| 488 | syslog(LOG_NOTICE, "[TES%c:%02u SND] scount: %4u, len: %4u",
|
---|
| 489 | apip, cepid, scount, (uint16_t)slen);
|
---|
| 490 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
| 491 |
|
---|
| 492 | rlen -= slen;
|
---|
| 493 | soff += slen;
|
---|
| 494 | }
|
---|
| 495 | }
|
---|
| 496 | err_fin:
|
---|
| 497 |
|
---|
| 498 | #ifdef USE_TCP_SHT_CEP
|
---|
| 499 | if ((error = tcp_sht_cep(cepid)) != E_OK)
|
---|
| 500 | syslog(LOG_NOTICE, "[TES%c:%02u SHT] error: %s",
|
---|
| 501 | apip, cepid, itron_strerror(error));
|
---|
| 502 | #endif /* of #ifdef USE_TCP_SHT_CEP */
|
---|
| 503 |
|
---|
| 504 | if ((error = tcp_cls_cep(cepid, CLS_TMO)) != E_OK)
|
---|
| 505 | syslog(LOG_NOTICE, "[TES%c:%02u CLS] error: %s",
|
---|
| 506 | apip, cepid, itron_strerror(error));
|
---|
| 507 |
|
---|
| 508 | syscall(get_tim(&now));
|
---|
| 509 | syslog(LOG_NOTICE, "[TES%c:%02u FIN] finsh: %7lu, ttl: %lu",
|
---|
| 510 | apip, cepid, now / SYSTIM_HZ, total);
|
---|
| 511 |
|
---|
| 512 | return error;
|
---|
| 513 | }
|
---|
| 514 |
|
---|
| 515 | #endif /* of #ifdef USE_COPYSAVE_API */
|
---|
| 516 |
|
---|
| 517 | #endif /* of #ifndef USE_TCP_NON_BLOCKING */
|
---|
| 518 |
|
---|
| 519 | #ifndef USE_TCP_EXTENTIONS
|
---|
| 520 |
|
---|
| 521 | /*
|
---|
| 522 | * tcp_echo_srv_task -- TCP ã¨ã³ã¼ãµã¼ãã¿ã¹ã¯
|
---|
| 523 | */
|
---|
| 524 |
|
---|
| 525 | void
|
---|
| 526 | tcp_echo_srv_task(intptr_t exinf)
|
---|
| 527 | {
|
---|
| 528 | ID tskid, cepid;
|
---|
| 529 | ER error;
|
---|
| 530 | uint_t six;
|
---|
| 531 | char apip;
|
---|
| 532 |
|
---|
| 533 | six = INDEX_SRV_INFO((ID)exinf);
|
---|
| 534 |
|
---|
| 535 | #if defined(SUPPORT_INET6)
|
---|
| 536 |
|
---|
| 537 | #if defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV)
|
---|
| 538 |
|
---|
| 539 | if (six >= NUM_TCP4_ECHO_SRV_TASKS)
|
---|
| 540 | apip = API_PROTO_IPV6;
|
---|
| 541 | else
|
---|
| 542 | apip = API_PROTO_IPV4;
|
---|
| 543 |
|
---|
| 544 | #else /* of #if defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
|
---|
| 545 |
|
---|
| 546 | apip = API_PROTO_IPV6;
|
---|
| 547 |
|
---|
| 548 | #endif /* of #if defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
|
---|
| 549 |
|
---|
| 550 | #else /* of #if defined(SUPPORT_INET6) */
|
---|
| 551 |
|
---|
| 552 | apip = API_PROTO_IPV4;
|
---|
| 553 |
|
---|
| 554 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
| 555 |
|
---|
| 556 | syscall(get_tid(&tskid));
|
---|
| 557 | cepid = tcp_echo_srv_info[six].cepid;
|
---|
| 558 | syslog(LOG_NOTICE, "[TCP%c ECHO SRV:%d,%d] started.", apip, tskid, cepid);
|
---|
| 559 |
|
---|
| 560 | while (true) {
|
---|
| 561 | while ((error = tcp_echo_srv(six, apip)) == E_OK)
|
---|
| 562 | ;
|
---|
| 563 | syslog(LOG_NOTICE, "[TES%c:%02u TSK] sleep 60[s], error: %s", apip, cepid, itron_strerror(error));
|
---|
| 564 | tslp_tsk(60 * 1000 * 1000);
|
---|
| 565 | syslog(LOG_NOTICE, "[TES%c:%02u TSK] resume.", apip, cepid);
|
---|
| 566 | }
|
---|
| 567 | }
|
---|
| 568 |
|
---|
| 569 | #endif /* of #ifndef USE_TCP_EXTENTIONS */
|
---|
| 570 |
|
---|
| 571 | #endif /* of #ifdef USE_TCP_ECHO_SRV1 */
|
---|