mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
Preparing for v2.0.0 branch merge
This commit reverts changes from v1.4.5 to v1.4.7, to prepare for v2.0.0 branch codes. Changes includes in these releases have been included in v2.0.0 branch already. Details: Revert "feat: add --rfc1918 flag for explicit LAN client support" This reverts commit0e3f764299. Revert "Upgrade quic-go to v0.54.0" This reverts commite52402eb0c. Revert "docs: add known issues documentation for Darwin 15.5 upgrade issue" This reverts commit2133f31854. Revert "start mobile library with provision id and custom hostname." This reverts commita198a5cd65. Revert "Add OPNsense new lease file" This reverts commit7af29cfbc0. Revert ".github/workflows: bump go version to 1.24.x" This reverts commitce1a165348. Revert "fix: ensure upstream health checks can handle large DNS responses" This reverts commitfd48e6d795. Revert "refactor(prog): move network monitoring outside listener loop" This reverts commitd71d1341b6. Revert "fix: correct Windows API constants to fix domain join detection" This reverts commit21855df4af. Revert "refactor: move network monitoring to separate goroutine" This reverts commit66e2d3a40a. Revert "refactor: extract empty string filtering to reusable function" This reverts commit36a7423634. Revert "cmd/cli: ignore empty positional argument for start command" This reverts commite616091249. Revert "Avoiding Windows runners file locking issue" This reverts commit0948161529. Revert "refactor: split selfUpgradeCheck into version check and upgrade execution" This reverts commitce29b5d217. Revert "internal/router: support Ubios 4.3+" This reverts commitde24fa293e. Revert "internal/router: support Merlin Guest Network Pro VLAN" This reverts commit6663925c4d.
This commit is contained in:
committed by
Cuong Manh Le
parent
3ca559e5a4
commit
51e58b64a5
@@ -16,5 +16,4 @@ var clientInfoFiles = map[string]ctrld.LeaseFileFormat{
|
||||
"/var/dhcpd/var/db/dhcpd.leases": ctrld.IscDhcpd, // Pfsense
|
||||
"/home/pi/.router/run/dhcp/dnsmasq.leases": ctrld.Dnsmasq, // Firewalla
|
||||
"/var/lib/kea/dhcp4.leases": ctrld.KeaDHCP4, // Pfsense
|
||||
"/var/db/dnsmasq.leases": ctrld.Dnsmasq, // OPNsense
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ func (m *mdns) lookupIPByHostname(name string, v6 bool) string {
|
||||
if value == name {
|
||||
if addr, err := netip.ParseAddr(key.(string)); err == nil && addr.Is6() == v6 {
|
||||
ip = addr.String()
|
||||
//lint:ignore S1008 This is used for readable.
|
||||
if addr.IsLoopback() { // Continue searching if this is loopback address.
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@ func (p *ptrDiscover) lookupIPByHostname(name string, v6 bool) string {
|
||||
if value == name {
|
||||
if addr, err := netip.ParseAddr(key.(string)); err == nil && addr.Is6() == v6 {
|
||||
ip = addr.String()
|
||||
//lint:ignore S1008 This is used for readable.
|
||||
if addr.IsLoopback() { // Continue searching if this is loopback address.
|
||||
return true
|
||||
}
|
||||
@@ -119,7 +120,8 @@ func (p *ptrDiscover) lookupIPByHostname(name string, v6 bool) string {
|
||||
// is reachable, set p.serverDown to false, so p.lookupHostname can continue working.
|
||||
func (p *ptrDiscover) checkServer() {
|
||||
bo := backoff.NewBackoff("ptrDiscover", func(format string, args ...any) {}, time.Minute*5)
|
||||
m := (&ctrld.UpstreamConfig{}).VerifyMsg()
|
||||
m := new(dns.Msg)
|
||||
m.SetQuestion(".", dns.TypeNS)
|
||||
ping := func() error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -29,62 +28,3 @@ func interfaceNameFromReader(r io.Reader) (string, error) {
|
||||
}
|
||||
return "", errors.New("not found")
|
||||
}
|
||||
|
||||
// AdditionalConfigFiles returns a list of Dnsmasq configuration files found in the "/tmp/etc" directory.
|
||||
func AdditionalConfigFiles() []string {
|
||||
if paths, err := filepath.Glob("/tmp/etc/dnsmasq-*.conf"); err == nil {
|
||||
return paths
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AdditionalLeaseFiles returns a list of lease file paths corresponding to the Dnsmasq configuration files.
|
||||
func AdditionalLeaseFiles() []string {
|
||||
cfgFiles := AdditionalConfigFiles()
|
||||
if len(cfgFiles) == 0 {
|
||||
return nil
|
||||
}
|
||||
leaseFiles := make([]string, 0, len(cfgFiles))
|
||||
for _, cfgFile := range cfgFiles {
|
||||
if leaseFile := leaseFileFromConfigFileName(cfgFile); leaseFile != "" {
|
||||
leaseFiles = append(leaseFiles, leaseFile)
|
||||
|
||||
} else {
|
||||
leaseFiles = append(leaseFiles, defaultLeaseFileFromConfigPath(cfgFile))
|
||||
}
|
||||
}
|
||||
return leaseFiles
|
||||
}
|
||||
|
||||
// leaseFileFromConfigFileName retrieves the DHCP lease file path by reading and parsing the provided configuration file.
|
||||
func leaseFileFromConfigFileName(cfgFile string) string {
|
||||
if f, err := os.Open(cfgFile); err == nil {
|
||||
return leaseFileFromReader(f)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// leaseFileFromReader parses the given io.Reader for the "dhcp-leasefile" configuration and returns its value as a string.
|
||||
func leaseFileFromReader(r io.Reader) string {
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
}
|
||||
before, after, found := strings.Cut(line, "=")
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
if before == "dhcp-leasefile" {
|
||||
return after
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// defaultLeaseFileFromConfigPath generates the default lease file path based on the provided configuration file path.
|
||||
func defaultLeaseFileFromConfigPath(path string) string {
|
||||
name := filepath.Base(path)
|
||||
return filepath.Join("/var/lib/misc", strings.TrimSuffix(name, ".conf")+".leases")
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dnsmasq
|
||||
|
||||
import (
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -45,49 +44,3 @@ interface=eth0
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_leaseFileFromReader(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
in io.Reader
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
"default",
|
||||
strings.NewReader(`
|
||||
dhcp-script=/sbin/dhcpc_lease
|
||||
dhcp-leasefile=/var/lib/misc/dnsmasq-1.leases
|
||||
script-arp
|
||||
`),
|
||||
"/var/lib/misc/dnsmasq-1.leases",
|
||||
},
|
||||
{
|
||||
"non-default",
|
||||
strings.NewReader(`
|
||||
dhcp-script=/sbin/dhcpc_lease
|
||||
dhcp-leasefile=/tmp/var/lib/misc/dnsmasq-1.leases
|
||||
script-arp
|
||||
`),
|
||||
"/tmp/var/lib/misc/dnsmasq-1.leases",
|
||||
},
|
||||
{
|
||||
"missing",
|
||||
strings.NewReader(`
|
||||
dhcp-script=/sbin/dhcpc_lease
|
||||
script-arp
|
||||
`),
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if got := leaseFileFromReader(tc.in); got != tc.expected {
|
||||
t.Errorf("leaseFileFromReader() = %v, want %v", got, tc.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"html/template"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -27,13 +26,9 @@ max-cache-ttl=0
|
||||
{{- end}}
|
||||
`
|
||||
|
||||
const (
|
||||
MerlinConfPath = "/tmp/etc/dnsmasq.conf"
|
||||
MerlinJffsConfDir = "/jffs/configs"
|
||||
MerlinJffsConfPath = "/jffs/configs/dnsmasq.conf"
|
||||
MerlinPostConfPath = "/jffs/scripts/dnsmasq.postconf"
|
||||
)
|
||||
|
||||
const MerlinConfPath = "/tmp/etc/dnsmasq.conf"
|
||||
const MerlinJffsConfPath = "/jffs/configs/dnsmasq.conf"
|
||||
const MerlinPostConfPath = "/jffs/scripts/dnsmasq.postconf"
|
||||
const MerlinPostConfMarker = `# GENERATED BY ctrld - EOF`
|
||||
const MerlinPostConfTmpl = `# GENERATED BY ctrld - DO NOT MODIFY
|
||||
|
||||
@@ -164,27 +159,3 @@ func FirewallaSelfInterfaces() []*net.Interface {
|
||||
}
|
||||
return ifaces
|
||||
}
|
||||
|
||||
const (
|
||||
ubios43ConfPath = "/run/dnsmasq.dhcp.conf.d"
|
||||
ubios42ConfPath = "/run/dnsmasq.conf.d"
|
||||
ubios43PidFile = "/run/dnsmasq-main.pid"
|
||||
ubios42PidFile = "/run/dnsmasq.pid"
|
||||
UbiosConfName = "zzzctrld.conf"
|
||||
)
|
||||
|
||||
// UbiosConfPath returns the appropriate configuration path based on the system's directory structure.
|
||||
func UbiosConfPath() string {
|
||||
if st, _ := os.Stat(ubios43ConfPath); st != nil && st.IsDir() {
|
||||
return ubios43ConfPath
|
||||
}
|
||||
return ubios42ConfPath
|
||||
}
|
||||
|
||||
// UbiosPidFile returns the appropriate dnsmasq pid file based on the system's directory structure.
|
||||
func UbiosPidFile() string {
|
||||
if st, _ := os.Stat(ubios43PidFile); st != nil && !st.IsDir() {
|
||||
return ubios43PidFile
|
||||
}
|
||||
return ubios42PidFile
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/kardianos/service"
|
||||
@@ -182,7 +181,7 @@ func ContentFilteringEnabled() bool {
|
||||
// DnsShieldEnabled reports whether DNS Shield is enabled.
|
||||
// See: https://community.ui.com/releases/UniFi-OS-Dream-Machines-3-2-7/251dfc1e-f4dd-4264-a080-3be9d8b9e02b
|
||||
func DnsShieldEnabled() bool {
|
||||
buf, err := os.ReadFile(filepath.Join(dnsmasq.UbiosConfPath(), "dns.conf"))
|
||||
buf, err := os.ReadFile("/var/run/dnsmasq.conf.d/dns.conf")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
@@ -21,18 +20,10 @@ import (
|
||||
|
||||
const Name = "merlin"
|
||||
|
||||
// nvramKvMap is a map of NVRAM key-value pairs used to configure and manage Merlin-specific settings.
|
||||
var nvramKvMap = map[string]string{
|
||||
"dnspriv_enable": "0", // Ensure Merlin native DoT disabled.
|
||||
}
|
||||
|
||||
// dnsmasqConfig represents configuration paths for dnsmasq operations in Merlin firmware.
|
||||
type dnsmasqConfig struct {
|
||||
confPath string
|
||||
jffsConfPath string
|
||||
}
|
||||
|
||||
// Merlin represents a configuration handler for setting up and managing ctrld on Merlin routers.
|
||||
type Merlin struct {
|
||||
cfg *ctrld.Config
|
||||
}
|
||||
@@ -42,22 +33,18 @@ func New(cfg *ctrld.Config) *Merlin {
|
||||
return &Merlin{cfg: cfg}
|
||||
}
|
||||
|
||||
// ConfigureService configures the service based on the provided configuration. It returns an error if the configuration fails.
|
||||
func (m *Merlin) ConfigureService(config *service.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Install sets up the necessary configurations and services required for the Merlin instance to function properly.
|
||||
func (m *Merlin) Install(_ *service.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Uninstall removes the ctrld-related configurations and services from the Merlin router and reverts to the original state.
|
||||
func (m *Merlin) Uninstall(_ *service.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// PreRun prepares the Merlin instance for operation by waiting for essential services and directories to become available.
|
||||
func (m *Merlin) PreRun() error {
|
||||
// Wait NTP ready.
|
||||
_ = m.Cleanup()
|
||||
@@ -79,7 +66,6 @@ func (m *Merlin) PreRun() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Setup initializes and configures the Merlin instance for use, including setting up dnsmasq and necessary nvram settings.
|
||||
func (m *Merlin) Setup() error {
|
||||
if m.cfg.FirstListener().IsDirectDnsListener() {
|
||||
return nil
|
||||
@@ -93,10 +79,35 @@ func (m *Merlin) Setup() error {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, cfg := range getDnsmasqConfigs() {
|
||||
if err := m.setupDnsmasq(cfg); err != nil {
|
||||
return fmt.Errorf("failed to setup dnsmasq: config: %s, error: %w", cfg.confPath, err)
|
||||
}
|
||||
// Copy current dnsmasq config to /jffs/configs/dnsmasq.conf,
|
||||
// Then we will run postconf script on this file.
|
||||
//
|
||||
// Normally, adding postconf script is enough. However, we see
|
||||
// reports on some Merlin devices that postconf scripts does not
|
||||
// work, but manipulating the config directly via /jffs/configs does.
|
||||
src, err := os.Open(dnsmasq.MerlinConfPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open dnsmasq config: %w", err)
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
dst, err := os.Create(dnsmasq.MerlinJffsConfPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create %s: %w", dnsmasq.MerlinJffsConfPath, err)
|
||||
}
|
||||
defer dst.Close()
|
||||
|
||||
if _, err := io.Copy(dst, src); err != nil {
|
||||
return fmt.Errorf("failed to copy current dnsmasq config: %w", err)
|
||||
}
|
||||
if err := dst.Close(); err != nil {
|
||||
return fmt.Errorf("failed to save %s: %w", dnsmasq.MerlinJffsConfPath, err)
|
||||
}
|
||||
|
||||
// Run postconf script on /jffs/configs/dnsmasq.conf directly.
|
||||
cmd := exec.Command("/bin/sh", dnsmasq.MerlinPostConfPath, dnsmasq.MerlinJffsConfPath)
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("failed to run post conf: %s: %w", string(out), err)
|
||||
}
|
||||
|
||||
// Restart dnsmasq service.
|
||||
@@ -111,7 +122,6 @@ func (m *Merlin) Setup() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Cleanup restores the original dnsmasq and nvram configurations and restarts dnsmasq if necessary.
|
||||
func (m *Merlin) Cleanup() error {
|
||||
if m.cfg.FirstListener().IsDirectDnsListener() {
|
||||
return nil
|
||||
@@ -133,11 +143,9 @@ func (m *Merlin) Cleanup() error {
|
||||
if err := os.WriteFile(dnsmasq.MerlinPostConfPath, merlinParsePostConf(buf), 0750); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, cfg := range getDnsmasqConfigs() {
|
||||
if err := m.cleanupDnsmasqJffs(cfg); err != nil {
|
||||
return fmt.Errorf("failed to cleanup jffs dnsmasq: config: %s, error: %w", cfg.confPath, err)
|
||||
}
|
||||
// Remove /jffs/configs/dnsmasq.conf file.
|
||||
if err := os.Remove(dnsmasq.MerlinJffsConfPath); err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
// Restart dnsmasq service.
|
||||
if err := restartDNSMasq(); err != nil {
|
||||
@@ -146,54 +154,6 @@ func (m *Merlin) Cleanup() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// setupDnsmasq sets up dnsmasq configuration by writing postconf, copying configuration, and running a postconf script.
|
||||
func (m *Merlin) setupDnsmasq(cfg *dnsmasqConfig) error {
|
||||
src, err := os.Open(cfg.confPath)
|
||||
if os.IsNotExist(err) {
|
||||
return nil // nothing to do if conf file does not exist.
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open dnsmasq config: %w", err)
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
// Copy current dnsmasq config to cfg.jffsConfPath,
|
||||
// Then we will run postconf script on this file.
|
||||
//
|
||||
// Normally, adding postconf script is enough. However, we see
|
||||
// reports on some Merlin devices that postconf scripts does not
|
||||
// work, but manipulating the config directly via /jffs/configs does.
|
||||
dst, err := os.Create(cfg.jffsConfPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create %s: %w", cfg.jffsConfPath, err)
|
||||
}
|
||||
defer dst.Close()
|
||||
|
||||
if _, err := io.Copy(dst, src); err != nil {
|
||||
return fmt.Errorf("failed to copy current dnsmasq config: %w", err)
|
||||
}
|
||||
if err := dst.Close(); err != nil {
|
||||
return fmt.Errorf("failed to save %s: %w", cfg.jffsConfPath, err)
|
||||
}
|
||||
|
||||
// Run postconf script on cfg.jffsConfPath directly.
|
||||
cmd := exec.Command("/bin/sh", dnsmasq.MerlinPostConfPath, cfg.jffsConfPath)
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("failed to run post conf: %s: %w", string(out), err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// cleanupDnsmasqJffs removes the JFFS configuration file specified in the given dnsmasqConfig, if it exists.
|
||||
func (m *Merlin) cleanupDnsmasqJffs(cfg *dnsmasqConfig) error {
|
||||
// Remove cfg.jffsConfPath file.
|
||||
if err := os.Remove(cfg.jffsConfPath); err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// writeDnsmasqPostconf writes the requireddnsmasqConfigs post-configuration for dnsmasq to enable custom DNS settings with ctrld.
|
||||
func (m *Merlin) writeDnsmasqPostconf() error {
|
||||
buf, err := os.ReadFile(dnsmasq.MerlinPostConfPath)
|
||||
// Already setup.
|
||||
@@ -219,8 +179,6 @@ func (m *Merlin) writeDnsmasqPostconf() error {
|
||||
return os.WriteFile(dnsmasq.MerlinPostConfPath, []byte(data), 0750)
|
||||
}
|
||||
|
||||
// restartDNSMasq restarts the dnsmasq service by executing the appropriate system command using "service".
|
||||
// Returns an error if the command fails or if there is an issue processing the command output.
|
||||
func restartDNSMasq() error {
|
||||
if out, err := exec.Command("service", "restart_dnsmasq").CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("restart_dnsmasq: %s, %w", string(out), err)
|
||||
@@ -228,22 +186,6 @@ func restartDNSMasq() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// getDnsmasqConfigs retrieves a list of dnsmasqConfig containing configuration and JFFS paths for dnsmasq operations.
|
||||
func getDnsmasqConfigs() []*dnsmasqConfig {
|
||||
cfgs := []*dnsmasqConfig{
|
||||
{dnsmasq.MerlinConfPath, dnsmasq.MerlinJffsConfPath},
|
||||
}
|
||||
for _, path := range dnsmasq.AdditionalConfigFiles() {
|
||||
jffsConfPath := filepath.Join(dnsmasq.MerlinJffsConfDir, filepath.Base(path))
|
||||
cfgs = append(cfgs, &dnsmasqConfig{path, jffsConfPath})
|
||||
}
|
||||
|
||||
return cfgs
|
||||
}
|
||||
|
||||
// merlinParsePostConf parses the dnsmasq post configuration by removing content after the MerlinPostConfMarker, if present.
|
||||
// If no marker is found, the original buffer is returned unmodified.
|
||||
// Returns nil if the input buffer is empty.
|
||||
func merlinParsePostConf(buf []byte) []byte {
|
||||
if len(buf) == 0 {
|
||||
return nil
|
||||
@@ -255,7 +197,6 @@ func merlinParsePostConf(buf []byte) []byte {
|
||||
return buf
|
||||
}
|
||||
|
||||
// waitDirExists waits until the specified directory exists, polling its existence every second.
|
||||
func waitDirExists(dir string) {
|
||||
for {
|
||||
if _, err := os.Stat(dir); !os.IsNotExist(err) {
|
||||
|
||||
@@ -13,13 +13,14 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/kardianos/service"
|
||||
|
||||
"github.com/Control-D-Inc/ctrld/internal/router/dnsmasq"
|
||||
)
|
||||
|
||||
// This is a copy of https://github.com/kardianos/service/blob/v1.2.1/service_sysv_linux.go,
|
||||
// with modification for supporting ubios v1 init system.
|
||||
|
||||
// Keep in sync with ubios.ubiosDNSMasqConfigPath
|
||||
const ubiosDNSMasqConfigPath = "/run/dnsmasq.conf.d/zzzctrld.conf"
|
||||
|
||||
type ubiosSvc struct {
|
||||
i service.Interface
|
||||
platform string
|
||||
@@ -85,7 +86,7 @@ func (s *ubiosSvc) Install() error {
|
||||
}{
|
||||
s.Config,
|
||||
path,
|
||||
filepath.Join(dnsmasq.UbiosConfPath(), dnsmasq.UbiosConfName),
|
||||
ubiosDNSMasqConfigPath,
|
||||
}
|
||||
|
||||
if err := s.template().Execute(f, to); err != nil {
|
||||
|
||||
@@ -3,7 +3,6 @@ package ubios
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/kardianos/service"
|
||||
@@ -13,19 +12,19 @@ import (
|
||||
"github.com/Control-D-Inc/ctrld/internal/router/edgeos"
|
||||
)
|
||||
|
||||
const Name = "ubios"
|
||||
const (
|
||||
Name = "ubios"
|
||||
ubiosDNSMasqConfigPath = "/run/dnsmasq.conf.d/zzzctrld.conf"
|
||||
ubiosDNSMasqDnsConfigPath = "/run/dnsmasq.conf.d/dns.conf"
|
||||
)
|
||||
|
||||
type Ubios struct {
|
||||
cfg *ctrld.Config
|
||||
dnsmasqConfPath string
|
||||
cfg *ctrld.Config
|
||||
}
|
||||
|
||||
// New returns a router.Router for configuring/setup/run ctrld on Ubios routers.
|
||||
func New(cfg *ctrld.Config) *Ubios {
|
||||
return &Ubios{
|
||||
cfg: cfg,
|
||||
dnsmasqConfPath: filepath.Join(dnsmasq.UbiosConfPath(), dnsmasq.UbiosConfName),
|
||||
}
|
||||
return &Ubios{cfg: cfg}
|
||||
}
|
||||
|
||||
func (u *Ubios) ConfigureService(config *service.Config) error {
|
||||
@@ -60,7 +59,7 @@ func (u *Ubios) Setup() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.WriteFile(u.dnsmasqConfPath, []byte(data), 0600); err != nil {
|
||||
if err := os.WriteFile(ubiosDNSMasqConfigPath, []byte(data), 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
// Restart dnsmasq service.
|
||||
@@ -75,7 +74,7 @@ func (u *Ubios) Cleanup() error {
|
||||
return nil
|
||||
}
|
||||
// Remove the custom dnsmasq config
|
||||
if err := os.Remove(u.dnsmasqConfPath); err != nil {
|
||||
if err := os.Remove(ubiosDNSMasqConfigPath); err != nil {
|
||||
return err
|
||||
}
|
||||
// Restart dnsmasq service.
|
||||
@@ -86,7 +85,7 @@ func (u *Ubios) Cleanup() error {
|
||||
}
|
||||
|
||||
func restartDNSMasq() error {
|
||||
buf, err := os.ReadFile(dnsmasq.UbiosPidFile())
|
||||
buf, err := os.ReadFile("/run/dnsmasq.pid")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user