all: disable client discover on desktop platforms

Since requests are mostly originated from the machine itself, so all
necessary metadata is local to it.

Currently, the desktop platforms are Windows desktop and darwin.
This commit is contained in:
Cuong Manh Le
2025-03-12 00:09:19 +07:00
committed by Cuong Manh Le
parent 58c0e4f15a
commit 7a136b8874
5 changed files with 56 additions and 6 deletions

4
client_info_darwin.go Normal file
View File

@@ -0,0 +1,4 @@
package ctrld
// SelfDiscover reports whether ctrld should only do self discover.
func SelfDiscover() bool { return true }

6
client_info_others.go Normal file
View File

@@ -0,0 +1,6 @@
//go:build !windows && !darwin
package ctrld
// SelfDiscover reports whether ctrld should only do self discover.
func SelfDiscover() bool { return false }

18
client_info_windows.go Normal file
View File

@@ -0,0 +1,18 @@
package ctrld
import (
"golang.org/x/sys/windows"
)
// isWindowsWorkStation reports whether ctrld was run on a Windows workstation machine.
func isWindowsWorkStation() bool {
// From https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-osversioninfoexa
const VER_NT_WORKSTATION = 0x0000001
osvi := windows.RtlGetVersion()
return osvi.ProductType == VER_NT_WORKSTATION
}
// SelfDiscover reports whether ctrld should only do self discover.
func SelfDiscover() bool {
return isWindowsWorkStation()
}

View File

@@ -178,6 +178,8 @@ Perform LAN client discovery using mDNS. This will spawn a listener on port 5353
- Required: no - Required: no
- Default: true - Default: true
This config is ignored, and always set to `false` on Windows Desktop and Macos.
### discover_arp ### discover_arp
Perform LAN client discovery using ARP. Perform LAN client discovery using ARP.
@@ -185,6 +187,8 @@ Perform LAN client discovery using ARP.
- Required: no - Required: no
- Default: true - Default: true
This config is ignored, and always set to `false` on Windows Desktop and Macos.
### discover_dhcp ### discover_dhcp
Perform LAN client discovery using DHCP leases files. Common file locations are auto-discovered. Perform LAN client discovery using DHCP leases files. Common file locations are auto-discovered.
@@ -192,6 +196,8 @@ Perform LAN client discovery using DHCP leases files. Common file locations are
- Required: no - Required: no
- Default: true - Default: true
This config is ignored, and always set to `false` on Windows Desktop and Macos.
### discover_ptr ### discover_ptr
Perform LAN client discovery using PTR queries. Perform LAN client discovery using PTR queries.
@@ -199,6 +205,8 @@ Perform LAN client discovery using PTR queries.
- Required: no - Required: no
- Default: true - Default: true
This config is ignored, and always set to `false` on Windows Desktop and Macos.
### discover_hosts ### discover_hosts
Perform LAN client discovery using hosts file. Perform LAN client discovery using hosts file.
@@ -206,6 +214,8 @@ Perform LAN client discovery using hosts file.
- Required: no - Required: no
- Default: true - Default: true
This config is ignored, and always set to `false` on Windows Desktop and Macos.
### discover_refresh_interval ### discover_refresh_interval
Time in seconds between each discovery refresh loop to update new client information data. Time in seconds between each discovery refresh loop to update new client information data.
The default value is 120 seconds, lower this value to make the discovery process run more aggressively. The default value is 120 seconds, lower this value to make the discovery process run more aggressively.

View File

@@ -177,15 +177,27 @@ func (t *Table) SetSelfIP(ip string) {
t.dhcp.addSelf() t.dhcp.addSelf()
} }
// initSelfDiscover initializes necessary client metadata for self query.
func (t *Table) initSelfDiscover() {
t.dhcp = &dhcp{selfIP: t.selfIP}
t.dhcp.addSelf()
t.ipResolvers = append(t.ipResolvers, t.dhcp)
t.macResolvers = append(t.macResolvers, t.dhcp)
t.hostnameResolvers = append(t.hostnameResolvers, t.dhcp)
}
func (t *Table) init() { func (t *Table) init() {
// Custom client ID presents, use it as the only source. // Custom client ID presents, use it as the only source.
if _, clientID := controld.ParseRawUID(t.cdUID); clientID != "" { if _, clientID := controld.ParseRawUID(t.cdUID); clientID != "" {
ctrld.ProxyLogger.Load().Debug().Msg("start self discovery") ctrld.ProxyLogger.Load().Debug().Msg("start self discovery with custom client id")
t.dhcp = &dhcp{selfIP: t.selfIP} t.initSelfDiscover()
t.dhcp.addSelf() return
t.ipResolvers = append(t.ipResolvers, t.dhcp) }
t.macResolvers = append(t.macResolvers, t.dhcp)
t.hostnameResolvers = append(t.hostnameResolvers, t.dhcp) // If we are running on platforms that should only do self discover, use it as the only source, too.
if ctrld.SelfDiscover() {
ctrld.ProxyLogger.Load().Debug().Msg("start self discovery on desktop platforms")
t.initSelfDiscover()
return return
} }