mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-08-10 13:20:33 +02: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:
@@ -22,7 +22,9 @@ server={{ .IP }}#{{ .Port }}
|
|||||||
add-mac
|
add-mac
|
||||||
add-subnet=32,128
|
add-subnet=32,128
|
||||||
{{- end}}
|
{{- end}}
|
||||||
|
{{- if .CacheDisabled}}
|
||||||
cache-size=0
|
cache-size=0
|
||||||
|
{{- end}}
|
||||||
`
|
`
|
||||||
|
|
||||||
const MerlinPostConfPath = "/jffs/scripts/dnsmasq.postconf"
|
const MerlinPostConfPath = "/jffs/scripts/dnsmasq.postconf"
|
||||||
@@ -71,6 +73,10 @@ type Upstream struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ConfTmpl(tmplText string, cfg *ctrld.Config) (string, error) {
|
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()
|
listener := cfg.FirstListener()
|
||||||
if listener == nil {
|
if listener == nil {
|
||||||
return "", errors.New("missing listener")
|
return "", errors.New("missing listener")
|
||||||
@@ -80,24 +86,26 @@ func ConfTmpl(tmplText string, cfg *ctrld.Config) (string, error) {
|
|||||||
ip = "127.0.0.1"
|
ip = "127.0.0.1"
|
||||||
}
|
}
|
||||||
upstreams := []Upstream{{IP: ip, Port: listener.Port}}
|
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) {
|
func FirewallaConfTmpl(tmplText string, cfg *ctrld.Config) (string, error) {
|
||||||
if lc := cfg.FirstListener(); lc != nil && (lc.IP == "0.0.0.0" || lc.IP == "") {
|
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)
|
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))
|
tmpl := template.Must(template.New("").Parse(tmplText))
|
||||||
var to = &struct {
|
var to = &struct {
|
||||||
SendClientInfo bool
|
SendClientInfo bool
|
||||||
Upstreams []Upstream
|
Upstreams []Upstream
|
||||||
|
CacheDisabled bool
|
||||||
}{
|
}{
|
||||||
SendClientInfo: sendClientInfo,
|
SendClientInfo: sendClientInfo,
|
||||||
Upstreams: upstreams,
|
Upstreams: upstreams,
|
||||||
|
CacheDisabled: cacheDisabled,
|
||||||
}
|
}
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
if err := tmpl.Execute(&sb, to); err != nil {
|
if err := tmpl.Execute(&sb, to); err != nil {
|
||||||
|
|||||||
@@ -8,19 +8,18 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Control-D-Inc/ctrld/internal/router/dnsmasq"
|
"github.com/kardianos/service"
|
||||||
|
|
||||||
"github.com/Control-D-Inc/ctrld"
|
"github.com/Control-D-Inc/ctrld"
|
||||||
"github.com/kardianos/service"
|
"github.com/Control-D-Inc/ctrld/internal/router/dnsmasq"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Name = "edgeos"
|
Name = "edgeos"
|
||||||
edgeOSDNSMasqDefaultConfigPath = "/etc/dnsmasq.conf"
|
edgeOSDNSMasqConfigPath = "/etc/dnsmasq.d/dnsmasq-zzz-ctrld.conf"
|
||||||
edgeOSDNSMasqConfigPath = "/etc/dnsmasq.d/dnsmasq-zzz-ctrld.conf"
|
usgDNSMasqConfigPath = "/etc/dnsmasq.conf"
|
||||||
usgDNSMasqConfigPath = "/etc/dnsmasq.conf"
|
usgDNSMasqBackupConfigPath = "/etc/dnsmasq.conf.bak"
|
||||||
usgDNSMasqBackupConfigPath = "/etc/dnsmasq.conf.bak"
|
toggleContentFilteringLink = "https://community.ui.com/questions/UDM-Pro-disable-enable-DNS-filtering/e2cc4060-e56a-4139-b200-62d7f773ff8f"
|
||||||
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
|
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") {
|
if strings.HasPrefix(line, "all-servers") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(line, "cache-size") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
sb.WriteString(line)
|
sb.WriteString(line)
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := dnsmasq.ConfTmpl(dnsmasq.ConfigContentTmpl, e.cfg)
|
data, err := dnsmasq.ConfTmplWitchCacheDisabled(dnsmasq.ConfigContentTmpl, e.cfg, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -131,11 +127,7 @@ func (e *EdgeOS) setupUSG() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *EdgeOS) setupUDM() error {
|
func (e *EdgeOS) setupUDM() error {
|
||||||
// Disable dnsmasq cache.
|
data, err := dnsmasq.ConfTmplWitchCacheDisabled(dnsmasq.ConfigContentTmpl, e.cfg, false)
|
||||||
if err := dnsmasq.DisableCache(edgeOSDNSMasqDefaultConfigPath); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
data, err := dnsmasq.ConfTmpl(dnsmasq.ConfigContentTmpl, e.cfg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -161,10 +153,6 @@ func (e *EdgeOS) cleanupUSG() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *EdgeOS) cleanupUDM() error {
|
func (e *EdgeOS) cleanupUDM() error {
|
||||||
// Enable dnsmasq cache.
|
|
||||||
if err := dnsmasq.EnableCache(edgeOSDNSMasqDefaultConfigPath); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// Remove the custom dnsmasq config
|
// Remove the custom dnsmasq config
|
||||||
if err := os.Remove(edgeOSDNSMasqConfigPath); err != nil {
|
if err := os.Remove(edgeOSDNSMasqConfigPath); err != nil {
|
||||||
return fmt.Errorf("cleanupUDM: os.Remove: %w", err)
|
return fmt.Errorf("cleanupUDM: os.Remove: %w", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user