Skip to content

sptp: fix pktinfo build break on non-Linux platforms - #593

Closed
AasishDairelSahayaGrinspan wants to merge 1 commit into
meta:mainfrom
AasishDairelSahayaGrinspan:fix/sptp-pktinfo-crossplatform
Closed

AasishDairelSahayaGrinspan wants to merge 1 commit into
meta:mainfrom
AasishDairelSahayaGrinspan:fix/sptp-pktinfo-crossplatform

Conversation

@AasishDairelSahayaGrinspan

Copy link
Copy Markdown

Summary

golang.org/x/sys/unix declares Inet4Pktinfo.Ifindex as int32 on Linux, but as uint32 on darwin, solaris and z/OS. The direct assignment in pktInfo4Cmsg (ptp/sptp/client/connection.go) only compiles on Linux, which breaks the build of the whole sptp package — and therefore cmd/sptp — on non-Linux platforms:

ptp/sptp/client/connection.go:242:20: cannot use ifIndex (variable of type int32) as uint32 value in assignment

This makes local development and testing of the sptp client (e.g. go test ./ptp/sptp/...) impossible on a Mac, where fbclock is the only other Linux-only package and is easy to work around.

The fix keeps the existing int32 ifIndex4 representation and routes the assignment through a tiny per-platform setter (setInet4PktinfoIfindex), following the repo's existing _linux/_notlinux file convention. No behavior change on Linux.

Adds unit tests for both the IPv4 and IPv6 pktinfo control message builders, which verify level, type, size, destination address encoding and the (reinterpret-cast, platform-independent) interface index.

Test Plan

On macOS arm64 (where the bug reproduces on main):

  • go build ./ptp/... ./cmd/sptp/... — previously failed, now passes
  • go vet ./ptp/sptp/... — passes
  • go test ./ptp/sptp/client -run TestPktInfo -v — both new tests pass

Cross-platform sanity check for the Linux CI job:

  • CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./ptp/... ./cmd/sptp/... — passes
  • GOOS=linux GOARCH=amd64 go vet ./ptp/sptp/... — passes

golang.org/x/sys/unix declares Inet4Pktinfo.Ifindex as int32 on Linux,
but as uint32 on darwin, solaris and z/OS. The direct assignment in
pktInfo4Cmsg breaks compilation of the sptp package (and therefore
cmd/sptp) on non-Linux platforms.

Keep the struct's int32 representation and route the assignment through
a tiny per-platform setter, following the existing _linux/_notlinux
file convention. Add unit tests for both IPv4 and IPv6 pktinfo
control message builders.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 5, 2026
@meta-codesync

meta-codesync Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@pmazzini has imported this pull request. If you are a Meta employee, you can view this in D130177894.

@leoleovich

Copy link
Copy Markdown
Contributor

This is slop

@leoleovich leoleovich closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants