-
Notifications
You must be signed in to change notification settings - Fork 259
New option --traceroute to send a traceroute with fping #421
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
base: develop
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @gsnw-sebast, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new --traceroute option to fping, adding a trace_ttl field to the host_entry structure and a global traceroute_flag. The changes involve parsing the new option, setting the number of trials to 255 for traceroute, dynamically setting the IP TTL for outgoing IPv4 packets using setsockopt in the main loop, and handling ICMP_TIMXCEED and ICMP_ECHOREPLY messages to report hop information and manage the traceroute process. Review comments suggest improving the option parsing by using strcmp instead of strstr for exact matching, optimizing TTL setting by using sendmsg with ancillary data instead of setsockopt per packet (and noting the current lack of IPv6 support), standardizing time formatting with sprint_tm(), and replacing the magic number 100 with a named constant for better code clarity.
| }else{ | ||
| usage(1); | ||
| } | ||
| } else if (strstr(optparse_state.optlongname, "traceroute") != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using strcmp is safer here than strstr for checking the long option name. strstr could lead to incorrect behavior if another option name contains "traceroute" as a substring (e.g., --traceroute-foo). Since --traceroute doesn't take an argument, optparse_state.optlongname will be an exact match.
} else if (strcmp(optparse_state.optlongname, "traceroute") == 0) {| if (traceroute_flag) { | ||
| int ttl_set = h->trace_ttl; | ||
| if (ttl_set > 30) ttl_set = 30; | ||
| if (socket4 >= 0) { | ||
| if (setsockopt(socket4, IPPROTO_IP, IP_TTL, &ttl_set, sizeof(ttl_set))) | ||
| perror("setsockopt IP_TTL"); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of points on this section:
- Efficiency: Calling
setsockopt()for every packet sent is a system call and can be inefficient. A more performant approach is to usesendmsg()with ancillary data (cmsg) to set the TTL on a per-packet basis. This would involve modifyingsend_ping()andsocket_sendto_ping_ipv4(). - IPv6 Support: As noted in the PR description, this is IPv4-only. For completeness, IPv6 support would require adding similar logic for
socket6usingsetsockoptwithIPPROTO_IPV6andIPV6_UNICAST_HOPS.
cff90ac to
7cd41ff
Compare
auerswal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this, @gsnw-sebast!
At least on Linux, receiving ICMP error messages requires the use of raw sockets. Please add checks that fping opened raw sockets when using --traceroute.
I have not yet looked at all code in detail, this was a first glance.
5bbc365 to
5e5efb1
Compare
…ecks whether RAW socket is being used.
5e5efb1 to
799a495
Compare
|
Checklist with options that allow and tested
|
This is my first working version for sending a traceroute with fping.
It can be tested with the following command. I have omitted IPv6 for now, and some of the text still needs to be revised.
The primary focus was on the function itself.
./fping --traceroute 8.8.8.8