Conversation
findReverseZone keeps the matching reverse zones in a map and returns the one with the highest key, to get the most specific zone. The key was wrong. net.IPMask.Size() returns the prefix length first and the total bit count second, but the code read the second value. That value is 32 for every IPv4 zone and 128 for every IPv6 zone, so all zones of one family shared a key. The map kept the zone that came last, which made the result depend on the order of the zone list. With 10.0.0.0/8 and 10.1.2.0/24 configured, a PTR record for 10.1.2.3 could land in the /8 zone. Read the prefix length instead. Add tests for IPv4 and IPv6 that cover both list orders.
MaxRink
requested review from
Buzzglo,
TebogoTS,
ampie,
k0da and
kuritka
as code owners
August 15, 2026 11:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
findReverseZonecollects every reverse zone that contains the target address and returns the most specific one. It keys the candidates by mask size:net.IPMask.Size()returns(ones, bits). The code readsbits, which is 32 for every IPv4 zone and 128 for every IPv6 zone. Every zone of one address family therefore shares a single key, and the map keeps whichever zone appears last in the list.The selection is not "most specific". It is "last in the list".
Effect
With
10.0.0.0/8and10.1.2.0/24both configured, a PTR record for10.1.2.3can be written to the/8zone, depending on the order in which the WAPI returns the zones.Change
Read the prefix length instead of the bit count.
Tests
Two tests, IPv4 and IPv6, each asserting both list orders so the result cannot depend on ordering, plus a case where the address falls outside the narrow zone and must fall back to the broad one.
Both tests fail on
mainand pass with this change.Verification
go build ./...,go vet ./...,go test ./...and golangci-lint v2.10.1 all pass locally. GoLic reports no missing headers.