zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.52k stars 6.46k forks source link

eth: ping: can't ping others from zephyr console #7989

Closed qianfan-Zhao closed 6 years ago

qianfan-Zhao commented 6 years ago

my custom board(ip: 192.168.3.25) can't ping others(ip: 192.168.3.101, win10) in console.

net> ping 192.168.3.101                                                               
Sent a ping to 192.168.3.101                                                          
Ping timeout                                                                          
net> 

but from my win10 computer can ping Zephyr:

C:\Users\qianfan>ping 192.168.3.25  -t

正在 Ping 192.168.3.25 具有 32 字节的数据:
来自 192.168.3.25 的回复: 字节=32 时间=1ms TTL=128
来自 192.168.3.25 的回复: 字节=32 时间=1ms TTL=128
来自 192.168.3.25 的回复: 字节=32 时间=1ms TTL=128
来自 192.168.3.25 的回复: 字节=32 时间=1ms TTL=128
来自 192.168.3.25 的回复: 字节=32 时间=1ms TTL=128
来自 192.168.3.25 的回复: 字节=32 时间=1ms TTL=128

192.168.3.25 的 Ping 统计信息:
    数据包: 已发送 = 6,已接收 = 6,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 1ms,最长 = 1ms,平均 = 1ms
Control-C
^C

this is the capture from wireshark:

15  17.012626       Broadcast   ARP 60  Who has 192.168.3.101? Tell 192.168.3.25
16  17.013821       Stmicroe_69:00:c2   ARP 60  192.168.3.101 is at e0:94:67:d6:eb:a1
17  17.013882   192.168.3.25    192.168.3.101   ICMP    60  Echo (ping) request  id=0x6ec4, seq=14628/9273, ttl=64 (no response found!)
Frame 17: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
    Interface id: 0 (\Device\NPF_{B0FBA592-04BB-4FD0-8E73-033577335F1B})
        Interface name: \Device\NPF_{B0FBA592-04BB-4FD0-8E73-033577335F1B}
    Encapsulation type: Ethernet (1)
    Arrival Time: May 29, 2018 15:36:55.012391000 中国标准时间
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1527579415.012391000 seconds
    [Time delta from previous captured frame: 0.000061000 seconds]
    [Time delta from previous displayed frame: 0.000061000 seconds]
    [Time since reference or first frame: 17.013882000 seconds]
    Frame Number: 17
    Frame Length: 60 bytes (480 bits)
    Capture Length: 60 bytes (480 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: eth:ethertype:ip:icmp]
    [Coloring Rule Name: ICMP]
    [Coloring Rule String: icmp || icmpv6]
Ethernet II, Src: Stmicroe_69:00:c2 (00:80:e1:69:00:c2), Dst: IntelCor_d6:eb:a1 (e0:94:67:d6:eb:a1)
    Destination: IntelCor_d6:eb:a1 (e0:94:67:d6:eb:a1)
        Address: IntelCor_d6:eb:a1 (e0:94:67:d6:eb:a1)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Source: Stmicroe_69:00:c2 (00:80:e1:69:00:c2)
        Address: Stmicroe_69:00:c2 (00:80:e1:69:00:c2)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: IPv4 (0x0800)
    Padding: 000000000000000000000000000000000000
Internet Protocol Version 4, Src: 192.168.3.25, Dst: 192.168.3.101
    0100 .... = Version: 4
    .... 0101 = Header Length: 20 bytes (5)
    Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
        0000 00.. = Differentiated Services Codepoint: Default (0)
        .... ..00 = Explicit Congestion Notification: Not ECN-Capable Transport (0)
    Total Length: 28
    Identification: 0x0000 (0)
    Flags: 0x00
        0... .... = Reserved bit: Not set
        .0.. .... = Don't fragment: Not set
        ..0. .... = More fragments: Not set
    Fragment offset: 0
    Time to live: 64
    Protocol: ICMP (1)
    Header checksum: 0x7ae2 [validation disabled]
    [Header checksum status: Unverified]
    Source: 192.168.3.25
    Destination: 192.168.3.101
    [Source GeoIP: Unknown]
    [Destination GeoIP: Unknown]
Internet Control Message Protocol
    Type: 8 (Echo (ping) request)
    Code: 0
    Checksum: 0x5017 [correct]
    [Checksum Status: Good]
    Identifier (BE): 28356 (0x6ec4)
    Identifier (LE): 50286 (0xc46e)
    Sequence number (BE): 14628 (0x3924)
    Sequence number (LE): 9273 (0x2439)
    [No response seen]
        [Expert Info (Warning/Sequence): No response seen to ICMP request]
            [No response seen to ICMP request]
            [Severity level: Warning]
            [Group: Sequence]
qianfan-Zhao commented 6 years ago

ping win10 from zephyr's console continued, seems the first time after ARP failed and the next time successful.

shell> select net                                                                                
net> ping 192.168.3.101                                                                          
Sent a ping to 192.168.3.101                                                                     
Ping timeout                                                                                     
net> ping 192.168.3.101                                                                          
Sent a ping to 192.168.3.101                                                                     
Received echo reply from 192.168.3.101 to 192.168.3.25                                           
net> ping 192.168.3.101                                                                          
Sent a ping to 192.168.3.101                                                                     
Ping timeout                                                                                     
net> ping 192.168.3.101                                                                          
Sent a ping to 192.168.3.101                                                                     
Received echo reply from 192.168.3.101 to 192.168.3.25                                           
net> ping 192.168.3.101                                                                          
Sent a ping to 192.168.3.101                                                                     
Received echo reply from 192.168.3.101 to 192.168.3.25                                           
net> ping 192.168.3.101                                                                          
Sent a ping to 192.168.3.101                                                                     
Ping timeout                                                                                     
net> 

capture from wireshark:

22  33.645701           Broadcast       ARP 60  Who has 192.168.3.101? Tell 192.168.3.25
23  33.646615           Stmicroe_69:00:be   ARP 60  192.168.3.101 is at e0:94:67:d6:eb:a1
24  33.646683   192.168.3.25    192.168.3.101       ICMP    60  Echo (ping) request  id=0x53fb, seq=7771/23326, ttl=64 (no response found!)
31  43.645714   192.168.3.25    192.168.3.101       ICMP    60  Echo (ping) request  id=0xa83d, seq=29341/40306, ttl=64 (reply in 32)
32  43.646177   192.168.3.101   192.168.3.25        ICMP    60  Echo (ping) reply    id=0xa83d, seq=29341/40306, ttl=128 (request in 31)
36  48.501918           Stmicroe_69:00:be   ARP 60  Who has 192.168.3.25? Tell 192.168.3.101
37  48.501968           IntelCor_d6:eb:a1   ARP 60  192.168.3.25 is at 00:80:e1:69:00:be
47  64.323065   192.168.3.25    192.168.3.101       ICMP    60  Echo (ping) request  id=0x2e23, seq=63619/33784, ttl=64 (no response found!)
54  73.565826   192.168.3.25    192.168.3.101       ICMP    60  Echo (ping) request  id=0x7fb9, seq=18969/6474, ttl=64 (reply in 55)
55  73.566479   192.168.3.101   192.168.3.25        ICMP    60  Echo (ping) reply    id=0x7fb9, seq=18969/6474, ttl=128 (request in 54)
59  78.265330   192.168.3.25    192.168.3.101       ICMP    60  Echo (ping) request  id=0x0617, seq=53367/30672, ttl=64 (no response found!)
60  78.265954   192.168.3.101   192.168.3.25        ICMP    60  Echo (ping) reply    id=0x0617, seq=53367/30672, ttl=128 (request in 59)
61  78.513619           Stmicroe_69:00:be   ARP 60  Who has 192.168.3.25? Tell 192.168.3.101
62  78.513662           IntelCor_d6:eb:a1   ARP 60  192.168.3.25 is at 00:80:e1:69:00:be
66  83.093363   192.168.3.25    192.168.3.101       ICMP    60  Echo (ping) request  id=0x4cf1, seq=5969/20759, ttl=64 (no response found!)
tbursztyka commented 6 years ago

According to your wireshark logs, it's the responses that are not sent, so the issue does not seem to be on your Zephyr enabled board.

qianfan-Zhao commented 6 years ago

@tbursztyka yes zephyr has sent ICMP packet but doens't get reply sometimes.

tbursztyka commented 6 years ago

yes, and according to your wireshark logs the response is not sent by the destination (win10), so either your win10 does not receives it or something else, but zephyr does not seem to have any issue here.

qianfan-Zhao commented 6 years ago

but sometimes ping successful and sometimes failed. not only my computer but also my route(193.168.3.1)has same appears

qianfan-Zhao commented 6 years ago

@tbursztyka @jukkar I had enable "Validata the IPv4 checksum if possible" option and found the checksum in IP part is incorrent. please refer Frame 47

Frame 47: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
Ethernet II, Src: Stmicroe_69:00:be (00:80:e1:69:00:be), Dst: IntelCor_d6:eb:a1 (e0:94:67:d6:eb:a1)
Internet Protocol Version 4, Src: 192.168.3.25, Dst: 192.168.3.101
    0100 .... = Version: 4
    .... 0101 = Header Length: 20 bytes (5)
    Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
    Total Length: 28
    Identification: 0x0000 (0)
    Flags: 0x00
    Fragment offset: 0
    Time to live: 64
    Protocol: ICMP (1)
    Header checksum: 0xd5cd incorrect, should be 0xf312(may be caused by "IP checksum offload"?)
        [Expert Info (Error/Checksum): Bad checksum [should be 0xf312]]
    [Header checksum status: Bad]
    [Calculated Checksum: 0xf312]
    Source: 192.168.3.25
    Destination: 192.168.3.101
    [Source GeoIP: Unknown]
    [Destination GeoIP: Unknown]
Internet Control Message Protocol

AND seems checksum always incorrect if there has an ARP packet before ICMP.

qianfan-Zhao commented 6 years ago

I print all IPv4's data in calc_chksum in this way:

--- a/subsys/net/ip/utils.c
+++ b/subsys/net/ip/utils.c
@@ -379,6 +379,14 @@ static u16_t calc_chksum(u16_t sum, const u8_t *ptr, u16_t len)
        const u8_t *end;

        end = ptr + len - 1;
+       const u8_t *p = ptr;
+
+       if (len == 20) {
+               while (p <= end) {
+                       printk("%02x ", *p++);
+               }
+               printk("\n");
+       }

If I always ping a const ip address, the data in IPv4 part should be fixed, but it doesn't.

shell> select net
net> ping 192.168.3.101
45 00 00 1c 00 00 00 00 40 01 00 00 00 00 00 00 00 00 00 00
Sent a ping to 192.168.3.101
Ping timeout
net> ping 192.168.3.101
45 00 00 1c 00 00 00 00 40 01 00 00 c0 a8 03 19 c0 a8 03 65
Sent a ping to 192.168.3.101
Received echo reply from 192.168.3.101 to 192.168.3.25
net> ping 192.168.3.101
45 00 00 1c 00 00 00 00 40 01 00 00 01 d2 c0 a8 03 19 e0 94
Sent a ping to 192.168.3.101
Ping timeout

AND I had fixed this issue in #8058

tbursztyka commented 6 years ago

That clarifies indeed, good catch