Cuong Manh Le and Cuong Manh Le
4bfcacaf3c
cmd/ctrld: bump version to v1.1.2
2023-03-16 10:53:33 +07:00
Cuong Manh Le and Cuong Manh Le
5b362412be
Add quic free version to goreleaser
2023-03-16 10:40:17 +07:00
Cuong Manh Le and Cuong Manh Le
ccf07a7d1c
cmd/ctrld: log that ctrld is starting
2023-03-16 09:53:08 +07:00
Cuong Manh Le and Cuong Manh Le
e4eb3b2ded
Do not query ipv6 eagerly when setup bootstrap IP
...
We only need on demand information when re-bootstrapping. On Bootsrap,
this is already checked by ctrldnet.Up, so on demand query will cause
un-necessary slow down if external ipv6 is slow to response.
2023-03-16 09:52:57 +07:00
Cuong Manh Le and Cuong Manh Le
77b62f8734
cmd/ctrld: add default timeout for os resolver
...
So it can fail fast if internet broken suddenly. While at it, also
filtering out ipv6 nameservers if ipv6 not available.
2023-03-16 09:52:39 +07:00
Cuong Manh Le and Cuong Manh Le
096e7ea429
internal/net: enforce timeout for probing stack
...
On Windows host with StarLink network, ctrld hangs on startup for ~30s
before continue running. This dues to IPv6 is configured but no external
IPv6 can be reached. When probing stack, ctrld is dialing using ipv6
without any timeout set, so the dialing timeout is enforced by OS.
This commit adds a timeout for probing dialer, so we ensure the probing
process will fail fast.
2023-03-16 09:52:22 +07:00
Cuong Manh Le and Cuong Manh Le
3e6f6cc721
cmd/ctrld: add TCP listener
...
Fixes #25
2023-03-16 09:51:33 +07:00
Cuong Manh Le and Cuong Manh Le
7cd1f7adda
cmd/ctrld: bump version to v1.1.1
2023-03-10 23:20:31 +07:00
Cuong Manh Le and Cuong Manh Le
9a249c3029
.github/workflows: use go 1.20
2023-03-10 23:20:31 +07:00
Cuong Manh Le and Cuong Manh Le
0dfa377e08
Add freebsd to goreleaser config
...
While at it, fixed the hook upx script to run per file, and ignore
binaries which are not supported.
2023-03-10 23:20:31 +07:00
Cuong Manh Le and Cuong Manh Le
14bc29751f
Use both os and bootstrap DNS to resolve bootstrap IP
2023-03-10 23:20:22 +07:00
Cuong Manh Le and Cuong Manh Le
e6800fbc82
Query all possible nameservers for os resolver
...
So we don't have to worry about network stack changes causes an upstream
to be broken. Just send requests to all nameservers concurrently, and
get the first success response.
2023-03-10 09:25:48 +07:00
Cuong Manh Le and Cuong Manh Le
4f6c2032a1
cmd/ctrld: log reason if first query failed
2023-03-10 09:25:42 +07:00
Cuong Manh Le and Cuong Manh Le
d1589bd9d6
Use separate context when querying upstream ips
...
While at it, also include query type in log, and only honor upstream
timeout when it greater than zero.
2023-03-10 09:25:35 +07:00
Cuong Manh Le and Cuong Manh Le
85c95a6a3a
all: set timeout for re-bootstrapping
2023-03-10 09:25:29 +07:00
Cuong Manh Le and Cuong Manh Le
fa50cd4df4
all: another rework on discovering bootstrap IPs
...
Instead of re-query DNS record for upstream when re-bootstrapping, just
query all records on startup, then selecting the next bootstrap ip
depends on the current network stack.
2023-03-10 09:25:17 +07:00
Cuong Manh Le and Cuong Manh Le
018f6651c1
Fix wrong time precision in bootstrapping timeout
...
The timeout is in millisecond, not second.
2023-03-08 10:19:49 +07:00
Cuong Manh Le and Cuong Manh Le
1a40767cb7
Use upstream timeout when querying bootstrap IP
2023-03-08 10:16:56 +07:00
Cuong Manh Le and Cuong Manh Le
12512a60da
Always use first record from DNS response
2023-03-07 10:45:29 +07:00
Cuong Manh Le and Cuong Manh Le
b0114dfaeb
cmd/ctrld: make staticcheck happy
2023-03-07 10:28:49 +07:00
Cuong Manh Le and Cuong Manh Le
fb20d443c1
all: retry the request more agressively
...
For better recovery and dealing with network stack changes, this commit
change the request flow to:
failure of any kind -> recreate transport/re-bootstrap -> retry once
That would make ctrld recover from all scenarios in theory.
2023-03-07 10:25:48 +07:00
Cuong Manh Le and Cuong Manh Le
262dcb1dff
cmd/ctrld: check for ipv6 listen local
...
Since when the machine may not have external ipv6 capability, but still
can do ipv6 network on local network.
2023-03-07 10:25:48 +07:00
Cuong Manh Le and Cuong Manh Le
8b08cc8a6e
all: rework bootstrap IP discovering
...
At startup, ctrld gathers bootstrap IP information and use this
bootstrap IP for connecting to upstream. However, in case the network
stack changed, for example, dues to VPN connection, ctrld will still use
this old (maybe invalid) bootstrap IP for the current network stack.
This commit rework the discovering process, and re-initializing the
bootstrap IP if connecting to upstream failed.
2023-03-07 10:25:48 +07:00
Cuong Manh Le and Cuong Manh Le
930a5ad439
cmd/ctrld: only set ::1 as DNS server on Windows if ipv6 available
2023-03-07 10:25:48 +07:00
Cuong Manh Le and Cuong Manh Le
8852f60ccb
Add idle conn timeout for HTTP transport
...
Allowing the connection to be re-new once it becomes un-usable.
2023-03-07 10:25:48 +07:00
Cuong Manh Le and Cuong Manh Le
2e1b3f9d07
Upgrade golang.org/x/net to v0.7.0
...
For pulling CVE-2022-41723 fix.
2023-03-07 10:25:48 +07:00
Cuong Manh Le and Cuong Manh Le
6d3c82d38d
internal/dns: add debian/openresolv to linux manager
2023-02-27 21:50:06 +07:00
Cuong Manh Le and Cuong Manh Le
cad71997aa
cmd/ctrld: allocate new ip instead of port
...
So the alternative listener address can still be used as system
resolver.
2023-02-27 20:50:01 +07:00
Cuong Manh Le and Cuong Manh Le
82900eeca6
cmd/ctrld: move log file if existed on app start
...
Updates #59
2023-02-27 20:43:56 +07:00
Cuong Manh Le and Cuong Manh Le
84fca06c62
cmd/ctrld: implement allocate/deallocate ip on freebsd
...
Updates #56
2023-02-27 20:43:56 +07:00
Cuong Manh Le and Cuong Manh Le
64f2dcb25b
Fix parsing network service name on darwin
...
The network service name appears on the previous line, not the same line
with "Device" name.
Updates #57
2023-02-27 20:43:56 +07:00
Cuong Manh Le and Cuong Manh Le
4c2d21a8f8
all: add freebsd supports
...
This commit add support for ctrld to run on freebsd, supported platforms
are amd64/arm64/armv6/armv7,386.
Supporting freebsd also requires adding debian and openresolv resolvconf.
Updates #47
2023-02-27 20:43:56 +07:00
Cuong Manh Le and Cuong Manh Le
4172fc09d0
cmd/ctrld: add self check for better error message reported
...
After telling service manager to start ctrld, performing self check
status by sending DNS query to ctrld listener. So if ctrld could not
start for any reason, an error message will be reported to user instead
of simply telling service started.
Updates #56
2023-02-27 20:43:55 +07:00
Cuong Manh Le and Cuong Manh Le
d9b699501d
cmd/ctrld: merge proxy log to main log
...
There's no reason to separate those two loggers anymore, and making them
separated may lead to inconsistent logging behavior.
Updates #54
2023-02-27 20:13:44 +07:00
Cuong Manh Le and Cuong Manh Le
71b1b324db
cmd/ctrld: honor configPath when writing config file
...
Updates #58
2023-02-27 20:13:44 +07:00
Cuong Manh Le and Cuong Manh Le
35c890048b
cmd/ctrld: remove prefix main field
...
While at it, also make init logging with empty log path when running
start command.
Updates #55
2023-02-27 20:13:44 +07:00
Cuong Manh Le and Cuong Manh Le
bac6810956
cmd/ctrld: fix missing unmarshalling config without --cd
...
Otherwise, DNS won't be set in non-Linux systems.
Updates #54
2023-02-27 20:13:44 +07:00
Cuong Manh Le and Cuong Manh Le
997ec342e0
cmd/ctrld,internal/dns: support systemd-networkd dbus
...
For interface managed by systemd-networkd, systemd-resolved can not
reset DNS. To fix this, attempting to check before the run loop and set
the suitable manager for the system.
Updates #55
2023-02-27 20:13:44 +07:00
Cuong Manh Le and Cuong Manh Le
e385547461
internal/net: fix wrong address when testing network up
2023-02-27 20:13:44 +07:00
Cuong Manh Le and Cuong Manh Le
83b551fb2d
internal/controld: check if ipv4 is available before connect to API
...
Updates #53
2023-02-27 20:13:42 +07:00
Cuong Manh Le and Cuong Manh Le
45f827a2c5
internal/controld: connect to API using ipv4 only
...
Connecting to API using ipv6 sometimes hang at TLS handshake, using ipv4
only so we can fetch the config more reliably.
Fixed #53
2023-02-27 19:54:52 +07:00
Cuong Manh Le and Cuong Manh Le
3218b5fac1
Add quic-free binaries in build pipeline
...
Updates #51
2023-02-27 19:54:18 +07:00
Cuong Manh Le and Cuong Manh Le
df514d15a5
Update quic-go to v0.32.0
...
Updates #51
2023-02-27 19:51:39 +07:00
Cuong Manh Le and Cuong Manh Le
50b0e5a4b0
cmd/ctrld: use proper exit codes for status command
...
While at it, disable sort commands, so help output will be in order.
Updates #48
2023-02-27 19:50:28 +07:00
Cuong Manh Le and Cuong Manh Le
f13f61592c
Add upx to goreleaser builds
...
Reducing the size of the final binaries, except for darwin, where the
packed binaries failed to run.
2023-02-13 21:58:45 +07:00
Cuong Manh Le and Cuong Manh Le
2f42fc055d
Add some badges to README.md
2023-02-08 00:53:16 +07:00
Cuong Manh Le and Cuong Manh Le
d73ece9d9e
Remove darwin from regular builds
...
PR #13 add notarizing step for darwin, but forgot to remove darwin from
regular OS builds.
2023-02-08 00:21:15 +07:00
Cuong Manh Le and Cuong Manh Le
56d8c102e1
Remove conflicts marker in README.md
2023-02-07 23:22:12 +07:00
Cuong Manh Le and Cuong Manh Le
0e09b45bca
cmd/ctrld: bump version to v1.1.0
2023-02-07 22:53:54 +07:00
Cuong Manh Le and Cuong Manh Le
8571580aae
cmd/ctrld: fatal if failed to get default iface name
...
So it left a chance for system service manager to bring up ctrld for us.
Without default iface name, ctrld could not work properly anyway.
2023-02-07 22:53:49 +07:00
Cuong Manh Le and Cuong Manh Le
d3fe2c730c
cmd/ctrld: surpress backoff logging message
2023-02-07 22:53:41 +07:00
Cuong Manh Le and Cuong Manh Le
318fec27de
cmd/ctrld: fatal loudly if listen failed
...
For address already in use error when listening, we have a workaround to
spawn a new listener on different port. However, if that case does not
match, we must fatal to notice the error to user.
2023-02-07 22:53:27 +07:00
Cuong Manh Le and Cuong Manh Le
beca95d5b9
cmd/ctrld: fix systemd dependencies config
...
See https://github.com/systemd/systemd/issues/22360
2023-02-07 22:53:14 +07:00
Cuong Manh Le and Cuong Manh Le
31b30c52b1
Add notarizing darwin binary with gon
2023-02-07 09:34:42 +07:00
Cuong Manh Le and Cuong Manh Le
851f9b9742
all: fork tailscale Linux dns manager package
...
With modification to fit our use case.
2023-02-03 02:47:31 +07:00
Cuong Manh Le and Cuong Manh Le
b8772d7b4a
cmd/ctrld: log fatal if could not start the listener
2023-02-03 02:16:19 +07:00
Cuong Manh Le and Cuong Manh Le
eb0dd6235e
cmd/ctrld: use NetworkManager to disable DNS manager
...
Currently, ctrld force NetworkManager ignore auto DNS setup from DHCP
per connection. This does not work well, because an interface can be
attached to many connections. So if `ctrld` started with a connection,
then user connect to new one, the DNS configured by ctrld will be
override.
Instead, we can force NetworkManager not to manage DNS by:
- Using dns=none
- Set systemd-resolved=false
So NetworkManager won't attempt to send DNS setup to systemd-resolved,
leaving what ctrld set as-is.
2023-02-02 22:10:06 +07:00
Cuong Manh Le and Cuong Manh Le
1c2cd555bd
cmd/ctrld: ensure ctrld start after NetworkManager
2023-02-01 23:11:33 +07:00
Cuong Manh Le and Cuong Manh Le
8c47ffb5ec
cmd/ctrld: make NetworkManger ignore auto dns
...
So the DNS that set by ctrld won't be override on startup.
2023-02-01 23:11:33 +07:00
Cuong Manh Le and Cuong Manh Le
44bd580e48
cmd/ctrld: fix reset DNS when uninstalling
...
The "--iface" needs to be explicitly passed, otherwise, ctrld does not
know which interface to restore.
2023-02-01 23:11:33 +07:00
Cuong Manh Le and Cuong Manh Le
61156453b2
cmd/ctrld: workaround setting DNS issue on Linux
...
On some Ubuntu systems, we experiment with DNS is not set even though
systemd-resolved log indicates that it set them. To ensure the DNS will
be set, after setting them, double check the current DNS for interface
is actually the value was set, if not, attempting to set again.
While at it, also make sure the DNS is set when ctrld start on Linux.
2023-02-01 23:11:33 +07:00
Cuong Manh Le and Cuong Manh Le
37de5441c1
cmd/ctrld: silent DHCPv6 error
...
It's hard to imagine a system with IPv6 but not IPv4, so silent the
DHCPv6 error if any.
2023-02-01 23:11:33 +07:00
Cuong Manh Le and Cuong Manh Le
149941f17f
cmd/ctrld: do set/reset DNS only when start/stop/uninstall
2023-02-01 23:11:33 +07:00
Cuong Manh Le and Cuong Manh Le
4ea1e64795
all: make cache scope to upstream
2023-02-01 23:11:32 +07:00
Cuong Manh Le and Cuong Manh Le
06372031b5
cmd/ctrld: add more logging details
2023-02-01 23:09:01 +07:00
Cuong Manh Le and Cuong Manh Le
c82a0e2562
cmd/ctrld: optimizing set/reset DNS
...
Currently, when reset DNS, ctrld always find the net.Interface by
interface name. This may produce unexpected error because the interface
table may be cleared at the time ctrld is being stopped.
Instead, we can get the net interface only once, and use that interface
for restoring the DNS before shutting down.
While at it, also making logging message clearer.
2023-01-24 16:57:16 +07:00
Cuong Manh Le and Cuong Manh Le
b0dc96aa01
cmd/ctrld: use debug level when --log set
2023-01-24 16:57:08 +07:00
Cuong Manh Le and Cuong Manh Le
31e4bcb4c3
cmd/ctrld: init logging before processing --cd
...
So it's easier to debug in case of weird thing happens.
2023-01-24 01:32:51 +07:00
Cuong Manh Le and Cuong Manh Le
9fc546443b
cmd/ctrld: ignore syscall.EINTR on Linux
...
Observing while tested on Ubuntu 22.04.1, the request to reset using
systemd resolved via dbus may be interruped.
2023-01-24 01:32:44 +07:00
Cuong Manh Le and Cuong Manh Le
8a2c48e996
cmd/ctrld: allow log/cache flags work wit --cd flag
2023-01-23 14:06:51 +07:00
Cuong Manh Le and Cuong Manh Le
1186963531
all: use controld dialer for probing network
2023-01-23 14:06:43 +07:00
Cuong Manh Le and Cuong Manh Le
837563dcd5
all: wait for network up before running
...
If ctrld setup the interface correctly, the interface DNS is set to
ctrld listener address. At boot time, the ctrld is not up yet, so it
would break the processing Control D config fetching.
Fixing this by waiting for network up before doing the query.
2023-01-23 00:48:33 +07:00
Cuong Manh Le and Cuong Manh Le
cd37d93b06
cmd/ctrld: ensure cleaning up done when self-uninstall
...
While at it, also making DNS reset always use DHCP.
2023-01-21 13:43:07 +07:00
Cuong Manh Le and Cuong Manh Le
f6371360bc
all: satisfy staticcheck
2023-01-21 01:14:03 +07:00
Cuong Manh Le and Cuong Manh Le
46965b04b4
internal/resolvconffile: add build tag for test file
2023-01-21 01:14:03 +07:00
Cuong Manh Le and Cuong Manh Le
065a391ff4
cmd/ctrld: check elevated privilege for service mode
2023-01-21 01:13:59 +07:00
Cuong Manh Le and Cuong Manh Le
d830706692
cmd/ctrld: always process "--cd" in start mode
...
So if there's any error in fetching configuration, it will be reported
to user and service won't start.
2023-01-21 01:13:54 +07:00
Cuong Manh Le and Cuong Manh Le
14ddb1faa0
cmd/ctrld: ensure writing config message is printed on non-Windows
2023-01-21 01:13:49 +07:00
Cuong Manh Le and Cuong Manh Le
326d7a43d4
cmd/ctrld: rework reset DNS statically vs DHCP
...
If the interface was originally configured DNS via DHCP, ctrld should
reset the interface using DHCP, not statically.
2023-01-20 21:43:04 +07:00
Cuong Manh Le and Cuong Manh Le
87091f20b0
cmd/ctrld: print writing config file message
2023-01-20 21:43:04 +07:00
Cuong Manh Le and Cuong Manh Le
d418e57def
cmd/ctrld: workaround ipv6 dns resolver on Windows
...
On Windows, there's no easy way for disabling/removing IPv6 DNS
resolver, so we check whether we can listen on ::1, then spawn a
listener for receiving DNS requests
2023-01-20 21:43:04 +07:00
Cuong Manh Le and Cuong Manh Le
49e9b8b51c
cmd/ctrld: do not change DNS for tailscale0
...
Let user decide which option is prefer.
2023-01-20 21:43:04 +07:00
Cuong Manh Le and Cuong Manh Le
dc7d77b22e
cmd/ctrld: only add "--iface" if not changed for start/stop aliases
2023-01-20 21:43:04 +07:00
Cuong Manh Le and Cuong Manh Le
a9fabd1b79
cmd/ctrld: separate iface variable for start/stop aliases
...
While at it, also fix a bug in getDNSByResolvectl, which won't return
correct DNS values if there's no "%" symbol in output.
2023-01-20 21:43:04 +07:00
Cuong Manh Le and Cuong Manh Le
47c280cf1d
cmd/ctrld: use network service on darwin
2023-01-20 21:43:04 +07:00
Cuong Manh Le and Cuong Manh Le
05cfb9b661
cmd/ctrld: fix typo in Network name
2023-01-20 21:43:04 +07:00
Cuong Manh Le and Cuong Manh Le
99b0cbedc3
cmd/ctrld: include DNS in interface list
2023-01-20 21:43:04 +07:00
Cuong Manh Le and 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 and Cuong Manh Le
a318e19e33
Workaround quic-go DoQ server issue
...
Reported in https://feedback.controld.com/posts/1739
2023-01-20 21:43:04 +07:00
Cuong Manh Le and 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 and Cuong Manh Le
d5344aea52
cmd/ctrld: add list interfaces command
2023-01-20 21:37:55 +07:00
Cuong Manh Le and 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 and Cuong Manh Le
53306235dc
all: uninstall service if got invalid config from API
2023-01-20 21:37:44 +07:00
Cuong Manh Le and 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 and 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 and Cuong Manh Le
9f90811567
cmd/ctrld: update config when "--cd" present
2023-01-20 21:37:24 +07:00
Cuong Manh Le and 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 and 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 and Cuong Manh Le
3014556f2d
cmd/ctrld,internal/controld: do not set bootstrap IP
2023-01-20 21:36:56 +07:00
Cuong Manh Le and 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