[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: ping.c 270 2017-02-09 04:03:47Z coas-nagasima $
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 | /*
|
---|
| 47 | * ping -- ICMP 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 | #include <netinet/ip.h>
|
---|
| 82 | #include <netinet/ip_var.h>
|
---|
| 83 | #include <netinet/ip_icmp.h>
|
---|
| 84 | #include <netinet/icmp_var.h>
|
---|
| 85 |
|
---|
| 86 | #ifdef USE_PING
|
---|
| 87 |
|
---|
| 88 | /*
|
---|
| 89 | * å¤æ°
|
---|
| 90 | */
|
---|
| 91 |
|
---|
| 92 | static uint16_t icmp_id = 0;
|
---|
| 93 | static uint16_t curr_icmp_id;
|
---|
| 94 | static uint16_t curr_icmp_len;
|
---|
| 95 | static SYSTIM icmp_start_time;
|
---|
| 96 |
|
---|
| 97 | /*
|
---|
| 98 | * icmp_reply_timeout -- ICMP REPLY ã¿ã¤ã ã¢ã¦ãå¦ç
|
---|
| 99 | */
|
---|
| 100 |
|
---|
| 101 | static void
|
---|
| 102 | icmp_reply_timeout (void *arg)
|
---|
| 103 | {
|
---|
| 104 | syslog(LOG_NOTICE, "[PING] request timeout.");
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | /*
|
---|
| 108 | * icmp_echo_reply -- ICMP ECHO REPLY ã¡ãã»ã¼ã¸ãå¦çããã
|
---|
| 109 | */
|
---|
| 110 |
|
---|
| 111 | void
|
---|
| 112 | icmp_echo_reply (T_NET_BUF *input, uint_t ihoff)
|
---|
| 113 | {
|
---|
| 114 | SYSTIM time;
|
---|
| 115 |
|
---|
| 116 | syscall(get_tim(&time));
|
---|
| 117 | untimeout(icmp_reply_timeout, NULL);
|
---|
| 118 | syslog(LOG_NOTICE, "[PING] reply, %d [ms].",
|
---|
| 119 | (time - icmp_start_time) * 1000 / SYSTIM_HZ);
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | /*
|
---|
| 123 | * ping4 -- ICMP ECHO ã¡ãã»ã¼ã¸ãéä¿¡ããã
|
---|
| 124 | */
|
---|
| 125 |
|
---|
| 126 | void
|
---|
| 127 | ping4 (T_IN4_ADDR *addr, uint_t tmo, uint_t len)
|
---|
| 128 | {
|
---|
| 129 | T_ICMP4_HDR *icmp4h;
|
---|
| 130 | T_NET_BUF *output;
|
---|
| 131 | uint8_t *sdu;
|
---|
| 132 | int_t ix;
|
---|
| 133 |
|
---|
| 134 | /* éä¿¡ç¨ã® IP ãã¼ã¿ã°ã©ã ãç²å¾ããã*/
|
---|
| 135 | if (in4_get_datagram(&output, ICMP4_HDR_SIZE + len, 0,
|
---|
| 136 | addr, NULL, IPPROTO_ICMP,
|
---|
| 137 | IP4_DEFTTL, NBA_SEARCH_ASCENT, TMO_FEVR) != E_OK)
|
---|
| 138 | return;
|
---|
| 139 |
|
---|
| 140 | /* ICMP ããããè¨å®ããã*/
|
---|
| 141 | icmp4h = GET_ICMP4_HDR(output, IF_IP4_ICMP4_HDR_OFFSET);
|
---|
| 142 | icmp4h->type = ICMP4_ECHO_REQUEST;
|
---|
| 143 | icmp4h->code = 0;
|
---|
| 144 | icmp4h->data.id_seq.id = htons(icmp_id);
|
---|
| 145 | icmp4h->data.id_seq.seq = 0;
|
---|
| 146 |
|
---|
| 147 | /* ãã¼ã¿ãè¨å®ããã*/
|
---|
| 148 | sdu = GET_ICMP4_SDU(output, IF_IP4_ICMP4_HDR_OFFSET) + len;
|
---|
| 149 | for (ix = len; ix -- > 0; )
|
---|
| 150 | *-- sdu = ('0' + icmp_id + ix) & 0xff;
|
---|
| 151 |
|
---|
| 152 | /* ãã§ãã¯ãµã ãè¨ç®ããã*/
|
---|
| 153 | icmp4h->sum = 0;
|
---|
| 154 | icmp4h->sum = in_cksum(icmp4h, ICMP4_HDR_SIZE + len);
|
---|
| 155 |
|
---|
| 156 | /* å¿çãã§ãã¯ç¨ã®å¤æ°ãè¨å®ããã*/
|
---|
| 157 | curr_icmp_id = icmp_id ++;
|
---|
| 158 | curr_icmp_len = len;
|
---|
| 159 |
|
---|
| 160 | NET_COUNT_MIB(icmp_stats.icmpOutMsgs, 1);
|
---|
| 161 | NET_COUNT_MIB(icmp_stats.icmpOutEchos, 1);
|
---|
| 162 |
|
---|
| 163 | /* éä¿¡å¾ãç¾å¨ã®æéãè¨æ¶ããã¿ã¤ã ã¢ã¦ããè¨å®ããã*/
|
---|
| 164 | ip_output(output, TMO_FEVR);
|
---|
| 165 |
|
---|
| 166 | syscall(get_tim(&icmp_start_time));
|
---|
| 167 | timeout(icmp_reply_timeout, NULL, tmo * NET_TIMER_HZ);
|
---|
| 168 |
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | #endif /* of #ifdef USE_PING */
|
---|