Files
ctrld/internal/clientinfo/arp.go
Cuong Manh Le 0f3e8c7ada all: include client IP if ctrld is dnsmasq upstream
So ctrld can record the raw/original client IP instead of looking up
from MAC to IP, which may not the right choice in some network setup
like using wireguard/vpn on Merlin router.
2023-09-22 18:40:25 +07:00

50 lines
787 B
Go

package clientinfo
import "sync"
type arpDiscover struct {
mac sync.Map // ip => mac
ip sync.Map // mac => ip
}
func (a *arpDiscover) refresh() error {
a.scan()
return nil
}
func (a *arpDiscover) LookupIP(mac string) string {
val, ok := a.ip.Load(mac)
if !ok {
return ""
}
return val.(string)
}
func (a *arpDiscover) LookupMac(ip string) string {
val, ok := a.mac.Load(ip)
if !ok {
return ""
}
return val.(string)
}
func (a *arpDiscover) String() string {
return "arp"
}
func (a *arpDiscover) List() []string {
if a == nil {
return nil
}
var ips []string
a.ip.Range(func(key, value any) bool {
ips = append(ips, value.(string))
return true
})
a.mac.Range(func(key, value any) bool {
ips = append(ips, key.(string))
return true
})
return ips
}