From 9a11d0356766b786b9a69a66b19ef27853dbeb5d Mon Sep 17 00:00:00 2001 From: Ilker Manap Date: Wed, 28 Oct 2026 09:38:19 +0100 Subject: [PATCH] ipam: a subnet domain names records only inside the authority's zone Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- cmd/rollcall/ipam.go | 13 ++++++++----- cmd/rollcall/ipam_test.go | 6 ++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 14914b8..0444afa 100644 --- a/README.md +++ b/README.md @@ -511,7 +511,7 @@ address Rollcall hands out is registered there first: Rollcall-owned records that are no longer in use deleted. - **DNS follows the record.** `dns_name` is `.` for a machine's provisioning/mgmt address and `-.` elsewhere (a subnet's - `domain` overrides the zone). A NetBox-to-DNS sync (PowerDNS here, a host + `domain` replaces the zone when it lies inside it; `pxe.local` stays local). A NetBox-to-DNS sync (PowerDNS here, a host record on Infoblox) publishes it; Rollcall writes one object per address. - **Prefixes are delegated in NetBox.** Tag a prefix `rollcall`; `rollcall ipam prefixes` lists them and `rollcall ipam import` creates the diff --git a/cmd/rollcall/ipam.go b/cmd/rollcall/ipam.go index 16814d4..8b613dd 100644 --- a/cmd/rollcall/ipam.go +++ b/cmd/rollcall/ipam.go @@ -150,17 +150,20 @@ func (a *App) extFor(x IPAddr, sn *Subnet) extAddr { } // extDNSName: the machine's main address gets .; addresses on -// other subnets (storage, IB, a tagged VLAN) get -.. +// other subnets (storage, IB, a tagged VLAN) get -.. A +// subnet's domain replaces the zone when it lies inside it. func (a *App) extDNSName(x IPAddr, sn *Subnet) string { - zone := a.cfg.IPAM.DNSZone - if sn != nil && sn.Domain != "" { - zone = sn.Domain + zone := strings.TrimSuffix(strings.ToLower(a.cfg.IPAM.DNSZone), ".") + if sn != nil && sn.Domain != "" { // a subnet domain counts only inside the authority's zone; "pxe.local" stays local + d := strings.TrimSuffix(strings.ToLower(sn.Domain), ".") + if zone == "" || d == zone || strings.HasSuffix(d, "."+zone) { + zone = d + } } host := strings.ToLower(strings.TrimSuffix(x.Hostname, ".")) if zone == "" || host == "" { return "" } - zone = strings.TrimSuffix(strings.ToLower(zone), ".") if strings.HasSuffix(host, "."+zone) { return host } diff --git a/cmd/rollcall/ipam_test.go b/cmd/rollcall/ipam_test.go index 1c55a2f..9110f83 100644 --- a/cmd/rollcall/ipam_test.go +++ b/cmd/rollcall/ipam_test.go @@ -140,7 +140,8 @@ func testIPAM(t *testing.T) (*App, *fakeNetBox) { a.subnets = []Subnet{ {CIDR: "10.213.77.0/24", Purpose: "provisioning"}, {CIDR: "10.213.79.0/24", Purpose: "storage"}, - {CIDR: "10.213.78.0/24", Purpose: "provisioning", Domain: "hall-b.example"}, + {CIDR: "10.213.78.0/24", Purpose: "provisioning", Domain: "hall-b.int.example"}, + {CIDR: "10.213.76.0/24", Purpose: "provisioning", Domain: "pxe.local"}, } return a, f } @@ -154,7 +155,8 @@ func TestIPAMDNSNames(t *testing.T) { }{ {IPAddr{IP: "10.213.77.50", Subnet: "10.213.77.0/24", Hostname: "node001", Iface: "bond0"}, "node001.int.example"}, {IPAddr{IP: "10.213.79.50", Subnet: "10.213.79.0/24", Hostname: "node001", Iface: "bond0.200"}, "node001-bond0-200.int.example"}, - {IPAddr{IP: "10.213.78.50", Subnet: "10.213.78.0/24", Hostname: "Node002"}, "node002.hall-b.example"}, + {IPAddr{IP: "10.213.78.50", Subnet: "10.213.78.0/24", Hostname: "Node002"}, "node002.hall-b.int.example"}, + {IPAddr{IP: "10.213.76.50", Subnet: "10.213.76.0/24", Hostname: "node003", Iface: "eth0"}, "node003.int.example"}, {IPAddr{IP: "10.213.77.5", Subnet: "10.213.77.0/24", Hostname: "core switch", Kind: "reserved"}, ""}, {IPAddr{IP: "10.213.77.6", Subnet: "10.213.77.0/24", Kind: "reserved"}, ""}, }