Skip to content

x/net/route: IPv4 netmasks parsed incorrectly when parsing reply of RTM_GET #71578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hurricanehrndz opened this issue Feb 5, 2025 · 2 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@hurricanehrndz
Copy link

Go version

go version go1.23.5 darwin/arm64

Output of go env in your module/workspace:

NA

What did you do?

https://go.dev/play/p/k7RfzHvKvBg

Netmask should be 255.0.0.0

run the following to confirm

route get 127.0.0.1

It seems macOS like other UNIX systems stores netmasks in radix trie data structures, but completely ignores the family field of a sockaddr that represents a netmask. Reading TCP-IP-Illustrated-Volume-2 has led me to this conclusion for three reasons:

  1. On page 620: The second argument, dst, is a socket address structure specifying the key to be added or deleted
    from the routing table. The sa_family from this key selects the routing table

  2. In the illustration of the radix mask structure, the family is specifically denote as being unspecified (pg 588)

Image

  1. Below the illustration it states the following: The mask structure pointed to by rn_mask (pg 588)
    and rm_mask has a length of 8 and a family of 0 (this family is AF_UNSPEC, but it is never
    even looked at).

So netmask address should ignore the family field and depend on family of the DST

What did you see happen?

When attempting to replicate route get

What did you expect to see?

The correct netmask 255.0.0.0

@hurricanehrndz
Copy link
Author

I will try to address the issue

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Feb 5, 2025
hurricanehrndz added a commit to hurricanehrndz/golang-net that referenced this issue Feb 6, 2025
On Darwin, the AF_FAMILY byte of a sockaddr for a netmask or genmask
can be ignored if unreasonable. In such cases, it is the family of the
DST address that should instead be used.

Fixes golang/go#71578.
hurricanehrndz added a commit to hurricanehrndz/golang-net that referenced this issue Feb 6, 2025
On Darwin, the AF_FAMILY byte of a sockaddr for a netmask or genmask
can be ignored if unreasonable. In such cases, it is the family of the
DST address that should instead be used.

Depends on golang#231.
Fixes golang/go#71578.
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/647176 mentions this issue: route: fix RTM_GET netmask parsing on Darwin

@cherrymui cherrymui added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. FixPending Issues that have a fix which has not yet been reviewed or submitted. labels Feb 7, 2025
@cherrymui cherrymui added this to the Backlog milestone Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants