internal: record correct interfaces for queries from router on Firewalla

This commit is contained in:
Cuong Manh Le
2023-07-25 20:28:30 +00:00
committed by Cuong Manh Le
parent 12c8ab696f
commit 59dc74ffbb
3 changed files with 62 additions and 23 deletions
+21 -2
View File
@@ -11,11 +11,12 @@ import (
"strings"
"sync"
"github.com/Control-D-Inc/ctrld"
"github.com/fsnotify/fsnotify"
"tailscale.com/net/interfaces"
"tailscale.com/util/lineread"
"github.com/fsnotify/fsnotify"
"github.com/Control-D-Inc/ctrld"
"github.com/Control-D-Inc/ctrld/internal/router"
)
type dhcp struct {
@@ -279,4 +280,22 @@ func (d *dhcp) addSelf() {
}
}
})
for _, netIface := range router.SelfInterfaces() {
mac := netIface.HardwareAddr.String()
if mac == "" {
return
}
d.mac2name.Store(mac, hostname)
addrs, _ := netIface.Addrs()
for _, addr := range addrs {
ipNet, ok := addr.(*net.IPNet)
if !ok {
continue
}
ip := ipNet.IP
d.mac.LoadOrStore(ip.String(), mac)
d.ip.LoadOrStore(mac, ip.String())
d.ip2name.Store(ip.String(), hostname)
}
}
}