prometheus-community / pro-bing

A library for creating continuous probers
MIT License
309 stars 52 forks source link

Workaround unprivileged PacketConn on darwin returns the entire IP packet in icmp.ListenPacket() #37

Closed floatingstatic closed 1 year ago

floatingstatic commented 1 year ago

TLDR: unprivileged icmp echo replies are discarded on macOS (darwin)

This is a patch to work around an issue described in https://github.com/golang/go/issues/47369 which can be summarized as follows:

Due to setting the IP_STRPHDR socket option in darwin (macOS) environments, reads on unprivileged sockets (udp) include the IP header before the ICMP header in the read bytes returned by icmp.ListenPacket(). As a result of this, pro-bing ends up discarding icmp echo replies due to the unexpected ip header bytes returned by icmp.ListenPacket().

While this problem needs to be addressed in go itself, this patch provides a work around until this issue is addressed.

floatingstatic commented 1 year ago

Also worth pointing out pinger.SetPrivileged(true) works fine on macOS, this is only a problem when this is false