mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
use the changed iface if no default route is set yet
This commit is contained in:
@@ -1316,7 +1316,7 @@ func (p *prog) monitorNetworkChanges(ctx context.Context) error {
|
||||
|
||||
changed := false
|
||||
activeInterfaceExists := false
|
||||
|
||||
changeIPs := []netip.Prefix{}
|
||||
// Check each valid interface for changes
|
||||
for ifaceName := range validIfaces {
|
||||
oldIface := delta.Old.Interface[ifaceName]
|
||||
@@ -1336,6 +1336,7 @@ func (p *prog) monitorNetworkChanges(ctx context.Context) error {
|
||||
if !interfaceStatesEqual(&oldIface, &newIface) || !interfaceIPsEqual(oldIPs, newIPs) {
|
||||
if newIface.IsUp() && len(newIPs) > 0 {
|
||||
changed = true
|
||||
changeIPs = newIPs
|
||||
mainLog.Load().Debug().
|
||||
Str("interface", ifaceName).
|
||||
Interface("old_ips", oldIPs).
|
||||
@@ -1372,6 +1373,18 @@ func (p *prog) monitorNetworkChanges(ctx context.Context) error {
|
||||
ipv6 = addr.String()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If no default route interface is set yet, use the changed IPs
|
||||
for _, ip := range changeIPs {
|
||||
ipAddr, _ := netip.ParsePrefix(ip.String())
|
||||
addr := ipAddr.Addr()
|
||||
if addr.Is4() && selfIP == "" && !addr.IsLoopback() && !addr.IsLinkLocalUnicast() {
|
||||
selfIP = addr.String()
|
||||
}
|
||||
if addr.Is6() && !addr.IsLoopback() && !addr.IsLinkLocalUnicast() {
|
||||
ipv6 = addr.String()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ip := net.ParseIP(selfIP); ip != nil {
|
||||
|
||||
Reference in New Issue
Block a user