all: writing correct routers setup to config file

When running on routers, ctrld leverages default setup, let dnsmasq runs
on port 53, and forward queries to ctrld listener on port 5354. However,
this setup is not serialized to config file, causing confusion to users.

Fixing this by writing the correct routers setup to config file. While
at it, updating documentation to refelct that, and also adding note that
changing default router setup could break things.
This commit is contained in:
Cuong Manh Le authored and Cuong Manh Le committed 2023-08-09 23:54:23 +07:00
1 parent 350d8355b1
commit 50bfed706d
6 files changed
+41 -14

No files matched your search

+15
View File
@@ -73,7 +73,13 @@ $ go install github.com/Control-D-Inc/ctrld/cmd/ctrld@latest
$ docker build -t controld/ctrld . $ docker build -t controld/ctrld .
$ docker run -d --name=ctrld -p 53:53/tcp -p 53:53/udp controld/ctrld --cd=p2 -vv $ docker run -d --name=ctrld -p 53:53/tcp -p 53:53/udp controld/ctrld --cd=p2 -vv
``` ```
-----
*NOTE*
When running inside container, and listener address is set to "127.0.0.1:53", `ctrld` will change
the listen address to "0.0.0.0:53", so users can expose the port to outside.
----
# Usage # Usage
The cli is self documenting, so free free to run `--help` on any sub-command to get specific usages. The cli is self documenting, so free free to run `--help` on any sub-command to get specific usages.
@@ -176,6 +182,15 @@ In order to start `ctrld` as a DNS provider, simply run `./ctrld setup auto` com
In this mode, and when Control D upstreams are used, the router will [relay your network topology](https://docs.controld.com/docs/device-clients) to Control D (LAN IPs, MAC addresses, and hostnames), and you will be able to see your LAN devices in the web panel, view analytics and apply unique profiles to them. In this mode, and when Control D upstreams are used, the router will [relay your network topology](https://docs.controld.com/docs/device-clients) to Control D (LAN IPs, MAC addresses, and hostnames), and you will be able to see your LAN devices in the web panel, view analytics and apply unique profiles to them.
----
*NOTE*
`ctrld` will try leveraging default setup on routers, so changing routers default configuration would causes things won't work as expected (For example, changing dnsmasq configuration).
Advanced users who want to play around, just run `ctrld` in [Service Mode](#service-mode) with custom configuration.
----
### Control D Auto Configuration ### Control D Auto Configuration
Application can be started with a specific resolver config, instead of the default one. Simply supply your Resolver ID with a `--cd` flag, when using the `run` (foreground) or `start` (service) or `setup` (router) modes. Application can be started with a specific resolver config, instead of the default one. Simply supply your Resolver ID with a `--cd` flag, when using the `run` (foreground) or `start` (service) or `setup` (router) modes.
+9 -5
View File
@@ -751,11 +751,10 @@ func processCDFlags() {
listener.Port = 53 listener.Port = 53
} }
} }
// On router, we want to keep the listener address point to dnsmasq listener, aka 127.0.0.1:53. if setupRouter {
if router.Name() != "" {
if lc := cfg.Listener["0"]; lc != nil { if lc := cfg.Listener["0"]; lc != nil {
lc.IP = "127.0.0.1" lc.IP = router.ListenIP()
lc.Port = 53 lc.Port = router.ListenPort()
} }
} }
} else { } else {
@@ -776,7 +775,7 @@ func processCDFlags() {
rules = append(rules, ctrld.Rule{domain: []string{}}) rules = append(rules, ctrld.Rule{domain: []string{}})
} }
cfg.Listener = make(map[string]*ctrld.ListenerConfig) cfg.Listener = make(map[string]*ctrld.ListenerConfig)
cfg.Listener["0"] = &ctrld.ListenerConfig{ lc := &ctrld.ListenerConfig{
IP: "127.0.0.1", IP: "127.0.0.1",
Port: 53, Port: 53,
Policy: &ctrld.ListenerPolicyConfig{ Policy: &ctrld.ListenerPolicyConfig{
@@ -784,6 +783,11 @@ func processCDFlags() {
Rules: rules, Rules: rules,
}, },
} }
if setupRouter {
lc.IP = router.ListenIP()
lc.Port = router.ListenPort()
}
cfg.Listener["0"] = lc
processLogAndCacheFlags() processLogAndCacheFlags()
} }
+5 -2
View File
@@ -402,8 +402,11 @@ func needLocalIPv6Listener() bool {
} }
func dnsListenAddress(lcNum string, lc *ctrld.ListenerConfig) string { func dnsListenAddress(lcNum string, lc *ctrld.ListenerConfig) string {
if addr := router.ListenAddress(); setupRouter && addr != "" && lcNum == "0" { addr := net.JoinHostPort(lc.IP, strconv.Itoa(lc.Port))
return addr // If we are inside container and the listener address is localhost,
// Change it to 0.0.0.0:53, so user can expose the port to outside.
if addr == "127.0.0.1:53" && cdUID != "" && inContainer() {
return "0.0.0.0:53"
} }
return net.JoinHostPort(lc.IP, strconv.Itoa(lc.Port)) return net.JoinHostPort(lc.IP, strconv.Itoa(lc.Port))
} }
+2 -2
View File
@@ -316,14 +316,14 @@ IP address that serves the incoming requests. If `ip` is empty, ctrld will liste
- Type: ip address string - Type: ip address string
- Required: no - Required: no
- Default: "" - Default: "" or "127.0.0.1" in [Router Mode](../README.md#router-mode).
### port ### port
Port number that the listener will listen on for incoming requests. If `port` is `0`, a random available port will be chosen. Port number that the listener will listen on for incoming requests. If `port` is `0`, a random available port will be chosen.
- Type: number - Type: number
- Required: no - Required: no
- Default: 0 - Default: 0 or 5354 in [Router Mode](../README.md#router-mode).
### restricted ### restricted
If set to `true` makes the listener `REFUSE` DNS queries from all source IP addresses that are not explicitly defined in the policy using a `network`. If set to `true` makes the listener `REFUSE` DNS queries from all source IP addresses that are not explicitly defined in the policy using a `network`.
+1 -1
View File
@@ -69,7 +69,7 @@ func cleanupFirewalla() error {
// Restart dnsmasq service. // Restart dnsmasq service.
if err := restartDNSMasq(); err != nil { if err := restartDNSMasq(); err != nil {
return fmt.Errorf("cleaupFirewalla: restartDNSMasq: %w", err) return fmt.Errorf("cleanupFirewalla: restartDNSMasq: %w", err)
} }
return nil return nil
+9 -4
View File
@@ -214,16 +214,21 @@ func Cleanup(svc *service.Config) error {
return nil return nil
} }
// ListenAddress returns the listener address of ctrld on router. // ListenIP returns the listener IP of ctrld on router.
func ListenAddress() string { func ListenIP() string {
return "127.0.0.1"
}
// ListenPort returns the listener port of ctrld on router.
func ListenPort() int {
name := Name() name := Name()
switch name { switch name {
case DDWrt, Firewalla, Merlin, OpenWrt, Synology, Tomato, Ubios: case DDWrt, Firewalla, Merlin, OpenWrt, Synology, Tomato, Ubios:
return "127.0.0.1:5354" return 5354
case Pfsense: case Pfsense:
// On pfsense, we run ctrld as DNS resolver. // On pfsense, we run ctrld as DNS resolver.
} }
return "" return 53
} }
// Name returns name of the router platform. // Name returns name of the router platform.