mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
internal/router: do not disable cache on EdgeOS
The dnsmasq cache-size setting on EdgeOS could be re-generated anytime by vyatta router/dhcp components. This conflicts with setting generated by ctrld, causing dnsmasq fails to start. It's better to keep dnsmasq cache enabled on EdgeOS, we can turn it off again once we find a reliable way to control cache-size setting.
This commit is contained in:
committed by
Cuong Manh Le
parent
28ec1869fc
commit
2bebe93e47
@@ -22,7 +22,9 @@ server={{ .IP }}#{{ .Port }}
|
||||
add-mac
|
||||
add-subnet=32,128
|
||||
{{- end}}
|
||||
{{- if .CacheDisabled}}
|
||||
cache-size=0
|
||||
{{- end}}
|
||||
`
|
||||
|
||||
const MerlinPostConfPath = "/jffs/scripts/dnsmasq.postconf"
|
||||
@@ -71,6 +73,10 @@ type Upstream struct {
|
||||
}
|
||||
|
||||
func ConfTmpl(tmplText string, cfg *ctrld.Config) (string, error) {
|
||||
return ConfTmplWitchCacheDisabled(tmplText, cfg, true)
|
||||
}
|
||||
|
||||
func ConfTmplWitchCacheDisabled(tmplText string, cfg *ctrld.Config, cacheDisabled bool) (string, error) {
|
||||
listener := cfg.FirstListener()
|
||||
if listener == nil {
|
||||
return "", errors.New("missing listener")
|
||||
@@ -80,24 +86,26 @@ func ConfTmpl(tmplText string, cfg *ctrld.Config) (string, error) {
|
||||
ip = "127.0.0.1"
|
||||
}
|
||||
upstreams := []Upstream{{IP: ip, Port: listener.Port}}
|
||||
return confTmpl(tmplText, upstreams, cfg.HasUpstreamSendClientInfo())
|
||||
return confTmpl(tmplText, upstreams, cfg.HasUpstreamSendClientInfo(), cacheDisabled)
|
||||
}
|
||||
|
||||
func FirewallaConfTmpl(tmplText string, cfg *ctrld.Config) (string, error) {
|
||||
if lc := cfg.FirstListener(); lc != nil && (lc.IP == "0.0.0.0" || lc.IP == "") {
|
||||
return confTmpl(tmplText, firewallaUpstreams(lc.Port), cfg.HasUpstreamSendClientInfo())
|
||||
return confTmpl(tmplText, firewallaUpstreams(lc.Port), cfg.HasUpstreamSendClientInfo(), true)
|
||||
}
|
||||
return ConfTmpl(tmplText, cfg)
|
||||
}
|
||||
|
||||
func confTmpl(tmplText string, upstreams []Upstream, sendClientInfo bool) (string, error) {
|
||||
func confTmpl(tmplText string, upstreams []Upstream, sendClientInfo, cacheDisabled bool) (string, error) {
|
||||
tmpl := template.Must(template.New("").Parse(tmplText))
|
||||
var to = &struct {
|
||||
SendClientInfo bool
|
||||
Upstreams []Upstream
|
||||
CacheDisabled bool
|
||||
}{
|
||||
SendClientInfo: sendClientInfo,
|
||||
Upstreams: upstreams,
|
||||
CacheDisabled: cacheDisabled,
|
||||
}
|
||||
var sb strings.Builder
|
||||
if err := tmpl.Execute(&sb, to); err != nil {
|
||||
|
||||
@@ -8,19 +8,18 @@ import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/Control-D-Inc/ctrld/internal/router/dnsmasq"
|
||||
"github.com/kardianos/service"
|
||||
|
||||
"github.com/Control-D-Inc/ctrld"
|
||||
"github.com/kardianos/service"
|
||||
"github.com/Control-D-Inc/ctrld/internal/router/dnsmasq"
|
||||
)
|
||||
|
||||
const (
|
||||
Name = "edgeos"
|
||||
edgeOSDNSMasqDefaultConfigPath = "/etc/dnsmasq.conf"
|
||||
edgeOSDNSMasqConfigPath = "/etc/dnsmasq.d/dnsmasq-zzz-ctrld.conf"
|
||||
usgDNSMasqConfigPath = "/etc/dnsmasq.conf"
|
||||
usgDNSMasqBackupConfigPath = "/etc/dnsmasq.conf.bak"
|
||||
toggleContentFilteringLink = "https://community.ui.com/questions/UDM-Pro-disable-enable-DNS-filtering/e2cc4060-e56a-4139-b200-62d7f773ff8f"
|
||||
Name = "edgeos"
|
||||
edgeOSDNSMasqConfigPath = "/etc/dnsmasq.d/dnsmasq-zzz-ctrld.conf"
|
||||
usgDNSMasqConfigPath = "/etc/dnsmasq.conf"
|
||||
usgDNSMasqBackupConfigPath = "/etc/dnsmasq.conf.bak"
|
||||
toggleContentFilteringLink = "https://community.ui.com/questions/UDM-Pro-disable-enable-DNS-filtering/e2cc4060-e56a-4139-b200-62d7f773ff8f"
|
||||
)
|
||||
|
||||
var ErrContentFilteringEnabled = fmt.Errorf(`the "Content Filtering" feature" is enabled, which is conflicted with ctrld.\n
|
||||
@@ -107,13 +106,10 @@ func (e *EdgeOS) setupUSG() error {
|
||||
if strings.HasPrefix(line, "all-servers") {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(line, "cache-size") {
|
||||
continue
|
||||
}
|
||||
sb.WriteString(line)
|
||||
}
|
||||
|
||||
data, err := dnsmasq.ConfTmpl(dnsmasq.ConfigContentTmpl, e.cfg)
|
||||
data, err := dnsmasq.ConfTmplWitchCacheDisabled(dnsmasq.ConfigContentTmpl, e.cfg, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -131,11 +127,7 @@ func (e *EdgeOS) setupUSG() error {
|
||||
}
|
||||
|
||||
func (e *EdgeOS) setupUDM() error {
|
||||
// Disable dnsmasq cache.
|
||||
if err := dnsmasq.DisableCache(edgeOSDNSMasqDefaultConfigPath); err != nil {
|
||||
return err
|
||||
}
|
||||
data, err := dnsmasq.ConfTmpl(dnsmasq.ConfigContentTmpl, e.cfg)
|
||||
data, err := dnsmasq.ConfTmplWitchCacheDisabled(dnsmasq.ConfigContentTmpl, e.cfg, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -161,10 +153,6 @@ func (e *EdgeOS) cleanupUSG() error {
|
||||
}
|
||||
|
||||
func (e *EdgeOS) cleanupUDM() error {
|
||||
// Enable dnsmasq cache.
|
||||
if err := dnsmasq.EnableCache(edgeOSDNSMasqDefaultConfigPath); err != nil {
|
||||
return err
|
||||
}
|
||||
// Remove the custom dnsmasq config
|
||||
if err := os.Remove(edgeOSDNSMasqConfigPath); err != nil {
|
||||
return fmt.Errorf("cleanupUDM: os.Remove: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user