[270] | 1 | /*
|
---|
| 2 | * TINET (TCP/IP Protocol Stack)
|
---|
| 3 | *
|
---|
| 4 | * Copyright (C) 2001-2009 by Dep. of Computer Science and Engineering
|
---|
| 5 | * Tomakomai National College of Technology, JAPAN
|
---|
| 6 | *
|
---|
| 7 | * ä¸è¨èä½æ¨©è
|
---|
| 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 270 2017-02-09 04:03:47Z 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_buf.h>
|
---|
| 76 | #include <net/net_timer.h>
|
---|
| 77 | #include <net/net_count.h>
|
---|
| 78 |
|
---|
| 79 | #include <netinet/in.h>
|
---|
| 80 | #include <netinet/in_var.h>
|
---|
| 81 |
|
---|
| 82 | #include <netinet6/in6.h>
|
---|
| 83 | #include <netinet6/in6_var.h>
|
---|
| 84 | #include <netinet6/nd6.h>
|
---|
| 85 |
|
---|
| 86 | #include <netinet/ip6.h>
|
---|
| 87 | #include <netinet6/ip6_var.h>
|
---|
| 88 | #include <netinet/icmp6.h>
|
---|
| 89 |
|
---|
| 90 | #include <net/if6_var.h>
|
---|
| 91 |
|
---|
| 92 | #ifdef USE_PING
|
---|
| 93 |
|
---|
| 94 | /*
|
---|
| 95 | * å¤æ°
|
---|
| 96 | */
|
---|
| 97 |
|
---|
| 98 | static uint16_t send_icmp6_id = 0;
|
---|
| 99 | static uint16_t curr_icmp6_id;
|
---|
| 100 | static uint16_t curr_icmp6_size;
|
---|
| 101 | static uint16_t reply_count;
|
---|
| 102 | static SYSTIM icmp6_start_time;
|
---|
| 103 |
|
---|
| 104 | /*
|
---|
| 105 | * icmp6_reply_timeout -- ICMP6 REPLY ã¿ã¤ã ã¢ã¦ãå¦ç
|
---|
| 106 | */
|
---|
| 107 |
|
---|
| 108 | static void
|
---|
| 109 | icmp6_reply_timeout (void *arg)
|
---|
| 110 | {
|
---|
| 111 | if (reply_count == 0)
|
---|
| 112 | syslog(LOG_NOTICE, "[PING6] request timeout.");
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | /*
|
---|
| 116 | * icmp6_echo_reply -- ICMP6 ECHO REPLY ã¡ãã»ã¼ã¸ãå¦çããã
|
---|
| 117 | */
|
---|
| 118 |
|
---|
| 119 | void
|
---|
| 120 | icmp6_echo_reply (T_NET_BUF *input, uint_t ihoff)
|
---|
| 121 | {
|
---|
| 122 | T_IP6_HDR *ip6h;
|
---|
| 123 | SYSTIM time;
|
---|
| 124 |
|
---|
| 125 | syscall(get_tim(&time));
|
---|
| 126 | ip6h = GET_IP6_HDR(input);
|
---|
| 127 |
|
---|
| 128 | syslog(LOG_NOTICE, "[PING6] reply: %5d [ms] from: %s",
|
---|
| 129 | (time - icmp6_start_time) * 1000 / SYSTIM_HZ,
|
---|
| 130 | ipv62str(NULL, &ip6h->src));
|
---|
| 131 | reply_count ++;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | /*
|
---|
| 135 | * ping6 -- ICMP ECHO ã¡ãã»ã¼ã¸ãéä¿¡ããã
|
---|
| 136 | */
|
---|
| 137 |
|
---|
| 138 | void
|
---|
| 139 | ping6 (T_IN6_ADDR *addr, uint_t tmo, uint_t size)
|
---|
| 140 | {
|
---|
| 141 | T_IFNET *ifp = IF_GET_IFNET();
|
---|
| 142 | T_ICMP6_HDR *icmp6h;
|
---|
| 143 | T_NET_BUF *output;
|
---|
| 144 | T_IN6_IFADDR *ia;
|
---|
| 145 | int_t ix;
|
---|
| 146 | uint16_t ipflags = 0;
|
---|
| 147 | uint8_t *sdu;
|
---|
| 148 |
|
---|
| 149 | /*
|
---|
| 150 | * å®å
|
---|
| 151 | ã¢ãã¬ã¹ã«ãµããããéä¿¡å
|
---|
| 152 | ã¢ãã¬ã¹ãã
|
---|
| 153 | * ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ããæ¢ç´¢ãã¦å©ç¨ããã
|
---|
| 154 | */
|
---|
| 155 | if ((ia = in6_ifawithifp(ifp, addr)) == NULL)
|
---|
| 156 | return;
|
---|
| 157 |
|
---|
| 158 | if (IN6_IS_ADDR_MULTICAST(addr))
|
---|
| 159 | ipflags = IPV6_OUT_SET_HOP_LIMIT(IPV6_OUT_FLG_HOP_LIMIT, IPV6_DEFHLIM);
|
---|
| 160 |
|
---|
| 161 | /* éä¿¡ç¨ã® IP ãã¼ã¿ã°ã©ã ãç²å¾ããã*/
|
---|
| 162 | if (in6_get_datagram(&output, ICMP6_HDR_SIZE + size, 0,
|
---|
| 163 | addr, &ia->addr, IPPROTO_ICMPV6,
|
---|
| 164 | IPV6_DEFHLIM, NBA_SEARCH_ASCENT, TMO_FEVR) != E_OK)
|
---|
| 165 | return;
|
---|
| 166 |
|
---|
| 167 | /* ICMP ããããè¨å®ããã*/
|
---|
| 168 | icmp6h = GET_ICMP6_HDR(output, IF_IP6_ICMP6_HDR_OFFSET);
|
---|
| 169 | icmp6h->type = ICMP6_ECHO_REQUEST;
|
---|
| 170 | icmp6h->code = 0;
|
---|
| 171 | icmp6h->icmp6_id = htons(send_icmp6_id);
|
---|
| 172 | icmp6h->icmp6_seq= 0;
|
---|
| 173 |
|
---|
| 174 | /* ãã¼ã¿ãè¨å®ããã*/
|
---|
| 175 | sdu = GET_ICMP6_SDU(output, IF_IP6_ICMP6_HDR_OFFSET) + size;
|
---|
| 176 | for (ix = size; ix -- > 0; )
|
---|
| 177 | *-- sdu = ('0' + send_icmp6_id + ix) & 0xff;
|
---|
| 178 |
|
---|
| 179 | /* ãã§ãã¯ãµã ãè¨ç®ããã*/
|
---|
| 180 | icmp6h->sum = 0;
|
---|
| 181 | icmp6h->sum = in6_cksum(output, IPPROTO_ICMPV6,
|
---|
| 182 | (uint8_t*)icmp6h - output->buf, ICMP6_HDR_SIZE + size);
|
---|
| 183 |
|
---|
| 184 | /* å¿çãã§ãã¯ç¨ã®å¤æ°ãè¨å®ããã*/
|
---|
| 185 | curr_icmp6_id = send_icmp6_id ++;
|
---|
| 186 | curr_icmp6_size = size;
|
---|
| 187 |
|
---|
| 188 | reply_count = 0;
|
---|
| 189 |
|
---|
| 190 | syslog(LOG_NOTICE, "[PING6] send: TMO:%d, SIZE:%d, to: %s, from %s",
|
---|
| 191 | tmo, size,
|
---|
| 192 | ipv62str(NULL, addr), ipv62str(NULL, &ia->addr));
|
---|
| 193 |
|
---|
| 194 | /* éä¿¡å¾ãç¾å¨ã®æéãè¨æ¶ããã¿ã¤ã ã¢ã¦ããè¨å®ããã*/
|
---|
| 195 | ip6_output(output, ipflags, TMO_FEVR);
|
---|
| 196 | NET_COUNT_MIB(icmp6_ifstat.ipv6IfIcmpOutMsgs, 1);
|
---|
| 197 | NET_COUNT_MIB(icmp6_ifstat.ipv6IfIcmpOutEchos, 1);
|
---|
| 198 |
|
---|
| 199 | syscall(get_tim(&icmp6_start_time));
|
---|
| 200 | timeout(icmp6_reply_timeout, NULL, tmo * NET_TIMER_HZ);
|
---|
| 201 |
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | #endif /* of #ifdef USE_PING */
|
---|