Skip to content

Commit b130ab6

Browse files
committed
fix(dns,auth): handle TypeANY DNS queries and support dynamic peer IPv6 updates
- Return both A and AAAA records for TypeANY DNS queries in awldns - Allow updating peer.IPAddrV6 when a peer announces a changed IPv6 address in auth_status - Trigger ensureIPv6AddressLocked in SetIdentity to prevent unassigned IPv6 prefix on fresh node configs - Revert unintended comment formatting in test_suite_test.go
1 parent e999002 commit b130ab6

3 files changed

Lines changed: 35 additions & 29 deletions

File tree

awldns/awldns.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func (r *Resolver) dnsLocalDomainHandler(resp dns.ResponseWriter, req *dns.Msg)
222222
mappedIPv6, foundV6 := cfg.directMappingV6[hostnameLower]
223223

224224
switch qtype {
225-
case dns.TypeA, dns.TypeANY:
225+
case dns.TypeA:
226226
if !found {
227227
if foundV6 {
228228
continue // domain exists but no A record, return NOERROR with 0 answers (NODATA)
@@ -261,6 +261,37 @@ func (r *Resolver) dnsLocalDomainHandler(resp dns.ResponseWriter, req *dns.Msg)
261261
AAAA: ip,
262262
})
263263
}
264+
case dns.TypeANY:
265+
if !found && !foundV6 {
266+
m.SetRcode(req, dns.RcodeNameError)
267+
continue
268+
}
269+
if found {
270+
if ip := net.ParseIP(mappedIP).To4(); ip != nil {
271+
m.Answer = append(m.Answer, &dns.A{
272+
Hdr: dns.RR_Header{
273+
Name: hostname,
274+
Rrtype: dns.TypeA,
275+
Class: dns.ClassINET,
276+
Ttl: defaultTTLSeconds,
277+
},
278+
A: ip,
279+
})
280+
}
281+
}
282+
if foundV6 {
283+
if ip := net.ParseIP(mappedIPv6).To16(); ip != nil {
284+
m.Answer = append(m.Answer, &dns.AAAA{
285+
Hdr: dns.RR_Header{
286+
Name: hostname,
287+
Rrtype: dns.TypeAAAA,
288+
Class: dns.ClassINET,
289+
Ttl: defaultTTLSeconds,
290+
},
291+
AAAA: ip,
292+
})
293+
}
294+
}
264295
}
265296
}
266297

test_suite_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ type TestSuite struct {
5353

5454
func NewTestSuite(t testing.TB) *TestSuite {
5555
// Snapshot goroutine state before anything starts. Because t.Cleanup is LIFO,
56-
// registering here means this check runs last ?after all peers and bootstrap
57-
// nodes have been closed ?so it reliably detects goroutine leaks.
56+
// registering here means this check runs last after all peers and bootstrap
57+
// nodes have been closed so it reliably detects goroutine leaks.
5858
//
5959
// libp2p.NATPortMap() spawns a short-lived UPnP SSDP discovery goroutine
6060
// (koron/go-ssdp.Search) with a 5-second timeout. It exits on its own and
@@ -312,7 +312,7 @@ func (ts *TestSuite) makeFriends(peer1, peer2 TestPeer) {
312312

313313
// makeFriendsWithAliases is the same as makeFriends but lets the caller pick
314314
// the per-side aliases. Tests that wire up more than two peers per Application
315-
// need distinct aliases ?awl rejects duplicate names.
315+
// need distinct aliases awl rejects duplicate names.
316316
func (ts *TestSuite) makeFriendsWithAliases(peer1, peer2 TestPeer, alias1, alias2 string) {
317317
ts.ensurePeersAvailableInDHT(peer1, peer2)
318318
ts.sendAndAcceptFriendRequest(peer1, peer2, alias1, alias2)

vpn/vpn.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,6 @@ func (d *Device) PutTempPacket(data *Packet) {
7979
d.packetsPool.Put(data)
8080
}
8181

82-
func (d *Device) WritePacket(data *Packet, senderIP net.IP) error {
83-
if data.IsIPv6 {
84-
if d.localIP6 == nil {
85-
// IPv6 not configured on this device — drop silently.
86-
return nil
87-
}
88-
copy(data.Src, senderIP)
89-
copy(data.Dst, d.localIP6)
90-
} else {
91-
copy(data.Src, senderIP)
92-
copy(data.Dst, d.localIP)
93-
}
94-
data.RecalculateChecksum()
95-
96-
bufs := [][]byte{data.Buf()}
97-
packetsCount, err := d.tun.Write(bufs, tunPacketOffset)
98-
if err != nil {
99-
return fmt.Errorf("write packet to tun: %v", err)
100-
} else if packetsCount < len(bufs) {
101-
d.logger.Warnf("wrote %d packets, len(bufs): %d", packetsCount, len(bufs))
102-
}
103-
104-
return nil
105-
}
106-
10782
// LocalIP returns the awl IPv4 address assigned to this device. Set once in NewDevice.
10883
func (d *Device) LocalIP() net.IP {
10984
return d.localIP

0 commit comments

Comments
 (0)