[313] | 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: ping6.c 315 2017-07-23 05:29:40Z coas-nagasima $
|
---|
| 32 | */
|
---|
| 33 |
|
---|
| 34 | /*
|
---|
| 35 | * ping6 -- ICMPv6 ECHO メッセージを送信する。
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | #ifdef TARGET_KERNEL_ASP
|
---|
| 39 |
|
---|
| 40 | #include <kernel.h>
|
---|
| 41 | #include <sil.h>
|
---|
| 42 | #include <t_syslog.h>
|
---|
| 43 |
|
---|
| 44 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 45 |
|
---|
| 46 | #ifdef TARGET_KERNEL_JSP
|
---|
| 47 |
|
---|
| 48 | #include <s_services.h>
|
---|
| 49 | #include <t_services.h>
|
---|
| 50 |
|
---|
| 51 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
| 52 |
|
---|
| 53 | #include <tinet_defs.h>
|
---|
| 54 | #include <tinet_config.h>
|
---|
| 55 |
|
---|
| 56 | #include <net/if.h>
|
---|
| 57 | #include <net/if_ppp.h>
|
---|
| 58 | #include <net/if_loop.h>
|
---|
| 59 | #include <net/ethernet.h>
|
---|
| 60 | #include <net/ppp_var.h>
|
---|
| 61 | #include <net/ppp_ipcp.h>
|
---|
| 62 | #include <net/net.h>
|
---|
| 63 | #include <net/net_endian.h>
|
---|
| 64 | #include <net/net_buf.h>
|
---|
| 65 | #include <net/net_timer.h>
|
---|
| 66 | #include <net/net_count.h>
|
---|
| 67 |
|
---|
| 68 | #include <netinet/in.h>
|
---|
| 69 | #include <netinet/in_var.h>
|
---|
| 70 | #include <netinet/ip.h>
|
---|
| 71 | #include <netinet/ip_var.h>
|
---|
| 72 | #include <netinet/ip_icmp.h>
|
---|
| 73 |
|
---|
| 74 | #include <netinet6/nd6.h>
|
---|
| 75 |
|
---|
| 76 | #include <net/if_var.h>
|
---|
| 77 |
|
---|
| 78 | #ifdef USE_PING
|
---|
| 79 |
|
---|
| 80 | #if defined(SUPPORT_INET6)
|
---|
| 81 |
|
---|
| 82 | /*
|
---|
| 83 | * 変数
|
---|
| 84 | */
|
---|
| 85 |
|
---|
| 86 | #if 0
|
---|
| 87 | static uint16_t curr_icmp6_id;
|
---|
| 88 | static uint16_t curr_icmp6_size;
|
---|
| 89 | #endif
|
---|
| 90 |
|
---|
| 91 | static uint16_t send_icmp6_id = 0;
|
---|
| 92 | static uint16_t reply_count;
|
---|
| 93 | static SYSTIM icmp6_start_time;
|
---|
| 94 |
|
---|
| 95 | /*
|
---|
| 96 | * icmp6_reply_timeout -- ICMP6 REPLY タイムアウト処理
|
---|
| 97 | */
|
---|
| 98 |
|
---|
| 99 | static void
|
---|
| 100 | icmp6_reply_timeout (void *arg)
|
---|
| 101 | {
|
---|
| 102 | if (reply_count == 0)
|
---|
| 103 | syslog(LOG_NOTICE, "[PING6] request timeout.");
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | /*
|
---|
| 107 | * icmp6_echo_reply -- ICMP6 ECHO REPLY メッセージを処理する。
|
---|
| 108 | */
|
---|
| 109 |
|
---|
| 110 | void
|
---|
| 111 | icmp6_echo_reply (T_NET_BUF *input, uint_t ihoff)
|
---|
| 112 | {
|
---|
| 113 | SYSTIM time;
|
---|
| 114 |
|
---|
| 115 | syscall(get_tim(&time));
|
---|
| 116 | untimeout(icmp6_reply_timeout, NULL);
|
---|
| 117 | syslog(LOG_NOTICE, "[PING6] reply: %5ld [ms] from: %s",
|
---|
| 118 | (time - icmp6_start_time) * 1000 / SYSTIM_HZ,
|
---|
| 119 | ipv62str(NULL, &GET_IP6_HDR(input)->src));
|
---|
| 120 | reply_count ++;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | /*
|
---|
| 124 | * ping6 -- ICMP ECHO メッセージを送信する。
|
---|
| 125 | */
|
---|
| 126 |
|
---|
| 127 | void
|
---|
| 128 | ping6 (T_IN6_ADDR *addr, uint_t tmo, uint_t size)
|
---|
| 129 | {
|
---|
| 130 | T_IFNET *ifp = IF_GET_IFNET();
|
---|
| 131 | T_ICMP6_HDR *icmp6h;
|
---|
| 132 | T_NET_BUF *output;
|
---|
| 133 | T_IN6_IFADDR *ia;
|
---|
| 134 | int_t ix;
|
---|
| 135 | uint16_t ipflags = 0;
|
---|
| 136 | uint8_t *sdu;
|
---|
| 137 |
|
---|
| 138 | /*
|
---|
| 139 | * 宛先アドレスにふさわしい送信元アドレスを、
|
---|
| 140 | * ネットワークインタフェースから探索して利用する。
|
---|
| 141 | */
|
---|
| 142 | if ((ia = in6_ifawithifp(ifp, addr)) == NULL)
|
---|
| 143 | return;
|
---|
| 144 |
|
---|
| 145 | if (IN6_IS_ADDR_MULTICAST(addr))
|
---|
| 146 | ipflags = IPV6_OUT_SET_HOP_LIMIT(IPV6_OUT_FLG_HOP_LIMIT, IPV6_DEFHLIM);
|
---|
| 147 |
|
---|
| 148 | /* 送信用の IP データグラムを獲得する。*/
|
---|
| 149 | if (in6_get_datagram(&output, ICMP6_HDR_SIZE + size, 0,
|
---|
| 150 | addr, &ia->addr, IPPROTO_ICMPV6,
|
---|
| 151 | IPV6_DEFHLIM, NBA_SEARCH_ASCENT, TMO_FEVR) != E_OK)
|
---|
| 152 | return;
|
---|
| 153 |
|
---|
| 154 | /* ICMP ヘッダを設定する。*/
|
---|
| 155 | icmp6h = GET_ICMP6_HDR(output, IF_IP6_ICMP6_HDR_OFFSET);
|
---|
| 156 | icmp6h->type = ICMP6_ECHO_REQUEST;
|
---|
| 157 | icmp6h->code = 0;
|
---|
| 158 | icmp6h->icmp6_id = htons(send_icmp6_id);
|
---|
| 159 | icmp6h->icmp6_seq= 0;
|
---|
| 160 |
|
---|
| 161 | /* データを設定する。*/
|
---|
| 162 | sdu = GET_ICMP6_SDU(output, IF_IP6_ICMP6_HDR_OFFSET) + size;
|
---|
| 163 | for (ix = size; ix -- > 0; )
|
---|
| 164 | *-- sdu = ('0' + send_icmp6_id + ix) & 0xff;
|
---|
| 165 |
|
---|
| 166 | /* チェックサムを計算する。*/
|
---|
| 167 | icmp6h->sum = 0;
|
---|
| 168 | icmp6h->sum = in6_cksum(output, IPPROTO_ICMPV6,
|
---|
| 169 | (uint8_t*)icmp6h - output->buf, ICMP6_HDR_SIZE + size);
|
---|
| 170 |
|
---|
| 171 | /* 応答チェック用の変数を設定する。*/
|
---|
| 172 | reply_count = 0;
|
---|
| 173 |
|
---|
| 174 | #if 0
|
---|
| 175 | curr_icmp6_id = send_icmp6_id ++;
|
---|
| 176 | curr_icmp6_size = size;
|
---|
| 177 | #endif
|
---|
| 178 |
|
---|
| 179 | #if 0
|
---|
| 180 | syslog(LOG_NOTICE, "[PING6] send: TMO:%d, SIZE:%d, to: %s, from %s",
|
---|
| 181 | tmo, size,
|
---|
| 182 | ipv62str(NULL, addr), ipv62str(NULL, &ia->addr));
|
---|
| 183 | #endif
|
---|
| 184 |
|
---|
| 185 | /* 送信後、現在の時間を記憶し、タイムアウトを設定する。*/
|
---|
| 186 | ip6_output(output, ipflags, TMO_FEVR);
|
---|
| 187 | NET_COUNT_MIB(icmp6_ifstat.ipv6IfIcmpOutMsgs, 1);
|
---|
| 188 | NET_COUNT_MIB(icmp6_ifstat.ipv6IfIcmpOutEchos, 1);
|
---|
| 189 |
|
---|
| 190 | syscall(get_tim(&icmp6_start_time));
|
---|
| 191 | timeout(icmp6_reply_timeout, NULL, tmo * NET_TIMER_HZ);
|
---|
| 192 |
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
| 196 |
|
---|
| 197 | #endif /* of #ifdef USE_PING */
|
---|