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
+1 -25
View File
@@ -1,18 +1,14 @@
package openwrt
import (
"bytes"
"errors"
"fmt"
"os"
"os/exec"
"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/internal/router/dnsmasq"
)
const (
@@ -20,8 +16,6 @@ const (
openwrtDNSMasqConfigPath = "/tmp/dnsmasq.d/ctrld.conf"
)
var errUCIEntryNotFound = errors.New("uci: Entry not found")
type Openwrt struct {
cfg *ctrld.Config
}
@@ -59,10 +53,6 @@ func (o *Openwrt) Setup() error {
if err := os.WriteFile(openwrtDNSMasqConfigPath, []byte(data), 0600); err != nil {
return err
}
// Commit.
if _, err := uci("commit"); err != nil {
return err
}
// Restart dnsmasq service.
if err := restartDNSMasq(); err != nil {
return err
@@ -91,17 +81,3 @@ func restartDNSMasq() error {
}
return nil
}
func uci(args ...string) (string, error) {
cmd := exec.Command("uci", args...)
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
if strings.HasPrefix(stderr.String(), errUCIEntryNotFound.Error()) {
return "", errUCIEntryNotFound
}
return "", fmt.Errorf("%s:%w", stderr.String(), err)
}
return strings.TrimSpace(stdout.String()), nil
}