Skip to content

fix: sockaddr for ipv4 source addresses in ping probe - #1189

Merged
manugarg merged 1 commit into
cloudprober:mainfrom
rhodesn:rhodesn/ping-source-addr
Dec 19, 2025
Merged

manugarg merged 1 commit into
cloudprober:mainfrom
rhodesn:rhodesn/ping-source-addr

Conversation

@rhodesn

@rhodesn rhodesn commented Dec 18, 2025 •

Copy link
Copy Markdown
Contributor

Fixes a bug in the sockaddr function where configuring a specific IPv4 source_ip resulted in the probe binding to 0.0.0.0 (all interfaces) instead of the requested address.

The net.IP is a 16-byte slice, IPv4 mapped IPv6 in this case. The previous implementation used copy() to transfer the slice into the 4-byte syscall.SockaddrInet4.Addr array, however copy() only transfers the minimum length, which in this case is the 4-byte SockaddrInet4.Addr. The resulting sa.Addr is the first 4-bytes of the sourceIP (net.IP) which is just 0.0.0.0. So IPv4 source addresses were being ignored, and 0.0.0.0 was being bound to.

Fix is to get respective byte ranges for IPv4 and IPv6 before the copy.

@rhodesn rhodesn changed the title fix: fix sockaddr for ipv4 source addresses in ping probe fix: sockaddr for ipv4 source addresses in ping probe Dec 18, 2025
@rhodesn
rhodesn force-pushed the rhodesn/ping-source-addr branch 3 times, most recently from 28fe1c0 to cff23a0 Compare December 18, 2025 16:38
Fixes a bug in the sockaddr function where configuring a specific IPv4
source_ip resulted in the probe binding to 0.0.0.0 (all interfaces)
instead of the requested address.

The `net.IP` is a 16-byte slice, IPv4 mapped IPv6 in the case of this
bug. The previous implementation used `copy()` to transfer the slice
into the 4-byte `syscall.SockaddrInet4.Addr` array, however `copy()`
only transfers the minimum length, which in this case is the 4-byte
`SockaddrInet4.Addr`. The resulting `sa.Addr` is the first 4-bytes of
the `sourceIP (net.IP)` which is just `0.0.0.0`. So IPv4 source
addresses were being ignored, and `0.0.0.0` was being bound to.

Fix is to get respective byte ranges for IPv4 and IPv6 before the copy.
@rhodesn
rhodesn force-pushed the rhodesn/ping-source-addr branch from cff23a0 to 5e43645 Compare December 18, 2025 16:45

@manugarg manugarg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interesting. Thank you!

@manugarg
manugarg merged commit 31ed8bd into cloudprober:main Dec 19, 2025
@manugarg manugarg added this to the v0.14.2 milestone Dec 19, 2025
@rhodesn
rhodesn deleted the rhodesn/ping-source-addr branch December 22, 2025 11:37
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