Skip to content

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

Closed
@hurricanehrndz

Description

@hurricanehrndz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions