Skip to content

New option --oiface for outgoing interface#463

Open
gsnw-sebast wants to merge 1 commit intoschweikert:developfrom
gsnw:oiface
Open

New option --oiface for outgoing interface#463
gsnw-sebast wants to merge 1 commit intoschweikert:developfrom
gsnw:oiface

Conversation

@gsnw-sebast
Copy link
Collaborator

With this new option, it should be possible to send a packet on one interface and receive any packet on another. There is no fallback to SO_BINDTODEVICE, for example. The -I option must be used for this.

Unfortunately, it is difficult for me to test this behavior. Therefore, I have only worked with the debugger.

@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 introduces a new --oiface command-line option for fping, enabling users to explicitly define the network interface through which outgoing ping packets are sent. This enhancement provides more granular control over network traffic, allowing pings to originate from a specific interface while still permitting the reception of responses from any available interface. The implementation utilizes IP_PKTINFO and IPV6_PKTINFO for robust interface binding.

Highlights

  • New --oiface option: Introduced a new command-line option --oiface to specify the outgoing network interface for ping packets.
  • Separate send/receive interfaces: This option allows sending packets via a specific interface while still being able to receive responses on any interface, differentiating it from the existing -I (SO_BINDTODEVICE) option.
  • IP_PKTINFO implementation: The functionality is implemented using IP_PKTINFO for IPv4 and IPV6_PKTINFO for IPv6, leveraging sendmsg to attach control messages with interface information.
  • Test case and documentation: A new test case was added for the --oiface option, and the fping man page was updated to include its description.

🧠 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.

Changelog
  • CHANGELOG.md
    • Added an entry for the new --oiface feature.
  • ci/test-07-options-i-m.pl
    • Increased the test count and added a new test case for the --oiface option, specifically for Linux.
  • doc/fping.pod
    • Documented the newly introduced --oiface command-line option, explaining its purpose.
  • src/fping.c
    • Registered the --oiface option in the command-line parser and added logic to handle its argument, calling interface-setting functions.
    • Added a check for IP_PKTINFO availability when --oiface is used.
  • src/fping.h
    • Declared new functions socket_set_outgoing_iface_ipv4 and socket_set_outgoing_iface_ipv6.
  • src/socket4.c
    • Included net/if.h for interface functions.
    • Added a static variable outgoing_iface_idx_ipv4 to store the outgoing interface index.
    • Implemented socket_set_outgoing_iface_ipv4 to resolve the interface name to an index and set the IP_PKTINFO socket option.
    • Modified socket_sendto_ping_ipv4 to use sendmsg with IP_PKTINFO control messages if an outgoing interface is specified.
  • src/socket6.c
    • Included net/if.h for interface functions.
    • Added a static variable outgoing_iface_idx_ipv6 to store the outgoing interface index.
    • Implemented socket_set_outgoing_iface_ipv6 to resolve the interface name to an index and set the IPV6_RECVPKTINFO socket option.
    • Modified socket_sendto_ping_ipv6 to use sendmsg with IPV6_PKTINFO control messages if an outgoing interface is specified.
Activity
  • The author, @gsnw-sebast, implemented the --oiface option to allow sending packets on one interface and receiving on another, noting it's distinct from SO_BINDTODEVICE.
  • The author mentioned that testing this specific behavior was challenging and primarily relied on debugger analysis.
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 Feb 22, 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 new --oiface option to specify the outgoing network interface for ping packets. The implementation correctly uses sendmsg with ancillary data (IP_PKTINFO for IPv4 and IPV6_PKTINFO for IPv6) to achieve this. The changes are well-structured and include documentation and a basic test case. My review includes a couple of suggestions for improvement: one to clarify a comment in the new test and another to make the command-line option parsing more robust to prevent potential issues with future options.

#endif
} else if (strstr(optparse_state.optlongname, "seqmap-timeout") != NULL) {
opt_seqmap_timeout = strtod_strict(optparse_state.optarg) * 1000000;
} else if (strstr(optparse_state.optlongname, "oiface") != NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using strstr to check for the option name is not robust. It could lead to incorrect behavior if another long option is added that contains "oiface" as a substring (e.g., --oiface-extra). A more precise check using strncmp would be safer and prevent potential future bugs. This applies to other long option checks in this block as well, but this change should at least be applied for the new option.

            } else if (strncmp(optparse_state.optlongname, "oiface", 6) == 0 && (optparse_state.optlongname[6] == '\0' || optparse_state.optlongname[6] == '=')) {

@coveralls
Copy link

coveralls commented Feb 22, 2026

Coverage Status

coverage: 87.467% (-0.6%) from 88.037%
when pulling 060128c on gsnw:oiface
into b862609 on schweikert:develop.

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.

New option for "outgoing interface"

2 participants