From 564c9ef71293cc74abc80b75a97f0828321b6b00 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 16 Nov 2023 19:48:40 +0700 Subject: [PATCH] cmd/cli: use IP as hostname for ipv4 clients only For Android devices, when it joins the network, it uses ctrld to resolve its private DNS once and never reaches ctrld again. For each time, it uses a different IPv6 address, which causes hundreds/thousands different client IDs created for the same device, which is pointless. --- cmd/cli/dns_proxy.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/cli/dns_proxy.go b/cmd/cli/dns_proxy.go index 69d94f3..77ec44e 100644 --- a/cmd/cli/dns_proxy.go +++ b/cmd/cli/dns_proxy.go @@ -586,8 +586,17 @@ func (p *prog) getClientInfo(remoteIP string, msg *dns.Msg) *ctrld.ClientInfo { if hostname := p.ciTable.LookupHostname(ci.IP, ""); hostname != "" { ci.Hostname = hostname } else { - ci.Hostname = ci.IP - p.ciTable.StoreVPNClient(ci) + // Only use IP as hostname for IPv4 clients. + // For Android devices, when it joins the network, it uses ctrld to resolve + // its private DNS once and never reaches ctrld again. For each time, it uses + // a different IPv6 address, which causes hundreds/thousands different client + // IDs created for the same device, which is pointless. + // + // TODO(cuonglm): investigate whether this can be a false positive for other clients? + if !ctrldnet.IsIPv6(ci.IP) { + ci.Hostname = ci.IP + p.ciTable.StoreVPNClient(ci) + } } } else { ci.Hostname = p.ciTable.LookupHostname(ci.IP, ci.Mac)