isle/go/cmd/entrypoint/dnsmasq_util.go

52 lines
1.2 KiB
Go
Raw Normal View History

package main
import (
"isle/bootstrap"
"isle/daemon"
"isle/dnsmasq"
"fmt"
"path/filepath"
"sort"
"code.betamike.com/micropelago/pmux/pmuxlib"
)
func dnsmasqPmuxProcConfig(
2022-10-26 22:23:39 +00:00
hostBootstrap bootstrap.Bootstrap,
daemonConfig daemon.Config,
) (
pmuxlib.ProcessConfig, error,
) {
2022-10-26 22:37:03 +00:00
confPath := filepath.Join(envRuntimeDirPath, "dnsmasq.conf")
hostsSlice := make([]dnsmasq.ConfDataHost, 0, len(hostBootstrap.Hosts))
2022-10-26 22:23:39 +00:00
for _, host := range hostBootstrap.Hosts {
hostsSlice = append(hostsSlice, dnsmasq.ConfDataHost{
Name: host.Name,
IP: host.IP().String(),
})
}
sort.Slice(hostsSlice, func(i, j int) bool {
return hostsSlice[i].IP < hostsSlice[j].IP
})
confData := dnsmasq.ConfData{
Resolvers: daemonConfig.DNS.Resolvers,
2022-10-26 22:23:39 +00:00
Domain: hostBootstrap.AdminCreationParams.Domain,
IP: hostBootstrap.ThisHost().IP().String(),
Hosts: hostsSlice,
}
if err := dnsmasq.WriteConfFile(confPath, confData); err != nil {
return pmuxlib.ProcessConfig{}, fmt.Errorf("writing dnsmasq.conf to %q: %w", confPath, err)
}
return pmuxlib.ProcessConfig{
Name: "dnsmasq",
Cmd: binPath("dnsmasq"),
Args: []string{"-d", "-C", confPath},
}, nil
}