Skip to content

Conversation

@snormore
Copy link
Contributor

Summary

Adds support for explicitly setting the ICMP source address when sending ping requests. Previously, the source IP was determined by system routing; with this change, the existing Pinger.Source field (already used for binding) is also applied to outgoing packets, allowing control over which local address is used.

Motivation

On systems with multiple interfaces or addresses, it’s often useful to choose the source IP for ICMP echo requests—for example, to test reachability or routing behavior from a specific interface. This change makes the Source field consistent across bind and send operations.

Example

p, _ := probing.NewPinger("8.8.8.8")
p.Source = "192.168.1.10"
p.Run()

This sends ICMP packets using 192.168.1.10 as the source.

Copy link
Contributor

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

We also need a test for invalid pinger.Source values.

@snormore
Copy link
Contributor Author

Thanks @SuperQ - I pushed those updates in new commits. If it looks good I can squash them into the original commit and fix the DCO CI failure.

Copy link
Contributor

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

Nice, thanks.

Previously, the source IP for ICMP echo requests was determined by
system routing. This change applies the Pinger.Source value—already
used when binding the socket—to outgoing control messages as well,
allowing users to specify which local address ICMP packets originate
from.

This is useful on multi-interface systems or when testing routing
behavior from specific local addresses.

Signed-off-by: Steven Normore <[email protected]>
@SuperQ SuperQ merged commit 1478ef5 into prometheus-community:main Oct 23, 2025
5 checks passed
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.

2 participants