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.
This commit is contained in:
Cuong Manh Le authored and Cuong Manh Le committed 2023-11-27 22:19:16 +07:00
1 parent 856abb71b7
commit 564c9ef712
1 file changed
+11 -2
+11 -2
View File
@@ -586,8 +586,17 @@ func (p *prog) getClientInfo(remoteIP string, msg *dns.Msg) *ctrld.ClientInfo {
if hostname := p.ciTable.LookupHostname(ci.IP, ""); hostname != "" { if hostname := p.ciTable.LookupHostname(ci.IP, ""); hostname != "" {
ci.Hostname = hostname ci.Hostname = hostname
} else { } else {
ci.Hostname = ci.IP // Only use IP as hostname for IPv4 clients.
p.ciTable.StoreVPNClient(ci) // 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 { } else {
ci.Hostname = p.ciTable.LookupHostname(ci.IP, ci.Mac) ci.Hostname = p.ciTable.LookupHostname(ci.IP, ci.Mac)