2024-06-17 18:51:02 +00:00
|
|
|
package daemon
|
2022-10-26 20:18:16 +00:00
|
|
|
|
|
|
|
import (
|
2024-06-17 18:51:02 +00:00
|
|
|
"fmt"
|
2023-08-05 21:53:17 +00:00
|
|
|
"isle/bootstrap"
|
|
|
|
"isle/dnsmasq"
|
2022-10-26 20:18:16 +00:00
|
|
|
"path/filepath"
|
|
|
|
"sort"
|
|
|
|
|
2023-07-06 15:51:38 +00:00
|
|
|
"code.betamike.com/micropelago/pmux/pmuxlib"
|
2022-10-26 20:18:16 +00:00
|
|
|
)
|
|
|
|
|
2022-10-26 21:21:31 +00:00
|
|
|
func dnsmasqPmuxProcConfig(
|
2024-06-17 18:51:02 +00:00
|
|
|
runtimeDirPath, binDirPath string,
|
2022-10-26 22:23:39 +00:00
|
|
|
hostBootstrap bootstrap.Bootstrap,
|
2024-06-17 18:51:02 +00:00
|
|
|
daemonConfig Config,
|
2022-10-26 21:21:31 +00:00
|
|
|
) (
|
|
|
|
pmuxlib.ProcessConfig, error,
|
|
|
|
) {
|
2024-06-17 18:51:02 +00:00
|
|
|
confPath := filepath.Join(runtimeDirPath, "dnsmasq.conf")
|
2022-10-26 20:18:16 +00:00
|
|
|
|
2022-10-29 19:11:40 +00:00
|
|
|
hostsSlice := make([]dnsmasq.ConfDataHost, 0, len(hostBootstrap.Hosts))
|
2022-10-26 22:23:39 +00:00
|
|
|
for _, host := range hostBootstrap.Hosts {
|
2022-10-29 19:11:40 +00:00
|
|
|
hostsSlice = append(hostsSlice, dnsmasq.ConfDataHost{
|
|
|
|
Name: host.Name,
|
|
|
|
IP: host.IP().String(),
|
|
|
|
})
|
2022-10-26 20:18:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(hostsSlice, func(i, j int) bool {
|
2022-10-29 19:11:40 +00:00
|
|
|
return hostsSlice[i].IP < hostsSlice[j].IP
|
2022-10-26 20:18:16 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
confData := dnsmasq.ConfData{
|
2022-10-26 21:21:31 +00:00
|
|
|
Resolvers: daemonConfig.DNS.Resolvers,
|
2022-10-26 22:23:39 +00:00
|
|
|
Domain: hostBootstrap.AdminCreationParams.Domain,
|
2022-10-29 19:11:40 +00:00
|
|
|
IP: hostBootstrap.ThisHost().IP().String(),
|
2022-10-26 20:18:16 +00:00
|
|
|
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",
|
2024-06-17 18:51:02 +00:00
|
|
|
Cmd: filepath.Join(binDirPath, "dnsmasq"),
|
2022-10-26 20:18:16 +00:00
|
|
|
Args: []string{"-d", "-C", confPath},
|
|
|
|
}, nil
|
|
|
|
}
|