cmd/ctrld: only spawn DNS server for ntpd if necessary

On some platforms, like pfsense, ntpd is not problem, so do not spawn
the DNS server for it, which may conflict with default DNS server.

While at it, also make sure that ctrld will be run at last on startup.
This commit is contained in:
Cuong Manh Le authored and Cuong Manh Le committed 2023-06-08 02:07:10 +07:00
1 parent 542c4f7daf
commit 929de49c7b
4 files changed
+36 -21

No files matched your search

+2 -2
View File
@@ -165,11 +165,11 @@ func initCLI() {
initLogging()
if setupRouter {
s, _ := runDNSServerForNTPD()
s, errCh := runDNSServerForNTPD(router.ListenAddress())
if err := router.PreRun(); err != nil {
mainLog.Fatal().Err(err).Msg("failed to perform router pre-start check")
}
if err := s.Shutdown(); err != nil {
if err := s.Shutdown(); err != nil && errCh != nil {
mainLog.Fatal().Err(err).Msg("failed to shutdown dns server for ntpd")
}
}
+5 -2
View File
@@ -473,10 +473,13 @@ func runDNSServer(addr, network string, handler dns.Handler) (*dns.Server, <-cha
// runDNSServerForNTPD starts a DNS server listening on router.ListenAddress(). It must only be called when ctrld
// running on router, before router.PreRun() to serve DNS request for NTP synchronization. The caller must call
// s.Shutdown() explicitly when NTP is synced successfully.
func runDNSServerForNTPD() (*dns.Server, <-chan error) {
func runDNSServerForNTPD(addr string) (*dns.Server, <-chan error) {
if addr == "" {
return &dns.Server{}, nil
}
dnsResolver := ctrld.NewBootstrapResolver()
s := &dns.Server{
Addr: router.ListenAddress(),
Addr: addr,
Net: "udp",
Handler: dns.HandlerFunc(func(w dns.ResponseWriter, m *dns.Msg) {
mainLog.Debug().Msg("Serving query for ntpd")