[270] | 1 | /*
|
---|
| 2 | * TINET (TCP/IP Protocol Stack)
|
---|
| 3 | *
|
---|
| 4 | * Copyright (C) 2001-2009 by Dep. of Computer Science and Engineering
|
---|
| 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 <tinet_defs.h>
|
---|
| 59 | #include <tinet_config.h>
|
---|
| 60 |
|
---|
| 61 | #include <net/if.h>
|
---|
| 62 | #include <net/if_ppp.h>
|
---|
| 63 | #include <net/if_loop.h>
|
---|
| 64 | #include <net/ethernet.h>
|
---|
| 65 | #include <net/net.h>
|
---|
| 66 | #include <net/net_var.h>
|
---|
| 67 | #include <net/net_timer.h>
|
---|
| 68 |
|
---|
| 69 | #include <netinet/in.h>
|
---|
| 70 | #include <netinet/ip.h>
|
---|
| 71 | #include <netinet/ip6.h>
|
---|
| 72 | #include <netinet/udp.h>
|
---|
| 73 | #include <netinet/udp_var.h>
|
---|
| 74 | #include <netinet/in_itron.h>
|
---|
| 75 |
|
---|
| 76 | #include <netapp/netapp.h>
|
---|
| 77 | #include <netapp/netapp_var.h>
|
---|
| 78 | #include <netapp/discard.h>
|
---|
| 79 |
|
---|
| 80 | #ifdef USE_UDP_DISCARD_CLI
|
---|
| 81 |
|
---|
| 82 | /* discard サーバのポート番号 */
|
---|
| 83 |
|
---|
| 84 | #define DISCARD_SRV_PORTNO UINT_C(9)
|
---|
| 85 |
|
---|
| 86 | /*
|
---|
| 87 | * 変数
|
---|
| 88 | */
|
---|
| 89 |
|
---|
| 90 | #define PAT_BEGIN ' '
|
---|
| 91 | #define PAT_END '~'
|
---|
| 92 |
|
---|
| 93 | /*
|
---|
| 94 | * 全域変数
|
---|
| 95 | */
|
---|
| 96 |
|
---|
| 97 | bool_t udp_discard_cli_valid;
|
---|
| 98 |
|
---|
| 99 | /*
|
---|
| 100 | * send_udp_discard -- DISCARD/UDP サーバにメッセージを送信する。
|
---|
| 101 | */
|
---|
| 102 |
|
---|
| 103 | static ER
|
---|
| 104 | send_udp_discard (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno)
|
---|
| 105 | {
|
---|
| 106 | static char smsg[IF_MTU - IP_UDP_HDR_SIZE];
|
---|
| 107 |
|
---|
| 108 | T_IPEP dst;
|
---|
| 109 | ER_UINT len;
|
---|
| 110 | SYSTIM time;
|
---|
| 111 | char *p;
|
---|
| 112 | uint32_t total;
|
---|
| 113 | uint16_t pat, slen, scount;
|
---|
| 114 |
|
---|
| 115 | dst.ipaddr = *ipaddr;
|
---|
| 116 | dst.portno = portno;
|
---|
| 117 |
|
---|
| 118 | p = smsg;
|
---|
| 119 | for (slen = IF_MTU - IP_UDP_HDR_SIZE; slen > 0; )
|
---|
| 120 | for (pat = PAT_BEGIN; slen > 0 && pat <= PAT_END; pat ++, slen --)
|
---|
| 121 | *p ++ = pat;
|
---|
| 122 |
|
---|
| 123 | get_tim(&time);
|
---|
| 124 | syslog(LOG_NOTICE, "[UDC:%02d SND] sending: %6ld, to: %s.%d",
|
---|
| 125 | cepid, time / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
|
---|
| 126 |
|
---|
| 127 | scount = total = 0;
|
---|
| 128 | udp_discard_cli_valid = true;
|
---|
| 129 | for (slen = IF_MTU - IP_UDP_HDR_SIZE; udp_discard_cli_valid && slen > 0; slen --) {
|
---|
| 130 | scount ++;
|
---|
| 131 | if ((len = UDP_SND_DAT(cepid, &dst, smsg, slen, TMO_FEVR)) < 0) {
|
---|
| 132 | syslog(LOG_NOTICE, "[UDC:%02d SND] send error: %s", cepid, itron_strerror(len));
|
---|
| 133 | return len;
|
---|
| 134 | }
|
---|
| 135 | else
|
---|
| 136 | syslog(LOG_NOTICE, "[UDC:%02d SND] send: %4d, %4d", cepid, scount, slen);
|
---|
| 137 | total += len;
|
---|
| 138 | dly_tsk(10 * SYSTIM_HZ + net_rand() % (10 * SYSTIM_HZ));
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | get_tim(&time);
|
---|
| 142 | syslog(LOG_NOTICE, "[UDC:%02d SND] finished: %6ld, snd: %4d, len: %ld",
|
---|
| 143 | cepid, time / SYSTIM_HZ, scount, total);
|
---|
| 144 | return E_OK;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | /*
|
---|
| 148 | * UDP DISCARD クライアント送信タスク
|
---|
| 149 | */
|
---|
| 150 |
|
---|
| 151 | void
|
---|
| 152 | udp_discard_cli_task (intptr_t exinf)
|
---|
| 153 | {
|
---|
| 154 | T_IN_ADDR addr;
|
---|
| 155 | ID tskid, cepid;
|
---|
| 156 | ER error;
|
---|
| 157 | char *line;
|
---|
| 158 | int_t no;
|
---|
| 159 | uint16_t portno;
|
---|
| 160 |
|
---|
| 161 | #ifdef USE_UDP_EXTENTIONS
|
---|
| 162 |
|
---|
| 163 | T_UDP_CCEP ccep;
|
---|
| 164 |
|
---|
| 165 | #endif /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
| 166 |
|
---|
| 167 | get_tid(&tskid);
|
---|
| 168 | syslog(LOG_NOTICE, "[UDP DISCARD CLI:%d,%d] started.", tskid, (ID)exinf);
|
---|
| 169 | while (true) {
|
---|
| 170 | if (rcv_dtq(DTQ_UDP_DISCARD_CLI, (intptr_t*)&line) == E_OK) {
|
---|
| 171 | line = skip_blanks(GET_IPADDR(&addr, skip_blanks(line))); /* IP Address */
|
---|
| 172 |
|
---|
| 173 | if ('0' <= *line && *line <= '9') { /* Port No */
|
---|
| 174 | line = get_int(&no, line);
|
---|
| 175 | portno = (uint16_t)no;
|
---|
| 176 | }
|
---|
| 177 | else {
|
---|
| 178 | line ++;
|
---|
| 179 | portno = DISCARD_SRV_PORTNO;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | #ifdef USE_UDP_EXTENTIONS
|
---|
| 183 |
|
---|
| 184 | ccep.cepatr = UINT_C(0);
|
---|
| 185 | ccep.callback = NULL;
|
---|
| 186 | ccep.myaddr.portno = UDP_PORTANY;
|
---|
| 187 |
|
---|
| 188 | #if defined(SUPPORT_INET4)
|
---|
| 189 | ccep.myaddr.ipaddr = IPV4_ADDRANY;
|
---|
| 190 | #endif
|
---|
| 191 |
|
---|
| 192 | #if defined(SUPPORT_INET6)
|
---|
| 193 | memcpy(&ccep.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
|
---|
| 194 | #endif
|
---|
| 195 |
|
---|
| 196 | if ((error = alloc_udp_cep(&cepid, tskid, &ccep)) != E_OK) {
|
---|
| 197 | syslog(LOG_NOTICE, "[UDC:%02d TSK] CEP create error: %s", cepid, itron_strerror(error));
|
---|
| 198 | continue;
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | #else /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
| 202 |
|
---|
| 203 | cepid = (ID)exinf;
|
---|
| 204 |
|
---|
| 205 | #endif /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
| 206 |
|
---|
| 207 | if ((error = send_udp_discard(cepid, &addr, portno)) != E_OK)
|
---|
| 208 | syslog(LOG_NOTICE, "[UDC:%02d TSK] error: %s", cepid, itron_strerror(error));
|
---|
| 209 |
|
---|
| 210 | #ifdef USE_UDP_EXTENTIONS
|
---|
| 211 |
|
---|
| 212 | if ((error = free_udp_cep(cepid, !(error == E_NOEXS || error == E_DLT))) != E_OK)
|
---|
| 213 | syslog(LOG_NOTICE, "[UDC:%02d TSK] CEP delete error: %s", cepid, itron_strerror(error));
|
---|
| 214 |
|
---|
| 215 | #endif /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
| 216 |
|
---|
| 217 | }
|
---|
| 218 | }
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | #endif /* of #ifdef USE_UDP_DISCARD_CLI */
|
---|