Skip to content

net: document possible networks for {Dialer,ListenConfig}.Control #69693

@favonia

Description

@favonia

Go version

go version go1.23.1 linux/amd64

What did you do?

The Control function is useful for enforcing IPv4 or IPv6 on a dual-stack machine. The idea is to selectively reject IPv6 for IPv4-only connections and IPv4 for IPv6-only ones. However, in order to do so, it's crucial to identify known networks that could be sent to the Control function. A demonstration of the idea is at https://go.dev/play/p/ttwNDrCXpla

What did you see happen?

The current documentation says:

	// Network and address parameters passed to Control function are not
	// necessarily the ones passed to Dial. For example, passing "tcp" to Dial
	// will cause the Control function to be called with "tcp4" or "tcp6".

The documentation is uncommitted about the behavior in other scenarios, such as udp and ip:<protocol>.

What did you expect to see?

The source code (across all platforms) seems to indicate the following relation between Dial/Listen and Control:

Input network for Dial/Listen Possible network for Control
unix, unixgram, unixpacket, udp4, udp6, tcp4, tcp6 Same network value
udp udp4 or udp6 (but not udp)
tcp tcp4 or tcp6 (but not tcp)
ip4:<protocol> ip4
ip6:<protocol> ip6
ip:<protocol> ip4 or ip6 (but not ip)

If the table is accurate, I wonder if we can explicitly document it?

Edits (after some comments)

I did not mean we should literally document the whole table. Documenting the general rules behind the table is sufficient! My real question is, can we document the general rules and guarantee that they will be followed in the future?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.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