diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-09-29 14:13:04 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-09-29 14:13:04 +0000 |
commit | ccb682f332e5ad1d9cdfd97a9a3ee12e6d00b898 (patch) | |
tree | 6aaf796d9badf837309fab85bfcd77e79f3d12d1 /nuttx/net/uip/uip_icmpping.c | |
parent | 4333422d5fb28a10118a186f8af53c903a49b7bc (diff) | |
download | px4-firmware-ccb682f332e5ad1d9cdfd97a9a3ee12e6d00b898.tar.gz px4-firmware-ccb682f332e5ad1d9cdfd97a9a3ee12e6d00b898.tar.bz2 px4-firmware-ccb682f332e5ad1d9cdfd97a9a3ee12e6d00b898.zip |
Fix problem with ping that prevent ping from going outside local network (Darcy Gong)
git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5204 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/net/uip/uip_icmpping.c')
-rw-r--r-- | nuttx/net/uip/uip_icmpping.c | 157 |
1 files changed, 82 insertions, 75 deletions
diff --git a/nuttx/net/uip/uip_icmpping.c b/nuttx/net/uip/uip_icmpping.c index 356187d09..e3ebf7252 100644 --- a/nuttx/net/uip/uip_icmpping.c +++ b/nuttx/net/uip/uip_icmpping.c @@ -148,122 +148,129 @@ static inline int ping_timeout(struct icmp_ping_s *pstate) ****************************************************************************/ static uint16_t ping_interrupt(struct uip_driver_s *dev, void *conn, - void *pvpriv, uint16_t flags) + void *pvpriv, uint16_t flags) { struct icmp_ping_s *pstate = (struct icmp_ping_s *)pvpriv; uint8_t *ptr; - int failcode = -ETIMEDOUT; int i; nllvdbg("flags: %04x\n", flags); if (pstate) { - /* Check if this device is on the same network as the destination device. */ - - if (!uip_ipaddr_maskcmp(pstate->png_addr, dev->d_ipaddr, dev->d_netmask)) - { - /* Destination address was not on the local network served by this - * device. If a timeout occurs, then the most likely reason is - * that the destination address is not reachable. - */ + /* Check if this is a ICMP ECHO reply. If so, return the sequence + * number to the caller. NOTE: We may not even have sent the + * requested ECHO request; this could have been the delayed ECHO + * response from a previous ping. + */ - nllvdbg("Not reachable\n"); - failcode = -ENETUNREACH; - } - else + if ((flags & UIP_ECHOREPLY) != 0 && conn != NULL) { - /* Check if this is a ICMP ECHO reply. If so, return the sequence - * number to the caller. NOTE: We may not even have sent the - * requested ECHO request; this could have been the delayed ECHO - * response from a previous ping. - */ + struct uip_icmpip_hdr *icmp = (struct uip_icmpip_hdr *)conn; + nlldbg("ECHO reply: id=%d seqno=%d\n", + ntohs(icmp->id), ntohs(icmp->seqno)); - if ((flags & UIP_ECHOREPLY) != 0 && conn != NULL) + if (ntohs(icmp->id) == pstate->png_id) { - struct uip_icmpip_hdr *icmp = (struct uip_icmpip_hdr *)conn; - nlldbg("ECHO reply: id=%d seqno=%d\n", ntohs(icmp->id), ntohs(icmp->seqno)); + /* Consume the ECHOREPLY */ - if (ntohs(icmp->id) == pstate->png_id) - { - /* Consume the ECHOREPLY */ + flags &= ~UIP_ECHOREPLY; + dev->d_len = 0; - flags &= ~UIP_ECHOREPLY; - dev->d_len = 0; + /* Return the result to the caller */ - /* Return the result to the caller */ - - pstate->png_result = OK; - pstate->png_seqno = ntohs(icmp->seqno); - goto end_wait; - } + pstate->png_result = OK; + pstate->png_seqno = ntohs(icmp->seqno); + goto end_wait; } + } - /* Check: - * If the outgoing packet is available (it may have been claimed - * by a sendto interrupt serving a different thread - * -OR- - * If the output buffer currently contains unprocessed incoming - * data. - * -OR- - * If we have alread sent the ECHO request - * - * In the first two cases, we will just have to wait for the next - * polling cycle. - */ + /* Check: + * If the outgoing packet is available (it may have been claimed + * by a sendto interrupt serving a different thread) + * -OR- + * If the output buffer currently contains unprocessed incoming + * data. + * -OR- + * If we have alread sent the ECHO request + * + * In the first two cases, we will just have to wait for the next + * polling cycle. + */ - if (dev->d_sndlen <= 0 && /* Packet available */ - (flags & UIP_NEWDATA) == 0 && /* No incoming data */ - !pstate->png_sent) /* Request not sent */ - { - struct uip_icmpip_hdr *picmp = ICMPBUF; + if (dev->d_sndlen <= 0 && /* Packet available */ + (flags & UIP_NEWDATA) == 0 && /* No incoming data */ + !pstate->png_sent) /* Request not sent */ + { + struct uip_icmpip_hdr *picmp = ICMPBUF; - /* We can send the ECHO request now. - * - * Format the ICMP ECHO request packet - */ + /* We can send the ECHO request now. + * + * Format the ICMP ECHO request packet + */ - picmp->type = ICMP_ECHO_REQUEST; - picmp->icode = 0; + picmp->type = ICMP_ECHO_REQUEST; + picmp->icode = 0; #ifndef CONFIG_NET_IPv6 - picmp->id = htons(pstate->png_id); - picmp->seqno = htons(pstate->png_seqno); + picmp->id = htons(pstate->png_id); + picmp->seqno = htons(pstate->png_seqno); #else # error "IPv6 ECHO Request not implemented" #endif - /* Add some easily verifiable data */ + /* Add some easily verifiable data */ - for (i = 0, ptr = ICMPDAT; i < pstate->png_datlen; i++) - { - *ptr++ = i; - } + for (i = 0, ptr = ICMPDAT; i < pstate->png_datlen; i++) + { + *ptr++ = i; + } - /* Send the ICMP echo request. Note that d_sndlen is set to - * the size of the ICMP payload and does not include the size - * of the ICMP header. - */ + /* Send the ICMP echo request. Note that d_sndlen is set to + * the size of the ICMP payload and does not include the size + * of the ICMP header. + */ - nlldbg("Send ECHO request: seqno=%d\n", pstate->png_seqno); + nlldbg("Send ECHO request: seqno=%d\n", pstate->png_seqno); - dev->d_sndlen = pstate->png_datlen + 4; - uip_icmpsend(dev, &pstate->png_addr); - pstate->png_sent = true; - return flags; - } + dev->d_sndlen = pstate->png_datlen + 4; + uip_icmpsend(dev, &pstate->png_addr); + pstate->png_sent = true; + return flags; } /* Check if the selected timeout has elapsed */ if (ping_timeout(pstate)) { - /* Yes.. report the timeout */ + int failcode; + + /* Check if this device is on the same network as the destination + * device. + */ + + if (!uip_ipaddr_maskcmp(pstate->png_addr, dev->d_ipaddr, dev->d_netmask)) + { + /* Destination address was not on the local network served by this + * device. If a timeout occurs, then the most likely reason is + * that the destination address is not reachable. + */ + + nlldbg("Not reachable\n"); + failcode = -ENETUNREACH; + } + else + { + nlldbg("Ping timeout\n"); + failcode = -ETIMEDOUT; + } + + /* Report the failure */ - nlldbg("Ping timeout\n"); pstate->png_result = failcode; goto end_wait; } /* Continue waiting */ } + return flags; end_wait: |