source: EcnlProtoTool/trunk/asp3_dcre/tinet/netapp/wwws.c@ 321

Last change on this file since 321 was 321, checked in by coas-nagasima, 7 years ago

文字コードを設定

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