776 Commits

Author SHA1 Message Date
Cuong Manh Le
595071b608 all: update client info table on network changes
So the client metadata will be updated correctly when the device roaming
between networks.
2025-02-05 13:15:01 +07:00
Cuong Manh Le
57ef717080 cmd/cli: improve error message returned by FlushDNSCache
By recording both the error and output of external commands.

While at it:

 - Removing un-necessary usages of sudo, since ctrld already
   running with root privilege.
 - Removing un-used function triggerCaptiveCheck.
2025-02-05 13:14:52 +07:00
Cuong Manh Le
eb27d1482b cmd/cli: use warn level for network changes logging
So these events will be recorded separately from normal runtime log,
making troubleshooting later more easily.

While at it, only update ctrld.ProxyLogger for runCmd, it's the only one
which needs to log the query when proxying requests.
2025-02-05 13:14:39 +07:00
Cuong Manh Le
f57972ead7 cmd/cli: make runtime log format better
By using more friendly markers to indicate the end of each log section,
so it's easier to read/parse for both human and machine.
2025-02-05 13:14:31 +07:00
Alex
168eaf538b increase OSresolver timeout, fix debug log statements
flush dns cache, manually hit captive portal on MacOS

fix real ip in debug log

treat all upstreams as down upon network change

delay upstream checks when leaking queries on network changes
2025-02-04 18:03:41 +07:00
Cuong Manh Le
1560455ca3 Use all available nameservers in lookupIP
Some systems may be configured with public DNS only, so relying solely
on LAN servers could make the lookup process failed unexpectedly.
2025-02-02 11:48:25 +07:00
Alex
028475a193 fix os.Resolve method to prefer LAN answers
fix os.Resolve method to prefer LAN answers

early return for stop cmd when not installed or stopped

increase service restart delay to 5s
2025-02-02 11:21:39 +07:00
Alex
f7a6dbe39b fix upgrade flow
set service on new run, fix duplicate args

set service on new run, fix duplicate args

revert startCmd in upgrade flow due to pin compat issues

make restart reset DNS like upgrade, add debugging to uninstall method

debugging

debugging

debugging

debugging

debugging WMI

remove stackexchange lib, use ms wmi pkg

debugging

debugging

set correct class

fix os reolver init issues

fix netadapter class

use os resolver instead of fetching default nameservers while already running

remove debug lines

fix lookup IP

fix lookup IP

fix lookup IP

fix lookup IP

fix dns namserver retries when not needed
2025-01-31 20:04:03 +07:00
Alex
e573a490c9 ignore non physical ifaces in validInterfaces method on Windows
debugging

skip type 24 in nameserver detection

skip type 24 in nameserver detection

remove interface type check from valid interfaces for now

skip non hardware interfaces in DNS nameserver lookup

ignore win api log output

set retries to 5 and 1s backoff

reset DNS when upgrading to make sure we get the proper OS nameservers on start

init running iface for upgrade

update windows service options for auto restarts on failure

make upgrade use the actual stop and start commands

fix the windows service retry logic

fix the windows service retry logic

task debugging

more task debugging

windows service name fix

windows service name fix

fix start command args

fix restart delay

dont recover from non crash failures

fix upgrade flow
2025-01-30 17:06:43 +07:00
Alex
ce3281e70d much more debugging, improved nameserver detection, no more testing nameservers
fix logging

fix logging

try to enable nameserver logs

try to enable nameserver logs

handle flags in interface state changes

debugging

debugging

debugging

fix state detection, AD status fix

fix debugging line

more dc info

always log state changes

remove unused method

windows AD IP discovery

windows AD IP discovery

windows AD IP discovery
2025-01-29 12:28:49 +07:00
Cuong Manh Le
0fbfd160c9 cmd/cli: log interfaces state after dns set
The data will be useful for troubleshooting later.
2025-01-24 14:54:28 +07:00
Cuong Manh Le
20759017e6 all: use local resolver for ADDC
For normal OS resolver, ctrld does not use local addresses as nameserver
to avoid possible looping. However, on AD environment with local DNS
running, AD queries must be sent to the local DNS server for proper
resolving.
2025-01-24 14:54:20 +07:00
Cuong Manh Le
69e0aab73e cmd/cli: use wmi to get AD domain
Since using syscall.NetGetJoinInformation won't return the full domain
name.

Discovered while investigating issue with SRV ldap check.
2025-01-24 14:54:10 +07:00
Cuong Manh Le
7ed6733fb7 cmd/cli: better error if internal log is not available 2025-01-24 14:54:01 +07:00
Cuong Manh Le
9718ab8579 cmd/cli: fix getting interface name when disabled on Windows
By getting the name property directly from adapter instance, instead of
using net.InterfaceByIndex function, which could return an error when
the adapter is disabled.
2025-01-20 15:03:40 +07:00
Alex
2687a4a018 remove leaking timeout, fix blocking upstreams checks, leaking is per listener, OS resolvers are tested in parallel, reset is only done is os is down
fix test

use upstreamIS var

init map, fix watcher flag

attempt to detect network changes

attempt to detect network changes

cancel and rerun reinitializeOSResolver

cancel and rerun reinitializeOSResolver

cancel and rerun reinitializeOSResolver

ignore invalid inferaces

ignore invalid inferaces

allow OS resolver upstream to fail

dont wait for dnsWait group on reinit, check for active interfaces to trigger reinit

fix unused var

simpler active iface check, debug logs

dont spam network service name patching on Mac

dont wait for os resolver nameserver testing

remove test for osresovlers for now

async nameserver testing

remove unused test
2025-01-20 15:03:27 +07:00
Cuong Manh Le
2d9c60dea1 cmd/cli: log that multiple interfaces DNS set 2025-01-20 15:00:23 +07:00
Cuong Manh Le
841be069b7 cmd/cli: only list physical interfaces when listing
Since these are the interfaces that ctrld will manipulate anyway.

While at it, also skipping non-working devices on MacOS, by checking
if the device is present in network service order
2025-01-20 15:00:08 +07:00
Alex Paguis
7833132917 Don't automatically restore saved DNS settings when switching networks
smol tweaks to nameserver test queries

fix restoreDNS errors

add some debugging information

fix wront type in log msg

set send logs command timeout to 5 mins

when the runningIface is no longer up, attempt to find a new interface

prefer default route, ignore non physical interfaces

prefer default route, ignore non physical interfaces

add max context timeout on performLeakingQuery with more debug logs
2025-01-20 14:59:31 +07:00
Cuong Manh Le
e9e63b0983 cmd/cli: check root privilege for log commands 2025-01-20 14:57:45 +07:00
Cuong Manh Le
4df470b869 cmd/cli: ensure all ifaces operation is set correctly
Since ctrld process does not rely on the global variable iface anymore
during runtime, ctrld client's operations must be updated to reflect
this change, too.
2025-01-20 14:57:34 +07:00
Cuong Manh Le
89600f6091 cmd/cli: new flow for leaking queries to OS resolver
The current flow involves marking OS resolver as down, which is not
right at all, since ctrld depends on it for leaking queries.

This commits implements new flow, which ctrld will restore DNS settings
once leaking marked, allowing queries go to OS resolver until the
internet connection is established.
2025-01-20 14:57:23 +07:00
Cuong Manh Le
f986a575e8 cmd/cli: log upstream name if endpoint is empty 2025-01-20 14:57:09 +07:00
Cuong Manh Le
9c2fe8d21f cmd/cli: set running iface for stop/uninstall commands 2025-01-20 14:56:53 +07:00
Cuong Manh Le
8bcbb9249e cmd/cli: add an internal warn level log writer
So important events like upstream online/offline/failed will be
preserved, and submitted to the server as necessary.
2025-01-14 14:33:27 +07:00
Cuong Manh Le
a95d50c0af cmd/cli: ensure set/reset DNS is done before checking OS resolver
Otherwise, new DNS settings could be reverted by dns watchers, causing
the checking will be always false.
2025-01-14 14:33:15 +07:00
Cuong Manh Le
5db7d3577b cmd/cli: handle . domain query
By returning FormErr response, the same behavior with ControlD.
2025-01-14 14:33:05 +07:00
Cuong Manh Le
c53a0ca1c4 cmd/cli: close log reader after reading 2025-01-14 14:32:54 +07:00
Cuong Manh Le
6fd3d1788a cmd/cli: fix memory leaked when querying wmi instance
By ensuring the instance is closed when query finished.
2025-01-14 14:32:44 +07:00
Cuong Manh Le
087c1975e5 internal/controld: bump send log timeout to 300s 2025-01-14 14:32:35 +07:00
Cuong Manh Le
3713cbecc3 cmd/cli: correct log writer initial size 2025-01-14 14:32:26 +07:00
Cuong Manh Le
6046789fa4 cmd/cli: re-initializing OS resolver before doing check upstream
Otherwise, the check will be done for old stale nameservers, causing it
never succeed.
2025-01-14 14:32:15 +07:00
Cuong Manh Le
3ea69b180c cmd/cli: use config timeout when checking upstream
Otherwise, for slow network connection (like plane wifi), the check may
fail even though the internet is available.
2025-01-14 14:32:01 +07:00
Cuong Manh Le
db6e977e3a Only used saved LAN servers if available 2025-01-14 14:31:48 +07:00
Cuong Manh Le
a5c776c846 all: change send log to use x-www-form-urlencoded 2025-01-14 14:31:37 +07:00
Cuong Manh Le
5a566c028a cmd/cli: better error message when log file is empty
While at it, also record the size of logs being sent in debug/error
message.
2025-01-14 14:31:24 +07:00
Cuong Manh Le
ff43c74d8d Bump golang.org/x/net to v0.33.0
Fix CVE-2024-45338
2025-01-14 14:31:13 +07:00
Yegor S
3c7255569c Update config.md 2025-01-06 18:40:44 -05:00
Cuong Manh Le
4a92ec4d2d cmd/cli: fix race in Test_addSplitDnsRule 2024-12-19 22:10:34 +07:00
Cuong Manh Le
9bbccb4082 cmd/cli: get default interface once 2024-12-19 21:50:00 +07:00
Cuong Manh Le
4f62314646 cmd/cli: do API reloading if exlcude list changed 2024-12-19 21:50:00 +07:00
Cuong Manh Le
cb49d0d947 cmd/cli: perform leaking queries in non-cd mode 2024-12-19 21:50:00 +07:00
Cuong Manh Le
89f7874fc6 cmd/cli: normalize log path when sending log
So the correct log file that "ctrld run" process is writing logs to will
be sent to server correctly.
2024-12-19 21:50:00 +07:00
Cuong Manh Le
221917e80b Bump golang.org/x/crypto to v0.31.0
To fix CVE-2024-45337 (even though ctrld do not use SSH)
2024-12-19 21:50:00 +07:00
Cuong Manh Le
37d41bd215 Skip public DNS for LAN query
So we don't blindly send requests to public DNS even though they can not
handle these queries.
2024-12-19 21:50:00 +07:00
Cuong Manh Le
8a96b8bec4 cmd/cli: adopt FilteredLevelWriter when doing internal logging
Without verbose log, we use internal log writer with log level set to
debug. However, this will affect other writers, like console log, since
they are default to notice level.

By adopting FilteredLevelWriter, we can make internal log writer run in
debug level, but all others will run in default level instead.
2024-12-19 21:50:00 +07:00
Cuong Manh Le
02ee113b95 Add missing kea dhcp4 format when validating config
Thanks Discord user cosmoxl for reporting this.
2024-12-19 21:50:00 +07:00
Cuong Manh Le
f71dd78915 cmd/cli: move cobra commands to separated file
So each command initialization/logic can be read/update more easily.
2024-12-19 21:50:00 +07:00
Cuong Manh Le
cd5619a05b cmd/cli: add internal logging
So in case of no logging enabled, useful data could be sent to ControlD
server for further troubleshooting.
2024-12-19 21:50:00 +07:00
Cuong Manh Le
a63a30c76b all: add sending logs to ControlD API 2024-12-19 21:50:00 +07:00