Skip to content

Conversation

fcelda
Copy link
Contributor

@fcelda fcelda commented Aug 12, 2025

Hello. This PR cleans up a few quirks related to IPv4-mapped IPv6 address handling. It doesn't add any new functionality and the change should be backward compatible (at least, no tests broke).

TLDR: The PR replaces net.ParseIP and net.ParseCIDR with netip.ParseAddr and netip.ParsePrefix.

The old address parsing interface has some implicit behavior regarding IPv4-mapped IPv6 handling. Namely, any parsed IPv4 address is stored as IPv4-mapped IPv6 internally. At the same time, parsing explicit IPv4-mapped IPv6 address and converting it back to string will return the address in the IPv4 format. Essentially, net.ParseIP(in).String() == in is not always true.

This probably doesn't matter for most applications, however in case of a DNS library, there are a plenty of places where we need to distinguish IPv4 and IPv6 explicitly. The address parsing interface in the netip package works without the magical conversions and therefore seems to be better suited for our use case.

I've replaced the use of the old functions everywhere in the code for consistency except for unit tests where I think it doesn't matter. I've also added a few more tests. Please, let me know what you think and if I missed something else worth updating.

@fcelda fcelda requested review from miekg and tmthrgd as code owners August 12, 2025 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant