[270] | 1 | /*
|
---|
| 2 | * TINET (TCP/IP Protocol Stack)
|
---|
| 3 | *
|
---|
[331] | 4 | * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
|
---|
[270] | 5 | * Tomakomai National College of Technology, JAPAN
|
---|
| 6 | *
|
---|
| 7 | * 上記著作権者は,以下の (1)~(4) の条件か,Free Software Foundation
|
---|
| 8 | * によって公表されている GNU General Public License の Version 2 に記
|
---|
| 9 | * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
|
---|
| 10 | * を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
|
---|
| 11 | * 利用と呼ぶ)することを無償で許諾する.
|
---|
| 12 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 13 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 14 | * スコード中に含まれていること.
|
---|
| 15 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 16 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 17 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 18 | * の無保証規定を掲載すること.
|
---|
| 19 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 20 | * 用できない形で再配布する場合には,次の条件を満たすこと.
|
---|
| 21 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 22 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 23 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 24 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 25 | *
|
---|
| 26 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 27 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
|
---|
| 28 | * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
|
---|
| 29 | * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
|
---|
| 30 | *
|
---|
| 31 | * @(#) $Id$
|
---|
| 32 | */
|
---|
| 33 |
|
---|
| 34 | /*
|
---|
| 35 | * UDP DISCARD クライアント
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | #include <stdlib.h>
|
---|
| 39 | #include <string.h>
|
---|
| 40 |
|
---|
| 41 | #ifdef TARGET_KERNEL_ASP
|
---|
| 42 |
|
---|
| 43 | #include <kernel.h>
|
---|
| 44 | #include <sil.h>
|
---|
| 45 | #include <t_syslog.h>
|
---|
| 46 | #include "kernel_cfg.h"
|
---|
| 47 |
|
---|
| 48 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 49 |
|
---|
| 50 | #ifdef TARGET_KERNEL_JSP
|
---|
| 51 |
|
---|
| 52 | #include <t_services.h>
|
---|
| 53 | #include "kernel_id.h"
|
---|
| 54 | #include "tinet_id.h"
|
---|
| 55 |
|
---|
| 56 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
| 57 |
|
---|
| 58 | #include <netinet/in.h>
|
---|
[331] | 59 | #include <netinet/in_itron.h>
|
---|
[270] | 60 | #include <netinet/ip.h>
|
---|
| 61 | #include <netinet/udp.h>
|
---|
| 62 |
|
---|
| 63 | #include <netapp/netapp.h>
|
---|
| 64 | #include <netapp/netapp_var.h>
|
---|
[331] | 65 | #include <netapp/udp_discard_cli.h>
|
---|
[270] | 66 |
|
---|
| 67 | #ifdef USE_UDP_DISCARD_CLI
|
---|
| 68 |
|
---|
| 69 | /* discard サーバのポート番号 */
|
---|
| 70 |
|
---|
| 71 | #define DISCARD_SRV_PORTNO UINT_C(9)
|
---|
| 72 |
|
---|
| 73 | /*
|
---|
| 74 | * 変数
|
---|
| 75 | */
|
---|
| 76 |
|
---|
| 77 | #define PAT_BEGIN ' '
|
---|
| 78 | #define PAT_END '~'
|
---|
| 79 |
|
---|
[331] | 80 | #if defined(SUPPORT_INET6)
|
---|
| 81 | #define API_PROTO '6'
|
---|
| 82 | #else
|
---|
| 83 | #define API_PROTO '4'
|
---|
| 84 | #endif
|
---|
| 85 |
|
---|
[270] | 86 | /*
|
---|
| 87 | * 全域変数
|
---|
| 88 | */
|
---|
| 89 |
|
---|
| 90 | bool_t udp_discard_cli_valid;
|
---|
| 91 |
|
---|
| 92 | /*
|
---|
| 93 | * send_udp_discard -- DISCARD/UDP サーバにメッセージを送信する。
|
---|
| 94 | */
|
---|
| 95 |
|
---|
| 96 | static ER
|
---|
| 97 | send_udp_discard (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno)
|
---|
| 98 | {
|
---|
[331] | 99 | #if defined(SUPPORT_INET6)
|
---|
| 100 | static char smsg[IPV6_MMTU - (IP6_HDR_SIZE + UDP_HDR_SIZE)];
|
---|
| 101 | #else
|
---|
| 102 | static char smsg[IP4_MSS - (IP4_HDR_SIZE + UDP_HDR_SIZE)];
|
---|
| 103 | #endif
|
---|
[270] | 104 |
|
---|
| 105 | T_IPEP dst;
|
---|
| 106 | ER_UINT len;
|
---|
| 107 | SYSTIM time;
|
---|
| 108 | char *p;
|
---|
| 109 | uint32_t total;
|
---|
| 110 | uint16_t pat, slen, scount;
|
---|
| 111 |
|
---|
| 112 | dst.ipaddr = *ipaddr;
|
---|
| 113 | dst.portno = portno;
|
---|
| 114 |
|
---|
| 115 | p = smsg;
|
---|
[331] | 116 | for (slen = sizeof(smsg); slen > 0; )
|
---|
[270] | 117 | for (pat = PAT_BEGIN; slen > 0 && pat <= PAT_END; pat ++, slen --)
|
---|
| 118 | *p ++ = pat;
|
---|
| 119 |
|
---|
| 120 | get_tim(&time);
|
---|
[331] | 121 | syslog(LOG_NOTICE, "[UDC%c:%02u SND] send: %7lu, to: %s.%d",
|
---|
| 122 | API_PROTO, cepid, time / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
|
---|
[270] | 123 |
|
---|
| 124 | scount = total = 0;
|
---|
| 125 | udp_discard_cli_valid = true;
|
---|
[331] | 126 | for (slen = sizeof(smsg); udp_discard_cli_valid && slen > 0; slen --) {
|
---|
[270] | 127 | scount ++;
|
---|
| 128 | if ((len = UDP_SND_DAT(cepid, &dst, smsg, slen, TMO_FEVR)) < 0) {
|
---|
[331] | 129 | syslog(LOG_NOTICE, "[UDC%c:%02u SND] error: %s", API_PROTO, cepid, itron_strerror(len));
|
---|
[270] | 130 | return len;
|
---|
| 131 | }
|
---|
| 132 | else
|
---|
[331] | 133 | syslog(LOG_NOTICE, "[UDC%c:%02u SND] send: %7lu, %4u", API_PROTO, cepid, scount, slen);
|
---|
[270] | 134 | total += len;
|
---|
[331] | 135 | dly_tsk(10 * SYSTIM_HZ + netapp_rand() % (10 * SYSTIM_HZ));
|
---|
[270] | 136 | }
|
---|
| 137 |
|
---|
| 138 | get_tim(&time);
|
---|
[331] | 139 | syslog(LOG_NOTICE, "[UDC%c:%02u SND] finsh: %7lu, snd: %4u, len: %ld",
|
---|
| 140 | API_PROTO, cepid, time / SYSTIM_HZ, scount, total);
|
---|
[270] | 141 | return E_OK;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | /*
|
---|
| 145 | * UDP DISCARD クライアント送信タスク
|
---|
| 146 | */
|
---|
| 147 |
|
---|
| 148 | void
|
---|
| 149 | udp_discard_cli_task (intptr_t exinf)
|
---|
| 150 | {
|
---|
| 151 | T_IN_ADDR addr;
|
---|
| 152 | ID tskid, cepid;
|
---|
| 153 | ER error;
|
---|
| 154 | char *line;
|
---|
| 155 | int_t no;
|
---|
| 156 | uint16_t portno;
|
---|
[331] | 157 | char apip;
|
---|
[270] | 158 |
|
---|
| 159 | #ifdef USE_UDP_EXTENTIONS
|
---|
| 160 |
|
---|
[331] | 161 | #if defined(SUPPORT_INET6)
|
---|
| 162 | T_UDP6_CCEP ccep;
|
---|
| 163 | #else
|
---|
[270] | 164 | T_UDP_CCEP ccep;
|
---|
[331] | 165 | #endif
|
---|
[270] | 166 |
|
---|
| 167 | #endif /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
| 168 |
|
---|
[331] | 169 | #if defined(SUPPORT_INET6)
|
---|
| 170 | apip = API_PROTO_IPV6;
|
---|
| 171 | #else
|
---|
| 172 | apip = API_PROTO_IPV4;
|
---|
| 173 | #endif
|
---|
| 174 |
|
---|
[270] | 175 | get_tid(&tskid);
|
---|
| 176 | syslog(LOG_NOTICE, "[UDP DISCARD CLI:%d,%d] started.", tskid, (ID)exinf);
|
---|
| 177 | while (true) {
|
---|
| 178 | if (rcv_dtq(DTQ_UDP_DISCARD_CLI, (intptr_t*)&line) == E_OK) {
|
---|
| 179 | line = skip_blanks(GET_IPADDR(&addr, skip_blanks(line))); /* IP Address */
|
---|
| 180 |
|
---|
[331] | 181 | if ((line = lookup_ipaddr(&addr, line, apip)) == NULL) {
|
---|
| 182 | syslog(LOG_NOTICE, "[UDC%c:%02u TSK] unknown host.", (ID)exinf);
|
---|
| 183 | continue;
|
---|
| 184 | }
|
---|
| 185 |
|
---|
[270] | 186 | if ('0' <= *line && *line <= '9') { /* Port No */
|
---|
| 187 | line = get_int(&no, line);
|
---|
| 188 | portno = (uint16_t)no;
|
---|
| 189 | }
|
---|
| 190 | else {
|
---|
| 191 | line ++;
|
---|
| 192 | portno = DISCARD_SRV_PORTNO;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | #ifdef USE_UDP_EXTENTIONS
|
---|
| 196 |
|
---|
| 197 | ccep.cepatr = UINT_C(0);
|
---|
| 198 | ccep.callback = NULL;
|
---|
| 199 | ccep.myaddr.portno = UDP_PORTANY;
|
---|
| 200 |
|
---|
[331] | 201 | #if defined(SUPPORT_INET6)
|
---|
| 202 |
|
---|
| 203 | memcpy(&ccep.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
|
---|
| 204 |
|
---|
| 205 | #else /* #if defined(SUPPORT_INET6) */
|
---|
| 206 |
|
---|
[270] | 207 | #if defined(SUPPORT_INET4)
|
---|
| 208 | ccep.myaddr.ipaddr = IPV4_ADDRANY;
|
---|
| 209 | #endif
|
---|
| 210 |
|
---|
[331] | 211 | #endif /* #if defined(SUPPORT_INET6) */
|
---|
[270] | 212 |
|
---|
[331] | 213 | if ((error = ALLOC_UDP_CEP(&cepid, tskid, &ccep)) != E_OK) {
|
---|
| 214 | syslog(LOG_NOTICE, "[UDC%c:%02u TSK] CEP create error: %s", API_PROTO, cepid, itron_strerror(error));
|
---|
[270] | 215 | continue;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | #else /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
| 219 |
|
---|
| 220 | cepid = (ID)exinf;
|
---|
| 221 |
|
---|
| 222 | #endif /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
| 223 |
|
---|
| 224 | if ((error = send_udp_discard(cepid, &addr, portno)) != E_OK)
|
---|
[331] | 225 | syslog(LOG_NOTICE, "[UDC%c:%02u TSK] error: %s", API_PROTO, cepid, itron_strerror(error));
|
---|
[270] | 226 |
|
---|
| 227 | #ifdef USE_UDP_EXTENTIONS
|
---|
| 228 |
|
---|
[331] | 229 | if ((error = FREE_UDP_CEP(cepid, !(error == E_NOEXS || error == E_DLT))) != E_OK)
|
---|
| 230 | syslog(LOG_NOTICE, "[UDC%c:%02u TSK] CEP delete error: %s", API_PROTO, cepid, itron_strerror(error));
|
---|
[270] | 231 |
|
---|
| 232 | #endif /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
| 233 |
|
---|
| 234 | }
|
---|
| 235 | }
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | #endif /* of #ifdef USE_UDP_DISCARD_CLI */
|
---|