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
2023-06-21 15:38:08 +07:00
committed by Cuong Manh Le
parent 350d8355b1
commit 50bfed706d
6 changed files with 41 additions and 14 deletions
+9 -5
View File
@@ -751,11 +751,10 @@ func processCDFlags() {
listener.Port = 53
}
}
// On router, we want to keep the listener address point to dnsmasq listener, aka 127.0.0.1:53.
if router.Name() != "" {
if setupRouter {
if lc := cfg.Listener["0"]; lc != nil {
lc.IP = "127.0.0.1"
lc.Port = 53
lc.IP = router.ListenIP()
lc.Port = router.ListenPort()
}
}
} else {
@@ -776,7 +775,7 @@ func processCDFlags() {
rules = append(rules, ctrld.Rule{domain: []string{}})
}
cfg.Listener = make(map[string]*ctrld.ListenerConfig)
cfg.Listener["0"] = &ctrld.ListenerConfig{
lc := &ctrld.ListenerConfig{
IP: "127.0.0.1",
Port: 53,
Policy: &ctrld.ListenerPolicyConfig{
@@ -784,6 +783,11 @@ func processCDFlags() {
Rules: rules,
},
}
if setupRouter {
lc.IP = router.ListenIP()
lc.Port = router.ListenPort()
}
cfg.Listener["0"] = lc
processLogAndCacheFlags()
}
+5 -2
View File
@@ -402,8 +402,11 @@ func needLocalIPv6Listener() bool {
}
func dnsListenAddress(lcNum string, lc *ctrld.ListenerConfig) string {
if addr := router.ListenAddress(); setupRouter && addr != "" && lcNum == "0" {
return addr
addr := net.JoinHostPort(lc.IP, strconv.Itoa(lc.Port))
// 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))
}