Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed wrong icmp header length #10

Merged
merged 1 commit into from
Aug 9, 2016
Merged

Fixed wrong icmp header length #10

merged 1 commit into from
Aug 9, 2016

Conversation

kylezhou
Copy link
Contributor

@kylezhou kylezhou commented Aug 2, 2016

ping_receive_ipv4() and ping_send_one_ipv4() incorrectly used struct icmp, whereas struct icmphdr should be used. struct icmp includes a 20-byte icmp_dun after icmp_hun, which causes the echo request to include an extra 20-byte zeros between icmp header and payload.

@octo octo added the Bugfix label Aug 5, 2016
@octo
Copy link
Owner

octo commented Aug 5, 2016

Hi @kylezhou, thank you very much for your patch! Unfortunately, struct icmphdr is not portable: on FreeBSD it is four bytes long: type, code and checksum. On Linux it is eight bytes long, because it also includes a four byte union, e.g. for the echo ID and sequence number. Maybe it would be easiest if we defined these struct ourselves …

I'm curious why I don't see the extra bytes on the network though. Is the kernel being smart on us?

Best regards,
—octo

@kylezhou
Copy link
Contributor Author

kylezhou commented Aug 5, 2016

Hi @octo, I was not aware of the difference in BSD. You are right struct icmphdr is not a good choice. It even does not exist on osx. Should we simply use the macro ICMP_MINLEN in place of sizeof(struct icmphdr), which is always defined to 8 in all platforms I checked.

@kylezhou
Copy link
Contributor Author

kylezhou commented Aug 5, 2016

I tested the unchanged code on both an Ubuntu PC and an ARM router device, both show the extra 20 bytes. The icmp_dun field in struct icmp is the culprit. Did you do wireshark/tcpdump?

@octo
Copy link
Owner

octo commented Aug 5, 2016

Yeah, I compiled a clean master on an Ubuntu box with the eight byte struct icmphdr, captured the packets with tcpdump and visualized with Wireshark. No extra bytes between header and payload … ICMP_MINLEN looks promising – other tools such a Busybox and traceroute appear to be using it as well.

@octo
Copy link
Owner

octo commented Aug 5, 2016

Err, the eight byte struct icmphdr is of course not relevant to this bug: it used the large struct icmp with the icmp_dun union.

@kylezhou
Copy link
Contributor Author

kylezhou commented Aug 5, 2016

sorry, octo. I might misunderstood. when you did tcpdump, you used struct icmphdr or struct icmp?

@octo octo merged commit 2599a5d into octo:master Aug 9, 2016
@octo
Copy link
Owner

octo commented Aug 9, 2016

I used the vanilla master branch, i.e. with struct icmp and the offset that should have been too large.

I've replaced the sizeof (struct icmphdr) with ICMP_MINLEN now and cleaned up some other code while I was at it. Thanks again for fixing this!

Best regards,
—octo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants