[337] | 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 | * 上記著作権者は,以下の (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 | * WWW サーバ
|
---|
| 36 | *
|
---|
| 37 | * ・送受信タスク同一型
|
---|
| 38 | * ・ノンブロッキングコール
|
---|
| 39 | * ・省コピー API
|
---|
| 40 | * ・IPv4/IPv6
|
---|
| 41 | */
|
---|
| 42 |
|
---|
| 43 | #include <stdlib.h>
|
---|
| 44 | #include <string.h>
|
---|
| 45 |
|
---|
| 46 | #ifdef TARGET_KERNEL_ASP
|
---|
| 47 |
|
---|
| 48 | #include <kernel.h>
|
---|
| 49 | #include <sil.h>
|
---|
| 50 | #include <t_syslog.h>
|
---|
| 51 | #include "kernel/kernel_impl.h"
|
---|
| 52 | #include "target_config.h"
|
---|
| 53 | #include "target_syssvc.h"
|
---|
| 54 | #include "target_stddef.h"
|
---|
| 55 | #include "kernel_cfg.h"
|
---|
| 56 | #include "tinet_cfg.h"
|
---|
| 57 |
|
---|
| 58 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 59 |
|
---|
| 60 | #ifdef TARGET_KERNEL_JSP
|
---|
| 61 |
|
---|
| 62 | #include <s_services.h>
|
---|
| 63 | #include <t_services.h>
|
---|
| 64 | #include "kernel_id.h"
|
---|
| 65 | #include "tinet_id.h"
|
---|
| 66 |
|
---|
| 67 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
| 68 |
|
---|
| 69 | #include <tinet_defs.h>
|
---|
| 70 | #include <tinet_config.h>
|
---|
| 71 |
|
---|
| 72 | #include <net/if.h>
|
---|
| 73 | #include <net/if_ppp.h>
|
---|
| 74 | #include <net/if_loop.h>
|
---|
| 75 | #include <net/ethernet.h>
|
---|
| 76 | #include <net/net.h>
|
---|
| 77 | #include <net/net_endian.h>
|
---|
| 78 | #include <net/net_buf.h>
|
---|
| 79 | #include <net/net_count.h>
|
---|
| 80 |
|
---|
| 81 | #include <netinet/in.h>
|
---|
| 82 | #include <netinet/in_itron.h>
|
---|
| 83 |
|
---|
| 84 | #include <netapp/netapp.h>
|
---|
| 85 | #include <netapp/netapp_var.h>
|
---|
| 86 | #include <netapp/wwws.h>
|
---|
| 87 |
|
---|
| 88 | #ifdef USE_WWW_SRV
|
---|
| 89 |
|
---|
| 90 | /*
|
---|
| 91 | * 送受信 API の選択
|
---|
| 92 | */
|
---|
| 93 |
|
---|
| 94 | #define EOF (-1)
|
---|
| 95 |
|
---|
| 96 | typedef struct file {
|
---|
| 97 | ER (*func)(ID cepid, T_WWW_RWBUF *srbuf);
|
---|
| 98 | char *uri;
|
---|
| 99 | } T_FILE;
|
---|
| 100 |
|
---|
| 101 | typedef struct status {
|
---|
| 102 | uint16_t code;
|
---|
| 103 | uint8_t *reason;
|
---|
| 104 | } T_STATUS;
|
---|
| 105 |
|
---|
| 106 | /*
|
---|
| 107 | * 関数
|
---|
| 108 | */
|
---|
| 109 |
|
---|
| 110 | static ER index_html(ID cepid, T_WWW_RWBUF *srbuf);
|
---|
| 111 |
|
---|
| 112 | #if NET_COUNT_ENABLE
|
---|
| 113 |
|
---|
| 114 | static ER stat_html(ID cepid, T_WWW_RWBUF *srbuf);
|
---|
| 115 |
|
---|
| 116 | #endif /* of #if NET_COUNT_ENABLE */
|
---|
| 117 |
|
---|
| 118 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 119 |
|
---|
| 120 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV)
|
---|
| 121 |
|
---|
| 122 | #if NUM_WWW_SRV_TASKS >= 2 /* 2 を超える個数は想定していない。 */
|
---|
| 123 |
|
---|
| 124 | #define WWW4_SRV_TASK WWW_SRV_TASK1
|
---|
| 125 | #define WWW6_SRV_TASK WWW_SRV_TASK2
|
---|
| 126 |
|
---|
| 127 | #else /* of #if NUM_WWW_SRV_TASKS >= 2 */
|
---|
| 128 |
|
---|
| 129 | #define WWW4_SRV_TASK WWW_SRV_TASK1
|
---|
| 130 | #define WWW6_SRV_TASK WWW_SRV_TASK1
|
---|
| 131 |
|
---|
| 132 | #endif /* of #if NUM_WWW_SRV_TASKS >= 2 */
|
---|
| 133 |
|
---|
| 134 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
|
---|
| 135 |
|
---|
| 136 | #define WWW4_SRV_TASK WWW_SRV_TASK1
|
---|
| 137 | #define WWW6_SRV_TASK WWW_SRV_TASK1
|
---|
| 138 |
|
---|
| 139 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
|
---|
| 140 |
|
---|
| 141 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 142 |
|
---|
| 143 |
|
---|
| 144 | /*
|
---|
| 145 | * 全域変数
|
---|
| 146 | */
|
---|
| 147 |
|
---|
| 148 | /* TCP 送受信ウィンドバッファ */
|
---|
| 149 |
|
---|
| 150 | #ifndef TCP_CFG_SWBUF_CSAVE
|
---|
| 151 | uint8_t www_srv_swbuf[NUM_WWW_SRV_TASKS][WWW_SRV_SWBUF_SIZE];
|
---|
| 152 | #endif
|
---|
| 153 |
|
---|
| 154 | #ifndef TCP_CFG_RWBUF_CSAVE
|
---|
| 155 | uint8_t www_srv_rwbuf[NUM_WWW_SRV_TASKS][WWW_SRV_RWBUF_SIZE];
|
---|
| 156 | #endif
|
---|
| 157 |
|
---|
| 158 | /*
|
---|
| 159 | * 変数
|
---|
| 160 | */
|
---|
| 161 |
|
---|
| 162 | SYSTIM srv_start;
|
---|
| 163 |
|
---|
| 164 | static const T_FILE file[] = {
|
---|
| 165 | { index_html, "/" },
|
---|
| 166 | { index_html, "/index.html" },
|
---|
| 167 |
|
---|
| 168 | #if NET_COUNT_ENABLE
|
---|
| 169 |
|
---|
| 170 | { stat_html, "/stat.html" },
|
---|
| 171 |
|
---|
| 172 | #endif /* of #if NET_COUNT_ENABLE */
|
---|
| 173 | };
|
---|
| 174 |
|
---|
| 175 | #define NUM_FILES (sizeof(file) / sizeof(T_FILE))
|
---|
| 176 |
|
---|
| 177 | static const char *status[] = {
|
---|
| 178 | "200 OK",
|
---|
| 179 | "404 Not Found",
|
---|
| 180 | };
|
---|
| 181 |
|
---|
| 182 | #define NUM_STATUS (sizeof(status) / sizeof(T_STATUS))
|
---|
| 183 |
|
---|
| 184 | #define ST_OK 0
|
---|
| 185 | #define ST_NOT_FOUND 1
|
---|
| 186 |
|
---|
| 187 | /*
|
---|
| 188 | * 接続相手の情報構造体
|
---|
| 189 | */
|
---|
| 190 |
|
---|
| 191 | #ifdef NUM_WWW4_SRV_TASKS
|
---|
| 192 | #undef NUM_WWW4_SRV_TASKS
|
---|
| 193 | #endif
|
---|
| 194 | #define NUM_WWW4_SRV_TASKS 1
|
---|
| 195 |
|
---|
| 196 | typedef struct t_www_srv_info {
|
---|
| 197 | ID cepid; /* 通信端点 ID */
|
---|
| 198 | ID repid; /* 受付口 ID */
|
---|
| 199 | T_IPEP dst; /* 接続相手アドレス情報 */
|
---|
| 200 | } T_WWW_SRV_INFO;
|
---|
| 201 |
|
---|
| 202 | #define INDEX_SRV_INFO(id) ((id)-1)
|
---|
| 203 |
|
---|
| 204 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 205 |
|
---|
| 206 | static T_WWW_SRV_INFO www_srv_info[NUM_WWW_SRV_TASKS];
|
---|
| 207 | /* 2 を超える個数は想定していない。 */
|
---|
| 208 |
|
---|
| 209 | #else /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 210 |
|
---|
| 211 | static T_WWW_SRV_INFO www_srv_info[] = {
|
---|
| 212 |
|
---|
| 213 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV)
|
---|
| 214 |
|
---|
| 215 | { WWW4_SRV_CEPID1, WWW4_SRV_REPID },
|
---|
| 216 |
|
---|
| 217 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
|
---|
| 218 |
|
---|
| 219 | { WWW_SRV_CEPID1, WWW_SRV_REPID },
|
---|
| 220 |
|
---|
| 221 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
|
---|
| 222 |
|
---|
| 223 | #if NUM_WWW_SRV_TASKS >= 2 /* 2 を超える個数は想定していない。 */
|
---|
| 224 | { WWW_SRV_CEPID2, WWW_SRV_REPID },
|
---|
| 225 | #endif
|
---|
| 226 |
|
---|
| 227 | };
|
---|
| 228 |
|
---|
| 229 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 230 |
|
---|
| 231 | #ifdef USE_COPYSAVE_API
|
---|
| 232 |
|
---|
| 233 | /*
|
---|
| 234 | * get_char -- 一文字入力する。
|
---|
| 235 | */
|
---|
| 236 |
|
---|
| 237 | static int_t
|
---|
| 238 | get_char (ID cepid, T_WWW_RWBUF *srbuf)
|
---|
| 239 | {
|
---|
| 240 | int_t len, ch;
|
---|
| 241 | ER error;
|
---|
| 242 |
|
---|
| 243 | if (srbuf->unget) {
|
---|
| 244 | ch = srbuf->unget;
|
---|
| 245 | srbuf->unget = 0;
|
---|
| 246 | }
|
---|
| 247 | else {
|
---|
| 248 | if (srbuf->rbuf.index >= srbuf->rbuf.len) {
|
---|
| 249 | if ((error = tcp_rel_buf(cepid, srbuf->rbuf.len)) != E_OK)
|
---|
| 250 | syslog(LOG_WARNING, "[WWWn:%02u REL] tcp_rel_buf error: %s",
|
---|
| 251 | cepid, itron_strerror(error));
|
---|
| 252 | srbuf->rbuf.index = 0;
|
---|
| 253 | if ((len = tcp_rcv_buf(cepid, (void**)&srbuf->rbuf.buf, TMO_FEVR)) <= 0) {
|
---|
| 254 | if (len < 0)
|
---|
| 255 | syslog(LOG_WARNING, "[WWWn:%02u RCV] tcp_rcv_buf error: %s",
|
---|
| 256 | cepid, itron_strerror(len));
|
---|
| 257 | srbuf->rbuf.len = 0;
|
---|
| 258 | return EOF;
|
---|
| 259 | }
|
---|
| 260 | else
|
---|
| 261 | srbuf->rbuf.len = len;
|
---|
| 262 | }
|
---|
| 263 | ch = srbuf->rbuf.buf[srbuf->rbuf.index ++];
|
---|
| 264 | }
|
---|
| 265 | return ch;
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | /*
|
---|
| 269 | * flush_sbuf -- 送信バッファをフラッシュする。
|
---|
| 270 | */
|
---|
| 271 |
|
---|
| 272 | static ER
|
---|
| 273 | flush_sbuf (ID cepid, T_WWW_RWBUF *srbuf)
|
---|
| 274 | {
|
---|
| 275 | ER_UINT error;
|
---|
| 276 |
|
---|
| 277 | error = tcp_snd_buf(cepid, srbuf->sbuf.index);
|
---|
| 278 | srbuf->sbuf.index = srbuf->sbuf.len = 0;
|
---|
| 279 |
|
---|
| 280 | return error;
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | /*
|
---|
| 284 | * put_str -- 文字列を出力する。
|
---|
| 285 | */
|
---|
| 286 |
|
---|
| 287 | static uint_t
|
---|
| 288 | put_str (ID cepid, T_WWW_RWBUF *srbuf, const char *str)
|
---|
| 289 | {
|
---|
| 290 | ER error;
|
---|
| 291 | ER_UINT blen;
|
---|
| 292 | uint16_t len, off = 0;
|
---|
| 293 |
|
---|
| 294 | len = strlen(str);
|
---|
| 295 | while (len > 0) {
|
---|
| 296 | if (srbuf->sbuf.index >= srbuf->sbuf.len)
|
---|
| 297 | if ((error = flush_sbuf(cepid, srbuf)) != E_OK) {
|
---|
| 298 | syslog(LOG_WARNING, "[WWWn:%02u SND] error: %s", cepid, itron_strerror(error));
|
---|
| 299 | return 0;
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 | if (srbuf->sbuf.len == 0) {
|
---|
| 303 | if ((blen = tcp_get_buf(cepid, (void**)&srbuf->sbuf.buf, TMO_FEVR)) < 0) {
|
---|
| 304 | syslog(LOG_WARNING, "[WWWn:%02u GET] error: %s", cepid, itron_strerror(srbuf->sbuf.len));
|
---|
| 305 | return 0;
|
---|
| 306 | }
|
---|
| 307 | srbuf->sbuf.len = (uint16_t)blen;
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | if (len > srbuf->sbuf.len - srbuf->sbuf.index)
|
---|
| 311 | blen = srbuf->sbuf.len - srbuf->sbuf.index;
|
---|
| 312 | else
|
---|
| 313 | blen = len;
|
---|
| 314 | memcpy(&srbuf->sbuf.buf[srbuf->sbuf.index], str + off, blen);
|
---|
| 315 | srbuf->sbuf.index += (uint16_t)blen;
|
---|
| 316 | off += (uint16_t)blen;
|
---|
| 317 | len -= (uint16_t)blen;
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | return off;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | #else /* of #ifdef USE_COPYSAVE_API */
|
---|
| 324 |
|
---|
| 325 | /*
|
---|
| 326 | * get_char -- 一文字入力する。
|
---|
| 327 | */
|
---|
| 328 |
|
---|
| 329 | static int_t
|
---|
| 330 | get_char (ID cepid, T_WWW_RWBUF *srbuf)
|
---|
| 331 | {
|
---|
| 332 | int_t len, ch;
|
---|
| 333 |
|
---|
| 334 | if (srbuf->unget) {
|
---|
| 335 | ch = srbuf->unget;
|
---|
| 336 | srbuf->unget = 0;
|
---|
| 337 | }
|
---|
| 338 | else {
|
---|
| 339 | if (srbuf->rbuf.index >= srbuf->rbuf.len) {
|
---|
| 340 | if ((len = tcp_rcv_dat(cepid, srbuf->rbuf.buf, sizeof(srbuf->rbuf.buf), TMO_FEVR)) <= 0) {
|
---|
| 341 | if (len < 0) {
|
---|
| 342 | syslog(LOG_WARNING, "[WWWn:%02u RCV] error: %s",
|
---|
| 343 | cepid, itron_strerror(len));
|
---|
| 344 | }
|
---|
| 345 | return EOF;
|
---|
| 346 | }
|
---|
| 347 | else {
|
---|
| 348 | srbuf->rbuf.len = len;
|
---|
| 349 | srbuf->rbuf.index = 0;
|
---|
| 350 | }
|
---|
| 351 | }
|
---|
| 352 | ch = srbuf->rbuf.buf[srbuf->rbuf.index ++];
|
---|
| 353 | }
|
---|
| 354 | return ch;
|
---|
| 355 | }
|
---|
| 356 |
|
---|
| 357 | /*
|
---|
| 358 | * flush_sbuf -- 送信バッファをフラッシュする。
|
---|
| 359 | */
|
---|
| 360 |
|
---|
| 361 | static ER
|
---|
| 362 | flush_sbuf (ID cepid, T_WWW_RWBUF *srbuf)
|
---|
| 363 | {
|
---|
| 364 | ER_UINT len = E_OK;
|
---|
| 365 | uint16_t off = 0;
|
---|
| 366 |
|
---|
| 367 | while (off < srbuf->sbuf.index) {
|
---|
| 368 | if ((len = tcp_snd_dat(cepid, srbuf->sbuf.buf + off, srbuf->sbuf.index - off, TMO_FEVR)) < 0)
|
---|
| 369 | break;
|
---|
| 370 | off += len;
|
---|
| 371 | }
|
---|
| 372 | srbuf->sbuf.index = 0;
|
---|
| 373 |
|
---|
| 374 | return len < 0 ? len : E_OK;
|
---|
| 375 | }
|
---|
| 376 |
|
---|
| 377 | /*
|
---|
| 378 | * put_str -- 文字列を出力する。
|
---|
| 379 | */
|
---|
| 380 |
|
---|
| 381 | static uint16_t
|
---|
| 382 | put_str (ID cepid, T_WWW_RWBUF *srbuf, const char *str)
|
---|
| 383 | {
|
---|
| 384 | ER error;
|
---|
| 385 | uint16_t blen, len, off = 0;
|
---|
| 386 |
|
---|
| 387 | len = strlen(str);
|
---|
| 388 | while (len > 0) {
|
---|
| 389 | if (srbuf->sbuf.index >= srbuf->sbuf.len)
|
---|
| 390 | if ((error = flush_sbuf(cepid, srbuf)) != E_OK) {
|
---|
| 391 | syslog(LOG_WARNING, "[WWWn:%02u SND] error: %s", cepid, itron_strerror(error));
|
---|
| 392 | return 0;
|
---|
| 393 | }
|
---|
| 394 | if (len > srbuf->sbuf.len - srbuf->sbuf.index)
|
---|
| 395 | blen = srbuf->sbuf.len - srbuf->sbuf.index;
|
---|
| 396 | else
|
---|
| 397 | blen = len;
|
---|
| 398 | memcpy(&srbuf->sbuf.buf[srbuf->sbuf.index], str + off, blen);
|
---|
| 399 | srbuf->sbuf.index += blen;
|
---|
| 400 | off += blen;
|
---|
| 401 | len -= blen;
|
---|
| 402 | }
|
---|
| 403 |
|
---|
| 404 | return off;
|
---|
| 405 | }
|
---|
| 406 |
|
---|
| 407 | #endif /* of #ifdef USE_COPYSAVE_API */
|
---|
| 408 |
|
---|
| 409 | /*
|
---|
| 410 | * get_line -- 一行入力する。
|
---|
| 411 | */
|
---|
| 412 |
|
---|
| 413 | static uint16_t
|
---|
| 414 | get_line (ID cepid, T_WWW_LINE *line, T_WWW_RWBUF *srbuf)
|
---|
| 415 | {
|
---|
| 416 | int_t ch = 0;
|
---|
| 417 | uint16_t len;
|
---|
| 418 | char *p, *t;
|
---|
| 419 |
|
---|
| 420 | p = line->buf;
|
---|
| 421 | t = line->buf + WWW_LINE_SIZE;
|
---|
| 422 | while (p < t && (ch = get_char(cepid, srbuf)) != EOF && ch != '\n' && ch != '\r')
|
---|
| 423 | *p ++ = ch;
|
---|
| 424 | *p = '\0';
|
---|
| 425 | len = p - line->buf;
|
---|
| 426 | if (p >= t) {
|
---|
| 427 | while ((ch = get_char(cepid, srbuf)) != EOF && ch != '\n' && ch != '\r')
|
---|
| 428 | len ++;
|
---|
| 429 | }
|
---|
| 430 | if (ch == '\r') {
|
---|
| 431 | len ++;
|
---|
| 432 | if ((ch = get_char(cepid, srbuf)) != EOF && ch != '\n')
|
---|
| 433 | srbuf->unget = ch;
|
---|
| 434 | }
|
---|
| 435 | if (ch == '\n')
|
---|
| 436 | len ++;
|
---|
| 437 | line->len = len;
|
---|
| 438 | return p - line->buf;
|
---|
| 439 | }
|
---|
| 440 |
|
---|
| 441 | #if NET_COUNT_ENABLE
|
---|
| 442 |
|
---|
| 443 | #ifdef _int64_
|
---|
| 444 | #define VAL_TYPE uint64_t
|
---|
| 445 | #else
|
---|
| 446 | #define VAL_TYPE uint32_t
|
---|
| 447 | #endif
|
---|
| 448 |
|
---|
| 449 | /*
|
---|
| 450 | * convert -- 数値変換
|
---|
| 451 | */
|
---|
| 452 |
|
---|
| 453 | static int_t
|
---|
| 454 | convert (char *buf, VAL_TYPE val, int_t radix, int_t width, bool_t minus, char padchar)
|
---|
| 455 | {
|
---|
| 456 | static const char radhex[] = "0123456789abcdef";
|
---|
| 457 |
|
---|
| 458 | char digits[23], *start;
|
---|
| 459 | int_t ix, pad;
|
---|
| 460 |
|
---|
| 461 | ix = 0;
|
---|
| 462 | start = buf;
|
---|
| 463 | do {
|
---|
| 464 | digits[ix ++] = radhex[val % radix];
|
---|
| 465 | val /= radix;
|
---|
| 466 | } while (val != 0);
|
---|
| 467 | if (minus)
|
---|
| 468 | digits[ix ++] = '-';
|
---|
| 469 | for (pad = ix; pad < width; pad ++)
|
---|
| 470 | *buf ++ = padchar;
|
---|
| 471 | while (ix -- > 0)
|
---|
| 472 | *buf ++ = digits[ix];
|
---|
| 473 | *buf = '\0';
|
---|
| 474 | return buf - start;
|
---|
| 475 | }
|
---|
| 476 |
|
---|
| 477 | #endif /* of #if NET_COUNT_ENABLE */
|
---|
| 478 |
|
---|
| 479 | /*
|
---|
| 480 | * split_fields -- フィールドに分割する。
|
---|
| 481 | */
|
---|
| 482 |
|
---|
| 483 | static void
|
---|
| 484 | split_fields (T_WWW_LINE *line, char *delim)
|
---|
| 485 | {
|
---|
| 486 | char *p, quote;
|
---|
| 487 | int_t ix = 0;
|
---|
| 488 |
|
---|
| 489 | line->off[ix ++] = 0;
|
---|
| 490 | for (p = line->buf; ix < WWW_NUM_FIELDS && *p; p ++) {
|
---|
| 491 | if (strchr("\"'`", *p) != NULL) {
|
---|
| 492 | for (quote = *p ++; *p && *p != quote; p ++)
|
---|
| 493 | ;
|
---|
| 494 | }
|
---|
| 495 | else if (strchr(delim, *p) != NULL) {
|
---|
| 496 | *p = '\0';
|
---|
| 497 | line->off[ix ++] = (uint8_t)(p - line->buf + 1);
|
---|
| 498 | }
|
---|
| 499 | }
|
---|
| 500 | line->num = ix;
|
---|
| 501 | }
|
---|
| 502 |
|
---|
| 503 | /*
|
---|
| 504 | * put_status -- status line を出力する。
|
---|
| 505 | */
|
---|
| 506 |
|
---|
| 507 | static uint16_t
|
---|
| 508 | put_status (ID cepid, T_WWW_RWBUF *srbuf, int_t index)
|
---|
| 509 | {
|
---|
| 510 | uint16_t len = 0;
|
---|
| 511 |
|
---|
| 512 | len += put_str(cepid, srbuf, "HTTP/1.0 ");
|
---|
| 513 | len += put_str(cepid, srbuf, status[index]);
|
---|
| 514 | len += put_str(cepid, srbuf, "\r\n");
|
---|
| 515 | return len;
|
---|
| 516 | }
|
---|
| 517 |
|
---|
| 518 | /*
|
---|
| 519 | * put_content_length -- Content-length を出力する。
|
---|
| 520 | */
|
---|
| 521 |
|
---|
| 522 | static uint16_t
|
---|
| 523 | put_content_length (ID cepid, T_WWW_RWBUF *srbuf, int_t content_len)
|
---|
| 524 | {
|
---|
| 525 | uint16_t len = 0;
|
---|
| 526 | #if 0
|
---|
| 527 | char length[TD_DIGITS + 1];
|
---|
| 528 |
|
---|
| 529 | convert(length, content_len, 10, 0, false, ' ');
|
---|
| 530 | len += put_str(cepid, srbuf, "Content-length: ");
|
---|
| 531 | len += put_str(cepid, srbuf, length);
|
---|
| 532 | len += put_str(cepid, srbuf, "\r\n");
|
---|
| 533 | #endif /* of #if 0 */
|
---|
| 534 | return len;
|
---|
| 535 | }
|
---|
| 536 |
|
---|
| 537 | /*
|
---|
| 538 | * get_method -- GET メソッドの処理
|
---|
| 539 | */
|
---|
| 540 |
|
---|
| 541 | static ER
|
---|
| 542 | get_method (ID cepid, T_WWW_RWBUF *srbuf, T_WWW_LINE *line)
|
---|
| 543 | {
|
---|
| 544 | int_t ix;
|
---|
| 545 |
|
---|
| 546 | for (ix = NUM_FILES; ix -- > 0; ) {
|
---|
| 547 | if (!strcmp(file[ix].uri, &line->buf[line->off[1]])) {
|
---|
| 548 | //syslog(LOG_NOTICE, "[WWWn:%02u PTH] '%s'", cepid, &line->buf[line->off[1]]);
|
---|
| 549 | return (*file[ix].func)(cepid, srbuf);
|
---|
| 550 | }
|
---|
| 551 | }
|
---|
| 552 | put_status(cepid, srbuf, ST_NOT_FOUND);
|
---|
| 553 | return E_NOEXS;
|
---|
| 554 | }
|
---|
| 555 |
|
---|
| 556 | /*
|
---|
| 557 | * parse_request -- リクエストを解析する。
|
---|
| 558 | */
|
---|
| 559 |
|
---|
| 560 | static ER
|
---|
| 561 | parse_request (ID cepid, T_WWW_RWBUF *srbuf)
|
---|
| 562 | {
|
---|
| 563 | T_WWW_LINE *method, *line;
|
---|
| 564 | ER error = E_OK;
|
---|
| 565 | int_t blen = 0;
|
---|
| 566 |
|
---|
| 567 | if ((error = tget_mpf(MPF_WWW_LINE, (void*)&method, TMO_FEVR)) != E_OK) {
|
---|
| 568 | syslog(LOG_CRIT, "[WWWn:%02u MPF] get line error: %s.",
|
---|
| 569 | cepid, itron_strerror(error));
|
---|
| 570 | return error;
|
---|
| 571 | }
|
---|
| 572 |
|
---|
| 573 | if (get_line(cepid, method, srbuf) == 0) {
|
---|
| 574 | if ((error = rel_mpf(MPF_WWW_LINE, method)) != E_OK)
|
---|
| 575 | syslog(LOG_WARNING, "[WWWn:%02u MPF] release line buffer error: %s.",
|
---|
| 576 | cepid, itron_strerror(error));
|
---|
| 577 | return error;
|
---|
| 578 | }
|
---|
| 579 |
|
---|
| 580 | if ((error = tget_mpf(MPF_WWW_LINE, (void*)&line, TMO_FEVR)) != E_OK) {
|
---|
| 581 | syslog(LOG_CRIT, "[WWWn:%02u MPF] get line buffer error: %s.",
|
---|
| 582 | cepid, itron_strerror(error));
|
---|
| 583 | if ((error = rel_mpf(MPF_WWW_LINE, method)) != E_OK)
|
---|
| 584 | syslog(LOG_WARNING, "[WWWn:%02u MPF] release line buffer error: %s.",
|
---|
| 585 | cepid, itron_strerror(error));
|
---|
| 586 | return error;
|
---|
| 587 | }
|
---|
| 588 |
|
---|
| 589 | while (get_line(cepid, line, srbuf) > 0) { /* ヘッダをスキップする。*/
|
---|
| 590 | split_fields(line, ": ");
|
---|
| 591 | if (strcmp("Content-Length", &line->buf[line->off[0]]) == 0)
|
---|
| 592 | blen = atoi(&line->buf[line->off[1]]);
|
---|
| 593 | }
|
---|
| 594 | while (blen > 0 && get_line(cepid, line, srbuf) > 0) {
|
---|
| 595 | /* エンティティ・ボディをスキップする。*/
|
---|
| 596 | blen -= line->len;
|
---|
| 597 | }
|
---|
| 598 |
|
---|
| 599 | if ((error = rel_mpf(MPF_WWW_LINE, line)) != E_OK)
|
---|
| 600 | syslog(LOG_WARNING, "[WWWn:%02u MPF] release line buffer error: %s.",
|
---|
| 601 | cepid, itron_strerror(error));
|
---|
| 602 |
|
---|
| 603 | split_fields(method, ": ");
|
---|
| 604 | if (!strcmp(&method->buf[method->off[0]], "GET"))
|
---|
| 605 | error = get_method(cepid, srbuf, method);
|
---|
| 606 |
|
---|
| 607 | flush_sbuf(cepid, srbuf);
|
---|
| 608 |
|
---|
| 609 | if ((error = rel_mpf(MPF_WWW_LINE, method)) != E_OK)
|
---|
| 610 | syslog(LOG_WARNING, "[WWWn:%02u MPF] release line buffer error: %s.",
|
---|
| 611 | cepid, itron_strerror(error));
|
---|
| 612 |
|
---|
| 613 | return error;
|
---|
| 614 | }
|
---|
| 615 |
|
---|
| 616 | /*
|
---|
| 617 | * index_html -- /index.html ファイル
|
---|
| 618 | */
|
---|
| 619 |
|
---|
| 620 | static ER
|
---|
| 621 | index_html (ID cepid, T_WWW_RWBUF *srbuf)
|
---|
| 622 | {
|
---|
| 623 | static const char response[] =
|
---|
| 624 | "\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD html 3.2//EN\">\r\n"
|
---|
| 625 | "<html><head>\r\n"
|
---|
| 626 |
|
---|
| 627 | #ifdef TOPPERS_S810_CLG3_85
|
---|
| 628 | "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\">\r\n"
|
---|
| 629 | #else
|
---|
| 630 | "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=EUC-JP\">\r\n"
|
---|
| 631 | #endif
|
---|
| 632 |
|
---|
| 633 | "<title>TINET TCP/IP Protocol Stack</title>\r\n"
|
---|
| 634 | "</head><body bgcolor=\"#ffffbb\">\r\n"
|
---|
| 635 | "<hr>この WWW サーバは<br>"
|
---|
| 636 |
|
---|
| 637 | #ifdef TARGET_KERNEL_ASP
|
---|
| 638 | "ASP Kernel for " TARGET_NAME " (" __DATE__ "," __TIME__ ") と<br>\r\n"
|
---|
| 639 | #endif
|
---|
| 640 |
|
---|
| 641 | #ifdef TARGET_KERNEL_JSP
|
---|
| 642 | "JSP Kernel for " TARGET_NAME " (" __DATE__ "," __TIME__ ") と<br>\r\n"
|
---|
| 643 | #endif
|
---|
| 644 |
|
---|
| 645 | "TINET TCP/IP プロトコルスタックによりサービスしています。<br><hr>\r\n"
|
---|
| 646 |
|
---|
| 647 | #if NET_COUNT_ENABLE
|
---|
| 648 |
|
---|
| 649 | "<ul><li type=\"square\"><a href=\"stat.html\">ネットワーク統計情報</a></ul><hr>\r\n"
|
---|
| 650 |
|
---|
| 651 | #else /* of #if NET_COUNT_ENABLE */
|
---|
| 652 |
|
---|
| 653 | "<ul><li type=\"square\">ネットワーク統計情報</ul><hr>\r\n"
|
---|
| 654 |
|
---|
| 655 | #endif /* of #if NET_COUNT_ENABLE */
|
---|
| 656 |
|
---|
| 657 | "FreeBSD: Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994, 1995<br>\r\n"
|
---|
| 658 | "The Regents of the University of California. All rights reserved.<br><br>\r\n"
|
---|
| 659 |
|
---|
| 660 | #ifdef SUPPORT_PPP
|
---|
| 661 |
|
---|
| 662 | "pppd: Copyright (c) 1989 Carnegie Mellon University.<br>\r\n"
|
---|
| 663 | "All rights reserved.<br><br>\r\n"
|
---|
| 664 | "ppp: Written by Toshiharu OHNO (tony-o@iij.ad.jp)<br>\r\n"
|
---|
| 665 | "Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.<br><br>\r\n"
|
---|
| 666 |
|
---|
| 667 | #endif /* of #ifdef SUPPORT_PPP */
|
---|
| 668 |
|
---|
| 669 | #ifdef SUPPORT_ETHER
|
---|
| 670 |
|
---|
| 671 | "if_ed: Copyright (c) 1995, David Greenman<br>\r\n"
|
---|
| 672 | "All rights reserved.<br><br>\r\n"
|
---|
| 673 |
|
---|
| 674 | #endif /* of #ifdef SUPPORT_ETHER */
|
---|
| 675 |
|
---|
| 676 | #ifdef TARGET_KERNEL_ASP
|
---|
| 677 | "TOPPERS/ASP Kernel<br>\r\n"
|
---|
| 678 | "Toyohashi Open Platform for Embedded Real-Time Systems/<br>\r\n"
|
---|
| 679 | "Advanced Standard Profile Kernel<br>\r\n"
|
---|
| 680 | "Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory<br>\r\n"
|
---|
| 681 | "Toyohashi Univ. of Technology, JAPAN<br>\r\n"
|
---|
| 682 | "Copyright (C) 2004-2008 by Embedded and Real-Time Systems Laboratory<br>\r\n"
|
---|
| 683 | "Graduate School of Information Science, Nagoya Univ., JAPAN<br><br>\r\n"
|
---|
| 684 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 685 |
|
---|
| 686 | #ifdef TARGET_KERNEL_JSP
|
---|
| 687 | "TOPPERS/JSP Kernel<br>\r\n"
|
---|
| 688 | "Toyohashi Open Platform for Embedded Real-Time Systems/<br>\r\n"
|
---|
| 689 | "Just Standard Profile Kernel<br>\r\n"
|
---|
| 690 | "Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory<br>\r\n"
|
---|
| 691 | "Toyohashi Univ. of Technology, JAPAN<br>\r\n"
|
---|
| 692 | "Copyright (C) 2005 by Embedded and Real-Time Systems Laboratory<br>\r\n"
|
---|
| 693 | "Graduate School of Information Science, Nagoya Univ., JAPAN<br><br>\r\n"
|
---|
| 694 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
| 695 |
|
---|
| 696 | "TINET (TCP/IP Protocol Stack)<br>\r\n"
|
---|
| 697 | "Copyright (C) 2001-2008 by Dep. of Computer Science and Engineering<br>\r\n"
|
---|
| 698 | "Tomakomai National College of Technology, JAPAN\r\n"
|
---|
| 699 | "</body></html>\r\n"
|
---|
| 700 | ;
|
---|
| 701 |
|
---|
| 702 | SYSTIM start, finish;
|
---|
| 703 | uint16_t len = 0;
|
---|
| 704 |
|
---|
| 705 | get_tim(&start);
|
---|
| 706 | len += put_status(cepid, srbuf, ST_OK);
|
---|
| 707 | len += put_content_length(cepid, srbuf, strlen(response) - 2); /* 2 は最初の \r\n */
|
---|
| 708 | len += put_str(cepid, srbuf, response);
|
---|
| 709 | get_tim(&finish);
|
---|
[364] | 710 | syslog(LOG_NOTICE, "[WWWn:%02u SND] send: index.html, len: %4u, time: %lu [us]",
|
---|
[337] | 711 | cepid, len, (finish - start) * 1000 / SYSTIM_HZ);
|
---|
| 712 | return E_OK;
|
---|
| 713 | }
|
---|
| 714 |
|
---|
| 715 | #if NET_COUNT_ENABLE
|
---|
| 716 |
|
---|
| 717 | #define TD_TEMPLATE1 "<tr><td></td><td align=\"right\"></td>\r\n<td align=\"right\"></td>\r\n<td align=\"right\"></td>\r\n<td align=\"right\"></td>\r\n<td align=\"right\"></td>\r\n<td align=\"right\"></td></tr>\r\n"
|
---|
| 718 | #define TD_TEMPLATE2 "<tr><td></td><td align=\"right\"></td><td align=\"right\"></td></tr>\r\n"
|
---|
| 719 | #define TD_TEMPLATE3 "<tr><td></td><td align=\"right\"></td></tr>\r\n"
|
---|
| 720 | #define TD_TEMPLATE4 "<tr><td></td><td align=\"right\"></td><td align=\"right\"></td><td align=\"right\"></td></tr>\r\n"
|
---|
| 721 |
|
---|
| 722 | #define TD_LEN1(i) (sizeof(i) + sizeof(TD_TEMPLATE1) + TD_DIGITS * 6 - 2)
|
---|
| 723 | #define TD_LEN2(i) (sizeof(i) + sizeof(TD_TEMPLATE2) + TD_DIGITS * 2 - 2)
|
---|
| 724 | #define TD_LEN4(i) (sizeof(i) + sizeof(TD_TEMPLATE4) + TD_DIGITS * 3 - 2)
|
---|
| 725 | #define TD_DIGITS 20
|
---|
| 726 |
|
---|
| 727 | static const char time_prefix[] =
|
---|
| 728 | "経過時間: "
|
---|
| 729 | ;
|
---|
| 730 |
|
---|
| 731 | static const char time_suffix[] =
|
---|
| 732 | "<hr>\r\n"
|
---|
| 733 | ;
|
---|
| 734 |
|
---|
| 735 | static const char table_suffix[] = "</table><br><hr>";
|
---|
| 736 |
|
---|
| 737 | #if defined(SUPPORT_INET4)
|
---|
| 738 |
|
---|
| 739 | static const char table_prefix_ip4[] =
|
---|
| 740 | "<h2>IPv4</h2><table border>\r\n"
|
---|
| 741 | "<tr><th>項目</th><th>カウント</th></tr>\r\n"
|
---|
| 742 | ;
|
---|
| 743 |
|
---|
| 744 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
| 745 |
|
---|
| 746 | #if defined(SUPPORT_INET6)
|
---|
| 747 |
|
---|
| 748 | static const char table_prefix_ip6[] =
|
---|
| 749 | "<h2>IPv6</h2><table border>\r\n"
|
---|
| 750 | "<tr><th>項目</th><th>カウント</th></tr>\r\n"
|
---|
| 751 | ;
|
---|
| 752 |
|
---|
| 753 | static const char table_prefix_icmp6[] =
|
---|
| 754 | "<h2>ICMPv6</h2><table border>\r\n"
|
---|
| 755 | "<tr><th>項目</th><th>カウント</th></tr>\r\n"
|
---|
| 756 | ;
|
---|
| 757 |
|
---|
| 758 | static const char table_prefix_nd6[] =
|
---|
| 759 | "<h2>近隣探索</h2><table border>\r\n"
|
---|
| 760 | "<tr><th>項目</th><th>カウント</th></tr>\r\n"
|
---|
| 761 | ;
|
---|
| 762 |
|
---|
| 763 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
| 764 |
|
---|
| 765 | static const char table_prefix_tcp[] =
|
---|
| 766 | "<h2>TCP</h2><table border>\r\n"
|
---|
| 767 | "<tr><th>項目</th><th>カウント</th></tr>\r\n"
|
---|
| 768 | ;
|
---|
| 769 |
|
---|
| 770 | static const char table_prefix_net_buf[] =
|
---|
| 771 | "<h2>ネットワークバッファ</h2><table border>\r\n"
|
---|
| 772 | "<tr><th>サイズ</th>"
|
---|
| 773 | "<th>用意数</th>"
|
---|
| 774 | "<th>割当要求数</th>"
|
---|
| 775 | "<th>割当数</th>"
|
---|
| 776 | "<th>割当て<br>エラー数</th></tr>\r\n"
|
---|
| 777 | ;
|
---|
| 778 |
|
---|
| 779 | #ifdef SUPPORT_PPP
|
---|
| 780 |
|
---|
| 781 | static const char table_prefix_ppp[] =
|
---|
| 782 | "<h2>PPP ネットワークインタフェース</h2><table border>\r\n"
|
---|
| 783 | "<tr><th>項目</th><th>カウント</th></tr>\r\n"
|
---|
| 784 | ;
|
---|
| 785 |
|
---|
| 786 | static const char *ppp_item[NC_PPP_SIZE] = {
|
---|
| 787 | "受信オクテット数",
|
---|
| 788 | "送信オクテット数",
|
---|
| 789 | "受信フレーム数",
|
---|
| 790 | "送信フレーム数",
|
---|
| 791 | "受信エラーフレーム数",
|
---|
| 792 | "送信エラーフレーム数",
|
---|
| 793 | "バッファ割り当て失敗数",
|
---|
| 794 | };
|
---|
| 795 |
|
---|
| 796 | #endif /* of #ifdef SUPPORT_PPP */
|
---|
| 797 |
|
---|
| 798 | #ifdef SUPPORT_ETHER
|
---|
| 799 |
|
---|
| 800 | static const char table_prefix_ether_nic[] =
|
---|
| 801 | "<h2>イーサネット・ネットワークインタフェース</h2><table border>\r\n"
|
---|
| 802 | "<tr><th>項目</th><th>カウント</th></tr>\r\n"
|
---|
| 803 | ;
|
---|
| 804 |
|
---|
| 805 | static const char *ether_nic_item[NC_ETHER_NIC_SIZE] = {
|
---|
| 806 | "リセット数",
|
---|
| 807 | "送信セマフォ資源返却オーバー数",
|
---|
| 808 | "送信タイムアウト数",
|
---|
| 809 | "衝突数",
|
---|
| 810 | "送信エラーフレーム数",
|
---|
| 811 | "送信フレーム数",
|
---|
| 812 | "送信オクテット数",
|
---|
| 813 | "受信セマフォ資源返却オーバー数",
|
---|
| 814 | "受信バッファ割り当て失敗数",
|
---|
| 815 | "受信エラーフレーム数",
|
---|
| 816 | "受信フレーム数",
|
---|
| 817 | "受信オクテット数",
|
---|
| 818 | };
|
---|
| 819 |
|
---|
| 820 | #endif /* of #ifdef SUPPORT_ETHER */
|
---|
| 821 |
|
---|
| 822 | #if defined(SUPPORT_INET4)
|
---|
| 823 |
|
---|
| 824 | static const char *ip4_item[NC_IP4_SIZE] = {
|
---|
| 825 | "分割送信、フラグメント数",
|
---|
| 826 | "分割送信数",
|
---|
| 827 | "送信エラーデータグラム数",
|
---|
| 828 | "送信データグラム数",
|
---|
| 829 | "送信オクテット数",
|
---|
| 830 | "分割受信タイムアウト数",
|
---|
| 831 | "分割受信バッファ割り当て失敗数",
|
---|
| 832 | "分割受信破棄数",
|
---|
| 833 | "分割受信再構成成功数",
|
---|
| 834 | "分割受信フラグメント数",
|
---|
| 835 | "分割受信数",
|
---|
| 836 | "オプション入力数",
|
---|
| 837 | "プロトコルエラー数",
|
---|
| 838 | "アドレスエラー数",
|
---|
| 839 | "バージョンエラー数",
|
---|
| 840 | "長さエラー数",
|
---|
| 841 | "チェックサムエラー数",
|
---|
| 842 | "受信エラーデータグラム数",
|
---|
| 843 | "受信データグラム数",
|
---|
| 844 | "受信オクテット数",
|
---|
| 845 | };
|
---|
| 846 |
|
---|
| 847 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
| 848 |
|
---|
| 849 | #if defined(SUPPORT_INET6)
|
---|
| 850 |
|
---|
| 851 | static const char *ip6_item[NC_IP6_SIZE] = {
|
---|
| 852 | "分割送信、フラグメント数",
|
---|
| 853 | "分割送信数",
|
---|
| 854 | "送信エラーデータグラム数",
|
---|
| 855 | "送信データグラム数",
|
---|
| 856 | "送信オクテット数 ",
|
---|
| 857 | "分割受信タイムアウト数",
|
---|
| 858 | "分割受信バッファ割り当て失敗数",
|
---|
| 859 | "分割受信破棄数",
|
---|
| 860 | "分割受信再構成成功数",
|
---|
| 861 | "分割受信フラグメント数",
|
---|
| 862 | "分割受信数",
|
---|
| 863 | "プロトコルエラー数 ",
|
---|
| 864 | "アドレスエラー数 ",
|
---|
| 865 | "バージョンエラー数 ",
|
---|
| 866 | "長さエラー数",
|
---|
| 867 | "受信エラーデータグラム数",
|
---|
| 868 | "受信データグラム数",
|
---|
| 869 | "受信オクテット数 ",
|
---|
| 870 | };
|
---|
| 871 |
|
---|
| 872 | static const char *icmp6_item[NC_ICMP6_SIZE] = {
|
---|
| 873 | "送信エラー ICMP データ数 ",
|
---|
| 874 | "送信 ICMP データ数",
|
---|
| 875 | "送信 ICMP オクテット数",
|
---|
| 876 | "長さエラー数",
|
---|
| 877 | "受信エラー ICMP データ数 ",
|
---|
| 878 | "受信 ICMP データ数",
|
---|
| 879 | "受信 ICMP オクテット数",
|
---|
| 880 | };
|
---|
| 881 |
|
---|
| 882 | static const char *nd6_item[NC_ND6_SIZE] = {
|
---|
| 883 | "重複アドレス検出送信数",
|
---|
| 884 | "近隣要請送信数",
|
---|
| 885 | "近隣要請受信数",
|
---|
| 886 | "近隣通知送信数",
|
---|
| 887 | "近隣通知受信数",
|
---|
| 888 | "ルータ要請出力数",
|
---|
| 889 | "ルータ通知受信数",
|
---|
| 890 | };
|
---|
| 891 |
|
---|
| 892 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
| 893 |
|
---|
| 894 | static const char *tcp_item[NC_TCP_SIZE] = {
|
---|
| 895 | "能動オープン数",
|
---|
| 896 | "受動オープン数",
|
---|
| 897 | "RTT 更新数",
|
---|
| 898 | "送信 RST 数",
|
---|
| 899 | "送信 ACK 数",
|
---|
| 900 | "送信緊急セグメント数",
|
---|
| 901 | "送信データセグメント数",
|
---|
| 902 | "再送セグメント数",
|
---|
| 903 | "送信セグメント数",
|
---|
| 904 | "送信制御セグメント数",
|
---|
| 905 | "送信データオクテット数",
|
---|
| 906 | "受信キュー解放数",
|
---|
| 907 | "受信多重数",
|
---|
| 908 | "受信破棄数",
|
---|
| 909 | "受信 RST 数",
|
---|
| 910 | "受信多重 ACK 数",
|
---|
| 911 | "受信 ACK 数",
|
---|
| 912 | "受信チェックサム不正数",
|
---|
| 913 | "受信ヘッダ不正数",
|
---|
| 914 | "受信緊急セグメント数",
|
---|
| 915 | "受信データセグメント数",
|
---|
| 916 | "受信セグメント数",
|
---|
| 917 | "受信データオクテット数",
|
---|
| 918 | "受信オクテット数",
|
---|
| 919 | };
|
---|
| 920 |
|
---|
| 921 | /*
|
---|
| 922 | * put_count_item1 -- カウンタの内容を出力する。グループ 1
|
---|
| 923 | */
|
---|
| 924 |
|
---|
| 925 | static uint16_t
|
---|
| 926 | put_count_item1 (ID cepid, T_WWW_RWBUF *srbuf, const char *item, T_NET_COUNT *counter)
|
---|
| 927 | {
|
---|
| 928 | char buf[TD_DIGITS + 1];
|
---|
| 929 | uint16_t len = 0;
|
---|
| 930 |
|
---|
| 931 | len += put_str(cepid, srbuf, "<tr><td>");
|
---|
| 932 | len += put_str(cepid, srbuf, item);
|
---|
| 933 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 934 |
|
---|
| 935 | convert(buf, counter->in_octets, 10, TD_DIGITS, false, ' ');
|
---|
| 936 | len += put_str(cepid, srbuf, buf);
|
---|
| 937 | len += put_str(cepid, srbuf, "</td>\r\n<td align=\"right\">");
|
---|
| 938 |
|
---|
| 939 | convert(buf, counter->out_octets, 10, TD_DIGITS, false, ' ');
|
---|
| 940 | len += put_str(cepid, srbuf, buf);
|
---|
| 941 | len += put_str(cepid, srbuf, "</td>\r\n<td align=\"right\">");
|
---|
| 942 |
|
---|
| 943 | convert(buf, counter->in_packets, 10, TD_DIGITS, false, ' ');
|
---|
| 944 | len += put_str(cepid, srbuf, buf);
|
---|
| 945 | len += put_str(cepid, srbuf, "</td>\r\n<td align=\"right\">");
|
---|
| 946 |
|
---|
| 947 | convert(buf, counter->out_packets, 10, TD_DIGITS, false, ' ');
|
---|
| 948 | len += put_str(cepid, srbuf, buf);
|
---|
| 949 | len += put_str(cepid, srbuf, "</td>\r\n<td align=\"right\">");
|
---|
| 950 |
|
---|
| 951 | convert(buf, counter->in_err_packets, 10, TD_DIGITS, false, ' ');
|
---|
| 952 | len += put_str(cepid, srbuf, buf);
|
---|
| 953 | len += put_str(cepid, srbuf, "</td>\r\n<td align=\"right\">");
|
---|
| 954 |
|
---|
| 955 | convert(buf, counter->out_err_packets, 10, TD_DIGITS, false, ' ');
|
---|
| 956 | len += put_str(cepid, srbuf, buf);
|
---|
| 957 | len += put_str(cepid, srbuf, "</td></tr>\r\n");
|
---|
| 958 |
|
---|
| 959 | return len;
|
---|
| 960 | }
|
---|
| 961 |
|
---|
| 962 | #ifdef SUPPORT_PPP
|
---|
| 963 |
|
---|
| 964 | /*
|
---|
| 965 | * put_count_item2 -- カウンタの内容を出力する。グループ 2
|
---|
| 966 | */
|
---|
| 967 |
|
---|
| 968 | static uint16_t
|
---|
| 969 | put_count_item2 (ID cepid, T_WWW_RWBUF *srbuf, const char *item, uint32_t octets, uint32_t packets)
|
---|
| 970 | {
|
---|
| 971 | char buf[TD_DIGITS + 1];
|
---|
| 972 | uint16_t len = 0;
|
---|
| 973 |
|
---|
| 974 | len += put_str(cepid, srbuf, "<tr><td>");
|
---|
| 975 | len += put_str(cepid, srbuf, item);
|
---|
| 976 | len += put_str(cepid, srbuf, "</td><td>");
|
---|
| 977 |
|
---|
| 978 | convert(buf, octets, 10, TD_DIGITS, false, ' ');
|
---|
| 979 | len += put_str(cepid, srbuf, buf);
|
---|
| 980 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 981 |
|
---|
| 982 | convert(buf, packets, 10, TD_DIGITS, false, ' ');
|
---|
| 983 | len += put_str(cepid, srbuf, buf);
|
---|
| 984 | len += put_str(cepid, srbuf, "</td></tr>\r\n");
|
---|
| 985 |
|
---|
| 986 | return len;
|
---|
| 987 | }
|
---|
| 988 |
|
---|
| 989 | /*
|
---|
| 990 | * td_len_ppp -- put_count_ppp で出力する文字数。
|
---|
| 991 | */
|
---|
| 992 |
|
---|
| 993 | static uint16_t
|
---|
| 994 | td_len_ppp (void)
|
---|
| 995 | {
|
---|
| 996 | int_t ix;
|
---|
| 997 | uint16_t len = 0;
|
---|
| 998 |
|
---|
| 999 | for (ix = NC_PPP_SIZE; ix -- > 0; )
|
---|
| 1000 | len += strlen(ppp_item[ix]);
|
---|
| 1001 | return len + (sizeof(TD_TEMPLATE3) + TD_DIGITS - 1) * NC_PPP_SIZE;
|
---|
| 1002 | }
|
---|
| 1003 |
|
---|
| 1004 | /*
|
---|
| 1005 | * put_count_ppp -- カウンタ (PPP) の内容を出力する。
|
---|
| 1006 | */
|
---|
| 1007 |
|
---|
| 1008 | static uint16_t
|
---|
| 1009 | put_count_ppp (ID cepid, T_WWW_RWBUF *srbuf)
|
---|
| 1010 | {
|
---|
| 1011 |
|
---|
| 1012 | char buf[TD_DIGITS + 1];
|
---|
| 1013 | uint16_t len = 0;
|
---|
| 1014 |
|
---|
| 1015 | len += put_str(cepid, srbuf, table_prefix_ppp);
|
---|
| 1016 |
|
---|
| 1017 | len += put_str(cepid, srbuf, "<tr><td>");
|
---|
| 1018 | len += put_str(cepid, srbuf, ppp_item[0]);
|
---|
| 1019 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1020 | convert(buf, net_count_ppp.in_octets, 10, TD_DIGITS, false, ' ');
|
---|
| 1021 | len += put_str(cepid, srbuf, buf);
|
---|
| 1022 | len += put_str(cepid, srbuf, "</td></tr>\r\n");
|
---|
| 1023 |
|
---|
| 1024 | len += put_str(cepid, srbuf, "<tr><td>");
|
---|
| 1025 | len += put_str(cepid, srbuf, ppp_item[1]);
|
---|
| 1026 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1027 | convert(buf, net_count_ppp.out_octets, 10, TD_DIGITS, false, ' ');
|
---|
| 1028 | len += put_str(cepid, srbuf, buf);
|
---|
| 1029 | len += put_str(cepid, srbuf, "</td></tr>\r\n");
|
---|
| 1030 |
|
---|
| 1031 | len += put_str(cepid, srbuf, "<tr><td>");
|
---|
| 1032 | len += put_str(cepid, srbuf, ppp_item[2]);
|
---|
| 1033 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1034 | convert(buf, net_count_ppp.in_packets, 10, TD_DIGITS, false, ' ');
|
---|
| 1035 | len += put_str(cepid, srbuf, buf);
|
---|
| 1036 | len += put_str(cepid, srbuf, "</td></tr>\r\n");
|
---|
| 1037 |
|
---|
| 1038 | len += put_str(cepid, srbuf, "<tr><td>");
|
---|
| 1039 | len += put_str(cepid, srbuf, ppp_item[3]);
|
---|
| 1040 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1041 | convert(buf, net_count_ppp.out_packets, 10, TD_DIGITS, false, ' ');
|
---|
| 1042 | len += put_str(cepid, srbuf, buf);
|
---|
| 1043 | len += put_str(cepid, srbuf, "</td></tr>\r\n");
|
---|
| 1044 |
|
---|
| 1045 | len += put_str(cepid, srbuf, "<tr><td>");
|
---|
| 1046 | len += put_str(cepid, srbuf, ppp_item[4]);
|
---|
| 1047 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1048 | convert(buf, net_count_ppp.in_err_packets, 10, TD_DIGITS, false, ' ');
|
---|
| 1049 | len += put_str(cepid, srbuf, buf);
|
---|
| 1050 | len += put_str(cepid, srbuf, "</td></tr>\r\n");
|
---|
| 1051 |
|
---|
| 1052 | len += put_str(cepid, srbuf, "<tr><td>");
|
---|
| 1053 | len += put_str(cepid, srbuf, ppp_item[5]);
|
---|
| 1054 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1055 | convert(buf, net_count_ppp.out_err_packets, 10, TD_DIGITS, false, ' ');
|
---|
| 1056 | len += put_str(cepid, srbuf, buf);
|
---|
| 1057 | len += put_str(cepid, srbuf, "</td></tr>\r\n");
|
---|
| 1058 |
|
---|
| 1059 | len += put_str(cepid, srbuf, "<tr><td>");
|
---|
| 1060 | len += put_str(cepid, srbuf, ppp_item[6]);
|
---|
| 1061 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1062 | convert(buf, net_count_ppp_no_bufs, 10, TD_DIGITS, false, ' ');
|
---|
| 1063 | len += put_str(cepid, srbuf, buf);
|
---|
| 1064 | len += put_str(cepid, srbuf, "</td></tr>\r\n");
|
---|
| 1065 |
|
---|
| 1066 | len += put_str(cepid, srbuf, table_suffix);
|
---|
| 1067 |
|
---|
| 1068 | return len;
|
---|
| 1069 | }
|
---|
| 1070 |
|
---|
| 1071 | #endif /* of #ifdef SUPPORT_PPP */
|
---|
| 1072 |
|
---|
| 1073 | #if defined(SUPPORT_INET4)
|
---|
| 1074 |
|
---|
| 1075 | /*
|
---|
| 1076 | * td_len_ip4 -- put_count_ip4 で出力する文字数。
|
---|
| 1077 | */
|
---|
| 1078 |
|
---|
| 1079 | static uint16_t
|
---|
| 1080 | td_len_ip4 (void)
|
---|
| 1081 | {
|
---|
| 1082 | int_t ix;
|
---|
| 1083 | uint16_t len = 0;
|
---|
| 1084 |
|
---|
| 1085 | for (ix = NC_IP4_SIZE; ix -- > 0; )
|
---|
| 1086 | len += strlen(ip4_item[ix]);
|
---|
| 1087 | return len + (sizeof(TD_TEMPLATE3) + TD_DIGITS - 1) * NC_IP4_SIZE;
|
---|
| 1088 | }
|
---|
| 1089 |
|
---|
| 1090 | /*
|
---|
| 1091 | * put_count_ip4 -- カウンタ (IP4) の内容を出力する。
|
---|
| 1092 | */
|
---|
| 1093 |
|
---|
| 1094 | static uint16_t
|
---|
| 1095 | put_count_ip4 (ID cepid, T_WWW_RWBUF *srbuf)
|
---|
| 1096 | {
|
---|
| 1097 | char buf[TD_DIGITS + 1];
|
---|
| 1098 | uint16_t len = 0;
|
---|
| 1099 | int_t ix;
|
---|
| 1100 |
|
---|
| 1101 | len += put_str(cepid, srbuf, table_prefix_ip4);
|
---|
| 1102 | for (ix = NC_IP4_SIZE; ix -- > 0; ) {
|
---|
| 1103 | len += put_str(cepid, srbuf, "<tr><td>");
|
---|
| 1104 | len += put_str(cepid, srbuf, ip4_item[ix]);
|
---|
| 1105 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1106 | convert(buf, net_count_ip4[ix], 10, TD_DIGITS, false, ' ');
|
---|
| 1107 | len += put_str(cepid, srbuf, buf);
|
---|
| 1108 | len += put_str(cepid, srbuf, "</td></tr>\r\n");
|
---|
| 1109 | }
|
---|
| 1110 | len += put_str(cepid, srbuf, table_suffix);
|
---|
| 1111 |
|
---|
| 1112 | return len;
|
---|
| 1113 | }
|
---|
| 1114 |
|
---|
| 1115 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
| 1116 |
|
---|
| 1117 | #if defined(SUPPORT_INET6)
|
---|
| 1118 |
|
---|
| 1119 | /*
|
---|
| 1120 | * td_len_nd6 -- put_count_nd6 で出力する文字数。
|
---|
| 1121 | */
|
---|
| 1122 |
|
---|
| 1123 | static uint16_t
|
---|
| 1124 | td_len_nd6 (void)
|
---|
| 1125 | {
|
---|
| 1126 | int_t ix;
|
---|
| 1127 | uint16_t len = 0;
|
---|
| 1128 |
|
---|
| 1129 | for (ix = NC_ND6_SIZE; ix -- > 0; )
|
---|
| 1130 | len += strlen(nd6_item[ix]);
|
---|
| 1131 | return len + (sizeof(TD_TEMPLATE3) + TD_DIGITS - 1) * NC_ND6_SIZE;
|
---|
| 1132 | }
|
---|
| 1133 |
|
---|
| 1134 | /*
|
---|
| 1135 | * put_count_nd6 -- カウンタ (ND6) の内容を出力する。
|
---|
| 1136 | */
|
---|
| 1137 |
|
---|
| 1138 | static uint16_t
|
---|
| 1139 | put_count_nd6 (ID cepid, T_WWW_RWBUF *srbuf)
|
---|
| 1140 | {
|
---|
| 1141 | char buf[TD_DIGITS + 1];
|
---|
| 1142 | uint16_t len = 0;
|
---|
| 1143 | int_t ix;
|
---|
| 1144 |
|
---|
| 1145 | len += put_str(cepid, srbuf, table_prefix_nd6);
|
---|
| 1146 | for (ix = NC_ND6_SIZE; ix -- > 0; ) {
|
---|
| 1147 | len += put_str(cepid, srbuf, "<tr><td>");
|
---|
| 1148 | len += put_str(cepid, srbuf, nd6_item[ix]);
|
---|
| 1149 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1150 | convert(buf, net_count_nd6[ix], 10, TD_DIGITS, false, ' ');
|
---|
| 1151 | len += put_str(cepid, srbuf, buf);
|
---|
| 1152 | len += put_str(cepid, srbuf, "</td></tr>\r\n");
|
---|
| 1153 | }
|
---|
| 1154 | len += put_str(cepid, srbuf, table_suffix);
|
---|
| 1155 |
|
---|
| 1156 | return len;
|
---|
| 1157 | }
|
---|
| 1158 |
|
---|
| 1159 | /*
|
---|
| 1160 | * td_len_icmp6 -- put_count_icmp6 で出力する文字数。
|
---|
| 1161 | */
|
---|
| 1162 |
|
---|
| 1163 | static uint16_t
|
---|
| 1164 | td_len_icmp6 (void)
|
---|
| 1165 | {
|
---|
| 1166 | int_t ix;
|
---|
| 1167 | uint16_t len = 0;
|
---|
| 1168 |
|
---|
| 1169 | for (ix = NC_ICMP6_SIZE; ix -- > 0; )
|
---|
| 1170 | len += strlen(icmp6_item[ix]);
|
---|
| 1171 | return len + (sizeof(TD_TEMPLATE3) + TD_DIGITS - 1) * NC_ICMP6_SIZE;
|
---|
| 1172 | }
|
---|
| 1173 |
|
---|
| 1174 | /*
|
---|
| 1175 | * put_count_icmp6 -- カウンタ (ICMP6) の内容を出力する。
|
---|
| 1176 | */
|
---|
| 1177 |
|
---|
| 1178 | static uint16_t
|
---|
| 1179 | put_count_icmp6 (ID cepid, T_WWW_RWBUF *srbuf)
|
---|
| 1180 | {
|
---|
| 1181 | char buf[TD_DIGITS + 1];
|
---|
| 1182 | uint16_t len = 0;
|
---|
| 1183 | int_t ix;
|
---|
| 1184 |
|
---|
| 1185 | len += put_str(cepid, srbuf, table_prefix_icmp6);
|
---|
| 1186 | for (ix = NC_ICMP6_SIZE; ix -- > 0; ) {
|
---|
| 1187 | len += put_str(cepid, srbuf, "<tr><td>");
|
---|
| 1188 | len += put_str(cepid, srbuf, icmp6_item[ix]);
|
---|
| 1189 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1190 | convert(buf, net_count_icmp6[ix], 10, TD_DIGITS, false, ' ');
|
---|
| 1191 | len += put_str(cepid, srbuf, buf);
|
---|
| 1192 | len += put_str(cepid, srbuf, "</td></tr>\r\n");
|
---|
| 1193 | }
|
---|
| 1194 | len += put_str(cepid, srbuf, table_suffix);
|
---|
| 1195 |
|
---|
| 1196 | return len;
|
---|
| 1197 | }
|
---|
| 1198 |
|
---|
| 1199 | /*
|
---|
| 1200 | * td_len_ip6 -- put_count_ip6 で出力する文字数。
|
---|
| 1201 | */
|
---|
| 1202 |
|
---|
| 1203 | static uint16_t
|
---|
| 1204 | td_len_ip6 (void)
|
---|
| 1205 | {
|
---|
| 1206 | int_t ix;
|
---|
| 1207 | uint16_t len = 0;
|
---|
| 1208 |
|
---|
| 1209 | for (ix = NC_IP6_SIZE; ix -- > 0; )
|
---|
| 1210 | len += strlen(ip6_item[ix]);
|
---|
| 1211 | return len + (sizeof(TD_TEMPLATE3) + TD_DIGITS - 1) * NC_IP6_SIZE;
|
---|
| 1212 | }
|
---|
| 1213 |
|
---|
| 1214 | /*
|
---|
| 1215 | * put_count_ip6 -- カウンタ (IP6) の内容を出力する。
|
---|
| 1216 | */
|
---|
| 1217 |
|
---|
| 1218 | static uint16_t
|
---|
| 1219 | put_count_ip6 (ID cepid, T_WWW_RWBUF *srbuf)
|
---|
| 1220 | {
|
---|
| 1221 | char buf[TD_DIGITS + 1];
|
---|
| 1222 | uint16_t len = 0;
|
---|
| 1223 | int_t ix;
|
---|
| 1224 |
|
---|
| 1225 | len += put_str(cepid, srbuf, table_prefix_ip6);
|
---|
| 1226 | for (ix = NC_IP6_SIZE; ix -- > 0; ) {
|
---|
| 1227 | len += put_str(cepid, srbuf, "<tr><td>");
|
---|
| 1228 | len += put_str(cepid, srbuf, ip6_item[ix]);
|
---|
| 1229 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1230 | convert(buf, net_count_ip6[ix], 10, TD_DIGITS, false, ' ');
|
---|
| 1231 | len += put_str(cepid, srbuf, buf);
|
---|
| 1232 | len += put_str(cepid, srbuf, "</td></tr>\r\n");
|
---|
| 1233 | }
|
---|
| 1234 | len += put_str(cepid, srbuf, table_suffix);
|
---|
| 1235 |
|
---|
| 1236 | return len;
|
---|
| 1237 | }
|
---|
| 1238 |
|
---|
| 1239 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
| 1240 |
|
---|
| 1241 | /*
|
---|
| 1242 | * td_len_tcp -- put_count_tcp で出力する文字数。
|
---|
| 1243 | */
|
---|
| 1244 |
|
---|
| 1245 | static uint16_t
|
---|
| 1246 | td_len_tcp (void)
|
---|
| 1247 | {
|
---|
| 1248 | int_t ix;
|
---|
| 1249 | uint16_t len = 0;
|
---|
| 1250 |
|
---|
| 1251 | for (ix = NC_TCP_SIZE; ix -- > 0; )
|
---|
| 1252 | len += strlen(tcp_item[ix]);
|
---|
| 1253 | return len + (sizeof(TD_TEMPLATE3) + TD_DIGITS - 1) * NC_TCP_SIZE;
|
---|
| 1254 | }
|
---|
| 1255 |
|
---|
| 1256 | /*
|
---|
| 1257 | * put_count_tcp -- カウンタ (TCP) の内容を出力する。
|
---|
| 1258 | */
|
---|
| 1259 |
|
---|
| 1260 | static uint16_t
|
---|
| 1261 | put_count_tcp (ID cepid, T_WWW_RWBUF *srbuf)
|
---|
| 1262 | {
|
---|
| 1263 | char buf[TD_DIGITS + 1];
|
---|
| 1264 | uint16_t len = 0;
|
---|
| 1265 | int_t ix;
|
---|
| 1266 |
|
---|
| 1267 | len += put_str(cepid, srbuf, table_prefix_tcp);
|
---|
| 1268 | for (ix = NC_TCP_SIZE; ix -- > 0; ) {
|
---|
| 1269 | len += put_str(cepid, srbuf, "<tr><td>");
|
---|
| 1270 | len += put_str(cepid, srbuf, tcp_item[ix]);
|
---|
| 1271 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1272 | convert(buf, net_count_tcp[ix], 10, TD_DIGITS, false, ' ');
|
---|
| 1273 | len += put_str(cepid, srbuf, buf);
|
---|
| 1274 | len += put_str(cepid, srbuf, "</td></tr>\r\n");
|
---|
| 1275 | }
|
---|
| 1276 | len += put_str(cepid, srbuf, table_suffix);
|
---|
| 1277 |
|
---|
| 1278 | return len;
|
---|
| 1279 | }
|
---|
| 1280 |
|
---|
| 1281 | /*
|
---|
| 1282 | * put_elapse_time -- 経過時間を出力する。
|
---|
| 1283 | */
|
---|
| 1284 |
|
---|
| 1285 | static uint16_t
|
---|
| 1286 | put_elapse_time (ID cepid, T_WWW_RWBUF *srbuf)
|
---|
| 1287 | {
|
---|
| 1288 | SYSTIM now, elapse;
|
---|
| 1289 | char buf[TD_DIGITS + 1];
|
---|
| 1290 | uint16_t len = 0;
|
---|
| 1291 |
|
---|
| 1292 | get_tim(&now);
|
---|
| 1293 | elapse = now - srv_start;
|
---|
| 1294 |
|
---|
| 1295 | len += put_str(cepid, srbuf, time_prefix);
|
---|
| 1296 |
|
---|
| 1297 | convert(buf, elapse / (60 * 60 * SYSTIM_HZ), 10, 4, false, ' ');
|
---|
| 1298 | len += put_str(cepid, srbuf, buf);
|
---|
| 1299 | len += put_str(cepid, srbuf, ":");
|
---|
| 1300 |
|
---|
| 1301 | convert(buf, (elapse / (60 * SYSTIM_HZ)) % 60, 10, 2, false, ' ');
|
---|
| 1302 | len += put_str(cepid, srbuf, buf);
|
---|
| 1303 | len += put_str(cepid, srbuf, ":");
|
---|
| 1304 |
|
---|
| 1305 | convert(buf, (elapse / SYSTIM_HZ) % 60, 10, 2, false, ' ');
|
---|
| 1306 | len += put_str(cepid, srbuf, buf);
|
---|
| 1307 |
|
---|
| 1308 | len += put_str(cepid, srbuf, time_suffix);
|
---|
| 1309 |
|
---|
| 1310 | return len;
|
---|
| 1311 | }
|
---|
| 1312 |
|
---|
| 1313 | /*
|
---|
| 1314 | * put_count_net_buf -- カウンタ (TCP) の内容を出力する。
|
---|
| 1315 | */
|
---|
| 1316 |
|
---|
| 1317 | static uint16_t
|
---|
| 1318 | put_count_net_buf (ID cepid, T_WWW_RWBUF *srbuf)
|
---|
| 1319 | {
|
---|
| 1320 |
|
---|
| 1321 | const T_NET_BUF_ENTRY *tbl;
|
---|
| 1322 | char buf[TD_DIGITS + 1];
|
---|
| 1323 | uint16_t len = 0;
|
---|
| 1324 | int_t ix;
|
---|
| 1325 |
|
---|
| 1326 | len += put_str(cepid, srbuf, table_prefix_net_buf);
|
---|
| 1327 | tbl = nbuf_get_tbl();
|
---|
| 1328 | for (ix = nbuf_get_tbl_size(); ix -- > 0; ) {
|
---|
| 1329 | len += put_str(cepid, srbuf, "<tr><td align=\"right\">");
|
---|
| 1330 | convert(buf, tbl[ix].size, 10, 4, false, ' ');
|
---|
| 1331 | len += put_str(cepid, srbuf, buf);
|
---|
| 1332 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1333 | convert(buf, tbl[ix].prepares, 10, TD_DIGITS, false, ' ');
|
---|
| 1334 | len += put_str(cepid, srbuf, buf);
|
---|
| 1335 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1336 | convert(buf, tbl[ix].requests, 10, TD_DIGITS, false, ' ');
|
---|
| 1337 | len += put_str(cepid, srbuf, buf);
|
---|
| 1338 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1339 | convert(buf, tbl[ix].allocs, 10, TD_DIGITS, false, ' ');
|
---|
| 1340 | len += put_str(cepid, srbuf, buf);
|
---|
| 1341 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1342 | convert(buf, tbl[ix].errors, 10, TD_DIGITS, false, ' ');
|
---|
| 1343 | len += put_str(cepid, srbuf, buf);
|
---|
| 1344 | len += put_str(cepid, srbuf, "</td></tr>\r\n");
|
---|
| 1345 | }
|
---|
| 1346 | len += put_str(cepid, srbuf, table_suffix);
|
---|
| 1347 |
|
---|
| 1348 | return len;
|
---|
| 1349 | }
|
---|
| 1350 |
|
---|
| 1351 | #ifdef SUPPORT_ETHER
|
---|
| 1352 |
|
---|
| 1353 | /*
|
---|
| 1354 | * td_len_ether_nic -- put_count_ether_nic で出力する文字数。
|
---|
| 1355 | */
|
---|
| 1356 |
|
---|
| 1357 | static uint16_t
|
---|
| 1358 | td_len_ether_nic (void)
|
---|
| 1359 | {
|
---|
| 1360 | int_t ix;
|
---|
| 1361 | uint16_t len = 0;
|
---|
| 1362 |
|
---|
| 1363 | for (ix = NC_ETHER_NIC_SIZE; ix -- > 0; )
|
---|
| 1364 | len += strlen(ether_nic_item[ix]);
|
---|
| 1365 | return len + (sizeof(TD_TEMPLATE3) + TD_DIGITS - 1) * NC_ETHER_NIC_SIZE;
|
---|
| 1366 | }
|
---|
| 1367 |
|
---|
| 1368 | /*
|
---|
| 1369 | * put_count_ether_nic -- カウンタ (ETHER_NIC) の内容を出力する。
|
---|
| 1370 | */
|
---|
| 1371 |
|
---|
| 1372 | static uint16_t
|
---|
| 1373 | put_count_ether_nic (ID cepid, T_WWW_RWBUF *srbuf)
|
---|
| 1374 | {
|
---|
| 1375 | char buf[TD_DIGITS + 1];
|
---|
| 1376 | uint16_t len = 0;
|
---|
| 1377 | int_t ix;
|
---|
| 1378 |
|
---|
| 1379 | len += put_str(cepid, srbuf, table_prefix_ether_nic);
|
---|
| 1380 | for (ix = NC_ETHER_NIC_SIZE; ix -- > 0; ) {
|
---|
| 1381 | len += put_str(cepid, srbuf, "<tr><td>");
|
---|
| 1382 | len += put_str(cepid, srbuf, ether_nic_item[ix]);
|
---|
| 1383 | len += put_str(cepid, srbuf, "</td><td align=\"right\">");
|
---|
| 1384 | convert(buf, net_count_ether_nic[ix], 10, TD_DIGITS, false, ' ');
|
---|
| 1385 | len += put_str(cepid, srbuf, buf);
|
---|
| 1386 | len += put_str(cepid, srbuf, "</td></tr>\r\n");
|
---|
| 1387 | }
|
---|
| 1388 | len += put_str(cepid, srbuf, table_suffix);
|
---|
| 1389 |
|
---|
| 1390 | return len;
|
---|
| 1391 | }
|
---|
| 1392 |
|
---|
| 1393 | #endif /* of #ifdef SUPPORT_ETHER */
|
---|
| 1394 |
|
---|
| 1395 | /*
|
---|
| 1396 | * stat_html -- /stat.html ファイル
|
---|
| 1397 | */
|
---|
| 1398 |
|
---|
| 1399 | static ER
|
---|
| 1400 | stat_html (ID cepid, T_WWW_RWBUF *srbuf)
|
---|
| 1401 | {
|
---|
| 1402 | static const char res_prefix[] =
|
---|
| 1403 | "\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD html 3.2//EN\">\r\n"
|
---|
| 1404 | "<html><head>\r\n"
|
---|
| 1405 |
|
---|
| 1406 | #ifdef TOPPERS_S810_CLG3_85
|
---|
| 1407 | "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\">\r\n"
|
---|
| 1408 | #else
|
---|
| 1409 | "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=EUC-JP\">\r\n"
|
---|
| 1410 | #endif
|
---|
| 1411 |
|
---|
| 1412 | "<title>ネットワーク統計情報</title>\r\n"
|
---|
| 1413 | "</head><body bgcolor=\"#ffffbb\">\r\n"
|
---|
| 1414 | "<hr><h1 align=\"center\">ネットワーク統計情報</h1><hr>\r\n"
|
---|
| 1415 | ;
|
---|
| 1416 |
|
---|
| 1417 | static const char res_suffix[] =
|
---|
| 1418 | "</body></html>\r\n"
|
---|
| 1419 | ;
|
---|
| 1420 |
|
---|
| 1421 | static const char table_prefix1[] =
|
---|
| 1422 | "<h2>グループ 1</h2><table border>\r\n"
|
---|
| 1423 | "<tr><th>項目</th>\r\n"
|
---|
| 1424 | "<th>受信オクテット数</th>"
|
---|
| 1425 | "<th>送信オクテット数</th>\r\n"
|
---|
| 1426 | "<th>受信パケット数</th>"
|
---|
| 1427 | "<th>送信パケット数</th>\r\n"
|
---|
| 1428 | "<th>受信エラー<br>パケット数</th>"
|
---|
| 1429 | "<th>送信エラー<br>パケット数</th></tr>\r\n"
|
---|
| 1430 | ;
|
---|
| 1431 |
|
---|
| 1432 | #ifdef SUPPORT_PPP
|
---|
| 1433 |
|
---|
| 1434 | static const char table_prefix2[] =
|
---|
| 1435 | "<h2>グループ 2</h2><table border>\r\n"
|
---|
| 1436 | "<tr><th>項目</th>"
|
---|
| 1437 | "<th>受信オクテット数</th>"
|
---|
| 1438 | "<th>受信フレーム数</th></tr>\r\n"
|
---|
| 1439 | ;
|
---|
| 1440 |
|
---|
| 1441 | #endif /* of #ifdef SUPPORT_PPP */
|
---|
| 1442 |
|
---|
| 1443 | uint16_t content_len, len = 0;
|
---|
| 1444 | SYSTIM start, finish;
|
---|
| 1445 |
|
---|
| 1446 | get_tim(&start);
|
---|
| 1447 | content_len = 0
|
---|
| 1448 |
|
---|
| 1449 | #ifdef SUPPORT_PPP
|
---|
| 1450 |
|
---|
| 1451 | + TD_LEN1("HDLC")
|
---|
| 1452 |
|
---|
| 1453 | #endif /* of #ifdef SUPPORT_PPP */
|
---|
| 1454 |
|
---|
| 1455 | #ifdef SUPPORT_PPP
|
---|
| 1456 |
|
---|
| 1457 | + td_len_ppp()
|
---|
| 1458 | + TD_LEN2("LCP")
|
---|
| 1459 | + TD_LEN2("IPCP")
|
---|
| 1460 |
|
---|
| 1461 | #endif /* of #ifdef SUPPORT_PPP */
|
---|
| 1462 |
|
---|
| 1463 | #ifdef SUPPORT_ETHER
|
---|
| 1464 |
|
---|
| 1465 | + TD_LEN1("ARP")
|
---|
| 1466 | + td_len_ether_nic()
|
---|
| 1467 |
|
---|
| 1468 | #endif /* of #ifdef SUPPORT_ETHER */
|
---|
| 1469 |
|
---|
| 1470 | + TD_LEN1("ICMP")
|
---|
| 1471 | + TD_LEN1("UDP")
|
---|
| 1472 |
|
---|
| 1473 | #if defined(SUPPORT_INET4)
|
---|
| 1474 |
|
---|
| 1475 | + td_len_ip4()
|
---|
| 1476 |
|
---|
| 1477 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
| 1478 |
|
---|
| 1479 | #if defined(SUPPORT_INET6)
|
---|
| 1480 |
|
---|
| 1481 | + td_len_ip6()
|
---|
| 1482 | + td_len_nd6()
|
---|
| 1483 | + td_len_icmp6()
|
---|
| 1484 |
|
---|
| 1485 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
| 1486 |
|
---|
| 1487 | + td_len_tcp()
|
---|
| 1488 | + TD_LEN4("0123") * nbuf_get_tbl_size();
|
---|
| 1489 | ;
|
---|
| 1490 |
|
---|
| 1491 | len += put_status(cepid, srbuf, ST_OK);
|
---|
| 1492 | len += put_content_length(cepid, srbuf, strlen(res_prefix)
|
---|
| 1493 | + strlen(res_suffix)
|
---|
| 1494 | + strlen(time_prefix)
|
---|
| 1495 | + strlen("1234:12:12")
|
---|
| 1496 | + strlen(time_suffix)
|
---|
| 1497 | + strlen(table_prefix1)
|
---|
| 1498 | + strlen(table_prefix_net_buf)
|
---|
| 1499 |
|
---|
| 1500 | #if defined(SUPPORT_INET4)
|
---|
| 1501 |
|
---|
| 1502 | + strlen(table_prefix_ip4)
|
---|
| 1503 |
|
---|
| 1504 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
| 1505 |
|
---|
| 1506 | #if defined(SUPPORT_INET6)
|
---|
| 1507 |
|
---|
| 1508 | + strlen(table_prefix_ip6)
|
---|
| 1509 | + strlen(table_prefix_nd6)
|
---|
| 1510 | + strlen(table_prefix_icmp6)
|
---|
| 1511 |
|
---|
| 1512 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
| 1513 | + strlen(table_prefix_tcp)
|
---|
| 1514 | + strlen(table_suffix) * 3
|
---|
| 1515 |
|
---|
| 1516 | #ifdef SUPPORT_PPP
|
---|
| 1517 | + strlen(table_prefix2)
|
---|
| 1518 | + strlen(table_prefix_ppp)
|
---|
| 1519 | + strlen(table_suffix) * 2
|
---|
| 1520 |
|
---|
| 1521 | #endif /* of #ifdef SUPPORT_PPP */
|
---|
| 1522 |
|
---|
| 1523 | #ifdef SUPPORT_ETHER
|
---|
| 1524 |
|
---|
| 1525 | + strlen(table_prefix_ether_nic)
|
---|
| 1526 | + strlen(table_suffix) * 1
|
---|
| 1527 |
|
---|
| 1528 | #endif /* of #ifdef SUPPORT_ETHER */
|
---|
| 1529 |
|
---|
| 1530 | + content_len
|
---|
| 1531 | - 2); /* 2 は最初の \r\n */
|
---|
| 1532 |
|
---|
| 1533 | len += put_str(cepid, srbuf, res_prefix);
|
---|
| 1534 | len += put_elapse_time(cepid, srbuf);
|
---|
| 1535 | len += put_str(cepid, srbuf, table_prefix1);
|
---|
| 1536 |
|
---|
| 1537 | #ifdef SUPPORT_PPP
|
---|
| 1538 |
|
---|
| 1539 | len += put_count_item1(cepid, srbuf, "HDLC", &net_count_hdlc);
|
---|
| 1540 |
|
---|
| 1541 | #endif /* of #ifdef SUPPORT_PPP */
|
---|
| 1542 |
|
---|
| 1543 | #ifdef SUPPORT_ETHER
|
---|
| 1544 |
|
---|
| 1545 | len += put_count_item1(cepid, srbuf, "Ethernet", &net_count_ether);
|
---|
| 1546 |
|
---|
| 1547 | #if defined(SUPPORT_INET4)
|
---|
| 1548 |
|
---|
| 1549 | len += put_count_item1(cepid, srbuf, "ARP", &net_count_arp);
|
---|
| 1550 |
|
---|
| 1551 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
| 1552 |
|
---|
| 1553 | #endif /* of #ifdef SUPPORT_ETHER */
|
---|
| 1554 |
|
---|
| 1555 | #if defined(SUPPORT_INET4)
|
---|
| 1556 |
|
---|
| 1557 | len += put_count_item1(cepid, srbuf, "ICMP", &net_count_icmp4);
|
---|
| 1558 |
|
---|
| 1559 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
| 1560 |
|
---|
| 1561 | #ifdef SUPPORT_UDP
|
---|
| 1562 |
|
---|
| 1563 | len += put_count_item1(cepid, srbuf, "UDP", &net_count_udp);
|
---|
| 1564 |
|
---|
| 1565 | #endif /* of #ifdef SUPPORT_UDP */
|
---|
| 1566 |
|
---|
| 1567 | len += put_str(cepid, srbuf, table_suffix);
|
---|
| 1568 |
|
---|
| 1569 | #ifdef SUPPORT_PPP
|
---|
| 1570 |
|
---|
| 1571 | len += put_str(cepid, srbuf, table_prefix2);
|
---|
| 1572 | len += put_count_item2(cepid, srbuf, "LCP",
|
---|
| 1573 | net_count_ppp_lcp_in_octets,
|
---|
| 1574 | net_count_ppp_lcp_in_packets);
|
---|
| 1575 | len += put_count_item2(cepid, srbuf, "IPCP",
|
---|
| 1576 | net_count_ppp_ipcp_in_octets,
|
---|
| 1577 | net_count_ppp_ipcp_in_packets);
|
---|
| 1578 | len += put_str(cepid, srbuf, table_suffix);
|
---|
| 1579 |
|
---|
| 1580 | len += put_count_ppp(cepid, srbuf);
|
---|
| 1581 |
|
---|
| 1582 | #endif /* of #ifdef SUPPORT_PPP */
|
---|
| 1583 |
|
---|
| 1584 | #ifdef SUPPORT_ETHER
|
---|
| 1585 |
|
---|
| 1586 | len += put_count_ether_nic(cepid, srbuf);
|
---|
| 1587 |
|
---|
| 1588 | #endif /* of #ifdef SUPPORT_ETHER */
|
---|
| 1589 |
|
---|
| 1590 | #if defined(SUPPORT_INET4)
|
---|
| 1591 |
|
---|
| 1592 | len += put_count_ip4(cepid, srbuf);
|
---|
| 1593 |
|
---|
| 1594 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
| 1595 |
|
---|
| 1596 | #if defined(SUPPORT_INET6)
|
---|
| 1597 |
|
---|
| 1598 | len += put_count_ip6(cepid, srbuf);
|
---|
| 1599 | len += put_count_nd6(cepid, srbuf);
|
---|
| 1600 | len += put_count_icmp6(cepid, srbuf);
|
---|
| 1601 |
|
---|
| 1602 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
| 1603 |
|
---|
| 1604 | len += put_count_tcp(cepid, srbuf);
|
---|
| 1605 |
|
---|
| 1606 | len += put_count_net_buf(cepid, srbuf);
|
---|
| 1607 |
|
---|
| 1608 | len += put_str(cepid, srbuf, res_suffix);
|
---|
| 1609 |
|
---|
| 1610 | get_tim(&finish);
|
---|
[364] | 1611 | syslog(LOG_NOTICE, "[WWWn:%02u SND]send: stat.html, len: %4u, time: %lu [us]",
|
---|
[337] | 1612 | cepid, len, (finish - start) * 1000 / SYSTIM_HZ);
|
---|
| 1613 | return E_OK;
|
---|
| 1614 | }
|
---|
| 1615 |
|
---|
| 1616 | #endif /* of #if NET_COUNT_ENABLE */
|
---|
| 1617 |
|
---|
| 1618 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 1619 |
|
---|
| 1620 | /*
|
---|
| 1621 | * get_tcp_rep -- TCP 受付口を獲得する。
|
---|
| 1622 | */
|
---|
| 1623 |
|
---|
| 1624 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
| 1625 |
|
---|
| 1626 | static ER
|
---|
| 1627 | get_tcp_rep (ID *repid)
|
---|
| 1628 | {
|
---|
| 1629 | ID tskid;
|
---|
| 1630 | T_TCP6_CREP crep6;
|
---|
| 1631 | T_TCP_CREP crep4;
|
---|
| 1632 |
|
---|
| 1633 | get_tid(&tskid);
|
---|
| 1634 | if (tskid == WWW4_SRV_TASK) {
|
---|
| 1635 | crep4.repatr = UINT_C(0);
|
---|
| 1636 | crep4.myaddr.portno = UINT_C(80);
|
---|
| 1637 | crep4.myaddr.ipaddr = IPV4_ADDRANY;
|
---|
| 1638 | return alloc_tcp4_rep(repid, tskid, &crep4);
|
---|
| 1639 | }
|
---|
| 1640 | else {
|
---|
| 1641 | crep6.repatr = UINT_C(0);
|
---|
| 1642 | crep6.myaddr.portno = UINT_C(80);
|
---|
| 1643 | memcpy(&crep6.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
|
---|
| 1644 | return alloc_tcp6_rep(repid, tskid, &crep6);
|
---|
| 1645 | }
|
---|
| 1646 | }
|
---|
| 1647 |
|
---|
| 1648 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 1649 |
|
---|
| 1650 | static ER
|
---|
| 1651 | get_tcp_rep (ID *repid)
|
---|
| 1652 | {
|
---|
| 1653 | ID tskid;
|
---|
| 1654 | T_TCPN_CREP crep;
|
---|
| 1655 |
|
---|
| 1656 | get_tid(&tskid);
|
---|
| 1657 |
|
---|
| 1658 | crep.repatr = UINT_C(0);
|
---|
| 1659 | crep.myaddr.portno = UINT_C(80);
|
---|
| 1660 |
|
---|
| 1661 | #if defined(SUPPORT_INET6)
|
---|
| 1662 |
|
---|
| 1663 | memcpy(&crep.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
|
---|
| 1664 |
|
---|
| 1665 | #else /* #if defined(SUPPORT_INET6) */
|
---|
| 1666 |
|
---|
| 1667 | #if defined(SUPPORT_INET4)
|
---|
| 1668 | crep.myaddr.ipaddr = IPV4_ADDRANY;
|
---|
| 1669 | #endif
|
---|
| 1670 |
|
---|
| 1671 | #endif /* #if defined(SUPPORT_INET6) */
|
---|
| 1672 |
|
---|
| 1673 | return ALLOC_TCP_REP(repid, tskid, &crep);
|
---|
| 1674 | }
|
---|
| 1675 |
|
---|
| 1676 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 1677 |
|
---|
| 1678 | /*
|
---|
| 1679 | * get_tcp_cep -- TCP 通信端点を獲得する。
|
---|
| 1680 | */
|
---|
| 1681 |
|
---|
| 1682 | static ER
|
---|
| 1683 | get_tcp_cep (ID *cepid)
|
---|
| 1684 | {
|
---|
| 1685 | ID tskid;
|
---|
| 1686 | T_TCP_CCEP ccep;
|
---|
| 1687 |
|
---|
| 1688 | get_tid(&tskid);
|
---|
| 1689 |
|
---|
| 1690 | ccep.cepatr = UINT_C(0);
|
---|
| 1691 | ccep.sbufsz = WWW_SRV_SWBUF_SIZE;
|
---|
| 1692 | ccep.rbufsz = WWW_SRV_RWBUF_SIZE;
|
---|
| 1693 | ccep.callback = NULL;
|
---|
| 1694 |
|
---|
| 1695 | #ifdef TCP_CFG_SWBUF_CSAVE
|
---|
| 1696 | ccep.sbuf = NADR;
|
---|
| 1697 | #else
|
---|
| 1698 | ccep.sbuf = www_srv_swbuf[0];
|
---|
| 1699 | #endif
|
---|
| 1700 | #ifdef TCP_CFG_RWBUF_CSAVE
|
---|
| 1701 | ccep.rbuf = NADR;
|
---|
| 1702 | #else
|
---|
| 1703 | ccep.rbuf = www_srv_rwbuf[0];
|
---|
| 1704 | #endif
|
---|
| 1705 |
|
---|
| 1706 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
| 1707 |
|
---|
| 1708 | if (tskid == WWW4_SRV_TASK)
|
---|
| 1709 | return alloc_tcp4_cep(cepid, tskid, &ccep);
|
---|
| 1710 | else
|
---|
| 1711 | return alloc_tcp6_cep(cepid, tskid, &ccep);
|
---|
| 1712 |
|
---|
| 1713 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 1714 |
|
---|
| 1715 | return ALLOC_TCP_CEP(cepid, tskid, &ccep);
|
---|
| 1716 |
|
---|
| 1717 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 1718 |
|
---|
| 1719 | }
|
---|
| 1720 |
|
---|
| 1721 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 1722 |
|
---|
| 1723 | /*
|
---|
| 1724 | * tcp_passive_open -- 受動オープンを実行する。
|
---|
| 1725 | *
|
---|
| 1726 | * USE_TCP_NON_BLOCKING OFF
|
---|
| 1727 | */
|
---|
| 1728 |
|
---|
| 1729 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
| 1730 |
|
---|
| 1731 | static ER
|
---|
| 1732 | tcp_passive_open (T_WWW_SRV_INFO *info, char apip)
|
---|
| 1733 | {
|
---|
| 1734 | ER error = E_OK;
|
---|
| 1735 | T_IPV4EP dst4;
|
---|
| 1736 |
|
---|
| 1737 | if (apip == API_PROTO_IPV6) {
|
---|
| 1738 | /* 受付口は IPv6 */
|
---|
| 1739 | if ((error = tcp6_acp_cep(info->cepid, info->repid, &info->dst, TMO_FEVR)) != E_OK)
|
---|
| 1740 | return error;
|
---|
| 1741 |
|
---|
| 1742 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 1743 | if ((error = free_tcp6_rep(info->repid, true)) != E_OK)
|
---|
| 1744 | return error;
|
---|
| 1745 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 1746 |
|
---|
| 1747 | }
|
---|
| 1748 | else {
|
---|
| 1749 | /* 受付口は IPv4 */
|
---|
| 1750 | if ((error = tcp_acp_cep(info->cepid, info->repid, &dst4, TMO_FEVR)) != E_OK)
|
---|
| 1751 | return error;
|
---|
| 1752 | in6_make_ipv4mapped (&info->dst.ipaddr, dst4.ipaddr);
|
---|
| 1753 | info->dst.portno = dst4.portno;
|
---|
| 1754 |
|
---|
| 1755 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 1756 | if ((error = free_tcp4_rep(info->repid, true)) != E_OK)
|
---|
| 1757 | return error;
|
---|
| 1758 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 1759 | }
|
---|
| 1760 |
|
---|
| 1761 | return error;
|
---|
| 1762 | }
|
---|
| 1763 |
|
---|
| 1764 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 1765 |
|
---|
| 1766 | static ER
|
---|
| 1767 | tcp_passive_open (T_WWW_SRV_INFO *info, char apip)
|
---|
| 1768 | {
|
---|
| 1769 | ER error = E_OK;
|
---|
| 1770 |
|
---|
| 1771 | if ((error = TCP_ACP_CEP(info->cepid, info->repid, &info->dst, TMO_FEVR)) != E_OK)
|
---|
| 1772 | return error;
|
---|
| 1773 |
|
---|
| 1774 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 1775 | if ((error = FREE_TCP_REP(info->repid, true)) != E_OK)
|
---|
| 1776 | return error;
|
---|
| 1777 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 1778 |
|
---|
| 1779 | return error;
|
---|
| 1780 | }
|
---|
| 1781 |
|
---|
| 1782 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 1783 |
|
---|
| 1784 | /*
|
---|
| 1785 | * WWW サーバ
|
---|
| 1786 | */
|
---|
| 1787 |
|
---|
| 1788 | static ER
|
---|
| 1789 | www_srv (uint_t six, char apip)
|
---|
| 1790 | {
|
---|
| 1791 | T_WWW_RWBUF *srbuf;
|
---|
| 1792 | ER error;
|
---|
| 1793 | SYSTIM now;
|
---|
| 1794 |
|
---|
| 1795 | if ((error = tcp_passive_open(&www_srv_info[six], apip)) != E_OK)
|
---|
| 1796 | return error;
|
---|
| 1797 |
|
---|
| 1798 | syscall(get_tim(&now));
|
---|
| 1799 |
|
---|
| 1800 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV)
|
---|
| 1801 |
|
---|
| 1802 | if (apip == API_PROTO_IPV6)
|
---|
| 1803 | syslog(LOG_NOTICE, "[WWW6:%02u ACP] conct: %6lu,from: %s.%u",
|
---|
| 1804 | www_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
| 1805 | ipv62str(NULL, &www_srv_info[six].dst.ipaddr),
|
---|
| 1806 | www_srv_info[six].dst.portno);
|
---|
| 1807 | else
|
---|
| 1808 | syslog(LOG_NOTICE, "[WWW4:%02u ACP] conct: %6lu,from: %s.%u",
|
---|
| 1809 | www_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
| 1810 | ip2str(NULL, &www_srv_info[six].dst.ipaddr.s6_addr32[3]),
|
---|
| 1811 | www_srv_info[six].dst.portno);
|
---|
| 1812 |
|
---|
| 1813 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
|
---|
| 1814 |
|
---|
| 1815 | syslog(LOG_NOTICE, "[WWWn:%02u ACP] conct: %6lu,from: %s.%u",
|
---|
| 1816 | www_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
| 1817 | IP2STR(NULL, &www_srv_info[six].dst.ipaddr),
|
---|
| 1818 | www_srv_info[six].dst.portno);
|
---|
| 1819 |
|
---|
| 1820 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
|
---|
| 1821 |
|
---|
| 1822 | if ((error = tget_mpf(MPF_WWW_RWBUF, (void*)&srbuf, TMO_FEVR)) != E_OK) {
|
---|
| 1823 | syslog(LOG_CRIT, "[WWWn:%02u MPF] get buffer error: %s.",
|
---|
| 1824 | www_srv_info[six].cepid, itron_strerror(error));
|
---|
| 1825 | srbuf = NULL;
|
---|
| 1826 | }
|
---|
| 1827 | else {
|
---|
| 1828 | srbuf->rbuf.len = srbuf->rbuf.index = srbuf->sbuf.index = srbuf->unget = 0;
|
---|
| 1829 |
|
---|
| 1830 | #ifdef USE_COPYSAVE_API
|
---|
| 1831 |
|
---|
| 1832 | srbuf->sbuf.len = 0;
|
---|
| 1833 |
|
---|
| 1834 | #else /* of #ifdef USE_COPYSAVE_API */
|
---|
| 1835 |
|
---|
| 1836 | srbuf->sbuf.len = sizeof(srbuf->sbuf.buf);
|
---|
| 1837 |
|
---|
| 1838 | #endif /* of #ifdef USE_COPYSAVE_API */
|
---|
| 1839 |
|
---|
| 1840 | if ((error = parse_request(www_srv_info[six].cepid, srbuf)) != E_OK)
|
---|
| 1841 | syslog(LOG_WARNING, "[WWWn:%02u RCV] parse request error: %s",
|
---|
| 1842 | www_srv_info[six].cepid, itron_strerror(error));
|
---|
| 1843 | }
|
---|
| 1844 |
|
---|
| 1845 | if ((error = tcp_sht_cep(www_srv_info[six].cepid)) != E_OK)
|
---|
| 1846 | syslog(LOG_WARNING, "[WWWn:%02u SHD] shutdown error: %s",
|
---|
| 1847 | www_srv_info[six].cepid, itron_strerror(error));
|
---|
| 1848 |
|
---|
| 1849 | if (srbuf != NULL) {
|
---|
| 1850 | while (get_char(www_srv_info[six].cepid, srbuf) != EOF)
|
---|
| 1851 | ;
|
---|
| 1852 | if (srbuf != NULL && (error = rel_mpf(MPF_WWW_RWBUF, srbuf)) != E_OK)
|
---|
| 1853 | syslog(LOG_WARNING, "[WWWn:%02u REL] release buffer error: %s.",
|
---|
| 1854 | www_srv_info[six].cepid, itron_strerror(error));
|
---|
| 1855 | }
|
---|
| 1856 |
|
---|
| 1857 | if ((error = tcp_cls_cep(www_srv_info[six].cepid, TMO_FEVR)) != E_OK)
|
---|
| 1858 | syslog(LOG_WARNING, "[WWWn:%02u CLS] close error: %s",
|
---|
| 1859 | www_srv_info[six].cepid, itron_strerror(error));
|
---|
| 1860 |
|
---|
| 1861 | get_tim(&now);
|
---|
| 1862 | syslog(LOG_NOTICE, "[WWWn:%02u FIN] finsh: %6lu",
|
---|
| 1863 | www_srv_info[six].cepid, now / SYSTIM_HZ);
|
---|
| 1864 |
|
---|
| 1865 | return error;
|
---|
| 1866 | }
|
---|
| 1867 |
|
---|
| 1868 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 1869 |
|
---|
| 1870 | /*
|
---|
| 1871 | * WWW サーバタスク
|
---|
| 1872 | */
|
---|
| 1873 |
|
---|
| 1874 | void
|
---|
| 1875 | www_srv_task(intptr_t exinf)
|
---|
| 1876 | {
|
---|
| 1877 | ID tskid;
|
---|
| 1878 | ER error = E_OK;
|
---|
| 1879 | uint_t six;
|
---|
| 1880 | char apip;
|
---|
| 1881 |
|
---|
| 1882 | syscall(get_tid(&tskid));
|
---|
| 1883 | six = INDEX_SRV_INFO((ID)exinf);
|
---|
| 1884 |
|
---|
| 1885 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV)
|
---|
| 1886 |
|
---|
| 1887 | if (six >= NUM_WWW4_SRV_TASKS)
|
---|
| 1888 | apip = API_PROTO_IPV6;
|
---|
| 1889 | else
|
---|
| 1890 | apip = API_PROTO_IPV4;
|
---|
| 1891 |
|
---|
| 1892 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
|
---|
| 1893 |
|
---|
| 1894 | apip = API_PROTO_IPVn;
|
---|
| 1895 |
|
---|
| 1896 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
|
---|
| 1897 |
|
---|
| 1898 | syslog(LOG_NOTICE, "[WWW%c:%d] started.", apip, tskid);
|
---|
| 1899 | while (true) {
|
---|
| 1900 |
|
---|
| 1901 | syscall(slp_tsk());
|
---|
| 1902 | if ((error = get_tcp_cep(&www_srv_info[six].cepid)) != E_OK) {
|
---|
| 1903 | syslog(LOG_NOTICE, "[WWW%c:%02u EXT] create CEP error: %s",
|
---|
| 1904 | apip, www_srv_info[six].cepid, itron_strerror(error));
|
---|
| 1905 | continue;
|
---|
| 1906 | }
|
---|
| 1907 |
|
---|
| 1908 | while (true) {
|
---|
| 1909 |
|
---|
| 1910 | if ((error = get_tcp_rep(&www_srv_info[six].repid)) != E_OK) {
|
---|
| 1911 | syslog(LOG_NOTICE, "[WWW%c:%02u EXT] create REP error: %02u, %s",
|
---|
| 1912 | apip, www_srv_info[six].cepid, www_srv_info[six].repid, itron_strerror(error));
|
---|
| 1913 | break;
|
---|
| 1914 | }
|
---|
| 1915 | else if ((error = www_srv(six, apip)) != E_OK) {
|
---|
| 1916 |
|
---|
| 1917 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
| 1918 |
|
---|
| 1919 | if (tskid == WWW4_SRV_TASK)
|
---|
| 1920 | error = free_tcp4_rep(www_srv_info[six].repid, error != E_DLT);
|
---|
| 1921 | else
|
---|
| 1922 | error = free_tcp6_rep(www_srv_info[six].repid, error != E_DLT);
|
---|
| 1923 |
|
---|
| 1924 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 1925 |
|
---|
| 1926 | error = FREE_TCP_REP(www_srv_info[six].repid, error != E_DLT);
|
---|
| 1927 |
|
---|
| 1928 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 1929 |
|
---|
| 1930 | if (error != E_OK) {
|
---|
| 1931 | syslog(LOG_NOTICE, "[WWW%c:%02u EXT] delete REP error: %02u, %s",
|
---|
| 1932 | apip, www_srv_info[six].cepid,
|
---|
| 1933 | www_srv_info[six].repid, itron_strerror(error));
|
---|
| 1934 |
|
---|
| 1935 | }
|
---|
| 1936 | break;
|
---|
| 1937 | }
|
---|
| 1938 | }
|
---|
| 1939 |
|
---|
| 1940 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
| 1941 |
|
---|
| 1942 | if (tskid == WWW4_SRV_TASK) {
|
---|
| 1943 | if ((error = free_tcp4_cep(www_srv_info[six].cepid)) != E_OK)
|
---|
| 1944 | syslog(LOG_NOTICE, "[WWW%c:%02u EXT] delete CEP error: %s",
|
---|
| 1945 | apip, www_srv_info[six].cepid, itron_strerror(error));
|
---|
| 1946 | }
|
---|
| 1947 | else {
|
---|
| 1948 | if ((error = free_tcp6_cep(www_srv_info[six].cepid)) != E_OK)
|
---|
| 1949 | syslog(LOG_NOTICE, "[WWW%c:%02u EXT] delete CEP error: %s",
|
---|
| 1950 | apip, www_srv_info[six].cepid, itron_strerror(error));
|
---|
| 1951 | }
|
---|
| 1952 |
|
---|
| 1953 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 1954 |
|
---|
| 1955 | if ((error = FREE_TCP_CEP(www_srv_info[six].cepid)) != E_OK)
|
---|
| 1956 | syslog(LOG_NOTICE, "[WWW%c:%02u EXT] delete CEP error: %s",
|
---|
| 1957 | apip, www_srv_info[six].cepid, itron_strerror(error));
|
---|
| 1958 |
|
---|
| 1959 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 1960 |
|
---|
| 1961 | }
|
---|
| 1962 | }
|
---|
| 1963 |
|
---|
| 1964 | /*
|
---|
| 1965 | * wakeup_www_srv -- WWW サーバタスクの休止解除
|
---|
| 1966 | */
|
---|
| 1967 |
|
---|
| 1968 | ER
|
---|
| 1969 | wakeup_www_srv (char apip)
|
---|
| 1970 | {
|
---|
| 1971 | ID taskid;
|
---|
| 1972 |
|
---|
| 1973 | if (apip == API_PROTO_IPV6)
|
---|
| 1974 | taskid = WWW6_SRV_TASK;
|
---|
| 1975 | else
|
---|
| 1976 | taskid = WWW4_SRV_TASK;
|
---|
| 1977 | syslog(LOG_NOTICE, "[WWW%c(EXT):%d] wake up.", apip, taskid);
|
---|
| 1978 | return wup_tsk(taskid);
|
---|
| 1979 | }
|
---|
| 1980 |
|
---|
| 1981 | #else /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 1982 |
|
---|
| 1983 | /*
|
---|
| 1984 | * WWW サーバタスク
|
---|
| 1985 | */
|
---|
| 1986 |
|
---|
| 1987 | void
|
---|
| 1988 | www_srv_task(intptr_t exinf)
|
---|
| 1989 | {
|
---|
| 1990 | ID tskid, cepid;
|
---|
| 1991 | uint_t six;
|
---|
| 1992 | char apip;
|
---|
| 1993 |
|
---|
| 1994 | get_tim(&srv_start);
|
---|
| 1995 | get_tid(&tskid);
|
---|
| 1996 | six = INDEX_SRV_INFO((ID)exinf);
|
---|
| 1997 | cepid = www_srv_info[INDEX_SRV_INFO((ID)exinf)].cepid;
|
---|
| 1998 |
|
---|
| 1999 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV)
|
---|
| 2000 |
|
---|
| 2001 | if (six >= NUM_WWW4_SRV_TASKS)
|
---|
| 2002 | apip = API_PROTO_IPV6;
|
---|
| 2003 | else
|
---|
| 2004 | apip = API_PROTO_IPV4;
|
---|
| 2005 |
|
---|
| 2006 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
|
---|
| 2007 |
|
---|
| 2008 | apip = API_PROTO_IPVn;
|
---|
| 2009 |
|
---|
| 2010 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_WWW4_SRV) */
|
---|
| 2011 |
|
---|
| 2012 | syslog(LOG_NOTICE, "[WWW%c SRV:%d,%d] started.", apip, tskid, cepid);
|
---|
| 2013 |
|
---|
| 2014 | while (true) {
|
---|
| 2015 | while (www_srv(six, apip) == E_OK)
|
---|
| 2016 | ;
|
---|
| 2017 | }
|
---|
| 2018 | }
|
---|
| 2019 |
|
---|
| 2020 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 2021 |
|
---|
| 2022 | #endif /* of #ifdef USE_WWW_SRV */
|
---|