internal/router/dnsmasq: disable cache

So multiple upstreams config could work properly.
This commit is contained in:
Cuong Manh Le
2023-11-08 23:51:18 +07:00
committed by Cuong Manh Le
parent 4816a09e3a
commit 43ff2f648c
5 changed files with 97 additions and 36 deletions
+18 -6
View File
@@ -15,11 +15,12 @@ import (
)
const (
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"
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"
)
var ErrContentFilteringEnabled = fmt.Errorf(`the "Content Filtering" feature" is enabled, which is conflicted with ctrld.\n
@@ -95,7 +96,7 @@ func (e *EdgeOS) setupUSG() error {
return fmt.Errorf("setupUSG: backup current config: %w", err)
}
// Removing all configured upstreams.
// Removing all configured upstreams and cache config.
var sb strings.Builder
scanner := bufio.NewScanner(bytes.NewReader(buf))
for scanner.Scan() {
@@ -106,6 +107,9 @@ func (e *EdgeOS) setupUSG() error {
if strings.HasPrefix(line, "all-servers") {
continue
}
if strings.HasPrefix(line, "cache-size") {
continue
}
sb.WriteString(line)
}
@@ -127,6 +131,10 @@ 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)
if err != nil {
return err
@@ -153,6 +161,10 @@ 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)