776 Commits

Author SHA1 Message Date
Cuong Manh Le
24910f1fa6 Merge pull request #230 from Control-D-Inc/release-branch-v1.4.2
Release branch v1.4.2
v1.4.2
2025-04-10 23:27:30 +07:00
Yegor Sak
433a61d2ee Update file README.md 2025-04-08 10:10:32 +07:00
Cuong Manh Le
3937e885f0 Bump golang.org/x/net to v0.38.0
Fixes CVE-2025-22872
2025-04-01 23:20:12 +07:00
Cuong Manh Le
c651003cc4 Support direct ip in lookupIP function
So users can supply ip directly in config, avoiding unnecessary domain
lookup while bootstrapping.
2025-03-31 23:02:59 +07:00
Cuong Manh Le
b7ccfcb8b4 Do not include commit hash when releasing tag 2025-03-27 20:11:57 +07:00
Cuong Manh Le
a9ed70200b internal/router: change dnsmasq config manipulation on Merlin
Generally, using /jffs/scripts/dnsmasq.postconf is the right way to add
custom configuration to dnsmasq on Merlin. However, we have seen many
reports that the postconf does not work on their devices.

This commit changes how dnsmasq config manipulation is done on Merlin,
so it's expected to work on all Merlin devices:

 - Writing /jffs/scripts/dnsmasq.postconf script
 - Copy current dnsmasq.conf to /jffs/configs/dnsmasq.conf
 - Run postconf script directly on /jffs/configs/dnsmasq.conf
 - Restart dnsmasq

This way, the /jffs/configs/dnsmasq.conf will contain both current
dnsmasq config, and also custom config added by ctrld, without worrying
about conflicting, because configuration was added by postconf.

See (1) for more details about custom config files on Merlin.

(1) https://github.com/RMerl/asuswrt-merlin.ng/wiki/Custom-config-files
2025-03-26 23:18:53 +07:00
Cuong Manh Le
c6365e6b74 cmd/cli: handle stop signal from service manager
So using "ctrld stop" or service manager to stop ctrld will end up with
the same result, stopped ctrld with a working DNS, and deactivation pin
code will always have effects if set.
2025-03-26 23:18:36 +07:00
Cuong Manh Le
dacc67e50f Using LAN servers from OS resolver for private resolver
So heavy functions are only called once and could be re-used in
subsequent calls to NewPrivateResolver.
2025-03-26 23:18:21 +07:00
Cuong Manh Le
c60cf33af3 all: implement self-upgrade flag from API
So upgrading don't have to be initiated manually, helping large
deployments to upgrade to latest ctrld version easily.
2025-03-26 23:18:04 +07:00
Cuong Manh Le
f27cbe3525 all: fallback to use direct IPs for ControlD assets 2025-03-26 23:17:50 +07:00
Cuong Manh Le
2de1b9929a Do not send legacy DNS queries to bootstrap DNS 2025-03-26 23:17:26 +07:00
Cuong Manh Le
8bf654aece Bump golang.org/x/net to v0.36.0
Fixing https://pkg.go.dev/vuln/GO-2025-3503
2025-03-26 23:17:18 +07:00
Cuong Manh Le
84376ed719 cmd/cli: add missing pre-run setup for start command
Otherwise, ctrld won't be able to reset DNS correctly if problems
happened during self-check process.
2025-03-26 23:17:06 +07:00
Cuong Manh Le
7a136b8874 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.
2025-03-26 23:16:57 +07:00
Cuong Manh Le
58c0e4f15a all: remove ipv6 check polling
netmon provides ipv6 availability during network event changes, so use
this metadata instead of wasting on polling check.

Further, repeated network errors will force marking ipv6 as disable if
were being enabled, catching a rare case when ipv6 were disabled from
cli or system settings.
2025-03-26 23:16:38 +07:00
Cuong Manh Le
e0d35d8ba2 Merge pull request #218 from Control-D-Inc/release-branch-v1.4.1
Release branch v1.4.1
v1.4.1
2025-03-07 08:25:38 +07:00
Cuong Manh Le
3b2e48761e Upgrade dominikh/staticcheck-action to v1.3.1
To upgrade actions/cache dependency, since v1-v2 was deprecated.
2025-03-06 18:42:06 +07:00
Cuong Manh Le
b27064008e cmd/cli: do not validate if custom config is empty
Avoiding useless warnings when doing rules validation.
2025-03-06 18:17:48 +07:00
Cuong Manh Le
1ad63827e1 cmd/cli: do not validate invalid syntax config
If the remote custom config is an invalid syntax config, we should not
do rules validation, prevent unnecessary error messages printed.
2025-03-01 00:24:59 +07:00
Cuong Manh Le
20e61550c2 cmd/cli: set default value for remote config before validating
Since empty network will now have a default value, we need to set it
after sytax validation, prevent false positive when validating rules.
2025-03-01 00:24:55 +07:00
Cuong Manh Le
020b814402 cmd/cli: fix validating remote custom config
Currently, custom config is only validated against invalid syntax, not
the validating rules for each configuration value. It causes ctrld
process fatal instead of disregarding as expected.

To fix this, force the validating rule after fetching remote config.
While at it, also add the default network value if non-existed.
2025-02-28 20:08:26 +07:00
Cuong Manh Le
e578867118 internal/router: fix fresh tomato config path
When ctrld performs upgrading tasks, the current binary would be moved
to different file, thus the executable will return this new file name,
instead of the old "/path/to/ctrld".

The config path on FreshTomato is located in the same directory with
ctrld binary, with ".startup" suffix. So when the binary was moved
during upgrading, the config path is located wrongly.

To fix it, read the binary path from service config first, then only
fallback to the current executable if the path is empty (this is the
same way ctrld is doing for other router platforms).
2025-02-27 23:47:46 +07:00
Alex Paguis
46a1039f21 guard against nil interface 2025-02-27 18:53:10 +07:00
Cuong Manh Le
cc9e27de5f Add some more mDNS services
Import from https://github.com/Control-D-Inc/ctrld/pull/145

Thanks @jaydeethree for contributing.
2025-02-27 18:52:50 +07:00
Cuong Manh Le
6ab3ab9faf cmd/cli: add DNS as ctrld service dependency
So on Windows system where there's local DNS running, ctrld could set
DNS forwarders correctly after DNS service started.
2025-02-26 00:44:13 +07:00
Alex Paguis
e68bfa795a add a small delay service start self check 2025-02-25 20:07:57 +07:00
Cuong Manh Le
e60a92e93e cmd/cli: improving IPC when try listening failed
So the "ctrld start" should know earlier that "ctrld run" failed to
listen on certain port, and terminate earlier instead of waiting for
timeout happened.
2025-02-25 03:33:00 +07:00
Alex
62fe14f76b prevent running on custom ports for clients 2025-02-24 18:36:18 +07:00
Alex Paguis
a0c5062e3a Resolve "OS upstream failure / wrong default route" 2025-02-24 18:36:08 +07:00
Alex
49eb152d02 transport should try ipv4 then ipv6 explicitly
client list panic guards and debug logging
2025-02-21 20:44:34 +07:00
Cuong Manh Le
b05056423a docs: add documentation for LAN queries 2025-02-21 20:44:34 +07:00
Cuong Manh Le
c7168739c7 cmd/cli: use OS resolver as default upstream for SRV lan hostname
Since application may need SRV record for public domains, which could be
blocked by OS resolver, but not with remote upstreams.

This was reported by a Minecraft user, who seeing thing is broken after
upgrading to v1.4.0 release.
2025-02-21 20:44:34 +07:00
Alex
5b1faf1ce3 dont allow positional args in start commands 2025-02-21 20:44:34 +07:00
Cuong Manh Le
513a6f9ec7 cmd/cli: guarding against nil log ipc connection
The log ip connection may be nil, since it was not created if blocked by
firewall/VPN apps.

While at it, also add warning when the ipc connection could not be created.
2025-02-21 20:44:34 +07:00
Cuong Manh Le
8db6fa4232 cmd/cli: remove un-used functions 2025-02-21 20:44:34 +07:00
Cuong Manh Le
5036de2602 cmd/cli: add support for no default route systems
Currently, ctrld requires the default route interface existed to be
functional correctly.

However, on systems where default route is non existed, or point to a
virtual interface (like ipsec based VPN), the fact that the OS is using
this interface as default gateway and doesn't actually send things to
127.0.0.1 is not ctrld's problem.

In this case, ctrld should just start normally, without worrying about
the no default route interface problem.
2025-02-21 20:44:34 +07:00
Alex
332f8ccc37 debugging save/restore staticinterface settings
postRun should not restore static settings

put back validInterface check

better debug logs for os resolver init, use mutex to prevent duplicate initializations

use WMI instead of registry keys for static DNS data on Windows

use WMI instead of registry keys for static DNS data on Windows

use winipcfg DNS method

use WMI with registry fallback

go back to registry method

restore saved static configs on stop and uninstall

restore ipv6 DHCP if no saved static ipv6 addresses

do not save loopback IPs for static configs

handle watchdog interface changed for new interfaces

dont overwrite static file on start when staticdns is set to loopback

dont overwrite static file on start when staticdns is set to loopback

dont overwrite static file on start when staticdns is set to loopback

no need to resetDNS on start, uninstall already takes care of this
2025-02-21 20:44:34 +07:00
Cuong Manh Le
a582195cec internal/controld: bump default http client timeout
While at it, also converting them to global constants.
2025-02-21 20:44:34 +07:00
Cuong Manh Le
9fe36ae984 Removing unnecessary ProxyLogger nil check
By ensuring it is initialized before codes that access it.
2025-02-21 20:44:34 +07:00
Cuong Manh Le
54cb455522 Fix staticcheck linter warnings
By moving darwin specific codes to darwin file.
2025-02-21 20:44:34 +07:00
Cuong Manh Le
8bd3b9e474 cmd/cli: fix missing runtime log for startup
The runtime internal log should be initialized right after normal log
from configuration, prevent missing log from any actions that could be
happened between two initializations.
2025-02-21 20:44:27 +07:00
Alex
eff5ff580b use saved static nameservers stored for the default router interface when doing nameserver discovery
fix bad logger usages

patch darwin interface name

patch darwin interface name, debugging

make resetDNS check for static config on startup, optionally restoring static confiration as needed

fix netmon logging
2025-02-21 20:33:04 +07:00
Cuong Manh Le
c45f863ed8 cmd/cli: workaround status command with new Openwrt
New Openwrt returns a non-success code even when status command run
successfully, causing wrong status returned.
2025-02-18 20:31:56 +07:00
Alex Paguis
414d4e356d dont repeat ipv6availablity for each interface, increase self check timeout but reduce max attempts 2025-02-18 20:31:56 +07:00
Yegor Sak
ef697eb781 add better explaination
"code quality"
2025-02-18 20:31:51 +07:00
Cuong Manh Le
0631ffe831 all: allow verbose log when connecting to ControlD API
So troubleshooting will be easier in case of errors happened.
2025-02-18 20:31:08 +07:00
Cuong Manh Le
7444d8517a cmd/cli: fix log init end marker with partial data
For partial init log data (does not end with a newline), the log writer
discard data after the last newline to make the log prettier, then write
the init end marker. This causes the marker could be written more than
once, since the second overflows will preserve the data which does
include the marker from the first write.

To fix this, ensure that the init end marker is only written once, and
the second overflows will preserve data until the marker instead of the
fixed initial size like the first one.
2025-02-18 20:31:08 +07:00
Alex
3480043e40 handle default route changes
remove old os resolver IPs on interface down

better debugging for os resolver
2025-02-18 20:30:54 +07:00
Yegor Sak
619b6e7516 Update file config.md
update bad grammar, describe things better
2025-02-18 20:30:47 +07:00
Alex
0123ca44fb ignore ipv6 addresses from defaultRouteIP, guard against using ipv6 address as v4 default 2025-02-18 20:25:35 +07:00