Add extra logs to engine and dns manager

This commit is contained in:
Diego Romar
2025-12-18 13:58:11 -03:00
parent c29bb1a289
commit 72e1fe7b48
2 changed files with 46 additions and 0 deletions

View File

@@ -420,10 +420,14 @@ func (e *Engine) Start(netbirdConfig *mgmProto.NetbirdConfig, mgmtURL *url.URL)
e.wgInterface = wgIface
e.statusRecorder.SetWgIface(wgIface)
log.Info("set wg interface to statusRecorder")
// start flow manager right after interface creation
publicKey := e.config.WgPrivateKey.PublicKey()
e.flowManager = netflow.NewManager(e.wgInterface, publicKey[:], e.statusRecorder)
log.Info("created flow manager")
if e.config.RosenpassEnabled {
log.Infof("rosenpass is enabled")
if e.config.RosenpassPermissive {
@@ -441,6 +445,8 @@ func (e *Engine) Start(netbirdConfig *mgmProto.NetbirdConfig, mgmtURL *url.URL)
}
e.stateManager.Start()
log.Info("started state manager")
initialRoutes, dnsConfig, dnsFeatureFlag, err := e.readInitialSettings()
if err != nil {
e.close()
@@ -454,6 +460,8 @@ func (e *Engine) Start(netbirdConfig *mgmProto.NetbirdConfig, mgmtURL *url.URL)
}
e.dnsServer = dnsServer
log.Info("created dns server")
// Populate DNS cache with NetbirdConfig and management URL for early resolution
if err := e.PopulateNetbirdConfig(netbirdConfig, mgmtURL); err != nil {
log.Warnf("failed to populate DNS cache: %v", err)
@@ -478,19 +486,27 @@ func (e *Engine) Start(netbirdConfig *mgmProto.NetbirdConfig, mgmtURL *url.URL)
log.Errorf("Failed to initialize route manager: %s", err)
}
log.Info("set route manager")
e.routeManager.SetRouteChangeListener(e.mobileDep.NetworkChangeListener)
log.Info("set route change listener to route manager")
if err = e.wgInterfaceCreate(); err != nil {
log.Errorf("failed creating tunnel interface %s: [%s]", e.config.WgIfaceName, err.Error())
e.close()
return fmt.Errorf("create wg interface: %w", err)
}
log.Info("created tunnel interface")
if err := e.createFirewall(); err != nil {
e.close()
return err
}
log.Info("created firewall")
e.udpMux, err = e.wgInterface.Up()
if err != nil {
log.Errorf("failed to pull up wgInterface [%s]: %s", e.wgInterface.Name(), err.Error())
@@ -498,6 +514,8 @@ func (e *Engine) Start(netbirdConfig *mgmProto.NetbirdConfig, mgmtURL *url.URL)
return fmt.Errorf("up wg interface: %w", err)
}
log.Info("pulled up tunnel interface")
// if inbound conns are blocked there is no need to create the ACL manager
if e.firewall != nil && !e.config.BlockInbound {
e.acl = acl.NewDefaultManager(e.firewall)
@@ -509,24 +527,38 @@ func (e *Engine) Start(netbirdConfig *mgmProto.NetbirdConfig, mgmtURL *url.URL)
return fmt.Errorf("initialize dns server: %w", err)
}
log.Info("initialized dns server")
iceCfg := e.createICEConfig()
log.Infof("created ICE config: %v", iceCfg)
e.connMgr = NewConnMgr(e.config, e.statusRecorder, e.peerStore, wgIface)
e.connMgr.Start(e.ctx)
log.Info("started connection manager")
e.srWatcher = guard.NewSRWatcher(e.signal, e.relayManager, e.mobileDep.IFaceDiscover, iceCfg)
e.srWatcher.Start()
log.Info("started SR watcher")
e.receiveSignalEvents()
e.receiveManagementEvents()
log.Info("started receiving events from Signal and Management services")
// starting network monitor at the very last to avoid disruptions
e.startNetworkMonitor()
log.Info("started network monitor")
// monitor WireGuard interface lifecycle and restart engine on changes
e.wgIfaceMonitor = NewWGIfaceMonitor()
e.shutdownWg.Add(1)
log.Infof("starting WireGuard interface monitor")
go func() {
defer e.shutdownWg.Done()
@@ -538,6 +570,8 @@ func (e *Engine) Start(netbirdConfig *mgmProto.NetbirdConfig, mgmtURL *url.URL)
}
}()
log.Info("engine started successfully")
return nil
}
@@ -731,21 +765,28 @@ func (e *Engine) PopulateNetbirdConfig(netbirdConfig *mgmProto.NetbirdConfig, mg
return nil
}
log.Info("PopulateNetbirdConfig: starting")
// Populate management URL if provided
if mgmtURL != nil {
log.Infof("PopulateNetbirdConfig: calling PopulateManagementDomain for %s", mgmtURL.Host)
if err := e.dnsServer.PopulateManagementDomain(mgmtURL); err != nil {
log.Warnf("failed to populate DNS cache with management URL: %v", err)
}
log.Info("PopulateNetbirdConfig: PopulateManagementDomain completed")
}
// Populate NetbirdConfig domains if provided
if netbirdConfig != nil {
log.Info("PopulateNetbirdConfig: calling UpdateServerConfig")
serverDomains := dnsconfig.ExtractFromNetbirdConfig(netbirdConfig)
if err := e.dnsServer.UpdateServerConfig(serverDomains); err != nil {
return fmt.Errorf("update DNS server config from NetbirdConfig: %w", err)
}
log.Info("PopulateNetbirdConfig: UpdateServerConfig completed")
}
log.Info("PopulateNetbirdConfig: done")
return nil
}