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 | * ä¸è¨èä½æ¨©è
|
---|
8 | ã¯ï¼ä»¥ä¸ã® (1)ï½(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
9 | * ã«ãã£ã¦å
|
---|
10 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
11 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
12 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
13 | å¸ï¼ä»¥ä¸ï¼
|
---|
14 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
15 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
16 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
17 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
18 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
19 | * ç¨ã§ããå½¢ã§åé
|
---|
20 | å¸ããå ´åã«ã¯ï¼åé
|
---|
21 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
22 | * è
|
---|
23 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
24 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
25 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
26 | * ç¨ã§ããªãå½¢ã§åé
|
---|
27 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®æ¡ä»¶ãæºãããã¨ï¼
|
---|
28 | * (a) åé
|
---|
29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
31 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
32 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
33 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
34 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
35 | 責ãããã¨ï¼
|
---|
36 | *
|
---|
37 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
38 | ã
|
---|
39 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
40 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
41 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
42 | *
|
---|
43 | * @(#) $Id: ping6.c 313 2017-07-23 04:50:32Z coas-nagasima $
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * ping6 -- ICMPv6 ECHO ã¡ãã»ã¼ã¸ãéä¿¡ããã
|
---|
48 | */
|
---|
49 |
|
---|
50 | #ifdef TARGET_KERNEL_ASP
|
---|
51 |
|
---|
52 | #include <kernel.h>
|
---|
53 | #include <sil.h>
|
---|
54 | #include <t_syslog.h>
|
---|
55 |
|
---|
56 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
57 |
|
---|
58 | #ifdef TARGET_KERNEL_JSP
|
---|
59 |
|
---|
60 | #include <s_services.h>
|
---|
61 | #include <t_services.h>
|
---|
62 |
|
---|
63 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
64 |
|
---|
65 | #include <tinet_defs.h>
|
---|
66 | #include <tinet_config.h>
|
---|
67 |
|
---|
68 | #include <net/if.h>
|
---|
69 | #include <net/if_ppp.h>
|
---|
70 | #include <net/if_loop.h>
|
---|
71 | #include <net/ethernet.h>
|
---|
72 | #include <net/ppp_var.h>
|
---|
73 | #include <net/ppp_ipcp.h>
|
---|
74 | #include <net/net.h>
|
---|
75 | #include <net/net_endian.h>
|
---|
76 | #include <net/net_buf.h>
|
---|
77 | #include <net/net_timer.h>
|
---|
78 | #include <net/net_count.h>
|
---|
79 |
|
---|
80 | #include <netinet/in.h>
|
---|
81 | #include <netinet/in_var.h>
|
---|
82 | #include <netinet/ip.h>
|
---|
83 | #include <netinet/ip_var.h>
|
---|
84 | #include <netinet/ip_icmp.h>
|
---|
85 |
|
---|
86 | #include <netinet6/nd6.h>
|
---|
87 |
|
---|
88 | #include <net/if_var.h>
|
---|
89 |
|
---|
90 | #ifdef USE_PING
|
---|
91 |
|
---|
92 | #if defined(SUPPORT_INET6)
|
---|
93 |
|
---|
94 | /*
|
---|
95 | * å¤æ°
|
---|
96 | */
|
---|
97 |
|
---|
98 | #if 0
|
---|
99 | static uint16_t curr_icmp6_id;
|
---|
100 | static uint16_t curr_icmp6_size;
|
---|
101 | #endif
|
---|
102 |
|
---|
103 | static uint16_t send_icmp6_id = 0;
|
---|
104 | static uint16_t reply_count;
|
---|
105 | static SYSTIM icmp6_start_time;
|
---|
106 |
|
---|
107 | /*
|
---|
108 | * icmp6_reply_timeout -- ICMP6 REPLY ã¿ã¤ã ã¢ã¦ãå¦ç
|
---|
109 | */
|
---|
110 |
|
---|
111 | static void
|
---|
112 | icmp6_reply_timeout (void *arg)
|
---|
113 | {
|
---|
114 | if (reply_count == 0)
|
---|
115 | syslog(LOG_NOTICE, "[PING6] request timeout.");
|
---|
116 | }
|
---|
117 |
|
---|
118 | /*
|
---|
119 | * icmp6_echo_reply -- ICMP6 ECHO REPLY ã¡ãã»ã¼ã¸ãå¦çããã
|
---|
120 | */
|
---|
121 |
|
---|
122 | void
|
---|
123 | icmp6_echo_reply (T_NET_BUF *input, uint_t ihoff)
|
---|
124 | {
|
---|
125 | SYSTIM time;
|
---|
126 |
|
---|
127 | syscall(get_tim(&time));
|
---|
128 | untimeout(icmp6_reply_timeout, NULL);
|
---|
129 | syslog(LOG_NOTICE, "[PING6] reply: %5ld [ms] from: %s",
|
---|
130 | (time - icmp6_start_time) * 1000 / SYSTIM_HZ,
|
---|
131 | ipv62str(NULL, &GET_IP6_HDR(input)->src));
|
---|
132 | reply_count ++;
|
---|
133 | }
|
---|
134 |
|
---|
135 | /*
|
---|
136 | * ping6 -- ICMP ECHO ã¡ãã»ã¼ã¸ãéä¿¡ããã
|
---|
137 | */
|
---|
138 |
|
---|
139 | void
|
---|
140 | ping6 (T_IN6_ADDR *addr, uint_t tmo, uint_t size)
|
---|
141 | {
|
---|
142 | T_IFNET *ifp = IF_GET_IFNET();
|
---|
143 | T_ICMP6_HDR *icmp6h;
|
---|
144 | T_NET_BUF *output;
|
---|
145 | T_IN6_IFADDR *ia;
|
---|
146 | int_t ix;
|
---|
147 | uint16_t ipflags = 0;
|
---|
148 | uint8_t *sdu;
|
---|
149 |
|
---|
150 | /*
|
---|
151 | * å®å
|
---|
152 | ã¢ãã¬ã¹ã«ãµããããéä¿¡å
|
---|
153 | ã¢ãã¬ã¹ãã
|
---|
154 | * ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ããæ¢ç´¢ãã¦å©ç¨ããã
|
---|
155 | */
|
---|
156 | if ((ia = in6_ifawithifp(ifp, addr)) == NULL)
|
---|
157 | return;
|
---|
158 |
|
---|
159 | if (IN6_IS_ADDR_MULTICAST(addr))
|
---|
160 | ipflags = IPV6_OUT_SET_HOP_LIMIT(IPV6_OUT_FLG_HOP_LIMIT, IPV6_DEFHLIM);
|
---|
161 |
|
---|
162 | /* éä¿¡ç¨ã® IP ãã¼ã¿ã°ã©ã ãç²å¾ããã*/
|
---|
163 | if (in6_get_datagram(&output, ICMP6_HDR_SIZE + size, 0,
|
---|
164 | addr, &ia->addr, IPPROTO_ICMPV6,
|
---|
165 | IPV6_DEFHLIM, NBA_SEARCH_ASCENT, TMO_FEVR) != E_OK)
|
---|
166 | return;
|
---|
167 |
|
---|
168 | /* ICMP ããããè¨å®ããã*/
|
---|
169 | icmp6h = GET_ICMP6_HDR(output, IF_IP6_ICMP6_HDR_OFFSET);
|
---|
170 | icmp6h->type = ICMP6_ECHO_REQUEST;
|
---|
171 | icmp6h->code = 0;
|
---|
172 | icmp6h->icmp6_id = htons(send_icmp6_id);
|
---|
173 | icmp6h->icmp6_seq= 0;
|
---|
174 |
|
---|
175 | /* ãã¼ã¿ãè¨å®ããã*/
|
---|
176 | sdu = GET_ICMP6_SDU(output, IF_IP6_ICMP6_HDR_OFFSET) + size;
|
---|
177 | for (ix = size; ix -- > 0; )
|
---|
178 | *-- sdu = ('0' + send_icmp6_id + ix) & 0xff;
|
---|
179 |
|
---|
180 | /* ãã§ãã¯ãµã ãè¨ç®ããã*/
|
---|
181 | icmp6h->sum = 0;
|
---|
182 | icmp6h->sum = in6_cksum(output, IPPROTO_ICMPV6,
|
---|
183 | (uint8_t*)icmp6h - output->buf, ICMP6_HDR_SIZE + size);
|
---|
184 |
|
---|
185 | /* å¿çãã§ãã¯ç¨ã®å¤æ°ãè¨å®ããã*/
|
---|
186 | reply_count = 0;
|
---|
187 |
|
---|
188 | #if 0
|
---|
189 | curr_icmp6_id = send_icmp6_id ++;
|
---|
190 | curr_icmp6_size = size;
|
---|
191 | #endif
|
---|
192 |
|
---|
193 | #if 0
|
---|
194 | syslog(LOG_NOTICE, "[PING6] send: TMO:%d, SIZE:%d, to: %s, from %s",
|
---|
195 | tmo, size,
|
---|
196 | ipv62str(NULL, addr), ipv62str(NULL, &ia->addr));
|
---|
197 | #endif
|
---|
198 |
|
---|
199 | /* éä¿¡å¾ãç¾å¨ã®æéãè¨æ¶ããã¿ã¤ã ã¢ã¦ããè¨å®ããã*/
|
---|
200 | ip6_output(output, ipflags, TMO_FEVR);
|
---|
201 | NET_COUNT_MIB(icmp6_ifstat.ipv6IfIcmpOutMsgs, 1);
|
---|
202 | NET_COUNT_MIB(icmp6_ifstat.ipv6IfIcmpOutEchos, 1);
|
---|
203 |
|
---|
204 | syscall(get_tim(&icmp6_start_time));
|
---|
205 | timeout(icmp6_reply_timeout, NULL, tmo * NET_TIMER_HZ);
|
---|
206 |
|
---|
207 | }
|
---|
208 |
|
---|
209 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
210 |
|
---|
211 | #endif /* of #ifdef USE_PING */
|
---|