528 Commits

Author SHA1 Message Date
Cuong Manh Le
05cfb9b661 cmd/ctrld: fix typo in Network name 2023-01-20 21:43:04 +07:00
Cuong Manh Le
99b0cbedc3 cmd/ctrld: include DNS in interface list 2023-01-20 21:43:04 +07:00
Cuong Manh Le
1f2bd90308 cmd/ctrld: fix wrong stop command alias
It's "stopCmd", not "startCmd"
2023-01-20 21:43:04 +07:00
Cuong Manh Le
b00a7c34ee cmd/ctrld: add --iface for setting DNS on specific interface 2023-01-20 21:43:03 +07:00
Cuong Manh Le
d5344aea52 cmd/ctrld: add list interfaces command 2023-01-20 21:37:55 +07:00
Cuong Manh Le
8e164185b9 cmd/ctrld: always pass config file on windows start mode
On windows, the SYSTEM user is used to run ctrld service. This user has
different environment with the user that run the `ctrld` binary via CLI.
That causes the mismatch issue in config file path, log path, or more
generally, everything that involve with home directory.

To circumvent this pain, just always passing the config path and the
original home dir in start mode. So `ctrld run` command can setup things
correctly.
2023-01-20 21:37:50 +07:00
Cuong Manh Le
53306235dc all: uninstall service if got invalid config from API 2023-01-20 21:37:44 +07:00
Cuong Manh Le
3a5c71514c cmd/ctrld: ensure viper is re-new in --cd mode 2023-01-20 21:37:39 +07:00
Cuong Manh Le
279e938b2a cmd/ctrld: make "--cd" always owerwrites the config
While at it, also make the toml encoded config format nicer.
2023-01-20 21:37:34 +07:00
Cuong Manh Le
9f90811567 cmd/ctrld: update config when "--cd" present 2023-01-20 21:37:24 +07:00
Cuong Manh Le
6edd42629e cmd/ctrld: correct write default config condition when start
!76 was merged without rebasing on latest master, so it missed the
condition of "--cd" when checking for writing default config.
2023-01-20 21:37:10 +07:00
Cuong Manh Le
8e91123dbf cmd/ctrld: write default config to home dir when start
This piece was missing in last resolving conflicts.
2023-01-20 21:37:04 +07:00
Cuong Manh Le
3014556f2d cmd/ctrld,internal/controld: do not set bootstrap IP 2023-01-20 21:36:56 +07:00
Cuong Manh Le
b021833ed6 cmd/ctrld: correct the write default config condition
When "--cd" is supplied, we don't want to write default config. This
happens due to faulty in resolving conflicts in !70.
2023-01-20 21:36:52 +07:00
Cuong Manh Le
7b13fd862d cmd/ctrld: fix mis-handling of start alias
For "ctrld start", os.Args length is just 2, so we we could not shorten
it from 3.
2023-01-20 21:36:45 +07:00
Cuong Manh Le
114ef9aad6 all: add starting service with Control D config 2023-01-20 21:33:38 +07:00
Cuong Manh Le
ec72af1916 cmd/ctrld: add commands to control ctrld as a system service
Supported actions:

 - start: install and start ctrld as a system service
 - stop: stop the ctrld service
 - restart: restart ctrld service
 - status: show status of ctrld service
 - uninstall: remove ctrld from system service
2023-01-20 21:33:31 +07:00
Cuong Manh Le
9e7578fb29 cmd/ctrld: use better approach for checking IPv6 available
Some operating systems may throw a confirmation dialog when attempting
to listen on any interface other than loopback. A better approach is
checking for any interface which is up and can be routed IP traffic.
2023-01-20 21:33:25 +07:00
Cuong Manh Le
e331a4113a Rework os resolver
Currently, os resolver not only handle A and AAAA records, but also does
it wrongly, since when it packs AAAA record to a dns.A record.

This commit reworks os resolver to make it works with all supported
record types.
2023-01-20 21:33:17 +07:00
Cuong Manh Le
e6d77e2586 cmd/ctrld: add default value and CLI flag for cache size 2023-01-20 21:33:11 +07:00
Cuong Manh Le
b93970ccfd all: add CLI flags for no config start
This commit adds the ability to start `ctrld` without config file. All
necessary information can be provided via command line flags, either in
base64 encoded config or launch arguments.
2023-01-20 21:33:05 +07:00
Cuong Manh Le
30fefe7ab9 all: add local caching
This commit adds config params to enable local DNS response caching and
control its behavior, allow tweaking the cache size, ttl override and
serving stale response.
2023-01-20 21:33:01 +07:00
Cuong Manh Le
837d3195ca cmd/ctrld: rework "verbose" flag
This commit changes "verbose" flag from boolean to count flag, so we can
specify the flag multiple times to indicate different logging output:

 - No "-v": no query logging except startup/listeners
 - "-v"   : query logging enabled
 - "-vv"  : debug level logging enabled
2023-01-20 21:32:33 +07:00
Cuong Manh Le
a7ae6c9853 all: support ipv6 for upstream bootstrap ip 2023-01-20 21:32:26 +07:00
Cuong Manh Le
ebcc545547 all: improving DoH query performance
Previously, for each DoH query, we use the net/http default transport
with DialContext function re-assigned. This has some problems:

 - The first query to server will be slow.
 - Using the default transport for all upstreams can have race condition
   in case of multiple queries to multiple DoH upstreams

This commit fixes those issues, by initializing a separate transport for
each DoH upstream, the warming up the transport by doing a test query.
Later queries can take the advantage and re-use the connection.
2023-01-20 21:32:14 +07:00
Cuong Manh Le
0240f7ab15 cmd/ctrld: bump version to v1.0.1 2022-12-15 00:57:16 +07:00
Cuong Manh Le
ccada70e31 all: implement policy failover rcodes
While at it, ensure that config is validated, and fixing a bug related
to reuse ctx between multiple upstreams resolving.
2022-12-14 23:34:24 +07:00
Cuong Manh Le
91d60d2a64 Import code, preparing for release 2022-12-13 01:27:48 +07:00