mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-10-12 01:58:46 +02:00
cmd/cli: get default interface once
This commit is contained in:
1 parent
4f62314646
commit
9bbccb4082
1 file changed
+17
-22
+17
-22
@@ -103,6 +103,8 @@ type prog struct {
|
|||||||
initInternalLogWriterOnce sync.Once
|
initInternalLogWriterOnce sync.Once
|
||||||
internalLogWriter *logWriter
|
internalLogWriter *logWriter
|
||||||
internalLogSent time.Time
|
internalLogSent time.Time
|
||||||
|
runningIface string
|
||||||
|
requiredMultiNICsConfig bool
|
||||||
|
|
||||||
selfUninstallMu sync.Mutex
|
selfUninstallMu sync.Mutex
|
||||||
refusedQueryCount int
|
refusedQueryCount int
|
||||||
@@ -243,6 +245,11 @@ func (p *prog) runWait() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *prog) preRun() {
|
func (p *prog) preRun() {
|
||||||
|
if iface == "auto" {
|
||||||
|
iface = defaultIfaceName()
|
||||||
|
p.requiredMultiNICsConfig = requiredMultiNICsConfig()
|
||||||
|
}
|
||||||
|
p.runningIface = iface
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
p.onStopped = append(p.onStopped, func() {
|
p.onStopped = append(p.onStopped, func() {
|
||||||
if !service.Interactive() {
|
if !service.Interactive() {
|
||||||
@@ -607,25 +614,18 @@ func (p *prog) setDNS() {
|
|||||||
if cfg.Listener == nil {
|
if cfg.Listener == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if iface == "" {
|
if p.runningIface == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
runningIface := iface
|
|
||||||
// allIfaces tracks whether we should set DNS for all physical interfaces.
|
// allIfaces tracks whether we should set DNS for all physical interfaces.
|
||||||
allIfaces := false
|
allIfaces := p.requiredMultiNICsConfig
|
||||||
if runningIface == "auto" {
|
|
||||||
runningIface = defaultIfaceName()
|
|
||||||
// If runningIface is "auto", it means user does not specify "--iface" flag.
|
|
||||||
// In this case, ctrld has to set DNS for all physical interfaces, so
|
|
||||||
// thing will still work when user switch from one to the other.
|
|
||||||
allIfaces = requiredMultiNICsConfig()
|
|
||||||
}
|
|
||||||
lc := cfg.FirstListener()
|
lc := cfg.FirstListener()
|
||||||
if lc == nil {
|
if lc == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger := mainLog.Load().With().Str("iface", runningIface).Logger()
|
logger := mainLog.Load().With().Str("iface", p.runningIface).Logger()
|
||||||
netIface, err := netInterface(runningIface)
|
netIface, err := netInterface(p.runningIface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error().Err(err).Msg("could not get interface")
|
logger.Error().Err(err).Msg("could not get interface")
|
||||||
return
|
return
|
||||||
@@ -754,18 +754,13 @@ func (p *prog) dnsWatchdog(iface *net.Interface, nameservers []string, allIfaces
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *prog) resetDNS() {
|
func (p *prog) resetDNS() {
|
||||||
if iface == "" {
|
if p.runningIface == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
runningIface := iface
|
// See corresponding comments in (*prog).setDNS function.
|
||||||
allIfaces := false
|
allIfaces := p.requiredMultiNICsConfig
|
||||||
if runningIface == "auto" {
|
logger := mainLog.Load().With().Str("iface", p.runningIface).Logger()
|
||||||
runningIface = defaultIfaceName()
|
netIface, err := netInterface(p.runningIface)
|
||||||
// See corresponding comments in (*prog).setDNS function.
|
|
||||||
allIfaces = requiredMultiNICsConfig()
|
|
||||||
}
|
|
||||||
logger := mainLog.Load().With().Str("iface", runningIface).Logger()
|
|
||||||
netIface, err := netInterface(runningIface)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error().Err(err).Msg("could not get interface")
|
logger.Error().Err(err).Msg("could not get interface")
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in new issue
Block a user