Skip to content

Conversation

@gsnw-sebast
Copy link
Collaborator

@gsnw-sebast gsnw-sebast commented Jan 3, 2026

The traceroute function is now complete. There is no JSON output in the current version, and testing is still pending, if it is even possible given the required root privileges.
IPv6 also works.

./fping --traceroute 8.8.8.8

Output

fping traceroute to 127.0.0.1 (127.0.0.1), 30 hops max, 84 byte packets
127.0.0.1: hop 1 reached DESTINATION 127.0.0.1 (0.055 ms)

Test Checklist

Option Test Supported
--ipv4 (-4) Yes Yes
--ipv6 (-6) Yes Yes
--alive (-a) Yes No (No effect)
--addr (-A) Yes Yes
--size (-b) Yes Yes (I couldn't really check the results and effects.)
--backoff (-B) Yes No (No effect)
--count (-c) Yes No
--vcount (-C) Yes No
--rdns (-d) Yes Yes
--timestamp (-D) Yes No
--elapsed (-e) Yes No (No effect)
--file (-f)
--generate (-g)
--ttl (-H) Yes Yes (1-30)
--interval (-i) Yes Yes
--iface (-I) No Yes (Untested)
--json (-j) No No (Next version)
--icmp-timestamp
--fwmark (-k) No No (Untested)
--loop (-l) Yes No
--all (-m) Yes No (No effect)
--dontfrag (-M) Yes Yes
--name (-n) Yes Yes
--netdata (-N) Yes No
--outage (-o)
--tos (-O) Yes Yes
--period (-p) Yes Yes (same effect as -i)
--quiet (-q) Yes No
--squiet (-Q) Yes No
--retry (-r) Yes No (No effect)
--random (-R) Yes Yes
--stats (-s) Yes No (Works, but the output is misleading)
--src (-S) No Yes (Untested)
--timeout (-t) Yes No (No effect)
(-T)
--unreach (-u) Yes No (No effect)
--retry (-r) Yes No (No effect)
--fast-reachable (-X)
--check-source Yes Yes
--print-tos Yes No
--print-ttl Yes No
--seqmap-timeout
(-z)

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 integrates a new traceroute capability into the fping utility, accessible via the --traceroute option. The implementation supports both IPv4 and IPv6, providing hop-by-hop path discovery to a target host. It includes necessary checks for root privileges and manages Time-To-Live (TTL) values to control hop limits. While the core functionality is complete, the current version focuses on standard output, with JSON output slated for a later release.

Highlights

  • New Traceroute Option: Introduces a new --traceroute command-line option to fping, allowing users to perform traceroute functionality.
  • IPv4 and IPv6 Support: The traceroute feature is implemented to work with both IPv4 and IPv6 addresses.
  • Root Privileges Required: The --traceroute option requires root privileges to operate, particularly for raw socket access on Linux.
  • Option Compatibility: The --traceroute option cannot be combined with several existing fping options, such as -c, -C, -l, -N, -q, -Q, -s, or -J.
  • TTL Management: A default TTL of 30 hops is set for traceroute, and any user-specified TTL exceeding 30 will be clamped to 30.
  • No JSON Output (Current Version): The initial implementation of the traceroute feature does not include JSON output, which is planned for a future version.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gsnw-sebast gsnw-sebast linked an issue Jan 3, 2026 that may be closed by this pull request
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 --traceroute option to fping, which is a significant and useful feature. The implementation correctly handles both IPv4 and IPv6, including the necessary ICMP message processing and TTL manipulation. The code is generally well-structured and follows the existing patterns in the codebase. I've provided a few suggestions to improve maintainability by reducing code duplication, enhance efficiency by optimizing memory allocation, and increase correctness in option parsing. Overall, this is a solid contribution.

@coveralls
Copy link

coveralls commented Jan 3, 2026

Coverage Status

coverage: 84.76% (-3.3%) from 88.037%
when pulling 6f7cc42 on gsnw:issue/62
into 7dcd667 on schweikert:develop.

@gsnw-sebast
Copy link
Collaborator Author

gsnw-sebast commented Jan 4, 2026

The code block for traceroute in the function int wait_for_reply(int64_t wait_time) can still be optimized and is currently structured purely functionally.

Update: Optimization completed

@gsnw-sebast gsnw-sebast force-pushed the issue/62 branch 2 times, most recently from 73d0936 to 15bc7d4 Compare January 4, 2026 07:13
@gsnw-sebast
Copy link
Collaborator Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 feature to fping. The implementation is comprehensive, covering both IPv4 and IPv6, and handling various fping options. However, I've found several issues that need to be addressed. There is a critical race condition when using traceroute with multiple hosts due to improper handling of socket options. I've also identified a high-severity buffer over-read vulnerability and a bug that affects IPv6 traceroute output. Additionally, there are several opportunities to improve code quality by removing hardcoded values and refactoring duplicated code.

@gsnw-sebast gsnw-sebast force-pushed the issue/62 branch 4 times, most recently from c013498 to c450285 Compare January 4, 2026 11:56
@gsnw-sebast
Copy link
Collaborator Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 feature, which is a great addition to fping's capabilities. The implementation is mostly complete and handles both IPv4 and IPv6. I've identified a few issues related to option parsing, the logic for the traceroute loop, and error handling that should be addressed to ensure correctness and robustness. Specifically, the check for the number of hosts in traceroute mode is currently ineffective, there's an off-by-one error in the traceroute loop, a potential infinite loop on the last hop, and the error handling for setsockopt could be strengthened. The documentation and general structure of the changes are well done.

if (traceroute_flag) {
printf("%s: hop %d no reply\n", h->host, h->trace_ttl);
h->trace_ttl++;
if (h->trace_ttl > (int)ttl) h->trace_ttl = (int)ttl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This line, which clamps h->trace_ttl to ttl, can cause an infinite loop. When the main loop condition is corrected to h->trace_ttl <= (int)ttl, if the last hop (ttl) times out, h->trace_ttl is incremented to ttl + 1 on the previous line, then clamped back to ttl here. The next ping event will then re-send a ping for the same hop ttl, leading to an infinite loop. This clamp should be removed, as the loop termination is correctly handled by the scheduler condition.

Comment on lines +4075 to +4102
if (h->trace_ttl > (int)ttl) {
h->trace_ttl = (int)ttl;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This block, which clamps h->trace_ttl to ttl, can cause an infinite loop. When the main loop condition is corrected to h->trace_ttl <= (int)ttl, if the last hop (ttl) does not reach the destination, h->trace_ttl is incremented to ttl + 1, then clamped back to ttl here. The next ping event will then re-send a ping for the same hop ttl, leading to an infinite loop if that hop also doesn't reach the destination. This clamp should be removed.

Comment on lines +1903 to +1909
if (setsockopt(socket4, IPPROTO_IP, IP_TTL, &ttl_set, sizeof(ttl_set)))
perror("setsockopt IP_TTL");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Failing to set the IP_TTL socket option is a fatal error for traceroute mode, as it won't be able to control the TTL of outgoing packets. The program should exit with an error instead of just printing to perror and continuing, which would lead to incorrect traceroute behavior.

                    if (setsockopt(socket4, IPPROTO_IP, IP_TTL, &ttl_set, sizeof(ttl_set)))
                        errno_crash_and_burn("setsockopt IP_TTL");

Comment on lines +1909 to +1916
if (setsockopt(socket6, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl_set, sizeof(ttl_set))) {
perror("setsockopt IPV6_UNICAST_HOPS");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Failing to set the IPV6_UNICAST_HOPS socket option is a fatal error for traceroute mode, as it won't be able to control the hop limit of outgoing packets. The program should exit with an error instead of just printing to perror and continuing, which would lead to incorrect traceroute behavior.

                    if (setsockopt(socket6, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl_set, sizeof(ttl_set))) {
                        errno_crash_and_burn("setsockopt IPV6_UNICAST_HOPS");
                    }

/* Loop and count mode: schedule next ping */
if (loop_flag || (count_flag && event->ping_index + 1 < count)) {
/* Loop, count and traceroute mode: schedule next ping */
if (loop_flag || (count_flag && event->ping_index + 1 < count) || (traceroute_flag && h->trace_ttl < (int)ttl)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The loop condition for traceroute, h->trace_ttl < (int)ttl, is an off-by-one error. If a user specifies --ttl 30, they expect fping to try all hops from 1 to 30. With the current condition, it will only try up to TTL 29. The condition should be h->trace_ttl <= (int)ttl to include the final hop.

            if (loop_flag || (count_flag && event->ping_index + 1 < count) || (traceroute_flag && h->trace_ttl <= (int)ttl)) {

@schweikert
Copy link
Owner

I appreciate the effort, but I am a bit sceptical about this change. It adds quite a bit of complexity, and I don't yet understand why it would be a useful addition to fping. In particular, the limitation of only allowing one host seems to defeat the purpose of adding this to fping, which is focused on doing parallel requests to multiple hosts.

@gsnw-sebast
Copy link
Collaborator Author

gsnw-sebast commented Jan 4, 2026

I wouldn't have expected such complexity, and querying different hosts doesn't make it any easier.

I would have no problem closing the function change or, if necessary, creating something like ftraceroute, i.e., an extra program based on fping outside of fping itself.

Especially since the tests are currently very complex

@auerswal
Copy link
Collaborator

auerswal commented Jan 6, 2026

I also appreciate the effort, but it seems to me as if this functionality does not really fit into the existing fping code. Please note that issue #71 explicitly asks for parallel traceroutes to multiple hosts.

@gsnw-sebast
Copy link
Collaborator Author

gsnw-sebast commented Jan 8, 2026

I took another look at the whole thing, and if sendmsg() is used instead of sendto(), a parallel query should be possible.
From my side, I couldn't find any reason why sendto() must be used.

I've now made the change. The output is still a bit ugly, but it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFE: option for "ftraceroute" functionality

4 participants