Ignore:
Timestamp:
Jan 21, 2018, 12:10:09 AM (6 years ago)
Author:
coas-nagasima
Message:

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

File:
1 edited

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/asp3_dcre/tinet/netapp/tcp_discard_cli.c

    r321 r331  
    22 *  TINET (TCP/IP Protocol Stack)
    33 *
    4  *  Copyright (C) 2001-2009 by Dep. of Computer Science and Engineering
     4 *  Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
    55 *                   Tomakomai National College of Technology, JAPAN
    66 *
     
    5858#endif  /* of #ifdef TARGET_KERNEL_JSP */
    5959
    60 #include <tinet_defs.h>
    61 #include <tinet_config.h>
    62 
    63 #include <net/if.h>
    64 #include <net/if_ppp.h>
    65 #include <net/if_loop.h>
    66 #include <net/ethernet.h>
    67 #include <net/net.h>
    68 #include <net/net_var.h>
    69 #include <net/net_timer.h>
    70 
    7160#include <netinet/in.h>
    7261#include <netinet/in_itron.h>
    73 #include <netinet/ip.h>
    74 #include <netinet/ip6.h>
    75 #include <netinet/tcp.h>
    7662
    7763#include <netapp/netapp.h>
    7864#include <netapp/netapp_var.h>
    79 #include <netapp/discard.h>
     65#include <netapp/tcp_discard_cli.h>
    8066
    8167#ifdef USE_TCP_DISCARD_CLI
     
    8874
    8975/*#define SHOW_RCV_RANGE*/
     76
     77/* 送信間隔 */
     78
     79#ifdef TOPPERS_S810_CLG3_85
     80
     81#define START_DLY       (10*SYSTIM_HZ)
     82#define SND_ITV         (5*SYSTIM_HZ)
     83#define SLP_ITV         (30*SYSTIM_HZ)
     84
     85#else   /* of #ifdef TOPPERS_S810_CLG3_85 */
     86
     87#define START_DLY       (10*SYSTIM_HZ)
     88#define SND_ITV         (5*SYSTIM_HZ)
     89#define SLP_ITV         (60*SYSTIM_HZ)
     90
     91#endif  /* of #ifdef TOPPERS_S810_CLG3_85 */
     92
     93/* 自動実行 */
     94
     95#if defined(TCP_DISCARD_CLI_AUTO_RUN_STR)
     96#else
     97#if 0
     98#if defined(SUPPORT_INET6)
     99#define TCP_DISCARD_CLI_AUTO_RUN_STR    "fd90:cce5:25f6:ff81:201:2ff:fe81:e7c9 - 0"
     100#else
     101#define TCP_DISCARD_CLI_AUTO_RUN_STR    "172.25.129.142 - 0"
     102#endif
     103#endif
     104#endif
    90105
    91106/*
     
    143158        case TFN_TCP_CLS_CEP:
    144159                if (nblk_error < 0)
    145                         syslog(LOG_NOTICE, "[TDC:%02d CBN] close error: %s", cepid, itron_strerror(nblk_error));
     160                        syslog(LOG_NOTICE, "[TDCn:%02u CBN] close error: %s", cepid, itron_strerror(nblk_error));
    146161                syscall(sig_sem(SEM_TCP_DISCARD_CLI_NBLK_READY));
    147162                break;
     
    162177 */
    163178
    164 static void
     179static ER
    165180send_tcp_discard (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno)
    166181{
     
    183198
    184199        if ((error = TCP_CON_CEP(cepid, &nblk_src, &nblk_dst, TMO_NBLK)) != E_WBLK) {
    185                 syslog(LOG_NOTICE, "[TDC:%02d SND] connect error: %s", cepid, itron_strerror(error));
    186                 return;
     200                syslog(LOG_NOTICE, "[TDCn:%02u SND] connect error: %s", cepid, itron_strerror(error));
     201                return error;
    187202                }
    188203
     
    191206
    192207        if (nblk_error != E_OK)
    193                 syslog(LOG_NOTICE, "[TDC:%02d SND] connect error: %s", cepid, itron_strerror(nblk_error));
     208                syslog(LOG_NOTICE, "[TDCn:%02u SND] connect error: %s", cepid, itron_strerror(nblk_error));
    194209        else {
    195210                get_tim(&time);
    196                 syslog(LOG_NOTICE, "[TDC:%02d SND] connecting: %6ld, to:   %s.%d",
     211                syslog(LOG_NOTICE, "[TDCn:%02u SND] conct: %7lu, to:   %s.%d",
    197212                                   cepid, time / SYSTIM_HZ, IP2STR(NULL, ipaddr), nblk_dst.portno);
    198213
     
    202217                        while (soff < SND_BUF_SIZE) {
    203218                                if ((slen = tcp_snd_dat(cepid, smsg + soff, sizeof(smsg) - soff, TMO_FEVR)) < 0) {
    204                                         syslog(LOG_NOTICE, "[TDC:%02d SND] send error: %s",
     219                                        syslog(LOG_NOTICE, "[TDCn:%02u SND] send error: %s",
    205220                                                           cepid, itron_strerror(slen));
    206221                                        goto cls_ret;
     
    211226
    212227#ifdef SHOW_RCV_RANGE
    213                                 syslog(LOG_NOTICE, "[TDC:%02d SND] snd: %2d, len: %4d, off: %4d",
     228                                syslog(LOG_NOTICE, "[TDCn:%02u SND] send:  %7lu, len: %4u, off: %4u",
    214229                                                   cepid, scount, (uint16_t)slen, soff);
    215230#endif  /* of #ifdef SHOW_RCV_RANGE */
    216231
    217                                 syscall(dly_tsk(500 + net_rand() % SYSTIM_HZ));
     232                                syscall(dly_tsk(500 + netapp_rand() % SYSTIM_HZ));
    218233                                }
    219234                        }
     
    221236        cls_ret:
    222237                get_tim(&time);
    223                 syslog(LOG_NOTICE, "[TDC:%02d SND] finished:   %6ld, snd: %4d,            len: %ld",
     238                syslog(LOG_NOTICE, "[TDCn:%02u SND] finsh: %7lu, ttl: %lu",
    224239                                   cepid, time / SYSTIM_HZ, scount, total);
    225240
    226241                if ((error = tcp_sht_cep(cepid)) < 0)
    227                         syslog(LOG_NOTICE, "[TDC:%02d SND] shutdown error: %s", cepid, itron_strerror(error));
     242                        syslog(LOG_NOTICE, "[TDCn:%02u SND] shutdown error: %s", cepid, itron_strerror(error));
    228243
    229244                if ((error = tcp_cls_cep(cepid, TMO_NBLK)) != E_WBLK)
    230                         syslog(LOG_NOTICE, "[TDC:%02d SND] close error: %s", cepid, itron_strerror(error));
     245                        syslog(LOG_NOTICE, "[TDCn:%02u SND] close error: %s", cepid, itron_strerror(error));
    231246
    232247                /* 開放が完了するまで待つ。*/
    233248                syscall(wai_sem(SEM_TCP_DISCARD_CLI_NBLK_READY));
    234249                }
     250
     251        return E_OK;
    235252        }
    236253
     
    241258 */
    242259
    243 static void
     260static ER
    244261send_tcp_discard (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno)
    245262{
     
    266283
    267284        if ((error = TCP_CON_CEP(cepid, &src, &dst, 60 * 1000)) != E_OK) {
    268                 syslog(LOG_NOTICE, "[TDC:%02d SND] connect error: %s", cepid, itron_strerror(error));
    269                 return;
     285                syslog(LOG_NOTICE, "[TDCn:%02u SND] connect error: %s", cepid, itron_strerror(error));
     286                return error;
    270287                }
    271288
    272289        get_tim(&time);
    273         syslog(LOG_NOTICE, "[TDC:%02d SND] connecting: %6ld, to:   %s.%d",
     290        syslog(LOG_NOTICE, "[TDCn:%02u SND] conct: %7lu, to:   %s.%d",
    274291                           cepid, time / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
    275292
     
    279296                while (soff < SND_BUF_SIZE) {
    280297                        if ((slen = tcp_snd_dat(cepid, smsg + soff, sizeof(smsg) - soff, TMO_FEVR)) < 0) {
    281                                 syslog(LOG_NOTICE, "[TDC:%02d SND] send error: %s", cepid, itron_strerror(slen));
     298                                syslog(LOG_NOTICE, "[TDCn:%02u SND] send error: %s", cepid, itron_strerror(slen));
    282299                                goto cls_ret;
    283300                                }
     
    287304
    288305#ifdef SHOW_RCV_RANGE
    289                         syslog(LOG_NOTICE, "[TDC:%02d SND] snd: %3d, len: %4d, off: %4d",
     306                        syslog(LOG_NOTICE, "[TDCn:%02u SND] send:  %7lu, len: %4u, off: %4u",
    290307                                           cepid, scount, (uint16_t)slen, soff);
    291308#endif  /* of #ifdef SHOW_RCV_RANGE */
    292309
    293                         syscall(dly_tsk(500 + net_rand() % SYSTIM_HZ));
     310                        syscall(dly_tsk(500 + netapp_rand() % SYSTIM_HZ));
    294311                        }
    295312                }
     
    297314cls_ret:
    298315        get_tim(&time);
    299         syslog(LOG_NOTICE, "[TDC:%02d SND] finished:   %6ld, snd: %4d,            len: %ld",
     316        syslog(LOG_NOTICE, "[TDCn:%02u SND] finsh: %7lu, ttl: %lu",
    300317                           cepid, time / SYSTIM_HZ, scount, total);
    301318
    302319        if ((error = tcp_sht_cep(cepid)) < 0)
    303                 syslog(LOG_NOTICE, "[TDC:%02d SND] shutdown error: %s", cepid, itron_strerror(error));
     320                syslog(LOG_NOTICE, "[TDCn:%02u SND] shutdown error: %s", cepid, itron_strerror(error));
    304321
    305322        if ((error = tcp_cls_cep(cepid, TMO_FEVR)) < 0)
    306                 syslog(LOG_NOTICE, "[TDC:%02d SND] close error: %s", cepid, itron_strerror(error));
     323                syslog(LOG_NOTICE, "[TDCn:%02u SND] close error: %s", cepid, itron_strerror(error));
     324
     325        return E_OK;
    307326        }
    308327
    309328#endif  /* of #ifdef USE_TCP_NON_BLOCKING */
     329
     330/*
     331 *  getcomd -- コマンドを得る。
     332 */
     333
     334#ifdef TCP_DISCARD_CLI_AUTO_RUN_STR
     335
     336static char *
     337getcomd (ID cepid, bool_t retry)
     338{
     339        ER              error;
     340        char            *line = NULL;
     341        static char     auto_run_str[] = TCP_DISCARD_CLI_AUTO_RUN_STR;
     342        static int_t    count = 0;
     343
     344        if (retry || (count == 0)) {
     345                line = auto_run_str;
     346                dly_tsk(3 * 1000);
     347                }
     348        else {
     349                while ((error = rcv_dtq(DTQ_TCP_DISCARD_CLI, (intptr_t*)&line)) != E_OK) {
     350                        syslog(LOG_NOTICE, "[TDCn:%02u TSK] error: %s", cepid, itron_strerror(error));
     351                        dly_tsk(SLP_ITV);
     352                        }
     353                }
     354
     355        count ++;
     356        return line;
     357        }
     358
     359#else   /* of #ifdef TCP_DISCARD_CLI_AUTO_RUN_STR */
     360
     361static char *
     362getcomd (ID cepid, bool_t retry)
     363{
     364        ER      error;
     365        char    *line = NULL;
     366
     367        while ((error = rcv_dtq(DTQ_TCP_DISCARD_CLI, (intptr_t*)&line)) != E_OK) {
     368                syslog(LOG_NOTICE, "[TDCn:%02u TSK] error: %s", cepid, itron_strerror(error));
     369                dly_tsk(SLP_ITV);
     370                }
     371        return line;
     372        }
     373
     374#endif  /* of #ifdef TCP_DISCARD_CLI_AUTO_RUN_STR */
    310375
    311376void
    312377tcp_discard_cli_task (intptr_t exinf)
    313378{
     379        ID              tskid, cepid;
    314380        T_IN_ADDR       addr;
    315         ID              tskid, cepid;
    316         int_t           rep;
    317         uint32_t        count;
     381        ER              error;
     382        uint8_t         *line;
     383        int_t           rep, count;
     384        bool_t          retry = false;
    318385        uint16_t        portno;
    319         uint8_t         *line;
     386        char            apip;
    320387
    321388#ifdef USE_TCP_EXTENTIONS
    322389
    323         ER              error;
    324390        T_TCP_CCEP      ccep;
    325391
    326392#endif  /* of #ifdef USE_TCP_EXTENTIONS */
    327393
     394#ifdef TCP_ECHO_CLI_AUTO_RUN_STR
     395        dly_tsk(START_DLY);
     396#endif
    328397        get_tid(&tskid);
    329         syslog(LOG_NOTICE, "[TCP DISCARD CLI:%d,%d] started.", tskid, (ID)exinf);
     398
     399#if defined(SUPPORT_INET6)
     400        apip = API_PROTO_IPV6;
     401#if defined(SUPPORT_INET4)
     402        syslog(LOG_NOTICE, "[TCPn DISCARD CLI:%d,%d] started.", tskid, (ID)exinf);
     403#else
     404        syslog(LOG_NOTICE, "[TCP6 DISCARD CLI:%d,%d] started.", tskid, (ID)exinf);
     405#endif
     406#else
     407        apip = API_PROTO_IPV4;
     408        syslog(LOG_NOTICE, "[TCP4 DISCARD CLI:%d,%d] started.", tskid, (ID)exinf);
     409#endif
     410
    330411        while (true) {
    331                 if (rcv_dtq(DTQ_TCP_DISCARD_CLI, (intptr_t*)&line) == E_OK) {
    332                         line = skip_blanks(GET_IPADDR(&addr, skip_blanks(line)));       /* IP Address */
    333 
    334                         if ('0' <= *line && *line <= '9') {                             /* Port No */
    335                                 line = get_int(&rep, line);
    336                                 portno = (uint16_t)rep;
     412                line = skip_blanks(getcomd((ID)exinf, retry));
     413
     414                if ((line = lookup_ipaddr(&addr, line, apip)) == NULL) {
     415                        syslog(LOG_NOTICE, "[TDCn:%02u TSK] sleep %d.%03u[s], unknown host.",
     416                               (ID)exinf, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
     417                        dly_tsk(SLP_ITV);
     418                        syslog(LOG_NOTICE, "[TDCn:%02u TSK] resume.", (ID)exinf);
     419                        retry = true;
     420                        continue;
     421                        }
     422                else
     423                        retry = false;
     424
     425                line = skip_blanks(line);
     426                if ('0' <= *line && *line <= '9') {     /* Port No */
     427                        line = get_int(&rep, line);
     428                        portno = (uint16_t)rep;
     429                        }
     430                else {
     431                        line ++;
     432                        portno = DISCARD_SRV_PORTNO;
     433                        }
     434
     435                line = skip_blanks(line);
     436                if ('0' <= *line && *line <= '9')       /* Repeat */
     437                        line = get_int(&rep, line);
     438                else
     439                        rep = 1;
     440
     441#ifdef USE_TCP_EXTENTIONS
     442
     443                ccep.cepatr = 0;
     444                ccep.sbufsz = TCP_DISCARD_CLI_SWBUF_SIZE;
     445                ccep.rbufsz = 0;
     446                ccep.rbuf = NADR;
     447
     448#ifdef TCP_CFG_SWBUF_CSAVE
     449                ccep.sbuf = NADR;
     450#else
     451                ccep.sbuf = tcp_discard_cli_swbuf;
     452#endif
     453#ifdef USE_TCP_NON_BLOCKING
     454                ccep.callback = (FP)callback_nblk_tcp_discard_cli;
     455#else
     456                ccep.callback = NULL;
     457#endif
     458
     459                if ((error = ALLOC_TCP_CEP(&cepid, tskid, &ccep)) != E_OK) {
     460                        syslog(LOG_NOTICE, "[TDCn:%02u TSK] CEP create error: %s", cepid, itron_strerror(error));
     461                        continue;
     462                        }
     463
     464#else   /* of #ifdef USE_TCP_EXTENTIONS */
     465
     466                cepid = (ID)exinf;
     467
     468#endif  /* of #ifdef USE_TCP_EXTENTIONS */
     469
     470                tcp_discard_cli_valid = true;
     471                count = 0;
     472                while (rep == 0 || count < rep) {
     473                        if (!tcp_discard_cli_valid) {
     474                                syslog(LOG_NOTICE, "[TDCn:%02u TSK] canceled.", cepid);
     475                                break;
     476                                }
     477
     478                        count ++;
     479                        if (rep == 0) {
     480                                syslog(LOG_NOTICE, "[TDCn:%02u TSK] start:       repeat: %d", cepid, count);
     481                                error = send_tcp_discard(cepid, &addr, portno);
     482                                syslog(LOG_NOTICE, "[TDCn:%02u TSK] finsh:       repeat: %d", cepid, count);
    337483                                }
    338484                        else {
    339                                 line ++;
    340                                 portno = DISCARD_SRV_PORTNO;
    341                                 }
    342 
    343                         line = skip_blanks(line);
    344                         if ('0' <= *line && *line <= '9')                               /* Repeat */
    345                                 line = get_int(&rep, line);
    346                         else
    347                                 rep = 1;
     485                                syslog(LOG_NOTICE, "[TDCn:%02u TSK] start:       repeat: %d/%d", cepid, count, rep);
     486                                error = send_tcp_discard(cepid, &addr, portno);
     487                                syslog(LOG_NOTICE, "[TDCn:%02u TSK] finsh:       repeat: %d/%d", cepid, count, rep);
     488                                }
     489
     490                        if (error != E_OK) {
     491                                syslog(LOG_NOTICE, "[TDCn:%02u TSK] sleep %d.%03u[s], error: %s",
     492                                                   cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ, itron_strerror(error));
     493                                tslp_tsk(SLP_ITV);
     494                                syslog(LOG_NOTICE, "[TDCn:%02u TSK] resume.", cepid);
     495                                }
     496
     497#if defined(SND_ITV)
     498#if SND_ITV > 0
     499                        if (count < rep) {
     500                                uint_t itv;
     501                               
     502                                itv = SND_ITV;
     503                                syslog(LOG_NOTICE, "[TDCn:%02u TSK] interval: %d[s].", cepid, itv / SYSTIM_HZ);
     504                                syscall(dly_tsk(SND_ITV));
     505                                }
     506#endif
     507#endif
     508                        }
    348509
    349510#ifdef USE_TCP_EXTENTIONS
    350511
    351                         ccep.cepatr = 0;
    352                         ccep.sbufsz = TCP_DISCARD_CLI_SWBUF_SIZE;
    353                         ccep.rbufsz = 0;
    354                         ccep.rbuf = NADR;
    355 
    356 #ifdef TCP_CFG_SWBUF_CSAVE
    357                         ccep.sbuf = NADR;
    358 #else
    359                         ccep.sbuf = tcp_discard_cli_swbuf;
    360 #endif
    361 #ifdef USE_TCP_NON_BLOCKING
    362                         ccep.callback = (FP)callback_nblk_tcp_discard_cli;
    363 #else
    364                         ccep.callback = NULL;
    365 #endif
    366 
    367                         if ((error = alloc_tcp_cep(&cepid, tskid, &ccep)) != E_OK) {
    368                                 syslog(LOG_NOTICE, "[TDC:%02d TSK] CEP create error: %s", cepid, itron_strerror(error));
    369                                 continue;
    370                                 }
    371 
    372 #else   /* of #ifdef USE_TCP_EXTENTIONS */
    373 
    374                         cepid = (ID)exinf;
     512                if ((error = FREE_TCP_CEP(cepid)) != E_OK)
     513                        syslog(LOG_NOTICE, "[TDCn:%02u TSK] CEP delete error: %s", cepid, itron_strerror(error));
    375514
    376515#endif  /* of #ifdef USE_TCP_EXTENTIONS */
    377516
    378                         tcp_discard_cli_valid = true;
    379                         for (count = rep; count -- > 0; ) {
    380                                 if (!tcp_discard_cli_valid) {
    381                                         syslog(LOG_NOTICE, "[TDC:%02d TSK] canceled.", (ID)exinf);
    382                                         break;
    383                                         }
    384                                 syslog(LOG_NOTICE, "[TDC:%02d TSK] start:              repeat: %d/%d",
    385                                                    (ID)exinf, rep - count, rep);
    386                                 send_tcp_discard(cepid, &addr, portno);
    387                                 syslog(LOG_NOTICE, "[TDC:%02d TSK] finished:           repeat: %d/%d",
    388                                                    (ID)exinf, rep - count, rep);
    389                                 syscall(dly_tsk(500 + net_rand() % SYSTIM_HZ));
    390                                 }
    391 
    392 #ifdef USE_TCP_EXTENTIONS
    393 
    394                         if ((error = free_tcp_cep(cepid)) != E_OK)
    395                                 syslog(LOG_NOTICE, "[TDC:%02d TSK] CEP delete error: %s", cepid, itron_strerror(error));
    396 
    397 #endif  /* of #ifdef USE_TCP_EXTENTIONS */
    398 
    399                         }
    400517                }
    401518        }
Note: See TracChangeset for help on using the changeset viewer.